create-pmos 0.841.0 → 0.843.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 +59 -54
- 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 +58 -0
- package/workspace/guide/cli.md +24 -0
- package/workspace/guide/layout.md +3 -0
- package/workspace/guide/settings-and-switches.md +1 -0
- package/workspace/lib/build-engine.js +4 -1
- package/workspace/lib/copy-tests.js +281 -0
- package/workspace/lib/events-place.js +38 -2
- package/workspace/lib/factory-traces.js +2 -1
- package/workspace/lib/features.json +2 -0
- package/workspace/lib/initiative-cost.js +259 -0
- package/workspace/lib/pmos-verbs.js +6 -0
- package/workspace/lib/routes-artefacts.js +31 -1
- package/workspace/lib/routes-factory-metrics.js +54 -1
- package/workspace/lib/routes-proposals.js +7 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/bd-backlog.css +3 -0
- package/workspace/public/pm/bd-backlog.js +36 -7
- package/workspace/public/pm/bd-pop-ds.js +8 -4
- package/workspace/public/pm/copy-tests.js +95 -0
- package/workspace/public/pm/cozy-events-view.js +16 -2
- package/workspace/public/pm/cozy-events.css +5 -1
- package/workspace/public/pm/cozy-events.js +6 -1
- package/workspace/public/pm/cozy-pop-work.js +14 -1
- package/workspace/public/pm/initiative-cost.js +103 -0
- package/workspace/public/pm/pop-work-model.js +2 -1
- package/workspace/test-lists/copy-tests.json +9 -0
- package/workspace/test-lists/events-bring.json +9 -0
- package/workspace/test-lists/initiative-cost.json +9 -0
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* marks { fixed: Set<key>, declined: Set<sig> } the PM's fixed dates and the suggestions they said no to (lib/routes-events-place.js)
|
|
20
20
|
*
|
|
21
21
|
* AN ITEM: { key, kind, type, date, time, until, title, line, product, work, task, own, jira, source, scope, fixed, canFix, editable, tone, days,
|
|
22
|
-
* group, suggest, act }
|
|
22
|
+
* group, suggest, act, bring }
|
|
23
23
|
* kind milestone (a ◇ task, a program milestone, or the plan end of an initiative that has no open milestone) · task · report · meeting
|
|
24
24
|
* · deadline (a date stated in a source)
|
|
25
25
|
* type the one word the row starts its grey line with (TYPE_WORD), and the filter of the key: meeting · focus · milestone · task · report
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
* group late (before today, not done) · today · coming (the next WINDOW_DAYS days; a meeting the next MEET_DAYS) · later ·
|
|
32
32
|
* past (a meeting before today: never late, shown when the PM picks its day, and a mark on the calendar)
|
|
33
33
|
* tone late · risk (a milestone of an initiative at risk, or whose Jira forecast says it will miss) · ''
|
|
34
|
+
* bring a meeting today or coming that is about a piece of work or a product: { text, calls: [{ key, text }], more }, what to bring
|
|
35
|
+
* (board TbEvents): its work's or product's late dates, dates at risk and dates due by its day; none: "Nothing new for this one yet."
|
|
36
|
+
* Focus time, a passed meeting, and a meeting tied to no work or product have none (null).
|
|
34
37
|
* suggest { op: done | move | drop | met | gone | ask, to?, with?, ask?, text, why, sig } or null. What PMOS suggests; the PM says yes (✓)
|
|
35
38
|
* or no (✕). met and gone are kept by Events (the date is met, or dropped: Events stops listing it); ask adds a task for the PM.
|
|
36
39
|
*
|
|
@@ -118,6 +121,27 @@ const norm = (s) => String(s || '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').tr
|
|
|
118
121
|
/** Does `text` hold `phrase` as whole words? */
|
|
119
122
|
const hasWords = (text, phrase) => { const p = norm(phrase); return p.length >= 3 && (' ' + norm(text) + ' ').includes(' ' + p + ' '); };
|
|
120
123
|
|
|
124
|
+
const NUM = ['', 'one', 'two', 'three'];
|
|
125
|
+
/** What to bring to meeting `m`: its work's or product's late dates, dates at risk, and dates due on or before its day. Up to BRING_MAX
|
|
126
|
+
* calls, each naming a date this model lists (its key). → { text, calls: [{ key, text }], more } */
|
|
127
|
+
const BRING_MAX = 3;
|
|
128
|
+
function bringOf(m, mine, today) {
|
|
129
|
+
const late = mine.filter((y) => y.group === 'late').sort((a, b) => a.date.localeCompare(b.date));
|
|
130
|
+
const risk = mine.filter((y) => y.group !== 'late' && y.tone === 'risk' && y.date <= m.date).sort((a, b) => a.date.localeCompare(b.date));
|
|
131
|
+
const due = mine.filter((y) => y.group !== 'late' && y.tone !== 'risk' && y.date <= m.date).sort((a, b) => a.date.localeCompare(b.date));
|
|
132
|
+
const when = (y) => (y.date === today ? 'today' : shortDay(y.date, today));
|
|
133
|
+
const calls = [];
|
|
134
|
+
if (late.length === 1) calls.push({ key: late[0].key, text: late[0].title + ' is ' + (-late[0].days) + ' ' + (late[0].days === -1 ? 'day' : 'days') + ' late' });
|
|
135
|
+
else if (late.length > 1) calls.push({ key: late[0].key, keys: late.map((y) => y.key), text: late.length + ' dates are late, the oldest ' + late[0].title });
|
|
136
|
+
for (const y of risk) calls.push({ key: y.key, text: y.title + ' may slip, due ' + when(y) });
|
|
137
|
+
for (const y of due) calls.push({ key: y.key, text: y.title + ' is due ' + when(y) });
|
|
138
|
+
if (!calls.length) return { text: 'Nothing new for this one yet.', calls: [], more: 0 };
|
|
139
|
+
const shown = calls.slice(0, BRING_MAX), more = calls.length - shown.length;
|
|
140
|
+
const text = 'Bring ' + NUM[shown.length] + ' ' + (shown.length === 1 ? 'call' : 'calls') + ': ' + shown.map((c) => c.text).join('; ') + '.'
|
|
141
|
+
+ (more ? ' And ' + more + ' more ' + (more === 1 ? 'date' : 'dates') + '.' : '');
|
|
142
|
+
return { text, calls: shown, more };
|
|
143
|
+
}
|
|
144
|
+
|
|
121
145
|
function build(input = {}) {
|
|
122
146
|
const today = isDay(input.today) ? day10(input.today) : null;
|
|
123
147
|
if (!today) return { today: null, items: [], later: { count: 0, next: null }, filters: { products: [], programs: [], projects: [] } };
|
|
@@ -393,6 +417,18 @@ function build(input = {}) {
|
|
|
393
417
|
delete x.oldDrafts;
|
|
394
418
|
}
|
|
395
419
|
|
|
420
|
+
// what to bring (board TbEvents): each meeting today or coming that is about a piece of work or a product says, by itself, which of that
|
|
421
|
+
// work's or product's own dates need a call there. Only dates this model lists; nothing is written or asked.
|
|
422
|
+
for (const x of items) {
|
|
423
|
+
x.bring = null;
|
|
424
|
+
if (x.kind !== 'meeting' || x.type !== 'meeting' || (x.group !== 'today' && x.group !== 'coming')) continue;
|
|
425
|
+
const proj = x.scope.filter((t) => t.startsWith('j:')), prod = x.scope.filter((t) => t.startsWith('p:'));
|
|
426
|
+
const by = proj.length ? proj : prod;
|
|
427
|
+
if (!by.length) continue;
|
|
428
|
+
const mine = items.filter((y) => y !== x && y.kind !== 'meeting' && (y.scope || []).some((t) => by.includes(t)));
|
|
429
|
+
x.bring = bringOf(x, mine, today);
|
|
430
|
+
}
|
|
431
|
+
|
|
396
432
|
const ORDER = { past: 0, late: 1, today: 2, coming: 3, later: 4 };
|
|
397
433
|
// Late: the newest first, so the dates you can still save come before the old ones. A day: the dates with no time first, then by time
|
|
398
434
|
items.sort((a, b) => ORDER[a.group] - ORDER[b.group] || (a.group === 'late' ? b.date.localeCompare(a.date) : a.date.localeCompare(b.date)) || String(a.time || '').localeCompare(String(b.time || '')) || a.title.localeCompare(b.title));
|
|
@@ -410,4 +446,4 @@ function build(input = {}) {
|
|
|
410
446
|
filters: { products: named(products), programs: named(programs), projects: named(projects) } };
|
|
411
447
|
}
|
|
412
448
|
|
|
413
|
-
module.exports = { build, shortDay, daysBetween, KINDS, TYPES, TYPE_WORD, FOCUS, DROP_DAYS, OLD_DAYS, WINDOW_DAYS, MEET_DAYS };
|
|
449
|
+
module.exports = { build, bringOf, BRING_MAX, shortDay, daysBetween, KINDS, TYPES, TYPE_WORD, FOCUS, DROP_DAYS, OLD_DAYS, WINDOW_DAYS, MEET_DAYS };
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* THE TRACE. <product state>/factory-traces.jsonl (pmos/state: runtime, gitignored, never a control-graph record). One line per Builder
|
|
13
13
|
* or reviewer run that named a work item (`pmos build claim|propose|open|policy|status <item>`):
|
|
14
|
-
* { at, kind: 'run', item, role, turns, tools: { Name: count }, files: [rel], model, input, cacheCreate, cacheRead, output, costUsd, ok }
|
|
14
|
+
* { at, kind: 'run', item, role, turns, tools: { Name: count }, files: [rel], model, input, cacheCreate, cacheRead, output, costUsd, ms, ok }
|
|
15
15
|
* tools are the tool NAMES the run called; files are the paths Write and Edit touched, relative to the item's worktree. The tokens and the
|
|
16
16
|
* cost come from lib/headless.js parseResult and usageOf, the same reads lib/run-tokens.js keeps. No line holds a prompt, an answer, a
|
|
17
17
|
* tool input, a command or a key. The server writes the line after the run ends, from the run's own stdout: the Builder's run gains no
|
|
@@ -105,6 +105,7 @@ function record(stateDir, { item, role = '', result = null, tracker: t = null, o
|
|
|
105
105
|
model: typeof r.model === 'string' ? r.model.slice(0, 80) : null,
|
|
106
106
|
input: num(tk.input), cacheCreate: num(tk.cacheCreate), cacheRead: num(tk.cacheRead), output: num(tk.output),
|
|
107
107
|
costUsd: Number.isFinite(r.costUsd) ? Math.round(r.costUsd * 10000) / 10000 : null,
|
|
108
|
+
ms: Number.isFinite(r.durationMs) && r.durationMs >= 0 ? Math.round(r.durationMs) : null, // the run's time: agent hours (lib/initiative-cost.js)
|
|
108
109
|
ok: ok == null ? null : !!ok,
|
|
109
110
|
});
|
|
110
111
|
}
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
{"id": "rules", "audience": "user", "status": "ga", "group": "What PMOS did", "name": "Rules PMOS learned", "say": "The standing rules PMOS learned from your corrections, and edit or retire one.", "cmd": "/rules", "verb": "rules"},
|
|
62
62
|
{"id": "line", "audience": "user", "status": "ga", "group": "Catch up", "name": "Where each initiative stands", "say": "Days in its stage, what is missing, the next move, and whether it is stuck.", "cmd": "/line", "verb": "line", "hint": "<initiative>", "ask": ["initiative"]},
|
|
63
63
|
{"id": "hire", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "The next hire", "say": "The role your open work most needs, and a one-page role brief to edit.", "cmd": "/hire", "verb": "hire"},
|
|
64
|
+
{"id": "experiment", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Copy and layout tests", "say": "Try new words or a new layout on an initiative: PMOS drafts the test, you start it, one line says how sure the winner is.", "cmd": "/experiment", "verb": "experiment", "hint": "draft <initiative> \"<what to try>\""},
|
|
64
65
|
{"id": "review", "audience": "user", "status": "ga", "group": "Before you ship", "name": "Built beside its design", "say": "The built screen beside its design, each difference circled and numbered. Accept it, or send a difference back as a fix.", "cmd": "/built-vs-design", "verb": "review", "sub": "list", "hint": "<initiative>", "place": "board"},
|
|
65
66
|
{"id": "story-map", "audience": "user", "status": "ga", "group": "Plan and decide", "name": "Story map", "say": "A new bet's user journey left to right, with the Release 1 line to move tasks across.", "cmd": "/story-map", "verb": "story-map", "hint": "<initiative>"},
|
|
66
67
|
{"id": "print", "audience": "user", "status": "ga", "group": "Your product", "name": "Print or PDF", "say": "One clean page of a report or an initiative, to print or save as PDF.", "cmd": "/print", "verb": "print", "hint": "<file or initiative>"},
|
|
@@ -92,6 +93,7 @@
|
|
|
92
93
|
{"id": "source", "audience": "agent", "status": "ga", "group": "Catch up", "name": "Stored tool reads", "say": "An agent session saves its read of a tool for the Briefing.", "cmd": "/source", "verb": "source"},
|
|
93
94
|
{"id": "refresh", "audience": "agent", "status": "ga", "group": "Catch up", "name": "Read only what changed", "say": "An agent session asks a tool what changed since the last read.", "cmd": "/refresh", "verb": "refresh"},
|
|
94
95
|
{"id": "lead", "audience": "agent", "status": "ga", "group": "Catch up", "name": "A popup's lead", "say": "PMOS writes a popup's short lead ahead, from stored reads.", "cmd": "/lead", "verb": "lead"},
|
|
96
|
+
{"id": "cost", "audience": "user", "status": "beta", "group": "What PMOS did", "name": "What the factory spent", "say": "Agent hours and spend per initiative and per merged pull request. Pause one that spends with no merge.", "cmd": "/spend", "verb": "cost", "place": "board", "since": "0.825.0"},
|
|
95
97
|
{"id": "propose", "audience": "agent", "status": "ga", "group": "What PMOS did", "name": "File a suggestion", "say": "A PMOS run files what it found under an initiative's ✦ for you to keep or drop.", "cmd": "/propose", "verb": "propose"},
|
|
96
98
|
{"id": "lab", "audience": "agent", "status": "ga", "group": "What PMOS did", "name": "The idle lab", "say": "What the idle lab's runs read and filed while you were away.", "cmd": "/lab", "verb": "lab"},
|
|
97
99
|
{"id": "metrics", "audience": "agent", "status": "ga", "group": "Your product", "name": "Metric drafts", "say": "A metric-draft run files a metric for you to keep or drop.", "cmd": "/metrics", "verb": "metrics"},
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* initiative-cost.js — what each initiative and each merged pull request cost the factory, and a pause for one that spends without a
|
|
3
|
+
* result (initiative initiative-cost, job #1906, idea A17; board BatchReleaseDS panel 21, agreed 2026-11-25). `pmos cost`.
|
|
4
|
+
*
|
|
5
|
+
* THE SOURCES, all the product's own, read-only here:
|
|
6
|
+
* traces <state>/factory-traces.jsonl (lib/factory-traces.js): one `run` line per Builder or reviewer run on a work item, with its
|
|
7
|
+
* tokens, its cost in dollars and (since this build) its time `ms`. An item `<initiative>.<n>` belongs to <initiative>.
|
|
8
|
+
* ledger <factory>/planning/work-items.jsonl: `integrated` or `shipped` is a merged item; `declared` carries its criterion.
|
|
9
|
+
* prs <state>/proposals.jsonl: a kept build ✦ wrote { op: 'pr', item, url }, the pull request PMOS opened for the item.
|
|
10
|
+
* THE ONE STORE this module writes: <state>/initiative-pause.jsonl, { at, by, ini, kind: 'pause' | 'resume', why }. The last line for an
|
|
11
|
+
* initiative wins. The UI (POST /api/initiative-cost/*), the ✦ (lib/routes-proposals.js group cost) and `pmos cost pause|resume` all write
|
|
12
|
+
* it through pause() and resume(), and lib/build-engine.js reads pausedOf().
|
|
13
|
+
*
|
|
14
|
+
* A PAUSE stops NEW jobs only: build-engine next() offers no declared item of a paused initiative and claim() refuses one. An item a
|
|
15
|
+
* Builder already holds keeps its claim, its worktree and its fix rounds, so running work finishes. Nothing here writes the work-item ledger.
|
|
16
|
+
*
|
|
17
|
+
* A STALL: the initiative's factory spent in the last STALL_DAYS days, and it has had no merge for STALL_DAYS days, counted from its last
|
|
18
|
+
* merge or, with none, from its first run. The proposal pass files ONE ✦ (group cost, type pause, class C: only the PM's ✓ pauses) per
|
|
19
|
+
* stall: its id carries the stall's start, so a ✕ or a ✓ is never asked again for the same stall. A ✦ whose initiative merged, stopped
|
|
20
|
+
* spending or was paused another way is dropped (zero is silence). Money is the Cost tab's alone: the ✦ title and why name no amount.
|
|
21
|
+
*
|
|
22
|
+
* costOf({ traces, ledger, prs, pauses, now }) PURE → { total: { costUsd, tokens, hours, runs }, rows: [row] }
|
|
23
|
+
* row { ini, runs, costUsd, tokens, hours, merged, prs: [{ item, title, costUsd, tokens, hours, url, mergedAt }], firstRunAt,
|
|
24
|
+
* lastRunAt, lastMergeAt, recentUsd (spent in the last STALL_DAYS), sinceUsd (spent since the stall's start), stall: { since } | null,
|
|
25
|
+
* paused }
|
|
26
|
+
* iniOf(item) · pausedOf(sd) → Set · pause(sd, ini, o) · resume(sd, ini, o) · readOf(root, { now }) → costOf over the repository's files
|
|
27
|
+
* proposePass(root, { now, stateDir? }) → { ok, filed: [id], dropped: [id] } never throws
|
|
28
|
+
* lines(C) · prLines(row) · run(argv, o) the CLI
|
|
29
|
+
* Nothing here calls a model or sends anything. */
|
|
30
|
+
const fs = require('fs');
|
|
31
|
+
const path = require('path');
|
|
32
|
+
|
|
33
|
+
const FILE = 'initiative-pause.jsonl';
|
|
34
|
+
const TAG = '[initiative-cost]';
|
|
35
|
+
const BY = 'agent:initiative-cost';
|
|
36
|
+
const DAY = 86400000;
|
|
37
|
+
const STALL_DAYS = 7;
|
|
38
|
+
const ITEM_RE = /^([a-z0-9][a-z0-9_-]*)\.[0-9]+$/;
|
|
39
|
+
const ID_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
40
|
+
|
|
41
|
+
const num = (v) => (Number.isFinite(Number(v)) && Number(v) >= 0 ? Number(v) : 0);
|
|
42
|
+
const tOf = (at) => { const t = Date.parse(at); return Number.isFinite(t) ? t : null; };
|
|
43
|
+
const r2 = (n) => Math.round(n * 100) / 100;
|
|
44
|
+
const r1 = (n) => Math.round(n * 10) / 10;
|
|
45
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
46
|
+
const iniOf = (item) => { const m = ITEM_RE.exec(String(item || '')); return m ? m[1] : null; };
|
|
47
|
+
|
|
48
|
+
function readJsonl(file) {
|
|
49
|
+
let text = '';
|
|
50
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
51
|
+
const out = [];
|
|
52
|
+
for (const s of text.split('\n')) { if (!s.trim()) continue; try { const o = JSON.parse(s); if (o && typeof o === 'object') out.push(o); } catch { /* a torn line */ } }
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* ── the pause store ── */
|
|
57
|
+
const pauseFile = (sd) => (sd ? path.join(sd, FILE) : null);
|
|
58
|
+
function pausesOf(sd) { return sd ? readJsonl(pauseFile(sd)) : []; }
|
|
59
|
+
/** PURE over the lines: the initiatives whose last line is a pause. */
|
|
60
|
+
function pausedSet(lines) {
|
|
61
|
+
const last = new Map();
|
|
62
|
+
for (const l of lines || []) if (l && ID_RE.test(String(l.ini || '')) && (l.kind === 'pause' || l.kind === 'resume')) last.set(l.ini, l.kind);
|
|
63
|
+
return new Set([...last].filter(([, k]) => k === 'pause').map(([i]) => i));
|
|
64
|
+
}
|
|
65
|
+
const pausedOf = (sd) => pausedSet(pausesOf(sd));
|
|
66
|
+
function write(sd, ini, kind, { by = 'pm', why = '', now = Date.now() } = {}) {
|
|
67
|
+
if (!sd) return { ok: false, error: 'this product has no state folder' };
|
|
68
|
+
if (!ID_RE.test(String(ini || ''))) return { ok: false, error: 'name an initiative' };
|
|
69
|
+
const on = pausedOf(sd).has(ini);
|
|
70
|
+
if (kind === 'pause' && on) return { ok: true, already: true, ini };
|
|
71
|
+
if (kind === 'resume' && !on) return { ok: true, already: true, ini };
|
|
72
|
+
const line = { at: new Date(now).toISOString(), by: one(by, 60) || 'pm', ini, kind, ...(why ? { why: one(why, 200) } : {}) };
|
|
73
|
+
try { fs.mkdirSync(sd, { recursive: true }); fs.appendFileSync(pauseFile(sd), JSON.stringify(line) + '\n'); } catch (e) { return { ok: false, error: one(e && e.message, 160) }; }
|
|
74
|
+
console.info(`${TAG} ${kind} ${ini}`);
|
|
75
|
+
return { ok: true, ini, line };
|
|
76
|
+
}
|
|
77
|
+
const pause = (sd, ini, o) => write(sd, ini, 'pause', o);
|
|
78
|
+
const resume = (sd, ini, o) => write(sd, ini, 'resume', o);
|
|
79
|
+
|
|
80
|
+
/* ── the fold ── */
|
|
81
|
+
/** PURE. prs: [{ item, url }]; pauses: the pause store's lines. */
|
|
82
|
+
function costOf({ traces = [], ledger = [], prs = [], pauses = [], now = Date.now() } = {}) {
|
|
83
|
+
const from = now - STALL_DAYS * DAY;
|
|
84
|
+
const mergedAt = new Map(), title = new Map(), urlOf = new Map();
|
|
85
|
+
for (const e of ledger || []) {
|
|
86
|
+
if (!e || typeof e.item_id !== 'string') continue;
|
|
87
|
+
if (e.event === 'declared' && e.criterion) title.set(e.item_id, one(e.criterion, 120));
|
|
88
|
+
const t = tOf(e.at);
|
|
89
|
+
if ((e.event === 'integrated' || e.event === 'shipped') && t != null && !mergedAt.has(e.item_id)) mergedAt.set(e.item_id, t);
|
|
90
|
+
}
|
|
91
|
+
for (const p of prs || []) if (p && p.item && p.url) urlOf.set(p.item, String(p.url));
|
|
92
|
+
const paused = pausedSet(pauses);
|
|
93
|
+
const by = new Map(), items = new Map();
|
|
94
|
+
const row = (ini) => { if (!by.has(ini)) by.set(ini, { ini, runs: 0, costUsd: 0, tokens: 0, ms: 0, firstRunAt: null, lastRunAt: null, runAts: [] }); return by.get(ini); };
|
|
95
|
+
for (const l of traces || []) {
|
|
96
|
+
if (!l || l.kind !== 'run') continue;
|
|
97
|
+
const ini = iniOf(l.item), t = tOf(l.at);
|
|
98
|
+
if (!ini || t == null || t > now) continue;
|
|
99
|
+
const x = row(ini), usd = num(l.costUsd), tk = num(l.input) + num(l.cacheCreate) + num(l.cacheRead) + num(l.output), ms = num(l.ms);
|
|
100
|
+
x.runs += 1; x.costUsd += usd; x.tokens += tk; x.ms += ms; x.runAts.push([t, usd]);
|
|
101
|
+
if (x.firstRunAt == null || t < x.firstRunAt) x.firstRunAt = t;
|
|
102
|
+
if (x.lastRunAt == null || t > x.lastRunAt) x.lastRunAt = t;
|
|
103
|
+
if (!items.has(l.item)) items.set(l.item, { item: l.item, costUsd: 0, tokens: 0, ms: 0 });
|
|
104
|
+
const it = items.get(l.item); it.costUsd += usd; it.tokens += tk; it.ms += ms;
|
|
105
|
+
}
|
|
106
|
+
const rows = [...by.values()].map((x) => {
|
|
107
|
+
const mine = [...items.values()].filter((it) => iniOf(it.item) === x.ini && mergedAt.has(it.item));
|
|
108
|
+
const merges = mine.map((it) => mergedAt.get(it.item)).filter((t) => t <= now);
|
|
109
|
+
const lastMergeAt = merges.length ? Math.max(...merges) : null;
|
|
110
|
+
const start = lastMergeAt != null ? lastMergeAt : x.firstRunAt;
|
|
111
|
+
const recentUsd = x.runAts.filter(([t]) => t >= from).reduce((s, [, u]) => s + u, 0);
|
|
112
|
+
const sinceUsd = x.runAts.filter(([t]) => lastMergeAt == null || t > lastMergeAt).reduce((s, [, u]) => s + u, 0);
|
|
113
|
+
const stalled = x.runAts.some(([t]) => t >= from) && start != null && now - start >= STALL_DAYS * DAY && (lastMergeAt == null || x.lastRunAt > lastMergeAt);
|
|
114
|
+
return {
|
|
115
|
+
ini: x.ini, runs: x.runs, costUsd: r2(x.costUsd), tokens: x.tokens, hours: r1(x.ms / 3600000), merged: mine.length,
|
|
116
|
+
prs: mine.sort((a, b) => mergedAt.get(b.item) - mergedAt.get(a.item)).map((it) => ({ item: it.item, title: title.get(it.item) || '', costUsd: r2(it.costUsd), tokens: it.tokens, hours: r1(it.ms / 3600000), url: urlOf.get(it.item) || '', mergedAt: new Date(mergedAt.get(it.item)).toISOString() })),
|
|
117
|
+
firstRunAt: new Date(x.firstRunAt).toISOString(), lastRunAt: new Date(x.lastRunAt).toISOString(), lastMergeAt: lastMergeAt == null ? null : new Date(lastMergeAt).toISOString(),
|
|
118
|
+
recentUsd: r2(recentUsd), sinceUsd: r2(sinceUsd), stall: stalled ? { since: new Date(start).toISOString() } : null, paused: paused.has(x.ini),
|
|
119
|
+
};
|
|
120
|
+
}).sort((a, b) => b.costUsd - a.costUsd || b.runs - a.runs || a.ini.localeCompare(b.ini));
|
|
121
|
+
const total = rows.reduce((s, r) => ({ costUsd: s.costUsd + r.costUsd, tokens: s.tokens + r.tokens, hours: s.hours + r.hours, runs: s.runs + r.runs }), { costUsd: 0, tokens: 0, hours: 0, runs: 0 });
|
|
122
|
+
return { total: { ...total, costUsd: r2(total.costUsd), hours: r1(total.hours) }, rows };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* ── the repository's files ── */
|
|
126
|
+
const stateDirOf = (root, create = false) => { try { return require('./driver.js').stateDirOf(root, { create }); } catch { return null; } };
|
|
127
|
+
function prsOf(sd) {
|
|
128
|
+
const out = [];
|
|
129
|
+
for (const l of sd ? readJsonl(path.join(sd, 'proposals.jsonl')) : []) if (l.kind === 'keep' && Array.isArray(l.wrote)) for (const w of l.wrote) if (w && w.op === 'pr' && w.item && w.url) out.push({ item: w.item, url: w.url });
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
/** costOf over this repository's own files. An empty answer ({ rows: [] }) when no factory ran here. */
|
|
133
|
+
function readOf(root, { now = Date.now(), stateDir = null } = {}) {
|
|
134
|
+
const sd = stateDir || stateDirOf(root, false);
|
|
135
|
+
let dir = null; try { dir = require('./work-kind.js').factoryDir(root); } catch { dir = null; }
|
|
136
|
+
const ledger = dir ? readJsonl(path.join(dir, 'planning', 'work-items.jsonl')) : [];
|
|
137
|
+
const traces = sd ? readJsonl(path.join(sd, 'factory-traces.jsonl')) : [];
|
|
138
|
+
return costOf({ traces, ledger, prs: prsOf(sd), pauses: pausesOf(sd), now });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/* ── the ✦ ── */
|
|
142
|
+
const dayOf = (iso) => String(iso || '').slice(0, 10);
|
|
143
|
+
/** The ✦ for one stalled row. No amount of money in it (Totals only on the Cost tab). */
|
|
144
|
+
function proposalOf(r, now) {
|
|
145
|
+
const PR = require('./proposals.js');
|
|
146
|
+
const days = Math.floor((now - Date.parse(r.stall.since)) / DAY);
|
|
147
|
+
return {
|
|
148
|
+
kind: 'propose', ini: r.ini, board: '', run: 'initiative-cost', id: PR.idOf(r.ini, 'cost', 'pause', dayOf(r.stall.since)), group: 'cost', type: 'pause', section: 'check',
|
|
149
|
+
title: `Pause ${r.ini}'s new jobs?`,
|
|
150
|
+
why: one(`The factory has run agents on ${r.ini} for ${days} days with no merge${r.lastMergeAt ? ` since ${dayOf(r.lastMergeAt)}` : ''}. A pause stops new jobs; the work it holds now finishes, and Undo starts them again.`, 300),
|
|
151
|
+
sources: [{ label: 'Factory run traces', ref: 'factory-traces.jsonl' }, { label: 'Work items', ref: 'planning/work-items.jsonl' }],
|
|
152
|
+
items: [{ id: r.ini, title: 'Pause new jobs' }],
|
|
153
|
+
data: { since: r.stall.since, lastMergeAt: r.lastMergeAt, runs: r.runs },
|
|
154
|
+
at: new Date(now).toISOString(),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** The pause ✦ pass, run when Work reads the costs (lib/routes-factory-metrics.js). Never throws. */
|
|
158
|
+
function proposePass(root, { now = Date.now(), stateDir = null, env = process.env } = {}) {
|
|
159
|
+
try {
|
|
160
|
+
if (/^(off|0|false|no)$/i.test(String(env.PMOS_INITIATIVE_COST || ''))) return { ok: true, filed: [], dropped: [], why: 'PMOS_INITIATIVE_COST=off' };
|
|
161
|
+
const sd = stateDir || stateDirOf(root, false);
|
|
162
|
+
if (!sd) return { ok: true, filed: [], dropped: [] };
|
|
163
|
+
const PR = require('./proposals.js');
|
|
164
|
+
const C = readOf(root, { now, stateDir: sd });
|
|
165
|
+
if (!C.rows.length) return { ok: true, filed: [], dropped: [] };
|
|
166
|
+
const F = PR.read(sd), kept = new Set(); for (const k of F.kept) if (!F.undone.has(k.batch)) for (const id of k.ids) kept.add(id);
|
|
167
|
+
const want = new Map(C.rows.filter((r) => r.stall && !r.paused).map((r) => [PR.idOf(r.ini, 'cost', 'pause', dayOf(r.stall.since)), r]));
|
|
168
|
+
const dropped = [], filed = [];
|
|
169
|
+
for (const p of F.props.values()) {
|
|
170
|
+
if (p.group !== 'cost' || p.type !== 'pause' || kept.has(p.id) || F.drops.has(PR.sigOf(p)) || want.has(p.id)) continue;
|
|
171
|
+
PR.append(sd, { by: BY }, { kind: 'drop', ini: p.ini, sig: PR.sigOf(p), id: p.id, group: 'cost', type: 'pause', why: 'it merged, stopped spending or was paused' });
|
|
172
|
+
dropped.push(p.id);
|
|
173
|
+
}
|
|
174
|
+
for (const [id, r] of want) {
|
|
175
|
+
if (F.props.has(id)) continue; // one ✦ per stall: open, kept or dropped, never filed again
|
|
176
|
+
PR.append(sd, { by: BY }, proposalOf(r, now));
|
|
177
|
+
filed.push(id);
|
|
178
|
+
}
|
|
179
|
+
if (filed.length || dropped.length) console.info(`${TAG} proposals filed=${filed.length} dropped=${dropped.length}`);
|
|
180
|
+
return { ok: true, filed, dropped };
|
|
181
|
+
} catch (e) { return { ok: false, filed: [], dropped: [], why: one(e && e.message, 160) }; }
|
|
182
|
+
}
|
|
183
|
+
/** The Cost tab's ✕ "Keep going" and its pause: the stall's open ✦ is answered, so it does not ask again. → the ids dropped */
|
|
184
|
+
function answer(sd, ini, why, { by = 'pm' } = {}) {
|
|
185
|
+
const PR = require('./proposals.js'), F = PR.read(sd), out = [];
|
|
186
|
+
for (const p of F.props.values()) {
|
|
187
|
+
if (p.group !== 'cost' || p.ini !== ini || F.drops.has(PR.sigOf(p))) continue;
|
|
188
|
+
PR.append(sd, { by }, { kind: 'drop', ini, sig: PR.sigOf(p), id: p.id, group: 'cost', type: 'pause', why: one(why, 120) });
|
|
189
|
+
out.push(p.id);
|
|
190
|
+
}
|
|
191
|
+
return out;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* ── the CLI ── */
|
|
195
|
+
const usd = (n) => '$' + (n >= 100 ? Math.round(n) : n.toFixed(2));
|
|
196
|
+
const hrs = (h) => (h > 0 ? `${h} h` : 'no time logged');
|
|
197
|
+
const result = (r) => (r.stall ? `0 merged in ${STALL_DAYS} days` : r.merged ? `${r.merged} PR${r.merged === 1 ? '' : 's'} merged` : 'nothing merged yet');
|
|
198
|
+
/** PURE. */
|
|
199
|
+
function lines(C) {
|
|
200
|
+
if (!C.rows.length) return ['No factory run on any initiative here yet.'];
|
|
201
|
+
const out = [`Factory cost by initiative: ${usd(C.total.costUsd)} in all, ${C.total.runs} run${C.total.runs === 1 ? '' : 's'}.`];
|
|
202
|
+
for (const r of C.rows) out.push(` ${r.ini}: ${hrs(r.hours)} · ${usd(r.costUsd)} · ${result(r)}${r.paused ? ' · paused' : r.stall ? ` · pause it? pmos cost pause ${r.ini}` : ''}`);
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
/** PURE. One initiative's merged pull requests. */
|
|
206
|
+
function prLines(r) {
|
|
207
|
+
if (!r) return ['No factory run on that initiative.'];
|
|
208
|
+
const out = [`${r.ini}: ${hrs(r.hours)} · ${usd(r.costUsd)} · ${r.tokens} tokens · ${result(r)}${r.paused ? ' · paused' : ''}`];
|
|
209
|
+
for (const p of r.prs) out.push(` ${p.item}${p.title ? ' ' + p.title : ''}: ${hrs(p.hours)} · ${usd(p.costUsd)} · ${p.tokens} tokens${p.url ? ' · ' + p.url : ''}`);
|
|
210
|
+
if (!r.prs.length) out.push(' No pull request merged yet.');
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const COMMANDS = { cost: ['show', 'pause', 'resume'] };
|
|
215
|
+
const USAGE = [
|
|
216
|
+
'usage: pmos cost [<initiative>] [--json] | pmos cost pause|resume <initiative> — what the factory spent per initiative and merged pull request',
|
|
217
|
+
' pmos cost [--json] each initiative: agent hours, spend and what merged',
|
|
218
|
+
' pmos cost <initiative> [--json] its merged pull requests, each with its own cost',
|
|
219
|
+
' pmos cost pause <initiative> the factory takes no new job of it; work it holds now finishes',
|
|
220
|
+
' pmos cost resume <initiative> the factory takes its jobs again',
|
|
221
|
+
];
|
|
222
|
+
function repoOf(cwd) {
|
|
223
|
+
let d = path.resolve(cwd);
|
|
224
|
+
for (;;) { try { if (fs.existsSync(path.join(d, '.git'))) return d; } catch { /* look further up */ } const up = path.dirname(d); if (up === d) return path.resolve(cwd); d = up; }
|
|
225
|
+
}
|
|
226
|
+
function run(argv, o = {}) {
|
|
227
|
+
const say = o.say || ((s) => console.log(s)), now = o.now || Date.now();
|
|
228
|
+
const args = argv[0] === 'cost' ? argv.slice(1) : argv.slice();
|
|
229
|
+
const pos = [], flags = {};
|
|
230
|
+
for (let i = 0; i < args.length; i++) { const a = args[i]; if (a === '--root') flags.root = args[++i]; else if (a === '--json') flags.json = true; else pos.push(a); }
|
|
231
|
+
if (pos[0] === 'help' || pos[0] === '--help') { USAGE.forEach((l) => say(l)); return 0; }
|
|
232
|
+
const root = path.resolve(flags.root || o.root || repoOf(o.cwd || process.cwd()));
|
|
233
|
+
const sd = o.stateDir || stateDirOf(root, pos[0] === 'pause' || pos[0] === 'resume');
|
|
234
|
+
if (pos[0] === 'pause' || pos[0] === 'resume') {
|
|
235
|
+
const ini = pos[1];
|
|
236
|
+
if (!ini || !ID_RE.test(ini)) { say(`✗ name an initiative: pmos cost ${pos[0]} <initiative>`); return 2; }
|
|
237
|
+
const r = (pos[0] === 'pause' ? pause : resume)(sd, ini, { by: 'pm:cli', now, why: pos[0] === 'pause' ? 'pmos cost pause' : '' });
|
|
238
|
+
if (!r.ok) { say('✗ ' + r.error); return 1; }
|
|
239
|
+
if (pos[0] === 'pause') try { answer(sd, ini, 'paused with pmos cost pause', { by: 'pm:cli' }); } catch { /* no ✦ to answer */ }
|
|
240
|
+
if (flags.json) { say(JSON.stringify({ ok: true, ini, paused: pos[0] === 'pause', already: !!r.already })); return 0; }
|
|
241
|
+
say(r.already ? `${ini} was already ${pos[0] === 'pause' ? 'paused' : 'running'}.` : pos[0] === 'pause' ? `✓ Paused ${ini}'s new jobs. Work it holds now finishes. pmos cost resume ${ini} undoes it.` : `✓ ${ini}'s jobs run again.`);
|
|
242
|
+
return 0;
|
|
243
|
+
}
|
|
244
|
+
const C = readOf(root, { now, stateDir: sd });
|
|
245
|
+
try { require('./use-log.js').record(sd || root, [{ kind: 'use', page: 'premium-board', control: 'costCli', device: 'desk' }], now); } catch { /* a count, never a reason to fail */ }
|
|
246
|
+
console.info(`${TAG} rows=${C.rows.length} stalled=${C.rows.filter((r) => r.stall).length}`);
|
|
247
|
+
const ini = pos[0] && pos[0] !== 'show' ? pos[0] : null;
|
|
248
|
+
if (ini) {
|
|
249
|
+
const r = C.rows.find((x) => x.ini === ini) || null;
|
|
250
|
+
if (flags.json) { say(JSON.stringify({ ok: true, row: r })); return 0; }
|
|
251
|
+
prLines(r).forEach((l) => say(l));
|
|
252
|
+
return 0;
|
|
253
|
+
}
|
|
254
|
+
if (flags.json) { say(JSON.stringify({ ok: true, ...C })); return 0; }
|
|
255
|
+
lines(C).forEach((l) => say(l));
|
|
256
|
+
return 0;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
module.exports = { FILE, TAG, STALL_DAYS, iniOf, costOf, pausedSet, pausedOf, pause, resume, readOf, proposalOf, proposePass, answer, lines, prLines, run, COMMANDS, USAGE };
|
|
@@ -157,6 +157,9 @@ const VERBS = Object.freeze({
|
|
|
157
157
|
// Not a pm-os-absorb verb (run: null): initiative three-line-why (bet A86) added it through the same table.
|
|
158
158
|
why: Object.freeze({ module: 'why-cli.js', run: null, guide: 'cli.md',
|
|
159
159
|
help: 'pmos why <initiative or task> | coverage — why the work exists in three lines: goal, problem, evidence, read from its records (pmos why help)' }),
|
|
160
|
+
// Not a pm-os-absorb verb (run: null): initiative copy-tests (job #1905, A351) added it through the same table.
|
|
161
|
+
experiment: Object.freeze({ module: 'copy-tests.js', run: null, guide: 'cli.md',
|
|
162
|
+
help: 'pmos experiment draft|list|show|flag|start|result|keep|undo|count — copy and layout tests on an initiative: drafted from plain words, started by you, one table and one ✦ line with how sure (pmos experiment help)' }),
|
|
160
163
|
// Not a pm-os-absorb verb (run: null): initiative story-map (job #1892, A419) added it through the same table.
|
|
161
164
|
'story-map': Object.freeze({ module: 'story-map-cli.js', run: null, guide: 'cli.md',
|
|
162
165
|
help: 'pmos story-map show|set|move|keep|unkeep|drop|count — a new bet\'s story map: the user\'s journey and the Release 1 line (pmos story-map help)' }),
|
|
@@ -164,6 +167,9 @@ const VERBS = Object.freeze({
|
|
|
164
167
|
tradeoff: Object.freeze({ module: 'tradeoff-cli.js', run: null, guide: 'cli.md',
|
|
165
168
|
help: 'pmos tradeoff [list|show|keep|undo|count] — two close items on the Roadmap side by side, and the reason you kept one first (pmos tradeoff help)' }),
|
|
166
169
|
// Not a pm-os-absorb verb (run: null): initiative next-hire-draft (job #1876, A75) added it through the same table.
|
|
170
|
+
// Not a pm-os-absorb verb (run: null): initiative initiative-cost (job #1906, A17) added it through the same table.
|
|
171
|
+
cost: Object.freeze({ module: 'initiative-cost.js', run: null, guide: 'cli.md',
|
|
172
|
+
help: 'pmos cost [<initiative>] | pmos cost pause|resume <initiative> — what the factory spent per initiative and merged pull request, and its pause (pmos cost help)' }),
|
|
167
173
|
// Not a pm-os-absorb verb (run: null): initiative starter-goals (job #1916, A84) added it through the same table.
|
|
168
174
|
goals: Object.freeze({ module: 'goals-cli.js', run: null, guide: 'cli.md',
|
|
169
175
|
help: 'pmos goals [starter|draft|keep <n>|drop <n>|undo] — starter goals PMOS drafts from your own product, each with its source; keep one and it becomes a goal (pmos goals help)' }),
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* An experiment's Problem, Goal and Done test checks the ledger lacks come from the record's own sections,
|
|
8
8
|
* carried as kind `record` (lib/case-lines.js), so the card shows what `pmos why` reads. The Experiment
|
|
9
9
|
* carries `power` ({ n, weeks, weekly, due, ends, text, path }) only when the record's baseline, min_change
|
|
10
|
-
* and weekly_traffic cannot reach a conclusion by its check date (lib/experiment-power.js)
|
|
10
|
+
* and weekly_traffic cannot reach a conclusion by its check date (lib/experiment-power.js), and `copyTests` (lib/copy-tests.js foldOf)
|
|
11
|
+
* when the initiative has a copy or layout test, else `copyTestOffer` { initiative, flag } when its record names a rollout_flag
|
|
11
12
|
* GET /api/artefacts/story?ws → { ok, ws, story: { scope, at, lines: [{ text, sources }] } | null, seeding? } "The story so far" on the
|
|
12
13
|
* product page (board AwE): the Narrative of board:<ws>, else of the portfolio (lib/artefacts.js storyOf). A
|
|
13
14
|
* shared Board carries it without the sources (lib/board-pack.js). seeding: there is no story yet and PMOS is
|
|
@@ -28,6 +29,9 @@
|
|
|
28
29
|
* changes that line again (lib/artefacts.js pmEdited, lib/driver-decide.js autoApply).
|
|
29
30
|
* POST /api/artefacts/undo { ws, ref } → { ok, line } the Undo of that edit (the popup's Overview, nav slice 3 round 3): the PM's set line
|
|
30
31
|
* `ref` no longer counts. The same page press and PM-only rule as set; the mirror follows it.
|
|
32
|
+
* POST /api/artefacts/copy-test { ws, id, op: start | keep | undo } | { ws, op: draft, initiative, ask } → { ok, said, test } the work popup's press on a copy test
|
|
33
|
+
* (copy-tests, A351, lib/copy-tests.js act): the same page press and PM-only rule as set; keep is refused
|
|
34
|
+
* under 80 % sure (409)
|
|
31
35
|
*
|
|
32
36
|
* THE MIGRATION. Every read of a repository carries its older records (core documents, kept driver proposals,
|
|
33
37
|
* report drafts) under their artefacts: lib/artefacts.js migrateRepo. It is idempotent and only appends pointers; nothing is deleted or
|
|
@@ -67,6 +71,23 @@ async function handle(req, res, url, ctx) {
|
|
|
67
71
|
const mirror = require('./artefact-mirror.js').after(w.root, r.line, A.file(dir));
|
|
68
72
|
return send(200, { ok: true, line: pageBy(r.line), ...(mirror ? { mirror } : {}) });
|
|
69
73
|
}
|
|
74
|
+
// the work popup's presses on a copy test (copy-tests, A351): start, keep and undo, written by the PM's page only (lib/copy-tests.js)
|
|
75
|
+
if (sub === 'copy-test' && req.method === 'POST') {
|
|
76
|
+
const read = await ctx.readJson(req);
|
|
77
|
+
if (!read.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
78
|
+
const b = read.body || {};
|
|
79
|
+
const g = require('./pm-guard.js').requirePagePress(req, b);
|
|
80
|
+
if (!g.ok) return send(g.status, { ok: false, error: g.error });
|
|
81
|
+
if (!/^pm:/.test(String((g.actor && g.actor.by) || ''))) return send(403, { ok: false, error: 'only the PM starts or keeps a copy test' });
|
|
82
|
+
if (!['draft', 'start', 'keep', 'undo'].includes(b.op)) return send(400, { ok: false, error: 'op is draft, start, keep or undo' });
|
|
83
|
+
const w = wsOf(ctx, typeof b.ws === 'string' ? b.ws : '');
|
|
84
|
+
if (!w || !w.root) return send(404, { ok: false, error: 'no such workspace' });
|
|
85
|
+
// draft: the offer's field on the popup (Rule 12, the test shows by itself); the words are the PM's, the flag is the record's
|
|
86
|
+
const CT = require('./copy-tests.js'), r = b.op === 'draft' ? CT.act(w.root, 'draft', { initiative: b.initiative, ask: b.ask }) : CT.act(w.root, b.op, { id: b.id });
|
|
87
|
+
const use = { draft: 'copyTestDraft', keep: 'copyTestKeep' }[b.op];
|
|
88
|
+
if (r.ok && use) { try { require('./use-log.js').record(ctx.stateDirFor(w), [{ kind: 'use', page: 'work', control: use, device: 'desk' }]); } catch { /* a count */ } }
|
|
89
|
+
return send(r.ok ? 200 : 409, r.ok ? { ok: true, said: r.said, test: r.test || null } : { ok: false, error: r.error });
|
|
90
|
+
}
|
|
70
91
|
if (req.method !== 'GET') return send(405, { ok: false, error: 'the artefacts are read here; the PM edits a line with POST /api/artefacts/set' });
|
|
71
92
|
if (sub === 'map') return send(200, { ok: true, artefacts: A.KEYS, rows: require('./artefacts-cli.js').mapRows() });
|
|
72
93
|
if (sub === 'lessons') {
|
|
@@ -157,6 +178,15 @@ function withRecord(artefacts, root, id) {
|
|
|
157
178
|
if (w) ex.power = { ...w, path: require('path').relative(root, f).split(require('path').sep).join('/') };
|
|
158
179
|
} catch { /* an unreadable record shows no warning */ }
|
|
159
180
|
}
|
|
181
|
+
// the initiative's copy and layout tests (copy-tests, A351): carried only when there is one (zero is silence)
|
|
182
|
+
// with no test yet, a record that names its rollout_flag carries an offer (copyTestOffer), so the block shows by itself (LINE Rule 12)
|
|
183
|
+
if (ex) {
|
|
184
|
+
try {
|
|
185
|
+
const CT = require('./copy-tests.js'), T = CT.forInitiative(root, id);
|
|
186
|
+
if (T.length) ex.copyTests = T;
|
|
187
|
+
else { const o = CT.offerOf(root, id); if (o) ex.copyTestOffer = o; }
|
|
188
|
+
} catch { /* no ledger, no tests */ }
|
|
189
|
+
}
|
|
160
190
|
}
|
|
161
191
|
|
|
162
192
|
module.exports = { prefixes: ['/api/artefacts'], handle, _migrated: migrated };
|
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
* The factory floor per product as the Driver saved it after its last run (lib/factory-floor.js load). It reads one file per product and
|
|
13
13
|
* folds nothing, so the Factory page opens in 200 ms or less. snapshot is null while no run has saved one: a read never computes or writes.
|
|
14
14
|
* ws: one workspace (404 when unknown); without it, every workspace.
|
|
15
|
+
*
|
|
16
|
+
* GET /api/initiative-cost?ws → { ok, products: [{ ws, name, total, rows }] } (initiative initiative-cost, A17; lib/initiative-cost.js)
|
|
17
|
+
* What the factory spent per initiative and per merged pull request, and which initiatives are stalled or paused. Zero is silence: a
|
|
18
|
+
* product where no factory ran is left out, so Work shows no Cost tab. It reads two small files per product and writes nothing.
|
|
19
|
+
* POST /api/initiative-cost/pause|resume|keep { ws, ini } → { ok, ini, paused } page press only (pm-guard requirePagePress)
|
|
20
|
+
* pause: the factory takes no new job of the initiative (work it holds finishes), and the stall's ✦ is answered. resume: Undo.
|
|
21
|
+
* keep: "Keep going", the stall's ✦ is answered and nothing pauses. The same store as `pmos cost pause|resume`.
|
|
15
22
|
*/
|
|
16
23
|
const FT = require('./factory-traces.js');
|
|
17
24
|
|
|
@@ -45,8 +52,54 @@ function floorFor(ctx, { ws = '' } = {}) {
|
|
|
45
52
|
return { status: 200, body: { ok: true, products } };
|
|
46
53
|
}
|
|
47
54
|
|
|
55
|
+
const PASS_AT = new Map(), PASS_EVERY = 30 * 60 * 1000;
|
|
56
|
+
function costFor(ctx, { ws = '', now = Date.now() } = {}) {
|
|
57
|
+
let list;
|
|
58
|
+
if (ws) {
|
|
59
|
+
const w = ctx.getWs(ws);
|
|
60
|
+
if (!w || w.id !== ws) return bad(404, 'no such workspace');
|
|
61
|
+
list = [w];
|
|
62
|
+
} else list = (ctx.workspaceList ? ctx.workspaceList() : []).filter((w) => w && w.root && !w.linked);
|
|
63
|
+
const IC = require('./initiative-cost.js'), products = [];
|
|
64
|
+
for (const w of list) {
|
|
65
|
+
let C = null;
|
|
66
|
+
const sd = (ctx.stateDirFor && ctx.stateDirFor(w)) || null;
|
|
67
|
+
// the pause ✦ (no model): filed when Work reads the costs, at most once per half hour per product
|
|
68
|
+
if (now - (PASS_AT.get(w.root) || 0) >= PASS_EVERY) { PASS_AT.set(w.root, now); try { IC.proposePass(w.root, { now, stateDir: sd }); } catch { /* the read still answers */ } }
|
|
69
|
+
try { C = IC.readOf(w.root, { now, stateDir: sd }); } catch { C = null; }
|
|
70
|
+
if (C && C.rows.length) products.push({ ws: w.id, name: w.name || w.id, ...C });
|
|
71
|
+
}
|
|
72
|
+
return { status: 200, body: { ok: true, products } };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function costPost(req, url, ctx) {
|
|
76
|
+
const sub = url.pathname.replace(/^\/api\/initiative-cost\/?/, '');
|
|
77
|
+
if (!['pause', 'resume', 'keep'].includes(sub)) return bad(404, 'no such cost route');
|
|
78
|
+
if (req.method !== 'POST') return bad(405, 'POST only');
|
|
79
|
+
const read = await ctx.readJson(req);
|
|
80
|
+
if (!read.ok || !read.body || typeof read.body !== 'object') return bad(400, 'the body must be a JSON object');
|
|
81
|
+
const g = require('./pm-guard.js').requirePagePress(req, read.body);
|
|
82
|
+
if (!g.ok) return bad(g.status, g.error);
|
|
83
|
+
const ini = typeof read.body.ini === 'string' ? read.body.ini : '';
|
|
84
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/.test(ini)) return bad(400, 'ini must name an initiative');
|
|
85
|
+
const w = ctx.getWs(typeof read.body.ws === 'string' && read.body.ws ? read.body.ws : null);
|
|
86
|
+
if (!w || (read.body.ws && w.id !== read.body.ws)) return bad(404, 'no such workspace');
|
|
87
|
+
const IC = require('./initiative-cost.js'), sd = (ctx.stateDirFor && ctx.stateDirFor(w)) || require('./driver.js').stateDirOf(w.root, { create: true });
|
|
88
|
+
const by = (g.actor && g.actor.by) || 'pm';
|
|
89
|
+
if (sub === 'keep') { IC.answer(sd, ini, 'keep going', { by }); return { status: 200, body: { ok: true, ini, paused: IC.pausedOf(sd).has(ini) } }; }
|
|
90
|
+
const r = (sub === 'pause' ? IC.pause : IC.resume)(sd, ini, { by, why: sub === 'pause' ? 'Work › Cost' : 'Undo' });
|
|
91
|
+
if (!r.ok) return bad(400, r.error);
|
|
92
|
+
if (sub === 'pause') IC.answer(sd, ini, 'paused from Work › Cost', { by });
|
|
93
|
+
return { status: 200, body: { ok: true, ini, paused: sub === 'pause' } };
|
|
94
|
+
}
|
|
95
|
+
|
|
48
96
|
async function handle(req, res, url, ctx) {
|
|
49
97
|
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
98
|
+
if (url.pathname === '/api/initiative-cost') {
|
|
99
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
100
|
+
return send(costFor(ctx, { ws: String(url.searchParams.get('ws') || '') }));
|
|
101
|
+
}
|
|
102
|
+
if (url.pathname.startsWith('/api/initiative-cost/')) return send(await costPost(req, url, ctx));
|
|
50
103
|
if (url.pathname === '/api/factory') {
|
|
51
104
|
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
52
105
|
return send(floorFor(ctx, { ws: String(url.searchParams.get('ws') || '') }));
|
|
@@ -59,4 +112,4 @@ async function handle(req, res, url, ctx) {
|
|
|
59
112
|
return send(metricsFor(ctx, { ws: String(url.searchParams.get('ws') || ''), days }));
|
|
60
113
|
}
|
|
61
114
|
|
|
62
|
-
module.exports = { prefixes: ['/api/factory/metrics', '/api/factory'], handle, metricsFor, floorFor };
|
|
115
|
+
module.exports = { prefixes: ['/api/factory/metrics', '/api/factory', '/api/initiative-cost'], handle, metricsFor, floorFor, costFor };
|
|
@@ -157,6 +157,7 @@ function undoCore(ctx, p, g, id) {
|
|
|
157
157
|
// a new experiment the ✦ made goes from every list (the Board's own Delete: the record file stays, a restore brings it back)
|
|
158
158
|
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); }
|
|
159
159
|
else if (w.op === 'round') { const LR = require('./live-round.js'); LR.cancel(w.round); if (w.proposal) LR.dropCard(dir, w.proposal); back++; continue; } // a live round: its runs stop and its card goes
|
|
160
|
+
else if (w.op === 'pause') { const r2 = require('./initiative-cost.js').resume(dir, w.ini || k.ini, { by: (g.actor && g.actor.by) || 'pm', why: 'Undo' }); if (r2.ok) back++; else kept++; continue; } // initiative-cost: Undo starts its jobs again
|
|
160
161
|
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)
|
|
161
162
|
else if (w.op === 'verdict') {
|
|
162
163
|
// the PM's Undo of a verdict PMOS recorded by itself: the check is taken back (the outcome is due again, and Your move asks the PM),
|
|
@@ -383,6 +384,12 @@ function applyOne(ctx, p, g, f, ini, x, choices, outbox) {
|
|
|
383
384
|
const pol = r.policy || null, guard = pol ? { verdict: pol.verdict, rules: (pol.reasons || []).map((y) => String(y.rule || '')).filter(Boolean).slice(0, 12), detail: String(pol.why || '').slice(0, 300) } : null;
|
|
384
385
|
if (r.ok) add({ op: 'pr', item: d.item, branch: d.branch, url: r.url || '', ...(guard ? { guard } : {}) });
|
|
385
386
|
else x.failed = r.error;
|
|
387
|
+
} else if (x.group === 'cost') {
|
|
388
|
+
// a stall: the factory spent 7 days on the initiative with no merge (lib/initiative-cost.js, A17). Class C: only the PM's ✓ reaches
|
|
389
|
+
// here. It pauses the initiative's NEW factory jobs; an item a Builder holds finishes. Undo starts them again
|
|
390
|
+
const r = require('./initiative-cost.js').pause(dirOf(ctx, p.w), ini, { by: (g.actor && g.actor.by) || 'pm', why: 'the ✦ pause proposal' });
|
|
391
|
+
if (r.ok && !r.already) add({ op: 'pause', ini });
|
|
392
|
+
else if (!r.ok) x.failed = r.error;
|
|
386
393
|
} else if (x.group === 'harness') {
|
|
387
394
|
// a failure the factory repeated (lib/factory-lessons.js). Class C: only the PM's ✓ reaches here. It adds a task for the PM with the
|
|
388
395
|
// evidence; the harness itself changes only through the PM's own reviewed pull request
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.843.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.843.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -350,3 +350,6 @@ textarea.bk-rvl-ed, .bk-rvl textarea.bd { resize: vertical; min-height: 180px; }
|
|
|
350
350
|
.fx-sheet .fx-fold summary { cursor: pointer; padding: 6px 0; font-size: var(--fs-meta); color: var(--muted); }
|
|
351
351
|
.fx-sheet .ff-undo { all: unset; box-sizing: border-box; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-md); cursor: pointer; }
|
|
352
352
|
.fx-sheet .ff-undo:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
|
|
353
|
+
/* Work › Cost (initiative-cost, A17): a stalled initiative's result, and the ✦ line under the table */
|
|
354
|
+
.ic-alert { color: var(--alert); }
|
|
355
|
+
.ic-ask { margin-top: var(--space-8); }
|