@andares/pi-toolkits 0.12.3 → 0.13.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 (65) hide show
  1. package/README.md +100 -15
  2. package/README.zh-CN.md +94 -14
  3. package/package.json +19 -10
  4. package/src/features/ask/index.ts +6 -0
  5. package/src/features/init/apply.ts +32 -12
  6. package/src/features/init/audit-uat.test.ts +103 -0
  7. package/src/features/init/audit.ts +148 -0
  8. package/src/features/init/detect.ts +4 -0
  9. package/src/features/init/index.ts +47 -2
  10. package/src/features/init/plan.ts +11 -0
  11. package/src/features/init/refresh.test.ts +208 -0
  12. package/src/features/init/refresh.ts +255 -0
  13. package/src/features/init/spec.ts +20 -0
  14. package/src/features/init/templates/agents-skeleton.md +2 -0
  15. package/src/features/init/templates/uat-readme.md +53 -0
  16. package/src/features/init/templates/workflow-block.md +21 -0
  17. package/src/features/init/templates.test.ts +3 -1
  18. package/src/features/init/templates.ts +2 -0
  19. package/src/features/init/types.ts +12 -1
  20. package/src/features/permission/index.ts +32 -0
  21. package/src/features/plan/assets/index-C1YLIi4I.js +1 -0
  22. package/src/features/plan/assets/index-DMEpYC3V.css +1 -0
  23. package/src/features/plan/assets/index.html +14 -0
  24. package/src/features/plan/assets.test.ts +64 -0
  25. package/src/features/plan/blocks.test.ts +77 -0
  26. package/src/features/plan/blocks.ts +153 -0
  27. package/src/features/plan/diff.test.ts +144 -0
  28. package/src/features/plan/diff.ts +193 -0
  29. package/src/features/plan/feedback.test.ts +233 -0
  30. package/src/features/plan/feedback.ts +182 -0
  31. package/src/features/plan/index.test.ts +385 -0
  32. package/src/features/plan/index.ts +433 -0
  33. package/src/features/plan/prompt.test.ts +91 -0
  34. package/src/features/plan/prompt.ts +110 -0
  35. package/src/features/plan/render.test.ts +94 -0
  36. package/src/features/plan/render.ts +131 -0
  37. package/src/features/plan/server.test.ts +374 -0
  38. package/src/features/plan/server.ts +272 -0
  39. package/src/features/plan/store.test.ts +145 -0
  40. package/src/features/plan/store.ts +244 -0
  41. package/src/features/review/index.ts +54 -28
  42. package/src/features/review/review.test.ts +46 -1
  43. package/src/features/uat/assets/index-D-W9zj0w.css +1 -0
  44. package/src/features/uat/assets/index-DCBQCsli.js +1 -0
  45. package/src/features/uat/assets/index.html +14 -0
  46. package/src/features/uat/constants.ts +23 -0
  47. package/src/features/uat/index.test.ts +404 -0
  48. package/src/features/uat/index.ts +329 -0
  49. package/src/features/uat/item-tool.ts +280 -0
  50. package/src/features/uat/ledger.test.ts +249 -0
  51. package/src/features/uat/ledger.ts +504 -0
  52. package/src/features/uat/prompt.ts +78 -0
  53. package/src/features/uat/record-tool.ts +167 -0
  54. package/src/features/uat/records.test.ts +145 -0
  55. package/src/features/uat/records.ts +268 -0
  56. package/src/features/uat/server.ts +181 -0
  57. package/src/features/uat/state.test.ts +41 -0
  58. package/src/features/uat/state.ts +67 -0
  59. package/src/index.ts +10 -1
  60. package/src/lib/ask-control.ts +25 -0
  61. package/src/lib/opener.test.ts +72 -0
  62. package/src/lib/opener.ts +121 -0
  63. package/src/lib/permission-control.ts +39 -0
  64. package/src/lib/startup.test.ts +1 -1
  65. package/src/lib/web-review.ts +341 -0
