create-pmos 0.543.0 → 0.545.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 -63
- package/payload/KIT-VERSION +2 -2
- 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/payload/state/log.md +1 -1
- package/workspace/changelog.json +26 -0
- package/workspace/guide/cli.md +4 -0
- package/workspace/lib/artefacts-cli.js +105 -0
- package/workspace/lib/artefacts.js +369 -0
- package/workspace/lib/autonomy.js +1 -0
- package/workspace/lib/claude-signin.js +51 -0
- package/workspace/lib/driver-cli.js +1 -1
- package/workspace/lib/driver-decide.js +15 -1
- package/workspace/lib/driver.js +9 -1
- package/workspace/lib/harness-health.js +1 -1
- package/workspace/lib/headless.js +1 -1
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/refresh-run.js +10 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-artefacts.js +48 -0
- package/workspace/lib/routes-meeting-focus.js +1 -1
- package/workspace/lib/source-heal.js +1 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/run-tests.js +22 -1
- package/workspace/server.js +14 -2
- package/workspace/test-lists/claude-signin.json +5 -0
- package/workspace/test-lists/seven-artefacts.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.545.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": {
|
|
@@ -32,6 +32,32 @@
|
|
|
32
32
|
"audit"
|
|
33
33
|
],
|
|
34
34
|
"pmosChanges": [
|
|
35
|
+
{
|
|
36
|
+
"v": "0.545.0",
|
|
37
|
+
"at": "2026-11-09T10:45:44.000Z",
|
|
38
|
+
"f": 4,
|
|
39
|
+
"prs": [
|
|
40
|
+
{
|
|
41
|
+
"n": 1273,
|
|
42
|
+
"t": "Seven artefacts — model, map, lossless carry, and proposed D107",
|
|
43
|
+
"s": "Seven artefacts — model, map, lossless carry, and proposed D107",
|
|
44
|
+
"k": "new"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"v": "0.544.0",
|
|
50
|
+
"at": "2026-11-08T14:45:01.680Z",
|
|
51
|
+
"f": 4,
|
|
52
|
+
"prs": [
|
|
53
|
+
{
|
|
54
|
+
"n": 1272,
|
|
55
|
+
"t": "Claude calls and sign-in advice follow the chosen Claude profile; a session stuck at sign-in ends",
|
|
56
|
+
"s": "Claude calls and sign-in advice follow the chosen Claude profile; a session stuck at sign-in ends",
|
|
57
|
+
"k": "fix"
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
},
|
|
35
61
|
{
|
|
36
62
|
"v": "0.543.0",
|
|
37
63
|
"at": "2026-11-08T10:18:52.684Z",
|
|
@@ -391,68 +417,6 @@
|
|
|
391
417
|
"k": "new"
|
|
392
418
|
}
|
|
393
419
|
]
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
"v": "0.525.0",
|
|
397
|
-
"at": "2026-11-04T09:08:28.453Z",
|
|
398
|
-
"f": 4,
|
|
399
|
-
"prs": [
|
|
400
|
-
{
|
|
401
|
-
"n": 1231,
|
|
402
|
-
"t": "Smart refresh steps 1 and 2: measure each read, ask first, share one session",
|
|
403
|
-
"s": "Smart refresh steps 1 and 2: measure each read, ask first, share one session",
|
|
404
|
-
"k": "new"
|
|
405
|
-
},
|
|
406
|
-
{
|
|
407
|
-
"n": 1233,
|
|
408
|
-
"t": "Two programs in one link keep both, each tab on its own product",
|
|
409
|
-
"s": "Two programs in one link keep both, each tab on its own product",
|
|
410
|
-
"k": "fix"
|
|
411
|
-
}
|
|
412
|
-
]
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
"v": "0.524.0",
|
|
416
|
-
"at": "2026-11-04T08:57:48.087Z",
|
|
417
|
-
"f": 4,
|
|
418
|
-
"prs": [
|
|
419
|
-
{
|
|
420
|
-
"n": 1224,
|
|
421
|
-
"t": "Setup as one conversation, with the fundamentals settled (onboarding B1)",
|
|
422
|
-
"s": "Setup as one conversation, with the fundamentals settled (onboarding B1)",
|
|
423
|
-
"k": "new"
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
"n": 1223,
|
|
427
|
-
"t": "A feature appears when its moment comes (onboarding B3, gradual exposure)",
|
|
428
|
-
"s": "A feature appears when its moment comes (onboarding B3, gradual exposure)",
|
|
429
|
-
"k": "new"
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
"n": 1222,
|
|
433
|
-
"t": "After setup, Home shows what it did, the product portrait and the drafted first initiative (onboarding B2)",
|
|
434
|
-
"s": "After setup, Home shows what it did, the product portrait and the drafted first initiative (onboarding B2)",
|
|
435
|
-
"k": "new"
|
|
436
|
-
},
|
|
437
|
-
{
|
|
438
|
-
"n": 1227,
|
|
439
|
-
"t": "Idle lab screens: ✦ cards, compare view and Intelligence › Lab (build U)",
|
|
440
|
-
"s": "Idle lab screens: ✦ cards, compare view and Intelligence › Lab (build U)",
|
|
441
|
-
"k": "new"
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
"n": 1234,
|
|
445
|
-
"t": "Good morning reads the quarter — goal states, the PM's line, snapshot, goal tags, Yes effect (GM1)",
|
|
446
|
-
"s": "Good morning reads the quarter — goal states, the PM's line, snapshot, goal tags, Yes effect (GM1)",
|
|
447
|
-
"k": "new"
|
|
448
|
-
},
|
|
449
|
-
{
|
|
450
|
-
"n": 1228,
|
|
451
|
-
"t": "One queue for all background work (idle lab build Q)",
|
|
452
|
-
"s": "One queue for all background work (idle lab build Q)",
|
|
453
|
-
"k": "new"
|
|
454
|
-
}
|
|
455
|
-
]
|
|
456
420
|
}
|
|
457
421
|
]
|
|
458
422
|
}
|
package/payload/KIT-VERSION
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
kernel-source: pmos@
|
|
2
|
-
assembled: 2026-11-
|
|
1
|
+
kernel-source: pmos@3f329472
|
|
2
|
+
assembled: 2026-11-09
|
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-09T10:45:40Z"}
|
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-09T10:45:40Z"}
|
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-09T10:45:40Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/payload/state/log.md
CHANGED
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.545.0",
|
|
4
|
+
"at": "2026-11-09T10:45:44.000Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1273,
|
|
9
|
+
"t": "Seven artefacts — model, map, lossless carry, and proposed D107",
|
|
10
|
+
"s": "Seven artefacts — model, map, lossless carry, and proposed D107",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"v": "0.544.0",
|
|
17
|
+
"at": "2026-11-08T14:45:01.680Z",
|
|
18
|
+
"f": 4,
|
|
19
|
+
"prs": [
|
|
20
|
+
{
|
|
21
|
+
"n": 1272,
|
|
22
|
+
"t": "Claude calls and sign-in advice follow the chosen Claude profile; a session stuck at sign-in ends",
|
|
23
|
+
"s": "Claude calls and sign-in advice follow the chosen Claude profile; a session stuck at sign-in ends",
|
|
24
|
+
"k": "fix"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
2
28
|
{
|
|
3
29
|
"v": "0.543.0",
|
|
4
30
|
"at": "2026-11-08T10:18:52.684Z",
|
package/workspace/guide/cli.md
CHANGED
|
@@ -377,6 +377,10 @@ When the agent files a proposal, it can also state what it knows, so that the Br
|
|
|
377
377
|
|
|
378
378
|
The ledger is `driver.jsonl` in the state folder of the repository (`pmos/state`, `state` or `.pmos`). Each action adds one line. Nothing is changed or removed.
|
|
379
379
|
|
|
380
|
+
### pmos artefacts: the seven artefacts
|
|
381
|
+
|
|
382
|
+
`pmos artefacts show [<scope>]` lists the seven artefacts of a scope: Intent, Goal, Narrative, Experiment, Specimens, Done test and Lessons. The scope is `portfolio` (the default), `board:<id>`, `goal:<id>` or `experiment:<id>`. `pmos artefacts map` lists what each older core document, driver proposal kind, report cadence and lane becomes. `pmos artefacts migrate` puts every older record under its artefact as a pointer: issued and draft core documents, kept driver proposals and report drafts. It deletes and moves nothing, and a second run carries nothing new. `pmos artefacts set <scope> <artefact> [<field>] --text "<text>"` writes one field, and `pmos artefacts undo <id>` takes it back. Intent is yours: an agent proposes a change to it and waits for you. Goal is read from the OKRs, health budgets and readings, so you cannot type it.
|
|
383
|
+
|
|
380
384
|
### pmos coredoc: core documents
|
|
381
385
|
|
|
382
386
|
`pmos coredoc write --scope <scope> --key <key> --file <path>` writes one draft of a core document. The scope is `portfolio`, `board:<id>` or `initiative:<id>`. With `--file -` the command reads the document from standard input. The command refuses a scope it does not know, a key that is not a document of that level, and a document that PMOS reads from another source. A background run can write only the document it was started for. The command writes a draft and nothing else: you issue it on the page.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* artefacts-cli.js — `pmos artefacts`: the seven artefacts (R18, proposed D107, lib/artefacts.js).
|
|
3
|
+
*
|
|
4
|
+
* pmos artefacts show [<scope>] [--json] the seven artefacts of a scope (default portfolio), with what was carried into each
|
|
5
|
+
* pmos artefacts map [--json] what each of the 36 core documents, 9 proposal kinds, 5 cadences and 6 lanes becomes
|
|
6
|
+
* pmos artefacts migrate [--json] carry every older record (core documents, kept driver proposals, report drafts) under
|
|
7
|
+
* its artefact. Idempotent; it deletes and moves nothing
|
|
8
|
+
* pmos artefacts set <scope> <artefact> [<field>] --text "<…>" [--source label=ref]… one field (PM or agent; Intent is the PM's)
|
|
9
|
+
* pmos artefacts undo <a-id> one set line no longer counts
|
|
10
|
+
* every command: [--root <dir>]
|
|
11
|
+
* Exit codes: 0 done, 1 refused, 2 usage. */
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { execFileSync } = require('child_process');
|
|
14
|
+
const A = require('./artefacts.js');
|
|
15
|
+
const actorLib = require('./actor.js');
|
|
16
|
+
|
|
17
|
+
const COMMANDS = { artefacts: ['show', 'map', 'migrate', 'set', 'undo'] };
|
|
18
|
+
const USAGE = [
|
|
19
|
+
'usage: pmos artefacts show|map|migrate|set|undo — the seven artefacts: Intent, Goal, Narrative, Experiment, Specimens, Done test, Lessons',
|
|
20
|
+
' pmos artefacts show [<scope>] [--json] scope: portfolio (default), board:<id>, goal:<id> or experiment:<id>',
|
|
21
|
+
' pmos artefacts map [--json] what every older document, proposal kind, report cadence and lane becomes',
|
|
22
|
+
' pmos artefacts migrate [--json] carry the older records under their artefacts (idempotent; nothing is deleted)',
|
|
23
|
+
' pmos artefacts set <scope> <artefact> [<field>] --text "<text>" [--source label=ref]…',
|
|
24
|
+
' pmos artefacts undo <a-id>',
|
|
25
|
+
];
|
|
26
|
+
function parse(args) {
|
|
27
|
+
const pos = []; const flags = { source: [] };
|
|
28
|
+
for (let i = 0; i < args.length; i++) {
|
|
29
|
+
const a = args[i];
|
|
30
|
+
if (!a.startsWith('--')) { pos.push(a); continue; }
|
|
31
|
+
const k = a.slice(2);
|
|
32
|
+
if (k === 'json') { flags.json = true; continue; }
|
|
33
|
+
const v = args[i + 1] !== undefined && !String(args[i + 1]).startsWith('--') ? args[++i] : '';
|
|
34
|
+
if (k === 'source') flags.source.push(v); else flags[k] = v;
|
|
35
|
+
}
|
|
36
|
+
return { pos, flags };
|
|
37
|
+
}
|
|
38
|
+
function repoRoot(cwd) { try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; } }
|
|
39
|
+
|
|
40
|
+
function mapRows() {
|
|
41
|
+
const rows = [];
|
|
42
|
+
for (const [k, v] of Object.entries(A.FROM_DOCS)) rows.push({ from: 'document', name: k, ...v });
|
|
43
|
+
for (const [k, v] of Object.entries(A.FROM_WHATS)) rows.push({ from: 'proposal kind', name: k, ...v });
|
|
44
|
+
for (const [k, v] of Object.entries(A.FROM_CADENCES)) rows.push({ from: 'report cadence', name: k, ...v });
|
|
45
|
+
for (const [k, v] of Object.entries(A.FROM_LANES)) rows.push({ from: 'lane', name: k, ...v });
|
|
46
|
+
return rows;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), env = process.env, isTTY, now, dir: dirIn } = {}) {
|
|
50
|
+
const args = argv[0] === 'artefacts' ? argv.slice(1) : argv.slice();
|
|
51
|
+
const verb = args[0];
|
|
52
|
+
if (!verb || ['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
|
|
53
|
+
if (!COMMANDS.artefacts.includes(verb)) { say(`unknown artefacts command "${verb}" — one of ${COMMANDS.artefacts.join(', ')}`); return 2; }
|
|
54
|
+
const { pos, flags } = parse(args.slice(1));
|
|
55
|
+
if (verb === 'map') {
|
|
56
|
+
const rows = mapRows();
|
|
57
|
+
if (flags.json) { say(JSON.stringify({ ok: true, artefacts: A.KEYS, rows })); return 0; }
|
|
58
|
+
for (const r of rows) say(`${r.from.padEnd(15)} ${r.name.padEnd(22)} → ${r.artefact ? `${r.artefact}${r.field ? '.' + r.field : ''}` : '(not an artefact)'} — ${r.note}`);
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
|
|
62
|
+
let dir = dirIn || null;
|
|
63
|
+
if (!dir) { try { dir = A.dirOf(root); } catch (e) { say('✗ ' + String((e && e.message) || e)); return 1; } }
|
|
64
|
+
const f = A.file(dir);
|
|
65
|
+
if (verb === 'show') {
|
|
66
|
+
const scope = pos[0] || 'portfolio';
|
|
67
|
+
const v = A.viewOf(A.fold(A.readLines(f)), scope);
|
|
68
|
+
if (!v) { say('✗ scope must be portfolio, board:<id>, goal:<id> or experiment:<id>'); return 2; }
|
|
69
|
+
if (flags.json) { say(JSON.stringify({ ok: true, ...v })); return 0; }
|
|
70
|
+
say(v.scope);
|
|
71
|
+
for (const a of v.artefacts) {
|
|
72
|
+
say(` ${a.title}${a.empty ? ' — nothing yet' : ''}`);
|
|
73
|
+
for (const [k, val] of Object.entries(a.fields)) {
|
|
74
|
+
const list = Array.isArray(val) ? val : val ? [val] : [];
|
|
75
|
+
for (const x of list) say(` ${a.labels[k]}: ${x.text} (${x.id})`);
|
|
76
|
+
}
|
|
77
|
+
for (const c of a.carried) say(` carried ${c.kind} ${c.ref}${c.path ? ' · ' + c.path : ''}${c.text ? ' — ' + c.text : ''}`);
|
|
78
|
+
}
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
if (verb === 'migrate') {
|
|
82
|
+
const r = dirIn ? A.migrate({ dir }, { now }) : A.migrateRepo(root, { now });
|
|
83
|
+
if (!r.ok) { say('✗ ' + r.error); return 1; }
|
|
84
|
+
if (flags.json) { say(JSON.stringify({ ok: true, carried: r.carried, already: r.already })); return 0; }
|
|
85
|
+
say(r.carried ? `✓ carried ${r.carried} older record${r.carried === 1 ? '' : 's'} under the seven artefacts (${r.already} were already)` : `✓ nothing new to carry (${r.already} already carried)`);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
const actor = actorLib.fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env });
|
|
89
|
+
if (verb === 'set') {
|
|
90
|
+
if (pos.length < 2 || typeof flags.text !== 'string') { say(USAGE[4]); return 2; }
|
|
91
|
+
const sources = [];
|
|
92
|
+
for (const s of flags.source) { const i = s.indexOf('='); if (i < 1) { say('✗ --source is label=ref'); return 2; } sources.push({ label: s.slice(0, i), ref: s.slice(i + 1) }); }
|
|
93
|
+
const r = A.set(f, { scope: pos[0], artefact: pos[1], field: pos[2], text: flags.text, sources }, actor, { now });
|
|
94
|
+
if (!r.ok) { say('✗ ' + r.error); return 1; }
|
|
95
|
+
say(flags.json ? JSON.stringify({ ok: true, id: r.line.id }) : `✓ ${r.line.artefact}.${r.line.field} on ${r.line.scope} (${r.line.id}; pmos artefacts undo ${r.line.id})`);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
if (!pos[0]) { say(USAGE[5]); return 2; }
|
|
99
|
+
const r = A.undo(f, { ref: pos[0] }, actor, { now });
|
|
100
|
+
if (!r.ok) { say('✗ ' + r.error); return 1; }
|
|
101
|
+
say(`✓ ${pos[0]} undone`);
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = { run, COMMANDS, USAGE, mapRows };
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* artefacts.js — the seven artefacts of an agent-run workspace (requirement R18, proposed decision D107).
|
|
3
|
+
* THE ONE WRITER and THE ONE FOLD of <state>/artefacts.jsonl.
|
|
4
|
+
*
|
|
5
|
+
* R18 (agreed by PM wawan 2026-11-09, "Yes to all"): exactly seven artefacts and no form. They replace the 36 core documents
|
|
6
|
+
* (lib/core-docs.js SETS and the workflow stage documents), the 9 driver proposal kinds (lib/driver.js WHATS.initiative), the 5 report
|
|
7
|
+
* cadences and the 6 lanes. Readings, sources, memory and agent ledgers are machinery, not artefacts, and stay as they are.
|
|
8
|
+
*
|
|
9
|
+
* ARTEFACTS · KEYS · EXECUTORS · FROM_DOCS · FROM_WHATS · FROM_CADENCES · FROM_LANES
|
|
10
|
+
* parseScope(scope) → { kind, id, scope } | null portfolio · board:<id> · goal:<id> · experiment:<id> (initiative:<id> is an alias)
|
|
11
|
+
* targetOfDoc(level, key) · targetOfWhat(what, data) → { artefact, field, note } | { artefact: null, note }
|
|
12
|
+
* file(dir) · readLines(file) · fold(lines) → Map scope → Map artefact → { fields: { name: value|[values] }, carried: [line] }
|
|
13
|
+
* set(file, { scope, artefact, field, text, sources }, actor, { now }) → { ok, line } | { ok: false, status, error }
|
|
14
|
+
* undo(file, { ref }, actor, { now }) → { ok, line } | refusal a set goes back; carry lines cannot be undone (they point at records)
|
|
15
|
+
* viewOf(state, scope) → { scope, artefacts: [{ key, title, owner, for, fields, carried, empty }] } always all seven that fit the scope
|
|
16
|
+
* migrate({ dir, coreDocs, driverLines, reports }, { now }) → { ok, carried, already, lines } idempotent; deletes nothing
|
|
17
|
+
*
|
|
18
|
+
* THE LINES. Every line is { v: 1, ev, id, scope, at, by }.
|
|
19
|
+
* set { artefact, field, text, sources: [{ label, ref }] } a value. A `one` field: the newest set wins. A `list` field: every set is a line.
|
|
20
|
+
* undo { ref } the set with id `ref` no longer counts
|
|
21
|
+
* carry { artefact, field, from: { kind, ref, path?, title?, state?, text? } } an older record (a core document, a kept driver proposal,
|
|
22
|
+
* a report draft) that now lives under this artefact. The old record stays where it is: a carry is a pointer, never a copy that
|
|
23
|
+
* could drift. Idempotent on from.kind + from.ref.
|
|
24
|
+
*
|
|
25
|
+
* WHO WRITES. `by` is the call path (lib/actor.js). Intent is the PM's: a set on it from anything but the PM is refused, so an agent's
|
|
26
|
+
* Intent change waits for the PM as a driver proposal. Goal is derived (from OKRs, health budgets and readings): it takes carry lines only.
|
|
27
|
+
* Every other artefact is agent-written (D98, D106): a set is reversible, and Undo is a correction.
|
|
28
|
+
*/
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
const crypto = require('crypto');
|
|
32
|
+
|
|
33
|
+
const LEDGER = 'artefacts.jsonl';
|
|
34
|
+
const EVENTS = Object.freeze(['set', 'undo', 'carry']);
|
|
35
|
+
const EXECUTORS = Object.freeze(['factory', 'team', 'team-agents']);
|
|
36
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/;
|
|
37
|
+
const REF_RE = /^a-[0-9a-f]{10}$/;
|
|
38
|
+
const MAX_TEXT = 4000;
|
|
39
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
40
|
+
|
|
41
|
+
const f = (name, mode, label) => Object.freeze({ name, mode, label });
|
|
42
|
+
/* The seven. `scopes` are where a set may land; `owner` is pm (the PM writes it), derived (no set) or agent. */
|
|
43
|
+
const ARTEFACTS = Object.freeze([
|
|
44
|
+
Object.freeze({ key: 'intent', title: 'Intent', owner: 'pm', scopes: ['portfolio', 'board'],
|
|
45
|
+
for: 'What we want, the limits agents work inside, and what we will not do. The PM owns it; agents propose changes to it.',
|
|
46
|
+
fields: Object.freeze([f('want', 'one', 'What we want'), f('limits', 'one', 'Limits and budgets'), f('not', 'one', 'What we will not do')]) }),
|
|
47
|
+
Object.freeze({ key: 'goal', title: 'Goal', owner: 'derived', scopes: ['portfolio', 'goal'],
|
|
48
|
+
for: 'An outcome with a live reading and the experiments on it. Read from the OKRs, health budgets and readings; never typed.',
|
|
49
|
+
fields: Object.freeze([f('reading', 'one', 'Reading'), f('experiments', 'list', 'Experiments')]) }),
|
|
50
|
+
Object.freeze({ key: 'narrative', title: 'Narrative', owner: 'agent', scopes: ['portfolio', 'board', 'goal'],
|
|
51
|
+
for: 'The standing, as-of story of a goal: where it stands, what changed this week, what is next. The only report.',
|
|
52
|
+
fields: Object.freeze([f('now', 'one', 'Where it stands'), f('week', 'list', 'This week'), f('asks', 'list', 'Stakeholder asks')]) }),
|
|
53
|
+
Object.freeze({ key: 'experiment', title: 'Experiment', owner: 'agent', scopes: ['experiment'],
|
|
54
|
+
for: 'The unit of work: a hypothesis, the kill condition, the budget and who builds it. "Initiative" is the stakeholder word for it.',
|
|
55
|
+
fields: Object.freeze([f('hypothesis', 'one', 'Hypothesis'), f('why', 'one', 'Problem'), f('evidence', 'list', 'Evidence'), f('kill', 'one', 'Kill condition'),
|
|
56
|
+
f('budget', 'one', 'Budget'), f('executor', 'one', 'Built by'), f('risks', 'list', 'Risks'), f('people', 'list', 'People'), f('related', 'list', 'Related experiments')]) }),
|
|
57
|
+
Object.freeze({ key: 'specimens', title: 'Specimens', owner: 'agent', scopes: ['experiment'],
|
|
58
|
+
for: 'Working attempts made against one done test, before any spec. The PM sees the winner.',
|
|
59
|
+
fields: Object.freeze([f('specimen', 'list', 'Attempts'), f('kept', 'one', 'Kept specimen')]) }),
|
|
60
|
+
Object.freeze({ key: 'done-test', title: 'Done test', owner: 'agent', scopes: ['experiment'],
|
|
61
|
+
for: 'The checks that say the experiment is done. A team that builds it gets the kept specimen and this test, not a PRD.',
|
|
62
|
+
fields: Object.freeze([f('check', 'list', 'Checks'), f('result', 'one', 'Result')]) }),
|
|
63
|
+
Object.freeze({ key: 'lessons', title: 'Lessons', owner: 'agent', scopes: ['portfolio', 'board', 'goal', 'experiment'],
|
|
64
|
+
for: 'One line per thing learned, kept or killed, with its pointer. The OS evolves its own process from these.',
|
|
65
|
+
fields: Object.freeze([f('line', 'list', 'Lessons')]) }),
|
|
66
|
+
]);
|
|
67
|
+
const KEYS = Object.freeze(ARTEFACTS.map((a) => a.key));
|
|
68
|
+
const BY_KEY = new Map(ARTEFACTS.map((a) => [a.key, a]));
|
|
69
|
+
const fieldOf = (artefact, field) => { const a = BY_KEY.get(artefact); return a ? a.fields.find((x) => x.name === field) || null : null; };
|
|
70
|
+
|
|
71
|
+
/* ── what the old shapes become ─────────────────────────────────────────────────────────────────────────────────────────────────
|
|
72
|
+
* Every one of the 36 core documents, keyed level:key (lib/core-docs.js SETS, plus initiative:wf-* for a workflow stage's document). */
|
|
73
|
+
const t = (artefact, field, note) => Object.freeze({ artefact, field, note });
|
|
74
|
+
const FROM_DOCS = Object.freeze({
|
|
75
|
+
'portfolio:strategy': t('intent', 'want', 'Vision and where we play is the PM\'s intent; what we will not do is its `not` line.'),
|
|
76
|
+
'portfolio:okrs': t('goal', 'reading', 'Goals are read from the OKRs and health budgets.'),
|
|
77
|
+
'portfolio:roadmap': t('goal', 'experiments', 'The goal portfolio replaces the roadmap: each goal lists its experiments and budgets.'),
|
|
78
|
+
'portfolio:invest': t('goal', 'experiments', 'The investment mix is the sum of the experiment budgets per goal.'),
|
|
79
|
+
'portfolio:scan': t('lessons', 'line', 'Horizon scans are sources (machinery); what they teach lands as lessons.'),
|
|
80
|
+
'portfolio:status': t('narrative', 'now', 'The status report is the standing narrative, as of today.'),
|
|
81
|
+
'portfolio:decisions': t('lessons', 'line', 'A decision and its reason is a lesson line.'),
|
|
82
|
+
'portfolio:kill': t('experiment', 'kill', 'Every experiment carries its own kill condition.'),
|
|
83
|
+
'portfolio:prisks': t('experiment', 'risks', 'Risks live on the experiment; the narrative names the ones that matter.'),
|
|
84
|
+
'portfolio:quarter': t('lessons', 'line', 'The quarterly review is the lessons of the quarter and the narrative as of its end.'),
|
|
85
|
+
'portfolio:context': t('lessons', 'line', 'Market and user research are sources; what they teach is a lesson.'),
|
|
86
|
+
'board:charter': t('intent', 'want', 'A board\'s purpose and scope is the intent of that area.'),
|
|
87
|
+
'board:backlog': t('goal', 'experiments', 'The ranked list is the experiments on each goal.'),
|
|
88
|
+
'board:intake': t('lessons', 'line', 'An ask declined, and why, is a lesson; an ask accepted becomes an experiment.'),
|
|
89
|
+
'board:bstatus': t('narrative', 'now', 'The board status report is the narrative of its goals.'),
|
|
90
|
+
'board:capacity': t('experiment', 'budget', 'Capacity is the experiment budgets and who builds each one.'),
|
|
91
|
+
'board:metrics': t('goal', 'reading', 'The numbers a board moves are its goals\' readings.'),
|
|
92
|
+
'board:brisks': t('experiment', 'risks', 'Risks live on the experiment.'),
|
|
93
|
+
'board:sprint': t('narrative', 'week', 'What a sprint finished is a weekly narrative line.'),
|
|
94
|
+
'board:release': t('narrative', 'week', 'A release is a weekly narrative line, every line cited.'),
|
|
95
|
+
'board:retro': t('lessons', 'line', 'A retro is the lessons across a board\'s experiments.'),
|
|
96
|
+
'initiative:record': t('experiment', 'hypothesis', 'The initiative record is the experiment.'),
|
|
97
|
+
'initiative:problem': t('experiment', 'why', 'The problem statement is the experiment\'s problem.'),
|
|
98
|
+
'initiative:research': t('experiment', 'evidence', 'Research notes are the experiment\'s evidence.'),
|
|
99
|
+
'initiative:rice': t('experiment', 'budget', 'Priority is the budget and the expected effect, compared across the goal.'),
|
|
100
|
+
'initiative:prd': t('done-test', 'check', 'Specimens before specs: the PRD\'s done criteria become the done test; the rest is the kept specimen.'),
|
|
101
|
+
'initiative:rubric': t('done-test', 'check', 'The rubric is the done test.'),
|
|
102
|
+
'initiative:design': t('specimens', 'specimen', 'A design or mockup is a specimen.'),
|
|
103
|
+
'initiative:stories': t('done-test', 'check', 'Stories become checks of the done test; a technical decision is a lesson.'),
|
|
104
|
+
'initiative:risks': t('experiment', 'risks', 'Risks live on the experiment.'),
|
|
105
|
+
'initiative:launch': t('done-test', 'check', 'What must be true to ship is part of the done test. Messages out still wait for the PM.'),
|
|
106
|
+
'initiative:review': t('done-test', 'result', 'The review verdict is the done test\'s result.'),
|
|
107
|
+
'initiative:update': t('narrative', 'week', 'A status update is a narrative line.'),
|
|
108
|
+
'initiative:explainer': t('narrative', 'now', 'An explainer is the narrative in plain words.'),
|
|
109
|
+
'initiative:outcome': t('lessons', 'line', 'An outcome review is a lesson, and the reading on the goal.'),
|
|
110
|
+
'initiative:wf-*': t('specimens', 'specimen', 'What a workflow stage produces is a specimen of the experiment.'),
|
|
111
|
+
});
|
|
112
|
+
/* The 9 driver proposal kinds of an initiative (lib/driver.js WHATS.initiative). `move` is not an artefact: R11, a stage is derived. */
|
|
113
|
+
const FROM_WHATS = Object.freeze({
|
|
114
|
+
problem: t('experiment', 'why', 'The problem.'),
|
|
115
|
+
evidence: t('experiment', 'evidence', 'One evidence line per item, each with its pointer.'),
|
|
116
|
+
sizing: t('experiment', 'budget', 'Reach and impact are the budget\'s expected effect.'),
|
|
117
|
+
assumption: t('experiment', 'hypothesis', 'The riskiest assumption is the hypothesis; its test is the kill condition.'),
|
|
118
|
+
stakeholders: t('experiment', 'people', 'Who to ask.'),
|
|
119
|
+
move: t(null, null, 'A stage is derived from the work, never declared (R11): a move is not an artefact.'),
|
|
120
|
+
note: t('lessons', 'line', 'A note is a lesson line.'),
|
|
121
|
+
doc: t(null, null, 'A document proposal goes where its document goes (FROM_DOCS).'),
|
|
122
|
+
overlap: t('experiment', 'related', 'An overlap is a related experiment.'),
|
|
123
|
+
});
|
|
124
|
+
/* The 5 report cadences (lib/report-setups.js CADENCES plus quarterly). R9: the narrative is the only report. */
|
|
125
|
+
const FROM_CADENCES = Object.freeze({
|
|
126
|
+
daily: t('narrative', 'week', 'No daily report: a change shows where the work is (R7).'),
|
|
127
|
+
weekly: t('narrative', 'week', 'One weekly line on the standing narrative.'),
|
|
128
|
+
'bi-weekly': t('narrative', 'week', 'The narrative is standing: read it as of any date.'),
|
|
129
|
+
monthly: t('narrative', 'now', 'The narrative is standing: read it as of any date.'),
|
|
130
|
+
quarterly: t('lessons', 'line', 'A quarter is its lessons and the narrative as of its end.'),
|
|
131
|
+
});
|
|
132
|
+
/* The 6 lanes (D56, D58, D60). R12: everything is an experiment; the lane's one difference becomes a field or another artefact. */
|
|
133
|
+
const FROM_LANES = Object.freeze({
|
|
134
|
+
feature: t('experiment', 'hypothesis', 'A feature is an experiment with a hypothesis, a kill condition and a done test.'),
|
|
135
|
+
discovery: t('experiment', 'hypothesis', 'A spike is an experiment whose done test is the question answered.'),
|
|
136
|
+
chore: t('experiment', 'budget', 'A chore is an experiment anchored to a health budget, with a done test and no hypothesis to argue.'),
|
|
137
|
+
incident: t('lessons', 'line', 'An incident is a lesson written after the fact, and an experiment only when there is work to do.'),
|
|
138
|
+
content: t('specimens', 'specimen', 'Content is an experiment whose specimens are the drafts.'),
|
|
139
|
+
prototype: t('specimens', 'specimen', 'A prototype is the specimens of an experiment (R13: specimens before specs, always).'),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
function targetOfDoc(level, key) {
|
|
143
|
+
const k = String(key || '');
|
|
144
|
+
return FROM_DOCS[`${level}:${k}`] || (level === 'initiative' && /^wf-/.test(k) ? FROM_DOCS['initiative:wf-*'] : null);
|
|
145
|
+
}
|
|
146
|
+
function targetOfWhat(what, data) {
|
|
147
|
+
if (what === 'doc' && isObj(data) && data.key) return targetOfDoc('initiative', data.key) || FROM_WHATS.doc;
|
|
148
|
+
return FROM_WHATS[what] || null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── scopes ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
152
|
+
function parseScope(scope) {
|
|
153
|
+
const s = String(scope || '');
|
|
154
|
+
if (s === 'portfolio') return { kind: 'portfolio', id: null, scope: 'portfolio' };
|
|
155
|
+
const m = /^(board|goal|experiment|initiative):(.+)$/.exec(s);
|
|
156
|
+
if (!m || !ID_RE.test(m[2])) return null;
|
|
157
|
+
const kind = m[1] === 'initiative' ? 'experiment' : m[1];
|
|
158
|
+
return { kind, id: m[2], scope: `${kind}:${m[2]}` };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ── the ledger ───────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
162
|
+
const file = (dir) => (dir ? path.join(dir, LEDGER) : null);
|
|
163
|
+
function readLines(f) {
|
|
164
|
+
let text = '';
|
|
165
|
+
try { text = fs.readFileSync(f, 'utf8'); } catch { return []; }
|
|
166
|
+
const out = [];
|
|
167
|
+
for (const raw of text.split('\n')) {
|
|
168
|
+
if (!raw.trim()) continue;
|
|
169
|
+
try { const l = JSON.parse(raw); if (isObj(l) && EVENTS.includes(l.ev)) out.push(l); } catch { /* a torn line is skipped */ }
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
const newId = () => `a-${crypto.randomBytes(5).toString('hex')}`;
|
|
174
|
+
/** THE SINGLE WRITER of artefacts.jsonl. `v`, `id` (when absent) and `at` are set here. */
|
|
175
|
+
function append(f, line, { now } = {}) {
|
|
176
|
+
if (!isObj(line) || !EVENTS.includes(line.ev)) throw new Error(`artefacts: unknown event ${JSON.stringify(line && line.ev)}`);
|
|
177
|
+
const out = { v: 1, ev: line.ev, id: line.id || newId(), ...line, at: new Date(now == null ? Date.now() : now).toISOString() };
|
|
178
|
+
out.v = 1;
|
|
179
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
180
|
+
fs.appendFileSync(f, JSON.stringify(out) + '\n');
|
|
181
|
+
return out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Map scope → Map artefact → { sets: [line], carried: [line] }, with undone sets removed. Pure. */
|
|
185
|
+
function fold(lines) {
|
|
186
|
+
const undone = new Set();
|
|
187
|
+
for (const l of lines || []) if (l && l.ev === 'undo' && typeof l.ref === 'string') undone.add(l.ref);
|
|
188
|
+
const m = new Map();
|
|
189
|
+
const seen = new Set();
|
|
190
|
+
const slot = (scope, artefact) => {
|
|
191
|
+
if (!m.has(scope)) m.set(scope, new Map());
|
|
192
|
+
const s = m.get(scope);
|
|
193
|
+
if (!s.has(artefact)) s.set(artefact, { sets: [], carried: [] });
|
|
194
|
+
return s.get(artefact);
|
|
195
|
+
};
|
|
196
|
+
for (const l of lines || []) {
|
|
197
|
+
if (!isObj(l) || typeof l.scope !== 'string' || !BY_KEY.has(l.artefact)) continue;
|
|
198
|
+
if (l.ev === 'set' && !undone.has(l.id) && fieldOf(l.artefact, l.field)) slot(l.scope, l.artefact).sets.push(l);
|
|
199
|
+
else if (l.ev === 'carry' && isObj(l.from)) {
|
|
200
|
+
const k = `${l.from.kind}|${l.from.ref}`;
|
|
201
|
+
if (seen.has(k)) continue;
|
|
202
|
+
seen.add(k);
|
|
203
|
+
slot(l.scope, l.artefact).carried.push(l);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return m;
|
|
207
|
+
}
|
|
208
|
+
const carriedKeys = (lines) => new Set((lines || []).filter((l) => l && l.ev === 'carry' && isObj(l.from)).map((l) => `${l.from.kind}|${l.from.ref}`));
|
|
209
|
+
|
|
210
|
+
/** The seven artefacts of one scope, the ones that fit it, each with its current fields and what was carried into it. Pure. */
|
|
211
|
+
function viewOf(state, scope) {
|
|
212
|
+
const p = parseScope(scope);
|
|
213
|
+
if (!p) return null;
|
|
214
|
+
const here = (state && state.get(p.scope)) || new Map();
|
|
215
|
+
const artefacts = ARTEFACTS.filter((a) => a.scopes.includes(p.kind) || here.has(a.key)).map((a) => {
|
|
216
|
+
const x = here.get(a.key) || { sets: [], carried: [] };
|
|
217
|
+
const fields = {};
|
|
218
|
+
for (const fd of a.fields) {
|
|
219
|
+
const sets = x.sets.filter((l) => l.field === fd.name).map((l) => ({ id: l.id, text: l.text, sources: l.sources || [], by: l.by || null, at: l.at || null }));
|
|
220
|
+
fields[fd.name] = fd.mode === 'one' ? (sets.length ? sets[sets.length - 1] : null) : sets;
|
|
221
|
+
}
|
|
222
|
+
const carried = x.carried.map((l) => ({ field: l.field || null, ...l.from, at: l.at || null }));
|
|
223
|
+
const empty = !carried.length && Object.values(fields).every((v) => (Array.isArray(v) ? !v.length : !v));
|
|
224
|
+
return { key: a.key, title: a.title, owner: a.owner, for: a.for, labels: Object.fromEntries(a.fields.map((fd) => [fd.name, fd.label])), fields, carried, empty };
|
|
225
|
+
});
|
|
226
|
+
return { scope: p.scope, kind: p.kind, artefacts };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// ── writes ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
|
|
230
|
+
const refuse = (status, error) => ({ ok: false, status, error });
|
|
231
|
+
const oneLine = (v, max) => typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= max && !/[\r\n\x00-\x08\x0b-\x1f]/.test(v);
|
|
232
|
+
const validBy = (actor) => isObj(actor) && typeof actor.by === 'string' && /^(pm|agent):/.test(actor.by);
|
|
233
|
+
const isPmActor = (actor) => validBy(actor) && actor.by.startsWith('pm:');
|
|
234
|
+
|
|
235
|
+
/** Check a set without writing it. → { ok, line } | refusal. */
|
|
236
|
+
function checkSet({ scope, artefact, field, text, sources } = {}, actor) {
|
|
237
|
+
if (!validBy(actor)) return refuse(403, 'only the PM or an agent session writes an artefact');
|
|
238
|
+
const p = parseScope(scope);
|
|
239
|
+
if (!p) return refuse(400, 'scope must be portfolio, board:<id>, goal:<id> or experiment:<id>');
|
|
240
|
+
const a = BY_KEY.get(artefact);
|
|
241
|
+
if (!a) return refuse(400, `artefact must be one of ${KEYS.join(', ')}`);
|
|
242
|
+
if (a.owner === 'derived') return refuse(409, `${a.title} is read from the OKRs, health budgets and readings; it is never typed`);
|
|
243
|
+
if (a.owner === 'pm' && !isPmActor(actor)) return refuse(403, `${a.title} is the PM's: propose the change and the PM keeps it`);
|
|
244
|
+
if (!a.scopes.includes(p.kind)) return refuse(400, `${a.title} lives on ${a.scopes.join(' or ')}, not on ${p.kind}`);
|
|
245
|
+
const fd = field ? fieldOf(a.key, field) : a.fields[0];
|
|
246
|
+
if (!fd) return refuse(400, `field must be one of ${a.fields.map((x) => x.name).join(', ')}`);
|
|
247
|
+
if (typeof text !== 'string' || !text.trim() || text.length > MAX_TEXT) return refuse(400, `text is 1 to ${MAX_TEXT} characters`);
|
|
248
|
+
if (a.key === 'experiment' && fd.name === 'executor' && !EXECUTORS.includes(text.trim())) return refuse(400, `executor is one of ${EXECUTORS.join(', ')}`);
|
|
249
|
+
const src = [];
|
|
250
|
+
for (const s of Array.isArray(sources) ? sources : []) {
|
|
251
|
+
if (!isObj(s) || !oneLine(s.label, 80) || !oneLine(s.ref, 500)) return refuse(400, 'each source needs a label (up to 80 characters) and a ref (up to 500)');
|
|
252
|
+
src.push({ label: s.label.trim(), ref: s.ref.trim() });
|
|
253
|
+
}
|
|
254
|
+
return { ok: true, line: { ev: 'set', scope: p.scope, artefact: a.key, field: fd.name, text: text.trim(), sources: src, by: actor.by } };
|
|
255
|
+
}
|
|
256
|
+
function set(f, input, actor, { now } = {}) {
|
|
257
|
+
if (!f) return refuse(409, 'this repository has no state folder for the artefacts');
|
|
258
|
+
const c = checkSet(input, actor);
|
|
259
|
+
if (!c.ok) return c;
|
|
260
|
+
return { ok: true, line: append(f, c.line, { now }) };
|
|
261
|
+
}
|
|
262
|
+
function undo(f, { ref } = {}, actor, { now } = {}) {
|
|
263
|
+
if (!f) return refuse(409, 'this repository has no state folder for the artefacts');
|
|
264
|
+
if (!validBy(actor)) return refuse(403, 'only the PM or an agent session undoes an artefact line');
|
|
265
|
+
if (!REF_RE.test(String(ref || ''))) return refuse(400, 'ref is the id of a set line (a-<10 hex>)');
|
|
266
|
+
const lines = readLines(f);
|
|
267
|
+
const hit = lines.find((l) => l.ev === 'set' && l.id === ref);
|
|
268
|
+
if (!hit) return refuse(404, `no artefact line ${ref}`);
|
|
269
|
+
if (lines.some((l) => l.ev === 'undo' && l.ref === ref)) return refuse(409, 'that line is undone already');
|
|
270
|
+
if (BY_KEY.get(hit.artefact).owner === 'pm' && !isPmActor(actor)) return refuse(403, 'Intent is the PM\'s: only the PM undoes it');
|
|
271
|
+
return { ok: true, line: append(f, { ev: 'undo', scope: hit.scope, artefact: hit.artefact, ref, by: actor.by }, { now }) };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// ── migration: the old records, carried into the seven ───────────────────────────────────────────────────────────────────────
|
|
275
|
+
const short = (v, n = 500) => { const s = String(v == null ? '' : v).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1) + '…' : s; };
|
|
276
|
+
function proposalText(p) {
|
|
277
|
+
const d = p.data;
|
|
278
|
+
if (!isObj(d)) return short(d);
|
|
279
|
+
if (typeof d.text === 'string') return short(d.text);
|
|
280
|
+
if (p.what === 'assumption') return short([d.assumption, d.test && `Test: ${d.test}`].filter(Boolean).join(' · '));
|
|
281
|
+
if (p.what === 'sizing') return short([d.reach && `Reach: ${d.reach}`, d.impact && `Impact: ${d.impact}`].filter(Boolean).join(' · '));
|
|
282
|
+
if (p.what === 'evidence' && Array.isArray(d.items)) return short(d.items.map((x) => isObj(x) ? `${x.text} (${x.ref})` : String(x)).join(' · '));
|
|
283
|
+
if (p.what === 'overlap') return short(`With ${d.with}${d.text ? `: ${d.text}` : ''}`);
|
|
284
|
+
return short(JSON.stringify(d));
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The carry lines that put every older record under its artefact. Pure: the caller reads and writes.
|
|
288
|
+
* coreDocs: core-docs.js fold() (Map 'scope|key' → { scope, key, issued, draft, issues, drafts })
|
|
289
|
+
* driverLines: driver.js readLines() of driver.jsonl; a kept proposal is carried (open, returned, dropped and undone ones are not the record)
|
|
290
|
+
* reports: [{ cadence, slot, path }] the report drafts on disk
|
|
291
|
+
* have: the from-keys already carried
|
|
292
|
+
* → [carry line without v/at]
|
|
293
|
+
*/
|
|
294
|
+
function planMigration({ coreDocs = new Map(), driverLines = [], reports = [], have = new Set() } = {}) {
|
|
295
|
+
const out = [];
|
|
296
|
+
const push = (scope, tg, from) => {
|
|
297
|
+
if (!tg || !tg.artefact) return;
|
|
298
|
+
const k = `${from.kind}|${from.ref}`;
|
|
299
|
+
if (have.has(k)) return;
|
|
300
|
+
have.add(k);
|
|
301
|
+
out.push({ ev: 'carry', scope, artefact: tg.artefact, field: tg.field, from, by: 'migrate' });
|
|
302
|
+
};
|
|
303
|
+
for (const x of coreDocs.values()) {
|
|
304
|
+
const p = /^(portfolio)$|^(board|initiative):(.+)$/.exec(String(x.scope || ''));
|
|
305
|
+
if (!p) continue;
|
|
306
|
+
const level = p[1] || p[2];
|
|
307
|
+
const scope = level === 'initiative' ? `experiment:${p[3]}` : x.scope;
|
|
308
|
+
const tg = targetOfDoc(level, x.key);
|
|
309
|
+
const docs = [...(x.issues || []), ...(x.draft ? [x.draft] : [])];
|
|
310
|
+
for (const d of docs) push(scope, tg, { kind: 'core-doc', ref: `${x.scope}|${x.key}|${d.slot}`, path: d.path || null, title: x.key, state: d.ev === 'issue' ? 'issued' : 'draft' });
|
|
311
|
+
}
|
|
312
|
+
const D = require('./driver.js');
|
|
313
|
+
const st = D.fold(driverLines);
|
|
314
|
+
for (const id of st.order) {
|
|
315
|
+
const pr = st.proposals.get(id);
|
|
316
|
+
if (!pr || pr.state !== 'kept' || pr.target.kind !== 'initiative') continue;
|
|
317
|
+
if (pr.what === 'artefact') continue; // written to this ledger already when it was kept
|
|
318
|
+
push(`experiment:${pr.target.id}`, targetOfWhat(pr.what, pr.data), { kind: 'proposal', ref: pr.id, title: pr.what, text: proposalText(pr), state: 'kept' });
|
|
319
|
+
}
|
|
320
|
+
for (const r of reports) {
|
|
321
|
+
const tg = FROM_CADENCES[r.cadence] || FROM_CADENCES.weekly;
|
|
322
|
+
push('portfolio', tg, { kind: 'report', ref: `${r.cadence}/${r.slot}`, path: r.path || null, title: `${r.cadence} report`, state: 'draft' });
|
|
323
|
+
}
|
|
324
|
+
return out;
|
|
325
|
+
}
|
|
326
|
+
/** Write the carry lines that are not written yet. Idempotent: a second run carries nothing. Nothing is deleted or moved. */
|
|
327
|
+
function migrate({ dir, coreDocs, driverLines, reports } = {}, { now } = {}) {
|
|
328
|
+
const f = file(dir);
|
|
329
|
+
if (!f) return refuse(409, 'this repository has no state folder for the artefacts');
|
|
330
|
+
const before = readLines(f);
|
|
331
|
+
const have = carriedKeys(before);
|
|
332
|
+
const already = have.size;
|
|
333
|
+
const plan = planMigration({ coreDocs, driverLines, reports, have });
|
|
334
|
+
const lines = plan.map((l) => append(f, l, { now }));
|
|
335
|
+
return { ok: true, carried: lines.length, already, lines };
|
|
336
|
+
}
|
|
337
|
+
/** The report drafts on disk under <state>/reports/<cadence>/<slot>.md (definitions excluded). */
|
|
338
|
+
function reportDrafts(stateAbs, rel) {
|
|
339
|
+
const base = path.join(stateAbs, 'reports');
|
|
340
|
+
const out = [];
|
|
341
|
+
let cads = [];
|
|
342
|
+
try { cads = fs.readdirSync(base, { withFileTypes: true }).filter((d) => d.isDirectory() && d.name !== 'definitions').map((d) => d.name); } catch { return out; }
|
|
343
|
+
for (const c of cads.sort()) {
|
|
344
|
+
let files = [];
|
|
345
|
+
try { files = fs.readdirSync(path.join(base, c)).filter((n) => /\.md$/.test(n)).sort(); } catch { continue; }
|
|
346
|
+
for (const n of files) out.push({ cadence: c, slot: n.replace(/\.md$/, ''), path: `${rel}/reports/${c}/${n}` });
|
|
347
|
+
}
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
350
|
+
/** Where a repository keeps this ledger: the core documents' state folder (pmos/state in a kit repository, planning in PMOS-self). */
|
|
351
|
+
function dirOf(root) {
|
|
352
|
+
const CD = require('./core-docs.js');
|
|
353
|
+
return path.dirname(CD.ledgerFile(root));
|
|
354
|
+
}
|
|
355
|
+
/** Read every older record of a repository and carry it. */
|
|
356
|
+
function migrateRepo(root, { now } = {}) {
|
|
357
|
+
const CD = require('./core-docs.js');
|
|
358
|
+
const D = require('./driver.js');
|
|
359
|
+
const dir = dirOf(root);
|
|
360
|
+
const rel = path.relative(path.resolve(String(root)), dir).split(path.sep).join('/');
|
|
361
|
+
const sd = D.stateDirOf(root);
|
|
362
|
+
return migrate({ dir, coreDocs: CD.fold(CD.readLines(CD.ledgerFile(root))), driverLines: sd ? D.readLines(D.ledgerFile(sd)) : [], reports: reportDrafts(dir, rel) }, { now });
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
module.exports = {
|
|
366
|
+
LEDGER, EVENTS, ARTEFACTS, KEYS, EXECUTORS, FROM_DOCS, FROM_WHATS, FROM_CADENCES, FROM_LANES,
|
|
367
|
+
parseScope, targetOfDoc, targetOfWhat, fieldOf, file, readLines, append, fold, viewOf, checkSet, set, undo,
|
|
368
|
+
planMigration, migrate, migrateRepo, reportDrafts, dirOf, proposalText,
|
|
369
|
+
};
|
|
@@ -57,6 +57,7 @@ const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().sli
|
|
|
57
57
|
const DRIVER_CLASS = Object.freeze({
|
|
58
58
|
note: 'A',
|
|
59
59
|
problem: 'B', evidence: 'B', sizing: 'B', assumption: 'B', stakeholders: 'B', overlap: 'B', doc: 'B', 'next-step': 'B',
|
|
60
|
+
artefact: 'B', // R18: a field of one of the seven artefacts; Intent is the PM's and its Keep refuses an agent (lib/artefacts.js)
|
|
60
61
|
move: 'C', // a stage move shows on boards others read (D103) and can move a Jira ticket (D100)
|
|
61
62
|
'follow-up': 'C', // a message to a person
|
|
62
63
|
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/*
|
|
3
|
+
* lib/claude-signin.js — the command the PM types to sign Claude in again: the one for the Claude profile PMOS runs under.
|
|
4
|
+
*
|
|
5
|
+
* Every background run starts under the PM's chosen Claude profile (prefs.json `claude`, Settings → Claude). The sign-in
|
|
6
|
+
* advice said "run claude" whatever that choice was. On a Mac whose runs use `claude-personal`, that advice signs in the
|
|
7
|
+
* wrong login, and the runs stay signed out (bug 2026-11-08). The advice now names the command of the chosen profile.
|
|
8
|
+
*
|
|
9
|
+
* commandFor(profile, home) → 'claude' | 'claude-personal' | 'CLAUDE_CONFIG_DIR=~/.claude-x claude'
|
|
10
|
+
* profile: the resolved profile (lib/profiles.js shape) or null for Claude's own login.
|
|
11
|
+
* configure({ profile }) the server registers () => profile (setResolver(fn) is the same); the libraries read it through command()
|
|
12
|
+
* command() the command for the profile chosen now ('claude' when nothing is registered or it fails)
|
|
13
|
+
* how() 'Open Terminal, run `<command>`, type /login and sign in.'
|
|
14
|
+
* signedOutWhy() the reason a background run shows when Claude was signed out
|
|
15
|
+
* paneSignedOut(screen) a terminal pane's screen is Claude's sign-in (expired login, login-method picker)
|
|
16
|
+
*/
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const os = require('os');
|
|
19
|
+
|
|
20
|
+
const SAFE = /^[a-zA-Z0-9._-]{1,80}$/;
|
|
21
|
+
const tilde = (p, home) => (home && (p === home || p.startsWith(home + path.sep)) ? '~' + p.slice(home.length) : p);
|
|
22
|
+
|
|
23
|
+
function commandFor(profile, home = os.homedir()) {
|
|
24
|
+
if (!profile || typeof profile !== 'object') return 'claude';
|
|
25
|
+
const d = profile.detected && profile.detected.source;
|
|
26
|
+
// an alias, a shell function or a launcher script: its name is a command the PM can type
|
|
27
|
+
if ((d === 'shell' || d === 'launcher') && SAFE.test(String(profile.id || ''))) return String(profile.id);
|
|
28
|
+
const dir = profile.env && typeof profile.env === 'object' ? profile.env.CLAUDE_CONFIG_DIR : '';
|
|
29
|
+
if (typeof dir === 'string' && dir) {
|
|
30
|
+
const shown = tilde(path.resolve(dir), home);
|
|
31
|
+
return /^[~a-zA-Z0-9._/-]+$/.test(shown) ? `CLAUDE_CONFIG_DIR=${shown} claude` : `CLAUDE_CONFIG_DIR='${shown.replace(/'/g, "'\\''")}' claude`;
|
|
32
|
+
}
|
|
33
|
+
return 'claude';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let resolver = null;
|
|
37
|
+
function setResolver(fn) { resolver = typeof fn === 'function' ? fn : null; }
|
|
38
|
+
/** The server's wiring: configure({ profile: () => profile }) → this module. */
|
|
39
|
+
function configure({ profile } = {}) { setResolver(profile); return module.exports; }
|
|
40
|
+
function command() {
|
|
41
|
+
if (!resolver) return 'claude';
|
|
42
|
+
try { return commandFor(resolver()); } catch { return 'claude'; }
|
|
43
|
+
}
|
|
44
|
+
const how = () => `Open Terminal, run \`${command()}\`, type /login and sign in.`;
|
|
45
|
+
// Claude Code's own sign-in screens in a terminal pane: the expired-login line, and the login-method picker it opens. Narrower than
|
|
46
|
+
// lib/headless.js signedOut(), which reads a run's result: a pane also shows the agent's own words, which may name a login.
|
|
47
|
+
const PANE_RE = /please run \/login|select login method|oauth (?:session|token) (?:has )?expired/i;
|
|
48
|
+
const paneSignedOut = (screen) => PANE_RE.test(String(screen || ''));
|
|
49
|
+
const signedOutWhy = () => `Claude is signed out on this computer. ${how()} PMOS carries on by itself afterwards.`;
|
|
50
|
+
|
|
51
|
+
module.exports = { commandFor, configure, setResolver, command, how, signedOutWhy, paneSignedOut };
|
|
@@ -32,7 +32,7 @@ const COMMANDS = { driver: ['propose', 'status', 'keep', 'return', 'drop', 'undo
|
|
|
32
32
|
const USAGE = [
|
|
33
33
|
'usage: pmos driver propose|status|keep|return|drop|undo|pause|resume|mode — the Initiative Driver',
|
|
34
34
|
' pmos driver propose <initiative|work> <id> --what <what> (--file <json|md> | --data "<text>") --why "<one line>" [--source label=ref …] [--confidence 0..1] [--recommended "<what you suggest>"] [--reversible true|false] [--effort S|M|L]',
|
|
35
|
-
' what: problem, evidence, sizing, assumption, stakeholders, move, note, doc, overlap (initiative) · next-step, follow-up, note (Work task)',
|
|
35
|
+
' what: problem, evidence, sizing, assumption, stakeholders, move, note, doc, overlap, artefact (initiative) · next-step, follow-up, note (Work task)',
|
|
36
36
|
' pmos driver status <initiative|work> <id>',
|
|
37
37
|
' pmos driver keep <proposal> PM only',
|
|
38
38
|
' pmos driver return <proposal> --note "<what to change>" PM only',
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* move → the board move route's own function (lib/routes-boards.js move): its validation and warnings apply
|
|
22
22
|
* next-step → lib/pm-items.js appendEvent: a step (lib/item-steps.js) and, when the proposal names a date, an `edited` due
|
|
23
23
|
* doc → lib/core-docs.js issue: the draft the run wrote is issued (one `issue` line, `state: issued` in its file), as the PM
|
|
24
|
+
* artefact → lib/artefacts.js set: one field of one of the seven artefacts (R18), with Undo. Intent refuses an agent's Keep
|
|
24
25
|
* Every other kind (evidence, sizing, assumption, stakeholders, follow-up, note) is kept as a decision only: the PM's choice to
|
|
25
26
|
* rely on it. A follow-up is never sent: the PM sends it from their own session. The driver never moves a stage by itself (D3).
|
|
26
27
|
* RETURN needs a note and DROP may carry one; each logs one correction (the north star counts it) and a return wakes a run.
|
|
@@ -60,6 +61,15 @@ async function writeRecord(p, actor, ctx, now) {
|
|
|
60
61
|
if (!r.ok) return refuse(r.status || 409, r.error);
|
|
61
62
|
return { ok: true, wrote: 'doc' };
|
|
62
63
|
}
|
|
64
|
+
if (p.what === 'artefact') {
|
|
65
|
+
// R18 (proposed D107): one field of one of the seven artefacts. Intent is the PM's: an agent's Keep of it is refused and it waits.
|
|
66
|
+
if (!ctx.root) return refuse(409, 'this repository has no folder for the artefacts');
|
|
67
|
+
const A = require('./artefacts.js');
|
|
68
|
+
const d = p.data || {};
|
|
69
|
+
const r = A.set(A.file(A.dirOf(ctx.root)), { scope: d.scope, artefact: d.artefact, field: d.field, text: d.text, sources: p.sources }, actor, { now });
|
|
70
|
+
if (!r.ok) return refuse(r.status || 409, r.error);
|
|
71
|
+
return { ok: true, wrote: 'artefact', undo: { op: 'artefact', ref: r.line.id } };
|
|
72
|
+
}
|
|
63
73
|
if (p.what === 'next-step') {
|
|
64
74
|
if (!ctx.itemsDir) return refuse(409, 'no folder for the Work items');
|
|
65
75
|
const paths = itemsPaths(ctx.itemsDir);
|
|
@@ -79,7 +89,7 @@ async function writeRecord(p, actor, ctx, now) {
|
|
|
79
89
|
|
|
80
90
|
/* D106 "no Undo, no auto": the kinds whose Keep has an Undo. A decision-only kind (evidence, sizing, …) is undone in the ledger alone.
|
|
81
91
|
* `doc` issues a document and `move` moves a stage: neither has an Undo writer, so neither is applied by itself. */
|
|
82
|
-
const UNDOABLE = new Set(['problem', 'next-step', 'evidence', 'sizing', 'assumption', 'stakeholders', 'note', 'overlap']);
|
|
92
|
+
const UNDOABLE = new Set(['problem', 'next-step', 'evidence', 'sizing', 'assumption', 'stakeholders', 'note', 'overlap', 'artefact']);
|
|
83
93
|
|
|
84
94
|
async function decide(verb, { file, proposal, note, actor, ctx = {}, now, auto = false } = {}) {
|
|
85
95
|
if (!['keep', 'return', 'drop'].includes(verb)) return refuse(500, `driver: ${JSON.stringify(verb)} is not a decision`);
|
|
@@ -151,6 +161,10 @@ async function undo({ file, proposal, actor, ctx = {}, now, stateDir, product =
|
|
|
151
161
|
if (!now2 || JSON.stringify(now2.data) !== JSON.stringify(u.to)) back = false; // edited since: it keeps its edit
|
|
152
162
|
else if (u.from) stageTools.appendTool(ctx.stageFile, { initiative: p.target.id, tool: 'problem', data: u.from }, actor, { now: t });
|
|
153
163
|
else stageTools.clearTool(ctx.stageFile, { initiative: p.target.id, tool: 'problem' }, actor, { now: t });
|
|
164
|
+
} else if (p.what === 'artefact' && u.op === 'artefact' && ctx.root) {
|
|
165
|
+
const A = require('./artefacts.js');
|
|
166
|
+
const r = A.undo(A.file(A.dirOf(ctx.root)), { ref: u.ref }, actor, { now: t });
|
|
167
|
+
if (!r.ok) back = false;
|
|
154
168
|
} else if (p.what === 'next-step' && u.op === 'next-step' && ctx.itemsDir) {
|
|
155
169
|
const paths = itemsPaths(ctx.itemsDir);
|
|
156
170
|
pmItems.appendEvent(paths.steps, { event: 'step_removed', id: u.step }, new Date(t));
|
package/workspace/lib/driver.js
CHANGED
|
@@ -52,7 +52,7 @@ const crypto = require('crypto');
|
|
|
52
52
|
const LEDGER = 'driver.jsonl';
|
|
53
53
|
const KINDS = Object.freeze(['initiative', 'work']);
|
|
54
54
|
const WHATS = Object.freeze({
|
|
55
|
-
initiative: Object.freeze(['problem', 'evidence', 'sizing', 'assumption', 'stakeholders', 'move', 'note', 'doc', 'overlap']),
|
|
55
|
+
initiative: Object.freeze(['problem', 'evidence', 'sizing', 'assumption', 'stakeholders', 'move', 'note', 'doc', 'overlap', 'artefact']),
|
|
56
56
|
work: Object.freeze(['next-step', 'follow-up', 'note']),
|
|
57
57
|
});
|
|
58
58
|
// A claim without a pointer is not a proposal (PRD section 2: "Nothing without a pointer").
|
|
@@ -185,6 +185,14 @@ function checkProposal(input) {
|
|
|
185
185
|
const c = checkOverlap(data, t.target.id);
|
|
186
186
|
if (!c.ok) return c;
|
|
187
187
|
data = c.data;
|
|
188
|
+
} else if (i.what === 'artefact') {
|
|
189
|
+
// R18 (proposed D107): one field of one of the seven artefacts (lib/artefacts.js). Keep writes it to artefacts.jsonl, with Undo.
|
|
190
|
+
// The scope is this experiment unless data.scope names the portfolio or a board (Intent, Narrative, Lessons).
|
|
191
|
+
const A = require('./artefacts.js');
|
|
192
|
+
const scope = typeof data.scope === 'string' && data.scope ? data.scope : `experiment:${t.target.id}`;
|
|
193
|
+
const c = A.checkSet({ scope, artefact: data.artefact, field: data.field, text: data.text }, { by: 'pm:check' });
|
|
194
|
+
if (!c.ok) return { ok: false, error: `an artefact proposal: ${c.error}` };
|
|
195
|
+
data = { scope: c.line.scope, artefact: c.line.artefact, field: c.line.field, text: c.line.text };
|
|
188
196
|
} else if (i.what === 'next-step') {
|
|
189
197
|
if (!oneLine(data.text, 500)) return { ok: false, error: 'a next step needs data.text: one line of up to 500 characters' };
|
|
190
198
|
if (data.due != null && !(typeof data.due === 'string' && DATE_RE.test(data.due))) return { ok: false, error: 'data.due is YYYY-MM-DD' };
|
|
@@ -84,7 +84,7 @@ function of({ now, settings, state = {}, log, briefAt = 0, sessions = [], lastTi
|
|
|
84
84
|
if (signedOut.length) {
|
|
85
85
|
const names = signedOut.map((x) => x.label);
|
|
86
86
|
const list = names.length === 1 ? names[0] : names.slice(0, -1).join(', ') + ' and ' + names[names.length - 1];
|
|
87
|
-
add('bad', 'signedout', `Claude could not sign in at ${hm(Math.max(...signedOut.map((x) => x.at)))}, so ${list} did not refresh. Press Refresh all. If it fails again, open Terminal, run claude and type /login.`);
|
|
87
|
+
add('bad', 'signedout', `Claude could not sign in at ${hm(Math.max(...signedOut.map((x) => x.at)))}, so ${list} did not refresh. Press Refresh all. If it fails again, open Terminal, run ${require('./claude-signin.js').command()} and type /login.`);
|
|
88
88
|
}
|
|
89
89
|
const sync = runs('sync')[0];
|
|
90
90
|
if (set.sources.sync && set.sources.sync.on && sync && sync.result === 'failed') {
|
|
@@ -618,7 +618,7 @@ function outcomeOf(r, { code = null, signal = null, timedOut = false, stopped =
|
|
|
618
618
|
else if (stopped) why = 'Stopped by you.';
|
|
619
619
|
else if (timedOut) why = `Stopped: still running after ${timeoutMin || Math.round(DEFAULT_TIMEOUT_MS / 60000)} minutes.`;
|
|
620
620
|
else if (signal) why = `The process was ended (${signal}).`;
|
|
621
|
-
else if (signedOut(res.text)) why =
|
|
621
|
+
else if (signedOut(res.text)) why = require('./claude-signin.js').signedOutWhy();
|
|
622
622
|
else if (!res.ok) why = `It exited with code ${code} and printed no result${res.text ? ': ' + oneLine(res.text.split('\n').filter(Boolean).pop(), 200) : '.'}`;
|
|
623
623
|
else if (res.isError) why = `The run reported an error${first ? ': ' + oneLine(first, 200) : '.'}`;
|
|
624
624
|
else why = `It exited with code ${code}.`;
|
|
@@ -122,6 +122,9 @@ const VERBS = Object.freeze({
|
|
|
122
122
|
// Not a pm-os-absorb verb (run: null): initiative horizon-scan added it through the same table; horizon-scan-portfolio added section, propose, setting and --boards.
|
|
123
123
|
scan: Object.freeze({ module: 'scan-cli.js', run: null, guide: 'cli.md',
|
|
124
124
|
help: 'pmos scan file|section|propose|list [--sections]|match|suggest [--boards]|status|setting|cadence|watch [--boards] … — the Horizon scan: the portfolio watch list, the findings, the report sections and the proposals the PM approves, changes or dismisses (pmos scan help)' }),
|
|
125
|
+
// Not a pm-os-absorb verb (run: null): R18 (proposed D107), the seven artefacts, added it through the same table.
|
|
126
|
+
artefacts: Object.freeze({ module: 'artefacts-cli.js', run: null, guide: 'cli.md',
|
|
127
|
+
help: 'pmos artefacts show|map|migrate|set|undo — the seven artefacts (Intent, Goal, Narrative, Experiment, Specimens, Done test, Lessons) and what the older documents became (pmos artefacts help)' }),
|
|
125
128
|
// Not a pm-os-absorb verb (run: null): initiative core-documents added it through the same table.
|
|
126
129
|
coredoc: Object.freeze({ module: 'coredoc-cli.js', run: null, guide: 'cli.md',
|
|
127
130
|
help: 'pmos coredoc write --scope <scope> --key <key> --file <path|-> — write one draft of a core document; the PM issues it on the page (pmos coredoc help)' }),
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* { stateDir, now?, homeWs(), proactive() → { quiet, dayCheck: { start, end, every } }, schedules: { read, write },
|
|
21
21
|
* startSkill(wsId, skill, name, origin) → { ok, session?, error? }, jobs: { [id]: (ws) → { ok, error? } },
|
|
22
22
|
* freshRows(ws) → [freshness row], copyPaths(id, ws) → [path], tell({ source, label, error, ws }), sessionAlive(id) → bool,
|
|
23
|
+
* sessionSignedOut?(id) → bool (its screen shows Claude's sign-in), stopSession?(id),
|
|
23
24
|
* setDayCheckEvery(every), setRepoWatch(on), warn(what, e), leadsDue?(ws) → number of popup leads due,
|
|
24
25
|
* readDirs?(ws) → { runtime, jira } where the stored reads are, for their fingerprint (smart refresh step 1); by default the
|
|
25
26
|
* state folder and the Jira folder copyPaths('jira') names }
|
|
@@ -275,6 +276,15 @@ function create(host) {
|
|
|
275
276
|
for (const [id, st] of Object.entries(state)) {
|
|
276
277
|
for (const [sid, o] of Object.entries(openOf(st))) {
|
|
277
278
|
let alive = true; try { alive = host.sessionAlive(sid); } catch { alive = true; }
|
|
279
|
+
// A terminal session whose Claude is signed out waits at the sign-in screen for ever: Morning brief and Popup leads each sat
|
|
280
|
+
// 6 hours that way (bug 2026-11-08). It ends now as signed out, so the Sources row says how to sign in, and its pane is closed.
|
|
281
|
+
let out = false; if (alive && host.sessionSignedOut) { try { out = !!host.sessionSignedOut(sid); } catch { out = false; } }
|
|
282
|
+
if (out) {
|
|
283
|
+
delete st.open[sid]; st.retry_at = null; changed = true;
|
|
284
|
+
R.append(dir, { source: id, ev: 'end', run: o.run, result: 'failed', took_ms: t - o.at, error: require('./claude-signin.js').signedOutWhy() }, t);
|
|
285
|
+
try { if (host.stopSession) host.stopSession(sid); } catch (e) { warn('stop a signed-out session', e); }
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
278
288
|
if (!alive || t - o.at > LOST_MS) {
|
|
279
289
|
delete st.open[sid]; st.retry_at = null; changed = true;
|
|
280
290
|
R.append(dir, { source: id, ev: 'end', run: o.run, result: 'interrupted', took_ms: t - o.at, error: alive ? 'no end after 6 hours' : 'the session was gone (PMOS restarted, or the session was closed)' }, t);
|
|
@@ -104,6 +104,7 @@ const MODULES = Object.freeze([
|
|
|
104
104
|
'routes-driver', // initiative-driver: the Agent strip's data, Keep, Send back, Drop, Pause and the board mode (driver.jsonl)
|
|
105
105
|
'routes-scan', // horizon-scan-portfolio: one scan for the workspace: the watch list and setting, Scan now and Stop, report documents and their proposals (approve, change, dismiss, undo), plus the first scan's per-board and Briefing reads (scan.jsonl)
|
|
106
106
|
'routes-report-setups', // report-workspace: recurring reports, the Ask box, the finder, the report documents and their export (report-setups.jsonl)
|
|
107
|
+
'routes-artefacts', // R18 (proposed D107): the seven artefacts, read-only, and the lossless carry of the older records (artefacts.jsonl)
|
|
107
108
|
'routes-core-docs', // core-documents: the core documents of each level, Draft it (a core-doc run), Issue it and Drop (core-docs.jsonl)
|
|
108
109
|
'routes-custom-docs', // briefing-premium-adddoc: the documents the PM adds beyond the core set, Add a document (custom-docs.jsonl)
|
|
109
110
|
'routes-premium-dashboards', // briefing-premium-reports: the dashboards the PM makes on premium Insights (premium-dashboards.jsonl; page-press POST save)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-artefacts.js — the seven artefacts (R18, proposed D107, lib/artefacts.js).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/artefacts?ws&scope → { ok, ws, scope, kind, artefacts: [{ key, title, owner, for, labels, fields, carried, empty }] }
|
|
5
|
+
* scope: portfolio (default), board:<id>, goal:<id>, experiment:<id> (initiative:<id> is an alias)
|
|
6
|
+
* GET /api/artefacts/map → { ok, artefacts, rows: [{ from, name, artefact, field, note }] } what every older shape became
|
|
7
|
+
*
|
|
8
|
+
* THE MIGRATION. The first read of a repository in a server process carries its older records (core documents, kept driver proposals,
|
|
9
|
+
* report drafts) under their artefacts: lib/artefacts.js migrateRepo. It is idempotent and only appends pointers; nothing is deleted or
|
|
10
|
+
* moved, so a failed or repeated carry loses nothing. The page never writes here: a set is an agent's (the driver's `artefact` kind, with
|
|
11
|
+
* Undo) or the PM's (`pmos artefacts set`).
|
|
12
|
+
* Every `by` is mapped through actor.pageName, so a session token never reaches the page (F5).
|
|
13
|
+
*/
|
|
14
|
+
const A = require('./artefacts.js');
|
|
15
|
+
const actorLib = require('./actor.js');
|
|
16
|
+
|
|
17
|
+
const migrated = new Set(); // the repository roots this process has carried
|
|
18
|
+
|
|
19
|
+
function wsOf(ctx, id) {
|
|
20
|
+
const w = ctx.getWs(id || '');
|
|
21
|
+
return w && (!id || w.id === id) ? w : null;
|
|
22
|
+
}
|
|
23
|
+
const pageBy = (x) => (x && x.by ? { ...x, by: actorLib.pageName(x.by) } : x);
|
|
24
|
+
|
|
25
|
+
async function handle(req, res, url, ctx) {
|
|
26
|
+
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
27
|
+
if (req.method !== 'GET') return send(405, { ok: false, error: 'the artefacts are read here; agents write them through the driver' });
|
|
28
|
+
const sub = url.pathname.replace(/^\/api\/artefacts\/?/, '');
|
|
29
|
+
if (sub === 'map') return send(200, { ok: true, artefacts: A.KEYS, rows: require('./artefacts-cli.js').mapRows() });
|
|
30
|
+
if (sub) return send(404, { ok: false, error: 'no such artefacts route' });
|
|
31
|
+
const q = url.searchParams;
|
|
32
|
+
const w = wsOf(ctx, q.get('ws'));
|
|
33
|
+
if (!w || !w.root) return send(404, { ok: false, error: 'no such workspace' });
|
|
34
|
+
const scope = q.get('scope') || 'portfolio';
|
|
35
|
+
if (!A.parseScope(scope)) return send(400, { ok: false, error: 'scope must be portfolio, board:<id>, goal:<id> or experiment:<id>' });
|
|
36
|
+
let dir;
|
|
37
|
+
try { dir = A.dirOf(w.root); } catch (e) { return send(409, { ok: false, error: String((e && e.message) || e) }); }
|
|
38
|
+
if (!migrated.has(w.root)) {
|
|
39
|
+
migrated.add(w.root);
|
|
40
|
+
try { A.migrateRepo(w.root); } catch { /* a failed carry loses nothing: the older records stay where they are */ }
|
|
41
|
+
}
|
|
42
|
+
const v = A.viewOf(A.fold(A.readLines(A.file(dir))), scope);
|
|
43
|
+
const artefacts = v.artefacts.map((a) => ({ ...a,
|
|
44
|
+
fields: Object.fromEntries(Object.entries(a.fields).map(([k, val]) => [k, Array.isArray(val) ? val.map(pageBy) : pageBy(val)])) }));
|
|
45
|
+
return send(200, { ok: true, ws: w.id, scope: v.scope, kind: v.kind, artefacts });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { prefixes: ['/api/artefacts'], handle, _migrated: migrated };
|
|
@@ -130,7 +130,7 @@ function settleRun(ctx, key, done, now) {
|
|
|
130
130
|
const res = done && done.result;
|
|
131
131
|
if (done && done.stopped) return append(ctx.runtimeDir, key + '.jsonl', { k: 'fail', at, error: 'The run was stopped before it answered.' });
|
|
132
132
|
if (done && done.timedOut) return append(ctx.runtimeDir, key + '.jsonl', { k: 'fail', at, error: 'The companion took too long and was stopped.' });
|
|
133
|
-
if (res && headless.signedOut(res.text)) return append(ctx.runtimeDir, key + '.jsonl', { k: 'fail', at, auth: true, error:
|
|
133
|
+
if (res && headless.signedOut(res.text)) return append(ctx.runtimeDir, key + '.jsonl', { k: 'fail', at, auth: true, error: require('./claude-signin.js').signedOutWhy() });
|
|
134
134
|
if (!res || !res.ok || res.isError) return append(ctx.runtimeDir, key + '.jsonl', { k: 'fail', at, error: 'The companion did not answer (' + ((done && done.note) || 'no result') + ').' });
|
|
135
135
|
const parsed = F.parseCompanion(res.text);
|
|
136
136
|
// a malformed answer is dropped, not shown
|
|
@@ -119,7 +119,7 @@ function view(h, name = 'It') {
|
|
|
119
119
|
const tried = n ? `Claude read it again ${n === 1 ? 'once' : n + ' times'} since ${hm(h.attempts[0].at)}${c ? `, and ${c.why}` : ''}.` : '';
|
|
120
120
|
let action = null;
|
|
121
121
|
if (h.state === 'needs-you') {
|
|
122
|
-
if (h.cause === 'claude-signin') action = { label: 'Sign in to Claude', how: '
|
|
122
|
+
if (h.cause === 'claude-signin') action = { label: 'Sign in to Claude', how: require('./claude-signin.js').how(), sec: 'claude' };
|
|
123
123
|
else if (h.cause === 'connector-missing') action = { label: 'Connect ' + name, how: 'Turn on its connector in your Claude connectors.', href: CONNECTORS };
|
|
124
124
|
else if (h.cause === 'sign-in') action = { label: 'Reconnect ' + name, how: 'Sign in to its connector again in your Claude connectors.', href: CONNECTORS };
|
|
125
125
|
else action = { label: 'Read ' + name + ' again', how: h.cause === 'manual' ? 'You chose to read it only when you press ↻.' : 'Claude stopped after ' + n + ' tries.', read: true };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.545.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.545.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
package/workspace/run-tests.js
CHANGED
|
@@ -493,6 +493,27 @@ function traceChanges(changes, ctx) {
|
|
|
493
493
|
const used = [...line.matchAll(reqRe)];
|
|
494
494
|
return used.length > 0 && used.every((u) => u[1] && !ex.has(u[1].slice(1)));
|
|
495
495
|
};
|
|
496
|
+
// seven-artefacts: an indented `const D = require('./lib/f.js')` (alone, or first in `const D = require(…), C = require(…)`) inside a
|
|
497
|
+
// function is a use of f only through the members its body reads. The body is the lines after it, up to the first line indented less
|
|
498
|
+
// than the require that closes a block. Every use must be `D.<export>` with no changed export; a bare `D` (passed on, spread) cannot tell.
|
|
499
|
+
const innerBindingOther = (src, i, f) => {
|
|
500
|
+
const ex = changedExports(f); if (!ex) return false;
|
|
501
|
+
const line = src[i];
|
|
502
|
+
const m = new RegExp(`^(\\s+)(?:const|let|var)\\s+(\\w+)\\s*=\\s*require\\(\\s*['"\`][^'"\`]*/${reEsc(stemOf(f))}(?:\\.m?js)?['"\`]\\s*\\)\\s*[,;]`).exec(line);
|
|
503
|
+
if (!m) return false;
|
|
504
|
+
const ind = m[1].length; const name = m[2];
|
|
505
|
+
const tail = line.slice(m[0].length);
|
|
506
|
+
const body = [tail];
|
|
507
|
+
for (let k = i + 1; k < src.length; k++) {
|
|
508
|
+
const l = src[k]; const lead = (/^\s*/.exec(l) || [''])[0].length;
|
|
509
|
+
if (l.trim() && lead < ind && /^\s*[})]/.test(l)) break;
|
|
510
|
+
if (l.trim() && lead < ind) return false; // no closing line where one was expected: cannot tell
|
|
511
|
+
body.push(l);
|
|
512
|
+
}
|
|
513
|
+
const text = body.join('\n');
|
|
514
|
+
const all = [...text.matchAll(new RegExp(`\\b${reEsc(name)}\\b(\\.[\\w$]+)?`, 'g'))];
|
|
515
|
+
return all.every((u) => u[1] && !ex.has(u[1].slice(1)));
|
|
516
|
+
};
|
|
496
517
|
// Does file g use one of the changed exports of the changed lib file f? false only when it can tell: every require of f in g is a
|
|
497
518
|
// plain binding whose every use is `binding.<export>`, or a destructuring, or `require(…).<export>`, and none names a changed export.
|
|
498
519
|
const usesChanged = (g, f, re) => {
|
|
@@ -587,7 +608,7 @@ function traceChanges(changes, ctx) {
|
|
|
587
608
|
if (m && /require\([^)]*\)\.create\(/.test(line)) factories.push(m[2]); // a service built at start-up: only a route that calls it can reach a page
|
|
588
609
|
else if (m && m[2] && changedExports(f)) whole.push(m[2]); // a whole-module binding: only the changed exports count
|
|
589
610
|
else if (m) names.push(...(m[1] ? m[1].split(',').map((x) => x.split(':').pop().trim()).filter(Boolean) : [m[2]]));
|
|
590
|
-
else if (!onlyOther(line, f)) inline.push(i + 1); // a require inside a function or a route: that line, unless it only reads exports the change left alone
|
|
611
|
+
else if (!onlyOther(line, f) && !innerBindingOther(t.split('\n'), i, f)) inline.push(i + 1); // a require inside a function or a route: that line, unless it only reads exports the change left alone
|
|
591
612
|
});
|
|
592
613
|
for (const name of factories.filter(Boolean)) { // only the uses inside a route block; a timer or a start-up call is the boot suite's
|
|
593
614
|
if (used.has(name)) continue; used.add(name);
|
package/workspace/server.js
CHANGED
|
@@ -3258,6 +3258,9 @@ refreshRun = refreshRunLib.create({
|
|
|
3258
3258
|
proactive: () => proSettings(),
|
|
3259
3259
|
schedules: { read: readSchedules, write: writeSchedules },
|
|
3260
3260
|
startSkill: (wsId, skill, name, origin) => startSkillSession(wsId, skill, name, origin),
|
|
3261
|
+
// a terminal session stuck at Claude's sign-in screen (the login it runs under expired): read from its pane, ended by the engine
|
|
3262
|
+
sessionSignedOut: (id) => { const x = sessions.get(String(id || '')); return !!x && !!x.tmux && x.state !== 'exited' && require('./lib/claude-signin.js').paneSignedOut(paneScreen(x)); },
|
|
3263
|
+
stopSession: (id) => { const x = sessions.get(String(id || '')); if (x && x.tmux) tmuxKillSession(x.tmux); },
|
|
3261
3264
|
sessionAlive: (id) => { const x = sessions.get(String(id || '')); return !!x && x.state !== 'exited'; }, sessionOutcome: (id) => { const x = sessions.get(String(id || '')); return (x && x.outcome) || null; },
|
|
3262
3265
|
// popup context slice 3b: how many opened popups have no lead newer than the newest stored read
|
|
3263
3266
|
leadsDue: () => require('./lib/popup-leads.js').due(STATE, { readAt: require('./lib/lead-cli.js').newestRead(STATE) }).length,
|
|
@@ -4468,6 +4471,10 @@ const claudeSetup = require('./lib/claude-readiness').create({
|
|
|
4468
4471
|
envFor: sessionEnvWithProfile,
|
|
4469
4472
|
savePreference: (id) => { const p = readPrefs(); p.claude = id; return writePrefs(p); },
|
|
4470
4473
|
});
|
|
4474
|
+
// The sign-in advice names the command of the Claude profile background runs use (lib/claude-signin.js), never plain `claude` when another is chosen.
|
|
4475
|
+
const claudeSignin = require('./lib/claude-signin.js').configure({
|
|
4476
|
+
profile: () => { const r = resolveProfileForSpawn(defaultProfileFor('claude')); return r.ok ? r.profile : null; },
|
|
4477
|
+
});
|
|
4471
4478
|
claudeSetup.ensureOwn = () => require('./lib/own-profile').ensure(os.homedir(), profilesLib.profilesDir(os.homedir()));
|
|
4472
4479
|
/* Sign-in (bug 2026-11-02): a login that is signed in already is used as it is, with no terminal. Otherwise the sign-in runs
|
|
4473
4480
|
* `claude auth login`, not the full Claude Code screen: it opens the browser and at most asks for a pasted code, so a new user
|
|
@@ -6040,11 +6047,16 @@ function autoNameTick(s, hx) {
|
|
|
6040
6047
|
const fail = () => { s._naming = false; s.nameFail = { at: Date.now(), turns }; };
|
|
6041
6048
|
const cmd = process.env.PMOS_AUTONAME_CMD || 'claude';
|
|
6042
6049
|
if (!process.env.PMOS_AUTONAME_CMD && !commandExists('claude')) return;
|
|
6050
|
+
// Naming runs under the PM's chosen Claude profile like every other background call, never Claude's own login when another is chosen
|
|
6051
|
+
// (bug 2026-11-08: the default login had expired, the chosen claude-personal had not). A chosen profile that cannot be read names nothing.
|
|
6052
|
+
const pres = resolveProfileForSpawn(defaultProfileFor('claude'));
|
|
6053
|
+
if (!pres.ok) return;
|
|
6054
|
+
const nenv = { ...sessionEnv(), ...profileOverlay(pres.profile) };
|
|
6043
6055
|
s._naming = true;
|
|
6044
6056
|
let child, out = '';
|
|
6045
6057
|
try {
|
|
6046
|
-
const run = winCommand.resolve(cmd, { env:
|
|
6047
|
-
child = spawn(run.file, [...run.prefix, ...sessionName.argv()], { cwd: s.cwd || s.root, env:
|
|
6058
|
+
const run = winCommand.resolve(cmd, { env: nenv });
|
|
6059
|
+
child = spawn(run.file, [...run.prefix, ...sessionName.argv()], { cwd: s.cwd || s.root, env: nenv, stdio: ['pipe', 'pipe', 'ignore'] });
|
|
6048
6060
|
} catch { return fail(); }
|
|
6049
6061
|
const timer = setTimeout(() => { try { child.kill('SIGKILL'); } catch { /* gone */ } }, 90000);
|
|
6050
6062
|
child.on('error', () => { clearTimeout(timer); fail(); });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "R18 seven artefacts (proposed D107): lib/artefacts.js (the seven, the map of every older document, proposal kind, cadence and lane, the ledger, the lossless migration), pmos artefacts and the driver's artefact kind. Pure, node.",
|
|
3
|
+
"modules": [
|
|
4
|
+
"artefacts.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"artefacts.test.js": 1
|
|
8
|
+
}
|
|
9
|
+
}
|