create-pmos 0.682.0 → 0.683.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.682.0",
3
+ "version": "0.683.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -33,6 +33,19 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.683.0",
38
+ "at": "2026-11-22T08:20:39.884Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1494,
43
+ "t": "Acceptance criteria on each ticket, written from the done test",
44
+ "s": "Acceptance criteria on each ticket, written from the done test",
45
+ "k": "new"
46
+ }
47
+ ]
48
+ },
36
49
  {
37
50
  "v": "0.682.0",
38
51
  "at": "2026-11-22T07:57:47.146Z",
@@ -369,19 +382,6 @@
369
382
  "k": "new"
370
383
  }
371
384
  ]
372
- },
373
- {
374
- "v": "0.647.0",
375
- "at": "2026-11-20T05:31:50.958Z",
376
- "f": 4,
377
- "prs": [
378
- {
379
- "n": 1429,
380
- "t": "Work's Initiatives tab built from design system blocks",
381
- "s": "Work's Initiatives tab built from design system blocks",
382
- "k": "new"
383
- }
384
- ]
385
385
  }
386
386
  ]
387
387
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@2fa031e4
1
+ kernel-source: pmos@9303acc0
2
2
  assembled: 2026-11-22
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-22T07:57:44Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:20:37Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-22T07:57:44Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:20:37Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-22T07:57:44Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-22T08:20:37Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,17 @@
1
1
  [
2
+ {
3
+ "v": "0.683.0",
4
+ "at": "2026-11-22T08:20:39.884Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1494,
9
+ "t": "Acceptance criteria on each ticket, written from the done test",
10
+ "s": "Acceptance criteria on each ticket, written from the done test",
11
+ "k": "new"
12
+ }
13
+ ]
14
+ },
2
15
  {
3
16
  "v": "0.682.0",
4
17
  "at": "2026-11-22T07:57:47.146Z",
@@ -639,6 +639,7 @@ The benchmark needs a signed-in agent CLI. It never pushes and never opens a pul
639
639
  - `pmos jira moved <move id> --status "<Jira status>"` or `--refused "<why>"`
640
640
  - `pmos jira guesses <initiative> [--from <file|->]`
641
641
  - `pmos jira answer <initiative> <ticket> <n> --text "<answer>"` or `--keep-default`
642
+ - `pmos jira criteria <initiative>`: the done-test checks each ticket carries as acceptance criteria, and the checks on no ticket
642
643
 
643
644
  Every command takes `--json` and `--root <dir>`.
644
645
 
@@ -92,6 +92,28 @@ To see every ticket in the terminal:
92
92
  pmos jira show <initiative>
93
93
  ```
94
94
 
95
+ ## Acceptance criteria from the done test
96
+
97
+ The people who build a ticket often never see the initiative's done test. So when the initiative has a done test (`done_test_path`), each drafted ticket carries the checks that apply to it, at the end of its Acceptance Criteria, under **From the done test**. Each check is written as Given / When / Then:
98
+
99
+ - **Given** the ticket's work is built,
100
+ - **When** a reviewer checks it the way the done test says,
101
+ - **Then** the check holds.
102
+
103
+ PMOS puts a check on a ticket in this order:
104
+
105
+ 1. A check that names a ticket id, such as TD-01, goes to that ticket.
106
+ 2. With one ticket, every check goes to it.
107
+ 3. Otherwise a check goes to the ticket that shares the most words with it (at least two).
108
+
109
+ A check that fits no ticket is not put on a ticket. `pmos jira draft` and `pmos jira criteria` list it as "on no ticket". To place it, name the ticket id in the check, or add the criteria to a ticket yourself.
110
+
111
+ Your own criteria stay above the block. A ticket you edited, selected or pushed is not changed. When the done test changes, the next draft updates the block on the tickets PMOS may still change. Nothing is sent to Jira until you select a ticket and push it.
112
+
113
+ ```
114
+ pmos jira criteria <initiative>
115
+ ```
116
+
95
117
  ## The dry run: where a builder would guess
96
118
 
97
119
  A ticket points to the PRD, but the builder holds only the ticket. Before you select the tickets, PMOS dry-runs them: the initiative's background run reads each drafted ticket as a builder would, and lists every point where it would have to guess. For each guess it quotes the PRD lines that answer it.
@@ -20,6 +20,7 @@
20
20
  * pmos jira moved <move id> --status "<Jira status>" | --refused "<why>" the agent's answer for one move
21
21
  * pmos jira guesses <initiative> [--from <file|->] a ticket dry run (lib/ticket-dry-run.js), recorded or shown
22
22
  * pmos jira answer <initiative> <ticket> <n> --text "<answer>" | --keep-default the PM's answer to one dry-run gap, or its default kept
23
+ * pmos jira criteria <initiative> the done-test checks each ticket carries, and the checks on no ticket (A384)
23
24
  * every command: [--json] [--root <dir>]
24
25
  *
25
26
  * This command never talks to Jira. An agent session does, with the PM's own Atlassian connection (D53, D88), and
@@ -35,7 +36,7 @@ const jiraMoves = require('./jira-moves.js');
35
36
  const planItems = require('./plan-items.js');
36
37
  const guard = require('./pm-guard.js');
37
38
 
38
- const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which', 'moves', 'moved', 'guesses', 'answer'] };
39
+ const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which', 'moves', 'moved', 'guesses', 'answer', 'criteria'] };
39
40
  const USAGE = [
40
41
  'usage: pmos jira draft|show|epic|approve|pending|record|query|sync|summary|which — Jira tickets from the PRD, and their status',
41
42
  ' pmos jira draft <initiative> [--dry-run] draft one ticket per PRD item, in the ticket template',
@@ -45,6 +46,7 @@ const USAGE = [
45
46
  ' Quotes not found word for word in the PRD, done test or record are dropped. Gaps go to the day\'s question list.',
46
47
  ' pmos jira guesses <initiative> the dry run so far: the guesses of each ticket and the open gaps',
47
48
  ' pmos jira answer <initiative> <ticket> <n> --text "<answer>" | --keep-default the PM\'s answer to gap n, or keep its default: it goes into the ticket',
49
+ ' pmos jira criteria <initiative> the done-test checks each ticket carries as acceptance criteria, and the checks on no ticket',
48
50
  ' pmos jira epic <initiative> new|<KEY or link> [--group <g>] create a new epic at the first push, or use an existing one',
49
51
  ' pmos jira approve <initiative> <ID> … select tickets to push (you, in your own terminal)',
50
52
  ' pmos jira pending <initiative> what the push creates or updates in Jira',
@@ -219,6 +221,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
219
221
  if (r.from === 'done-test' || r.from === 'tasks') lines.push(` From ${r.from === 'done-test' ? 'the done test\'s checks' : 'the open tasks'} (${r.sources.join(', ')}): the PRD has no stories section.`);
220
222
  else if (r.from === 'plan') lines.push(' From the plan: each milestone is an epic, with the tasks that end before it. A Project has no PRD.');
221
223
  for (const c of r.changes) lines.push(` ${c.what.padEnd(9)} ${c.ticket} · ${c.summary}${c.why ? ` (${c.why})` : ''}`);
224
+ if (r.criteria) lines.push(` Acceptance criteria from the done test (${r.criteria.doneTest}): ${r.criteria.checks - r.criteria.unmatched.length} of ${r.criteria.checks} checks on a ticket${r.criteria.unmatched.length ? `; on no ticket: ${r.criteria.unmatched.join(', ')} (see pmos jira criteria ${initiative})` : ''}.`);
222
225
  lines.push('Read them on the Jira tickets tab, or with pmos jira show. Select the ready ones there, or with pmos jira approve.');
223
226
  return out(r, lines);
224
227
  }
@@ -243,6 +246,16 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
243
246
  if (r.gaps) lines.push(` The ${r.gaps === 1 ? 'gap goes' : r.gaps + ' gaps go'} to the PM's question list for today or tomorrow.`);
244
247
  return out(r, lines);
245
248
  }
