create-pmos 0.570.0 → 0.571.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 +14 -14
- package/payload/AGENTS.md +4 -3
- 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/scripts/factory-guardrail.js +267 -0
- package/payload/scripts/work-item.js +25 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/payload/templates/pmos-guardrail.yml +61 -0
- package/workspace/changelog.json +13 -0
- package/workspace/guide/cli.md +39 -4
- package/workspace/guide/initiatives-and-next-steps.md +1 -1
- package/workspace/lib/autonomy.js +3 -1
- package/workspace/lib/build-cli.js +33 -6
- package/workspace/lib/build-engine.js +89 -19
- package/workspace/lib/factory-rollout.js +190 -0
- package/workspace/lib/pmos-verbs.js +1 -1
- package/workspace/lib/routes-proposals.js +1 -1
- package/workspace/lib/team-cli.js +1 -1
- package/workspace/lib/verify-runs.js +17 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/ini-props.js +1 -1
- package/workspace/test-lists/build-engine.json +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.571.0",
|
|
4
4
|
"description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -33,6 +33,19 @@
|
|
|
33
33
|
"audit"
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
|
+
{
|
|
37
|
+
"v": "0.571.0",
|
|
38
|
+
"at": "2026-11-16T04:26:43.356Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1303,
|
|
43
|
+
"t": "The factory merges behind a guardrail, and rolls out behind a flag",
|
|
44
|
+
"s": "The factory merges behind a guardrail, and rolls out behind a flag",
|
|
45
|
+
"k": "new"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
36
49
|
{
|
|
37
50
|
"v": "0.570.0",
|
|
38
51
|
"at": "2026-11-15T17:32:20.370Z",
|
|
@@ -297,19 +310,6 @@
|
|
|
297
310
|
"k": "fix"
|
|
298
311
|
}
|
|
299
312
|
]
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
"v": "0.551.0",
|
|
303
|
-
"at": "2026-11-10T11:25:58.991Z",
|
|
304
|
-
"f": 4,
|
|
305
|
-
"prs": [
|
|
306
|
-
{
|
|
307
|
-
"n": 1279,
|
|
308
|
-
"t": "Intent card on the product page; the Board by goal, and a Next column that says what Claude does next",
|
|
309
|
-
"s": "Intent card on the product page; the Board by goal, and a Next column that says what Claude does next",
|
|
310
|
-
"k": "new"
|
|
311
|
-
}
|
|
312
|
-
]
|
|
313
313
|
}
|
|
314
314
|
]
|
|
315
315
|
}
|
package/payload/AGENTS.md
CHANGED
|
@@ -125,10 +125,11 @@ This kit carries the factory: `pmos/scripts/work-item.js` (the one writer of `pm
|
|
|
125
125
|
|
|
126
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
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.
|
|
129
|
-
4.
|
|
128
|
+
3. PMOS opens the pull request by itself (D108): the workspace applies the proposal, pushes the one branch and runs `gh pr create --draft`. Undo closes it. With `pmos ai off` it waits for the PM's ✓. The Builder's own run never pushes.
|
|
129
|
+
4. Who merges is the product's own check, `pmos-guardrail` (copy `pmos/templates/pmos-guardrail.yml` to `.github/workflows/`; D108). It runs the default branch's `pmos/scripts/factory-guardrail.js` on the pull request's diff and reads AUTO or HUMAN. On AUTO it turns on GitHub auto-merge with the workflow's own token, so GitHub merges when every required check is green. On HUMAN the PM merges. The triggers that always read HUMAN are listed in that script and in the workspace guide (`pmos build policy <item>` shows the answer).
|
|
130
|
+
5. After the merge, `pmos verify-work` marks the item integrated, and the item's flag rolls out 5% → 50% → 100% through the commands in `pmos/factory.json`. A metric over its budget turns the flag off, opens a revert pull request and puts the factory back to propose-only for 7 days.
|
|
130
131
|
|
|
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
|
|
132
|
+
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 guardrail workflow holds a write token and reads untrusted content (the diff), so it never runs the pull request's code: `pull_request_target` runs the default branch's workflow and script, and the head is only fetched and diffed. A pull request that changes CI, the guardrail or its own tests reads HUMAN. The compensating gate is the product's own CI and branch protection on the default branch: protect it, and make your CI required, before you use the guardrail.
|
|
132
133
|
|
|
133
134
|
## Escalation (stop and ask the PM)
|
|
134
135
|
|
package/payload/KIT-VERSION
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
kernel-source: pmos@
|
|
2
|
-
assembled: 2026-11-
|
|
1
|
+
kernel-source: pmos@f2bfbfa4
|
|
2
|
+
assembled: 2026-11-16
|
|
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-16T04:26: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-16T04:26:40Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* factory-guardrail.js — when a factory pull request may merge with no person (D108, initiative factory-guardrail-merge).
|
|
4
|
+
*
|
|
5
|
+
* Deterministic: it reads the diff, the work item and git history. No model call, no network except the two gh calls below.
|
|
6
|
+
* It is vendored with the factory into the kit (pmos/scripts/), and the product repository's workflow `pmos-guardrail`
|
|
7
|
+
* (kit/templates/pmos-guardrail.yml, on pull_request_target) runs THE DEFAULT BRANCH'S COPY of this file on the pull request's
|
|
8
|
+
* diff. The pull request's own code never runs, so a pull request cannot rewrite the rule that judges it.
|
|
9
|
+
*
|
|
10
|
+
* classify({ cwd, base, head, branch, body, ledgerText, now }) → { factory, item, verdict: 'auto'|'human'|'none', reasons, files }
|
|
11
|
+
*
|
|
12
|
+
* `none` not a factory pull request (no branch pmos/<item> and no line `Work-Item: <id>`): PMOS does nothing.
|
|
13
|
+
* `auto` ALL of: the item is verified in the default branch's ledger; every changed file is inside the item's declared scope;
|
|
14
|
+
* the change sits behind the item's flag (its name appears in the added lines) or the item is declared with no
|
|
15
|
+
* user-facing effect; and no trigger below fires. Required CI is GitHub's part: auto-merge waits for every required check.
|
|
16
|
+
* `human` any trigger, or any `auto` condition missing. Every reason is named.
|
|
17
|
+
*
|
|
18
|
+
* TRIGGERS (any one → human): migrations or data deletion · auth, permissions, payments, personal data or secrets · CI, gates,
|
|
19
|
+
* the guardrail, PMOS records or branch protection · a new dependency (a manifest line or a lock file) · a public API or contract ·
|
|
20
|
+
* anything sent outward · a new agent path · a changed existing test, test configuration or the item's own check reference ·
|
|
21
|
+
* the D11 triggers: the item failed before, a revert on the default branch in the last 14 days, a subsystem untouched 90 days ·
|
|
22
|
+
* the line `PMOS-Merge: human` (PMOS writes it when autonomy is off or the factory is demoted; the PM may add it to stop a merge) ·
|
|
23
|
+
* a pull request from a fork (a branch named pmos/… elsewhere is not PMOS's).
|
|
24
|
+
*
|
|
25
|
+
* CLI (the workflow's one step):
|
|
26
|
+
* node pmos/scripts/factory-guardrail.js --base <ref> --head <ref> [--branch <name>] [--body-file <f>] [--head-repo o/r --base-repo o/r] [--json]
|
|
27
|
+
* [--github --pr <number>] in GitHub Actions only: write verdict to GITHUB_OUTPUT and the step summary; on auto run
|
|
28
|
+
* `gh pr ready` and `gh pr merge --auto --squash` with the workflow's own token; on human turn
|
|
29
|
+
* auto-merge off. The agent never runs this: the Builder has no node, gh or push.
|
|
30
|
+
* Exit 0 for every verdict (the check reports, it does not block). A failure to read anything is `human`, never `auto`.
|
|
31
|
+
*/
|
|
32
|
+
const fs = require('fs');
|
|
33
|
+
const path = require('path');
|
|
34
|
+
const cp = require('child_process');
|
|
35
|
+
|
|
36
|
+
const DAY = 86400000;
|
|
37
|
+
const REVERT_DAYS = 14;
|
|
38
|
+
const STALE_DAYS = 90;
|
|
39
|
+
const ITEM_RE = /^[a-z0-9][a-z0-9_-]*\.[0-9]+$/;
|
|
40
|
+
|
|
41
|
+
/* ---- the trigger list. Paths are matched lower case on their segments, so "controller" is not "role". ---- */
|
|
42
|
+
const seg = (f) => String(f).toLowerCase().split(/[\/._-]+/).filter(Boolean);
|
|
43
|
+
const segHas = (f, words) => seg(f).some((s) => words.includes(s));
|
|
44
|
+
const SENSITIVE = ['auth', 'authn', 'authz', 'oauth', 'login', 'logout', 'signin', 'session', 'sessions', 'permission', 'permissions', 'rbac', 'acl',
|
|
45
|
+
'role', 'roles', 'payment', 'payments', 'billing', 'stripe', 'checkout', 'invoice', 'invoices', 'pii', 'gdpr', 'privacy', 'secret', 'secrets',
|
|
46
|
+
'credential', 'credentials', 'password', 'passwords', 'vault', 'kms', 'env', 'keystore'];
|
|
47
|
+
const MIGRATION = ['migration', 'migrations', 'migrate', 'alembic', 'flyway', 'liquibase', 'sql'];
|
|
48
|
+
const API = ['openapi', 'swagger', 'proto', 'graphql', 'gql', 'wsdl'];
|
|
49
|
+
const AGENT_PATH = ['agents', 'claude', 'prompts', 'prompt', 'skills', 'mcp'];
|
|
50
|
+
const MANIFESTS = ['requirements.txt', 'requirements-dev.txt', 'pyproject.toml', 'pipfile', 'setup.py', 'setup.cfg', 'go.mod', 'cargo.toml', 'gemfile',
|
|
51
|
+
'pom.xml', 'build.gradle', 'build.gradle.kts', 'composer.json', 'mix.exs', 'pubspec.yaml', 'package.swift', 'podfile', 'deno.json'];
|
|
52
|
+
const LOCKS = ['package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'poetry.lock', 'pipfile.lock', 'cargo.lock',
|
|
53
|
+
'go.sum', 'gemfile.lock', 'composer.lock', 'mix.lock', 'pubspec.lock', 'podfile.lock', 'uv.lock'];
|
|
54
|
+
const TEST_CONFIG = /(^|\/)(jest|vitest|playwright|cypress|karma|mocha|ava|babel|tsconfig)[^/]*\.(js|cjs|mjs|ts|json)$|(^|\/)(\.mocharc[^/]*|pytest\.ini|tox\.ini|conftest\.py|\.nycrc[^/]*|phpunit\.xml[^/]*)$/;
|
|
55
|
+
const TEST_FILE = /(^|\/)(tests?|__tests__|specs?|e2e|testdata|fixtures|__snapshots__)\//;
|
|
56
|
+
const TEST_NAME = /\.(test|spec)\.[a-z0-9]+$|_test\.(go|py|rb)$|(^|\/)test_[^/]*\.py$|\.snap$/;
|
|
57
|
+
const CI = /^(\.github\/|\.gitlab-ci\.yml$|\.gitlab\/|\.circleci\/|\.buildkite\/|\.drone\.yml$|azure-pipelines|bitbucket-pipelines\.yml$|jenkinsfile$|\.travis\.yml$|codeowners$|docs\/codeowners$|\.pre-commit-config\.yaml$|\.husky\/|lefthook\.yml$|pmos\/|\.pmos-profile$)/;
|
|
58
|
+
const GUARD_NAME = /(^|\/)(factory-guardrail\.js|pmos-guardrail\.ya?ml)$/;
|
|
59
|
+
const AGENT_FILES = /(^|\/)(agents\.md|claude\.md|gemini\.md|\.cursorrules|\.claude\/|\.cursor\/|\.codex\/)/;
|
|
60
|
+
|
|
61
|
+
const ADDED = [
|
|
62
|
+
{ rule: 'data-deletion', re: /\b(drop\s+(table|column|database|schema|index)|truncate\s+(table\s+)?\w|delete\s+from\s|alter\s+table\b[^;]*\bdrop\b)/i, why: 'deletes data or changes a schema' },
|
|
63
|
+
{ rule: 'data-deletion', re: /\.(deleteMany|dropCollection|dropDatabase|drop_table|remove_column|drop_column)\s*\(|\brm\s+-rf?\s+\//, why: 'deletes data' },
|
|
64
|
+
{ rule: 'secrets', re: /(api[_-]?key|secret[_-]?key|client[_-]?secret|private[_-]?key|access[_-]?token|auth[_-]?token|password\s*[:=]|BEGIN [A-Z ]*PRIVATE KEY|aws_secret|xox[abp]-|gh[pousr]_[A-Za-z0-9]{20,}|sk-[A-Za-z0-9]{20,})/i, why: 'names a secret or a credential' },
|
|
65
|
+
{ rule: 'outward', re: /\b(fetch\s*\(|axios\b|XMLHttpRequest|https?\.request\s*\(|https?\.get\s*\(|new\s+WebSocket\s*\(|navigator\.sendBeacon|sendMail|nodemailer|smtplib|smtp\b|webhook|twilio|sendgrid|mailgun|requests\.(get|post|put|delete|patch)\s*\(|urllib\.request|net\/http|http\.Post|curl\s|wget\s)/i, why: 'sends something outward' },
|
|
66
|
+
{ rule: 'agent-path', re: /(@anthropic-ai\/|\banthropic\b|\bopenai\b|\bclaude\s+-p\b|\blangchain\b|\bllm\b|child_process|\bexecSync\s*\(|\bexecFile(Sync)?\s*\(|\bspawn(Sync)?\s*\(|\beval\s*\(|new\s+Function\s*\(|subprocess\.|os\.system\s*\()/i, why: 'adds a model call or runs a program (a new agent path)' },
|
|
67
|
+
];
|
|
68
|
+
|
|
69
|
+
function git(cwd, args) {
|
|
70
|
+
const r = cp.spawnSync('git', args, { cwd, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, env: { ...process.env, GIT_TERMINAL_PROMPT: '0' } });
|
|
71
|
+
return { ok: !r.error && r.status === 0, out: String(r.stdout || ''), err: String(r.stderr || (r.error && r.error.message) || '').trim() };
|
|
72
|
+
}
|
|
73
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
74
|
+
|
|
75
|
+
/** The ledger as the base has it: `git show <base>:<path>`, so a local preview reads exactly what CI reads. */
|
|
76
|
+
function baseLedger(cwd, base) {
|
|
77
|
+
const top = git(cwd, ['rev-parse', '--show-toplevel']).out.trim() || cwd;
|
|
78
|
+
const file = path.join(__dirname, '..', 'planning', 'work-items.jsonl');
|
|
79
|
+
const rel = path.relative(top, file).split(path.sep).join('/');
|
|
80
|
+
if (!rel.startsWith('..')) { const r = git(top, ['show', `${base}:${rel}`]); if (r.ok) return { text: r.out, rel }; }
|
|
81
|
+
return { text: null, rel };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Files and added lines of base...head (three dots: what the pull request adds to its merge base). */
|
|
85
|
+
function diffOf(cwd, base, head) {
|
|
86
|
+
const ns = git(cwd, ['diff', '--name-status', '-M', '--no-color', `${base}...${head}`]);
|
|
87
|
+
if (!ns.ok) return { error: `git could not diff ${base}...${head}: ${one(ns.err, 200)}` };
|
|
88
|
+
const files = [];
|
|
89
|
+
for (const l of ns.out.split('\n').filter(Boolean)) {
|
|
90
|
+
const p = l.split('\t');
|
|
91
|
+
const st = p[0][0];
|
|
92
|
+
files.push({ status: st, path: p[p.length - 1], from: st === 'R' || st === 'C' ? p[1] : null });
|
|
93
|
+
}
|
|
94
|
+
const u = git(cwd, ['diff', '-U0', '--no-color', '--no-ext-diff', `${base}...${head}`]);
|
|
95
|
+
const added = new Map();
|
|
96
|
+
let cur = null;
|
|
97
|
+
for (const l of u.out.split('\n')) {
|
|
98
|
+
if (l.startsWith('+++ ')) { cur = l.slice(4).replace(/^b\//, ''); if (!added.has(cur)) added.set(cur, []); continue; }
|
|
99
|
+
if (l.startsWith('+') && cur && cur !== '/dev/null') added.get(cur).push(l.slice(1));
|
|
100
|
+
}
|
|
101
|
+
return { files, added };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function depsOf(text) {
|
|
105
|
+
try {
|
|
106
|
+
const j = JSON.parse(text);
|
|
107
|
+
const out = new Set();
|
|
108
|
+
for (const k of ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies', 'bundledDependencies']) {
|
|
109
|
+
const v = j[k];
|
|
110
|
+
if (Array.isArray(v)) v.forEach((x) => out.add(k + ':' + x));
|
|
111
|
+
else if (v && typeof v === 'object') Object.keys(v).forEach((x) => out.add(k + ':' + x));
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
} catch { return null; }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Was a merge reverted on the base lately? → days ago | null */
|
|
118
|
+
function recentRevert(cwd, base, nowMs) {
|
|
119
|
+
const r = git(cwd, ['log', `--since=${new Date(nowMs - REVERT_DAYS * DAY).toISOString()}`, '--format=%ct%x09%s', base]);
|
|
120
|
+
if (!r.ok) return null;
|
|
121
|
+
for (const l of r.out.split('\n').filter(Boolean)) {
|
|
122
|
+
const [ct, s] = l.split('\t');
|
|
123
|
+
if (/^revert\b/i.test(s || '')) return Math.max(0, Math.floor((nowMs - Number(ct) * 1000) / DAY));
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The touched folders whose last change on the base is older than 90 days (D11: a subsystem untouched ~3 months). */
|
|
129
|
+
function staleDirs(cwd, base, files, nowMs) {
|
|
130
|
+
const dirs = [...new Set(files.filter((f) => f.status !== 'A').map((f) => path.posix.dirname(f.from || f.path)).filter((d) => d && d !== '.'))];
|
|
131
|
+
const out = [];
|
|
132
|
+
for (const d of dirs.slice(0, 40)) {
|
|
133
|
+
const r = git(cwd, ['log', '-1', '--format=%ct', base, '--', d]);
|
|
134
|
+
const ct = Number(r.out.trim());
|
|
135
|
+
if (ct && nowMs - ct * 1000 > STALE_DAYS * DAY) out.push({ dir: d, days: Math.floor((nowMs - ct * 1000) / DAY) });
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const pathsIn = (ref) => String(ref || '').split(/\s+/).map((t) => t.replace(/^['"]|['"]$/g, '').replace(/^\.\//, '')).filter((t) => /[\/]|\.[a-z0-9]+$/i.test(t) && !t.startsWith('-'));
|
|
141
|
+
const inScope = (f, scope) => scope.some((s) => { const p = s.replace(/^\.\//, ''); return p.endsWith('/') ? f.startsWith(p) : f === p || f.startsWith(p + '/'); });
|
|
142
|
+
|
|
143
|
+
/** The verdict. Pure but for git reads in `cwd`. */
|
|
144
|
+
function classify({ cwd = process.cwd(), base, head, branch = '', body = '', ledgerText, now, headRepo = null, baseRepo = null } = {}) {
|
|
145
|
+
const nowMs = now == null ? Date.now() : (typeof now === 'number' ? now : Date.parse(now));
|
|
146
|
+
const fromBranch = /^(?:refs\/heads\/)?pmos\/(?:revert-)?([a-z0-9][a-z0-9_-]*\.[0-9]+)$/.exec(String(branch || ''));
|
|
147
|
+
const fromBody = /^Work-Item:\s*(\S+)\s*$/m.exec(String(body || ''));
|
|
148
|
+
const item = fromBranch ? fromBranch[1] : fromBody && ITEM_RE.test(fromBody[1]) ? fromBody[1] : null;
|
|
149
|
+
const isRevert = /^(?:refs\/heads\/)?pmos\/revert-/.test(String(branch || ''));
|
|
150
|
+
if (!item && !isRevert) return { factory: false, item: null, verdict: 'none', reasons: [{ rule: 'not-factory', detail: 'not a factory pull request (no branch pmos/<item>, no Work-Item line)' }], files: [] };
|
|
151
|
+
const reasons = [];
|
|
152
|
+
const human = (rule, detail) => reasons.push({ rule, detail });
|
|
153
|
+
if (isRevert) human('revert', 'a revert pull request opened by the rollout: the flag is already off, and the PM merges the revert');
|
|
154
|
+
if (headRepo && baseRepo && String(headRepo).toLowerCase() !== String(baseRepo).toLowerCase()) human('fork', `the pull request comes from ${one(headRepo, 100)}, not from this repository: PMOS pushes only here`);
|
|
155
|
+
if (/^PMOS-Merge:\s*human\s*$/mi.test(String(body || ''))) human('pmos-merge-human', 'PMOS asked for a person (autonomy is off, or the factory is back to propose-only)');
|
|
156
|
+
if (!base || !head) { human('unreadable', 'no base or head to compare'); return { factory: true, item, verdict: 'human', reasons, files: [] }; }
|
|
157
|
+
|
|
158
|
+
const d = diffOf(cwd, base, head);
|
|
159
|
+
if (d.error) { human('unreadable', d.error); return { factory: true, item, verdict: 'human', reasons, files: [] }; }
|
|
160
|
+
const files = d.files;
|
|
161
|
+
if (!files.length) human('empty', 'the pull request changes nothing');
|
|
162
|
+
|
|
163
|
+
// ---- the work item, as the default branch's ledger has it
|
|
164
|
+
let it = null;
|
|
165
|
+
const lt = ledgerText !== undefined ? { text: ledgerText } : baseLedger(cwd, base);
|
|
166
|
+
if (item) {
|
|
167
|
+
if (lt.text == null) human('no-ledger', 'the default branch has no work-item ledger');
|
|
168
|
+
else {
|
|
169
|
+
try {
|
|
170
|
+
const W = require('./work-item.js');
|
|
171
|
+
it = (W.deriveItems(lt.text, { now: new Date(nowMs).toISOString() }).items || []).find((x) => x.item_id === item) || null;
|
|
172
|
+
} catch (e) { human('unreadable', 'the ledger could not be read: ' + one(e.message, 160)); }
|
|
173
|
+
if (!it) human('not-declared', `${item} is not in the default branch's ledger. Push the PMOS records (Sync), then run this check again`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const hist = (it && it.history) || [];
|
|
177
|
+
if (it && !hist.includes('verified')) human('not-verified', `${item} is ${it.state} on the default branch, not verified: its check has not passed there. Push the PMOS records (Sync), then run this check again`);
|
|
178
|
+
if (hist.includes('failed')) human('d11-failed', `${item} failed before (D11)`);
|
|
179
|
+
const g = (it && it.guard) || null;
|
|
180
|
+
const scope = g && Array.isArray(g.scope) ? g.scope.filter((s) => typeof s === 'string' && s.trim()) : [];
|
|
181
|
+
if (it && !scope.length) human('no-scope', `${item} declares no scope, so PMOS cannot tell whether the change stayed inside it`);
|
|
182
|
+
|
|
183
|
+
// ---- per file
|
|
184
|
+
const all = [];
|
|
185
|
+
for (const f of files) {
|
|
186
|
+
const p = f.path, l = p.toLowerCase(), base_ = path.posix.basename(l);
|
|
187
|
+
const add = d.added.get(p) || [];
|
|
188
|
+
all.push(...add.map((t) => [p, t]));
|
|
189
|
+
if (scope.length && !inScope(p, scope) && !(f.from && inScope(f.from, scope) && inScope(p, scope))) human('out-of-scope', `${p} is outside the declared scope (${scope.join(', ')})`);
|
|
190
|
+
if (CI.test(l) || GUARD_NAME.test(l)) human('ci-gates', `${p} is CI, a gate, the guardrail, a PMOS record or branch protection`);
|
|
191
|
+
if (AGENT_FILES.test(l) || segHas(p, AGENT_PATH)) human('agent-path', `${p} is an agent rule, prompt or skill (a new agent path)`);
|
|
192
|
+
if (segHas(p, MIGRATION) || /schema\.prisma$|(^|\/)db\/schema\./.test(l)) human('migration', `${p} is a migration or a schema`);
|
|
193
|
+
if (segHas(p, SENSITIVE) || /(^|\/)\.env(\.|$)|\.(pem|key|p12|pfx|jks)$/.test(l)) human('sensitive', `${p} touches auth, permissions, payments, personal data or secrets`);
|
|
194
|
+
if (segHas(p, API) || /(^|\/)index\.d\.ts$/.test(l)) human('public-api', `${p} is a public API or contract`);
|
|
195
|
+
if (LOCKS.includes(base_)) human('dependency', `${p} changes a lock file (a dependency may be new)`);
|
|
196
|
+
if (MANIFESTS.includes(base_) && add.some((t) => t.trim())) human('dependency', `${p} changes a dependency manifest`);
|
|
197
|
+
if (base_ === 'package.json') {
|
|
198
|
+
const before = git(cwd, ['show', `${base}:${f.from || p}`]), after = git(cwd, ['show', `${head}:${p}`]);
|
|
199
|
+
const a = before.ok ? depsOf(before.out) : new Set(), b = after.ok ? depsOf(after.out) : null;
|
|
200
|
+
if (!a || !b) human('dependency', `${p} could not be read`);
|
|
201
|
+
else { const added = [...b].filter((x) => !a.has(x)); if (added.length) human('dependency', `${p} adds ${added.map((x) => x.split(':')[1]).join(', ')}`); }
|
|
202
|
+
}
|
|
203
|
+
if (f.status !== 'A' && (TEST_FILE.test(l) || TEST_NAME.test(l))) human('self-test', `${p} changes an existing test (a pull request may not change what judges it)`);
|
|
204
|
+
if (TEST_CONFIG.test(l)) human('self-test', `${p} changes the test configuration`);
|
|
205
|
+
if (it && it.criterion) for (const r of pathsIn(it.criterion.ref)) if (p === r || p.startsWith(r.replace(/\/?$/, '/'))) human('self-test', `${p} is the item's own check (${it.criterion.ref})`);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ---- added lines
|
|
209
|
+
const code = all.filter(([p]) => !/\.(md|mdx|txt|rst|adoc)$/i.test(p) && !TEST_FILE.test(p.toLowerCase()) && !TEST_NAME.test(p.toLowerCase()));
|
|
210
|
+
for (const t of ADDED) {
|
|
211
|
+
const hit = code.find(([, line]) => t.re.test(line));
|
|
212
|
+
if (hit) human(t.rule, `${hit[0]} ${t.why}: "${one(hit[1], 100)}"`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ---- the flag, or no user-facing effect
|
|
216
|
+
if (it && g) {
|
|
217
|
+
if (g.user_facing === false) { /* declared with no user-facing effect: no flag needed */ }
|
|
218
|
+
else if (!g.flag || !g.flag.name) human('no-flag', `${item} is user-facing and declares no flag. Declare --flag <name>, or --no-user-facing`);
|
|
219
|
+
else if (!code.some(([, line]) => line.includes(g.flag.name))) human('not-flagged', `the change does not read its flag ${g.flag.name}, so it would reach users at once`);
|
|
220
|
+
} else if (it) human('no-flag', `${item} declares neither a flag nor --no-user-facing`);
|
|
221
|
+
|
|
222
|
+
// ---- D11: history
|
|
223
|
+
const rv = recentRevert(cwd, base, nowMs);
|
|
224
|
+
if (rv !== null) human('d11-revert', `a merge was reverted on the default branch ${rv === 0 ? 'today' : rv + ' days ago'} (D11)`);
|
|
225
|
+
for (const s of staleDirs(cwd, base, files, nowMs)) human('d11-stale', `${s.dir} was last changed ${s.days} days ago (D11: a subsystem untouched about 3 months)`);
|
|
226
|
+
|
|
227
|
+
const seen = new Set();
|
|
228
|
+
const uniq = reasons.filter((r) => { const k = r.rule + '|' + r.detail; if (seen.has(k)) return false; seen.add(k); return true; });
|
|
229
|
+
return { factory: true, item, verdict: uniq.length ? 'human' : 'auto', reasons: uniq, files: files.map((f) => f.path) };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function summaryOf(v) {
|
|
233
|
+
if (v.verdict === 'none') return 'pmos-guardrail: not a factory pull request. Nothing to do.';
|
|
234
|
+
if (v.verdict === 'auto') return `pmos-guardrail: AUTO for ${v.item}. Auto-merge is on: GitHub merges when every required check is green. The change reaches users only through its flag.`;
|
|
235
|
+
return [`pmos-guardrail: HUMAN for ${v.item || 'this revert'}. A person merges this pull request, because:`, ...v.reasons.map((r) => `- ${r.detail}`)].join('\n');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** GitHub Actions only: act on the verdict with the workflow's own token. The agent never reaches this. → [{ args, status }] */
|
|
239
|
+
function actOnGitHub(v, { pr, env = process.env } = {}) {
|
|
240
|
+
if (env.GITHUB_ACTIONS !== 'true') throw new Error('--github runs only inside GitHub Actions');
|
|
241
|
+
if (!/^[0-9]+$/.test(String(pr || ''))) throw new Error('--github needs --pr <number>');
|
|
242
|
+
const run = (args) => { const r = cp.spawnSync('gh', args, { encoding: 'utf8', env }); return { args, status: r.status, out: one(r.stdout || r.stderr || (r.error && r.error.message), 300) }; };
|
|
243
|
+
if (env.GITHUB_OUTPUT) fs.appendFileSync(env.GITHUB_OUTPUT, `verdict=${v.verdict}\nitem=${v.item || ''}\n`);
|
|
244
|
+
if (env.GITHUB_STEP_SUMMARY) fs.appendFileSync(env.GITHUB_STEP_SUMMARY, summaryOf(v) + '\n');
|
|
245
|
+
if (v.verdict === 'auto') return [run(['pr', 'ready', String(pr)]), run(['pr', 'merge', String(pr), '--auto', '--squash'])];
|
|
246
|
+
if (v.verdict === 'human') return [run(['pr', 'merge', String(pr), '--disable-auto'])];
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function cliMain(argv, { say = (s) => console.log(s), env = process.env, cwd = process.cwd() } = {}) {
|
|
251
|
+
const opt = (k) => { const i = argv.indexOf(k); return i !== -1 && argv[i + 1] !== undefined && !argv[i + 1].startsWith('--') ? argv[i + 1] : undefined; };
|
|
252
|
+
const base = opt('--base'), head = opt('--head');
|
|
253
|
+
if (!base || !head) { say('usage: node factory-guardrail.js --base <ref> --head <ref> [--branch <name>] [--body-file <f>] [--json] [--github --pr <n>]'); return 2; }
|
|
254
|
+
let body = '';
|
|
255
|
+
if (opt('--body-file')) { try { body = fs.readFileSync(opt('--body-file'), 'utf8'); } catch { body = 'PMOS-Merge: human'; } }
|
|
256
|
+
let v;
|
|
257
|
+
try { v = classify({ cwd, base, head, branch: opt('--branch') || '', body, headRepo: opt('--head-repo') || null, baseRepo: opt('--base-repo') || null }); }
|
|
258
|
+
catch (e) { v = { factory: true, item: null, verdict: 'human', reasons: [{ rule: 'unreadable', detail: 'the guardrail failed: ' + one(e.message, 200) }], files: [] }; }
|
|
259
|
+
say(argv.includes('--json') ? JSON.stringify(v) : summaryOf(v));
|
|
260
|
+
if (argv.includes('--github')) {
|
|
261
|
+
for (const r of actOnGitHub(v, { pr: opt('--pr'), env })) say(`gh ${r.args.join(' ')} → ${r.status}${r.out ? ' ' + r.out : ''}`);
|
|
262
|
+
}
|
|
263
|
+
return 0;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
module.exports = { classify, summaryOf, actOnGitHub, cliMain, REVERT_DAYS, STALE_DAYS };
|
|
267
|
+
if (require.main === module) process.exitCode = cliMain(process.argv.slice(2));
|
|
@@ -453,6 +453,7 @@ function deriveItems(input, opts) {
|
|
|
453
453
|
blast: obj.blast,
|
|
454
454
|
criterion: obj.criterion,
|
|
455
455
|
...(obj.plan_item !== undefined ? { plan_item: obj.plan_item } : {}), // D86 point 1; absent stays absent
|
|
456
|
+
...(obj.guard !== undefined ? { guard: obj.guard } : {}), // D108: scope, flag, user_facing, kr — what the merge guardrail reads
|
|
456
457
|
state: 'declared',
|
|
457
458
|
claim: null,
|
|
458
459
|
evidence: null,
|
|
@@ -1382,6 +1383,26 @@ module.exports = {
|
|
|
1382
1383
|
* prints the trailer line for the PR body: `Work-Item: <id>`. `verify` appends `verified` once the criterion's check passed.
|
|
1383
1384
|
* After the PR merges, `verify-work.js` (or `pmos verify-work`) finds the line in the squash commit and appends `integrated`.
|
|
1384
1385
|
* Every append goes through appendEvent, so every rule above still decides; a refusal prints its reason and exits 1. */
|
|
1386
|
+
/** D108: what the merge guardrail (scripts/factory-guardrail.js) reads from a declared item. → guard | null | { error }
|
|
1387
|
+
* --scope <prefix[,prefix]> the paths the item may change (no scope: its pull request always waits for the PM)
|
|
1388
|
+
* --flag <name> [--metric <name in factory.json metrics> --budget <max>] the flag the change sits behind, and its guard metric
|
|
1389
|
+
* --no-user-facing the change has no user-facing effect, so it needs no flag
|
|
1390
|
+
* --kr the item moves a key result: its rollout waits for the PM before 100% */
|
|
1391
|
+
function guardOf(argv, opt) {
|
|
1392
|
+
const has = (k) => argv.includes(k);
|
|
1393
|
+
if (!['--scope', '--flag', '--no-user-facing', '--kr', '--metric', '--budget'].some(has)) return null;
|
|
1394
|
+
const scope = String(opt('--scope') || '').split(',').map((x) => x.trim().replace(/^\.\//, '')).filter(Boolean);
|
|
1395
|
+
if (scope.some((x) => x.startsWith('/') || x.split('/').includes('..'))) return { error: '--scope takes paths inside the repository' };
|
|
1396
|
+
const g = { scope, user_facing: !has('--no-user-facing'), kr: has('--kr') };
|
|
1397
|
+
if (opt('--flag')) {
|
|
1398
|
+
if (!/^[A-Za-z0-9_.:-]{2,80}$/.test(opt('--flag'))) return { error: '--flag is one name: letters, digits, _ . : -' };
|
|
1399
|
+
g.flag = { name: opt('--flag') };
|
|
1400
|
+
if (opt('--metric')) { if (!/^[A-Za-z0-9_.:-]{1,80}$/.test(opt('--metric'))) return { error: '--metric names a metric in factory.json' }; g.flag.metric = opt('--metric'); }
|
|
1401
|
+
if (opt('--budget') !== undefined) { const b = Number(opt('--budget')); if (!Number.isFinite(b)) return { error: '--budget is a number' }; g.flag.budget = b; }
|
|
1402
|
+
} else if (has('--metric') || has('--budget')) return { error: '--metric and --budget belong to a --flag' };
|
|
1403
|
+
return g;
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1385
1406
|
function cliMain(argv) {
|
|
1386
1407
|
const opt = (k) => { const i = argv.indexOf(k); return i !== -1 && argv[i + 1] && !argv[i + 1].startsWith('--') ? argv[i + 1] : undefined; };
|
|
1387
1408
|
const [verb, target] = argv;
|
|
@@ -1389,6 +1410,7 @@ function cliMain(argv) {
|
|
|
1389
1410
|
const read = () => { try { return readLedgerSafely(ledger); } catch (e) { if (e && e.code === 'ENOENT') return ''; throw e; } };
|
|
1390
1411
|
const usage = () => {
|
|
1391
1412
|
console.log('usage: node scripts/work-item.js declare <initiative> --type <t> --blast <b> --criterion "<text>" --check <kind> --ref "<ref>" [--plan-item <id>] [--agent <who>] [--hours N]');
|
|
1413
|
+
console.log(' [--scope <path,…>] [--flag <name> [--metric <name> --budget <max>] | --no-user-facing] [--kr] (D108: what the merge guardrail reads)');
|
|
1392
1414
|
console.log(' node scripts/work-item.js verify <item> --evidence "<what passed>"');
|
|
1393
1415
|
console.log(' node scripts/work-item.js claim <item> [--agent <who>] [--hours N]');
|
|
1394
1416
|
console.log(' node scripts/work-item.js show [<initiative>] [--json]');
|
|
@@ -1410,8 +1432,10 @@ function cliMain(argv) {
|
|
|
1410
1432
|
const id = `${target}.${n}`;
|
|
1411
1433
|
const at = writerNow();
|
|
1412
1434
|
const criterion = { text: opt('--criterion') || '', check: opt('--check') || 'test', ref: opt('--ref') || '' };
|
|
1435
|
+
const guard = guardOf(argv, opt);
|
|
1436
|
+
if (guard && guard.error) { console.log(`✗ ${guard.error}`); return 2; }
|
|
1413
1437
|
const declared = { item_id: id, initiative_id: target, event: 'declared', at, type: opt('--type') || 'feature-slice', blast: opt('--blast') || 'low', criterion,
|
|
1414
|
-
...(opt('--plan-item') ? { plan_item: opt('--plan-item') } : {}) };
|
|
1438
|
+
...(opt('--plan-item') ? { plan_item: opt('--plan-item') } : {}), ...(guard ? { guard } : {}) };
|
|
1415
1439
|
if (!append(declared)) return 1;
|
|
1416
1440
|
if (argv.includes('--no-claim')) {
|
|
1417
1441
|
console.log(`✓ ${id} declared → planning/work-items.jsonl (not claimed; a Builder claims it)`);
|
|
@@ -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-16T04:26:40Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/payload/state/log.md
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# PMOS factory guardrail (D108). Copy to .github/workflows/pmos-guardrail.yml in the product repository, then make
|
|
2
|
+
# "pmos-guardrail / classify" a required check on the default branch, together with your own CI.
|
|
3
|
+
#
|
|
4
|
+
# What it does: for a pull request the PMOS factory opened (branch pmos/<item>), it reads AUTO or HUMAN from the default
|
|
5
|
+
# branch's copy of pmos/scripts/factory-guardrail.js. On AUTO it marks the pull request ready and turns on GitHub auto-merge
|
|
6
|
+
# with this workflow's own token: GitHub then merges only when every required check is green. On HUMAN it turns auto-merge
|
|
7
|
+
# off and names every reason in the run summary; a person merges. Any other pull request: nothing. To stop one merge, add the
|
|
8
|
+
# line "PMOS-Merge: human" to the pull request's description: the edit runs this check again and turns auto-merge off.
|
|
9
|
+
#
|
|
10
|
+
# Why pull_request_target: it runs THIS workflow and THE DEFAULT BRANCH'S guardrail, never the pull request's code. The head
|
|
11
|
+
# is fetched and diffed only. Do not add a step that runs, installs or builds anything from the head in this workflow.
|
|
12
|
+
#
|
|
13
|
+
# Before it can merge anything:
|
|
14
|
+
# - Settings > General > "Allow auto-merge" is on.
|
|
15
|
+
# - Branch protection (or a ruleset) on the default branch requires your CI checks. Without required checks GitHub could
|
|
16
|
+
# merge before CI runs, so leave this workflow out until they exist.
|
|
17
|
+
# - A merge made with this token does not start other workflows on the default branch (GitHub's rule). If your release
|
|
18
|
+
# runs on push to the default branch, start it from a pull_request "closed" event or give this job a GitHub App token.
|
|
19
|
+
name: pmos-guardrail
|
|
20
|
+
on:
|
|
21
|
+
pull_request_target:
|
|
22
|
+
types: [opened, synchronize, reopened, ready_for_review, edited]
|
|
23
|
+
|
|
24
|
+
permissions:
|
|
25
|
+
contents: write
|
|
26
|
+
pull-requests: write
|
|
27
|
+
|
|
28
|
+
concurrency:
|
|
29
|
+
group: pmos-guardrail-${{ github.event.pull_request.number }}
|
|
30
|
+
cancel-in-progress: true
|
|
31
|
+
|
|
32
|
+
jobs:
|
|
33
|
+
classify:
|
|
34
|
+
name: classify
|
|
35
|
+
if: startsWith(github.event.pull_request.head.ref, 'pmos/')
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
with:
|
|
40
|
+
ref: ${{ github.event.pull_request.base.sha }}
|
|
41
|
+
fetch-depth: 0
|
|
42
|
+
persist-credentials: false
|
|
43
|
+
- name: Fetch the pull request's head (diffed, never run)
|
|
44
|
+
env:
|
|
45
|
+
PR: ${{ github.event.pull_request.number }}
|
|
46
|
+
run: git fetch --no-tags origin "+refs/pull/${PR}/head:refs/remotes/pmos-pr/head"
|
|
47
|
+
- name: Guardrail
|
|
48
|
+
env:
|
|
49
|
+
GH_TOKEN: ${{ github.token }}
|
|
50
|
+
GH_REPO: ${{ github.repository }}
|
|
51
|
+
PR: ${{ github.event.pull_request.number }}
|
|
52
|
+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
|
|
53
|
+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
|
|
54
|
+
PR_BODY: ${{ github.event.pull_request.body }}
|
|
55
|
+
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
|
|
56
|
+
BASE_REPO: ${{ github.repository }}
|
|
57
|
+
run: |
|
|
58
|
+
printf '%s' "$PR_BODY" > "$RUNNER_TEMP/pmos-pr-body.txt"
|
|
59
|
+
node pmos/scripts/factory-guardrail.js --base "$BASE_SHA" --head refs/remotes/pmos-pr/head \
|
|
60
|
+
--branch "$HEAD_REF" --body-file "$RUNNER_TEMP/pmos-pr-body.txt" --head-repo "$HEAD_REPO" --base-repo "$BASE_REPO" \
|
|
61
|
+
--github --pr "$PR"
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.571.0",
|
|
4
|
+
"at": "2026-11-16T04:26:43.356Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1303,
|
|
9
|
+
"t": "The factory merges behind a guardrail, and rolls out behind a flag",
|
|
10
|
+
"s": "The factory merges behind a guardrail, and rolls out behind a flag",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"v": "0.570.0",
|
|
4
17
|
"at": "2026-11-15T17:32:20.370Z",
|
package/workspace/guide/cli.md
CHANGED
|
@@ -447,20 +447,55 @@ The Builder does these steps:
|
|
|
447
447
|
2. `pmos build claim <item>` claims one item. PMOS makes the branch `pmos/<item>` from the default branch, in a worktree outside your folder. Your own checkout does not change.
|
|
448
448
|
3. The Builder changes files in that worktree only, and runs the item's check.
|
|
449
449
|
4. `pmos build propose <item> "<what it does>" --evidence "<the check that passed>"` commits the change with the line `Work-Item: <item>`, marks the item verified, and puts "Open a draft pull request" under the initiative's ✦. Nothing is pushed yet.
|
|
450
|
-
5.
|
|
451
|
-
6.
|
|
450
|
+
5. PMOS opens the pull request by itself: it pushes only `pmos/<item>` and opens a draft pull request with `gh`. The push comes from PMOS, never from the Builder's run. Undo on the ✦ closes the pull request. When agents are off (`pmos ai off`), or the factory is back to propose-only after a revert, the proposal waits for your ✓. You can also run `pmos build open <item>` yourself.
|
|
451
|
+
6. The product's `pmos-guardrail` check decides who merges (see below). Then `pmos verify-work` marks the item integrated.
|
|
452
452
|
|
|
453
453
|
`pmos build status` lists every work item, its branch and whether its worktree is on this computer.
|
|
454
454
|
|
|
455
|
+
#### Who merges: the guardrail
|
|
456
|
+
|
|
457
|
+
PMOS never merges and the Builder holds no merge right (D108). The product repository's own check decides. Copy `pmos/templates/pmos-guardrail.yml` to `.github/workflows/`, turn on "Allow auto-merge" in the repository settings, and make your CI checks required on the default branch.
|
|
458
|
+
|
|
459
|
+
For each pull request on a `pmos/` branch, the check runs the default branch's copy of `pmos/scripts/factory-guardrail.js`. It reads the pull request's changes and never runs its code. The answer is one of these:
|
|
460
|
+
|
|
461
|
+
- **AUTO.** The item is verified in the default branch's records, every changed file is inside the item's declared scope, the change reads its flag (or the item has no user-facing effect), and no trigger fires. The check marks the pull request ready and turns on auto-merge. GitHub merges when every required check is green.
|
|
462
|
+
- **HUMAN.** The check names every reason and turns auto-merge off. You merge.
|
|
463
|
+
|
|
464
|
+
These triggers always make the answer HUMAN: migrations or data deletion; auth, permissions, payments, personal data or secrets; CI, gates, the guardrail or PMOS records; a new dependency; a public API or contract; anything sent outward; a new agent path; a changed existing test, test configuration or the item's own check; an item that failed before; a revert on the default branch in the last 14 days; a folder untouched for 90 days. When agents are switched off (`pmos ai off`) or the factory is back to propose-only after a revert, PMOS writes `PMOS-Merge: human` in the pull request, and the check reads HUMAN. To stop one merge yourself, add that line to the pull request's description. A pull request from a fork always reads HUMAN.
|
|
465
|
+
|
|
466
|
+
`pmos build policy <item>` shows the answer on this computer before the check runs.
|
|
467
|
+
|
|
468
|
+
A work item says what the guardrail reads when it is declared: `node pmos/scripts/work-item.js declare <initiative> … --scope src/login/ --flag otp_login --metric login_errors --budget 0.02`. Use `--no-user-facing` instead of a flag for a change users cannot see, and `--kr` for an item that moves a key result.
|
|
469
|
+
|
|
470
|
+
#### The flag rollout
|
|
471
|
+
|
|
472
|
+
After the merge, PMOS moves the item's flag to 5%, then 50%, then 100%. Each step holds for an hour (`hold_minutes`) and moves only while the item's metric stays inside its budget. A key-result item stops before 100% and waits for you. When the metric goes over its budget, PMOS turns the flag off, opens a revert pull request for you to merge, and puts the factory back to propose-only for 7 days.
|
|
473
|
+
|
|
474
|
+
PMOS uses your flag service through the commands in `pmos/factory.json`:
|
|
475
|
+
|
|
476
|
+
```json
|
|
477
|
+
{ "flags": { "set": "my-flags set {flag} {percent}" },
|
|
478
|
+
"metrics": { "login_errors": "node ops/login-error-rate.js" },
|
|
479
|
+
"hold_minutes": 60 }
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
`{flag}` and `{percent}` are filled in. Each metric command prints one number. With no `factory.json`, or no metric for the item, PMOS says so and moves nothing: the change merged with its flag off, and you turn it on.
|
|
483
|
+
|
|
484
|
+
- `pmos build rollout` shows where every flag stands.
|
|
485
|
+
- `pmos build rollout <item> [--to <percent>]` moves one flag yourself.
|
|
486
|
+
- `pmos build rollback <item>` turns the flag off and stops its rollout.
|
|
487
|
+
|
|
488
|
+
`pmos ai off` stops the rollout too.
|
|
489
|
+
|
|
455
490
|
The command refuses these cases:
|
|
456
491
|
|
|
457
492
|
- The repository has no git identity of its own. Set it once with `pmos git-identity set`. PMOS never guesses who commits.
|
|
458
493
|
- The change touches a PMOS record, CI or the agent rules: `pmos/`, `.github/`, `planning/initiatives/`, `CLAUDE.md`, `AGENTS.md`.
|
|
459
494
|
- `propose` without `--evidence`. The check comes before the pull request.
|
|
460
|
-
- `open` inside a role run.
|
|
495
|
+
- `open` inside a role run. PMOS or you open the pull request, never the Builder's run.
|
|
461
496
|
- `open` without `gh`. The branch is pushed, and the command tells you to open the pull request on your Git host.
|
|
462
497
|
|
|
463
|
-
PMOS never pushes to the default branch and merges
|
|
498
|
+
PMOS never pushes to the default branch and never merges. Every command takes `--json` and `--root <dir>`.
|
|
464
499
|
|
|
465
500
|
### pmos jira
|
|
466
501
|
|
|
@@ -135,7 +135,7 @@ The writer makes the record in `planning/initiatives/<id>.md` with its type, tit
|
|
|
135
135
|
**New initiative** asks for one kind of work. PMOS works out the rest from it.
|
|
136
136
|
|
|
137
137
|
- **Product.** Product management. You decide what to build and whether it worked. Engineers build it, and PMOS writes the specs.
|
|
138
|
-
- **Full SDLC.** From idea to shipped. Where a factory runs in the repository, PMOS also builds it, as pull requests
|
|
138
|
+
- **Full SDLC.** From idea to shipped. Where a factory runs in the repository, PMOS also builds it, as pull requests. The product's guardrail check merges the safe ones and leaves the rest for you. Elsewhere PMOS writes the done test and the pull request plan, and the team's agents build it. A factory runs where the repository has `planning/work-items.jsonl` and `scripts/verify-work.js`. A repository made with `create-pmos` has no factory yet.
|
|
139
139
|
- **Project.** Project management. Others do the work. PMOS chases, syncs the dates and reports.
|
|
140
140
|
|
|
141
141
|
PMOS picks a kind from the name as you type, and a blue line says so. Tap another kind to change it. After you tap a kind, PMOS does not change it. When the name gives no hint, the kind is Product.
|
|
@@ -120,7 +120,9 @@ function classOfProposal(p) {
|
|
|
120
120
|
const c = PROPOSAL_CLASS[p.group] || 'C';
|
|
121
121
|
if (p.group === 'status' && (p.items || []).some((x) => x && x.jira)) return 'C';
|
|
122
122
|
if (p.group === 'outcome' && p.type === 'refuted') return 'C';
|
|
123
|
-
|
|
123
|
+
// D108 as amended 2026-11-16 (Wawan: "Open them automatically"): the factory's pull request opens by itself, from the server (never the
|
|
124
|
+
// Builder's run), and Undo closes it. The guardrail and CI decide merge or review. `pmos ai off` or a demotion returns it to the ✓.
|
|
125
|
+
if (p.group === 'build') return 'B'; // stopping or replacing an experiment is the PM's call (launch simulation W2)
|
|
124
126
|
// a maybe, or a duplicate already in another initiative (type link, or an item with `other`), is a question for the PM, not a change
|
|
125
127
|
// found type stage moves the initiative's stage: a stage move is C (as the Driver's `move`)
|
|
126
128
|
if (p.group === 'found' && (p.type === 'stage' || p.type === 'maybe' || p.type === 'link' || (p.items || []).some((x) => x && x.other))) return 'C';
|
|
@@ -8,26 +8,33 @@
|
|
|
8
8
|
* commit, mark verified, and file "Open a draft pull request" under the ✦
|
|
9
9
|
* pmos build open <item> [--json] the PM only: push the branch and open the DRAFT pull request
|
|
10
10
|
* pmos build status [--json] every work item, its branch and whether its worktree is here
|
|
11
|
+
* pmos build policy <item> [--json] what the merge guardrail reads for it now: auto or human, and why (D108)
|
|
12
|
+
* pmos build rollout [<item> [--to <percent>]] [--json] no item: where every flag stands; an item: the PM's own next step
|
|
13
|
+
* pmos build rollback <item> [--json] undo a rollout: the item's flag to 0
|
|
11
14
|
* common: [--root <dir>]
|
|
12
15
|
*
|
|
13
|
-
* `open` is what the
|
|
14
|
-
*
|
|
16
|
+
* `open` is what the ✦ runs by itself (class B since D108 as amended 2026-11-16; Undo closes the pull request), or the ✓ when agents
|
|
17
|
+
* are off. A role run (PMOS_TEAM_RUN set) cannot run it: the push comes from PMOS, never from the Builder's own run. Nothing here merges: the product's pmos-guardrail check turns on auto-merge for a pull request it
|
|
18
|
+
* reads AUTO (D108; lib/build-engine.js mergePolicy previews it). The flag rollout runs by itself (lib/factory-rollout.js).
|
|
15
19
|
* Exit codes: 0 done, 1 refused, 2 usage.
|
|
16
20
|
*/
|
|
17
21
|
const path = require('path');
|
|
18
22
|
const { execFileSync } = require('child_process');
|
|
19
23
|
const BE = require('./build-engine.js');
|
|
20
24
|
|
|
21
|
-
const COMMANDS = { build: ['next', 'claim', 'propose', 'open', 'status'] };
|
|
25
|
+
const COMMANDS = { build: ['next', 'claim', 'propose', 'open', 'status', 'policy', 'rollout', 'rollback'] };
|
|
22
26
|
const USAGE = [
|
|
23
|
-
'usage: pmos build next|claim|propose|open|status — the Builder: PMOS builds a declared work item as a
|
|
27
|
+
'usage: pmos build next|claim|propose|open|status|policy|rollout|rollback — the Builder: PMOS builds a declared work item as a pull request',
|
|
24
28
|
' pmos build next [<initiative>] the declared work items no Builder has taken',
|
|
25
29
|
' pmos build claim <item> claim one; PMOS makes the branch pmos/<item> in a worktree outside this folder',
|
|
26
30
|
' pmos build propose <item> "<what it does>" --evidence "<the check that passed>"',
|
|
27
31
|
' commit it and file "Open a draft pull request" under the initiative\'s ✦',
|
|
28
32
|
' pmos build open <item> you only (the ✓ runs it): push pmos/<item> and open the draft pull request',
|
|
29
33
|
' pmos build status every work item and its branch',
|
|
30
|
-
'
|
|
34
|
+
' pmos build policy <item> auto or human: whether its pull request merges by itself, and why',
|
|
35
|
+
' pmos build rollout [<item> [--to <percent>]] where every flag stands; with an item, take its flag to the next step',
|
|
36
|
+
' pmos build rollback <item> turn the item\'s flag off and stop its rollout',
|
|
37
|
+
'every command: [--json] [--root <dir>]. PMOS never merges: the product\'s pmos-guardrail check turns on auto-merge, or you merge.',
|
|
31
38
|
];
|
|
32
39
|
|
|
33
40
|
function parse(argv) {
|
|
@@ -67,8 +74,28 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
|
|
|
67
74
|
for (const x of list) say(verb === 'next' ? `${x.item_id} ${x.type || ''} ${(x.criterion && x.criterion.text) || ''}` : `${x.item} ${x.state} ${x.branch}${x.here ? ' (worktree here)' : ''}`);
|
|
68
75
|
return 0;
|
|
69
76
|
}
|
|
77
|
+
if (verb === 'rollout' && !pos[0]) {
|
|
78
|
+
const list = require('./factory-rollout.js').statusOf(root);
|
|
79
|
+
if (json) return ok({ flags: list });
|
|
80
|
+
if (!list.length) { say('No flag is rolling out.'); return 0; }
|
|
81
|
+
for (const x of list) say(`${x.item} ${x.flag} ${x.percent}% ${x.step} ${x.why || ''}`);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
70
84
|
const item = pos[0];
|
|
71
85
|
if (!item) return fail(`usage: pmos build ${verb} <item>`, 2);
|
|
86
|
+
if (verb === 'policy') {
|
|
87
|
+
const it = BE.itemsOf(root).find((x) => x.item_id === item);
|
|
88
|
+
if (!it) return fail(`${item} is not a work item here`);
|
|
89
|
+
const p = BE.mergePolicy(root, it, { env });
|
|
90
|
+
return ok({ item, ...p }, `${p.verdict === 'auto' ? 'AUTO' : 'HUMAN'} ${item}: ${p.why}`);
|
|
91
|
+
}
|
|
92
|
+
if (verb === 'rollout' || verb === 'rollback') {
|
|
93
|
+
if (env.PMOS_TEAM_RUN) return fail('a role run cannot move a flag. The rollout runs by itself, and the PM moves it by hand');
|
|
94
|
+
const FR = require('./factory-rollout.js');
|
|
95
|
+
const r = verb === 'rollout' ? FR.rollout(root, item, { to: flags.to !== undefined && flags.to !== '' ? Number(flags.to) : null, env }) : FR.rollback(root, item, { env });
|
|
96
|
+
if (!r.ok) return fail(r.error);
|
|
97
|
+
return ok(r, `✓ ${r.flag} is at ${r.percent}%${verb === 'rollback' ? '. Its rollout stops until you run pmos build rollout ' + item : ''}`);
|
|
98
|
+
}
|
|
72
99
|
if (verb === 'claim') {
|
|
73
100
|
const agent = env.PMOS_TEAM_RUN ? `pmos:builder:${env.PMOS_TEAM_RUN}` : 'pmos:builder';
|
|
74
101
|
const r = BE.claim(root, item, { agent });
|
|
@@ -80,7 +107,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
|
|
|
80
107
|
if (!summary) return fail(`usage: pmos build propose ${item} "<what it does>" --evidence "<the check that passed>"`, 2);
|
|
81
108
|
const r = BE.propose(root, item, { summary, evidence: flags.evidence || '', run: env.PMOS_TEAM_RUN || null });
|
|
82
109
|
if (!r.ok) return fail(r.error);
|
|
83
|
-
return ok(r, `✓ committed ${r.commit.slice(0, 8)} (${r.files.length} ${r.files.length === 1 ? 'file' : 'files'}) and filed "Open a draft pull request" under the ✦.
|
|
110
|
+
return ok(r, `✓ committed ${r.commit.slice(0, 8)} (${r.files.length} ${r.files.length === 1 ? 'file' : 'files'}) and filed "Open a draft pull request" under the ✦. PMOS opens it by itself (with Undo); when agents are off it waits for the PM's ✓. Nothing is pushed by this run.`);
|
|
84
111
|
}
|
|
85
112
|
if (verb === 'open') {
|
|
86
113
|
const r = BE.open(root, item, { env });
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
* next(root, ini?) → [item] declared and not claimed: what a Builder may take
|
|
8
8
|
* claim(root, item, { agent }) → { ok, branch, worktree, base } | { ok: false, error }
|
|
9
9
|
* propose(root, item, { summary, evidence, run? }) → { ok, commit, files, proposal } | { ok: false, error }
|
|
10
|
-
* open(root, item, { env,
|
|
10
|
+
* open(root, item, { env, title, revert }) → { ok, pushed, url, policy } | { ok: false, pushed, error }
|
|
11
|
+
* revert(root, item, { env, why }) → { ok, branch, url } | { ok: false, error } the rollout's revert pull request (lib/factory-rollout.js)
|
|
11
12
|
* status(root) → [{ item, state, branch, worktree, here }]
|
|
12
|
-
* mergePolicy(item,
|
|
13
|
+
* mergePolicy(root, item, { env }) → { merge, verdict, why, reasons, mark } when a PR merges with no person (see MERGE POLICY)
|
|
13
14
|
* FORBIDDEN · forbiddenIn(files) · worktreeOf(root, item) · branchOf(item) · defaultBranch(root)
|
|
14
15
|
*
|
|
15
16
|
* THE STEPS, in order. Each one is a separate verb, so each refusal is its own and a test can reach it:
|
|
@@ -22,17 +23,21 @@
|
|
|
22
23
|
* (FORBIDDEN: the kit's pmos/ folder, .github/, the agent rules; D65: the factory may never write one). Then it commits
|
|
23
24
|
* with the line `Work-Item: <id>`, appends `verified` with the evidence, and FILES a class C ✦ proposal "Open a draft
|
|
24
25
|
* pull request". It pushes nothing.
|
|
25
|
-
* 3. open
|
|
26
|
+
* 3. open never the Builder's run (refused when PMOS_TEAM_RUN is set). D108 as amended 2026-11-16: the proposal is class B, so the
|
|
27
|
+
* server's ✦ applies it by itself (routes-proposals autoKeep) and Undo closes the pull request; with `pmos ai off` or a
|
|
28
|
+
* demoted factory it waits for the PM's ✓. The PM can still run `pmos build open`.
|
|
26
29
|
* It pushes the ONE branch by an explicit refspec (refs/heads/pmos/<item>, never forced) and refuses a branch that is not
|
|
27
30
|
* pmos/… or that names the default branch. Then `gh pr create --draft`. With no gh it says so and claims no PR.
|
|
28
31
|
*
|
|
29
32
|
* THE TRIFECTA, structurally (kit/AGENTS.md): a Builder run reads private code and untrusted content, so it holds no outward channel:
|
|
30
|
-
* no git push, no gh, no network tool, and open() refuses it. The one outward step
|
|
33
|
+
* no git push, no gh, no network tool, and open() refuses it. The one outward step runs in PMOS's own process (the ✦, class B since D108), never in the Builder's run.
|
|
31
34
|
*
|
|
32
|
-
* MERGE POLICY (
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
35
|
+
* MERGE POLICY (D108). Nothing here merges, and the Builder never holds a merge right. The product repository's own workflow
|
|
36
|
+
* `pmos-guardrail` (kit/templates/pmos-guardrail.yml) runs the default branch's scripts/factory-guardrail.js on each factory pull
|
|
37
|
+
* request and, on `auto`, turns on GitHub auto-merge with the workflow's token: GitHub merges when every required check is green.
|
|
38
|
+
* mergePolicy() runs the SAME classifier here, as a preview for the PM and the ✦, and adds what only this machine knows: autonomy off
|
|
39
|
+
* (`pmos ai off`, PMOS_AUTONOMY=off) or the factory demoted after a revert (D106 (5), job ai:factory). Then `mark` is true and open()
|
|
40
|
+
* writes `PMOS-Merge: human` into the pull request body, which the guardrail reads as human.
|
|
36
41
|
*/
|
|
37
42
|
const fs = require('fs');
|
|
38
43
|
const os = require('os');
|
|
@@ -41,10 +46,32 @@ const crypto = require('crypto');
|
|
|
41
46
|
const cp = require('child_process');
|
|
42
47
|
const WK = require('./work-kind.js');
|
|
43
48
|
|
|
44
|
-
const POLICY = '
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
const POLICY = 'guardrail';
|
|
50
|
+
const FACTORY_JOB = 'ai:factory';
|
|
51
|
+
/** The merge seam (D108). → { merge, verdict: 'auto'|'human', why, reasons: [{ rule, detail }], mark } */
|
|
52
|
+
function mergePolicy(root, it, { env = process.env } = {}) {
|
|
53
|
+
const human = (why, reasons = [], mark = false) => ({ merge: false, verdict: 'human', why, reasons, mark });
|
|
54
|
+
const A = require('./autonomy.js');
|
|
55
|
+
const k = A.killed({ env });
|
|
56
|
+
if (k) return human(`A person merges this pull request: ${k}.`, [{ rule: 'autonomy-off', detail: k }], true);
|
|
57
|
+
if (typeof root !== 'string' || !it || !it.item_id) return human('A person merges this pull request.');
|
|
58
|
+
const top = topOf(root) || root;
|
|
59
|
+
try {
|
|
60
|
+
const sd = require('./driver.js').stateDirOf(top, { create: false });
|
|
61
|
+
const dm = sd ? A.demotedNow(A.fold(A.read(sd)), FACTORY_JOB, null) : null;
|
|
62
|
+
if (dm) return human(`A person merges this pull request: the factory is back to propose-only until ${String(dm.until).slice(0, 10)} (${dm.why}).`, [{ rule: 'demoted', detail: dm.why }], true);
|
|
63
|
+
} catch { /* no autonomy ledger: nothing demoted */ }
|
|
64
|
+
const dir = WK.factoryDir(root);
|
|
65
|
+
const gpath = dir && path.join(dir, 'scripts', 'factory-guardrail.js');
|
|
66
|
+
if (!gpath || !fs.existsSync(gpath)) return human('A person merges this pull request: this repository\'s PMOS kit has no merge guardrail yet. Update PMOS to get it.');
|
|
67
|
+
const d = defaultBranch(root);
|
|
68
|
+
if (!d) return human('A person merges this pull request: there is no default branch to compare with.');
|
|
69
|
+
let v;
|
|
70
|
+
try { v = require(gpath).classify({ cwd: top, base: d.ref, head: 'refs/heads/' + branchOf(it.item_id), branch: branchOf(it.item_id) }); }
|
|
71
|
+
catch (e) { return human(`A person merges this pull request: the guardrail failed here (${one(e.message, 160)}).`); }
|
|
72
|
+
if (v.verdict === 'auto') return { merge: true, verdict: 'auto', reasons: [], mark: false,
|
|
73
|
+
why: 'The guardrail reads AUTO: once every required check is green, the product\'s pmos-guardrail check turns on auto-merge. The change reaches users only through its flag.' };
|
|
74
|
+
return human(`A person merges this pull request (the guardrail reads HUMAN): ${v.reasons.map((r) => r.detail).join('; ')}.`, v.reasons);
|
|
48
75
|
}
|
|
49
76
|
|
|
50
77
|
/* What a factory commit may not touch (D65: the factory never writes a control-graph record). Lower case; a folder ends in "/".
|
|
@@ -164,13 +191,13 @@ function hasGh(env) {
|
|
|
164
191
|
}
|
|
165
192
|
|
|
166
193
|
/** The outward step. Only the PM: the ✓ or the PM's own command. */
|
|
167
|
-
function open(root, item, { env = process.env, title = '' } = {}) {
|
|
194
|
+
function open(root, item, { env = process.env, title = '', revert = null } = {}) {
|
|
168
195
|
if (env.PMOS_TEAM_RUN) return { ok: false, pushed: false, error: 'a role run cannot open a pull request. It waits for the PM\'s ✓ under the ✦' };
|
|
169
196
|
const it = itemOf(root, item);
|
|
170
197
|
if (!it) return { ok: false, pushed: false, error: `${item} is not a work item here` };
|
|
171
|
-
if (it.state !== 'verified') return { ok: false, pushed: false, error: `${item} is ${it.state}; only a verified item gets a pull request` };
|
|
198
|
+
if (!revert && it.state !== 'verified') return { ok: false, pushed: false, error: `${item} is ${it.state}; only a verified item gets a pull request` };
|
|
172
199
|
const d = defaultBranch(root);
|
|
173
|
-
const branch = branchOf(item);
|
|
200
|
+
const branch = revert ? revertBranchOf(item) : branchOf(item);
|
|
174
201
|
if (!d) return { ok: false, pushed: false, error: 'this repository has no default branch' };
|
|
175
202
|
if (!branch.startsWith('pmos/') || branch === d.name || branch.replace(/^refs\/heads\//, '') === d.name) return { ok: false, pushed: false, error: `PMOS never pushes to ${d.name}` };
|
|
176
203
|
if (!git(root, ['rev-parse', '--verify', '--quiet', 'refs/heads/' + branch]).ok) return { ok: false, pushed: false, error: `there is no branch ${branch}` };
|
|
@@ -178,20 +205,63 @@ function open(root, item, { env = process.env, title = '' } = {}) {
|
|
|
178
205
|
const login = require('./git-identity.js').pushLogin(top);
|
|
179
206
|
const p = git(top, ['push', 'origin', `refs/heads/${branch}:refs/heads/${branch}`]);
|
|
180
207
|
if (!p.ok) return { ok: false, pushed: false, error: `the push of ${branch} failed: ${one(p.err, 300)}` };
|
|
181
|
-
const policy = mergePolicy(it, {});
|
|
208
|
+
const policy = revert ? { merge: false, verdict: 'human', why: 'A person merges this revert. Its flag is already off.', reasons: [], mark: true } : mergePolicy(root, it, { env });
|
|
182
209
|
let ghEnv = { ...env };
|
|
183
210
|
if (login) { const t = cp.spawnSync('gh', ['auth', 'token', '--user', login], { encoding: 'utf8', env }); if (t.status === 0 && String(t.stdout).trim()) ghEnv = { ...ghEnv, GH_TOKEN: String(t.stdout).trim() }; }
|
|
184
211
|
if (!hasGh(ghEnv)) return { ok: false, pushed: true, policy, error: `${branch} is pushed, but gh is not installed here, so no pull request was opened. Open a draft pull request from ${branch} into ${d.name} on your Git host` };
|
|
185
212
|
const it2 = itemOf(root, item);
|
|
186
|
-
const body =
|
|
187
|
-
|
|
213
|
+
const body = (revert
|
|
214
|
+
? [`PMOS reverts work item ${item}: ${revert.why}.`, '', policy.why, '', 'PMOS-Merge: human', `Work-Item: ${item}`]
|
|
215
|
+
: [`PMOS built work item ${item}.`, '', it2 && it2.evidence ? `Check that passed: ${it2.evidence}` : '', '', policy.why, '', ...(policy.mark ? ['PMOS-Merge: human'] : []), `Work-Item: ${item}`])
|
|
216
|
+
.filter((x, i, a) => x || a[i - 1]).join('\n');
|
|
217
|
+
const r = cp.spawnSync('gh', ['pr', 'create', ...(revert ? [] : ['--draft']), '--base', d.name, '--head', branch, '--title', one(title || (revert ? `Revert ${item}` : `PMOS: ${item}`), 120), '--body', body], { cwd: top, encoding: 'utf8', env: ghEnv });
|
|
188
218
|
if (r.error || r.status !== 0) return { ok: false, pushed: true, policy, error: `${branch} is pushed, but gh could not open the pull request: ${one(r.stderr || (r.error && r.error.message), 300)}` };
|
|
189
219
|
const url = (String(r.stdout).match(/https?:\/\/\S+/) || [''])[0];
|
|
190
220
|
return { ok: true, pushed: true, url, branch, base: d.name, policy };
|
|
191
221
|
}
|
|
192
222
|
|
|
223
|
+
const revertBranchOf = (item) => 'pmos/revert-' + item;
|
|
224
|
+
|
|
225
|
+
/** The rollout's breach (lib/factory-rollout.js): revert the merged change on pmos/revert-<item> and open a pull request through open().
|
|
226
|
+
* It reads the default branch as this checkout last fetched it (the PM's sync fetches); it fetches nothing itself. */
|
|
227
|
+
function revert(root, item, { env = process.env, why = 'its guard metric left its budget' } = {}) {
|
|
228
|
+
if (env.PMOS_TEAM_RUN) return { ok: false, error: 'a role run cannot revert' };
|
|
229
|
+
const it = itemOf(root, item);
|
|
230
|
+
if (!it) return { ok: false, error: `${item} is not a work item here` };
|
|
231
|
+
const d = defaultBranch(root);
|
|
232
|
+
if (!d) return { ok: false, error: 'this repository has no default branch' };
|
|
233
|
+
const top = topOf(root) || root;
|
|
234
|
+
const hit = git(top, ['log', '--format=%H %P', '-E', `--grep=^Work-Item: ${item.replace(/\./g, '\\.')}$`, d.ref]).out.split('\n').filter(Boolean);
|
|
235
|
+
if (!hit.length) return { ok: false, error: `no commit on ${d.name} carries Work-Item: ${item}` };
|
|
236
|
+
// the newest commit naming the item: a merge commit reverts against its first parent; a squash merge is one commit
|
|
237
|
+
const [sha, ...parents] = hit[0].split(' ');
|
|
238
|
+
const id = require('./git-identity.js').localIdentity(top);
|
|
239
|
+
if (!id.name || !id.email) return { ok: false, error: 'this repository has no git identity of its own, and PMOS never guesses who commits' };
|
|
240
|
+
const branch = revertBranchOf(item), wt = worktreeOf(root, 'revert-' + item);
|
|
241
|
+
if (fs.existsSync(wt)) return { ok: false, error: `${wt} already exists` };
|
|
242
|
+
fs.mkdirSync(path.dirname(wt), { recursive: true });
|
|
243
|
+
const w = git(top, ['worktree', 'add', '-b', branch, wt, d.ref]);
|
|
244
|
+
if (!w.ok) return { ok: false, error: `the revert worktree could not be made: ${one(w.err, 300)}` };
|
|
245
|
+
const r = git(wt, ['-c', `user.name=${id.name}`, '-c', `user.email=${id.email}`, 'revert', '--no-edit', ...(parents.length > 1 ? ['-m', '1'] : []), sha]);
|
|
246
|
+
if (!r.ok) return { ok: false, error: `git could not revert ${sha.slice(0, 8)}: ${one(r.err, 300)}` };
|
|
247
|
+
const o = open(root, item, { env, revert: { why } });
|
|
248
|
+
return o.ok ? { ok: true, branch, url: o.url } : { ok: false, branch, error: o.error };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Undo of an opened pull request (D108): close it with gh, comment why, leave the branch. → { ok } | { ok: false, error } */
|
|
252
|
+
function close(root, item, { url = '', env = process.env } = {}) {
|
|
253
|
+
if (env.PMOS_TEAM_RUN) return { ok: false, error: 'a role run cannot close a pull request' };
|
|
254
|
+
const target = /^https?:\/\/\S+$/.test(String(url || '')) ? url : branchOf(item);
|
|
255
|
+
const top = topOf(root) || root;
|
|
256
|
+
const login = require('./git-identity.js').pushLogin(top);
|
|
257
|
+
let ghEnv = { ...env };
|
|
258
|
+
if (login) { const t = cp.spawnSync('gh', ['auth', 'token', '--user', login], { encoding: 'utf8', env }); if (t.status === 0 && String(t.stdout).trim()) ghEnv = { ...ghEnv, GH_TOKEN: String(t.stdout).trim() }; }
|
|
259
|
+
const r = cp.spawnSync('gh', ['pr', 'close', target, '--comment', 'Closed by Undo in PMOS.'], { cwd: top, encoding: 'utf8', env: ghEnv });
|
|
260
|
+
return r.error || r.status !== 0 ? { ok: false, error: one(r.stderr || (r.error && r.error.message) || 'gh could not close it', 300) } : { ok: true };
|
|
261
|
+
}
|
|
262
|
+
|
|
193
263
|
function status(root) {
|
|
194
264
|
return itemsOf(root).map((x) => { const wt = worktreeOf(root, x.item_id); return { item: x.item_id, state: x.state, branch: branchOf(x.item_id), worktree: wt, here: fs.existsSync(wt) }; });
|
|
195
265
|
}
|
|
196
266
|
|
|
197
|
-
module.exports = { POLICY, FORBIDDEN, mergePolicy, forbiddenIn, branchOf, worktreeOf, defaultBranch, itemsOf, next, claim, propose, open, status };
|
|
267
|
+
module.exports = { POLICY, FACTORY_JOB, FORBIDDEN, mergePolicy, forbiddenIn, branchOf, revertBranchOf, worktreeOf, defaultBranch, itemsOf, next, claim, propose, open, revert, close, status };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* factory-rollout.js — a merged factory change reaches users through its flag, 5% → 50% → 100%, and rolls itself back (D108,
|
|
3
|
+
* initiative factory-guardrail-merge, done test G5). No model.
|
|
4
|
+
*
|
|
5
|
+
* tick(root, { now, env }) → { acted: [{ item, step, percent, why }], why? } what the server's verify tick runs for each product
|
|
6
|
+
* rollout(root, item, { to, now, env, by }) → { ok, percent } | { ok: false, error } the PM's own flip (`pmos build rollout`)
|
|
7
|
+
* rollback(root, item, { now, env, by }) → { ok } | { ok: false, error } undo: the flag to 0 (`pmos build rollback`)
|
|
8
|
+
* statusOf(root) → [{ item, flag, percent, step, at, why }]
|
|
9
|
+
* configOf(root) → { set, get?, metrics, hold_minutes } | null
|
|
10
|
+
*
|
|
11
|
+
* THE PROVIDER is the PM's: `<kit>/factory.json` (pmos/factory.json in a product repository) names the commands, so PMOS holds no
|
|
12
|
+
* flag service key and runs nothing the PM did not write there:
|
|
13
|
+
* { "flags": { "set": "my-flags set {flag} {percent}" }, {flag} and {percent} are filled in; nothing else is
|
|
14
|
+
* "metrics": { "login_errors": "node ops/login-error-rate.js" }, each prints one number
|
|
15
|
+
* "hold_minutes": 60 } how long each step holds before the next (default 60)
|
|
16
|
+
* A work item names its flag and metric when it is declared: `work-item.js declare … --flag otp_login --metric login_errors --budget 0.02`.
|
|
17
|
+
*
|
|
18
|
+
* THE RULES, per merged (integrated) item with a flag:
|
|
19
|
+
* - autonomy off (`pmos ai off`, PMOS_AUTONOMY=off): nothing moves.
|
|
20
|
+
* - no provider, or no metric for the item: PMOS says so once (`wait-pm`). The change merged default-off; the PM flips the flag.
|
|
21
|
+
* - the metric is read before every step. Above its budget: BREACH. The flag goes to 0, a revert pull request is opened
|
|
22
|
+
* (lib/build-engine.js revert, the PM's own push path), and the autonomy ledger records a revert: the factory is back to
|
|
23
|
+
* propose-only for 7 days (D106 (5)), so open() writes `PMOS-Merge: human` and the guardrail reads human.
|
|
24
|
+
* - inside budget and the step has held hold_minutes: the next step. A key-result item (`--kr`) stops before 100% (`wait-pm`).
|
|
25
|
+
* - a metric that cannot be read holds the step; it never advances on a missing number.
|
|
26
|
+
* Every step is one line in <state>/factory-rollout.jsonl; `pmos build rollback` sets the flag to 0 and records it.
|
|
27
|
+
*/
|
|
28
|
+
const fs = require('fs');
|
|
29
|
+
const path = require('path');
|
|
30
|
+
const cp = require('child_process');
|
|
31
|
+
const WK = require('./work-kind.js');
|
|
32
|
+
|
|
33
|
+
const STEPS = Object.freeze([5, 50, 100]);
|
|
34
|
+
const JOB = 'ai:factory';
|
|
35
|
+
const OPEN_JOB = 'propose:build'; // the ✦ job that opens the factory's pull request by itself (D108 as amended 2026-11-16)
|
|
36
|
+
const LEDGER = 'factory-rollout.jsonl';
|
|
37
|
+
const FLAG_RE = /^[A-Za-z0-9_.:-]{2,80}$/;
|
|
38
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
39
|
+
|
|
40
|
+
function configOf(root) {
|
|
41
|
+
const dir = WK.factoryDir(root);
|
|
42
|
+
if (!dir) return null;
|
|
43
|
+
let j;
|
|
44
|
+
try { j = JSON.parse(fs.readFileSync(path.join(dir, 'factory.json'), 'utf8')); } catch { return null; }
|
|
45
|
+
const set = j && j.flags && typeof j.flags.set === 'string' && j.flags.set.includes('{flag}') && j.flags.set.includes('{percent}') ? j.flags.set : null;
|
|
46
|
+
if (!set) return null;
|
|
47
|
+
const metrics = j.metrics && typeof j.metrics === 'object' ? Object.fromEntries(Object.entries(j.metrics).filter(([, v]) => typeof v === 'string' && v.trim())) : {};
|
|
48
|
+
const hold = Number(j.hold_minutes);
|
|
49
|
+
return { set, metrics, hold_minutes: Number.isFinite(hold) && hold >= 0 ? hold : 60, dir };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function stateDir(root) {
|
|
53
|
+
const top = topOf(root) || root;
|
|
54
|
+
return require('./driver.js').stateDirOf(top, { create: true });
|
|
55
|
+
}
|
|
56
|
+
function topOf(root) {
|
|
57
|
+
const r = cp.spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd: root, encoding: 'utf8' });
|
|
58
|
+
return r.status === 0 ? String(r.stdout).trim() : null;
|
|
59
|
+
}
|
|
60
|
+
function lines(root) {
|
|
61
|
+
const d = stateDir(root);
|
|
62
|
+
if (!d) return [];
|
|
63
|
+
let t = '';
|
|
64
|
+
try { t = fs.readFileSync(path.join(d, LEDGER), 'utf8'); } catch { return []; }
|
|
65
|
+
return t.split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
|
66
|
+
}
|
|
67
|
+
function log(root, line, now) {
|
|
68
|
+
const d = stateDir(root);
|
|
69
|
+
if (!d) return line;
|
|
70
|
+
const full = { at: new Date(now == null ? Date.now() : now).toISOString(), ...line };
|
|
71
|
+
fs.appendFileSync(path.join(d, LEDGER), JSON.stringify(full) + '\n');
|
|
72
|
+
return full;
|
|
73
|
+
}
|
|
74
|
+
/** The newest line per item. */
|
|
75
|
+
function lastOf(root) {
|
|
76
|
+
const m = new Map();
|
|
77
|
+
for (const l of lines(root)) if (l.item) m.set(l.item, l);
|
|
78
|
+
return m;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Run one of the PM's commands. Placeholders are filled from checked values only. → { ok, out } */
|
|
82
|
+
function sh(cmd, cwd, env) {
|
|
83
|
+
const r = cp.spawnSync('sh', ['-c', cmd], { cwd, encoding: 'utf8', timeout: 60000, env });
|
|
84
|
+
return { ok: !r.error && r.status === 0, out: one(r.stdout, 300), err: one(r.stderr || (r.error && r.error.message), 300) };
|
|
85
|
+
}
|
|
86
|
+
function setFlag(cfg, flag, percent, env) {
|
|
87
|
+
if (!FLAG_RE.test(flag) || !Number.isInteger(percent) || percent < 0 || percent > 100) return { ok: false, err: 'refused: a flag name or a percent that is not plain' };
|
|
88
|
+
return sh(cfg.set.split('{flag}').join(flag).split('{percent}').join(String(percent)), cfg.dir, env);
|
|
89
|
+
}
|
|
90
|
+
function readMetric(cfg, name, env) {
|
|
91
|
+
const cmd = cfg.metrics[name];
|
|
92
|
+
if (!cmd) return { ok: false, err: `no metric "${name}" in factory.json` };
|
|
93
|
+
const r = sh(cmd, cfg.dir, env);
|
|
94
|
+
const v = r.ok ? Number((r.out.match(/-?[0-9]+(\.[0-9]+)?(e-?[0-9]+)?/i) || [])[0]) : NaN;
|
|
95
|
+
return Number.isFinite(v) ? { ok: true, value: v } : { ok: false, err: r.ok ? `"${name}" printed no number` : `"${name}" failed: ${r.err}` };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function flagged(root) {
|
|
99
|
+
return require('./build-engine.js').itemsOf(root).filter((x) => x.guard && x.guard.flag && x.guard.flag.name && x.state === 'integrated');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function tick(root, { now = Date.now(), env = process.env } = {}) {
|
|
103
|
+
const A = require('./autonomy.js');
|
|
104
|
+
const k = A.killed({ env });
|
|
105
|
+
if (k) return { acted: [], why: k };
|
|
106
|
+
const items = flagged(root);
|
|
107
|
+
if (!items.length) return { acted: [] };
|
|
108
|
+
const cfg = configOf(root);
|
|
109
|
+
const last = lastOf(root);
|
|
110
|
+
const acted = [];
|
|
111
|
+
const say = (line) => { const l = log(root, line, now); acted.push(l); return l; };
|
|
112
|
+
for (const it of items) {
|
|
113
|
+
const f = it.guard.flag, prev = last.get(it.item_id) || null;
|
|
114
|
+
const percent = prev ? Number(prev.percent) || 0 : 0;
|
|
115
|
+
if (prev && ['breach', 'rollback', 'error'].includes(prev.step)) continue; // stopped: only the PM moves it again
|
|
116
|
+
if (percent >= 100) continue;
|
|
117
|
+
if (!cfg) {
|
|
118
|
+
if (!prev || prev.step !== 'wait-pm') say({ item: it.item_id, flag: f.name, percent, step: 'wait-pm', why: `No flag provider is set in pmos/factory.json, so PMOS cannot roll ${f.name} out. The change merged with the flag off; turn it on when you choose` });
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (!f.metric || !cfg.metrics[f.metric] || !Number.isFinite(Number(f.budget))) {
|
|
122
|
+
if (!prev || prev.step !== 'wait-pm') say({ item: it.item_id, flag: f.name, percent, step: 'wait-pm', why: `${it.item_id} names no guard metric with a budget that factory.json can read, so PMOS does not roll ${f.name} out by itself. The flag stays off; turn it on when you choose` });
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const m = readMetric(cfg, f.metric, env);
|
|
126
|
+
if (!m.ok) { if (!prev || prev.why !== m.err) say({ item: it.item_id, flag: f.name, percent, step: 'hold', why: `the step holds: ${m.err}` }); continue; }
|
|
127
|
+
if (m.value > Number(f.budget)) {
|
|
128
|
+
const s = setFlag(cfg, f.name, 0, env);
|
|
129
|
+
const rv = require('./build-engine.js').revert(root, it.item_id, { env, why: `${f.metric} read ${m.value}, above its budget ${f.budget}` });
|
|
130
|
+
const sd = stateDir(root);
|
|
131
|
+
const sb = sd ? A.recordSetback(sd, { job: JOB, product: null, ref: it.item_id, kind: 'revert' }, { now }) : { demoted: null };
|
|
132
|
+
// the factory's pull requests stop opening by themselves too (they wait for the PM's ✓ again)
|
|
133
|
+
if (sd) A.recordSetback(sd, { job: OPEN_JOB, product: null, ref: it.item_id, kind: 'revert' }, { now });
|
|
134
|
+
say({ item: it.item_id, flag: f.name, percent: s.ok ? 0 : percent, from: percent, step: 'breach', value: m.value, budget: Number(f.budget),
|
|
135
|
+
why: `${f.metric} read ${m.value}, above its budget ${f.budget}. ${s.ok ? `${f.name} is off` : `Turning ${f.name} off FAILED (${s.err}); turn it off now`}. ${rv.ok ? `Revert pull request: ${rv.url || rv.branch}` : `No revert pull request: ${rv.error}`}. ${sb.demoted ? 'The factory is back to propose-only until ' + sb.demoted.until.slice(0, 10) : 'Recorded as a revert'}.`,
|
|
136
|
+
...(rv.ok && rv.url ? { revert: rv.url } : {}) });
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const nextP = STEPS.find((p) => p > percent);
|
|
140
|
+
if (nextP === 100 && it.guard.kr) {
|
|
141
|
+
if (!prev || prev.step !== 'wait-pm') say({ item: it.item_id, flag: f.name, percent, step: 'wait-pm', value: m.value, why: `${it.item_id} moves a key result, so ${f.name} stays at ${percent}% until you take it to 100% (pmos build rollout ${it.item_id} --to 100)` });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (prev && percent > 0 && now - Date.parse(prev.at) < cfg.hold_minutes * 60000) continue;
|
|
145
|
+
const s = setFlag(cfg, f.name, nextP, env);
|
|
146
|
+
if (!s.ok) { say({ item: it.item_id, flag: f.name, percent, step: 'error', why: `the provider refused ${f.name} at ${nextP}%: ${s.err}. The rollout stops here` }); continue; }
|
|
147
|
+
say({ item: it.item_id, flag: f.name, percent: nextP, from: percent, step: 'set', value: m.value, budget: Number(f.budget), by: 'pmos', why: `${f.metric} read ${m.value} (budget ${f.budget}); ${f.name} ${percent}% → ${nextP}%` });
|
|
148
|
+
}
|
|
149
|
+
return { acted };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function itemFlag(root, item) {
|
|
153
|
+
const it = require('./build-engine.js').itemsOf(root).find((x) => x.item_id === item);
|
|
154
|
+
if (!it) return { error: `${item} is not a work item here` };
|
|
155
|
+
if (!it.guard || !it.guard.flag || !it.guard.flag.name) return { error: `${item} declares no flag` };
|
|
156
|
+
return { it, flag: it.guard.flag.name };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function rollout(root, item, { to = null, now = Date.now(), env = process.env, by = 'pm' } = {}) {
|
|
160
|
+
const f = itemFlag(root, item);
|
|
161
|
+
if (f.error) return { ok: false, error: f.error };
|
|
162
|
+
const cfg = configOf(root);
|
|
163
|
+
if (!cfg) return { ok: false, error: 'no flag provider is set in pmos/factory.json; turn the flag on in your flag service' };
|
|
164
|
+
const prev = lastOf(root).get(item);
|
|
165
|
+
const percent = prev ? Number(prev.percent) || 0 : 0;
|
|
166
|
+
const target = to == null ? STEPS.find((p) => p > percent) : Number(to);
|
|
167
|
+
if (!Number.isInteger(target) || target < 0 || target > 100) return { ok: false, error: 'the percent is a whole number from 0 to 100' };
|
|
168
|
+
const s = setFlag(cfg, f.flag, target, env);
|
|
169
|
+
if (!s.ok) return { ok: false, error: `the provider refused: ${s.err}` };
|
|
170
|
+
log(root, { item, flag: f.flag, percent: target, from: percent, step: 'set', by, why: `${f.flag} ${percent}% → ${target}% by ${by}` }, now);
|
|
171
|
+
return { ok: true, item, flag: f.flag, percent: target };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function rollback(root, item, { now = Date.now(), env = process.env, by = 'pm' } = {}) {
|
|
175
|
+
const f = itemFlag(root, item);
|
|
176
|
+
if (f.error) return { ok: false, error: f.error };
|
|
177
|
+
const cfg = configOf(root);
|
|
178
|
+
if (!cfg) return { ok: false, error: 'no flag provider is set in pmos/factory.json; turn the flag off in your flag service' };
|
|
179
|
+
const prev = lastOf(root).get(item);
|
|
180
|
+
const s = setFlag(cfg, f.flag, 0, env);
|
|
181
|
+
if (!s.ok) return { ok: false, error: `the provider refused: ${s.err}` };
|
|
182
|
+
log(root, { item, flag: f.flag, percent: 0, from: prev ? Number(prev.percent) || 0 : 0, step: 'rollback', by, why: `${f.flag} rolled back to 0% by ${by}; the rollout stops until you run pmos build rollout ${item}` }, now);
|
|
183
|
+
return { ok: true, item, flag: f.flag, percent: 0 };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function statusOf(root) {
|
|
187
|
+
return [...lastOf(root).values()].map((l) => ({ item: l.item, flag: l.flag, percent: Number(l.percent) || 0, step: l.step, at: l.at, why: l.why }));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
module.exports = { STEPS, JOB, LEDGER, configOf, tick, rollout, rollback, statusOf };
|
|
@@ -35,7 +35,7 @@ const VERBS = Object.freeze({
|
|
|
35
35
|
help: 'pmos verify-work — mark work items integrated from the default branch (local refs only)' }),
|
|
36
36
|
// Not a pm-os-absorb verb (run: null): launch simulation W7 (kit-factory-builder) added it through the same table.
|
|
37
37
|
build: Object.freeze({ module: 'build-cli.js', run: null, guide: 'cli.md',
|
|
38
|
-
help: 'pmos build next|claim|propose|open|status — the Builder: a declared work item becomes a
|
|
38
|
+
help: 'pmos build next|claim|propose|open|status|policy|rollout|rollback — the Builder: a declared work item becomes a pull request; the product\'s guardrail decides who merges (pmos build help)' }),
|
|
39
39
|
report: Object.freeze({ module: 'report-cli.js', run: 5, guide: 'cli.md',
|
|
40
40
|
help: 'pmos report draft|issue|list … — draft and issue reports (pmos report help)' }),
|
|
41
41
|
// Not a pm-os-absorb verb (run: null): initiative jira-wbs added it through the same table.
|
|
@@ -118,7 +118,7 @@ function undoCore(ctx, p, g, id) {
|
|
|
118
118
|
else if (w.op === 'life') { const r2 = require('./outcomes.js').setLife(p.w.root, k.ini, w.from === 'cancelled' ? 'cancelled' : 'active', 'Undo: PMOS ✦ stopped it', g.actor); if (r2.ok) back++; else kept++; continue; }
|
|
119
119
|
// a new experiment the ✦ made goes from every list (the Board's own Delete: the record file stays, a restore brings it back)
|
|
120
120
|
else if (w.op === 'created') { r = RB.writeAs(ctx, '/api/boards/ini-delete', { ws: p.w.id, board: p.board.id, id: w.id }, g); }
|
|
121
|
-
else if (w.op === 'pr') {
|
|
121
|
+
else if (w.op === 'pr') { const r2 = require('./build-engine.js').close(p.w.root, w.item, { url: w.url }); if (r2.ok) back++; else kept++; continue; } // D108: Undo closes the pull request (the branch stays)
|
|
122
122
|
else if (w.op === 'outcome') { const r2 = require('./initiative-writer.js').restoreOutcome(p.w.root, k.ini, w.from || {}, w.to || {}, { actor: g.actor }); if (r2.ok && !r2.kept) back++; else kept++; continue; } // a record edited since keeps its edit
|
|
123
123
|
if (r && r.body && r.body.ok) back++; else kept++;
|
|
124
124
|
}
|
|
@@ -77,7 +77,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
|
|
|
77
77
|
say(` owns: ${r.what}`);
|
|
78
78
|
if (r.owns.paths.length || r.owns.verbs.length) say(` writes only: ${[...r.owns.paths, ...r.owns.verbs].join(', ')}`);
|
|
79
79
|
say(` wakes on: ${r.triggers.map((x) => (x.on === 'stage' ? `stage ${x.stage}${x.unless ? ' without ' + x.unless : ''}` : x.on === 'written' ? 'a write by another role' : 'a dispatch')).join(', ')}`);
|
|
80
|
-
if (r.key === 'build') say(` here: ${factory ? 'the factory runs in this repository. The Builder
|
|
80
|
+
if (r.key === 'build') say(` here: ${factory ? 'the factory runs in this repository. The Builder\'s pull requests open by themselves (pmos build); the product\'s guardrail decides who merges.' : 'no factory runs in this repository, so the Builder does not run. The team\'s agents build from the done test and the pull request plan PMOS writes.'}`);
|
|
81
81
|
}
|
|
82
82
|
return 0;
|
|
83
83
|
}
|
|
@@ -170,9 +170,25 @@ function create(deps) {
|
|
|
170
170
|
return null;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
/* D108: in a product repository that carries the kit's factory, mark merged work items integrated, then move each flag one rollout
|
|
174
|
+
* step (lib/factory-rollout.js; no model, the PM's own provider commands). PMOS-self's checkout runs verify-work below. */
|
|
175
|
+
function factory(now) {
|
|
176
|
+
const out = [];
|
|
177
|
+
if (deps.factory === false) return out;
|
|
178
|
+
const WK = require('./work-kind.js');
|
|
179
|
+
for (const w of (deps.roots && deps.roots()) || []) {
|
|
180
|
+
const fdir = w && w.root ? WK.factoryDir(w.root) : null;
|
|
181
|
+
if (!fdir) continue;
|
|
182
|
+
if (!isCheckout(w.root)) { try { run(fdir, ['scripts/verify-work.js', '--json']); } catch (e) { warn('verify-work', e); } }
|
|
183
|
+
try { out.push(...require('./factory-rollout.js').tick(w.root, { now, env: deps.env || process.env }).acted); } catch (e) { warn('rollout', e); }
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
|
|
173
188
|
function tick({ now = Date.now() } = {}) {
|
|
174
189
|
if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { off: true };
|
|
175
|
-
|
|
190
|
+
const rolled = factory(now);
|
|
191
|
+
if (active) return { running: active.run_id, ...(rolled.length ? { rolled } : {}) };
|
|
176
192
|
let open = true;
|
|
177
193
|
try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
|
|
178
194
|
if (!open) return { started: null, closed: true };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.571.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.571.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -121,7 +121,7 @@ function itemHtml(p, x) {
|
|
|
121
121
|
else if (p.group === 'status') { t = x.title || taskTitle(p.ini, x.task); m = x.jira ? 'Jira: a drafted comment' : ''; }
|
|
122
122
|
else if (p.group === 'outcome') { t = x.title; m = x.due ? 'Check on ' + md(x.due) : ''; }
|
|
123
123
|
else if (p.group === 'description') { t = (p.data && p.data.text) || x.title; m = p.type === 'enrich' && p.data && p.data.from ? 'Now: ' + clip(p.data.from, 120) : ''; }
|
|
124
|
-
else if (p.group === 'build') { const d = p.data || {}; t = x.title; m = [d.branch ? d.branch + ' → ' + (d.base || 'main') : '', d.files && d.files.length ? (d.files.length === 1 ? '1 file' : d.files.length + ' files') : '', '
|
|
124
|
+
else if (p.group === 'build') { const d = p.data || {}; t = x.title; m = [d.branch ? d.branch + ' → ' + (d.base || 'main') : '', d.files && d.files.length ? (d.files.length === 1 ? '1 file' : d.files.length + ' files') : '', 'the guardrail decides who merges'].filter(Boolean).join(' · '); }
|
|
125
125
|
else if (p.group === 'names') { t = x.to; m = 'Was: ' + (x.from || '') + (x.jira ? ' · Jira: a drafted comment' : ''); }
|
|
126
126
|
return `<div class="pp-it"><span class="w"><b>${esc(clip(t, p.group === 'description' ? 700 : 90))}</b>${m ? `<small>${esc(m)}</small>` : ''}</span>${x.sig ? ib(`data-pp-dropit="${esc(x.sig)}"`, 'Leave this one out', I.x) : ''}</div>`;
|
|
127
127
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_comment": "Launch simulation W7 (kit-factory-builder): the D65 factory in a product repository. One sandbox run against a kit built by kit/build-kit.sh and a local bare remote: vendoring (F1), the kit (F2), the Builder's claim, propose,
|
|
2
|
+
"_comment": "Launch simulation W7 (kit-factory-builder): the D65 factory in a product repository. One sandbox run against a kit built by kit/build-kit.sh and a local bare remote: vendoring (F1), the kit (F2), the Builder's claim, propose, \u2726 and draft PR (F3), verify-work (F4). No browser, no network. D108 (factory-guardrail-merge): the merge guardrail, one case per rule (factory-guardrail.test.js), and G1\u2013G6 in the same sandbox.",
|
|
3
3
|
"modules": [
|
|
4
|
-
"build-engine.test.js"
|
|
4
|
+
"build-engine.test.js",
|
|
5
|
+
"factory-guardrail.test.js"
|
|
5
6
|
],
|
|
6
7
|
"seconds": {
|
|
7
|
-
"build-engine.test.js":
|
|
8
|
+
"build-engine.test.js": 8,
|
|
9
|
+
"factory-guardrail.test.js": 3
|
|
8
10
|
}
|
|
9
11
|
}
|