create-pmos 0.492.0 → 0.493.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 (57) hide show
  1. package/package.json +14 -14
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/mods/pmos-cockpit/README.md +1 -1
  4. package/payload/mods/pmos-cockpit/hooks/lib/guard.mjs +2 -2
  5. package/payload/planning/evals/eval-calibration.md +1 -1
  6. package/payload/planning/okrs/health-budgets.md +1 -1
  7. package/payload/state/discoveries.md +1 -1
  8. package/workspace/changelog.json +13 -0
  9. package/workspace/fixtures/initiatives-api/list.json +0 -4
  10. package/workspace/fixtures/initiatives-api/roadmap.json +255 -275
  11. package/workspace/fixtures/initiatives-api/sheet.json +2 -3
  12. package/workspace/fixtures/report-api/draft.json +4 -4
  13. package/workspace/fixtures/reports-page/draft-biweekly-2026-10-16.md +4 -4
  14. package/workspace/guide/board.md +2 -2
  15. package/workspace/guide/index.md +2 -2
  16. package/workspace/guide/initiative-boards.md +2 -2
  17. package/workspace/guide/initiatives-roadmap.md +38 -39
  18. package/workspace/guide/initiatives-screen.md +20 -20
  19. package/workspace/guide/initiatives-timeline.md +7 -9
  20. package/workspace/guide/integrated-work.md +7 -8
  21. package/workspace/guide/layout.md +2 -2
  22. package/workspace/guide/lifecycle.md +2 -2
  23. package/workspace/guide/notes.md +1 -1
  24. package/workspace/guide/pm-only-acts.md +5 -5
  25. package/workspace/guide/pm-only-lines.md +3 -3
  26. package/workspace/guide/reports.md +2 -2
  27. package/workspace/guide/today.md +2 -2
  28. package/workspace/lib/board-cli.js +1 -1
  29. package/workspace/lib/board-fold.js +6 -6
  30. package/workspace/lib/board-premium.js +3 -3
  31. package/workspace/lib/calendar-tidy.js +1 -1
  32. package/workspace/lib/core-docs.js +2 -2
  33. package/workspace/lib/engine/boards.js +11 -11
  34. package/workspace/lib/engine/signals/detectors.js +13 -13
  35. package/workspace/lib/engine/signals/facts.js +5 -3
  36. package/workspace/lib/health-rules-factory.js +13 -14
  37. package/workspace/lib/health-rules-plan.js +8 -7
  38. package/workspace/lib/initiative-cli.js +59 -63
  39. package/workspace/lib/initiative-needs.js +6 -6
  40. package/workspace/lib/initiative-premium.js +2 -2
  41. package/workspace/lib/initiative-writer.js +2 -2
  42. package/workspace/lib/lifecycle-stage.js +39 -0
  43. package/workspace/lib/placements.js +117 -95
  44. package/workspace/lib/plan-rules.js +7 -5
  45. package/workspace/lib/pm-guard.js +1 -3
  46. package/workspace/lib/pm-lines-needs.js +1 -1
  47. package/workspace/lib/report-draft.js +17 -16
  48. package/workspace/lib/report-slides-data.js +11 -7
  49. package/workspace/lib/routes-boards.js +8 -7
  50. package/workspace/lib/routes-initiatives.js +29 -43
  51. package/workspace/lib/routes-notes.js +24 -15
  52. package/workspace/lib/split-merge.js +2 -3
  53. package/workspace/package-lock.json +2 -2
  54. package/workspace/package.json +1 -1
  55. package/workspace/public/pm/http.js +1 -1
  56. package/workspace/public/pm/view-notes.js +8 -8
  57. package/workspace/replaced-tests.json +14 -0
@@ -4,9 +4,8 @@
4
4
  *
5
5
  * pmos initiative new "<title>" --lane <lane> --anchor <KR|health:id> [--intent "<text>"] [--id <id>]
6
6
  * pmos initiative new --from capture-YYYY-MM-DD-<n> [--anchor …] [--lane …] [--title "…"]
