Principle:20000419 Fauxnix Stateful Session Execution
| Knowledge Sources | |
|---|---|
| Domains | Session_State, Execution, Shell_Semantics |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
A session-state persistence technique that carries cwd, environment variables, export/unset, cd/OLDPWD, and positional parameters across separate command invocations within a single logical shell session.
Description
Stateful Session Execution makes a sequence of independent command calls behave like a logged-in shell. After each command, the session syncs its state (cwd, env, prevExit for $?) from temp files written by the host process. On the next call, that state is layered into the child process environment. This means cd src in one call affects pwd in the next; export FOO=bar persists; set -- a b c makes $1/$2/$3 available; unset FOO removes the variable. The session is a single object with a lifecycle lock so run/reset/dispose are serialized. reset kills and re-prewarms the host for a fresh shell without constructing a new session object.
Usage
Use this principle when an agent harness issues multiple commands that must share working directory and environment — the common case for iterative development, debugging, and multi-step workflows. It is the right choice over stateless one-shot execution whenever the agent's mental model is "a single terminal session."
Theoretical Basis
State is carried via temp files + environment layering:
[after each segment]
host writes cwd → cwdFile, env → envFile
session.syncFromDisk() reads them back
[next call]
env = hasEnvSnapshot ? {...session.env} : {...process.env, ...session.env}
env.FAUXNIX_CWD = session.cwd
env.FAUXNIX_PREV_EXIT = session.prevExit
spawn host with env
Before the first completed request, env is layered over process.env; after, it is a complete snapshot restored verbatim (so an unset does not resurrect inherited variables).