249
+ if (verb === 'criteria') {
250
+ const r = jiraTickets.criteria(root, initiative);
251
+ if (!r.ok) return fail(r.error);
252
+ if (!r.doneTest) return out(r, [`${initiative} · no done test: give the record a done_test_path, then run pmos jira draft ${initiative}`]);
253
+ const lines = [`${initiative} · ${r.tickets_with_criteria} of ${r.tickets.length} ${r.tickets.length === 1 ? 'ticket carries' : 'tickets carry'} acceptance criteria from ${r.doneTest} · ${r.checks_on_a_ticket} of ${r.checks} checks on a ticket`];
254
+ for (const t of r.tickets) lines.push(` ${t.id} · ${t.checks.length ? `checks ${t.checks.join(', ')}` : 'no check'} · ${t.summary}`);
255
+ for (const u of r.unmatched) lines.push(` on no ticket: ${u.label} · ${u.check}`);
256
+ if (r.unmatched.length) lines.push('Name the ticket id in the check, or add the criteria to a ticket by hand, then run pmos jira draft again.');
257
+ return out(r, lines);
258
+ }
246
259
  if (verb === 'answer') {
247
260
  const [, ticket, n] = pos;
248
261
  if (!ticket || !n || (!flags.text === !flags['keep-default'])) return need('<initiative> <ticket> <n> --text "<the answer>" | --keep-default');
@@ -52,6 +52,7 @@ const planItems = require('./plan-items.js');
52
52
  const planTree = require('./plan-tree.js');
53
53
  const consoleState = require('./console-state');
54
54
  const { repoScript } = require('./repo-script.js');
55
+ const TAm = () => require('./ticket-acceptance.js');
55
56
 
56
57
  const KEY_RE = /^[A-Za-z][A-Za-z0-9_]*-\d+$/;
57
58
  const KEY_IN = /\b([A-Z][A-Z0-9_]+-\d+)\b/;
@@ -215,22 +216,9 @@ function readPrd(root, prd) {
215
216
  try { return fs.readFileSync(path.join(root, prd), 'utf8'); } catch { /* the main tree */ }
216
217
  try { return fs.readFileSync(path.join(mainRoot(root), prd), 'utf8'); } catch { return null; }
217
218
  }
218
- /** The checks of a done test (D107): its table rows `| n | check | how |`, else its top-level bullets. → [{ n, check, how }] */
219
- function checksInDoneTest(text) {
220
- const lines = stripFm(text).split('\n');
221
- const out = [];
222
- for (const l of lines) {
223
- const m = /^\|\s*(\d+)\s*\|\s*(.+?)\s*\|\s*(.*?)\s*\|?\s*$/.exec(l);
224
- if (m && m[2] && !/^-+$/.test(m[2])) out.push({ n: Number(m[1]), check: m[2].replace(/\\\|/g, '|'), how: m[3] || '' });
225
- }
226
- if (out.length) return out;
227
- let n = 0;
228
- for (const l of lines) {
229
- const b = /^[-*] (?:\[[ xX]\] )?(.+)$/.exec(l);
230
- if (b) out.push({ n: ++n, check: b[1].trim(), how: '' });
231
- }
232
- return out;
233
- }
219
+ /** The checks of a done test (D107): its table rows `| 1 | check | how |` or `| Q1 | … |`, else its top-level bullets.
220
+ * → [{ label, n, check, how }] (lib/ticket-acceptance.js) */
221
+ function checksInDoneTest(text) { return TAm().checksOf(text); }
234
222
  /** The done test a record names, read from the worktree or the main tree (a kit repository may name it under pmos/). */
235
223
  function readDoneTest(root, rfm) {
236
224
  const p = rfm && isStr(rfm.done_test_path) ? rfm.done_test_path.trim() : '';
@@ -244,12 +232,14 @@ function readDoneTest(root, rfm) {
244
232
  }
245
233
  return null;
246
234
  }
247
- /** One ticket item per done-test check: the check is the requirement, and how to check it is the acceptance. */
235
+ /** One ticket item per done-test check: the check is the requirement, and how to check it is the acceptance. `check` names the
236
+ * done-test row, so the criteria block (ticket-acceptance-from-done-test) writes it as Given / When / Then in place of these lines. */
248
237
  function itemsFromDoneTest(dt, title) {
249
238
  return checksInDoneTest(dt.text).map((c) => {
250
239
  const check = oneLine(c.check);
251
240
  return {
252
- id: `DT-${String(c.n).padStart(2, '0')}`, title: clip(check.replace(/\.$/, ''), 120), epic: null, refLabel: 'Done test', source: dt.path,
241
+ id: /^\d+$/.test(c.label) ? `DT-${String(c.n).padStart(2, '0')}` : `DT-${c.label}`, check: c.label,
242
+ title: clip(check.replace(/\.$/, ''), 120), epic: null, refLabel: 'Done test', source: dt.path,
253
243
  body: [`### User Story`, `As the PM of ${title}, I want this check of the done test to pass: ${check}`,
254
244
  `### Functional Requirements`, check,
255
245
  `### Acceptance Criteria`, `- ${check}`, ...(c.how ? [`- How to check: ${oneLine(c.how)}`] : [])].join('\n'),
@@ -537,18 +527,84 @@ function draft(root, initiative, { dryRun = false, now } = {}) {
537
527
  }
538
528
  // Tickets whose item is gone stay, at the end: the tab says so and Jira is not touched (J10).
539
529
  for (const t of byId.values()) out.push(t);
530
+ // Acceptance criteria from the done test (ticket-acceptance-from-done-test, A384), on every ticket PMOS may still write.
531
+ const crit = applyCriteria(root, initiative, st, out);
532
+ const listed = new Set(changes.map((c) => c.ticket));
533
+ for (const id of crit.written) if (!listed.has(id)) { const t = out.find((x) => x.id === id); changes.push({ ticket: id, what: 'criteria', summary: t.summary, why: 'its acceptance criteria from the done test changed' }); }
540
534
  const fm = old ? { ...old.fm } : {};
541
535
  if (!fm.epic_mode) {
542
536
  const anchor = anchorOf(recordFm(root, initiative) || {});
543
537
  fm.epic_mode = anchor ? 'existing' : 'new';
544
538
  if (anchor && !fm.epic) fm.epic = anchor;
545
539
  }
546
- const result = { ok: true, initiative, draft: draftRel(root, initiative), sources: st.sources, from: st.from, tickets: out.length, changes, changed: !old || changes.length > 0 };
540
+ const result = { ok: true, initiative, draft: draftRel(root, initiative), sources: st.sources, from: st.from, tickets: out.length, changes, changed: !old || changes.length > 0,
541
+ criteria: crit.doneTest ? { doneTest: crit.doneTest, checks: crit.checks, unmatched: crit.unmatched } : null };
547
542
  if (dryRun || (old && !changes.length)) return result;
548
543
  writeDraft(root, initiative, { fm, tickets: out }, { now, prd: st.prd });
549
544
  return result;
550
545
  }
551
546
 
547
+ // ── acceptance criteria from the done test (initiative ticket-acceptance-from-done-test; A384) ──────────
548
+ /** What a ticket says, for matching it to a check: summary, story, flow, requirements, end states and the PM's own criteria. */
549
+ function ticketWords(t) {
550
+ const sec = t.sections || {};
551
+ return [t.summary, sec.story, sec.flow, sec.functional, sec.terminal, TAm().withBlock(sec.acceptance, '')].filter(Boolean).join('\n');
552
+ }
553
+ /**
554
+ * Put each ticket's done-test checks, as Given / When / Then, at the end of its Acceptance Criteria. Only tickets PMOS may still
555
+ * write (dryRunWritable). A ticket drafted from one check alone carries the block in place of its plain lines.
556
+ * → { doneTest, checks, unmatched: [label], written: [id] }
557
+ */
558
+ function applyCriteria(root, initiative, st, tickets) {
559
+ const rfm = recordFm(root, initiative) || {};
560
+ const dt = readDoneTest(root, rfm);
561
+ const checks = dt ? checksInDoneTest(dt.text) : [];
562
+ if (!dt || !checks.length) return { doneTest: null, checks: 0, unmatched: [], written: [] };
563
+ const own = new Map((st && st.ok ? st.items : []).filter((x) => x.check).map((x) => [x.id, x.check]));
564
+ const a = TAm().assign(checks, tickets.map((t) => ({ id: t.id, text: ticketWords(t) })), { own });
565
+ const byLabel = new Map(checks.map((c) => [c.label, c]));
566
+ const title = oneLine(rfm.title || initiative);
567
+ const written = [];
568
+ for (const t of tickets) {
569
+ if (!dryRunWritable(t)) continue;
570
+ const labels = a.byTicket.get(t.id) || [];
571
+ const block = TAm().blockOf(labels.map((l) => byLabel.get(l)), { path: dt.path, subject: own.has(t.id) ? title : oneLine(t.summary) });
572
+ const base = own.has(t.id) && block ? '' : t.sections.acceptance;
573
+ const next = TAm().withBlock(base, block);
574
+ if (next === (t.sections.acceptance || '')) continue;
575
+ t.sections.acceptance = next; t.drafted = contentHash(t); written.push(t.id);
576
+ }
577
+ return { doneTest: dt.path, checks: checks.length, unmatched: a.unmatched, written };
578
+ }
579
+ /** The labels of the checks a ticket's text carries in its "From the done test" block. */
580
+ function criteriaLabelsOf(t) {
581
+ const s = String((t.sections || {}).acceptance || '');
582
+ const i = s.indexOf(TAm().MARK);
583
+ if (i < 0) return [];
584
+ return [...s.slice(i).matchAll(/^- Check (\S+)\s*$/gm)].map((m) => m[1]);
585
+ }
586
+ /**
587
+ * The coverage of the done test by the drafted tickets, read from the ticket text itself: which checks each ticket carries, and
588
+ * which checks no ticket carries. → { ok, doneTest, tickets: [{ id, summary, checks: [label] }], tickets_with_criteria, checks,
589
+ * checks_on_a_ticket, unmatched: [{ label, check }] } | { ok: false, status, error }
590
+ */
591
+ function criteria(root, initiative) {
592
+ const rfm = recordFm(root, initiative);
593
+ if (!rfm) return { ok: false, status: 404, error: `no initiative ${initiative} in this repository` };
594
+ const { d, error } = mustDraft(root, initiative);
595
+ if (error) return { ok: false, status: 404, error };
596
+ const dt = readDoneTest(root, rfm);
597
+ const checks = dt ? checksInDoneTest(dt.text) : [];
598
+ const tickets = d.tickets.map((t) => ({ id: t.id, summary: t.summary, checks: criteriaLabelsOf(t) }));
599
+ const on = new Set(tickets.flatMap((t) => t.checks));
600
+ return {
601
+ ok: true, initiative, doneTest: dt ? dt.path : null, tickets: tickets.length ? tickets : [],
602
+ tickets_with_criteria: tickets.filter((t) => t.checks.length).length, checks: checks.length,
603
+ checks_on_a_ticket: checks.filter((c) => on.has(c.label)).length,
604
+ unmatched: checks.filter((c) => !on.has(c.label)).map((c) => ({ label: c.label, check: oneLine(c.check) })),
605
+ };
606
+ }
607
+
552
608
  // ── the dry run (initiative dry-run-tickets-before-build; A194) ─────────────────────────────────────
553
609
  /** The dry-run helpers, loaded when a dry run is read or written. */
554
610
  /** The state folder of the repository: <state>/tracker/ holds the ticket drafts, dry runs and sign-offs. */
@@ -713,7 +769,7 @@ function view(root, initiative, { snapshot } = {}) {
713
769
  : waiting ? 'pushing' : edited ? 'edited' : null;
714
770
  return {
715
771
  id: t.id, summary: t.summary, type: t.type, priority: t.priority, estimate: t.estimate, depends: t.depends,
716
- epic: t.epic ? groupId(t.epic) : null, sections: t.sections, key: t.jira, inJira: !!t.jira, edited, prdChanged, removed, missing, waiting,
772
+ epic: t.epic ? groupId(t.epic) : null, sections: t.sections, doneTestChecks: criteriaLabelsOf(t), key: t.jira, inJira: !!t.jira, edited, prdChanged, removed, missing, waiting,
717
773
  selectable: !missing.length && !removed && (!t.jira || t.pushed !== h), flag,
718
774
  jira: r ? { status: r.status, category: r.category, sprint: r.sprint, subtasks: r.subtasks, flagged: !!r.flagged, reason: r.reason || null, url: r.url || null, stale: !!r.stale,
719
775
  assignee: (typeof r.assignee === 'string' && r.assignee.trim()) || (r.assignee && (r.assignee.displayName || r.assignee.name)) || null } : null,
@@ -1011,4 +1067,5 @@ module.exports = {
1011
1067
  readDraft, parseDraft, pushedTickets, draftedInitiatives, epicInitiatives, epicKeysOf, linkedEpics, anchorOf, missingOf, contentHash, describe,
1012
1068
  draftPath, draftRel, jiraDir, relOf, recordFm, prdOf,
1013
1069
  dryRun, answerDryRun, dryRunGaps, dryRunView, dryRunInitiatives, dryRunPath, stateDirOf,
1070
+ criteria, checksInDoneTest,
1014
1071
  };
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+ /* ticket-acceptance.js — acceptance criteria on each drafted ticket, written from the initiative's done test
3
+ * (initiative ticket-acceptance-from-done-test; bet A384 in pmos-ideas proofs/A384-ac).
4
+ *
5
+ * On three test products, 69% of recent tickets stated no acceptance criteria, and the done test the PM agreed lived only in
6
+ * PMOS. So each ticket PMOS drafts carries the done-test checks that apply to it, as Given / When / Then, and the checks that fit
7
+ * no ticket are listed so the PM can place them.
8
+ *
9
+ * checksOf(text) → [{ label, n, check, how }] the done test's rows (`| 1 |` or `| Q1 |`), else bullets PURE
10
+ * gwt(check, { subject }) → { given, when, then } PURE
11
+ * assign(checks, tickets) → { byTicket: Map(id → [label]), unmatched: [label] } PURE
12
+ * blockOf(rows, { path, subject }) → the block that goes at the end of Acceptance Criteria, or '' PURE
13
+ * withBlock(text, block) → the section text with the old block replaced PURE
14
+ *
15
+ * MATCHING. A check that names a ticket id (TD-01) goes to that ticket. With one ticket, every check goes to it. Else a check goes
16
+ * to the ticket, or the tied tickets, that share most of its words (summary, story and requirements), when they share at least
17
+ * two. A check that fits no ticket is never guessed onto one: it is listed as not on any ticket. No model, nothing sent.
18
+ */
19
+
20
+ const MARK = '**From the done test**';
21
+ const MIN_SHARED = 2;
22
+ const STOP = new Set(('a an and are as at be been by can cannot does each every for from has have how in into is it its it\'s more no not ' +
23
+ 'of on one or our per same says so than that the their them then there these they this those to two was we were what when where which who ' +
24
+ 'will with without would you your check checks test tests done pass passes run runs ticket tickets item items shows show read reads ' +
25
+ 'still only also any all some other new use used uses user users pmos').split(' '));
26
+
27
+ const one = (s) => String(s == null ? '' : s).replace(/[\r\n\t]+/g, ' ').replace(/\s{2,}/g, ' ').trim();
28
+ const stripFm = (text) => String(text).replace(/^---\n[\s\S]*?\n---\n?/, '');
29
+ const words = (s) => {
30
+ const out = new Set();
31
+ for (const w of String(s || '').toLowerCase().replace(/`[^`]*`/g, (m) => m.replace(/[^a-z0-9]+/g, ' ')).split(/[^a-z0-9]+/)) {
32
+ if (w.length < 3 || STOP.has(w) || /^\d+$/.test(w)) continue;
33
+ out.add(w.length > 4 ? w.replace(/(ies|es|s|ed|ing)$/, '') : w); // a light stem: "tickets" and "ticket", "drafted" and "draft"
34
+ }
35
+ return out;
36
+ };
37
+ const sentence = (s) => one(s).replace(/[.;:,\s]+$/, '');
38
+ const lowerFirst = (s) => (/^[A-Z](?![A-Z0-9_-])/.test(s) ? s[0].toLowerCase() + s.slice(1) : s); // "A reader" → "a reader"; "PW-3", "API" kept
39
+
40
+ /** The checks of a done test: its table rows `| 1 | check | how |` or `| Q1 | … |`, else its top-level bullets. */
41
+ function checksOf(text) {
42
+ const lines = stripFm(text).split('\n');
43
+ const out = [];
44
+ for (const l of lines) {
45
+ if (!/^\s*\|/.test(l)) continue;
46
+ // cells split on pipes, an escaped pipe (\|) kept as text
47
+ const cells = l.replace(/\\\|/g, '\u0000').trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((c) => c.replace(/\u0000/g, '|').trim());
48
+ const [label, check, how] = cells;
49
+ if (!/^[A-Za-z]{0,4}-?\d+[a-z]?$/.test(label || '') || !check || /^:?-+:?$/.test(check)) continue;
50
+ out.push({ label, n: Number(/(\d+)/.exec(label)[1]), check, how: how || '' });
51
+ }
52
+ if (out.length) return out;
53
+ let n = 0;
54
+ for (const l of lines) {
55
+ const b = /^[-*] (?:\[[ xX]\] )?(.+)$/.exec(l);
56
+ if (b) { n++; out.push({ label: String(n), n, check: b[1].trim(), how: '' }); }
57
+ }
58
+ return out;
59
+ }
60
+
61
+ /** A check as Given / When / Then. subject: what is built (the ticket's summary, or the initiative's title). */
62
+ function gwt(c, { subject } = {}) {
63
+ const what = sentence(subject) || 'this work';
64
+ const how = sentence(c && c.how);
65
+ return {
66
+ given: `${what} is built`,
67
+ when: how ? `a reviewer checks it: ${lowerFirst(how)}` : 'a reviewer checks it',
68
+ then: lowerFirst(sentence(c && c.check)),
69
+ };
70
+ }
71
+
72
+ /**
73
+ * Which checks go on which ticket. tickets: [{ id, text }] where text is what the ticket says (summary, story, requirements).
74
+ * own: optional Map(ticket id → label) for tickets drafted from one check each (a draft from the done test alone).
75
+ */
76
+ function assign(checks, tickets, { own } = {}) {
77
+ const byTicket = new Map(tickets.map((t) => [t.id, []]));
78
+ const unmatched = [];
79
+ const tw = tickets.map((t) => ({ id: t.id, w: words(t.text) }));
80
+ for (const c of checks) {
81
+ let to = [];
82
+ if (own) for (const [id, label] of own) if (label === c.label && byTicket.has(id)) to.push(id);
83
+ if (!to.length) {
84
+ const named = tickets.filter((t) => new RegExp(`(^|[^A-Za-z0-9-])${t.id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}([^A-Za-z0-9-]|$)`).test(`${c.check} ${c.how}`));
85
+ to = named.map((t) => t.id);
86
+ }
87
+ if (!to.length && tickets.length === 1) to = [tickets[0].id];
88
+ if (!to.length) {
89
+ const cw = words(`${c.check} ${c.how}`);
90
+ let best = 0;
91
+ const score = tw.map((t) => { let s = 0; for (const w of cw) if (t.w.has(w)) s++; if (s > best) best = s; return { id: t.id, s }; });
92
+ if (best >= MIN_SHARED) to = score.filter((x) => x.s === best).map((x) => x.id);
93
+ }
94
+ if (!to.length) { unmatched.push(c.label); continue; }
95
+ for (const id of to) byTicket.get(id).push(c.label);
96
+ }
97
+ return { byTicket, unmatched };
98
+ }
99
+
100
+ /** The block for one ticket: each check as Given / When / Then. rows: [{ label, check, how }]. '' when there is none. */
101
+ function blockOf(rows, { path, subject } = {}) {
102
+ if (!rows || !rows.length) return '';
103
+ const lines = [`${MARK}${path ? ` (\`${path}\`)` : ''}`, ''];
104
+ for (const c of rows) {
105
+ const g = gwt(c, { subject });
106
+ lines.push(`- Check ${c.label}`, ` - Given ${g.given}`, ` - When ${g.when}`, ` - Then ${g.then}`);
107
+ }
108
+ return lines.join('\n');
109
+ }
110
+
111
+ /** The section text with the old block taken out and the new one put at its end. */
112
+ function withBlock(text, block) {
113
+ const s = String(text || '');
114
+ const i = s.indexOf(MARK);
115
+ const base = (i >= 0 ? s.slice(0, i) : s).replace(/\s+$/, '');
116
+ const clean = /^[\s—–-]*$/.test(base) ? '' : base;
117
+ return [clean, block].filter(Boolean).join('\n\n');
118
+ }
119
+
120
+ module.exports = { MARK, checksOf, gwt, assign, blockOf, withBlock, words };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.682.0",
3
+ "version": "0.683.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.682.0",
9
+ "version": "0.683.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.682.0",
3
+ "version": "0.683.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Acceptance criteria from the done test (initiative ticket-acceptance-from-done-test, done test AC1-AC9): each drafted ticket carries the done-test checks that apply to it as Given / When / Then, and the checks on no ticket are listed. Synthetic kit-layout repositories. No connector, model or network.",
3
+ "modules": [
4
+ "ticket-acceptance.test.js"
5
+ ],
6
+ "seconds": {
7
+ "ticket-acceptance.test.js": 5
8
+ }
9
+ }