create-pmos 0.554.0 → 0.555.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.554.0",
3
+ "version": "0.555.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.555.0",
38
+ "at": "2026-11-11T00:11:34.194Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1284,
43
+ "t": "PMOS writes the first story, says why it acted quietly, and a verifier FAIL or revert sends a job back to asking",
44
+ "s": "PMOS writes the first story, says why it acted quietly, and a verifier FAIL or revert sends a job back to asking",
45
+ "k": "new"
46
+ }
47
+ ]
48
+ },
36
49
  {
37
50
  "v": "0.554.0",
38
51
  "at": "2026-11-10T22:52:00.722Z",
@@ -357,19 +370,6 @@
357
370
  "k": "new"
358
371
  }
359
372
  ]
360
- },
361
- {
362
- "v": "0.535.0",
363
- "at": "2026-11-05T09:07:13.086Z",
364
- "f": 4,
365
- "prs": [
366
- {
367
- "n": 1251,
368
- "t": "Calmer Settings › Connectors, one list with trouble first",
369
- "s": "Calmer Settings › Connectors, one list with trouble first",
370
- "k": "new"
371
- }
372
- ]
373
373
  }
374
374
  ]
375
375
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@c2106e9a
2
- assembled: 2026-11-10
1
+ kernel-source: pmos@565ff904
2
+ assembled: 2026-11-11
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-10T22:51:57Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-11T00:11:30Z"}
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-10T22:51:57Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-11T00:11:30Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-10T22:51:57Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-11T00:11:30Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  Newest first, ISO dates.
4
4
 
5
- ## 2026-11-10
5
+ ## 2026-11-11
6
6
 
7
7
  - Adopted OKF v0.2 (D73).
@@ -1,4 +1,17 @@
1
1
  [
2
+ {
3
+ "v": "0.555.0",
4
+ "at": "2026-11-11T00:11:34.194Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1284,
9
+ "t": "PMOS writes the first story, says why it acted quietly, and a verifier FAIL or revert sends a job back to asking",
10
+ "s": "PMOS writes the first story, says why it acted quietly, and a verifier FAIL or revert sends a job back to asking",
11
+ "k": "new"
12
+ }
13
+ ]
14
+ },
2
15
  {
3
16
  "v": "0.554.0",
4
17
  "at": "2026-11-10T22:52:00.722Z",
@@ -102,6 +102,8 @@ A loop never sends a message, moves a Jira ticket, merges into a product reposit
102
102
  | [Horizon scan](intelligence-okr-goals.md) | Daily by default, at most once a day, the first time you step away after 09:00. Scan now: at most 3 a day. | The public web for your kept watch list, and your repository | Report documents and proposals you approve | Cadence: Off. `PMOS_SCAN=off` |
103
103
  | Idle lab | When you have not used PMOS for 30 minutes. One run at a time, at most 3 results each time you step away. | Prototypes: the initiative's record, PRD and earlier specimens. Scans: public pages only, read through `pmos lab page`, and no repository. | "PMOS prototyped it", "PMOS improved it" and "PMOS scanned for it" under the initiative's ✦. A finding that fits no initiative: Intelligence › Lab. | `pmos ai off idle-lab` |
104
104
  | [What you might have missed](claude-proposes.md) | Each Monday, for the week before. It uses no model. | Records only: tasks, dates, initiatives and Jira status | One ✦ in Home's chat, at most 3 items | `pmos ai off drift`. `PMOS_DRIFT=off` |
105
+ | [The story so far](home.md) | Once, when you open a product that has no story yet. At most once a day for each product. | The initiatives, their stages and dates, and the Intent and Goal | "The story so far" on the product page. After that, the weekly report keeps it current. | `pmos ai off story-seed`. `PMOS_STORY_SEED=off` |
106
+ | Change check | When no merged pull request waits for the verifier. At most 4 a day. | One change that PMOS made by itself, the record it changed, and its sources | Nothing when it passes. A FAIL removes the change from "did" and counts like an Undo. | `pmos ai off verify`. `PMOS_VERIFY_CHANGES=off` |
105
107
  | [Your impact](claude-proposes.md) | PMOS reads once a day. Home shows the week after it ends. | Slack, mail, Jira, your meeting notes, your documents and your key results | Adler's sprout on Home, and your impact log | Settings › General › Your impact. `PMOS_IMPACT=off` |
106
108
  | [Morning brief and day check](proactive-engine.md) | The morning brief at 06:45, once you schedule it. The day check every 60 minutes by default (30, 60 or off). | Calendar, Wispr Flow, Slack, Jira and Confluence are on by default. Mail, GitHub, Drive, Figma and websites are off by default. Mail: subjects and senders only. | Today | Each source is a setting. `pmos proactive settings` |
107
109
  | [Day tasks](proactive-engine.md) | You press Prepare my day. At most 5 sessions at once. | The sources of the brief, read-only | Today: a draft waits for Approve or Revise | Do not press Prepare my day |
@@ -192,6 +192,7 @@ PMOS's grill run files with these commands, which refuse outside that run:
192
192
 
193
193
  - `pmos autonomy status` lists what agents applied in the last 14 days (D106), each with its id, and the jobs that went back to propose.
194
194
  - `pmos autonomy restore <job>` ends a job's 7 days back at propose early.
195
+ - `pmos autonomy check <ref> --verdict PASS|FAIL --why "<one line>"` records the grade of one change PMOS made by itself. Only the check run that PMOS starts for that change can use it. A FAIL counts like an Undo.
195
196
  - Undo a change of the Initiative Driver with `pmos driver undo <proposal>`. A ✦ change is undone on its initiative's ✦.
196
197
 
197
198
  [What PMOS does behind the scenes](agent-capabilities.md) explains the three classes of change and when a job goes back to propose.
@@ -99,6 +99,9 @@ An "off" switch accepts `off`, `0`, `false` or `no` unless the row says a differ
99
99
  | `PMOS_AI_<JOB>` | `off` turns one AI job off. The names are `PMOS_AI_PAST_REPEAT`, `PMOS_AI_DECISION_MEMORY`, `PMOS_AI_OUTCOMES`, `PMOS_AI_DESCRIPTIONS`, `PMOS_AI_DRIFT`, `PMOS_AI_REHEARSE`, `PMOS_AI_NEXT_PROMPT`, `PMOS_AI_SHARPEN_PROMPT` and `PMOS_AI_IDLE_LAB`. | on | `pmos ai off <job>` (the `ai.off` setting) |
100
100
  | `PMOS_AUTONOMY` | `off` stops every change PMOS applies by itself (D106) and every goal loop; proposals still wait for your ✓. | on | `pmos ai off` |
101
101
  | `PMOS_VERIFY` | `off` stops the verifier that checks each merged pull request. | on | `pmos ai off verify` |
102
+ | `PMOS_VERIFY_CHANGES` | `off` stops the check of the changes PMOS made by itself. A failed check sends that kind of change back to asking. | on | `pmos ai off verify` |
103
+ | `PMOS_CHECK_REF`, `PMOS_CHECK_DIR` | Set by PMOS for one check run only. They name the change it checks and the ledger it writes to. Do not set them yourself. | — | — |
104
+ | `PMOS_STORY_SEED` | `off` stops PMOS from writing the first story so far for a product that has none. | on | `pmos ai off story-seed` |
102
105
  | `PMOS_DRIVER` | `off` starts no [Initiative Driver](initiatives-and-next-steps.md) run and no horizon scan. | on | — |
103
106
  | `PMOS_CHECKER` | `off` stops the check of the Driver's drafts. | on | — |
104
107
  | `PMOS_PROPOSE` | `off` stops the runs that file proposals under an initiative's ✦. | on | — |
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * pmos autonomy status [--json] [--root <dir>] the changes applied by agents in the last 14 days, and the jobs back to propose
5
5
  * pmos autonomy restore <job> [--product <ws>] end a job's demotion early (PM or agent, D98)
6
+ * pmos autonomy check <ref> --verdict PASS|FAIL --why "<one line>" the verifier's grade of one applied change (batch 29 item 9).
7
+ * Only inside the check run the server started for that change: PMOS_CHECK_REF and PMOS_CHECK_DIR pin the change and its
8
+ * ledger (lib/verify-runs.js). A FAIL sends the job back to asking, like an Undo.
6
9
  *
7
10
  * Undo a change on its page, or with `pmos driver undo <proposal>` for a Driver change. Exit codes: 0 done, 1 refused, 2 usage. */
8
11
  const path = require('path');
@@ -11,11 +14,12 @@ const A = require('./autonomy.js');
11
14
  const D = require('./driver.js');
12
15
  const actorLib = require('./actor.js');
13
16
 
14
- const COMMANDS = { autonomy: ['status', 'restore'] };
17
+ const COMMANDS = { autonomy: ['status', 'restore', 'check'] };
15
18
  const USAGE = [
16
- 'usage: pmos autonomy status|restore — what agents do by themselves (class A and B, with Undo)',
19
+ 'usage: pmos autonomy status|restore|check — what agents do by themselves (class A and B, with Undo)',
17
20
  ' pmos autonomy status [--json] the changes agents applied in the last 14 days, and the jobs back to propose',
18
21
  ' pmos autonomy restore <job> [--product <ws>] end a job\'s demotion early',
22
+ ' pmos autonomy check <ref> --verdict PASS|FAIL --why "<one line>" inside a check run only: the grade of the change it checks',
19
23
  'Class C (a message to a person, a Jira move others see, a merge into a product repository, a delete, spend) always waits for you.',
20
24
  ];
21
25
  const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (args[i + 1] === undefined || args[i + 1].startsWith('--') ? true : args[i + 1]) : undefined; };
