@juicesharp/rpiv-todo 2.13.4 → 2.13.5

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/README.md CHANGED
@@ -48,9 +48,10 @@ by status.
48
48
  - **The plan stays on screen.** A panel above the editor shows every task with a
49
49
  status glyph, the label of whatever is in progress, and a `Todos (done/total)`
50
50
  heading — you never have to ask the agent where it is.
51
- - **Tasks survive `/reload` and compaction.** Each tool call carries the full
52
- post-mutation snapshot, and the list is replayed from the session branch. No
53
- disk writes, nothing to lose.
51
+ - **Tasks survive `/reload` and compaction.** Every change records the full
52
+ post-mutation snapshot on the session branch, including changes made from a
53
+ codemode script, and the list is replayed from there. No disk writes, nothing
54
+ to lose.
54
55
  - **Finished work gets out of the way.** Completed rows stay visible for the rest
55
56
  of the turn, then drop at the start of the next one; the panel disappears
56
57
  entirely when the list empties.
package/docs/overlay.md CHANGED
@@ -19,8 +19,9 @@ The widget is mounted above the Pi editor under the key `rpiv-todos`.
19
19
  Task state is partitioned by session id, so parallel sessions cannot read or
20
20
  overwrite each other's lists. Nothing is written to disk: on session start,
21
21
  compaction, and session-tree changes, the list is rebuilt by walking the branch
22
- and taking the last `todo` tool result's snapshot, which replaces the whole list
23
- (last-write-wins).
22
+ and taking the last saved snapshot, which replaces the whole list
23
+ (last-write-wins). See [tool-schema.md](./tool-schema.md#persistence) for where
24
+ snapshots are saved.
24
25
 
25
26
  ## Anatomy of a row
26
27
 
@@ -101,10 +101,22 @@ tasks' `blockedBy` arrays.
101
101
  }
