create-pmos 0.598.0 → 0.599.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -14
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/pmos-memory.js +42 -16
- package/payload/state/discoveries.md +1 -1
- package/workspace/changelog.json +13 -0
- package/workspace/guide/cli.md +9 -0
- package/workspace/lib/bg-queue.js +1 -0
- package/workspace/lib/briefing-premium-agent.js +12 -5
- package/workspace/lib/corrections-memory.js +9 -5
- package/workspace/lib/cos-chat.js +15 -1
- package/workspace/lib/driver.js +4 -1
- package/workspace/lib/engine/pmos-memory.js +42 -16
- package/workspace/lib/goal-loop.js +2 -1
- package/workspace/lib/headless.js +7 -3
- package/workspace/lib/job-graph.js +4 -0
- package/workspace/lib/owner-cli.js +30 -0
- package/workspace/lib/pmos-verbs.js +5 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-briefing-premium.js +3 -1
- package/workspace/lib/routes-home-desk.js +13 -1
- package/workspace/lib/routes-proposals.js +1 -1
- package/workspace/lib/routes-units.js +52 -0
- package/workspace/lib/team-cli.js +16 -1
- package/workspace/lib/team-runs.js +5 -2
- package/workspace/lib/unit-memory.js +65 -0
- package/workspace/lib/unit-owner.js +185 -0
- package/workspace/lib/units-cli.js +45 -0
- package/workspace/lib/units-host.js +151 -0
- package/workspace/lib/units.js +88 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/cozy-today.css +3 -0
- package/workspace/public/pm/home-app.js +13 -1
- package/workspace/public/pm/home-list.js +14 -2
- package/workspace/public/pm/home-today.js +7 -4
- package/workspace/server.js +26 -1
- package/workspace/test-files.json +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-pmos",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.599.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.599.0",
|
|
38
|
+
"at": "2026-11-18T05:55:46.962Z",
|
|
39
|
+
"f": 4,
|
|
40
|
+
"prs": [
|
|
41
|
+
{
|
|
42
|
+
"n": 1341,
|
|
43
|
+
"t": "Chief agent and unit owners — derived owner, daily brief, chief's desk, scoped memory",
|
|
44
|
+
"s": "Chief agent and unit owners — derived owner, daily brief, chief's desk, scoped memory",
|
|
45
|
+
"k": "new"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
36
49
|
{
|
|
37
50
|
"v": "0.598.0",
|
|
38
51
|
"at": "2026-11-18T04:35:50.009Z",
|
|
@@ -297,19 +310,6 @@
|
|
|
297
310
|
"k": "new"
|
|
298
311
|
}
|
|
299
312
|
]
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
"v": "0.579.0",
|
|
303
|
-
"at": "2026-11-17T02:01:31.178Z",
|
|
304
|
-
"f": 4,
|
|
305
|
-
"prs": [
|
|
306
|
-
{
|
|
307
|
-
"n": 1312,
|
|
308
|
-
"t": "Present a prototype round on a shared screen (live round W3)",
|
|
309
|
-
"s": "Present a prototype round on a shared screen (live round W3)",
|
|
310
|
-
"k": "new"
|
|
311
|
-
}
|
|
312
|
-
]
|
|
313
313
|
}
|
|
314
314
|
]
|
|
315
315
|
}
|
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-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T05:55:44Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Health budgets"
|
|
4
4
|
description: "Closed registry of health-budget anchors (D59), edited only by the PM."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T05:55:44Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
/* pmos-memory — curated repository memory (D72).
|
|
4
4
|
*
|
|
5
|
-
* node pmos-memory.js add --text "…" [--target memory|user] [--confidence unconfirmed] [--source kind:ref] [--stale-after YYYY-MM-DD]
|
|
5
|
+
* node pmos-memory.js add --text "…" [--target memory|user] [--confidence unconfirmed] [--source kind:ref] [--stale-after YYYY-MM-DD] [--scope …]
|
|
6
6
|
* node pmos-memory.js replace --old "unique substring" --text "…" [--target …]
|
|
7
7
|
* node pmos-memory.js remove --old "unique substring" [--target …]
|
|
8
8
|
* node pmos-memory.js confirm --old "unique substring"
|
|
@@ -15,6 +15,13 @@
|
|
|
15
15
|
* USER.md are generated, git-ignored, and rebuilt at session start: a session reads them once (a frozen
|
|
16
16
|
* snapshot) and sees its own writes only in the next one.
|
|
17
17
|
*
|
|
18
|
+
* THREE SCOPES (chief-unit-owners ✦4, Wawan 2026-11-18): every entry has a scope. `workspace` (the default, and every line written before
|
|
19
|
+
* scopes) holds the standing rules and the PM's preferences, read by every session and run. `unit:<kind>:<id>` (lib/units.js keyOf, e.g.
|
|
20
|
+
* unit:program:ascent) holds a lesson that repeated across that unit's initiatives. `initiative:<id>` holds what one initiative's runs learned.
|
|
21
|
+
* A run reads workspace, then its unit, then its initiative, never another unit's (workspace/lib/headless.js memoryNote). The capacity
|
|
22
|
+
* limit is per target AND scope, so a busy initiative never crowds out the standing rules. The snapshot views (MEMORY.md, USER.md) show
|
|
23
|
+
* the workspace scope only. AGE OUT: an unconfirmed entry not touched for AGE_DAYS (30) is `aged` and no run reads it.
|
|
24
|
+
*
|
|
18
25
|
* This is the harness pattern Hermes uses (bounded curated files, add/replace/remove by unique
|
|
19
26
|
* substring, a capacity error that lists the entries, a frozen snapshot, optional write approval, a
|
|
20
27
|
* scan for injection and credentials) with three changes: the store lives in the repository so it
|
|
@@ -29,6 +36,9 @@ const TARGETS = ['memory', 'user'];
|
|
|
29
36
|
const DEFAULTS = { memory_chars: 2200, user_chars: 1375, write_approval: false };
|
|
30
37
|
const CONFIDENCE = ['confirmed', 'unconfirmed'];
|
|
31
38
|
const HUMAN = /^human:/;
|
|
39
|
+
const SCOPE_RE = /^(workspace|unit:(program|product|project):[A-Za-z0-9][A-Za-z0-9._-]{0,80}|initiative:[A-Za-z0-9][A-Za-z0-9._-]{0,80})$/;
|
|
40
|
+
const AGE_DAYS = 30;
|
|
41
|
+
const scopeOf = (v) => (v && SCOPE_RE.test(String(v)) ? String(v) : 'workspace');
|
|
32
42
|
|
|
33
43
|
// ── paths ────────────────────────────────────────────────────────────────────────────────────
|
|
34
44
|
function stateDir(root, create) {
|
|
@@ -113,7 +123,7 @@ function fold(events, now) {
|
|
|
113
123
|
}
|
|
114
124
|
if (e.op === 'add') {
|
|
115
125
|
if (!TARGETS.includes(e.target)) continue;
|
|
116
|
-
entries.set(e.eid, { id: e.eid, target: e.target, text: String(e.text), confidence: e.confidence === 'confirmed' ? 'confirmed' : 'unconfirmed',
|
|
126
|
+
entries.set(e.eid, { id: e.eid, target: e.target, scope: scopeOf(e.scope), text: String(e.text), confidence: e.confidence === 'confirmed' ? 'confirmed' : 'unconfirmed',
|
|
117
127
|
source: e.source || null, by: e.by || 'unknown', at: e.at, updated_at: e.at, stale_after: e.stale_after || null, verified: [] });
|
|
118
128
|
} else if (e.op === 'replace') {
|
|
119
129
|
const cur = entries.get(e.id); if (!cur) continue;
|
|
@@ -129,11 +139,12 @@ function fold(events, now) {
|
|
|
129
139
|
cur.confidence = 'confirmed'; cur.verified.push({ by: e.by, at: e.at });
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
|
-
const list = [...entries.values()].map((x) => ({ ...x, stale: !!(x.stale_after && Date.parse(x.stale_after) <= nowMs)
|
|
142
|
+
const list = [...entries.values()].map((x) => ({ ...x, stale: !!(x.stale_after && Date.parse(x.stale_after) <= nowMs),
|
|
143
|
+
aged: x.confidence === 'unconfirmed' && nowMs - Date.parse(x.updated_at || x.at) > AGE_DAYS * 86400000 }));
|
|
133
144
|
return { entries: list, pending, blocked };
|
|
134
145
|
}
|
|
135
146
|
|
|
136
|
-
const used = (entries, target) => entries.filter((e) => e.target === target).reduce((n, e) => n + e.text.length + 1, 0);
|
|
147
|
+
const used = (entries, target, scope = 'workspace') => entries.filter((e) => e.target === target && (e.scope || 'workspace') === scope && !e.aged).reduce((n, e) => n + e.text.length + 1, 0);
|
|
137
148
|
function usage(state, cfg) {
|
|
138
149
|
const out = {};
|
|
139
150
|
for (const t of TARGETS) {
|
|
@@ -175,11 +186,11 @@ function load(root) {
|
|
|
175
186
|
return { dir, cfg, state, torn, usage: usage(state, cfg) };
|
|
176
187
|
}
|
|
177
188
|
|
|
178
|
-
function listFor(state, target) { return state.entries.filter((e) => e.target === target); }
|
|
179
|
-
function matchOne(state, target, sub) {
|
|
189
|
+
function listFor(state, target, scope) { return state.entries.filter((e) => e.target === target && (!scope || (e.scope || 'workspace') === scope)); }
|
|
190
|
+
function matchOne(state, target, sub, scope) {
|
|
180
191
|
const s = String(sub || '').trim();
|
|
181
192
|
if (!s) return { ok: false, error: 'a substring that identifies one entry is required (--old)' };
|
|
182
|
-
const pool = listFor(state, target);
|
|
193
|
+
const pool = listFor(state, target, scope);
|
|
183
194
|
const exact = pool.filter((e) => e.text === s);
|
|
184
195
|
const hits = exact.length === 1 ? exact : pool.filter((e) => e.text.includes(s));
|
|
185
196
|
if (hits.length === 1) return { ok: true, entry: hits[0] };
|
|
@@ -192,6 +203,8 @@ function write(root, req) {
|
|
|
192
203
|
const op = req.op;
|
|
193
204
|
const target = req.target || 'memory';
|
|
194
205
|
if (!TARGETS.includes(target)) return { ok: false, error: `target must be one of ${TARGETS.join(', ')}` };
|
|
206
|
+
if (req.scope && !SCOPE_RE.test(String(req.scope))) return { ok: false, error: 'scope must be workspace, unit:<program|product|project>:<id> or initiative:<id>' };
|
|
207
|
+
const scope = req.scope ? String(req.scope) : null;
|
|
195
208
|
const cur = load(root);
|
|
196
209
|
const dir = memDir(root, true);
|
|
197
210
|
const cfg = cur.dir ? cur.cfg : readConfig(dir);
|
|
@@ -209,18 +222,19 @@ function write(root, req) {
|
|
|
209
222
|
if (!CONFIDENCE.includes(conf)) return { ok: false, error: `confidence must be ${CONFIDENCE.join(' or ')}` };
|
|
210
223
|
let id = null; let delta = text.length + 1;
|
|
211
224
|
if (op === 'replace') {
|
|
212
|
-
const m = matchOne(cur.state, target, req.old);
|
|
225
|
+
const m = matchOne(cur.state, target, req.old, scope);
|
|
213
226
|
if (!m.ok) return m;
|
|
214
227
|
id = m.entry.id; delta = text.length - m.entry.text.length;
|
|
215
228
|
}
|
|
216
|
-
const
|
|
229
|
+
const inScope = id ? (cur.state.entries.find((e) => e.id === id) || {}).scope || 'workspace' : scope || 'workspace';
|
|
230
|
+
const limit = cfg[`${target}_chars`]; const u = used(cur.state.entries, target, inScope);
|
|
217
231
|
if (u + delta > limit) {
|
|
218
|
-
return { ok: false, error: `${target} is full (${u}/${limit} chars) and this write needs ${delta} more — merge or remove entries first`, entries: listFor(cur.state, target), usage: cur.usage };
|
|
232
|
+
return { ok: false, error: `${target}${inScope === 'workspace' ? '' : ' at ' + inScope} is full (${u}/${limit} chars) and this write needs ${delta} more — merge or remove entries first`, entries: listFor(cur.state, target, inScope), usage: cur.usage };
|
|
219
233
|
}
|
|
220
|
-
ev = { eid: newEid(), at, by: actor, op, target, ...(id ? { id } : {}), text, confidence: conf,
|
|
234
|
+
ev = { eid: newEid(), at, by: actor, op, target, ...(id ? { id } : {}), ...(op === 'add' && scope && scope !== 'workspace' ? { scope } : {}), text, confidence: conf,
|
|
221
235
|
...(req.source ? { source: req.source } : {}), ...(req.stale_after ? { stale_after: req.stale_after } : {}), ...(staged ? { staged: true } : {}) };
|
|
222
236
|
} else if (op === 'remove' || op === 'confirm') {
|
|
223
|
-
const m = matchOne(cur.state, target, req.old || req.text);
|
|
237
|
+
const m = matchOne(cur.state, target, req.old || req.text, scope);
|
|
224
238
|
if (!m.ok) return m;
|
|
225
239
|
ev = { eid: newEid(), at, by: actor, op, target, id: m.entry.id, ...(staged ? { staged: true } : {}) };
|
|
226
240
|
if (op === 'confirm' && !HUMAN.test(actor)) return { ok: false, error: 'only the PM confirms an entry' };
|
|
@@ -244,7 +258,7 @@ function viewFor(target, state, usageT, cfg, at) {
|
|
|
244
258
|
`# ${title} [${usageT.percent}% — ${usageT.used}/${usageT.limit} chars]`, '',
|
|
245
259
|
];
|
|
246
260
|
if (usageT.percent >= 80) lines.push('> Above 80% full: merge or remove entries before adding.', '');
|
|
247
|
-
const es = listFor(state, target).sort(byTime);
|
|
261
|
+
const es = listFor(state, target, 'workspace').filter((e) => !e.aged).sort(byTime);
|
|
248
262
|
if (!es.length) lines.push('_Nothing recorded yet._');
|
|
249
263
|
for (const e of es) {
|
|
250
264
|
const tags = [e.confidence === 'unconfirmed' ? 'UNCONFIRMED' : null, e.stale ? 'STALE' : null].filter(Boolean);
|
|
@@ -356,13 +370,13 @@ function main(argv) {
|
|
|
356
370
|
if (cmd === 'pending') { for (const p of cur.state.pending) process.stdout.write(`${p.eid} ${p.op} ${p.target} ${p.text || p.id} (${p.by})\n`); return 0; }
|
|
357
371
|
for (const t of TARGETS) {
|
|
358
372
|
process.stdout.write(`${t} [${cur.usage[t].percent}% — ${cur.usage[t].used}/${cur.usage[t].limit}]\n`);
|
|
359
|
-
for (const e of listFor(cur.state, t)) process.stdout.write(` ${e.confidence === 'unconfirmed' ? '(unconfirmed) ' : ''}${e.stale ? '(stale) ' : ''}${e.text}\n`);
|
|
373
|
+
for (const e of listFor(cur.state, t)) process.stdout.write(` ${e.scope && e.scope !== 'workspace' ? `[${e.scope}] ` : ''}${e.confidence === 'unconfirmed' ? '(unconfirmed) ' : ''}${e.stale ? '(stale) ' : ''}${e.aged ? '(aged) ' : ''}${e.text}\n`);
|
|
360
374
|
}
|
|
361
375
|
for (const b of cur.state.blocked) process.stdout.write(`BLOCKED ${b.eid}: ${b.reason}\n`);
|
|
362
376
|
return 0;
|
|
363
377
|
}
|
|
364
378
|
const req = { op: cmd, target: opt.target, text: opt.text, old: opt.old, confidence: opt.confidence, source: opt.source,
|
|
365
|
-
stale_after: opt['stale-after'], by: opt.by, ref: rest[0] };
|
|
379
|
+
stale_after: opt['stale-after'], by: opt.by, ref: rest[0], scope: opt.scope };
|
|
366
380
|
const r = write(root, req);
|
|
367
381
|
if (opt.json) { say(r); return r.ok ? 0 : 2; }
|
|
368
382
|
if (r.ok) { process.stdout.write(`${r.staged ? 'held for the PM to approve' : 'saved'} — ${req.target || 'memory'} ${r.usage[req.target || 'memory'].percent}% full. It appears in the next session's snapshot.\n`); return 0; }
|
|
@@ -371,5 +385,17 @@ function main(argv) {
|
|
|
371
385
|
return 2;
|
|
372
386
|
}
|
|
373
387
|
|
|
374
|
-
|
|
388
|
+
/** The entries a session or run reads, in order: workspace, then its unit, then its initiative. Never another unit's or initiative's,
|
|
389
|
+
* never a stale, aged or staged one. `cap` bounds the unit and initiative entries (the workspace scope is bounded by its capacity). */
|
|
390
|
+
function scoped(state, { unit = null, ini = null, cap = 12 } = {}) {
|
|
391
|
+
const live = (state.entries || []).filter((e) => e && typeof e.text === 'string' && e.text.trim() && !e.stale && !e.aged && !e.staged);
|
|
392
|
+
const newest = (xs) => xs.sort(byTime).slice(-cap);
|
|
393
|
+
return [
|
|
394
|
+
...live.filter((e) => (e.scope || 'workspace') === 'workspace'),
|
|
395
|
+
...(unit ? newest(live.filter((e) => e.scope === 'unit:' + unit)) : []),
|
|
396
|
+
...(ini ? newest(live.filter((e) => e.scope === 'initiative:' + ini)) : []),
|
|
397
|
+
];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
module.exports = { fold, scan, load, write, render, search, memDir, stateDir, readEvents, readConfig, usage, appendEvent, scoped, scopeOf, TARGETS, DEFAULTS, SCAN, SCOPE_RE, AGE_DAYS };
|
|
375
401
|
if (require.main === module) process.exit(main(process.argv));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
type: Reference
|
|
3
3
|
title: "Discoveries and friction log"
|
|
4
4
|
description: "Append-only record of what runs discovered and where the process rubbed."
|
|
5
|
-
generated: {by: process:create-pmos, at: "2026-11-
|
|
5
|
+
generated: {by: process:create-pmos, at: "2026-11-18T05:55:44Z"}
|
|
6
6
|
status: stable
|
|
7
7
|
---
|
|
8
8
|
|
package/workspace/changelog.json
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "0.599.0",
|
|
4
|
+
"at": "2026-11-18T05:55:46.962Z",
|
|
5
|
+
"f": 4,
|
|
6
|
+
"prs": [
|
|
7
|
+
{
|
|
8
|
+
"n": 1341,
|
|
9
|
+
"t": "Chief agent and unit owners — derived owner, daily brief, chief's desk, scoped memory",
|
|
10
|
+
"s": "Chief agent and unit owners — derived owner, daily brief, chief's desk, scoped memory",
|
|
11
|
+
"k": "new"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
},
|
|
2
15
|
{
|
|
3
16
|
"v": "0.598.0",
|
|
4
17
|
"at": "2026-11-18T04:35:50.009Z",
|
package/workspace/guide/cli.md
CHANGED
|
@@ -220,10 +220,19 @@ PMOS looks for problems that repeat in a product (your Undos and ✕ reasons, re
|
|
|
220
220
|
- `pmos team dispatch <initiative>`: the chief of staff picks the roles that the initiative needs and runs them in order. `--roles spec,eval` picks them yourself. `pmos team dispatch --goal "<goal>"` does the same for a goal in words.
|
|
221
221
|
- `pmos team status`: who works on what, what waits, and the inbox entries of ended dispatches.
|
|
222
222
|
- `pmos team pause <role|all>` and `pmos team resume <role|all>`: stop or restart a role's runs. `pmos ai off team` stops the whole team.
|
|
223
|
+
- `pmos team dispatch --unit <unit>`: dispatch the roles for the unit's first open initiative in Roadmap order. `pmos team pause --unit <unit>` and `pmos team resume --unit <unit>` stop or restart every role run on that unit's initiatives.
|
|
223
224
|
- Inside a role run only: `pmos team wrote <path>`, `pmos team done "<summary>" [--propose <path> "<what>"]` and `pmos team verdict <path> pass|fail "<why>"`.
|
|
224
225
|
|
|
225
226
|
[What PMOS does behind the scenes](agent-capabilities.md) lists each role, what it may write and its rules.
|
|
226
227
|
|
|
228
|
+
### pmos units and pmos owner: who owns each initiative
|
|
229
|
+
|
|
230
|
+
Each initiative has one owner unit. PMOS works it out: the program when the initiative is in one, else its product. Project work in a product belongs to the product's project unit. Each unit's owner is a record, not a session. Once a day it folds what the runs on its initiatives did into one brief. Home shows that brief as one line on the group, for example "3 done · 1 for you", and Home's chat reads it.
|
|
231
|
+
|
|
232
|
+
- `pmos units` (or `pmos units list`): every unit, its initiatives, today's brief, what did not finish and why, and what is next.
|
|
233
|
+
- `pmos units show <unit>`: one unit. A unit is `program:<id>`, `product:<id>` or `project:<id>`.
|
|
234
|
+
- `pmos owner brief [<unit>]`: write a fresh brief now. With no unit, every unit that has no brief today gets one.
|
|
235
|
+
|
|
227
236
|
### pmos lab: the idle lab and the live round
|
|
228
237
|
|
|
229
238
|
The idle lab run uses only the first three commands:
|
|
@@ -86,6 +86,7 @@ const JOBS = Object.freeze([
|
|
|
86
86
|
{ id: 'report-design', step: 4, label: 'Report design' },
|
|
87
87
|
{ id: 'report-structure', step: 4, label: 'Report structure' },
|
|
88
88
|
{ id: 'team', step: 4, label: 'Role agents' },
|
|
89
|
+
{ id: 'owner', step: 4, label: 'Unit owners', ai: false }, // chief-unit-owners: one brief a day per program, product and project (lib/unit-owner.js); no model
|
|
89
90
|
{ id: 'scan', step: 5, label: 'Horizon scan' },
|
|
90
91
|
{ id: 'improve', step: 5, label: 'Improvement loop' }, // improve-loop-engine: lessons from repeated problems (lib/improve-runs.js)
|
|
91
92
|
{ id: 'idle-lab', step: 5, label: 'Idle lab' },
|
|
@@ -201,8 +201,9 @@ function openingFor(row, text, extra = []) {
|
|
|
201
201
|
].filter((l) => l !== '').join('\n');
|
|
202
202
|
}
|
|
203
203
|
/** sessions: { alive(id) → bool, spawn(spec) → session row, type(id, text) → bool (Enter after, `/` left as typed) }.
|
|
204
|
-
* iniInfo: () → lib/initiative-chat.js infoOf answer | null, read only when an init: chat needs it (its opening, a message about a stage).
|
|
205
|
-
|
|
204
|
+
* iniInfo: () → lib/initiative-chat.js infoOf answer | null, read only when an init: chat needs it (its opening, a message about a stage).
|
|
205
|
+
* unitsInfo: () → { chief: [line], ofIni(ini) → [line], ofUnit(key) → [line] } | null, the unit owners' briefs (chief-unit-owners ✦3), read only for an opening. */
|
|
206
|
+
function chat({ runtimeDir, key, text, model, context, sessions, wsId, iniInfo, reportInfo, unitsInfo, now = new Date() }) {
|
|
206
207
|
if (!runtimeDir) return fail(409, 'this workspace has no state folder to keep the conversation in');
|
|
207
208
|
if (!KEY_RE.test(String(key || ''))) return fail(400, 'key must name a row');
|
|
208
209
|
const q = String(text == null ? '' : text).trim();
|
|
@@ -251,11 +252,17 @@ function chat({ runtimeDir, key, text, model, context, sessions, wsId, iniInfo,
|
|
|
251
252
|
const name = 'chat: ' + clip(row ? row.title : prev.name || key, 60);
|
|
252
253
|
let s;
|
|
253
254
|
// an initiative chat's opening (or its resumed first message) states the initiative's workflow and stage (lib/initiative-chat.js)
|
|
254
|
-
|
|
255
|
+
// chief-unit-owners ✦3: unitsInfo() → { chief: [line], ofIni(ini) → [line] } (lib/units-host.js), read only for an opening
|
|
256
|
+
const units = () => { try { return typeof unitsInfo === 'function' ? unitsInfo() || null : null; } catch { return null; } };
|
|
257
|
+
const iniRule = /^init:/.test(key) && !goal ? [...IniChat.rule(info(), iniId(key)), ...(((u) => (u && u.ofIni ? u.ofIni(iniId(key)) : []))(units()))] : [];
|
|
255
258
|
if (resume && iniRule.length && msg === q && !/^\/[A-Za-z0-9]/.test(q)) msg = IniChat.wrap(q, info(), iniId(key)); // a / command goes as typed (batch 20 item 7)
|
|
256
259
|
// chief-of-staff C1/C6: the opening of Home's own chat carries the chief-of-staff rule (lib/cos-chat.js)
|
|
257
|
-
const cosRule = CosChat.isKey(key) && !goal ? [CosChat.RULE] : [];
|
|
258
|
-
|
|
260
|
+
const cosRule = CosChat.isKey(key) && !goal ? [CosChat.RULE, ...CosChat.briefsBlock(((u) => (u && u.chief) || [])(units()))] : [];
|
|
261
|
+
// chief-unit-owners addendum (Wawan 2026-11-18 12:32 SGT): a unit's own chat (chat:unit:<kind>:<id>, the press on its Home line) opens with the
|
|
262
|
+
// chief's rule, the unit's newest brief and its last 3 lessons. It is the chief's rule scoped to one unit, never a session per owner.
|
|
263
|
+
const unitKey = !goal ? CosChat.unitOfKey(key) : null;
|
|
264
|
+
const unitRule = unitKey ? [CosChat.RULE, ...(((u) => (u && u.ofUnit ? u.ofUnit(unitKey) : []))(units()))] : [];
|
|
265
|
+
try { s = sessions.spawn({ name, agent: 'claude', ws: wsId, origin: 'chat:' + key, chatClaude: { id: claude, resume }, initialInput: (resume ? msg : openingFor(row, msg, [...iniRule, ...cosRule, ...unitRule])) + '\r', ...(resume && /^\/[A-Za-z0-9]/.test(msg) ? { typedByPm: true } : {}) }); } catch (e) { s = { state: 'exited', note: String((e && e.message) || e).slice(0, 120) }; }
|
|
259
266
|
if (!s || s.state === 'exited' || !s.id) return fail(409, 'PMOS could not start: ' + ((s && s.note) || 'no session'));
|
|
260
267
|
fs.mkdirSync(runtimeDir, { recursive: true });
|
|
261
268
|
fs.appendFileSync(path.join(runtimeDir, CHATS), JSON.stringify({ key, session: s.id, claude, name, at: now.toISOString() }) + '\n');
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
* live at once: the oldest is removed first. A full memory is never forced: the write is skipped and the reason stays on the ✕ line.
|
|
11
11
|
* The same text twice is written once. PMOS_CORRECTION_MEMORY=off stops it.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* SCOPE (chief-unit-owners ✦4): with `ini` the entry is written at initiative scope (initiative:<id>), so only runs on that initiative read
|
|
14
|
+
* it until the unit's tick sees the same lesson on a second initiative and promotes it (lib/unit-memory.js). The KEEP bound is per scope.
|
|
15
|
+
*
|
|
16
|
+
* remember(root, { what, why, source, ini?, env, now }) → { ok, wrote?: bool, why?: string } never throws
|
|
14
17
|
*/
|
|
15
18
|
const DAY = 86400000;
|
|
16
19
|
const BY = 'agent:corrections';
|
|
@@ -26,7 +29,7 @@ function textOf(what, why) {
|
|
|
26
29
|
return one(head + '"' + one(why, MAX - head.length - 2) + '"', MAX);
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
function remember(root, { what = '', why = '', source = '', env = process.env, now = Date.now() } = {}) {
|
|
32
|
+
function remember(root, { what = '', why = '', source = '', ini = null, env = process.env, now = Date.now() } = {}) {
|
|
30
33
|
try {
|
|
31
34
|
const reason = one(why, 300);
|
|
32
35
|
if (!root || reason.length < MIN_WHY) return { ok: true, wrote: false, why: 'no reason to learn from' };
|
|
@@ -34,15 +37,16 @@ function remember(root, { what = '', why = '', source = '', env = process.env, n
|
|
|
34
37
|
const c = require('./memory.js').core();
|
|
35
38
|
if (!c.ok) return { ok: true, wrote: false, why: c.error };
|
|
36
39
|
const M = c.core, text = textOf(what, reason);
|
|
37
|
-
const
|
|
40
|
+
const scope = ini && /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/.test(String(ini)) && M.SCOPE_RE ? 'initiative:' + ini : null;
|
|
41
|
+
const mine = () => M.load(root).state.entries.filter((e) => e.target === 'memory' && e.by === BY && (e.scope || 'workspace') === (scope || 'workspace')).sort((a, b) => String(a.at).localeCompare(String(b.at)));
|
|
38
42
|
let have = mine();
|
|
39
43
|
if (have.some((e) => e.text === text)) return { ok: true, wrote: false, why: 'already remembered' };
|
|
40
44
|
while (have.length >= KEEP) {
|
|
41
|
-
const r = M.write(root, { op: 'remove', target: 'memory', old: have[0].text, by: BY });
|
|
45
|
+
const r = M.write(root, { op: 'remove', target: 'memory', old: have[0].text, by: BY, ...(scope ? { scope } : {}) });
|
|
42
46
|
if (!r.ok) break;
|
|
43
47
|
have = mine();
|
|
44
48
|
}
|
|
45
|
-
const r = M.write(root, { op: 'add', target: 'memory', text, by: BY, confidence: 'unconfirmed', source: one(source, 120) || undefined,
|
|
49
|
+
const r = M.write(root, { op: 'add', target: 'memory', text, by: BY, confidence: 'unconfirmed', source: one(source, 120) || undefined, ...(scope ? { scope } : {}),
|
|
46
50
|
stale_after: new Date(now + STALE_DAYS * DAY).toISOString() });
|
|
47
51
|
return r.ok ? { ok: true, wrote: true } : { ok: true, wrote: false, why: r.error };
|
|
48
52
|
} catch (e) { return { ok: false, wrote: false, why: String((e && e.message) || e).slice(0, 160) }; }
|
|
@@ -25,6 +25,8 @@ const isKey = (key) => String(key || '') === KEY;
|
|
|
25
25
|
|
|
26
26
|
/** Words that point at a `pmos` read, best first. Each entry: the verb, and the words that send a question to it. */
|
|
27
27
|
const ROUTES = [
|
|
28
|
+
// chief-unit-owners ✦3: who owns what, and each unit's brief
|
|
29
|
+
['units', /\b(units?|coordinators?|unit briefs?|each (program|product|project)|every (program|product|project)|all (the )?(programs|products|projects)|across (the )?(programs|products|projects))\b/i],
|
|
28
30
|
['past', /\b(why did (we|i)|did (we|i) (ever )?decide|what did (we|i) decide|dropp?ed|declined|decision|decided)\b/i],
|
|
29
31
|
['mention', /\b(mention(s|ed)?|reply|replies|who (asked|is waiting)|waiting on my (reply|answer)|owe (a )?repl)/i],
|
|
30
32
|
['calendar', /\b(meeting|meetings|calendar|schedule|agenda|today'?s? (calls|meetings)|this week'?s? meetings)\b/i],
|
|
@@ -51,6 +53,7 @@ const RULE = [
|
|
|
51
53
|
'End every answer that rests on a read with one fenced code block with the language tag pmos-src holding one JSON array: [{"name":"Board","fresh":"read now"},{"name":"Jira","fresh":"read 4 min ago"}]. Name each source and how fresh it is; say "not read" for one you could not reach. The page shows it under your answer.',
|
|
52
54
|
'Five kinds of work, one rule each. A read runs at once and asks nothing. Upkeep with one right answer (repair a record, close an ask a decision retired, refresh a stale read) you finish, and say it once. A change inside PMOS (move a date, add a task, set a state, draft a report) is a proposal the PM keeps with ✓: file it with `pmos propose` or `pmos task`, never write it yourself. Anything that leaves PMOS (email, Slack, a Jira comment, an invite) is a draft in the outbox that the PM sends: never send it. A longer job (a report, a grill, an update, a clean-up) runs to its end; stop only for a call that is the PM\'s, and save those for one proposal.',
|
|
53
55
|
'Never from this chat: accept a run, anchor or dispose an initiative, approve a contract, merge a pull request. These stay on the PM-only pages. Say where each one waits and stop.',
|
|
56
|
+
'You are the chief: the one live session over every Program, Product and Project. Each unit has one owner, a record with a daily brief, never a session; an initiative in a program is the program\'s, else its product\'s. Never ask another session; read the records. `pmos units` lists the units and their briefs. You may run these yourself: `pmos owner brief [<unit>]` (a fresh brief now), `pmos team dispatch --unit <unit>` (the roles for the unit\'s first open initiative), `pmos team pause|resume --unit <unit>` (stop or restart the role runs on a unit). When the same lesson shows in two units, file it with `pmos propose` as a workspace rule the PM keeps or drops.',
|
|
54
57
|
'Answer in plain sentences, the answer first. Never start with "I can help with".',
|
|
55
58
|
].join('\n');
|
|
56
59
|
|
|
@@ -72,4 +75,15 @@ function parseSources(text) {
|
|
|
72
75
|
return a.filter((x) => x && typeof x.name === 'string' && x.name.trim()).slice(0, 8).map((x) => ({ name: x.name.trim().slice(0, 40), fresh: typeof x.fresh === 'string' ? x.fresh.trim().slice(0, 40) : '' }));
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
|
|
78
|
+
/** A unit's own chat (chief-unit-owners addendum): 'chat:unit:program:ascent' → 'program:ascent', else null. */
|
|
79
|
+
function unitOfKey(key) {
|
|
80
|
+
const m = /^chat:unit:((program|product|project):[A-Za-z0-9][A-Za-z0-9._-]{0,80})$/.exec(String(key || ''));
|
|
81
|
+
return m ? m[1] : null;
|
|
82
|
+
}
|
|
83
|
+
/** The chief's opening block (chief-unit-owners ✦3): the units' newest briefs, one line each, or nothing when no unit has one yet. */
|
|
84
|
+
function briefsBlock(lines) {
|
|
85
|
+
const ls = (Array.isArray(lines) ? lines : []).filter((l) => typeof l === 'string' && l.trim()).slice(0, 8);
|
|
86
|
+
return ls.length ? [['The unit owners\' newest briefs (pmos units has the rest; a failed run is done work with a reason, not the PM\'s):', ...ls].join('\n')] : [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = { KEY, MARK, RULE, ROUTES, isKey, routeOf, wrap, parseSources, briefsBlock, unitOfKey };
|
package/workspace/lib/driver.js
CHANGED
|
@@ -120,7 +120,10 @@ const ledgerFile = (stateDir) => (stateDir ? path.join(stateDir, LEDGER) : null)
|
|
|
120
120
|
function append(file, line, { now } = {}) {
|
|
121
121
|
if (!file) throw new Error('driver: no ledger file');
|
|
122
122
|
if (!isObj(line) || !EVENTS.includes(line.ev)) throw new Error(`driver: unknown event ${JSON.stringify(line && line.ev)}`);
|
|
123
|
-
|
|
123
|
+
// chief-unit-owners ✦1: a line about an initiative carries the unit that owns it (lib/units.js); a Work task line carries none
|
|
124
|
+
const t = line.target;
|
|
125
|
+
const stamped = t && t.kind === 'initiative' ? require('./units.js').stamp(line, { ws: t.ws, ini: t.id }) : line;
|
|
126
|
+
const out = { ...stamped, v: 1, at: new Date(now == null ? Date.now() : now).toISOString() };
|
|
124
127
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
125
128
|
fs.appendFileSync(file, JSON.stringify(out) + '\n');
|
|
126
129
|
return out;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
/* pmos-memory — curated repository memory (D72).
|
|
4
4
|
*
|
|
5
|
-
* node pmos-memory.js add --text "…" [--target memory|user] [--confidence unconfirmed] [--source kind:ref] [--stale-after YYYY-MM-DD]
|
|
5
|
+
* node pmos-memory.js add --text "…" [--target memory|user] [--confidence unconfirmed] [--source kind:ref] [--stale-after YYYY-MM-DD] [--scope …]
|
|
6
6
|
* node pmos-memory.js replace --old "unique substring" --text "…" [--target …]
|
|
7
7
|
* node pmos-memory.js remove --old "unique substring" [--target …]
|
|
8
8
|
* node pmos-memory.js confirm --old "unique substring"
|
|
@@ -15,6 +15,13 @@
|
|
|
15
15
|
* USER.md are generated, git-ignored, and rebuilt at session start: a session reads them once (a frozen
|
|
16
16
|
* snapshot) and sees its own writes only in the next one.
|
|
17
17
|
*
|
|
18
|
+
* THREE SCOPES (chief-unit-owners ✦4, Wawan 2026-11-18): every entry has a scope. `workspace` (the default, and every line written before
|
|
19
|
+
* scopes) holds the standing rules and the PM's preferences, read by every session and run. `unit:<kind>:<id>` (lib/units.js keyOf, e.g.
|
|
20
|
+
* unit:program:ascent) holds a lesson that repeated across that unit's initiatives. `initiative:<id>` holds what one initiative's runs learned.
|
|
21
|
+
* A run reads workspace, then its unit, then its initiative, never another unit's (workspace/lib/headless.js memoryNote). The capacity
|
|
22
|
+
* limit is per target AND scope, so a busy initiative never crowds out the standing rules. The snapshot views (MEMORY.md, USER.md) show
|
|
23
|
+
* the workspace scope only. AGE OUT: an unconfirmed entry not touched for AGE_DAYS (30) is `aged` and no run reads it.
|
|
24
|
+
*
|
|
18
25
|
* This is the harness pattern Hermes uses (bounded curated files, add/replace/remove by unique
|
|
19
26
|
* substring, a capacity error that lists the entries, a frozen snapshot, optional write approval, a
|
|
20
27
|
* scan for injection and credentials) with three changes: the store lives in the repository so it
|
|
@@ -29,6 +36,9 @@ const TARGETS = ['memory', 'user'];
|
|
|
29
36
|
const DEFAULTS = { memory_chars: 2200, user_chars: 1375, write_approval: false };
|
|
30
37
|
const CONFIDENCE = ['confirmed', 'unconfirmed'];
|
|
31
38
|
const HUMAN = /^human:/;
|
|
39
|
+
const SCOPE_RE = /^(workspace|unit:(program|product|project):[A-Za-z0-9][A-Za-z0-9._-]{0,80}|initiative:[A-Za-z0-9][A-Za-z0-9._-]{0,80})$/;
|
|
40
|
+
const AGE_DAYS = 30;
|
|
41
|
+
const scopeOf = (v) => (v && SCOPE_RE.test(String(v)) ? String(v) : 'workspace');
|
|
32
42
|
|
|
33
43
|
// ── paths ────────────────────────────────────────────────────────────────────────────────────
|
|
34
44
|
function stateDir(root, create) {
|
|
@@ -113,7 +123,7 @@ function fold(events, now) {
|
|
|
113
123
|
}
|
|
114
124
|
if (e.op === 'add') {
|
|
115
125
|
if (!TARGETS.includes(e.target)) continue;
|
|
116
|
-
entries.set(e.eid, { id: e.eid, target: e.target, text: String(e.text), confidence: e.confidence === 'confirmed' ? 'confirmed' : 'unconfirmed',
|
|
126
|
+
entries.set(e.eid, { id: e.eid, target: e.target, scope: scopeOf(e.scope), text: String(e.text), confidence: e.confidence === 'confirmed' ? 'confirmed' : 'unconfirmed',
|
|
117
127
|
source: e.source || null, by: e.by || 'unknown', at: e.at, updated_at: e.at, stale_after: e.stale_after || null, verified: [] });
|
|
118
128
|
} else if (e.op === 'replace') {
|
|
119
129
|
const cur = entries.get(e.id); if (!cur) continue;
|
|
@@ -129,11 +139,12 @@ function fold(events, now) {
|
|
|
129
139
|
cur.confidence = 'confirmed'; cur.verified.push({ by: e.by, at: e.at });
|
|
130
140
|
}
|
|
131
141
|
}
|
|
132
|
-
const list = [...entries.values()].map((x) => ({ ...x, stale: !!(x.stale_after && Date.parse(x.stale_after) <= nowMs)
|
|
142
|
+
const list = [...entries.values()].map((x) => ({ ...x, stale: !!(x.stale_after && Date.parse(x.stale_after) <= nowMs),
|
|
143
|
+
aged: x.confidence === 'unconfirmed' && nowMs - Date.parse(x.updated_at || x.at) > AGE_DAYS * 86400000 }));
|
|
133
144
|
return { entries: list, pending, blocked };
|
|
134
145
|
}
|
|
135
146
|
|
|
136
|
-
const used = (entries, target) => entries.filter((e) => e.target === target).reduce((n, e) => n + e.text.length + 1, 0);
|
|
147
|
+
const used = (entries, target, scope = 'workspace') => entries.filter((e) => e.target === target && (e.scope || 'workspace') === scope && !e.aged).reduce((n, e) => n + e.text.length + 1, 0);
|
|
137
148
|
function usage(state, cfg) {
|
|
138
149
|
const out = {};
|
|
139
150
|
for (const t of TARGETS) {
|
|
@@ -175,11 +186,11 @@ function load(root) {
|
|
|
175
186
|
return { dir, cfg, state, torn, usage: usage(state, cfg) };
|
|
176
187
|
}
|
|
177
188
|
|
|
178
|
-
function listFor(state, target) { return state.entries.filter((e) => e.target === target); }
|
|
179
|
-
function matchOne(state, target, sub) {
|
|
189
|
+
function listFor(state, target, scope) { return state.entries.filter((e) => e.target === target && (!scope || (e.scope || 'workspace') === scope)); }
|
|
190
|
+
function matchOne(state, target, sub, scope) {
|
|
180
191
|
const s = String(sub || '').trim();
|
|
181
192
|
if (!s) return { ok: false, error: 'a substring that identifies one entry is required (--old)' };
|
|
182
|
-
const pool = listFor(state, target);
|
|
193
|
+
const pool = listFor(state, target, scope);
|
|
183
194
|
const exact = pool.filter((e) => e.text === s);
|
|
184
195
|
const hits = exact.length === 1 ? exact : pool.filter((e) => e.text.includes(s));
|
|
185
196
|
if (hits.length === 1) return { ok: true, entry: hits[0] };
|
|
@@ -192,6 +203,8 @@ function write(root, req) {
|
|
|
192
203
|
const op = req.op;
|
|
193
204
|
const target = req.target || 'memory';
|
|
194
205
|
if (!TARGETS.includes(target)) return { ok: false, error: `target must be one of ${TARGETS.join(', ')}` };
|
|
206
|
+
if (req.scope && !SCOPE_RE.test(String(req.scope))) return { ok: false, error: 'scope must be workspace, unit:<program|product|project>:<id> or initiative:<id>' };
|
|
207
|
+
const scope = req.scope ? String(req.scope) : null;
|
|
195
208
|
const cur = load(root);
|
|
196
209
|
const dir = memDir(root, true);
|
|
197
210
|
const cfg = cur.dir ? cur.cfg : readConfig(dir);
|
|
@@ -209,18 +222,19 @@ function write(root, req) {
|
|
|
209
222
|
if (!CONFIDENCE.includes(conf)) return { ok: false, error: `confidence must be ${CONFIDENCE.join(' or ')}` };
|
|
210
223
|
let id = null; let delta = text.length + 1;
|
|
211
224
|
if (op === 'replace') {
|
|
212
|
-
const m = matchOne(cur.state, target, req.old);
|
|
225
|
+
const m = matchOne(cur.state, target, req.old, scope);
|
|
213
226
|
if (!m.ok) return m;
|
|
214
227
|
id = m.entry.id; delta = text.length - m.entry.text.length;
|
|
215
228
|
}
|
|
216
|
-
const
|
|
229
|
+
const inScope = id ? (cur.state.entries.find((e) => e.id === id) || {}).scope || 'workspace' : scope || 'workspace';
|
|
230
|
+
const limit = cfg[`${target}_chars`]; const u = used(cur.state.entries, target, inScope);
|
|
217
231
|
if (u + delta > limit) {
|
|
218
|
-
return { ok: false, error: `${target} is full (${u}/${limit} chars) and this write needs ${delta} more — merge or remove entries first`, entries: listFor(cur.state, target), usage: cur.usage };
|
|
232
|
+
return { ok: false, error: `${target}${inScope === 'workspace' ? '' : ' at ' + inScope} is full (${u}/${limit} chars) and this write needs ${delta} more — merge or remove entries first`, entries: listFor(cur.state, target, inScope), usage: cur.usage };
|
|
219
233
|
}
|
|
220
|
-
ev = { eid: newEid(), at, by: actor, op, target, ...(id ? { id } : {}), text, confidence: conf,
|
|
234
|
+
ev = { eid: newEid(), at, by: actor, op, target, ...(id ? { id } : {}), ...(op === 'add' && scope && scope !== 'workspace' ? { scope } : {}), text, confidence: conf,
|
|
221
235
|
...(req.source ? { source: req.source } : {}), ...(req.stale_after ? { stale_after: req.stale_after } : {}), ...(staged ? { staged: true } : {}) };
|
|
222
236
|
} else if (op === 'remove' || op === 'confirm') {
|
|
223
|
-
const m = matchOne(cur.state, target, req.old || req.text);
|
|
237
|
+
const m = matchOne(cur.state, target, req.old || req.text, scope);
|
|
224
238
|
if (!m.ok) return m;
|
|
225
239
|
ev = { eid: newEid(), at, by: actor, op, target, id: m.entry.id, ...(staged ? { staged: true } : {}) };
|
|
226
240
|
if (op === 'confirm' && !HUMAN.test(actor)) return { ok: false, error: 'only the PM confirms an entry' };
|
|
@@ -244,7 +258,7 @@ function viewFor(target, state, usageT, cfg, at) {
|
|
|
244
258
|
`# ${title} [${usageT.percent}% — ${usageT.used}/${usageT.limit} chars]`, '',
|
|
245
259
|
];
|
|
246
260
|
if (usageT.percent >= 80) lines.push('> Above 80% full: merge or remove entries before adding.', '');
|
|
247
|
-
const es = listFor(state, target).sort(byTime);
|
|
261
|
+
const es = listFor(state, target, 'workspace').filter((e) => !e.aged).sort(byTime);
|
|
248
262
|
if (!es.length) lines.push('_Nothing recorded yet._');
|
|
249
263
|
for (const e of es) {
|
|
250
264
|
const tags = [e.confidence === 'unconfirmed' ? 'UNCONFIRMED' : null, e.stale ? 'STALE' : null].filter(Boolean);
|
|
@@ -356,13 +370,13 @@ function main(argv) {
|
|
|
356
370
|
if (cmd === 'pending') { for (const p of cur.state.pending) process.stdout.write(`${p.eid} ${p.op} ${p.target} ${p.text || p.id} (${p.by})\n`); return 0; }
|
|
357
371
|
for (const t of TARGETS) {
|
|
358
372
|
process.stdout.write(`${t} [${cur.usage[t].percent}% — ${cur.usage[t].used}/${cur.usage[t].limit}]\n`);
|
|
359
|
-
for (const e of listFor(cur.state, t)) process.stdout.write(` ${e.confidence === 'unconfirmed' ? '(unconfirmed) ' : ''}${e.stale ? '(stale) ' : ''}${e.text}\n`);
|
|
373
|
+
for (const e of listFor(cur.state, t)) process.stdout.write(` ${e.scope && e.scope !== 'workspace' ? `[${e.scope}] ` : ''}${e.confidence === 'unconfirmed' ? '(unconfirmed) ' : ''}${e.stale ? '(stale) ' : ''}${e.aged ? '(aged) ' : ''}${e.text}\n`);
|
|
360
374
|
}
|
|
361
375
|
for (const b of cur.state.blocked) process.stdout.write(`BLOCKED ${b.eid}: ${b.reason}\n`);
|
|
362
376
|
return 0;
|
|
363
377
|
}
|
|
364
378
|
const req = { op: cmd, target: opt.target, text: opt.text, old: opt.old, confidence: opt.confidence, source: opt.source,
|
|
365
|
-
stale_after: opt['stale-after'], by: opt.by, ref: rest[0] };
|
|
379
|
+
stale_after: opt['stale-after'], by: opt.by, ref: rest[0], scope: opt.scope };
|
|
366
380
|
const r = write(root, req);
|
|
367
381
|
if (opt.json) { say(r); return r.ok ? 0 : 2; }
|
|
368
382
|
if (r.ok) { process.stdout.write(`${r.staged ? 'held for the PM to approve' : 'saved'} — ${req.target || 'memory'} ${r.usage[req.target || 'memory'].percent}% full. It appears in the next session's snapshot.\n`); return 0; }
|
|
@@ -371,5 +385,17 @@ function main(argv) {
|
|
|
371
385
|
return 2;
|
|
372
386
|
}
|
|
373
387
|
|
|
374
|
-
|
|
388
|
+
/** The entries a session or run reads, in order: workspace, then its unit, then its initiative. Never another unit's or initiative's,
|
|
389
|
+
* never a stale, aged or staged one. `cap` bounds the unit and initiative entries (the workspace scope is bounded by its capacity). */
|
|
390
|
+
function scoped(state, { unit = null, ini = null, cap = 12 } = {}) {
|
|
391
|
+
const live = (state.entries || []).filter((e) => e && typeof e.text === 'string' && e.text.trim() && !e.stale && !e.aged && !e.staged);
|
|
392
|
+
const newest = (xs) => xs.sort(byTime).slice(-cap);
|
|
393
|
+
return [
|
|
394
|
+
...live.filter((e) => (e.scope || 'workspace') === 'workspace'),
|
|
395
|
+
...(unit ? newest(live.filter((e) => e.scope === 'unit:' + unit)) : []),
|
|
396
|
+
...(ini ? newest(live.filter((e) => e.scope === 'initiative:' + ini)) : []),
|
|
397
|
+
];
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
module.exports = { fold, scan, load, write, render, search, memDir, stateDir, readEvents, readConfig, usage, appendEvent, scoped, scopeOf, TARGETS, DEFAULTS, SCAN, SCOPE_RE, AGE_DAYS };
|
|
375
401
|
if (require.main === module) process.exit(main(process.argv));
|
|
@@ -86,7 +86,8 @@ function read(dir) {
|
|
|
86
86
|
}
|
|
87
87
|
function append(dir, line, { now } = {}) {
|
|
88
88
|
if (!dir) throw new Error('goal-loop: no runtime folder');
|
|
89
|
-
|
|
89
|
+
// chief-unit-owners ✦1: a goal's start line carries the unit of its workspace (lib/units.js), so the product's owner folds its rounds
|
|
90
|
+
const out = { v: 1, at: new Date(now == null ? Date.now() : now).toISOString(), ...(line && line.ev === 'start' && line.ws ? require('./units.js').stamp(line, { ws: line.ws }) : line) };
|
|
90
91
|
fs.mkdirSync(dir, { recursive: true });
|
|
91
92
|
fs.appendFileSync(file(dir), JSON.stringify(out) + '\n');
|
|
92
93
|
return out;
|
|
@@ -439,7 +439,7 @@ function userModelOf(env) {
|
|
|
439
439
|
* ledger's scan blocks, a staged write and a stale entry are left out. A web kind never gets it: it reads untrusted pages and has web
|
|
440
440
|
* tools, so it holds nothing it could send out. PMOS_RUN_MEMORY=off: no note. */
|
|
441
441
|
const MEMORY_HEAD = 'What PMOS remembers (curated memory, D72). Follow it unless this run\'s own instructions say otherwise.';
|
|
442
|
-
function memoryNote(roots, env) {
|
|
442
|
+
function memoryNote(roots, env, { unit = null, ini = null } = {}) {
|
|
443
443
|
if (/^(off|0|false|no)$/i.test(String(((env || {}).PMOS_RUN_MEMORY) || '').trim())) return '';
|
|
444
444
|
let c = null; try { c = require('./memory.js').core(); } catch { return ''; }
|
|
445
445
|
if (!c || !c.ok) return '';
|
|
@@ -448,11 +448,15 @@ function memoryNote(roots, env) {
|
|
|
448
448
|
const root = String(r || ''); if (!root || seen.has(root)) continue; seen.add(root);
|
|
449
449
|
let cur = null; try { cur = c.core.load(root); } catch { cur = null; }
|
|
450
450
|
if (!cur || !cur.dir || !cur.state || !Array.isArray(cur.state.entries)) continue;
|
|
451
|
-
|
|
451
|
+
// chief-unit-owners ✦4: workspace, then this run's unit, then its initiative; never another unit's or initiative's (scripts/pmos-memory.js scoped)
|
|
452
|
+
const es = typeof c.core.scoped === 'function' ? c.core.scoped(cur.state, { unit, ini })
|
|
453
|
+
: cur.state.entries.filter((e) => e && typeof e.text === 'string' && e.text.trim() && !e.stale && !e.staged);
|
|
452
454
|
if (!es.length) continue;
|
|
453
455
|
const line = (e) => '- ' + (e.confidence === 'unconfirmed' ? '(unconfirmed) ' : '') + oneLine(e.text, 600);
|
|
454
456
|
const user = es.filter((e) => e.target === 'user'), mem = es.filter((e) => e.target !== 'user');
|
|
455
|
-
|
|
457
|
+
const ws = mem.filter((e) => !e.scope || e.scope === 'workspace'), un = mem.filter((e) => String(e.scope || '').startsWith('unit:')), own = mem.filter((e) => String(e.scope || '').startsWith('initiative:'));
|
|
458
|
+
return [MEMORY_HEAD, ...(user.length ? ['About the PM:', ...user.map(line)] : []), ...(ws.length ? ['About the product:', ...ws.map(line)] : []),
|
|
459
|
+
...(un.length ? [`Lessons of ${unit}, the unit that owns this work:`, ...un.map(line)] : []), ...(own.length ? [`Lessons of ${ini}:`, ...own.map(line)] : [])].join('\n');
|
|
456
460
|
}
|
|
457
461
|
return '';
|
|
458
462
|
}
|