create-pmos 0.408.0 → 0.410.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 (77) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/board-programs-test.js +1 -1
  7. package/workspace/board-wf-shot.js +45 -0
  8. package/workspace/board-workflows-test.js +186 -0
  9. package/workspace/briefing-premium-board-test.js +2 -2
  10. package/workspace/briefing-premium-initiative-test.js +1 -1
  11. package/workspace/changelog.json +24 -0
  12. package/workspace/fixtures/board-workflows-facts.js +49 -0
  13. package/workspace/fixtures/workflows-facts.js +53 -0
  14. package/workspace/guide/home.md +1 -0
  15. package/workspace/guide/index.md +1 -0
  16. package/workspace/guide/programs.md +2 -1
  17. package/workspace/guide/workflows.md +58 -0
  18. package/workspace/ini-workflow-test.js +177 -0
  19. package/workspace/lib/board-premium.js +30 -5
  20. package/workspace/lib/board-trail.js +24 -7
  21. package/workspace/lib/briefing-premium-agent.js +3 -0
  22. package/workspace/lib/engine/boards.js +30 -2
  23. package/workspace/lib/engine/workflows.js +204 -0
  24. package/workspace/lib/pmos-verbs.js +3 -0
  25. package/workspace/lib/programs.js +22 -7
  26. package/workspace/lib/route-modules.js +1 -0
  27. package/workspace/lib/routes-boards.js +157 -7
  28. package/workspace/lib/routes-programs.js +5 -0
  29. package/workspace/lib/routes-workflows.js +105 -0
  30. package/workspace/lib/workflow-chat.js +26 -0
  31. package/workspace/lib/workflow-cli.js +141 -0
  32. package/workspace/lib/workflows-store.js +108 -0
  33. package/workspace/package-lock.json +2 -2
  34. package/workspace/package.json +1 -1
  35. package/workspace/program-charter-test.js +243 -0
  36. package/workspace/program-panel-test.js +1 -1
  37. package/workspace/public/pm/bd-acts.js +10 -5
  38. package/workspace/public/pm/bd-asks.js +2 -2
  39. package/workspace/public/pm/bd-prog-panel.js +36 -15
  40. package/workspace/public/pm/bd-prog.js +14 -4
  41. package/workspace/public/pm/bd-views.js +128 -45
  42. package/workspace/public/pm/bd-wf.js +99 -0
  43. package/workspace/public/pm/cozy-board.css +67 -6
  44. package/workspace/public/pm/cozy-evmodel.js +1 -1
  45. package/workspace/public/pm/cozy-panel.css +12 -6
  46. package/workspace/public/pm/cozy-settings.js +4 -2
  47. package/workspace/public/pm/cozy-viewer.js +36 -9
  48. package/workspace/public/pm/cozy-vw-shell.css +8 -0
  49. package/workspace/public/pm/goal-chat.js +1 -1
  50. package/workspace/public/pm/home-app.js +17 -9
  51. package/workspace/public/pm/home-ini-model.js +2 -2
  52. package/workspace/public/pm/home-ini.css +30 -0
  53. package/workspace/public/pm/home-ini.js +52 -9
  54. package/workspace/public/pm/home-list.js +10 -5
  55. package/workspace/public/pm/home-today.js +5 -5
  56. package/workspace/public/pm/ini-wf-model.js +91 -0
  57. package/workspace/public/pm/ini-wf.js +160 -0
  58. package/workspace/public/pm/premium-board.js +98 -30
  59. package/workspace/public/pm/premium-initiative-head.js +18 -8
  60. package/workspace/public/pm/program-charter.css +135 -0
  61. package/workspace/public/pm/program-charter.js +333 -0
  62. package/workspace/public/pm/program-model.js +48 -5
  63. package/workspace/public/pm/wf-edit.js +119 -0
  64. package/workspace/public/pm/wf-model.js +48 -0
  65. package/workspace/public/pm/wf-page.css +162 -0
  66. package/workspace/public/pm/wf-page.js +398 -0
  67. package/workspace/public/pm/wf-stage.js +187 -0
  68. package/workspace/public/premium-workflows.html +31 -0
  69. package/workspace/public/premium.html +1 -0
  70. package/workspace/server.js +1 -1
  71. package/workspace/skills/workflow-setup.skill +57 -0
  72. package/workspace/test-lists/ini-workflow.json +6 -0
  73. package/workspace/test-lists/program-charter.json +9 -0
  74. package/workspace/test-lists/workflows-board.json +13 -0
  75. package/workspace/test-lists/workflows-setup.json +13 -0
  76. package/workspace/test-lists/workflows.json +5 -0
  77. package/workspace/workflows-setup-test.js +346 -0
