@ftrdotdev/pi-tracker 0.6.0 → 0.8.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.
Files changed (36) hide show
  1. package/README.md +183 -60
  2. package/package.json +23 -11
  3. package/src/compaction/candidate.test.ts +9 -6
  4. package/src/compaction/candidate.ts +32 -2
  5. package/src/compaction/classifier.test.ts +67 -60
  6. package/src/compaction/classifier.ts +24 -22
  7. package/src/compaction/completion.test.ts +127 -49
  8. package/src/compaction/completion.ts +1 -3
  9. package/src/compaction/decision-record.test.ts +91 -0
  10. package/src/compaction/decision-record.ts +101 -0
  11. package/src/compaction/digest.test.ts +104 -9
  12. package/src/compaction/digest.ts +96 -9
  13. package/src/compaction/footprint.test.ts +135 -0
  14. package/src/compaction/footprint.ts +387 -0
  15. package/src/compaction/observations.test.ts +199 -0
  16. package/src/compaction/observations.ts +348 -0
  17. package/src/compaction/rules.test.ts +253 -0
  18. package/src/compaction/rules.ts +188 -0
  19. package/src/compaction/settings.test.ts +105 -49
  20. package/src/compaction/settings.ts +53 -31
  21. package/src/compaction/settle.test.ts +370 -0
  22. package/src/compaction/settle.ts +109 -53
  23. package/src/core/deps.test.ts +1 -1
  24. package/src/core/domain.test.ts +42 -9
  25. package/src/core/domain.ts +73 -8
  26. package/src/core/persistence.test.ts +7 -7
  27. package/src/core/store.test.ts +116 -50
  28. package/src/core/store.ts +92 -31
  29. package/src/index.test.ts +209 -68
  30. package/src/index.ts +170 -48
  31. package/src/presentation/tool-metadata.test.ts +263 -48
  32. package/src/presentation/tool-metadata.ts +325 -102
  33. package/src/presentation/ui.test.ts +122 -7
  34. package/src/presentation/ui.ts +81 -18
  35. package/src/presentation/vim-settings.test.ts +98 -0
  36. package/src/presentation/vim-settings.ts +59 -0
@@ -16,8 +16,8 @@ export const TOOL_ACTIONS = [
16
16
  "create_list",
17
17
  "delete_list",
18
18
  "set_active",
19
- "add_item",
20
- "update_item",
19
+ "add_items",
20
+ "update_items",
21
21
  "remove_item",
22
22
  ] as const;
23
23
 
@@ -35,18 +35,97 @@ const depsSchema = Type.Array(
35
35
  { description: "Same-list items that must be done before this one." },
36
36
  );
37
37
 
