create-pmos 0.570.0 → 0.572.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.
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+ /* factory-rollout.js — a merged factory change reaches users through its flag, 5% → 50% → 100%, and rolls itself back (D108,
3
+ * initiative factory-guardrail-merge, done test G5). No model.
4
+ *
5
+ * tick(root, { now, env }) → { acted: [{ item, step, percent, why }], why? } what the server's verify tick runs for each product
6
+ * rollout(root, item, { to, now, env, by }) → { ok, percent } | { ok: false, error } the PM's own flip (`pmos build rollout`)
7
+ * rollback(root, item, { now, env, by }) → { ok } | { ok: false, error } undo: the flag to 0 (`pmos build rollback`)
8
+ * statusOf(root) → [{ item, flag, percent, step, at, why }]
9
+ * configOf(root) → { set, get?, metrics, hold_minutes } | null
10
+ *
11
+ * THE PROVIDER is the PM's: `<kit>/factory.json` (pmos/factory.json in a product repository) names the commands, so PMOS holds no
12
+ * flag service key and runs nothing the PM did not write there:
13
+ * { "flags": { "set": "my-flags set {flag} {percent}" }, {flag} and {percent} are filled in; nothing else is
14
+ * "metrics": { "login_errors": "node ops/login-error-rate.js" }, each prints one number
15
+ * "hold_minutes": 60 } how long each step holds before the next (default 60)
16
+ * A work item names its flag and metric when it is declared: `work-item.js declare … --flag otp_login --metric login_errors --budget 0.02`.
17
+ *
18
+ * THE RULES, per merged (integrated) item with a flag:
19
+ * - autonomy off (`pmos ai off`, PMOS_AUTONOMY=off): nothing moves.
20
+ * - no provider, or no metric for the item: PMOS says so once (`wait-pm`). The change merged default-off; the PM flips the flag.
21
+ * - the metric is read before every step. Above its budget: BREACH. The flag goes to 0, a revert pull request is opened
22
+ * (lib/build-engine.js revert, the PM's own push path), and the autonomy ledger records a revert: the factory is back to
23
+ * propose-only for 7 days (D106 (5)), so open() writes `PMOS-Merge: human` and the guardrail reads human.
24
+ * - inside budget and the step has held hold_minutes: the next step. A key-result item (`--kr`) stops before 100% (`wait-pm`).
25
+ * - a metric that cannot be read holds the step; it never advances on a missing number.
26
+ * Every step is one line in <state>/factory-rollout.jsonl; `pmos build rollback` sets the flag to 0 and records it.
27
+ */
28
+ const fs = require('fs');
29
+ const path = require('path');
30
+ const cp = require('child_process');
31
+ const WK = require('./work-kind.js');
32
+
33
+ const STEPS = Object.freeze([5, 50, 100]);
34
+ const JOB = 'ai:factory';
35
+ const OPEN_JOB = 'propose:build'; // the ✦ job that opens the factory's pull request by itself (D108 as amended 2026-11-16)
36
+ const LEDGER = 'factory-rollout.jsonl';
37
+ const FLAG_RE = /^[A-Za-z0-9_.:-]{2,80}$/;
38
+ const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
39
+
40
+ function configOf(root) {
41
+ const dir = WK.factoryDir(root);
42
+ if (!dir) return null;
43
+ let j;
44
+ try { j = JSON.parse(fs.readFileSync(path.join(dir, 'factory.json'), 'utf8')); } catch { return null; }
45
+ const set = j && j.flags && typeof j.flags.set === 'string' && j.flags.set.includes('{flag}') && j.flags.set.includes('{percent}') ? j.flags.set : null;
46
+ if (!set) return null;
47
+ const metrics = j.metrics && typeof j.metrics === 'object' ? Object.fromEntries(Object.entries(j.metrics).filter(([, v]) => typeof v === 'string' && v.trim())) : {};
48
+ const hold = Number(j.hold_minutes);
49
+ return { set, metrics, hold_minutes: Number.isFinite(hold) && hold >= 0 ? hold : 60, dir };
50
+ }
51
+
52
+ function stateDir(root) {
53
+ const top = topOf(root) || root;
54
+ return require('./driver.js').stateDirOf(top, { create: true });
55
+ }
56
+ function topOf(root) {
57
+ const r = cp.spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd: root, encoding: 'utf8' });
58
+ return r.status === 0 ? String(r.stdout).trim() : null;
59
+ }
60
+ function lines(root) {
61
+ const d = stateDir(root);
62
+ if (!d) return [];
63
+ let t = '';
64
+ try { t = fs.readFileSync(path.join(d, LEDGER), 'utf8'); } catch { return []; }
65
+ return t.split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
66
+ }
67
+ function log(root, line, now) {
68
+ const d = stateDir(root);
69
+ if (!d) return line;
70
+ const full = { at: new Date(now == null ? Date.now() : now).toISOString(), ...line };
71
+ fs.appendFileSync(path.join(d, LEDGER), JSON.stringify(full) + '\n');
72
+ return full;
73
+ }
74
+ /** The newest line per item. */
75
+ function lastOf(root) {
76
+ const m = new Map();
77
+ for (const l of lines(root)) if (l.item) m.set(l.item, l);
78
+ return m;
79
+ }
80
+
81
+ /** Run one of the PM's commands. Placeholders are filled from checked values only. → { ok, out } */
82
+ function sh(cmd, cwd, env) {
83
+ const r = cp.spawnSync('sh', ['-c', cmd], { cwd, encoding: 'utf8', timeout: 60000, env });
84
+ return { ok: !r.error && r.status === 0, out: one(r.stdout, 300), err: one(r.stderr || (r.error && r.error.message), 300) };
85
+ }
86
+ function setFlag(cfg, flag, percent, env) {
87
+ if (!FLAG_RE.test(flag) || !Number.isInteger(percent) || percent < 0 || percent > 100) return { ok: false, err: 'refused: a flag name or a percent that is not plain' };
88
+ return sh(cfg.set.split('{flag}').join(flag).split('{percent}').join(String(percent)), cfg.dir, env);
89
+ }
90
+ function readMetric(cfg, name, env) {
91
+ const cmd = cfg.metrics[name];
92
+ if (!cmd) return { ok: false, err: `no metric "${name}" in factory.json` };
93
+ const r = sh(cmd, cfg.dir, env);
94
+ const v = r.ok ? Number((r.out.match(/-?[0-9]+(\.[0-9]+)?(e-?[0-9]+)?/i) || [])[0]) : NaN;
95
+ return Number.isFinite(v) ? { ok: true, value: v } : { ok: false, err: r.ok ? `"${name}" printed no number` : `"${name}" failed: ${r.err}` };
96
+ }
97
+
98
+ function flagged(root) {
99
+ return require('./build-engine.js').itemsOf(root).filter((x) => x.guard && x.guard.flag && x.guard.flag.name && x.state === 'integrated');
100
+ }
101
+
102
+ function tick(root, { now = Date.now(), env = process.env } = {}) {
103
+ const A = require('./autonomy.js');
104
+ const k = A.killed({ env });
105
+ if (k) return { acted: [], why: k };
106
+ const items = flagged(root);
107
+ if (!items.length) return { acted: [] };
108
+ const cfg = configOf(root);
109
+ const last = lastOf(root);
110
+ const acted = [];
111
+ const say = (line) => { const l = log(root, line, now); acted.push(l); return l; };
112
+ for (const it of items) {
113
+ const f = it.guard.flag, prev = last.get(it.item_id) || null;
114
+ const percent = prev ? Number(prev.percent) || 0 : 0;
115
+ if (prev && ['breach', 'rollback', 'error'].includes(prev.step)) continue; // stopped: only the PM moves it again
116
+ if (percent >= 100) continue;
117
+ if (!cfg) {
118
+ if (!prev || prev.step !== 'wait-pm') say({ item: it.item_id, flag: f.name, percent, step: 'wait-pm', why: `No flag provider is set in pmos/factory.json, so PMOS cannot roll ${f.name} out. The change merged with the flag off; turn it on when you choose` });
119
+ continue;
120
+ }
121
+ if (!f.metric || !cfg.metrics[f.metric] || !Number.isFinite(Number(f.budget))) {
122
+ if (!prev || prev.step !== 'wait-pm') say({ item: it.item_id, flag: f.name, percent, step: 'wait-pm', why: `${it.item_id} names no guard metric with a budget that factory.json can read, so PMOS does not roll ${f.name} out by itself. The flag stays off; turn it on when you choose` });
123
+ continue;
124
+ }
125
+ const m = readMetric(cfg, f.metric, env);
126
+ if (!m.ok) { if (!prev || prev.why !== m.err) say({ item: it.item_id, flag: f.name, percent, step: 'hold', why: `the step holds: ${m.err}` }); continue; }
127
+ if (m.value > Number(f.budget)) {
128
+ const s = setFlag(cfg, f.name, 0, env);
129
+ const rv = require('./build-engine.js').revert(root, it.item_id, { env, why: `${f.metric} read ${m.value}, above its budget ${f.budget}` });
130
+ const sd = stateDir(root);
131
+ const sb = sd ? A.recordSetback(sd, { job: JOB, product: null, ref: it.item_id, kind: 'revert' }, { now }) : { demoted: null };
132
+ // the factory's pull requests stop opening by themselves too (they wait for the PM's ✓ again)
133
+ if (sd) A.recordSetback(sd, { job: OPEN_JOB, product: null, ref: it.item_id, kind: 'revert' }, { now });
134
+ say({ item: it.item_id, flag: f.name, percent: s.ok ? 0 : percent, from: percent, step: 'breach', value: m.value, budget: Number(f.budget),
135
+ why: `${f.metric} read ${m.value}, above its budget ${f.budget}. ${s.ok ? `${f.name} is off` : `Turning ${f.name} off FAILED (${s.err}); turn it off now`}. ${rv.ok ? `Revert pull request: ${rv.url || rv.branch}` : `No revert pull request: ${rv.error}`}. ${sb.demoted ? 'The factory is back to propose-only until ' + sb.demoted.until.slice(0, 10) : 'Recorded as a revert'}.`,
136
+ ...(rv.ok && rv.url ? { revert: rv.url } : {}) });
137
+ continue;
138
+ }
139
+ const nextP = STEPS.find((p) => p > percent);
140
+ if (nextP === 100 && it.guard.kr) {
141
+ if (!prev || prev.step !== 'wait-pm') say({ item: it.item_id, flag: f.name, percent, step: 'wait-pm', value: m.value, why: `${it.item_id} moves a key result, so ${f.name} stays at ${percent}% until you take it to 100% (pmos build rollout ${it.item_id} --to 100)` });
142
+ continue;
143
+ }
144
+ if (prev && percent > 0 && now - Date.parse(prev.at) < cfg.hold_minutes * 60000) continue;
145
+ const s = setFlag(cfg, f.name, nextP, env);
146
+ if (!s.ok) { say({ item: it.item_id, flag: f.name, percent, step: 'error', why: `the provider refused ${f.name} at ${nextP}%: ${s.err}. The rollout stops here` }); continue; }
147
+ say({ item: it.item_id, flag: f.name, percent: nextP, from: percent, step: 'set', value: m.value, budget: Number(f.budget), by: 'pmos', why: `${f.metric} read ${m.value} (budget ${f.budget}); ${f.name} ${percent}% → ${nextP}%` });
148
+ }
149
+ return { acted };
150
+ }
151
+
152
+ function itemFlag(root, item) {
153
+ const it = require('./build-engine.js').itemsOf(root).find((x) => x.item_id === item);
154
+ if (!it) return { error: `${item} is not a work item here` };
155
+ if (!it.guard || !it.guard.flag || !it.guard.flag.name) return { error: `${item} declares no flag` };
156
+ return { it, flag: it.guard.flag.name };
157
+ }
158
+
159
+ function rollout(root, item, { to = null, now = Date.now(), env = process.env, by = 'pm' } = {}) {
160
+ const f = itemFlag(root, item);
161
+ if (f.error) return { ok: false, error: f.error };
162
+ const cfg = configOf(root);
163
+ if (!cfg) return { ok: false, error: 'no flag provider is set in pmos/factory.json; turn the flag on in your flag service' };
164
+ const prev = lastOf(root).get(item);
165
+ const percent = prev ? Number(prev.percent) || 0 : 0;
166
+ const target = to == null ? STEPS.find((p) => p > percent) : Number(to);
167
+ if (!Number.isInteger(target) || target < 0 || target > 100) return { ok: false, error: 'the percent is a whole number from 0 to 100' };
168
+ const s = setFlag(cfg, f.flag, target, env);
169
+ if (!s.ok) return { ok: false, error: `the provider refused: ${s.err}` };
170
+ log(root, { item, flag: f.flag, percent: target, from: percent, step: 'set', by, why: `${f.flag} ${percent}% → ${target}% by ${by}` }, now);
171
+ return { ok: true, item, flag: f.flag, percent: target };
172
+ }
173
+
174
+ function rollback(root, item, { now = Date.now(), env = process.env, by = 'pm' } = {}) {
175
+ const f = itemFlag(root, item);
176
+ if (f.error) return { ok: false, error: f.error };
177
+ const cfg = configOf(root);
178
+ if (!cfg) return { ok: false, error: 'no flag provider is set in pmos/factory.json; turn the flag off in your flag service' };
179
+ const prev = lastOf(root).get(item);
180
+ const s = setFlag(cfg, f.flag, 0, env);
181
+ if (!s.ok) return { ok: false, error: `the provider refused: ${s.err}` };
182
+ log(root, { item, flag: f.flag, percent: 0, from: prev ? Number(prev.percent) || 0 : 0, step: 'rollback', by, why: `${f.flag} rolled back to 0% by ${by}; the rollout stops until you run pmos build rollout ${item}` }, now);
183
+ return { ok: true, item, flag: f.flag, percent: 0 };
184
+ }
185
+
186
+ function statusOf(root) {
187
+ return [...lastOf(root).values()].map((l) => ({ item: l.item, flag: l.flag, percent: Number(l.percent) || 0, step: l.step, at: l.at, why: l.why }));
188
+ }
189
+
190
+ module.exports = { STEPS, JOB, LEDGER, configOf, tick, rollout, rollback, statusOf };
@@ -35,7 +35,7 @@ const VERBS = Object.freeze({
35
35
  help: 'pmos verify-work — mark work items integrated from the default branch (local refs only)' }),
