@ftrdotdev/pi-tracker 0.6.0 → 0.7.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/src/index.test.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Bridge tests for `src/index.ts`. The store and the planner have their own
3
3
  * suites; these tests pin the thin wiring between them, including the result
4
- * contract that both `update_item` forms report an affected-items array. That
4
+ * contract that both `update_items` forms report an affected-items array. That
5
5
  * contract broke once: the scalar form returned one `TodoItem`, the renderer
6
6
  * called `.map` on it, and the tool failed with `items.map is not a function`.
7
7
  */
@@ -11,6 +11,7 @@ import {
11
11
  type CompactOptions,
12
12
  type ExtensionAPI,
13
13
  type ExtensionToolContext,
14
+ type Theme,
14
15
  type ToolDefinition,
15
16
  } from "@earendil-works/pi-coding-agent";
16
17
  import type {
@@ -215,16 +216,40 @@ const textOf = (result: AgentToolResult<TrackerToolDetails>): string => {
215
216
  return block?.type === "text" ? block.text : "";
216
217
  };
217
218
 
219
+ /** Identity theme: styles pass text through, so assertions search plain text. */
220
+ const identityTheme = {
221
+ fg: (_color: string, text: string): string => text,
222
+ bold: (text: string): string => text,
223
+ strikethrough: (text: string): string => text,
224
+ style: (text: string): string => text,
225
+ } as unknown as Theme;
226
+
227
+ /** Render a tool result through the registered `renderResult`. */
228
+ const renderList = (
229
+ harness: Harness,
230
+ result: AgentToolResult<TrackerToolDetails>,
231
+ expanded: boolean,
232
+ ): string =>
233
+ harness.tool.renderResult!(
234
+ result,
235
+ { expanded, isPartial: false },
236
+ identityTheme,
237
+ harness.ctx as never,
238
+ )
239
+ .render(400)
240
+ .join("\n")
241
+ .replace(/\s+/g, " ");
242
+
218
243
  describe("tracker tool bridge", () => {
219
- it("returns an affected-items array for the scalar update_item form", async () => {
244
+ it("returns an affected-items array for the scalar update_items form", async () => {
220
245
  const harness = await makeHarness();
221
246
  await run(harness, {
222
247
  action: "create_list",
223
248
  name: "Work",
224
- initial_items: ["write plan", "ship it"],
249
+ initial_items: [{ title: "write plan" }, { title: "ship it" }],
225
250
  });
226
251
 
227
- const result = await run(harness, { action: "update_item", item_id: "Work:1", done: true });
252
+ const result = await run(harness, { action: "update_items", item_id: "Work:1", done: true });
228
253
 
229
254
  expect(result.details?.items).toHaveLength(1);
230
255
  expect(result.details?.items?.[0]?.done).toBe(true);
@@ -232,33 +257,37 @@ describe("tracker tool bridge", () => {
232
257
  expect(textOf(result)).toContain("Work:1 (completed)");
233
258
  });
234
259
 
235
- it("keeps the text patch for the scalar update_item form", async () => {
260
+ it("keeps the title patch for the scalar update_items form", async () => {
236
261
  const harness = await makeHarness();
237
- await run(harness, { action: "create_list", name: "Work", initial_items: ["old"] });
262
+ await run(harness, { action: "create_list", name: "Work", initial_items: [{ title: "old" }] });
238
263
 
239
- const result = await run(harness, { action: "update_item", item_id: "Work:1", text: "new" });
264
+ const result = await run(harness, { action: "update_items", item_id: "Work:1", title: "new" });
240
265
 
241
266
  expect(result.details?.items).toHaveLength(1);
242
- expect(result.details?.items?.[0]?.text).toBe("new");
243
- expect(textOf(result)).toContain("Work:1 (text: new)");
267
+ expect(result.details?.items?.[0]?.title).toBe("new");
268
+ expect(textOf(result)).toContain("Work:1 (title: new)");
244
269
  });
245
270
 
246
- it("returns one entry per patch for the batch update_item form", async () => {
271
+ it("returns one entry per patch for the batch update_items form", async () => {
247
272
  const harness = await makeHarness();
248
- await run(harness, { action: "create_list", name: "Work", initial_items: ["a", "b", "c"] });
273
+ await run(harness, {
274
+ action: "create_list",
275
+ name: "Work",
276
+ initial_items: [{ title: "a" }, { title: "b" }, { title: "c" }],
277
+ });
249
278
 
250
279
  const result = await run(harness, {
251
- action: "update_item",
280
+ action: "update_items",
252
281
  list_id: 1,
253
282
  items: [
254
283
  { item_id: "Work:1", done: true },
255
- { item_id: "Work:3", text: "cee" },
284
+ { item_id: "Work:3", title: "cee" },
256
285
  ],
257
286
  });
258
287
 
259
288
  expect(result.details?.items).toHaveLength(2);
260
289
  expect(textOf(result)).toContain("Updated 2 items");
261
- expect(textOf(result)).toContain("Work:3 (text: cee)");
290
+ expect(textOf(result)).toContain("Work:3 (title: cee)");
262
291
  });
263
292
 
264
293
  it("shows id-based references in the list output", async () => {
@@ -266,10 +295,10 @@ describe("tracker tool bridge", () => {
266
295
  await run(harness, {
267
296
  action: "create_list",
268
297
  name: "Work",
269
- initial_items: ["write plan", "ship it"],
298
+ initial_items: [{ title: "write plan" }, { title: "ship it" }],
270
299
  });
271
300
 
272
- await run(harness, { action: "update_item", item_id: "Work:2", done: true });
301
+ await run(harness, { action: "update_items", item_id: "Work:2", done: true });
273
302
  const result = await run(harness, { action: "list" });
274
303
 
275
304
  expect(textOf(result)).toContain("[x] #Work:2: ship it");
@@ -277,7 +306,11 @@ describe("tracker tool bridge", () => {
277
306
 
278
307
  it("shows stable ids after a removal", async () => {
279
308
  const harness = await makeHarness();
280
- await run(harness, { action: "create_list", name: "Work", initial_items: ["a", "b", "c"] });
309
+ await run(harness, {
310
+ action: "create_list",
311
+ name: "Work",
312
+ initial_items: [{ title: "a" }, { title: "b" }, { title: "c" }],
313
+ });
281
314
 
282
315
  await run(harness, { action: "remove_item", item_id: "Work:1" });
283
316
  const result = await run(harness, { action: "list" });
@@ -288,11 +321,26 @@ describe("tracker tool bridge", () => {
288
321
  expect(textOf(result)).not.toContain("#Work:1");
289
322
  });
290
323
 
324
+ it("shows the full description in the expanded list view", async () => {
325
+ const harness = await makeHarness();
326
+ const description = "detail ".repeat(30).trim();
327
+ await run(harness, { action: "create_list", name: "Work" });
328
+ await run(harness, {
329
+ action: "add_items",
330
+ list_id: 1,
331
+ items: [{ title: "big", description }],
332
+ });
333
+ const result = await run(harness, { action: "list" });
334
+
335
+ expect(renderList(harness, result, true)).toContain(description);
336
+ expect(renderList(harness, result, false)).not.toContain(description);
337
+ });
338
+
291
339
  it("reports an error result for a missing item instead of throwing", async () => {
292
340
  const harness = await makeHarness();
293
- await run(harness, { action: "create_list", name: "Work", initial_items: ["only"] });
341
+ await run(harness, { action: "create_list", name: "Work", initial_items: [{ title: "only" }] });
294
342
 
295
- const result = await run(harness, { action: "update_item", item_id: "Work:9", done: true });
343
+ const result = await run(harness, { action: "update_items", item_id: "Work:9", done: true });
296
344
 
297
345
  expect(result.details?.error).toContain("Work:9");
298
346
  expect(result.content[0]).toMatchObject({ type: "text" });
@@ -303,13 +351,13 @@ describe("tracker tool bridge", () => {
303
351
  await run(harness, {
304
352
  action: "create_list",
305
353
  name: "Work",
306
- initial_items: ["a", { text: "b", deps: ["Work:1"] }],
354
+ initial_items: [{ title: "a" }, { title: "b", deps: ["Work:1"] }],
307
355
  });
308
356
 
309
357
  const added = await run(harness, {
310
- action: "add_item",
358
+ action: "add_items",
311
359
  list_id: 1,
312
- text: { text: "c", deps: ["Work:2"] },
360
+ items: [{ title: "c", deps: ["Work:2"] }],
313
361
  });
314
362
 
315
363
  expect(added.details?.error).toBeUndefined();
@@ -317,14 +365,46 @@ describe("tracker tool bridge", () => {
317
365
  expect(textOf(added)).toContain("Work:3");
318
366
  });
319
367
 
368
+ it("carries every nested object field on add_items", async () => {
369
+ const harness = await makeHarness();
370
+ await run(harness, {
371
+ action: "create_list",
372
+ name: "Work",
373
+ initial_items: [{ title: "a" }, { title: "b" }],
374
+ });
375
+
376
+ const added = await run(harness, {
377
+ action: "add_items",
378
+ list_id: 1,
379
+ items: [
380
+ {
381
+ title: "Wire the promotion script",
382
+ description: "Add evals/promote.ts.",
383
+ refs: [{ kind: "path", path: "evals/rules.ts" }],
384
+ produces: [{ path: "evals/promote.ts" }],
385
+ deps: ["Work:1"],
386
+ },
387
+ ],
388
+ });
389
+
390
+ expect(added.details?.error).toBeUndefined();
391
+ expect(added.details?.items?.[0]).toMatchObject({
392
+ title: "Wire the promotion script",
393
+ description: "Add evals/promote.ts.",
394
+ refs: [{ kind: "path", path: "evals/rules.ts" }],
395
+ produces: [{ path: "evals/promote.ts" }],
396
+ deps: ["Work:1"],
397
+ });
398
+ });
399
+
320
400
  it("rejects a malformed dependency reference with an actionable message", async () => {
321
401
  const harness = await makeHarness();
322
- await run(harness, { action: "create_list", name: "Work", initial_items: ["a"] });
402
+ await run(harness, { action: "create_list", name: "Work", initial_items: [{ title: "a" }] });
323
403
 
324
404
  const result = await run(harness, {
325
- action: "add_item",
405
+ action: "add_items",
326
406
  list_id: 1,
327
- text: { text: "b", deps: ["nonsense"] },
407
+ items: [{ title: "b", deps: ["nonsense"] }],
328
408
  });
329
409
 
330
410
  expect(result.details?.error).toContain("listName:id");
@@ -335,11 +415,11 @@ describe("tracker tool bridge", () => {
335
415
  await run(harness, {
336
416
  action: "create_list",
337
417
  name: "Work",
338
- initial_items: ["a", { text: "b", deps: ["Work:1"] }],
418
+ initial_items: [{ title: "a" }, { title: "b", deps: ["Work:1"] }],
339
419
  });
340
420
 
341
421
  const result = await run(harness, {
342
- action: "update_item",
422
+ action: "update_items",
343
423
  item_id: "Work:1",
344
424
  deps: ["Work:2"],
345
425
  });
@@ -353,7 +433,11 @@ describe("tracker tool bridge", () => {
353
433
  await run(harness, {
354
434
  action: "create_list",
355
435
  name: "Work",
356
- initial_items: ["a", { text: "b", deps: ["Work:1"] }, { text: "c", deps: ["Work:2"] }],
436
+ initial_items: [
437
+ { title: "a" },
438
+ { title: "b", deps: ["Work:1"] },
439
+ { title: "c", deps: ["Work:2"] },
440
+ ],
357
441
  });
358
442
 
359
443
  const text = textOf(await run(harness, { action: "list" }));
@@ -365,7 +449,11 @@ describe("tracker tool bridge", () => {
365
449
 
366
450
  it("leaves the list output untouched for a dependency-free list", async () => {
367
451
  const harness = await makeHarness();
368
- await run(harness, { action: "create_list", name: "Work", initial_items: ["a", "b"] });
452
+ await run(harness, {
453
+ action: "create_list",
454
+ name: "Work",
455
+ initial_items: [{ title: "a" }, { title: "b" }],
456
+ });
369
457
 
370
458
  const text = textOf(await run(harness, { action: "list" }));
371
459
 
@@ -379,10 +467,10 @@ describe("tracker tool bridge", () => {
379
467
  await run(harness, {
380
468
  action: "create_list",
381
469
  name: "Work",
382
- initial_items: ["a", { text: "b", deps: ["Work:1"] }],
470
+ initial_items: [{ title: "a" }, { title: "b", deps: ["Work:1"] }],
383
471
  });
384
472
 
385
- const result = await run(harness, { action: "update_item", item_id: "Work:2", done: true });
473
+ const result = await run(harness, { action: "update_items", item_id: "Work:2", done: true });
386
474
 
387
475
  expect(result.details?.error).toContain("Work:1");
388
476
  expect(result.details?.error).toContain("blocked");
@@ -393,13 +481,13 @@ describe("tracker tool bridge", () => {
393
481
  await run(harness, {
394
482
  action: "create_list",
395
483
  name: "Work",
396
- initial_items: ["a", { text: "b", deps: ["Work:1"] }],
484
+ initial_items: [{ title: "a" }, { title: "b", deps: ["Work:1"] }],
397
485
  });
398
- await run(harness, { action: "update_item", item_id: "Work:1", done: true });
399
- await run(harness, { action: "update_item", item_id: "Work:2", done: true });
486
+ await run(harness, { action: "update_items", item_id: "Work:1", done: true });
487
+ await run(harness, { action: "update_items", item_id: "Work:2", done: true });
400
488
 
401
489
  const text = textOf(
402
- await run(harness, { action: "update_item", item_id: "Work:1", done: false }),
490
+ await run(harness, { action: "update_items", item_id: "Work:1", done: false }),
403
491
  );
404
492
 
405
493
  expect(text).toContain("Note:");
@@ -411,12 +499,12 @@ describe("tracker tool bridge", () => {
411
499
  await run(harness, {
412
500
  action: "create_list",
413
501
  name: "Work",
414
- initial_items: ["a", { text: "b", deps: ["Work:1"] }],
502
+ initial_items: [{ title: "a" }, { title: "b", deps: ["Work:1"] }],
415
503
  });
416
- await run(harness, { action: "update_item", item_id: "Work:1", done: true });
504
+ await run(harness, { action: "update_items", item_id: "Work:1", done: true });
417
505
 
418
506
  const text = textOf(
419
- await run(harness, { action: "update_item", item_id: "Work:1", done: false }),
507
+ await run(harness, { action: "update_items", item_id: "Work:1", done: false }),
420
508
  );
421
509
 
422
510
  expect(text).not.toContain("Note:");
@@ -427,11 +515,11 @@ describe("tracker tool bridge", () => {
427
515
  await run(harness, {
428
516
  action: "create_list",
429
517
  name: "Work",
430
- initial_items: ["a", { text: "b", deps: ["Work:1"] }],
518
+ initial_items: [{ title: "a" }, { title: "b", deps: ["Work:1"] }],
431
519
  });
432
- await run(harness, { action: "update_item", item_id: "Work:1", done: true });
433
- await run(harness, { action: "update_item", item_id: "Work:2", done: true });
434
- await run(harness, { action: "update_item", item_id: "Work:1", done: false });
520
+ await run(harness, { action: "update_items", item_id: "Work:1", done: true });
521
+ await run(harness, { action: "update_items", item_id: "Work:2", done: true });
522
+ await run(harness, { action: "update_items", item_id: "Work:1", done: false });
435
523
 
436
524
  const text = textOf(await run(harness, { action: "list" }));
437
525
 
@@ -443,11 +531,15 @@ describe("tracker tool bridge", () => {
443
531
 
444
532
  it("notes a done item that a dependency edit left waiting", async () => {
445
533
  const harness = await makeHarness();
446
- await run(harness, { action: "create_list", name: "Work", initial_items: ["a", "b"] });
447
- await run(harness, { action: "update_item", item_id: "Work:2", done: true });
534
+ await run(harness, {
535
+ action: "create_list",
536
+ name: "Work",
537
+ initial_items: [{ title: "a" }, { title: "b" }],
538
+ });
539
+ await run(harness, { action: "update_items", item_id: "Work:2", done: true });
448
540
 
449
541
  const text = textOf(
450
- await run(harness, { action: "update_item", item_id: "Work:2", deps: ["Work:1"] }),
542
+ await run(harness, { action: "update_items", item_id: "Work:2", deps: ["Work:1"] }),
451
543
  );
452
544
 
453
545
  expect(text).toContain("Note: Work:2 is done but now waits on Work:1");
@@ -458,15 +550,15 @@ describe("tracker tool bridge", () => {
458
550
  await run(harness, {
459
551
  action: "create_list",
460
552
  name: "Work",
461
- initial_items: ["a", { text: "b", deps: ["Work:1"] }, "c"],
553
+ initial_items: [{ title: "a" }, { title: "b", deps: ["Work:1"] }, { title: "c" }],
462
554
  });
463
555
 
464
- const cleared = await run(harness, { action: "update_item", item_id: "Work:2", deps: [] });
556
+ const cleared = await run(harness, { action: "update_items", item_id: "Work:2", deps: [] });
465
557
  expect(textOf(cleared)).toContain("deps cleared (was Work:1)");
466
558
 
467
- await run(harness, { action: "update_item", item_id: "Work:2", deps: ["Work:1"] });
559
+ await run(harness, { action: "update_items", item_id: "Work:2", deps: ["Work:1"] });
468
560
  const replaced = await run(harness, {
469
- action: "update_item",
561
+ action: "update_items",
470
562
  item_id: "Work:2",
471
563
  deps: ["Work:3"],
472
564
  });
@@ -475,13 +567,17 @@ describe("tracker tool bridge", () => {
475
567
 
476
568
  it("persists overlapping mutations in order", async () => {
477
569
  const harness = await makeHarness();
478
- await run(harness, { action: "create_list", name: "Work", initial_items: ["a", "b"] });
570
+ await run(harness, {
571
+ action: "create_list",
572
+ name: "Work",
573
+ initial_items: [{ title: "a" }, { title: "b" }],
574
+ });
479
575
 
480
576
  // Two calls in flight at once. The last snapshot the session receives must
481
577
  // be the state after both, or a later restore resurrects an older one.
482
578
  await Promise.all([
483
- run(harness, { action: "update_item", item_id: "Work:1", done: true }),
484
- run(harness, { action: "update_item", item_id: "Work:2", done: true }),
579
+ run(harness, { action: "update_items", item_id: "Work:1", done: true }),
580
+ run(harness, { action: "update_items", item_id: "Work:2", done: true }),
485
581
  ]);
486
582
 
487
583
  const last = harness.appends.at(-1) as {
@@ -499,7 +595,7 @@ describe("tracker tool bridge", () => {
499
595
  await run(harness, {
500
596
  action: "create_list",
501
597
  name: "Work",
502
- initial_items: [{ text: "ship", deps: ["Work:2"] }, "write plan"],
598
+ initial_items: [{ title: "ship", deps: ["Work:2"] }, { title: "write plan" }],
503
599
  });
504
600
 
505
601
  const text = textOf(await run(harness, { action: "list" }));
@@ -533,9 +629,9 @@ describe("tracker smart-compaction bridge", () => {
533
629
  await run(harness, {
534
630
  action: "create_list",
535
631
  name: "Work",
536
- initial_items: ["first", { text: "second", deps: ["Work:1"] }],
632
+ initial_items: [{ title: "first" }, { title: "second", deps: ["Work:1"] }],
537
633
  });
538
- await run(harness, { action: "update_item", item_id: "Work:1", done: true });
634
+ await run(harness, { action: "update_items", item_id: "Work:1", done: true });
539
635
  };
540
636
 
541
637
  it("a completed item with a compact verdict starts pi's compaction at the settle boundary", async () => {
@@ -559,10 +655,10 @@ describe("tracker smart-compaction bridge", () => {
559
655
  expect(harness.compacts).toHaveLength(0);
560
656
  });
561
657
 
562
- it("a raised keepContextThreshold compacts an answer the default would keep", async () => {
658
+ it("a raised needsContextProbabilityThreshold compacts an answer the default would keep", async () => {
563
659
  const harness = await makeHarness({
564
660
  registry: compactRegistry(0.6),
565
- config: { smartCompaction: { keepContextThreshold: 0.9 } },
661
+ config: { smartCompaction: { needsContextProbabilityThreshold: 0.9 } },
566
662
  });
567
663
  await completeFirst(harness);
568
664
 
@@ -571,10 +667,10 @@ describe("tracker smart-compaction bridge", () => {
571
667
  expect(harness.compacts).toHaveLength(1);
572
668
  });
573
669
 
574
- it("a lowered keepContextThreshold keeps an answer the default would compact", async () => {
670
+ it("a lowered needsContextProbabilityThreshold keeps an answer the default would compact", async () => {
575
671
  const harness = await makeHarness({
576
672
  registry: compactRegistry(0.45),
577
- config: { smartCompaction: { keepContextThreshold: 0.2 } },
673
+ config: { smartCompaction: { needsContextProbabilityThreshold: 0.2 } },
578
674
  });
579
675
  await completeFirst(harness);
580
676
 
@@ -586,7 +682,7 @@ describe("tracker smart-compaction bridge", () => {
586
682
  it("keeps context when the classifier answer is below the confidence floor", async () => {
587
683
  const harness = await makeHarness({
588
684
  registry: compactRegistry(0.1, undefined, 0.2),
589
- config: { smartCompaction: { keepContextMinConfidence: 0.9 } },
685
+ config: { smartCompaction: { minAnswerConfidence: 0.9 } },
590
686
  });
591
687
  await completeFirst(harness);
592
688
 
@@ -598,7 +694,7 @@ describe("tracker smart-compaction bridge", () => {
598
694
  it("compacts when the classifier answer reaches the confidence floor", async () => {
599
695
  const harness = await makeHarness({
600
696
  registry: compactRegistry(0.1, undefined, 0.9),
601
- config: { smartCompaction: { keepContextMinConfidence: 0.5 } },
697
+ config: { smartCompaction: { minAnswerConfidence: 0.5 } },
602
698
  });
603
699
  await completeFirst(harness);
604
700
 
@@ -642,9 +738,13 @@ describe("tracker smart-compaction bridge", () => {
642
738
  await run(harness, {
643
739
  action: "create_list",
644
740
  name: "Work",
645
- initial_items: ["first", { text: "second", deps: ["Work:1"] }, "third"],
741
+ initial_items: [
742
+ { title: "first" },
743
+ { title: "second", deps: ["Work:1"] },
744
+ { title: "third" },
745
+ ],
646
746
  });
647
- await run(harness, { action: "update_item", item_id: "Work:1", done: true });
747
+ await run(harness, { action: "update_items", item_id: "Work:1", done: true });
648
748
 
649
749
  await harness.settle();
650
750
 
@@ -657,9 +757,13 @@ describe("tracker smart-compaction bridge", () => {
657
757
  await run(harness, {
658
758
  action: "create_list",
659
759
  name: "Work",
660
- initial_items: ["first", { text: "second", deps: ["Work:1"] }, "third"],
760
+ initial_items: [
761
+ { title: "first" },
762
+ { title: "second", deps: ["Work:1"] },
763
+ { title: "third" },
764
+ ],
661
765
  });
662
- await run(harness, { action: "update_item", item_id: "Work:1", done: true });
766
+ await run(harness, { action: "update_items", item_id: "Work:1", done: true });
663
767
 
664
768
  await harness.settle();
665
769
 
@@ -711,7 +815,7 @@ describe("tracker smart-compaction bridge", () => {
711
815
  await run(harness, {
712
816
  action: "create_list",
713
817
  name: "Work",
714
- initial_items: ["first", { text: "second", deps: ["Work:1"] }],
818
+ initial_items: [{ title: "first" }, { title: "second", deps: ["Work:1"] }],
715
819
  });
716
820
 
717
821
  await harness.settle();
@@ -813,10 +917,10 @@ describe("tracker smart-compaction bridge", () => {
813
917
  await run(harness, {
814
918
  action: "create_list",
815
919
  name: "Work",
816
- initial_items: ["first", { text: "second", deps: ["Work:1"] }],
920
+ initial_items: [{ title: "first" }, { title: "second", deps: ["Work:1"] }],
817
921
  });
818
922
 
819
- const result = await run(harness, { action: "update_item", item_id: "Work:1", done: true });
923
+ const result = await run(harness, { action: "update_items", item_id: "Work:1", done: true });
820
924
  const appendsBefore = harness.appends.length;
821
925
 
822
926
  await harness.settle();