38
- const ItemSpecSchema = Type.Union([
39
- Type.String({ description: "Item text." }),
38
+ /** The item-title cap. Enforced only at the tool input, never persisted. */
39
+ export const TITLE_LIMIT = 200;
40
+
41
+ const titleField = Type.String({
42
+ description:
43
+ "Item title: one short action line (max 200 characters). Move longer detail into 'description'.",
44
+ });
45
+
46
+ const descriptionField = Type.String({
47
+ description:
48
+ "Optional: the longer explanation of the item. Put the essential detail in the first paragraph.",
49
+ });
50
+
51
+ /** A declared reference: a path (optionally narrowed to a symbol or span) or a decision topic. */
52
+ const referenceSchema = Type.Union([
53
+ Type.Object(
54
+ {
55
+ kind: Type.Literal("path"),
56
+ path: Type.String({ description: "The file path this item must read next." }),
57
+ symbol: Type.Optional(Type.String({ description: "A symbol inside the path." })),
58
+ span: Type.Optional(Type.String({ description: 'A line span, e.g. "12-14" or "12".' })),
59
+ },
60
+ { additionalProperties: false },
61
+ ),
40
62
  Type.Object(
41
63
  {
42
- text: Type.String({ description: "Item text." }),
43
- deps: Type.Optional(depsSchema),
64
+ kind: Type.Literal("decision"),
65
+ topic: Type.String({ description: "The decision the item depends on." }),
44
66
  },
45
- // Item objects are strict: a typo inside one fails here.
46
67
  { additionalProperties: false },
47
68
  ),
48
69
  ]);
49
70
 
71
+ const refsSchema = Type.Array(referenceSchema, {
72
+ description:
73
+ "Optional: the files, symbols, regions, or decisions this item must read after the completed item finishes.",
74
+ });
75
+
76
+ const producesSchema = Type.Array(
77
+ Type.Object(
78
+ { path: Type.String({ description: "A document the item will write." }) },
79
+ { additionalProperties: false },
80
+ ),
81
+ { description: "Optional: every document this item will write." },
82
+ );
83
+
84
+ /** One new item, as the strict item object both add paths accept. */
85
+ const ItemObjectSchema = Type.Object(
86
+ {
87
+ title: titleField,
88
+ description: Type.Optional(descriptionField),
89
+ refs: Type.Optional(refsSchema),
90
+ produces: Type.Optional(producesSchema),
91
+ deps: Type.Optional(depsSchema),
92
+ },
93
+ // Item objects are strict: a typo inside one fails here.
94
+ { additionalProperties: false },
95
+ );
96
+
97
+ /** One `update_items` patch: the item id plus the fields to replace. */
98
+ const UpdatePatchSchema = Type.Object(
99
+ {
100
+ item_id: Type.String({
101
+ description:
102
+ 'The id of the item within list_id, as shown by the list action (e.g. "Work:2").',
103
+ }),
104
+ title: Type.Optional(Type.String({ description: "Replacement title for the item." })),
105
+ description: Type.Optional(
106
+ Type.String({ description: "Replacement description for the item." }),
107
+ ),
108
+ refs: Type.Optional(refsSchema),
109
+ produces: Type.Optional(producesSchema),
110
+ done: Type.Optional(
111
+ Type.Boolean({ description: "true marks the item done, false reopens it." }),
112
+ ),
113
+ deps: Type.Optional(
114
+ Type.Array(Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
115
+ description:
116
+ "Replacement dependency set for this item. Pass [] to clear. Must not form a cycle.",
117
+ }),
118
+ ),
119
+ },
120
+ // Patch objects are strict: a typo inside an item update fails here.
121
+ { additionalProperties: false },
122
+ );
123
+
124
+ /** One item to add, as the tool accepts it. */
125
+ export type TrackerItemSpec = Static<typeof ItemObjectSchema>;
126
+ /** One update_items patch, as the tool accepts it. */
127
+ export type TrackerUpdatePatch = Static<typeof UpdatePatchSchema>;
128
+
50
129
  /**
51
130
  * Parameter schema for the tracker tool.
52
131
  *
@@ -61,22 +140,22 @@ export const TrackerToolParams = Type.Object({
61
140
  list_id: Type.Optional(
62
141
  Type.Number({
63
142
  description:
64
- "List id, as shown by the list action. Required for delete_list, add_item, and for update_item's items={...} batch; optional for set_active (omit to deselect).",
143
+ "List id, as shown by the list action. Required for delete_list, add_items, and for update_items' items={...} batch; optional for set_active (omit to deselect).",
65
144
  }),
66
145
  ),
67
146
  item_id: Type.Optional(
68
147
  Type.String({
69
148
  description:
70
- 'Item id, as shown by the list action: listName:id (e.g. "Work:2"). Ids are permanent: removing an item does not change the other ids. Required for update_item (scalar form) and remove_item.',
149
+ 'Item id, as shown by the list action: listName:id (e.g. "Work:2"). Ids are permanent: removing an item does not change the other ids. Required for update_items (scalar form) and remove_item.',
71
150
  }),
72
151
  ),
73
152
  name: Type.Optional(
74
153
  Type.String({ description: "Name for the new list. Required for create_list." }),
75
154
  ),
76
155
  initial_items: Type.Optional(
77
- Type.Array(ItemSpecSchema, {
156
+ Type.Array(ItemObjectSchema, {
78
157
  description:
79
- "For create_list: initial items (text, or {text, deps}), added when the list is created.",
158
+ "For create_list: initial items, each {title, description?, refs?, produces?, deps?}, added when the list is created.",
80
159
  minItems: 1,
81
160
  }),
82
161
  ),
@@ -86,61 +165,29 @@ export const TrackerToolParams = Type.Object({
86
165
  "For create_list: switch the active list to the new list (defaults to true; pass false to keep the current active list).",
87
166
  }),
88
167
  ),
89
- text: Type.Optional(
90
- Type.Union(
91
- [
92
- ItemSpecSchema,
93
- Type.Array(ItemSpecSchema, {
94
- description: "For add_item: several items to add in one call.",
95
- minItems: 1,
96
- }),
97
- ],
98
- {
99
- description:
100
- "Item text: a string, an item object {text, deps?}, or (add_item only) an array of either.",
101
- },
102
- ),
168
+ title: Type.Optional(
169
+ Type.String({
170
+ description: "For update_items: the replacement title for the item (max 200 characters).",
171
+ }),
103
172
  ),
173
+ description: Type.Optional(descriptionField),
174
+ refs: Type.Optional(refsSchema),
175
+ produces: Type.Optional(producesSchema),
104
176
  done: Type.Optional(
105
- Type.Boolean({ description: "For update_item: true marks the item done, false reopens it." }),
177
+ Type.Boolean({ description: "For update_items: true marks the item done, false reopens it." }),
106
178
  ),
107
179
  deps: Type.Optional(
108
180
  Type.Array(Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
109
181
  description:
110
- "For update_item: the replacement dependency set (same-list items that must be done first). Pass [] to clear. Must not form a cycle.",
182
+ "For update_items: the replacement dependency set (same-list items that must be done first). Pass [] to clear. Must not form a cycle.",
111
183
  }),
112
184
  ),
113
185
  items: Type.Optional(
114
- Type.Array(
115
- Type.Object(
116
- {
117
- item_id: Type.String({
118
- description:
119
- 'The id of the item within list_id, as shown by the list action (e.g. "Work:2").',
120
- }),
121
- text: Type.Optional(Type.String({ description: "Replacement text for the item." })),
122
- done: Type.Optional(
123
- Type.Boolean({ description: "true marks the item done, false reopens it." }),
124
- ),
125
- deps: Type.Optional(
126
- Type.Array(
127
- Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }),
128
- {
129
- description:
130
- "Replacement dependency set for this item. Pass [] to clear. Must not form a cycle.",
131
- },
132
- ),
133
- ),
134
- },
135
- // Patch objects are strict: a typo inside an item update fails here.
136
- { additionalProperties: false },
137
- ),
138
- {
139
- description:
140
- "For update_item: one or more item updates within a single list_id (mirrors add_item's list_id + text[]). Alternative to item_id/text/done/deps.",
141
- minItems: 1,
142
- },
143
- ),
186
+ Type.Array(Type.Union([ItemObjectSchema, UpdatePatchSchema]), {
187
+ description:
188
+ "For add_items: the item objects to add, each {title, description?, refs?, produces?, deps?}. For update_items: the item patches, each with an item_id.",
189
+ minItems: 1,
190
+ }),
144
191
  ),
145
192
  });
146
193
 
@@ -152,8 +199,18 @@ const ACTION_PARAMS: Readonly<Record<TrackerToolAction, readonly string[]>> = {
152
199
  create_list: ["name", "initial_items", "activate"],
153
200
  delete_list: ["list_id"],
154
201
  set_active: ["list_id"],
155
- add_item: ["list_id", "text"],
156
- update_item: ["list_id", "item_id", "text", "done", "deps", "items"],
202
+ add_items: ["list_id", "items"],
203
+ update_items: [
204
+ "list_id",
205
+ "item_id",
206
+ "title",
207
+ "description",
208
+ "refs",
209
+ "produces",
210
+ "done",
211
+ "deps",
212
+ "items",
213
+ ],
157
214
  remove_item: ["item_id"],
158
215
  };
159
216
 
@@ -162,12 +219,145 @@ export type TrackerCallValidation =
162
219
  | { ok: true; params: TrackerToolParams }
163
220
  | { ok: false; message: string };
164
221
 
222
+ /** Every title a call declares, in any accepted shape. */
223
+ const declaredTitles = (record: Record<string, unknown>): readonly string[] => {
224
+ const titles: string[] = [];
225
+ const collect = (value: unknown): void => {
226
+ if (typeof value === "string") titles.push(value);
227
+ else if (Array.isArray(value)) value.forEach(collect);
228
+ else if (typeof value === "object" && value !== null) {
229
+ const title = (value as Record<string, unknown>).title;
230
+ if (typeof title === "string") titles.push(title);
231
+ }
232
+ };
233
+ collect(record.title);
234
+ collect(record.initial_items);
235
+ if (Array.isArray(record.items)) {
236
+ for (const patch of record.items) {
237
+ if (typeof patch !== "object" || patch === null) continue;
238
+ const title = (patch as Record<string, unknown>).title;
239
+ if (typeof title === "string") titles.push(title);
240
+ }
241
+ }
242
+ return titles;
243
+ };
244
+
245
+ /** The title-cap error, naming where the detail belongs. */
246
+ const titleLimitError = (title: string): string =>
247
+ `Item title is ${title.length} characters, over the ${TITLE_LIMIT}-character limit. ` +
248
+ "Move the detail into 'description'.";
249
+
250
+ /** The first declared title over the cap, or undefined. */
251
+ const firstLongTitle = (record: Record<string, unknown>): string | undefined =>
252
+ declaredTitles(record).find((title) => title.length > TITLE_LIMIT);
253
+
254
+ /** The first malformed declared reference, or null. Names the field to fix. */
255
+ const referenceError = (refs: unknown, where = "refs"): string | null => {
256
+ if (refs === undefined) return null;
257
+ if (!Array.isArray(refs)) return `${where} must be an array of declared references`;
258
+ for (const [index, ref] of refs.entries()) {
259
+ if (typeof ref !== "object" || ref === null || Array.isArray(ref)) {
260
+ return `${where}[${index}] must be an object with a 'kind' of "path" or "decision"`;
261
+ }
262
+ const record = ref as Record<string, unknown>;
263
+ if (record.kind === "path") {
264
+ if (typeof record.path !== "string" || record.path.length === 0) {
265
+ return `${where}[${index}] is a path reference and requires a 'path' string`;
266
+ }
267
+ } else if (record.kind === "decision") {
268
+ if (typeof record.topic !== "string" || record.topic.length === 0) {
269
+ return `${where}[${index}] is a decision reference and requires a 'topic' string`;
270
+ }
271
+ } else {
272
+ return `${where}[${index}].kind must be "path" or "decision" (got ${JSON.stringify(record.kind)})`;
273
+ }
274
+ }
275
+ return null;
276
+ };
277
+
278
+ /** The first malformed declared product, or null. */
279
+ const producesError = (produces: unknown, where = "produces"): string | null => {
280
+ if (produces === undefined) return null;
281
+ if (!Array.isArray(produces)) return `${where} must be an array of declared products`;
282
+ for (const [index, product] of produces.entries()) {
283
+ if (
284
+ typeof product !== "object" ||
285
+ product === null ||
286
+ typeof (product as Record<string, unknown>).path !== "string"
287
+ ) {
288
+ return `${where}[${index}] requires a 'path' string`;
289
+ }
290
+ }
291
+ return null;
292
+ };
293
+
294
+ /** The first declaration problem anywhere in the call, or null. */
295
+ const firstDeclarationError = (record: Record<string, unknown>): string | null => {
296
+ const direct = referenceError(record.refs) ?? producesError(record.produces);
297
+ if (direct !== null) return direct;
298
+ const containers = [
299
+ ...(Array.isArray(record.items) ? record.items : []),
300
+ ...(Array.isArray(record.initial_items) ? record.initial_items : []),
301
+ ];
302
+ for (const entry of containers) {
303
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) continue;
304
+ const nested = firstDeclarationError(entry as Record<string, unknown>);
305
+ if (nested !== null) return nested;
306
+ }
307
+ return null;
308
+ };
309
+
310
+ /** The first entry that is not an item object with a title, or null. */
311
+ const firstItemObjectError = (items: readonly unknown[], where: string): string | null => {
312
+ for (const [index, entry] of items.entries()) {
313
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
314
+ return `${where}[${index}] must be an item object {title, description?, refs?, produces?, deps?}`;
315
+ }
316
+ if (typeof (entry as Record<string, unknown>).title !== "string") {
317
+ return `${where}[${index}] requires a 'title' string (one short action line; put longer detail in 'description')`;
318
+ }
319
+ }
320
+ return null;
321
+ };
322
+
323
+ /**
324
+ * The first `add_items` entry that is not an item object with a title, or
325
+ * null. The `items` field is shared with `update_items`, whose entries carry
326
+ * `item_id`; that field belongs to the patch form and is rejected here.
327
+ */
328
+ const firstAddEntryError = (items: readonly unknown[]): string | null => {
329
+ for (const [index, entry] of items.entries()) {
330
+ if (
331
+ typeof entry === "object" &&
332
+ entry !== null &&
333
+ !Array.isArray(entry) &&
334
+ (entry as Record<string, unknown>).item_id !== undefined
335
+ ) {
336
+ return `items[${index}] carries 'item_id', which update_items uses; add_items entries are {title, ...}`;
337
+ }
338
+ }
339
+ return firstItemObjectError(items, "items");
340
+ };
341
+
342
+ /** The first `update_items` entry that carries no `item_id`, or null. */
343
+ const firstUpdateEntryError = (items: readonly unknown[]): string | null => {
344
+ for (const [index, entry] of items.entries()) {
345
+ if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
346
+ return `items[${index}] must be an item patch {item_id, ...}`;
347
+ }
348
+ if (typeof (entry as Record<string, unknown>).item_id !== "string") {
349
+ return `items[${index}] requires an 'item_id' string`;
350
+ }
351
+ }
352
+ return null;
353
+ };
354
+
165
355
  /**
166
356
  * Runtime validation for a tracker call — the error-nudging layer.
167
357
  *
168
358
  * The parameter schema only enforces types; this checks what the schema
169
359
  * cannot express (presence of required fields per action, unknown fields,
170
- * the mutually exclusive update_item forms) and returns an actionable error
360
+ * the mutually exclusive update_items forms) and returns an actionable error
171
361
  * message naming exactly what to fix. `execute` surfaces that message to the
172
362
  * agent, so an incorrect call self-corrects on the next attempt.
173
363
  */