@@ -26,6 +30,16 @@ function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), env = pro
26
30
  const verb = args[0];
27
31
  if (!verb || ['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
28
32
  if (!COMMANDS.autonomy.includes(verb)) { say(`unknown autonomy command "${verb}" — one of ${COMMANDS.autonomy.join(', ')}`); return 2; }
33
+ if (verb === 'check') {
34
+ const ref = args[1] && !args[1].startsWith('--') ? args[1] : null;
35
+ const verdict = flag(args, 'verdict'), why = flag(args, 'why');
36
+ if (!ref || typeof verdict !== 'string' || typeof why !== 'string') { say('usage: pmos autonomy check <ref> --verdict PASS|FAIL --why "<one line>"'); return 2; }
37
+ if (!env.PMOS_CHECK_DIR || env.PMOS_CHECK_REF !== ref) { say('✗ a check is recorded only inside the check run PMOS started for that change'); return 1; }
38
+ const r = A.recordCheck(env.PMOS_CHECK_DIR, { ref, verdict, why }, { now, by: 'agent:verifier' });
39
+ if (!r.ok) { say('✗ ' + r.error); return 1; }
40
+ say(`✓ ${ref}: ${verdict.toUpperCase()}` + (r.demoted ? ` — the job asks first until ${r.demoted.until.slice(0, 10)}` : ''));
41
+ return 0;
42
+ }
29
43
  const root = typeof flag(args, 'root') === 'string' ? path.resolve(cwd, flag(args, 'root')) : repoRoot(cwd);
30
44
  const dir = D.stateDirOf(root);
31
45
  if (!dir) { say('✗ this repository has no PMOS state folder (pmos/state, state or .pmos)'); return 1; }
@@ -10,12 +10,15 @@
10
10
  * A change with no Undo writer is never applied by itself, whatever its class ("no Undo, no auto"): it waits like C.
11
11
  *
12
12
  * THE LEDGER: <state folder>/autonomy.jsonl, append-only, THIS FILE IS ITS ONE WRITER. One line per event { v: 1, at, ev, ... }:
13
- * applied { job, product, ref, title, cls, ini?, why? } an agent applied a change by itself (ref: the proposal id or the ✦ batch;
14
- * ini: the initiative it changed; why: the evidence it acted on, one line)
13
+ * applied { job, product, ref, title, cls, ini?, why?, run?, way, kept, set? } an agent applied a change by itself (ref: the proposal
14
+ * id or the ✦ batch; ini: the initiative it changed; why: the evidence it acted on, one line;
15
+ * run: the agent run that made it; way/kept/set: how it acted then, quiet or show, the
16
+ * changes of its job kept before it, and whether the PM set that way)
15
17
  * setback { job, product, ref?, kind } kind: undo (the PM pressed Undo) · revert (a revert of the change) ·
16
18
  * verifier-fail (the T4 verifier failed it; counts like an Undo)
17
19
  * demote { job, product, until, why } the job falls back to propose for this product until `until`
18
20
  * seen { job, product, until } Home said so once; it does not say it again for this demotion
21
+ * checked { job, product, ref, verdict, why, by? } the verifier graded one applied change (PASS | FAIL; a FAIL also writes a setback)
19
22
  * A job is `driver:<what>` for the Initiative Driver and `propose:<group>` for a ✦ group. A product is the workspace id.
20
23
  *
21
24
  * AUTOMATIC DEMOTION (a safety net, not a gate). A job on a product falls back to propose for 7 days when:
@@ -27,7 +30,8 @@
27
30
  * CLASSES · DRIVER_CLASS · PROPOSAL_CLASS · DEMOTE_DAYS · UNDO_DAYS · RATE_LIMIT · RATE_MIN
28
31
  * classOfDriver(what) · classOfProposal(p) → 'A' | 'B' | 'C'
29
32
  * file(stateDir) · read(stateDir) → lines · fold(lines, { now }) → state the ledger
30
- * recordApplied(stateDir, { job, product, ref, title, cls }, { now })
33
+ * recordApplied(stateDir, { job, product, ref, title, cls, ini?, why?, run? }, { now, settingsDir }) writes the way the job acted with
34
+ * (wayAt: quiet or show, the kept count, the PM's setting), so the line can say why it was quiet
31
35
  * recordSetback(stateDir, { job, product, ref?, kind }, { now }) → { demoted: null | { until, why } } the hook T4 calls on a FAIL
32
36
  * decide({ stateDir, job, product, cls, mode, undoable, now, env, settingsDir }) → { apply: bool, why } killed() first
33
37
  * autoFor(cls, { stateDir?, job?, product?, undoable? }) → bool for callers with no mode: does `cls` apply by itself now
@@ -59,7 +63,7 @@ const RATE_DAYS = 7;
59
63
  const RATE_LIMIT = 0.3;
60
64
  const RATE_MIN = 4;
61
65
  const KINDS = Object.freeze(['undo', 'revert', 'verifier-fail']);
62
- const EVENTS = Object.freeze(['applied', 'setback', 'demote', 'seen', 'restore']);
66
+ const EVENTS = Object.freeze(['applied', 'setback', 'demote', 'seen', 'restore', 'checked']);
63
67
  const JOB_RE = /^(driver|propose|ai|goal):[a-z0-9][a-z0-9-]{0,40}$/;
64
68
  const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
65
69
  const WAYS = Object.freeze(['quiet', 'show', 'ask']);
@@ -155,13 +159,17 @@ function fold(lines) {
155
159
  if (!isObj(l) || typeof l.job !== 'string') continue;
156
160
  const j = get(l.job, l.product);
157
161
  if (l.ev === 'applied') {
158
- const a = { ref: l.ref || null, title: l.title || '', cls: l.cls || null, job: l.job, product: l.product || null, ini: l.ini || null, why: l.why || '', at: l.at, undone: false, undoneAt: null };
162
+ const a = { ref: l.ref || null, title: l.title || '', cls: l.cls || null, job: l.job, product: l.product || null, ini: l.ini || null, why: l.why || '', at: l.at, undone: false, undoneAt: null,
163
+ run: l.run || null, rec: WAYS.includes(l.way) && Number.isInteger(l.kept) ? { way: l.way, kept: l.kept, set: l.set === true } : null, checked: null };
159
164
  j.applied.push(a);
160
165
  if (a.ref) applied.set(a.ref, a);
161
166
  } else if (l.ev === 'setback') {
162
167
  j.setbacks.push({ kind: l.kind, ref: l.ref || null, at: l.at });
163
168
  const a = l.ref ? applied.get(l.ref) : null;
164
169
  if (a && (l.kind === 'undo' || l.kind === 'verifier-fail' || l.kind === 'revert')) { a.undone = true; a.undoneAt = l.at; }
170
+ } else if (l.ev === 'checked') {
171
+ const a = l.ref ? applied.get(l.ref) : null;
172
+ if (a) a.checked = { verdict: l.verdict, why: l.why || '', at: l.at };
165
173
  } else if (l.ev === 'demote') j.demote = { until: l.until, why: l.why || '', at: l.at };
166
174
  else if (l.ev === 'seen') j.seen = l.until || null;
167
175
  else if (l.ev === 'restore') j.demote = null;
@@ -191,10 +199,22 @@ function trip(j, now) {
191
199
  return null;
192
200
  }
193
201
 
194
- function recordApplied(stateDir, { job, product, ref, title, cls, ini, why }, { now } = {}) {
202
+ /** How the job acts on this product at this moment: the PM's way for its kind (Ask first aside), else the automatic one from the changes
203
+ * of the job nobody undid. → { way: 'quiet' | 'show', kept, set } (set: the PM chose the way). Read when a change is applied, so the
204
+ * change keeps the reason it was made with (batch 29 item 6: a later setting or Undo does not rewrite why an earlier change was quiet). */
205
+ function wayAt(stateDir, job, product, { settingsDir = null } = {}) {
206
+ const j = fold(read(stateDir)).jobs.get(keyOf(job, product));
207
+ const kept = j ? j.applied.filter((a) => !a.undone).length : 0;
208
+ const own = waysSet(settingsDir)[kindOf(job)];
209
+ return own && own !== 'ask' ? { way: own, kept, set: true } : { way: autoWay({ kept }), kept, set: false };
210
+ }
211
+
212
+ function recordApplied(stateDir, { job, product, ref, title, cls, ini, why, run }, { now, settingsDir = null } = {}) {
195
213
  if (!JOB_RE.test(String(job || ''))) return null;
214
+ const w = wayAt(stateDir, job, product, { settingsDir });
196
215
  return append(stateDir, { ev: 'applied', job, product: product || null, ref: ref ? one(ref, 120) : null, title: one(title, 200), cls: CLASSES.includes(cls) ? cls : null,
197
- ...(ini ? { ini: one(ini, 80) } : {}), ...(why ? { why: one(why, 200) } : {}) }, { now });
216
+ ...(ini ? { ini: one(ini, 80) } : {}), ...(why ? { why: one(why, 200) } : {}), ...(run ? { run: one(run, 80) } : {}),
217
+ way: w.way, kept: w.kept, ...(w.set ? { set: true } : {}) }, { now });
198
218
  }
199
219
 
200
220
  /** THE HOOK for an Undo, a revert or a verifier FAIL. Writes the setback and, when it trips, the demotion. */
@@ -278,8 +298,10 @@ function done(stateDir, { now, days = UNDO_DAYS, settingsDir = null } = {}) {
278
298
  const own = set[kindOf(j.job)] || null;
279
299
  for (const a of j.applied) {
280
300
  if (!a.undone && Date.parse(a.at) >= since) {
281
- const way = own && own !== 'ask' ? own : autoWay({ kept });
282
- out.push({ ...a, kept, way, reason: reasonOf({ cls: a.cls, why: a.why, kept, way: own }) });
301
+ const { rec, ...rest } = a;
302
+ // a change applied since batch 29 carries the way it was made with; an older line is read with today's way, as before
303
+ if (rec) out.push({ ...rest, kept: rec.kept, way: rec.way, reason: reasonOf({ cls: a.cls, why: a.why, kept: rec.kept, way: rec.set ? rec.way : null }) });
304
+ else out.push({ ...rest, kept, way: own && own !== 'ask' ? own : autoWay({ kept }), reason: reasonOf({ cls: a.cls, why: a.why, kept, way: own }) });
283
305
  }
284
306
  if (!a.undone) kept++;
285
307
  }
@@ -311,6 +333,57 @@ function kindsOf(dirs, { now, settingsDir = null } = {}) {
311
333
  }).filter((x) => x.made || x.set).sort((p, q) => q.made - p.made);
312
334
  }
313
335
 
336
+ /* ── batch 29 item 9: a verifier FAIL or a revert sends the job back to asking (D106) ──
337
+ * Jobs that change records open no pull request, so the merged-run verifier never sees them. Two routes reach recordSetback:
338
+ * the applied-change check the verifier job grades one applied change (toCheck) in a read-only run, whose one write is
339
+ * `pmos autonomy check <ref> --verdict PASS|FAIL` (recordCheck). A FAIL is a `verifier-fail` setback.
340
+ * a PR-backed run an applied line that names its run: a verifier FAIL on that run (evals.jsonl), or a revert of its merge
341
+ * (scripts/run-corrections.js), is a setback of every change the run applied (fromRuns). */
342
+ const VERDICTS = Object.freeze(['PASS', 'FAIL']);
343
+ const CHECK_MIN_AGE = 3600000; // a change settles for an hour before it is checked, so an Undo the PM presses at once is not graded
344
+
345
+ /** The next applied change the check should grade: class B (a judgment; class A is upkeep with one right answer), not undone, not
346
+ * checked, older than an hour and still inside its Undo window; oldest first. skip: refs tried already. → applied entry | null */
347
+ function toCheck(stateDir, { now, skip = [] } = {}) {
348
+ const t = now == null ? Date.now() : now;
349
+ const out = [];
350
+ for (const a of fold(read(stateDir)).applied.values()) {
351
+ const age = t - Date.parse(a.at);
352
+ if (a.cls !== 'B' || a.undone || a.checked || !a.ref || skip.includes(a.ref) || !(age >= CHECK_MIN_AGE) || age > UNDO_DAYS * DAY) continue;
353
+ out.push(a);
354
+ }
355
+ out.sort((x, y) => Date.parse(x.at) - Date.parse(y.at));
356
+ if (!out.length) return null;
357
+ const { rec, ...a } = out[0];
358
+ return a;
359
+ }
360
+ /** Record the check of one applied change. A FAIL is a verifier-fail setback of its job (it counts like an Undo). → { ok, demoted } */
361
+ function recordCheck(stateDir, { ref, verdict, why = '' }, { now, by = null } = {}) {
362
+ const v = String(verdict || '').toUpperCase();
363
+ if (!VERDICTS.includes(v)) return { ok: false, error: 'the verdict is PASS or FAIL' };
364
+ if (!one(why, 300)) return { ok: false, error: 'say why in one line (--why "…")' };
365
+ const a = fold(read(stateDir)).applied.get(ref);
366
+ if (!a) return { ok: false, error: 'no change was applied by an agent under that id' };
367
+ if (a.checked) return { ok: false, error: 'that change is checked already' };
368
+ append(stateDir, { ev: 'checked', job: a.job, product: a.product, ref: a.ref, verdict: v, why: one(why, 300), ...(by ? { by } : {}) }, { now });
369
+ if (v === 'PASS' || a.undone) return { ok: true, demoted: null };
370
+ return { ok: true, demoted: recordSetback(stateDir, { job: a.job, product: a.product, ref: a.ref, kind: 'verifier-fail' }, { now }).demoted };
371
+ }
372
+ /** PR-backed runs: failed and reverted are run ids. Every applied change of such a run that is not undone yet becomes a setback, once.
373
+ * → [{ job, product, ref, kind, demoted }] */
374
+ function fromRuns(stateDir, { failed = [], reverted = [] } = {}, { now } = {}) {
375
+ const f = new Set(failed), r = new Set(reverted), out = [];
376
+ if (!f.size && !r.size) return out;
377
+ for (const a of fold(read(stateDir)).applied.values()) {
378
+ if (!a.run || a.undone || !a.ref) continue;
379
+ const kind = r.has(a.run) ? 'revert' : f.has(a.run) ? 'verifier-fail' : null;
380
+ if (!kind) continue;
381
+ const s = recordSetback(stateDir, { job: a.job, product: a.product, ref: a.ref, kind }, { now });
382
+ out.push({ job: a.job, product: a.product, ref: a.ref, kind, demoted: s.demoted || null });
383
+ }
384
+ return out;
385
+ }
386
+
314
387
  /** May this applied change still be undone (within 14 days, not undone yet)? */
315
388
  function undoOpen(stateDir, ref, { now } = {}) {
316
389
  const a = fold(read(stateDir)).applied.get(ref);
@@ -327,7 +400,7 @@ function restore(stateDir, { job, product }, actor, { now } = {}) {
327
400
  }
328
401
 
329
402
  module.exports = {
330
- WAYS, SHOW_UNTIL, KIND_LIST, kindOf, waysSet, autoWay, kindsOf,
403
+ wayAt, toCheck, recordCheck, fromRuns, VERDICTS, WAYS, SHOW_UNTIL, KIND_LIST, kindOf, waysSet, autoWay, kindsOf,
331
404
  LEDGER, CLASSES, DRIVER_CLASS, PROPOSAL_CLASS, DEMOTE_DAYS, UNDO_DAYS, RATE_LIMIT, RATE_MIN, KINDS,
332
405
  classOfDriver, classOfProposal, killed, autoFor, file, read, fold, recordApplied, reasonOf, recordSetback, decide, demotedNow, notices, markSeen, done, undoOpen, restore,
333
406
  };
@@ -151,7 +151,10 @@ async function autoApply({ file, proposal, actor, ctx = {}, now, stateDir, produ
151
151
  }
152
152
  const r = await decide('keep', { file, proposal, actor, ctx, now, auto: true });
153
153
  if (!r.ok) return { applied: false, why: r.error, cls };
154
- A.recordApplied(stateDir, { job: jobOf(p), product, ref: p.id, title: `${p.what}: ${p.why}`, cls, ini: p.target && p.target.kind === 'initiative' ? p.target.id : null }, { now });
154
+ // batch 29 item 6: the line keeps what the change was read from (its sources) and the run that made it, so "PMOS did" can say why
155
+ const from = (p.sources || []).map((x) => x && x.label).filter(Boolean).slice(0, 3);
156
+ A.recordApplied(stateDir, { job: jobOf(p), product, ref: p.id, title: `${p.what}: ${p.why}`, cls, ini: p.target && p.target.kind === 'initiative' ? p.target.id : null,
157
+ why: from.length ? 'From ' + from.join(', ') : '', run: p.run || null }, { now, settingsDir: ctx.settingsDir || null });
155
158
  return { applied: true, why: d.why, cls, wrote: r.wrote };
156
159
  } catch (e) { return { applied: false, why: 'the apply failed: ' + String((e && e.message) || e).slice(0, 160) }; }
157
160
  }
@@ -86,6 +86,7 @@ const path = require('path');
86
86
  const HEADLESS_SKILLS = Object.freeze([
87
87
  'day-check', 'calendar-sync', 'jira-sync', 'my-work-read', 'report-biweekly', 'report-template',
88
88
  'tracker-refresh', 'measure', 'memory-groom', 'backlog-triage',
89
+ 'story-first', // batch 29 item 5: the first story so far, once, when a product has none (lib/story-seed.js)
89
90
  ]);
90
91
  // The note passes that run headless, by the origin prefix lib/routes-notes.js gives them.
91
92
  const HEADLESS_ORIGINS = Object.freeze(['notes-bullets:', 'notes-summary:']);
@@ -208,8 +209,10 @@ const TOOLS = Object.freeze({
208
209
  'Bash(pmos initiative export *)', 'Bash(git log *)', 'Bash(date *)']),
209
210
  // The verifier run (lib/verify-runs.js): read and search the repository and its history, and the one command that records the verdict for
210
211
  // the run it was started for. No Write, no Edit, no web, no connector, nothing that sends; `git` only to read.
212
+ // Batch 29 item 9: the same kind grades one change an agent applied by itself (origin `verify:change:<ref>:<token>`); its one write there
213
+ // is `pmos autonomy check`, pinned by PMOS_CHECK_REF and PMOS_CHECK_DIR to that change. The read verbs show the record it changed.
211
214
  verify: Object.freeze(['Read', 'Glob', 'Grep', 'Bash(git show *)', 'Bash(git log *)', 'Bash(git diff *)', 'Bash(node scripts/verifier.js record *)',
212
- 'Bash(node scripts/workflow-state.js *)', 'Bash(date *)']),
215
+ 'Bash(node scripts/workflow-state.js *)', 'Bash(pmos autonomy check *)', 'Bash(pmos initiative export *)', 'Bash(pmos artefacts show *)', 'Bash(date *)']),
213
216
  // The reading run (lib/metric-read-runs.js): read and search, and the one verb that files a reading. The PM's analytics and Jira are read through
