@ian-pascoe/pi-todo 0.6.2 → 0.6.4

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
@@ -43,9 +43,11 @@ A Pi `codemode` script receives the result as an object (the tool declares an `o
43
43
 
44
44
  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.
45
45
 
46
- 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, and so does a group whose last `todo` result is a successful `list`, batch `add`, or batch `update` whose `details.tasks` equal the complete final Todo List, since the model already saw that list. Partial results, such as a single `update` or a batch `update` of some Tasks, still add one. A `codemode` result counts only when Pi recorded a nested `todo` call on it, so an unrelated script never replaces an earlier `todo` result. Such a group skips the same way when its result is successful, its output is at most 64 KiB, and the last Todo List it prints as JSON (such as a nested `todo` call's returned value) equals the complete final Todo List; Pi records nested calls without their results, so the script's output text is the only evidence, and a script that prints no list, a partial result, or a stale list still adds one. 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.
46
+ 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, and so does a group whose last `todo` result is a successful `list`, batch `add`, or batch `update` whose `details.tasks` equal the complete final Todo List, since the model already saw that list. Partial results, such as a single `update` or a batch `update` of some Tasks, still add one. A `codemode` result counts only when Pi recorded a nested `todo` call on it, so an unrelated script never replaces an earlier `todo` result. Such a group skips the same way when its result is successful, its output is at most 64 KiB, and the last Todo List it prints as JSON (such as a nested `todo` call's returned value) equals the complete final Todo List; Pi records nested calls without their results, so the script's output text is the only evidence, and a script that prints no list, a partial result, or a stale list still adds one. 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 definition stay the same for the whole session.
47
47
 
48
- 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.
48
+ The tool adds one line to the Available tools section of Pi's default system prompt (`todo: Track this session's Tasks in the Todo List`) and one guideline: when the Todo List has Tasks, mark a Task active when you start it and completed as soon as it is done, and bring the list up to date before context is compacted. Both are fixed text, so they never change the prompt prefix. A custom system prompt (`SYSTEM.md`) omits tool snippets and guidelines, as Pi does for every tool.
49
+
50
+ After compaction, a fixed baseline immediately after the summary restores the state from before the retained Tail. Retained and newer tool groups follow chronologically. When the Todo List still has unfinished Tasks at the checkpoint, a **Checkpoint Snapshot** follows the retained Tail, where the next Context Window resumes: it repeats the list as compaction left it and asks the agent to reconcile it with the work already done and the plan carried forward (a Handoff's own next steps otherwise quietly replace the list). It replaces the Tail's last Snapshot when that sits at the same position and shows the same list, such as the baseline when the Tail is empty, so the list is not printed twice. An empty or fully completed list adds none. This preserves previously written conversation cache prefixes between checkpoints; it does not guarantee provider cache hits.
49
51
 
50
52
  `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.
51
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ian-pascoe/pi-todo",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "private": false,
5
5
  "description": "Minimal session-native Todo List for Pi agents.",
6
6
  "keywords": [
@@ -33,7 +33,7 @@
33
33
  "provenance": true
34
34
  },
35
35
  "dependencies": {
36
- "@ian-pascoe/pi-utils": "^0.6.0"
36
+ "@ian-pascoe/pi-utils": "^0.7.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@earendil-works/pi-ai": ">=1.1.0",
@@ -40,6 +40,11 @@ function assertTodoJournalReadable(context: ExtensionContext): void {
40
40
  }
41
41
  const TODO_WIDGET_ID = "pi-todo";
42
42
 
43
+ /** Static system prompt lines, so they never move the cache prefix within a session. */
44
+ export const TODO_PROMPT_SNIPPET = "Track this session's Tasks in the Todo List";
45
+ export const TODO_PROMPT_GUIDELINE =
46
+ "When the Todo List has Tasks, keep it current: mark a Task active when you start it and completed as soon as it is done, and bring it up to date before context is compacted.";
47
+
43
48
  const TodoParameters = Type.Object({
44
49
  action: StringEnum(TODO_ACTIONS),
45
50
  id: Type.Optional(
@@ -185,6 +190,8 @@ export default function piTodoExtension(pi: ExtensionAPI): void {
185
190
  name: "todo",
186
191
  label: "Todo",
187
192
  description: "Manage the current session branch's Todo List.",
193
+ promptSnippet: TODO_PROMPT_SNIPPET,
194
+ promptGuidelines: [TODO_PROMPT_GUIDELINE],
188
195
  parameters: TodoParameters,
189
196
  annotations: {
190
197
  readOnlyHint: false,
@@ -17,6 +17,9 @@ import {
17
17
  type Message = ContextEvent["messages"][number];
18
18
  /** Marks a snapshot as extension state so the model does not read it as user-authored. */
19
19
  const SNAPSHOT_HEADER = "Todo List state from the pi-todo extension (not a user message):";
20
+ /** Closes a Checkpoint Snapshot: a Handoff's own plan otherwise silently replaces the Todo List. */
21
+ export const CHECKPOINT_INSTRUCTION =
22
+ "Context was compacted while Tasks were unfinished. Before continuing, reconcile this Todo List with the work already done and the plan carried forward: mark finished Tasks completed, remove abandoned ones, and keep it current as you work.";
20
23
  const ListDetails = Type.Object({ tasks: Type.Array(Type.Unknown()) });
21
24
  const ProjectionDetails = Type.Object(
22
25
  {
@@ -124,12 +127,14 @@ function snapshotMessage(
124
127
  entry: SessionEntry,
125
128
  state: TodoStateSnapshot,
126
129
  checkpointId: string | null,
130
+ instruction?: string,
127
131
  ): Message {
132
+ const list = `${SNAPSHOT_HEADER}\n${formatTodoList(state.tasks)}`;
128
133
  return {
129
134
  role: "custom",
130
135
  customType: "pi-todo-context",
131
136
  display: false,
132
- content: `${SNAPSHOT_HEADER}\n${formatTodoList(state.tasks)}`,
137
+ content: instruction === undefined ? list : `${list}\n\n${instruction}`,
133
138
  timestamp: Date.parse(entry.timestamp),
134
139
  details: { version: 1, stateEntryId: entry.id, checkpointId },
135
140
  };
@@ -153,9 +158,12 @@ export function projectTodoContext(
153
158
  let start = 0;
154
159
  let anchor: Message | undefined;
155
160
  let previousContent: string | undefined;
161
+ // The latest state at the point being projected; at the checkpoint, the state it compacted.
162
+ let current: { entry: SessionEntry; state: TodoStateSnapshot } | undefined;
156
163
  const insertions = new Map<number, Message[]>();
157
164
  let previousIndex = -1;
158
- const insert = (snapshot: Message): void => {
165
+ /** `supersedes` replaces the last Snapshot at the same position when it shows the same list. */
166
+ const insert = (snapshot: Message, supersedes?: string): void => {
159
167
  let index = -1;
160
168
  if (anchor) {
161
169
  // ponytail: linear exact matching per mutation; index fingerprints if large journals make this measurable.
@@ -171,6 +179,8 @@ export function projectTodoContext(
171
179
  if (index < previousIndex) throw new Error("Todo context anchors are reordered");
172
180
  previousIndex = index;
173
181
  const group = insertions.get(index) ?? [];
182
+ const last = group.at(-1);
183
+ if (last?.role === "custom" && last.content === supersedes) group.pop();
174
184
  group.push(snapshot);
175
185
  insertions.set(index, group);
176
186
  };
@@ -183,11 +193,26 @@ export function projectTodoContext(
183
193
  for (const entry of branch.slice(0, start).toReversed()) {
184
194
  const state = todoStateFromEntry(entry);
185
195
  if (!state) continue;
196
+ current = { entry, state };
186
197
  previousContent = formatTodoList(state.tasks);
187
198
  insert(snapshotMessage(entry, state, checkpoint.id));
188
199
  break;
189
200
  }
190
201
  }
202
+ /**
203
+ * After the retained Tail, where the next Context Window resumes, unfinished Tasks get one
204
+ * Checkpoint Snapshot asking the agent to reconcile them. It replaces an identical Snapshot at the
205
+ * same position, such as the baseline when the Tail is empty, rather than repeating the list.
206
+ */
207
+ const projectCheckpoint = (checkpointId: string): void => {
208
+ if (!current?.state.tasks.some((task) => task.status !== "completed")) return;
209
+ const { entry, state } = current;
210
+ previousContent = formatTodoList(state.tasks);
211
+ insert(
212
+ snapshotMessage(entry, state, checkpointId, CHECKPOINT_INSTRUCTION),
213
+ `${SNAPSHOT_HEADER}\n${previousContent}`,
214
+ );
215
+ };
191
216
  const outstanding = new Map<string, number>();
192
217
  // A tool group projects only its final state, once its last result has landed. Nested `todo`
193
218
  // calls in a `codemode` script leave no results in the journal, so the script's result stands in.
@@ -206,9 +231,13 @@ export function projectTodoContext(
206
231
  previousContent = content;
207
232
  };
208
233
  for (const entry of branch.slice(start)) {
209
- if (entry === checkpoint) continue;
234
+ if (entry === checkpoint) {
235
+ projectCheckpoint(entry.id);
236
+ continue;
237
+ }
210
238
  const state = todoStateFromEntry(entry);
211
239
  if (state) {
240
+ current = { entry, state };
212
241
  if (outstanding.size > 0) pending = { entry, state };
213
242
  else project(entry, state);
214
243
  continue;