@@ -180,7 +370,7 @@ export function validateTrackerCall(args: unknown): TrackerCallValidation {
180
370
  if (typeof action !== "string" || !(TOOL_ACTIONS as readonly string[]).includes(action)) {
181
371
  return {
182
372
  ok: false,
183
- message: `Unknown tracker action ${JSON.stringify(action)} — expected one of: ${TOOL_ACTIONS.join(", ")}`,
373
+ message: `Unknown tracker action ${JSON.stringify(action)}; expected one of: ${TOOL_ACTIONS.join(", ")}`,
184
374
  };
185
375
  }
186
376
  const typed = action as TrackerToolAction;
@@ -193,8 +383,8 @@ export function validateTrackerCall(args: unknown): TrackerCallValidation {
193
383
  ok: false,
194
384
  message:
195
385
  allowed.length === 0
196
- ? `tracker ${typed} accepts no parameters — unexpected: ${unexpected.join(", ")}`
197
- : `tracker ${typed} does not accept ${unexpected.join(", ")} — it accepts: ${allowed.join(", ")}`,
386
+ ? `tracker ${typed} accepts no parameters; unexpected: ${unexpected.join(", ")}`
387
+ : `tracker ${typed} does not accept ${unexpected.join(", ")}; it accepts: ${allowed.join(", ")}`,
198
388
  };
199
389
  }