214
217
  // the PM's own connectors only where the PM's settings allow it. No Write, no Edit, no web fetch, nothing that sends.
215
218
  'metric-read': Object.freeze(['Read', 'Glob', 'Grep', 'Bash(pmos metrics reading *)', 'Bash(pmos source show *)', 'Bash(pmos source status *)', 'Bash(date *)']),
@@ -647,7 +650,7 @@ const RUN_ENV = Object.freeze(['PMOS_SCAN_FILE', 'PMOS_SCAN_ORIGIN', 'PMOS_SCAN_
647
650
  'PMOS_METRIC_READ_FILE', 'PMOS_METRIC_READ_RECORDS', 'PMOS_METRIC_READ_DRAFTS', 'PMOS_METRIC_READ_WS', 'PMOS_METRIC_READ_RUN', 'PMOS_METRIC_READ_RIDS', 'PMOS_METRIC_READ_TEST',
648
651
  'PMOS_PROPOSE_FILE', 'PMOS_PROPOSE_WS', 'PMOS_PROPOSE_BOARD', 'PMOS_PROPOSE_INI', 'PMOS_PROPOSE_RUN',
649
652
  'PMOS_GRILL_FILE', 'PMOS_GRILL_LOG', 'PMOS_GRILL_WS', 'PMOS_GRILL_BOARD', 'PMOS_GRILL_INI', 'PMOS_GRILL_RUN', 'PMOS_GRILL_BUDGET',
650
- 'PMOS_IMPACT_FILE', 'PMOS_IMPACT_RUN', 'PMOS_VERIFY_RUN', 'PMOS_MS_REVIEW_FILE', 'PMOS_MS_REVIEW_RUN', 'PMOS_MS_REVIEW_PROGRAM',
653
+ 'PMOS_IMPACT_FILE', 'PMOS_IMPACT_RUN', 'PMOS_VERIFY_RUN', 'PMOS_CHECK_REF', 'PMOS_CHECK_DIR', 'PMOS_MS_REVIEW_FILE', 'PMOS_MS_REVIEW_RUN', 'PMOS_MS_REVIEW_PROGRAM',
651
654
  'PMOS_TEAM_FILE', 'PMOS_TEAM_ROOT', 'PMOS_TEAM_WS', 'PMOS_TEAM_ROLE', 'PMOS_TEAM_RUN', 'PMOS_TEAM_INI', 'PMOS_TEAM_MODE',
652
655
  'PMOS_LAB_RUN', 'PMOS_LAB_KIND', 'PMOS_LAB_PENDING', 'PMOS_LAB_INI', 'PMOS_LAB_BUDGET', 'PMOS_LAB_PAGES', 'PMOS_LAB_SPECIMENS']);