36
36
  // Not a pm-os-absorb verb (run: null): launch simulation W7 (kit-factory-builder) added it through the same table.
37
37
  build: Object.freeze({ module: 'build-cli.js', run: null, guide: 'cli.md',
38
- help: 'pmos build next|claim|propose|open|status — the Builder: a declared work item becomes a draft pull request you merge (pmos build help)' }),
38
+ help: 'pmos build next|claim|propose|open|status|policy|rollout|rollback — the Builder: a declared work item becomes a pull request; the product\'s guardrail decides who merges (pmos build help)' }),
39
39
  report: Object.freeze({ module: 'report-cli.js', run: 5, guide: 'cli.md',
40
40
  help: 'pmos report draft|issue|list … — draft and issue reports (pmos report help)' }),
41
41
  // Not a pm-os-absorb verb (run: null): initiative jira-wbs added it through the same table.
@@ -118,7 +118,7 @@ function undoCore(ctx, p, g, id) {
118
118
  else if (w.op === 'life') { const r2 = require('./outcomes.js').setLife(p.w.root, k.ini, w.from === 'cancelled' ? 'cancelled' : 'active', 'Undo: PMOS ✦ stopped it', g.actor); if (r2.ok) back++; else kept++; continue; }
119
119
  // a new experiment the ✦ made goes from every list (the Board's own Delete: the record file stays, a restore brings it back)
120
120
  else if (w.op === 'created') { r = RB.writeAs(ctx, '/api/boards/ini-delete', { ws: p.w.id, board: p.board.id, id: w.id }, g); }
121
- else if (w.op === 'pr') { kept++; continue; } // a pull request others can see stays: close it on the Git host if it should not land (W7)
121
+ else if (w.op === 'pr') { const r2 = require('./build-engine.js').close(p.w.root, w.item, { url: w.url }); if (r2.ok) back++; else kept++; continue; } // D108: Undo closes the pull request (the branch stays)
122
122
  else if (w.op === 'outcome') { const r2 = require('./initiative-writer.js').restoreOutcome(p.w.root, k.ini, w.from || {}, w.to || {}, { actor: g.actor }); if (r2.ok && !r2.kept) back++; else kept++; continue; } // a record edited since keeps its edit
123
123
  if (r && r.body && r.body.ok) back++; else kept++;
124
124
  }