102
102
  ```
103
103
 
104
+ ## Persistence
105
+
104
106
  `details` is the persistence format. Every successful call embeds the complete
105
- post-mutation snapshot, and the session-lifecycle handlers rebuild state by
106
- walking the branch and taking the last snapshot they find — which is why tasks
107
- survive `/reload` and compaction without any disk writes.
107
+ post-mutation snapshot. Every call that changes the list (`create`, `delete`,
108
+ `clear`, or an `update` that changed something) also saves the same `details`
109
+ object as a `rpiv-todo-state` custom entry on the session branch. Custom entries
110
+ are never sent to the model.
111
+
112
+ The custom entry matters when `todo` is called from another tool, such as a Pi
113
+ codemode script: Pi records that call only as a short summary on the outer
114
+ tool's result, so its own `details` never reach the branch.
115
+
116
+ The session-lifecycle handlers rebuild state by walking the branch and taking
117
+ the last `rpiv-todo-state` snapshot. Sessions saved before these entries existed
118
+ fall back to the last `todo` tool result's `details`. Either way, tasks survive
119
+ `/reload`, `/resume`, `/tree` and compaction without any disk writes.
108
120
 
109
121
  ## Content strings
110
122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-todo",
3
- "version": "2.13.4",
3
+ "version": "2.13.5",
4
4
  "description": "Pi extension. A todo list for the model, rendered as a live overlay that survives /reload and conversation compaction.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -70,6 +70,6 @@
70
70
  }
71
71
  },
72
72
  "dependencies": {
73
- "@juicesharp/rpiv-config": "^2.13.4"
73
+ "@juicesharp/rpiv-config": "^2.13.5"
74
74
  }
75
75
  }
package/state/replay.ts CHANGED
@@ -12,27 +12,51 @@ export function isTaskDetails(value: unknown): value is TaskDetails {
12
12
  return Array.isArray(v.tasks) && typeof v.nextId === "number";
13
13
  }
14
14
 
15
+ /** Fresh `TaskState` from a persisted snapshot — copies each task so replay never aliases branch data. */
16
+ function stateOf(details: TaskDetails): TaskState {
17
+ return { tasks: details.tasks.map((t) => ({ ...t })), nextId: details.nextId };
18
+ }
19
+
15
20
  /**
16
- * Walk the current branch in chronological order; the LAST `toolResult` whose
17
- * `toolName === "todo"` and whose `details` shape matches `TaskDetails` wins
18
- * (last-write-wins). When no matching entry exists, returns `EMPTY_STATE`.
21
+ * Walk the current branch in chronological order and return the last persisted
22
+ * snapshot (last-write-wins). Two sources carry the same `TaskDetails` shape:
23
+ *
24
+ * - `custom` entries of type `"rpiv-todo-state"` (mirrors `STATE_ENTRY_TYPE` in
25
+ * `tool/types.ts` — a literal here, like `"todo"`, so `state/` keeps no value
26
+ * import of the Pi-aware tool layer). Written by `todo.ts` for EVERY
27
+ * state-changing call, including calls made through another tool
28
+ * (`ctx.executeTool`, e.g. codemode) that never land as a `toolResult`.
29
+ * - `toolResult` messages with `toolName === "todo"` — the `details` envelope.
30
+ *
31
+ * Once the branch carries any state entry, state entries are authoritative:
32
+ * they are appended at commit time for every change, so a `toolResult`
33
+ * snapshot can only repeat or predate them. Branches with no state entry
34
+ * (sessions written before entries existed) replay from `toolResult` snapshots.
35
+ * When neither exists, returns `EMPTY_STATE`.
19
36
  *
20
37
  * Pure of module state — `index.ts` writes the returned snapshot into the
21
38
  * store after this returns. The function explicitly does NOT touch the store
22
39
  * cell.
23
40
  */
24
41
  export function replayFromBranch(ctx: { sessionManager: { getBranch(): Iterable<unknown> } }): TaskState {
25
- let result: TaskState = { tasks: [...EMPTY_STATE.tasks], nextId: EMPTY_STATE.nextId };
42
+ let fromEntries: TaskState | undefined;
43
+ let fromToolResults: TaskState | undefined;
26
44
  for (const entry of ctx.sessionManager.getBranch()) {
27
- const e = entry as { type?: string; message?: { role?: string; toolName?: string; details?: unknown } };
45
+ const e = entry as {
46
+ type?: string;
47
+ customType?: string;
48
+ data?: unknown;
49
+ message?: { role?: string; toolName?: string; details?: unknown };
50
+ };
51
+ if (e.type === "custom") {
52
+ if (e.customType === "rpiv-todo-state" && isTaskDetails(e.data)) fromEntries = stateOf(e.data);
53
+ continue;
54
+ }
28
55
  if (e.type !== "message") continue;
29
56
  const msg = e.message;
30
57
  if (msg?.role !== "toolResult" || msg.toolName !== "todo") continue;
31
58
  if (!isTaskDetails(msg.details)) continue;
32
- result = {
33
- tasks: msg.details.tasks.map((t) => ({ ...t })),
34
- nextId: msg.details.nextId,
35
- };
59
+ fromToolResults = stateOf(msg.details);
36
60
  }
37
- return result;
61
+ return fromEntries ?? fromToolResults ?? { tasks: [...EMPTY_STATE.tasks], nextId: EMPTY_STATE.nextId };
38
62
  }
@@ -26,6 +26,27 @@ export interface ApplyResult {
26
26
  op: Op;
27
27
  }
28
28
 
29
+ /**
30
+ * True when `op` changed the task state — the calls whose post-commit snapshot
31
+ * must be persisted for replay. Reads (`list`/`get`), failures, and a no-effect
32
+ * `update` leave state untouched. Exhaustive over `Op` (compiler-enforced), so a
33
+ * new action must decide here whether it persists.
34
+ */
35
+ export function changesState(op: Op): boolean {
36
+ switch (op.kind) {
37
+ case "create":
38
+ case "delete":
39
+ case "clear":
40
+ return true;
41
+ case "update":
42
+ return op.changed;
43
+ case "list":
44
+ case "get":
45
+ case "error":
46
+ return false;
47
+ }
48
+ }
49
+
29
50
  function errorResult(state: TaskState, message: string): ApplyResult {
30
51
  return { state, op: { kind: "error", message } };
31
52
  }
package/todo.ts CHANGED
@@ -16,13 +16,14 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
16
16
  import { loadConfig, validateGuidanceFields } from "./config.js";
17
17
  import { formatStatusLabel, t } from "./state/i18n-bridge.js";
18
18
  import { selectTasksByStatus, selectTodoCounts, selectVisibleTasks } from "./state/selectors.js";
19
- import { applyTaskMutation } from "./state/state-reducer.js";
19
+ import { applyTaskMutation, changesState } from "./state/state-reducer.js";
20
20
  import { commitState, getRenderState, getState, sid } from "./state/store.js";
21
21
  import { buildToolResult } from "./tool/response-envelope.js";
22
22
  import {
23
23
  COMMAND_NAME,
24
24
  ERR_REQUIRES_INTERACTIVE,
25
25
  MSG_NO_TODOS,
26
+ STATE_ENTRY_TYPE,
26
27
  type TaskMutationParams,
27
28
  TOOL_LABEL,
28
29
  TOOL_NAME,
@@ -78,7 +79,13 @@ export function registerTodoTool(pi: ExtensionAPI): void {
78
79
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
79
80
  const result = applyTaskMutation(getState(sid(ctx)), params.action, params as TaskMutationParams);
80
81
  commitState(sid(ctx), result.state);
81
- return buildToolResult(params.action, params as TaskMutationParams, result.state, result.op);
82
+ const toolResult = buildToolResult(params.action, params as TaskMutationParams, result.state, result.op);
83
+ // Persist the snapshot as a custom entry on the calling session's branch, however the
84
+ // tool was reached: a call made through another tool (`ctx.executeTool`, e.g. codemode)
85
+ // never lands as a standalone `toolResult`, so its `details` alone would not survive
86
+ // replay. Pi's own codemode persists its `store()` the same way.
87
+ if (changesState(result.op)) pi.appendEntry(STATE_ENTRY_TYPE, toolResult.details);
88
+ return toolResult;
82
89
  },
83
90
 
84
91
  // renderCall reflects the FOREGROUND slot, not the calling session's. Pi's
package/tool/types.ts CHANGED
@@ -12,6 +12,15 @@ export const TOOL_NAME = "todo";
12
12
  export const TOOL_LABEL = "Todo";
13
13
  export const COMMAND_NAME = "todos";
14
14
 
15
+ /**
16
+ * Custom session-entry type carrying the `details` snapshot of every
17
+ * state-changing `todo` call — the replay source that survives calls made
18
+ * through another tool (`ctx.executeTool`, e.g. Pi's codemode), whose results
19
+ * never land on the branch as standalone `toolResult` messages. Persistence key
20
+ * for branch replay, like `TOOL_NAME`. DO NOT rename.
21
+ */
22
+ export const STATE_ENTRY_TYPE = "rpiv-todo-state";
23
+
15
24
  // ---------------------------------------------------------------------------
16
25
  // User-facing strings (kept stable for /todos UX parity).
17
26
  // ---------------------------------------------------------------------------