653
656
  function runEnvOf(extra) {
@@ -47,6 +47,9 @@ const LEDGERS = Object.freeze({
47
47
  r('lib/routes-grill.js', null, "Settings › PMOS's checks: this month's spend")] },
48
48
  '<runtime>/goal-loops.jsonl': { concept: 'goal-loops', owner: 'lib/goal-loop.js', readers: [
49
49
  r('lib/loop-cli.js', null, '`pmos loop status`: each goal, its round and its state')] },
50
+ '<state>/autonomy.jsonl': { concept: 'autonomy', owner: 'lib/autonomy.js', readers: [
51
+ r('lib/routes-autonomy.js', 'A.done', 'what PMOS did by itself on Home and in the Viewer, each with its reason and Undo'),
52
+ r('lib/loop-health.js', 'A.fold', 'the jobs back to asking, on the health line')] },
50
53
  '<state>/driver.jsonl': { concept: 'driver-runs', owner: 'lib/driver.js', readers: [
51
54
  r('lib/routes-driver.js', null, "the initiative's Agent strip"),
52
55
  r('lib/driver-needs.js', null, 'Needs you')] },
@@ -126,7 +129,7 @@ const JOBS = Object.freeze([
126
129
  q('grill', 'lib/grill-runs.js', [props, '<runtime>/grill-runs.jsonl'], [props, 'repo:DECISIONS.md']),
127
130
  q('metric-drafts', 'lib/metric-draft-runs.js', ['<state>/metric-drafts.jsonl'], ['<state>/metric-reads.jsonl']),
128
131
  q('impact', 'lib/impact-runs.js', ['<runtime>/impact.jsonl'], ['connectors']),
129
- q('verify', 'lib/verify-runs.js', ['repo:planning/runs/evals.jsonl', 'repo:planning/runs/verify-queue.jsonl', 'repo:planning/work-items.jsonl'], ['repo:planning/runs/verify-queue.jsonl', 'git']),
132
+ q('verify', 'lib/verify-runs.js', ['repo:planning/runs/evals.jsonl', 'repo:planning/runs/verify-queue.jsonl', 'repo:planning/work-items.jsonl', '<state>/autonomy.jsonl'], ['repo:planning/runs/verify-queue.jsonl', '<state>/autonomy.jsonl', 'git']),
130
133
  q('metric-reads', 'lib/metric-read-runs.js', ['<state>/metric-reads.jsonl'], ['connectors']),
131
134
  q('forecast', 'lib/forecast-tick.js', ['<state>/forecast.jsonl'], ['<state>/boards.jsonl']),
132
135
  q('report-design', 'lib/routes-report-design.js', ['<state>/design.jsonl']),
@@ -3,9 +3,10 @@
3
3
  *
4
4
  * GET /api/artefacts?ws&scope → { ok, ws, scope, kind, artefacts: [{ key, title, owner, for, labels, fields, carried, empty }] }
5
5
  * scope: portfolio (default), board:<id>, goal:<id>, experiment:<id> (initiative:<id> is an alias)
6
- * GET /api/artefacts/story?ws → { ok, ws, story: { scope, at, lines: [{ text, sources }] } | null } "The story so far" on the product
7
- * page (board AwE): the Narrative of board:<ws>, else of the portfolio (lib/artefacts.js storyOf). A shared
8
- * Board carries it without the sources (lib/board-pack.js).
6
+ * GET /api/artefacts/story?ws → { ok, ws, story: { scope, at, lines: [{ text, sources }] } | null, seeding? } "The story so far" on the
7
+ * product page (board AwE): the Narrative of board:<ws>, else of the portfolio (lib/artefacts.js storyOf). A
8
+ * shared Board carries it without the sources (lib/board-pack.js). seeding: there is no story yet and PMOS is
9
+ * writing the first one (lib/story-seed.js, batch 29 item 5).
9
10
  * GET /api/artefacts/lessons → { ok, lessons: [{ ws, product, scope, text, at }] } every product's Lessons, newest first, at most 20
10
11
  * (Settings › Claude, board AwG2)
11
12
  * GET /api/artefacts/map → { ok, artefacts, rows: [{ from, name, artefact, field, note }] } what every older shape became
@@ -99,7 +100,12 @@ async function handle(req, res, url, ctx) {
99
100
  let dir;
100
101
  try { dir = A.dirOf(w.root); } catch (e) { return send(409, { ok: false, error: String((e && e.message) || e) }); }
101
102
  const scopes = (A.parseScope('board:' + w.id) ? ['board:' + w.id] : []).concat('portfolio');
102
- return send(200, { ok: true, ws: w.id, story: A.storyOf(A.fold(A.readLines(A.file(dir))), scopes) });
103
+ const story = A.storyOf(A.fold(A.readLines(A.file(dir))), scopes);
104
+ // batch 29 item 5: no story yet, so PMOS writes the first one itself (lib/story-seed.js: one lean run, at most once a day per product)
105
+ let seeding = false;
106
+ const seeder = ctx.storySeed || require('./story-seed.js').forCtx(ctx);
107
+ if (!story && seeder) { try { const r = seeder.seed(w); seeding = !!r.started || r.why === 'running'; } catch { seeding = false; } }
108
+ return send(200, { ok: true, ws: w.id, story, ...(seeding ? { seeding: true } : {}) });
103
109
  }
104
110
  if (sub) return send(404, { ok: false, error: 'no such artefacts route' });
105
111
  const q = url.searchParams;
@@ -149,4 +149,4 @@ async function handle(req, res, url, ctx) {
149
149
  return send({ status: 200, body: { ok: true } });
150
150
  }
151
151
 
152
- module.exports = { prefixes: ['/api/autonomy'], handle, undoRef, failedOf, sayOf };
152
+ module.exports = { prefixes: ['/api/autonomy'], handle, undoRef, failedOf, sayOf, dirsOf };
@@ -154,7 +154,7 @@ function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
154
154
  if (!d.apply) { out.held++; continue; }
155
155
  try {
156
156
  const r = keepCore(ctx, p, g, f, ini, [x], {}, { auto: true, group: x.group });
157
- A.recordApplied(dir, { job: `propose:${x.group}`, product: w.id, ref: r.batch, title: x.title || x.why || x.group, cls, ini, why: x.title && x.why && x.why !== x.title ? x.why : '' }, { now });
157
+ A.recordApplied(dir, { job: `propose:${x.group}`, product: w.id, ref: r.batch, title: x.title || x.why || x.group, cls, ini, why: x.title && x.why && x.why !== x.title ? x.why : '' }, { now, settingsDir: ctx.runtimeDir || null });
158
158
  out.applied.push({ ini, batch: r.batch, group: x.group, title: x.title || x.why || '' });
159
159
  } catch { out.held++; }
160
160
  }
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+ /* story-seed.js — PMOS writes a product's first story so far itself (feedback batch 29 item 5).
3
+ *
4
+ * off(env) → true when PMOS_STORY_SEED=off, or on a scratch server (PMOS_STATE_DIR set) unless PMOS_STORY_SEED=1
5
+ * due(last, now) PURE → true when no seed started for the product in the last RETRY_MS (last: ISO time | null)
6
+ * create(deps) → { seed(w, { now }) → { started, why } }
7
+ *
8
+ * WHY. The product page shows "The story so far" (D107 Narrative, board AwE) only after the weekly report writes it, so a new product had
9
+ * no card for up to a week. When the story route finds no story, it calls seed(w): ONE lean background run of the `story-first` skill
10
+ * (headless kind `skill`, `claude -p`), whose only write is `pmos artefacts set portfolio narrative now` with one source per line. The card
11
+ * shows once the line lands; the weekly report keeps it current from then on.
12
+ *
13
+ * At most one start per product per RETRY_MS (kept in <state folder>/story-seed.json, so a restart does not start it again), and one run at
14
+ * a time per product. Off with PMOS_STORY_SEED=off, `pmos ai off story-seed`, PMOS_HEADLESS=off, or on a scratch server.
15
+ *
16
+ * forCtx(ctx) builds the server's one seed from the route context; tests pass their own deps to create().
17
+ *
18
+ * deps: { env, headlessOff() → bool, aiOff() → reason | null, stateDirFor(w) → dir | null, start(w) → { ok, session?, error? }, warn(what, err) }
19
+ */
20
+ const fs = require('fs');
21
+ const path = require('path');
22
+
23
+ const FILE = 'story-seed.json';
24
+ const RETRY_MS = 24 * 3600000;
25
+ const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
26
+ function off(env) {
27
+ const e = env || process.env;
28
+ const v = String(e.PMOS_STORY_SEED || '').trim();
29
+ if (/^(1|on|true|yes)$/i.test(v)) return false;
30
+ return flagOff(v) || !!String(e.PMOS_STATE_DIR || '').trim();
31
+ }
32
+ function due(last, now) {
33
+ const t = Date.parse(last || '');
34
+ return !Number.isFinite(t) || now - t >= RETRY_MS;
35
+ }
36
+
37
+ function create(deps) {
38
+ const warn = deps.warn || (() => {});
39
+ const running = new Set(); // product ids with a seed run in flight
40
+ const fileOf = (w) => { const d = deps.stateDirFor ? deps.stateDirFor(w) : null; return d ? path.join(d, FILE) : null; };
41
+ function readLast(f, id) { try { const o = JSON.parse(fs.readFileSync(f, 'utf8')); return o && typeof o === 'object' ? o[id] || null : null; } catch { return null; } }
42
+ function writeLast(f, id, at) {
43
+ let o = {};
44
+ try { o = JSON.parse(fs.readFileSync(f, 'utf8')) || {}; } catch { o = {}; }
45
+ o[id] = at;
46
+ fs.mkdirSync(path.dirname(f), { recursive: true });
47
+ fs.writeFileSync(f, JSON.stringify(o) + '\n');
48
+ }
49
+
50
+ function seed(w, { now = Date.now() } = {}) {
51
+ if (!w || !w.id) return { started: false, why: 'no product' };
52
+ if (off(deps.env)) return { started: false, why: 'off' };
53
+ if (deps.headlessOff && deps.headlessOff()) return { started: false, why: 'background runs are off' };
54
+ let ai = null; try { ai = deps.aiOff ? deps.aiOff() : null; } catch { ai = null; }
55
+ if (ai) return { started: false, why: ai };
56
+ if (running.has(w.id)) return { started: false, why: 'running' };
57
+ const f = fileOf(w);
58
+ if (!f) return { started: false, why: 'no state folder' };
59
+ if (!due(readLast(f, w.id), now)) return { started: false, why: 'tried in the last day' };
60
+ try { writeLast(f, w.id, new Date(now).toISOString()); } catch (e) { warn('story-seed.json', e); return { started: false, why: 'could not record the start' }; }
61
+ let r = null;
62
+ try { r = deps.start(w, { onDone: () => running.delete(w.id) }); } catch (e) { warn('story seed', e); }
63
+ if (!r || !r.ok) return { started: false, why: (r && r.error) || 'the run could not start' };
64
+ running.add(w.id);
65
+ return { started: true, session: r.session || null };
66
+ }
67
+ return { seed };
68
+ }
69
+
70
+ /* The one seed of a server, built from the route context (lib/route-modules.js ctx: spawnSession, stateDirFor, runtimeDir), so server.js
71
+ * needs no wiring of its own. The run's prompt is the built-in story-first skill's body. null when the context cannot start a run. */
72
+ const SKILL = path.join(__dirname, '..', 'skills', 'story-first.skill');
73
+ let shared = null;
74
+ function forCtx(ctx) {
75
+ if (shared) return shared;
76
+ if (!ctx || typeof ctx.spawnSession !== 'function' || typeof ctx.stateDirFor !== 'function') return null;
77
+ shared = create({
78
+ env: process.env,
79
+ headlessOff: () => require('./headless.js').switchedOff(process.env),
80
+ aiOff: () => require('./ai-guard.js').off('story-seed', { settingsDir: ctx.runtimeDir || null }),
81
+ stateDirFor: (w) => ctx.stateDirFor(w, { create: true }),
82
+ start: (w, { onDone } = {}) => {
83
+ let prompt = '';
84
+ try { prompt = require('./skill-store.js').parseSkill(fs.readFileSync(SKILL, 'utf8')).body || ''; } catch { prompt = ''; }
85
+ if (!prompt) return { ok: false, error: 'the story-first skill is not installed' };
86
+ const s = ctx.spawnSession({ name: 'Writing the first story', agent: 'claude', ws: w.id, origin: 'story-first:' + w.id, initialInput: prompt + '\r', autoDelete: undefined, onDone,
87
+ modelAsk: { scheduleTier: null, skillTier: null, skill: 'story-first' } });
88
+ if (!s || s.state === 'exited') return { ok: false, error: (s && s.note) || 'the run could not start' };
89
+ return { ok: true, session: s.id };
90
+ },
91
+ });
92
+ return shared;
93
+ }
94
+
95
+ module.exports = { off, due, create, forCtx, FILE, RETRY_MS };
@@ -123,7 +123,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, cwd =
123
123
  if (!v.ok) return fail(`the ${role.name} may not write ${pos[0] || '(nothing)'}: ${v.why}`);
124
124
  if (!fs.existsSync(path.join(root, v.rel))) return fail(`${v.rel} is not on disk; write it first`);
125
125
  R.append(dir, { kind: 'write', run: runId, role: role.key, session, rel: v.rel, ini, mode }, now);
126
- try { const A = require('./autonomy.js'); if (typeof A.recordApplied === 'function') A.recordApplied(dir, { job: 'ai:' + role.key, product: ini || null, ref: v.rel, title: `${role.name} wrote ${v.rel}`, cls: role.cls }); } catch { /* the autonomy build is not here yet */ }
126
+ try { const A = require('./autonomy.js'); if (typeof A.recordApplied === 'function') A.recordApplied(dir, { job: 'ai:' + role.key, product: ini || null, ref: v.rel, title: `${role.name} wrote ${v.rel}`, cls: role.cls, run: runId }); } catch { /* the autonomy build is not here yet */ }
127
127
  return ok({ rel: v.rel }, `✓ recorded: the ${role.name} wrote ${v.rel}`);
128
128
  }
129
129
  if (verb === 'done') {
@@ -21,8 +21,16 @@
21
21
  *
22
22
  * Off: PMOS_VERIFY=off, a scratch server (PMOS_STATE_DIR set, unless PMOS_VERIFY=1), PMOS_HEADLESS=off, `pmos ai off verify` (the bg-queue switch). Runs only when deep work may run (open(now)).
23
23
  *
24
+ * THE APPLIED-CHANGE CHECK (batch 29 item 9, D106). Jobs that change records by themselves open no pull request, so step 2 never grades
25
+ * them. When no merged run is started, one turn may instead grade ONE change an agent applied by itself (lib/autonomy.js toCheck: class B,
26
+ * an hour old, inside its Undo window): headless kind `verify`, origin `verify:change:<ref>:<token>`, with PMOS_CHECK_REF and PMOS_CHECK_DIR
27
+ * pinned to that change. Its one write is `pmos autonomy check <ref> --verdict PASS|FAIL`; a FAIL sends the job back to asking for 7 days.
28
+ * At most CHECKS_PER_DAY a day; a change tried once is not tried again that day. Off with PMOS_VERIFY_CHANGES=off.
29
+ * PR-BACKED RUNS: an applied line that names its run is a setback when the verifier FAILs that run (evals.jsonl) or its merge is reverted
30
+ * (`node scripts/run-corrections.js --json`, at most every SWEEP_MS per repository, and only while such a line exists).
31
+ *
24
32
  * deps: { roots() → [{ id, root }], open(now) → bool, headlessOff() → bool, env, spawn(spec), stop(session), warn(what, err),
25
- * run(root, args) → { code, stdout } (default: spawnSync node), perDay? }
33
+ * run(root, args) → { code, stdout } (default: spawnSync node), perDay?, stateDirs(w) → [the autonomy ledgers of a workspace] }
26
34
  */
27
35
  const fs = require('fs');
28
36
  const path = require('path');
@@ -30,6 +38,29 @@ const crypto = require('crypto');
30
38
  const { spawnSync } = require('child_process');
31
39
 
32
40
  const PER_DAY = 4;
41
+ const CHECKS_PER_DAY = 4;
42
+ const SWEEP_MS = 6 * 3600000;
43
+ const one = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n);
44
+ /** The prompt of one applied-change check. a: the applied entry (lib/autonomy.js). */
45
+ function changePrompt(a) {
46
+ const ini = a.ini ? `initiative ${a.ini}` : 'the record it names';
47
+ return 'You check ONE change that PMOS made by itself, without asking the PM. Grade only this change. Read only; change nothing.\n\n'
48
+ + `- Change: ${one(a.title, 200)}\n- Job: ${a.job} (class ${a.cls || 'B'}), on ${ini}, made ${a.at}\n`
49
+ + `- What it was read from: ${one(a.why, 200) || 'not recorded'}\n\n`
50
+ + `1. Read the record it changed${a.ini ? `: \`pmos initiative export ${a.ini}\` (and \`pmos artefacts show experiment:${a.ini}\` for a line of the experiment)` : ''}, and the sources it names.\n`
51
+ + '2. Decide: is the change true to what it was read from, about this record, not a duplicate and not invented? A change you cannot confirm from what you can read is a FAIL.\n'
52
+ + `3. Record it once: \`pmos autonomy check ${a.ref} --verdict PASS|FAIL --why "<one line>"\`. Then stop. Send nothing.`;
53
+ }
54
+ /** The run ids a repository's own evidence turns against their changes: verifier FAILs and reverted merges. PURE on its inputs. */
55
+ function runEvidence(evalsText, corrections) {
56
+ const failed = new Set(), reverted = new Set();
57
+ for (const l of String(evalsText || '').split('\n')) {
58
+ if (!l.includes('FAIL')) continue;
59
+ try { const o = JSON.parse(l); if (o && o.run_id && o.source === 'verifier-after-merge' && String(o.verdict || '').toUpperCase() === 'FAIL') failed.add(String(o.run_id)); } catch { /* a torn line */ }
60
+ }
61
+ for (const r of (corrections && corrections.rows) || []) if ((r.components || []).some((c) => c.kind === 'revert')) reverted.add(String(r.run_id));
62
+ return { failed: [...failed], reverted: [...reverted] };
63
+ }
33
64
  const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