@@ -77,7 +77,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
77
77
  say(` owns: ${r.what}`);
78
78
  if (r.owns.paths.length || r.owns.verbs.length) say(` writes only: ${[...r.owns.paths, ...r.owns.verbs].join(', ')}`);
79
79
  say(` wakes on: ${r.triggers.map((x) => (x.on === 'stage' ? `stage ${x.stage}${x.unless ? ' without ' + x.unless : ''}` : x.on === 'written' ? 'a write by another role' : 'a dispatch')).join(', ')}`);
80
- if (r.key === 'build') say(` here: ${factory ? 'the factory runs in this repository. The Builder files draft pull requests for your ✓ (pmos build); you merge.' : 'no factory runs in this repository, so the Builder does not run. The team\'s agents build from the done test and the pull request plan PMOS writes.'}`);
80
+ if (r.key === 'build') say(` here: ${factory ? 'the factory runs in this repository. The Builder\'s pull requests open by themselves (pmos build); the product\'s guardrail decides who merges.' : 'no factory runs in this repository, so the Builder does not run. The team\'s agents build from the done test and the pull request plan PMOS writes.'}`);
81
81
  }
82
82
  return 0;
83
83
  }
@@ -231,6 +231,48 @@ function layout(root) {
231
231
  };
232
232
  }
