Repository navigation
feat(sessions): project continuity and the session library (AA-CONT-04) - #99
Conversation
Durable sessions existed but were not operable: finding one meant knowing an
opaque id or browsing ~/.aether-agent by hand, and every "what was I doing
here" question cost a walk of every session directory plus a parse of every
manifest. This adds the library that makes them first class.
core/session_index.ts is one small document beside the session directories:
{schemaVersion, entries}. It is a CACHE with an authority rule — the
per-session manifest.json is the truth — so a lost, corrupt, or forward-version
index costs time, never information. Writes go through durable_store.ts's
existing transaction (lock -> read -> mutate -> temp -> flush -> backup ->
rename), read inside the lock, so two runs closing in the same second both
land. A future-schema index is refused and never overwritten, and the write
path reports whether it actually persisted so a caller cannot print "archived"
for a change that is not on disk.
commands/sessions.ts is the screen: list / inspect / continue / export /
archive / clean, an interactive-width table on a TTY and tab-separated columns
with a fixed field order when piped. ui/continuity.ts computes where a session
can be continued and keeps the six answers apart — ready, stale-branch, moved
checkout, another workspace, missing checkout, archived — because the remedies
differ and collapsing any two of them misleads. ui/splash.ts shows the same
facts as a PROJECT CONTINUITY block on entry.
Nothing on the listing path opens events.jsonl; that file is the transcript and
`aether resume` is what replays it. Nothing here deletes: archive sets a flag,
clean drops index rows for sessions already gone, and neither touches a session
directory, a worktree, a branch, or a file a run wrote.
Unknown is never rendered as zero. A count nobody recorded prints "unknown"; a
run whose manifest never closed prints "never finished (running or interrupted
— unknown which)" rather than guessing; a branch the record does not name is
not assumed to be the branch you are on.
core/logs_root.ts exists only so session_log.ts and session_index.ts do not
import each other; session_log.ts re-exports logsRoot, so no caller changed.
Proven by 24 new tests: four separate processes writing concurrently lose no
row, an interrupted write leaves the previous generation byte-identical, a
corrupt index rebuilds visibly and its unreadable copy is preserved, a
future-schema index is refused and left intact, twenty-five sessions with
malformed transcripts list without a parse error, a shared timestamp prefix
never resolves across workspaces, and ESC/OSC sequences in a task never reach
a terminal. Four mutants of the load-bearing invariant were killed.
The library in the previous commit is complete but unreachable: this is the whole wiring, and it is deliberately separate so it can be dropped or reordered without touching the feature. Four additive edits to files this lane shares with others: one row in the CLI registry, one `case "sessions"` in main.ts that lazily imports the command, a `resume list` alias so the listing is reachable from the command people already know, and one field passed to the splash so the PROJECT CONTINUITY block can render. Nothing existing changes behaviour: omit the field and the splash reads nothing from disk and renders exactly as before. The registry spec is mirrored by SESSIONS_CLI_COMMAND next to the implementation and pinned equal by test, so the help text and the behaviour cannot drift. COMMANDS.md documents the surface, including the piped field order, which is part of the contract.
…nting repo names The cost claims were prose. These tests make them a property of the run: every session's manifest.json and events.jsonl is replaced by a DIRECTORY of the same name, so anything that opens one throws EISDIR. A warm listing of 300 sessions answers correctly with all 600 files unopenable, which is the claim "the listing reads the index, not the transcripts" stated in a form that can fail. shortRemote also turned a local path into something that reads like a repository: "/srv/git/bare-repo" rendered as "git/bare-repo", a GitHub-shaped identity for a directory. It now shortens only what is actually an https or scp-style git URL and returns anything else whole.
…recorded" as three different things
`inspect` had three ways of quietly claiming more than the record supports.
ended: "still running" is a claim nobody can back. A manifest with no `ended`
is a manifest that was never closed, and a run that was killed leaves
exactly the same bytes on disk as one that is still going. It now says
the run may still be live or may have been interrupted, and does not
pick.
status: a bare "running" reads like a state the verify gate signed off on. It
now carries "(never verified — the run did not finish)".
pr: the line was printed only when a pull request URL existed, so its
absence read as "no pull request was opened". Nothing in this build
records a pull request against a session, so silence there was the
wrong fact. It now always prints, and says the record cannot answer.
Also pins the CLI registry row against SESSIONS_CLI_COMMAND. The previous test
asserted the spec's own fields, which cannot fail if the row is never copied
into the shared registry at all — the command would simply be unreachable with
a green test. And both confirmation prompts now end in "[y/N] " so the cursor
does not sit against the question mark.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Follow-up: the bounded-cost numbers, and the third unknownPushed Bounded cost, measuredBoth runs use the same fixture: 200 sessions, each with a 400-line Answering "which session was last here" —
3 = the index, plus the manifest and transcript of the one session it actually Listing the library —
One read of the index, one directory listing to reconcile it against the disk. The one-time migration — the first read after upgrading, when sessions
Manifests only. Even the cold path never opens a transcript: 140 KB against
Mutation test: unknown is not zeroThe PR's four mutants cover index-is-a-cache. This is the other invariant. Two deliberate mutations, applied together: - if (usage.status !== "observed" || usage.observed == null) return `${UNKNOWN} spent · ${cap}`;
+ if (usage.status !== "observed" || usage.observed == null) return `${uvt(usage.observed ?? 0)} / ${cap}`;- return typeof value === "number" ? String(value) : UNKNOWN;
+ return String(value ?? 0);Result — 4 failures, both mutants killed: Reverted; 16/16 and 14/14 green again. The third unknown
Registry parity was not actually pinnedThe existing test asserted Verification of this commit
Lane noteTwo agents were live in |
The library had columns for these and nothing to put in them: `branch`,
`repoRemote`, `headRev` and `skills` existed on SessionMeta, but the only
caller that builds a SessionLog (commands/code.ts, another lane's file) passes
none of them, so every real session rendered `unknown` for all four. Honest,
and useless — two of the questions the library exists to answer could never be
answered for a session this build actually wrote.
Both are now taken from what the session already has:
branch / repoRemote / headRev — probed from the workspace ONCE, in close().
Not in the constructor: `aether agent` startup must spawn no git, which is
what #89 cleared off that path, and a test asserts the probe has not been
called after construction. The run is over by close(), so three
`git rev-parse`-class calls cost nothing anyone waits on. The probe is
injected, so every branch of it is testable without a checkout. A probe
that finds nothing, or throws, leaves the fields ABSENT — the library then
says "unknown", which is the truth, rather than an empty string that
renders as a blank cell.
skills — accumulated from the `skill` events already streaming through
event(). Deduplicated (one entry per skill, not per event) and bounded at
32, so a looping brain cannot grow the manifest without limit. The
alternative was re-reading the transcript at listing time, which is exactly
the cost the index exists to remove.
What the caller declares still wins over what was probed: a caller that made
the branch knows better than a probe of the launch directory.
readRepoIdentity and repoFrom move from handoff.ts to session_log.ts, because
the identity is now STORED here — handoff.ts already imports this module, so
the other direction would be a cycle. handoff.ts re-exports readRepoIdentity
and HandoffRepo is now an alias of RepoIdentity, so a handoff and a library row
cannot describe a repository in two different shapes. No caller changed.
1144 pass / 0 fail / 1 skipped across 132 test files.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
| question | answered from |
|---|---|
| what projects did I work on | manifest.cwd, always recorded |
| which session is running or incomplete | finalStatus + ended; running-vs-interrupted is unknown by design and named |
| which model and brain | recorded |
| which branch / worktree | branch, remote and HEAD now recorded; worktree still unknown — only code.ts knows the isolated directory |
| did verification pass | finalStatus + testCmd + remaining, from the host's verify gate |
| was a PR opened | unknown by construction, printed as such |
| which skills / project instructions | skills now recorded; instructionsDigest still unknown — nothing computes it |
| how much UVT was spent | current session only, from checkUvtCap(), as unknown / observed / not-metered. No per-session UVT is recorded anywhere, so a past session's spend is not shown at all rather than shown as 0 |
| can I continue / export / archive / clean | all four, with the six-state continuability classification |
Three remain unknown and are named as unknown rather than defaulted:
worktree, instructionsDigest, and historical per-session UVT. Each needs a
field set by a file this lane does not own (code.ts) or a meter this lane does
not own (AA-USAGE-06).
Verification
npm run typecheck— clean- 132 test files: 1144 pass / 0 fail / 1 skipped (skip is pre-existing:
symlink creation not permitted on this host) dist/test/session_library.test.js18/18
Not merging this myself.
The charter asks for "an interactive selector for TTY and a stable flat table for pipes". The table existed; this is the other half. ui/session_picker.ts follows the shape logs_viewer.ts already established: a PURE reducer (pickerReduce) that a test drives with no terminal at all, plus a thin driver that owns raw mode, the alternate screen and restoration. Movement clamps rather than wrapping, `/` filters incrementally over the sanitized session id, task, branch and state, Enter chooses, Esc inside a filter restores the previous query without abandoning the picker, and q/Esc/Ctrl+C leave. It is wired as a convenience that can always decline: an empty library, a non-TTY stdin, `--json`, `--no-select`, or any failure inside the picker falls back to the flat listing. That is what makes it safe as the default — the listing is never lost, only sometimes replaced by something better. Choosing a row opens `sessions inspect` for it, so there is one detail screen rather than two that can drift. 35 tests cover the reducer, the scrolling window, and the driver against fake streams — including that ESC/OSC in a task never reaches the screen and that a row with no recorded file count renders "unknown", not 0.
The charter requires local session continuation and portable handoff import to be clearly distinguished. They were not: `continuityHeader` had a `kind` field that nothing ever set to "handoff", and `aether resume` only understood a local session id, so the file form had no screen of its own at all. `aether resume <file.json>` now shows what an imported handoff carries — the same Project Continuity header, then the files the prior run wrote and the steps it took, then the exact command to continue. The branch is chosen by the loader's own rule (isHandoffPath), the same one resolveResume uses, so a value can never fall through both. The two are said differently because they behave differently. A local session is keyed to one absolute directory and carries a transcript to replay. A handoff is keyed to NONE — that is what makes it portable — so handoffEntry leaves the workspace empty and the header renders no continuity state for it at all. "ready" or "elsewhere" would be a confident answer about a checkout the file was never keyed to. Eight tests, including: the two provenance lines are never both claimed, an imported handoff is never given a state it cannot have, a bare session id still takes the local path, a newer schema is refused rather than half-read, and terminal escapes inside a handoff never reach the screen.
A run redirected into a worktree executes somewhere other than where it was launched, and the record said nothing about it. Worse, the repository identity was probed against the LAUNCH directory, so the branch stored for such a run was the branch the user happened to be standing on — not the branch the commits landed on. That is the exact failure this library exists to avoid: a confident wrong answer where "unknown" was available. SessionMeta gains `worktree`, cmdCode passes it when the executing directory differs from the launch directory, and the identity probe now asks the checkout the work ran in. The session stays SCOPED to the launch directory, because that is where the user will be standing when they resume. The code.ts change is one conditional field, kept in the same additive spirit as the CLI wiring commit. Two tests drive SessionLog with an injected probe and assert on the manifest and the index row: the worktree run reports the worktree's branch and path, and a run with no worktree and no checkout reports neither rather than inventing either. COMMANDS.md documents the picker, --no-select, and `aether resume <file.json>`.
`main` replaced main.ts's inline parseArgs literal with CLI_PARSE_OPTIONS and a DISPATCH_COMMANDS lookup. This lane's `sessions` case merges cleanly onto the new structure; the declarations it needs move to GLOBAL_FLAGS in the next commit, which is what #98's declared-flag assertion is asking for. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
#98's declared-flag assertion caught its first real case, and it is not a merge artifact: neither flag was EVER declared, on this lane or before it. main.ts parses with strict:false, so an undeclared `--undo` was captured into `values` and stripped from the positionals sessions.ts re-parses. `aether sessions archive <id> --undo` therefore archived instead of un-archiving and reported success, and `--no-select` — the documented escape hatch out of the TTY picker — never reached the command at all, which left a scripted caller on a TTY with no way out of an interactive selector. Declaring both in GLOBAL_FLAGS is what makes them arrive; `--no-select` is forwarded in the sessions case alongside `--all`/`--undo`, so the read and the declaration stay in step and the assertion covers it from now on. The old parser would have swallowed this silently and shipped it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
main advanced with #98, which replaced main.ts's hand-written switch and its regex-guarded flag table with a dispatch table where a command carries its own help metadata, its own flags and its own loader. This lane's wiring predated it, and the merge exposed exactly the failure that seam was built to end: main.ts parsed with strict:false, so `--all` and `--undo` were captured into `values` and stripped from the positionals the command received. `aether sessions --all` silently listed one project. CI caught it as an undeclared-flag violation. `sessions` is now one entry in DISPATCH_COMMANDS: the registry row, the flags and the handler in one place, reachability structural rather than asserted. The switch case in main.ts is gone. `--all` and `--out` are NOT declared here. They are global — other commands already answer to those spellings — and the table refuses a command that shadows a global, because the merged parseArgs namespace is flat and the shadow would change what the flag means elsewhere. They reach the command on ctx.flags, which now carries them the way it already carried --yes. Adversarial review of the picker/handoff/worktree commits also found two real defects, fixed here: - cmdCode decided "was this run redirected into a worktree?" by comparing the RAW `--cwd` string to the resolved executing path, so `aether agent --cwd .` recorded a worktree for a plain in-place run and `sessions inspect` reported a checkout that did not exist. The comparison is normalized now. - handoffEntry called its file count exact. It is not: summarizeEvents stops adding at MAX_FILES and parseHandoff slices to it again, so a run that wrote 200 files arrives carrying 60. At the bound the count is omitted and renders "unknown" rather than confidently reporting the cap as the total.
Both sides of this branch fixed the same thing and disagreed on where the fix belongs. The other side declared `--undo` and `--no-select` in GLOBAL_FLAGS and kept the `case "sessions"` in main.ts; this side moved the whole command onto the dispatch table #98 introduced. Resolved toward the table, because that is what #98 argued for and what makes the fix structural: the registry row, the flags and the loader are one entry, so the next flag cannot be read without being declared. `--undo` and `--no-select` are `sessions`' OWN flags there — nothing else answers to either spelling, and making them global would hand every command a flag that means nothing to it. `--all` and `--out` stay global, because other commands do answer to those, and reach the command on ctx.flags. The other side's finding stands and is preserved in the comment: neither flag was ever declared, on this lane or before it, so `aether sessions archive <id> --undo` archived instead of un-archiving and said it had restored, and `--no-select` never reached the command at all. Verified end to end on the built binary: `--all` crosses workspaces, and archive/--undo round-trips.
…argv #98's spec is explicit that a dispatched command receives its flags as a typed object and never as tokens re-rendered for a second parse. The sessions entry was rebuilding `["--all"]`, `["--undo"]` and handing them back for the command's own parser to read — an array rather than a shell string, so not a hole today, but exactly the shape the seam exists to remove: a second parse is where a value can be promoted into a flag nobody typed. `cmdSessions` now takes a fourth parameter, `SessionsFlags`. The dispatch entry passes `{all, undo, noSelect, out}` and `argv` carries only the positionals the host already separated out. The argv fallback stays for callers that never went through the CLI parse — the tests, and `aether resume list` — but typed values take PRECEDENCE over tokens, and a test pins that: an argv `--all` loses to `{all: false}`. Without that test the fallback quietly becomes a second parse again the first time someone reorders the function. Raised by the lane that owns the seam; their objection was correct.
Five conflicts, all resolved toward the seam main established: - src/commands/cli_registry.ts — union of dispatch entries. The lane's `sessions` entry (own `flags`: --undo, --no-select; --all/--out read off ctx.flags because they are globals) sits beside main's `review`/`ship` entries. No entry redeclares a global. - src/main.ts — GlobalFlags now carries `all`, `testCmd` (main) and `out` (lane). No inline options literal and no `case "sessions"`: the lane had already moved onto CLI_PARSE_OPTIONS in d1dc8c4/a6c6f7b. - src/core/context.ts — GlobalFlags is the union: all, out, testCmd. - src/core/session_log.ts — both provenance sets kept. #99's manifestBody()/indexSelf() structure survives (the session index is built only from manifestBody), and #100's `context` field is carried into that body alongside the lane's `skills`/`instructionsDigest`: they record different things — what the caller declared, and what the host loop saw. `homedir` dropped from the imports; the lane resolves the log root through logs_root.ts, so main's import had no remaining use. - COMMANDS.md — every command row kept; the CLI registry index is the union (sessions + review + ship). typecheck clean; npm test 1440 tests, 1436 pass, 0 fail, 4 skipped.
|
Merged
Edited beyond the automatic merge: one line only —
No test needed rewriting: the lane already asserts parsed argv through Gates (local, Windows):
|
What this is
Lane AA-CONT-04. The agent already kept durable session records; they were
not operable. Finding one meant knowing an opaque id or browsing
~/.aether-agentby hand, and every "what was I doing here" question cost awalk of every session directory plus a parse of every manifest.
This makes the sessions a first-class screen.
Design
The index is a cache; the manifest is the authority.
core/session_index.tskeeps one small
{schemaVersion, entries}document beside the sessiondirectories. Anything the index cannot answer is answered by rebuilding from
the manifests — never by rendering an empty list. That rule is what makes it
safe to delete, corrupt, or lose. Writes go through the transaction
durable_store.tsalready implements (lock → read → mutate → temp → flush →backup → rename), with the read inside the lock, so two runs closing in the
same second both land. A future-schema index is refused and never overwritten,
and the write path now reports whether it actually persisted, so no caller can
print "archived" for a change that is not on disk.
Nothing on the listing path opens
events.jsonl. That file is thetranscript and
aether resumeis what replays it.Where a session can be continued is computed, not assumed. Six states kept
apart because the remedies differ:
ready,stale-branch,moved,elsewhere,missing,archived. A session that cannot be continued here isrefused with the reason and pointed at
export, which is the form that crossesmachines.
Unknown is never rendered as zero. A count nobody recorded prints
unknown. A run whose manifest never closed prints never finished (running orinterrupted — unknown which), because nothing on this machine can tell those
apart. A branch the record does not name is not assumed to be the branch you
are on.
Nothing here deletes.
archivesets a flag and--undoreverses it.cleanremoves index rows for sessions already gone from disk, after printingevery row and asking. Neither touches a session directory, a worktree, a
branch, or a file a run wrote.
Evidence
npm run typecheck— cleannpm test— 1169 pass / 0 fail / 1 skipped; the skip is pre-existing(
symlink creation not permitted on this host)npm run verify:production—{"ok":true,"packedFiles":536,"packedBytes":2561364}before-renameleaves the previous generationbyte-identical and still readable
archivereports failure rather than success against itmanifest.json/events.jsonlfiles replaced by directories, so opening anyone of them would throw
4 mutants — empty-on-corrupt, future-schema clobber, unconditional field
overwrite,
missing-checkout→other-workspacecollapse — all 4 killed.continue, archive,
resume list,help sessions.Adversarial review by a model that did not write it raised two real defects,
both fixed here:
archivereported success when the index write had beenrefused, and
filesToucheddouble-counted paths differing only by case onWindows (it is also now labelled as what it measures — files written via
write_file).Shape of the commits
feat(sessions)— the library. Only files this lane owns.feat(cli)— the wiring. Four additive edits to shared files(
cli_registry.ts,main.ts,chat.ts,COMMANDS.md). Kept separate sothe merge controller can drop or reorder it without touching the feature —
cli_registry.tsis AA-SKILLS-03's lease andmain.ts/chat.tsare theintegration lane's.
test(sessions)— the cost/honesty tests and theshortRemotefix.Notes for review
main @ ed094dc8885945e69f66e166e854142005bf1d62, verified againstorigin/mainbefore branching.core/logs_root.tsis a new leaf module that exists only sosession_log.tsand
session_index.tsdo not import each other.session_log.tsre-exportslogsRoot, so no existing caller changed.npm run smokereports one failure on this machine —local turn: Ollama model 'qwen2.5-coder:7b' not found (404). Environmental, untouched by thisbranch.
🤖 Generated with Claude Code