34
65
  /* Off when PMOS_VERIFY says so, and on a scratch server unless asked (PMOS_VERIFY=1): a server given its own state directory (every suite
35
66
  * does, through test-run.js) must never claim real queue entries or start a model, the same rule lib/auto-sync.js enabledFor keeps. */
@@ -85,9 +116,60 @@ function create(deps) {
85
116
  const run = deps.run || nodeRun;
86
117
  const perDay = Number(deps.perDay) > 0 ? Number(deps.perDay) : PER_DAY;
87
118
  let active = null; // { run_id, token, root, session }
119
+ const tried = new Map(); // day → [refs a check started for]
120
+ const swept = new Map(); // root → when its runs were last swept
88
121
 
89
122
  function ended(token) { if (active && active.token === token) active = null; }
90
123
 
124
+ const dirsOf = (w) => { try { return (deps.stateDirs && deps.stateDirs(w)) || []; } catch { return []; } };
125
+ /* PR-backed runs: a FAIL or a revert of a run is a setback of the changes it applied (lib/autonomy.js fromRuns) */
126
+ function sweepRuns(roots, now) {
127
+ const A = require('./autonomy.js');
128
+ const out = [];
129
+ for (const w of roots) {
130
+ const dirs = dirsOf(w);
131
+ if (!isCheckout(w.root) || !dirs.length || now - (swept.get(w.root) || 0) < SWEEP_MS) continue;
132
+ if (!dirs.some((d) => [...A.fold(A.read(d)).applied.values()].some((a) => a.run && !a.undone))) continue;
133
+ swept.set(w.root, now);
134
+ let ev = '', corr = null;
135
+ try { ev = fs.readFileSync(path.join(w.root, 'planning', 'runs', 'evals.jsonl'), 'utf8'); } catch { ev = ''; }
136
+ try { if (fs.existsSync(path.join(w.root, 'scripts', 'run-corrections.js'))) corr = parse(run(w.root, ['scripts/run-corrections.js', '--json']).stdout); } catch (e) { warn('run-corrections', e); }
137
+ const rs = runEvidence(ev, corr);
138
+ for (const d of dirs) { try { out.push(...A.fromRuns(d, rs, { now })); } catch (e) { warn('autonomy setback', e); } }
139
+ }
140
+ return out;
141
+ }
142
+ /* one applied-change check, when the day's cap allows */
143
+ function checkChange(roots, now, day) {
144
+ const e = deps.env || process.env;
145
+ if (/^(off|0|false|no)$/i.test(String(e.PMOS_VERIFY_CHANGES || '').trim())) return null;
146
+ const A = require('./autonomy.js');
147
+ const today = tried.get(day) || [];
148
+ if (today.length >= CHECKS_PER_DAY) return null;
149
+ for (const w of roots) {
150
+ for (const dir of dirsOf(w)) {
151
+ const a = A.toCheck(dir, { now, skip: today });
152
+ if (!a) continue;
153
+ today.push(a.ref); tried.clear(); tried.set(day, today);
154
+ const token = 'vc' + now.toString(36) + crypto.randomBytes(3).toString('hex');
155
+ active = { run_id: 'change:' + a.ref, token, root: w.root, session: null };
156
+ let session = null;
157
+ try {
158
+ session = deps.spawn({ name: 'Checking a change PMOS made', ws: w.id, origin: `verify:change:${a.ref}:${token}`, initialInput: changePrompt(a) + '\r',
159
+ env: { PMOS_CHECK_REF: a.ref, PMOS_CHECK_DIR: dir }, onDone: () => ended(token) });
160
+ } catch (err) { warn('change check', err); }
161
+ if (!session || session.held || session.state === 'exited' || session.headless !== 'verify') {
162
+ if (session && !session.held && session.headless !== 'verify' && session.state !== 'exited' && deps.stop) { try { deps.stop(session); } catch { /* best effort */ } }
163
+ active = null;
164
+ return { checked: null, held: !!(session && session.held) };
165
+ }
166
+ active.session = session;
167
+ return { checked: a.ref };
168
+ }
169
+ }
170
+ return null;
171
+ }
172
+
91
173
  function tick({ now = Date.now() } = {}) {
92
174
  if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { off: true };
93
175
  if (active) return { running: active.run_id };
@@ -124,10 +206,12 @@ function create(deps) {
124
206
  active.session = session;
125
207
  return { started: e.run_id, integrated };
126
208
  }
127
- return { started: null, integrated };
209
+ const setbacks = sweepRuns(roots, now);
210
+ const c = checkChange(roots, now, day);
211
+ return { started: null, integrated, ...(setbacks.length ? { setbacks } : {}), ...(c ? c : {}) };
128
212
  }
129
213
 
130
214
  return { tick, active: () => (active ? active.run_id : null) };
131
215
  }
