Files
adaptiveos/etc/profile.d/adaptive-loop.sh
Daveswo 77856f0a09 Initial commit: apkovl deployment source, synced from shell-project main
This directory is what gets packaged into localhost.apkovl.tar.gz and
baked into adaptiveos-vN.iso. It had drifted out of sync with the real
project (root/shell-project/ had gone missing entirely at some point
after being written earlier this session -- cause unconfirmed, Desktop
is a plausible sync-related suspect but not verified) and separately
carried a stale, pre-fix copy of fx.sh.

Current contents:
  etc/profile.d/adaptive-loop.sh   -- disk-persists p AND p.trace
                                       (fx()'s fix-provenance record)
                                       across reboot, two separate 1MB
                                       blocks on the attached state disk
  etc/profile.d/adaptive-setup.sh  -- unchanged, network/git/fzf bring-up
  root/shell-project/              -- synced from space.seodr.ovh/
                                       Daveswo/self-healing-autopoietic-
                                       shell @ 3c4947e (main), plus three
                                       deployment-only files not in that
                                       repo: contrib/fx/builtin-fixes.txt,
                                       contrib/fx/sources.d/15-builtin-
                                       fixes.sh, contrib/heal/heal.sh

Verified byte-identical to what's actually embedded in the currently
shipping adaptiveos-v6.iso before this commit (full recursive diff),
and every .sh file passes `sh -n`.

.gitattributes (text=auto eol=lf) added to prevent the CRLF corruption
that hit the canonical repo earlier this session from recurring here.
2026-08-22 02:55:40 -04:00

54 lines
2.7 KiB
Bash

#!/bin/sh
export FX_SOURCES_DIR=/root/shell-project/contrib/fx/sources.d
. /root/shell-project/src/f.sh
. /root/shell-project/contrib/fx/fx.sh
. /root/shell-project/contrib/heal/heal.sh
cd /root/shell-project 2>/dev/null
# --- Persistent learning state -------------------------------------------
# f()/fx() key learned fixes in a file called "p" in the current directory.
# On a plain live-CD boot that file lives on tmpfs and every reboot forgets
# everything the shell has ever learned.
#
# If a second, writable disk is attached (anything that isn't the boot
# CD), use it as a raw flat store for "p" -- no filesystem, no mkfs. This
# live image never mounts modloop-virt into /lib/modules, so modprobe has
# nothing to load and mkfs.ext4/mount fail with "Invalid argument"
# regardless of e2fsprogs being installed; dd/tr are busybox builtins and
# need no kernel module at all, so they work unconditionally. Learned
# fixes are restored from the disk's first 1MB at boot, and a background
# loop flushes "p" back to it every few seconds. No such disk -> "p"
# stays on tmpfs exactly as before.
STATE_DEV=""
for d in /dev/vda /dev/vdb /dev/vdc /dev/sda /dev/sdb /dev/sdc /dev/xvda /dev/xvdb; do
[ -b "$d" ] && { STATE_DEV="$d"; break; }
done
if [ -n "$STATE_DEV" ]; then
dd if="$STATE_DEV" bs=1M count=1 2>/dev/null | tr -d '\0' > /root/shell-project/p
# p.trace (fx()'s "which source suggested this fix" record) lives in
# the SECOND 1MB block of the same raw device via skip=1/seek=1 --
# a distinct region, not appended after p, so growth of one file can
# never overwrite the other's flat 1MB slot. Requires STATE_DEV to be
# at least 2MB; a device only large enough for p's block silently
# leaves p.trace unpersisted rather than corrupting p.
dd if="$STATE_DEV" bs=1M skip=1 count=1 2>/dev/null | tr -d '\0' > /root/shell-project/p.trace
(
while true; do
sleep 3
[ -f /root/shell-project/p ] && dd if=/root/shell-project/p of="$STATE_DEV" bs=1M count=1 conv=notrunc 2>/dev/null
[ -f /root/shell-project/p.trace ] && dd if=/root/shell-project/p.trace of="$STATE_DEV" bs=1M seek=1 count=1 conv=notrunc 2>/dev/null
done
) &
echo "AdaptiveOS: persistent learning state active on $STATE_DEV -- learned fixes AND fix provenance survive reboot"
fi
echo '========================================='
echo ' Welcome to AdaptiveOS'
echo ' Self-healing shell is live: f(), fx(), heal()'
echo ' Try: fx some-command-that-might-fail'
echo ' heal() does the same, plus logs a MISS to'
echo ' /var/log/glyphos-heal.log if nothing (not'
echo ' even the manual prompt) fixes it'
echo '========================================='