7
- * pmos initiative now <id> PM only: type the id to confirm
8
- * pmos initiative next|later <id> [--top] to the end of that horizon, or its top
9
- * pmos initiative top|up|down <id> reorder inside its horizon
7
+ * pmos initiative top|up|down|bottom <id> reorder it on the Roadmap (one ranked list, D105)
8
+ * pmos initiative after <id> <other-id> rank it right after another initiative
10
9
  * pmos initiative check-by <id> <YYYY-MM-DD|none>
11
10
  * pmos initiative adopt <proposal-eid> the PM types the eid to confirm; an agent passes (D98)
12
11
  * pmos initiative drop <proposal-eid>
@@ -15,11 +14,12 @@
15
14
  * every command: [--json] [--root <dir>]
16
15
  *
17
16
  * The SAME writers the workspace page uses (lib/initiative-writer.js, lib/placements.js) — no server is needed. Who
18
- * wrote a line comes from the call path, never from an argument: Move to Now, adopt, and any line into Now go through
19
- * lib/pm-guard.js requirePmCli — the PM types the confirmation at a terminal, and an agent session passes with its own
20
- * actor (D98); every other command takes lib/actor.js fromCli: the PM at a terminal, the bound agent session from
17
+ * wrote a line comes from the call path, never from an argument: adopt goes through lib/pm-guard.js requirePmCli — the
18
+ * PM types the confirmation at a terminal, and an agent session passes with its own actor (D98); every other command
19
+ * takes lib/actor.js fromCli: the PM at a terminal, the bound agent session from
21
20
  * PMOS_SESSION, `agent:unknown` otherwise. An agent's placement applies at once and its line names the agent (D98).
22
21
  * Work lanes only (D86 point 4): `list` and `export` leave document-lane initiatives out.
22
+ * D105 retired Now / Next / Later: `now`, `next` and `later` answer with what to use instead and change nothing.
23
23
  * Exit codes: 0 done, 1 refused, 2 usage.
24
24
  */
25
25
  const path = require('path');
@@ -32,25 +32,28 @@ const rowsLib = require('./initiative-rows.js');
32
32
  const planRules = require('./plan-rules.js');
33
33
  const breakdownExport = require('./breakdown-export.js');
34
34
  const triage = require('./triage.js');
35
+ const lifecycle = require('./lifecycle-stage.js');
35
36
  const { parseArgs } = require('./schedule-cli');
36
37
 
37
- const COMMANDS = { initiative: ['new', 'now', 'next', 'later', 'top', 'up', 'down', 'check-by', 'adopt', 'drop', 'list', 'export'] };
38
+ const COMMANDS = { initiative: ['new', 'top', 'up', 'down', 'bottom', 'after', 'check-by', 'adopt', 'drop', 'list', 'export'] };
39
+ /** The horizon verbs D105 retired: they answer with what to use instead. */
40
+ const RETIRED = Object.freeze(['now', 'next', 'later']);
38
41
  const USAGE = [
39
- 'usage: pmos initiative new|now|next|later|top|up|down|check-by|adopt|drop|list|export — initiatives on the Roadmap',
42
+ 'usage: pmos initiative new|top|up|down|bottom|after|check-by|adopt|drop|list|export — initiatives on the Roadmap',
40
43
  ' pmos initiative new "<title>" --lane <lane> --anchor <KR|health:id> [--intent "<text>"] [--id <id>]',
41
44
  ' pmos initiative new --from capture-YYYY-MM-DD-<n> [--anchor <anchor>] [--lane <lane>] [--title "<title>"]',
42
- ' pmos initiative now <id> move it into Now (you only; type the id to confirm)',
43
- ' pmos initiative next|later <id> [--top] move it to the end of Next or Later, or to its top',
44
- ' pmos initiative top|up|down <id> reorder it inside its horizon',
45
+ ' pmos initiative top|up|down|bottom <id> reorder it on the Roadmap',
46
+ ' pmos initiative after <id> <other-id> rank it right after another initiative',
45
47
  ' pmos initiative check-by <id> <YYYY-MM-DD|none>',
46
48
  ' pmos initiative adopt <proposal> keep an open proposal (you type the proposal to confirm)',
47
49
  ' pmos initiative drop <proposal> close an open proposal',
48
- ' pmos initiative list Now, Next and Later, in order',
50
+ ' pmos initiative list the Roadmap, ranked, with each lifecycle stage',
49
51
  ' pmos initiative export <id> the breakdown as markdown on stdout',
50
52
  ' every command: [--json] [--root <dir>]',
51
- 'An agent session\'s placement applies at once and names the agent. A new initiative lands in Later.',
53
+ 'An agent session\'s move applies at once and names the agent. A new initiative lands at the end of the Roadmap.',
54
+ 'Now, Next and Later are retired (D105): the rank says what comes first, the lifecycle stage says where it is.',
52
55
  ];