132
216
 
133
- module.exports = { off, startsToday, create, isCheckout, PER_DAY, statusOf };
217
+ module.exports = { off, startsToday, create, isCheckout, PER_DAY, CHECKS_PER_DAY, statusOf, changePrompt, runEvidence };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.554.0",
3
+ "version": "0.555.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.554.0",
9
+ "version": "0.555.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.554.0",
3
+ "version": "0.555.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -3115,6 +3115,8 @@ const impactTick = () => { try { impactRuns.tick({}); } catch (e) { warnWriteFai
3115
3115
  // Off with PMOS_VERIFY=off or `pmos ai off verify`.
3116
3116
  const verifyRuns = require('./lib/verify-runs.js').create({
3117
3117
  roots: () => [...workspaces.values()].map((w) => ({ id: w.id, root: w.root })),
3118
+ // batch 29 item 9: the autonomy ledgers of a workspace (the server's ✦ and the Driver's), for the applied-change check and run setbacks
3119
+ stateDirs: (r) => { const w = workspaces.get(r.id); return w ? require('./lib/routes-autonomy.js').dirsOf({ stateDirFor }, w) : []; },
3118
3120
  open: deepOpenNow,
3119
3121
  headlessOff: () => headlessLib.switchedOff(process.env),
3120
3122
  env: process.env,
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: story-first
3
+ label: "Write the first story (once, when a product has none)"
4
+ description: "Write the product's first story so far, from the records, when the product page has none yet. It runs once; the weekly report keeps the story current after that."
5
+ run: agent
6
+ agent: claude
7
+ output:
8
+ - The story so far
9
+ ---
10
+
11
+ /story-first — write the FIRST story so far for THIS repository. The product page shows it as "The story so far". The weekly report keeps it current later; this run only fills the empty card once. Work only from what you can read here.
12
+
13
+ Rules that always hold:
14
+ 1. ONE WRITE. Your only write is one `pmos artefacts set portfolio narrative now` command (step 3). Write no file. Send, post or share nothing.
15
+ 2. SOURCED. Every sentence has a record that holds it: an initiative id, a task, a decision, an acceptance, a report. A sentence with no record is left out.
16
+ 3. NOTHING INVENTED. If the records say little, write less. Two true sentences are correct; six guessed ones are not.
17
+ 4. LIGHT. Do not copy message bodies, tokens or credentials.
18
+
19
+ Procedure:
20
+ 1. Read where the product stands: `pmos initiative list` (stage, owner, dates), and `node scripts/workflow-state.js` if the repository has it. Read `pmos artefacts show portfolio` for an Intent or a Goal to lead with.
21
+ 2. Write 3 to 6 short sentences, one per line, on where the product stands now: what was settled, what waits, what is late, what has no verdict yet. Plain words. Bold a few words with **two stars** only when they are the point.
22
+ 3. Run once: `pmos artefacts set portfolio narrative now --text "<line 1>"$'\n'"<line 2>"… --source "<label>=<ref>" --source …` with one `--source` per line, in the same order. A label is short ("Initiative scarlet · 30 Oct"); a ref is an initiative id, a path or a link.
23
+ 4. End with one line: how many sentences you wrote. If the records hold nothing to say, write nothing and say so in one line.