@@ -0,0 +1,58 @@
1
+ ---
2
+ type: Guide
3
+ title: "Workflows: the stages each kind of initiative goes through"
4
+ description: "Settings › Workflows: the workflow list, one numbered list of stages across To do, In progress and Done, the stage panel, Only when conditions, removing a stage in use, New workflow in the chat, and the pmos workflow commands."
5
+ timestamp: 2026-10-25
6
+ ---
7
+
8
+ # Workflows
9
+
10
+ A **workflow** is the list of stages that one kind of initiative goes through ([D99](/DECISIONS.md)). PMOS ships one workflow, **Product feature**: Triage, Discover, Plan, Prioritize, Build, ◆ Deliver, Monitor and ◆ Evaluate. You make any other workflow, for example a tender or a vendor onboarding.
11
+
12
+ Open it from **Menu › Settings › Workflows**. The address is `/premium-workflows.html`.
13
+
14
+ ## The page
15
+
16
+ - **The list** on the left shows each workflow and how many initiatives use it. **+** starts a new workflow. An archived workflow shows last, under **Archived**.
17
+ - **The workflow** is one numbered list of stages, in three columns: **To do**, **In progress** and **Done**. Drag a stage to change its place or its column. **Add a stage** adds one at the end of that column. The dashed **Won't do · Archived** column is in every workflow: any initiative can go there from any stage, and come back to Triage.
18
+ - **Triage** is always the first stage, in To do.
19
+ - Tap the name of the workflow to rename it. **⋯** has **Copy** and **Archive**. You cannot archive a workflow that initiatives use.
20
+ - **Product feature** cannot change. **Copy it** to make a workflow of your own from it.
21
+
22
+ ## A stage
23
+
24
+ Tap a stage to open it in the side panel. Tap its name at the top to rename it. The panel has:
25
+
26
+ - **Category**: To do, In progress or Done.
27
+ - **Output**: what finishes the stage, and its kind. **Document** (PMOS drafts it from the template), **Jira tickets**, **Sign-off** or **Checklist only**. The kind sets how the Board counts progress.
28
+ - **To finish**: the list of items to do before the stage is done.
29
+ - **When it runs**: **Always**, **Optional** (you can skip it) or **Only when** a condition holds.
30
+ - **Then**: the next stage in the list, or a stage you pick. **Unless … go to …** adds a jump or a loop, in plain words.
31
+ - **Milestone**: a ◆ checkpoint with a date. **Moves on by itself**: the initiative goes to the next stage when every item is done.
32
+ - **⋯** has **Move up**, **Move down** and **Remove this stage**.
33
+
34
+ ### Only when
35
+
36
+ Write the condition in your own words, for example "the contract is over $50k". There is no rule builder. PMOS reads the initiative's documents when it reaches the stage before, and decides. **How it reads today** shows what PMOS read for each initiative on the workflow. **Who decides** is set per workflow: **PMOS, and tells you why**, or **PMOS suggests, you confirm**. The stage card always shows the reason, and you can undo a skip.
37
+
38
+ ### Removing a stage in use
39
+
40
+ If initiatives are in the stage, PMOS asks where they move. **Move and remove** moves them and then removes the stage. Initiatives that already passed the stage keep it in their history.
41
+
42
+ ## New workflow
43
+
44
+ Press **+**. The chat opens, scoped **New workflow**. Tell Claude how the work goes, in your own words, and add a policy or an old checklist if you have one. Claude drafts the stages and shows the draft beside the chat, with a reason for each choice. Answer its question or ask for a change, and it drafts again.
45
+
46
+ - **Create workflow** saves the draft.
47
+ - **Edit by hand** opens the draft on the page, so you can change it before you create it.
48
+ - You can also start **blank** (only Triage) or **from a copy** of a workflow.
49
+
50
+ ## The pmos workflow commands
51
+
52
+ An agent writes a draft or a reading with these commands. It never saves, copies or archives a workflow: those are your presses on the page.
53
+
54
+ - `pmos workflow list` names the workflows of this repository.
55
+ - `pmos workflow show <id>` shows one workflow, its stages numbered.
56
+ - `pmos workflow draft --file <path>` writes the draft that the New workflow chat shows. `--note` adds a line.
57
+ - `pmos workflow show-draft` shows the draft that is open.
58
+ - `pmos workflow judge --board <id> --id <initiative> --stage <key> --runs yes|no|unsure --why <reason> --cite <where>` records PMOS's reading of an Only when stage. **unsure** makes PMOS ask you. `--undo` takes a reading back.
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* ini-workflow-test.js — an initiative's own workflow on its page in Home's Viewer (D99, initiative workflows-per-initiative, workstream D;
4
+ * canvas WfTriage, WfAChange, WfAWontDo, the wfBuild note). The pure half is ini-workflow.test.js.
5
+ * Serves the real page from the real server; GET /api/board-premium answers lib/board-premium.js's fixture model with one initiative on a
6
+ * Tender workflow that PMOS set from the BRD, GET /api/workflows answers Product feature and Tender, and every write is caught.
7
+ * W1 the kind line and the card count its own workflow · W2 "Set to Tender from the BRD · Undo" · W3 the Change picker · W4 Switch ·
8
+ * W5 the ⋯ menu · W6 Won't do · W7 back to Triage · W8 phone and dark. SHOTS=<dir> also writes the screenshots at 1440 and 390. */
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const { spawn } = require('child_process');
12
+ const { findBrowser } = require('./lib/find-browser');
13
+ const T = require('./test-run').configure({ name: 'ini-workflow' });
14
+ const IP = require('./lib/initiative-premium.js');
15
+ const F = require('./fixtures/initiative-premium-facts.js');
16
+ const BP = require('./lib/board-premium.js');
17
+ const BF = require('./fixtures/board-premium-facts.js');
18
+ const BRP = require('./lib/briefing-premium.js');
19
+ const BRF = require('./fixtures/briefing-premium-facts.js');
20
+ const WF = require('../scripts/workflows.js');
21
+
22
+ const BASE = T.BASE;
23
+ const SHOTS = process.env.SHOTS || '';
24
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
25
+ const until = async (fn, ms = 10000, step = 100) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
26
+ const results = [];
27
+ const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 600) : ''}`); };
28
+ let srv = null; let browser = null;
29
+ const finish = async (code) => {
30
+ if (browser) await browser.close().catch(() => {});
31
+ if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
32
+ T.killTmux();
33
+ const bad = results.filter((x) => !x.cond).length;
34
+ console.log(`\n${results.length - bad}/${results.length} ini-workflow assertions passed`);
35
+ process.exit(code !== undefined ? code : (bad ? 1 : 0));
36
+ };
37
+ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
38
+
39
+ const TENDER = WF.check({ id: 'tender', name: 'Tender', icon: 'doc', stages: [
40
+ { name: 'Triage', cat: 'todo', output: { name: 'BRD', kind: 'doc' } }, { name: 'Requirements', cat: 'doing' }, { name: 'RFP out', cat: 'doing', milestone: true },
41
+ { name: 'Q&A session', cat: 'doing', when: { mode: 'optional' } }, { name: 'Bids', cat: 'doing' }, { name: 'Evaluate bids', cat: 'doing' },
42
+ { name: 'Legal review', cat: 'doing' }, { name: 'Award', cat: 'done', milestone: true }, { name: 'Contract', cat: 'done' }, { name: 'Review', cat: 'done', milestone: true },
43
+ ] }).workflow;
44
+ const LIB = [{ ...WF.PRODUCT_FEATURE, count: 6 }, { ...TENDER, count: 1 }];
45
+ const ID = 'self-serve-v2';
46
+ /** The board model with the initiative on Tender, at `cur`, as lib/routes-boards.js workflowRowOf would send it. */
47
+ function board(cur = 'triage', o = {}) {
48
+ const B = BP.build(BF.facts());
49
+ const st = WF.stagesOf(TENDER, { current: cur });
50
+ const s = st.find((x) => x.key === cur);
51
+ const patch = (r) => (r.id !== ID ? r : { ...r, title: 'Office network tender', stage: s.name,
52
+ wf: { id: 'tender', name: 'Tender', icon: 'doc', ...(o.pmos ? { setBy: 'pmos', why: '“choose a vendor for the office network” and “three bidders invited” in the BRD', from: 'product-feature' } : {}) },
53
+ wfStage: { key: s.key, name: s.name, cat: s.cat, milestone: s.milestone, n: s.n, of: s.of },
54
+ wfStages: st.map((x) => ({ key: x.key, name: x.name, cat: x.cat, milestone: x.milestone, auto: x.auto, when: x.when, status: x.status, reading: x.reading })),
55
+ ended: o.ended || null });
56
+ B.rows = B.rows.map(patch);
57
+ if (B.initiatives && B.initiatives.list) B.initiatives.list.rows = B.initiatives.list.rows.map(patch);
58
+ return B;
59
+ }
60
+ const BRIEF = BRP.build(BRF.facts());
61
+
62
+ (async () => {
63
+ const exe = findBrowser();
64
+ if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
65
+ let chromium;
66
+ try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
67
+ srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT), PMOS_SELF_ROOT: path.resolve(__dirname, '..') }) });
68
+ await T.waitForServer(BASE);
69
+ browser = await chromium.launch({ executablePath: exe });
70
+ if (SHOTS) fs.mkdirSync(SHOTS, { recursive: true });
71
+ const shot = async (p, name) => { if (SHOTS) await p.screenshot({ path: path.join(SHOTS, name + '.png') }); };
72
+
73
+ const open = async ({ w = 1440, h = 900, theme = 'light', B = board('triage', { pmos: true }), fresh = true } = {}) => {
74
+ const ctx = await browser.newContext({ viewport: { width: w, height: h } });
75
+ const page = await ctx.newPage();
76
+ const S = { B };
77
+ const errors = [], posts = [];
78
+ page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
79
+ page.on('request', (rq) => { if (rq.method() === 'POST') posts.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}') }); });
80
+ const json = (r, b, status = 200) => r.fulfill({ status, contentType: 'application/json', body: JSON.stringify(b) });
81
+ await page.route('**/api/initiative-premium*', (r) => json(r, { ok: true, state: 'ready', model: IP.build(F.facts()), as_of: Date.now() }));
82
+ await page.route(/\/api\/board-premium(\?.*)?$/, (r) => json(r, { ok: true, state: 'ready', model: S.B, as_of: Date.now() }));
83
+ await page.route(/\/api\/briefing-premium(\?.*)?$/, (r) => json(r, { ok: true, state: 'ready', model: BRIEF, as_of: Date.now() }));
84
+ await page.route('**/api/briefing-premium/**', (r) => json(r, { ok: true, turns: [], working: false }));
85
+ await page.route(/\/api\/workflows(\?.*)?$/, (r) => json(r, { ok: true, workflows: LIB }));
86
+ for (const p of ['ini-wf', 'wontdo', 'archive', 'ini-auto', 'move']) await page.route('**/api/boards/' + p, (r) => json(r, { ok: true, row: {} }));
87
+ if (!fresh) await page.addInitScript(() => { try { localStorage.setItem('pmos.wf.seen', JSON.stringify({ 'self-serve-v2|tender': 1 })); } catch { /* none */ } });
88
+ await page.goto(BASE + '/premium.html?ini=' + ID + '&ws=w1&board=w1&theme=' + theme);
89
+ const up = await until(() => page.evaluate(() => /Tender/.test((document.querySelector('#czViewer:not([hidden]) .cz-vw-kind') || {}).textContent || '') && !!document.querySelector('#czViewer [data-hi-v="page"] .hm-card [data-hm-wf]')), 30000);
90
+ return { ctx, page, errors, posts, up, S };
91
+ };
92
+ const V = '#czViewer:not([hidden])';
93
+ const txt = (p, s) => p.evaluate((q) => ((document.querySelector(q) || {}).textContent || '').replace(/\s+/g, ' ').trim(), s);
94
+ const moreLabels = (p) => p.evaluate(async () => { const b = document.querySelector('#czViewer [data-cz-vw="more"]'); if (!b) return []; b.click(); await new Promise((r) => setTimeout(r, 80)); const m = document.querySelector('#czViewer .cz-vw-menu'); const out = m ? [...m.querySelectorAll('[role="menuitem"] span:first-of-type')].map((x) => x.textContent) : []; b.click(); return out; });
95
+ const pickMore = async (p, label) => { await p.click('#czViewer [data-cz-vw="more"]'); await until(() => p.evaluate(() => !!document.querySelector('#czViewer .cz-vw-menu'))); await p.click(`#czViewer .cz-vw-menu [role="menuitem"]:has(> span:first-child:text-is("${label}"))`); };
96
+
97
+ const A = await open(), p = A.page;
98
+ ok('W1 the page opens on the initiative with the workflow\'s icon on its card', A.up, await txt(p, V + ' .cz-vw-kind'));
99
+ ok('W1 the kind line names the workflow and the anchor: "Tender · KR 1.1" (Kind becomes Workflow)', /^Tender · KR 1\.1$/.test(await txt(p, V + ' .cz-vw-kind')), await txt(p, V + ' .cz-vw-kind'));
100
+ ok('W1 the card counts that workflow\'s stages: "1 of 10 · Triage"', /1 of 10 · Triage/.test(await txt(p, V + ' .hm-card .hm-br .st')), await txt(p, V + ' .hm-card .hm-br .st'));
101
+ ok('W1 the ladder draws the ten stages of Tender, three of them milestones', await p.evaluate((v) => document.querySelectorAll(v + ' .hm-card .hm-bars i').length === 10, V));
102
+ ok('W1 the next stage is Tender\'s own: Move to Requirements', /Move to Requirements/.test(await txt(p, V + ' [data-hi-move]')), await txt(p, V + ' [data-hi-move]'));
103
+ ok('W1 the icon names the workflow for a screen reader', await p.evaluate((v) => /Workflow: Tender/.test(document.querySelector(v + ' [data-hm-wf]').getAttribute('aria-label')), V));
104
+ ok('W2 PMOS set it from the BRD: the toast says so, with Undo (WfTriage)', await until(() => p.evaluate(() => { const t = document.getElementById('hiToast'); return !!t && !t.hidden && /Set to Tender from the BRD/.test(t.textContent) && !!t.querySelector('[data-hi-undo]'); })));
105
+ await shot(p, 'triage-1440');
106
+ await p.click('#hiToast [data-hi-undo]');
107
+ ok('W2 Undo puts it back on the workflow it ran before', await until(() => A.posts.some((x) => x.path === '/api/boards/ini-wf' && x.body.wf === 'product-feature' && x.body.id === ID)), JSON.stringify(A.posts));
108
+
109
+ // W3 the Change picker
110
+ await p.click(V + ' [data-hm-wf]');
111
+ const pick = await until(() => p.evaluate(() => { const el = document.querySelector('.hi-pop[role="listbox"]'); if (!el) return null; return { opts: [...el.querySelectorAll('[role="option"]')].map((o) => o.textContent.replace(/\s+/g, ' ').trim() + (o.getAttribute('aria-selected') === 'true' ? '*' : '')), text: el.textContent }; }));
112
+ ok('W3 the picker lists every workflow with its stage count, Tender picked', pick && JSON.stringify(pick.opts) === JSON.stringify(['Product feature8', 'Tender10*']), JSON.stringify(pick));
113
+ ok('W3 it offers New workflow…, shows Tender\'s stage chain and why PMOS picked it', pick && /New workflow…/.test(pick.text) && /Triage → Requirements → ◆\sRFP out/.test(pick.text) && /Why: “choose a vendor/.test(pick.text), pick && pick.text);
114
+ await shot(p, 'picker-1440');
115
+ await p.click('.hi-pop [data-wf-pick="product-feature"]');
116
+ const sw = await until(() => p.evaluate(() => { const el = document.querySelector('.hi-pop[role="dialog"]'); return el && /Switch Office network tender to Product feature\?/.test(el.textContent) ? { text: el.textContent.replace(/\s+/g, ' '), land: el.querySelector('#wfLand').value, opts: el.querySelectorAll('#wfLand option').length } : null; }));
117
+ ok('W4 Switch to another workflow asks first: each stage and where it lands, "It lands in" Triage, the rule in one line (WfAChange)', sw && /Triage\s*now\s*Triage\s*same stage, carries over/.test(sw.text) && sw.land === 'triage' && sw.opts === 8 && /Nothing is deleted\./.test(sw.text), JSON.stringify(sw));
118
+ await shot(p, 'switch-1440');
119
+ await p.selectOption('#wfLand', 'discover');
120
+ await p.click('.hi-pop [data-wf-go]');
121
+ ok('W4 Switch sends the workflow and the stage the PM picked', await until(() => A.posts.some((x) => x.path === '/api/boards/ini-wf' && x.body.wf === 'product-feature' && x.body.to === 'discover')), JSON.stringify(A.posts.filter((x) => /ini-wf/.test(x.path))));
122
+
123
+ // W5 the ⋯ menu
124
+ const labels = await moreLabels(p);
125
+ ok('W5 ⋯ holds Change workflow and Rename, then Won’t do and Archive (WfAWontDo)', ['Change workflow', 'Rename', 'Won’t do', 'Archive'].every((l) => labels.includes(l)) && labels.indexOf('Change workflow') < labels.indexOf('Won’t do'), JSON.stringify(labels));
126
+
127
+ // W6 Won't do
128
+ await pickMore(p, 'Won’t do');
129
+ const wd = await until(() => p.evaluate(() => { const el = document.querySelector('.hi-pop[role="dialog"]'); return el && /Won’t do Office network tender\?/.test(el.textContent) ? { chips: [...el.querySelectorAll('[data-wf-why]')].map((c) => c.textContent), off: el.querySelector('[data-wf-go]').disabled } : null; }));
130
+ ok('W6 Won’t do asks a reason: No budget, Out of scope, Done another way, Other; it waits for one', wd && wd.chips.join('|') === 'No budget|Out of scope|Done another way|Other' && wd.off, JSON.stringify(wd));
131
+ await p.click('.hi-pop [data-wf-why="budget"]');
132
+ await p.fill('#wfNote', 'Moved to next year’s budget.');
133
+ await shot(p, 'wontdo-1440');
134
+ await p.click('.hi-pop [data-wf-go]');
135
+ ok('W6 Won’t do sends the reason and the note', await until(() => A.posts.some((x) => x.path === '/api/boards/wontdo' && x.body.reason === 'budget' && x.body.note === 'Moved to next year’s budget.' && x.body.id === ID)), JSON.stringify(A.posts.filter((x) => /wontdo/.test(x.path))));
136
+
137
+ // W7 an initiative in Won't do: the page says so, with Back to Triage
138
+ A.S.B = board('bids', { ended: { as: 'wontdo', reason: 'budget', note: 'Moved to next year’s budget.', at: '2026-10-25' } });
139
+ await p.reload();
140
+ await until(() => p.evaluate((v) => !!document.querySelector(v + ' .hi-end'), V), 30000);
141
+ ok('W7 the page of a Won’t do says why, and offers Back to Triage', /Won't do · No budget: Moved to next year’s budget\./.test(await txt(p, V + ' .hi-end')), await txt(p, V + ' .hi-end'));
142
+ ok('W7 its stage does not move: the card says how to bring it back', /bring it back to Triage/.test(await txt(p, V + ' [data-hi-mv]')), await txt(p, V + ' [data-hi-mv]'));
143
+ ok('W7 ⋯ has Back to Triage in place of Won’t do', await moreLabels(p).then((l) => l.includes('Back to Triage') && !l.includes('Won’t do')));
144
+ await shot(p, 'wontdo-page-1440');
145
+ await p.click(V + ' .hi-end [data-wf-back]');
146
+ ok('W7 Back to Triage brings it back', await until(() => A.posts.some((x) => x.path === '/api/boards/wontdo' && x.body.back === true)));
147
+ ok('W1–W7 no page error', !A.errors.length, A.errors.join(' | '));
148
+ await A.ctx.close();
149
+
150
+ // W8 the phone, and dark
151
+ const P = await open({ w: 390, h: 844, fresh: false, B: board('requirements') });
152
+ ok('W8 the phone opens the page with the workflow and "2 of 10 · Requirements"', P.up && /2 of 10 · Requirements/.test(await txt(P.page, V + ' .hm-card .hm-br .st')));
153
+ ok('W8 the toast shows once only: seen before, not again', !(await P.page.evaluate(() => { const t = document.getElementById('hiToast'); return !!t && !t.hidden; })));
154
+ await shot(P.page, 'page-390');
155
+ await P.page.click(V + ' [data-hm-wf]');
156
+ await until(() => P.page.evaluate(() => !!document.querySelector('.hi-pop[role="listbox"]')));
157
+ await shot(P.page, 'picker-390');
158
+ await P.page.click('.hi-pop [data-wf-pick="product-feature"]');
159
+ ok('W8 on the phone the switch is a sheet', await until(() => P.page.evaluate(() => !!document.querySelector('.hi-pop.sheet[role="dialog"] #wfLand'))));
160
+ ok('W8 the sheet fits the phone: no side scroll', await P.page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1));
161
+ await shot(P.page, 'switch-390');
162
+ await P.page.click('.hi-pop [data-wf-x]');
163
+ await pickMore(P.page, 'Won’t do');
164
+ await until(() => P.page.evaluate(() => !!document.querySelector('.hi-pop.sheet [data-wf-why]')));
165
+ await shot(P.page, 'wontdo-390');
166
+ ok('W8 no page error on the phone', !P.errors.length, P.errors.join(' | '));
167
+ await P.ctx.close();
168
+ const D = await open({ theme: 'dark', fresh: false });
169
+ await D.page.click(V + ' [data-hm-wf]');
170
+ await until(() => D.page.evaluate(() => !!document.querySelector('.hi-pop[role="listbox"]')));
171
+ await shot(D.page, 'picker-1440-dark');
172
+ ok('W8 dark: the picker draws, no page error', D.up && !D.errors.length, D.errors.join(' | '));
173
+ await D.page.click('.hi-pop [data-wf-new]');
174
+ ok('W3 New workflow… opens the Workflows page, where the PM describes it and PMOS drafts it', await until(() => D.page.evaluate(() => location.pathname === '/premium-workflows.html' && new URLSearchParams(location.search).get('new') === '1')), D.page.url());
175
+ await D.ctx.close();
176
+ finish();
177
+ })();
@@ -7,7 +7,8 @@
7
7
  * facts come from the routes of lib/routes-boards.js and lib/routes-core-docs.js:
