@andares/pi-toolkits 1.2.5 → 1.3.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.
@@ -27,9 +27,28 @@ afterEach(() => {
27
27
  });
28
28
 
29
29
  let counter = 0;
30
+
31
+ /**
32
+ * Local ISO timestamp with seconds and the machine's own offset.
33
+ *
34
+ * Tests must not hardcode `+08:00`: records are written in local time, and a
35
+ * fixed offset silently shifts every comparison by the machine's timezone.
36
+ */
37
+ function isoSeconds(date: Date): string {
38
+ const pad = (value: number): string => String(value).padStart(2, "0");
39
+ const offset = -date.getTimezoneOffset();
40
+ const sign = offset >= 0 ? "+" : "-";
41
+ const absolute = Math.abs(offset);
42
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(
43
+ date.getHours(),
44
+ )}:${pad(date.getMinutes())}:${pad(date.getSeconds())}${sign}${pad(
45
+ Math.floor(absolute / 60),
46
+ )}:${pad(absolute % 60)}`;
47
+ }
48
+
30
49
  function event<T extends Omit<UatEvent, "v" | "id" | "ts">>(
31
50
  body: T,
32
- ts = "2026-11-13T21:00+08:00",
51
+ ts = isoSeconds(new Date(2026, 10, 13, 21, 0)),
33
52
  ): UatEvent {
34
53
  counter += 1;
35
54
  return { v: 1, id: `e-test-${counter}`, ts, ...body } as unknown as UatEvent;
@@ -43,7 +62,11 @@ function candidate(report: string, behavior = "operator sees it"): CandidateEven
43
62
  return event({ type: "candidate", report, title: report, behavior }) as CandidateEvent;
44
63
  }
45
64
 
46
- function item(id: string, reports: string[], ts = "2026-11-13T21:00+08:00"): ItemEvent {
65
+ function item(
66
+ id: string,
67
+ reports: string[],
68
+ ts = isoSeconds(new Date(2026, 10, 13, 21, 0)),
69
+ ): ItemEvent {
47
70
  return event(
48
71
  { type: "item", item: id, title: id, summary: "summary", reports },
49
72
  ts,
@@ -140,13 +163,16 @@ describe("derivation", () => {
140
163
  const state = deriveState(
141
164
  [a, b],
142
165
  [
143
- item("U-1", [a.id], "2026-11-13T20:00+08:00"),
144
- check("U-1", "2026-11-13T21:00+08:00"),
145
- event({ type: "link", item: "U-1", reports: [b.id] }, "2026-11-14T10:00+08:00"),
166
+ item("U-1", [a.id], isoSeconds(new Date(2026, 10, 13, 20, 0))),
167
+ check("U-1", isoSeconds(new Date(2026, 10, 13, 21, 0))),
168
+ event(
169
+ { type: "link", item: "U-1", reports: [b.id] },
170
+ isoSeconds(new Date(2026, 10, 14, 10, 0)),
171
+ ),
146
172
  ],
147
173
  );
148
174
  const entry = state.items.find((candidateItem) => candidateItem.id === "U-1");
149
- expect(entry?.checkedAt).toBe("2026-11-13T21:00+08:00");
175
+ expect(entry?.checkedAt).toBe(isoSeconds(new Date(2026, 10, 13, 21, 0)));
150
176
  expect(entry?.reopened).toBe(true);
151
177
  expect(state.open.map((candidateItem) => candidateItem.id)).toEqual(["U-1"]);
152
178
  expect(state.checked).toEqual([]);
@@ -158,11 +184,11 @@ describe("derivation", () => {
158
184
  const state = deriveState(
159
185
  [a, b],
160
186
  [
161
- item("U-1", [a.id], "2026-11-13T21:06:00+08:00"),
162
- check("U-1", "2026-11-13T21:07:10+08:00"),
187
+ item("U-1", [a.id], isoSeconds(new Date(2026, 10, 13, 21, 6, 0))),
188
+ check("U-1", isoSeconds(new Date(2026, 10, 13, 21, 7, 10))),
163
189
  event(
164
190
  { type: "link", item: "U-1", reports: [b.id] },
165
- "2026-11-13T21:07:50+08:00",
191
+ isoSeconds(new Date(2026, 10, 13, 21, 7, 50)),
166
192
  ),
167
193
  ],
168
194
  );
@@ -172,7 +198,13 @@ describe("derivation", () => {
172
198
 
173
199
  it("keeps a checked item checked when no newer evidence exists", () => {
174
200
  const a = record("alpha", new Date(2026, 10, 13, 9, 0));
175
- const state = deriveState([a], [item("U-1", [a.id], "2026-11-13T20:00+08:00"), check("U-1", "2026-11-13T21:00+08:00")]);
201
+ const state = deriveState(
202
+ [a],
203
+ [
204
+ item("U-1", [a.id], isoSeconds(new Date(2026, 10, 13, 20, 0))),
205
+ check("U-1", isoSeconds(new Date(2026, 10, 13, 21, 0))),
206
+ ],
207
+ );
176
208
  expect(state.checked.map((entry) => entry.id)).toEqual(["U-1"]);
177
209
  expect(state.open).toEqual([]);
178
210
  });
@@ -221,10 +253,13 @@ describe("derivation", () => {
221
253
  const state = deriveState(
222
254
  [a, b],
223
255
  [
224
- item("U-target", [a.id], "2026-11-13T10:00+08:00"),
225
- item("U-source", [b.id], "2026-11-12T10:00+08:00"),
226
- check("U-target", "2026-11-13T11:00+08:00"),
227
- event({ type: "merge", item: "U-target", sources: ["U-source"] }, "2026-11-13T12:00+08:00"),
256
+ item("U-target", [a.id], isoSeconds(new Date(2026, 10, 13, 10, 0))),
257
+ item("U-source", [b.id], isoSeconds(new Date(2026, 10, 12, 10, 0))),
258
+ check("U-target", isoSeconds(new Date(2026, 10, 13, 11, 0))),
259
+ event(
260
+ { type: "merge", item: "U-target", sources: ["U-source"] },
261
+ isoSeconds(new Date(2026, 10, 13, 12, 0)),
262
+ ),
228
263
  ],
229
264
  );
230
265
  expect(state.open.map((entry) => entry.id)).toEqual(["U-target"]);
@@ -246,4 +281,125 @@ describe("derivation", () => {
246
281
  const state = deriveState([], [item("U-1", ["gone"])]);
247
282
  expect(state.items[0]?.missingReports).toEqual(["gone"]);
248
283
  });
284
+
285
+ it("keeps a none: hint record out of the queue and counts it as retired", () => {
286
+ const a = record("alpha", new Date(2026, 10, 13, 9, 0));
287
+ const b = record("beta", new Date(2026, 10, 13, 10, 0));
288
+ const state = deriveState(
289
+ [a, b],
290
+ [
291
+ candidate(a.id, "alpha behaviour"),
292
+ event({
293
+ type: "candidate",
294
+ report: b.id,
295
+ title: b.id,
296
+ behavior: "docs only",
297
+ hint: " None:internal docs, nothing to test ",
298
+ }),
299
+ ],
300
+ );
301
+ expect(state.pending.map((entry) => entry.id)).toEqual([a.id]);
302
+ expect(state.counts.retired).toBe(1);
303
+ expect(state.retired[0]).toMatchObject({ id: b.id, reason: "none" });
304
+ });
305
+
306
+ it("does not treat a hint that merely mentions none as a retirement", () => {
307
+ const a = record("alpha", new Date(2026, 10, 13, 9, 0));
308
+ const state = deriveState(
309
+ [a],
310
+ [
311
+ event({
312
+ type: "candidate",
313
+ report: a.id,
314
+ title: a.id,
315
+ behavior: "operator sees it",
316
+ hint: "open the list, nothing none-ish about it",
317
+ }),
318
+ ],
319
+ );
320
+ expect(state.pending.map((entry) => entry.id)).toEqual([a.id]);
321
+ expect(state.counts.retired).toBe(0);
322
+ });
323
+
324
+ it("splits pending into new records and legacy files", () => {
325
+ const fresh = record("fresh", new Date(2026, 10, 13, 9, 0));
326
+ const legacy = record("legacy", new Date(2026, 10, 12, 9, 0));
327
+ const state = deriveState([fresh, legacy], [candidate(fresh.id, "fresh behaviour")]);
328
+ const byId = new Map(state.pending.map((entry) => [entry.id, entry]));
329
+ expect(byId.get(fresh.id)?.hasBehavior).toBe(true);
330
+ expect(byId.get(legacy.id)?.hasBehavior).toBe(false);
331
+ expect(state.counts.pendingNew).toBe(1);
332
+ expect(state.counts.pendingLegacy).toBe(1);
333
+ expect(state.counts.pending).toBe(2);
334
+ });
335
+
336
+ it("retires records by drop even when no item exists", () => {
337
+ const a = record("alpha", new Date(2026, 10, 13, 9, 0));
338
+ const state = deriveState(
339
+ [a],
340
+ [
341
+ event(
342
+ { type: "drop", reports: [a.id], reason: "absorbed by a later item" },
343
+ "2026-11-13T22:00+08:00",
344
+ ),
345
+ ],
346
+ );
347
+ expect(state.items).toEqual([]);
348
+ expect(state.pending).toEqual([]);
349
+ expect(state.counts.retired).toBe(1);
350
+ expect(state.retired[0]).toMatchObject({ id: a.id, reason: "dropped" });
351
+ });
352
+
353
+ it("keeps an accepted item accepted when an older record is attached", () => {
354
+ const recent = record("recent", new Date(2026, 10, 10, 9, 0));
355
+ const old = record("old", new Date(2026, 10, 5, 9, 0));
356
+ const state = deriveState(
357
+ [recent, old],
358
+ [
359
+ item("U-1", [recent.id], isoSeconds(new Date(2026, 10, 10, 20, 0))),
360
+ check("U-1", isoSeconds(new Date(2026, 10, 12, 21, 0))),
361
+ event(
362
+ { type: "link", item: "U-1", reports: [old.id] },
363
+ isoSeconds(new Date(2026, 10, 13, 9, 0)),
364
+ ),
365
+ ],
366
+ );
367
+ expect(state.checked.map((entry) => entry.id)).toEqual(["U-1"]);
368
+ expect(state.items[0]?.reopened).toBe(false);
369
+ });
370
+
371
+ it("does not reopen when the attached record predates the check's minute", () => {
372
+ const recent = record("recent", new Date(2026, 10, 13, 21, 5));
373
+ const earlier = record("earlier", new Date(2026, 10, 13, 21, 6));
374
+ const state = deriveState(
375
+ [recent, earlier],
376
+ [
377
+ item("U-1", [recent.id], isoSeconds(new Date(2026, 10, 13, 21, 5, 30))),
378
+ check("U-1", isoSeconds(new Date(2026, 10, 13, 21, 7, 40))),
379
+ event(
380
+ { type: "link", item: "U-1", reports: [earlier.id] },
381
+ isoSeconds(new Date(2026, 10, 13, 23, 0)),
382
+ ),
383
+ ],
384
+ );
385
+ expect(state.checked.map((entry) => entry.id)).toEqual(["U-1"]);
386
+ });
387
+
388
+ it("reopens when a record newer than the check lands later", () => {
389
+ const recent = record("recent", new Date(2026, 10, 13, 21, 5));
390
+ const newer = record("newer", new Date(2026, 10, 14, 8, 0));
391
+ const state = deriveState(
392
+ [recent, newer],
393
+ [
394
+ item("U-1", [recent.id], isoSeconds(new Date(2026, 10, 13, 21, 5, 30))),
395
+ check("U-1", isoSeconds(new Date(2026, 10, 13, 21, 7, 40))),
396
+ event(
397
+ { type: "link", item: "U-1", reports: [newer.id] },
398
+ isoSeconds(new Date(2026, 10, 14, 10, 0)),
399
+ ),
400
+ ],
401
+ );
402
+ expect(state.open.map((entry) => entry.id)).toEqual(["U-1"]);
403
+ expect(state.items[0]?.reopened).toBe(true);
404
+ });
249
405
  });
@@ -100,7 +100,10 @@ export interface MergeEvent extends BaseEvent {
100
100
 
101
101
  export interface DropEvent extends BaseEvent {
102
102
  readonly type: "drop";
103
- readonly item: string;
103
+ /** Item to retire. Optional: a drop may retire records without an item. */
104
+ readonly item?: string;
105
+ /** Records retired directly (no item is created for them). */
106
+ readonly reports?: string[];
104
107
  readonly reason?: string;
105
108
  }
106
109
 
@@ -129,7 +132,7 @@ export interface UatItemView {
129
132
  /** Last time evidence was attached (item/link event), not just record time. */
130
133
  evidenceUpdatedAt: string;
131
134
  checkedAt?: string;
132
- /** New evidence landed after the last check: counts as unchecked. */
135
+ /** Evidence newer than the last tick (minute-aligned): counts as unchecked. */
133
136
  reopened: boolean;
134
137
  dropped?: string;
135
138
  mergedInto?: string;
@@ -143,6 +146,23 @@ export interface PendingCandidate extends RecordEntry {
143
146
  area?: string;
144
147
  spec?: string;
145
148
  files?: string[];
149
+ /**
150
+ * True when a `candidate` event supplied a behaviour sentence.
151
+ *
152
+ * Records written before `record_change` existed have no behaviour line, and
153
+ * clustering them means reading every file by hand. They are kept in the
154
+ * queue but counted separately (`counts.pendingLegacy`) and only fed to a
155
+ * clustering run on explicit `/ask-uat legacy`.
156
+ */
157
+ hasBehavior: boolean;
158
+ }
159
+
160
+ /** One record retired without an item: a `none:` hint or an explicit drop. */
161
+ export interface RetiredRecord {
162
+ id: string;
163
+ title: string;
164
+ reason: "none" | "dropped";
165
+ at?: string;
146
166
  }
147
167
 
148
168
  export interface UatBatchView {
@@ -152,20 +172,27 @@ export interface UatBatchView {
152
172
  }
153
173
 
154
174
  export interface UatState {
155
- items: UatItemView[];
156
- /** Items that still need the operator (never checked, or reopened). */
157
- open: UatItemView[];
158
- checked: UatItemView[];
159
- pending: PendingCandidate[];
160
- batches: UatBatchView[];
161
- lastEventTs?: string;
162
- counts: {
163
- items: number;
164
- open: number;
165
- checked: number;
166
- pending: number;
167
- totalRecords: number;
168
- };
175
+ items: UatItemView[];
176
+ /** Items that still need the operator (never checked, or reopened). */
177
+ open: UatItemView[];
178
+ checked: UatItemView[];
179
+ pending: PendingCandidate[];
180
+ /** Records retired in place (none: hint, or a drop that named no item). */
181
+ retired: RetiredRecord[];
182
+ batches: UatBatchView[];
183
+ lastEventTs?: string;
184
+ counts: {
185
+ items: number;
186
+ open: number;
187
+ checked: number;
188
+ pending: number;
189
+ /** Pending records that carry a behaviour sentence (the default queue). */
190
+ pendingNew: number;
191
+ /** Pending records that exist only as files (need `/ask-uat legacy`). */
192
+ pendingLegacy: number;
193
+ retired: number;
194
+ totalRecords: number;
195
+ };
169
196
  }
170
197
 
171
198
  /** `<root>/.agents/uat/ledger.jsonl` */
@@ -246,8 +273,18 @@ function isEvent(value: unknown): value is UatEvent {
246
273
  );
247
274
  case "merge":
248
275
  return string(event.item) && strings(event.sources);
249
- case "drop":
250
- return string(event.item) && optionalString(event.reason);
276
+ case "drop": {
277
+ if (
278
+ !optionalString(event.item) ||
279
+ !optionalStrings(event.reports) ||
280
+ !optionalString(event.reason)
281
+ ) {
282
+ return false;
283
+ }
284
+ const hasItem = typeof event.item === "string" && event.item !== "";
285
+ const hasReports = Array.isArray(event.reports) && event.reports.length > 0;
286
+ return hasItem || hasReports;
287
+ }
251
288
  default:
252
289
  return false;
253
290
  }
@@ -276,6 +313,8 @@ export function deriveState(
276
313
  const items = new Map<string, UatItemView>();
277
314
  const batches: UatBatchView[] = [];
278
315
  const byId = new Map(records.map((record) => [record.id, record]));
316
+ /** Records retired without an item, and why (drop wins over a none: hint). */
317
+ const retired = new Map<string, "none" | "dropped">();
279
318
 
280
319
  const ensure = (id: string, ts: string): UatItemView => {
281
320
  const existing = items.get(id);
@@ -362,8 +401,11 @@ export function deriveState(
362
401
  break;
363
402
  }
364
403
  case "drop": {
365
- const item = ensure(event.item, event.ts);
366
- item.dropped = event.reason ?? "dropped";
404
+ if (event.item !== undefined && event.item !== "") {
405
+ const item = ensure(event.item, event.ts);
406
+ item.dropped = event.reason ?? "dropped";
407
+ }
408
+ for (const report of event.reports ?? []) retired.set(report, "dropped");
367
409
  break;
368
410
  }
369
411
  case "candidate":
@@ -376,13 +418,21 @@ export function deriveState(
376
418
  for (const item of items.values()) {
377
419
  if (item.dropped !== undefined) continue;
378
420
  if (item.mergedInto !== undefined) continue;
379
- const evidenceEpoch = Math.max(
421
+ // Only the evidence records' own timestamps decide whether an accepted
422
+ // item is out of date. `evidenceUpdatedAt` moves on every `link`, so using
423
+ // it would reopen an item merely because an old record was attached late.
424
+ const newestEvidence = item.reports.reduce(
425
+ (max, report) => Math.max(max, byId.get(report)?.epochMs ?? 0),
380
426
  0,
381
- Date.parse(item.evidenceUpdatedAt) || 0,
382
- ...item.reports.map((report) => byId.get(report)?.epochMs ?? 0),
383
427
  );
384
- item.reopened =
385
- item.checkedAt !== undefined && evidenceEpoch > (Date.parse(item.checkedAt) || 0);
428
+ const checkedMs = Date.parse(item.checkedAt ?? "");
429
+ // Record headers are minute-precision, `check` events are not: round the
430
+ // tick down to its minute so a record written later in that same minute
431
+ // still counts as newer (better a redundant question than a missed one).
432
+ const checkedMinute = Number.isFinite(checkedMs)
433
+ ? Math.floor(checkedMs / 60_000) * 60_000
434
+ : 0;
435
+ item.reopened = item.checkedAt !== undefined && newestEvidence >= checkedMinute;
386
436
  item.missingReports = item.reports.filter((report) => !byId.has(report));
387
437
  live.push(item);
388
438
  }
@@ -391,28 +441,50 @@ export function deriveState(
391
441
  // Dropped items still consume their evidence: otherwise abandoning work
392
442
  // would resurrect the same records as fresh acceptance debt on the next run.
393
443
  for (const item of items.values()) for (const report of item.reports) referenced.add(report);
444
+ // Records retired without an item leave the queue the same way.
445
+ for (const report of retired.keys()) referenced.add(report);
394
446
 
395
447
  const candidates = candidateByReport(events);
396
- const pending: PendingCandidate[] = records
397
- .filter((record) => !referenced.has(record.id))
398
- .map((record) => {
399
- const candidate = candidates.get(record.id);
400
- return {
401
- ...record,
402
- ...(candidate
403
- ? {
404
- behavior: candidate.behavior,
405
- hint: candidate.hint,
406
- area: candidate.area,
407
- spec: candidate.spec,
408
- files: candidate.files,
409
- }
410
- : {}),
411
- };
448
+ const pending: PendingCandidate[] = [];
449
+ for (const record of records) {
450
+ if (referenced.has(record.id)) continue;
451
+ const candidate = candidates.get(record.id);
452
+ if (candidate?.hint !== undefined && isNoneHint(candidate.hint)) {
453
+ // No user-visible effect was declared at implementation time: keep the
454
+ // record on disk, but out of the acceptance queue.
455
+ retired.set(record.id, "none");
456
+ continue;
457
+ }
458
+ pending.push({
459
+ ...record,
460
+ hasBehavior: (candidate?.behavior ?? "").trim() !== "",
461
+ ...(candidate
462
+ ? {
463
+ behavior: candidate.behavior,
464
+ hint: candidate.hint,
465
+ area: candidate.area,
466
+ spec: candidate.spec,
467
+ files: candidate.files,
468
+ }
469
+ : {}),
470
+ });
471
+ }
472
+ // Newest first, independent of the caller's input order: the page and the
473
+ // clustering work order both read this queue top-down.
474
+ pending.sort((a, b) => b.epochMs - a.epochMs || a.id.localeCompare(b.id));
475
+
476
+ const retiredRecords: RetiredRecord[] = [...retired.entries()]
477
+ .map(([id, reason]) => {
478
+ const record = byId.get(id);
479
+ return { id, reason, title: record?.title ?? id, at: record?.at };
412
480
  })
413
- // Newest first, independent of the caller's input order: the page and the
414
- // clustering work order both read this queue top-down.
415
- .sort((a, b) => b.epochMs - a.epochMs || a.id.localeCompare(b.id));
481
+ // `at` retains the record's original timezone offset; compare epochs so
482
+ // records written in different zones still sort chronologically.
483
+ .sort(
484
+ (a, b) =>
485
+ (byId.get(b.id)?.epochMs ?? 0) - (byId.get(a.id)?.epochMs ?? 0) ||
486
+ a.id.localeCompare(b.id),
487
+ );
416
488
 
417
489
  const open = live
418
490
  .filter((item) => item.checkedAt === undefined || item.reopened)
@@ -429,6 +501,7 @@ export function deriveState(
429
501
  open,
430
502
  checked,
431
503
  pending,
504
+ retired: retiredRecords,
432
505
  batches,
433
506
  lastEventTs: events.length > 0 ? events[events.length - 1]?.ts : undefined,
434
507
  counts: {
@@ -436,11 +509,21 @@ export function deriveState(
436
509
  open: open.length,
437
510
  checked: checked.length,
438
511
  pending: pending.length,
512
+ pendingNew: pending.filter((entry) => entry.hasBehavior).length,
513
+ pendingLegacy: pending.filter((entry) => !entry.hasBehavior).length,
514
+ retired: retiredRecords.length,
439
515
  totalRecords: records.length,
440
516
  },
441
517
  };
442
518
  }
443
519
 
520
+ /** `none: …` / `none:…` — a hint that says the change has no visible effect. */
521
+ const NONE_HINT_RE = /^none\s*[::]/i;
522
+
523
+ function isNoneHint(hint: string): boolean {
524
+ return NONE_HINT_RE.test(hint.trim());
525
+ }
526
+
444
527
  function evidenceEpochOf(item: UatItemView, byId: Map<string, RecordEntry>): number {
445
528
  let max = Date.parse(item.createdAt) || 0;
446
529
  for (const report of item.reports) {
@@ -8,14 +8,24 @@
8
8
  * The work order is a *contract about shape*, not a template to fill in. The
9
9
  * number that matters is the ratio: many change records collapse into few
10
10
  * acceptance items, because the operator verifies behaviour, not commits.
11
+ *
12
+ * The queue has two lanes. Records written by `record_change` carry a behaviour
13
+ * sentence and cluster cheaply; older files have only a title, so clustering
14
+ * them means opening every file. Only an explicit `/ask-uat legacy` pays that
15
+ * cost — a default run stays in the cheap lane and says how much it left out.
11
16
  */
12
17
  import type { PendingCandidate, UatItemView, UatState } from "./ledger.js";
13
18
 
14
19
  export interface KickoffInput {
20
+ /** The records this run may cluster (already selected by the caller). */
15
21
  pending: readonly PendingCandidate[];
16
22
  openItems: readonly UatItemView[];
17
23
  maxCandidates: number;
18
24
  maxItems: number;
25
+ /** The caller included historical (no-behaviour) records. */
26
+ legacy?: boolean;
27
+ /** Historical records this run still leaves out. */
28
+ legacyRemaining?: number;
19
29
  }
20
30
 
21
31
  function describeCandidate(candidate: PendingCandidate): string {
@@ -30,8 +40,10 @@ function describeCandidate(candidate: PendingCandidate): string {
30
40
  }
31
41
 
32
42
  export function buildUatKickoff(input: KickoffInput): string {
33
- const shown = input.pending.slice(0, input.maxCandidates);
34
- const hidden = input.pending.length - shown.length;
43
+ const fresh = input.pending.filter((candidate) => candidate.hasBehavior);
44
+ const historical = input.pending.filter((candidate) => !candidate.hasBehavior);
45
+ const shownFresh = fresh.slice(0, input.maxCandidates);
46
+ const shownHistorical = historical.slice(0, Math.max(0, input.maxCandidates - shownFresh.length));
35
47
  const existing =
36
48
  input.openItems.length === 0
37
49
  ? "- (none)"
@@ -40,20 +52,32 @@ export function buildUatKickoff(input: KickoffInput): string {
40
52
  .map((item) => `- ${item.id} | ${item.title} | ${item.summary}`)
41
53
  .join("\n");
42
54
 
43
- return [
55
+ const lines = [
44
56
  "UAT clustering run.",
45
57
  "",
46
58
  "The operator is about to accept user-visible behaviour in the browser page that is now open.",
47
59
  "Turn the pending change records into a small number of acceptance items — not one item per record.",
48
60
  "",
49
- `Pending change records (${input.pending.length}, showing ${shown.length}${hidden > 0 ? `, ${hidden} left for the next run` : ""}):`,
50
- ...shown.map(describeCandidate),
61
+ `Pending change records (${shownFresh.length}${fresh.length > shownFresh.length ? ` of ${fresh.length}` : ""}):`,
62
+ ...(shownFresh.length > 0 ? shownFresh.map(describeCandidate) : ["- (none)"]),
63
+ ];
64
+
65
+ if (shownHistorical.length > 0) {
66
+ lines.push(
67
+ "",
68
+ `Records without a behaviour line (${shownHistorical.length}${historical.length > shownHistorical.length ? ` of ${historical.length}` : ""}).`,
69
+ "Open each file before you cluster it: the title alone is not a behaviour, and guessing one puts a wrong test in front of the operator.",
70
+ ...shownHistorical.map(describeCandidate),
71
+ );
72
+ }
73
+
74
+ lines.push(
51
75
  "",
52
76
  "Already open acceptance items (link new evidence here instead of duplicating):",
53
77
  existing,
54
78
  "",
55
79
  "Rules:",
56
- `- One item is one behaviour a person can verify by hand. If two records land on the same screen or the same command, they are one item unless the operator must test them separately.`,
80
+ "- One item is one behaviour a person can verify by hand. If two records land on the same screen or the same command, they are one item unless the operator must test them separately.",
57
81
  "- summary: 2-3 sentences, user-facing. What can the operator now do, see, or stop worrying about. No file names, no function names, no implementation detail.",
58
82
  "- steps: 3-6 concrete steps (what to open, click, type, run) and the expected result of each.",
59
83
  "- edge: optional corner cases worth one quick try (empty input, wrong order, offline, permission denied).",
@@ -62,7 +86,16 @@ export function buildUatKickoff(input: KickoffInput): string {
62
86
  `- Create at most ${input.maxItems} new items in this run; leftovers stay pending and show up next time.`,
63
87
  "- Call `uat_item` once per item (or per link). Do not edit the ledger by hand, and do not change code in this phase.",
64
88
  "- When you are done, reply with one line: how many items and links you recorded.",
65
- ].join("\n");
89
+ );
90
+
91
+ if (input.legacy !== true && (input.legacyRemaining ?? 0) > 0) {
92
+ lines.push(
93
+ "",
94
+ `${input.legacyRemaining} record${input.legacyRemaining === 1 ? "" : "s"} without a behaviour line ${input.legacyRemaining === 1 ? "is" : "are"} not part of this run; \`/ask-uat legacy\` includes them.`,
95
+ );
96
+ }
97
+
98
+ return lines.join("\n");
66
99
  }
