@ian-pascoe/pi-todo 0.6.0 → 0.6.1

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,7 +43,7 @@ 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. 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` group never skips, because its result is not a `todo` result. 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.
47
47
 
48
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.
49
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ian-pascoe/pi-todo",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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.5.0"
36
+ "@ian-pascoe/pi-utils": "^0.6.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@earendil-works/pi-ai": ">=1.1.0",
@@ -1,6 +1,12 @@
1
1
  import { StringEnum } from "@earendil-works/pi-ai";
2
- import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
2
+ import {
3
+ defineTool,
4
+ type ExtensionAPI,
5
+ type ExtensionContext,
6
+ type Theme,
7
+ } from "@earendil-works/pi-coding-agent";
3
8
  import { type Component } from "@earendil-works/pi-tui";
9
+ import { acceptNullForOptionalArguments } from "@ian-pascoe/pi-utils/null-optional-arguments";
4
10
  import { noticeText } from "@ian-pascoe/pi-utils/ui";
5
11
  import { Type } from "typebox";
6
12
  import { projectTodoContext, todoStateFromEntry } from "./todo-context.js";
@@ -175,7 +181,7 @@ export default function piTodoExtension(pi: ExtensionAPI): void {
175
181
  }
176
182
  });
177
183
 
178
- pi.registerTool<typeof TodoParameters, TodoToolDetails | undefined>({
184
+ const todoTool = defineTool<typeof TodoParameters, TodoToolDetails | undefined>({
179
185
  name: "todo",
180
186
  label: "Todo",
181
187
  description: "Manage the current session branch's Todo List.",
@@ -211,6 +217,7 @@ export default function piTodoExtension(pi: ExtensionAPI): void {
211
217
  renderResult: (result, options, theme, context) =>
212
218
  renderTodoResult(result, options, theme, context),
213
219
  });
220
+ pi.registerTool(acceptNullForOptionalArguments(todoTool));
214
221
 
215
222
  pi.registerCommand("todo", {
216
223
  description: "Manage the Todo List",
@@ -16,6 +16,7 @@ import {
16
16
  type Message = ContextEvent["messages"][number];
17
17
  /** Marks a snapshot as extension state so the model does not read it as user-authored. */
18
18
  const SNAPSHOT_HEADER = "Todo List state from the pi-todo extension (not a user message):";
19
+ const ListDetails = Type.Object({ tasks: Type.Array(Type.Unknown()) });
19
20
  const ProjectionDetails = Type.Object(
20
21
  {
21
22
  version: Type.Literal(1),
@@ -43,6 +44,15 @@ export function todoStateFromEntry(entry: SessionEntry): TodoStateSnapshot | und
43
44
  return parseTodoStateSnapshot(entry.data);
44
45
  }
45
46
 
47
+ /** True when a successful `todo` result's details carry exactly the complete resulting list. */
48
+ function resultRendersList(message: Message | undefined, tasks: TodoStateSnapshot["tasks"]) {
49
+ if (message?.role !== "toolResult" || message.toolName !== "todo" || message.isError)
50
+ return false;
51
+ return (
52
+ Value.Check(ListDetails, message.details) && isDeepStrictEqual(message.details.tasks, tasks)
53
+ );
54
+ }
55
+
46
56
  function snapshotMessage(
47
57
  entry: SessionEntry,
48
58
  state: TodoStateSnapshot,
@@ -113,10 +123,17 @@ export function projectTodoContext(
113
123
  }
114
124
  const outstanding = new Map<string, number>();
115
125
  // A tool group projects only its final state, once its last result has landed.
126
+ let lastTodoResult: Message | undefined;
116
127
  let pending: { entry: SessionEntry; state: TodoStateSnapshot } | undefined;
117
- const project = (entry: SessionEntry, state: TodoStateSnapshot): void => {
128
+ const project = (entry: SessionEntry, state: TodoStateSnapshot, finalResult?: Message): void => {
118
129
  const content = formatTodoList(state.tasks);
119
- if (content !== previousContent && (previousContent !== undefined || state.tasks.length > 0))
130
+ // The model already saw this exact list in the group's last result; a Snapshot would repeat it.
131
+ const rendered = resultRendersList(finalResult, state.tasks);
132
+ if (
133
+ !rendered &&
134
+ content !== previousContent &&
135
+ (previousContent !== undefined || state.tasks.length > 0)
136
+ )
120
137
  insert(snapshotMessage(entry, state, null));
121
138
  previousContent = content;
122
139
  };
@@ -134,17 +151,19 @@ export function projectTodoContext(
134
151
  if (outstanding.size > 0 && pending)
135
152
  throw new Error("Todo mutation has an incomplete tool group");
136
153
  outstanding.clear();
154
+ lastTodoResult = undefined;
137
155
  for (const block of message.content)
138
156
  if (block.type === "toolCall")
139
157
  outstanding.set(block.id, (outstanding.get(block.id) ?? 0) + 1);
140
158
  } else if (message.role === "toolResult") {
159
+ if (message.toolName === "todo") lastTodoResult = message;
141
160
  const remaining = (outstanding.get(message.toolCallId) ?? 0) - 1;
142
161
  if (remaining > 0) outstanding.set(message.toolCallId, remaining);
143
162
  else outstanding.delete(message.toolCallId);
144
163
  }
145
164
  anchor = message;
146
165
  if (outstanding.size === 0 && pending) {
147
- project(pending.entry, pending.state);
166
+ project(pending.entry, pending.state, lastTodoResult);
148
167
  pending = undefined;
149
168
  }
150
169
  }