create-pmos 0.752.0 → 0.753.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.752.0",
3
+ "version": "0.753.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -33,6 +33,19 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.753.0",
38
+ "at": "2026-11-24T00:26:15.065Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1702,
43
+ "t": "Program line, Charter to Land over pmos line",
44
+ "s": "Program line, Charter to Land over pmos line",
45
+ "k": "new"
46
+ }
47
+ ]
48
+ },
36
49
  {
37
50
  "v": "0.752.0",
38
51
  "at": "2026-11-24T00:12:53.761Z",
@@ -584,50 +597,6 @@
584
597
  }
585
598
  }
586
599
  ]
587
- },
588
- {
589
- "v": "0.730.0",
590
- "at": "2026-11-23T05:37:33.548Z",
591
- "f": 4,
592
- "prs": [
593
- {
594
- "n": 1625,
595
- "t": "A short cue when an item is done, moved or dropped (A313)",
596
- "s": "A short cue when an item is done, moved or dropped (A313)",
597
- "k": "new",
598
- "try": {
599
- "steps": [
600
- "Mark a task done, or move it, on Today or Work."
601
- ],
602
- "see": "A short cue on the row, even with reduced motion on.",
603
- "open": "/premium-board.html"
604
- }
605
- },
606
- {
607
- "n": 1623,
608
- "t": "Write the done test's acceptance criteria onto Jira tickets (A384)",
609
- "s": "Write the done test's acceptance criteria onto Jira tickets (A384)",
610
- "k": "new",
611
- "try": {
612
- "steps": [
613
- "Open an initiative's Work breakdown that tracks open Jira tickets."
614
- ],
615
- "see": "A ✦ with criteria per ticket. Your ✓ writes them onto your own tickets; others' go to a draft."
616
- }
617
- },
618
- {
619
- "n": 1626,
620
- "t": "Kind as scope, part 2: the chat can change kinds, and a project's Build follows its milestones",
621
- "s": "Kind as scope, part 2: the chat can change kinds, and a project's Build follows its milestones",
622
- "k": "new",
623
- "try": {
624
- "steps": [
625
- "In an initiative's chat, ask: make this a project."
626
- ],
627
- "see": "The kind changes; a project's Build stage follows its milestone dates."
628
- }
629
- }
630
- ]
631
600
  }
632
601
  ]