67
100
 
68
101
  export const UAT_MODE_BANNER = [
@@ -74,5 +107,5 @@ export const UAT_MODE_BANNER = [
74
107
 
75
108
  /** One-line status for the command notice. */
76
109
  export function describeCounts(state: UatState): string {
77
- return `${state.counts.open} open · ${state.counts.checked} accepted · ${state.counts.pending} pending`;
110
+ return `${state.counts.open} open · ${state.counts.checked} accepted · ${state.counts.pendingNew} new · ${state.counts.pendingLegacy} unlabeled`;
78
111
  }
@@ -105,6 +105,20 @@ describe("listRecords", () => {
105
105
  );
106
106
  expect(listRecords(root)).toEqual([]);
107
107
  });
108
+
109
+ it("treats the directory README as documentation, not a record", () => {
110
+ writeRaw("README.md", "# Change records\n\nOne file per finished round.\n");
111
+ writeRaw("readme.md", "# duplicate on a case-insensitive filesystem\n");
112
+ writeRaw("2026-11-13_2107_real.md", "# 2026-11-13T21:07+08:00 — real\n");
113
+ expect(listRecords(root).map((record) => record.id)).toEqual(["2026-11-13_2107_real"]);
114
+ });
115
+
116
+ it("skips _-prefixed drafts and archive notes", () => {
117
+ writeRaw("_draft.md", "# scratch\n");
118
+ writeRaw("__rollup-2026.md", "# rolled up\n");
119
+ writeRaw("2026-11-13_2107_real.md", "# 2026-11-13T21:07+08:00 — real\n");
120
+ expect(listRecords(root).map((record) => record.id)).toEqual(["2026-11-13_2107_real"]);
121
+ });
108
122
  });
