create-pmos 0.537.0 → 0.538.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 (100) hide show
  1. package/package.json +68 -14
  2. package/payload/KIT-VERSION +2 -2
  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/payload/state/log.md +1 -1
  7. package/workspace/board-columns-test.js +11 -10
  8. package/workspace/board-programs-test.js +21 -23
  9. package/workspace/board-publish-ui-test.js +19 -15
  10. package/workspace/board-shared-ui-test.js +15 -12
  11. package/workspace/briefing-premium-board-test.js +46 -31
  12. package/workspace/briefing-premium-insights-test.js +24 -31
  13. package/workspace/briefing-premium-metrics-test.js +2 -2
  14. package/workspace/calm-timeline-test.js +1 -1
  15. package/workspace/changelog.json +67 -0
  16. package/workspace/ev-everywhere-test.js +4 -5
  17. package/workspace/fixtures/board-premium-facts.js +1 -1
  18. package/workspace/fixtures/initiative-premium-facts.js +1 -1
  19. package/workspace/fixtures/insights-premium-facts.js +6 -6
  20. package/workspace/fixtures/program-ascent.js +1 -1
  21. package/workspace/guide/adler.md +2 -2
  22. package/workspace/guide/agent-capabilities.md +38 -6
  23. package/workspace/guide/board.md +13 -6
  24. package/workspace/guide/claude-proposes.md +1 -1
  25. package/workspace/guide/home.md +2 -2
  26. package/workspace/guide/index.md +3 -3
  27. package/workspace/guide/intelligence-okr-goals.md +18 -7
  28. package/workspace/guide/lifecycle.md +2 -2
  29. package/workspace/guide/programs.md +2 -2
  30. package/workspace/guide/reports-needs-you.md +5 -5
  31. package/workspace/guide/settings.md +14 -11
  32. package/workspace/guide/workflows.md +3 -3
  33. package/workspace/guide/your-impact.md +1 -1
  34. package/workspace/lib/agent-team.js +262 -0
  35. package/workspace/lib/ai-cli.js +36 -4
  36. package/workspace/lib/bg-queue.js +9 -4
  37. package/workspace/lib/board-premium.js +6 -3
  38. package/workspace/lib/goal-source.js +77 -0
  39. package/workspace/lib/grill-runs.js +6 -3
  40. package/workspace/lib/headless.js +36 -4
  41. package/workspace/lib/idle-lab-engine.js +7 -6
  42. package/workspace/lib/initiative-premium.js +6 -3
  43. package/workspace/lib/insights-premium.js +1 -1
  44. package/workspace/lib/job-graph.js +191 -0
  45. package/workspace/lib/okr-goals.js +3 -0
  46. package/workspace/lib/orchestrator-keeprate.js +108 -7
  47. package/workspace/lib/pmos-verbs.js +3 -0
  48. package/workspace/lib/proposal-runs.js +8 -5
  49. package/workspace/lib/proposals.js +32 -2
  50. package/workspace/lib/report-slots.js +14 -10
  51. package/workspace/lib/routes-boards.js +2 -2
  52. package/workspace/lib/routes-insights-premium.js +11 -4
  53. package/workspace/lib/routes-premium-dashboards.js +20 -6
  54. package/workspace/lib/routes-proposals.js +10 -5
  55. package/workspace/lib/routes-your-move.js +6 -7
  56. package/workspace/lib/status-proof.js +45 -0
  57. package/workspace/lib/status-signal.js +4 -2
  58. package/workspace/lib/task-links.js +3 -1
  59. package/workspace/lib/team-cli.js +164 -0
  60. package/workspace/lib/team-runs.js +244 -0
  61. package/workspace/lib/verify-runs.js +112 -0
  62. package/workspace/okr-goals-ui-test.js +10 -13
  63. package/workspace/package-lock.json +2 -2
  64. package/workspace/package.json +1 -1
  65. package/workspace/premium-vw-backlog-test.js +2 -2
  66. package/workspace/premium-vw-jira-test.js +1 -1
  67. package/workspace/public/pm/bd-acts.js +14 -34
  68. package/workspace/public/pm/bd-ini-panel.js +38 -27
  69. package/workspace/public/pm/bd-publish.js +1 -1
  70. package/workspace/public/pm/bd-span.js +2 -1
  71. package/workspace/public/pm/bd-views.js +7 -5
  72. package/workspace/public/pm/c3-ini-ui.js +9 -7
  73. package/workspace/public/pm/cozy-board.css +17 -6
  74. package/workspace/public/pm/cozy-insights.css +18 -0
  75. package/workspace/public/pm/cozy-nav.js +2 -2
  76. package/workspace/public/pm/cozy-search.js +29 -7
  77. package/workspace/public/pm/cozy-settings.js +39 -20
  78. package/workspace/public/pm/home-data.js +3 -1
  79. package/workspace/public/pm/home-ini-model.js +15 -1
  80. package/workspace/public/pm/home-ini.js +9 -3
  81. package/workspace/public/pm/ini-tail.js +61 -0
  82. package/workspace/public/pm/ini-view-model.js +10 -7
  83. package/workspace/public/pm/premium-board.js +66 -99
  84. package/workspace/public/pm/premium-insights.js +95 -112
  85. package/workspace/public/pm/premium-report-intel.js +3 -2
  86. package/workspace/public/pm/readonly.js +4 -3
  87. package/workspace/public/pm/stage-chip.js +2 -1
  88. package/workspace/public/pm/status-proof.js +43 -0
  89. package/workspace/public/premium-board.html +10 -28
  90. package/workspace/public/premium-intelligence.html +7 -9
  91. package/workspace/server.js +35 -1
  92. package/workspace/sort-order-test.js +10 -8
  93. package/workspace/test-files.json +4 -2
  94. package/workspace/test-lists/agent-team.json +9 -0
  95. package/workspace/test-lists/job-graph.json +11 -0
  96. package/workspace/test-lists/status-proof.json +5 -0
  97. package/workspace/workflows-setup-test.js +3 -2
  98. package/workspace/public/premium-chat.html +0 -14
  99. package/workspace/public/premium-initiative.html +0 -15
  100. package/workspace/public/premium-work.html +0 -14