53
- const BOOL = new Set(['json', 'top', 'help']);
56
+ const BOOL = new Set(['json', 'top', 'help']); // --top is kept so an old script gets the retired answer, not a usage error
54
57
  const VALUE = new Set(['lane', 'anchor', 'intent', 'id', 'from', 'title', 'root']);
55
58
  const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
56
59
 
@@ -78,6 +81,11 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
78
81
  for (const l of USAGE) say(l);
79
82
  return verb ? 0 : 1;
80
83
  }
84
+ if (RETIRED.includes(verb)) {
85
+ const msg = `Now, Next and Later are retired (D105); nothing was moved. Rank the initiative instead: pmos initiative top|up|down|bottom <id>, or pmos initiative after <id> <other-id>. Its lifecycle stage (Triage to Evaluate) says where it is.`;
86
+ if (json) say(JSON.stringify({ ok: false, error: msg })); else say(`✗ ${msg}`);
87
+ return 2;
88
+ }
81
89
  if (!COMMANDS.initiative.includes(verb)) { say(`unknown initiative command "${verb}" — one of ${COMMANDS.initiative.join(', ')}`); return 2; }
82
90
  if ('by' in flags || 'via' in flags) { say(`attribution is set from the call path; --${'by' in flags ? 'by' : 'via'} is not accepted`); return 2; }
83
91
  for (const k of Object.keys(flags)) {
@@ -115,28 +123,32 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
115
123
  for (const k of ['lane', 'anchor', 'intent', 'id']) if (flags[k]) input[k] = flags[k];
116
124
  const r = writer.createInitiative(root, input, { actor: actorLib.fromCli(who), now });
117
125
  if (!r.ok) return fail(r.error);
118
- return done({ id: r.id, path: r.path }, `✓ ${r.id} added to Later (${r.path}). Commit the record to keep it.`);
126
+ return done({ id: r.id, path: r.path }, `✓ ${r.id} added at the end of the Roadmap (${r.path}). Commit the record to keep it.`);
119
127
  }
120
128
 
