create-pmos 0.541.0 → 0.543.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 +33 -39
- 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/adler-moments-test.js +4 -8
- package/workspace/briefing-premium-board-test.js +1 -1
- package/workspace/briefing-premium-initiative-test.js +1 -1
- package/workspace/briefing-premium-sources-test.js +3 -3
- package/workspace/briefing-premium-test.js +2 -4
- package/workspace/changelog.json +32 -0
- package/workspace/ev-everywhere-test.js +3 -3
- package/workspace/guide/home.md +22 -9
- package/workspace/guide/intelligence-okr-goals.md +1 -1
- package/workspace/guide/settings-and-switches.md +2 -0
- package/workspace/home-rows-test.js +19 -24
- package/workspace/lib/briefing-premium-agent.js +7 -2
- package/workspace/lib/corrections-memory.js +51 -0
- package/workspace/lib/cos-chat.js +75 -0
- package/workspace/lib/done-feed.js +33 -0
- package/workspace/lib/grill-runs.js +1 -1
- package/workspace/lib/headless.js +29 -2
- package/workspace/lib/loop-health.js +65 -0
- package/workspace/lib/proposal-runs.js +1 -1
- package/workspace/lib/proposals.js +44 -9
- package/workspace/lib/routes-lab.js +1 -0
- package/workspace/lib/routes-proposals.js +2 -0
- package/workspace/lib/routes-sources.js +2 -0
- package/workspace/lib/routes-your-move.js +25 -4
- package/workspace/lib/team-runs.js +32 -4
- package/workspace/lib/verify-runs.js +22 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/public/pm/batch-press.js +184 -0
- package/workspace/public/pm/bd-fc-card.js +2 -1
- package/workspace/public/pm/bd-next.js +2 -1
- package/workspace/public/pm/chat-src.js +18 -0
- package/workspace/public/pm/cozy-home.css +4 -0
- package/workspace/public/pm/cozy-lab-ins.js +17 -1
- package/workspace/public/pm/cozy-nav.js +22 -21
- package/workspace/public/pm/cozy-search.js +18 -9
- package/workspace/public/pm/cozy-today.css +7 -0
- package/workspace/public/pm/cozy-viewer.js +1 -1
- package/workspace/public/pm/goal-chat.js +1 -1
- package/workspace/public/pm/good-morning.js +1 -1
- package/workspace/public/pm/home-app.js +65 -14
- package/workspace/public/pm/home-chat.js +8 -4
- package/workspace/public/pm/home-day.js +46 -14
- package/workspace/public/pm/home-today.js +5 -4
- package/workspace/public/pm/ini-props.js +7 -2
- package/workspace/public/pm/ini-view.css +14 -0
- package/workspace/public/pm/move-rank.js +67 -9
- package/workspace/public/pm/outbox-view.js +35 -0
- package/workspace/public/pm/page-chat.css +2 -0
- package/workspace/public/pm/page-chat.js +33 -5
- package/workspace/run-tests.js +23 -4
- package/workspace/server.js +2 -1
- package/workspace/task-links-test.js +6 -2
- package/workspace/test-lists/chief-of-staff-chat.json +9 -0
- package/workspace/test-lists/corrections-memory.json +9 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* corrections-memory.js — the PM's ✕ reasons become curated memory by themselves (harness + memory evaluation, item 3, PM wawan 2026-11-08).
|
|
3
|
+
*
|
|
4
|
+
* When the PM drops a ✦ proposal or an idle-lab result and gives a reason, that reason is a correction every later run should know.
|
|
5
|
+
* remember() writes it to the repository's D72 memory (scripts/pmos-memory.js, through lib/memory.js) as one short entry:
|
|
6
|
+
* target memory · confidence unconfirmed · by agent:corrections · source <kind>:<ref> · stale_after +30 days
|
|
7
|
+
* so lib/headless.js memoryNote puts it in every background run, marked "(unconfirmed)" until the PM confirms it.
|
|
8
|
+
*
|
|
9
|
+
* BOUNDS. A reason shorter than MIN_WHY characters says nothing to learn from and is skipped. At most KEEP entries by agent:corrections
|
|
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
|
+
* The same text twice is written once. PMOS_CORRECTION_MEMORY=off stops it.
|
|
12
|
+
*
|
|
13
|
+
* remember(root, { what, why, source, env, now }) → { ok, wrote?: bool, why?: string } never throws
|
|
14
|
+
*/
|
|
15
|
+
const DAY = 86400000;
|
|
16
|
+
const BY = 'agent:corrections';
|
|
17
|
+
const MIN_WHY = 12;
|
|
18
|
+
const KEEP = 6;
|
|
19
|
+
const STALE_DAYS = 30;
|
|
20
|
+
const MAX = 200;
|
|
21
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
22
|
+
const off = (env) => /^(off|0|false|no)$/i.test(String((env || process.env).PMOS_CORRECTION_MEMORY || '').trim());
|
|
23
|
+
|
|
24
|
+
function textOf(what, why) {
|
|
25
|
+
const head = `The PM dropped ${one(what, 60) || 'a proposal'}: `;
|
|
26
|
+
return one(head + '"' + one(why, MAX - head.length - 2) + '"', MAX);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function remember(root, { what = '', why = '', source = '', env = process.env, now = Date.now() } = {}) {
|
|
30
|
+
try {
|
|
31
|
+
const reason = one(why, 300);
|
|
32
|
+
if (!root || reason.length < MIN_WHY) return { ok: true, wrote: false, why: 'no reason to learn from' };
|
|
33
|
+
if (off(env)) return { ok: true, wrote: false, why: 'PMOS_CORRECTION_MEMORY=off' };
|
|
34
|
+
const c = require('./memory.js').core();
|
|
35
|
+
if (!c.ok) return { ok: true, wrote: false, why: c.error };
|
|
36
|
+
const M = c.core, text = textOf(what, reason);
|
|
37
|
+
const mine = () => M.load(root).state.entries.filter((e) => e.target === 'memory' && e.by === BY).sort((a, b) => String(a.at).localeCompare(String(b.at)));
|
|
38
|
+
let have = mine();
|
|
39
|
+
if (have.some((e) => e.text === text)) return { ok: true, wrote: false, why: 'already remembered' };
|
|
40
|
+
while (have.length >= KEEP) {
|
|
41
|
+
const r = M.write(root, { op: 'remove', target: 'memory', old: have[0].text, by: BY });
|
|
42
|
+
if (!r.ok) break;
|
|
43
|
+
have = mine();
|
|
44
|
+
}
|
|
45
|
+
const r = M.write(root, { op: 'add', target: 'memory', text, by: BY, confidence: 'unconfirmed', source: one(source, 120) || undefined,
|
|
46
|
+
stale_after: new Date(now + STALE_DAYS * DAY).toISOString() });
|
|
47
|
+
return r.ok ? { ok: true, wrote: true } : { ok: true, wrote: false, why: r.error };
|
|
48
|
+
} catch (e) { return { ok: false, wrote: false, why: String((e && e.message) || e).slice(0, 160) }; }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = { BY, MIN_WHY, KEEP, STALE_DAYS, textOf, remember };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* cos-chat.js — the chief-of-staff chat's rule (chief-of-staff C1 and C6; boards CsA and CsC on the main canvas, In development).
|
|
3
|
+
*
|
|
4
|
+
* Home's own chat (key chat:main) is the one chat with no scope: its chip reads "Everything", and the same chat opens over any page
|
|
5
|
+
* (public/pm/page-chat.js). Its sessions carry this rule, so a loose question is answered from PMOS's own reads and every answer says where
|
|
6
|
+
* it came from. Scoped chats (init:, board:, report keys) keep their own rules.
|
|
7
|
+
*
|
|
8
|
+
* isKey(key) → true for the chief-of-staff chat
|
|
9
|
+
* RULE the lines its opening carries (lib/briefing-premium-agent.js openingFor)
|
|
10
|
+
* routeOf(text) → [verb] the `pmos` reads that fit a loose question, best first ([] when none fits). Deterministic, no model.
|
|
11
|
+
* wrap(text, page?) → the message as typed into a live session: the mark, the page the PM is on (the soft "You are on …" chip,
|
|
12
|
+
* C5), the reads that fit, then the PM's words. The page shows only the PM's words (pm/goal-chat.js shownUser).
|
|
13
|
+
* parseSources(text) → [{ name, fresh }] from the answer's ```pmos-src block (the page draws them under the answer)
|
|
14
|
+
*
|
|
15
|
+
* THE FIVE KINDS OF WORK (CsC), one rule each: a read runs at once; upkeep with one right answer is done and listed with Undo; a change inside
|
|
16
|
+
* PMOS is a ✦ the PM keeps with ✓; anything that leaves PMOS is a draft in the outbox the PM sends; a long job runs to its end and can be
|
|
17
|
+
* stopped. NEVER FROM CHAT: accept a run, anchor or dispose an initiative, approve a contract, merge. The chat says where those wait.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const KEY = 'chat:main';
|
|
21
|
+
const MARK = '[PMOS chief of staff]';
|
|
22
|
+
const SAYS = 'The PM says: ';
|
|
23
|
+
|
|
24
|
+
const isKey = (key) => String(key || '') === KEY;
|
|
25
|
+
|
|
26
|
+
/** Words that point at a `pmos` read, best first. Each entry: the verb, and the words that send a question to it. */
|
|
27
|
+
const ROUTES = [
|
|
28
|
+
['past', /\b(why did (we|i)|did (we|i) (ever )?decide|what did (we|i) decide|dropp?ed|declined|decision|decided)\b/i],
|
|
29
|
+
['mention', /\b(mention(s|ed)?|reply|replies|who (asked|is waiting)|waiting on my (reply|answer)|owe (a )?repl)/i],
|
|
30
|
+
['calendar', /\b(meeting|meetings|calendar|schedule|agenda|today'?s? (calls|meetings)|this week'?s? meetings)\b/i],
|
|
31
|
+
['jira', /\b(jira|ticket|tickets|epic|epics|sprint|bug|bugs)\b/i],
|
|
32
|
+
['outcomes', /\b(outcome|outcomes|did it work|check date|verdict)\b/i],
|
|
33
|
+
['metrics', /\b(metric|metrics|kpi|kr|krs|okr|okrs|north star|key result)\b/i],
|
|
34
|
+
['report', /\b(report|reports|weekly update|status update|deck)\b/i],
|
|
35
|
+
['people', /\b(who owns|owner|people|team|stakeholder|stakeholders)\b/i],
|
|
36
|
+
['docs', /\b(doc|docs|document|documents|prd|confluence|google docs?)\b/i],
|
|
37
|
+
['program', /\b(program|programme|programs|milestone|milestones)\b/i],
|
|
38
|
+
['board', /\b(late|blocked|holding up|on track|status|progress|tasks?|initiatives?|roadmap|launch|stage|due|deadline|slip|slipp(ed|ing))\b/i],
|
|
39
|
+
['today', /\b(what needs me|needs me|my day|today|what'?s next|what should i|catch me up|anything (new|urgent)|backlog|inbox|chase)\b/i],
|
|
40
|
+
];
|
|
41
|
+
function routeOf(text) {
|
|
42
|
+
const q = String(text == null ? '' : text);
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const [verb, re] of ROUTES) if (re.test(q) && !out.includes(verb)) out.push(verb);
|
|
45
|
+
return out.slice(0, 3);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const RULE = [
|
|
49
|
+
'You are the PM\'s chief of staff in PMOS. This chat has no scope: it reads everything the PM works on.',
|
|
50
|
+
'Read with the `pmos` commands (pmos today, pmos board, pmos jira, pmos calendar, pmos past, pmos mention, pmos outcomes, pmos metrics, pmos people, pmos docs, pmos report list), never by opening PMOS record files (*.jsonl, planning/ records) yourself: the commands apply the same rules the pages do. Run `pmos <verb> help` when unsure.',
|
|
51
|
+
'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
|
+
'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
|
+
'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.',
|
|
54
|
+
'Answer in plain sentences, the answer first. Never start with "I can help with".',
|
|
55
|
+
].join('\n');
|
|
56
|
+
|
|
57
|
+
/** The message as typed into a live session. page: the "You are on …" chip's words, or '' when the PM dropped it. */
|
|
58
|
+
function wrap(text, page) {
|
|
59
|
+
const t = String(text == null ? '' : text);
|
|
60
|
+
const verbs = routeOf(t);
|
|
61
|
+
const lines = [MARK + (page ? ' The PM is on ' + String(page).replace(/\s+/g, ' ').slice(0, 120) + '; answer about it first.' : '')];
|
|
62
|
+
if (verbs.length) lines.push('Reads that fit: ' + verbs.map((v) => 'pmos ' + v).join(', ') + '. End with the pmos-src block.');
|
|
63
|
+
return lines.join(' ') + '\n\n' + SAYS + t;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The sources an answer named in its ```pmos-src block: [{ name, fresh }] (at most 8), [] when none or when it does not parse. */
|
|
67
|
+
function parseSources(text) {
|
|
68
|
+
const m = /```pmos-src\s*\n([\s\S]*?)```/.exec(String(text || ''));
|
|
69
|
+
if (!m) return [];
|
|
70
|
+
let a; try { a = JSON.parse(m[1]); } catch { return []; }
|
|
71
|
+
if (!Array.isArray(a)) return [];
|
|
72
|
+
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
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { KEY, MARK, RULE, ROUTES, isKey, routeOf, wrap, parseSources };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* done-feed.js — what Claude finished by itself, for Your move's one Done group with Undo (chief-of-staff C2, board CsD on the main canvas,
|
|
3
|
+
* In development: "Done is one quiet group with Undo; only the calls that are yours come back as ✦").
|
|
4
|
+
*
|
|
5
|
+
* doneOf(F, { now, days }) → [{ batch, ini, board, at, by, said, n }] PURE. Newest first.
|
|
6
|
+
*
|
|
7
|
+
* WHAT COUNTS AS DONE. A keep line in proposals.jsonl that an agent wrote (by: 'agent:…' or 'claude'), not undone, from the last `days` days
|
|
8
|
+
* (14, the Undo window of the full-autonomy decision). The PM's own ✓ is not listed: the PM knows what they kept. Each line is one batch
|
|
9
|
+
* and one Undo (POST /api/proposals/undo { ws, board, batch }).
|
|
10
|
+
* The full-autonomy build writes the agent's auto-applied changes through the same keep path (its Driver `auto` mode applies a class A or B
|
|
11
|
+
* proposal through the existing writers), so they land here with no second record. Until it ships the group stays empty: zero is silence. */
|
|
12
|
+
|
|
13
|
+
const DAY = 864e5;
|
|
14
|
+
const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
|
|
15
|
+
const isAgent = (by) => /^agent:|^claude$/i.test(String(by || ''));
|
|
16
|
+
const OPWORD = { dates: ['date moved', 'dates moved'], state: ['state set', 'states set'], rename: ['name tidied', 'names tidied'], add: ['task added', 'tasks added'],
|
|
17
|
+
notes: ['note added', 'notes added'], link: ['link made', 'links made'], linked: ['link made', 'links made'], stage: ['stage set', 'stages set'], doc: ['document kept', 'documents kept'],
|
|
18
|
+
outbox: ['draft put in the outbox', 'drafts put in the outbox'], description: ['description written', 'descriptions written'], outcome: ['outcome set', 'outcomes set'], repair: ['record repaired', 'records repaired'] };
|
|
19
|
+
/** "2 dates moved, 1 name tidied" from a batch's writes. */
|
|
20
|
+
function saidOf(wrote) {
|
|
21
|
+
const n = new Map();
|
|
22
|
+
for (const w of wrote || []) { const k = OPWORD[w.op] ? w.op : 'other'; n.set(k, (n.get(k) || 0) + 1); }
|
|
23
|
+
return [...n].map(([k, c]) => (k === 'other' ? plural(c, 'change', 'changes') : c + ' ' + (c === 1 ? OPWORD[k][0] : OPWORD[k][1]))).join(', ');
|
|
24
|
+
}
|
|
25
|
+
function doneOf(F, o = {}) {
|
|
26
|
+
if (!F || !Array.isArray(F.kept)) return [];
|
|
27
|
+
const now = o.now || Date.now(), since = now - (o.days || 14) * DAY;
|
|
28
|
+
return F.kept.filter((k) => isAgent(k.by) && !F.undone.has(k.batch) && Date.parse(k.at || '') >= since && (k.wrote || []).length)
|
|
29
|
+
.map((k) => ({ batch: k.batch, ini: k.ini, board: k.board, at: k.at, by: k.by, said: saidOf(k.wrote), n: k.wrote.length }))
|
|
30
|
+
.sort((a, b) => String(b.at).localeCompare(String(a.at)));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = { doneOf, saidOf, isAgent };
|
|
@@ -104,7 +104,7 @@ function create(deps) {
|
|
|
104
104
|
const row = (deps.rowOf && deps.rowOf(w, ini)) || {};
|
|
105
105
|
const lines = PR.readLines(PR.ledgerFile(dir)), P = PR.fold(lines), kept = PR.keptIds(P);
|
|
106
106
|
// the learning edge (OS evaluation T1): the last 3 reasons the PM gave this job on this initiative, ✕ why and ✎ rewrites
|
|
107
|
-
const lessons = PR.lessonsOf(lines, { ini, match: (p) => p.group === 'grill' && p.type !== 'past' && p.type !== 'decision', n: 3 });
|
|
107
|
+
const lessons = PR.lessonsOf(lines, { ini, match: (p) => p.group === 'grill' && p.type !== 'past' && p.type !== 'decision', n: 3, wide: true });
|
|
108
108
|
const mine = [...P.props.values()].filter((p) => p.ini === ini && p.group === 'grill');
|
|
109
109
|
const dropped = mine.filter((p) => P.drops.has(PR.sigOf(p))).slice(0, 20).map((p) => one(p.title, 120));
|
|
110
110
|
const open = mine.filter((p) => !P.drops.has(PR.sigOf(p)) && !kept.has(p.id)).slice(0, 20).map((p) => one(p.title, 120));
|
|
@@ -406,7 +406,32 @@ function userModelOf(env) {
|
|
|
406
406
|
} catch { return null; }
|
|
407
407
|
}
|
|
408
408
|
|
|
409
|
-
|
|
409
|
+
/* MEMORY IN EVERY RUN (harness and memory evaluation, Wawan 2026-11-08: "Make it work"). The curated memory (D72, scripts/pmos-memory.js)
|
|
410
|
+
* reached a session only through an import in CLAUDE.md, and a lean run loads no CLAUDE.md, so a background run remembered nothing.
|
|
411
|
+
* memoryNote reads the ledger of the first folder that has one and returns its entries as a few plain lines; argsFor adds them to the
|
|
412
|
+
* run's appended system prompt. The ledger caps both lists (2,200 + 1,375 characters), so the note stays about 1k tokens. An entry the
|
|
413
|
+
* 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
|
|
414
|
+
* tools, so it holds nothing it could send out. PMOS_RUN_MEMORY=off: no note. */
|
|
415
|
+
const MEMORY_HEAD = 'What PMOS remembers (curated memory, D72). Follow it unless this run\'s own instructions say otherwise.';
|
|
416
|
+
function memoryNote(roots, env) {
|
|
417
|
+
if (/^(off|0|false|no)$/i.test(String(((env || {}).PMOS_RUN_MEMORY) || '').trim())) return '';
|
|
418
|
+
let c = null; try { c = require('./memory.js').core(); } catch { return ''; }
|
|
419
|
+
if (!c || !c.ok) return '';
|
|
420
|
+
const seen = new Set();
|
|
421
|
+
for (const r of roots || []) {
|
|
422
|
+
const root = String(r || ''); if (!root || seen.has(root)) continue; seen.add(root);
|
|
423
|
+
let cur = null; try { cur = c.core.load(root); } catch { cur = null; }
|
|
424
|
+
if (!cur || !cur.dir || !cur.state || !Array.isArray(cur.state.entries)) continue;
|
|
425
|
+
const es = cur.state.entries.filter((e) => e && typeof e.text === 'string' && e.text.trim() && !e.stale && !e.staged);
|
|
426
|
+
if (!es.length) continue;
|
|
427
|
+
const line = (e) => '- ' + (e.confidence === 'unconfirmed' ? '(unconfirmed) ' : '') + oneLine(e.text, 600);
|
|
428
|
+
const user = es.filter((e) => e.target === 'user'), mem = es.filter((e) => e.target !== 'user');
|
|
429
|
+
return [MEMORY_HEAD, ...(user.length ? ['About the PM:', ...user.map(line)] : []), ...(mem.length ? ['About the product:', ...mem.map(line)] : [])].join('\n');
|
|
430
|
+
}
|
|
431
|
+
return '';
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
function argsFor(kind, { modelArgs = [], addDirs = [], writePaths = [], budgetUsd = null, connectorTools = [], team = null, lean = false, memory = '' } = {}) {
|
|
410
435
|
if (!TOOLS[kind]) throw new Error('unknown headless kind: ' + kind);
|
|
411
436
|
let tools = TOOLS[kind].slice();
|
|
412
437
|
// A role run: the role's own tools. Its writable paths (auto mode only) are each a folder ("/" at the end: it and what is under it) or one file.
|
|
@@ -446,7 +471,7 @@ function argsFor(kind, { modelArgs = [], addDirs = [], writePaths = [], budgetUs
|
|
|
446
471
|
// dontAsk (batch 23 item 2): the PM's own Claude Code default mode must not reach a run that cannot answer. With "plan" as the PM's default, a
|
|
447
472
|
// report draft stopped after reading ("Plan mode is on, and the draft step writes files") and wrote nothing. dontAsk runs the list above and denies
|
|
448
473
|
// the rest, which is what this file already promises; it is not a bypass.
|
|
449
|
-
const argv = ['-p', '--output-format', 'stream-json', '--verbose', '--no-session-persistence', '--permission-mode', 'dontAsk', '--append-system-prompt', DENIED_RULE, ...modelArgs, '--allowedTools', tools.join(',')];
|
|
474
|
+
const argv = ['-p', '--output-format', 'stream-json', '--verbose', '--no-session-persistence', '--permission-mode', 'dontAsk', '--append-system-prompt', memory && !WEB_KINDS.includes(kind) ? DENIED_RULE + '\n\n' + String(memory) : DENIED_RULE, ...modelArgs, '--allowedTools', tools.join(',')];
|
|
450
475
|
if (lean) {
|
|
451
476
|
argv.push('--tools', builtinsOf(tools).join(','), ...LEAN_FLAGS);
|
|
452
477
|
if (!CONNECTOR_READ_KINDS.includes(kind)) argv.push('--strict-mcp-config');
|
|
@@ -634,3 +659,5 @@ function runEnvOf(extra) {
|
|
|
634
659
|
module.exports = { CONNECTOR_READ_KINDS, CONNECTOR_READ_SEED, DENIED_RULE, HEADLESS_ENV, headlessEnv, connectorReads, initTools, denialGuard, HEADLESS_SKILLS, HEADLESS_ORIGINS, ASK_ORIGINS, DRIVE_ORIGINS, SCAN_WEB_ORIGINS, SCAN_REPO_ORIGINS, SCAN_RESEARCH_WEB_ORIGINS, SCAN_RESEARCH_REPO_ORIGINS, WEB_KINDS, REPORT_SETUP_ORIGINS, REPORT_FIND_ORIGINS, CORE_DOC_ORIGINS, REPORT_DESIGN_ORIGINS, REPORT_SAMPLE_FETCH_ORIGINS, REPORT_STRUCTURE_ORIGINS, REPORT_STRUCTURE_DRY_ORIGINS, METRIC_DRAFT_ORIGINS, IMPACT_ORIGINS, TOOLS, SKILL_WRITE_DIRS, DEFAULT_TIMEOUT_MS, kindFor, argsFor, skillWriteDirs, timeoutMs, parseResult, streamLines, outcomeOf, signedOut, SIGNED_OUT_WHY, logLines, switchedOff, RUN_ENV, runEnvOf };
|
|
635
660
|
// the lean launch and the token counts (token efficiency build, 2026-11-08)
|
|
636
661
|
const LEAN_API = Object.assign(module.exports, { LEAN_FLAGS, leanOf, builtinsOf, userModelOf, tokensOf, modelOf, usageOf });
|
|
662
|
+
// the curated memory in every run (harness and memory build, 2026-11-08)
|
|
663
|
+
const MEMORY_API = Object.assign(module.exports, { MEMORY_HEAD, memoryNote });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* loop-health.js — the learning loop on the health line (harness and memory build, 2026-11-08), so its health shows without a terminal
|
|
3
|
+
* (`pmos ai status`). It adds issues to what lib/harness-health.js of() answered; GET /api/sources (lib/routes-sources.js) shows them on the
|
|
4
|
+
* Sources dot and rows. PURE: no file, no clock.
|
|
5
|
+
*
|
|
6
|
+
* loop = { demotions: [{ job, product, until, why }], verifier: [{ name, owed, lastAt, failAt, failRun }] }
|
|
7
|
+
* loopIssues(loop, now) → [{ level, key, text }]
|
|
8
|
+
* a job D106 sent back to propose → warn · the verifier silent for VERIFIER_LATE_MS while runs wait → warn · its newest verdict a FAIL → warn
|
|
9
|
+
* withLoop(h, loop, now) → h with those issues added, the worst one leading
|
|
10
|
+
* read({ workspaces, stateDirFor, env, now }) → loop the one impure part: lib/autonomy.js demotions per product, and the verifier's
|
|
11
|
+
* status per PMOS checkout (lib/verify-runs.js statusOf); at most once a minute
|
|
12
|
+
*/
|
|
13
|
+
const RANK = { ok: 0, warn: 1, bad: 2 };
|
|
14
|
+
const VERIFIER_LATE_MS = 2 * 86400000; // the verifier grades up to 4 merged runs a day; two days with none while runs wait is a stop
|
|
15
|
+
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
16
|
+
const ms = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : 0; };
|
|
17
|
+
|
|
18
|
+
/** The learning loop's issues: a job D106 sent back to propose, a verifier silent while runs wait, a verifier FAIL. */
|
|
19
|
+
function loopIssues(loop, now) {
|
|
20
|
+
const issues = [];
|
|
21
|
+
const add = (level, key, text) => issues.push({ level, key, text });
|
|
22
|
+
const L = loop && typeof loop === 'object' ? loop : {};
|
|
23
|
+
for (const d of Array.isArray(L.demotions) ? L.demotions : []) {
|
|
24
|
+
if (!d || !d.job || !(ms(d.until) > now)) continue;
|
|
25
|
+
add('warn', 'demoted:' + d.job + ':' + (d.product || ''), `${clip(d.job, 40)} proposes again until ${new Date(ms(d.until)).toDateString().slice(4, 10)}: ${clip(d.why || 'its changes were undone', 90)}`);
|
|
26
|
+
}
|
|
27
|
+
for (const v of Array.isArray(L.verifier) ? L.verifier : []) {
|
|
28
|
+
if (!v) continue;
|
|
29
|
+
const name = clip(v.name || 'this repository', 40);
|
|
30
|
+
if (v.failAt && ms(v.failAt) >= ms(v.lastAt)) add('warn', 'verifier-fail:' + name, `Verifier failed ${clip(v.failRun || 'a merged run', 60)} on ${new Date(ms(v.failAt)).toDateString().slice(4, 10)} in ${name}. See planning/runs/evals.jsonl.`);
|
|
31
|
+
else if (Number(v.owed) > 0 && now - ms(v.lastAt) > VERIFIER_LATE_MS) add('warn', 'verifier:' + name, v.lastAt ? `Verifier has graded nothing in ${name} since ${new Date(ms(v.lastAt)).toDateString().slice(4, 10)}; ${v.owed} merged runs wait.` : `Verifier has not graded a merged run in ${name} yet; ${v.owed} wait.`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return issues;
|
|
35
|
+
}
|
|
36
|
+
/** A health answer lib/harness-health.js of() gave, with the loop's issues added (the server adds them where the page reads the line, GET /api/sources). */
|
|
37
|
+
function withLoop(h, loop, now) {
|
|
38
|
+
const extra = loopIssues(loop, now);
|
|
39
|
+
if (!h || !extra.length) return h;
|
|
40
|
+
const issues = [...(h.issues || []), ...extra].sort((a, b) => RANK[b.level] - RANK[a.level]);
|
|
41
|
+
return { ...h, level: issues[0].level, line: issues[0].text, issues };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let memo = null;
|
|
45
|
+
function read({ workspaces = [], stateDirFor = () => null, env = process.env, now = Date.now() } = {}) {
|
|
46
|
+
if (memo && now - memo.at >= 0 && now - memo.at < 60000) return memo.v;
|
|
47
|
+
const fs = require('fs'), path = require('path');
|
|
48
|
+
const A = require('./autonomy.js'), VR = require('./verify-runs.js');
|
|
49
|
+
let vOff = VR.off(env); try { vOff = vOff || require('./headless.js').switchedOff(env); } catch { /* no headless lib: the verifier's own switch */ }
|
|
50
|
+
const demotions = [], verifier = [];
|
|
51
|
+
for (const w of workspaces || []) {
|
|
52
|
+
if (!w) continue;
|
|
53
|
+
try {
|
|
54
|
+
const dir = stateDirFor(w);
|
|
55
|
+
if (dir) for (const j of A.fold(A.read(dir)).jobs.values()) if (j.demote && Date.parse(j.demote.until) > now) demotions.push({ job: j.job, product: j.product, until: j.demote.until, why: j.demote.why });
|
|
56
|
+
} catch { /* an unreadable ledger says nothing */ }
|
|
57
|
+
if (vOff || !VR.isCheckout(w.root)) continue;
|
|
58
|
+
const rd = (f) => { try { return fs.readFileSync(path.join(w.root, 'planning', 'runs', f), 'utf8'); } catch { return ''; } };
|
|
59
|
+
verifier.push({ name: w.name || path.basename(w.root), ...VR.statusOf(rd('verify-queue.jsonl'), rd('evals.jsonl')) });
|
|
60
|
+
}
|
|
61
|
+
memo = { at: now, v: { demotions, verifier } };
|
|
62
|
+
return memo.v;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = { loopIssues, withLoop, read, VERIFIER_LATE_MS };
|
|
@@ -108,7 +108,7 @@ function create(deps) {
|
|
|
108
108
|
const lines = PR.readLines(PR.ledgerFile(dir)), F = PR.fold(lines);
|
|
109
109
|
const dropped = [...F.props.values()].filter((p) => p.ini === ini && F.drops.has(PR.sigOf(p))).slice(0, 20).map((p) => p.group + ' · ' + (p.title || p.type) + ' · ' + one(p.why, 100));
|
|
110
110
|
// the learning edge (OS evaluation T1): the last 3 reasons the PM gave this job on this initiative (found, dates, done, names)
|
|
111
|
-
const lessons = PR.lessonsOf(lines, { ini, match: (p) => ['found', 'dates', 'status', 'names'].includes(p.group), n: 3 });
|
|
111
|
+
const lessons = PR.lessonsOf(lines, { ini, match: (p) => ['found', 'dates', 'status', 'names'].includes(p.group), n: 3, wide: true });
|
|
112
112
|
let tasks = [];
|
|
113
113
|
if (why === 'check') { try { const c = (deps.checks(w, localDay(now)) || []).find((x) => x.ini === ini); tasks = c ? c.tasks : []; } catch { tasks = []; } }
|
|
114
114
|
const prompt = promptOf(skill, { run, why, ini, title: row.title || ini, intent: row.intent || '', stage: row.stage || '', stages: row.stages || [], today: localDay(now), tasks, dropped, lessons });
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
* (new section keys, so new ids and signatures), a reworded reason or a new day (new computed dates) does not bring it back
|
|
41
41
|
* keep { ini, board, batch, ids, wrote: [write] } ✓: what was written, each write with what it was before, for Undo and History
|
|
42
42
|
* undo { batch }
|
|
43
|
+
* expire { ini, id, sig, group, title, why } chief-of-staff C3: a filed ✦ the PM left unanswered for EXPIRE_DAYS. Nothing on the
|
|
44
|
+
* initiative changes; it folds as a drop of that signature (a newer filing with new evidence comes back), and the line keeps the
|
|
45
|
+
* reason for History. Computed date proposals (datesOf) are read fresh each time and never expire
|
|
43
46
|
* epoch { } the first scan of lib/proposal-runs.js: only initiatives made after it are looked for
|
|
44
47
|
*
|
|
45
48
|
* A WRITE (in keep.wrote): { op, task?, title?, from?, to?, why, source?, ... } op ∈ add · dates · state · rename · notes · stage · ran ·
|
|
@@ -48,7 +51,8 @@
|
|
|
48
51
|
*
|
|
49
52
|
* ledgerFile(dir) · read(dir) → fold · readLines(file) · append(dir, actor, line)
|
|
50
53
|
* fold(lines) PURE → { props, drops, kept, undone, looks, t }
|
|
51
|
-
* lessonsOf(lines, { ini, match, n }) PURE → the last n reasons the PM gave one job on one initiative (✕ why, ✎ rewrites), newest first
|
|
54
|
+
* lessonsOf(lines, { ini, match, n, wide }) PURE → the last n reasons the PM gave one job on one initiative (✕ why, ✎ rewrites), newest first
|
|
55
|
+
* wide: the job's reasons on other initiatives fill the rest, marked
|
|
52
56
|
* clean(group, type, input) → { prop } | { error } what `pmos propose` checks
|
|
53
57
|
* sigOf(p) · itemSig(p, x)
|
|
54
58
|
* tidyName(from, to) → '' when `to` keeps the standard (rule 5), else the reason it does not
|
|
@@ -63,7 +67,10 @@ const path = require('path');
|
|
|
63
67
|
const crypto = require('crypto');
|
|
64
68
|
|
|
65
69
|
const LEDGER = 'proposals.jsonl';
|
|
66
|
-
const KINDS = new Set(['epoch', 'look', 'src', 'end', 'propose', 'drop', 'keep', 'undo']);
|
|
70
|
+
const KINDS = new Set(['epoch', 'look', 'src', 'end', 'propose', 'drop', 'keep', 'undo', 'expire']);
|
|
71
|
+
/* chief-of-staff C3: a filed ✦ with no answer for this many days expires (left as it was, the reason kept) */
|
|
72
|
+
const EXPIRE_DAYS = 14;
|
|
73
|
+
const EXPIRE_WHY = 'No answer in 14 days, so I left it as it was.';
|
|
67
74
|
const GROUPS = ['found', 'dates', 'status', 'names', 'outcome', 'description'];
|
|
68
75
|
const TYPES = { found: ['stage', 'docs', 'tasks', 'link', 'maybe', 'unplaced'], dates: ['stage', 'task'], status: ['done'], names: ['tidy'], outcome: ['new', 'date'], description: ['new', 'enrich'] };
|
|
69
76
|
const SOURCES = ['drive', 'docs', 'sheets', 'slides', 'jira', 'calendar', 'notes', 'mail', 'slack', 'confluence', 'chat', 'repo'];
|
|
@@ -211,6 +218,7 @@ function fold(lines) {
|
|
|
211
218
|
const kept = []; // keep lines, oldest first
|
|
212
219
|
const undone = new Set();
|
|
213
220
|
const looks = new Map(); // ini → { run, why, at, ended, ok, stopped, sources: Map source → { state, n, what } }
|
|
221
|
+
const expired = []; // expire lines, oldest first (History and Your move's "N expired")
|
|
214
222
|
let t = '', epoch = '';
|
|
215
223
|
for (const l of lines || []) {
|
|
216
224
|
if (!isObj(l) || !KINDS.has(l.kind)) continue;
|
|
@@ -224,27 +232,38 @@ function fold(lines) {
|
|
|
224
232
|
else if (l.kind === 'drop' && str(l.sig)) { drops.add(l.sig); if (str(l.why)) dropWhy.set(l.sig, one(l.why, 300)); for (const f of Array.isArray(l.facts) ? l.facts : []) if (/^f:[0-9a-f]{10}$/.test(String(f))) drops.add(f); }
|
|
225
233
|
else if (l.kind === 'keep' && str(l.batch)) kept.push({ batch: l.batch, ini, board: str(l.board), ids: Array.isArray(l.ids) ? l.ids : [], wrote: Array.isArray(l.wrote) ? l.wrote.filter(isObj) : [], at: l.at || '', by: l.by || null });
|
|
226
234
|
else if (l.kind === 'undo' && str(l.batch)) undone.add(l.batch);
|
|
235
|
+
else if (l.kind === 'expire' && str(l.sig)) { drops.add(l.sig); expired.push({ ini, id: str(l.id), sig: l.sig, group: str(l.group), title: str(l.title), why: str(l.why) || EXPIRE_WHY, at: l.at || '' }); }
|
|
227
236
|
}
|
|
228
|
-
return { props, drops, dropWhy, kept, undone, looks, epoch, t };
|
|
237
|
+
return { props, drops, dropWhy, kept, undone, looks, epoch, t, expired };
|
|
229
238
|
}
|
|
230
239
|
/**
|
|
231
240
|
* PURE. What the PM taught one job on one initiative (OS evaluation T1, the learning edge): the reasons given with ✕ and the rewrites made
|
|
232
241
|
* with ✎, newest first, at most n. lines: the ledger, oldest first; match(p) → true for a proposal { group, type } of the job.
|
|
233
242
|
* → [string] each one line, ready for the job's prompt. A drop PMOS wrote itself (by `pmos:…`) teaches nothing.
|
|
243
|
+
* wide (harness and memory build, 2026-11-08): when this initiative has fewer than n, the job's newest reasons on OTHER initiatives fill
|
|
244
|
+
* the rest, each marked "(on another initiative)", so a correction the PM made once also reaches the job's first run on a new initiative.
|
|
234
245
|
*/
|
|
235
|
-
function lessonsOf(lines, { ini, match, n = 3 } = {}) {
|
|
246
|
+
function lessonsOf(lines, { ini, match, n = 3, wide = false } = {}) {
|
|
247
|
+
const own = lessonsOn(lines, { match, on: (i) => i === ini }).reverse().slice(0, n);
|
|
248
|
+
if (!wide || own.length >= n) return own;
|
|
249
|
+
const seen = new Set(own);
|
|
250
|
+
const other = lessonsOn(lines, { match, on: (i) => i !== ini }).reverse().filter((x) => !seen.has(x) && (seen.add(x), true));
|
|
251
|
+
return [...own, ...other.slice(0, n - own.length).map((x) => x + ' (on another initiative)')];
|
|
252
|
+
}
|
|
253
|
+
/** PURE. The lessons of one job on the initiatives `on(ini)` accepts, oldest first. A proposal is joined to its drop or keep on the same initiative. */
|
|
254
|
+
function lessonsOn(lines, { match, on }) {
|
|
236
255
|
const byId = new Map(), bySig = new Map(), out = [];
|
|
237
256
|
for (const l of lines || []) {
|
|
238
257
|
if (!isObj(l)) continue;
|
|
239
|
-
if (l.kind === 'propose' && str(l.id) && l.ini
|
|
258
|
+
if (l.kind === 'propose' && str(l.id) && on(l.ini)) {
|
|
240
259
|
if (!match(l)) continue;
|
|
241
260
|
byId.set(l.id, l);
|
|
242
261
|
const p = { id: l.id, why: l.why, sources: Array.isArray(l.sources) ? l.sources : [], items: Array.isArray(l.items) ? l.items.filter(isObj) : [] };
|
|
243
262
|
bySig.set(sigOf(p), l); for (const x of p.items) bySig.set(itemSig(p, x), l);
|
|
244
|
-
} else if (l.kind === 'drop' && l.ini
|
|
263
|
+
} else if (l.kind === 'drop' && on(l.ini) && str(l.why) && !(typeof l.by === 'string' && l.by.startsWith('pmos:'))) {
|
|
245
264
|
const p = (str(l.id) && byId.get(l.id)) || bySig.get(str(l.sig)) || (str(l.group) && match(l) ? l : null);
|
|
246
265
|
if (p) out.push(`✕ on "${one(p.title || p.type || 'a proposal', 90)}": ${one(l.why, 200)}`);
|
|
247
|
-
} else if (l.kind === 'keep' && l.ini
|
|
266
|
+
} else if (l.kind === 'keep' && on(l.ini)) {
|
|
248
267
|
for (const w of Array.isArray(l.wrote) ? l.wrote : []) {
|
|
249
268
|
if (!isObj(w) || !isObj(w.edited)) continue;
|
|
250
269
|
const ids = Array.isArray(l.ids) ? l.ids : [];
|
|
@@ -253,7 +272,7 @@ function lessonsOf(lines, { ini, match, n = 3 } = {}) {
|
|
|
253
272
|
}
|
|
254
273
|
}
|
|
255
274
|
}
|
|
256
|
-
return out
|
|
275
|
+
return out;
|
|
257
276
|
}
|
|
258
277
|
/** The kept proposal ids (a batch undone gives its proposals back). */
|
|
259
278
|
const keptIds = (F) => { const s = new Set(); for (const k of F.kept) if (!F.undone.has(k.batch)) for (const id of k.ids) s.add(id); return s; };
|
|
@@ -414,6 +433,22 @@ function viewOf(F, ini, o = {}) {
|
|
|
414
433
|
return { n: props.length, sure: props.filter((p) => p.section === 'sure').length, look: looking, groups, t: F.t };
|
|
415
434
|
}
|
|
416
435
|
|
|
436
|
+
/** chief-of-staff C3: the filed proposals with no answer for EXPIRE_DAYS days, as the expire lines to append. PURE. now: ms. A proposal
|
|
437
|
+
* kept, dropped or already expired is left out, and so is every date proposal (computed fresh from the tasks, never stale). */
|
|
438
|
+
function staleOf(F, now = Date.now(), days = EXPIRE_DAYS) {
|
|
439
|
+
if (!F) return [];
|
|
440
|
+
const kept = keptIds(F), cut = now - days * 864e5, out = [];
|
|
441
|
+
for (const p0 of F.props.values()) {
|
|
442
|
+
if (p0.group === 'dates' || kept.has(p0.id)) continue;
|
|
443
|
+
const at = Date.parse(p0.at || ''); if (!Number.isFinite(at) || at > cut) continue;
|
|
444
|
+
const sig = sigOf(p0); if (F.drops.has(sig)) continue;
|
|
445
|
+
out.push({ kind: 'expire', ini: p0.ini, id: p0.id, sig, group: p0.group, title: one(p0.title, 140), why: EXPIRE_WHY });
|
|
446
|
+
}
|
|
447
|
+
return out;
|
|
448
|
+
}
|
|
449
|
+
/** The expire lines since `since` (ms), newest first: what Your move says once ("2 expired after 14 days"). */
|
|
450
|
+
const expiredSince = (F, since) => ((F && F.expired) || []).filter((e) => Date.parse(e.at || '') >= since).reverse();
|
|
451
|
+
|
|
417
452
|
/** Claude's approved changes to one task, newest first: { at, by: 'claude', field, from, to, why, source, batch, undone } (rule 10). */
|
|
418
453
|
function historyOf(F, uid) {
|
|
419
454
|
const out = [];
|
|
@@ -444,5 +479,5 @@ function decorate(rows, F, items, o = {}) {
|
|
|
444
479
|
|
|
445
480
|
module.exports = {
|
|
446
481
|
LEDGER, GROUPS, TYPES, SOURCES, SOURCE_NAMES, RISK_DAYS, ledgerFile, read, readLines, append, fold, lessonsOf, clean, idOf, sigOf, itemSig, factsOf, tidyName, taskOf, lateOf,
|
|
447
|
-
datesOf, viewOf, foundOf, historyOf, decorate, keptIds, newBatch, dn, isoN, md, hash, workday,
|
|
482
|
+
datesOf, viewOf, foundOf, historyOf, decorate, keptIds, newBatch, dn, isoN, md, hash, workday, staleOf, expiredSince, EXPIRE_DAYS, EXPIRE_WHY,
|
|
448
483
|
};
|
|
@@ -146,6 +146,7 @@ const WRITES = {
|
|
|
146
146
|
const why = typeof body.why === 'string' ? body.why.replace(/\s+/g, ' ').trim().slice(0, 300) : '';
|
|
147
147
|
const batch = PR.newBatch();
|
|
148
148
|
LAB.append(dir, g.actor, { kind: 'drop', id: p.id, batch, ...(why ? { why } : {}) });
|
|
149
|
+
if (why) require('./corrections-memory.js').remember(w.root, { what: 'an idle-lab result', why, source: 'lab:' + p.id });
|
|
149
150
|
ctx.json(res, { ok: true, batch });
|
|
150
151
|
return true;
|
|
151
152
|
},
|
|
@@ -375,6 +375,8 @@ const WRITES = {
|
|
|
375
375
|
// the PM's reason, when given (the idle lab's ✕ asks for one; Claude learns from it)
|
|
376
376
|
const why = typeof body.why === 'string' ? body.why.replace(/\s+/g, ' ').trim().slice(0, 300) : '';
|
|
377
377
|
PR.append(dirOf(ctx, p.w), g.actor, { kind: 'drop', ini, sig, ...which, ...(facts.length ? { facts } : {}), ...(why ? { why } : {}) });
|
|
378
|
+
// the reason becomes curated memory by itself, so every later run knows it (lib/corrections-memory.js)
|
|
379
|
+
if (why) require('./corrections-memory.js').remember(p.w.root, { what: `a ${(of && (of.group || of.type)) || ''} proposal on ${ini}`.replace(/ +/g, ' '), why, source: 'proposal:' + (which.id || sig) });
|
|
378
380
|
ctx.json(res, { ok: true });
|
|
379
381
|
},
|
|
380
382
|
'/api/proposals/undo': (ctx, res, body, g, p) => {
|
|
@@ -39,6 +39,8 @@ async function handle(req, res, url, ctx) {
|
|
|
39
39
|
// self-heal (lib/source-heal.js): a row Claude is repairing, or that needs the PM, carries its repair
|
|
40
40
|
const sources = F.sources({ id: w.id, root: w.root, repoStateDir: repoStateDir(ctx, w) }).map((r) => (heal[r.id] ? { ...r, heal: heal[r.id] } : r));
|
|
41
41
|
let health = null; try { health = ctx.health ? ctx.health() : null; } catch { health = null; }
|
|
42
|
+
// the learning loop's issues (harness and memory build): a demoted job, a silent or failing verifier
|
|
43
|
+
try { if (health && ctx.workspaceList) { const LH = require('./loop-health.js'), t = Date.now(); health = LH.withLoop(health, LH.read({ workspaces: ctx.workspaceList(), stateDirFor: ctx.stateDirFor, now: t }), t); } } catch { /* the line stays as it was */ }
|
|
42
44
|
let all = null; try { all = ctx.refreshAllState ? ctx.refreshAllState() : null; } catch { all = null; }
|
|
43
45
|
let derived = []; try { derived = ctx.refreshDerived ? ctx.refreshDerived(w.id) : []; } catch { derived = []; }
|
|
44
46
|
ctx.json(res, { ok: true, ws: w.id, version: F.versions()[w.id] || 0, sources, health, all, derived });
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* routes-your-move.js — what Your move reads from a product beside its Board rows (workspace grill W3, frame WgW3Move).
|
|
3
3
|
*
|
|
4
|
-
* GET /api/your-move?ws=<id> → { ok, ws, today, verdicts: [lib/your-move.js verdict + board], kr: lib/your-move.js krOf | null
|
|
4
|
+
* GET /api/your-move?ws=<id> → { ok, ws, today, verdicts: [lib/your-move.js verdict + board], kr: lib/your-move.js krOf | null,
|
|
5
|
+
* expired: [{ ini, id, group, title, why, at }], done: lib/done-feed.js doneOf }
|
|
5
6
|
*
|
|
6
7
|
* verdicts: the outcome checks past their date with no verdict (lib/outcomes.js scan, less Intelligence's verdicts in
|
|
7
8
|
* lib/insights-records.js), each with Claude's draft from the board's Jira tickets and the board it is on (the ✓ records it there through
|
|
8
9
|
* POST /api/insights-records/verdict). kr: the first key result of the OKR file that waits on a source (lib/goal-source.js source(), the kr-metrics records
|
|
9
|
-
* as its readers).
|
|
10
|
+
* as its readers). A part that cannot be read is left out, never guessed.
|
|
11
|
+
*
|
|
12
|
+
* EXPIRY (chief-of-staff C3, board CsE). The one write: a filed ✦ the PM left unanswered for 14 days expires here, as upkeep with one right
|
|
13
|
+
* answer. Nothing on the initiative changes; one `expire` line per proposal goes to proposals.jsonl with its reason (lib/proposals.js
|
|
14
|
+
* staleOf), and `expired` lists the ones of the last 7 days, so Your move says it once. Idempotent: an expired proposal folds as dropped.
|
|
15
|
+
* DONE (C2, board CsD): what an agent kept by itself in the last 14 days, one line per batch with its Undo (lib/done-feed.js). */
|
|
10
16
|
const YM = require('./your-move.js');
|
|
11
17
|
|
|
12
18
|
const localDay = (ms = Date.now()) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
@@ -45,7 +51,19 @@ function kr(ctx, w, today) {
|
|
|
45
51
|
return YM.krOf(OG.build({ okr: src.okr, goals, initiatives: [], records: {}, today }));
|
|
46
52
|
}
|
|
47
53
|
|
|
54
|
+
/** Expire the stale ✦ of the workspace and list the ones of the last 7 days. */
|
|
55
|
+
function expire(ctx, w, now = Date.now()) {
|
|
56
|
+
const dir = ctx.stateDirFor ? ctx.stateDirFor(w) : null;
|
|
57
|
+
if (!dir) return [];
|
|
58
|
+
const PR = require('./proposals.js');
|
|
59
|
+
let F = PR.read(dir);
|
|
60
|
+
const stale = PR.staleOf(F, now);
|
|
61
|
+
if (stale.length) { for (const l of stale) PR.append(dir, { by: 'claude' }, l); F = PR.read(dir); }
|
|
62
|
+
return PR.expiredSince(F, now - 7 * 864e5).map((e) => ({ ini: e.ini, id: e.id, group: e.group, title: e.title, why: e.why, at: e.at }));
|
|
63
|
+
}
|
|
64
|
+
|
|
48
65
|
module.exports = {
|
|
66
|
+
expire,
|
|
49
67
|
prefixes: ['/api/your-move'],
|
|
50
68
|
handle: async (req, res, url, ctx) => {
|
|
51
69
|
if (url.pathname !== '/api/your-move') return false;
|
|
@@ -54,10 +72,13 @@ module.exports = {
|
|
|
54
72
|
try { w = ctx.getWs(url.searchParams.get('ws') || null); } catch { w = null; }
|
|
55
73
|
if (!w || !w.root) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
56
74
|
const today = localDay();
|
|
57
|
-
let V = [], K = null;
|
|
75
|
+
let V = [], K = null, X = [];
|
|
58
76
|
try { V = verdicts(ctx, w, today); } catch { V = []; }
|
|
59
77
|
try { K = kr(ctx, w, today); } catch { K = null; }
|
|
60
|
-
|
|
78
|
+
try { X = expire(ctx, w); } catch { X = []; }
|
|
79
|
+
let D = [];
|
|
80
|
+
try { const dir = ctx.stateDirFor ? ctx.stateDirFor(w) : null; D = dir ? require('./done-feed.js').doneOf(require('./proposals.js').read(dir)) : []; } catch { D = []; }
|
|
81
|
+
ctx.json(res, { ok: true, ws: w.id, today, verdicts: V, kr: K, expired: X, done: D });
|
|
61
82
|
return true;
|
|
62
83
|
},
|
|
63
84
|
};
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* lastWriter(F, rel) → the last write line of one artifact, or null
|
|
7
7
|
* dispatch(dir, { kind, target, ws?, board?, facts?, roles?, now }) → { ok, id, roles } | { ok: false, error }
|
|
8
8
|
* status(F, { now }) → { roles: [{ key, name, working: [..], queued: n, today: n, budget }], dispatches: [...], inbox: [...] }
|
|
9
|
-
* promptOf(role, step, o) → the prompt of one role run
|
|
9
|
+
* promptOf(role, step, o) → the prompt of one role run (o.notebook: notebookOf's result, what became of the role's earlier writes)
|
|
10
|
+
* notebookOf(F, role, autonomyLines, { n }) → { lines, kept, total }
|
|
10
11
|
* create(deps) → { tick({ now }), active() }
|
|
11
12
|
*
|
|
12
13
|
* THE LINES (append-only):
|
|
@@ -130,6 +131,28 @@ function status(F, { now = Date.now() } = {}) {
|
|
|
130
131
|
return { roles, dispatches, inbox: [...F.inbox.values()].reverse().slice(0, 20) };
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/** A role's notebook (harness + memory evaluation, item 5): what became of its earlier writes, read from the team ledger (the Evaluator's
|
|
135
|
+
* verdicts) and the autonomy ledger (the PM's Undo). The changes that were undone or failed come first, then the newest. Pure. */
|
|
136
|
+
function notebookOf(F, key, autoLines = [], { n = 5 } = {}) {
|
|
137
|
+
if (!key || key === 'eval') return { lines: [], kept: 0, total: 0 };
|
|
138
|
+
const applied = [];
|
|
139
|
+
try { for (const j of require('./autonomy.js').fold(autoLines).jobs.values()) if (j.job === 'ai:' + key) applied.push(...j.applied); } catch { /* no ledger: nothing undone */ }
|
|
140
|
+
const seen = new Set(), rows = [];
|
|
141
|
+
for (const w of F.writes.slice().reverse()) {
|
|
142
|
+
if (w.role !== key || seen.has(w.run + '|' + w.rel)) continue;
|
|
143
|
+
seen.add(w.run + '|' + w.rel);
|
|
144
|
+
const t = Date.parse(w.at) || 0;
|
|
145
|
+
const a = applied.filter((x) => x.ref === w.rel && (Date.parse(x.at) || 0) >= t - 60000).sort((x, y) => Date.parse(x.at) - Date.parse(y.at))[0];
|
|
146
|
+
const v = F.verdicts.filter((x) => x.rel === w.rel && x.of && x.of.run === w.run).pop();
|
|
147
|
+
const undone = !!(a && a.undone), failed = !!(v && v.verdict === 'fail');
|
|
148
|
+
const said = [undone ? 'the PM undid it' : 'kept', v ? `the Evaluator ${failed ? 'failed' : 'passed'} it${v.why ? ': ' + one(v.why, 160) : ''}` : ''].filter(Boolean).join('; ');
|
|
149
|
+
rows.push({ bad: undone || failed, undone, line: `${w.rel}${w.ini ? ' (' + w.ini + ')' : ''}: ${said}` });
|
|
150
|
+
}
|
|
151
|
+
const total = rows.length, kept = rows.filter((r) => !r.undone).length;
|
|
152
|
+
const lines = rows.filter((r) => r.bad).concat(rows.filter((r) => !r.bad)).slice(0, n).map((r) => r.line);
|
|
153
|
+
return { lines, kept, total };
|
|
154
|
+
}
|
|
155
|
+
|
|
133
156
|
function promptOf(r, step, o = {}) {
|
|
134
157
|
const ro = T.roleOf(r);
|
|
135
158
|
const list = (a, none) => (a && a.length ? a.map((x) => '- ' + x).join('\n') : '- ' + none);
|
|
@@ -141,7 +164,10 @@ function promptOf(r, step, o = {}) {
|
|
|
141
164
|
const evalPart = ro.key === 'eval'
|
|
142
165
|
? `\nYou are the Evaluator, in a session of your own. Check each artifact below against its rubric or the PRD's done criteria. Read only the artifacts; you do not have, and must not ask for, the transcript of the run that wrote them. For each one: \`pmos team verdict <path> pass|fail "<why, one line>"\`. PMOS refuses a verdict on work the Evaluator itself wrote.\n`
|
|
143
166
|
: '';
|
|
144
|
-
|
|
167
|
+
const nb = o.notebook && o.notebook.lines && o.notebook.lines.length
|
|
168
|
+
? `\nYour notebook: what became of your earlier work. Learn from it, and do not repeat what was undone or failed:\n${list(o.notebook.lines)}\nThe PM kept ${o.notebook.kept} of your last ${o.notebook.total} changes.\n`
|
|
169
|
+
: '';
|
|
170
|
+
return `${skill}You are the ${ro.name} on the PMOS team, under the chief of staff. You own ${ro.what}.\n\nThis run:\n- Run: ${step.id}\n- For: ${target}\n- Why: ${step.trigger === 'dispatch' ? 'the chief of staff dispatched it' : step.trigger + (step.detail ? ' (' + one(step.detail, 160) + ')' : '')}\n- Today: ${T.localDay(o.now || Date.now())}\n\nWhat the roles before you handed over (read these artifacts; they are the handoff):\n${list(o.handoff, 'nothing yet')}\n${evalPart}${nb}\n${mode}\n\nEnd with \`pmos team done "<what you did, in one line>"\`.\n`;
|
|
145
171
|
}
|
|
146
172
|
|
|
147
173
|
/** deps: { workspaces() → [w], stateDirFor(w), inis(w) → [{ ini, board, stage, has }], promptFor(skillId), spawn(spec) → session,
|
|
@@ -167,7 +193,9 @@ function create(deps) {
|
|
|
167
193
|
const mode = auto(dir, ro);
|
|
168
194
|
const dsp = step.dispatch ? F.dispatches.get(step.dispatch) : null;
|
|
169
195
|
const skill = ro.skills.map((s) => { try { return deps.promptFor ? deps.promptFor(s) : null; } catch { return null; } }).find(Boolean) || '';
|
|
170
|
-
|
|
196
|
+
let notebook = null;
|
|
197
|
+
if (!/^(off|0|false|no)$/i.test(String(process.env.PMOS_RUN_MEMORY || '').trim())) { try { notebook = notebookOf(F, ro.key, require('./autonomy.js').read(dir)); } catch (e) { warn('team notebook', e); } }
|
|
198
|
+
const prompt = promptOf(ro.key, step, { mode, handoff: handoffOf(F, step), goal: dsp && dsp.of === 'goal' ? dsp.target : '', skill, notebook, now });
|
|
171
199
|
const { tools, writePaths } = T.toolsOf(ro, { root: w.root, mode });
|
|
172
200
|
const env = { PMOS_TEAM_FILE: file(dir), PMOS_TEAM_ROOT: w.root || '', PMOS_TEAM_WS: w.id || '', PMOS_TEAM_ROLE: ro.key, PMOS_TEAM_RUN: step.id,
|
|
173
201
|
PMOS_TEAM_INI: step.ini || '', PMOS_TEAM_MODE: mode };
|
|
@@ -241,4 +269,4 @@ function create(deps) {
|
|
|
241
269
|
return { tick, ended, active: () => [...active.keys()], stop(run) { const a = active.get(run); if (a && a.session && deps.stop) deps.stop(a.session); } };
|
|
242
270
|
}
|
|
243
271
|
|
|
244
|
-
module.exports = { factsOf, LEDGER, append, read, fold, lastWriter, unchecked, dispatch, status, promptOf, create };
|
|
272
|
+
module.exports = { factsOf, LEDGER, append, read, fold, lastWriter, unchecked, dispatch, status, promptOf, notebookOf, create };
|