233
233
 
234
+ // ── A Project's dated plan in the task store (launch simulation W6 follow-up) ─────────────────────
235
+ // `pmos task add/link/set --milestone` writes a Project's plan as task lines in <runsDir>/initiative-tasks.jsonl (lib/task-store.js; lines
236
+ // not yet moved there still sit in boards.jsonl). Dated tasks with at least one dated ◇ milestone ARE the dated plan, so plan_path is not
237
+ // needed: the gate (kit/scripts/gate-initiative.sh, through --task-plan) and both ladders read them here. The fold is the task part of
238
+ // scripts/boards.js fold: the first task line makes the task, task-update moves or re-dates it, task-remove and task-restore take it out and
239
+ // back, and the last task-milestone line wins. → { ok, dated, milestones, file, evidence }
240
+ const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
241
+ function taskPlanOf(root, id) {
242
+ const L = layout(root);
243
+ const files = ['boards.jsonl', 'initiative-tasks.jsonl'].map((f) => path.join(L.runsDir, f));
244
+ const tasks = new Map(); const removed = new Map(); const milestones = new Map();
245
+ for (const file of files) {
246
+ let text = '';
247
+ try { text = fs.readFileSync(file, 'utf8'); } catch { continue; }
248
+ for (const raw of text.split('\n')) {
249
+ const t = raw.trim();
250
+ if (!t || t[0] !== '{' || !t.includes('"task')) continue;
251
+ let e; try { e = JSON.parse(t); } catch { continue; }
252
+ if (!e || typeof e.task !== 'string' || !e.task) continue;
253
+ if (e.kind === 'task' && typeof e.initiative === 'string' && !tasks.has(e.task) && !removed.has(e.task)) {
254
+ tasks.set(e.task, { initiative: e.initiative, due: typeof e.due === 'string' ? e.due : '' });
255
+ } else if (e.kind === 'task-update' && tasks.has(e.task)) {
256
+ const x = tasks.get(e.task);
257
+ if (typeof e.initiative === 'string' && e.initiative) x.initiative = e.initiative;
258
+ if (typeof e.due === 'string') x.due = e.due;
259
+ } else if (e.kind === 'task-milestone' && typeof e.milestone === 'boolean') milestones.set(e.task, e.milestone);
260
+ else if (e.kind === 'task-remove' && tasks.has(e.task)) { removed.set(e.task, tasks.get(e.task)); tasks.delete(e.task); }
261
+ else if (e.kind === 'task-restore' && removed.has(e.task) && !tasks.has(e.task)) { tasks.set(e.task, removed.get(e.task)); removed.delete(e.task); }
262
+ }
263
+ }
264
+ let dated = 0; let ms = 0;
265
+ for (const [tid, x] of tasks) {
266
+ if (x.initiative !== id || !DAY_RE.test(x.due)) continue;
267
+ dated++;
268
+ if (milestones.get(tid) === true) ms++;
269
+ }
270
+ const file = path.relative(root, path.join(L.runsDir, 'initiative-tasks.jsonl')).split(path.sep).join('/');
271
+ const ok = ms > 0;
272
+ const evidence = `${dated} dated task${dated === 1 ? '' : 's'}, ${ms} dated milestone${ms === 1 ? '' : 's'} in ${file}`;
273
+ return { ok, dated, milestones: ms, file, evidence };
274
+ }
275
+
234
276
  // ── Git ────────────────────────────────────────────────────────────────────────────────────────