121
129
  if (verb === 'list') {
122
130
  const o = order();
123
131
  if (o.error) return fail(o.error);
124
- const titles = new Map(o.rows.map((r) => [r.id, r.title || r.id]));
125
- if (json) { say(JSON.stringify({ ok: true, order: o.placed.order, byInit: o.placed.byInit, proposals: o.placed.proposals.map((p) => ({ ...p, by: actorLib.pageName(p.by) })) })); return 0; }
126
- for (const h of placements.HORIZONS) {
127
- const ids = o.placed.order[h];
128
- const dormant = h === 'later' ? ids.filter((id) => o.placed.byInit[id].dormant).length : 0;
129
- say(`${h[0].toUpperCase()}${h.slice(1)} · ${ids.length}${dormant ? ` (${dormant} dormant)` : ''}`);
130
- for (const id of ids) {
131
- const p = o.placed.byInit[id];
132
- const bits = [];
133
- if (h === 'now' && !p.confirmed) bits.push('unconfirmed');
134
- if (p.check_by) bits.push(`check by ${p.check_by}`);
135
- if (p.dormant) bits.push('dormant');
136
- say(` ${p.rank + 1}. ${id} — ${titles.get(id)}${bits.length ? ' · ' + bits.join(' · ') : ''}`);
137
- }
132
+ const byRow = new Map(o.rows.map((r) => [r.id, r]));
133
+ const stage = (id) => lifecycle.labelOf(byRow.get(id));
134
+ if (json) {
135
+ say(JSON.stringify({ ok: true, ranked: o.placed.ranked, byInit: o.placed.byInit, stages: Object.fromEntries(o.placed.ranked.map((id) => [id, stage(id)])),
136
+ proposals: o.placed.proposals.map((p) => ({ ...p, by: actorLib.pageName(p.by) })) }));
137
+ return 0;
138
+ }
139
+ const ids = o.placed.ranked;
140
+ const dormant = ids.filter((id) => o.placed.byInit[id].dormant).length;
141
+ say(`Roadmap · ${ids.length}${dormant ? ` (${dormant} dormant)` : ''}`);
142
+ for (const id of ids) {
143
+ const p = o.placed.byInit[id];
144
+ const bits = [];
145
+ if (stage(id)) bits.push(stage(id));
146
+ if (!p.confirmed) bits.push('not ranked yet');
147
+ if (p.check_by) bits.push(`check by ${p.check_by}`);
148
+ if (p.dormant) bits.push('dormant');
149
+ say(` ${p.rank + 1}. ${id} — ${(byRow.get(id) || {}).title || id}${bits.length ? ' · ' + bits.join(' · ') : ''}`);
138
150
  }
139
- for (const p of o.placed.proposals) say(`proposal ${p.eid}: ${p.init} to ${p.horizon} · ${actorLib.pageName(p.by)}`);
151
+ for (const p of o.placed.proposals) say(`proposal ${p.eid}: ${p.init} ${p.after ? `after ${p.after}` : 'to the top'} · ${actorLib.pageName(p.by)}`);
140
152
  return 0;
141
153
  }
142
154
 
@@ -166,32 +178,14 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
166
178
  const id = pos[0];
167
179
  if (!id) { say(`usage: pmos initiative ${verb} <id>${verb === 'check-by' ? ' <YYYY-MM-DD|none>' : ''}`); return 2; }
168
180
 
169
- if (verb === 'now' || verb === 'next' || verb === 'later') {
170
- // After the last line of that horizon in the LEDGER's order, so no workflow derivation is needed (fast). Day one's
171
- // rows are seeded before the lines (placements.js), so the ones no line was placed after sort below it. --top puts
172
- // it first.
173
- const ledgerOnly = placements.readPlacements(root);
174
- const list = ledgerOnly.order[verb].filter((x) => x !== id);
175
- const after = flags.top ? null : (list.length ? list[list.length - 1] : null);
176
- let actor;
177
- if (verb === 'now') {
178
- const g = await pmPress('now', id);
179
- if (!g.ok) return fail(g.error);
180
- actor = g.actor;
181
- } else actor = actorLib.fromCli(who);
182
- const r = write([{ ev: 'placed', initiative: id, horizon: verb, after }], actor);
183
- if (!r.ok) return fail(r.error);
184
- return done({ written: r.written, proposed: r.lines[0].proposed }, said(r, `✓ ${id} moved to ${verb[0].toUpperCase()}${verb.slice(1)}${flags.top ? ', at the top' : ''}`));
185
- }
186
-
187
- // top | up | down | check-by: the whole order, day one included.
181
+ // top | up | down | bottom | after | check-by: the whole order, day one included.
188
182
  const o = order();
189
183
  if (o.error) return fail(o.error);
190
184
  const cur = o.placed.byInit[id];
191
185
  if (!cur) return fail(`no work-lane initiative ${id} in this repository`);
192
- const list = o.placed.order[cur.horizon];
186
+ const list = o.placed.ranked;
193
187
  const i = list.indexOf(id);
194
- const ev = { ev: 'placed', initiative: id, horizon: cur.horizon };
188
+ const ev = { ev: 'ranked', initiative: id };
195
189
  let what;
196
190
  if (verb === 'check-by') {
197
191
  const v = pos[1];
@@ -199,24 +193,26 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
199
193
  ev.after = i > 0 ? list[i - 1] : null;
200
194
  ev.check_by = v === 'none' ? null : v;
201
195
  what = v === 'none' ? `✓ ${id}: check-by cleared` : `✓ ${id}: check by ${v}`;
196
+ } else if (verb === 'after') {
197
+ const other = pos[1];
198
+ if (!other) { say('usage: pmos initiative after <id> <other-id>'); return 2; }
199
+ if (other === id) return fail('an initiative cannot come after itself');
200
+ if (!o.placed.byInit[other]) return fail(`no work-lane initiative ${other} on the Roadmap`);
201
+ if (i > 0 && list[i - 1] === other) return done({ written: 0 }, `${id} comes right after ${other} already`);
202
+ ev.after = other;
203
+ what = `✓ ${id} ranked right after ${other}`;
202
204
  } else if (verb === 'top' || verb === 'up') {
203
- if (i === 0) return done({ written: 0 }, `${id} is at the top of ${cur.horizon} already`);
205
+ if (i === 0) return done({ written: 0 }, `${id} is at the top of the Roadmap already`);
204
206
  ev.after = verb === 'top' || i === 1 ? null : list[i - 2];
205
207
  what = `✓ ${id} moved ${verb === 'top' ? 'to the top' : 'up'}`;
206
208
  } else {
207
- if (i === list.length - 1) return done({ written: 0 }, `${id} is at the end of ${cur.horizon} already`);
208
- ev.after = list[i + 1];
209
- what = `✓ ${id} moved down`;
209
+ if (i === list.length - 1) return done({ written: 0 }, `${id} is at the end of the Roadmap already`);
210
+ ev.after = verb === 'bottom' ? list[list.length - 1] : list[i + 1];
211
+ what = `✓ ${id} moved ${verb === 'bottom' ? 'to the end' : 'down'}`;
210
212
  }
211
- let actor;
212
- if (cur.horizon === 'now') {
213
- const g = await pmPress('now', id);
214
- if (!g.ok) return fail(g.error);
215
- actor = g.actor;
216
- } else actor = actorLib.fromCli(who);
217
- const r = write([ev], actor);
213
+ const r = write([ev], actorLib.fromCli(who));
218
214
  if (!r.ok) return fail(r.error);
219
215
  return done({ written: r.written, proposed: r.lines[0].proposed }, said(r, what));
220
216
  }
