create-pmos 0.537.0 → 0.538.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 +68 -14
- package/payload/KIT-VERSION +2 -2
- 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/payload/state/log.md +1 -1
- package/workspace/board-columns-test.js +11 -10
- package/workspace/board-programs-test.js +21 -23
- package/workspace/board-publish-ui-test.js +19 -15
- package/workspace/board-shared-ui-test.js +15 -12
- package/workspace/briefing-premium-board-test.js +46 -31
- package/workspace/briefing-premium-insights-test.js +24 -31
- package/workspace/briefing-premium-metrics-test.js +2 -2
- package/workspace/calm-timeline-test.js +1 -1
- package/workspace/changelog.json +67 -0
- package/workspace/ev-everywhere-test.js +4 -5
- package/workspace/fixtures/board-premium-facts.js +1 -1
- package/workspace/fixtures/initiative-premium-facts.js +1 -1
- package/workspace/fixtures/insights-premium-facts.js +6 -6
- package/workspace/fixtures/program-ascent.js +1 -1
- package/workspace/guide/adler.md +2 -2
- package/workspace/guide/agent-capabilities.md +38 -6
- package/workspace/guide/board.md +13 -6
- package/workspace/guide/claude-proposes.md +1 -1
- package/workspace/guide/home.md +2 -2
- package/workspace/guide/index.md +3 -3
- package/workspace/guide/intelligence-okr-goals.md +18 -7
- package/workspace/guide/lifecycle.md +2 -2
- package/workspace/guide/programs.md +2 -2
- package/workspace/guide/reports-needs-you.md +5 -5
- package/workspace/guide/settings.md +14 -11
- package/workspace/guide/workflows.md +3 -3
- package/workspace/guide/your-impact.md +1 -1
- package/workspace/lib/agent-team.js +262 -0
- package/workspace/lib/ai-cli.js +36 -4
- package/workspace/lib/bg-queue.js +9 -4
- package/workspace/lib/board-premium.js +6 -3
- package/workspace/lib/goal-source.js +77 -0
- package/workspace/lib/grill-runs.js +6 -3
- package/workspace/lib/headless.js +36 -4
- package/workspace/lib/idle-lab-engine.js +7 -6
- package/workspace/lib/initiative-premium.js +6 -3
- package/workspace/lib/insights-premium.js +1 -1
- package/workspace/lib/job-graph.js +191 -0
- package/workspace/lib/okr-goals.js +3 -0
- package/workspace/lib/orchestrator-keeprate.js +108 -7
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/proposal-runs.js +8 -5
- package/workspace/lib/proposals.js +32 -2
- package/workspace/lib/report-slots.js +14 -10
- package/workspace/lib/routes-boards.js +2 -2
- package/workspace/lib/routes-insights-premium.js +11 -4
- package/workspace/lib/routes-premium-dashboards.js +20 -6
- package/workspace/lib/routes-proposals.js +10 -5
- package/workspace/lib/routes-your-move.js +6 -7
- package/workspace/lib/status-proof.js +45 -0
- package/workspace/lib/status-signal.js +4 -2
- package/workspace/lib/task-links.js +3 -1
- package/workspace/lib/team-cli.js +164 -0
- package/workspace/lib/team-runs.js +244 -0
- package/workspace/lib/verify-runs.js +112 -0
- package/workspace/okr-goals-ui-test.js +10 -13
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-vw-backlog-test.js +2 -2
- package/workspace/premium-vw-jira-test.js +1 -1
- package/workspace/public/pm/bd-acts.js +14 -34
- package/workspace/public/pm/bd-ini-panel.js +38 -27
- package/workspace/public/pm/bd-publish.js +1 -1
- package/workspace/public/pm/bd-span.js +2 -1
- package/workspace/public/pm/bd-views.js +7 -5
- package/workspace/public/pm/c3-ini-ui.js +9 -7
- package/workspace/public/pm/cozy-board.css +17 -6
- package/workspace/public/pm/cozy-insights.css +18 -0
- package/workspace/public/pm/cozy-nav.js +2 -2
- package/workspace/public/pm/cozy-search.js +29 -7
- package/workspace/public/pm/cozy-settings.js +39 -20
- package/workspace/public/pm/home-data.js +3 -1
- package/workspace/public/pm/home-ini-model.js +15 -1
- package/workspace/public/pm/home-ini.js +9 -3
- package/workspace/public/pm/ini-tail.js +61 -0
- package/workspace/public/pm/ini-view-model.js +10 -7
- package/workspace/public/pm/premium-board.js +66 -99
- package/workspace/public/pm/premium-insights.js +95 -112
- package/workspace/public/pm/premium-report-intel.js +3 -2
- package/workspace/public/pm/readonly.js +4 -3
- package/workspace/public/pm/stage-chip.js +2 -1
- package/workspace/public/pm/status-proof.js +43 -0
- package/workspace/public/premium-board.html +10 -28
- package/workspace/public/premium-intelligence.html +7 -9
- package/workspace/server.js +35 -1
- package/workspace/sort-order-test.js +10 -8
- package/workspace/test-files.json +4 -2
- package/workspace/test-lists/agent-team.json +9 -0
- package/workspace/test-lists/job-graph.json +11 -0
- package/workspace/test-lists/status-proof.json +5 -0
- package/workspace/workflows-setup-test.js +3 -2
- package/workspace/public/premium-chat.html +0 -14
- package/workspace/public/premium-initiative.html +0 -15
- package/workspace/public/premium-work.html +0 -14
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* agent-team.js — the role agents under the chief of staff (brief /mnt/project-files/os-eval/brief-agent-team.md, section GO;
|
|
3
|
+
* Wawan 2026-11-08 02:28 "Ok go work on the proposal").
|
|
4
|
+
*
|
|
5
|
+
* TEAM · ORDER · FORBIDDEN the role records, the order roles hand off in, the paths no role may write
|
|
6
|
+
* roleOf(key) → role | null one role record
|
|
7
|
+
* mayWrite(role, target, { root? }) → { ok, why?, rel? }
|
|
8
|
+
* assertWrite(role, target, { root? }) throws RoleWriteRefused, like lib/drive-guard.js
|
|
9
|
+
* mayRunVerb(role, command) → { ok, why? } a `pmos …` command line against the role's verb allowlist
|
|
10
|
+
* mayEvaluate({ run, session }, lastWriter) → { ok, why? }
|
|
11
|
+
* modeOf(role, autoFor?) → 'auto' | 'propose'
|
|
12
|
+
* due({ roles, inis, steps, paused, now }) → [{ role, ini, board, ws, trigger, key }] PURE: what the per-role triggers wake now
|
|
13
|
+
* planDispatch({ kind, target, facts, roles? }) → [role key] PURE: the roles a dispatch runs, in order
|
|
14
|
+
* toolsOf(role, { root, mode }) → { tools: [...], writePaths: [abs] } the headless tool list of one role run
|
|
15
|
+
* tableForPage() → plain data for `pmos team roles` and, later, the Team board
|
|
16
|
+
*
|
|
17
|
+
* BEFORE THIS, a role was only a LABEL (lib/agent-roles.js roleOf: derived from the skill that started a session). It owned nothing, had no
|
|
18
|
+
* trigger, no budget and no permission of its own. This file makes each role a RECORD: the skills it runs, the artifacts it owns (the only
|
|
19
|
+
* things it may write), what it reads, what wakes it, its action class, the connectors it may read and its share of the runs.
|
|
20
|
+
* agent-roles.js keeps its labels; this file takes `name` and `initial` from it, so a session and its role never disagree about a name.
|
|
21
|
+
*
|
|
22
|
+
* THE WRITE ALLOWLIST. A role writes two kinds of thing:
|
|
23
|
+
* paths repository paths relative to the root. An entry that ends in "/" is a folder and what is under it; any other entry is one file.
|
|
24
|
+
* verbs `pmos …` command prefixes, for the records PMOS keeps behind a verb (tasks, measured values, outcome proposals).
|
|
25
|
+
* Anything not on a role's lists is refused. It is an allowlist for the same reason drive-guard.js is one: a denylist is "everything somebody
|
|
26
|
+
* thought of". On top of it, FORBIDDEN names the control-graph records no role may write even if a role's list is widened by mistake
|
|
27
|
+
* (decisions, acceptances, the anchors of initiatives, the agent rules). The factory may never write a control-graph record (D65); neither
|
|
28
|
+
* may a role agent.
|
|
29
|
+
*
|
|
30
|
+
* WHERE IT BINDS, honestly. A role run is a headless `claude -p` run (lib/headless.js kind `team`). Its Write and Edit tools are scoped by
|
|
31
|
+
* toolsOf() to the role's own paths, so Claude Code itself refuses a write anywhere else; its Bash list holds only the role's verbs and the
|
|
32
|
+
* `pmos team` verbs. `pmos team wrote` (lib/team-cli.js) calls assertWrite again and records the write, so the last writer of each artifact is
|
|
33
|
+
* known. This binds the role runs PMOS starts. A person, a chat session or another job is not bound by it.
|
|
34
|
+
*
|
|
35
|
+
* THE EVALUATOR NEVER CHECKS ITS OWN WORK. mayEvaluate refuses a verdict on an artifact whose last recorded writer is the Evaluator role, or
|
|
36
|
+
* is the same run or session as the one asking. An Evaluator run is always a session of its own, started for that check alone, and its prompt
|
|
37
|
+
* names the artifacts, never the transcript of the run that wrote them (lib/team-runs.js).
|
|
38
|
+
*
|
|
39
|
+
* ACTION CLASSES come from the autonomy build ("Let agents act without approval"): A reversible upkeep, B judgment with Undo, C outward or
|
|
40
|
+
* irreversible. modeOf asks `autoFor(cls)`; until that build lands nothing answers true, so every role runs in propose mode: it writes
|
|
41
|
+
* nothing and reports what it would write. The chief of staff collects the reports into one inbox entry.
|
|
42
|
+
*/
|
|
43
|
+
const path = require('path');
|
|
44
|
+
const { ROLES } = require('./agent-roles.js');
|
|
45
|
+
|
|
46
|
+
class RoleWriteRefused extends Error {
|
|
47
|
+
constructor(role, target, detail) {
|
|
48
|
+
super(`agent-team: the ${role} may not write ${target}: ${detail}`);
|
|
49
|
+
this.name = 'RoleWriteRefused';
|
|
50
|
+
this.role = role;
|
|
51
|
+
this.target = target;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* No role writes these, whatever its list says. Lower case; a folder ends in "/". */
|
|
56
|
+
const FORBIDDEN = Object.freeze([
|
|
57
|
+
'decisions.md', 'pm-decisions.md', 'principles.md', 'claude.md', 'agents.md', 'bootstrap-debt.md',
|
|
58
|
+
'okf/products/pmos/adr/', 'planning/initiatives/', '.github/', 'scripts/', 'workspace/', 'kit/', 'npm-pkg/',
|
|
59
|
+
'pmos/state/acceptances.jsonl', 'state/acceptances.jsonl', 'planning/runs/',
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
const label = (key) => ({ name: ROLES[key] ? ROLES[key].name : key, initial: ROLES[key] ? ROLES[key].initial : key.slice(0, 2) });
|
|
63
|
+
const role = (key, o) => Object.freeze({ key, ...label(key), ...o,
|
|
64
|
+
owns: Object.freeze({ paths: Object.freeze(o.owns.paths || []), verbs: Object.freeze(o.owns.verbs || []) }),
|
|
65
|
+
reads: Object.freeze(o.reads || []), triggers: Object.freeze(o.triggers || []), skills: Object.freeze(o.skills || []),
|
|
66
|
+
connectors: Object.freeze(o.connectors || []) });
|
|
67
|
+
|
|
68
|
+
/* trigger shapes (due() reads them):
|
|
69
|
+
* { on: 'stage', stage: /re/, unless: 'prd'|'rubric'|'tasks' } an initiative is in a stage whose name matches, and lacks that artifact
|
|
70
|
+
* { on: 'written' } another role recorded a write (the Evaluator)
|
|
71
|
+
* { on: 'asked' } only a dispatch starts it
|
|
72
|
+
* budget: the most runs the role starts in one local day; it shares the queue's cap (bg-queue CAP) and the capacity governor with every job. */
|
|
73
|
+
const TEAM = Object.freeze({
|
|
74
|
+
chief: Object.freeze({ key: 'chief', name: 'Chief of staff', initial: 'Cs', cls: 'dispatch', runs: false, skills: Object.freeze([]),
|
|
75
|
+
owns: Object.freeze({ paths: Object.freeze([]), verbs: Object.freeze([]) }), reads: Object.freeze(['every role\'s results']),
|
|
76
|
+
triggers: Object.freeze([{ on: 'asked' }]), connectors: Object.freeze([]), budget: 0,
|
|
77
|
+
what: 'the conversation with you, the goals, the one inbox; dispatches the others and runs no model of its own' }),
|
|
78
|
+
strategy: role('strategy', { cls: 'B', runs: true, skills: ['okr', 'metrics-review', 'health-budgets'], budget: 2,
|
|
79
|
+
owns: { paths: ['planning/okrs/'], verbs: ['pmos measure add', 'pmos initiative top', 'pmos initiative up', 'pmos initiative down', 'pmos initiative bottom', 'pmos initiative after'] },
|
|
80
|
+
reads: ['planning/okrs/', 'planning/prd/', 'the metric readings'], triggers: [{ on: 'asked' }], connectors: ['analytics'],
|
|
81
|
+
what: 'OKRs, the North Star, health budgets and the ranking' }),
|
|
82
|
+
research: role('research', { cls: 'B', runs: true, skills: ['discovery', 'synthesize-research'], budget: 3,
|
|
83
|
+
owns: { paths: ['planning/research/', 'planning/radar/'] }, reads: ['planning/', 'the stored reads'],
|
|
84
|
+
triggers: [{ on: 'stage', stage: /^(triage|discover|discovery)/i, unless: 'research' }], connectors: ['docs', 'slack', 'mail'],
|
|
85
|
+
what: 'discovery notes and scans' }),
|
|
86
|
+
spec: role('spec', { cls: 'B', runs: true, skills: ['prd', 'eval-rubric'], budget: 3,
|
|
87
|
+
owns: { paths: ['planning/prd/', 'planning/evals/'], verbs: ['pmos outcomes propose'] }, reads: ['planning/okrs/', 'planning/research/'],
|
|
88
|
+
triggers: [{ on: 'stage', stage: /^plan/i, unless: 'prd' }], connectors: ['docs'],
|
|
89
|
+
what: 'the PRD, the rubric, the expected outcome and its check date' }),
|
|
90
|
+
design: role('design', { cls: 'B', runs: true, skills: ['prototype', 'design-brief'], budget: 1,
|
|
91
|
+
owns: { paths: ['prototype/', 'planning/design/'] }, reads: ['planning/prd/', 'okf/products/pmos/references/design-principles.md'],
|
|
92
|
+
triggers: [{ on: 'asked' }], connectors: [], what: 'prototypes and specimens' }),
|
|
93
|
+
eval: role('eval', { cls: 'A', runs: true, skills: ['evaluator'], budget: 6,
|
|
94
|
+
owns: { paths: [], verbs: ['pmos team verdict'] }, reads: ['what the other roles wrote', 'planning/evals/'],
|
|
95
|
+
triggers: [{ on: 'written' }], connectors: [], independent: true,
|
|
96
|
+
what: 'findings and verdicts on what the other roles wrote; never on its own work' }),
|
|
97
|
+
delivery: role('delivery', { cls: 'B', runs: true, skills: ['tracker-handoff', 'sprint-planning'], budget: 3,
|
|
98
|
+
owns: { paths: [], verbs: ['pmos task add', 'pmos task set', 'pmos task state', 'pmos jira draft'] }, reads: ['planning/prd/', 'the tasks', 'Jira'],
|
|
99
|
+
triggers: [{ on: 'stage', stage: /^(prioriti[sz]e|build)/i, unless: 'tasks' }], connectors: ['jira'],
|
|
100
|
+
what: 'the task breakdown, dates and risks; Jira moves others see are class C' }),
|
|
101
|
+
comms: role('comms', { cls: 'B', runs: true, skills: ['stakeholder-update', 'weekly-update'], budget: 2,
|
|
102
|
+
owns: { paths: ['planning/reports/'], verbs: ['pmos report draft'] }, reads: ['planning/', 'the reports'], triggers: [{ on: 'asked' }],
|
|
103
|
+
connectors: ['docs'], what: 'reports and drafts; sending is class C' }),
|
|
104
|
+
build: role('build', { cls: 'C', runs: false, skills: ['builder'], budget: 0, owns: { paths: [] }, reads: ['planning/prd/', 'planning/evals/'],
|
|
105
|
+
triggers: [{ on: 'asked' }], connectors: [],
|
|
106
|
+
what: 'pull requests in the product repositories (the factory, propose-only, D65); never a run of this team' }),
|
|
107
|
+
});
|
|
108
|
+
/* The order roles hand off in. A dispatch keeps this order whatever roles it picks. */
|
|
109
|
+
const ORDER = Object.freeze(['strategy', 'research', 'spec', 'design', 'eval', 'delivery', 'comms']);
|
|
110
|
+
|
|
111
|
+
const roleOf = (key) => TEAM[String(key || '')] || null;
|
|
112
|
+
|
|
113
|
+
/** A repository-relative, forward-slash path, or null when the target escapes the root or is empty. */
|
|
114
|
+
function relOf(target, root) {
|
|
115
|
+
let t = String(target == null ? '' : target).trim().replace(/\\/g, '/');
|
|
116
|
+
if (!t || t.includes('\0')) return null;
|
|
117
|
+
const base = root ? path.resolve(String(root)) : null;
|
|
118
|
+
if (path.isAbsolute(t) || /^[a-z]:\//i.test(t)) {
|
|
119
|
+
if (!base) return null;
|
|
120
|
+
const r = path.relative(base, path.resolve(t));
|
|
121
|
+
if (!r || r.startsWith('..') || path.isAbsolute(r)) return null;
|
|
122
|
+
t = r.replace(/\\/g, '/');
|
|
123
|
+
}
|
|
124
|
+
const norm = path.posix.normalize(t).replace(/^\.\//, '');
|
|
125
|
+
if (!norm || norm === '.' || norm.startsWith('../') || norm === '..' || norm.startsWith('/')) return null;
|
|
126
|
+
return norm.replace(/\/+$/, '');
|
|
127
|
+
}
|
|
128
|
+
const under = (rel, entry) => (entry.endsWith('/') ? rel === entry.slice(0, -1) || rel.startsWith(entry) : rel === entry);
|
|
129
|
+
|
|
130
|
+
function mayWrite(r, target, { root = null } = {}) {
|
|
131
|
+
const ro = typeof r === 'string' ? roleOf(r) : r;
|
|
132
|
+
if (!ro) return { ok: false, why: 'no such role' };
|
|
133
|
+
const rel = relOf(target, root);
|
|
134
|
+
if (!rel) return { ok: false, why: 'the path is empty or outside the repository' };
|
|
135
|
+
const low = rel.toLowerCase(); // a case-insensitive disk (macOS) must not let DECISIONS.md in as decisions.MD
|
|
136
|
+
if (FORBIDDEN.some((f) => under(low, f))) return { ok: false, why: 'it is a control-graph record no role writes', rel };
|
|
137
|
+
if (!ro.owns.paths.some((p) => { const e = p.toLowerCase(); return e.endsWith('/') ? low.startsWith(e) : low === e; })) // a folder entry admits what is under it, never the folder itself
|
|
138
|
+
return { ok: false, why: `it is not one of the ${ro.name}'s artifacts (${ro.owns.paths.join(', ') || 'none'})`, rel };
|
|
139
|
+
return { ok: true, rel };
|
|
140
|
+
}
|
|
141
|
+
function assertWrite(r, target, opts) {
|
|
142
|
+
const v = mayWrite(r, target, opts);
|
|
143
|
+
if (!v.ok) throw new RoleWriteRefused(typeof r === 'string' ? r : (r && r.key) || '?', String(target), v.why);
|
|
144
|
+
return v.rel;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A `pmos …` command against the role's verbs: the command must start with one of them, word for word. */
|
|
148
|
+
function mayRunVerb(r, command) {
|
|
149
|
+
const ro = typeof r === 'string' ? roleOf(r) : r;
|
|
150
|
+
if (!ro) return { ok: false, why: 'no such role' };
|
|
151
|
+
const c = String(command || '').trim().replace(/\s+/g, ' ');
|
|
152
|
+
if (!c) return { ok: false, why: 'no command' };
|
|
153
|
+
if (/[;&|`$<>]/.test(c)) return { ok: false, why: 'one command at a time, with no shell operators' };
|
|
154
|
+
if (ro.owns.verbs.some((v) => c === v || c.startsWith(v + ' '))) return { ok: true };
|
|
155
|
+
return { ok: false, why: `it is not one of the ${ro.name}'s verbs (${ro.owns.verbs.join(', ') || 'none'})` };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** asker: { run, session } of the Evaluator run. lastWriter: the last `write` line of the artifact ({ role, run, session }) or null. */
|
|
159
|
+
function mayEvaluate(asker, lastWriter) {
|
|
160
|
+
if (!lastWriter) return { ok: false, why: 'no role run wrote it, so there is nothing of a role to check' };
|
|
161
|
+
if (lastWriter.role === 'eval') return { ok: false, why: 'the Evaluator wrote it last; it never checks its own work' };
|
|
162
|
+
if (asker && asker.run && lastWriter.run && asker.run === lastWriter.run) return { ok: false, why: 'the same run wrote it' };
|
|
163
|
+
if (asker && asker.session && lastWriter.session && asker.session === lastWriter.session) return { ok: false, why: 'the same session wrote it' };
|
|
164
|
+
return { ok: true };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 'auto' when the autonomy build says the role's class applies by itself, else 'propose'. A role with no class of its own never auto-applies. */
|
|
168
|
+
function modeOf(r, autoFor = null) {
|
|
169
|
+
const ro = typeof r === 'string' ? roleOf(r) : r;
|
|
170
|
+
if (!ro || !/^[AB]$/.test(ro.cls)) return 'propose';
|
|
171
|
+
let yes = false;
|
|
172
|
+
try { yes = !!(autoFor && autoFor(ro.cls)); } catch { yes = false; }
|
|
173
|
+
return yes ? 'auto' : 'propose';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
177
|
+
|
|
178
|
+
/** PURE. What the per-role triggers wake now.
|
|
179
|
+
* inis: [{ ws, ini, board?, stage, has: { prd, rubric, tasks, research } }]
|
|
180
|
+
* steps: the folded steps (lib/team-runs.js fold().steps): [{ role, ini, key, state, at }]
|
|
181
|
+
* writes: the folded write lines not yet checked: [{ role, run, rel, ini, ws, at }]
|
|
182
|
+
* paused: Set of role keys (or 'all')
|
|
183
|
+
* One run per initiative per role: a role with a live step on an initiative is not woken on it again. A trigger key fires once. A role at its
|
|
184
|
+
* budget for the day waits for the next day. */
|
|
185
|
+
function due({ roles = TEAM, inis = [], steps = [], writes = [], paused = new Set(), now = Date.now(), checked = new Set() } = {}) {
|
|
186
|
+
if (paused.has('all')) return [];
|
|
187
|
+
const keys = new Set(steps.map((s) => s.key).filter(Boolean));
|
|
188
|
+
const live = new Set(steps.filter((s) => s.state === 'queued' || s.state === 'running' || s.state === 'held').map((s) => s.role + '\u0000' + s.ini));
|
|
189
|
+
const today = localDay(now);
|
|
190
|
+
const spent = new Map();
|
|
191
|
+
for (const s of steps) if (s.started && localDay(Date.parse(s.started)) === today) spent.set(s.role, (spent.get(s.role) || 0) + 1);
|
|
192
|
+
const out = [];
|
|
193
|
+
const room = (r) => (spent.get(r.key) || 0) + out.filter((o) => o.role === r.key).length < r.budget;
|
|
194
|
+
for (const r of Object.values(roles)) {
|
|
195
|
+
if (!r.runs || paused.has(r.key)) continue;
|
|
196
|
+
for (const t of r.triggers) {
|
|
197
|
+
if (t.on === 'stage') {
|
|
198
|
+
for (const x of inis) {
|
|
199
|
+
if (!x || !x.ini || !t.stage.test(String(x.stage || ''))) continue;
|
|
200
|
+
if (t.unless && x.has && x.has[t.unless]) continue;
|
|
201
|
+
const key = `stage:${x.ws || ''}:${x.ini}:${r.key}:${String(x.stage).toLowerCase()}`;
|
|
202
|
+
if (keys.has(key) || live.has(r.key + '\u0000' + x.ini) || !room(r)) continue;
|
|
203
|
+
out.push({ role: r.key, ini: x.ini, board: x.board || null, ws: x.ws || null, trigger: 'stage', key, detail: 'stage ' + x.stage });
|
|
204
|
+
}
|
|
205
|
+
} else if (t.on === 'written') {
|
|
206
|
+
for (const w of writes) {
|
|
207
|
+
if (!w || w.role === r.key || !w.rel) continue;
|
|
208
|
+
const key = `written:${w.run}:${w.rel}`;
|
|
209
|
+
if (keys.has(key) || checked.has(key) || !room(r)) continue;
|
|
210
|
+
if (out.some((o) => o.role === r.key && o.ini === (w.ini || null) && o.trigger === 'written')) continue; // one check run per initiative per tick
|
|
211
|
+
if (live.has(r.key + '\u0000' + (w.ini || '-'))) continue;
|
|
212
|
+
out.push({ role: r.key, ini: w.ini || null, ws: w.ws || null, board: null, trigger: 'written', key, detail: w.rel, artifacts: [w.rel] });
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** PURE. The roles a dispatch runs, in ORDER. kind 'goal': Strategist, Researcher, Evaluator. kind 'initiative': what its artifacts still lack
|
|
221
|
+
* (facts: { prd, rubric, tasks }), always checked by the Evaluator before the Delivery lead breaks it down. `roles` overrides the pick (unknown
|
|
222
|
+
* keys and roles that do not run are dropped, and an Evaluator is added after the first writing role when none is named). */
|
|
223
|
+
function planDispatch({ kind = 'initiative', facts = {}, roles = null } = {}) {
|
|
224
|
+
let pick;
|
|
225
|
+
if (Array.isArray(roles) && roles.length) {
|
|
226
|
+
pick = roles.map(String).filter((k) => TEAM[k] && TEAM[k].runs);
|
|
227
|
+
if (pick.length && !pick.includes('eval') && pick.some((k) => k !== 'eval')) pick.push('eval');
|
|
228
|
+
} else if (kind === 'goal') {
|
|
229
|
+
pick = ['strategy', 'research', 'eval'];
|
|
230
|
+
} else {
|
|
231
|
+
pick = [];
|
|
232
|
+
if (!facts.prd || !facts.rubric) pick.push('spec');
|
|
233
|
+
pick.push('eval');
|
|
234
|
+
if (!facts.tasks) pick.push('delivery');
|
|
235
|
+
}
|
|
236
|
+
return ORDER.filter((k) => pick.includes(k));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** The headless tool list of one role run. Read tools for every role; Write and Edit only on the role's own paths, and only in auto mode;
|
|
240
|
+
* Bash only for the role's verbs (auto mode) and the `pmos team` verbs. */
|
|
241
|
+
function toolsOf(r, { root = null, mode = 'propose' } = {}) {
|
|
242
|
+
const ro = typeof r === 'string' ? roleOf(r) : r;
|
|
243
|
+
const tools = ['Read', 'Glob', 'Grep', 'Bash(pmos team done *)', 'Bash(pmos team status *)', 'Bash(pmos initiative export *)', 'Bash(pmos initiative list *)',
|
|
244
|
+
'Bash(pmos task list *)', 'Bash(git log *)', 'Bash(date *)'];
|
|
245
|
+
const writePaths = [];
|
|
246
|
+
if (!ro) return { tools, writePaths };
|
|
247
|
+
if (ro.key === 'eval') tools.push('Bash(pmos team verdict *)');
|
|
248
|
+
if (mode === 'auto') {
|
|
249
|
+
tools.push('Bash(pmos team wrote *)');
|
|
250
|
+
for (const v of ro.owns.verbs) if (v !== 'pmos team verdict') tools.push(`Bash(${v} *)`);
|
|
251
|
+
if (root) for (const p of ro.owns.paths) writePaths.push(path.join(path.resolve(String(root)), p.replace(/\/+$/, '')) + (p.endsWith('/') ? '/' : ''));
|
|
252
|
+
}
|
|
253
|
+
return { tools, writePaths };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function tableForPage() {
|
|
257
|
+
return Object.values(TEAM).map((r) => ({ key: r.key, name: r.name, initial: r.initial, cls: r.cls, runs: r.runs, budget: r.budget, what: r.what,
|
|
258
|
+
skills: [...r.skills], owns: { paths: [...r.owns.paths], verbs: [...r.owns.verbs] }, reads: [...r.reads], connectors: [...r.connectors],
|
|
259
|
+
triggers: r.triggers.map((t) => (t.on === 'stage' ? { on: 'stage', stage: t.stage.source, unless: t.unless || null } : { on: t.on })) }));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
module.exports = { TEAM, ORDER, FORBIDDEN, RoleWriteRefused, roleOf, relOf, mayWrite, assertWrite, mayRunVerb, mayEvaluate, modeOf, due, planDispatch, toolsOf, tableForPage, localDay };
|
package/workspace/lib/ai-cli.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* ai-cli.js — `pmos ai`: the kill switch and the audit of the AI jobs that file through lib/ai-guard.js.
|
|
3
3
|
*
|
|
4
|
-
* pmos ai status [--json] the switch, each job's replay state and its last run
|
|
4
|
+
* pmos ai status [--json] the switch, each job's replay state and its last run, and the keep rate of every ✦ job (OS evaluation
|
|
5
|
+
* T1): the last 14 days, per job and per product, from each hosted product's proposals.jsonl. A job with
|
|
6
|
+
* 3 or more decided and none kept is listed to pause; the PM pauses it (`pmos ai off <job>`), never this.
|
|
5
7
|
* pmos ai off [<job>] turn every AI job off, or one job
|
|
6
8
|
* pmos ai on [<job>] turn every AI job on again, or one job
|
|
7
9
|
* pmos ai log [<job>] [--n N] the last audit lines: filed, dropped (with why), held, off, replay
|
|
@@ -21,8 +23,27 @@ const USAGE = [
|
|
|
21
23
|
];
|
|
22
24
|
const flag = (args, k) => { const i = args.indexOf('--' + k); return i >= 0 ? (args[i + 1] === undefined || args[i + 1].startsWith('--') ? true : args[i + 1]) : undefined; };
|
|
23
25
|
const stateOf = (env) => require('./state-root.js').defaultRoot({ env });
|
|
26
|
+
const fs = require('fs');
|
|
27
|
+
const path = require('path');
|
|
28
|
+
/** The product repositories the workspace hosts (workspaces.json in the state folder), and this one when it has a PMOS state folder. */
|
|
29
|
+
function rootsOf(dir, cwd) {
|
|
30
|
+
let reg = [];
|
|
31
|
+
try { reg = JSON.parse(fs.readFileSync(path.join(dir, 'workspaces.json'), 'utf8')); } catch { reg = []; }
|
|
32
|
+
const out = (Array.isArray(reg) ? reg : []).filter((x) => x && typeof x.root === 'string').map((x) => path.resolve(x.root));
|
|
33
|
+
if (cwd && !out.includes(path.resolve(cwd)) && require('./driver.js').stateDirOf(cwd)) out.push(path.resolve(cwd));
|
|
34
|
+
return [...new Set(out)];
|
|
35
|
+
}
|
|
36
|
+
const pct = (r) => (r == null ? '–' : Math.round(r * 100) + '%');
|
|
37
|
+
/** The ✦ keep rate: { since, jobs: [row], products: [{ product, jobs: [row] }], pause: [job], unplaced } (lib/orchestrator-keeprate.js byJob). */
|
|
38
|
+
function keepOf(roots, now) {
|
|
39
|
+
const K = require('./orchestrator-keeprate.js');
|
|
40
|
+
const { items, unplaced } = K.readAll(roots);
|
|
41
|
+
const products = [...new Set(items.filter((x) => x.src === 'proposal').map((x) => x.product))].sort();
|
|
42
|
+
const jobs = K.byJob(items, { now });
|
|
43
|
+
return { days: K.PAUSE_DAYS, jobs, products: products.map((product) => ({ product, jobs: K.byJob(items, { now, product }) })), pause: [...new Set(jobs.filter((j) => j.pause).map((j) => j.off))], unplaced };
|
|
44
|
+
}
|
|
24
45
|
|
|
25
|
-
function run(argv, { say = (s) => console.log(s), env = process.env, stateDir = null } = {}) {
|
|
46
|
+
function run(argv, { say = (s) => console.log(s), env = process.env, stateDir = null, roots = null, cwd = process.cwd(), now = Date.now() } = {}) {
|
|
26
47
|
const args = argv[0] === 'ai' ? argv.slice(1) : argv.slice();
|
|
27
48
|
const verb = args[0];
|
|
28
49
|
if (!verb || ['help', '--help', '-h'].includes(verb)) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
|
|
@@ -32,7 +53,9 @@ function run(argv, { say = (s) => console.log(s), env = process.env, stateDir =
|
|
|
32
53
|
|
|
33
54
|
if (verb === 'status') {
|
|
34
55
|
const s = AG.status({ stateDir: dir, settingsDir: dir, env });
|
|
35
|
-
|
|
56
|
+
let keep = null;
|
|
57
|
+
try { keep = keepOf(roots || rootsOf(dir, cwd), now); } catch { keep = null; }
|
|
58
|
+
if (flag(args, 'json')) { say(JSON.stringify({ ...s, keep })); return 0; }
|
|
36
59
|
say(`AI jobs: ${s.on ? 'on' : 'off'}${s.settingsOff.length ? ' · off one by one: ' + s.settingsOff.join(', ') : ''}`);
|
|
37
60
|
if (!s.jobs.length) say(' no job has run yet');
|
|
38
61
|
for (const j of s.jobs) {
|
|
@@ -40,6 +63,15 @@ function run(argv, { say = (s) => console.log(s), env = process.env, stateDir =
|
|
|
40
63
|
const last = j.last ? ` · last run ${String(j.last.at).slice(0, 16).replace('T', ' ')}: ${j.last.filed} filed, ${j.last.dropped} dropped` : '';
|
|
41
64
|
say(` ${j.job}: ${j.off ? 'off' : 'on'} · ${rep}${last}`);
|
|
42
65
|
}
|
|
66
|
+
if (keep) {
|
|
67
|
+
const line = (j) => `${j.label}: ${j.decided ? pct(j.keepRate) + ' kept (' + j.kept + ' of ' + j.decided + ')' : 'nothing decided'}${j.open ? ' · ' + j.open + ' waiting' : ''}${j.pause ? ' · none kept: pause it?' : ''}`;
|
|
68
|
+
const seen = keep.jobs.filter((j) => j.decided || j.open);
|
|
69
|
+
say(`✦ keep rate, last ${keep.days} days${seen.length ? '' : ': no ✦ decided or waiting yet'}`);
|
|
70
|
+
for (const j of seen) say(' ' + line(j));
|
|
71
|
+
if (keep.products.length > 1) for (const p of keep.products) { const pj = p.jobs.filter((j) => j.decided || j.open); if (pj.length) { say(` ${p.product}:`); for (const j of pj) say(' ' + line(j)); } }
|
|
72
|
+
if (keep.pause.length) say(` To pause (you decide): ${keep.pause.map((j) => '`pmos ai off ' + j + '`').join(', ')}`);
|
|
73
|
+
if (keep.unplaced) say(` ${keep.unplaced} older ✕ could not be placed on a job (a computed proposal that was never filed)`);
|
|
74
|
+
}
|
|
43
75
|
return 0;
|
|
44
76
|
}
|
|
45
77
|
if (verb === 'log') {
|
|
@@ -60,4 +92,4 @@ function run(argv, { say = (s) => console.log(s), env = process.env, stateDir =
|
|
|
60
92
|
return 0;
|
|
61
93
|
}
|
|
62
94
|
|
|
63
|
-
module.exports = { run, COMMANDS, USAGE };
|
|
95
|
+
module.exports = { run, keepOf, rootsOf, COMMANDS, USAGE };
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* schedules, Git sync
|
|
17
17
|
* 3 driver the Initiative Driver
|
|
18
18
|
* 4 deep the deep drafts: core documents, Your impact, metric drafts and reads, proposals, grill, the report finder, the
|
|
19
|
-
* report design and structure checks, milestone reviews, the forecast
|
|
19
|
+
* report design and structure checks, milestone reviews, the forecast, the role agents (lib/team-runs.js), the verifier after merge
|
|
20
20
|
* 5 idle the idle lab and the slow reads: the Horizon scan (its daily run waits for the first idle stretch of the day), then the idle
|
|
21
21
|
* lab (lib/idle-lab-engine.js: prototypes and scans for the PM's initiatives)
|
|
22
22
|
*
|
|
@@ -56,7 +56,8 @@ const STEPS = Object.freeze([
|
|
|
56
56
|
{ step: 4, id: 'deep', label: 'Deep drafts' },
|
|
57
57
|
{ step: 5, id: 'idle', label: 'Idle lab and slow reads' },
|
|
58
58
|
]);
|
|
59
|
-
/* id: the queue's job id (also the `pmos ai off <job>` id). ai: false = no model, so the AI off switch does not stop it.
|
|
59
|
+
/* id: the queue's job id (also the `pmos ai off <job>` id). ai: false = no model, so the AI off switch does not stop it.
|
|
60
|
+
* A new job also gets a row in lib/job-graph.js (what it reads and writes, and who reads that): job-graph.test.js fails until it has one. */
|
|
60
61
|
const JOBS = Object.freeze([
|
|
61
62
|
{ id: 'schedules', step: 2, label: 'Scheduled skills' },
|
|
62
63
|
{ id: 'proactive', step: 2, label: 'Morning brief and day check' },
|
|
@@ -73,10 +74,12 @@ const JOBS = Object.freeze([
|
|
|
73
74
|
{ id: 'grill', step: 4, label: 'Grill' },
|
|
74
75
|
{ id: 'metric-drafts', step: 4, label: 'Metric drafts' },
|
|
75
76
|
{ id: 'impact', step: 4, label: 'Your impact' },
|
|
77
|
+
{ id: 'verify', step: 4, label: 'Verifier after merge' },
|
|
76
78
|
{ id: 'metric-reads', step: 4, label: 'Metric reads' },
|
|
77
79
|
{ id: 'forecast', step: 4, label: 'Forecast' },
|
|
78
80
|
{ id: 'report-design', step: 4, label: 'Report design' },
|
|
79
81
|
{ id: 'report-structure', step: 4, label: 'Report structure' },
|
|
82
|
+
{ id: 'team', step: 4, label: 'Role agents' },
|
|
80
83
|
{ id: 'scan', step: 5, label: 'Horizon scan' },
|
|
81
84
|
{ id: 'idle-lab', step: 5, label: 'Idle lab' },
|
|
82
85
|
]);
|
|
@@ -124,12 +127,14 @@ function holderOf(sessions, initiative, { except = null } = {}) {
|
|
|
124
127
|
}
|
|
125
128
|
return null;
|
|
126
129
|
}
|
|
127
|
-
/** The initiative an origin names: drive:initiative:<id>, grill:<ws>:<id>:<run>, propose:<ws>:<id>:<run>, idle-lab-proto|idle-lab-scan:<ws>:<id|->:<run
|
|
130
|
+
/** The initiative an origin names: drive:initiative:<id>, grill:<ws>:<id>:<run>, propose:<ws>:<id>:<run>, idle-lab-proto|idle-lab-scan:<ws>:<id|->:<run>,
|
|
131
|
+
* team:<ws>:<role>:<id|->:<run>. A role run holds its initiative like any background run, so one run per initiative per role holds a fortiori. */
|
|
128
132
|
function initiativeOfOrigin(origin) {
|
|
129
133
|
const p = String(origin || '').split(':');
|
|
130
134
|
if (p[0] === 'drive' && p[1] === 'initiative') return p.slice(2).join(':') || null;
|
|
131
135
|
if ((p[0] === 'grill' || p[0] === 'propose') && p.length >= 4) return p[2] || null;
|
|
132
136
|
if ((p[0] === 'idle-lab-proto' || p[0] === 'idle-lab-scan') && p.length >= 4) return p[2] && p[2] !== '-' ? p[2] : null;
|
|
137
|
+
if (p[0] === 'team' && p.length >= 5) return p[3] && p[3] !== '-' ? p[3] : null; // team:<ws>:<role>:<initiative|->:<run>
|
|
133
138
|
return null;
|
|
134
139
|
}
|
|
135
140
|
|
|
@@ -137,7 +142,7 @@ function initiativeOfOrigin(origin) {
|
|
|
137
142
|
const ORIGIN_JOB = Object.freeze({ drive: 'driver', grill: 'grill', propose: 'propose', 'metric-read': 'metric-reads', 'metric-draft': 'metric-drafts',
|
|
138
143
|
impact: 'impact', coredoc: 'coredocs', 'core-docs': 'coredocs', 'scan-web': 'scan', 'scan-repo': 'scan', 'scan-suggest': 'scan',
|
|
139
144
|
'scan-research-web': 'scan', 'scan-research-repo': 'scan', 'report-find': 'finder', 'ms-review': 'milestones', 'next-step': 'prepare',
|
|
140
|
-
'idle-lab-proto': 'idle-lab', 'idle-lab-scan': 'idle-lab' });
|
|
145
|
+
'idle-lab-proto': 'idle-lab', 'idle-lab-scan': 'idle-lab', team: 'team' });
|
|
141
146
|
// Runs a chat makes for the PM while they use it, not background work: briefing-ask is the read-only run behind a chat (its suggested next
|
|
142
147
|
// prompt, a quick ask). Wawan, 2026-11-04: the Lab's "What Claude did in the background" listed "chat: next prompt" fourteen times.
|
|
143
148
|
const NOT_BACKGROUND = new Set(['briefing-ask']);
|
|
@@ -31,7 +31,8 @@ const days = (a, b) => { const x = isoDay(a), y = isoDay(b); return x && y ? Mat
|
|
|
31
31
|
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
32
32
|
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
33
33
|
const MAX_LIST = 100, STAGE_ROWS = 5;
|
|
34
|
-
const
|
|
34
|
+
const SP = require('./status-proof.js'); // T3: a status renders only with its source and read time
|
|
35
|
+
const STATUS_LABEL = { 'no signal': 'No signal', 'at risk': 'At risk', late: 'Late', 'on hold': 'On hold', done: 'Done', cancelled: 'Cancelled' };
|
|
35
36
|
const DOC_STATE = { missing: 'Not started', draft: 'Draft', ok: 'Up to date', stale: 'Stale', due: 'Due' };
|
|
36
37
|
const BY = { drafts: 'PMOS drafts it', proposes: 'PMOS proposes', reviews: 'PMOS reviews', you: 'You write it', live: 'Live view' };
|
|
37
38
|
const GO = { reports: 'rep', initiatives: 'init', triage: 'asks', releases: 'rel', scan: 'scan' }; // where a document's Open goes on the premium pages (premium-board.js GOTAB)
|
|
@@ -269,7 +270,9 @@ const gapsOf = (r) => (Array.isArray(r.gaps) ? r.gaps : []).filter((g) => g && d
|
|
|
269
270
|
/** Where the dated work of each stage runs (batch 11 item 13): the » of a skipped stage sits between two of them. */
|
|
270
271
|
const stageSpansOf = (r) => (Array.isArray(r.stageSpans) ? r.stageSpans : []).filter((x) => x && stageKey(x.stage) && dayOr(x.start) && dayOr(x.due)).slice(0, 40)
|
|
271
272
|
.map((x) => ({ stage: stageKey(x.stage), start: x.start, due: x.due }));
|
|
272
|
-
function rowOf(
|
|
273
|
+
function rowOf(r0, wf, today) {
|
|
274
|
+
// T3 (lib/status-proof.js): a status word the row cannot prove (no source, no read time) says No signal, on every surface that reads it
|
|
275
|
+
const r = r0 && r0.status ? { ...r0, status: SP.provenStatus(r0) } : r0;
|
|
273
276
|
const names = (wf || []).map((s) => s.name), cur = names.indexOf(r.stage);
|
|
274
277
|
const bad = r.status === 'late' || r.status === 'at risk';
|
|
275
278
|
const facts = [
|
|
@@ -282,7 +285,7 @@ function rowOf(r, wf, today) {
|
|
|
282
285
|
const over = r.end && today && days(r.end, today) > 0 && r.status !== 'done' && !r.closed;
|
|
283
286
|
return {
|
|
284
287
|
key: 'board:' + r.id, id: r.id, title: clip(r.title, 140), sub: [r.owner || 'No owner', r.lane].filter(Boolean).join(' · '),
|
|
285
|
-
status: r.status || null, statusLabel: r.status && r.status !== 'on track' ? (STATUS_LABEL[r.status] || r.status) : null, bad, late: r.status === 'late', closed: !!r.closed,
|
|
288
|
+
status: r.status || null, statusLabel: r.status && r.status !== 'on track' ? (STATUS_LABEL[r.status] || r.status) : null, signal: r.signal || null, bad, late: r.status === 'late', closed: !!r.closed,
|
|
286
289
|
stage: r.stage || null, cat: r.cat || null, stageNote: r.stageSource === 'derived' ? 'derived' : null,
|
|
287
290
|
seg: names.map((n, j) => (j < cur ? 'p' : j === cur ? 'n' : '')), progress: pctOf(r.progress),
|
|
288
291
|
finish: r.end ? shortDate(r.end) : 'Not planned', over: !!over, start: r.start || null, end: r.end || null,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* goal-source.js — one goal source (OS evaluation T2, initiative one-goal-source; brief /mnt/project-files/os-eval/briefs.md).
|
|
3
|
+
*
|
|
4
|
+
* source({ root, recordsDir }) → { ok, okr, records, goals, loose, count, error } THE goal list of a workspace
|
|
5
|
+
* attach(okr, records) → { goals, loose } the same, from what was read. PURE
|
|
6
|
+
* goalOf(src, ref) → goal | null the key result a goal key (a::kr-a1) or KR token (O-A.KR-A1) names
|
|
7
|
+
* resolve(src, ref) → record | null a goal key, a KR token or a record id → the record that reads it
|
|
8
|
+
* listRecords(dir) · recordsDirOf(root) the kr-metrics records of a folder; a workspace's records folder
|
|
9
|
+
*
|
|
10
|
+
* WHY. Intelligence built its goal list from the OKR file (lib/okr-goals.js), while the product picker count, Your move's key result row, a report's KR
|
|
11
|
+
* slot and the dashboard save check each listed planning/records/kr-metrics.jsonl on their own: two producers of one concept. IDPF had 10 key results in
|
|
12
|
+
* its OKR file and 1 record, so the picker said 1 goal. Here the OKR file's key results are the goals, and a KR metric record is a key result's readings,
|
|
13
|
+
* attached by id (its `goal` field naming the key, its `kr` anchor, or its title naming the key result). A record no key result claims (a North Star, a
|
|
14
|
+
* budget limit, a goal kept before the OKR file) is a loose goal and keeps working as it did. No record is rewritten.
|
|
15
|
+
*/
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const OG = require('./okr-goals.js');
|
|
19
|
+
|
|
20
|
+
/** The kr-metrics records of a folder (scripts/records), retired ones left out. Throws when the folder cannot be read: the caller says so. */
|
|
21
|
+
function listRecords(dir) {
|
|
22
|
+
return require(require('./repo-script.js').repoScript('records/index.js')).list(dir, 'kr-metrics').filter((k) => k && k.retired !== true);
|
|
23
|
+
}
|
|
24
|
+
/** The records folder of a workspace root: pmos/state/records in a product repository, planning/records in PMOS (scripts/signals/layout-paths.js). */
|
|
25
|
+
function recordsDirOf(root) {
|
|
26
|
+
try { const p = require(require('./repo-script.js').repoScript('signals/layout-paths.js')).pathsFor(root).recordsDir; if (p && fs.existsSync(p)) return p; } catch { /* fall through */ }
|
|
27
|
+
return path.join(root, 'planning', 'records');
|
|
28
|
+
}
|
|
29
|
+
/** A record as a reader candidate: readerOf matches on id, title and kr. A `goal` field naming the key result's key ("a::kr-a1") attaches it first. */
|
|
30
|
+
const asReader = (r) => ({ id: r.rid, title: r.title || '', kr: r.kr || null, goal: typeof r.goal === 'string' ? r.goal.toLowerCase() : null });
|
|
31
|
+
|
|
32
|
+
/** The OKR file's key results, each with the record that reads it, and the records no key result claims. PURE.
|
|
33
|
+
* → { goals: [{ key, token, title, objective, o, k, record: record | null, readings: number }], loose: [record] } */
|
|
34
|
+
function attach(okr, records) {
|
|
35
|
+
const R = (records || []).filter((r) => r && r.rid), C = R.map(asReader), used = new Set(), goals = [];
|
|
36
|
+
for (const o of (okr && okr.ok && okr.objectives) || []) for (const k of o.krs) {
|
|
37
|
+
const key = o.id + '::' + k.id;
|
|
38
|
+
const byKey = C.find((c) => c.goal === key && !used.has(c.id));
|
|
39
|
+
const c = byKey || OG.readerOf(o, k, C.filter((x) => !used.has(x.id)));
|
|
40
|
+
const rec = c ? R.find((r) => r.rid === c.id) : null;
|
|
41
|
+
if (rec) used.add(rec.rid);
|
|
42
|
+
goals.push({ key, token: k.token, title: k.title, objective: o.title, o, k, record: rec, readings: rec && Array.isArray(rec.readings) ? rec.readings.length : 0 });
|
|
43
|
+
}
|
|
44
|
+
return { goals, loose: R.filter((r) => !used.has(r.rid)) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** THE goal list of a workspace. recordsDir defaults to the workspace's own records folder. Never throws: a part that cannot be read says so in `error`,
|
|
48
|
+
* and the other part is still returned (an OKR file with no records folder lists its key results with no readings). */
|
|
49
|
+
function source({ root, recordsDir } = {}) {
|
|
50
|
+
const okr = root ? OG.read(root) : { ok: false, files: [], period: null, objectives: [], error: 'no workspace' };
|
|
51
|
+
let records = [], error = null;
|
|
52
|
+
try { records = listRecords(recordsDir || recordsDirOf(root)); } catch (e) { error = 'the KR metric records could not be read: ' + String((e && e.message) || e).slice(0, 120); }
|
|
53
|
+
const { goals, loose } = attach(okr, records);
|
|
54
|
+
return { ok: !error, okr, records, goals, loose, count: goals.length + loose.length, error };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The key result a ref names: its key ("a::kr-a1") or its KR token ("O-A.KR-A1", "KR-A1"). → a goal of source() | null. */
|
|
58
|
+
function goalOf(src, ref) {
|
|
59
|
+
const s = String(ref || '').trim(), G = (src && src.goals) || [];
|
|
60
|
+
if (!s) return null;
|
|
61
|
+
const byKey = G.find((g) => g.key === s.toLowerCase());
|
|
62
|
+
if (byKey) return byKey;
|
|
63
|
+
const m = src.okr && src.okr.ok ? OG.matchAnchor(s, src.okr.objectives) : null;
|
|
64
|
+
return m ? G.find((x) => x.key === m.o.id + '::' + m.k.id) || null : null;
|
|
65
|
+
}
|
|
66
|
+
/** A goal named by its key, its KR token or a record id → the record that reads it. A key result with no reader is null, never a guess. An old record id
|
|
67
|
+
* keeps working. */
|
|
68
|
+
function resolve(src, ref) {
|
|
69
|
+
const s = String(ref || '').trim();
|
|
70
|
+
if (!src || !s) return null;
|
|
71
|
+
const byId = (src.records || []).find((r) => r.rid === s);
|
|
72
|
+
if (byId) return byId;
|
|
73
|
+
const g = goalOf(src, s);
|
|
74
|
+
return g ? g.record : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = { source, attach, goalOf, resolve, listRecords, recordsDirOf };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/* grill-runs.js — Claude's runs that grill an initiative by themselves (Grill and Forecast, part G-A; lib/grill.js says what and when).
|
|
3
3
|
*
|
|
4
4
|
* create(deps) → { tick(opts), start({ ws, board, ini, why, key, detail, now }), stop(run), active() }
|
|
5
|
-
* promptOf(skill, o) → the prompt of one run. o: { run, why, detail, ini, title, intent, stage, stages, today, open, dropped, budget, decisions }
|
|
5
|
+
* promptOf(skill, o) → the prompt of one run. o: { run, why, detail, ini, title, intent, stage, stages, today, open, dropped, lessons, budget, decisions }
|
|
6
6
|
*
|
|
7
7
|
* ONE RUN KIND (headless kind `grill`, origin `grill:<ws>:<initiative>:<run>`). The run reads the repository, the stored reads, the
|
|
8
8
|
* stored research and meeting notes, and files with `pmos grill find`, pinned by the server to this initiative and run (PMOS_GRILL_FILE,
|
|
@@ -42,6 +42,7 @@ function promptOf(skill, o) {
|
|
|
42
42
|
+ `- Its workflow's stages, in order:\n${list((o.stages || []).map((s) => s.key + ' · ' + s.name), 'not known')}\n`
|
|
43
43
|
+ `- Open findings already under its ✦ (do not file them again):\n${list(o.open, 'none')}\n`
|
|
44
44
|
+ `- Dropped by the PM (do not file these again unless the evidence is new):\n${list(o.dropped, 'none')}\n`
|
|
45
|
+
+ (o.lessons && o.lessons.length ? `- What the PM said about your earlier findings here, newest first (learn from it: file what they would keep):\n${list(o.lessons, 'none')}\n` : '')
|
|
45
46
|
+ (o.decisions && o.decisions.length ? `- The decisions that stand (for the decision angle; Read the line for a decision's words):\n${list(o.decisions, 'none')}\n` : '')
|
|
46
47
|
+ `- Your budget: $${o.budget}. Stop when you have your findings.\n\n`
|
|
47
48
|
+ 'File with `pmos grill find` only (the server pins this initiative and run). Send nothing.';
|
|
@@ -101,14 +102,16 @@ function create(deps) {
|
|
|
101
102
|
if (!skill) return { ok: false, error: 'the grill skill is not installed' };
|
|
102
103
|
const run = 'gr' + now.toString(36) + crypto.randomBytes(3).toString('hex');
|
|
103
104
|
const row = (deps.rowOf && deps.rowOf(w, ini)) || {};
|
|
104
|
-
const
|
|
105
|
+
const lines = PR.readLines(PR.ledgerFile(dir)), P = PR.fold(lines), kept = PR.keptIds(P);
|
|
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 });
|
|
105
108
|
const mine = [...P.props.values()].filter((p) => p.ini === ini && p.group === 'grill');
|
|
106
109
|
const dropped = mine.filter((p) => P.drops.has(PR.sigOf(p))).slice(0, 20).map((p) => one(p.title, 120));
|
|
107
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));
|
|
108
111
|
// decision memory: the decisions that stand go in the prompt, so the run checks the plan against all of them, not a search's hits
|
|
109
112
|
let decisions = [];
|
|
110
113
|
try { const DL = require('./decision-ledger.js'), L = w.root ? DL.load(w.root) : null; decisions = L ? DL.index(L) : []; } catch (e) { warn('grill decisions', e); }
|
|
111
|
-
const prompt = promptOf(skill, { run, why, detail, ini, title: row.title || ini, intent: row.intent || '', stage: row.stage || '', stages: row.stages || [], today: localDay(now), open, dropped, budget: b.budget, decisions });
|
|
114
|
+
const prompt = promptOf(skill, { run, why, detail, ini, title: row.title || ini, intent: row.intent || '', stage: row.stage || '', stages: row.stages || [], today: localDay(now), open, dropped, lessons, budget: b.budget, decisions });
|
|
112
115
|
active.set(run, { session: null });
|
|
113
116
|
const env = { PMOS_GRILL_FILE: PR.ledgerFile(dir), PMOS_GRILL_LOG: G.logFile(rt), PMOS_GRILL_ROOT: w.root || '', PMOS_GRILL_WS: ws, PMOS_GRILL_BOARD: board || '', PMOS_GRILL_INI: ini, PMOS_GRILL_RUN: run, PMOS_GRILL_BUDGET: String(b.budget) };
|
|
114
117
|
// With an API key the run goes to the Claude API (lib/grill-api.js); without one it stays a background agent session
|