pi-todo-ledger 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRACT.md +25 -0
- package/README.md +5 -1
- package/package.json +1 -1
- package/src/index.ts +6 -2
- package/src/ledger/finish-call.ts +46 -0
- package/src/ledger/herdr-owner.ts +74 -0
- package/src/state/store.ts +16 -4
- package/src/todo.ts +6 -51
package/CONTRACT.md
CHANGED
|
@@ -152,6 +152,31 @@ Error: metadata.<ns> refused #<id>: <reason>
|
|
|
152
152
|
`clear`, `list`, and `get` run no validators.
|
|
153
153
|
Namespaces nobody registered pass unchecked.
|
|
154
154
|
|
|
155
|
+
### Optional Herdr launch identity (`metadata.herdr`)
|
|
156
|
+
|
|
157
|
+
When `pi-herdr-agents` acknowledges a `subagent` launch with `details.status: "started"` and echoes the call's `item`, the ledger looks up that task in the **calling session**.
|
|
158
|
+
`item` can be a stable task uid or `<session8>#<id>`, where `session8` is the first eight hex digits of the calling session id.
|
|
159
|
+
A numeric reference identifies the task present at dispatch: ordinary updates keep that identity even on a legacy task without a uid, while clearing or replaying the list invalidates a pending legacy binding.
|
|
160
|
+
Missing, unknown, foreign-session, or tombstoned items and failed or uncertain launches leave the list unchanged.
|
|
161
|
+
|
|
162
|
+
A match issues a normal guarded `update`: `owner` becomes the full `details.name`, and `metadata.herdr` records the launch:
|
|
163
|
+
|
|
164
|
+
```json
|
|
165
|
+
{ "name": "api-worker", "id": "0accb6d1-4380-4d51-a6d7-81dd0408d82f", "pane": "w1:p4" }
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`name` is verbatim; `id` is the child **run id** (`details.id`), not the parent's session id or a path-derived id.
|
|
169
|
+
`pane` is the acknowledged `details.worktree.paneId` and is absent for ordinary launches.
|
|
170
|
+
On another successful assignment the new record replaces the old one, so an old pane id does not carry forward.
|
|
171
|
+
Other metadata stays intact; a refusal leaves the launch successful but adds the reason to its response.
|
|
172
|
+
Manual `owner` updates (including `self`) are still allowed; the optional `herdr` record describes the last bound launch, not proof of a live pane or of the current owner's identity.
|
|
173
|
+
|
|
174
|
+
Use `metadata.herdr.id` as the stable key when resolving or messaging the worker.
|
|
175
|
+
Use a name with `/boss send` only when it matches the name Straw Boss shows; on an unlabeled pane it may derive `api-worker` from the launch script for `API worker`.
|
|
176
|
+
For names longer than 24 UTF-16 units, Straw Boss displays just the first 23 units plus `…` in the `sb_name` pane token.
|
|
177
|
+
Resolve the live pane at read time rather than targeting that cosmetic label or a saved pane id.
|
|
178
|
+
This namespace needs no new status, schema field, or contract version.
|
|
179
|
+
|
|
155
180
|
## 4. Change guards
|
|
156
181
|
|
|
157
182
|
A namespace validator judges one task's value.
|
package/README.md
CHANGED
|
@@ -43,7 +43,11 @@ The new fields are optional parameters of `create` (and of each `tasks[]` item)
|
|
|
43
43
|
`get` shows all three fields.
|
|
44
44
|
|
|
45
45
|
`create`, `update`, `get`, and `list` print each task's stable `uid` if it has one (for example, `t_k7wrx2jzfq`).
|
|
46
|
-
Pass that value as a subagent's `item
|
|
46
|
+
Pass that value as a Herdr `subagent`'s `item` (or use `<session8>#<id>` from the same session).
|
|
47
|
+
Once the launch is acknowledged, the ledger sets `owner` to the child's full name and records its run id in [`metadata.herdr`](CONTRACT.md#optional-herdr-launch-identity-metadataherdr).
|
|
48
|
+
Use `metadata.herdr.id` to resolve or message the worker by its run key.
|
|
49
|
+
Use a name with `/boss send` only if it matches the name Straw Boss shows; a launch named `API worker` may appear there as `api-worker`.
|
|
50
|
+
You can still set `owner` by hand.
|
|
47
51
|
|
|
48
52
|
The panel and `/todos` indent each open task under its first unfinished blocker and show its owner as `@owner`.
|
|
49
53
|
To mark a task as waiting for someone, set `metadata.waitsOn` to their name; to defer it until a particular time, set `metadata.until` to an ISO timestamp, e.g. `2027-01-15T09:00:00+08:00`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-todo-ledger",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A todo list for pi agents with a public bookkeeping contract: snapshot entries, change events, and namespace validators. Fork of @juicesharp/rpiv-todo",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/index.ts
CHANGED
|
@@ -33,7 +33,9 @@ import {
|
|
|
33
33
|
READY_EVENT,
|
|
34
34
|
toChangedEvent,
|
|
35
35
|
} from "./ledger/contract.ts";
|
|
36
|
+
import { makeFinishCall } from "./ledger/finish-call.ts";
|
|
36
37
|
import { GuardRegistry } from "./ledger/guards.ts";
|
|
38
|
+
import { registerHerdrOwner } from "./ledger/herdr-owner.ts";
|
|
37
39
|
import { NamespaceRegistry } from "./ledger/namespaces.ts";
|
|
38
40
|
import { I18N_NAMESPACE } from "./state/i18n-bridge.ts";
|
|
39
41
|
import { replayFromBranch } from "./state/replay.ts";
|
|
@@ -186,7 +188,9 @@ export default function (
|
|
|
186
188
|
if (ignored) console.warn(`[pi-todo-ledger] ignored ${ignored}`);
|
|
187
189
|
});
|
|
188
190
|
|
|
189
|
-
|
|
191
|
+
const finish = makeFinishCall(pi, namespaces, guards);
|
|
192
|
+
registerTodoTool(pi, finish);
|
|
193
|
+
registerHerdrOwner(pi, finish);
|
|
190
194
|
registerTodosCommand(pi);
|
|
191
195
|
pi.events.emit(READY_EVENT, { v: CONTRACT_VERSION });
|
|
192
196
|
|
|
@@ -308,7 +312,7 @@ export default function (
|
|
|
308
312
|
// Reads getTodos() at render time; do NOT call replayFromBranch here
|
|
309
313
|
// (branch is stale — message_end runs after tool_execution_end).
|
|
310
314
|
pi.on("tool_execution_end", async (event) => {
|
|
311
|
-
if (event.toolName !== TOOL_NAME || event.isError) return;
|
|
315
|
+
if ((event.toolName !== TOOL_NAME && event.toolName !== "subagent") || event.isError) return;
|
|
312
316
|
try {
|
|
313
317
|
await updateTodoOverlay();
|
|
314
318
|
} catch (e) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { changesState, type ApplyResult } from "../state/state-reducer.ts";
|
|
3
|
+
import type { TaskState } from "../state/state.ts";
|
|
4
|
+
import { commitState, replaceState } from "../state/store.ts";
|
|
5
|
+
import { buildToolResult } from "../tool/response-envelope.ts";
|
|
6
|
+
import type { TaskAction, TaskMutationParams } from "../tool/types.ts";
|
|
7
|
+
import { CHANGED_EVENT, type GuardOp, SNAPSHOT_ENTRY_TYPE, toChangedEvent, toSnapshot } from "./contract.ts";
|
|
8
|
+
import type { GuardRegistry } from "./guards.ts";
|
|
9
|
+
import { changedTasks, type NamespaceRegistry } from "./namespaces.ts";
|
|
10
|
+
|
|
11
|
+
export const ABORTED = "call aborted; nothing changed";
|
|
12
|
+
|
|
13
|
+
export function refuse(action: TaskAction, input: TaskMutationParams, state: TaskState, message: string) {
|
|
14
|
+
return { ...buildToolResult(action, input, state, { kind: "error", message }), isError: true };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Shared commit boundary for tool calls and acknowledged Herdr launches. Caller holds the session lock. */
|
|
18
|
+
export function makeFinishCall(pi: ExtensionAPI, namespaces: NamespaceRegistry, guards: GuardRegistry) {
|
|
19
|
+
return async (sessionId: string, cwd: string, action: TaskAction, input: TaskMutationParams, before: TaskState, result: ApplyResult, signal?: AbortSignal) => {
|
|
20
|
+
const guardChange = {
|
|
21
|
+
op: action === "import" ? "create" as const : action as GuardOp,
|
|
22
|
+
params: input, before: before.tasks, after: result.state.tasks, sessionId, cwd,
|
|
23
|
+
};
|
|
24
|
+
if (!changesState(result.op)) {
|
|
25
|
+
// A valid no-op update reaches guards, but writes no entry and emits no event.
|
|
26
|
+
if (result.op.kind === "update") {
|
|
27
|
+
const refusal = await guards.check({ ...guardChange, noop: true });
|
|
28
|
+
if (refusal) return refuse(action, input, before, refusal);
|
|
29
|
+
if (signal?.aborted) return refuse(action, input, before, ABORTED);
|
|
30
|
+
}
|
|
31
|
+
commitState(sessionId, result.state);
|
|
32
|
+
return buildToolResult(action, input, result.state, result.op);
|
|
33
|
+
}
|
|
34
|
+
const refusal = namespaces.check(changedTasks(result.op, input, result.state)) ?? (await guards.check(guardChange));
|
|
35
|
+
if (refusal) return refuse(action, input, before, refusal);
|
|
36
|
+
if (signal?.aborted) return refuse(action, input, before, ABORTED);
|
|
37
|
+
// Append before committing the live slot; even nested tool calls survive replay, and a failed append changes nothing.
|
|
38
|
+
pi.appendEntry(SNAPSHOT_ENTRY_TYPE, toSnapshot(result.state, sessionId));
|
|
39
|
+
if (action === "clear") replaceState(sessionId, result.state);
|
|
40
|
+
else commitState(sessionId, result.state);
|
|
41
|
+
pi.events.emit(CHANGED_EVENT, toChangedEvent(sessionId, result.state));
|
|
42
|
+
return buildToolResult(action, input, result.state, result.op);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type FinishCall = ReturnType<typeof makeFinishCall>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { withSessionLock } from "../state/session-lock.ts";
|
|
3
|
+
import { applyTaskMutation } from "../state/state-reducer.ts";
|
|
4
|
+
import { getState, listGeneration, sid } from "../state/store.ts";
|
|
5
|
+
import { sanitizeTerminalText } from "../tool/sanitize.ts";
|
|
6
|
+
import type { FinishCall } from "./finish-call.ts";
|
|
7
|
+
import { runningGuard } from "./guards.ts";
|
|
8
|
+
|
|
9
|
+
const uid = /^t_[a-z2-7]{10}$/;
|
|
10
|
+
const local = /^([a-f0-9]{8})#([1-9]\d*)$/i;
|
|
11
|
+
const record = (x: unknown): x is Record<string, unknown> => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
12
|
+
const nonblank = (x: unknown): x is string => typeof x === "string" && x.trim().length > 0;
|
|
13
|
+
|
|
14
|
+
interface LaunchTarget { item: string; id: number; uid?: string; generation: symbol }
|
|
15
|
+
|
|
16
|
+
/** Per-load observer. A returned name is data, not a shell argument or a pane lookup. */
|
|
17
|
+
export function registerHerdrOwner(pi: ExtensionAPI, finish: FinishCall) {
|
|
18
|
+
// A numeric id can be reused by clear or a branch switch before Herdr acknowledges the launch.
|
|
19
|
+
// Pin the list generation for a legacy task; ordinary updates replace task objects but retain this identity.
|
|
20
|
+
const pending = new Map<string, Map<string, LaunchTarget>>();
|
|
21
|
+
pi.on("tool_call", (event, ctx) => {
|
|
22
|
+
if (event.toolName !== "subagent" || typeof event.input.item !== "string") return;
|
|
23
|
+
const item = event.input.item;
|
|
24
|
+
const match = local.exec(item);
|
|
25
|
+
if (!match) return;
|
|
26
|
+
const session = sid(ctx);
|
|
27
|
+
if (session.slice(0, 8).toLowerCase() !== match[1].toLowerCase()) return;
|
|
28
|
+
const task = getState(session).tasks.find(t => t.id === Number(match[2]) && t.status !== "deleted");
|
|
29
|
+
const generation = listGeneration(session);
|
|
30
|
+
if (!task || !generation) return;
|
|
31
|
+
const calls = pending.get(session) ?? new Map<string, LaunchTarget>();
|
|
32
|
+
calls.set(event.toolCallId, { item, id: task.id, uid: task.uid, generation });
|
|
33
|
+
pending.set(session, calls);
|
|
34
|
+
});
|
|
35
|
+
// A blocked call need not produce a result. Drop any leftover captures at the turn boundary.
|
|
36
|
+
pi.on("agent_end", (_event, ctx) => { pending.delete(sid(ctx)); });
|
|
37
|
+
pi.on("tool_result", async (event, ctx) => {
|
|
38
|
+
if (event.toolName !== "subagent") return;
|
|
39
|
+
const session = sid(ctx);
|
|
40
|
+
const calls = pending.get(session);
|
|
41
|
+
const capture = calls?.get(event.toolCallId);
|
|
42
|
+
calls?.delete(event.toolCallId);
|
|
43
|
+
if (!calls?.size) pending.delete(session);
|
|
44
|
+
const d = event.details;
|
|
45
|
+
if (event.isError || !record(d) || d.status !== "started" || !nonblank(d.name) || !nonblank(d.id)) return;
|
|
46
|
+
const item = d.item;
|
|
47
|
+
if (typeof item !== "string" || item !== event.input.item) return;
|
|
48
|
+
const pinned = capture?.item === item ? capture : undefined;
|
|
49
|
+
if (!pinned && !uid.test(item)) return;
|
|
50
|
+
const pane = record(d.worktree) ? d.worktree.paneId : undefined;
|
|
51
|
+
const herdr = { name: d.name, id: d.id, ...(nonblank(pane) ? { pane } : {}) };
|
|
52
|
+
const warn = (why: string) => ({
|
|
53
|
+
content: [...event.content, { type: "text" as const, text: `Todo owner binding: ${sanitizeTerminalText(why)}` }],
|
|
54
|
+
structuredContent: event.structuredContent,
|
|
55
|
+
});
|
|
56
|
+
if (runningGuard(session)) return warn("cannot update the list from its own change guard");
|
|
57
|
+
try {
|
|
58
|
+
return await withSessionLock(session, async () => {
|
|
59
|
+
const before = getState(session);
|
|
60
|
+
if (pinned && !pinned.uid && listGeneration(session) !== pinned.generation) return;
|
|
61
|
+
const task = pinned && !pinned.uid
|
|
62
|
+
? before.tasks.find(t => t.id === pinned.id && !t.uid)
|
|
63
|
+
: before.tasks.find(t => t.uid === (pinned?.uid ?? item));
|
|
64
|
+
if (!task || task.status === "deleted") return;
|
|
65
|
+
const params = { action: "update", id: task.id, owner: herdr.name, metadata: { herdr } };
|
|
66
|
+
const result = await finish(session, ctx.cwd, "update", params, before, applyTaskMutation(before, "update", params));
|
|
67
|
+
if (result.details.error) return warn(result.details.error);
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
// Herdr already launched the child. Don't turn a persistence error into a failed launch/retry.
|
|
71
|
+
return warn(error instanceof Error ? error.message : String(error));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
package/src/state/store.ts
CHANGED
|
@@ -8,7 +8,12 @@ import { EMPTY_STATE, type TaskState } from "./state.ts";
|
|
|
8
8
|
* The Map is the single mutation seam — only `commitState` / `replaceState` /
|
|
9
9
|
* `evictSession` write it; the reducer (`state/state-reducer.ts`) stays pure.
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
interface SessionSlot {
|
|
12
|
+
state: TaskState;
|
|
13
|
+
/** In-process identity of the list, not the session. Never serialized. */
|
|
14
|
+
generation: symbol;
|
|
15
|
+
}
|
|
16
|
+
const sessions = new Map<string, SessionSlot>();
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
19
|
* Ctx-less render pointer: which slot do the ctx-free readers (the overlay's
|
|
@@ -37,7 +42,7 @@ function freshState(): TaskState {
|
|
|
37
42
|
/** Get-or-read a session's slot: the committed slot by identity, or a fresh
|
|
38
43
|
* EMPTY_STATE copy (not stored) when the slot is absent. */
|
|
39
44
|
function slotFor(sessionId: string): TaskState {
|
|
40
|
-
return sessions.get(sessionId) ?? freshState();
|
|
45
|
+
return sessions.get(sessionId)?.state ?? freshState();
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
/**
|
|
@@ -64,7 +69,12 @@ export function getState(sessionId: string): TaskState {
|
|
|
64
69
|
* `replayFromBranch` decodes the latest snapshot, keyed to the session.
|
|
65
70
|
*/
|
|
66
71
|
export function replaceState(sessionId: string, next: TaskState): void {
|
|
67
|
-
sessions.set(sessionId, next);
|
|
72
|
+
sessions.set(sessionId, { state: next, generation: Symbol() });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Together with the local id, identifies a legacy task until clear, replay, or eviction. */
|
|
76
|
+
export function listGeneration(sessionId: string): symbol | undefined {
|
|
77
|
+
return sessions.get(sessionId)?.generation;
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
/**
|
|
@@ -73,7 +83,9 @@ export function replaceState(sessionId: string, next: TaskState): void {
|
|
|
73
83
|
* `/todos`, `renderCall`), keyed to the calling session.
|
|
74
84
|
*/
|
|
75
85
|
export function commitState(sessionId: string, next: TaskState): void {
|
|
76
|
-
sessions.
|
|
86
|
+
const slot = sessions.get(sessionId);
|
|
87
|
+
if (slot) slot.state = next;
|
|
88
|
+
else replaceState(sessionId, next);
|
|
77
89
|
}
|
|
78
90
|
|
|
79
91
|
/** Drop a session's slot on `session_shutdown`. No-op if the slot is absent. */
|
package/src/todo.ts
CHANGED
|
@@ -14,18 +14,15 @@
|
|
|
14
14
|
|
|
15
15
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
16
16
|
import { loadConfig, validateGuidanceFields } from "./config.ts";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { ABORTED, type FinishCall, refuse } from "./ledger/finish-call.ts";
|
|
18
|
+
import { runningGuard } from "./ledger/guards.ts";
|
|
19
19
|
import { readImport } from "./ledger/import-snapshot.ts";
|
|
20
|
-
import { changedTasks, type NamespaceRegistry } from "./ledger/namespaces.ts";
|
|
21
20
|
import { formatStatusLabel, t } from "./state/i18n-bridge.ts";
|
|
22
21
|
import { selectTasksByStatus, selectTodoCounts, selectVisibleTasks } from "./state/selectors.ts";
|
|
23
|
-
import { applyTaskMutation, type ApplyResult
|
|
22
|
+
import { applyTaskMutation, type ApplyResult } from "./state/state-reducer.ts";
|
|
24
23
|
import { withSessionLock } from "./state/session-lock.ts";
|
|
25
|
-
import
|
|
26
|
-
import { commitState, getRenderState, getState, sid } from "./state/store.ts";
|
|
24
|
+
import { getRenderState, getState, sid } from "./state/store.ts";
|
|
27
25
|
import { prepareTodoArguments } from "./tool/normalize-params.ts";
|
|
28
|
-
import { buildToolResult } from "./tool/response-envelope.ts";
|
|
29
26
|
import {
|
|
30
27
|
COMMAND_NAME,
|
|
31
28
|
ERR_REQUIRES_INTERACTIVE,
|
|
@@ -74,14 +71,7 @@ export const DEFAULT_PROMPT_GUIDELINES: string[] = [
|
|
|
74
71
|
"Optional bookkeeping fields: points (effort, 0 to 10), anchor (the check that shows the task is done, e.g. a test command), and evidence (runs of checks, each {command, sha?, result: pass|fail, at?}). On update, points and anchor replace; evidence is appended, never replaced.",
|
|
75
72
|
];
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
/** An `isError` result for a refused call; the list is reported as it was. */
|
|
80
|
-
function refuse(action: TaskAction, input: TaskMutationParams, state: TaskState, message: string) {
|
|
81
|
-
return { ...buildToolResult(action, input, state, { kind: "error", message }), isError: true };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function registerTodoTool(pi: ExtensionAPI, namespaces: NamespaceRegistry, guards: GuardRegistry): void {
|
|
74
|
+
export function registerTodoTool(pi: ExtensionAPI, finish: FinishCall): void {
|
|
85
75
|
const guidance = validateGuidanceFields(loadConfig().guidance);
|
|
86
76
|
pi.registerTool({
|
|
87
77
|
name: TOOL_NAME,
|
|
@@ -119,42 +109,7 @@ export function registerTodoTool(pi: ExtensionAPI, namespaces: NamespaceRegistry
|
|
|
119
109
|
} else {
|
|
120
110
|
result = applyTaskMutation(before, action, input);
|
|
121
111
|
}
|
|
122
|
-
|
|
123
|
-
op: action === "import" ? "create" as const : action as GuardOp,
|
|
124
|
-
params: input as Record<string, unknown>,
|
|
125
|
-
before: before.tasks,
|
|
126
|
-
after: result.state.tasks,
|
|
127
|
-
sessionId,
|
|
128
|
-
cwd: ctx.cwd,
|
|
129
|
-
};
|
|
130
|
-
if (!changesState(result.op)) {
|
|
131
|
-
// A valid update that changes nothing still reaches the guards (flagged `noop`):
|
|
132
|
-
// re-asserting a status is how an agent reports it after a reload, and guards may
|
|
133
|
-
// track it. It writes no snapshot and emits no event.
|
|
134
|
-
if (result.op.kind === "update") {
|
|
135
|
-
const refusal = await guards.check({ ...guardChange, noop: true });
|
|
136
|
-
if (refusal) return refuse(action, input, before, refusal);
|
|
137
|
-
if (signal?.aborted) return refuse(action, input, before, ABORTED);
|
|
138
|
-
}
|
|
139
|
-
commitState(sessionId, result.state);
|
|
140
|
-
return buildToolResult(action, input, result.state, result.op);
|
|
141
|
-
}
|
|
142
|
-
// Namespace owners, then change guards, see the change before it commits; a refusal
|
|
143
|
-
// leaves state untouched.
|
|
144
|
-
const refusal =
|
|
145
|
-
namespaces.check(changedTasks(result.op, input, result.state)) ?? (await guards.check(guardChange));
|
|
146
|
-
if (refusal) return refuse(action, input, before, refusal);
|
|
147
|
-
if (signal?.aborted) return refuse(action, input, before, ABORTED);
|
|
148
|
-
// Persist the snapshot as a custom entry on the calling session's branch, however the
|
|
149
|
-
// tool was reached: a call made through another tool (`ctx.executeTool`, e.g. codemode)
|
|
150
|
-
// never lands as a standalone `toolResult`, so its `details` alone would not survive
|
|
151
|
-
// replay. Pi's own codemode persists its `store()` the same way.
|
|
152
|
-
// The entry is written before the live state commits: if appending throws, the call
|
|
153
|
-
// fails with the list unchanged, so live state never runs ahead of the branch.
|
|
154
|
-
pi.appendEntry(SNAPSHOT_ENTRY_TYPE, toSnapshot(result.state, sessionId));
|
|
155
|
-
commitState(sessionId, result.state);
|
|
156
|
-
pi.events.emit(CHANGED_EVENT, toChangedEvent(sessionId, result.state));
|
|
157
|
-
return buildToolResult(action, input, result.state, result.op);
|
|
112
|
+
return finish(sessionId, ctx.cwd, action, input, before, result, signal);
|
|
158
113
|
});
|
|
159
114
|
},
|
|
160
115
|
|