create-pmos 0.690.0 → 0.691.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 +9 -3
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +8 -2
- package/workspace/guide/cli.md +7 -0
- package/workspace/lib/autonomy.js +41 -9
- package/workspace/lib/change-record.js +303 -0
- package/workspace/lib/default-decisions.js +2 -1
- package/workspace/lib/driver-decide.js +6 -3
- package/workspace/lib/factory-cli.js +58 -0
- package/workspace/lib/improve-runs.js +7 -4
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/proposals.js +5 -1
- package/workspace/lib/routes-proposals.js +5 -2
- package/workspace/lib/source-guard.js +26 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/test-lists/one-change-record-no-source-no-auto.json +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.691.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": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
],
|
|
35
35
|
"pmosChanges": [
|
|
36
36
|
{
|
|
37
|
-
"v": "0.
|
|
38
|
-
"at": "2026-11-22T09:
|
|
37
|
+
"v": "0.691.0",
|
|
38
|
+
"at": "2026-11-22T09:21:12.074Z",
|
|
39
39
|
"f": 4,
|
|
40
40
|
"prs": [
|
|
41
41
|
{
|
|
@@ -55,6 +55,12 @@
|
|
|
55
55
|
"t": "Kind marks each lifecycle stage owned, watched or hidden",
|
|
56
56
|
"s": "Kind marks each lifecycle stage owned, watched or hidden",
|
|
57
57
|
"k": "new"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"n": 1503,
|
|
61
|
+
"t": "One record of every agent change, and no source, no auto (A443)",
|
|
62
|
+
"s": "One record of every agent change, and no source, no auto (A443)",
|
|
63
|
+
"k": "new"
|
|
58
64
|
}
|
|
59
65
|
]
|
|
60
66
|
},
|
package/payload/KIT-VERSION
CHANGED
|
@@ -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-22T09:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T09:21:09Z"}
|
|
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-22T09:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T09:21:09Z"}
|
|
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-22T09:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-22T09:21:09Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"v": "0.
|
|
4
|
-
"at": "2026-11-22T09:
|
|
3
|
+
"v": "0.691.0",
|
|
4
|
+
"at": "2026-11-22T09:21:12.074Z",
|
|
5
5
|
"f": 4,
|
|
6
6
|
"prs": [
|
|
7
7
|
{
|
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
"t": "Kind marks each lifecycle stage owned, watched or hidden",
|
|
22
22
|
"s": "Kind marks each lifecycle stage owned, watched or hidden",
|
|
23
23
|
"k": "new"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"n": 1503,
|
|
27
|
+
"t": "One record of every agent change, and no source, no auto (A443)",
|
|
28
|
+
"s": "One record of every agent change, and no source, no auto (A443)",
|
|
29
|
+
"k": "new"
|
|
24
30
|
}
|
|
25
31
|
]
|
|
26
32
|
},
|
package/workspace/guide/cli.md
CHANGED
|
@@ -205,6 +205,13 @@ Before you share a spec, a strategy, a roadmap or a report, PMOS reads it as a s
|
|
|
205
205
|
|
|
206
206
|
[What PMOS does behind the scenes](agent-capabilities.md) lists the jobs and their queue names.
|
|
207
207
|
|
|
208
|
+
### pmos factory: everything PMOS changed by itself
|
|
209
|
+
|
|
210
|
+
- `pmos factory today` shows one record of every change PMOS made: for each line (product, project, SDLC) and station, how many changes, how many PMOS applied by itself, how many were kept, undone or ignored, how many cite no source, and how many background runs it used.
|
|
211
|
+
- `pmos factory today --days 7` shows the last 7 days. `--json` prints the totals.
|
|
212
|
+
- `pmos factory today --unsourced` prints one number on its last line: the percent of changes PMOS applied by itself that cite no source.
|
|
213
|
+
- A change that cites no source never applies by itself. It waits for you, as a change others see does.
|
|
214
|
+
|
|
208
215
|
### pmos autonomy: what agents applied by themselves
|
|
209
216
|
|
|
210
217
|
- `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.
|
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
*
|
|
30
30
|
* CLASSES · DRIVER_CLASS · PROPOSAL_CLASS · DEMOTE_DAYS · UNDO_DAYS · RATE_LIMIT · RATE_MIN
|
|
31
31
|
* classOfDriver(what) · classOfProposal(p) → 'A' | 'B' | 'C'
|
|
32
|
+
* classOfDriverProposal(p) → 'A' | 'B' | 'C' classOfDriver plus the source rule
|
|
33
|
+
*
|
|
34
|
+
* NO SOURCE, NO AUTO (initiative one-change-record-no-source-no-auto, idea A443). In every job kind, a change that cites nothing
|
|
35
|
+
* (lib/source-guard.js citedOf: no source, no item or claim source, a link guessed from the plan, "No reason found") is class C: it waits
|
|
36
|
+
* for the PM. decide() takes the change's `sources` and refuses an auto apply when they are given and empty; recordApplied keeps them as
|
|
37
|
+
* `src`, so lib/change-record.js counts unsourced changes without a join. Every refusal logs one [no-source-no-auto] line.
|
|
32
38
|
* file(stateDir) · read(stateDir) → lines · fold(lines, { now }) → state the ledger
|
|
33
39
|
* recordApplied(stateDir, { job, product, ref, title, cls, ini?, why?, run? }, { now, settingsDir }) writes the way the job acted with
|
|
34
40
|
* (wayAt: quiet or show, the kept count, the PM's setting), so the line can say why it was quiet
|
|
@@ -117,9 +123,18 @@ function waysSet(settingsDir) {
|
|
|
117
123
|
const autoWay = ({ kept = 0, demoted = false } = {}) => (demoted ? 'ask' : kept >= SHOW_UNTIL ? 'quiet' : 'show');
|
|
118
124
|
|
|
119
125
|
const classOfDriver = (what) => DRIVER_CLASS[what] || 'C';
|
|
126
|
+
const SG = () => require('./source-guard.js');
|
|
127
|
+
/** A Driver proposal's class: its kind's class, and C when it cites no source (no source, no auto). */
|
|
128
|
+
function classOfDriverProposal(p) {
|
|
129
|
+
if (!isObj(p)) return 'C';
|
|
130
|
+
const c = classOfDriver(p.what);
|
|
131
|
+
return c !== 'C' && !SG().citedOf(p).length ? 'C' : c;
|
|
132
|
+
}
|
|
120
133
|
function classOfProposal(p) {
|
|
121
134
|
if (!isObj(p)) return 'C';
|
|
122
135
|
const c = PROPOSAL_CLASS[p.group] || 'C';
|
|
136
|
+
// no source, no auto, in every group (A443): the plan groups' finer rule below (two kinds for a big change) still applies
|
|
137
|
+
if (c !== 'C' && p.group !== 'build' && !SG().citedOf(p).length) return 'C';
|
|
123
138
|
// act-alone-only-with-a-source: a plan change with no source, or a close, rename or big date move on one kind of source, is the owner's
|
|
124
139
|
// question (lib/source-guard.js); it joins the day's question list instead of applying by itself
|
|
125
140
|
if (c !== 'C' && require('./source-guard.js').holdOf(p)) return 'C';
|
|
@@ -130,7 +145,7 @@ function classOfProposal(p) {
|
|
|
130
145
|
// a live round's prototype (lib/live-round.js, data.live) is the PM's to keep: PMOS never keeps one by itself (2026-11-18: a test round it
|
|
131
146
|
// kept became the initiative's design). The newest version is the prototype anyway (lib/proposals.js currentOf).
|
|
132
147
|
if ((p.group === 'prototyped' || p.group === 'improved') && isObj(p.data) && isObj(p.data.live)) return 'C';
|
|
133
|
-
if (p.group === 'build') return 'B'; // stopping or replacing an experiment is the PM's call (launch simulation W2)
|
|
148
|
+
if (p.group === 'build') return SG().citedOf(p).length ? 'B' : 'C'; // stopping or replacing an experiment is the PM's call (launch simulation W2)
|
|
134
149
|
// 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
|
|
135
150
|
// found type stage moves the initiative's stage: a stage move is C (as the Driver's `move`)
|
|
136
151
|
if (p.group === 'found' && (p.type === 'stage' || p.type === 'maybe' || p.type === 'link' || (p.items || []).some((x) => x && x.other))) return 'C';
|
|
@@ -172,7 +187,7 @@ function fold(lines) {
|
|
|
172
187
|
const j = get(l.job, l.product);
|
|
173
188
|
if (l.ev === 'applied') {
|
|
174
189
|
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,
|
|
175
|
-
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 };
|
|
190
|
+
run: l.run || null, src: Array.isArray(l.src) ? l.src : null, rec: WAYS.includes(l.way) && Number.isInteger(l.kept) ? { way: l.way, kept: l.kept, set: l.set === true } : null, checked: null };
|
|
176
191
|
j.applied.push(a);
|
|
177
192
|
if (a.ref) applied.set(a.ref, a);
|
|
178
193
|
} else if (l.ev === 'setback') {
|
|
@@ -221,11 +236,14 @@ function wayAt(stateDir, job, product, { settingsDir = null } = {}) {
|
|
|
221
236
|
return own && own !== 'ask' ? { way: own, kept, set: true } : { way: autoWay({ kept }), kept, set: false };
|
|
222
237
|
}
|
|
223
238
|
|
|
224
|
-
|
|
239
|
+
/** src: what the change cited (labels, or { label, ref } sources); kept as up to 3 labels, [] when it cited nothing (lib/change-record.js). */
|
|
240
|
+
const srcOf = (src) => (Array.isArray(src) ? [...new Set(src.map((s) => (isObj(s) ? s.label || s.ref : s)).filter((s) => typeof s === 'string' && s.trim()).map((s) => one(s, 80)))].slice(0, 3) : null);
|
|
241
|
+
function recordApplied(stateDir, { job, product, ref, title, cls, ini, why, run, src }, { now, settingsDir = null } = {}) {
|
|
225
242
|
if (!JOB_RE.test(String(job || ''))) return null;
|
|
226
243
|
const w = wayAt(stateDir, job, product, { settingsDir });
|
|
244
|
+
const s = srcOf(src);
|
|
227
245
|
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,
|
|
228
|
-
...(ini ? { ini: one(ini, 80) } : {}), ...(why ? { why: one(why, 200) } : {}), ...(run ? { run: one(run, 80) } : {}),
|
|
246
|
+
...(ini ? { ini: one(ini, 80) } : {}), ...(why ? { why: one(why, 200) } : {}), ...(run ? { run: one(run, 80) } : {}), ...(s ? { src: s } : {}),
|
|
229
247
|
way: w.way, kept: w.kept, ...(w.set ? { set: true } : {}) }, { now });
|
|
230
248
|
}
|
|
231
249
|
|
|
@@ -252,11 +270,24 @@ function killed({ env = process.env, settingsDir = null } = {}) {
|
|
|
252
270
|
return null;
|
|
253
271
|
}
|
|
254
272
|
|
|
255
|
-
|
|
273
|
+
const NO_SOURCE_WHY = 'no source: the change cites nothing, so PMOS asks instead of applying it';
|
|
274
|
+
const logged = new Set();
|
|
275
|
+
/** One [no-source-no-auto] log line per held change per process (the health log of one-change-record-no-source-no-auto). */
|
|
276
|
+
function logHeld(job, product, ref, { log = console.error } = {}) {
|
|
277
|
+
const k = `${job}|${product || '*'}|${ref || ''}`;
|
|
278
|
+
if (logged.has(k)) return false;
|
|
279
|
+
if (logged.size > 5000) logged.clear();
|
|
280
|
+
logged.add(k);
|
|
281
|
+
try { log(`[no-source-no-auto] held ${job}${product ? ' on ' + product : ''}${ref ? ' ' + one(ref, 80) : ''}: it cites no source`); } catch { /* a log never stops the apply step */ }
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
/** sources: what the change cites (lib/source-guard.js citedOf). Given and empty: no source, no auto, whatever the class. */
|
|
285
|
+
function decide({ stateDir, job, product, cls, mode = 'auto', undoable = true, now, env = process.env, settingsDir = null, sources } = {}) {
|
|
256
286
|
const k = killed({ env, settingsDir });
|
|
257
287
|
if (k) return { apply: false, why: k };
|
|
258
288
|
if (mode !== 'auto') return { apply: false, why: `the mode is ${mode}` };
|
|
259
|
-
if (cls === 'C' || !CLASSES.includes(cls)) return { apply: false, why: 'class C: seen by others or not reversible, so it waits for the daily press' };
|
|
289
|
+
if (cls === 'C' || !CLASSES.includes(cls)) return { apply: false, why: 'class C: seen by others or not reversible, so it waits for the daily press', ...(Array.isArray(sources) && !sources.length ? { nosrc: true } : {}) };
|
|
290
|
+
if (Array.isArray(sources) && !sources.length) return { apply: false, why: NO_SOURCE_WHY, nosrc: true };
|
|
260
291
|
if (!undoable) return { apply: false, why: 'no Undo for this change, so it waits' };
|
|
261
292
|
const set = waysSet(settingsDir)[kindOf(job)];
|
|
262
293
|
if (set === 'ask') return { apply: false, why: 'you set this kind to Ask first' };
|
|
@@ -270,9 +301,10 @@ function decide({ stateDir, job, product, cls, mode = 'auto', undoable = true, n
|
|
|
270
301
|
|
|
271
302
|
/** For a caller with no mode of its own (a role agent, an AI job): does class `cls` apply by itself now? With `stateDir` and `job`
|
|
272
303
|
* the demotion of that job counts too. Class C never does. */
|
|
273
|
-
function autoFor(cls, { stateDir = null, job = null, product = null, undoable = true, now, env = process.env, settingsDir = null } = {}) {
|
|
304
|
+
function autoFor(cls, { stateDir = null, job = null, product = null, undoable = true, now, env = process.env, settingsDir = null, sources } = {}) {
|
|
305
|
+
if (Array.isArray(sources) && !sources.length) return false; // no source, no auto
|
|
274
306
|
if (!stateDir || !job) return !killed({ env, settingsDir }) && (cls === 'A' || cls === 'B') && !!undoable;
|
|
275
|
-
return decide({ stateDir, job, product, cls, mode: 'auto', undoable, now, env, settingsDir }).apply;
|
|
307
|
+
return decide({ stateDir, job, product, cls, mode: 'auto', undoable, now, env, settingsDir, sources }).apply;
|
|
276
308
|
}
|
|
277
309
|
|
|
278
310
|
function notices(stateDir, { now } = {}) {
|
|
@@ -414,5 +446,5 @@ function restore(stateDir, { job, product }, actor, { now } = {}) {
|
|
|
414
446
|
module.exports = {
|
|
415
447
|
wayAt, toCheck, recordCheck, fromRuns, VERDICTS, WAYS, SHOW_UNTIL, KIND_LIST, kindOf, waysSet, autoWay, kindsOf,
|
|
416
448
|
LEDGER, CLASSES, DRIVER_CLASS, PROPOSAL_CLASS, DEMOTE_DAYS, UNDO_DAYS, RATE_LIMIT, RATE_MIN, KINDS,
|
|
417
|
-
classOfDriver, classOfProposal, killed, autoFor, file, read, fold, recordApplied, reasonOf, recordSetback, decide, demotedNow, notices, markSeen, done, undoOpen, restore,
|
|
449
|
+
classOfDriver, classOfDriverProposal, classOfProposal, NO_SOURCE_WHY, logHeld, srcOf, killed, autoFor, file, read, fold, recordApplied, reasonOf, recordSetback, decide, demotedNow, notices, markSeen, done, undoOpen, restore,
|
|
418
450
|
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* change-record.js — one record of every agent change (initiative one-change-record-no-source-no-auto; idea A443; the factory grill
|
|
3
|
+
* W24NtYWFttw8DkqFVuoJCB, slice 1). READ-ONLY: this file never writes a line anywhere.
|
|
4
|
+
*
|
|
5
|
+
* PMOS changes a product by itself from six ledgers, each with its own writer: autonomy.jsonl (what an agent applied, lib/autonomy.js),
|
|
6
|
+
* proposals.jsonl (the ✦, lib/proposals.js), driver.jsonl (the Initiative Driver, lib/driver.js), bg-queue.jsonl (the background runs,
|
|
7
|
+
* lib/bg-queue.js), the outbox (drafts to people, lib/outbox-store.js) and each initiative's outcome check date (its record's
|
|
8
|
+
* outcome_horizon). This folds them into ONE ROW PER CHANGE, so a PM can see in one place what PMOS changed, why, and whether it held.
|
|
9
|
+
*
|
|
10
|
+
* rows(input, { now }) → { rows, runs } PURE. input: { autonomy, proposals, driver, bgQueue, outbox: raw ledger lines; checks: { ini: date } }
|
|
11
|
+
* read(root, { runtimeDir }) → input reads the ledgers of one repository (any layout lib/driver.js stateDirOf knows), no write
|
|
12
|
+
* summary(rows, runs, { now, days }) → { from, lines: [{ line, station, changes, applied, kept, undone, ignored, unsourced, runs }],
|
|
13
|
+
* total, placed, joined, unsourced_pct }
|
|
14
|
+
*
|
|
15
|
+
* A ROW: { at, line, station, job, product, ini, ref, title, cls, state, source: [label], sourced, joined, check }
|
|
16
|
+
* line pm (product decisions: problem, evidence, outcome, description, what was found, grill, the idle lab, role agents, goal loops)
|
|
17
|
+
* · project (the plan and its status: dates, done, names, links, stage moves, defaults, sends) · sdlc (the factory's builds)
|
|
18
|
+
* station the module that made it: Proposals, Driver, Defaults, Role agents, Goal loops, Lessons, Outbox, Factory
|
|
19
|
+
* state proposed · applied (by an agent, inside its 14-day Undo) · kept (by the PM, or applied and past its Undo) · undone · dropped
|
|
20
|
+
* · expired (a ✦ nobody answered) · sent (outbox)
|
|
21
|
+
* sourced true: it cites a source. false: it cites none ("No reason found", an empty reason). The applied line's own `src` decides when
|
|
22
|
+
* the ledger has it (lib/autonomy.js recordApplied, from this build on); else what its origin (✦ or Driver proposal) cites;
|
|
23
|
+
* else a reason that names a source kind (lib/source-guard.js kindOf). Nothing found counts as unsourced.
|
|
24
|
+
* joined the applied line was matched to its origin. Keys, in order: its ref is a ✦ keep batch, a kept ✦ id, or a Driver proposal id;
|
|
25
|
+
* else the ✦ keep (auto) or Driver keep (auto) of the same initiative and job within JOIN_MS of it (A443: on Scarlet only
|
|
26
|
+
* 10 of 57 refs joined by batch, so the ref alone is not enough). A row that joins nothing is still placed by its job.
|
|
27
|
+
* check the initiative's outcome check date, when its record names one
|
|
28
|
+
*
|
|
29
|
+
* A change PMOS applied by itself is one row even though it is in two ledgers (the applied line and its ✦ or Driver keep).
|
|
30
|
+
* The source rule the rows measure lives in lib/autonomy.js (no source, no auto). */
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
const path = require('path');
|
|
33
|
+
|
|
34
|
+
const DAY = 86400000;
|
|
35
|
+
const JOIN_MS = 3 * 60 * 1000;
|
|
36
|
+
const UNDO_DAYS = 14;
|
|
37
|
+
const IGNORED_MS = 3 * DAY; // a proposal nobody answered for 3 days is ignored (the grill's draft expiry is 72 hours)
|
|
38
|
+
const LINES = Object.freeze(['pm', 'project', 'sdlc']);
|
|
39
|
+
const LINE_NAMES = Object.freeze({ pm: 'Product', project: 'Project', sdlc: 'SDLC' });
|
|
40
|
+
const PROJECT_GROUPS = new Set(['dates', 'status', 'names', 'links', 'default', 'ask', 'tidy']);
|
|
41
|
+
const PROJECT_DRIVER = new Set(['move', 'follow-up']);
|
|
42
|
+
const NO_REASON = /^\s*(no reason( found)?|none|n\/a|-)?\s*\.?\s*$/i;
|
|
43
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
44
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
45
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
46
|
+
const ms = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : null; };
|
|
47
|
+
|
|
48
|
+
/** The line and station of a job (`propose:<group>`, `driver:<what>`, `ai:<role>`, `goal:<name>`). */
|
|
49
|
+
function placeOf(job) {
|
|
50
|
+
const [kind, name = ''] = String(job || '').split(':');
|
|
51
|
+
if (kind === 'propose') {
|
|
52
|
+
if (name === 'default') return { line: 'project', station: 'Defaults' };
|
|
53
|
+
if (name === 'build') return { line: 'sdlc', station: 'Factory' };
|
|
54
|
+
return { line: PROJECT_GROUPS.has(name) ? 'project' : 'pm', station: 'Proposals' };
|
|
55
|
+
}
|
|
56
|
+
if (kind === 'driver') return { line: PROJECT_DRIVER.has(name) ? 'project' : 'pm', station: 'Driver' };
|
|
57
|
+
if (kind === 'ai') {
|
|
58
|
+
if (name === 'improve') return { line: 'pm', station: 'Lessons' };
|
|
59
|
+
if (/factory|build|review/.test(name)) return { line: 'sdlc', station: 'Factory' };
|
|
60
|
+
return { line: 'pm', station: 'Role agents' };
|
|
61
|
+
}
|
|
62
|
+
if (kind === 'goal') return { line: 'pm', station: 'Goal loops' };
|
|
63
|
+
return { line: null, station: null };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The labels a list of { label, ref } sources (or strings) names. */
|
|
67
|
+
const labelsOf = (src) => (Array.isArray(src) ? src.map((s) => (isObj(s) ? str(s.label) || str(s.ref) : str(s))).map((s) => one(s, 80)).filter(Boolean) : []);
|
|
68
|
+
/** What a reason text names as its source, or [] (a reason is not a source unless it names one: Jira, a PRD, a meeting, a document…). */
|
|
69
|
+
function namedIn(why) {
|
|
70
|
+
const t = str(why);
|
|
71
|
+
if (!t || NO_REASON.test(t) || /no reason found/i.test(t)) return [];
|
|
72
|
+
const SG = require('./source-guard.js');
|
|
73
|
+
const k = SG.kindOf(t);
|
|
74
|
+
if (k !== 'other' && k !== 'plan') return [SG.KIND_NAMES[k] || k];
|
|
75
|
+
if (/^\s*(prd|from)\b/i.test(t)) return [one(t.replace(/^\s*from\s+/i, ''), 80)];
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
/** What one ✦ proposal (a propose line) cites. */
|
|
79
|
+
function citesOfProp(p) {
|
|
80
|
+
try { return labelsOf(require('./source-guard.js').citedOf(p)); } catch { return labelsOf(p && p.sources); }
|
|
81
|
+
}
|
|
82
|
+
/** What a ✦ keep's writes cite: each write's source, else a reason that names one. */
|
|
83
|
+
function citesOfWrote(wrote) {
|
|
84
|
+
const out = [];
|
|
85
|
+
for (const w of Array.isArray(wrote) ? wrote : []) {
|
|
86
|
+
if (!isObj(w)) continue;
|
|
87
|
+
if (str(w.source) && !/^(agent|plan|dates)$/i.test(w.source)) out.push(one(w.source, 80));
|
|
88
|
+
else out.push(...namedIn(w.why));
|
|
89
|
+
}
|
|
90
|
+
return [...new Set(out)];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* ── the fold ── */
|
|
94
|
+
function rows(input = {}, { now = Date.now() } = {}) {
|
|
95
|
+
const out = [];
|
|
96
|
+
const A = Array.isArray(input.autonomy) ? input.autonomy : [];
|
|
97
|
+
const P = Array.isArray(input.proposals) ? input.proposals : [];
|
|
98
|
+
const Dr = Array.isArray(input.driver) ? input.driver : [];
|
|
99
|
+
const checks = isObj(input.checks) ? input.checks : {};
|
|
100
|
+
const checkOf = (ini) => (ini && checks[ini]) || null;
|
|
101
|
+
|
|
102
|
+
// ✦ ledger: propose lines (newest per id), keep lines (with auto and group), undo, expire, drop
|
|
103
|
+
const props = new Map(), keeps = [], undone = new Set(), expired = [], drops = [];
|
|
104
|
+
for (const l of P) {
|
|
105
|
+
if (!isObj(l)) continue;
|
|
106
|
+
if (l.kind === 'propose' && str(l.id)) props.set(l.id, l);
|
|
107
|
+
else if (l.kind === 'keep' && str(l.batch)) keeps.push({ ...l, _t: ms(l.at), _used: false });
|
|
108
|
+
else if (l.kind === 'undo' && str(l.batch)) undone.add(l.batch);
|
|
109
|
+
else if (l.kind === 'expire') expired.push(l);
|
|
110
|
+
else if (l.kind === 'drop' && !l.default) drops.push(l);
|
|
111
|
+
}
|
|
112
|
+
const keepByBatch = new Map(keeps.map((k) => [k.batch, k]));
|
|
113
|
+
const keepById = new Map();
|
|
114
|
+
for (const k of keeps) for (const id of Array.isArray(k.ids) ? k.ids : []) keepById.set(String(id).split(':')[0], k);
|
|
115
|
+
|
|
116
|
+
// Driver ledger: proposals and their decisions
|
|
117
|
+
const dprops = new Map();
|
|
118
|
+
for (const l of Dr) {
|
|
119
|
+
if (!isObj(l)) continue;
|
|
120
|
+
if (l.ev === 'proposal' && str(l.id) && !dprops.has(l.id)) dprops.set(l.id, { ...l, state: 'open', _used: false, auto: false, decided_at: null });
|
|
121
|
+
else if ((l.ev === 'keep' || l.ev === 'return' || l.ev === 'drop') && dprops.has(l.proposal)) {
|
|
122
|
+
const p = dprops.get(l.proposal);
|
|
123
|
+
if (p.state !== 'open') continue;
|
|
124
|
+
p.state = l.ev === 'keep' ? 'kept' : 'dropped'; p.auto = l.auto === true; p.decided_at = l.at || null;
|
|
125
|
+
} else if (l.ev === 'undo' && dprops.has(l.proposal)) dprops.get(l.proposal).state = 'undone';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// autonomy ledger: applied lines, their setbacks and checks
|
|
129
|
+
const setback = new Map(); // ref → kind
|
|
130
|
+
for (const l of A) if (isObj(l) && l.ev === 'setback' && l.ref && ['undo', 'revert', 'verifier-fail'].includes(l.kind)) setback.set(l.ref, l.kind);
|
|
131
|
+
for (const l of A) if (isObj(l) && l.ev === 'checked' && l.verdict === 'FAIL' && l.ref) setback.set(l.ref, setback.get(l.ref) || 'verifier-fail');
|
|
132
|
+
|
|
133
|
+
const near = (t, u) => t != null && u != null && Math.abs(t - u) <= JOIN_MS;
|
|
134
|
+
for (const l of A) {
|
|
135
|
+
if (!isObj(l) || l.ev !== 'applied' || typeof l.job !== 'string') continue;
|
|
136
|
+
const t = ms(l.at);
|
|
137
|
+
const [kind, name] = l.job.split(':');
|
|
138
|
+
let origin = null, cites = null;
|
|
139
|
+
if (kind === 'propose') {
|
|
140
|
+
let k = (l.ref && keepByBatch.get(l.ref)) || (l.ref && keepById.get(l.ref)) || null;
|
|
141
|
+
if (!k) k = keeps.find((x) => !x._used && x.auto === true && (!l.ini || x.ini === l.ini) && (!x.group || x.group === name) && near(x._t, t)) || null;
|
|
142
|
+
if (k) {
|
|
143
|
+
k._used = true; origin = k;
|
|
144
|
+
const ids = (Array.isArray(k.ids) ? k.ids : []).map((id) => String(id).split(':')[0]);
|
|
145
|
+
cites = [...new Set([...ids.flatMap((id) => (props.has(id) ? citesOfProp(props.get(id)) : [])), ...citesOfWrote(k.wrote)])];
|
|
146
|
+
}
|
|
147
|
+
} else if (kind === 'driver') {
|
|
148
|
+
let p = (l.ref && dprops.get(l.ref)) || null;
|
|
149
|
+
if (!p) p = [...dprops.values()].find((x) => !x._used && x.auto && x.what === name && (!l.ini || (x.target && x.target.id === l.ini)) && near(ms(x.decided_at), t)) || null;
|
|
150
|
+
if (p) { p._used = true; origin = p; cites = citesOfProp(p); }
|
|
151
|
+
}
|
|
152
|
+
const src = Array.isArray(l.src) ? labelsOf(l.src) : null;
|
|
153
|
+
const source = src || (cites && cites.length ? cites : null) || namedIn(l.why);
|
|
154
|
+
const sb = l.ref ? setback.get(l.ref) : null;
|
|
155
|
+
const age = t == null ? 0 : now - t;
|
|
156
|
+
const { line, station } = placeOf(l.job);
|
|
157
|
+
out.push({ at: l.at || null, line, station, job: l.job, product: l.product || null, ini: l.ini || (origin && (origin.ini || (origin.target && origin.target.id))) || null,
|
|
158
|
+
ref: l.ref || null, title: one(l.title, 200), cls: l.cls || null, by: 'agent', state: sb ? 'undone' : age > UNDO_DAYS * DAY ? 'kept' : 'applied',
|
|
159
|
+
source, sourced: source.length > 0, joined: !!origin || !!src, check: checkOf(l.ini) });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ✦ proposals that were not applied by an agent: kept by the PM, still open, or expired
|
|
163
|
+
for (const k of keeps) {
|
|
164
|
+
if (k._used || k.auto === true) continue; // an auto keep with no applied line: the applied line is the record (a torn write is skipped)
|
|
165
|
+
const ids = (Array.isArray(k.ids) ? k.ids : []).map((id) => String(id).split(':')[0]);
|
|
166
|
+
const g = str(k.group) || (ids.map((id) => props.get(id)).find(Boolean) || {}).group || (/^lk:/.test(ids[0] || '') ? 'links' : 'dates');
|
|
167
|
+
const { line, station } = placeOf('propose:' + g);
|
|
168
|
+
const source = [...new Set([...ids.flatMap((id) => (props.has(id) ? citesOfProp(props.get(id)) : [])), ...citesOfWrote(k.wrote)])];
|
|
169
|
+
out.push({ at: k.at || null, line, station, job: 'propose:' + g, product: null, ini: k.ini || null, ref: k.batch, title: one((props.get(ids[0]) || {}).title || g, 200),
|
|
170
|
+
cls: null, by: 'pm', state: undone.has(k.batch) ? 'undone' : 'kept', source, sourced: source.length > 0, joined: true, check: checkOf(k.ini) });
|
|
171
|
+
}
|
|
172
|
+
const answered = new Set([...keepById.keys(), ...drops.map((d) => str(d.id)).filter(Boolean), ...expired.map((e) => str(e.id)).filter(Boolean)]);
|
|
173
|
+
for (const p of props.values()) {
|
|
174
|
+
if (answered.has(p.id)) continue;
|
|
175
|
+
const { line, station } = placeOf('propose:' + p.group);
|
|
176
|
+
const source = citesOfProp(p);
|
|
177
|
+
out.push({ at: p.at || null, line, station, job: 'propose:' + str(p.group), product: null, ini: p.ini || null, ref: p.id, title: one(p.title || p.why, 200), cls: null, by: 'agent',
|
|
178
|
+
state: 'proposed', source, sourced: source.length > 0, joined: true, check: checkOf(p.ini) });
|
|
179
|
+
}
|
|
180
|
+
for (const e of expired) {
|
|
181
|
+
const { line, station } = placeOf('propose:' + str(e.group));
|
|
182
|
+
out.push({ at: e.at || null, line, station, job: 'propose:' + str(e.group), product: null, ini: e.ini || null, ref: str(e.id) || null, title: one(e.title || e.why, 200), cls: null,
|
|
183
|
+
by: 'agent', state: 'expired', source: [], sourced: false, joined: true, check: checkOf(e.ini) });
|
|
184
|
+
}
|
|
185
|
+
// Driver proposals that were not applied by an agent
|
|
186
|
+
for (const p of dprops.values()) {
|
|
187
|
+
if (p._used || (p.auto && p.state !== 'open')) continue;
|
|
188
|
+
const { line, station } = placeOf('driver:' + p.what);
|
|
189
|
+
const ini = p.target && p.target.kind === 'initiative' ? p.target.id : null;
|
|
190
|
+
const source = citesOfProp(p);
|
|
191
|
+
out.push({ at: p.at || null, line, station, job: 'driver:' + str(p.what), product: (p.target && p.target.ws) || null, ini, ref: p.id, title: one(`${p.what}: ${p.why}`, 200),
|
|
192
|
+
cls: null, by: p.state === 'open' ? 'agent' : 'pm', state: p.state === 'open' ? 'proposed' : p.state, source, sourced: source.length > 0, joined: true, check: checkOf(ini) });
|
|
193
|
+
}
|
|
194
|
+
// the outbox: drafts to people (class C, never applied by an agent)
|
|
195
|
+
const ob = new Map();
|
|
196
|
+
for (const l of Array.isArray(input.outbox) ? input.outbox : []) {
|
|
197
|
+
if (!isObj(l) || !l.id) continue;
|
|
198
|
+
const cur = ob.get(l.id) || { id: l.id, at: l.at || null, state: 'proposed', title: '', ws: null, ini: null };
|
|
199
|
+
if (l.event === 'queued' || l.event === 'edited') { cur.title = one(l.text || l.title || l.subject || cur.title, 200); cur.ws = l.ws || cur.ws; cur.ini = l.initiative || l.ini || cur.ini; }
|
|
200
|
+
else if (l.event === 'sent') cur.state = 'sent';
|
|
201
|
+
else if (l.event === 'discarded') cur.state = 'dropped';
|
|
202
|
+
else if (l.event === 'restored') cur.state = 'proposed';
|
|
203
|
+
ob.set(l.id, cur);
|
|
204
|
+
}
|
|
205
|
+
for (const e of ob.values()) out.push({ at: e.at, line: 'project', station: 'Outbox', job: 'outbox', product: e.ws, ini: e.ini, ref: e.id, title: e.title, cls: 'C', by: 'agent',
|
|
206
|
+
state: e.state, source: [], sourced: null, joined: true, check: checkOf(e.ini) });
|
|
207
|
+
|
|
208
|
+
// the background runs: what each station spent (a run is one background agent session)
|
|
209
|
+
const runs = [];
|
|
210
|
+
for (const l of Array.isArray(input.bgQueue) ? input.bgQueue : []) if (isObj(l) && l.kind === 'done' && l.job) runs.push({ at: l.at || null, job: String(l.job), ini: l.ini || null, ws: l.ws || null });
|
|
211
|
+
|
|
212
|
+
out.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')));
|
|
213
|
+
return { rows: out, runs };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The station a background run's job spends for (lib/bg-queue.js JOBS ids). */
|
|
217
|
+
function stationOfRun(job) {
|
|
218
|
+
const j = String(job || '');
|
|
219
|
+
if (/driver/.test(j)) return { line: 'pm', station: 'Driver' };
|
|
220
|
+
if (/goal/.test(j)) return { line: 'pm', station: 'Goal loops' };
|
|
221
|
+
if (/team|role/.test(j)) return { line: 'pm', station: 'Role agents' };
|
|
222
|
+
if (/improve/.test(j)) return { line: 'pm', station: 'Lessons' };
|
|
223
|
+
if (/build|factory|verif/.test(j)) return { line: 'sdlc', station: 'Factory' };
|
|
224
|
+
if (/proposal|grill|lab|scan|outcome|doc|metric/.test(j)) return { line: 'pm', station: 'Proposals' };
|
|
225
|
+
return { line: 'project', station: 'Schedules' };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Per line and station over the last `days` days (today only when days is 1). */
|
|
229
|
+
function summary(R, runs = [], { now = Date.now(), days = 1 } = {}) {
|
|
230
|
+
const d = new Date(now);
|
|
231
|
+
const from = days <= 1 ? Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()) : now - days * DAY;
|
|
232
|
+
const inWin = (at) => { const t = ms(at); return t != null && t >= from && t <= now + 60000; };
|
|
233
|
+
const W = R.filter((r) => inWin(r.at));
|
|
234
|
+
const key = (line, station) => `${line}|${station}`;
|
|
235
|
+
const by = new Map();
|
|
236
|
+
const get = (line, station) => { const k = key(line, station); if (!by.has(k)) by.set(k, { line, station, changes: 0, applied: 0, kept: 0, undone: 0, ignored: 0, unsourced: 0, runs: 0 }); return by.get(k); };
|
|
237
|
+
for (const r of W) {
|
|
238
|
+
if (!r.line) continue;
|
|
239
|
+
const g = get(r.line, r.station);
|
|
240
|
+
g.changes++;
|
|
241
|
+
const self = r.by === 'agent' && (r.state === 'applied' || r.state === 'kept' || r.state === 'undone') && r.job !== 'outbox';
|
|
242
|
+
if (self) { g.applied++; if (!r.sourced) g.unsourced++; }
|
|
243
|
+
if (r.state === 'kept') g.kept++;
|
|
244
|
+
if (r.state === 'undone') g.undone++;
|
|
245
|
+
if (r.state === 'expired' || (r.state === 'proposed' && now - (ms(r.at) || now) > IGNORED_MS)) g.ignored++;
|
|
246
|
+
}
|
|
247
|
+
for (const u of runs) if (inWin(u.at)) { const s = stationOfRun(u.job); get(s.line, s.station).runs++; }
|
|
248
|
+
const lines = [...by.values()].sort((a, b) => LINES.indexOf(a.line) - LINES.indexOf(b.line) || b.changes - a.changes || a.station.localeCompare(b.station));
|
|
249
|
+
const self = W.filter((r) => r.by === 'agent' && ['applied', 'kept', 'undone'].includes(r.state) && r.job !== 'outbox');
|
|
250
|
+
const unsourced = self.filter((r) => !r.sourced).length;
|
|
251
|
+
return {
|
|
252
|
+
from: new Date(from).toISOString(), days,
|
|
253
|
+
lines,
|
|
254
|
+
total: W.length,
|
|
255
|
+
placed: W.filter((r) => r.line && r.station && r.state).length,
|
|
256
|
+
applied: self.length,
|
|
257
|
+
joined: self.filter((r) => r.joined).length,
|
|
258
|
+
unsourced,
|
|
259
|
+
unsourced_pct: self.length ? Math.round((unsourced / self.length) * 1000) / 10 : 0,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/* ── the read (no write) ── */
|
|
264
|
+
function linesOf(file) {
|
|
265
|
+
let text = '';
|
|
266
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
267
|
+
const out = [];
|
|
268
|
+
for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (isObj(l)) out.push(l); } catch { /* a torn line is skipped */ } }
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
271
|
+
/** Each initiative's outcome check date from its record (planning/initiatives or pmos/state/initiatives). */
|
|
272
|
+
function checksOf(root) {
|
|
273
|
+
const out = {};
|
|
274
|
+
for (const dir of [path.join(root, 'planning', 'initiatives'), path.join(root, 'pmos', 'state', 'initiatives')]) {
|
|
275
|
+
let names = [];
|
|
276
|
+
try { names = fs.readdirSync(dir).filter((n) => n.endsWith('.md')); } catch { continue; }
|
|
277
|
+
for (const n of names) {
|
|
278
|
+
let head = '';
|
|
279
|
+
try { head = fs.readFileSync(path.join(dir, n), 'utf8').slice(0, 6000); } catch { continue; }
|
|
280
|
+
const m = /^outcome_horizon:\s*["']?(\d{4}-\d{2}-\d{2})/m.exec(head);
|
|
281
|
+
const id = (/^id:\s*["']?([^"'\n]+)/m.exec(head) || [])[1] || n.slice(0, -3);
|
|
282
|
+
if (m && !out[id.trim()]) out[id.trim()] = m[1];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return out;
|
|
286
|
+
}
|
|
287
|
+
function read(root, { runtimeDir = null } = {}) {
|
|
288
|
+
const D = require('./driver.js');
|
|
289
|
+
const dir = D.stateDirOf(root);
|
|
290
|
+
const pick = (name) => [dir, runtimeDir].filter(Boolean).map((d) => path.join(d, name)).find((f) => fs.existsSync(f)) || null;
|
|
291
|
+
const ob = runtimeDir ? path.join(runtimeDir, 'outbox', 'outbox.jsonl') : null;
|
|
292
|
+
return {
|
|
293
|
+
stateDir: dir,
|
|
294
|
+
autonomy: dir ? linesOf(path.join(dir, 'autonomy.jsonl')) : [],
|
|
295
|
+
proposals: dir ? linesOf(path.join(dir, 'proposals.jsonl')) : [],
|
|
296
|
+
driver: dir ? linesOf(path.join(dir, 'driver.jsonl')) : [],
|
|
297
|
+
bgQueue: pick('bg-queue.jsonl') ? linesOf(pick('bg-queue.jsonl')) : [],
|
|
298
|
+
outbox: ob && fs.existsSync(ob) ? linesOf(ob) : [],
|
|
299
|
+
checks: checksOf(root),
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
module.exports = { rows, summary, read, placeOf, namedIn, checksOf, stationOfRun, LINES, LINE_NAMES, JOIN_MS, IGNORED_MS };
|
|
@@ -171,7 +171,8 @@ function take(dir, held, { dayLines = [], today = '', product = '', pm, now, env
|
|
|
171
171
|
...(facts.length ? { facts } : {}), why, default: true, batch });
|
|
172
172
|
}
|
|
173
173
|
const title = `Left the plan as it was on ${one(q.title, 80)}: ${plural(hs.length, 'change', 'changes')} nobody answered by ${md(dueDay)}`;
|
|
174
|
-
|
|
174
|
+
// its source is the owner's own question, unanswered by its deadline (the record counts it as sourced)
|
|
175
|
+
A.recordApplied(dir, { job: JOB, product, ref: batch, title, cls: 'B', ini: q.ini, why, src: [`Unanswered question, due ${dueDay}`] }, { now, settingsDir });
|
|
175
176
|
out.taken.push({ batch, ini: q.ini, board: q.board, ids: hs.map((h) => String(h.prop.id)), title });
|
|
176
177
|
}
|
|
177
178
|
return out;
|
|
@@ -140,8 +140,11 @@ async function autoApply({ file, proposal, actor, ctx = {}, now, stateDir, produ
|
|
|
140
140
|
const p = state.proposals.get(proposal);
|
|
141
141
|
if (!p || p.state !== 'open') return { applied: false, why: 'not open' };
|
|
142
142
|
const m = mode || D.modeOf(state, p.target.kind === 'work' ? 'work' : null);
|
|
143
|
-
|
|
144
|
-
const
|
|
143
|
+
// no source, no auto (A443): a Driver change that cites nothing is class C and waits for the PM
|
|
144
|
+
const cls = A.classOfDriverProposal(p);
|
|
145
|
+
const src = require('./source-guard.js').citedOf(p);
|
|
146
|
+
const d = A.decide({ stateDir, job: jobOf(p), product, cls, mode: m, undoable: UNDOABLE.has(p.what), now, settingsDir: ctx.settingsDir || null, sources: src });
|
|
147
|
+
if (!d.apply && !src.length) A.logHeld(jobOf(p), product, p.id);
|
|
145
148
|
if (!d.apply) return { applied: false, why: d.why, cls };
|
|
146
149
|
// board AwI: Intent is the PM's; Claude's change to it is a ✦ proposal on the product page and never applies by itself
|
|
147
150
|
if (p.what === 'artefact' && p.data && p.data.artefact === 'intent') return { applied: false, why: 'Intent is the PM\'s, so PMOS only proposes', cls };
|
|
@@ -155,7 +158,7 @@ async function autoApply({ file, proposal, actor, ctx = {}, now, stateDir, produ
|
|
|
155
158
|
// 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
|
|
156
159
|
const from = (p.sources || []).map((x) => x && x.label).filter(Boolean).slice(0, 3);
|
|
157
160
|
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,
|
|
158
|
-
why: from.length ? 'From ' + from.join(', ') : '', run: p.run || null }, { now, settingsDir: ctx.settingsDir || null });
|
|
161
|
+
why: from.length ? 'From ' + from.join(', ') : '', run: p.run || null, src: p.sources || [] }, { now, settingsDir: ctx.settingsDir || null });
|
|
159
162
|
return { applied: true, why: d.why, cls, wrote: r.wrote };
|
|
160
163
|
} catch (e) { return { applied: false, why: 'the apply failed: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
161
164
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* factory-cli.js — `pmos factory`: one view of everything PMOS changed by itself (initiative one-change-record-no-source-no-auto).
|
|
3
|
+
*
|
|
4
|
+
* pmos factory today [--days N] [--json] [--unsourced] [--root <dir>]
|
|
5
|
+
* Per line (product, project, SDLC) and station: changes, applied by PMOS, kept, undone, ignored, applied with no source, and
|
|
6
|
+
* background runs. --days 7 covers the last 7 days (default: today). --json prints the totals and the lines. --unsourced prints the
|
|
7
|
+
* percent of self-applied changes that cite no source as one number on the last line (the initiative's health number).
|
|
8
|
+
*
|
|
9
|
+
* Read-only: it folds the ledgers with lib/change-record.js and writes nothing. Exit codes: 0 done, 1 refused, 2 usage. */
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { execFileSync } = require('child_process');
|
|
12
|
+
const CR = require('./change-record.js');
|
|
13
|
+
|
|
14
|
+
const COMMANDS = { factory: ['today'] };
|
|
15
|
+
const USAGE = [
|
|
16
|
+
'usage: pmos factory today [--days N] [--json] [--unsourced] — everything PMOS changed by itself, in one record',
|
|
17
|
+
' pmos factory today per line and station: changes, applied, kept, undone, ignored, with no source, runs (today)',
|
|
18
|
+
' pmos factory today --days 7 the same over the last 7 days',
|
|
19
|
+
' pmos factory today --unsourced one number: the percent of changes PMOS applied by itself that cite no source',
|
|
20
|
+
'A change that cites no source never applies by itself: it waits for you (no source, no auto).',
|
|
21
|
+
];
|
|
22
|
+
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; };
|
|
23
|
+
function repoRoot(cwd) { try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; } catch { return cwd; } }
|
|
24
|
+
const pad = (s, n) => String(s).padEnd(n);
|
|
25
|
+
const num = (v, n = 6) => String(v).padStart(n);
|
|
26
|
+
|
|
27
|
+
function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), env = process.env, now = Date.now(), runtimeDir } = {}) {
|
|
28
|
+
const args = argv[0] === 'factory' ? argv.slice(1) : argv.slice();
|
|
29
|
+
const verb = args[0];
|
|
30
|
+
if (!verb || ['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return verb ? 0 : 2; }
|
|
31
|
+
if (!COMMANDS.factory.includes(verb)) { say(`unknown factory command "${verb}" — one of ${COMMANDS.factory.join(', ')}`); return 2; }
|
|
32
|
+
const d = flag(args, 'days');
|
|
33
|
+
const days = d === undefined ? 1 : Number(d);
|
|
34
|
+
if (!Number.isInteger(days) || days < 1 || days > 90) { say('--days is a whole number from 1 to 90'); return 2; }
|
|
35
|
+
const root = typeof flag(args, 'root') === 'string' ? path.resolve(cwd, flag(args, 'root')) : repoRoot(cwd);
|
|
36
|
+
let rt = runtimeDir;
|
|
37
|
+
if (rt === undefined) { try { rt = require('./state-root.js').defaultRoot({ env }); } catch { rt = null; } }
|
|
38
|
+
const input = CR.read(root, { runtimeDir: rt });
|
|
39
|
+
if (!input.stateDir) { say('✗ this repository has no PMOS state folder (pmos/state, state or .pmos)'); return 1; }
|
|
40
|
+
let ws = null; try { ws = require('./driver.js').wsIdOf(root); } catch { /* no id: every outbox draft counts */ }
|
|
41
|
+
if (ws) input.outbox = input.outbox.filter((l) => !l.ws || l.ws === ws);
|
|
42
|
+
const { rows, runs } = CR.rows(input, { now });
|
|
43
|
+
const S = CR.summary(rows, runs, { now, days });
|
|
44
|
+
if (flag(args, 'json')) { say(JSON.stringify({ ok: true, ...S })); return 0; }
|
|
45
|
+
if (flag(args, 'unsourced')) {
|
|
46
|
+
say(`${S.unsourced} of ${S.applied} changes PMOS applied by itself ${days === 1 ? 'today' : `in the last ${days} days`} cite no source`);
|
|
47
|
+
say(String(S.unsourced_pct));
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
say(`What PMOS changed ${days === 1 ? 'today' : `in the last ${days} days`}: ${S.total} ${S.total === 1 ? 'change' : 'changes'}, ${S.applied} applied by itself, ${S.unsourced} with no source (${S.unsourced_pct}%)`);
|
|
51
|
+
if (!S.lines.length) { say(' nothing yet'); return 0; }
|
|
52
|
+
say(' ' + pad('Line', 9) + pad('Station', 13) + ['changes', 'applied', 'kept', 'undone', 'ignored', 'no src', 'runs'].map((h) => h.padStart(8)).join(''));
|
|
53
|
+
for (const l of S.lines) say(' ' + pad(CR.LINE_NAMES[l.line] || l.line, 9) + pad(l.station, 13) + [l.changes, l.applied, l.kept, l.undone, l.ignored, l.unsourced, l.runs].map((v) => num(v, 8)).join(''));
|
|
54
|
+
if (S.applied) say(` ${S.joined} of ${S.applied} self-applied changes joined to where they came from`);
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -171,7 +171,12 @@ function lesson({ stateDir, root, ws, area, run, text, now = Date.now(), env = p
|
|
|
171
171
|
const st = L.fold(ledgerOf(stateDir));
|
|
172
172
|
if ([...st.fixes.values()].some((f) => f.source === run)) return { ok: false, error: 'this run already recorded its one lesson' };
|
|
173
173
|
const A = require('./autonomy.js');
|
|
174
|
-
|
|
174
|
+
// no source, no auto (A443): the lesson cites the signals of its area; with none it waits for the PM
|
|
175
|
+
const sigs = signals || signalsOf(stateDir);
|
|
176
|
+
const n = sigs.filter((s) => L.slug(s.area) === area).length;
|
|
177
|
+
const src = n ? [`${n} signals in ${area}`] : [];
|
|
178
|
+
const d = A.decide({ stateDir, job: JOB, product: ws, cls: 'B', undoable: true, now, env, sources: src });
|
|
179
|
+
if (d.nosrc) A.logHeld(JOB, ws, area);
|
|
175
180
|
const ref = 'im-' + crypto.createHash('sha256').update(`${ws}:${area}:${run}:${t}`).digest('hex').slice(0, 10);
|
|
176
181
|
if (!d.apply) {
|
|
177
182
|
append(stateDir, { ev: 'wawan', area, why: `a lesson waits for you (${d.why}): ${t}` }, now);
|
|
@@ -182,11 +187,9 @@ function lesson({ stateDir, root, ws, area, run, text, now = Date.now(), env = p
|
|
|
182
187
|
const stale = new Date(now + STALE_DAYS * L.DAY).toISOString().slice(0, 10);
|
|
183
188
|
const w = core.write(root, { op: 'add', text: t, by: 'agent:improve', source: `improve:${ref}`, stale_after: stale, confidence: 'unconfirmed' });
|
|
184
189
|
if (!w.ok) return { ok: false, error: w.error };
|
|
185
|
-
const sigs = signals || signalsOf(stateDir);
|
|
186
|
-
const n = sigs.filter((s) => L.slug(s.area) === area).length;
|
|
187
190
|
append(stateDir, { ev: 'fix', fix: ref, area, case: null, source: run, files: [] }, now);
|
|
188
191
|
append(stateDir, { ev: 'lesson', ref, area, text: t }, now);
|
|
189
|
-
A.recordApplied(stateDir, { job: JOB, product: ws, ref, title: `Learned: ${t}`, cls: 'B', why: `${n} signals in ${area}`, run }, { now });
|
|
192
|
+
A.recordApplied(stateDir, { job: JOB, product: ws, ref, title: `Learned: ${t}`, cls: 'B', why: `${n} signals in ${area}`, run, src }, { now });
|
|
190
193
|
return { ok: true, ref, applied: true };
|
|
191
194
|
}
|
|
192
195
|
function propose({ stateDir, ws, area, run, text, ini = null, now = Date.now() } = {}) {
|
|
@@ -143,6 +143,9 @@ const VERBS = Object.freeze({
|
|
|
143
143
|
help: 'pmos owner brief|budget — a unit owner\'s daily brief now, and its Driver runs a day (pmos owner help)' }),
|
|
144
144
|
driver: Object.freeze({ module: 'driver-cli.js', run: null, guide: 'cli.md',
|
|
145
145
|
help: 'pmos driver propose|status|keep|return|drop|undo|pause|resume|mode … — the Initiative Driver: class A and B changes apply with Undo, the rest wait for you (pmos driver help)' }),
|
|
146
|
+
// one-change-record-no-source-no-auto: everything PMOS changed by itself, in one record (lib/change-record.js)
|
|
147
|
+
factory: Object.freeze({ module: 'factory-cli.js', run: null, guide: 'cli.md',
|
|
148
|
+
help: 'pmos factory today [--days N] — everything PMOS changed by itself, per line and station, with what cites no source (pmos factory help)' }),
|
|
146
149
|
// D106 (Full autonomy now): what agents do by themselves, and the goals they work on until done
|
|
147
150
|
autonomy: Object.freeze({ module: 'autonomy-cli.js', run: null, guide: 'cli.md',
|
|
148
151
|
help: 'pmos autonomy status|restore — what agents applied by themselves (with Undo) and the jobs back to propose (pmos autonomy help)' }),
|
|
@@ -537,7 +537,11 @@ function viewOf(F, ini, o = {}) {
|
|
|
537
537
|
const grillHidden = o.grillAll ? [] : grill.slice(GRILL_SHOWN).map((p) => ({ id: p.id, group: 'grill', type: p.type, title: p.title, why: p.why, at: p.at, sig: p.sig, sources: p.sources, data: p.data, items: [] }));
|
|
538
538
|
if (!o.grillAll) for (const p of grill.slice(GRILL_SHOWN)) props.splice(props.indexOf(p), 1);
|
|
539
539
|
if (today != null) for (const p of datesOf(ini, T, { today, filed: [...F.props.values()].filter((x) => x.group === 'dates' && x.ini === ini), stages: o.stages, links: o.links, settle: o.settle, drops: F.drops })) if (!kept.has(p.id + ':' + p.sig)) props.push(p);
|
|
540
|
-
|
|
540
|
+
// one-change-record-no-source-no-auto: a link cites where it was read (the PRD line, a Jira dependency); a link guessed from the plan's
|
|
541
|
+
// order or from two dates that meet cites nothing, so lib/source-guard.js holds it for the PM instead of adding it by itself
|
|
542
|
+
const SG = require('./source-guard.js');
|
|
543
|
+
for (const lp of o.linkProps || []) props.push({ id: 'lk:' + lp.id, group: 'links', type: lp.kind, section: 'sure', link: lp, title: '', why: lp.why || '',
|
|
544
|
+
sources: SG.LINK_SOURCES[lp.source] ? [{ label: SG.LINK_SOURCES[lp.source], ref: String(lp.why || '').slice(0, 300) }] : [], items: [] });
|
|
541
545
|
// ✕ on one item drops that item for good: the page sends its signature
|
|
542
546
|
for (const p of props) if (p.group !== 'links') p.items = p.items.map((x) => ({ ...x, sig: itemSig(p, x) }));
|
|
543
547
|
props.sort((a, b) => ORDER[a.group] - ORDER[b.group] || (a.group === 'grill' ? ((a.data && a.data.rank) || 5) - ((b.data && b.data.rank) || 5) : 0) || (a.section === 'sure' ? 0 : a.section === 'check' ? 1 : 2) - (b.section === 'sure' ? 0 : b.section === 'check' ? 1 : 2));
|
|
@@ -154,6 +154,7 @@ function undoCore(ctx, p, g, id) {
|
|
|
154
154
|
* mode is not auto stay for the PM. → { applied: [{ ini, batch, group, title }], held: n } */
|
|
155
155
|
function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
|
|
156
156
|
const A = require('./autonomy.js');
|
|
157
|
+
const SGc = require('./source-guard.js');
|
|
157
158
|
const dir = dirOf(ctx, w);
|
|
158
159
|
const out = { applied: [], held: 0 };
|
|
159
160
|
if (!dir) return out;
|
|
@@ -170,12 +171,14 @@ function autoKeep(ctx, w, { modeOf = () => 'auto', now } = {}) {
|
|
|
170
171
|
if (!v) continue;
|
|
171
172
|
for (const x of v.groups.flatMap((gr) => gr.props)) {
|
|
172
173
|
const cls = A.classOfProposal(x);
|
|
173
|
-
const
|
|
174
|
+
const src = SGc.citedOf(x); // no source, no auto (A443), in every group
|
|
175
|
+
const d = A.decide({ stateDir: dir, job: `propose:${x.group}`, product: w.id, cls, mode: modeOf(board.id), undoable: true, now, settingsDir: ctx.runtimeDir || null, sources: src });
|
|
176
|
+
if (!d.apply && !src.length) A.logHeld(`propose:${x.group}`, w.id, x.id);
|
|
174
177
|
if (!d.apply) { out.held++; continue; }
|
|
175
178
|
try {
|
|
176
179
|
const r = keepCore(ctx, p, g, f, ini, [x], {}, { auto: true, group: x.group });
|
|
177
180
|
if (!r.keptIds.length) { out.held++; continue; } // nothing landed (a verdict no longer due, a pull request not opened): nothing to list
|
|
178
|
-
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 });
|
|
181
|
+
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 : '', src }, { now, settingsDir: ctx.runtimeDir || null });
|
|
179
182
|
out.applied.push({ ini, batch: r.batch, group: x.group, title: x.title || x.why || '' });
|
|
180
183
|
} catch { out.held++; }
|
|
181
184
|
}
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* kindsOf(p) → [kind] the different kinds of source a proposal cites, e.g. ['jira', 'meeting']
|
|
7
7
|
* kindOf(text) → kind the kind of one source label or ref
|
|
8
8
|
* bigOf(p) → '' | 'close' | 'rename' | 'date' a change that needs two kinds of source
|
|
9
|
+
* citedOf(x) → [label] what ANY agent change cites (one-change-record-no-source-no-auto): its sources, its items'
|
|
10
|
+
* sources, its claims' sources, a link's PRD or Jira source, a build's work item. [] = no source
|
|
11
|
+
* noReason(why) → bool a reason that says it has none ("No reason found") or is empty
|
|
9
12
|
*
|
|
10
13
|
* THE RULE. It applies to the plan changes on a product: the groups in PLAN (dates, status, names, found, links).
|
|
11
14
|
* 1. No source, or a date proposal that found no reason (`noReason`): held.
|
|
@@ -76,4 +79,26 @@ function holdOf(p) {
|
|
|
76
79
|
return null;
|
|
77
80
|
}
|
|
78
81
|
|
|
79
|
-
|
|
82
|
+
/* ── no source, no auto, in every job kind (initiative one-change-record-no-source-no-auto; idea A443) ──
|
|
83
|
+
* #1440 holds the plan groups above. This widens the one question "does the change cite anything?" to every change an agent makes:
|
|
84
|
+
* a ✦ proposal of any group, an Initiative Driver proposal, a default, a role agent's write. lib/autonomy.js makes a change that cites
|
|
85
|
+
* nothing class C, so it waits for the PM like a change others see. A link's own source (lib/task-links.js proposalsOf) counts when it
|
|
86
|
+
* names where the link was read (the PRD, a Jira dependency, a teammate's link); a link inferred from the plan's order or from two dates
|
|
87
|
+
* that meet is a guess and cites nothing. */
|
|
88
|
+
const LINK_SOURCES = { prd: 'PRD', jira: 'Jira', you: 'You' };
|
|
89
|
+
const NO_REASON = /^\s*(no reason( found)?|none|n\/a|-)?\s*\.?\s*$/i;
|
|
90
|
+
const noReason = (why) => NO_REASON.test(String(why == null ? '' : why));
|
|
91
|
+
function citedOf(x) {
|
|
92
|
+
if (!isObj(x)) return [];
|
|
93
|
+
const out = [];
|
|
94
|
+
const add = (s) => { if (isObj(s)) { const t = [s.label, s.ref].filter((v) => typeof v === 'string' && v.trim()).join(' '); if (t) out.push(t); } else if (typeof s === 'string' && s.trim()) out.push(s); };
|
|
95
|
+
for (const s of Array.isArray(x.sources) ? x.sources : []) add(s);
|
|
96
|
+
for (const it of Array.isArray(x.items) ? x.items : []) if (isObj(it) && it.source) add(String(it.source));
|
|
97
|
+
for (const c of Array.isArray(x.claims) ? x.claims : []) for (const s of (isObj(c) && Array.isArray(c.sources) ? c.sources : [])) add(s);
|
|
98
|
+
if (isObj(x.link) && LINK_SOURCES[x.link.source]) add({ label: LINK_SOURCES[x.link.source], ref: x.link.why || '' });
|
|
99
|
+
if (x.group === 'build' && isObj(x.data) && typeof x.data.item === 'string' && x.data.item) add({ label: 'Work item', ref: x.data.item });
|
|
100
|
+
if (x.noReason === true) return [];
|
|
101
|
+
return [...new Set(out)];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = { citedOf, noReason, LINK_SOURCES, holdOf, kindsOf, kindOf, bigOf, shiftOf, PLAN, BIG_DAYS, KIND_NAMES };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.691.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.691.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/sdk": "^1.3.0",
|
package/workspace/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "One record of every agent change, and no source, no auto (initiative one-change-record-no-source-no-auto, done test C1-C12): the source rule in every job kind, the read-only fold of the change ledgers, and pmos factory today. Pure checks plus a kit-layout fixture in a temp folder. No connector, model or network.",
|
|
3
|
+
"modules": [
|
|
4
|
+
"change-record.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"change-record.test.js": 5
|
|
8
|
+
}
|
|
9
|
+
}
|