pi-mono/apps/p2/plugins/locations/contract.worker.ts
David Brailovsky e885255061 feat(p2): /tree, branches of the main conversation as Durable forks
Each branch is a top-level conversation forked from another at an entry;
the session-scoped p2.main document lists them and names the current one.
Earlier branches are read-only. The main agent's per-agent state
(subagents, artifacts, voice and chat mode, pending move) stays on
conversation 1 for every branch.

- tree plugin: SessionTree (tree, navigate, select); the worker reports
  main and branches to the catalog (Sessions v4, catalog schema 4)
- TUI: /tree and double Escape (pi's default "tree"), a tree selector
  adapted from coding-agent
- web: Edit on user messages, Branch from here on answers, branch rows
  under the session in the sidebar
- main-agent checks use the branch list instead of conversation 1
- search indexes each branch's own entries

Design: apps/p2/docs/tree.md
2026-11-04 13:40:36 +01:00

20 lines
881 B
TypeScript

// Worker-side contracts of the location tools: the Durable document other worker plugins read (the workspace reopens
// its backend when a pending move lands).
import { defineDoc } from "@earendil-works/pi-durable";
import type { Location } from "@p2/app/v1";
/**
* The main agent's move, waiting for its turn to end (the worker applies it, `worker.ts`), and the last one that
* failed. Kept on conversation 1 for the session, whichever top-level conversation (the main one or a `/tree` branch)
* asked for it.
*/
export type LocationMoveState = { pending?: Location; failed?: { to: Location; error: string } };
export const LocationMoveDoc = defineDoc<LocationMoveState>({
kind: "p2.location-move",
version: 1,
scope: "conversation",
history: "latest",
fork: "initial",
initial: () => ({}),
checkpointWhen: (_v, _o, { deltasSinceBase }) => deltasSinceBase >= 64,
});