@@ -0,0 +1,504 @@
1
+ /**
2
+ * UAT feature — the acceptance ledger.
3
+ *
4
+ * `ledger.jsonl` is the only place where acceptance decisions live. It is an
5
+ * append-only event stream, not a document to be rewritten:
6
+ *
7
+ * - toggling a checkbox appends one line — there is no "submit", and closing
8
+ * the page cannot lose a decision that was already taken;
9
+ * - two sessions (or two branches) can append at the same time without
10
+ * clobbering each other; readers deduplicate by event `id`;
11
+ * - everything the page shows is derived from the stream, so the display can
12
+ * never drift from the record of what the operator actually did.
13
+ *
14
+ * Derivation is a pure function over (records on disk, events). That is
15
+ * deliberate: the fallback index is the directory itself, so a project that
16
+ * never called `record_change` still gets a correct (if less informative)
17
+ * acceptance queue.
18
+ */
19
+ import {
20
+ appendFileSync,
21
+ closeSync,
22
+ existsSync,
23
+ mkdirSync,
24
+ openSync,
25
+ readFileSync,
26
+ readSync,
27
+ statSync,
28
+ } from "node:fs";
29
+ import { dirname, join } from "node:path";
30
+ import type { RecordEntry } from "./records.js";
31
+
32
+ export const LEDGER_VERSION = 1;
33
+
34
+ interface BaseEvent {
35
+ readonly v: number;
36
+ readonly id: string;
37
+ readonly ts: string;
38
+ }
39
+
40
+ export interface CandidateEvent extends BaseEvent {
41
+ readonly type: "candidate";
42
+ /** Change-record id (file name without `.md`). */
43
+ readonly report: string;
44
+ readonly title: string;
45
+ readonly behavior: string;
46
+ readonly hint?: string;
47
+ readonly area?: string;
48
+ readonly files?: string[];
49
+ readonly spec?: string;
50
+ }
51
+
52
+ export interface BatchEvent extends BaseEvent {
53
+ readonly type: "batch";
54
+ readonly batch: string;
55
+ readonly candidates: number;
56
+ readonly since?: string;
57
+ }
58
+
59
+ export interface ItemEvent extends BaseEvent {
60
+ readonly type: "item";
61
+ readonly item: string;
62
+ readonly batch?: string;
63
+ readonly title: string;
64
+ readonly summary: string;
65
+ readonly steps?: string[];
66
+ readonly edge?: string[];
67
+ /** "What not to worry about" — internals that changed without user impact. */
68
+ readonly skip?: string;
69
+ readonly reports: string[];
70
+ readonly spec?: string;
71
+ readonly area?: string;
72
+ }
73
+
74
+ export interface LinkEvent extends BaseEvent {
75
+ readonly type: "link";
76
+ readonly item: string;
77
+ readonly reports: string[];
78
+ readonly reason?: string;
79
+ }
80
+
81
+ export interface CheckEvent extends BaseEvent {
82
+ readonly type: "check" | "uncheck";
83
+ readonly item: string;
84
+ readonly reason?: string;
85
+ }
86
+
87
+ export interface AmendEvent extends BaseEvent {
88
+ readonly type: "amend";
89
+ readonly item: string;
90
+ readonly title?: string;
91
+ readonly summary?: string;
92
+ readonly steps?: string[];
93
+ readonly edge?: string[];
94
+ readonly skip?: string;
95
+ readonly spec?: string;
96
+ }
97
+
98
+ export interface MergeEvent extends BaseEvent {
99
+ readonly type: "merge";
100
+ /** Surviving item. */
101
+ readonly item: string;
102
+ readonly sources: string[];
103
+ }
104
+
105
+ export interface DropEvent extends BaseEvent {
106
+ readonly type: "drop";
107
+ readonly item: string;
108
+ readonly reason?: string;
109
+ }
110
+
111
+ export type UatEvent =
112
+ | CandidateEvent
113
+ | BatchEvent
114
+ | ItemEvent
115
+ | LinkEvent
116
+ | CheckEvent
117
+ | AmendEvent
118
+ | MergeEvent
119
+ | DropEvent;
120
+
121
+ export interface UatItemView {
122
+ id: string;
123
+ title: string;
124
+ summary: string;
125
+ steps: string[];
126
+ edge: string[];
127
+ skip?: string;
128
+ spec?: string;
129
+ area?: string;
130
+ batch?: string;
131
+ reports: string[];
132
+ createdAt: string;
133
+ /** Last time evidence was attached (item/link event), not just record time. */
134
+ evidenceUpdatedAt: string;
135
+ checkedAt?: string;
136
+ /** New evidence landed after the last check: counts as unchecked. */
137
+ reopened: boolean;
138
+ dropped?: string;
139
+ mergedInto?: string;
140
+ /** Evidence ids that no longer exist on disk (the record was renamed/deleted). */
141
+ missingReports: string[];
142
+ }
143
+
144
+ export interface PendingCandidate extends RecordEntry {
145
+ behavior?: string;
146
+ hint?: string;
147
+ area?: string;
148
+ spec?: string;
149
+ files?: string[];
150
+ }
151
+
152
+ export interface UatBatchView {
153
+ id: string;
154
+ at: string;
155
+ candidates: number;
156
+ }
157
+
158
+ export interface UatState {
159
+ items: UatItemView[];
160
+ /** Items that still need the operator (never checked, or reopened). */
161
+ open: UatItemView[];
162
+ checked: UatItemView[];
163
+ pending: PendingCandidate[];
164
+ batches: UatBatchView[];
165
+ lastEventTs?: string;
166
+ counts: {
167
+ items: number;
168
+ open: number;
169
+ checked: number;
170
+ pending: number;
171
+ totalRecords: number;
172
+ };
173
+ }
174
+
175
+ /** `<root>/.agents/uat/ledger.jsonl` */
176
+ export function ledgerPath(root: string): string {
177
+ return join(root, ".agents/uat/ledger.jsonl");
178
+ }
179
+
180
+ /** Monotonic-enough id: time plus 6 random base36 chars. */
181
+ export function newEventId(now: Date = new Date()): string {
182
+ const random = Math.random().toString(36).slice(2, 8).padEnd(6, "0");
183
+ return `e-${now.getTime().toString(36)}-${random}`;
184
+ }
185
+
186
+ /**
187
+ * Append one event. The file always ends with a newline: if a previous write
188
+ * was interrupted mid-line, this repairs the boundary instead of gluing two
189
+ * JSON objects together (a gluing would silently drop both on read).
190
+ */
191
+ export function appendEvent(file: string, event: UatEvent): void {
192
+ mkdirSync(dirname(file), { recursive: true });
193
+ const line = JSON.stringify(event);
194
+ if (existsSync(file) && statSync(file).size > 0 && !endsWithNewline(file)) {
195
+ appendFileSync(file, `\n${line}\n`, "utf8");
196
+ return;
197
+ }
198
+ appendFileSync(file, `${line}\n`, "utf8");
199
+ }
200
+
201
+ function endsWithNewline(file: string): boolean {
202
+ const fd = openSync(file, "r");
203
+ try {
204
+ const size = statSync(file).size;
205
+ const buffer = Buffer.alloc(1);
206
+ readSync(fd, buffer, 0, 1, size - 1);
207
+ return buffer[0] === 0x0a;
208
+ } finally {
209
+ closeSync(fd);
210
+ }
211
+ }
212
+
213
+ /** Parse the stream, skipping malformed lines and duplicate ids. */
214
+ export function parseEvents(raw: string): { events: UatEvent[]; skipped: number } {
215
+ const events: UatEvent[] = [];
216
+ const seen = new Set<string>();
217
+ let skipped = 0;
218
+ for (const line of raw.split("\n")) {
219
+ const trimmed = line.trim();
220
+ if (trimmed === "") continue;
221
+ let parsed: unknown;
222
+ try {
223
+ parsed = JSON.parse(trimmed);
224
+ } catch {
225
+ skipped += 1;
226
+ continue;
227
+ }
228
+ if (!isEvent(parsed)) {
229
+ skipped += 1;
230
+ continue;
231
+ }
232
+ if (seen.has(parsed.id)) continue;
233
+ seen.add(parsed.id);
234
+ events.push(parsed);
235
+ }
236
+ return { events, skipped };
237
+ }
238
+
239
+ function isEvent(value: unknown): value is UatEvent {
240
+ if (!value || typeof value !== "object") return false;
241
+ const event = value as Record<string, unknown>;
242
+ if (typeof event.id !== "string" || typeof event.ts !== "string") return false;
243
+ if (typeof event.v !== "number") return false;
244
+ const string = (input: unknown): boolean => typeof input === "string";
245
+ const strings = (input: unknown): boolean =>
246
+ Array.isArray(input) && input.every((entry) => typeof entry === "string");
247
+ const optionalString = (input: unknown): boolean => input === undefined || string(input);
248
+ const optionalStrings = (input: unknown): boolean => input === undefined || strings(input);
249
+
250
+ switch (event.type) {
251
+ case "candidate":
252
+ return (
253
+ string(event.report) &&
254
+ string(event.title) &&
255
+ string(event.behavior) &&
256
+ optionalString(event.hint) &&
257
+ optionalString(event.area) &&
258
+ optionalStrings(event.files) &&
259
+ optionalString(event.spec)
260
+ );
261
+ case "batch":
262
+ return string(event.batch) && typeof event.candidates === "number";
263
+ case "item":
264
+ return (
265
+ string(event.item) &&
266
+ string(event.title) &&
267
+ string(event.summary) &&
268
+ strings(event.reports) &&
269
+ optionalStrings(event.steps) &&
270
+ optionalStrings(event.edge) &&
271
+ optionalString(event.skip) &&
272
+ optionalString(event.spec) &&
273
+ optionalString(event.area) &&
274
+ optionalString(event.batch)
275
+ );
276
+ case "link":
277
+ return string(event.item) && strings(event.reports);
278
+ case "check":
279
+ case "uncheck":
280
+ return string(event.item) && optionalString(event.reason);
281
+ case "amend":
282
+ return (
283
+ string(event.item) &&
284
+ optionalString(event.title) &&
285
+ optionalString(event.summary) &&
286
+ optionalStrings(event.steps) &&
287
+ optionalStrings(event.edge) &&
288
+ optionalString(event.skip) &&
289
+ optionalString(event.spec)
290
+ );
291
+ case "merge":
292
+ return string(event.item) && strings(event.sources);
293
+ case "drop":
294
+ return string(event.item) && optionalString(event.reason);
295
+ default:
296
+ return false;
297
+ }
298
+ }
299
+
300
+ export function readEvents(file: string): { events: UatEvent[]; skipped: number } {
301
+ if (!existsSync(file)) return { events: [], skipped: 0 };
302
+ try {
303
+ return parseEvents(readFileSync(file, "utf8"));
304
+ } catch {
305
+ return { events: [], skipped: 1 };
306
+ }
307
+ }
308
+
309
+ /** Latest candidate metadata per report id (last write wins). */
310
+ function candidateByReport(events: readonly UatEvent[]): Map<string, CandidateEvent> {
311
+ const map = new Map<string, CandidateEvent>();
312
+ for (const event of events) {
313
+ if (event.type === "candidate") map.set(event.report, event);
314
+ }
315
+ return map;
316
+ }
317
+
318
+ /**
319
+ * Derive everything the page needs. Pure: same inputs, same output.
320
+ */
321
+ export function deriveState(
322
+ records: readonly RecordEntry[],
323
+ events: readonly UatEvent[],
324
+ ): UatState {
325
+ const items = new Map<string, UatItemView>();
326
+ const batches: UatBatchView[] = [];
327
+ const byId = new Map(records.map((record) => [record.id, record]));
328
+
329
+ const ensure = (id: string, ts: string): UatItemView => {
330
+ const existing = items.get(id);
331
+ if (existing) return existing;
332
+ const created: UatItemView = {
333
+ id,
334
+ title: id,
335
+ summary: "",
336
+ steps: [],
337
+ edge: [],
338
+ reports: [],
339
+ createdAt: ts,
340
+ evidenceUpdatedAt: ts,
341
+ reopened: false,
342
+ missingReports: [],
343
+ };
344
+ items.set(id, created);
345
+ return created;
346
+ };
347
+
348
+ for (const event of events) {
349
+ switch (event.type) {
350
+ case "batch":
351
+ batches.push({ id: event.batch, at: event.ts, candidates: event.candidates });
352
+ break;
353
+ case "item": {
354
+ const item = ensure(event.item, event.ts);
355
+ item.title = event.title;
356
+ item.summary = event.summary;
357
+ item.steps = event.steps ?? [];
358
+ item.edge = event.edge ?? [];
359
+ item.skip = event.skip;
360
+ item.reports = unique([...item.reports, ...event.reports]);
361
+ item.batch = event.batch ?? item.batch;
362
+ item.spec = event.spec ?? item.spec;
363
+ item.area = event.area ?? item.area;
364
+ item.createdAt = event.ts;
365
+ item.evidenceUpdatedAt = event.ts;
366
+ break;
367
+ }
368
+ case "amend": {
369
+ const item = ensure(event.item, event.ts);
370
+ if (event.title !== undefined) item.title = event.title;
371
+ if (event.summary !== undefined) item.summary = event.summary;
372
+ if (event.steps !== undefined) item.steps = event.steps;
373
+ if (event.edge !== undefined) item.edge = event.edge;
374
+ if (event.skip !== undefined) item.skip = event.skip;
375
+ if (event.spec !== undefined) item.spec = event.spec;
376
+ break;
377
+ }
378
+ case "link": {
379
+ const item = ensure(event.item, event.ts);
380
+ item.reports = unique([...item.reports, ...event.reports]);
381
+ item.evidenceUpdatedAt = event.ts;
382
+ break;
383
+ }
384
+ case "merge": {
385
+ const target = ensure(event.item, event.ts);
386
+ for (const source of event.sources) {
387
+ const sourceItem = items.get(source);
388
+ if (!sourceItem || sourceItem.id === target.id) continue;
389
+ target.reports = unique([...target.reports, ...sourceItem.reports]);
390
+ // Merging an unchecked duplicate into an accepted item must not
391
+ // silently accept the source's evidence. When both were accepted,
392
+ // retain the earlier tick so newer evidence still reopens it.
393
+ if (sourceItem.checkedAt === undefined) {
394
+ target.checkedAt = undefined;
395
+ } else if (target.checkedAt !== undefined) {
396
+ target.checkedAt =
397
+ sourceItem.checkedAt < target.checkedAt
398
+ ? sourceItem.checkedAt
399
+ : target.checkedAt;
400
+ }
401
+ sourceItem.mergedInto = target.id;
402
+ }
403
+ break;
404
+ }
405
+ case "check":
406
+ ensure(event.item, event.ts).checkedAt = event.ts;
407
+ break;
408
+ case "uncheck": {
409
+ const item = ensure(event.item, event.ts);
410
+ item.checkedAt = undefined;
411
+ break;
412
+ }
413
+ case "drop": {
414
+ const item = ensure(event.item, event.ts);
415
+ item.dropped = event.reason ?? "dropped";
416
+ break;
417
+ }
418
+ case "candidate":
419
+ // Metadata only; the queue itself is derived from the records on disk.
420
+ break;
421
+ }
422
+ }
423
+
424
+ const live: UatItemView[] = [];
425
+ for (const item of items.values()) {
426
+ if (item.dropped !== undefined) continue;
427
+ if (item.mergedInto !== undefined) continue;
428
+ const evidenceEpoch = Math.max(
429
+ 0,
430
+ Date.parse(item.evidenceUpdatedAt) || 0,
431
+ ...item.reports.map((report) => byId.get(report)?.epochMs ?? 0),
432
+ );
433
+ item.reopened =
434
+ item.checkedAt !== undefined && evidenceEpoch > (Date.parse(item.checkedAt) || 0);
435
+ item.missingReports = item.reports.filter((report) => !byId.has(report));
436
+ live.push(item);
437
+ }
438
+
439
+ const referenced = new Set<string>();
440
+ // Dropped items still consume their evidence: otherwise abandoning work
441
+ // would resurrect the same records as fresh acceptance debt on the next run.
442
+ for (const item of items.values()) for (const report of item.reports) referenced.add(report);
443
+
444
+ const candidates = candidateByReport(events);
445
+ const pending: PendingCandidate[] = records
446
+ .filter((record) => !referenced.has(record.id))
447
+ .map((record) => {
448
+ const candidate = candidates.get(record.id);
449
+ return {
450
+ ...record,
451
+ ...(candidate
452
+ ? {
453
+ behavior: candidate.behavior,
454
+ hint: candidate.hint,
455
+ area: candidate.area,
456
+ spec: candidate.spec,
457
+ files: candidate.files,
458
+ }
459
+ : {}),
460
+ };
461
+ })
462
+ // Newest first, independent of the caller's input order: the page and the
463
+ // clustering work order both read this queue top-down.
464
+ .sort((a, b) => b.epochMs - a.epochMs || a.id.localeCompare(b.id));
465
+
466
+ const open = live
467
+ .filter((item) => item.checkedAt === undefined || item.reopened)
468
+ .sort((a, b) => evidenceEpochOf(b, byId) - evidenceEpochOf(a, byId) || b.createdAt.localeCompare(a.createdAt));
469
+ const checked = live
470
+ .filter((item) => item.checkedAt !== undefined && !item.reopened)
471
+ .sort((a, b) => (b.checkedAt ?? "").localeCompare(a.checkedAt ?? ""));
472
+
473
+ const ordered = [...open, ...checked];
474
+ batches.sort((a, b) => b.at.localeCompare(a.at));
475
+
476
+ return {
477
+ items: ordered,
478
+ open,
479
+ checked,
480
+ pending,
481
+ batches,
482
+ lastEventTs: events.length > 0 ? events[events.length - 1]?.ts : undefined,
483
+ counts: {
484
+ items: ordered.length,
485
+ open: open.length,
486
+ checked: checked.length,
487
+ pending: pending.length,
488
+ totalRecords: records.length,
489
+ },
490
+ };
491
+ }
492
+
493
+ function evidenceEpochOf(item: UatItemView, byId: Map<string, RecordEntry>): number {
494
+ let max = Date.parse(item.createdAt) || 0;
495
+ for (const report of item.reports) {
496
+ const record = byId.get(report);
497
+ if (record && record.epochMs > max) max = record.epochMs;
498
+ }
499
+ return max;
500
+ }
501
+
502
+ function unique(values: readonly string[]): string[] {
503
+ return [...new Set(values.filter((value) => value !== ""))];
504
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * UAT prompt — the clustering work order and the phase banner.
3
+ *
4
+ * English on purpose: everything the model and the operator see at runtime is
5
+ * English (see AGENTS.md). The text never asks for a particular language in the
6
+ * items it produces; the model follows the project's own documentation.
7
+ *
8
+ * The work order is a *contract about shape*, not a template to fill in. The
9
+ * number that matters is the ratio: many change records collapse into few
10
+ * acceptance items, because the operator verifies behaviour, not commits.
11
+ */
12
+ import type { PendingCandidate, UatItemView, UatState } from "./ledger.js";
13
+
14
+ export interface KickoffInput {
15
+ pending: readonly PendingCandidate[];
16
+ openItems: readonly UatItemView[];
17
+ maxCandidates: number;
18
+ maxItems: number;
19
+ }
20
+
21
+ function describeCandidate(candidate: PendingCandidate): string {
22
+ const parts = [
23
+ `- ${candidate.id}`,
24
+ `| ${candidate.title}`,
25
+ candidate.behavior ? `| ${candidate.behavior}` : "| (no behaviour sentence — read the record)",
26
+ candidate.hint ? `| hint: ${candidate.hint}` : "",
27
+ candidate.area ? `| area: ${candidate.area}` : "",
28
+ ];
29
+ return parts.filter((part) => part !== "").join(" ");
30
+ }
31
+
32
+ export function buildUatKickoff(input: KickoffInput): string {
33
+ const shown = input.pending.slice(0, input.maxCandidates);
34
+ const hidden = input.pending.length - shown.length;
35
+ const existing =
36
+ input.openItems.length === 0
37
+ ? "- (none)"
38
+ : input.openItems
39
+ .slice(0, 20)
40
+ .map((item) => `- ${item.id} | ${item.title} | ${item.summary}`)
41
+ .join("\n");
42
+
43
+ return [
44
+ "UAT clustering run.",
45
+ "",
46
+ "The operator is about to accept user-visible behaviour in the browser page that is now open.",
47
+ "Turn the pending change records into a small number of acceptance items — not one item per record.",
48
+ "",
49
+ `Pending change records (${input.pending.length}, showing ${shown.length}${hidden > 0 ? `, ${hidden} left for the next run` : ""}):`,
50
+ ...shown.map(describeCandidate),
51
+ "",
52
+ "Already open acceptance items (link new evidence here instead of duplicating):",
53
+ existing,
54
+ "",
55
+ "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.`,
57
+ "- 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
+ "- steps: 3-6 concrete steps (what to open, click, type, run) and the expected result of each.",
59
+ "- edge: optional corner cases worth one quick try (empty input, wrong order, offline, permission denied).",
60
+ "- skip: what NOT to test this round (internal refactors, renames, dependency bumps) — one short line.",
61
+ "- Prefer `uat_item` op=\"link\" onto an existing open item over creating a near-duplicate.",
62
+ `- Create at most ${input.maxItems} new items in this run; leftovers stay pending and show up next time.`,
63
+ "- 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
+ "- When you are done, reply with one line: how many items and links you recorded.",
65
+ ].join("\n");
66
+ }
67
+
68
+ export const UAT_MODE_BANNER = [
69
+ "[ASK-UAT — ACCEPTANCE]",
70
+ "The operator is accepting behaviour on the page that is open in their browser.",
71
+ "`uat_item` is active: create, link, amend, merge or drop acceptance items when asked.",
72
+ "Do not write the ledger or edit code by hand — the page writes check events itself.",
73
+ ].join("\n");
74
+
75
+ /** One-line status for the command notice. */
76
+ export function describeCounts(state: UatState): string {
77
+ return `${state.counts.open} open · ${state.counts.checked} accepted · ${state.counts.pending} pending`;
78
+ }