create-pmos 0.568.0 → 0.570.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 -27
- package/payload/AGENTS.md +11 -0
- 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/planning/work-items.jsonl +0 -0
- package/payload/scripts/gate-initiative.sh +29 -0
- package/payload/scripts/lib/sink.js +321 -0
- package/payload/scripts/verify-work.js +149 -0
- package/payload/scripts/work-item.js +1460 -0
- package/payload/scripts/workflow-state.js +16 -0
- 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 +27 -2
- package/workspace/guide/settings-and-switches.md +1 -0
- package/workspace/lib/agent-team.js +19 -4
- package/workspace/lib/artefact-mirror.js +121 -0
- package/workspace/lib/artefacts-cli.js +15 -1
- package/workspace/lib/autonomy.js +2 -1
- package/workspace/lib/build-cli.js +93 -0
- package/workspace/lib/build-engine.js +197 -0
- package/workspace/lib/driver-decide.js +2 -0
- package/workspace/lib/engine/workflow-state.js +16 -0
- package/workspace/lib/headless.js +3 -1
- package/workspace/lib/outcome-props.js +21 -1
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/proposals.js +15 -4
- package/workspace/lib/rehearse-read.js +4 -2
- package/workspace/lib/routes-artefacts.js +4 -1
- package/workspace/lib/routes-boards.js +6 -0
- package/workspace/lib/routes-proposals.js +14 -3
- package/workspace/lib/team-cli.js +3 -1
- package/workspace/lib/team-runs.js +4 -0
- package/workspace/lib/today-cli.js +19 -0
- package/workspace/lib/vendor/scripts/workflow-state.js +16 -0
- package/workspace/lib/verify-work-cli.js +4 -2
- package/workspace/lib/work-kind.js +12 -6
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/ini-props.js +3 -1
- package/workspace/run-tests.js +9 -0
- package/workspace/test-lists/build-engine.json +9 -0
- package/workspace/test-lists/launch-rerun-gaps.json +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.570.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,32 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.570.0",
|
|
38
|
+
"at": "2026-11-15T17:32:20.370Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1302,
|
|
43
|
+
"t": "The real build engine for Full SDLC (launch simulation W7)",
|
|
44
|
+
"s": "The real build engine for Full SDLC (launch simulation W7)",
|
|
45
|
+
"k": "new"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"v": "0.569.0",
|
|
51
|
+
"at": "2026-11-15T17:07:37.237Z",
|
|
52
|
+
"f": 4,
|
|
53
|
+
"prs": [
|
|
54
|
+
{
|
|
55
|
+
"n": 1301,
|
|
56
|
+
"t": "Close the five gaps the launch rerun found (launch simulation W6)",
|
|
57
|
+
"s": "Close the five gaps the launch rerun found (launch simulation W6)",
|
|
58
|
+
"k": "new"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
36
62
|
{
|
|
37
63
|
"v": "0.568.0",
|
|
38
64
|
"at": "2026-11-12T05:06:58.936Z",
|
|
@@ -284,32 +310,6 @@
|
|
|
284
310
|
"k": "new"
|
|
285
311
|
}
|
|
286
312
|
]
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
"v": "0.550.0",
|
|
290
|
-
"at": "2026-11-10T08:31:44.572Z",
|
|
291
|
-
"f": 4,
|
|
292
|
-
"prs": [
|
|
293
|
-
{
|
|
294
|
-
"n": 1278,
|
|
295
|
-
"t": "Run PMOS on an always-on cloud server — one paste on the Mac moves it, the Mac stays as the fallback",
|
|
296
|
-
"s": "Run PMOS on an always-on cloud server — one paste on the Mac moves it, the Mac stays as the fallback",
|
|
297
|
-
"k": "new"
|
|
298
|
-
}
|
|
299
|
-
]
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
"v": "0.549.0",
|
|
303
|
-
"at": "2026-11-10T07:06:56.286Z",
|
|
304
|
-
"f": 4,
|
|
305
|
-
"prs": [
|
|
306
|
-
{
|
|
307
|
-
"n": 1277,
|
|
308
|
-
"t": "The story so far on the product page and shared Board; Settings › Claude says how Claude decides",
|
|
309
|
-
"s": "The story so far on the product page and shared Board; Settings › Claude says how Claude decides",
|
|
310
|
-
"k": "new"
|
|
311
|
-
}
|
|
312
|
-
]
|
|
313
313
|
}
|
|
314
314
|
]
|
|
315
315
|
}
|
package/payload/AGENTS.md
CHANGED
|
@@ -119,6 +119,17 @@ When an initiative is bigger than one run, break it into **tickets** — the pla
|
|
|
119
119
|
|
|
120
120
|
Before creating any new agent path or widening a tool grant, verify it does **not** hold all three of: **private data access + untrusted-content exposure + external communication**. An agent holding all three can be tricked by content it reads into exfiltrating what it knows — remove a leg (preferably external communication) structurally; prompt-level defenses alone are bypassed by adaptive attacks. If a path genuinely needs all three, its PRD/brief must name the compensating gate; silence is not a pass. The evaluator is the standing example: it reads adversarial diffs, so it stays read-only with its verdict append as the only write.
|
|
121
121
|
|
|
122
|
+
### The Builder (the D65 factory in this repository)
|
|
123
|
+
|
|
124
|
+
This kit carries the factory: `pmos/scripts/work-item.js` (the one writer of `pmos/planning/work-items.jsonl`) and `pmos/scripts/verify-work.js`. With the PMOS workspace installed, `pmos build` is the Builder:
|
|
125
|
+
|
|
126
|
+
1. `pmos build claim <item>` claims one declared work item. The work happens on a new branch `pmos/<item>`, in a worktree outside the repository folder.
|
|
127
|
+
2. `pmos build propose <item> "<what it does>" --evidence "<the check that passed>"` commits with the repository's own git identity (`pmos git-identity`) and the line `Work-Item: <item>`, marks the item verified, and files "Open a draft pull request" for the PM.
|
|
128
|
+
3. Only the PM opens the pull request: the ✓ on that proposal, or `pmos build open <item>`. It pushes the one branch and runs `gh pr create --draft`.
|
|
129
|
+
4. After the merge, `pmos verify-work` marks the item integrated.
|
|
130
|
+
|
|
131
|
+
The audit for this path: a Builder run reads private code and untrusted content, so it holds no outward channel. It has no `git push`, no `gh` and no merge, and `pmos build open` refuses a role run. A commit that touches `pmos/`, `.github/`, `CLAUDE.md` or `AGENTS.md` is refused. The compensating gate is the product's own CI and branch protection on the default branch: protect it before you use the Builder.
|
|
132
|
+
|
|
122
133
|
## Escalation (stop and ask the PM)
|
|
123
134
|
|
|
124
135
|
An architectural choice with no recorded decision; a wrong or unsatisfiable contract; scope growth; any destructive/irreversible action; anything that would send product data outside this repo's remote. Confirm-first regardless of framing.
|
package/payload/KIT-VERSION
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
kernel-source: pmos@
|
|
2
|
-
assembled: 2026-11-
|
|
1
|
+
kernel-source: pmos@32443ddf
|
|
2
|
+
assembled: 2026-11-15
|
|
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-15T17:32:16Z"}
|
|
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-15T17:32:16Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
File without changes
|
|
@@ -86,6 +86,35 @@ anchor="$(frontval parent_kr)"
|
|
|
86
86
|
# file IS the row, so the gate is where the same rule lands. A KR or health:<id> — never blank.
|
|
87
87
|
[ -n "$anchor" ] || fail "initiative '$id' has no parent_kr in $init_file — anchor it to a KR, or to a declared health budget (parent_kr: health:<id> from $KIT_ROOT/planning/okrs/health-budgets.md, D59). Unanchored work is rejected (D21)."
|
|
88
88
|
|
|
89
|
+
# ---- D107 and the kind of work (launch simulation W6) --------------------------
|
|
90
|
+
# In both profiles, as .github/scripts/initiative-gate.sh does for PMOS itself: a record that names its done test and kill condition is
|
|
91
|
+
# an experiment and passes in any lane (the done test is the spec, D13 as amended by D107). The kind of work sets the gate (W5): Full
|
|
92
|
+
# SDLC needs a done test and a kill condition, never a PRD or a brief; a Project needs a dated plan (plan_path: milestones with dates
|
|
93
|
+
# and owners), never a PRD or a brief. A PRD or brief already on the record still passes: a gate passed stays passed. `pmos artefacts
|
|
94
|
+
# set experiment:<id> done-test …` writes done_test_path and kill: for you (lib/artefact-mirror.js).
|
|
95
|
+
done_test="$(frontval done_test_path)"
|
|
96
|
+
kill_cond="$(frontval kill)"
|
|
97
|
+
kind="$(frontval kind | tr -d "\"'")"
|
|
98
|
+
if [ -n "$done_test" ]; then
|
|
99
|
+
[ -f "$done_test" ] || fail "done_test_path '$done_test' (from $init_file) does not exist in the repo."
|
|
100
|
+
[ -n "$kill_cond" ] || fail "initiative '$id' names a done test but no kill condition — write kill: \"<the result that would make us stop>\" in $init_file (D107)."
|
|
101
|
+
echo "✅ initiative gate PASSED — '$id' (experiment, D107): $init_file exists, done test ($done_test) and kill condition present."
|
|
102
|
+
exit 0
|
|
103
|
+
fi
|
|
104
|
+
had_spec="$prd$(frontval brief_path)"
|
|
105
|
+
if [ "$kind" = sdlc ] && [ -z "$had_spec" ]; then
|
|
106
|
+
fail "initiative '$id' is Full SDLC: it needs a done test and a kill condition before the first pull request, never a PRD or a brief. Set done_test_path and kill: in $init_file (pmos artefacts set experiment:$id done-test check --text \"…\" writes both)."
|
|
107
|
+
fi
|
|
108
|
+
if [ "$kind" = project ]; then
|
|
109
|
+
plan="$(frontval plan_path)"
|
|
110
|
+
if [ -n "$plan" ] || [ -z "$had_spec" ]; then
|
|
111
|
+
[ -n "$plan" ] || fail "initiative '$id' is a Project: it needs a dated plan, never a PRD or a brief. Set plan_path in $init_file to the plan (milestones with dates and owners), or give it a done test."
|
|
112
|
+
[ -f "$plan" ] || fail "plan_path '$plan' (from $init_file) does not exist in the repo."
|
|
113
|
+
echo "✅ initiative gate PASSED — '$id' (Project): $init_file exists and the dated plan ($plan) is present."
|
|
114
|
+
exit 0
|
|
115
|
+
fi
|
|
116
|
+
fi
|
|
117
|
+
|
|
89
118
|
# ---- D68: the pm-artifacts profile ------------------------------------------
|
|
90
119
|
# A repository whose root holds `.pmos-profile` reading `pm-artifacts` is a PM's documents repo: its
|
|
91
120
|
# work lanes are new-feature | improvement | bug-fix | discovery | chore and its document lanes are
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* sink.js — the ONE place the append-only ledger discipline lives.
|
|
4
|
+
*
|
|
5
|
+
* ── WHY THIS FILE EXISTS ────────────────────────────────────────────────────────────────────────
|
|
6
|
+
* `record-eval.js` was PMOS's first validated writer. Three independent passes found four defects in
|
|
7
|
+
* it, and all four were fixed IN THAT FILE:
|
|
8
|
+
*
|
|
9
|
+
* 1. the sink was a caller-supplied allowlist -> a caller could name its own destination
|
|
10
|
+
* 2. the file was opened before validation -> N refused writes leaked N descriptors to EMFILE
|
|
11
|
+
* 3. a refused write still created the sink -> refusing to write left the file behind
|
|
12
|
+
* 4. the symlink check was a path-level stat -> a hardlink walked straight through it
|
|
13
|
+
*
|
|
14
|
+
* Two writers built afterwards inherited the fixes BY HAND, and each inheritance read as evidence
|
|
15
|
+
* that the pattern was holding. It was not holding — it was propagating FORWARD ONLY. The two
|
|
16
|
+
* writers that already existed when the defects were found were never revisited, because the process
|
|
17
|
+
* asks "does the new thing follow the rule?" and never "where else does this rule already live?"
|
|
18
|
+
*
|
|
19
|
+
* Measured by attempted write on 2026-08-04:
|
|
20
|
+
*
|
|
21
|
+
* scripts/work-item.js -> wrote 198 bytes through a symlink into a decoy
|
|
22
|
+
* scripts/verify-queue.js -> the same, AND wrote 202 bytes into a fresh tmpdir, because its
|
|
23
|
+
* allowlist compared `path.basename` alone. A basename is not a
|
|
24
|
+
* location; every directory on disk has one.
|
|
25
|
+
*
|
|
26
|
+
* Both are merged, PM-accepted, and load-bearing for D65 steps 1 and 2. So the discipline moves here
|
|
27
|
+
* and the writers call it. One wrong place that every assertion points at beats five where three
|
|
28
|
+
* happen to be right.
|
|
29
|
+
*
|
|
30
|
+
* ── THE RULE, STATED ONCE ───────────────────────────────────────────────────────────────────────
|
|
31
|
+
* Resolve before allowing. Validate before opening. Write to the descriptor that was vetted.
|
|
32
|
+
*
|
|
33
|
+
* The third clause is the one that looks redundant and is not. A path checked and then re-opened by
|
|
34
|
+
* path is two operations on two objects: whatever was approved may not be what gets written. The fd
|
|
35
|
+
* IS the approval, so it is what the caller must be handed.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const fs = require('fs');
|
|
39
|
+
const path = require('path');
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* THE `ForbiddenWrite`. One class, exported, re-exported by every writer that uses this guard.
|
|
43
|
+
*
|
|
44
|
+
* There were five of these — one per writer that had a guard at all — and that is not a cosmetic duplication. Callers and
|
|
45
|
+
* assertions tell "refused on purpose" from "crashed" with `instanceof`, so a guard throwing its own
|
|
46
|
+
* private copy makes every one of those checks silently false: `scripts/tests/work-item.sh` reported
|
|
47
|
+
* `threw ForbiddenWrite, want ForbiddenWrite` on seventeen assertions the moment this module started
|
|
48
|
+
* throwing a second class with the same name. A refusal nobody can recognise as a refusal is not one.
|
|
49
|
+
*
|
|
50
|
+
* `detail` is always set (null when absent) rather than conditionally attached, because a property
|
|
51
|
+
* that sometimes exists is a second shape for callers to handle.
|
|
52
|
+
*/
|
|
53
|
+
class ForbiddenWrite extends Error {
|
|
54
|
+
constructor(message, detail) {
|
|
55
|
+
super(message);
|
|
56
|
+
this.name = 'ForbiddenWrite';
|
|
57
|
+
this.detail = detail || null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Resolve a path through its real directory. Kept separate so the sink and the target are compared
|
|
62
|
+
* the same way — comparing a resolved target against an unresolved sink is a mismatch by
|
|
63
|
+
* construction, and would refuse every legitimate write on a machine where /tmp is a symlink. */
|
|
64
|
+
function resolveThrough(p) {
|
|
65
|
+
return path.join(fs.realpathSync(path.dirname(path.resolve(p))), path.basename(p));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Build a guard bound to ONE sink.
|
|
70
|
+
*
|
|
71
|
+
* @param {object} spec
|
|
72
|
+
* @param {string} spec.sink absolute path of the only file this guard will ever open.
|
|
73
|
+
* @param {string} spec.what noun for error messages, e.g. 'work-item events'.
|
|
74
|
+
* @returns {{ open: function, sinkPath: function, __setSinkForTests: function }}
|
|
75
|
+
*
|
|
76
|
+
* The sink is a CONSTRUCTION-TIME constant, never an argument to `open`. That is defect 1 of the
|
|
77
|
+
* original four, and re-admitting it as "just a parameter" is how it would come back.
|
|
78
|
+
*/
|
|
79
|
+
function createSinkGuard(spec) {
|
|
80
|
+
if (!spec || typeof spec.sink !== 'string' || !spec.sink) {
|
|
81
|
+
throw new ForbiddenWrite('a sink guard needs a declared `sink` path — refused (fail-closed)');
|
|
82
|
+
}
|
|
83
|
+
const what = spec.what || 'records';
|
|
84
|
+
const declared = spec.sink;
|
|
85
|
+
let overrideForTests = null;
|
|
86
|
+
|
|
87
|
+
/* A seam, not a door. Gated so it cannot be reached in a production process even if something
|
|
88
|
+
* calls it — the point of A4 is that no code path lets a caller choose the destination. */
|
|
89
|
+
function __setSinkForTests(p) {
|
|
90
|
+
/* An explicit allowed set. `!process.env.PMOS_TEST` treats the STRING '0' as truthy, so
|
|
91
|
+
* PMOS_TEST=0 — the natural way an operator turns test mode OFF — OPENED the production sink
|
|
92
|
+
* override instead of closing it. A flag whose "off" value means "on" is worse than no flag. */
|
|
93
|
+
const on = (v) => v === '1' || v === 'true' || v === 'yes';
|
|
94
|
+
if (process.env.NODE_ENV !== 'test' && !on(process.env.PMOS_TEST)) {
|
|
95
|
+
throw new ForbiddenWrite('__setSinkForTests is a test seam — set NODE_ENV=test or PMOS_TEST=1 to use it');
|
|
96
|
+
}
|
|
97
|
+
overrideForTests = p;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const sinkPath = () => overrideForTests || declared;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Pre-flight: validate the record and confirm the target RESOLVES to the sink — without opening
|
|
104
|
+
* anything. For callers that want to ask "would this be permitted?" without a side effect.
|
|
105
|
+
*
|
|
106
|
+
* NOT AUTHORITATIVE, and the gap is deliberate rather than an oversight. Whether the sink is a
|
|
107
|
+
* symlink or carries a second hard link cannot be established without a descriptor, and a `lstat`
|
|
108
|
+
* here would answer about a path that may differ from the file eventually opened — which is the
|
|
109
|
+
* check-then-write race this module exists to close. `open` is the authority; this is a courtesy.
|
|
110
|
+
* The suite asserts the difference: a symlinked sink passes `check` and is refused by `open`.
|
|
111
|
+
*/
|
|
112
|
+
function check(targetPath, validate) {
|
|
113
|
+
if (typeof targetPath !== 'string' || !targetPath) {
|
|
114
|
+
throw new ForbiddenWrite(`no target path supplied for ${what} — refused (fail-closed)`);
|
|
115
|
+
}
|
|
116
|
+
if (typeof validate === 'function') {
|
|
117
|
+
const v = validate();
|
|
118
|
+
if (!v || !v.ok) {
|
|
119
|
+
const errs = (v && v.errors) || ['invalid'];
|
|
120
|
+
throw new ForbiddenWrite(`invalid ${what} — refused: ${errs.join('; ')}`, { errors: errs });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
let resolved;
|
|
124
|
+
try { resolved = resolveThrough(targetPath); }
|
|
125
|
+
catch { throw new ForbiddenWrite(`the sink directory does not resolve for '${targetPath}' — refused (fail-closed)`); }
|
|
126
|
+
let sinkResolved = sinkPath();
|
|
127
|
+
try { sinkResolved = resolveThrough(sinkPath()); } catch { /* not created yet */ }
|
|
128
|
+
if (resolved !== sinkResolved) {
|
|
129
|
+
throw new ForbiddenWrite(
|
|
130
|
+
`${what} are written only to ${sinkResolved}; '${targetPath}' resolves to '${resolved}'`,
|
|
131
|
+
{ targetPath, resolved, sink: sinkResolved });
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Vet `targetPath` against the declared sink and return a descriptor open for append.
|
|
138
|
+
*
|
|
139
|
+
* The caller MUST close it. Everything that can refuse, refuses before the file is opened, so a
|
|
140
|
+
* refusal creates nothing and leaks nothing.
|
|
141
|
+
*
|
|
142
|
+
* @param {string} targetPath where the caller believes it is writing.
|
|
143
|
+
* @param {function} [validate] returns { ok, errors } — runs BEFORE the open (defects 2 and 3).
|
|
144
|
+
* @returns {number} a vetted file descriptor.
|
|
145
|
+
*/
|
|
146
|
+
function open(targetPath, validate) {
|
|
147
|
+
if (typeof targetPath !== 'string' || !targetPath) {
|
|
148
|
+
throw new ForbiddenWrite(`no target path supplied for ${what} — refused (fail-closed)`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* BEFORE the open. Ordering is the whole of defects 2 and 3: validating after opening leaks a
|
|
152
|
+
* descriptor per refusal, and O_CREAT means the refused write has already made the file. */
|
|
153
|
+
if (typeof validate === 'function') {
|
|
154
|
+
const v = validate();
|
|
155
|
+
if (!v || !v.ok) {
|
|
156
|
+
const errs = (v && v.errors) || ['invalid'];
|
|
157
|
+
throw new ForbiddenWrite(`invalid ${what} — refused: ${errs.join('; ')}`, { errors: errs });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let resolved;
|
|
162
|
+
try {
|
|
163
|
+
resolved = resolveThrough(targetPath);
|
|
164
|
+
} catch {
|
|
165
|
+
throw new ForbiddenWrite(`the sink directory does not resolve for '${targetPath}' — refused (fail-closed)`);
|
|
166
|
+
}
|
|
167
|
+
let sinkResolved = sinkPath();
|
|
168
|
+
try { sinkResolved = resolveThrough(sinkPath()); } catch { /* not created yet — compare literally */ }
|
|
169
|
+
|
|
170
|
+
/* A RESOLVED comparison, not a basename one. `verify-queue.js` compared basenames and therefore
|
|
171
|
+
* accepted every directory on disk that happened to contain the right filename. */
|
|
172
|
+
if (resolved !== sinkResolved) {
|
|
173
|
+
throw new ForbiddenWrite(
|
|
174
|
+
`${what} are written only to ${sinkResolved}; '${targetPath}' resolves to '${resolved}'`,
|
|
175
|
+
{ targetPath, resolved, sink: sinkResolved });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let fd;
|
|
179
|
+
try {
|
|
180
|
+
fd = fs.openSync(
|
|
181
|
+
resolved,
|
|
182
|
+
fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_APPEND
|
|
183
|
+
| fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK,
|
|
184
|
+
0o644);
|
|
185
|
+
} catch (e) {
|
|
186
|
+
/* O_NOFOLLOW turns "the sink is a symlink" into ELOOP here rather than a silent write to
|
|
187
|
+
* wherever it pointed. That is defect 4, and it is refused at open rather than by a stat that
|
|
188
|
+
* a hardlink does not answer.
|
|
189
|
+
*
|
|
190
|
+
* O_NONBLOCK is not about performance. Opening a FIFO for writing BLOCKS until a reader
|
|
191
|
+
* arrives, so a named pipe left at the sink path hangs the writer forever — found by the
|
|
192
|
+
* assertion below, which hung this suite past its timeout instead of failing. A refusal that
|
|
193
|
+
* never returns is worse than a wrong answer: nothing reports it and nothing times it out.
|
|
194
|
+
* With O_NONBLOCK the same case returns ENXIO immediately and lands in the refusal path, and
|
|
195
|
+
* on a regular file the flag does nothing at all. */
|
|
196
|
+
throw new ForbiddenWrite(
|
|
197
|
+
`cannot open the ${what} ledger at '${targetPath}' safely (${e.code || e.message}) — refused (fail-closed)`,
|
|
198
|
+
{ code: e.code });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
/* fstat on the FD, not stat on the path: for the FINAL component this genuinely closes the
|
|
203
|
+
* check-then-open race — an independent pass swapped the target inside the resolve→open window
|
|
204
|
+
* with perfect timing and got ELOOP, nlink=2 and a refusal every time.
|
|
205
|
+
*
|
|
206
|
+
* It does NOT cover the PARENT directory. `resolveThrough` realpaths the directory and
|
|
207
|
+
* `openSync` then re-walks that resolved path, so a local process able to rename the sink's
|
|
208
|
+
* parent and drop a directory symlink in its place inside that window can redirect the append
|
|
209
|
+
* — measured, 195 bytes into a foreign directory. That needs a concurrently-racing local
|
|
210
|
+
* attacker with write access to the parent, a strictly larger capability than the symlink
|
|
211
|
+
* defect this module was built to fix, so it is stated rather than claimed away. Closing it
|
|
212
|
+
* properly needs openat-style descent, which Node does not expose. The header's "the fd IS the
|
|
213
|
+
* approval" is true of the file, not of the path walked to reach it. */
|
|
214
|
+
const st = fs.fstatSync(fd);
|
|
215
|
+
if (!st.isFile()) {
|
|
216
|
+
throw new ForbiddenWrite(`'${targetPath}' is not a regular file — refused (fail-closed)`);
|
|
217
|
+
}
|
|
218
|
+
if (st.nlink !== 1) {
|
|
219
|
+
throw new ForbiddenWrite(
|
|
220
|
+
`'${targetPath}' has ${st.nlink} hard links; a ledger with a second name is not one this ` +
|
|
221
|
+
'writer controls — refused (fail-closed)', { nlink: st.nlink });
|
|
222
|
+
}
|
|
223
|
+
} catch (e) {
|
|
224
|
+
fs.closeSync(fd);
|
|
225
|
+
throw e;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return fd;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* The whole write, start to finish: vet, append one JSON line, close. Callers should prefer this
|
|
233
|
+
* over `open` — it is the shape that cannot forget to close, and every existing writer's append is
|
|
234
|
+
* exactly one line.
|
|
235
|
+
*/
|
|
236
|
+
function appendLine(targetPath, record, validate) {
|
|
237
|
+
const fd = open(targetPath, validate);
|
|
238
|
+
const line = JSON.stringify(record) + '\n';
|
|
239
|
+
const want = Buffer.byteLength(line);
|
|
240
|
+
try {
|
|
241
|
+
/* THE RETURN VALUE IS NOT OPTIONAL. This was `fs.writeSync(fd, line)` with the result
|
|
242
|
+
* discarded, which reports a SHORT WRITE as success. Forced on a 64K tmpfs: a normal-shaped
|
|
243
|
+
* record returned true having appended a 3901-byte fragment with no trailing newline, and the
|
|
244
|
+
* next append CONCATENATED onto it — so one ENOSPC destroys two records and leaves a single
|
|
245
|
+
* line that no reader can parse. This is the append-only system of record, every reader
|
|
246
|
+
* JSON.parses line by line, and all six writers route through this one call.
|
|
247
|
+
*
|
|
248
|
+
* Loop, because a partial write is not necessarily an error — then verify the total. A torn
|
|
249
|
+
* tail is worse than a refused write, so if the bytes did not all land, say so loudly rather
|
|
250
|
+
* than returning true over a corrupted ledger. */
|
|
251
|
+
/* The size BEFORE this append, taken from the vetted fd. This is what makes the failure path a
|
|
252
|
+
* real refusal instead of a report: if the write tears, the file is truncated back to here and
|
|
253
|
+
* the ledger is left exactly as it was found. `nlink === 1` was already proven above, so no
|
|
254
|
+
* other name for this file exists and the rollback cannot reach anyone else's data. */
|
|
255
|
+
const before = fs.fstatSync(fd).size;
|
|
256
|
+
const buf = Buffer.from(line, 'utf8');
|
|
257
|
+
let written = 0;
|
|
258
|
+
let cause = null;
|
|
259
|
+
try {
|
|
260
|
+
while (written < want) {
|
|
261
|
+
const n = fs.writeSync(fd, buf, written, want - written);
|
|
262
|
+
if (!(n > 0)) break; // no progress: stop rather than spin
|
|
263
|
+
written += n;
|
|
264
|
+
}
|
|
265
|
+
} catch (e) {
|
|
266
|
+
/* ENOSPC does NOT arrive as a short write. Measured on a full tmpfs: the first writeSync
|
|
267
|
+
* short-writes 376 of 440 bytes with no error and the SECOND one throws — so a version that
|
|
268
|
+
* only checked `written !== want` never reached its own error path, and a raw Error escaped
|
|
269
|
+
* with name 'Error'. Everything in this repo tells a deliberate refusal from a crash with
|
|
270
|
+
* `instanceof ForbiddenWrite` (workspace/test.js:1772 checks e.name), so an unwrapped throw
|
|
271
|
+
* on the worst outcome this module has is the one place that signal must not be missing. */
|
|
272
|
+
cause = e;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (cause || written !== want) {
|
|
276
|
+
/* THE ROLLBACK MUST NOT DESTROY SOMEONE ELSE'S RECORD, and the first version did.
|
|
277
|
+
*
|
|
278
|
+
* It called ftruncateSync(fd, before) unconditionally. `before` was measured at the top of
|
|
279
|
+
* this function, so ANY append by another process in between — a complete, successful,
|
|
280
|
+
* returned-true append — was inside the range being truncated away. Measured by an
|
|
281
|
+
* independent pass across 5 of 5 rounds: records whose write returned `true` were missing
|
|
282
|
+
* from disk afterwards, and the ledger was NUL-padded. A rollback that eats a committed
|
|
283
|
+
* record is worse than the torn line it was added to prevent.
|
|
284
|
+
*
|
|
285
|
+
* O_APPEND makes the arithmetic decidable: our bytes are the last `written` of the file if
|
|
286
|
+
* and only if nobody else appended. So truncate ONLY when the file is exactly the size our
|
|
287
|
+
* own write would have made it. Otherwise the tail is not ours to remove, and the honest
|
|
288
|
+
* outcome is to say the ledger is torn rather than to fix it by deleting a stranger's data. */
|
|
289
|
+
let rolledBack = false;
|
|
290
|
+
let intervened = false;
|
|
291
|
+
try {
|
|
292
|
+
const now = fs.fstatSync(fd).size;
|
|
293
|
+
if (now === before + written) { fs.ftruncateSync(fd, before); rolledBack = true; }
|
|
294
|
+
else intervened = true; // another writer appended; the tail is not ours
|
|
295
|
+
} catch { /* reported below */ }
|
|
296
|
+
|
|
297
|
+
const detail = { written, want, before, rolledBack, intervened, code: cause && cause.code };
|
|
298
|
+
throw new ForbiddenWrite(
|
|
299
|
+
`partial append to the ${what} ledger: ${written} of ${want} bytes landed` +
|
|
300
|
+
(cause ? ` (${cause.code || cause.message})` : '') + '. ' +
|
|
301
|
+
(rolledBack
|
|
302
|
+
? 'The ledger was truncated back to its pre-write size, so nothing was written and the ' +
|
|
303
|
+
'next append will not concatenate onto a fragment.'
|
|
304
|
+
: intervened
|
|
305
|
+
? 'NOT ROLLED BACK ON PURPOSE — another writer appended while this write was failing, ' +
|
|
306
|
+
'so the bytes at the end of the file are not this one\'s to remove. The ledger holds ' +
|
|
307
|
+
'a torn fragment that must be repaired by hand; truncating it here would have ' +
|
|
308
|
+
'deleted a record that committed successfully.'
|
|
309
|
+
: 'THE ROLLBACK ALSO FAILED — the ledger now ends in a torn line with no trailing ' +
|
|
310
|
+
'newline, and the next append WILL concatenate onto it, destroying a second record. ' +
|
|
311
|
+
'Repair it by hand before writing again.'),
|
|
312
|
+
detail);
|
|
313
|
+
}
|
|
314
|
+
} finally { fs.closeSync(fd); }
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return { check, open, appendLine, sinkPath, __setSinkForTests };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
module.exports = { createSinkGuard, ForbiddenWrite, resolveThrough };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* verify-work.js — mark work items integrated from the default branch (pm-os-absorb Run 4, PRD R7 and R24, D65, D70).
|
|
4
|
+
*
|
|
5
|
+
* node scripts/verify-work.js [--branch <ref>] [--dry-run] [--json]
|
|
6
|
+
* verifyWork({ branch, dryRun }) → { ok, branch, head, appended: [{ id, sha }], already: [id], unknown: [{ id, sha }],
|
|
7
|
+
* refused: [{ id, sha, why }], error? }
|
|
8
|
+
*
|
|
9
|
+
* A work item is integrated when a commit on the default branch carries its id on a `Work-Item: <id>` line (see trailersOn). For
|
|
10
|
+
* each such item that is not integrated yet, this appends ONE `integrated` line to planning/work-items.jsonl, through
|
|
11
|
+
* the ledger's one writer (scripts/work-item.js appendEvent), with `evidence: commit:<sha>`. Run it twice and the
|
|
12
|
+
* second run appends nothing: an item whose folded history already holds `integrated` is skipped (X26, idempotent per
|
|
13
|
+
* work item and sha). The plan item the work item materializes then reads Done with no hand edit (lib/plan-tree.js
|
|
14
|
+
* applies lib/factory-join.js), and a plan item moved to Done before this reads "Done · your call · not merged".
|
|
15
|
+
*
|
|
16
|
+
* LOCAL REFS ONLY (D70). The default branch is the engine's trunk (scripts/delivery-index.js trunkRef: origin/main,
|
|
17
|
+
* main, origin/master, master — as the local repository last saw them). This never runs `git fetch` or any other
|
|
18
|
+
* command that reaches a remote: `git rev-parse`, `git log` and `git merge-base`, nothing else. To see newer commits,
|
|
19
|
+
* the PM pulls (Sync) first.
|
|
20
|
+
*
|
|
21
|
+
* `--branch <ref>` NARROWS, IT NEVER WIDENS. The ref must be the default branch's head or an ancestor of it, so every
|
|
22
|
+
* commit it reads is already on the default branch. A ref that is not (an agent's own unmerged branch) is refused and
|
|
23
|
+
* nothing is appended: integrated means merged (C6/R7), and this command is not a PM-only act.
|
|
24
|
+
*
|
|
25
|
+
* THE WRITER DECIDES, NOT THIS FILE. An item that is merged but not verified (D65(d): verify comes before integrate),
|
|
26
|
+
* failed, or withdrawn is refused by appendEvent; this reports the refusal with its reason and appends nothing for it.
|
|
27
|
+
* A trailer that names no work item is reported, never turned into a declared item. The ledger this writes is the
|
|
28
|
+
* one the writer allows — the repository this file sits in — so `pmos verify-work` runs the repository's own copy.
|
|
29
|
+
*
|
|
30
|
+
* MAIN WORKING TREE ONLY. The workspace (lib/factory-join.js, lib/plan-tree.js) and the engine (plan-items-stage.js)
|
|
31
|
+
* read planning/work-items.jsonl of the MAIN working tree. A copy of this file in a linked worktree would write the
|
|
32
|
+
* worktree's ledger, which no view reads, so it refuses and names the main tree. `pmos verify-work` runs the main
|
|
33
|
+
* tree's copy from anywhere in the repository.
|
|
34
|
+
*
|
|
35
|
+
* Exit codes: 0 done (also when nothing was new), 1 a refusal or no default branch, 2 usage.
|
|
36
|
+
*/
|
|
37
|
+
const path = require('path');
|
|
38
|
+
const { spawnSync } = require('child_process');
|
|
39
|
+
const W = require('./work-item.js');
|
|
40
|
+
const delivery = require('./delivery-index.js');
|
|
41
|
+
const { mainTree } = require('./plan-items-stage.js');
|
|
42
|
+
|
|
43
|
+
const REPO = path.resolve(__dirname, '..');
|
|
44
|
+
const LEDGER = path.join(REPO, 'planning', 'work-items.jsonl');
|
|
45
|
+
const TRAILER = 'Work-Item';
|
|
46
|
+
|
|
47
|
+
function git(args) {
|
|
48
|
+
const r = spawnSync('git', args, { cwd: REPO, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
|
|
49
|
+
return r.error || r.status !== 0 ? null : r.stdout;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Every `Work-Item:` id on the branch, with the OLDEST commit that carries it (the commit that brought it in).
|
|
53
|
+
*
|
|
54
|
+
* A `Work-Item: <id>` LINE anywhere in the message counts, not only git's trailer block (initiative loop-telemetry). A PR is
|
|
55
|
+
* squash-merged, and the squash message is the PR body followed by GitHub's own `Co-authored-by:` paragraph, so a
|
|
56
|
+
* `Work-Item:` line in the body is never in the LAST paragraph, which is the only one `%(trailers)` reads. Every one of those
|
|
57
|
+
* merges read as carrying no work item. The line must start at column 0 with the exact key; a quoted or indented mention
|
|
58
|
+
* (`> Work-Item: x`, a code sample) does not count. */
|
|
59
|
+
const LINE_RE = new RegExp(`^${TRAILER}:[ \\t]*(.+?)[ \\t]*$`, 'gm');
|
|
60
|
+
function idsInMessage(msg) {
|
|
61
|
+
const ids = [];
|
|
62
|
+
for (const m of String(msg || '').matchAll(LINE_RE)) for (const raw of m[1].split(',')) { const id = raw.trim(); if (id && !ids.includes(id)) ids.push(id); }
|
|
63
|
+
return ids;
|
|
64
|
+
}
|
|
65
|
+
function trailersOn(ref) {
|
|
66
|
+
const out = git(['log', '--reverse', '--format=%x1e%H%x1f%B', ref, '--']);
|
|
67
|
+
if (out === null) return null;
|
|
68
|
+
const firstSha = new Map();
|
|
69
|
+
for (const rec of out.split('\x1e')) {
|
|
70
|
+
const at = rec.indexOf('\x1f');
|
|
71
|
+
if (at < 0) continue;
|
|
72
|
+
const sha = rec.slice(0, at).trim();
|
|
73
|
+
if (!/^[0-9a-f]{40}$/.test(sha)) continue;
|
|
74
|
+
for (const id of idsInMessage(rec.slice(at + 1))) if (!firstSha.has(id)) firstSha.set(id, sha);
|
|
75
|
+
}
|
|
76
|
+
return firstSha;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function verifyWork({ branch = null, dryRun = false } = {}) {
|
|
80
|
+
const res = { ok: true, branch: null, head: null, appended: [], already: [], unknown: [], refused: [] };
|
|
81
|
+
const main = mainTree(REPO);
|
|
82
|
+
if (main !== REPO) return { ...res, ok: false, error: `${REPO} is a linked worktree. The views read the ledger of the main working tree: run this from ${main}` };
|
|
83
|
+
let ref = branch;
|
|
84
|
+
if (ref) {
|
|
85
|
+
const head = git(['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]);
|
|
86
|
+
if (!head) return { ...res, ok: false, error: `no local ref named ${ref}` };
|
|
87
|
+
res.head = head.trim();
|
|
88
|
+
const t = delivery.trunkRef(REPO);
|
|
89
|
+
if (!t) return { ...res, ok: false, error: 'no default branch (origin/main, main, origin/master or master) in the local refs' };
|
|
90
|
+
if (git(['merge-base', '--is-ancestor', res.head, t.head]) === null) {
|
|
91
|
+
return { ...res, ok: false, error: `${ref} is not on the default branch ${t.ref}: only merged commits mark work integrated` };
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
const t = delivery.trunkRef(REPO);
|
|
95
|
+
if (!t) return { ...res, ok: false, error: 'no default branch (origin/main, main, origin/master or master) in the local refs' };
|
|
96
|
+
ref = t.ref; res.head = t.head;
|
|
97
|
+
}
|
|
98
|
+
res.branch = ref;
|
|
99
|
+
const trailers = trailersOn(ref);
|
|
100
|
+
if (!trailers) return { ...res, ok: false, error: `git log ${ref} failed` };
|
|
101
|
+
|
|
102
|
+
let body = '';
|
|
103
|
+
try { body = W.readLedgerSafely(LEDGER); } catch (e) {
|
|
104
|
+
if (!(e && e.code === 'ENOENT')) return { ...res, ok: false, error: `the work-item ledger cannot be read: ${(e && e.message) || e}` };
|
|
105
|
+
}
|
|
106
|
+
const { items } = W.deriveItems(body, { now: W.writerNow() });
|
|
107
|
+
const byId = new Map(items.map((it) => [it.item_id, it]));
|
|
108
|
+
for (const [id, sha] of trailers) {
|
|
109
|
+
const it = byId.get(id);
|
|
110
|
+
if (!it) { res.unknown.push({ id, sha }); continue; }
|
|
111
|
+
if ((it.history || []).includes('integrated')) { res.already.push(id); continue; }
|
|
112
|
+
const ev = { item_id: id, initiative_id: it.initiative_id, event: 'integrated', at: W.writerNow(), evidence: `commit:${sha}` };
|
|
113
|
+
if (dryRun) { res.appended.push({ id, sha, dryRun: true }); continue; }
|
|
114
|
+
try { W.appendEvent(LEDGER, ev); res.appended.push({ id, sha }); }
|
|
115
|
+
catch (e) {
|
|
116
|
+
if (!(e instanceof W.ForbiddenWrite)) throw e;
|
|
117
|
+
res.refused.push({ id, sha, why: String(e.message || e) });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (res.refused.length) res.ok = false;
|
|
121
|
+
return res;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function main(argv) {
|
|
125
|
+
const json = argv.includes('--json');
|
|
126
|
+
const dryRun = argv.includes('--dry-run');
|
|
127
|
+
const at = argv.indexOf('--branch');
|
|
128
|
+
const branch = at !== -1 ? argv[at + 1] : null;
|
|
129
|
+
const known = new Set(['--json', '--dry-run', '--branch']);
|
|
130
|
+
const stray = argv.filter((a, i) => !known.has(a) && !(at !== -1 && i === at + 1));
|
|
131
|
+
if (stray.length || (at !== -1 && (!branch || branch.startsWith('--')))) {
|
|
132
|
+
console.log('usage: node scripts/verify-work.js [--branch <ref>] [--dry-run] [--json]');
|
|
133
|
+
return 2;
|
|
134
|
+
}
|
|
135
|
+
const r = verifyWork({ branch, dryRun });
|
|
136
|
+
if (json) { console.log(JSON.stringify(r)); return r.ok ? 0 : 1; }
|
|
137
|
+
if (r.error) { console.log(`✗ ${r.error}`); return 1; }
|
|
138
|
+
const short = (s) => s.slice(0, 8);
|
|
139
|
+
console.log(`Default branch: ${r.branch} at ${short(r.head)} (local refs only, no fetch).`);
|
|
140
|
+
for (const a of r.appended) console.log(`✓ ${a.id}: integrated (commit ${short(a.sha)})${a.dryRun ? ' — dry run, not written' : ''}`);
|
|
141
|
+
for (const u of r.unknown) console.log(`! ${u.id}: commit ${short(u.sha)} names a work item that the ledger does not have`);
|
|
142
|
+
for (const f of r.refused) console.log(`✗ ${f.id}: not written — ${f.why}`);
|
|
143
|
+
console.log(`${r.appended.length} new, ${r.already.length} already integrated, ${r.unknown.length} unknown, ${r.refused.length} refused.`);
|
|
144
|
+
return r.ok ? 0 : 1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
module.exports = { verifyWork, trailersOn, idsInMessage, TRAILER };
|
|
148
|
+
|
|
149
|
+
if (require.main === module) process.exitCode = main(process.argv.slice(2));
|