200
390
  switch (typed) {
@@ -205,57 +395,72 @@ export function validateTrackerCall(args: unknown): TrackerCallValidation {
205
395
  message: "create_list requires the 'name' parameter (the new list's name).",
206
396
  };
207
397
  }
398
+ if (Array.isArray(record.initial_items)) {
399
+ const problem = firstItemObjectError(record.initial_items, "initial_items");
400
+ if (problem !== null) return { ok: false, message: problem };
401
+ }
208
402
  break;
209
403
  case "delete_list":
210
404
  if (record.list_id === undefined) {
211
405
  return { ok: false, message: "delete_list requires the 'list_id' parameter." };
212
406
  }
213
407
  break;
214
- case "add_item":
408
+ case "add_items": {
215
409
  if (record.list_id === undefined) {
216
- return { ok: false, message: "add_item requires the 'list_id' parameter." };
410
+ return { ok: false, message: "add_items requires the 'list_id' parameter." };
217
411
  }
218
- if (record.text === undefined) {
412
+ if (!Array.isArray(record.items) || record.items.length === 0) {
219
413
  return {
220
414
  ok: false,
221
415
  message:
222
- "add_item requires the 'text' parameter (a string, or an array of strings for several items).",
416
+ "add_items requires the 'items' parameter: one or more item objects " +
417
+ "{title, description?, refs?, produces?, deps?}.",
223
418
  };
224
419
  }
420
+ const problem = firstAddEntryError(record.items);
421
+ if (problem !== null) return { ok: false, message: problem };
225
422
  break;
226
- case "update_item":
423
+ }
424
+ case "update_items":
227
425
  if (record.items !== undefined) {
228
426
  // Batch form: list_id + items (id-based, one list).
229
427
  if (
230
428
  record.item_id !== undefined ||
231
- record.text !== undefined ||
429
+ record.title !== undefined ||
430
+ record.description !== undefined ||
431
+ record.refs !== undefined ||
432
+ record.produces !== undefined ||
232
433
  record.done !== undefined ||
233
434
  record.deps !== undefined
234
435
  ) {
235
436
  return {
236
437
  ok: false,
237
438
  message:
238
- "update_item: pass either item_id/text/done/deps (one item) or list_id + items (several items in one list), not both.",
439
+ "update_items: pass either item_id with title/description/refs/produces/done/deps (one item) or list_id + items (several items in one list), not both.",
239
440
  };
240
441
  }
241
442
  if (record.list_id === undefined) {
242
443
  return {
243
444
  ok: false,
244
445
  message:
245
- "update_item with 'items' requires the 'list_id' parameter (the list whose items are being updated).",
446
+ "update_items with 'items' requires the 'list_id' parameter (the list whose items are being updated).",
246
447
  };
247
448
  }
449
+ if (Array.isArray(record.items)) {
450
+ const problem = firstUpdateEntryError(record.items);
451
+ if (problem !== null) return { ok: false, message: problem };
452
+ }
248
453
  } else if (record.item_id === undefined) {
249
454
  return {
250
455
  ok: false,
251
456
  message:
252
- "update_item requires 'item_id' (one item) or 'list_id' + 'items' (several items in one list).",
457
+ "update_items requires 'item_id' (one item) or 'list_id' + 'items' (several items in one list).",
253
458
  };
254
- } else if (record.text !== undefined && typeof record.text !== "string") {
459
+ } else if (record.title !== undefined && typeof record.title !== "string") {
255
460
  return {
256
461
  ok: false,
257
462
  message:
258
- "update_item: 'text' must be a single string — use 'items' to update several items in one call.",
463
+ "update_items: 'title' must be a single string; use 'items' to update several items in one call.",
259
464
  };
260
465
  }
261
466
  break;
@@ -269,6 +474,10 @@ export function validateTrackerCall(args: unknown): TrackerCallValidation {
269
474
  // list and set_active need nothing beyond `action` (set_active may omit list_id to deselect).
270
475
  break;
271
476
  }
477
+ const long = firstLongTitle(record);
478
+ if (long !== undefined) return { ok: false, message: titleLimitError(long) };
479
+ const declaration = firstDeclarationError(record);
480
+ if (declaration !== null) return { ok: false, message: declaration };
272
481
  return { ok: true, params: args as TrackerToolParams };
273
482
  }