221
217
 
222
- module.exports = { run, COMMANDS, USAGE };
218
+ module.exports = { run, COMMANDS, RETIRED, USAGE };
@@ -9,8 +9,9 @@
9
9
  * triage one row per capture note not yet added (lib/triage.js): "Proposed: <title> · <lane> · <anchor>".
10
10
  * A capture whose words match a file under planning/out-of-scope/ says "matches an earlier rejection"
11
11
  * in today.cause and names that file in today.evidence. Act: Add (`pmos initiative new --from …`).
12
- * cycle-review ONE row (R12 kind 7) while the cycle holds something to confirm: day one's unconfirmed Now
13
- * initiatives (R26), agent proposals not kept or dropped (R23), and passed check-by dates. 2D draws it.
12
+ * cycle-review ONE row (R12 kind 7) while the cycle holds something to confirm: agent proposals not kept or
13
+ * dropped (R23) and passed check-by dates. 2D draws it. (Day one's "unconfirmed Now" went with the
14
+ * horizons, D105.)
14
15
  * no-anchor one row per work-lane initiative record with no parent_kr (R12 kind 8, "old records have no anchor").
15
16
  *
16
17
  * Every row is repository-wide, so a tree that is not the lead returns []. A row never carries a session token: no
@@ -60,17 +61,16 @@ function cycleRow(root, records, now) {
60
61
  const rules = planRules.readRules(root);
61
62
  const placed = placements.readPlacements(root, { now, rules, records });
62
63
  const today = new Date(now).toISOString().slice(0, 10);
63
- const unconfirmed = placed.order.now.filter((id) => placed.byInit[id].source === 'day-one');
64
+ // D105: there is no Now to confirm. Day one's guess is the activity order, and the PM ranks when it matters.
64
65
  const passed = Object.entries(placed.byInit).filter(([, p]) => p.check_by && p.check_by < today).map(([id]) => id);
65
66
  const proposals = placed.proposals.length;
66
- if (!unconfirmed.length && !passed.length && !proposals) return [];
67
+ if (!passed.length && !proposals) return [];
67
68
  const parts = [];
68
- if (unconfirmed.length) parts.push(`Day one: ${plural(unconfirmed.length, 'initiative reads', 'initiatives read')} Now, unconfirmed`);
69
69
  if (proposals) parts.push(`${plural(proposals, 'agent proposal', 'agent proposals')} to keep or drop`);
70
70
  if (passed.length) parts.push(`${plural(passed.length, 'check-by date', 'check-by dates')} passed`);
71
71
  return [{
72
72
  run_id: `${NAME}:cycle:${today}`, kind: 'cycle-review', initiative_id: null,
73
- question: unconfirmed.length ? 'Confirm what is in Now' : 'Review the cycle', doc: null,
73
+ question: 'Review the cycle', doc: null,
74
74
  today: { kind: 7, source: NAME, cause: parts.join('; '), evidence: ledgerRel(root, 'placements'), act: { label: 'Review', cli: null } },
75
75
  }];
76
76
  }
