@ftrdotdev/pi-tracker 0.4.0 → 0.5.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 +109 -36
- package/package.json +2 -2
- package/src/deps.test.ts +254 -0
- package/src/deps.ts +250 -0
- package/src/domain.test.ts +51 -6
- package/src/domain.ts +159 -13
- package/src/index.test.ts +358 -0
- package/src/index.ts +225 -75
- package/src/persistence.test.ts +105 -6
- package/src/persistence.ts +5 -3
- package/src/store.test.ts +559 -22
- package/src/store.ts +326 -132
- package/src/tool-metadata.test.ts +167 -9
- package/src/tool-metadata.ts +160 -35
- package/src/ui.test.ts +263 -0
- package/src/ui.ts +172 -15
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { Value } from "typebox/value";
|
|
3
|
+
import { TodoItem, TodoList, TrackerState, emptyState } from "./domain.ts";
|
|
3
4
|
import {
|
|
4
5
|
TOOL_ACTIONS,
|
|
5
6
|
TRACKER_TOOL_METADATA,
|
|
6
7
|
TRACKER_TOOL_NAME,
|
|
7
8
|
TrackerToolParams,
|
|
8
9
|
doneMarkReminder,
|
|
10
|
+
blockedDoneNote,
|
|
9
11
|
validateTrackerCall,
|
|
10
12
|
} from "./tool-metadata.ts";
|
|
11
13
|
|
|
@@ -29,8 +31,8 @@ describe("tracker tool parameter schema", () => {
|
|
|
29
31
|
action: "update_item",
|
|
30
32
|
list_id: 1,
|
|
31
33
|
items: [
|
|
32
|
-
{
|
|
33
|
-
{
|
|
34
|
+
{ item_id: "Work:1", done: true },
|
|
35
|
+
{ item_id: "Work:2", text: "New text" },
|
|
34
36
|
],
|
|
35
37
|
},
|
|
36
38
|
{ action: "remove_item", item_id: "Work:2" },
|
|
@@ -59,15 +61,15 @@ describe("tracker tool parameter schema", () => {
|
|
|
59
61
|
Value.Check(TrackerToolParams, {
|
|
60
62
|
action: "update_item",
|
|
61
63
|
list_id: 1,
|
|
62
|
-
items: [{
|
|
64
|
+
items: [{ item_id: 1, done: "yes" }],
|
|
63
65
|
}),
|
|
64
66
|
).toBe(false);
|
|
65
67
|
expect(
|
|
66
68
|
Value.Check(TrackerToolParams, {
|
|
67
|
-
//
|
|
69
|
+
// index inside the batch is the old positional field; patch objects are strict.
|
|
68
70
|
action: "update_item",
|
|
69
71
|
list_id: 1,
|
|
70
|
-
items: [{
|
|
72
|
+
items: [{ index: 1, done: true }],
|
|
71
73
|
}),
|
|
72
74
|
).toBe(false);
|
|
73
75
|
expect(Value.Check(TrackerToolParams, { action: "update_item", item_id: 2 })).toBe(false); // ids are strings
|
|
@@ -101,7 +103,7 @@ describe("validateTrackerCall (error-nudging layer)", () => {
|
|
|
101
103
|
{ action: "add_item", list_id: 1, text: ["a", "b"] },
|
|
102
104
|
{ action: "update_item", item_id: "Work:2" },
|
|
103
105
|
{ action: "update_item", item_id: "Work:2", text: "x", done: true },
|
|
104
|
-
{ action: "update_item", list_id: 1, items: [{
|
|
106
|
+
{ action: "update_item", list_id: 1, items: [{ item_id: "Work:2", done: true }] },
|
|
105
107
|
{ action: "remove_item", item_id: "Work:2" },
|
|
106
108
|
];
|
|
107
109
|
for (const call of valid) {
|
|
@@ -130,7 +132,7 @@ describe("validateTrackerCall (error-nudging layer)", () => {
|
|
|
130
132
|
const batch = validateTrackerCall({
|
|
131
133
|
action: "update_item",
|
|
132
134
|
list_id: 1,
|
|
133
|
-
items: [{
|
|
135
|
+
items: [{ item_id: "Work:2", done: true }],
|
|
134
136
|
});
|
|
135
137
|
expect(batch.ok).toBe(true);
|
|
136
138
|
});
|
|
@@ -155,14 +157,14 @@ describe("validateTrackerCall (error-nudging layer)", () => {
|
|
|
155
157
|
const mixed = validateTrackerCall({
|
|
156
158
|
action: "update_item",
|
|
157
159
|
item_id: "Work:2",
|
|
158
|
-
items: [{
|
|
160
|
+
items: [{ item_id: "Work:3" }],
|
|
159
161
|
});
|
|
160
162
|
expect(mixed.ok).toBe(false);
|
|
161
163
|
if (!mixed.ok) expect(mixed.message).toContain("not both");
|
|
162
164
|
|
|
163
165
|
const missingList = validateTrackerCall({
|
|
164
166
|
action: "update_item",
|
|
165
|
-
items: [{
|
|
167
|
+
items: [{ item_id: "Work:1", done: true }],
|
|
166
168
|
});
|
|
167
169
|
expect(missingList.ok).toBe(false);
|
|
168
170
|
if (!missingList.ok) expect(missingList.message).toContain("list_id");
|
|
@@ -187,6 +189,57 @@ describe("validateTrackerCall (error-nudging layer)", () => {
|
|
|
187
189
|
expect(validateTrackerCall(undefined).ok).toBe(false);
|
|
188
190
|
expect(validateTrackerCall([1]).ok).toBe(false);
|
|
189
191
|
});
|
|
192
|
+
|
|
193
|
+
it("accepts dependency declarations in every shape that supports them", () => {
|
|
194
|
+
const valid: Array<Record<string, unknown>> = [
|
|
195
|
+
{ action: "create_list", name: "Work", initial_items: [{ text: "a", deps: ["Work:1"] }] },
|
|
196
|
+
{
|
|
197
|
+
action: "create_list",
|
|
198
|
+
name: "Work",
|
|
199
|
+
initial_items: ["a", { text: "b", deps: ["Work:1"] }],
|
|
200
|
+
},
|
|
201
|
+
{ action: "add_item", list_id: 1, text: { text: "b", deps: ["Work:1"] } },
|
|
202
|
+
{ action: "add_item", list_id: 1, text: ["a", { text: "b", deps: ["Work:1"] }] },
|
|
203
|
+
{ action: "update_item", item_id: "Work:2", deps: ["Work:1"] },
|
|
204
|
+
{ action: "update_item", item_id: "Work:2", deps: [] },
|
|
205
|
+
{ action: "update_item", list_id: 1, items: [{ item_id: "Work:2", deps: ["Work:1"] }] },
|
|
206
|
+
];
|
|
207
|
+
for (const call of valid) {
|
|
208
|
+
expect(Value.Check(TrackerToolParams, call), JSON.stringify(call)).toBe(true);
|
|
209
|
+
const result = validateTrackerCall(call);
|
|
210
|
+
expect(result.ok, JSON.stringify(call)).toBe(true);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("rejects a deps list on an action that does not accept one", () => {
|
|
215
|
+
const result = validateTrackerCall({ action: "remove_item", item_id: "Work:1", deps: [] });
|
|
216
|
+
expect(result.ok).toBe(false);
|
|
217
|
+
if (!result.ok) {
|
|
218
|
+
expect(result.message).toContain("deps");
|
|
219
|
+
expect(result.message).toContain("item_id");
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("rejects a deps list on add_item, which takes deps inside the item object", () => {
|
|
224
|
+
const result = validateTrackerCall({
|
|
225
|
+
action: "add_item",
|
|
226
|
+
list_id: 1,
|
|
227
|
+
text: "a",
|
|
228
|
+
deps: ["Work:1"],
|
|
229
|
+
});
|
|
230
|
+
expect(result.ok).toBe(false);
|
|
231
|
+
if (!result.ok) expect(result.message).toContain("deps");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("rejects a batch entry that carries both an item_id and a stray index", () => {
|
|
235
|
+
expect(
|
|
236
|
+
Value.Check(TrackerToolParams, {
|
|
237
|
+
action: "update_item",
|
|
238
|
+
list_id: 1,
|
|
239
|
+
items: [{ item_id: "Work:1", index: 1, deps: [] }],
|
|
240
|
+
}),
|
|
241
|
+
).toBe(false);
|
|
242
|
+
});
|
|
190
243
|
});
|
|
191
244
|
|
|
192
245
|
describe("doneMarkReminder (terminal batch done-mark guard)", () => {
|
|
@@ -216,6 +269,99 @@ describe("doneMarkReminder (terminal batch done-mark guard)", () => {
|
|
|
216
269
|
});
|
|
217
270
|
});
|
|
218
271
|
|
|
272
|
+
describe("blockedDoneNote (advisory done-blocked guard)", () => {
|
|
273
|
+
/** A one-list state: `deps[i]` are the refs of item i, ids 1..n. */
|
|
274
|
+
const stateWith = (
|
|
275
|
+
deps: ReadonlyArray<readonly string[]>,
|
|
276
|
+
done: readonly number[],
|
|
277
|
+
): TrackerState =>
|
|
278
|
+
new TrackerState({
|
|
279
|
+
...emptyState(),
|
|
280
|
+
lists: [
|
|
281
|
+
new TodoList({
|
|
282
|
+
id: 1,
|
|
283
|
+
name: "Work",
|
|
284
|
+
nextItemId: deps.length + 1,
|
|
285
|
+
items: deps.map(
|
|
286
|
+
(itemDeps, index) =>
|
|
287
|
+
new TodoItem({
|
|
288
|
+
id: index + 1,
|
|
289
|
+
text: `item ${index + 1}`,
|
|
290
|
+
done: done.includes(index),
|
|
291
|
+
deps: itemDeps,
|
|
292
|
+
}),
|
|
293
|
+
),
|
|
294
|
+
}),
|
|
295
|
+
],
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("notes the done dependents of a reopened item", () => {
|
|
299
|
+
const state = stateWith([[], ["Work:1"]], [1]);
|
|
300
|
+
|
|
301
|
+
const note = blockedDoneNote([{ id: "Work:1", done: false }], state);
|
|
302
|
+
|
|
303
|
+
expect(note).not.toBeNull();
|
|
304
|
+
expect(note).toContain("Work:2");
|
|
305
|
+
expect(note).toContain("done but blocked");
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("is silent when a patch leaves no done item unsatisfied", () => {
|
|
309
|
+
const state = stateWith([[], ["Work:1"]], [1]);
|
|
310
|
+
|
|
311
|
+
expect(blockedDoneNote([{ id: "Work:1", done: true }], state)).toBeNull();
|
|
312
|
+
expect(blockedDoneNote([{ id: "Work:1", text: "new" }], state)).toBeNull();
|
|
313
|
+
expect(blockedDoneNote([], state)).toBeNull();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("notes a done item that a dependency edit left waiting", () => {
|
|
317
|
+
const state = stateWith([[], ["Work:1"]], [1]);
|
|
318
|
+
|
|
319
|
+
const note = blockedDoneNote([{ id: "Work:2", deps: ["Work:1"] }], state);
|
|
320
|
+
|
|
321
|
+
expect(note).not.toBeNull();
|
|
322
|
+
expect(note).toContain("Work:2 is done but now waits on Work:1");
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("is silent when a dependency edit leaves a done item satisfied", () => {
|
|
326
|
+
const done = stateWith([[], ["Work:1"]], [0, 1]);
|
|
327
|
+
expect(blockedDoneNote([{ id: "Work:2", deps: ["Work:1"] }], done)).toBeNull();
|
|
328
|
+
// Clearing is never a problem, and an open item's annotation already
|
|
329
|
+
// reports its own blockers.
|
|
330
|
+
expect(blockedDoneNote([{ id: "Work:2", deps: [] }], done)).toBeNull();
|
|
331
|
+
expect(
|
|
332
|
+
blockedDoneNote([{ id: "Work:2", deps: ["Work:1"] }], stateWith([[], ["Work:1"]], [])),
|
|
333
|
+
).toBeNull();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it("names an item once when a reopen and a dependency edit both hit it", () => {
|
|
337
|
+
const state = stateWith([[], ["Work:1"]], [1]);
|
|
338
|
+
|
|
339
|
+
const note = blockedDoneNote(
|
|
340
|
+
[
|
|
341
|
+
{ id: "Work:1", done: false },
|
|
342
|
+
{ id: "Work:2", deps: ["Work:1"] },
|
|
343
|
+
],
|
|
344
|
+
state,
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
expect(note?.match(/Work:2/g) ?? []).toHaveLength(1);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("is silent when no dependent is done", () => {
|
|
351
|
+
const state = stateWith([[], ["Work:1"]], []);
|
|
352
|
+
|
|
353
|
+
expect(blockedDoneNote([{ id: "Work:1", done: false }], state)).toBeNull();
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("ignores a patch id that does not resolve", () => {
|
|
357
|
+
const state = stateWith([[], ["Work:1"]], [1]);
|
|
358
|
+
|
|
359
|
+
expect(blockedDoneNote([{ id: "?", done: false }], state)).toBeNull();
|
|
360
|
+
expect(blockedDoneNote([{ id: "Other:1", done: false }], state)).toBeNull();
|
|
361
|
+
expect(blockedDoneNote([{ id: "Work:9", done: false }], state)).toBeNull();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
|
|
219
365
|
describe("tracker tool prompt metadata", () => {
|
|
220
366
|
it("every guideline names the tracker tool", () => {
|
|
221
367
|
for (const guideline of TRACKER_TOOL_METADATA.promptGuidelines) {
|
|
@@ -233,6 +379,18 @@ describe("tracker tool prompt metadata", () => {
|
|
|
233
379
|
}
|
|
234
380
|
});
|
|
235
381
|
|
|
382
|
+
it("states the dependency rules in the description", () => {
|
|
383
|
+
expect(TRACKER_TOOL_METADATA.description).toContain("blocked");
|
|
384
|
+
expect(TRACKER_TOOL_METADATA.description).toContain("Ready now");
|
|
385
|
+
expect(TRACKER_TOOL_METADATA.description).toContain("cannot be removed");
|
|
386
|
+
// A dependency-free list carries no blocked-by marker and no Ready now
|
|
387
|
+
// line, so the description has to say what that means.
|
|
388
|
+
expect(TRACKER_TOOL_METADATA.description).toContain("without a blocked-by marker");
|
|
389
|
+
// The done-row annotation and the batch order rule are stated too.
|
|
390
|
+
expect(TRACKER_TOOL_METADATA.description).toContain("waiting on");
|
|
391
|
+
expect(TRACKER_TOOL_METADATA.description).toContain("Patches apply in order");
|
|
392
|
+
});
|
|
393
|
+
|
|
236
394
|
it("runs tool calls sequentially to avoid mutation races", () => {
|
|
237
395
|
expect(TRACKER_TOOL_METADATA.executionMode).toBe("sequential");
|
|
238
396
|
});
|
package/src/tool-metadata.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
7
7
|
import { Type } from "typebox";
|
|
8
8
|
import type { Static } from "typebox";
|
|
9
|
-
import
|
|
9
|
+
import { dependentsOf, formatItemRef, parseItemRef, unsatisfiedDeps } from "./deps.ts";
|
|
10
|
+
import type { TodoItem, TodoList, TrackerState } from "./domain.ts";
|
|
10
11
|
import type { EncodedState } from "./persistence.ts";
|
|
11
12
|
|
|
12
13
|
/** Tracker tool actions, in the same order as the store operations. */
|
|
@@ -25,6 +26,27 @@ export type TrackerToolAction = (typeof TOOL_ACTIONS)[number];
|
|
|
25
26
|
export const TRACKER_TOOL_NAME = "tracker";
|
|
26
27
|
export const TRACKER_TOOL_LABEL = "Tracker";
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* How an item is declared when it is created: bare text, or an object that
|
|
31
|
+
* also carries the same-list items it must wait for.
|
|
32
|
+
*/
|
|
33
|
+
const depsSchema = Type.Array(
|
|
34
|
+
Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }),
|
|
35
|
+
{ description: "Same-list items that must be done before this one." },
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const ItemSpecSchema = Type.Union([
|
|
39
|
+
Type.String({ description: "Item text." }),
|
|
40
|
+
Type.Object(
|
|
41
|
+
{
|
|
42
|
+
text: Type.String({ description: "Item text." }),
|
|
43
|
+
deps: Type.Optional(depsSchema),
|
|
44
|
+
},
|
|
45
|
+
// Item objects are strict: a typo inside one fails here.
|
|
46
|
+
{ additionalProperties: false },
|
|
47
|
+
),
|
|
48
|
+
]);
|
|
49
|
+
|
|
28
50
|
/**
|
|
29
51
|
* Parameter schema for the tracker tool.
|
|
30
52
|
*
|
|
@@ -45,15 +67,16 @@ export const TrackerToolParams = Type.Object({
|
|
|
45
67
|
item_id: Type.Optional(
|
|
46
68
|
Type.String({
|
|
47
69
|
description:
|
|
48
|
-
'Item id, as shown by the list action: listName:
|
|
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.',
|
|
49
71
|
}),
|
|
50
72
|
),
|
|
51
73
|
name: Type.Optional(
|
|
52
74
|
Type.String({ description: "Name for the new list. Required for create_list." }),
|
|
53
75
|
),
|
|
54
76
|
initial_items: Type.Optional(
|
|
55
|
-
Type.Array(
|
|
56
|
-
description:
|
|
77
|
+
Type.Array(ItemSpecSchema, {
|
|
78
|
+
description:
|
|
79
|
+
"For create_list: initial items (text, or {text, deps}), added when the list is created.",
|
|
57
80
|
minItems: 1,
|
|
58
81
|
}),
|
|
59
82
|
),
|
|
@@ -66,40 +89,55 @@ export const TrackerToolParams = Type.Object({
|
|
|
66
89
|
text: Type.Optional(
|
|
67
90
|
Type.Union(
|
|
68
91
|
[
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}),
|
|
73
|
-
Type.Array(Type.String({ description: "Item text." }), {
|
|
74
|
-
description: "For add_item: several item texts to add in one call.",
|
|
92
|
+
ItemSpecSchema,
|
|
93
|
+
Type.Array(ItemSpecSchema, {
|
|
94
|
+
description: "For add_item: several items to add in one call.",
|
|
75
95
|
minItems: 1,
|
|
76
96
|
}),
|
|
77
97
|
],
|
|
78
|
-
{
|
|
98
|
+
{
|
|
99
|
+
description:
|
|
100
|
+
"Item text: a string, an item object {text, deps?}, or (add_item only) an array of either.",
|
|
101
|
+
},
|
|
79
102
|
),
|
|
80
103
|
),
|
|
81
104
|
done: Type.Optional(
|
|
82
105
|
Type.Boolean({ description: "For update_item: true marks the item done, false reopens it." }),
|
|
83
106
|
),
|
|
107
|
+
deps: Type.Optional(
|
|
108
|
+
Type.Array(Type.String({ description: 'A dependency as listName:id, e.g. "Work:1".' }), {
|
|
109
|
+
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.",
|
|
111
|
+
}),
|
|
112
|
+
),
|
|
84
113
|
items: Type.Optional(
|
|
85
114
|
Type.Array(
|
|
86
115
|
Type.Object(
|
|
87
116
|
{
|
|
88
|
-
|
|
117
|
+
item_id: Type.String({
|
|
89
118
|
description:
|
|
90
|
-
'
|
|
119
|
+
'The id of the item within list_id, as shown by the list action (e.g. "Work:2").',
|
|
91
120
|
}),
|
|
92
121
|
text: Type.Optional(Type.String({ description: "Replacement text for the item." })),
|
|
93
122
|
done: Type.Optional(
|
|
94
123
|
Type.Boolean({ description: "true marks the item done, false reopens it." }),
|
|
95
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
|
+
),
|
|
96
134
|
},
|
|
97
135
|
// Patch objects are strict: a typo inside an item update fails here.
|
|
98
136
|
{ additionalProperties: false },
|
|
99
137
|
),
|
|
100
138
|
{
|
|
101
139
|
description:
|
|
102
|
-
"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.",
|
|
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.",
|
|
103
141
|
minItems: 1,
|
|
104
142
|
},
|
|
105
143
|
),
|
|
@@ -115,7 +153,7 @@ const ACTION_PARAMS: Readonly<Record<TrackerToolAction, readonly string[]>> = {
|
|
|
115
153
|
delete_list: ["list_id"],
|
|
116
154
|
set_active: ["list_id"],
|
|
117
155
|
add_item: ["list_id", "text"],
|
|
118
|
-
update_item: ["list_id", "item_id", "text", "done", "items"],
|
|
156
|
+
update_item: ["list_id", "item_id", "text", "done", "deps", "items"],
|
|
119
157
|
remove_item: ["item_id"],
|
|
120
158
|
};
|
|
121
159
|
|
|
@@ -187,16 +225,17 @@ export function validateTrackerCall(args: unknown): TrackerCallValidation {
|
|
|
187
225
|
break;
|
|
188
226
|
case "update_item":
|
|
189
227
|
if (record.items !== undefined) {
|
|
190
|
-
// Batch form: list_id + items (
|
|
228
|
+
// Batch form: list_id + items (id-based, one list).
|
|
191
229
|
if (
|
|
192
230
|
record.item_id !== undefined ||
|
|
193
231
|
record.text !== undefined ||
|
|
194
|
-
record.done !== undefined
|
|
232
|
+
record.done !== undefined ||
|
|
233
|
+
record.deps !== undefined
|
|
195
234
|
) {
|
|
196
235
|
return {
|
|
197
236
|
ok: false,
|
|
198
237
|
message:
|
|
199
|
-
"update_item: pass either item_id/text/done (one item) or list_id + items (several items in one list), not both.",
|
|
238
|
+
"update_item: pass either item_id/text/done/deps (one item) or list_id + items (several items in one list), not both.",
|
|
200
239
|
};
|
|
201
240
|
}
|
|
202
241
|
if (record.list_id === undefined) {
|
|
@@ -212,7 +251,7 @@ export function validateTrackerCall(args: unknown): TrackerCallValidation {
|
|
|
212
251
|
message:
|
|
213
252
|
"update_item requires 'item_id' (one item) or 'list_id' + 'items' (several items in one list).",
|
|
214
253
|
};
|
|
215
|
-
} else if (
|
|
254
|
+
} else if (record.text !== undefined && typeof record.text !== "string") {
|
|
216
255
|
return {
|
|
217
256
|
ok: false,
|
|
218
257
|
message:
|
|
@@ -238,7 +277,7 @@ export interface TrackerToolDetails {
|
|
|
238
277
|
action: TrackerToolAction;
|
|
239
278
|
error?: string;
|
|
240
279
|
listId?: number;
|
|
241
|
-
/** `listName:
|
|
280
|
+
/** `listName:id`, as shown by the list action. */
|
|
242
281
|
itemId?: string;
|
|
243
282
|
list?: TodoList;
|
|
244
283
|
/** Items affected by an add_item/update_item call, in creation/patch order. */
|
|
@@ -247,6 +286,78 @@ export interface TrackerToolDetails {
|
|
|
247
286
|
snapshot?: EncodedState;
|
|
248
287
|
}
|
|
249
288
|
|
|
289
|
+
/**
|
|
290
|
+
* One applied `update_item` patch, as the advisory helpers need it: the display
|
|
291
|
+
* id plus whatever fields the caller changed.
|
|
292
|
+
*/
|
|
293
|
+
export interface AppliedUpdatePatch {
|
|
294
|
+
readonly id: string;
|
|
295
|
+
readonly text?: string;
|
|
296
|
+
readonly done?: boolean;
|
|
297
|
+
readonly deps?: readonly string[];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Advisory note for a call that leaves a done item unsatisfied, which the two
|
|
302
|
+
* edit paths can do:
|
|
303
|
+
*
|
|
304
|
+
* - A reopen (`done: false`): the reopen does not cascade, so its done
|
|
305
|
+
* dependents stay done and are now blocked.
|
|
306
|
+
* - A dependency edit (`deps`): a done item can be given a dependency that is
|
|
307
|
+
* still open, and nothing else would report it.
|
|
308
|
+
*
|
|
309
|
+
* Returns null when neither applies. Advisory text, never a rejection. Each
|
|
310
|
+
* affected item is named once, so a batch that hits both paths still produces
|
|
311
|
+
* one sentence about it.
|
|
312
|
+
*
|
|
313
|
+
* @param patches the update_item patches that were applied, in call order.
|
|
314
|
+
* @param state the state after the call. A reopen only changes the reopened
|
|
315
|
+
* item and a dependency edit only changes the patched item, so the other
|
|
316
|
+
* items' done flags are the same before and after.
|
|
317
|
+
*/
|
|
318
|
+
export const blockedDoneNote = (
|
|
319
|
+
patches: readonly AppliedUpdatePatch[],
|
|
320
|
+
state: TrackerState,
|
|
321
|
+
): string | null => {
|
|
322
|
+
const notes: string[] = [];
|
|
323
|
+
const reported = new Set<string>();
|
|
324
|
+
for (const patch of patches) {
|
|
325
|
+
const parsed = parseItemRef(patch.id);
|
|
326
|
+
if (parsed === null) continue;
|
|
327
|
+
const list = state.lists.find((candidate) => candidate.name === parsed.name);
|
|
328
|
+
if (list === undefined) continue;
|
|
329
|
+
const index = list.items.findIndex((item) => item.id === parsed.id);
|
|
330
|
+
if (index === -1) continue;
|
|
331
|
+
if (patch.done === false) {
|
|
332
|
+
const blocked = dependentsOf(list, index)
|
|
333
|
+
.filter((dependent) => list.items[dependent]!.done)
|
|
334
|
+
.map((dependent) => formatItemRef(list.name, list.items[dependent]!.id))
|
|
335
|
+
.filter((ref) => !reported.has(ref));
|
|
336
|
+
if (blocked.length > 0) {
|
|
337
|
+
for (const ref of blocked) reported.add(ref);
|
|
338
|
+
const one = blocked.length === 1;
|
|
339
|
+
notes.push(
|
|
340
|
+
`Note: ${patch.id} is open again, so ${blocked.join(", ")} ` +
|
|
341
|
+
`${one ? "is" : "are"} done but blocked. Reopen or re-plan ${one ? "it" : "them"}.`,
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (patch.deps !== undefined && list.items[index]!.done && !reported.has(patch.id)) {
|
|
346
|
+
const open = unsatisfiedDeps(list, index);
|
|
347
|
+
if (open.length > 0) {
|
|
348
|
+
reported.add(patch.id);
|
|
349
|
+
const one = open.length === 1;
|
|
350
|
+
notes.push(
|
|
351
|
+
`Note: ${patch.id} is done but now waits on ${open.join(", ")}, ` +
|
|
352
|
+
`${one ? "which is" : "which are"} still open. Reopen it or clear ` +
|
|
353
|
+
`${one ? "that dependency" : "those dependencies"}.`,
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return notes.length === 0 ? null : notes.join("\n");
|
|
359
|
+
};
|
|
360
|
+
|
|
250
361
|
/**
|
|
251
362
|
* Anti-pattern guard: the tracker guideline says to mark each item done in
|
|
252
363
|
* the same turn it completes and never batch the marking at the end. A call
|
|
@@ -282,25 +393,37 @@ const TRACKER_TOOL_DESCRIPTION =
|
|
|
282
393
|
"Manage todolists and track progress. Use for task lists, checklists, milestones, and step-by-step " +
|
|
283
394
|
"work; keep track of tasks with tracker instead of in chat or files. Work through items one at a " +
|
|
284
395
|
"time, marking each done as it completes, so the list always shows current progress.\n" +
|
|
285
|
-
'Item ids are listName:
|
|
286
|
-
"
|
|
287
|
-
"
|
|
396
|
+
'Item ids are listName:id, e.g. "Work:2" (copy them from the list action output). Ids are ' +
|
|
397
|
+
"permanent: removing an item does not change the other ids, so a reference you already hold " +
|
|
398
|
+
"stays valid.\n" +
|
|
399
|
+
"An item takes an optional deps list of same-list ids that must be done before it. Dependencies " +
|
|
400
|
+
"must form a DAG: a dependency that would close a cycle is rejected and the error names the " +
|
|
401
|
+
"cycle. The list action marks an open item that waits with (blocked by ...), marks a done item " +
|
|
402
|
+
"whose dependency is open with (waiting on ...), and ends each list that has dependencies with " +
|
|
403
|
+
"a Ready now line. A list without a blocked-by marker has nothing blocked; the Ready now line " +
|
|
404
|
+
"appears once a list carries dependencies.\n" +
|
|
405
|
+
"Completing a blocked item is refused, so an item can only be picked up once its dependencies " +
|
|
406
|
+
"are done. An item that other items depend on cannot be removed until those dependencies change. " +
|
|
407
|
+
"Reopening an item does not cascade, and a deps edit can leave a done item waiting: the result " +
|
|
408
|
+
"notes any done item left unsatisfied.\n" +
|
|
288
409
|
"The tracker tool is strict: each action accepts only its own parameters — any other argument is " +
|
|
289
410
|
"rejected. Parameter contract per action:\n" +
|
|
290
411
|
"- list: no parameters\n" +
|
|
291
|
-
"- create_list: name (required), initial_items (optional array of
|
|
292
|
-
"list is created), activate (optional, defaults to true: the new
|
|
293
|
-
"to keep the current active list)\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" +
|
|
294
415
|
"- delete_list: list_id (required)\n" +
|
|
295
416
|
"- set_active: list_id (omit the field to deselect)\n" +
|
|
296
|
-
"- add_item: list_id (required), text (required: a string,
|
|
297
|
-
"items in one call)\n" +
|
|
298
|
-
"- update_item: update several items in one list with list_id (required) + items=[{
|
|
299
|
-
"text?, done?}, ...] — just like add_item's list_id + text[] (
|
|
300
|
-
"
|
|
301
|
-
"
|
|
302
|
-
"the
|
|
303
|
-
"
|
|
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)";
|
|
304
427
|
|
|
305
428
|
const TRACKER_TOOL_PROMPT_SNIPPET =
|
|
306
429
|
"Manage todolists and track progress: create lists with initial items, add/update/remove items. " +
|
|
@@ -310,7 +433,9 @@ const TRACKER_TOOL_PROMPT_GUIDELINES = [
|
|
|
310
433
|
"Use tracker for todo lists, checklists, and multi-step work. Put progress in tracker, not in prose.",
|
|
311
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.",
|
|
312
435
|
"Before starting work, call tracker with action list. Work from the list, not from memory. Re-check it when the task drifts.",
|
|
313
|
-
"Copy tracker item ids (listName:
|
|
436
|
+
"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.",
|
|
438
|
+
"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.",
|
|
314
439
|
"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.",
|
|
315
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.",
|
|
316
441
|
];
|