create-pmos 0.302.0 → 0.303.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 +1 -1
- 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/lib/driver-run.js +8 -1
- package/workspace/lib/orchestrator-gate.js +62 -0
- package/workspace/lib/orchestrator-health.js +36 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-orchestrator.js +37 -0
- package/workspace/lib/state-backup.js +102 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/server.js +30 -2
- package/workspace/test-lists/agent-orchestrator-b.json +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.303.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": {
|
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-10-19T07:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-19T07:23:01Z"}
|
|
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-10-19T07:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-19T07:23:01Z"}
|
|
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-10-19T07:
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-10-19T07:23:01Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -190,7 +190,14 @@ function create(deps) {
|
|
|
190
190
|
let live = active.size;
|
|
191
191
|
for (const group of p.start) {
|
|
192
192
|
if (live >= D.BUDGET.concurrent) break;
|
|
193
|
+
// agent-orchestrator: the capacity governor may hold a start (stopped, machine busy, PM working, daily cap). The wakes stay queued, as for the login hold.
|
|
194
|
+
if (deps.mayStart) {
|
|
195
|
+
let g = { allowed: true };
|
|
196
|
+
try { g = deps.mayStart({ running: live }) || g; } catch (e) { warn('driver gate', e); }
|
|
197
|
+
if (!g.allowed) { summary.held = g.reason || 'the capacity governor'; break; }
|
|
198
|
+
}
|
|
193
199
|
startRun(w, file, group, state, factsNow, now);
|
|
200
|
+
if (deps.started) { try { deps.started(); } catch { /* a counter */ } }
|
|
194
201
|
live = active.size; summary.started++;
|
|
195
202
|
}
|
|
196
203
|
} catch (e) { warn('driver tick', e); }
|
|
@@ -198,7 +205,7 @@ function create(deps) {
|
|
|
198
205
|
return summary;
|
|
199
206
|
}
|
|
200
207
|
|
|
201
|
-
return { tick, active: () => [...active.keys()] };
|
|
208
|
+
return { tick, active: () => [...active.keys()], loginHeld: (now = Date.now()) => !!(loginFailedAt && now - loginFailedAt < LOGIN_HOLD_MS) };
|
|
202
209
|
}
|
|
203
210
|
|
|
204
211
|
module.exports = { create, off, dayCheckOpen, loginFailure, LOGIN_HOLD_MS };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* orchestrator-gate.js — the one question "may the orchestrator start another run now", answered from the machine and the PM's files
|
|
3
|
+
* (initiative agent-orchestrator, PRD "Capacity governor"). It joins lib/capacity-governor.js (the rule), lib/orchestrator-ledger.js (the
|
|
4
|
+
* stop switch) and the PM's settings file; the server hands it to the Initiative Driver and to the status route.
|
|
5
|
+
*
|
|
6
|
+
* create({ dir, now?, load?, quota?, bootAt? }) → gate
|
|
7
|
+
* gate.touch(at?) the PM did something (a key in a terminal, a page press): the work-hours mode needs this
|
|
8
|
+
* gate.mayStart({ running }) → the governor's answer { allowed, mode, cap, reason }, with the day's count and the stop switch read in
|
|
9
|
+
* gate.granted(at?) a start was made: it counts toward today's cap
|
|
10
|
+
* gate.status({ running }) → { stopped, mode, cap, allowed, reason, running, startedToday, settings, lastActivityAt }
|
|
11
|
+
* gate.settings() · gate.backupDir() → the governor's settings (defaults for what the file leaves out) · the nightly backup destination or null
|
|
12
|
+
* gate.setStopped(stopped, actor) the stop switch
|
|
13
|
+
*
|
|
14
|
+
* STATE: <dir>/orchestrator.json the PM's settings, written by the PM only: { v: 1, settings: {…governor keys}, backupDir? }
|
|
15
|
+
* <dir>/orchestrator-day.json { day, count }: runs started today, kept on disk so a restart does not reset the daily cap
|
|
16
|
+
* <dir>/orchestrator-stop.json the stop switch (lib/orchestrator-ledger.js)
|
|
17
|
+
* An unreadable or invalid settings file means the defaults, and the status says so. QUOTA: the Claude CLI shows no usage figure this
|
|
18
|
+
* module can read, so `quota` is null unless the caller supplies one; the daily cap is the backstop then (PRD: never unlimited). */
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const G = require('./capacity-governor.js');
|
|
22
|
+
const L = require('./orchestrator-ledger.js');
|
|
23
|
+
|
|
24
|
+
const localDay = (ms) => { const d = new Date(ms); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; };
|
|
25
|
+
const readJson = (f) => { try { return JSON.parse(fs.readFileSync(f, 'utf8')); } catch { return null; } };
|
|
26
|
+
|
|
27
|
+
function create({ dir, now = Date.now, load = () => ({ memFreeFrac: G.memFreeFrac(), cpuPerCore: G.cpuPerCore() }), quota = () => null, bootAt } = {}) {
|
|
28
|
+
let lastActivityAt = Number.isFinite(bootAt) ? bootAt : now(); // a restart counts as the PM being here: the safer mode
|
|
29
|
+
const cfgFile = path.join(dir, 'orchestrator.json'), dayFile = path.join(dir, 'orchestrator-day.json');
|
|
30
|
+
|
|
31
|
+
function config() {
|
|
32
|
+
const raw = readJson(cfgFile);
|
|
33
|
+
if (raw === null) return { settings: { ...G.DEFAULTS }, backupDir: null, problem: null };
|
|
34
|
+
const n = G.normalize(raw && raw.settings);
|
|
35
|
+
return { settings: n.ok ? n.settings : { ...G.DEFAULTS }, backupDir: raw && typeof raw.backupDir === 'string' && raw.backupDir.trim() ? raw.backupDir.trim() : null,
|
|
36
|
+
problem: n.ok ? null : `orchestrator.json is not valid (${n.error}); the defaults apply` };
|
|
37
|
+
}
|
|
38
|
+
function startedToday(t) { const d = readJson(dayFile); return d && d.day === localDay(t) && Number.isInteger(d.count) ? d.count : 0; }
|
|
39
|
+
function safeLoad() { try { return load(); } catch { return null; } }
|
|
40
|
+
function safeQuota() { try { return quota(); } catch { return null; } }
|
|
41
|
+
|
|
42
|
+
function mayStart({ running = 0 } = {}) {
|
|
43
|
+
const t = now();
|
|
44
|
+
return G.decide({ now: t, lastActivityAt, settings: config().settings, running, startedToday: startedToday(t), load: safeLoad(), quota: safeQuota(), stopped: L.isStopped(dir) });
|
|
45
|
+
}
|
|
46
|
+
function granted(at = now()) {
|
|
47
|
+
try { fs.mkdirSync(dir, { recursive: true }); fs.writeFileSync(dayFile, JSON.stringify({ day: localDay(at), count: startedToday(at) + 1 }) + '\n'); } catch { /* the cap is a backstop; a failed write must not stop a run that already started */ }
|
|
48
|
+
}
|
|
49
|
+
function status({ running = 0 } = {}) {
|
|
50
|
+
const t = now(), c = config(), d = mayStart({ running });
|
|
51
|
+
return { stopped: L.isStopped(dir), mode: d.mode, cap: d.cap, allowed: d.allowed, reason: d.reason, running, startedToday: startedToday(t), settings: c.settings,
|
|
52
|
+
settingsProblem: c.problem, backupDir: c.backupDir, lastActivityAt };
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
touch: (at = now()) => { lastActivityAt = at; },
|
|
56
|
+
mayStart, granted, status,
|
|
57
|
+
settings: () => config().settings, backupDir: () => config().backupDir,
|
|
58
|
+
setStopped: (stopped, actor) => L.setStopped(dir, stopped, actor, now()),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { create, localDay };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* orchestrator-health.js — what is wrong with the machine the orchestrator works on, in words (initiative agent-orchestrator, PRD "Keeping the Mac mini up").
|
|
3
|
+
*
|
|
4
|
+
* rows({ now, stopped, lastTickAt, tickMs, diskFreeFrac, loginHeld, backup }) → [{ id, level: 'warn' | 'bad', text }]
|
|
5
|
+
* diskFreeFrac(dir) → 0..1 | null the free share of the disk that holds `dir`
|
|
6
|
+
*
|
|
7
|
+
* Only a problem is a row: a healthy machine returns []. `backup` = { configured, lastOkAt, lastError } from lib/state-backup.js.
|
|
8
|
+
* Pure but for diskFreeFrac. The Briefing and the status route show these rows; no row starts or stops anything. */
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
|
|
11
|
+
const HOUR = 3600 * 1000;
|
|
12
|
+
|
|
13
|
+
function rows({ now = Date.now(), stopped = false, lastTickAt = null, tickMs = 60000, diskFreeFrac = null, loginHeld = false, backup = null } = {}) {
|
|
14
|
+
const out = [];
|
|
15
|
+
if (stopped) out.push({ id: 'stopped', level: 'warn', text: 'The orchestrator is stopped. Nothing new starts until you press Resume.' });
|
|
16
|
+
if (!stopped && lastTickAt !== null && now - lastTickAt > Math.max(5 * tickMs, 5 * 60000)) {
|
|
17
|
+
out.push({ id: 'tick', level: 'bad', text: `The workspace has not run its background tick for ${Math.round((now - lastTickAt) / 60000)} minutes.` });
|
|
18
|
+
}
|
|
19
|
+
if (loginHeld) out.push({ id: 'login', level: 'bad', text: 'Claude is signed out on this computer, so background runs are on hold. Sign in again with /login in a workspace terminal.' });
|
|
20
|
+
if (Number.isFinite(diskFreeFrac)) {
|
|
21
|
+
if (diskFreeFrac < 0.05) out.push({ id: 'disk', level: 'bad', text: `The disk is almost full (${Math.round(diskFreeFrac * 100)}% free).` });
|
|
22
|
+
else if (diskFreeFrac < 0.15) out.push({ id: 'disk', level: 'warn', text: `The disk is getting full (${Math.round(diskFreeFrac * 100)}% free).` });
|
|
23
|
+
}
|
|
24
|
+
if (backup) {
|
|
25
|
+
if (!backup.configured) out.push({ id: 'backup', level: 'warn', text: 'The nightly backup has no destination yet. Choose a folder outside this one (an external disk or a synced folder).' });
|
|
26
|
+
else if (backup.lastError) out.push({ id: 'backup', level: 'bad', text: `The last backup failed: ${backup.lastError}` });
|
|
27
|
+
else if (!Number.isFinite(backup.lastOkAt) || now - backup.lastOkAt > 36 * HOUR) out.push({ id: 'backup', level: 'bad', text: 'There has been no good backup in over 36 hours.' });
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function diskFreeFrac(dir) {
|
|
33
|
+
try { const s = fs.statfsSync(dir); return s.blocks > 0 ? s.bavail / s.blocks : null; } catch { return null; }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { rows, diskFreeFrac };
|
|
@@ -77,6 +77,7 @@ const MODULES = Object.freeze([
|
|
|
77
77
|
'routes-meeting-replay', // meeting-material-replay: the note, the Focus state and the shots joined for the Replay page (GET, read-only)
|
|
78
78
|
'routes-meeting-material', // meeting-material-replay: the material the PM links to a meeting (GET list and suggest; page-press POST add and remove; meeting-material.jsonl)
|
|
79
79
|
'routes-stage-tools', // stage-tools-records: the records the PM edits per stage, what PMOS holds per stage, the sprint burndown
|
|
80
|
+
'routes-orchestrator', // agent-orchestrator: the status of the capacity governor and the PM's stop switch (orchestrator-stop.json)
|
|
80
81
|
'routes-driver', // initiative-driver: the Agent strip's data, Keep, Send back, Drop, Pause and the board mode (driver.jsonl)
|
|
81
82
|
'routes-scan', // horizon-scan-portfolio: one scan for the workspace: the watch list and setting, Scan now and Stop, report documents and their proposals (approve, change, dismiss, undo), plus the first scan's per-board and Briefing reads (scan.jsonl)
|
|
82
83
|
'routes-report-setups', // report-workspace: recurring reports, the Ask box, the finder, the report documents and their export (report-setups.jsonl)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-orchestrator.js — the orchestrator's status and stop switch (initiative agent-orchestrator, PRD "Gates that stay yours").
|
|
3
|
+
*
|
|
4
|
+
* GET /api/orchestrator → { ok, stopped, mode, cap, allowed, reason, running, startedToday, settings, settingsProblem, backupDir, health: [{ id, level, text }] }
|
|
5
|
+
* POST /api/orchestrator/stop → { ok, stopped: true }
|
|
6
|
+
* POST /api/orchestrator/resume → { ok, stopped: false }
|
|
7
|
+
*
|
|
8
|
+
* The GET changes nothing. Both POSTs pass pm-guard requirePagePress, and a request that carries an agent session header is refused
|
|
9
|
+
* first: an agent cannot start the orchestrator again after the PM stopped it, and cannot stop it either. The stop switch is a file
|
|
10
|
+
* (lib/orchestrator-ledger.js); the tick reads it before every start. `ctx.orchestrator` is { gate, running(), health() } from server.js. */
|
|
11
|
+
const guard = require('./pm-guard.js');
|
|
12
|
+
const actorLib = require('./actor.js');
|
|
13
|
+
|
|
14
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
15
|
+
|
|
16
|
+
async function handle(req, res, url, ctx) {
|
|
17
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
18
|
+
const o = ctx.orchestrator;
|
|
19
|
+
if (!o || !o.gate) return send(bad(503, 'the orchestrator is not running in this workspace'));
|
|
20
|
+
const sub = url.pathname.replace(/^\/api\/orchestrator\/?/, '');
|
|
21
|
+
|
|
22
|
+
if (sub === '') {
|
|
23
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
24
|
+
return send({ status: 200, body: { ok: true, ...o.gate.status({ running: o.running() }), health: o.health() } });
|
|
25
|
+
}
|
|
26
|
+
if (sub !== 'stop' && sub !== 'resume') return send(bad(404, 'no such orchestrator route'));
|
|
27
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
28
|
+
const read = await ctx.readJson(req);
|
|
29
|
+
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
30
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot stop or resume the orchestrator'));
|
|
31
|
+
const g = guard.requirePagePress(req, read.body);
|
|
32
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
33
|
+
const r = o.gate.setStopped(sub === 'stop', actorLib.pageName ? actorLib.pageName(g.actor) : 'pm');
|
|
34
|
+
return send({ status: 200, body: { ok: true, stopped: r.stopped } });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { prefixes: ['/api/orchestrator'], handle };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* state-backup.js — the nightly copy of the workspace state folder (initiative agent-orchestrator, PRD "Keeping the Mac mini up").
|
|
3
|
+
*
|
|
4
|
+
* run({ src, dest, now?, keep? }) → { ok, day, files, bytes, pruned: [day] } | { ok: false, error }
|
|
5
|
+
* restore({ dest, day, target }) → { ok, files } | { ok: false, error }
|
|
6
|
+
* due({ now, lastOkAt, hour? }) → boolean once per local day, from `hour` (default 02:00)
|
|
7
|
+
* days(dest) → the dated folders there, oldest first
|
|
8
|
+
* readLog(src) · logTo(src, row) → <src>/backup-log.jsonl: { at, ok, day?, files?, bytes?, error? }; the last row feeds the health check
|
|
9
|
+
*
|
|
10
|
+
* WHAT IS COPIED: the small state files (.json .jsonl .md .txt) under `src`, to <dest>/<YYYY-MM-DD>/, with a manifest.json of what was
|
|
11
|
+
* copied. Terminal buffers, sockets, caches and anything whose name looks like a secret (token, secret, key, nonce, credential, password)
|
|
12
|
+
* are left out: a backup that copies the PM's keys to a second place is worse than none. A copy is checked by reading it back (file count and
|
|
13
|
+
* bytes against the manifest) before the run says ok, and only then are days beyond the newest `keep` (default 7) removed.
|
|
14
|
+
* `dest` must be outside `src`. Nothing is sent over a network; the PM chooses the folder. */
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
|
|
18
|
+
const KEEP_EXT = /\.(jsonl?|md|txt)$/i;
|
|
19
|
+
const SKIP_NAME = /(token|secret|key|nonce|credential|password|\.sock$|buffer|cache|node_modules|\.git$)/i;
|
|
20
|
+
const MAX_FILE = 50 * 1024 * 1024;
|
|
21
|
+
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
22
|
+
const LOG = 'backup-log.jsonl';
|
|
23
|
+
const localDay = (ms) => { const d = new Date(ms); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; };
|
|
24
|
+
const inside = (child, parent) => { const r = path.relative(path.resolve(parent), path.resolve(child)); return r === '' || (!r.startsWith('..') && !path.isAbsolute(r)); };
|
|
25
|
+
|
|
26
|
+
function listFiles(root) {
|
|
27
|
+
const out = [];
|
|
28
|
+
(function walk(d) {
|
|
29
|
+
let ents; try { ents = fs.readdirSync(d, { withFileTypes: true }); } catch { return; }
|
|
30
|
+
for (const e of ents) {
|
|
31
|
+
if (SKIP_NAME.test(e.name)) continue;
|
|
32
|
+
const p = path.join(d, e.name);
|
|
33
|
+
if (e.isDirectory()) walk(p);
|
|
34
|
+
else if (e.isFile() && KEEP_EXT.test(e.name)) { try { if (fs.statSync(p).size <= MAX_FILE) out.push(p); } catch { /* vanished */ } }
|
|
35
|
+
}
|
|
36
|
+
})(root);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function totals(root) { const fl = listFiles(root); return { files: fl.length, bytes: fl.reduce((n, f) => { try { return n + fs.statSync(f).size; } catch { return n; } }, 0) }; }
|
|
40
|
+
|
|
41
|
+
function days(dest) { try { return fs.readdirSync(dest).filter((n) => DAY_RE.test(n)).sort(); } catch { return []; } }
|
|
42
|
+
|
|
43
|
+
function run({ src, dest, now = Date.now(), keep = 7 } = {}) {
|
|
44
|
+
if (!src || !dest) return { ok: false, error: 'a source and a destination are needed' };
|
|
45
|
+
if (inside(dest, src)) return { ok: false, error: 'the destination is inside the state folder; choose a folder outside it' };
|
|
46
|
+
if (!fs.existsSync(src)) return { ok: false, error: 'the state folder is missing' };
|
|
47
|
+
const day = localDay(now), out = path.join(dest, day), tmp = path.join(dest, `.${day}.partial`);
|
|
48
|
+
try {
|
|
49
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
50
|
+
fs.mkdirSync(tmp, { recursive: true });
|
|
51
|
+
const files = listFiles(src);
|
|
52
|
+
for (const f of files) {
|
|
53
|
+
const to = path.join(tmp, path.relative(src, f));
|
|
54
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
55
|
+
fs.copyFileSync(f, to);
|
|
56
|
+
}
|
|
57
|
+
const copied = totals(tmp);
|
|
58
|
+
const want = files.reduce((n, f) => { try { return n + fs.statSync(f).size; } catch { return n; } }, 0);
|
|
59
|
+
if (copied.files !== files.length || copied.bytes !== want) throw new Error(`the copy does not match: ${copied.files} of ${files.length} files, ${copied.bytes} of ${want} bytes`);
|
|
60
|
+
fs.writeFileSync(path.join(tmp, 'manifest.json'), JSON.stringify({ v: 1, at: new Date(now).toISOString(), files: files.length, bytes: want }) + '\n');
|
|
61
|
+
fs.rmSync(out, { recursive: true, force: true });
|
|
62
|
+
fs.renameSync(tmp, out);
|
|
63
|
+
const all = days(dest), old = all.slice(0, Math.max(0, all.length - Math.max(1, keep)));
|
|
64
|
+
for (const d of old) fs.rmSync(path.join(dest, d), { recursive: true, force: true });
|
|
65
|
+
return { ok: true, day, files: files.length, bytes: want, pruned: old };
|
|
66
|
+
} catch (e) {
|
|
67
|
+
try { fs.rmSync(tmp, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
68
|
+
return { ok: false, error: String((e && e.message) || e).slice(0, 300) };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function restore({ dest, day, target } = {}) {
|
|
73
|
+
if (!dest || !target) return { ok: false, error: 'a backup folder and a target are needed' };
|
|
74
|
+
const d = day || days(dest).pop();
|
|
75
|
+
if (!d || !DAY_RE.test(d) || !fs.existsSync(path.join(dest, d))) return { ok: false, error: 'there is no such backup day' };
|
|
76
|
+
const from = path.join(dest, d);
|
|
77
|
+
let n = 0;
|
|
78
|
+
(function walk(dir) {
|
|
79
|
+
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
80
|
+
const p = path.join(dir, e.name);
|
|
81
|
+
if (e.isDirectory()) walk(p);
|
|
82
|
+
else if (e.name !== 'manifest.json') { const to = path.join(target, path.relative(from, p)); fs.mkdirSync(path.dirname(to), { recursive: true }); fs.copyFileSync(p, to); n++; }
|
|
83
|
+
}
|
|
84
|
+
})(from);
|
|
85
|
+
return { ok: true, files: n };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function due({ now = Date.now(), lastOkAt = null, hour = 2 } = {}) {
|
|
89
|
+
if (new Date(now).getHours() < hour) return false;
|
|
90
|
+
return !Number.isFinite(lastOkAt) || localDay(lastOkAt) !== localDay(now);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function logTo(src, row) { try { fs.appendFileSync(path.join(src, LOG), JSON.stringify(row) + '\n'); } catch { /* the log is informational */ } }
|
|
94
|
+
function readLog(src) {
|
|
95
|
+
try {
|
|
96
|
+
const rows = fs.readFileSync(path.join(src, LOG), 'utf8').split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean);
|
|
97
|
+
const lastOk = rows.filter((r) => r.ok).pop(), last = rows.pop() || null;
|
|
98
|
+
return { lastOkAt: lastOk ? Date.parse(lastOk.at) : null, lastError: last && !last.ok ? last.error : null };
|
|
99
|
+
} catch { return { lastOkAt: null, lastError: null }; }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
module.exports = { run, restore, due, days, logTo, readLog, listFiles, localDay, inside };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.303.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.303.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
package/workspace/server.js
CHANGED
|
@@ -2581,7 +2581,12 @@ const dashboardScheduleTick = () => {
|
|
|
2581
2581
|
};
|
|
2582
2582
|
// initiative-driver: the driver wakes on a creation, a move or a note, sweeps for blockers every 30 minutes inside the day-check
|
|
2583
2583
|
// window, and starts its short headless runs. Everything it decides is in lib/driver.js; this only hands it the server's parts.
|
|
2584
|
+
// agent-orchestrator: the capacity governor in front of every run the orchestrator may start. The Driver asks it before each start; the status route reads it.
|
|
2585
|
+
// PMOS_TICK_MS is the suites' fast clock: a suite runs beside forty others, so the machine-load check is skipped there (the rest of the gate applies).
|
|
2586
|
+
const orchGate = require('./lib/orchestrator-gate.js').create({ dir: STATE, ...(process.env.PMOS_TICK_MS ? { load: () => null } : {}) });
|
|
2584
2587
|
const driver = driverRunLib.create({
|
|
2588
|
+
mayStart: ({ running }) => orchGate.mayStart({ running }),
|
|
2589
|
+
started: () => orchGate.granted(),
|
|
2585
2590
|
workspaces: () => [...workspaces.values()],
|
|
2586
2591
|
isLead: (w) => isPlanNeedsTree(w),
|
|
2587
2592
|
stateDirFor: (w) => stateDirFor(w),
|
|
@@ -2598,6 +2603,27 @@ const driver = driverRunLib.create({
|
|
|
2598
2603
|
warn: (what, e) => warnWriteFail(what, e),
|
|
2599
2604
|
});
|
|
2600
2605
|
const driverTick = () => { try { driver.tick({}); } catch (e) { warnWriteFail('driver tick', e); } };
|
|
2606
|
+
// agent-orchestrator: the health rows (lib/orchestrator-health.js) and the nightly backup of the state folder (lib/state-backup.js, only when the PM has chosen a destination).
|
|
2607
|
+
let orchLastTickAt = null, orchBackupRunning = false;
|
|
2608
|
+
const orchHealth = () => {
|
|
2609
|
+
const backupLib = require('./lib/state-backup.js'), log = backupLib.readLog(STATE);
|
|
2610
|
+
return require('./lib/orchestrator-health.js').rows({ now: Date.now(), stopped: orchGate.status({}).stopped, lastTickAt: orchLastTickAt, tickMs: TICK_MS,
|
|
2611
|
+
diskFreeFrac: require('./lib/orchestrator-health.js').diskFreeFrac(STATE), loginHeld: driver.loginHeld(),
|
|
2612
|
+
backup: { configured: !!orchGate.backupDir(), lastOkAt: log.lastOkAt, lastError: log.lastError } });
|
|
2613
|
+
};
|
|
2614
|
+
const orchTick = () => {
|
|
2615
|
+
orchLastTickAt = Date.now();
|
|
2616
|
+
try {
|
|
2617
|
+
const dest = orchGate.backupDir();
|
|
2618
|
+
if (!dest || orchBackupRunning) return;
|
|
2619
|
+
const backupLib = require('./lib/state-backup.js');
|
|
2620
|
+
if (orchGate.status({}).mode !== 'away' || !backupLib.due({ now: Date.now(), lastOkAt: backupLib.readLog(STATE).lastOkAt })) return;
|
|
2621
|
+
orchBackupRunning = true;
|
|
2622
|
+
const r = backupLib.run({ src: STATE, dest, now: Date.now() });
|
|
2623
|
+
backupLib.logTo(STATE, r.ok ? { at: new Date().toISOString(), ok: true, day: r.day, files: r.files, bytes: r.bytes } : { at: new Date().toISOString(), ok: false, error: r.error });
|
|
2624
|
+
orchBackupRunning = false;
|
|
2625
|
+
} catch (e) { orchBackupRunning = false; warnWriteFail('orchestrator tick', e); }
|
|
2626
|
+
};
|
|
2601
2627
|
// horizon-scan: a scan is two headless runs for the whole portfolio (web, then repository), at most one scan at a time, on the workspace cadence inside the working hours.
|
|
2602
2628
|
// Everything it decides is in lib/scan.js and lib/scan-run.js; this only hands it the server's parts. The web run gets an empty scratch folder to run in.
|
|
2603
2629
|
const scanRoutesCtx = () => ({ getWs, stateDirFor, workspaceList: () => [...workspaces.values()], runtimeDir: STATE, selfRoot: EMBEDDED_SELF ? SELF_ROOT : null });
|
|
@@ -2741,7 +2767,7 @@ const gated = (id, fn) => () => { let g = { ok: true }; try { g = refreshRun.job
|
|
|
2741
2767
|
// data-refresh-settings: the seed schedules move to Settings › Data refresh (refreshRun.settings(), once) BEFORE checkDueSchedules reads
|
|
2742
2768
|
// schedules.json, so a schedule that is moving never fires once more from the old list on the first tick after an upgrade.
|
|
2743
2769
|
const scheduleOwner = require('./lib/schedule-owner.js').create({ port: PORT });
|
|
2744
|
-
try { const _tick = setInterval(() => { try { if (!scheduleOwner.mayRun()) return; } catch { /* no lock: run as before */ } try { refreshRun.settings(); } catch { /* the refresh tick tries again */ } checkDueSchedules(); proactiveTick(); try { prepareTick({ manual: false }); } catch { /* the next tick tries again */ } try { dayTick(); } catch (e) { warnWriteFail('day run tick', e); } try { refreshRun.tick(); } catch (e) { warnWriteFail('refresh tick', e); } gated('sync', () => autoSync.tick().catch(() => {}))(); dashboardScheduleTick(); gated('driver', driverTick)(); gated('scan', scanTick)(); gated('finder', reportFinderTick)(); gated('coredocs', coreDocsTick)(); reportDesignTick(); reportStructureTick(); }, TICK_MS); if (_tick.unref) _tick.unref(); } catch {}
|
|
2770
|
+
try { const _tick = setInterval(() => { try { if (!scheduleOwner.mayRun()) return; } catch { /* no lock: run as before */ } try { refreshRun.settings(); } catch { /* the refresh tick tries again */ } checkDueSchedules(); proactiveTick(); try { prepareTick({ manual: false }); } catch { /* the next tick tries again */ } try { dayTick(); } catch (e) { warnWriteFail('day run tick', e); } try { refreshRun.tick(); } catch (e) { warnWriteFail('refresh tick', e); } gated('sync', () => autoSync.tick().catch(() => {}))(); dashboardScheduleTick(); orchTick(); gated('driver', driverTick)(); gated('scan', scanTick)(); gated('finder', reportFinderTick)(); gated('coredocs', coreDocsTick)(); reportDesignTick(); reportStructureTick(); }, TICK_MS); if (_tick.unref) _tick.unref(); } catch {}
|
|
2745
2771
|
|
|
2746
2772
|
// ── Sessions: real PTYs, owned by the server, with disk-backed scrollback + metadata. ──
|
|
2747
2773
|
/** @type {Map<string, {id,ws,name,agent,cwd,state,note,created,pty,buf,cols,rows,clients:Set}>} */
|
|
@@ -9375,7 +9401,8 @@ async function handleRequest(req, res) {
|
|
|
9375
9401
|
}
|
|
9376
9402
|
// pm-os-absorb Runs 2–5 — the planning layer's routes, one file per run (lib/route-modules.js). Last, so none shadows a route above.
|
|
9377
9403
|
// meeting-notes Run 1: the Notes routes keep notes in the per-user runtime directory and start the agent-summary session.
|
|
9378
|
-
if (
|
|
9404
|
+
if (req.method === 'POST' && !(req.headers && req.headers['x-pmos-session'])) orchGate.touch(); // agent-orchestrator: a page press by the PM
|
|
9405
|
+
if (await routeModules.dispatch(req, res, url, { orchestrator: { gate: orchGate, running: () => driver.active().length, health: orchHealth }, json, readBody, getWs, invalidateNeedsAgg, boardCache, consoleState, stateDirFor, sessionList, initiativeIndex,
|
|
9379
9406
|
runtimeDir: STATE, homeRoot: HOME_ENABLED ? SELF_ROOT : null, spawnSession, jevModelOpts, sendToSession, endSupersededRuns, proSettings,
|
|
9380
9407
|
// report-workspace: the schedule store a recurring report registers its draft-only schedule in, a skill's body, and the stop of a headless run
|
|
9381
9408
|
scheduleStore: { read: readSchedules, write: writeSchedules },
|
|
@@ -9624,6 +9651,7 @@ wss.on('connection', (ws) => {
|
|
|
9624
9651
|
return;
|
|
9625
9652
|
}
|
|
9626
9653
|
if (m.t === 'input' && !rateLimit.take(ws._rlInput)) return; // drop excess input quietly
|
|
9654
|
+
if (m.t === 'input' || m.t === 'attach') orchGate.touch(); // agent-orchestrator: the PM is at a terminal, so the work-hours mode applies
|
|
9627
9655
|
if (m.t === 'attach') {
|
|
9628
9656
|
const s = sessions.get(m.id); if (!s) return;
|
|
9629
9657
|
s.clients.add(ws); ws.attached.add(s.id);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "agent-orchestrator slice B: the gate that joins the governor and the stop switch, the health rows, the nightly state backup and the status route (node, no server).",
|
|
3
|
+
"modules": [
|
|
4
|
+
"orchestrator-gate.test.js",
|
|
5
|
+
"orchestrator-health.test.js",
|
|
6
|
+
"state-backup.test.js",
|
|
7
|
+
"routes-orchestrator.test.js"
|
|
8
|
+
],
|
|
9
|
+
"seconds": {
|
|
10
|
+
"orchestrator-gate.test.js": 1,
|
|
11
|
+
"orchestrator-health.test.js": 1,
|
|
12
|
+
"state-backup.test.js": 1,
|
|
13
|
+
"routes-orchestrator.test.js": 1
|
|
14
|
+
}
|
|
15
|
+
}
|