274
483
 
@@ -280,19 +489,20 @@ export interface TrackerToolDetails {
280
489
  /** `listName:id`, as shown by the list action. */
281
490
  itemId?: string;
282
491
  list?: TodoList;
283
- /** Items affected by an add_item/update_item call, in creation/patch order. */
492
+ /** Items affected by an add_items/update_items call, in creation/patch order. */
284
493
  items?: TodoItem[];
285
494
  /** Full state snapshot, only for the `list` action (for rendering). */
286
495
  snapshot?: EncodedState;
287
496
  }
288
497
 
289
498
  /**
290
- * One applied `update_item` patch, as the advisory helpers need it: the display
499
+ * One applied `update_items` patch, as the advisory helpers need it: the display
291
500
  * id plus whatever fields the caller changed.
292
501
  */
293
502
  export interface AppliedUpdatePatch {
294
503
  readonly id: string;
295
- readonly text?: string;
504
+ readonly title?: string;
505
+ readonly description?: string;
296
506
  readonly done?: boolean;
297
507
  readonly deps?: readonly string[];
298
508
  }
@@ -310,7 +520,7 @@ export interface AppliedUpdatePatch {
310
520
  * affected item is named once, so a batch that hits both paths still produces
311
521
  * one sentence about it.
312
522
  *
313
- * @param patches the update_item patches that were applied, in call order.
523
+ * @param patches the update_items patches that were applied, in call order.
314
524
  * @param state the state after the call. A reopen only changes the reopened
315
525
  * item and a dependency edit only changes the patched item, so the other
316
526
  * items' done flags are the same before and after.
@@ -367,7 +577,7 @@ export const blockedDoneNote = (
367
577
  * advisory text, never a rejection, so legitimate same-turn multi-completions
368
578
  * (when work is still open) still pass silently.
369
579
  *
370
- * @param patches the update_item patches in call order.
580
+ * @param patches the update_items patches in call order.
371
581
  * @param openRemaining number of not-done items across all lists *after* the
372
582
  * call (0 means the batch cleared the whole tracker). Pass undefined when
373
583
  * the post-call state isn't known.
@@ -384,8 +594,8 @@ export const doneMarkReminder = (
384
594
  if (doneCount < 2) return null;
385
595
  if (openRemaining !== 0) return null;
386
596
  return (
387
- `Note: this call completed ${doneCount} items at once and left no open items — the tracker ` +
388
- "guideline is to mark each item done in the same turn it completes, not batch the marking at the end."
597
+ `Note: this call completed ${doneCount} items and left no open items. ` +
598
+ "Mark each item done in the same turn it completes, not in a batch at the end."
389
599
  );
390
600
  };
391
601
 
@@ -393,6 +603,13 @@ const TRACKER_TOOL_DESCRIPTION =
393
603
  "Manage todolists and track progress. Use for task lists, checklists, milestones, and step-by-step " +
394
604
  "work; keep track of tasks with tracker instead of in chat or files. Work through items one at a " +
395
605
  "time, marking each done as it completes, so the list always shows current progress.\n" +
606
+ "Every item has a required title: one short action line. An item may also carry a description " +
607
+ "with the longer detail, kept out of the title so the list stays scannable. Put the essential " +
608
+ "detail in the description's first paragraph.\n" +
609
+ "Declare a reference when the item must read a specific file, symbol, region, or decision after " +
610
+ "the completed work; declare a product for each document the item will write. Both are optional " +
611
+ "and may be empty. A declaration tells the tracker what the next step needs, so completed work " +
612
+ "can be compacted without losing it.\n" +
396
613
  'Item ids are listName:id, e.g. "Work:2" (copy them from the list action output). Ids are ' +
397
614
  "permanent: removing an item does not change the other ids, so a reference you already hold " +
398
615
  "stays valid.\n" +
@@ -406,38 +623,44 @@ const TRACKER_TOOL_DESCRIPTION =
406
623
  "are done. An item that other items depend on cannot be removed until those dependencies change. " +
407
624
  "Reopening an item does not cascade, and a deps edit can leave a done item waiting: the result " +
408
625
  "notes any done item left unsatisfied.\n" +
409
- "The tracker tool is strict: each action accepts only its own parameters — any other argument is " +
410
- "rejected. Parameter contract per action:\n" +
626
+ "Each action accepts only its own parameters; any other argument is rejected with the accepted " +
627
+ "list. Parameter rules the schema cannot express:\n" +
411
628
  "- list: no parameters\n" +
412
- "- create_list: name (required), initial_items (optional array of items, each a text string or " +
413
- "{text, deps?}, added when the list is created), activate (optional, defaults to true: the new " +
414
- "list becomes active; pass false to keep the current active list)\n" +
415
- "- delete_list: list_id (required)\n" +
416
- "- set_active: list_id (omit the field to deselect)\n" +
417
- "- add_item: list_id (required), text (required: a string, an item object {text, deps?}, or an " +
418
- "array of either to add several items in one call)\n" +
419
- "- update_item: update several items in one list with list_id (required) + items=[{item_id, " +
420
- "text?, done?, deps?}, ...] — just like add_item's list_id + text[] (item_id is the item's id, " +
421
- 'e.g. "Work:2"), or one item with item_id + optional text/done/deps. deps replaces the ' +
422
- "dependency set (pass [] to clear it) and the result names what was removed. Patches apply in " +
423
- "order, so later patches win and a blocker can be completed in the same call, before the " +
424
- "dependent. Never mix the two forms. Example: update_item list_id=2 " +
425
- 'items=[{item_id: "Work:2", done: true}, {item_id: "Work:3", deps: ["Work:1"]}]\n' +
426
- "- remove_item: item_id (required, listName:id)";
629
+ "- create_list: name (required), initial_items (optional array of item objects), activate " +
630
+ "(optional, defaults to true: the new list becomes active; pass false to keep the current " +
631
+ "active list)\n" +
632
+ "- delete_list: list_id (required); remove_item: item_id (required, listName:id)\n" +
633
+ "- set_active: list_id (omit the field to deselect, which hides the widget)\n" +
634
+ "- add_items: list_id and items (required). items is a non-empty array of item objects, each " +
635
+ "{title, description?, refs?, produces?, deps?}.\n" +
636
+ "- update_items: one item with item_id plus optional title/description/refs/produces/done/deps, " +
637
+ "or several items in one list with list_id (required) + items=[{item_id, title?, description?, " +
638
+ "refs?, produces?, done?, deps?}, ...]. Never mix the two forms. deps replaces the dependency " +
639
+ "set (pass [] to clear it) and the result names what was removed. Patches apply in order, so " +
640
+ "later patches win and a blocker can be completed in the same call, before the dependent. " +
641
+ 'Example: update_items list_id=2 items=[{item_id: "Work:2", done: true}, {item_id: "Work:3", ' +
642
+ 'deps: ["Work:1"]}]';
427
643
 
428
644
  const TRACKER_TOOL_PROMPT_SNIPPET =
429
645
  "Manage todolists and track progress: create lists with initial items, add/update/remove items. " +
430
- "Batch adds with text arrays and updates with update_item list_id + items=[...] in one call";
646
+ "Each item has a required title (one short line), an optional description, and optional refs and " +
647
+ "produces declarations. Batch adds with add_items items=[{title, ...}]; batch updates with " +
648
+ "update_items list_id + items=[...] in one call.";
431
649
 
432
650
  const TRACKER_TOOL_PROMPT_GUIDELINES = [
433
651
  "Use tracker for todo lists, checklists, and multi-step work. Put progress in tracker, not in prose.",
434
- "Break work into tracker items up front. One item per deliverable. Mark an item done in the same turn it completes. Never batch the marking at the end. Batch related adds and updates in one call — use update_item's list_id + items=[...] form to update several entries in one list at once.",
652
+ "Break work into tracker items up front. One item per deliverable.",
653
+ "Mark each tracker item done in the same turn it completes. Never batch the marking at the end.",
654
+ "Batch related tracker adds and updates in one call: use add_items items=[{title, ...}] and update_items' list_id + items=[...] forms.",
435
655
  "Before starting work, call tracker with action list. Work from the list, not from memory. Re-check it when the task drifts.",
436
656
  "Copy tracker item ids (listName:id, e.g. Work:2) from the list action output. Ids are permanent, so a reference stays valid after a removal.",
437
- "Declare tracker dependencies when one item must wait for another: pass deps (listName:id) on the item, or use the {text, deps} form when creating items. Dependencies live in the same list and must not form a cycle.",
657
+ "Declare refs and produces when you create or update a tracker item: the files, symbols, or decisions the item must read next, and each document it will write. A declaration lets tracker keep the next step moving after completed work leaves the context.",
658
+ "Declare tracker dependencies when one item must wait for another: pass deps (listName:id) on the item, or use the {title, deps} form when creating items.",
659
+ "Dependencies in tracker live in the same list and must not form a cycle.",
438
660
  "Pick up an unblocked tracker item: the list output marks blocked items and ends each list that has dependencies with a Ready now line. Completing a blocked item fails, so finish its dependencies first.",
439
661
  "When a tracker call fails, read the error. It tells you what to fix. Not-found errors name the available ids. Retry with corrected parameters in the same turn. Never repeat the same failing call.",
440
- "The tracker widget shows the active list. create_list makes the new list active by default; pass activate: false to keep the current one. Use set_active to show or hide a list.",
662
+ "The tracker widget shows the active list. create_list makes the new list active by default; pass activate: false to keep the current one.",
663
+ "Use set_active to show a tracker list in the widget, or omit list_id to hide it.",
441
664
  ];
442
665
 
443
666
  /** Metadata block spread into `pi.registerTool` in index.ts. */