create-pmos 0.753.0 → 0.755.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 +27 -78
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +26 -0
- package/workspace/guide/cli.md +16 -1
- package/workspace/lib/driver-cli.js +57 -4
- package/workspace/lib/driver-decide.js +36 -7
- package/workspace/lib/driver-facts.js +17 -1
- package/workspace/lib/driver.js +6 -1
- package/workspace/lib/line-driver-count.js +12 -0
- package/workspace/lib/line-driver.js +224 -0
- package/workspace/lib/line.js +64 -7
- package/workspace/lib/needs-providers.js +1 -0
- package/workspace/lib/pmos-verbs.js +4 -1
- package/workspace/lib/setup-cli.js +13 -0
- package/workspace/lib/setup-station.js +400 -0
- package/workspace/lib/task-jira.js +20 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/skills/initiative-drive.skill +8 -3
- package/workspace/test-lists/line-driver.json +9 -0
- package/workspace/test-lists/setup-station.json +9 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* line-driver.js — the Initiative Driver follows the line (product line plan, slice 3; initiative driver-follows-line).
|
|
3
|
+
*
|
|
4
|
+
* `pmos line` (lib/line.js) says, for every initiative, its station on its own workflow, the exit items still missing, the next move
|
|
5
|
+
* and a flag. This file turns that answer into the Driver's work, and gates the stage moves PMOS makes by itself.
|
|
6
|
+
*
|
|
7
|
+
* workOf(row) PURE → { act, why, station, missing, next, flag } whether the Driver works this row's exit items
|
|
8
|
+
* exitFact(row) PURE → the `exit` fact lib/driver-facts.js adds to one initiative (null when there is no row)
|
|
9
|
+
* blockerOf(fact, state, { now }) PURE → null | { code: 'exit-missing', text, items, key } for lib/driver.js detect: a wake when the
|
|
10
|
+
* missing set is new, and again each REWAKE_DAYS while it stays the same
|
|
11
|
+
* checkExits(data) PURE → { ok, exits } | { ok: false, error } the shape of a move's `exits` list
|
|
12
|
+
* quoteCheck(exits, readText) PURE → { ok, checks: [{ item, ok, why }] } every exit quotes a line that is really in its record
|
|
13
|
+
* moveGate({ row, exits, from, readText }) PURE → { ok, why, checks } the Checker's gate before PMOS moves a stage by itself
|
|
14
|
+
* readerOf(root, initiative) → readText(ref) → text | null a file inside the repository, or a Jira key in the initiative's read
|
|
15
|
+
* trackerOf(root, initiative) → [{ key, summary, assignee, sprint, start, end }] who holds each ticket and in which sprint
|
|
16
|
+
* linesFor(row, tracker) PURE → [text] the work list a Driver run reads (`pmos driver exits <id>`)
|
|
17
|
+
* CHECKER_REASON the reason prefix of the Checker line a passed gate writes (lib/driver-cli.js)
|
|
18
|
+
*
|
|
19
|
+
* THE RULES (plan rules 1, 2 and 4):
|
|
20
|
+
* 1. "Can't tell" beats a guess. A row flagged can't tell is not worked and never moved. A row that is waiting (on hold, on capacity, on
|
|
21
|
+
* another initiative) is not worked either: nothing it misses is the Driver's to do.
|
|
22
|
+
* 2. The outside wins. A move names the station it leaves (`from`); when the initiative is no longer there (you or Jira moved it since),
|
|
23
|
+
* the move is refused. A move by the PM on the page or by Jira is never gated here.
|
|
24
|
+
* 4. Check before PMOS moves. Every exit item of the station it leaves carries { item, quote, ref }. The quote must be found, word for
|
|
25
|
+
* word (spaces, case and markdown marks aside), in the record `ref` names: a file inside the repository, or a Jira key whose reading
|
|
26
|
+
* the initiative's last read holds. A link PMOS cannot read fails: the move then waits for the PM.
|
|
27
|
+
* Read-only: nothing here writes a file.
|
|
28
|
+
*/
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
|
|
32
|
+
const DAY = 86400000;
|
|
33
|
+
const REWAKE_DAYS = 7;
|
|
34
|
+
const MIN_QUOTE = 12;
|
|
35
|
+
const MAX_FILE = 2 * 1024 * 1024;
|
|
36
|
+
const KEY_RE = /^[A-Z][A-Z0-9_]{0,19}-\d{1,7}$/;
|
|
37
|
+
const CHECKER_REASON = 'quote check';
|
|
38
|
+
|
|
39
|
+
const lc = (s) => String(s == null ? '' : s).trim().toLowerCase();
|
|
40
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
41
|
+
const oneLine = (s, n) => typeof s === 'string' && s.trim().length > 0 && s.trim().length <= n && !/[\r\n]/.test(s.trim());
|
|
42
|
+
// the words of a text, with markdown marks, quotes and spacing taken out, so a quote matches the line it was copied from
|
|
43
|
+
const norm = (s) => String(s == null ? '' : s).replace(/[*_`>#|]+/g, ' ').replace(/[‘’]/g, "'").replace(/[“”]/g, '"')
|
|
44
|
+
.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
45
|
+
const hash = (s) => require('crypto').createHash('sha1').update(String(s)).digest('hex').slice(0, 10);
|
|
46
|
+
|
|
47
|
+
/** Whether the Driver works this row's exit items. A row with nothing missing has its move to make, and that is work too. */
|
|
48
|
+
function workOf(row) {
|
|
49
|
+
if (!row) return { act: false, why: 'not on the line' };
|
|
50
|
+
const base = { station: row.station || null, missing: row.missing || [], next: row.next || null, flag: row.flag || null };
|
|
51
|
+
if (!row.live) return { ...base, act: false, why: `ended: ${row.ended || 'closed'}` };
|
|
52
|
+
if (row.flag === 'cant-tell') return { ...base, act: false, why: `can't tell: ${row.why || 'the records disagree'}` };
|
|
53
|
+
if (row.flag === 'waiting') return { ...base, act: false, why: `waiting: ${row.why || 'nothing to do yet'}` };
|
|
54
|
+
if (!row.station) return { ...base, act: false, why: 'no station' };
|
|
55
|
+
return { ...base, act: true, why: row.missing && row.missing.length ? `${row.missing.length} exit ${row.missing.length === 1 ? 'item' : 'items'} missing` : 'every exit item is done' };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The `exit` fact of one initiative for the unblock sweep. */
|
|
59
|
+
function exitFact(row) {
|
|
60
|
+
if (!row) return null;
|
|
61
|
+
const w = workOf(row);
|
|
62
|
+
return { station: w.station ? w.station.name : null, missing: (w.missing || []).slice(0, 12), next: w.next, flag: w.flag, act: w.act, why: w.why };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** lib/driver.js detect: one exit-missing blocker while the Driver can act on missing items. It wakes a run when the missing set is new
|
|
66
|
+
* for this station, and again every REWAKE_DAYS while it stays the same (state.blockerDays holds `key|day` of every blocker line). */
|
|
67
|
+
function blockerOf(fact, state, { now = Date.now() } = {}) {
|
|
68
|
+
if (!fact || !fact.act || !Array.isArray(fact.missing) || !fact.missing.length) return null;
|
|
69
|
+
const key = `exit-missing:${hash(`${fact.station}|${fact.missing.join('|')}`)}`;
|
|
70
|
+
const seen = state && state.blockerDays instanceof Set ? state.blockerDays : new Set();
|
|
71
|
+
for (const k of seen) {
|
|
72
|
+
const i = k.lastIndexOf('|');
|
|
73
|
+
if (i < 0 || !k.slice(0, i).endsWith(key)) continue;
|
|
74
|
+
const d = Date.parse(k.slice(i + 1) + 'T00:00:00');
|
|
75
|
+
if (Number.isFinite(d) && now - d < REWAKE_DAYS * DAY && now - d >= DAY) return null; // woken for this set less than a week ago
|
|
76
|
+
}
|
|
77
|
+
const items = fact.missing.slice(0, 5);
|
|
78
|
+
return { code: 'exit-missing', key, items, text: `${fact.station}: missing ${items.join('; ')}${fact.missing.length > 5 ? ` (+${fact.missing.length - 5} more)` : ''}` };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The shape of a move's exits: [{ item, quote, ref }], at most 20. */
|
|
82
|
+
function checkExits(data) {
|
|
83
|
+
const list = isObj(data) ? data.exits : undefined;
|
|
84
|
+
if (list === undefined || list === null) return { ok: true, exits: [] };
|
|
85
|
+
if (!Array.isArray(list) || list.length > 20) return { ok: false, error: 'exits is a list of at most 20 { item, quote, ref }' };
|
|
86
|
+
const out = [];
|
|
87
|
+
for (const x of list) {
|
|
88
|
+
if (!isObj(x) || !oneLine(x.item, 200) || typeof x.quote !== 'string' || !x.quote.trim() || x.quote.length > 600 || !oneLine(x.ref, 300)) {
|
|
89
|
+
return { ok: false, error: 'each exit needs item (the To finish line), quote (up to 600 characters, copied word for word) and ref (a file path or a Jira key)' };
|
|
90
|
+
}
|
|
91
|
+
out.push({ item: x.item.trim(), quote: x.quote.trim(), ref: x.ref.trim() });
|
|
92
|
+
}
|
|
93
|
+
return { ok: true, exits: out };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Every exit's quote is found in the record its ref names. readText(ref) → the record's text, or null when PMOS cannot read it. */
|
|
97
|
+
function quoteCheck(exits, readText) {
|
|
98
|
+
const checks = [];
|
|
99
|
+
for (const x of exits || []) {
|
|
100
|
+
const q = norm(x.quote);
|
|
101
|
+
if (q.length < MIN_QUOTE) { checks.push({ item: x.item, ref: x.ref, ok: false, why: `the quote is shorter than ${MIN_QUOTE} characters` }); continue; }
|
|
102
|
+
let text = null;
|
|
103
|
+
try { text = readText(x.ref); } catch { text = null; }
|
|
104
|
+
if (text == null) { checks.push({ item: x.item, ref: x.ref, ok: false, why: `PMOS cannot read ${x.ref}: quote a file in the repository or a Jira key` }); continue; }
|
|
105
|
+
checks.push(norm(text).includes(q) ? { item: x.item, ref: x.ref, ok: true, why: 'quoted word for word' } : { item: x.item, ref: x.ref, ok: false, why: `the quote is not in ${x.ref}` });
|
|
106
|
+
}
|
|
107
|
+
return { ok: checks.length > 0 && checks.every((c) => c.ok), checks };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The exit items of the station a row stands on: its To finish lines, else its one output. */
|
|
111
|
+
function exitItemsOf(boardRow) {
|
|
112
|
+
const st0 = boardRow && boardRow.wfStage;
|
|
113
|
+
if (!st0) return [];
|
|
114
|
+
const st = { ...((boardRow.wfStages || []).find((s) => s.key === st0.key) || {}), ...st0 };
|
|
115
|
+
const finish = Array.isArray(st.finish) ? st.finish.filter((f) => typeof f === 'string' && f.trim()).map((f) => f.trim()) : [];
|
|
116
|
+
if (finish.length) return finish;
|
|
117
|
+
return [st.output && st.output.name ? String(st.output.name).trim() : `what finishes ${st.name}`];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The Checker's gate before PMOS moves a stage by itself. row: the line row; boardRow: the Board's row (its stage's To finish lines). */
|
|
121
|
+
function moveGate({ row, boardRow, exits, from, readText }) {
|
|
122
|
+
const w = workOf(row);
|
|
123
|
+
if (!row || !row.live) return { ok: false, why: 'the initiative is not on the line', checks: [] };
|
|
124
|
+
if (row.flag === 'cant-tell') return { ok: false, why: `can't tell where it stands (${row.why}), so PMOS does not move it`, checks: [] };
|
|
125
|
+
const here = row.station;
|
|
126
|
+
if (!here) return { ok: false, why: 'it has no station', checks: [] };
|
|
127
|
+
if (from && lc(from) !== lc(here.key) && lc(from) !== lc(here.name)) return { ok: false, why: `it moved to ${here.name} since (you or the tracker moved it): the move from ${from} no longer applies`, checks: [] };
|
|
128
|
+
const need = exitItemsOf(boardRow);
|
|
129
|
+
const given = new Map((exits || []).map((x) => [lc(x.item), x]));
|
|
130
|
+
const absent = need.filter((n) => !given.has(lc(n)));
|
|
131
|
+
if (absent.length) return { ok: false, why: `every exit item of ${here.name} needs a quote: missing ${absent.join('; ')}`, checks: [] };
|
|
132
|
+
const q = quoteCheck(need.map((n) => given.get(lc(n))), readText);
|
|
133
|
+
if (!q.ok) return { ok: false, why: q.checks.filter((c) => !c.ok).map((c) => `${c.item}: ${c.why}`).join('; '), checks: q.checks };
|
|
134
|
+
void w;
|
|
135
|
+
return { ok: true, why: `${q.checks.length} of ${q.checks.length} exit items of ${here.name} quote a real record line`, checks: q.checks };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** readText for one repository: a path inside it, or a Jira key the initiative's last read holds (its summary, status and sprint). */
|
|
139
|
+
function readerOf(root, initiative) {
|
|
140
|
+
const top = path.resolve(root);
|
|
141
|
+
let snap;
|
|
142
|
+
return (ref) => {
|
|
143
|
+
const r = String(ref || '').trim();
|
|
144
|
+
if (KEY_RE.test(r)) {
|
|
145
|
+
if (snap === undefined) { try { snap = require('./jira-status.js').readSnapshot(root, initiative); } catch { snap = null; } }
|
|
146
|
+
const t = snap && snap.tickets && snap.tickets.get ? snap.tickets.get(r) : null;
|
|
147
|
+
return t ? [t.key, t.summary, t.status, t.assignee, t.sprint && t.sprint.name, t.resolved].filter(Boolean).join(' · ') : null;
|
|
148
|
+
}
|
|
149
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(r)) return null; // a link: PMOS reads no network here
|
|
150
|
+
const rel = r.replace(/^\/+/, '').replace(/[#:]\d+(-\d+)?$/, '');
|
|
151
|
+
const abs = path.resolve(top, rel);
|
|
152
|
+
if (abs !== top && !abs.startsWith(top + path.sep)) return null;
|
|
153
|
+
try { const s = fs.statSync(abs); if (!s.isFile() || s.size > MAX_FILE) return null; return fs.readFileSync(abs, 'utf8'); } catch { return null; }
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Who holds each of the initiative's tickets and in which sprint, from the last Jira read (lib/jira-status.js). [] when none. */
|
|
158
|
+
function trackerOf(root, initiative) {
|
|
159
|
+
let snap = null;
|
|
160
|
+
try { snap = require('./jira-status.js').readSnapshot(root, initiative); } catch { snap = null; }
|
|
161
|
+
if (!snap || !snap.tickets) return [];
|
|
162
|
+
return [...snap.tickets.values()].filter((t) => t && !t.stale).map((t) => ({
|
|
163
|
+
key: t.key, summary: t.summary || '', category: t.category || 'todo', assignee: t.assignee || null,
|
|
164
|
+
sprint: t.sprint && t.sprint.name ? t.sprint.name : null, start: t.sprint && t.sprint.start ? String(t.sprint.start).slice(0, 10) : null,
|
|
165
|
+
end: t.sprint && t.sprint.end ? String(t.sprint.end).slice(0, 10) : null,
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The work list a Driver run reads. */
|
|
170
|
+
function linesFor(row, tracker = []) {
|
|
171
|
+
const w = workOf(row);
|
|
172
|
+
const out = [];
|
|
173
|
+
if (!row) return ['Not on the line: `pmos line` does not list this initiative.'];
|
|
174
|
+
out.push(`Station: ${w.station ? `${w.station.name} (${w.station.n} of ${w.station.of})` : 'none'} · flag: ${w.flag || 'none'}${row.why ? ` (${row.why})` : ''}.`);
|
|
175
|
+
if (!w.act) { out.push(`Do not work its exit items and do not propose a stage move: ${w.why}.`); return out; }
|
|
176
|
+
if (w.missing.length) {
|
|
177
|
+
out.push(`Missing exit items (the station's To finish lines): ${w.missing.map((m) => `"${m}"`).join('; ')}.`);
|
|
178
|
+
out.push('Work these items first, in this order. For each, file the proposal that gets it done, with its source.');
|
|
179
|
+
} else {
|
|
180
|
+
out.push(`Every exit item is done. Next move: ${w.next}. Propose it with --what move and data {"to": "<stage>", "from": "${w.station.key}", "exits": [{"item": "<each To finish line>", "quote": "<a line copied word for word>", "ref": "<the file path or Jira key it is in>"}]}.`);
|
|
181
|
+
}
|
|
182
|
+
const people = tracker.filter((t) => t.assignee || t.sprint);
|
|
183
|
+
if (people.length) {
|
|
184
|
+
out.push(`Tracker (last Jira read): ${people.slice(0, 15).map((t) => `${t.key} ${t.assignee || 'unassigned'}${t.sprint ? `, ${t.sprint}${t.start && t.end ? ` ${t.start} to ${t.end}` : ''}` : ''}`).join('; ')}${people.length > 15 ? `; +${people.length - 15} more` : ''}.`);
|
|
185
|
+
out.push('When you draft tasks or a scope and timeline, take each owner from its ticket\'s assignee and each date from its sprint, and cite the ticket key.');
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The Board's row of one initiative, read outside HTTP (lib/stage-read.js rowOf). → { ok, board, row } | { ok: false, error } */
|
|
191
|
+
function boardRowOf(root, id) {
|
|
192
|
+
const SR = require('./stage-read.js');
|
|
193
|
+
const { w, ctx } = SR.cliCtx(root);
|
|
194
|
+
const r = SR.rowOf(ctx, w, id);
|
|
195
|
+
return r && r.ok ? { ...r, w, ctx } : { ok: false, error: (r && r.error) || `no initiative ${id} on a board of this workspace` };
|
|
196
|
+
}
|
|
197
|
+
/** A stage move by the board move route's own function (its validation and warnings apply), as `actor`. → { status, body } */
|
|
198
|
+
function boardMove(root, { id, to, why }, actor) {
|
|
199
|
+
const b = boardRowOf(root, id);
|
|
200
|
+
if (!b.ok) return { status: 404, body: { ok: false, error: b.error } };
|
|
201
|
+
return require('./routes-boards.js').move(b.ctx, { ws: b.w.id, board: b.board.id, id, to, why: String(why || '').slice(0, 500) }, { ok: true, actor });
|
|
202
|
+
}
|
|
203
|
+
/** The station an initiative stands on now: { key, name } | null. */
|
|
204
|
+
function stationNow(root, id) {
|
|
205
|
+
const b = boardRowOf(root, id);
|
|
206
|
+
return b.ok && b.row.wfStage ? { key: b.row.wfStage.key, name: b.row.wfStage.name } : null;
|
|
207
|
+
}
|
|
208
|
+
const sameStage = (st, ref) => !!st && !!ref && (lc(st.key) === lc(ref) || lc(st.name) === lc(ref));
|
|
209
|
+
|
|
210
|
+
/** The Checker's quote-check lines of the last 14 days in a state folder: { pass, flag } (the health number, lib/line-driver-count.js). */
|
|
211
|
+
function countChecks(stateDir, now = Date.now()) {
|
|
212
|
+
const since = now - 14 * DAY;
|
|
213
|
+
let pass = 0, flag = 0, txt = '';
|
|
214
|
+
try { txt = fs.readFileSync(path.join(stateDir, 'checker.jsonl'), 'utf8'); } catch { return { pass, flag }; }
|
|
215
|
+
for (const l of txt.split('\n')) {
|
|
216
|
+
let x; try { x = JSON.parse(l); } catch { continue; }
|
|
217
|
+
if (!x || !String(x.reason || '').startsWith(CHECKER_REASON) || !(Date.parse(x.at) >= since)) continue;
|
|
218
|
+
if (x.verdict === 'pass') pass++; else if (x.verdict === 'flag') flag++;
|
|
219
|
+
}
|
|
220
|
+
return { pass, flag };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
module.exports = { countChecks, boardRowOf, boardMove, stationNow, sameStage, workOf, exitFact, blockerOf, checkExits, quoteCheck, exitItemsOf, moveGate, readerOf, trackerOf, linesFor, CHECKER_REASON, REWAKE_DAYS, MIN_QUOTE };
|
|
224
|
+
|
package/workspace/lib/line.js
CHANGED
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* moves: [{ at, to, via }], the Board moves and workflow switches of it (scripts/boards.js fold), oldest first
|
|
11
11
|
* jira: { fetchedAt, epics: [key], tickets: [{ key, category, updated? }] } | null
|
|
12
12
|
* activity: [ISO time] } dated lines that name it: ledger lines, ticket changes, its record's commits
|
|
13
|
-
*
|
|
13
|
+
* settle(p, { doubt, waitsOn }) PURE → the place answer, can't tell when doubt names why its station cannot be trusted (doubtOf), else
|
|
14
|
+
* waiting when it waits on live initiatives its record names as depends_on or predecessor (depsOf)
|
|
15
|
+
* lineOf(root, { only?, now?, derive? }) → { ok, product, rows: [place answer], live, placed, ended } | { ok: false, error, pending? }
|
|
16
|
+
* derive false: read only the rows already derived (the server's sweep); pending while they are not
|
|
14
17
|
* summary(line) → { live, placed, percent }
|
|
15
18
|
*
|
|
16
19
|
* THE STATION IS THE INITIATIVE'S OWN WORKFLOW STAGE (D99), the one the Board and `pmos workflow of` show. Its exit items are the stage's
|
|
@@ -176,24 +179,70 @@ function realHistory(root) {
|
|
|
176
179
|
catch { return false; }
|
|
177
180
|
}
|
|
178
181
|
|
|
179
|
-
|
|
182
|
+
/** Why a station read from the spec files alone cannot be trusted, or null. Two ways the files read Evaluate too early (idpf and
|
|
183
|
+
* microsites, 3 Nov): the engine (scripts/workflow-state.js) sets its stage to eval as soon as any run line names the initiative, a
|
|
184
|
+
* PRD-writing run included (descope-feature-parity, email-otp); and a discovery lane passes Prioritize, which no record signals yet,
|
|
185
|
+
* straight after its spec (update-lightbox-ui-design). When only the files say Evaluate, nothing accepted it, no build is done and no
|
|
186
|
+
* review verdict exists, the station is can't tell. */
|
|
187
|
+
function doubtOf(boardRow, derived) {
|
|
188
|
+
const one = (boardRow && boardRow.oneStage) || {};
|
|
189
|
+
if (one.setBy !== 'files' || one.step !== 'evaluate' || !derived || derived.stage === 'accepted') return null;
|
|
190
|
+
const st = new Map((Array.isArray(derived.steps) ? derived.steps : []).map((x) => [x.key, x.status]));
|
|
191
|
+
if (st.get('build') === 'done' || ['done', 'blocked'].includes(st.get('review'))) return null;
|
|
192
|
+
return 'only the spec files put it in Evaluate, and no build and no review say it got there';
|
|
193
|
+
}
|
|
194
|
+
/** Rule 1 and the dependency word on a placed row: can't tell when its station is doubtful, waiting when it waits on a live initiative.
|
|
195
|
+
* An ended row, or one already can't tell, stays as it is. */
|
|
196
|
+
function settleLine(p, { doubt = null, waitsOn = [] } = {}) {
|
|
197
|
+
if (!p || !p.live || p.flag === 'cant-tell') return p;
|
|
198
|
+
if (doubt) return { ...p, flag: 'cant-tell', why: doubt };
|
|
199
|
+
const w = (waitsOn || []).filter((x) => x && x.id);
|
|
200
|
+
if (!w.length || p.flag === 'waiting') return p;
|
|
201
|
+
return { ...p, flag: 'waiting', why: `waits on ${w.map((x) => `${x.id}${x.station ? ` (${x.station})` : ''}`).join(', ')}`, next: `wait for ${w.map((x) => x.id).join(', ')}` };
|
|
202
|
+
}
|
|
203
|
+
const settle = settleLine;
|
|
204
|
+
/** The initiatives a record names as `depends_on` or `predecessor` (one id, a list in brackets, or YAML list lines). */
|
|
205
|
+
function depsOf(root, rel) {
|
|
206
|
+
if (!rel) return [];
|
|
207
|
+
let txt = '';
|
|
208
|
+
try { txt = fs.readFileSync(path.join(root, rel), 'utf8'); } catch { return []; }
|
|
209
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---/.exec(txt);
|
|
210
|
+
if (!m) return [];
|
|
211
|
+
const out = [];
|
|
212
|
+
const lines = m[1].split(/\r?\n/);
|
|
213
|
+
for (let i = 0; i < lines.length; i++) {
|
|
214
|
+
const kv = /^(depends_on|predecessor):\s*(.*)$/.exec(lines[i]);
|
|
215
|
+
if (!kv) continue;
|
|
216
|
+
const v = kv[2].trim();
|
|
217
|
+
if (v) out.push(...v.replace(/^\[|\]$/g, '').split(','));
|
|
218
|
+
else for (let j = i + 1; j < lines.length && /^\s+-\s*/.test(lines[j]); j++) out.push(lines[j].replace(/^\s+-\s*/, ''));
|
|
219
|
+
}
|
|
220
|
+
return [...new Set(out.map((x) => x.trim().replace(/^["']|["']$/g, '')).filter((x) => /^[a-z0-9][a-z0-9._-]*$/i.test(x)))];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function lineOf(root, { only = null, now = Date.now(), derive = true } = {}) {
|
|
180
224
|
const SR = require('./stage-read.js');
|
|
181
225
|
const boards = require('./routes-boards.js');
|
|
182
226
|
const rowsLib = require('./initiative-rows.js');
|
|
183
227
|
const { w, ctx } = SR.cliCtx(root);
|
|
184
228
|
const stateDir = ctx.stateDirFor();
|
|
185
229
|
if (!stateDir) return { ok: false, error: 'this repository has no PMOS state folder (pmos/state, state or .pmos)' };
|
|
186
|
-
const was = rowsLib.setBackground(false);
|
|
230
|
+
const was = derive ? rowsLib.setBackground(false) : null;
|
|
187
231
|
try {
|
|
188
|
-
|
|
232
|
+
// derive false (the server's sweep, lib/driver-facts.js): read the rows the server already holds, never derive them inside its tick
|
|
233
|
+
if (derive) { try { rowsLib.deriveNow(root); } catch { /* baseRows says what could not be read */ } }
|
|
189
234
|
const pass = { ...ctx, boardsPass: new Map() };
|
|
190
235
|
const base = boards.baseRows(w, pass);
|
|
236
|
+
if (base.pending) return { ok: false, pending: true, error: 'the initiative records are still being read' };
|
|
191
237
|
if (!base.ok) return { ok: false, error: base.error || 'the initiative records could not be read' };
|
|
192
238
|
let ids = base.rows.map((r) => r.id);
|
|
193
239
|
if (only) { if (!ids.includes(only)) return { ok: false, error: `no initiative ${only} on a board of this workspace` }; ids = [only]; }
|
|
194
240
|
const folded = boards.foldOf(pass, w);
|
|
195
241
|
const acts = activityIndex([stateDir, path.join(root, 'planning', 'runs')], new Set(ids));
|
|
196
242
|
const real = realHistory(root);
|
|
243
|
+
let derived = new Map();
|
|
244
|
+
try { const pk = rowsLib.peek(root); if (pk && pk.ok) derived = new Map(pk.rows.map((x) => [x.id, x])); } catch { derived = new Map(); }
|
|
245
|
+
const liveIds = new Set(base.rows.filter((x) => !(x.status === 'done' || x.lifecycle)).map((x) => x.id));
|
|
197
246
|
let JS = null; try { JS = require('./jira-status.js'); } catch { JS = null; }
|
|
198
247
|
let JT = null; try { JT = require('./jira-tickets.js'); } catch { JT = null; }
|
|
199
248
|
const rows = [];
|
|
@@ -216,11 +265,19 @@ function lineOf(root, { only = null, now = Date.now() } = {}) {
|
|
|
216
265
|
}
|
|
217
266
|
const recRel = typeof b0.record === 'string' ? path.relative(root, path.resolve(root, b0.record)) : null;
|
|
218
267
|
const activity = (acts.get(id) || []).concat(gitTimes(root, recRel, real));
|
|
219
|
-
|
|
268
|
+
const deps = depsOf(root, recRel).filter((d) => d !== id && liveIds.has(d));
|
|
269
|
+
rows.push({ deps, doubt: doubtOf(r.row, derived.get(id)), p: place({ row: r.row, tasks, moves, jira, activity }, now) });
|
|
270
|
+
}
|
|
271
|
+
// a dependency counts while it is itself live on the line (not ended): waiting on it is never stuck
|
|
272
|
+
const first = new Map(rows.map((x) => [x.p.id, x.p]));
|
|
273
|
+
for (let i = 0; i < rows.length; i++) {
|
|
274
|
+
const x = rows[i];
|
|
275
|
+
const waitsOn = x.deps.map((d) => first.get(d) || { id: d, live: true, station: null }).filter((p) => p && p.live).map((p) => ({ id: p.id, station: p.station ? p.station.name : null }));
|
|
276
|
+
rows[i] = settle(x.p, { doubt: x.doubt, waitsOn });
|
|
220
277
|
}
|
|
221
278
|
const live = rows.filter((x) => x.live);
|
|
222
279
|
return { ok: true, product: path.basename(root), rows, live: live.length, placed: live.filter((x) => x.station && x.next).length, ended: rows.length - live.length };
|
|
223
|
-
} finally { rowsLib.setBackground(was); }
|
|
280
|
+
} finally { if (derive) rowsLib.setBackground(was); }
|
|
224
281
|
}
|
|
225
282
|
|
|
226
283
|
function summary(line) {
|
|
@@ -228,4 +285,4 @@ function summary(line) {
|
|
|
228
285
|
return { live, placed, percent: live ? Math.round((placed / live) * 1000) / 10 : 0 };
|
|
229
286
|
}
|
|
230
287
|
|
|
231
|
-
module.exports = { place, lineOf, summary, missingOf, limitOf, activityIndex, LIMITS, STALE_DAYS };
|
|
288
|
+
module.exports = { place, lineOf, summary, missingOf, limitOf, activityIndex, doubtOf, depsOf, settle, LIMITS, STALE_DAYS };
|
|
@@ -41,6 +41,7 @@ const PROVIDERS = Object.freeze([
|
|
|
41
41
|
'decision-journal-needs', // decision-journal-outcome-checks: a journal decision whose check date came, with no verdict (kind 1)
|
|
42
42
|
'parked-reasons', // parked-reason-way-back (bet A446): a parked initiative whose way back is met, to bring back (kind 7)
|
|
43
43
|
'product-health', // product-health-score: a product's health score fell 10 points or more against its past week (kind 8)
|
|
44
|
+
'setup-station', // setup-station: a product that has not passed Setup (tracker read, agreed goal, owner), with the next ✦ (kind 7)
|
|
44
45
|
]);
|
|
45
46
|
/** Kinds that already mean something in the needs queue. A provider may not reuse one. */
|
|
46
47
|
const RESERVED_KINDS = Object.freeze(['question', 'accept', 'outcome', 'keep', 'evidence', 'plan-flag', 'provider-error']);
|
|
@@ -175,10 +175,13 @@ const VERBS = Object.freeze({
|
|
|
175
175
|
owner: Object.freeze({ module: 'owner-cli.js', run: null, guide: 'cli.md',
|
|
176
176
|
help: 'pmos owner brief|budget — a unit owner\'s daily brief now, and its Driver runs a day (pmos owner help)' }),
|
|
177
177
|
driver: Object.freeze({ module: 'driver-cli.js', run: null, guide: 'cli.md',
|
|
178
|
-
help: 'pmos driver propose|status|keep|return|drop|undo|pause|resume|mode … — the Initiative Driver: class A and B changes apply with Undo, the rest wait for you (pmos driver help)' }),
|
|
178
|
+
help: 'pmos driver propose|status|exits|keep|return|drop|undo|pause|resume|mode … — the Initiative Driver: class A and B changes apply with Undo, the rest wait for you (pmos driver help)' }),
|
|
179
179
|
// one-change-record-no-source-no-auto: everything PMOS changed by itself, in one record (lib/change-record.js)
|
|
180
180
|
health: Object.freeze({ module: 'product-health-cli.js', run: null, guide: 'cli.md',
|
|
181
181
|
help: 'pmos health [score|trend|drops] — this product\'s health score (0 to 100), its trend this month and its past drops (pmos health help)' }),
|
|
182
|
+
// Not a pm-os-absorb verb (run: null): initiative setup-station (product line slice 5) added it through the same table.
|
|
183
|
+
setup: Object.freeze({ module: 'setup-cli.js', run: null, guide: 'cli.md',
|
|
184
|
+
help: 'pmos setup [agree goal|owner "<name>"|undo] — the Setup station of a new product: tracker read, an agreed goal and an owner (pmos setup help)' }),
|
|
182
185
|
factory: Object.freeze({ module: 'factory-cli.js', run: null, guide: 'cli.md',
|
|
183
186
|
help: 'pmos factory today [--days N] — everything PMOS changed by itself, per line and station, with what cites no source (pmos factory help)' }),
|
|
184
187
|
// D106 (Full autonomy now): what agents do by themselves, and the goals they work on until done
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* setup-cli.js — `pmos setup`: the Setup station of this product (initiative setup-station). The work is in lib/setup-station.js; this file
|
|
3
|
+
* is the verb's entry in lib/pmos-verbs.js. Reads, except the two approvals (agree goal, owner) and their undo. */
|
|
4
|
+
const S = require('./setup-station.js');
|
|
5
|
+
|
|
6
|
+
const COMMANDS = S.COMMANDS;
|
|
7
|
+
const USAGE = S.USAGE;
|
|
8
|
+
function run(argv, { say = (s) => console.log(s) } = {}) {
|
|
9
|
+
const args = argv[0] === 'setup' ? argv.slice(1) : argv.slice();
|
|
10
|
+
return S.cli(args, { say });
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { COMMANDS, USAGE, run };
|