@@ -0,0 +1,244 @@
1
+ 'use strict';
2
+ /* team-runs.js — the record of the role agents and the runner that starts them (brief agent-team, GO steps 2 to 4).
3
+ *
4
+ * LEDGER = 'team.jsonl' in a product's state folder (lib/driver.js stateDirOf)
5
+ * append(dir, line, now?) · read(dir) → [line] · fold(lines) → { dispatches, steps, writes, verdicts, inbox, paused }
6
+ * lastWriter(F, rel) → the last write line of one artifact, or null
7
+ * dispatch(dir, { kind, target, ws?, board?, facts?, roles?, now }) → { ok, id, roles } | { ok: false, error }
8
+ * status(F, { now }) → { roles: [{ key, name, working: [..], queued: n, today: n, budget }], dispatches: [...], inbox: [...] }
9
+ * promptOf(role, step, o) → the prompt of one role run
10
+ * create(deps) → { tick({ now }), active() }
11
+ *
12
+ * THE LINES (append-only):
13
+ * dispatch { kind: 'dispatch', id, of: 'goal'|'initiative', target, ws, board?, roles: [key], at } the chief of staff's plan
14
+ * step { kind: 'step', id, dispatch?, role, ini, ws, board?, trigger, key, state, artifacts?: [rel], at, started?, session?, why? }
15
+ * state: queued → running → done | failed | held. A later line for the same id replaces the earlier one in fold().
16
+ * write { kind: 'write', run, role, session?, rel, ini?, ws?, mode: 'auto', at } `pmos team wrote`: a role run wrote one artifact
17
+ * propose { kind: 'propose', run, role, rel, what, ini?, at } `pmos team done --propose`: what a propose-mode run would write
18
+ * result { kind: 'result', run, role, summary, at } `pmos team done`: what the run did, in one line
19
+ * verdict { kind: 'verdict', run, rel, verdict: 'pass'|'fail', why, of: { run, role }, at } `pmos team verdict` (Evaluator only)
20
+ * inbox { kind: 'inbox', dispatch, title, items: [{ role, summary, wrote, proposed, verdicts }], at } the one entry a dispatch ends in
21
+ * pause { kind: 'pause', role: key|'all', on: bool, at } `pmos team pause|resume`
22
+ *
23
+ * THE RUNNER (the bg-queue job `team`, step 4, once a minute):
24
+ * 1. a dispatch's steps run in ORDER, one after the other: a step is queued only when the step before it ended. Handoffs go through the
25
+ * artifacts: each prompt names what the earlier steps wrote or proposed, never their transcripts.
26
+ * 2. the per-role triggers (lib/agent-team.js due): a stage an initiative reached without its artifact, and a write by another role (the
27
+ * Evaluator checks it). Each trigger key fires once. One run per initiative per role; a role stops at its daily budget.
28
+ * 3. every start goes through deps.spawn, which is lib/orchestrator-spawn.js: the queue's cap, the capacity governor, and one background
29
+ * run per initiative (bg-queue holderOf). A held start stays queued and is tried on the next tick.
30
+ * 4. when every step of a dispatch has ended, the chief of staff writes ONE inbox line for it: what each role did, wrote, proposed, and
31
+ * the Evaluator's verdicts. The Team board and the chief-of-staff inbox read it (their design is not built yet).
32
+ * A run is origin `team:<ws>:<role>:<initiative|->:<run>`, headless kind `team` (lib/headless.js), env PMOS_TEAM_* pinned by the server, so
33
+ * `pmos team wrote|done|verdict` know the run, role and initiative from the call path, never from an argument.
34
+ */
35
+ const fs = require('fs');
36
+ const path = require('path');
37
+ const crypto = require('crypto');
38
+ const T = require('./agent-team.js');
39
+
40
+ const LEDGER = 'team.jsonl';
41
+ const ORPHAN_MS = 90 * 60 * 1000; // longer than a headless run's timeout (lib/headless.js, 20 minutes by default)
42
+ const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
43
+ const file = (dir) => (dir ? path.join(dir, LEDGER) : null);
44
+ const newId = (p, now) => p + now.toString(36) + crypto.randomBytes(3).toString('hex');
45
+
46
+ function append(dir, line, now = Date.now()) {
47
+ if (!dir) throw new Error('team-runs: no state folder');
48
+ fs.mkdirSync(dir, { recursive: true });
49
+ const l = { at: new Date(now).toISOString(), ...line };
50
+ fs.appendFileSync(file(dir), JSON.stringify(l) + '\n');
51
+ return l;
52
+ }
53
+ function read(dir) {
54
+ let text = '';
55
+ try { text = fs.readFileSync(file(dir), 'utf8'); } catch { return []; }
56
+ const out = [];
57
+ for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (l && l.kind) out.push(l); } catch { /* a torn line */ } }
58
+ return out;
59
+ }
60
+
61
+ function fold(lines) {
62
+ const dispatches = new Map(), steps = new Map(), writes = [], proposals = [], results = new Map(), verdicts = [], inbox = new Map(), paused = new Set();
63
+ for (const l of lines || []) {
64
+ if (l.kind === 'dispatch' && l.id) dispatches.set(l.id, l);
65
+ else if (l.kind === 'step' && l.id) steps.set(l.id, { ...(steps.get(l.id) || {}), ...l });
66
+ else if (l.kind === 'write' && l.rel) writes.push(l);
67
+ else if (l.kind === 'propose' && l.rel) proposals.push(l);
68
+ else if (l.kind === 'result' && l.run) results.set(l.run, l);
69
+ else if (l.kind === 'verdict' && l.rel) verdicts.push(l);
70
+ else if (l.kind === 'inbox' && l.dispatch) inbox.set(l.dispatch, l);
71
+ else if (l.kind === 'pause' && l.role) { if (l.on) paused.add(l.role); else paused.delete(l.role); }
72
+ }
73
+ return { dispatches, steps: [...steps.values()], writes, proposals, results, verdicts, inbox, paused };
74
+ }
75
+ function lastWriter(F, rel) {
76
+ for (let i = F.writes.length - 1; i >= 0; i--) if (F.writes[i].rel === rel) return F.writes[i];
77
+ return null;
78
+ }
79
+ /** The write lines no Evaluator run has checked or been started for: the `written` trigger's input. */
80
+ function unchecked(F) {
81
+ const checked = new Set(F.verdicts.map((v) => `written:${v.of && v.of.run}:${v.rel}`));
82
+ return F.writes.filter((w) => w.role !== 'eval' && !checked.has(`written:${w.run}:${w.rel}`) && lastWriter(F, w.rel) === w);
83
+ }
84
+
85
+ function dispatch(dir, { kind = 'initiative', target, ws = null, board = null, facts = {}, roles = null, now = Date.now() } = {}) {
86
+ const t = one(target, 200);
87
+ if (!t) return { ok: false, error: 'name a goal or an initiative' };
88
+ if (kind !== 'goal' && !/^[a-z0-9][a-z0-9._-]{0,80}$/i.test(t)) return { ok: false, error: `"${t}" is not an initiative id; use --goal for a goal in words` };
89
+ const pick = T.planDispatch({ kind, facts, roles });
90
+ if (!pick.length) return { ok: false, error: 'no role to run: ' + (roles ? 'none of those roles runs' : 'nothing is missing') };
91
+ const F = fold(read(dir));
92
+ if (kind !== 'goal') {
93
+ const open = [...F.dispatches.values()].find((d) => d.target === t && !F.inbox.has(d.id));
94
+ if (open) return { ok: false, error: `a dispatch for ${t} is still running (${open.id}); see pmos team status` };
95
+ }
96
+ const id = newId('td', now);
97
+ append(dir, { kind: 'dispatch', id, of: kind, target: t, ws, board, roles: pick }, now);
98
+ return { ok: true, id, roles: pick };
99
+ }
100
+
101
+ /** What an initiative already has, read from the repository: its PRD, its rubric and its breakdown items. A guess for the pick only;
102
+ * `pmos team dispatch --roles` overrides it. */
103
+ function factsOf(root, ini) {
104
+ const has = (dir, re) => { try { return fs.readdirSync(path.join(root, dir)).some((f) => re.test(f)); } catch { return false; } };
105
+ const esc = String(ini).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
106
+ let tasks = false;
107
+ try { const f = require('./plan-items.js').readFoldShared(root); tasks = Object.values(f.items || {}).some((it) => it.initiative === ini && it.state !== 'withdrawn'); } catch { tasks = false; }
108
+ return { prd: has('planning/prd', new RegExp(`^${esc}(-prd)?\\.md$`)), rubric: has('planning/evals', new RegExp(`^${esc}(-eval)?-rubric\\.md$|^${esc}-eval-rubric\\.md$`)), tasks,
109
+ research: has('planning/research', new RegExp(`^${esc}`)) };
110
+ }
111
+
112
+ // a dispatch already runs its own Evaluator step after its writing roles, so their writes do not wake a second one
113
+ const inDispatch = (F, run) => F.steps.some((s) => s.id === run && s.dispatch);
114
+ const isEnded = (s) => s.state === 'done' || s.state === 'failed';
115
+
116
+ function status(F, { now = Date.now() } = {}) {
117
+ const today = T.localDay(now);
118
+ const roles = Object.values(T.TEAM).map((r) => {
119
+ const mine = F.steps.filter((s) => s.role === r.key);
120
+ return { key: r.key, name: r.name, initial: r.initial, cls: r.cls, runs: r.runs, budget: r.budget, paused: F.paused.has(r.key) || F.paused.has('all'),
121
+ working: mine.filter((s) => s.state === 'running').map((s) => ({ ini: s.ini, run: s.id, since: s.started || s.at, trigger: s.trigger })),
122
+ queued: mine.filter((s) => s.state === 'queued' || s.state === 'held').length,
123
+ today: mine.filter((s) => s.started && T.localDay(Date.parse(s.started)) === today).length };
124
+ });
125
+ const dispatches = [...F.dispatches.values()].reverse().slice(0, 20).map((d) => {
126
+ const ss = F.steps.filter((s) => s.dispatch === d.id);
127
+ return { id: d.id, of: d.of, target: d.target, at: d.at, roles: d.roles, done: !!F.inbox.get(d.id),
128
+ steps: d.roles.map((k) => { const s = ss.find((x) => x.role === k); return { role: k, state: s ? s.state : 'waiting' }; }) };
129
+ });
130
+ return { roles, dispatches, inbox: [...F.inbox.values()].reverse().slice(0, 20) };
131
+ }
132
+
133
+ function promptOf(r, step, o = {}) {
134
+ const ro = T.roleOf(r);
135
+ const list = (a, none) => (a && a.length ? a.map((x) => '- ' + x).join('\n') : '- ' + none);
136
+ const skill = o.skill ? o.skill + '\n\n' : '';
137
+ const mode = o.mode === 'auto'
138
+ ? `You may write only these artifacts:\n${list(ro.owns.paths, 'no files')}\nand run only these commands:\n${list(ro.owns.verbs, 'none')}\nAfter each file you write, record it: \`pmos team wrote <path>\`. A path outside your list is refused.`
139
+ : `PROPOSE ONLY. Write no file and change no record. For each artifact you would write, file it: \`pmos team done --propose <path> "<what you would change, in one line>"\`. The PM, or the chief of staff once autonomy is on, applies it.`;
140
+ const target = step.ini ? `the initiative ${step.ini}` : `the goal: ${one(o.goal || '', 300)}`;
141
+ const evalPart = ro.key === 'eval'
142
+ ? `\nYou are the Evaluator, in a session of your own. Check each artifact below against its rubric or the PRD's done criteria. Read only the artifacts; you do not have, and must not ask for, the transcript of the run that wrote them. For each one: \`pmos team verdict <path> pass|fail "<why, one line>"\`. PMOS refuses a verdict on work the Evaluator itself wrote.\n`
143
+ : '';
144
+ return `${skill}You are the ${ro.name} on the PMOS team, under the chief of staff. You own ${ro.what}.\n\nThis run:\n- Run: ${step.id}\n- For: ${target}\n- Why: ${step.trigger === 'dispatch' ? 'the chief of staff dispatched it' : step.trigger + (step.detail ? ' (' + one(step.detail, 160) + ')' : '')}\n- Today: ${T.localDay(o.now || Date.now())}\n\nWhat the roles before you handed over (read these artifacts; they are the handoff):\n${list(o.handoff, 'nothing yet')}\n${evalPart}\n${mode}\n\nEnd with \`pmos team done "<what you did, in one line>"\`.\n`;
145
+ }
146
+
147
+ /** deps: { workspaces() → [w], stateDirFor(w), inis(w) → [{ ini, board, stage, has }], promptFor(skillId), spawn(spec) → session,
148
+ * stop(session), autoFor(cls, o) → bool, warn(what, e) } */
149
+ function create(deps) {
150
+ const warn = deps.warn || (() => {});
151
+ const active = new Map(); // run → { dir, session }
152
+ const auto = (dir, ro) => T.modeOf(ro, (cls) => (deps.autoFor ? deps.autoFor(cls, { stateDir: dir, job: 'ai:' + ro.key }) : false));
153
+
154
+ function handoffOf(F, step) {
155
+ if (step.artifacts && step.artifacts.length) return step.artifacts.slice();
156
+ if (!step.dispatch) return [];
157
+ const before = F.steps.filter((s) => s.dispatch === step.dispatch && s.id !== step.id && isEnded(s));
158
+ const runs = new Set(before.map((s) => s.id));
159
+ const out = [];
160
+ for (const w of F.writes) if (runs.has(w.run)) out.push(`${w.rel} (written by the ${T.roleOf(w.role).name})`);
161
+ for (const p of F.proposals) if (runs.has(p.run)) out.push(`${p.rel} (proposed by the ${T.roleOf(p.role).name}: ${one(p.what, 160)})`);
162
+ return out;
163
+ }
164
+
165
+ function start(w, dir, F, step, now) {
166
+ const ro = T.roleOf(step.role);
167
+ const mode = auto(dir, ro);
168
+ const dsp = step.dispatch ? F.dispatches.get(step.dispatch) : null;
169
+ const skill = ro.skills.map((s) => { try { return deps.promptFor ? deps.promptFor(s) : null; } catch { return null; } }).find(Boolean) || '';
170
+ const prompt = promptOf(ro.key, step, { mode, handoff: handoffOf(F, step), goal: dsp && dsp.of === 'goal' ? dsp.target : '', skill, now });
171
+ const { tools, writePaths } = T.toolsOf(ro, { root: w.root, mode });
172
+ const env = { PMOS_TEAM_FILE: file(dir), PMOS_TEAM_ROOT: w.root || '', PMOS_TEAM_WS: w.id || '', PMOS_TEAM_ROLE: ro.key, PMOS_TEAM_RUN: step.id,
173
+ PMOS_TEAM_INI: step.ini || '', PMOS_TEAM_MODE: mode };
174
+ let s = null;
175
+ try {
176
+ s = deps.spawn({ name: `${ro.name} · ${one(step.ini || (dsp && dsp.target) || 'goal', 60)}`, ws: w.id, origin: `team:${w.id}:${ro.key}:${step.ini || '-'}:${step.id}`,
177
+ initialInput: prompt + '\r', initiative: step.ini || undefined, env, tools, writePaths, onDone: (r) => ended(dir, step.id, r) });
178
+ } catch (e) { warn('team run', e); }
179
+ if (!s || s.held) { if (step.state !== 'held') append(dir, { kind: 'step', id: step.id, state: 'held', why: one((s && s.note) || 'could not start', 200) }, now); return false; }
180
+ if (s.state === 'exited') { append(dir, { kind: 'step', id: step.id, state: 'failed', why: one(s.note || 'the run could not start', 200) }, now); return false; }
181
+ active.set(step.id, { dir, session: s });
182
+ append(dir, { kind: 'step', id: step.id, state: 'running', started: new Date(now).toISOString(), session: s.id || null, mode }, now);
183
+ return true;
184
+ }
185
+
186
+ function ended(dir, run, r = {}) {
187
+ active.delete(run);
188
+ try { append(dir, { kind: 'step', id: run, state: r && r.code === 0 ? 'done' : 'failed', ...(r && r.code !== 0 ? { why: one(r.note || `exit ${r.code}`, 200) } : {}) }); } catch (e) { warn('team end', e); }
189
+ }
190
+
191
+ /** The next step of each dispatch, and the inbox line of each dispatch whose steps all ended. */
192
+ function advance(w, dir, F, now) {
193
+ for (const d of F.dispatches.values()) {
194
+ if (F.inbox.has(d.id)) continue;
195
+ const ss = F.steps.filter((s) => s.dispatch === d.id);
196
+ if (ss.some((s) => !isEnded(s))) continue;
197
+ const next = d.roles.find((k) => !ss.some((s) => s.role === k));
198
+ if (next) {
199
+ const st = { kind: 'step', id: newId('tr', now), dispatch: d.id, role: next, ini: d.of === 'goal' ? null : d.target, ws: w.id, board: d.board || null, trigger: 'dispatch', key: `dispatch:${d.id}:${next}`, state: 'queued' };
200
+ append(dir, st, now); F.steps.push({ ...st, at: new Date(now).toISOString() });
201
+ continue;
202
+ }
203
+ const items = ss.map((s) => {
204
+ const res = F.results.get(s.id);
205
+ return { role: s.role, state: s.state, summary: res ? one(res.summary, 300) : (s.why || ''), wrote: F.writes.filter((x) => x.run === s.id).map((x) => x.rel),
206
+ proposed: F.proposals.filter((x) => x.run === s.id).map((x) => ({ rel: x.rel, what: one(x.what, 200) })),
207
+ verdicts: F.verdicts.filter((x) => x.run === s.id).map((x) => ({ rel: x.rel, verdict: x.verdict, why: one(x.why, 200) })) };
208
+ });
209
+ const title = d.of === 'goal' ? `The team on: ${one(d.target, 80)}` : `The team on ${d.target}`;
210
+ append(dir, { kind: 'inbox', dispatch: d.id, title, items }, now);
211
+ }
212
+ }
213
+
214
+ function tick({ now = Date.now() } = {}) {
215
+ for (const w of (deps.workspaces ? deps.workspaces() : [])) {
216
+ const dir = deps.stateDirFor(w);
217
+ if (!dir) continue;
218
+ let F = fold(read(dir));
219
+ advance(w, dir, F, now);
220
+ F = fold(read(dir));
221
+ // the per-role triggers
222
+ let inis = [];
223
+ try { inis = (deps.inis ? deps.inis(w) : []).map((x) => ({ ...x, ws: w.id })); } catch (e) { warn('team inis', e); }
224
+ for (const d of T.due({ inis, steps: F.steps, writes: unchecked(F).filter((x) => !inDispatch(F, x.run)).map((x) => ({ ...x, ws: w.id })), paused: F.paused, now })) {
225
+ append(dir, { kind: 'step', id: newId('tr', now), role: d.role, ini: d.ini, ws: w.id, board: d.board, trigger: d.trigger, key: d.key, detail: d.detail,
226
+ artifacts: d.artifacts, state: 'queued' }, now);
227
+ }
228
+ F = fold(read(dir));
229
+ // a run the server lost (it restarted while the run worked) ends as failed after ORPHAN_MS, so its role and initiative are free again
230
+ for (const s of F.steps) if (s.state === 'running' && !active.has(s.id) && now - Date.parse(s.started || s.at) > ORPHAN_MS) {
231
+ append(dir, { kind: 'step', id: s.id, state: 'failed', why: 'the run was lost (the workspace restarted while it worked)' }, now); s.state = 'failed';
232
+ }
233
+ for (const s of F.steps) {
234
+ if (s.state !== 'queued' && s.state !== 'held') continue;
235
+ if (F.paused.has('all') || F.paused.has(s.role)) continue;
236
+ if (active.has(s.id)) continue;
237
+ start(w, dir, F, s, now);
238
+ }
239
+ }
240
+ }
241
+ return { tick, ended, active: () => [...active.keys()], stop(run) { const a = active.get(run); if (a && a.session && deps.stop) deps.stop(a.session); } };
242
+ }
243
+
244
+ module.exports = { factsOf, LEDGER, append, read, fold, lastWriter, unchecked, dispatch, status, promptOf, create };
@@ -0,0 +1,112 @@
1
+ 'use strict';
2
+ /* verify-runs.js — the verifier job: after a merge, a fresh headless evaluator grades one merged run (initiative loop-telemetry).
3
+ *
4
+ * off(env) → true when PMOS_VERIFY=off (or 0, false, no)
5
+ * startsToday(queueText, day) PURE → how many verifier claims the queue holds for that day (YYYY-MM-DD, UTC)
6
+ * create(deps) → { tick({ now }), active() }
7
+ *
8
+ * WHAT ONE TURN DOES (bg-queue job `verify`, step 4, at most one run at a time):
9
+ * 1. For each open repository that is a PMOS checkout (it has scripts/verifier.js and planning/runs/verify-queue.jsonl), run
10
+ * that repository's own `node scripts/verify-work.js --json` (no model: marks merged work items integrated) and
11
+ * `node scripts/verifier.js next --json` (the newest merged run that owes a verdict, and its evaluator prompt).
12
+ * 2. If one is pending and fewer than PER_DAY verifier runs started today, claim it in the queue
13
+ * (`verifier.js claim <run> --agent verifier:<token>`, a 90-minute lease) and start headless kind `verify`,
14
+ * origin `verify:<run_id>:<token>`, with PMOS_VERIFY_RUN pinned to that run.
15
+ * 3. The run is read-only (lib/headless.js TOOLS.verify). Its only write is `node scripts/verifier.js record`, which refuses a
16
+ * verdict for any other run and writes through record-eval.js. Auto-sync then pushes the record files as it does today.
17
+ *
18
+ * Never an in-session subagent: the evaluator is its own process, started by the queue, not by the builder (D65(i)). Nothing
19
+ * here gates a merge. A run that fails leaves its claim to expire, and the entry is tried again after the lease.
20
+ *
21
+ * Off: PMOS_VERIFY=off, a scratch server (PMOS_STATE_DIR set, unless PMOS_VERIFY=1), PMOS_HEADLESS=off, `pmos ai off verify` (the bg-queue switch). Runs only when deep work may run (open(now)).
22
+ *
23
+ * deps: { roots() → [{ id, root }], open(now) → bool, headlessOff() → bool, env, spawn(spec), stop(session), warn(what, err),
24
+ * run(root, args) → { code, stdout } (default: spawnSync node), perDay? }
25
+ */
26
+ const fs = require('fs');
27
+ const path = require('path');
28
+ const crypto = require('crypto');
29
+ const { spawnSync } = require('child_process');
30
+
31
+ const PER_DAY = 4;
32
+ const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
33
+ /* Off when PMOS_VERIFY says so, and on a scratch server unless asked (PMOS_VERIFY=1): a server given its own state directory (every suite
34
+ * does, through test-run.js) must never claim real queue entries or start a model, the same rule lib/auto-sync.js enabledFor keeps. */
35
+ const off = (env) => {
36
+ const e = env || process.env;
37
+ const v = String(e.PMOS_VERIFY || '').trim();
38
+ if (/^(1|on|true|yes)$/i.test(v)) return false;
39
+ return flagOff(v) || !!String(e.PMOS_STATE_DIR || '').trim();
40
+ };
41
+ const QUEUE = path.join('planning', 'runs', 'verify-queue.jsonl');
42
+ const isCheckout = (root) => !!root && fs.existsSync(path.join(root, 'scripts', 'verifier.js')) && fs.existsSync(path.join(root, QUEUE));
43
+
44
+ function startsToday(text, day) {
45
+ let n = 0;
46
+ for (const l of String(text || '').split('\n')) {
47
+ if (!l.includes('"claimed"') || !l.includes('verifier:')) continue;
48
+ try {
49
+ const o = JSON.parse(l);
50
+ if (o.event === 'claimed' && o.claim && String(o.claim.agent || '').startsWith('verifier:') && String(o.at || '').slice(0, 10) === day) n++;
51
+ } catch { /* a torn line is the queue checker's to report */ }
52
+ }
53
+ return n;
54
+ }
55
+
56
+ const nodeRun = (root, args) => {
57
+ const r = spawnSync(process.execPath, args, { cwd: root, encoding: 'utf8', timeout: 60000, maxBuffer: 64 * 1024 * 1024 });
58
+ return { code: r.status, stdout: r.stdout || '', stderr: r.stderr || '' };
59
+ };
60
+ const parse = (s) => { try { return JSON.parse(String(s || '').trim().split('\n').pop()); } catch { return null; } };
61
+
62
+ function create(deps) {
63
+ const warn = deps.warn || (() => {});
64
+ const run = deps.run || nodeRun;
65
+ const perDay = Number(deps.perDay) > 0 ? Number(deps.perDay) : PER_DAY;
66
+ let active = null; // { run_id, token, root, session }
67
+
68
+ function ended(token) { if (active && active.token === token) active = null; }
69
+
70
+ function tick({ now = Date.now() } = {}) {
71
+ if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { off: true };
72
+ if (active) return { running: active.run_id };
73
+ let open = true;
74
+ try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
75
+ if (!open) return { started: null, closed: true };
76
+ const day = new Date(now).toISOString().slice(0, 10);
77
+ const roots = (deps.roots && deps.roots()) || [];
78
+ const integrated = [];
79
+ for (const w of roots) {
80
+ if (!isCheckout(w.root)) continue;
81
+ // The factory join, no model: a merged `Work-Item:` line marks its item integrated (scripts/verify-work.js).
82
+ try { const vw = parse(run(w.root, ['scripts/verify-work.js', '--json']).stdout); if (vw && vw.appended && vw.appended.length) integrated.push(...vw.appended.map((a) => a.id)); } catch (e) { warn('verify-work', e); }
83
+ let text = '';
84
+ try { text = fs.readFileSync(path.join(w.root, QUEUE), 'utf8'); } catch { text = ''; }
85
+ if (startsToday(text, day) >= perDay) continue;
86
+ const nx = parse(run(w.root, ['scripts/verifier.js', 'next', '--json']).stdout);
87
+ if (!nx || !nx.entry || !nx.prompt) continue;
88
+ const e = nx.entry;
89
+ const token = 'vf' + now.toString(36) + crypto.randomBytes(3).toString('hex');
90
+ const c = run(w.root, ['scripts/verifier.js', 'claim', e.run_id, '--agent', `verifier:${token}`]);
91
+ if (c.code !== 0) { warn('verifier claim', new Error((c.stdout || c.stderr || '').trim() || 'the claim was refused')); continue; }
92
+ active = { run_id: e.run_id, token, root: w.root, session: null };
93
+ let session = null;
94
+ try {
95
+ session = deps.spawn({ name: 'Verifying a merged run', ws: w.id, origin: `verify:${e.run_id}:${token}`, initialInput: nx.prompt + '\r',
96
+ env: { PMOS_VERIFY_RUN: e.run_id }, onDone: () => ended(token) });
97
+ } catch (err) { warn('verifier run', err); }
98
+ if (!session || session.held || session.state === 'exited' || session.headless !== 'verify') {
99
+ if (session && !session.held && session.headless !== 'verify' && session.state !== 'exited' && deps.stop) { try { deps.stop(session); } catch { /* best effort */ } }
100
+ active = null;
101
+ return { started: null, held: !!(session && session.held), integrated };
102
+ }
103
+ active.session = session;
104
+ return { started: e.run_id, integrated };
105
+ }
106
+ return { started: null, integrated };
107
+ }
108
+
109
+ return { tick, active: () => (active ? active.run_id : null) };
110
+ }
111
+
112
+ module.exports = { off, startsToday, create, isCheckout, PER_DAY };
@@ -98,9 +98,11 @@ const ROWS = [
98
98
  ok('L1 top to bottom: the ✦ line, North Star, Key results, Health budgets', order.join('|') === '✦|North Star|Key results|Health budgets', order.join('|'));
99
99
  const rows = await p.evaluate(() => [...document.querySelectorAll('#goalTbl .ins-row[data-goal]')].map((r) => ({ id: r.dataset.goal, now: r.querySelector('.val').textContent.replace(/\s+/g, ' ').trim(), sofar: !!r.querySelector('.sofar svg, .sofar .ins-one, .sofar .note'), pace: r.querySelector('.pace').textContent.replace(/\s+/g, ' ').trim(), mv: !!r.querySelector('.mv') })));
100
100
  const act = rows.find((r) => r.id === 'krm-act') || {}, churn = rows.find((r) => r.id === 'krm-churn') || {};
101
- ok('L2 a row is the outcome, Now of target, So far, By its date and Moved by', rows.length >= 4 && rows.every((r) => r.sofar && r.mv && r.pace), JSON.stringify(rows));
101
+ ok('L2 a row is the outcome, Now of target, So far, By its date and Moved by', rows.length >= 3 && rows.every((r) => r.sofar && r.mv && r.pace), JSON.stringify(rows));
102
102
  ok('L3 a key result says its reading of its target and its pace by its date', /of \+?30|of 50%/.test(act.now) && /by Dec 31/.test(act.pace), JSON.stringify(act));
103
- ok('L4 a goal with no reading shows a dash and says so', /—/.test(churn.now) && /No reading yet/i.test(JSON.stringify(churn)) , JSON.stringify(churn));
103
+ // re-pointed (U3, UI grill item 4): a goal with no reading is not a row; it waits in "Waiting on a source", by its source
104
+ const wt = await p.evaluate(() => { const W = document.querySelector('#waitList'); return { shown: !!W && !W.hidden, churn: !!(W && W.querySelector('[data-goal="krm-churn"]')), head: ((W && W.querySelector('h2')) || {}).textContent || '' }; });
105
+ ok('L4 a goal with no reading is not a table row; it waits in Waiting on a source', !churn.id && wt.shown && wt.churn && wt.head === 'Waiting on a source', JSON.stringify([churn, wt]));
104
106
  const ns = await txt(p, '#nsRow .ins-nsc');
105
107
  ok('L6 the North Star is its own card with its number, its change and its line', /North Star Partner uptime/.test(ns) && /99\.6%/.test(ns) && !!(await p.$('#nsRow .ins-nsch')), ns);
106
108
  await shot(p, 'okr-desktop-light');
@@ -145,17 +147,10 @@ const ROWS = [
145
147
  ok('N2 Notify me posts the choice for that goal', await until(() => R.posts.some((x) => x.path === '/api/goals/notify' && x.body.id === 'krm-act' && x.body.notify === 'push')));
146
148
  await p.evaluate(() => window.czViewer && window.czViewer.close()); await sleep(200);
147
149
 
148
- /* M · ⋯ › Metrics */
150
+ /* M · ⋯ (re-pointed, U3): Reports and dashboards and Export CSV only; the table is the metric list, so ⋯ › Metrics is gone */
149
151
  await p.click('#moreB'); await sleep(80);
150
- ok('M1 ⋯ holds Reports and dashboards, Metrics, Delivery trends, Sources and Export', (await p.evaluate(() => [...document.querySelectorAll('#moreMenu [data-more]')].map((b) => b.dataset.more).join())).startsWith('library,metrics,trends,sources,export'));
151
- await p.click('#moreMenu [data-more="metrics"]');
152
- const ml = await until(() => p.evaluate(() => { const V = document.querySelector('#czViewer'); if (!V || V.hidden || !V.querySelector('.okr-met')) return null; return { heads: [...V.querySelectorAll('.okr-sh')].map((e) => e.textContent), watch: [...V.querySelectorAll('.okr-mrow')].filter((r) => r.querySelector('.okr-tag')).map((r) => r.querySelector('b').textContent + ':' + (r.querySelector('.cz-dot').className.includes('hollow') ? 'no status' : 'status')) }; }), 4000);
153
- ok('M2 Metrics is one list: goals first, then the watched ones with no status', ml && ml.heads.join('|') === 'On a goal|Watched, no goal' && ml.watch.join() === 'App store rating:no status', JSON.stringify(ml));
154
- await shot(p, 'okr-metrics-list');
155
- await p.click('#czViewer [data-mv2="tree"]'); await sleep(120);
156
- const tr = await p.evaluate(() => ({ ns: (document.querySelector('#czViewer .okr-node.ns b') || {}).textContent || '', inputs: [...document.querySelectorAll('#czViewer .okr-tree .okr-tr1 .okr-node b')].map((b) => b.textContent) }));
157
- ok('M3 one switch shows the same list as a tree: the North Star and its inputs', tr.ns === 'Partner uptime' && tr.inputs.includes('Partner activation'), JSON.stringify(tr));
158
- await shot(p, 'okr-metrics-tree');
152
+ ok('M1 ⋯ holds Reports and dashboards and Export only', (await p.evaluate(() => [...document.querySelectorAll('#moreMenu [data-more]')].map((b) => b.dataset.more).join())) === 'library,export');
153
+ await p.keyboard.press('Escape');
159
154
  ok('M4 no script error on the page', !R.errors.length, R.errors.join(' | '));
160
155
  await R.ctx.close();
161
156
 
@@ -171,7 +166,9 @@ const ROWS = [
171
166
  const Q = await open({ w: 390, h: 844, theme });
172
167
  const ph = await Q.page.evaluate(() => ({ over: document.documentElement.scrollWidth > innerWidth + 1, cards: document.querySelectorAll('#goalCards .ins-card').length, drafts: document.querySelectorAll('#goalCards > .okr-dr').length }));
173
168
  // re-pointed (batch 18 item 11 gap, Iq8Phone): on a phone each key result is a card, its drafts under it
174
- ok('P1 on a phone (' + theme + ') the key results are cards with their drafts, with no sideways scroll', !ph.over && ph.cards >= 4 && ph.drafts >= 2, JSON.stringify(ph));
169
+ // re-pointed (U3): only a key result with a reading is a card (3 here); the one with no reading waits in the waiting list, which shows on a phone too
170
+ const pw = await Q.page.evaluate(() => { const W = document.querySelector('#waitList'); return !!W && !W.hidden && W.getBoundingClientRect().height > 0 && !!W.querySelector('[data-goal="krm-churn"]'); });
171
+ ok('P1 on a phone (' + theme + ') the key results with a reading are cards with their drafts, the rest wait in the list, with no sideways scroll', !ph.over && ph.cards >= 3 && ph.drafts >= 2 && pw, JSON.stringify([ph, pw]));
175
172
  await shot(Q.page, 'okr-phone-' + theme);
176
173
  await Q.ctx.close();
177
174
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.537.0",
3
+ "version": "0.538.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.537.0",
9
+ "version": "0.538.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.537.0",
3
+ "version": "0.538.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",
@@ -119,7 +119,7 @@ const SPRINTS = { ok: true, source: 'jira', readAt: '2026-10-19T09:00:00Z', velo
119
119
  await ctx.close();
120
120
  }
121
121
 
122
- /* the Board (premium-uncovered-features, BdSprint) carries no Sprint card and no dialog; its sprint chip opens the Sprints and releases popover, whose Backlog row opens the backlog in the side panel */
122
+ /* the Board (premium-uncovered-features, BdSprint) carries no Sprint card and no dialog; its sprint row (in the (i) after the pill, UI grill U2) opens the Sprints and releases popover, whose Backlog row opens the backlog in the side panel */
123
123
  {
124
124
  const ctx = await openMission(await browser.newContext({ viewport: { width: 1280, height: 900 } })), page = await ctx.newPage(), errs = [];
125
125
  page.on('pageerror', (e) => errs.push(String((e && e.message) || e)));
@@ -127,7 +127,7 @@ const SPRINTS = { ok: true, source: 'jira', readAt: '2026-10-19T09:00:00Z', velo
127
127
  await page.route('**/api/board-premium*', (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, state: 'ready', model, as_of: Date.now() }) }));
128
128
  await page.goto(BASE + '/premium-board.html');
129
129
  const up = await until(() => page.evaluate(() => document.querySelectorAll('#ibBody .bt-l').length > 0), 20000);
130
- ok('R10 the Board has no Sprint card; its sprint chip opens the Sprints and releases popover, and its Backlog row opens the backlog in the Viewer, never the dialog', up && await page.evaluate(() => !document.querySelector('#cSpr, #openBacklog, #popSpr')) && (await page.click('#chSprint'), await until(() => page.evaluate(() => { const p = document.querySelector('#bdPop'); return !!p && !p.hidden && p.getAttribute('aria-label') === 'Sprints and releases' && !!p.querySelector('[data-backlog]'); }))) && (await page.click('#bdPop [data-backlog]'), await until(() => page.evaluate(() => { const k = document.querySelector('#czViewer'); return !!k && !k.hidden && /Backlog/.test((k.querySelector('.cz-vw-title') || {}).textContent) && !!!document.querySelector('#dlg.on'); }))));
130
+ ok('R10 the Board has no Sprint card; its sprint row (in the (i) after the pill, UI grill U2) opens the Sprints and releases popover, and its Backlog row opens the backlog in the Viewer, never the dialog', up && await page.evaluate(() => !document.querySelector('#cSpr, #openBacklog, #popSpr')) && (await page.click('#bdLgdBtn'), await page.click('#chSprint'), await until(() => page.evaluate(() => { const p = document.querySelector('#bdPop'); return !!p && !p.hidden && p.getAttribute('aria-label') === 'Sprints and releases' && !!p.querySelector('[data-backlog]'); }))) && (await page.click('#bdPop [data-backlog]'), await until(() => page.evaluate(() => { const k = document.querySelector('#czViewer'); return !!k && !k.hidden && /Backlog/.test((k.querySelector('.cz-vw-title') || {}).textContent) && !!!document.querySelector('#dlg.on'); }))));
131
131
  ok('R10 no page error on the Board', errs.length === 0, errs.join(' | '));
132
132
  await ctx.close();
133
133
  }
@@ -200,7 +200,7 @@ const TICKETS = {
200
200
  await pg.goto(BASE + '/premium-board.html');
201
201
  await until(() => pg.evaluate(() => !!document.querySelector('#chSprint')), 20000);
202
202
  const chip = await pg.evaluate(() => document.querySelector('#chSprint').getAttribute('aria-label').replace(/\. Sprints and releases$/, '').trim()); // one icon in the row now (batch 28 item 3): its name says the sprint
203
- await pg.click('#chSprint');
203
+ await pg.click('#bdLgdBtn'); await pg.click('#chSprint'); // the sprints and releases are a row of the pill's (i) (UI grill U2)
204
204
  ok('A1 the Board\'s sprint chip names the sprint and opens the Sprints and releases popover, which lists it from Jira, never the dialog', chip === 'Sprint 14' && await until(() => pg.evaluate(() => (() => { const p = document.querySelector('#bdPop'); return !!p && !p.hidden && p.getAttribute('aria-label') === 'Sprints and releases' && /Sprints · from Jira/.test(p.textContent) && !!p.querySelector('[data-sprint="Sprint 14"]'); })() && !!!document.querySelector('#dlg.on') && !document.querySelector('#cSpr'))), chip);
205
205
  ok('A2 no page error on the Board', errs.length === 0, errs.join(' | '));
206
206
  await ctx.close();
@@ -162,8 +162,8 @@ function openGone(from, seg) {
162
162
  }
163
163
 
164
164
  /* ── Find and Filter (BdFilter) ────────────────────────────────────────────────────────────────────────────────── */
165
- let findQ = '', findAt = 0;
166
- const mark = (t, q) => { if (!q) return esc(t); const i = t.toLowerCase().indexOf(q.toLowerCase()); return i < 0 ? esc(t) : esc(t.slice(0, i)) + '<mark>' + esc(t.slice(i, i + q.length)) + '</mark>' + esc(t.slice(i + q.length)); };
165
+ /* Find (UI grill U2: one search). The Board's own find box is gone: Find and ⌘K open Search (pm/cozy-search.js) with this scope, so the Board's
166
+ * initiatives and its Jira work-items come first and the rest of Search after them. */
167
167
  function findHits(q) {
168
168
  const s = q.trim().toLowerCase(); if (!s) return { ini: [], tk: [] };
169
169
  const rows = M().initiatives.list.rows;
@@ -171,21 +171,18 @@ function findHits(q) {
171
171
  const tk = rows.flatMap((r) => ((r.track && r.track.tickets) || []).map((k) => ({ k, r }))).filter(({ k }) => k.key.toLowerCase().includes(s) || String(k.title).toLowerCase().includes(s)).slice(0, 6);
172
172
  return { ini, tk };
173
173
  }
174
- function findList() {
175
- const h = findHits(findQ), all = [...h.ini.map((r) => ({ r })), ...h.tk];
176
- findAt = Math.max(0, Math.min(findAt, all.length - 1));
177
- let i = -1;
178
- const ini = h.ini.map((r) => { i++; const s = V.statusLine(r); return `<button type="button" class="bd-mi${i === findAt ? ' hl' : ''}" data-findini="${esc(r.key)}"><i class="cz-dot ${s.tone}"></i><span class="tx"><span>${mark(r.title, findQ)}</span><span class="bd-amut">${esc([stageName(r) || r.stage, s.text].filter(Boolean).join(' · '))}</span></span>${i === findAt ? '<span class="k">Enter</span>' : ''}</button>`; }).join('');
179
- const tk = h.tk.map(({ k, r }) => { i++; return `<button type="button" class="bd-mi${i === findAt ? ' hl' : ''}" data-findtk="${esc(k.key)}" data-ini="${esc(r.key)}"><span class="bd-pill">${mark(k.key, findQ)}</span><span class="tx"><span>${mark(k.title, findQ)}</span><span class="bd-amut">${esc([k.blocked ? 'Blocked' : k.status, k.assignee].filter(Boolean).join(' · '))}</span></span>${i === findAt ? '<span class="k">Enter</span>' : ''}</button>`; }).join('');
180
- return (ini ? '<p class="bd-mlbl">Initiatives</p>' + ini : '') + (tk ? '<p class="bd-mlbl">Work-items in Jira</p>' + tk : '') + (findQ.trim() && !ini && !tk ? `<p class="bd-amut bd-mnote">Nothing on this Board matches “${esc(findQ.trim())}”.</p>` : '');
181
- }
182
- function openFind(from) {
183
- findQ = ''; findAt = 0;
184
- Pop.open(`<div class="bd-finp">${SV(I.find)}<input id="bdQ" type="search" maxlength="80" placeholder="Find an initiative or work-item" aria-label="Find an initiative or work-item" autocomplete="off"><span class="bd-kbd">Esc</span></div><div id="bdQr" class="bd-fres">${findList()}</div><p class="bd-amut bd-mnote">Find stays in the Board. Search in the menu looks everywhere.</p>`, from, { label: 'Find', width: 460, cls: 'bd-find', focus: '#bdQ' });
185
- }
186
- function pickFind() {
187
- const b = $$('#bdQr .bd-mi')[findAt]; if (b) b.click();
174
+ /** Search's scope on the Board: { name, hits(q) } (pm/cozy-search.js openSearch). An initiative opens on the Board, a work-item its ticket panel. */
175
+ export function findScope() {
176
+ return { name: 'this Board', hits: (q) => {
177
+ if (!M()) return [];
178
+ const h = findHits(q);
179
+ return [
180
+ { label: 'On this Board · Initiatives', rows: h.ini.map((r) => { const s = V.statusLine(r); return { id: r.id || r.key, icon: 'flag', title: r.title, sub: [stageName(r) || r.stage, s.text].filter(Boolean).join(' · '), tag: 'Board', open: () => { const x = A.rowOf(r.key); if (x) A.openIni(x); } }; }) },
181
+ { label: 'On this Board · Work-items in Jira', rows: h.tk.map(({ k, r }) => ({ icon: 'jira', title: k.key + ' · ' + k.title, sub: [k.blocked ? 'Blocked' : k.status, k.assignee, r.title].filter(Boolean).join(' · '), tag: 'Jira', open: () => A.openTicket(r.key, k.key) })) },
182
+ ];
183
+ } };
188
184
  }
185
+ function openFind() { import('./cozy-search.js').then((S) => S.openSearch({ scope: findScope() })); }
189
186
  /** The Filter's groups: owner and category, sprint (from the Jira reading, and the backlog; on the timeline only on the Sprint span,
190
187
  * TsSprintFilter). No workflow group: batch 28 item 3 (canvas BhA) took workflow picking off the Board. */
191
188
  function filterHtml() {
@@ -323,14 +320,6 @@ function openAddDoc(from) {
323
320
  const f = $('#czViewer form[data-form="adddoc"]'); if (f) f.kind.onchange = () => { f.url.disabled = f.kind.value === 'In PMOS'; };
324
321
  }
325
322
 
326
- /* ── Notifications (the Board's Metrics moved to Intelligence › Delivery trends, batch 22 item 4) ── */
327
- function openBell(from) {
328
- const rows = (M().rows || []).filter((r) => r.track && r.track.you), na = (M().chips || {}).asks;
329
- const list = rows.map((r) => `<button type="button" class="bd-mi" data-act="ini" data-id="${esc(r.key)}"><i class="cz-dot you m-info"></i><span class="tx"><span>${esc(r.title)}</span><span class="bd-amut">${esc(r.track.you)}</span></span></button>`).join('');
330
- const asks = na ? `<button type="button" class="bd-mi" data-act="asks"><i class="cz-dot you"></i><span class="tx"><span>${na} new ${na === 1 ? 'ask' : 'asks'}</span><span class="bd-amut">Waiting for triage</span></span></button>` : '';
331
- Pop.open(`<p class="bd-mlbl">On this Board</p>${list || asks ? list + asks : '<p class="bd-amut bd-mnote">Nothing on this board waits on you, and no new ask waits for triage.</p>'}`, from, { label: 'Notifications', width: 340, align: 'right', cls: 'bd-bell' });
332
- }
333
-
334
323
  /** The Next cell's arrow (pm/bd-next.js): Move to the next stage, as the ⋯ menu's Move to does, with its Undo. */
335
324
  export function moveNext(r, btn) { const a = r.acts || {}, cur = (a.stages || []).indexOf(a.stage); if (cur >= 0 && a.stages[cur + 1]) runRow(r, 'mv:' + (cur + 1), btn); }
336
325
  /* ── a hold on the timeline (feedback batch 9 item 8, XtiA2Hold): the ⏸ press ─────────────────────────────────────────────── */
@@ -374,23 +363,14 @@ async function setBack(r, input) {
374
363
  await done(res, 'On hold · ' + r.title + ' · back ' + md(day(v)), async () => { const u = await lifeBack(r, p); A.say(u && u.ok ? r.title + ' is back as it was.' : errOf(u)); await A.load(); });
375
364
  }
376
365
 
377
- export const open = { more: moreAct, hold: openHold, new: (from) => Asks.openNew(from), asks: (from) => Asks.openAsks(from), sprint: openSprint, find: openFind, filter: openFilter, gone: (from) => openGone(from, 'all'), bell: openBell, trend: openTrend, release: openRelease, doc: openDocPanel };
366
+ export const open = { more: moreAct, hold: openHold, new: (from) => Asks.openNew(from), asks: (from) => Asks.openAsks(from), sprint: openSprint, find: openFind, filter: openFilter, gone: (from) => openGone(from, 'all'), trend: openTrend, release: openRelease, doc: openDocPanel };
378
367
  export const closeDoc = () => { docOpen = null; };
379
368
 
380
369
  /* ── the presses ─────────────────────────────────────────────────────────────────────────────────────────────── */
381
370
  document.addEventListener('change', (e) => { const f = e.target.closest && e.target.closest('[data-holdback]'); if (!f || !A || !M()) return; const r = A.rowOf(f.dataset.holdback); if (r) setBack(r, f); });
382
- document.addEventListener('input', (e) => { if (e.target.id === 'bdQ') { findQ = e.target.value; findAt = 0; const r = $('#bdQr'); if (r) r.innerHTML = findList(); } });
383
- document.addEventListener('keydown', (e) => {
384
- if (e.target.id !== 'bdQ') return;
385
- const n = $$('#bdQr .bd-mi').length;
386
- if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); findAt = n ? (findAt + (e.key === 'ArrowDown' ? 1 : n - 1)) % n : 0; $('#bdQr').innerHTML = findList(); }
387
- else if (e.key === 'Enter') { e.preventDefault(); pickFind(); }
388
- });
389
371
  document.addEventListener('click', async (e) => {
390
372
  if (!A || !M()) return;
391
373
  const t = e.target;
392
- const fi = t.closest('[data-findini]'); if (fi) { const r = A.rowOf(fi.dataset.findini); Pop.close(false); if (r) A.openIni(r); return; }
393
- const ft = t.closest('[data-findtk]'); if (ft) { Pop.close(false); A.openTicket(ft.dataset.ini, ft.dataset.findtk); return; }
394
374
  const fl = t.closest('[data-flt]'); if (fl && Pop.isOpen() && Pop.el().contains(fl)) { const S = A.F[fl.dataset.flt], v = fl.dataset.v; if (S.has(v)) S.delete(v); else S.add(v); Pop.redraw(filterHtml()); A.redraw(); return; }
395
375
  const fg = t.closest('[data-fgrp]'); if (fg && Pop.isOpen() && Pop.el().contains(fg)) { A.setGrouping(fg.dataset.fgrp === 'product'); Pop.redraw(filterHtml()); return; }
396
376
  if (t.closest('[data-fsonly]') && Pop.isOpen() && Pop.el().contains(t)) { A.toggleSprintOnly(); Pop.redraw(filterHtml()); A.redraw(); return; }