From c082f5044eedd2294d72f920d1018e40d73aab33 Mon Sep 17 00:00:00 2001 From: Igor Soarez Date: Fri, 23 Oct 2026 13:20:11 +0300 Subject: restore, step 2: resume agents, retype command lines - the pi extension reports its session file; the daemon keeps it in the pane option @agent_session, and snapshots carry it. restore runs `pi --session ` in the rebuilt pane, one agent every 0.5s, then reports which agents run and which were interrupted mid-turn. - other panes: the command line running in them is typed at the new prompt but not run. exactly as typed with the zsh hook (dingger install zsh: preexec/precmd keep @dingger_cmd), else the foreground program's exact argv from the kernel (KERN_PROCARGS2), shell-quoted. - "at a prompt" is the pane's own shell owning the terminal's foreground process group, not a name check: `sh -c ...` is a running program. - an agent or command that exits keeps its place in snapshots for 60s, so a shutdown that stops programs before tmux still restores them. - typing waits for each new prompt (text typed earlier echoes twice). e2e step 16 covers resume with a session path containing a space, the interrupted report, an agent that exits just before the server dies, a quoted command retyped not run, and the hook's text; dropping the grace period, judging prompts by name, running retyped commands, or not storing the session reference each fail it. the test's fake pi is guarded so a real pi never starts. --- crates/dinggerd/assets/pi/pi-agent-state.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'crates/dinggerd/assets/pi') diff --git a/crates/dinggerd/assets/pi/pi-agent-state.ts b/crates/dinggerd/assets/pi/pi-agent-state.ts index df9e4e2..ff893e7 100644 --- a/crates/dinggerd/assets/pi/pi-agent-state.ts +++ b/crates/dinggerd/assets/pi/pi-agent-state.ts @@ -56,6 +56,19 @@ async function sendRequest(request: unknown): Promise { type AgentState = "working" | "blocked" | "idle"; +// The session file, so `dingger restore` can resume this session with +// `pi --session `. It changes with /new, /resume, and forks. +let sessionFile: string | undefined; + +function updateSessionFile(ctx: any): void { + try { + const file = ctx?.sessionManager?.getSessionFile?.(); + sessionFile = typeof file === "string" && file.length > 0 ? file : undefined; + } catch { + sessionFile = undefined; + } +} + function report(state: AgentState, message?: string): Promise { return sendRequest({ id: `${source}:${Date.now()}:${Math.random().toString(36).slice(2)}`, @@ -67,6 +80,7 @@ function report(state: AgentState, message?: string): Promise { state, message, seq: Date.now() * 1000, + ...(sessionFile ? { agent_session_path: sessionFile } : {}), }, }); } @@ -154,11 +168,13 @@ export default function (pi) { } // A reload can replace this extension mid-run without emitting another agent_start. agentActive = ctx?.isIdle?.() === false; + updateSessionFile(ctx); publishState(true); }); pi.on("agent_start", (_event, ctx) => { agentActive = true; + updateSessionFile(ctx); publishState(); }); -- cgit v1.2.3