8
8
  * board GET /api/boards/board → .board { ws, id, name, workflow: [{ name, cat }], … }
9
9
  * counts the same answer's counts { total, open, byStage, byStatus }
10
- * rows GET /api/boards/backlog → rows [{ id, title, lane, stage, cat, owner, anchor, horizon, status, start, end, progress, warnings, updated, stageSource, dupOf }]
10
+ * rows GET /api/boards/backlog → rows [{ id, title, lane, stage, cat, owner, anchor, horizon, status, start, end, progress, warnings, updated, stageSource, dupOf,
11
+ * wf, wfStage, wfStages, ended }] (the workflow fields: workflows-per-initiative; a row without `wf` is on Product feature)
11
12
  * columns GET /api/boards/columns → [{ stage, cat, count, rows }]
12
13
  * sprints GET /api/boards/sprints → { source: 'jira'|'none', readAt, sprints: [{ name, state, start, end, counts: { todo, doing, done } }] }
13
14
  * docs GET /api/core-docs?level=board → { scope, summary, docs: [{ key, title, for, cadence, by, kind, st, act, running }] }
@@ -105,7 +106,9 @@ const pctOf = (v) => { const n = Number(v); if (v == null || v === '' || !Number
105
106
  * (a move past a stage leaves a "Skipped <stage>" warning on the row) and what waits on the PM. Nothing is invented: a part PMOS
106
107
  * has no record for is named and left uncounted. */
107
108
  function trackOf(r, tickets, today, release) {
108
- const k = stepIndex(r.stage, r.cat), step = STEPS[k] || null, key = step ? step.key : null;
109
+ // a row on another workflow than Product feature stands in its own stage, not one of the eight steps (workflows-per-initiative)
110
+ const own = r.wf && r.wf.id !== PF_ID ? (r.wfStage || { name: r.stage || 'No stage', milestone: false }) : null;
111
+ const k = own ? -1 : stepIndex(r.stage, r.cat), step = STEPS[k] || null, key = step ? step.key : null;
109
112
  const tk = (tickets || []).slice(0, 40);
110
113
  const done = tk.filter((t) => t.status === 'Done').length, blocked = tk.filter((t) => t.blocked);
111
114
  const pts = tk.filter((t) => t.points != null), ptsAll = pts.reduce((n, t) => n + t.points, 0), ptsDone = pts.filter((t) => t.status === 'Done').reduce((n, t) => n + t.points, 0);
@@ -146,16 +149,17 @@ function trackOf(r, tickets, today, release) {
146
149
  } else if (step) {
147
150
  count = 'Not counted yet';
148
151
  line.push({ text: 'Nothing is counted toward it yet' });
149
- } else line.push({ text: 'Its stage is not one of the eight steps' });
152
+ } else if (own) out = own.output && own.output.name ? own.output.name : '';
153
+ else line.push({ text: 'Its stage is not one of the eight steps' });
150
154
  if (!jira && pct != null) { count = pct + '%'; }
151
155
  // a step the row was moved past (lib/routes-boards.js keeps the move's "Skipped <stage>" warning)
152
- const skipped = [...new Set((r.warnings || []).map((w) => (typeof w === 'string' ? /^Skipped (.+)$/.exec(w) : null)).filter(Boolean).map((m) => stepIndex(m[1], null)).filter((i) => i >= 0 && (k < 0 || i < k)))].sort((a, b) => a - b);
156
+ const skipped = own ? [] : [...new Set((r.warnings || []).map((w) => (typeof w === 'string' ? /^Skipped (.+)$/.exec(w) : null)).filter(Boolean).map((m) => stepIndex(m[1], null)).filter((i) => i >= 0 && (k < 0 || i < k)))].sort((a, b) => a - b);
153
157
  // what waits on the PM: the sign-off of a release whose tickets are all done (the last part of Deliver is the PM's)
154
158
  const you = key === 'deliver' && tk.length && done === tk.length ? 'Your sign-off' + (release ? ' · ' + release : '') : null;
155
159
  const upd = r.updated ? days(String(r.updated).slice(0, 10), today) : null;
156
160
  const fc = tk.filter((t) => t.status !== 'Done' && t.sprintEnd).map((t) => t.sprintEnd).sort().pop() || null;
157
161
  const next = line.find((x) => x.tone === 'red') || null;
158
- return { k, key, label: step ? step.label : (r.stage || 'No stage'), ms: !!(step && step.ms), output: out, prog, pct: jira ? null : pct, segs, count, line, next, tickets: tk, blocked: blocked.length, skipped, you,
162
+ return { k, key, label: own ? own.name : step ? step.label : (r.stage || 'No stage'), ms: own ? !!own.milestone : !!(step && step.ms), output: out, prog, pct: jira ? null : pct, segs, count, line, next, tickets: tk, blocked: blocked.length, skipped, you,
159
163
  days: null, idle: upd != null && upd >= 30 && r.status !== 'done' ? upd : null, forecast: fc, forecastLabel: fc ? shortDate(fc) : '' };
160
164
  }
161
165
  const cap1 = (w, i) => (i === 0 ? w.charAt(0).toUpperCase() + w.slice(1) : w);
@@ -217,6 +221,20 @@ const askOf = (a, board, rows) => {
217
221
  close: closeTo(a.line, rows) };
218
222
  };
219
223
 
224
+ /* ── workflows (D99, common.md "Row fields"): each row is on one workflow; Product feature when none was set ─────────────────────────── */
225
+ const PF_ID = 'product-feature';
226
+ const PF = { id: PF_ID, name: 'Product feature', icon: 'feature' };
227
+ const CATS = ['todo', 'doing', 'done'];
228
+ const stageFields = (s) => (s && typeof s === 'object' && s.key ? { key: String(s.key), name: clip(s.name || s.key, 60), cat: CATS.includes(s.cat) ? s.cat : 'doing', milestone: !!s.milestone,
229
+ ...(Number.isInteger(s.n) ? { n: s.n, of: Number.isInteger(s.of) ? s.of : null } : {}), ...(s.when ? { when: s.when } : {}), ...(s.output && s.output.name ? { output: { name: clip(s.output.name, 60), kind: s.output.kind || '' } } : {}),
230
+ ...(s.status ? { status: s.status } : {}), ...(s.reading ? { reading: { runs: s.reading.runs, why: clip(s.reading.why || '', 200), cite: s.reading.cite || null } } : {}),
231
+ ...(s.skipped || s.status === 'skipped' ? { skipped: { why: clip((s.skipped || s.reading || {}).why || '', 200), cite: (s.skipped || s.reading || {}).cite || '' } } : {}) } : null);
232
+ /** The row's workflow fields as the routes give them: its workflow (Product feature when none), its stage, its own stage list, its end. */
233
+ function wfFields(r) {
234
+ const wf = r.wf && r.wf.id ? { id: String(r.wf.id), name: clip(r.wf.name || r.wf.id, 60), icon: r.wf.icon || 'flag', ...(r.wf.setBy ? { setBy: r.wf.setBy, why: clip(r.wf.why || '', 300) } : {}) } : PF;
235
+ const ended = r.ended && (r.ended.as === 'wontdo' || r.ended.as === 'archived') ? { as: r.ended.as, reason: r.ended.reason || '', note: clip(r.ended.note || '', 300), at: r.ended.at || null } : null;
236
+ return { wf, wfStage: stageFields(r.wfStage), wfStages: Array.isArray(r.wfStages) ? r.wfStages.map(stageFields).filter(Boolean).slice(0, 40) : null, ended };
237
+ }
220
238
  function rowOf(r, wf, today) {
221
239
  const names = (wf || []).map((s) => s.name), cur = names.indexOf(r.stage);
222
240
  const bad = r.status === 'late' || r.status === 'at risk';
@@ -235,6 +253,8 @@ function rowOf(r, wf, today) {
235
253
  finish: r.end ? shortDate(r.end) : 'Not planned', over: !!over, start: r.start || null, end: r.end || null,
236
254
  owner: r.owner || null, lane: r.lane || null, anchor: r.anchor || null, kr: krShort(r.anchor), rank: Number.isInteger(r.rank) ? r.rank : null, warnings: (r.warnings || []).filter((w) => typeof w === 'string').slice(0, 12), epics: Array.isArray(r.epics) ? r.epics.filter((e) => typeof e === 'string').slice(0, 6) : [], updated: r.updated || null, reading: r.reading || null, overDays: over ? days(r.end, today) : 0,
237
255
  acts: actsOf(r, names),
256
+ // D99: the workflow it runs and where it stands in it (lib/routes-boards.js workflowRowOf); Product feature when the server sends none
257
+ ...wfFields(r),
238
258
  dialog: {
239
259
  eye: 'Initiative', logTitle: 'Read from the board',
240
260
  log: ['Read the initiative from the board' + (r.stageSource === 'derived' ? ' (its stage is derived by the workflow engine)' : ''), 'Placed it in the ' + (r.stage || 'unknown') + ' stage', r.status ? 'Took its status from the record: ' + r.status : 'No status is on record'],
@@ -347,8 +367,13 @@ function build(f) {
347
367
  if (nLinked) docs.counts.linked = nLinked; // a key only when an added document is linked
348
368
  if (!dd && !missing.includes('core documents')) missing.push('core documents');
349
369
 
370
+ // D99: the workflows with an initiative on this board (Product feature first, then by count), for the Board's workflow chips (WfABoard)
371
+ const wfCount = new Map();
372
+ for (const r of rows) { const w = r.wf || { id: 'product-feature', name: 'Product feature', icon: 'feature' }; const c = wfCount.get(w.id) || { id: w.id, name: w.name, icon: w.icon, count: 0 }; c.count++; wfCount.set(w.id, c); }
373
+ const workflows = [...wfCount.values()].sort((a, b) => (a.id === 'product-feature' ? -1 : b.id === 'product-feature' ? 1 : b.count - a.count || a.name.localeCompare(b.name)));
350
374
  const model = {
351
375
  pending: !!f.pending,
376
+ workflows,
352
377
  header: { text: 'Real data · as of ' + hhmm(now) + (missing.length ? ' · not read: ' + missing.join(', ') : '') + (f.pending ? ' · reading the board' : ''), missing },
353
378
  board: { name: board.name || '', id: board.id || null, ws: board.ws || null, self: !!board.self, stages: wf.map((s) => s.name), switcher: (f.boards || []).length > 1 ? f.boards.map((b) => ({ id: b.id, ws: b.ws, name: b.name })) : null },
354
379
  initiatives: {
@@ -11,6 +11,9 @@
11
11
  * Triage, PRD → rubric is Plan, rubric → evaluation is Build) and from consecutive board moves;
12
12
  * null until 3 samples exist. A record reconstructed after the fact (reconstructed_from) is no sample,
13
13
  * and neither are two artifacts first seen in the same commit (they were written together).
14
+ * D99: it compares only within one workflow. `usual` is Product feature's; an initiative on
15
+ * another workflow (its row's wf) gives samples to `usualBy[workflow id][stage key]` instead,
16
+ * from its board moves since it last switched workflow.
14
17
  * · skipped stages and why the lane's own ladder (scripts/nine-stages.js LANE_STAGES: "the chore lane has no Triage step"),
15
18
  * and a board move past a stage, with the move's own reason
16
19
  * · the parts of a step's output Triage: the record and brief headings · Discover: the PRD headings · Plan: scope, timeline,
@@ -144,11 +147,23 @@ function trail({ root, ids, rows = [], moves = [], now = Date.now(), io } = {})
144
147
  }
145
148
  const byIni = new Map();
146
149
  for (const m of moves) { if (!m || !m.id || !m.at) continue; if (!byIni.has(m.id)) byIni.set(m.id, []); byIni.get(m.id).push(m); }
147
- for (const L of byIni.values()) {
150
+ const wfOfRow = (id) => { const r = rowBy.get(id); return r && r.wf && r.wf.id && r.wf.id !== 'product-feature' ? r.wf.id : null; };
151
+ const other = {}; // workflow id → stage key → [days]
152
+ for (const [id, L] of byIni) {
148
153
  L.sort((a, b) => String(a.at).localeCompare(String(b.at)));
154
+ const w = wfOfRow(id);
155
+ if (w) {
156
+ // only the moves since the last switch are moves of this workflow
157
+ let from = 0; for (let i = 0; i < L.length; i++) if (L[i].via === 'ini-wf') from = i;
158
+ const bucket = other[w] || (other[w] = {});
159
+ for (let i = from; i + 1 < L.length; i++) { const k = String(L[i].to || ''); if (!k) continue; (bucket[k] || (bucket[k] = [])).push(Math.max(0, Math.round((Date.parse(L[i + 1].at) - Date.parse(L[i].at)) / DAY))); }
160
+ continue;
161
+ }
149
162
  for (let i = 0; i + 1 < L.length; i++) { const k = stageKey(L[i].to); if (samples[k]) samples[k].push(Math.max(0, Math.round((Date.parse(L[i + 1].at) - Date.parse(L[i].at)) / DAY))); }
150
163
  }
151
- const usual = Object.fromEntries(STAGES.map((s) => [s, samples[s].length >= MIN_SAMPLES ? { days: median(samples[s]), n: samples[s].length } : { days: null, n: samples[s].length }]));
164
+ const usualOf = (xs) => (xs.length >= MIN_SAMPLES ? { days: median(xs), n: xs.length } : { days: null, n: xs.length });
165
+ const usual = Object.fromEntries(STAGES.map((s) => [s, usualOf(samples[s])]));
166
+ const usualBy = Object.fromEntries(Object.entries(other).map(([w, b]) => [w, Object.fromEntries(Object.entries(b).map(([k, xs]) => [k, usualOf(xs)]))]));
152
167
 
153
168
  const items = {};
154
169
  const themes = new Map();
@@ -156,7 +171,9 @@ function trail({ root, ids, rows = [], moves = [], now = Date.now(), io } = {})
156
171
  const r = fmOf(id);
157
172
  if (!r && !rowBy.has(id)) continue; // neither a record nor a row of the board: nothing to say about it
158
173
  const row = rowBy.get(id) || {}, fm = r ? r.fm : {};
159
- const stage = stageKey(row.stage);
174
+ // D99: on another workflow the stage is that workflow's own (its key); the lifecycle's parts, skips and asks do not apply to it
175
+ const wk = wfOfRow(id) && row.wfStage ? row.wfStage.key : null;
176
+ const stage = wk ? null : stageKey(row.stage);
160
177
  const lane = String(row.lane || fm.lane || 'feature').toLowerCase();
161
178
  const evals = evalFiles(id, evalNames);
162
179
  const prdRel = pathOf(fm.prd_path), rubRel = pathOf(fm.rubric_path);
@@ -168,15 +185,15 @@ function trail({ root, ids, rows = [], moves = [], now = Date.now(), io } = {})
168
185
 
169
186
  // days in the current stage: the last move into it, else the newest artifact on the ladder
170
187
  let since = null, sinceFrom = null;
171
- const mv = (byIni.get(id) || []).filter((m) => stageKey(m.to) === stage).pop();
188
+ const mv = (byIni.get(id) || []).filter((m) => (wk ? m.to === wk : stageKey(m.to) === stage)).pop();
172
189
  if (mv) { since = Date.parse(mv.at); sinceFrom = 'move'; }
173
- else { const L = ladderDates(id, fm, seen, evals); if (L.length) { since = L[L.length - 1][1]; sinceFrom = 'git'; } }
190
+ else if (!wk) { const L = ladderDates(id, fm, seen, evals); if (L.length) { since = L[L.length - 1][1]; sinceFrom = 'git'; } }
174
191
 
175
192
  // skipped: the lane's own ladder, then a move past a stage (with the move's reason)
176
193
  const k = STAGES.indexOf(stage), laneSet = new Set(LANE_STAGES[lane] || STAGES);
177
194
  const skipped = [];
178
195
  for (let j = 0; j < (k < 0 ? 0 : k); j++) if (!laneSet.has(STAGES[j])) skipped.push({ stage: STAGES[j], why: 'The ' + lane + ' lane has no ' + LABEL[STAGES[j]] + ' step.', from: 'lane' });
179
- for (const m of byIni.get(id) || []) for (const w of m.warnings || []) {
196
+ for (const m of wk ? [] : byIni.get(id) || []) for (const w of m.warnings || []) {
180
197
  const s = /^Skipped (.+)$/.exec(String(w)); if (!s) continue;
181
198
  const sk = stageKey(s[1]); if (STAGES.includes(sk) && !skipped.some((x) => x.stage === sk)) skipped.push({ stage: sk, why: m.why ? String(m.why) : null, from: 'move', at: m.at });
182
199
  }
@@ -217,7 +234,7 @@ function trail({ root, ids, rows = [], moves = [], now = Date.now(), io } = {})
217
234
  // a theme with no name on any PRD takes its objective's title; tones in order where none is set
218
235
  let ti = 0;
219
236
  const out = [...themes.values()].map((t) => ({ ...t, name: t.name || (t.key === 'health' ? 'Health budgets' : t.objective || (t.key === 'none' ? 'No anchor' : 'Other anchors')), tone: t.tone || TONES[ti++ % TONES.length] }));
220
- return { ok: true, at: new Date(now).toISOString(), usual, themes: out, items };
237
+ return { ok: true, at: new Date(now).toISOString(), usual, usualBy, themes: out, items };
221
238
  }
222
239
 
223
240
  module.exports = { trail, frontmatter, partsOf, ladderDates, median, STAGES, MIN_SAMPLES, TONES };
@@ -17,6 +17,7 @@ const headless = require('./headless.js');
17
17
  const Goal = require('./goal-chat.js');
18
18
  const ReportChat = require('./report-chat.js');
19
19
  const ProgramChat = require('./program-chat.js');
20
+ const WorkflowChat = require('./workflow-chat.js');
20
21
 
21
22
  const THREADS = 'briefing-premium-threads.jsonl';
22
23
  const KEY_RE = /^(decision|blocked|waited|src|ev|work|board|init|doc|ins|chat|pop):[A-Za-z0-9][A-Za-z0-9._:-]{0,100}$/; // chat: the PM's own chat on the Chat page (premium-chat-page); pop: a popup with no row of its own (premium-popup-context P1)
@@ -206,6 +207,8 @@ function chat({ runtimeDir, key, text, model, context, sessions, wsId, now = new
206
207
  let msg = q, goal = null;
207
208
  const cmd = Goal.parseCommand(q);
208
209
  if (cmd) { const b = Goal.begin({ runtimeDir, key, text: cmd.text, now }); if (b.error) return fail(400, b.error); msg = b.prompt; goal = b.id; }
210
+ // D99: the New workflow chat (Settings › Workflows) carries the workflow rule on every message (lib/workflow-chat.js)
211
+ else if (WorkflowChat.isKey(key) && !q.startsWith('/')) msg = WorkflowChat.wrap(q);
209
212
  // premium-reports-from-chat R1: a message about a report, a chart or a dashboard carries the pmos-report rule (lib/report-chat.js)
210
213
  else if (ReportChat.isAsk(q)) msg = ReportChat.wrap(q);
211
214
  // bug 2026-10-24: a message about a program carries the program rule (lib/program-chat.js), so the chat names the real press
@@ -157,7 +157,7 @@ function foundOf(f) {
157
157
  const sources = Array.isArray(f.sources) ? f.sources.filter((x) => x && typeof x.ref === 'string').slice(0, 8).map((x) => ({ label: String(x.label || ''), ref: x.ref })) : [];
158
158
  return { why: typeof f.why === 'string' ? f.why : '', sources, match: typeof f.match === 'string' && f.match ? f.match : null, scan: typeof f.scan === 'string' ? f.scan : null, run: typeof f.run === 'string' ? f.run : null };
159
159
  }
160
- const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'ini-epics', 'ini-archive', 'ini-notdup']);
160
+ const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto']);
161
161
  const TASK_STATES = Object.freeze(['To do', 'In progress', 'In review', 'Done']);
162
162
 
163
163
  const copyStages = (stages) => stages.map((s) => ({ name: s.name, cat: s.cat, hint: s.hint || '' }));
@@ -187,6 +187,11 @@ function fold(events) {
187
187
  const epics = new Map(); // initiative id → the Jira epic keys the PM linked to it (the last ini-epics line wins)
188
188
  const archives = new Map(); // initiative id → { at, by, reason, into, moved } while archived (an `archived: false` line restores it)
189
189
  const notDup = new Map(); // initiative id → Set of initiative ids the PM said it is not a duplicate of
190
+ // D99 workflows per initiative: the workflow each initiative runs, Won't do, the agent's readings of Only-when stages, Moves on by itself
191
+ const iniWf = new Map(); // key(board, id) → { wf, at, by, why, from } (the last ini-wf line)
192
+ const ends = new Map(); // key(board, id) → { as: 'wontdo', reason, note, at, by } while it is out (a `back` line brings it back to Triage)
193
+ const judged = new Map(); // key(board, id) → { [stageKey]: { runs, why, cite, at, by } } (an `undo` line drops the reading)
194
+ const autoOver = new Map(); // key(board, id) → { [stageKey]: true|false } the PM's own Moves on by itself for one initiative
190
195
  const list = [];
191
196
  for (let e of Array.isArray(events) ? events : []) {
192
197
  if (typeof e === 'string') { try { e = JSON.parse(e); } catch { continue; } }
@@ -264,13 +269,36 @@ function fold(events) {
264
269
  } else if (e.kind === 'ini-notdup' && typeof e.id === 'string' && typeof e.of === 'string') {
265
270
  if (!notDup.has(e.id)) notDup.set(e.id, new Set());
266
271
  notDup.get(e.id).add(e.of);
272
+ } else if (e.kind === 'ini-wf' && b && typeof e.id === 'string' && typeof e.wf === 'string' && e.wf) {
273
+ const k = key(b, e.id);
274
+ iniWf.set(k, { wf: e.wf, at: e.at || null, by: e.by || null, why: typeof e.why === 'string' ? e.why : '', from: typeof e.from === 'string' ? e.from : null, pmos: e.pmos === true });
275
+ if (isObj(e.moved) && typeof e.moved.to === 'string') {
276
+ stages.set(k, e.moved.to);
277
+ moves.push({ at: e.at || null, by: e.by || null, board: b, id: e.id, from: e.moved.from || null, to: e.moved.to, why: 'workflow changed', warnings: [], via: 'ini-wf' });
278
+ }
279
+ } else if (e.kind === 'ini-end' && b && typeof e.id === 'string') {
280
+ const k = key(b, e.id);
281
+ if (e.back === true) {
282
+ ends.delete(k);
283
+ stages.set(k, 'triage');
284
+ moves.push({ at: e.at || null, by: e.by || null, board: b, id: e.id, from: null, to: 'triage', why: 'back to Triage', warnings: [], via: 'ini-end' });
285
+ } else ends.set(k, { as: 'wontdo', reason: typeof e.reason === 'string' ? e.reason : 'other', note: typeof e.note === 'string' ? e.note : '', at: e.at || null, by: e.by || null, stage: typeof e.stage === 'string' ? e.stage : null });
286
+ } else if (e.kind === 'stage-judge' && b && typeof e.id === 'string' && typeof e.stage === 'string') {
287
+ const k = key(b, e.id);
288
+ const cur = judged.get(k) || {};
289
+ if (e.undo === true) delete cur[e.stage];
290
+ else cur[e.stage] = { runs: e.runs === true ? true : e.runs === false ? false : null, why: typeof e.why === 'string' ? e.why : '', cite: typeof e.cite === 'string' && e.cite ? e.cite : null, at: e.at || null, by: e.by || null };
291
+ judged.set(k, cur);
292
+ } else if (e.kind === 'ini-auto' && b && typeof e.id === 'string' && typeof e.stage === 'string' && typeof e.auto === 'boolean') {
293
+ const k = key(b, e.id);
294
+ autoOver.set(k, { ...(autoOver.get(k) || {}), [e.stage]: e.auto });
267
295
  } else if (e.kind === 'ask-decline' && typeof e.ask === 'string' && asks.has(e.ask)) {
268
296
  const a = asks.get(e.ask);
269
297
  if (a.state !== 'open') continue;
270
298
  Object.assign(a, { state: 'declined', why: e.why || '', closedAt: e.at || null });
271
299
  }
272
300
  }
273
- return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, epics, archives, notDup, events: list };
301
+ return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, epics, archives, notDup, iniWf, ends, judged, autoOver, events: list };
274
302
  }
275
303
 
276
304
  /** The stages an initiative runs on a board: its own workflow when one is recorded, else the board's. */