235
277
  function git(root, args) {
236
278
  try {
@@ -973,9 +1015,12 @@ function computeWorkflowDerived(id, opts) {
973
1015
  `write the done test (okf/core/templates/done-test-template.md), set done_test_path and kill: in ${recRel}`, { blocking: true, rule: 'R2' }));
974
1016
  } else if (!doneTest && workKind === 'project' && (planPath || !prd)) {
975
1017
  const planIdx = planPath ? firstAppearance(root, range, planPath) : null;
976
- if (!planPath) {
1018
+ const taskPlan = planPath ? null : taskPlanOf(root, id);
1019
+ if (taskPlan && taskPlan.ok) {
1020
+ steps.push(step('spec', 'spec', 'done', `dated plan in the task store: ${taskPlan.evidence}`));
1021
+ } else if (!planPath) {
977
1022
  steps.push(step('spec', 'spec', 'blocked', 'Project needs a dated plan before Execute — never a PRD',
978
- `write the plan (milestones with dates and owners, go-live matching the KR date) and set plan_path in ${recRel}, or a done test`, { blocking: true, rule: 'R2' }));
1023
+ `write the plan (milestones with dates and owners, go-live matching the KR date) and set plan_path in ${recRel}, or add dated tasks with a ◇ milestone (pmos task add --due … / pmos task set --milestone), or a done test`, { blocking: true, rule: 'R2' }));
979
1024
  } else if (planIdx === null) {
980
1025
  steps.push(step('spec', 'spec', 'blocked', `plan_path '${planPath}' does not exist in the repo`,
981
1026
  'create the plan the record points at, or correct plan_path', { blocking: true, rule: 'R2' }));
@@ -1605,14 +1650,16 @@ function pmLadder({ id, fm, lane, effLane, knownLane, legacy, steps, root, L, re
1605
1650
  const workKind = (() => { const k = String(fm.kind || '').trim().replace(/^["']|["']$/g, ''); return k === 'sdlc' || k === 'project' ? k : 'product'; })();
1606
1651
  const planPath = String(fm.plan_path || '').trim();
1607
1652
  const kindSpec = !doneTest && !exists(briefPath) && !foundBrief && (workKind === 'sdlc' || (workKind === 'project'));
1653
+ const tasksPlan = kindSpec && workKind === 'project' && !planPath ? taskPlanOf(root, id) : null;
1608
1654
  if (doneTest && dtPresent && killCond) steps.push(step('brief', def.brief_label, 'done', `done test ${doneTest} + kill condition (D107)`));
1609
1655
  else if (kindSpec && workKind === 'sdlc') steps.push(step('brief', 'done test', legacy ? 'pending' : 'blocked',
1610
1656
  'Full SDLC needs a done test and a kill condition before the first pull request — never a brief or a PRD',
1611
1657
  `write the done test, set done_test_path and kill: in ${recRel} (pmos artefacts set experiment:${id} done-test check --text "…" writes both)`, { blocking: !legacy, rule: 'R2' }));
1612
1658
  else if (kindSpec && exists(planPath)) steps.push(step('brief', 'dated plan', 'done', `plan ${planPath} present`));
1659
+ else if (kindSpec && !planPath && tasksPlan && tasksPlan.ok) steps.push(step('brief', 'dated plan', 'done', `dated plan in the task store: ${tasksPlan.evidence}`));
1613
1660
  else if (kindSpec) steps.push(step('brief', 'dated plan', legacy ? 'pending' : 'blocked',
1614
1661
  planPath ? `plan_path '${planPath}' does not exist in the repo` : 'Project needs a dated plan before Execute — never a brief or a PRD',
1615
- planPath ? 'create the plan the record points at, or correct plan_path' : `write the plan (milestones with dates and owners, go-live matching the KR date) and set plan_path in ${recRel}, or a done test`,
1662
+ planPath ? 'create the plan the record points at, or correct plan_path' : `write the plan (milestones with dates and owners, go-live matching the KR date) and set plan_path in ${recRel}, or add dated tasks with a ◇ milestone (pmos task add --due … / pmos task set --milestone), or a done test`,
1616
1663
  { blocking: !legacy, rule: 'R2' }));
1617
1664
  else if (doneTest && dtPresent) steps.push(step('brief', def.brief_label, 'blocked', 'no kill condition — an experiment states what would stop it (D107)',
1618
1665
  `write kill: "<the result that would make us stop>" in ${recRel}`, { blocking: !legacy, rule: 'R2' }));
@@ -1896,7 +1943,7 @@ function listInitiatives(root) {
1896
1943
  // ── CLI ────────────────────────────────────────────────────────────────────────────────────────
1897
1944
  function main(argv) {
1898
1945
  const args = argv.slice(2);
1899
- let root = process.cwd(); let json = false; let gate = false; let all = false; let lanes = false;
1946
+ let root = process.cwd(); let json = false; let gate = false; let all = false; let lanes = false; let taskPlan = null;
1900
1947
  const rest = [];
1901
1948
  for (let i = 0; i < args.length; i++) {
1902
1949
  const a = args[i];
@@ -1905,6 +1952,7 @@ function main(argv) {
1905
1952
  if (a === '--gate') { gate = true; continue; }
1906
1953
  if (a === '--all') { all = true; continue; }
1907
1954
  if (a === '--lanes') { lanes = true; continue; }
1955
+ if (a === '--task-plan') { taskPlan = args[++i] || ''; continue; }
1908
1956
  if (a === '--open') { continue; } // the board is in-flight-only by default now
1909
1957
  if (a === '--help' || a === '-h') {
1910
1958
  process.stdout.write([
@@ -1914,12 +1962,19 @@ function main(argv) {
1914
1962
  ' --gate <id> CI mode — exit 1 on a blocking order violation, with the next action',
1915
1963
  ' --all the board without the 12-row cap',
1916
1964
  ' --lanes every lane this repository offers: when to use it, input, output, done',
1965
+ ' --task-plan <id> exit 0 when the task store holds a Project\'s dated plan (dated tasks with a ◇ milestone)',
1917
1966
  ' --json machine-readable (what an agent reads at session start)', '',
1918
1967
  ].join('\n') + '\n');
1919
1968
  return 0;
1920
1969
  }
1921
1970
  rest.push(a);
1922
1971
  }
1972
+ if (taskPlan !== null) {
1973
+ if (!/^[a-z0-9][a-z0-9._-]*$/.test(taskPlan)) { process.stdout.write('--task-plan needs an initiative id\n'); return 2; }
1974
+ const tp = taskPlanOf(root, taskPlan);
1975
+ process.stdout.write(json ? JSON.stringify(tp) + '\n' : tp.evidence + '\n');
1976
+ return tp.ok ? 0 : 1;
1977
+ }
1923
1978
  if (lanes) {
1924
1979
  const info = lanesFor(root);
1925
1980
  if (json) { process.stdout.write(JSON.stringify(info, null, 2) + '\n'); return 0; }
@@ -1987,7 +2042,7 @@ function main(argv) {
1987
2042
  }
1988
2043
 
1989
2044
  module.exports = {
1990
- computeWorkflow, declaredLane: laneDefs.declaredLane, readLifecycle, STOPPED_STATES, renderLadder, renderBoard, listInitiatives, layout, inFlight, BOARD_CAP,
2045
+ computeWorkflow, taskPlanOf, declaredLane: laneDefs.declaredLane, readLifecycle, STOPPED_STATES, renderLadder, renderBoard, listInitiatives, layout, inFlight, BOARD_CAP,
1991
2046
  parseLeadingFrontmatter, specimenRoute, surfaceRoute, priorsCitation, isBuildPath, commitRange,
1992
2047
  // the board's trunk range, exported so the suite can assert the split: the same record is legacy
1993
2048
  // under BOTH ranges, and `in this change` is false under the trunk one.
@@ -170,9 +170,25 @@ function create(deps) {
170
170
  return null;
171
171
  }
172
172
 
173
+ /* D108: in a product repository that carries the kit's factory, mark merged work items integrated, then move each flag one rollout
174
+ * step (lib/factory-rollout.js; no model, the PM's own provider commands). PMOS-self's checkout runs verify-work below. */
175
+ function factory(now) {
176
+ const out = [];
177
+ if (deps.factory === false) return out;
178
+ const WK = require('./work-kind.js');
179
+ for (const w of (deps.roots && deps.roots()) || []) {
180
+ const fdir = w && w.root ? WK.factoryDir(w.root) : null;
181
+ if (!fdir) continue;
182
+ if (!isCheckout(w.root)) { try { run(fdir, ['scripts/verify-work.js', '--json']); } catch (e) { warn('verify-work', e); } }
183
+ try { out.push(...require('./factory-rollout.js').tick(w.root, { now, env: deps.env || process.env }).acted); } catch (e) { warn('rollout', e); }
184
+ }
185
+ return out;
186
+ }
187
+
173
188
  function tick({ now = Date.now() } = {}) {
174
189
  if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { off: true };
175
- if (active) return { running: active.run_id };
190
+ const rolled = factory(now);
191
+ if (active) return { running: active.run_id, ...(rolled.length ? { rolled } : {}) };
176
192
  let open = true;
177
193
  try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
178
194
  if (!open) return { started: null, closed: true };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.570.0",
3
+ "version": "0.572.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.570.0",
9
+ "version": "0.572.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.570.0",
3
+ "version": "0.572.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",
@@ -121,7 +121,7 @@ function itemHtml(p, x) {
121
121
  else if (p.group === 'status') { t = x.title || taskTitle(p.ini, x.task); m = x.jira ? 'Jira: a drafted comment' : ''; }
122
122
  else if (p.group === 'outcome') { t = x.title; m = x.due ? 'Check on ' + md(x.due) : ''; }
123
123
  else if (p.group === 'description') { t = (p.data && p.data.text) || x.title; m = p.type === 'enrich' && p.data && p.data.from ? 'Now: ' + clip(p.data.from, 120) : ''; }
124
- else if (p.group === 'build') { const d = p.data || {}; t = x.title; m = [d.branch ? d.branch + ' → ' + (d.base || 'main') : '', d.files && d.files.length ? (d.files.length === 1 ? '1 file' : d.files.length + ' files') : '', 'a draft you merge'].filter(Boolean).join(' · '); }
124
+ else if (p.group === 'build') { const d = p.data || {}; t = x.title; m = [d.branch ? d.branch + ' → ' + (d.base || 'main') : '', d.files && d.files.length ? (d.files.length === 1 ? '1 file' : d.files.length + ' files') : '', 'the guardrail decides who merges'].filter(Boolean).join(' · '); }
125
125
  else if (p.group === 'names') { t = x.to; m = 'Was: ' + (x.from || '') + (x.jira ? ' · Jira: a drafted comment' : ''); }
126
126
  return `<div class="pp-it"><span class="w"><b>${esc(clip(t, p.group === 'description' ? 700 : 90))}</b>${m ? `<small>${esc(m)}</small>` : ''}</span>${x.sig ? ib(`data-pp-dropit="${esc(x.sig)}"`, 'Leave this one out', I.x) : ''}</div>`;
127
127
  }
@@ -1,9 +1,11 @@
1
1
  {
2
- "_comment": "Launch simulation W7 (kit-factory-builder): the D65 factory in a product repository. One sandbox run against a kit built by kit/build-kit.sh and a local bare remote: vendoring (F1), the kit (F2), the Builder's claim, propose, ✦ and draft PR (F3), verify-work (F4). No browser, no network.",
2
+ "_comment": "Launch simulation W7 (kit-factory-builder): the D65 factory in a product repository. One sandbox run against a kit built by kit/build-kit.sh and a local bare remote: vendoring (F1), the kit (F2), the Builder's claim, propose, \u2726 and draft PR (F3), verify-work (F4). No browser, no network. D108 (factory-guardrail-merge): the merge guardrail, one case per rule (factory-guardrail.test.js), and G1\u2013G6 in the same sandbox.",
3
3
  "modules": [
4
- "build-engine.test.js"
4
+ "build-engine.test.js",
5
+ "factory-guardrail.test.js"
5
6
  ],
6
7
  "seconds": {
7
- "build-engine.test.js": 4
8
+ "build-engine.test.js": 8,
9
+ "factory-guardrail.test.js": 3
8
10
  }
9
11
  }