633
602
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@9d5ad11f
1
+ kernel-source: pmos@cb307f57
2
2
  assembled: 2026-11-24
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-24T00:12:50Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-24T00:26:11Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-24T00:12:50Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-24T00:26:11Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-24T00:12:50Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-24T00:26:11Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,17 @@
1
1
  [
2
+ {
3
+ "v": "0.753.0",
4
+ "at": "2026-11-24T00:26:15.065Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1702,
9
+ "t": "Program line, Charter to Land over pmos line",
10
+ "s": "Program line, Charter to Land over pmos line",
11
+ "k": "new"
12
+ }
13
+ ]
14
+ },
2
15
  {
3
16
  "v": "0.752.0",
4
17
  "at": "2026-11-24T00:12:53.761Z",
@@ -600,7 +600,23 @@ pmos signal count [<checkout>]
600
600
 
601
601
  `pmos program suggest` is the only write of the milestone review run. It files a suggestion for you to keep, change or drop.
602
602
 
603
- `pmos program charter <id> --goal "<text>"` or `--why "<text>"` saves the Goal or For line of a program's card, after you say yes in the chat. It writes one charter line and keeps every other key. Run it in the repository where the program was made. It prints the command that undoes it.
603
+ `pmos program charter <id> --goal "<text>"`, `--why "<text>"`, `--target YYYY-MM-DD` or `--owner "<name>"` saves that line of a program's card, after you say yes in the chat. It writes one charter line and keeps every other key. Run it in the repository where the program was made. It prints the command that undoes it.
604
+
605
+ The program line moves a program through four stations. Each station has an exit test that PMOS reads from records:
606
+
607
+ 1. **Charter.** The goal, target date and owner are set. PMOS drafts the missing ones from the initiatives in the program.
608
+ 2. **Sequence.** Every initiative has a place in the order, and every milestone has a date. PMOS proposes the order (an initiative's `predecessor:` first, then the earlier plan end) and drafts milestones from the initiatives' dates. It holds an initiative before Implementation when its team already builds as many as it can at once.
609
+ 3. **Track.** The forecast is inside the target date, or you recorded a decision for this forecast. PMOS names the initiative that slips and the milestones that move.
610
+ 4. **Land.** Every initiative passed Implementation (Build on Product feature), and the outcome is read against the goal.
611
+
612
+ An initiative with no plan end is "can't tell". PMOS never guesses its date.
613
+
614
+ - `pmos program line [<id>]` shows each open program: its station, what is missing, the next move and the forecast against the target. A program across several products gets one forecast from all of them. When two products need one team in Build and the team has no free place, PMOS shows one decision row with a recommendation: the initiative whose program has the earlier target goes first. It reads every product on this computer and writes nothing. Add `--json` for the whole answer.
615
+ - `pmos program draft <id>` files PMOS's milestone drafts as suggestions. The program shows them with Keep and Decline. Nothing changes until you keep one.
616
+ - `pmos program order <id> [<id>,<id>,…]` saves the order of the program's initiatives. With no list, it saves the order PMOS proposes. `--clear` goes back to A to Z. It prints the command that undoes it.
617
+ - `pmos program capacity <team> <n>` sets how many initiatives a team builds at once. The default is 2. An initiative's team is its record's `team:` line, else its product. It prints the command that undoes it.
618
+ - `pmos program decide <id> --keep-target` records that you keep the target date against the forecast. A new slip asks again. `pmos program decide --team <team> --first <initiative>` records which initiative a shared team builds first.
619
+ - `pmos program outcome <id> "<text>"` records the outcome read, the last exit of Land.
604
620
 
605
621
  ### pmos driver: the Initiative Driver
606
622
 
@@ -92,7 +92,7 @@ const VERBS = Object.freeze({
92
92
  blueprint: Object.freeze({ module: 'blueprint-cli.js', run: null, guide: 'cli.md',
93
93
  help: 'pmos blueprint [list|show|unplaced|check] — every feature of the product with a status worked out from its evidence (pmos blueprint help)' }),
94
94
  program: Object.freeze({ module: 'program-cli.js', run: null, guide: 'cli.md',
95
- help: 'pmos program suggest — Claude\'s milestone suggestions for a program, filed by its review run (pmos program help)' }),
95
+ help: 'pmos program line|draft|order|capacity|decide|outcome|charter|suggest — the program line (Charter, Sequence, Track, Land) and the milestone suggestions for a program (pmos program help)' }),
96
96
  // Not a pm-os-absorb verb (run: null): c3-meet-extension added it through the same table.
97
97
  extension: Object.freeze({ module: 'extension-cli.js', run: null, guide: 'cli.md',
98
98
  help: 'pmos extension — the folder of the Chrome extension for Google Meet, and the three steps to load it' }),
@@ -15,7 +15,7 @@ const fs = require('fs');
15
15
  const pmItems = require('./pm-items.js');
16
16
  const MS = require('./milestone-suggest.js');
17
17
 
18
- const COMMANDS = { program: ['suggest', 'charter'] };
18
+ const COMMANDS = { program: ['suggest', 'charter', 'line', 'draft', 'order', 'capacity', 'decide', 'outcome'] };
19
19
  const USAGE = [
20
20
  'usage: pmos program suggest — PMOS\'s milestone suggestions for a program',
21
21
  ' pmos program suggest --json <file|->',
@@ -23,8 +23,22 @@ const USAGE = [
23
23
  ' { "op": "add|move|rename|drop|risk", "milestone": "<id, not for add>", "name": "<add, rename>", "date": "YYYY-MM-DD (add, move)",',
24
24
  ' "waits": ["<initiative id>", … (add)], "why": "<one line>", "src": { "kind": "deliver|jira|meeting|task|target|member|charter", "label": "Steering, Oct 22" } }',
25
25
  ' It answers filed, duplicate or declined for each. The PM keeps, changes or drops it on the page. Nothing is sent.',
26
- ' pmos program charter <id> [--goal "<text>"] [--why "<text>"]',
27
- ' The program card\'s Goal and For lines, after the PM said yes in the chat. Run it in the repository where the program was made.',
26
+ ' pmos program charter <id> [--goal "<text>"] [--why "<text>"] [--target YYYY-MM-DD] [--owner "<name>"]',
27
+ ' The program card\'s Goal, For, target date and owner, after the user said yes in the chat. Run it in the repository where the program was made.',
28
+ ' pmos program line [<id>] [--json] [--root <dir>]',
29
+ ' Where each program stands: Charter, Sequence, Track or Land, what is missing, the next move, the forecast against the target,',
30
+ ' and one decision row for each team two products need in Build beyond its capacity. Reads every product on this computer, or only',
31
+ ' the --root folders given. Writes nothing.',
32
+ ' pmos program draft <id>',
33
+ ' File PMOS\'s milestone drafts (from the initiatives\' dates) as suggestions the program shows with Keep and Decline.',
34
+ ' pmos program order <id> [<id>,<id>,… | --clear]',
35
+ ' Save the order of the program\'s initiatives; with no list, the order PMOS proposes. Prints the Undo.',
36
+ ' pmos program capacity <team> <n>',
37
+ ' How many initiatives a team builds at once (default 2). The program line holds the rest before Implementation. Prints the Undo.',
38
+ ' pmos program decide <id> --keep-target | pmos program decide --team <team> --first <initiative>',
39
+ ' Record the user\'s decision on a forecast past the target, or which initiative a shared team builds first.',
40
+ ' pmos program outcome <id> "<what the outcome read says>"',
41
+ ' Record the outcome read against the program\'s goal (the last exit of Land).',
28
42
  ];
29
43
  const MAX_PER_RUN = 8;
30
44
 
@@ -34,6 +48,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
34
48
  if (!verb || verb === 'help' || verb === '--help' || verb === '-h') { for (const l of USAGE) say(l); return verb ? 0 : 1; }
35
49
  if (!COMMANDS.program.includes(verb)) { say(`unknown program command "${verb}" — one of ${COMMANDS.program.join(', ')}`); return 2; }
36
50
  if (verb === 'charter') return charter(args.slice(1), { say, cwd: process.cwd() });
51
+ if (LINE_VERBS.includes(verb)) return lineVerb(verb, args.slice(1), { say, cwd: process.cwd(), env });
37
52
  const i = args.indexOf('--json'), src = i >= 0 ? args[i + 1] : null;
38
53
  if (!src) { say('usage: pmos program suggest --json <file|->'); return 2; }
39
54
  const file = env.PMOS_MS_REVIEW_FILE, runId = env.PMOS_MS_REVIEW_RUN, program = env.PMOS_MS_REVIEW_PROGRAM;
@@ -66,9 +81,10 @@ function charter(args, { say, cwd }) {
66
81
  const path = require('path');
67
82
  const P = require('./programs.js');
68
83
  const pos = [], flags = {};
69
- for (let k = 0; k < args.length; k++) { const a = args[k]; if (/^--(goal|why|root)$/.test(a)) flags[a.slice(2)] = args[++k]; else if (a.startsWith('--')) { say(`✗ unknown flag ${a}`); return 2; } else pos.push(a); }
84
+ for (let k = 0; k < args.length; k++) { const a = args[k]; if (/^--(goal|why|root|target|owner)$/.test(a)) flags[a.slice(2)] = args[++k]; else if (a.startsWith('--')) { say(`✗ unknown flag ${a}`); return 2; } else pos.push(a); }
70
85
  const id = pos[0];
71
- if (!id || (flags.goal === undefined && flags.why === undefined)) { say(USAGE[USAGE.length - 2]); return 2; }
86
+ const keys = ['goal', 'why', 'target', 'owner'].filter((k) => flags[k] !== undefined);
87
+ if (!id || !keys.length) { say(USAGE.find((l) => l.includes('pmos program charter'))); return 2; }
72
88
  if (!P.ID_RE.test(id)) { say('✗ the program id is lower-case letters, numbers and dashes'); return 2; }
73
89
  const root = path.resolve(cwd, flags.root || '.');
74
90
  const files = [['pmos', 'state'], ['state'], ['.pmos'], ['planning', 'runs']].map((r) => path.join(root, ...r, 'programs.jsonl')).filter((f) => fs.existsSync(f));
@@ -76,15 +92,154 @@ function charter(args, { say, cwd }) {
76
92
  for (const f of files) { const p = P.fold(pmItems.readLines(f).filter(Boolean))[id]; if (p && p.charter) { file = f; prog = p; break; } }
77
93
  if (!prog) { say(`✗ no charter of ${id} in this repository. Run it in the product where the program was made`); return 1; }
78
94
  const next = { ...prog, id };
79
- if (flags.goal !== undefined) next.goal = String(flags.goal || '');
80
- if (flags.why !== undefined) next.why = String(flags.why || '');
95
+ for (const k of keys) next[k] = String(flags[k] || '');
81
96
  const v = P.validProgram(next);
82
97
  if (v.error) { say('✗ ' + v.error); return 1; }
83
98
  if (flags.goal !== undefined && String(flags.goal).trim().length > 160) say(' ! the goal was cut to 160 characters');
84
99
  pmItems.appendEvent(file, { ...v, from: prog.from || undefined });
85
- const undo = ['pmos program charter', id].concat(flags.goal !== undefined ? ['--goal', JSON.stringify(prog.goal || '')] : [], flags.why !== undefined ? ['--why', JSON.stringify(prog.why || '')] : []).join(' ');
86
- say(`✓ ${id}: ${[flags.goal !== undefined ? 'goal' : '', flags.why !== undefined ? 'why' : ''].filter(Boolean).join(' and ')} saved to ${path.relative(root, file)}. The program card shows it. Undo: ${undo}`);
100
+ const undo = ['pmos program charter', id].concat(...keys.map((k) => ['--' + k, JSON.stringify(prog[k] || '')])).join(' ');
101
+ say(`✓ ${id}: ${keys.map((k) => (k === 'target' ? 'target date' : k)).join(' and ')} saved to ${path.relative(root, file)}. The program card shows it. Undo: ${undo}`);
87
102
  return 0;
88
103
  }
89
104
 
90
- module.exports = { run, COMMANDS, USAGE, charter };
105
+ const LINE_VERBS = ['line', 'draft', 'order', 'capacity', 'decide', 'outcome'];
106
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
107
+ const short = (d) => (d ? MON[+d.slice(5, 7) - 1] + ' ' + (+d.slice(8, 10)) + ' ' + d.slice(0, 4) : '');
108
+
109
+ /** The program line verbs (lib/program-line.js). `line` reads; the rest write one line each, to the file that holds what they change:
110
+ * draft → the charter workspace's milestone-reviews.jsonl (suggestions the program page shows with Keep and Decline);
111
+ * order, decide <id>, outcome → the charter workspace's programs.jsonl; capacity and decide --team → this repository's programs.jsonl
112
+ * (a team spans products: extrasOf reads the lines of every product). Exit 0 done, 1 refused, 2 usage. */
113
+ function lineVerb(verb, args, { say, cwd, env, now = Date.now(), read: readFn } = {}) {
114
+ const path = require('path');
115
+ const PL = require('./program-line.js');
116
+ const driver = require('./driver.js');
117
+ const pos = [], flags = {};
118
+ for (let k = 0; k < args.length; k++) {
119
+ const a = args[k];
120
+ if (a === '--json' || a === '--keep-target' || a === '--clear') flags[a.slice(2)] = true;
121
+ else if (/^--(root|team|first)$/.test(a)) { const v = args[++k]; if (a === '--root') (flags.root = flags.root || []).push(v); else flags[a.slice(2)] = v; }
122
+ else if (a.startsWith('--')) { say(`✗ unknown flag ${a}`); return 2; }
123
+ else pos.push(a);
124
+ }
125
+ const here = (flags.root && flags.root[0]) ? path.resolve(cwd, flags.root[0]) : gitTop(cwd);
126
+ const roots = flags.root ? PL.rootsOf(flags.root.map((r) => path.resolve(cwd, r)), env, false) : PL.rootsOf([here], env, true);
127
+ const R = () => (readFn || PL.read)(roots, { now, only: verb === 'line' ? pos[0] || null : null, env });
128
+ const rootOfWs = (r, ws) => (r.products.find((x) => x.ws === ws) || {}).root || null;
129
+ const progFile = (root) => { const d = driver.stateDirOf(root); return d ? path.join(d, 'programs.jsonl') : null; };
130
+
131
+ if (verb === 'line') {
132
+ const r = R();
133
+ if (flags.json) { say(JSON.stringify({ ok: true, ...r })); return 0; }
134
+ if (!r.programs.length) { say(pos[0] ? `No open program ${pos[0]} in the products this computer has.` : 'No open program in the products this computer has.'); return 0; }
135
+ for (const L of r.programs) {
136
+ const where = L.station ? `${L.station.name} (${L.station.n} of ${L.station.of})` : 'Landed';
137
+ const fc = L.forecast.state === 'past' ? `forecast ${short(L.forecast.date)}, past the target ${short(L.target)}` : L.forecast.state === 'inside' ? `forecast ${short(L.forecast.date)}, inside the target ${short(L.target)}`
138
+ : L.forecast.state === 'cant-tell' ? "forecast: can't tell" : L.forecast.state === 'no-target' ? `forecast ${short(L.forecast.date)}, no target` : '';
139
+ say(`${L.title} · ${where}${L.products.length > 1 ? ' · ' + L.products.join(' + ') : ''}${fc ? ' · ' + fc : ''}`);
140
+ const miss = L.station ? L.stations[L.station.n - 1].missing : [];
141
+ if (miss.length) say(` missing: ${miss.join('; ')}`);
142
+ say(` next: ${L.next}`);
143
+ }
144
+ for (const c of r.clashes) {
145
+ say(`Decide · ${c.text}`);
146
+ say(` PMOS recommends: ${c.recommend.why}${c.recommend.wait.length ? ' ' + c.recommend.wait.join(', ') + ' wait.' : ''} Keep it: pmos program decide --team ${JSON.stringify(c.team)} --first ${c.recommend.first}`);
147
+ }
148
+ for (const p of r.products.filter((x) => !x.ok)) say(` ! ${p.product}: ${p.error}`);
149
+ return 0;
150
+ }
151
+
152
+ if (verb === 'capacity') {
153
+ const team = pos[0], n = Number(pos[1]);
154
+ if (!team || !Number.isInteger(n) || n < 1 || n > 50) { say('usage: pmos program capacity <team> <n> (n from 1 to 50)'); return 2; }
155
+ const file = progFile(here);
156
+ if (!file) { say('✗ this repository has no PMOS state folder'); return 1; }
157
+ const was = PL.extrasOf(pmItems.readLines(file).filter(Boolean)).capacity[team] || PL.DEFAULT_CAPACITY;
158
+ pmItems.appendEvent(file, { kind: 'team-capacity', team: String(team).slice(0, 80), n }, new Date(now));
159
+ say(`[program-line] ✓ ${team} builds ${n} at once (was ${was}). Undo: pmos program capacity ${JSON.stringify(team)} ${was}`);
160
+ return 0;
161
+ }
162
+
163
+ if (verb === 'decide' && flags.team) {
164
+ if (!flags.first || !P_INI.test(flags.first)) { say('usage: pmos program decide --team <team> --first <initiative>'); return 2; }
165
+ const file = progFile(here);
166
+ if (!file) { say('✗ this repository has no PMOS state folder'); return 1; }
167
+ pmItems.appendEvent(file, { kind: 'decision', team: String(flags.team).slice(0, 80), first: flags.first }, new Date(now));
168
+ say(`[program-line] ✓ ${flags.team} builds ${flags.first} first. The program line follows it.`);
169
+ return 0;
170
+ }
171
+
172
+ const id = pos[0];
173
+ if (!id) { say(USAGE.find((l) => l.includes('pmos program ' + verb))); return 2; }
174
+ const r = R();
175
+ const L = r.programs.find((x) => x.id === id);
176
+ if (!L) { say(`✗ no open program ${id} in the products this computer has`); return 1; }
177
+ const home = rootOfWs(r, L.home);
178
+ if (!home) { say(`✗ the charter of ${id} is in a product this computer does not have`); return 1; }
179
+
180
+ if (verb === 'order') {
181
+ const P = require('./programs.js');
182
+ const list = flags.clear ? [] : pos[1] ? String(pos[1]).split(',').map((x) => x.trim()).filter(Boolean) : L.order.proposed;
183
+ const v = P.validOrder(list);
184
+ if (v.error) { say('✗ ' + v.error); return 1; }
185
+ const known = new Set(L.members.map((m) => m.id));
186
+ const bad = v.find((x) => !known.has(x));
187
+ if (bad) { say(`✗ ${bad} is not an initiative of ${id}`); return 1; }
188
+ const lines = pmItems.readLines(progFile(home)).filter(Boolean);
189
+ const was = (P.fold(lines)[id] || {}).order || [];
190
+ pmItems.appendEvent(progFile(home), { kind: 'order', program: id, order: v }, new Date(now));
191
+ say(`[program-line] ✓ ${id} order: ${v.length ? v.join(' → ') : 'A to Z'}. Undo: pmos program order ${id} ${was.length ? was.join(',') : '--clear'}`);
192
+ return 0;
193
+ }
194
+
195
+ if (verb === 'decide') {
196
+ if (!flags['keep-target']) { say('usage: pmos program decide <id> --keep-target'); return 2; }
197
+ if (L.forecast.state !== 'past' && L.forecast.state !== 'cant-tell') { say(`${id}: the forecast is not past the target; nothing to decide.`); return 0; }
198
+ pmItems.appendEvent(progFile(home), { kind: 'decision', program: id, choice: 'keep-target', forecast: L.forecast.date, target: L.target }, new Date(now));
199
+ say(`[program-line] ✓ ${id}: target ${short(L.target)} kept against the forecast ${short(L.forecast.date) || "can't tell"}. A new slip asks again.`);
200
+ return 0;
201
+ }
202
+
203
+ if (verb === 'outcome') {
204
+ const text = String(pos.slice(1).join(' ') || '').replace(/\s+/g, ' ').trim().slice(0, 400);
205
+ if (!text) { say('usage: pmos program outcome <id> "<what the outcome read says>"'); return 2; }
206
+ pmItems.appendEvent(progFile(home), { kind: 'outcome', program: id, text }, new Date(now));
207
+ say(`[program-line] ✓ ${id}: outcome read saved.`);
208
+ return 0;
209
+ }
210
+
211
+ // draft: file the milestone drafts as one finished review run, so the program page shows them open with Keep and Decline. The open
212
+ // suggestions of the last review are filed again in the same run, so nothing a review said is withdrawn by this one.
213
+ const items = PL.draftsOf(L);
214
+ if (!items.length) { say(!(L.stations[1].missing || []).includes('milestones') ? `${id} already has milestones; PMOS drafts only a program's first ones.` : `${id}: no milestone to draft${L.drafts.cantTell.length ? `; can't tell for ${L.drafts.cantTell.join(', ')} (no date)` : ''}.`); return 0; }
215
+ const d = driver.stateDirOf(home);
216
+ const file = MS.fileOf(d);
217
+ const st = MS.fold(pmItems.readLines(file))[id] || null;
218
+ const prog = { milestones: [] };
219
+ const carry = st ? MS.openOf(st, prog) : [];
220
+ const run = 'line' + now.toString(36);
221
+ const at = new Date(now);
222
+ pmItems.appendEvent(file, { kind: 'review-start', program: id, run, why: 'line', members: L.members.map((m) => (m.ws || '') + ':' + m.id).sort().join(',') }, at);
223
+ let filed = 0, skipped = 0;
224
+ const keys = new Set();
225
+ for (const raw of items.concat(carry.map(({ key, run: _r, at: _a, ...it }) => it))) {
226
+ const v = MS.validItem(raw);
227
+ if (v.error) { skipped++; continue; }
228
+ const key = MS.keyOf(id, v.item);
229
+ if (keys.has(key) || (st && st.declined.has(MS.sigOf(v.item)))) { skipped++; continue; }
230
+ keys.add(key);
231
+ pmItems.appendEvent(file, { kind: 'suggest', program: id, run, key, item: v.item }, at);
232
+ filed++;
233
+ }
234
+ pmItems.appendEvent(file, { kind: 'review-end', program: id, run, ok: true }, at);
235
+ say(`[program-line] ✓ ${id}: ${filed} milestone suggestion${filed === 1 ? '' : 's'} filed${skipped ? ` (${skipped} declined before or repeated)` : ''}. The program shows them with Keep and Decline.`);
236
+ for (const it of items) say(` ${short(it.date)} · ${it.name} · waits on ${it.waits.join(', ')}`);
237
+ if (L.drafts.cantTell.length) say(` can't tell: ${L.drafts.cantTell.join(', ')} (no date)`);
238
+ return 0;
239
+ }
240
+ const P_INI = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
241
+ function gitTop(cwd) {
242
+ try { return require('child_process').execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; }
243
+ }
244
+
245
+ module.exports = { run, COMMANDS, USAGE, charter, lineVerb };
@@ -0,0 +1,380 @@
1
+ 'use strict';
2
+ /* program-line.js — the program line: where each program stands, and what moves it next (product line plan, slice 5; initiative program-line).
3
+ * A program is the level above initiatives, across products (lib/programs.js). Its line has four stations, each with an exit test read from
4
+ * records only (doc Ejs4HXyqpenvaiqiRMtzoF, tab Plan, "Setup line and program line"):
5
+ *
6
+ * Charter exit: goal, target date and owner set. PMOS drafts the missing ones from the members.
7
+ * Sequence exit: every member ordered; milestones dated (one at least). PMOS proposes the order (predecessors, then dates), drafts
8
+ * milestones from the members' dates, and limits Build entry to each team's capacity.
9
+ * Track exit: the forecast is inside the target, or a decision is recorded for this forecast. PMOS names the member that slips
10
+ * and the milestones that move.
11
+ * Land exit: every member passed Implementation (Build on Product feature); the outcome read. Asks only to close the program.
12
+ * The program stands at the first station whose exit fails; past Land it is Landed. Each member stays on its own product's line and
13
+ * workflow (lib/line.js); the program line only reads them. A program across products joins every product's rows into ONE forecast.
14
+ *
15
+ * lineOf(program, members, o) PURE → { id, title, home, station: { key, name, n, of } | null, landed, stations: [{ key, name, passed,
16
+ * missing: [text] }], next, forecast: { date, state, cantTell: [id], slips: [{ id, date, why }], moves: [{ id,
17
+ * name, from, to }] }, target, order: { set, proposed: [id], differs }, drafts: { charter, milestones, cantTell },
18
+ * build: { waits: [{ id, team, behind }] }, members: [member], decision }
19
+ * program lib/programs.js merge's answer (with the extra `decisions`, `outcome` from extrasOf)
20
+ * members [{ ws, product, id, title, live, ended, station, flag, next, passedImpl, inImpl, nextIsImpl, end, owner, team, after }]
21
+ * (factsOf builds one from a pmos line row and the Board row; a member no product read holds is { ws, id, missing: true })
22
+ * o { now, capacity: { [team]: n }, busy: { [team]: [member key] } (members in Build outside this program) }
23
+ * clashesOf(lines, o) PURE → [decision row] a team more than one product needs in Build beyond its capacity: ONE row each,
24
+ * with a recommendation (the member whose program lands first goes first)
25
+ * draftsOf(line) → [milestone-suggest item] the Sequence milestone drafts, as `pmos program suggest` items
26
+ * extrasOf(lines) PURE → { capacity: { team: n }, decisions: { [program]: [line] }, outcome: { [program]: line }, teamFirst }
27
+ * read(roots, o) → { programs: [line], clashes: [row], products: [{ ws, root, product, ok, error? }] } every registered workspace
28
+ * health(o) · CLI `node program-line.js health` the percent of open programs placed with a next move (the done test's health number)
29
+ *
30
+ * RULE 1 OF THE PLAN: "can't tell" beats a guess. A member with no date is never given one: it is listed under cantTell, and a program
31
+ * forecast with such a member says so. Nothing here writes; lib/program-cli.js holds the writes (draft, order, capacity, decide, charter). */
32
+ const fs = require('fs');
33
+ const path = require('path');
34
+
35
+ const DAY = 86400000;
36
+ const CLUSTER_DAYS = 14; // members finishing within this many days of the first share one drafted milestone
37
+ const DEFAULT_CAPACITY = 2; // initiatives one team builds at once, until the user sets one (`pmos program capacity`)
38
+ const MAX_MS = 12;
39
+ const STATIONS = [
40
+ { key: 'charter', name: 'Charter' }, { key: 'sequence', name: 'Sequence' }, { key: 'track', name: 'Track' }, { key: 'land', name: 'Land' },
41
+ ];
42
+ const IMPL = /^(implementation|build)$/i;
43
+ const DONE_ENDS = new Set(['Shipped', 'Closed']);
44
+ const DROPPED_ENDS = new Set(["Won't do", 'Cancelled', 'Archived']);
45
+ const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
46
+
47
+ const lc = (s) => String(s || '').trim().toLowerCase();
48
+ const dayOf = (iso) => (DAY_RE.test(String(iso || '').slice(0, 10)) ? String(iso).slice(0, 10) : '');
49
+ const todayOf = (now) => new Date(now).toISOString().slice(0, 10);
50
+ const addDays = (day, n) => new Date(Date.parse(day + 'T00:00:00Z') + n * DAY).toISOString().slice(0, 10);
51
+ const gap = (a, b) => Math.round((Date.parse(b + 'T00:00:00Z') - Date.parse(a + 'T00:00:00Z')) / DAY);
52
+ const keyOf = (m) => (m.ws || '') + ':' + m.id;
53
+ const clip = (s, n) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).trimEnd() + '…' : t; };
54
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
55
+ const short = (day) => (day ? MON[+day.slice(5, 7) - 1] + ' ' + (+day.slice(8, 10)) + ' ' + day.slice(0, 4) : '');
56
+
57
+ /** One member's facts from its pmos line row (lib/line.js place) and its Board row (lib/stage-read.js rowOf().row), plus its record's
58
+ * front matter (`team:`, `predecessor:`). Passed Implementation: its workflow's Implementation (or Build) stage is done, or it ended as
59
+ * Shipped or Closed. A workflow with neither stage reads the lifecycle step: past Build. */
60
+ function factsOf({ ws, product, line, row, front }) {
61
+ const r = row || {}, l = line || {}, f = front || {};
62
+ const st = Array.isArray(r.wfStages) ? r.wfStages : [];
63
+ const impl = st.find((s) => s && (IMPL.test(lc(s.name)) || IMPL.test(lc(s.key))));
64
+ const ended = l.ended || null;
65
+ let passedImpl = DONE_ENDS.has(ended);
66
+ if (!passedImpl && impl) passedImpl = impl.status === 'done';
67
+ else if (!passedImpl && !impl && r.oneStage && r.oneStage.step) passedImpl = ['deliver', 'monitor', 'evaluate'].includes(r.oneStage.step);
68
+ const cur = l.station || null;
69
+ const inImpl = !passedImpl && !!cur && (IMPL.test(lc(cur.name)) || IMPL.test(lc(cur.key)));
70
+ const ci = cur ? st.findIndex((s) => s && (s.key === cur.key || s.name === cur.name)) : -1;
71
+ const nextIsImpl = !passedImpl && !inImpl && !!impl && ci >= 0 && st.indexOf(impl) === ci + 1;
72
+ const after = String(f.predecessor || '').split(/[,\s]+/).map((x) => x.trim()).filter(Boolean);
73
+ return {
74
+ ws, product, id: l.id || r.id, title: l.title || r.title || l.id || r.id, live: l.live !== false && !ended, ended,
75
+ station: cur, flag: l.flag || null, next: l.next || '', passedImpl, inImpl, nextIsImpl,
76
+ end: dayOf(r.end), owner: String(r.owner || f.owner || '').trim(), team: String(f.team || '').trim() || product || ws || '', after,
77
+ };
78
+ }
79
+
80
+ /** The proposed order: a predecessor before the one that names it, then the earlier end date, then A to Z. Ids only of `list`. */
81
+ function proposeOrder(list) {
82
+ const ids = list.map((m) => m.id);
83
+ const by = new Map(list.map((m) => [m.id, m]));
84
+ const cmp = (a, b) => (by.get(a).end || '9999').localeCompare(by.get(b).end || '9999') || a.localeCompare(b);
85
+ const out = [], done = new Set(), seen = new Set();
86
+ const visit = (id) => {
87
+ if (done.has(id) || seen.has(id)) return; // a loop in predecessors: the date order decides
88
+ seen.add(id);
89
+ for (const p of (by.get(id).after || []).filter((x) => by.has(x)).sort(cmp)) visit(p);
90
+ done.add(id); out.push(id);
91
+ };
92
+ for (const id of ids.slice().sort(cmp)) visit(id);
93
+ return out;
94
+ }
95
+
96
+ /** Milestone drafts from the members' dates: members finishing within CLUSTER_DAYS of the first share one, dated at the latest end. */
97
+ function draftMilestones(list) {
98
+ const dated = list.filter((m) => !m.passedImpl && m.end).sort((a, b) => a.end.localeCompare(b.end) || a.id.localeCompare(b.id));
99
+ const out = [];
100
+ for (const m of dated) {
101
+ const last = out[out.length - 1];
102
+ if (last && gap(last.first, m.end) <= CLUSTER_DAYS) { last.members.push(m); last.date = m.end; } else out.push({ first: m.end, date: m.end, members: [m] });
103
+ }
104
+ return out.slice(0, MAX_MS).map((c) => {
105
+ const t = c.members.map((m) => clip(m.title, 40));
106
+ const name = t.length === 1 ? `${t[0]} delivered` : t.length === 2 ? `${t[0]} and ${t[1]} delivered` : `${t[0]} and ${t.length - 1} more delivered`;
107
+ return { name: clip(name, 80), date: c.date, waits: c.members.map((m) => m.id),
108
+ why: c.members.length === 1 ? `${c.members[0].id} ends ${short(c.date)} on its plan` : `${c.members.length} initiatives end between ${short(c.first)} and ${short(c.date)} on their plans`,
109
+ src: { kind: 'deliver', label: clip(`plan ends, ${c.members.map((m) => m.id + ' ' + m.end).join(', ')}`, 80) } };
110
+ });
111
+ }
112
+
113
+ function lineOf(program, members, o = {}) {
114
+ const p = program || {};
115
+ const now = o.now || Date.now(), today = todayOf(now);
116
+ const cap = (team) => { const n = (o.capacity || {})[team]; return Number.isInteger(n) && n > 0 ? n : DEFAULT_CAPACITY; };
117
+ const all = members || [];
118
+ const missingRead = all.filter((m) => m.missing).map((m) => m.id);
119
+ const list = all.filter((m) => !m.missing && !DROPPED_ENDS.has(m.ended));
120
+ const live = list.filter((m) => !m.passedImpl);
121
+ const target = dayOf(p.target);
122
+ const ms = Array.isArray(p.milestones) ? p.milestones : [];
123
+
124
+ // Charter
125
+ const charterMissing = [];
126
+ if (!String(p.goal || '').trim()) charterMissing.push('goal');
127
+ if (!target) charterMissing.push('target date');
128
+ if (!String(p.owner || '').trim()) charterMissing.push('owner');
129
+ const ends = list.map((m) => m.end).filter(Boolean).sort();
130
+ const owners = {};
131
+ for (const m of list) if (m.owner) owners[m.owner] = (owners[m.owner] || 0) + 1;
132
+ const topOwner = Object.entries(owners).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0];
133
+ const charter = {};
134
+ if (charterMissing.includes('target date') && ends.length && !list.some((m) => !m.passedImpl && !m.end)) charter.target = ends[ends.length - 1];
135
+ if (charterMissing.includes('owner') && topOwner) charter.owner = topOwner[0];
136
+ if (charterMissing.includes('goal') && list.length) charter.goal = clip('Deliver ' + list.slice(0, 3).map((m) => clip(m.title, 40)).join(', ') + (list.length > 3 ? ` and ${list.length - 3} more` : ''), 160);
137
+
138
+ // Sequence
139
+ const proposed = proposeOrder(list);
140
+ const set = Array.isArray(p.order) ? p.order : [];
141
+ const unordered = list.filter((m) => !set.includes(m.id)).map((m) => m.id);
142
+ const seqMissing = [];
143
+ if (unordered.length) seqMissing.push(`order of ${unordered.length} of ${list.length} initiatives`);
144
+ const undated = ms.filter((m) => !dayOf(m.date));
145
+ if (!ms.length) seqMissing.push('milestones');
146
+ else if (undated.length) seqMissing.push(`dates of ${undated.length} milestones`);
147
+ const msDrafts = ms.length ? [] : draftMilestones(list);
148
+ const cantTell = live.filter((m) => !m.end).map((m) => m.id);
149
+ // Build limit: per team, members in Implementation now (here and elsewhere) against capacity; the ones next in line wait in order
150
+ const seq = set.length ? set.concat(proposed.filter((x) => !set.includes(x))) : proposed;
151
+ const pos = (id) => { const i = seq.indexOf(id); return i < 0 ? 999 : i; };
152
+ const waits = [];
153
+ const teams = [...new Set(list.map((m) => m.team).filter(Boolean))];
154
+ for (const team of teams) {
155
+ const mine = list.filter((m) => m.team === team);
156
+ const busy = new Set([...((o.busy || {})[team] || []), ...mine.filter((m) => m.inImpl).map(keyOf)]);
157
+ let free = cap(team) - busy.size;
158
+ for (const m of mine.filter((x) => x.nextIsImpl).sort((a, b) => pos(a.id) - pos(b.id))) {
159
+ if (free > 0) { free--; continue; }
160
+ waits.push({ id: m.id, team, capacity: cap(team), behind: [...busy].map((k) => k.split(':').slice(1).join(':')) });
161
+ }
162
+ }
163
+
164
+ // Track: one forecast from every product's rows
165
+ const slips = [];
166
+ let fc = '';
167
+ for (const m of live) {
168
+ if (!m.end) continue;
169
+ let d = m.end, why = '';
170
+ if (m.end < today) { d = today; why = `its plan ended ${short(m.end)} and it has not passed Implementation`; }
171
+ else if (m.flag === 'stuck') why = 'stuck at ' + ((m.station && m.station.name) || 'its station');
172
+ if (target && d > target && !why) why = `ends ${short(d)}, after the target`;
173
+ if (why) slips.push({ id: m.id, product: m.product, date: d, why });
174
+ if (d > fc) fc = d;
175
+ }
176
+ const fcState = !live.length ? 'done' : cantTell.length ? 'cant-tell' : !target ? 'no-target' : fc <= target ? 'inside' : 'past';
177
+ const moves = [];
178
+ for (const s of slips) for (const m of ms) if ((m.waits || []).includes(s.id) && dayOf(m.date) && s.date > m.date) moves.push({ id: m.id, name: m.name, from: m.date, to: s.date });
179
+ const decision = ((p.decisions || [])).filter((d) => d.forecast === fc && d.target === target).pop() || null;
180
+ const trackMissing = [];
181
+ if (fcState === 'past' && !decision) trackMissing.push(`a decision: the forecast ${short(fc)} is past the target ${short(target)}`);
182
+ if (fcState === 'cant-tell' && !decision) trackMissing.push(`dates of ${cantTell.length} initiatives (can't tell the forecast)`);
183
+
184
+ // Land
185
+ const landMissing = [];
186
+ const notYet = list.filter((m) => !m.passedImpl);
187
+ if (notYet.length) landMissing.push(`${notYet.length} of ${list.length} initiatives past Implementation`);
188
+ if (!p.outcome) landMissing.push('the outcome read');
189
+ if (!list.length) landMissing.unshift('initiatives in the program');
190
+
191
+ const stations = [
192
+ { ...STATIONS[0], missing: charterMissing }, { ...STATIONS[1], missing: seqMissing },
193
+ { ...STATIONS[2], missing: trackMissing }, { ...STATIONS[3], missing: landMissing },
194
+ ].map((s) => ({ ...s, passed: !s.missing.length }));
195
+ const at = stations.findIndex((s) => !s.passed);
196
+ const station = at < 0 ? null : { key: stations[at].key, name: stations[at].name, n: at + 1, of: stations.length };
197
+
198
+ let next = '';
199
+ if (!station) next = 'Landed: every initiative passed Implementation and the outcome is read. Close the program when you are ready.';
200
+ else if (station.key === 'charter') {
201
+ const d = Object.entries(charter).map(([k, v]) => `${k === 'target' ? 'target ' + v : k === 'owner' ? 'owner ' + v : 'goal "' + v + '"'}`);
202
+ next = d.length ? `PMOS drafts ${d.join(', ')}; agree or change them.` : `Set the ${charterMissing.join(', ')}; no member record says ${charterMissing.length > 1 ? 'them' : 'it'}.`;
203
+ if (charter.target === undefined && charterMissing.includes('target date') && cantTell.length) next += ` Can't tell a target: ${cantTell.length} initiatives have no date.`;
204
+ } else if (station.key === 'sequence') {
205
+ const parts = [];
206
+ if (unordered.length) parts.push(`PMOS proposes the order ${proposed.join(' → ')}`);
207
+ if (msDrafts.length) parts.push(`PMOS drafts ${msDrafts.length} dated milestone${msDrafts.length > 1 ? 's' : ''} (keep or decline them on the program)`);
208
+ else if (!ms.length) parts.push("can't draft milestones: no initiative has a date");
209
+ if (undated.length) parts.push(`date ${undated.map((m) => m.name).join(', ')}`);
210
+ next = parts.join('; ') + '.';
211
+ } else if (station.key === 'track') {
212
+ if (fcState === 'past') next = `${slips.map((s) => s.id).join(', ')} slip${slips.length === 1 ? 's' : ''}: the forecast is ${short(fc)}, target ${short(target)}.` + (moves.length ? ` Moves ${moves.map((m) => `${m.name} to ${short(m.to)}`).join(', ')}.` : '') + ' Decide: move the target, or cut or reorder the work.';
213
+ else next = `Can't tell the forecast: ${cantTell.join(', ')} ${cantTell.length === 1 ? 'has' : 'have'} no date. Give each a plan end.`;
214
+ } else {
215
+ next = notYet.length ? `${list.length - notYet.length} of ${list.length} initiatives past Implementation; forecast ${fc ? short(fc) : 'none'}${target ? ', target ' + short(target) : ''}.` : 'Every initiative passed Implementation. Read the outcome against the goal.';
216
+ }
217
+ if (waits.length) next += ` ${waits.map((w) => `${w.id} waits for ${w.team} (builds ${w.capacity} at once)`).join('; ')}.`;
218
+ if (missingRead.length) next += ` Not read: ${missingRead.join(', ')}.`;
219
+
220
+ return {
221
+ id: p.id, title: p.title || p.id, home: p.home || '', station, landed: !station, stations, next: next.trim(), target,
222
+ forecast: { date: fc, state: fcState, cantTell, slips, moves },
223
+ order: { set: set.length > 0, proposed, differs: set.length > 0 && proposed.join() !== set.filter((x) => proposed.includes(x)).join() },
224
+ drafts: { charter, milestones: msDrafts, cantTell }, build: { waits },
225
+ members: list, missing: missingRead, decision, products: [...new Set(list.map((m) => m.product).filter(Boolean))],
226
+ };
227
+ }
228
+
229
+ /** The Sequence milestone drafts as `pmos program suggest` items (lib/milestone-suggest.js validItem: op add). */
230
+ const draftsOf = (line) => ((line && line.drafts && line.drafts.milestones) || []).map((d) => ({ op: 'add', name: d.name, date: d.date, waits: d.waits, why: d.why, src: d.src }));
231
+
232
+ /** A team more than one product needs in Build beyond its capacity: ONE decision row each. Members in Implementation hold their places;
233
+ * the ones next in line are ranked by their program's target (earlier first), then their place in its order. The first free places
234
+ * are the recommendation. A team whose contenders all come from one product is that product's own Build limit, not a clash. */
235
+ function clashesOf(lines, o = {}) {
236
+ const cap = (team) => { const n = (o.capacity || {})[team]; return Number.isInteger(n) && n > 0 ? n : DEFAULT_CAPACITY; };
237
+ const seen = new Map();
238
+ for (const L of lines || []) {
239
+ L.members.forEach((m) => {
240
+ const k = keyOf(m);
241
+ const prev = seen.get(k);
242
+ const rank = { target: L.target || '9999', pos: L.order.proposed.indexOf(m.id), program: L.id, title: L.title };
243
+ if (!prev || rank.target < prev.rank.target) seen.set(k, { m, rank });
244
+ });
245
+ }
246
+ const byTeam = new Map();
247
+ for (const { m, rank } of seen.values()) {
248
+ if (!m.team || (!m.inImpl && !m.nextIsImpl)) continue;
249
+ if (!byTeam.has(m.team)) byTeam.set(m.team, []);
250
+ byTeam.get(m.team).push({ m, rank });
251
+ }
252
+ const out = [];
253
+ for (const [team, xs] of byTeam) {
254
+ const busy = xs.filter((x) => x.m.inImpl), want = xs.filter((x) => x.m.nextIsImpl);
255
+ const free = cap(team) - busy.length;
256
+ const products = new Set(xs.map((x) => x.m.product || x.m.ws));
257
+ if (want.length <= Math.max(0, free) || products.size < 2) continue;
258
+ const chosen = (o.teamFirst || {})[team];
259
+ want.sort((a, b) => (chosen === a.m.id ? -1 : chosen === b.m.id ? 1 : 0) || a.rank.target.localeCompare(b.rank.target) || a.rank.pos - b.rank.pos || a.m.id.localeCompare(b.m.id));
260
+ const go = want.slice(0, Math.max(0, free)), wait = want.slice(Math.max(0, free));
261
+ const first = want[0];
262
+ out.push({
263
+ kind: 'clash', team, capacity: cap(team), decided: !!chosen,
264
+ busy: busy.map((x) => ({ id: x.m.id, product: x.m.product, program: x.rank.program })),
265
+ want: want.map((x) => ({ id: x.m.id, product: x.m.product, program: x.rank.program, target: x.rank.target === '9999' ? '' : x.rank.target })),
266
+ recommend: { go: go.map((x) => x.m.id), wait: wait.map((x) => x.m.id), first: first.m.id,
267
+ why: free > 0 ? `${first.m.id} goes first: its program ${first.rank.title} has the earliest target${first.rank.target !== '9999' ? ' (' + short(first.rank.target) + ')' : ''}.`
268
+ : `${team} builds ${cap(team)} at once and ${busy.length} ${busy.length === 1 ? 'is' : 'are'} in Implementation. When one passes, ${first.m.id} goes first: its program ${first.rank.title} has the earliest target${first.rank.target !== '9999' ? ' (' + short(first.rank.target) + ')' : ''}.` },
269
+ text: `${team} is needed in Build by ${[...products].join(' and ')}: ${want.length} want${want.length === 1 ? 's' : ''} to start, ${Math.max(0, free)} place${free === 1 ? '' : 's'} free.`,
270
+ });
271
+ }
272
+ return out;
273
+ }
274
+
275
+ /** The extra program lines this file reads, beside lib/programs.js fold: team capacity, decisions, outcome reads, a team's chosen first. */
276
+ function extrasOf(lines) {
277
+ const out = { capacity: {}, decisions: {}, outcome: {}, teamFirst: {} };
278
+ for (const l of lines || []) {
279
+ if (!l || typeof l !== 'object') continue;
280
+ if (l.kind === 'team-capacity' && l.team && Number.isInteger(l.n) && l.n > 0) out.capacity[String(l.team)] = l.n;
281
+ else if (l.kind === 'decision' && l.program) (out.decisions[l.program] = out.decisions[l.program] || []).push(l);
282
+ else if (l.kind === 'decision' && l.team && l.first) out.teamFirst[String(l.team)] = String(l.first);
283
+ else if (l.kind === 'outcome' && l.program) out.outcome[l.program] = l;
284
+ }
285
+ return out;
286
+ }
287
+
288
+ /** A record's front matter keys this line reads (team, predecessor, owner). */
289
+ function frontOf(file) {
290
+ let t = '';
291
+ try { t = fs.readFileSync(file, 'utf8'); } catch { return {}; }
292
+ const m = /^---\n([\s\S]*?)\n---/.exec(t);
293
+ const out = {};
294
+ if (!m) return out;
295
+ for (const k of ['team', 'predecessor', 'owner']) { const r = new RegExp('^' + k + ':\\s*(.*)$', 'm').exec(m[1]); if (r) out[k] = r[1].replace(/^["']|["']$/g, '').trim(); }
296
+ return out;
297
+ }
298
+
299
+ /** The roots to read: the given ones, then (registry true) the server's registry (workspaces.json), each once, only those with a PMOS
300
+ * state folder. */
301
+ function rootsOf(given, env = process.env, registry = true) {
302
+ const driver = require('./driver.js');
303
+ const out = [], seen = new Set();
304
+ const add = (r) => { const a = path.resolve(r); if (seen.has(a)) return; seen.add(a); if (driver.stateDirOf(a)) out.push(a); };
305
+ for (const r of given || []) add(r);
306
+ if (registry) {
307
+ let reg = [];
308
+ try { reg = JSON.parse(fs.readFileSync(path.join(require('./state-root.js').defaultRoot({ env }), 'workspaces.json'), 'utf8')); } catch { reg = []; }
309
+ if (Array.isArray(reg)) for (const x of reg) if (x && typeof x.root === 'string') { try { if (fs.statSync(x.root).isDirectory()) add(x.root); } catch { /* gone */ } }
310
+ }
311
+ return out;
312
+ }
313
+
314
+ /** Every program of the roots, placed on its line, and the clashes between products. Read-only. o: { now, only, env, lineOf (tests) } */
315
+ function read(roots, o = {}) {
316
+ const driver = require('./driver.js');
317
+ const P = require('./programs.js');
318
+ const pmItems = require('./pm-items.js');
319
+ const now = o.now || Date.now();
320
+ const products = [], perWs = [], extraLines = [];
321
+ const facts = new Map(); // ws → Map id → member
322
+ for (const root of roots) {
323
+ const ws = driver.wsIdOf(root), product = path.basename(root);
324
+ const dir = driver.stateDirOf(root);
325
+ const lines = dir ? pmItems.readLines(path.join(dir, 'programs.jsonl')).filter(Boolean) : [];
326
+ perWs.push({ ws, lines });
327
+ extraLines.push(...lines);
328
+ products.push({ ws, root, product, ok: true, dir });
329
+ }
330
+ const programs = P.merge(perWs).filter((p) => !o.only || p.id === o.only);
331
+ const need = new Set(programs.flatMap((p) => p.members.map((m) => m.ws)));
332
+ for (const pr of products) {
333
+ if (!need.has(pr.ws)) continue;
334
+ const L = (o.lineOf || require('./line.js').lineOf)(pr.root, { now });
335
+ if (!L.ok) { pr.ok = false; pr.error = L.error; continue; }
336
+ const SR = require('./stage-read.js');
337
+ const { w, ctx } = SR.cliCtx(pr.root);
338
+ const map = new Map();
339
+ const wanted = new Set(programs.flatMap((p) => p.members.filter((m) => m.ws === pr.ws).map((m) => m.initiative)));
340
+ for (const row of L.rows) {
341
+ if (!wanted.has(row.id)) continue;
342
+ let b = null;
343
+ try { const r = (o.rowOf || SR.rowOf)(ctx, w, row.id); b = r && r.ok ? r.row : null; } catch { b = null; }
344
+ const rec = b && typeof b.record === 'string' ? path.resolve(pr.root, b.record) : null;
345
+ map.set(row.id, factsOf({ ws: pr.ws, product: pr.product, line: row, row: b, front: rec ? frontOf(rec) : {} }));
346
+ }
347
+ facts.set(pr.ws, map);
348
+ }
349
+ const X = extrasOf(extraLines);
350
+ const membersOf = (p) => p.members.map((m) => { const f = facts.get(m.ws) && facts.get(m.ws).get(m.initiative); return f || { ws: m.ws, id: m.initiative, missing: true }; });
351
+ // members in Implementation, by team, across every program: a team's capacity is the team's, not one program's
352
+ const inImplBy = {};
353
+ const all = programs.map((p) => ({ p, ms: membersOf(p) }));
354
+ for (const { ms } of all) for (const m of ms) if (!m.missing && m.inImpl && m.team) (inImplBy[m.team] = inImplBy[m.team] || new Set()).add(keyOf(m));
355
+ const lines = all.map(({ p, ms }) => {
356
+ const own = new Set(ms.map(keyOf));
357
+ const busy = {};
358
+ for (const [t, s] of Object.entries(inImplBy)) busy[t] = [...s].filter((k) => !own.has(k));
359
+ return lineOf({ ...p, decisions: X.decisions[p.id] || [], outcome: X.outcome[p.id] || null }, ms, { now, capacity: X.capacity, busy });
360
+ });
361
+ return { programs: lines, clashes: clashesOf(lines, { capacity: X.capacity, teamFirst: X.teamFirst }), products: products.map(({ dir, ...x }) => x) };
362
+ }
363
+
364
+ function health(o = {}) {
365
+ const r = read(rootsOf(o.roots || [process.cwd()], o.env, !o.roots), o);
366
+ const open = r.programs.filter((l) => !l.landed);
367
+ const placed = open.filter((l) => l.station && l.next).length;
368
+ return { open: open.length, placed, percent: open.length ? Math.round((placed / open.length) * 1000) / 10 : 100 };
369
+ }
370
+
371
+ module.exports = { lineOf, clashesOf, draftsOf, extrasOf, factsOf, proposeOrder, draftMilestones, read, rootsOf, frontOf, health, STATIONS, DEFAULT_CAPACITY, CLUSTER_DAYS };
372
+
373
+ if (require.main === module) {
374
+ const [cmd, ...rest] = process.argv.slice(2);
375
+ if (cmd !== 'health') { console.log('usage: node program-line.js health [--root <dir> …]'); process.exit(2); }
376
+ const roots = []; for (let i = 0; i < rest.length; i++) if (rest[i] === '--root') roots.push(rest[++i]);
377
+ const h = health(roots.length ? { roots } : {});
378
+ console.log(`[program-line] ${h.placed} of ${h.open} open programs placed with a next move`);
379
+ console.log(String(h.percent));
380
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.752.0",
3
+ "version": "0.753.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.752.0",
9
+ "version": "0.753.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.752.0",
3
+ "version": "0.753.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Program line (initiative program-line, done test P1-P9): Charter, Sequence, Track, Land over pmos line; one forecast across products; one decision row per shared-team clash; the draft, order and capacity writes on a scratch repository. No server, model or network.",
3
+ "modules": [
4
+ "program-line.test.js"
5
+ ],
6
+ "seconds": {
7
+ "program-line.test.js": 2
8
+ }
9
+ }