@ian-pascoe/pi-todo 0.2.0 → 0.3.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/README.md +3 -3
- package/package.json +2 -2
- package/src/todo-context.ts +18 -17
package/README.md
CHANGED
|
@@ -35,9 +35,9 @@ A Pi `codemode` script receives the result as an object (the tool declares an `o
|
|
|
35
35
|
|
|
36
36
|
Task status is `pending`, `active`, or `completed`; `add` defaults to `pending`. Tasks are flat, duplicate titles are allowed, and multiple Tasks may be active. Set `description` to `null` during `update` to remove it.
|
|
37
37
|
|
|
38
|
-
Each
|
|
38
|
+
Each tool group that changes the Todo List is projected from the immutable session state entries as one hidden full **Todo List Snapshot** of the group's final state, at a fixed conversation position after all of the group's sibling results. A tool group is one assistant turn's tool calls, including several `todo` calls inside one `codemode` script, so ten calls in a script add one Todo List Snapshot, not ten. A group that ends in the state it began with adds none. A change made outside a tool group, such as `/todo clear`, still projects its own Todo List Snapshot right away. Each Todo List Snapshot starts with the header `Todo List state from the pi-todo extension (not a user message):` so it does not read like user input. Later requests keep earlier Todo List Snapshots in place. Clearing the list produces an explicit empty Todo List Snapshot. The system prompt and tool description do not change.
|
|
39
39
|
|
|
40
|
-
After compaction, a fixed baseline immediately after the summary restores the state from before the retained Tail. Retained and newer
|
|
40
|
+
After compaction, a fixed baseline immediately after the summary restores the state from before the retained Tail. Retained and newer tool groups follow chronologically. This preserves previously written conversation cache prefixes between checkpoints; it does not guarantee provider cache hits.
|
|
41
41
|
|
|
42
42
|
`todo` declares MCP-style `annotations`: not read-only, but non-destructive (it only appends to the session's own journal), not idempotent, and closed-world. Pi reports them through `pi.getAllTools()` for permission extensions and does not send them to model providers.
|
|
43
43
|
|
|
@@ -49,6 +49,6 @@ State is stored only in `pi-todo-state` session entries, without a second messag
|
|
|
49
49
|
|
|
50
50
|
A failed journal write leaves acknowledged Todo state unchanged and disables Todo in that loaded session, including across `/reload`. Pi has an existing persistence limitation: subsequent entries can reference the unwritten entry, so reopening may omit earlier history from the selected branch even though it remains in the file. Todo does not repair session history; recovery is outside this cache-prefix change.
|
|
51
51
|
|
|
52
|
-
Missing or ambiguous conversation anchors abort the request instead of silently relocating
|
|
52
|
+
Missing or ambiguous conversation anchors abort the request instead of silently relocating Todo List Snapshots. Extensions that rewrite those anchors are unsupported.
|
|
53
53
|
|
|
54
54
|
This is privileged extension code: review it before installing it into an agent that can access local files, tools, or credentials.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ian-pascoe/pi-todo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Minimal session-native Todo List for Pi agents.",
|
|
6
6
|
"keywords": [
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
]
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
|
-
"test": "vitest run
|
|
53
|
+
"test": "vitest run",
|
|
54
54
|
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/todo-context.ts
CHANGED
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
} from "./todo-list.js";
|
|
15
15
|
|
|
16
16
|
type Message = ContextEvent["messages"][number];
|
|
17
|
+
/** Marks a snapshot as extension state so the model does not read it as user-authored. */
|
|
18
|
+
const SNAPSHOT_HEADER = "Todo List state from the pi-todo extension (not a user message):";
|
|
17
19
|
const ProjectionDetails = Type.Object(
|
|
18
20
|
{
|
|
19
21
|
version: Type.Literal(1),
|
|
@@ -50,7 +52,7 @@ function snapshotMessage(
|
|
|
50
52
|
role: "custom",
|
|
51
53
|
customType: "pi-todo-context",
|
|
52
54
|
display: false,
|
|
53
|
-
content:
|
|
55
|
+
content: `${SNAPSHOT_HEADER}\n${formatTodoList(state.tasks)}`,
|
|
54
56
|
timestamp: Date.parse(entry.timestamp),
|
|
55
57
|
details: { version: 1, stateEntryId: entry.id, checkpointId },
|
|
56
58
|
};
|
|
@@ -110,27 +112,26 @@ export function projectTodoContext(
|
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
const outstanding = new Map<string, number>();
|
|
113
|
-
|
|
115
|
+
// A tool group projects only its final state, once its last result has landed.
|
|
116
|
+
let pending: { entry: SessionEntry; state: TodoStateSnapshot } | undefined;
|
|
117
|
+
const project = (entry: SessionEntry, state: TodoStateSnapshot): void => {
|
|
118
|
+
const content = formatTodoList(state.tasks);
|
|
119
|
+
if (content !== previousContent && (previousContent !== undefined || state.tasks.length > 0))
|
|
120
|
+
insert(snapshotMessage(entry, state, null));
|
|
121
|
+
previousContent = content;
|
|
122
|
+
};
|
|
114
123
|
for (const entry of branch.slice(start)) {
|
|
115
124
|
if (entry === checkpoint) continue;
|
|
116
125
|
const state = todoStateFromEntry(entry);
|
|
117
126
|
if (state) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
content !== previousContent &&
|
|
121
|
-
(previousContent !== undefined || state.tasks.length > 0)
|
|
122
|
-
) {
|
|
123
|
-
const snapshot = snapshotMessage(entry, state, null);
|
|
124
|
-
if (outstanding.size > 0) pending.push(snapshot);
|
|
125
|
-
else insert(snapshot);
|
|
126
|
-
}
|
|
127
|
-
previousContent = content;
|
|
127
|
+
if (outstanding.size > 0) pending = { entry, state };
|
|
128
|
+
else project(entry, state);
|
|
128
129
|
continue;
|
|
129
130
|
}
|
|
130
131
|
const message = conversationMessage(entry);
|
|
131
132
|
if (!message) continue;
|
|
132
133
|
if (message.role === "assistant") {
|
|
133
|
-
if (outstanding.size > 0 && pending
|
|
134
|
+
if (outstanding.size > 0 && pending)
|
|
134
135
|
throw new Error("Todo mutation has an incomplete tool group");
|
|
135
136
|
outstanding.clear();
|
|
136
137
|
for (const block of message.content)
|
|
@@ -142,12 +143,12 @@ export function projectTodoContext(
|
|
|
142
143
|
else outstanding.delete(message.toolCallId);
|
|
143
144
|
}
|
|
144
145
|
anchor = message;
|
|
145
|
-
if (outstanding.size === 0 && pending
|
|
146
|
-
|
|
147
|
-
pending =
|
|
146
|
+
if (outstanding.size === 0 && pending) {
|
|
147
|
+
project(pending.entry, pending.state);
|
|
148
|
+
pending = undefined;
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
|
-
if (pending
|
|
151
|
+
if (pending) throw new Error("Todo mutation has an incomplete tool group");
|
|
151
152
|
return [
|
|
152
153
|
...(insertions.get(-1) ?? []),
|
|
153
154
|
...messages.flatMap((message, index) => [message, ...(insertions.get(index) ?? [])]),
|