109
123
 
110
124
  describe("createRecord", () => {
@@ -121,6 +121,18 @@ export function canonicalRecordName(at: string, slug: string): string {
121
121
  return `${date}_${hhmm}_${slug}`;
122
122
  }
123
123
 
124
+ /**
125
+ * Files that live in `.agents/implementations/` but are not change records.
126
+ * `README.md` documents the directory; `_`-prefixed files are drafts or
127
+ * roll-up notes (the standing convention is a double underscore, `__name.md`;
128
+ * a single one is skipped too so older drafts keep working). Neither should
129
+ * ever reach the acceptance queue — a README would be pending forever.
130
+ */
131
+ function isRecordFile(name: string): boolean {
132
+ if (name.toLowerCase() === "readme.md") return false;
133
+ return !name.startsWith("_");
134
+ }
135
+
124
136
  /**
125
137
  * Read every top-level change record. Subdirectories (`archive/<year>/`) are
126
138
  * skipped on purpose: archived records are rolled up already and would
@@ -131,7 +143,7 @@ export function listRecords(root: string): RecordEntry[] {
131
143
  if (!existsSync(dir)) return [];
132
144
  const entries: RecordEntry[] = [];
133
145
  for (const name of readdirSync(dir)) {
134
- if (!name.endsWith(".md")) continue;
146
+ if (!name.endsWith(".md") || !isRecordFile(name)) continue;
135
147
  const absolute = join(dir, name);
136
148
  let stat;
137
149
  try {
@@ -1 +0,0 @@
1
- :root{--lightningcss-light: ;--lightningcss-dark:initial;color-scheme:dark;--bg:#191d24;--panel:#20252e;--panel-2:#262d38;--line:#333c4a;--text:#d7dee8;--muted:#8f9bb0;--accent:#7aa2f7;--ok:#7dcf8a;--warn:#e0af68;--bad:#f07178}*{box-sizing:border-box}body{background:var(--bg);color:var(--text);margin:0;font:14px/1.6 system-ui,-apple-system,Segoe UI,sans-serif}code{background:var(--panel-2);border-radius:4px;padding:.05rem .3rem;font-size:.92em}.shell{max-width:62rem;margin:0 auto;padding:2rem 1.5rem 4rem}.head{justify-content:space-between;align-items:flex-start;gap:1rem;margin-bottom:1.25rem;display:flex}.head h1{letter-spacing:.01em;margin:0;font-size:1.35rem}.sub{color:var(--muted);margin:.25rem 0 0;font-size:.9rem}.dot{margin:0 .4rem}.banner{border:1px solid var(--line);background:var(--panel);border-radius:6px;margin:0 0 .9rem;padding:.6rem .8rem;font-size:.92rem}.banner.warn{color:#f0d8a8;background:#2c2618;border-color:#6b5628}.banner.error{color:#f3b9bd;background:#2d1e21;border-color:#6e3a3f}.empty{color:var(--muted);text-align:center;padding:2rem 0}.items{flex-direction:column;gap:.6rem;margin:0;padding:0;list-style:none;display:flex}.item{background:var(--panel);border:1px solid var(--line);border-radius:8px;gap:.8rem;padding:.9rem 1rem;display:flex}.item.done{opacity:.72}.check{padding-top:.15rem}.check input{width:1.05rem;height:1.05rem;accent-color:var(--ok);cursor:pointer}.body{flex:1;min-width:0}.row{justify-content:space-between;align-items:baseline;gap:.75rem;display:flex}.row h2{margin:0;font-size:1rem;font-weight:600}.badges{flex-wrap:wrap;justify-content:flex-end;gap:.35rem;display:flex}.badge{color:var(--muted);border:1px solid var(--line);white-space:nowrap;border-radius:999px;padding:.05rem .45rem;font-size:.72rem}.badge.reopened{color:var(--warn);border-color:#6b5628}.badge.area{color:var(--accent);border-color:#35487a}.summary{color:#c3ccda;margin:.45rem 0 0}.more{color:var(--accent);font:inherit;cursor:pointer;background:0 0;border:none;margin-top:.5rem;padding:0;font-size:.85rem}.details{border-top:1px dashed var(--line);margin-top:.7rem;padding-top:.7rem}.steps,.edge{margin:.2rem 0 .6rem 1.2rem;padding:0}.steps li,.edge li{margin:.25rem 0}.label{text-transform:uppercase;letter-spacing:.06em;color:var(--muted);margin:.6rem 0 .3rem;font-size:.78rem}.skip{color:var(--muted);margin:.4rem 0 0;font-size:.88rem}.evidence{flex-wrap:wrap;gap:.35rem;display:flex}.chip{font:inherit;color:var(--text);background:var(--panel-2);border:1px solid var(--line);cursor:pointer;border-radius:5px;padding:.15rem .45rem;font-size:.76rem}.chip:hover{border-color:var(--accent)}.accepted{margin-top:1.75rem}.accepted summary{cursor:pointer;color:var(--muted);margin-bottom:.6rem;font-size:.9rem}.ghost{border:1px solid var(--line);color:var(--muted);font:inherit;cursor:pointer;background:0 0;border-radius:6px;padding:.25rem .6rem;font-size:.82rem}.ghost:hover{color:var(--text);border-color:var(--accent)}.drawer{border-top:1px solid var(--line);background:#12161c;flex-direction:column;max-height:70vh;display:flex;position:fixed;inset:auto 0 0;box-shadow:0 -12px 40px #00000073}.drawer-head{border-bottom:1px solid var(--line);justify-content:space-between;align-items:center;padding:.6rem 1.2rem;display:flex}.drawer pre{white-space:pre-wrap;color:#c8d2e0;margin:0;padding:1rem 1.2rem 2rem;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,monospace;overflow:auto}.foot{color:#5f6b7e;word-break:break-all;margin-top:2.5rem;font-size:.75rem}