feat(core): make path-local instruction discovery durable

Replace synthetic-message instruction injection with a durable
discovery projection so discovered AGENTS.md files survive compaction,
forks, reverts, and restarts.

- Add the instruction_file table and the durable
  session.instructions.discovered event; projection stores each
  discovered path and content with its owning assistant-message
  boundary and durable discovery order.
- Fold discovered files into the core/instructions source through
  InstructionDiscovery, absorbing SessionInstructions. Completed
  compaction rebaselines restate discovered instructions instead of
  summarizing them away.
- Re-read discovered files live at each observation so mid-session
  edits reach the model; the frozen discovery content stands in only
  when a file becomes unreadable.
- Narrate instruction file changes as per-file deltas via diffByKey,
  restating the full set only for pure reorderings.
- Fork copies discoveries within the inherited transcript, committed
  revert removes discoveries past the revert boundary, and Session
  movement clears them so the destination initializes a complete
  baseline.
This commit is contained in:
Kit Langton 2026-07-06 14:22:53 -04:00
commit 0726f09b05
28 changed files with 1166 additions and 598 deletions

View file

@ -140,6 +140,18 @@ export const InstructionsUpdated = Event.durable({
})
export type InstructionsUpdated = typeof InstructionsUpdated.Type
export const InstructionsDiscovered = Event.durable({
type: "session.instructions.discovered",
...options,
schema: {
...Base,
assistantMessageID: SessionMessage.ID,
location: Location.Ref,
files: Schema.Array(Schema.Struct({ path: Schema.String, content: Schema.String })),
},
})
export type InstructionsDiscovered = typeof InstructionsDiscovered.Type
export const Synthetic = Event.durable({
type: "session.synthetic",
...options,
@ -495,6 +507,7 @@ export const Definitions = Event.inventory(
PromptAdmitted,
ExecutionSettled,
InstructionsUpdated,
InstructionsDiscovered,
Synthetic,
Skill.Activated,
Shell.Started,

View file

@ -104,7 +104,7 @@ describe("public event manifest", () => {
"session.forked.1",
"session.prompt.promoted.1",
"session.prompt.admitted.1",
"session.instructions.discovered.1",
"session.instructions.updated.1",
"session.synthetic.1",
"session.skill.activated.1",