@@ -5,7 +5,7 @@
5
5
  * peekModel() → the last model built, for the agent to find the initiative in (null before the first)
6
6
  *
7
7
  * facts come from the routes of lib/routes-boards.js, lib/routes-initiatives.js and lib/routes-core-docs.js:
8
- * row GET /api/boards/initiative → .row { id, title, lane, stage, cat, owner, anchor, horizon, status, start, end, progress, warnings, updated, stageSource, workflow }
8
+ * row GET /api/boards/initiative → .row { id, title, lane, stage, cat, owner, anchor, rank, status, start, end, progress, warnings, updated, stageSource, workflow }
9
9
  * sheet GET /api/initiatives/<id> → { initiative: { health, progress, display }, stepper: [{ id, label, state, owed }], waiting, files, derived }
10
10
  * docs GET /api/core-docs?level=initiative → { summary, docs: [{ key, title, for, by, kind, st, when, open: { path }, act, running }] }
11
11
  * ladder the workflow engine's ladder for this initiative (console-state.ladder → row): { steps: [{ key, status, evidence, rule }], next: { step, why, action } }
@@ -149,7 +149,7 @@ function build(f) {
149
149
  const files = ((sheet && sheet.files) || []).filter((x) => x && x.path).slice(0, 12).map((x) => ({ label: x.label || x.kind, path: x.path }));
150
150
  const say = (row.title || id) + ' is ' + (status ? STATUS_LABEL[status] ? STATUS_LABEL[status].toLowerCase() : status : 'without a status') + (row.stage ? ', in the ' + row.stage + ' stage' : '') + '.'
151
151
  + (row.stageSource === 'derived' ? ' The stage comes from the workflow engine, not from a person.' : '');
152
- const facts = [['Lane', row.lane], ['Stage', row.stage], ['Anchor', row.anchor], ['Horizon', row.horizon], ['Status', head.statusLabel], ['Owner', row.owner], ['Planned finish', row.end ? shortDate(row.end) : ''], ['Progress', prog && prog.total ? prog.done + ' of ' + prog.total : '']].filter((x) => x[1]);
152
+ const facts = [['Lane', row.lane], ['Stage', row.stage], ['Anchor', row.anchor], ['Rank', Number.isInteger(row.rank) ? '#' + (row.rank + 1) + ' on the Roadmap' : ''], ['Status', head.statusLabel], ['Owner', row.owner], ['Planned finish', row.end ? shortDate(row.end) : ''], ['Progress', prog && prog.total ? prog.done + ' of ' + prog.total : '']].filter((x) => x[1]);
153
153
 
154
154
  const model = {
155
155
  pending: !!f.pending,
@@ -16,7 +16,7 @@
16
16
  * pmos/state/initiatives/ in a kit repository, from the engine's layout): the frontmatter the gates read (`type`,
17
17
  * `title`, `timestamp`, `lane`, `parent_kr`, and `status` — the chore lane's intent — plus the router's
18
18
  * `specimen_test` and `surface_check` when the caller has them). No new frontmatter field (R24). Then ONE `created`
19
- * line in placements.jsonl (lib/placements.js): the initiative lands at the top of Later, whoever made it (R16, R23).
19
+ * line in placements.jsonl (lib/placements.js): the initiative lands at the end of the Roadmap (D105), whoever made it (R16, R23).
20
20
  * The record is not committed: a commit is the caller's (the PM's) act.
21
21
  *
22
22
  * WHAT IT REFUSES, whoever calls:
@@ -29,7 +29,7 @@
29
29
  * - a writer field (`by`, `via`, `at`, …) in the input (400), and a call without an actor (500).
30
30
  * The file is opened O_CREAT|O_EXCL|O_NOFOLLOW inside the resolved initiatives folder, so an existing file or a
31
31
  * symlink is never written through. When the placement line cannot be written, the new record is removed again and
32
- * the refusal is returned: a record never lands without its place in Later.
32
+ * the refusal is returned: a record never lands without its place on the Roadmap.
33
33
  *
34
34
  * renameInitiative(root, id, title, { actor }) → { ok: true, id, path, from, title } | { ok: false, status, error, field }
35
35
  *
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+ /* lifecycle-stage.js — the lifecycle stage an initiative is in (Triage, Discover, Plan, Prioritize, Build, Deliver,
3
+ * Monitor, Evaluate), read from a workflow row (D105: the stage replaces Now / Next / Later as "where it is").
4
+ *
5
+ * keyOf(row) → 'build' | … | null the current stage of scripts/nine-stages.js, or null when no stage shows
6
+ * labelOf(row) → 'Build' | … | ''
7
+ * underway(row) → true when the work is under way: past its spec and not yet accepted (the engine's contract, build
8
+ * and eval rungs; the lifecycle reads Build to Evaluate there). An idle initiative is at risk only then.
9
+ *
10
+ * `row` is a workflow row ({ lane, stage, steps, accepted? }, lib/initiative-rows.js). The stage is derived, never stored:
11
+ * this file only names it. A finished row (accepted) reads Evaluate's milestone as done and has no current stage; it
12
+ * answers null. Nothing here is guessed: a row whose stages show no signal answers null.
13
+ */
14
+ const { repoScript } = require('./repo-script.js');
15
+ // The label layer is read on first use, not at load: a copy of the workspace with no scripts/ tree (state-isolation's
16
+ // scratch install) still starts, and keyOf answers null there. `underway` never needs it.
17
+ let NS = null;
18
+ function labels() {
19
+ if (NS === null) { try { NS = require(repoScript('nine-stages.js')); } catch { NS = false; } } // pure label layer; never workflow-state.js
20
+ return NS || null;
21
+ }
22
+
23
+ /** The engine's rungs (scripts/workflow-state.js) between an agreed spec and acceptance. */
24
+ const UNDERWAY = new Set(['contract', 'build', 'eval']);
25
+
26
+ function keyOf(row) {
27
+ if (!row || typeof row !== 'object') return null;
28
+ const ns = labels();
29
+ if (!ns) return null;
30
+ try {
31
+ const steps = ns.nineStages(row.lane, { stage: row.stage, steps: Array.isArray(row.steps) ? row.steps : [] });
32
+ const cur = steps.find((s) => s.status === 'current');
33
+ return cur ? cur.key : null;
34
+ } catch { return null; }
35
+ }
36
+ const labelOf = (row) => { const k = keyOf(row); return k ? labels().LABELS[k] : ''; };
37
+ const underway = (row) => !!row && !row.accepted && UNDERWAY.has(String(row.stage || ''));
38
+
39
+ module.exports = { keyOf, labelOf, underway, UNDERWAY };