create-pmos 0.433.0 → 0.435.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 +25 -25
- 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/briefing-premium-insights-test.js +63 -58
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/ready-reports.js +145 -0
- package/workspace/guide/index.md +2 -0
- package/workspace/guide/metric-drafts.md +21 -1
- package/workspace/guide/ready-made-dashboards.md +62 -0
- package/workspace/guide/your-impact.md +58 -0
- package/workspace/impact-screens-test.js +149 -0
- package/workspace/intel-report-ui-test.js +1 -1
- package/workspace/intelligence-gaps-ui-test.js +13 -9
- package/workspace/lib/board-premium.js +1 -1
- package/workspace/lib/engine/outbox.js +1 -1
- package/workspace/lib/engine/records/index.js +11 -3
- package/workspace/lib/goal-status.js +199 -0
- package/workspace/lib/goal-watch.js +71 -0
- package/workspace/lib/headless.js +24 -2
- package/workspace/lib/impact-cli.js +72 -0
- package/workspace/lib/impact-runs.js +114 -0
- package/workspace/lib/impact.js +195 -0
- package/workspace/lib/insights-premium.js +43 -4
- package/workspace/lib/intel-report.js +36 -5
- package/workspace/lib/metric-draft-runs.js +33 -10
- package/workspace/lib/metric-drafts.js +118 -15
- package/workspace/lib/metric-read-runs.js +132 -0
- package/workspace/lib/metric-reads.js +129 -0
- package/workspace/lib/metrics-cli.js +100 -5
- package/workspace/lib/pmos-verbs.js +4 -1
- package/workspace/lib/ready-reports.js +616 -0
- package/workspace/lib/report-dashboards.js +5 -0
- package/workspace/lib/report-setups.js +16 -7
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-board-premium.js +5 -0
- package/workspace/lib/routes-boards.js +1 -1
- package/workspace/lib/routes-goal-status.js +111 -0
- package/workspace/lib/routes-impact-views.js +58 -0
- package/workspace/lib/routes-impact.js +91 -0
- package/workspace/lib/routes-insights-premium.js +20 -0
- package/workspace/lib/routes-metric-drafts.js +55 -4
- package/workspace/lib/routes-ready-reports.js +455 -0
- package/workspace/lib/routes-records.js +2 -0
- package/workspace/lib/routes-report-setups.js +4 -3
- package/workspace/lib/settings-store.js +3 -0
- package/workspace/okr-goals-ui-test.js +175 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/program-charter-test.js +11 -7
- package/workspace/program-panel-test.js +1 -1
- package/workspace/public/pm/bd-ini-panel.js +33 -8
- package/workspace/public/pm/bd-prog-panel.js +58 -10
- package/workspace/public/pm/cozy-adler.css +5 -0
- package/workspace/public/pm/cozy-adler.js +17 -9
- package/workspace/public/pm/cozy-insights.css +84 -0
- package/workspace/public/pm/cozy-settings.js +11 -1
- package/workspace/public/pm/cozy-viewer.js +2 -2
- package/workspace/public/pm/cozy-vw-rp.css +13 -0
- package/workspace/public/pm/dash-view.css +111 -0
- package/workspace/public/pm/dash-view.js +261 -0
- package/workspace/public/pm/home-app.js +87 -8
- package/workspace/public/pm/home-data.js +3 -2
- package/workspace/public/pm/home-impact.css +16 -0
- package/workspace/public/pm/home-impact.js +72 -0
- package/workspace/public/pm/home-ini.js +19 -1
- package/workspace/public/pm/home-today.js +4 -2
- package/workspace/public/pm/impact.css +37 -0
- package/workspace/public/pm/impact.js +201 -0
- package/workspace/public/pm/okr-list.js +249 -0
- package/workspace/public/pm/premium-insights.js +232 -240
- package/workspace/public/pm/premium-report-read.js +36 -5
- package/workspace/public/pm/premium-vw-mtg.js +4 -1
- package/workspace/public/pm/ready-lib.css +29 -0
- package/workspace/public/pm/ready-lib.js +62 -0
- package/workspace/public/premium-intelligence.html +3 -2
- package/workspace/public/premium.html +1 -0
- package/workspace/ready-dash-ui-test.js +227 -0
- package/workspace/server.js +58 -2
- package/workspace/skills/impact-detect.skill +46 -0
- package/workspace/skills/metric-read.skill +32 -0
- package/workspace/test-lists/batch17-ready-reports.json +9 -0
- package/workspace/test-lists/goal-watch.json +9 -0
- package/workspace/test-lists/impact-screens.json +5 -0
- package/workspace/test-lists/impact-ui.json +9 -0
- package/workspace/test-lists/impact.json +9 -0
- package/workspace/test-lists/okr-goals-ui.json +5 -0
- package/workspace/test-lists/ready-reports-ui.json +6 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* goal-status.js — THE ONE STATUS of a goal, from its readings (feedback batch 16 item 6, "Claude runs the OKRs", gap 2). Intelligence's goal list,
|
|
3
|
+
* the goal Viewer and the product page's Goals line all read it from here, so a goal says the same thing everywhere. PURE: no I/O and no clock of
|
|
4
|
+
* its own; `today` (YYYY-MM-DD) comes in. Initiative delivery status never sets a goal's dot: only a reading does.
|
|
5
|
+
*
|
|
6
|
+
* readingOf(rec, today) → { dot, at, ageDays, stale, txt, line, value, source, via } one kr-metrics record (scripts/records fold)
|
|
7
|
+
* dot on the latest reading is on its line (or reached, or a limit with room left)
|
|
8
|
+
* behind behind the straight line from baseline to target by the early-warning share (10% of the span) or more
|
|
9
|
+
* close a limit goal inside its close band: within the limit, near it
|
|
10
|
+
* broken a limit goal over its ceiling (under its floor)
|
|
11
|
+
* none no reading yet: a hollow dot and no status
|
|
12
|
+
* stale the reading is older than its cadence allows (daily 3 days, weekly 14, monthly 45; 14 with no recipe). A stale reading keeps its
|
|
13
|
+
* dot and says its age.
|
|
14
|
+
* isLimit(rec) · bandOf(rec) · staleDays(rec) · CADENCE_DAYS
|
|
15
|
+
* whoOf(rec) → { name, initials, from: jira | pm } | null the goal's owner
|
|
16
|
+
* summaryOf(goals) → { on, behind: [title], broken: [title], close: [title], none, dots: [{ id, title, dot }], line } the product page
|
|
17
|
+
* lineOf(o) → { head, sub, tone: calm | behind | crit | drafts, keepAll } the ✦ line. o: { goals, drafts, alert, today }
|
|
18
|
+
* metricsOf(goals) → [{ id, title, meta, dot, role, parent }] Intelligence ⋯ › Metrics: goal metrics first, then the watched ones
|
|
19
|
+
* ownerFixes(goals, ws) → [fix input] an owner for a goal with none: the person who holds the most of the work anchored to it (Jira)
|
|
20
|
+
* chaseFixes(goals) → [fix input] a goal behind with an owner: a thankful note to the owner, sent only on the PM's ✓
|
|
21
|
+
* ticketFixes(goals) → [fix input] a broken limit: the drafted rollback (tracking) ticket for its owner
|
|
22
|
+
* noun(n, one, many)
|
|
23
|
+
*
|
|
24
|
+
* NOTHING HERE MAKES A NUMBER UP. A reading is a value a record holds; the line is the straight line from baseline to target; a band is the record's
|
|
25
|
+
* own close_band, else a tenth of the room between the baseline and the limit, said as that. */
|
|
26
|
+
|
|
27
|
+
const EARLY = 0.10; // the repository's early-warning share (scripts/calendar-model.js EARLY_WARNING, lib/routes-c3-strategy.js)
|
|
28
|
+
const CADENCE_DAYS = Object.freeze({ daily: 3, weekly: 14, monthly: 45 });
|
|
29
|
+
const NO_RECIPE_DAYS = 14;
|
|
30
|
+
const DAY = 864e5;
|
|
31
|
+
const fin = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
32
|
+
const ms = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
33
|
+
const r2 = (v) => Math.round(v * 100) / 100;
|
|
34
|
+
const num = (v, unit) => { const u = String(unit || '').trim(), s = String(r2(v)); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
|
|
35
|
+
const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
|
|
36
|
+
const noun = (n, one, many) => n + ' ' + (n === 1 ? one : many);
|
|
37
|
+
const first = (s) => String(s || '').trim().split(/\s+/)[0] || '';
|
|
38
|
+
const lower1 = (s) => (s ? s[0].toLowerCase() + s.slice(1) : s);
|
|
39
|
+
|
|
40
|
+
/** A goal that must stay within a limit: the record says so (type Stay within, or a limit), or it is a guardrail with a limit. */
|
|
41
|
+
const isLimit = (rec) => !!rec && (rec.type === 'Stay within' || rec.limit === 'ceiling' || rec.limit === 'floor');
|
|
42
|
+
const ceilingOf = (rec) => (rec.limit === 'floor' ? false : rec.limit === 'ceiling' ? true : !(fin(Number(rec.target)) && fin(Number(rec.baseline)) && Number(rec.target) > Number(rec.baseline)));
|
|
43
|
+
/** The close band of a limit: the record's own, else a tenth of the room between baseline and limit (a tenth of the limit when they are equal). */
|
|
44
|
+
function bandOf(rec) {
|
|
45
|
+
if (fin(Number(rec.close_band)) && Number(rec.close_band) > 0) return Number(rec.close_band);
|
|
46
|
+
const lim = Number(rec.target), base = Number(rec.baseline);
|
|
47
|
+
if (!fin(lim)) return 0;
|
|
48
|
+
const room = fin(base) ? Math.abs(lim - base) : 0;
|
|
49
|
+
return room > 0 ? room * EARLY : Math.abs(lim) * EARLY;
|
|
50
|
+
}
|
|
51
|
+
const staleDays = (rec) => CADENCE_DAYS[rec && rec.recipe && rec.recipe.cadence] || NO_RECIPE_DAYS;
|
|
52
|
+
const readingsOf = (rec) => ((rec && rec.readings) || []).filter((x) => x && fin(Number(x.value)) && ms(x.at) !== null)
|
|
53
|
+
.map((x) => ({ ...x, at: String(x.at).slice(0, 10), value: Number(x.value) })).sort((a, b) => a.at.localeCompare(b.at));
|
|
54
|
+
|
|
55
|
+
function readingOf(rec, today) {
|
|
56
|
+
const rs = readingsOf(rec), t = ms(today);
|
|
57
|
+
if (!rs.length) return { dot: 'none', at: null, ageDays: null, stale: false, txt: '', line: '', value: null, source: '', via: '' };
|
|
58
|
+
const last = rs[rs.length - 1], v = last.value, u = rec.unit || '';
|
|
59
|
+
const ageDays = t !== null ? Math.max(0, Math.round((t - ms(last.at)) / DAY)) : null;
|
|
60
|
+
const out = { dot: 'on', at: last.at, ageDays, stale: ageDays !== null && ageDays > staleDays(rec), txt: num(v, u), line: '', value: v, source: last.source || '', via: last.via || '' };
|
|
61
|
+
const tgt = Number(rec.target), base = Number(rec.baseline);
|
|
62
|
+
if (isLimit(rec) && fin(tgt)) {
|
|
63
|
+
const ceil = ceilingOf(rec), band = bandOf(rec);
|
|
64
|
+
const over = ceil ? v > tgt : v < tgt, close = !over && (ceil ? v >= tgt - band : v <= tgt + band);
|
|
65
|
+
out.dot = over ? 'broken' : close ? 'close' : 'on';
|
|
66
|
+
out.line = (ceil ? 'limit ' : 'floor ') + num(tgt, u);
|
|
67
|
+
out.limit = tgt; out.band = r2(band); out.ceiling = ceil;
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
if (rec.type === 'Done or not' && fin(tgt)) {
|
|
71
|
+
const done = v >= tgt;
|
|
72
|
+
out.txt = done ? 'Done' : 'Not yet';
|
|
73
|
+
out.dot = done || ms(rec.by) === null || t === null || ms(rec.by) >= t ? 'on' : 'behind';
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
if (!fin(tgt) || !fin(base) || tgt === base || ms(rec.by) === null) { out.line = ''; return out; }
|
|
77
|
+
const dir = Math.sign(tgt - base);
|
|
78
|
+
out.txt = num(v, u) + ' of ' + num(tgt, u);
|
|
79
|
+
if ((v - tgt) * dir >= 0) { out.line = 'target reached'; return out; }
|
|
80
|
+
const t0 = ms(rec.start) !== null ? ms(rec.start) : ms(rs[0].at), t1 = ms(rec.by);
|
|
81
|
+
const frac = t1 > t0 && t !== null ? Math.max(0, Math.min(1, (t - t0) / (t1 - t0))) : 1;
|
|
82
|
+
const expected = base + (tgt - base) * frac, shortfall = (expected - v) / Math.abs(tgt - base) * dir;
|
|
83
|
+
out.line = 'its line says ' + num(Math.abs(expected) >= 10 ? Math.round(expected) : Math.round(expected * 10) / 10, u); // a pace in whole units from 10 up (lib/insights-premium.js)
|
|
84
|
+
out.expected = r2(expected);
|
|
85
|
+
out.dot = shortfall >= EARLY ? 'behind' : 'on';
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const initials = (name) => String(name || '').trim().split(/\s+/).filter(Boolean).slice(0, 2).map((w) => w[0].toUpperCase()).join('');
|
|
90
|
+
function whoOf(rec) {
|
|
91
|
+
const name = clip(rec && rec.owner, 60);
|
|
92
|
+
return name ? { name, initials: initials(name), from: rec.owner_from === 'jira' ? 'jira' : 'pm' } : null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The product page's Goals line: "3 on their line · checkout sign-in is behind". goals: [{ id, title, reading }] */
|
|
96
|
+
function summaryOf(goals) {
|
|
97
|
+
const G = (goals || []).filter((g) => g && g.reading);
|
|
98
|
+
const by = (d) => G.filter((g) => g.reading.dot === d).map((g) => g.title);
|
|
99
|
+
const on = by('on').length, behind = by('behind'), broken = by('broken'), close = by('close'), none = by('none').length;
|
|
100
|
+
const parts = [];
|
|
101
|
+
if (on) parts.push(on + ' on ' + (on === 1 ? 'its line' : 'their line'));
|
|
102
|
+
for (const t of broken) parts.push(lower1(t) + ' broke its limit');
|
|
103
|
+
for (const t of behind) parts.push(lower1(t) + ' is behind');
|
|
104
|
+
for (const t of close) parts.push(lower1(t) + ' is close to its limit');
|
|
105
|
+
if (none) parts.push(noun(none, 'not read yet', 'not read yet'));
|
|
106
|
+
return { on, behind, broken, close, none, dots: G.map((g) => ({ id: g.id, title: g.title, dot: g.reading.dot })), line: parts.join(' · ') };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The ✦ line: the one thing that matters this week. It never says there is no insight: with no readings it says what Claude drafted.
|
|
110
|
+
* o: { goals: [{ id, title, role, reading, who }], drafts: n open drafts, alert: { title, txt, line } | null, moved: { title, txt } | null } */
|
|
111
|
+
function lineOf(o = {}) {
|
|
112
|
+
const G = (o.goals || []).filter((g) => g && g.reading), drafts = Math.max(0, o.drafts || 0);
|
|
113
|
+
const keepAll = drafts > 1 ? drafts : 0;
|
|
114
|
+
const draftSub = drafts ? (drafts === 1 ? 'I drafted one fix under it.' : 'I drafted ' + drafts + ' fixes. Keep them all at once, or one by one.') : '';
|
|
115
|
+
if (o.alert) return { head: o.alert.title + ' broke its limit: ' + o.alert.txt + ' against its ' + o.alert.line + '.', sub: draftSub || 'I will say when it is back under.', tone: 'crit', keepAll };
|
|
116
|
+
const behind = G.filter((g) => g.reading.dot === 'behind');
|
|
117
|
+
if (behind.length) {
|
|
118
|
+
const g = behind[0];
|
|
119
|
+
return { head: g.title + ' is behind its line: ' + g.reading.txt + (g.reading.line ? ', ' + g.reading.line : '') + '.' + (behind.length > 1 ? ' ' + noun(behind.length - 1, 'other goal is', 'other goals are') + ' behind too.' : ''),
|
|
120
|
+
sub: draftSub || (g.who ? g.who.name + ' owns it.' : 'It has no owner yet.'), tone: 'behind', keepAll };
|
|
121
|
+
}
|
|
122
|
+
const read = G.filter((g) => g.reading.dot !== 'none');
|
|
123
|
+
if (!read.length) {
|
|
124
|
+
if (drafts) return { head: 'I drafted ' + noun(drafts, 'fix', 'fixes') + ' so every goal can be read.', sub: 'Keep them all at once, or one by one. I test-read each one first.', tone: 'drafts', keepAll };
|
|
125
|
+
return { head: G.length ? 'I have not read a goal yet. I read each one when it has a way to be read.' : 'This product has no goal yet. I draft a North Star when the next check runs.', sub: '', tone: 'drafts', keepAll: 0 };
|
|
126
|
+
}
|
|
127
|
+
if (drafts) return { head: 'I drafted ' + noun(drafts, 'fix', 'fixes') + ' for your goals.', sub: 'Keep them all at once, or one by one.', tone: 'drafts', keepAll };
|
|
128
|
+
const close = G.filter((g) => g.reading.dot === 'close');
|
|
129
|
+
if (close.length) return { head: close[0].title + ' is close to its limit: ' + close[0].reading.txt + ', ' + close[0].reading.line + '.', sub: 'I keep reading it. Nothing needs you yet.', tone: 'calm', keepAll: 0 };
|
|
130
|
+
if (o.moved) return { head: o.moved.head, sub: o.moved.sub, tone: 'calm', keepAll: 0 };
|
|
131
|
+
const stale = read.filter((g) => g.reading.stale);
|
|
132
|
+
return { head: read.length === G.length && !stale.length ? 'Every goal was read and is on its line. Nothing needs you.' : noun(read.length - stale.length, 'goal is', 'goals are') + ' read and on their line.',
|
|
133
|
+
sub: stale.length ? noun(stale.length, 'reading is', 'readings are') + ' old: ' + stale.map((g) => g.title).slice(0, 2).join(', ') + '.' : '', tone: 'calm', keepAll: 0 };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** When the North Star moved since its reading before, the input that moved the same way the most (relative to its own span). null when none did. */
|
|
137
|
+
function movedOf(goals) {
|
|
138
|
+
const ns = (goals || []).find((g) => g.role === 'north-star');
|
|
139
|
+
const step = (g) => { const s = g && g.series; if (!s || s.length < 2) return null; const a = s[s.length - 2].v, b = s[s.length - 1].v; return { d: b - a, rel: Math.abs(a) > 0 ? (b - a) / Math.abs(a) : 0 }; };
|
|
140
|
+
const n = step(ns); if (!n || n.d === 0) return null;
|
|
141
|
+
const ins = (goals || []).filter((g) => g.role === 'input').map((g) => ({ g, s: step(g) })).filter((x) => x.s && Math.sign(x.s.d) === Math.sign(n.d));
|
|
142
|
+
if (!ins.length) return null;
|
|
143
|
+
const top = ins.sort((a, b) => Math.abs(b.s.rel) - Math.abs(a.s.rel))[0];
|
|
144
|
+
const sign = (d, u) => (d > 0 ? '+' : '') + num(d, u);
|
|
145
|
+
return { head: ns.title + ' moved ' + sign(n.d, ns.unit) + ' since its last reading.', sub: top.g.title + ' moved the same way, ' + sign(top.s.d, top.g.unit) + '.' };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Intelligence ⋯ › Metrics: the goal metrics first (North Star, inputs, guardrails, key results, budgets), then what Claude only watches. */
|
|
149
|
+
const ORDER = ['north-star', 'input', 'guardrail', 'kr', 'budget', 'program-goal', 'rollup', 'success', 'signal', 'watch'];
|
|
150
|
+
function metricsOf(goals) {
|
|
151
|
+
const ns = (goals || []).find((g) => g.role === 'north-star');
|
|
152
|
+
return (goals || []).map((g) => {
|
|
153
|
+
const role = g.role === 'watch' ? 'watch' : g.budget ? 'budget' : g.role || 'kr';
|
|
154
|
+
const r = g.reading || { dot: 'none' };
|
|
155
|
+
const meta = [r.txt, r.at ? (r.ageDays === 0 ? 'today' : r.ageDays === 1 ? '1 day ago' : r.ageDays + ' days ago') : 'not read yet', g.recipe ? g.recipe.connector : ''].filter(Boolean).join(' · ');
|
|
156
|
+
return { id: g.id, title: g.title, meta, dot: role === 'watch' ? 'none' : r.dot, role, parent: (role === 'input' || role === 'guardrail') && ns ? ns.id : null };
|
|
157
|
+
}).sort((a, b) => ORDER.indexOf(a.role) - ORDER.indexOf(b.role));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* ── the fixes the goal watch drafts by itself, from the records alone: each is a cleanFix input (lib/metric-drafts.js), filed standing ── */
|
|
161
|
+
/** goals: [{ id, title, who, moves: [{ owner, title }] }]. The person who holds the most of the work anchored to a goal with no owner. Two with as
|
|
162
|
+
* many is a guess: none is drafted. */
|
|
163
|
+
function ownerFixes(goals) {
|
|
164
|
+
const out = [];
|
|
165
|
+
for (const g of goals || []) {
|
|
166
|
+
if (!g || g.who || g.role === 'watch') continue;
|
|
167
|
+
const n = new Map();
|
|
168
|
+
for (const m of g.moves || []) if (m && m.owner) n.set(m.owner, (n.get(m.owner) || 0) + 1);
|
|
169
|
+
const top = [...n.entries()].sort((a, b) => b[1] - a[1]);
|
|
170
|
+
if (!top.length || (top[1] && top[1][1] === top[0][1])) continue;
|
|
171
|
+
const [name, k] = top[0], all = (g.moves || []).length;
|
|
172
|
+
out.push({ kind: 'owner', goal: g.id, text: name + ' owns ' + clip(g.title, 80) + '.', why: name + ' is the assignee of ' + k + ' of the ' + noun(all, 'initiative', 'initiatives') + ' that move it (Jira).', owner: { name, from: 'jira' } });
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
/** A goal behind its line with an owner: a thankful note that names the reading. It goes only on the PM's ✓, and then only to the outbox. */
|
|
177
|
+
function chaseFixes(goals) {
|
|
178
|
+
const out = [];
|
|
179
|
+
for (const g of goals || []) {
|
|
180
|
+
if (!g || !g.who || !g.reading || g.reading.dot !== 'behind') continue;
|
|
181
|
+
const body = 'Hi ' + first(g.who.name) + ', thank you for the work on ' + clip(g.title, 80) + '. It reads ' + g.reading.txt + (g.reading.line ? ' and ' + g.reading.line : '') + ' on '
|
|
182
|
+
+ g.reading.at + '. What would help it catch up? I can take anything off your plate that is not yours to carry.';
|
|
183
|
+
out.push({ kind: 'chase', goal: g.id, to: g.who.name, body, text: 'Thank ' + g.who.name + ' and ask what would help ' + clip(g.title, 60) + ' catch up.', why: 'It reads ' + g.reading.txt + ', ' + (g.reading.line || 'behind its line') + '.' });
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
/** A limit that broke: the rollback (tracking) ticket for its owner, sent to Jira only on the PM's ✓. */
|
|
188
|
+
function ticketFixes(goals) {
|
|
189
|
+
const out = [];
|
|
190
|
+
for (const g of goals || []) {
|
|
191
|
+
if (!g || !g.reading || g.reading.dot !== 'broken') continue;
|
|
192
|
+
const who = g.who ? g.who.name : 'the owner';
|
|
193
|
+
out.push({ kind: 'ticket', goal: g.id, text: 'Send ' + who + ' a ticket to roll back or fix what broke ' + clip(g.title, 60) + '.', why: 'It reads ' + g.reading.txt + ' against its ' + g.reading.line + ' on ' + g.reading.at + '.',
|
|
194
|
+
ticket: { title: clip(g.title, 80) + ' is over its limit', text: clip(g.title, 80) + ' read ' + g.reading.txt + ' on ' + g.reading.at + ', past its ' + g.reading.line + (g.reading.source ? ' (' + g.reading.source + ')' : '') + '. Roll back the last change that moved it, or fix it, and say which.' } });
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = { EARLY, CADENCE_DAYS, NO_RECIPE_DAYS, readingOf, readingsOf, isLimit, bandOf, staleDays, whoOf, summaryOf, lineOf, movedOf, metricsOf, ownerFixes, chaseFixes, ticketFixes, noun, initials };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* goal-watch.js — what happens around a reading (feedback batch 16 item 6, gaps 7 and 8): the limit alert, the bell, and the fixes Claude files by
|
|
3
|
+
* itself from the records alone (an owner, a thankful chase note, a rollback ticket). The I/O around the pure parts in lib/goal-status.js,
|
|
4
|
+
* lib/metric-reads.js and lib/metric-drafts.js. Nothing here is sent: a chase or a ticket is a draft until the PM's ✓, and then it waits in the outbox.
|
|
5
|
+
*
|
|
6
|
+
* afterRead(o) o: { dir, ws, records, rids, today, at, tell(rec, reading) } after readings of `rids` landed (a run ended, a CSV, a typed reading):
|
|
7
|
+
* for each limit goal, open the episode when it breaks (ONE bell line when its notify is push: the push) and close it when it is back;
|
|
8
|
+
* a goal that reads again clears its standing connect and recipe fixes. → [{ kind: broke | back, rid }]
|
|
9
|
+
* syncFixes(o) o: { dir, ws, goals, at } the owner, chase and ticket fixes the goals call for now (lib/goal-status.js), filed standing (src
|
|
10
|
+
* watch) when new; a standing watch fix whose reason is gone is cleared. A fix the PM kept or dropped is never filed again.
|
|
11
|
+
* → { filed, cleared }
|
|
12
|
+
* historyOf(lines, rid) → [{ at, text }] the record's own ledger: what Claude changed and what the PM kept (newest first, at most 12)
|
|
13
|
+
*/
|
|
14
|
+
const MD = require('./metric-drafts.js');
|
|
15
|
+
const MR = require('./metric-reads.js');
|
|
16
|
+
const GS = require('./goal-status.js');
|
|
17
|
+
|
|
18
|
+
function afterRead(o) {
|
|
19
|
+
const out = [];
|
|
20
|
+
if (!o || !o.dir) return out;
|
|
21
|
+
const F = MR.read(o.dir), D = MD.read(o.dir).scopes.get(MD.keyOf('product', o.ws));
|
|
22
|
+
for (const rid of o.rids || []) {
|
|
23
|
+
const rec = (o.records || []).find((r) => r && r.rid === rid && r.retired !== true); if (!rec) continue;
|
|
24
|
+
const reading = GS.readingOf(rec, o.today);
|
|
25
|
+
if (GS.isLimit(rec)) {
|
|
26
|
+
const step = MR.alertStep(F, rid, reading);
|
|
27
|
+
if (step) {
|
|
28
|
+
MR.append(o.dir, null, step, o.at);
|
|
29
|
+
out.push({ kind: step.kind, rid });
|
|
30
|
+
if (step.kind === 'broke' && (rec.notify || 'intel') === 'push' && typeof o.tell === 'function') { try { o.tell(rec, reading); } catch { /* the line on Intelligence still says it */ } }
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const x = F.rids.get(rid);
|
|
34
|
+
if (D && reading.dot !== 'none' && x && x.last && x.last.ok) for (const r of D.rows.values()) {
|
|
35
|
+
if (r.state === 'open' && r.standing === 'read' && r.goal === rid && (r.kind === 'connect' || r.kind === 'recipe')) MD.append(o.dir, null, { kind: 'clear', scope: 'product', id: o.ws, row: r.id }, o.at);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function syncFixes(o) {
|
|
42
|
+
const res = { filed: 0, cleared: 0 };
|
|
43
|
+
if (!o || !o.dir || !o.ws) return res;
|
|
44
|
+
const goals = (o.goals || []).filter((g) => g && g.role !== 'watch');
|
|
45
|
+
const want = [...GS.ownerFixes(goals), ...GS.chaseFixes(goals), ...GS.ticketFixes(goals)].map((x) => MD.cleanFix('product', o.ws, x)).filter((c) => c.row).map((c) => c.row);
|
|
46
|
+
const S = MD.read(o.dir).scopes.get(MD.keyOf('product', o.ws));
|
|
47
|
+
const ids = new Set(want.map((r) => r.id));
|
|
48
|
+
for (const row of want) {
|
|
49
|
+
const was = S && S.rows.get(row.id);
|
|
50
|
+
if (was) continue; // open already, or the PM answered it: filed once
|
|
51
|
+
MD.append(o.dir, null, { kind: 'fix', scope: 'product', id: o.ws, row, src: 'watch' }, o.at); res.filed++;
|
|
52
|
+
}
|
|
53
|
+
if (S) for (const r of S.rows.values()) if (r.state === 'open' && r.standing === 'watch' && !ids.has(r.id)) { MD.append(o.dir, null, { kind: 'clear', scope: 'product', id: o.ws, row: r.id }, o.at); res.cleared++; }
|
|
54
|
+
return res;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The ULID of a records line carries its time (scripts/trust/ledger.js newId): the first 10 characters, base 32. */
|
|
58
|
+
const B = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
59
|
+
const timeOf = (id) => { let t = 0; for (const c of String(id || '').slice(0, 10)) { const k = B.indexOf(c); if (k < 0) return null; t = t * 32 + k; } return t ? new Date(t).toISOString() : null; };
|
|
60
|
+
function historyOf(lines, rid) {
|
|
61
|
+
const out = [];
|
|
62
|
+
for (const l of lines || []) {
|
|
63
|
+
if (!l || l.rid !== rid || l.kind === 'reading') continue;
|
|
64
|
+
const who = String(l.by || '').startsWith('human:') ? 'You' : 'Claude';
|
|
65
|
+
const what = l.kind === 'add' ? 'added it' : 'changed ' + Object.keys(l.fields || {}).filter((k) => k !== 'retired').join(', ');
|
|
66
|
+
out.push({ at: timeOf(l.id), text: who + ' ' + what + (l.why ? ': ' + String(l.why).slice(0, 120) : '') });
|
|
67
|
+
}
|
|
68
|
+
return out.reverse().slice(0, 12);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = { afterRead, syncFixes, historyOf, timeOf };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (initiative workspace-headless-jobs; PM decision 2026-10-11: keep Jev, no direct Claude API, background
|
|
4
4
|
* jobs that need no human run headless).
|
|
5
5
|
*
|
|
6
|
-
* kindFor({ agent, origin, skill, env }) → 'notes' | 'skill' | 'ask' | 'drive' | 'scan-web' | 'scan-repo' | 'scan-research-web' | 'scan-research-repo' | 'report-setup' | 'report-find' | 'core-doc' | 'report-design' | 'report-structure-pull' | 'report-sample-fetch' | 'report-structure' | 'report-structure-dry' | 'ms-review' | 'propose' | 'metric-draft' | null (null: open a pane, as before)
|
|
6
|
+
* kindFor({ agent, origin, skill, env }) → 'notes' | 'skill' | 'ask' | 'drive' | 'scan-web' | 'scan-repo' | 'scan-research-web' | 'scan-research-repo' | 'report-setup' | 'report-find' | 'core-doc' | 'report-design' | 'report-structure-pull' | 'report-sample-fetch' | 'report-structure' | 'report-structure-dry' | 'ms-review' | 'propose' | 'metric-draft' | 'impact' | 'metric-read' | null (null: open a pane, as before)
|
|
7
7
|
* argsFor(kind, { modelArgs, addDirs, writePaths }) → the argv after `claude` (writePaths: the one render file a report-design job may write;
|
|
8
8
|
* for the skill kind, the folders the run may write in, from skillWriteDirs)
|
|
9
9
|
* skillWriteDirs(skill, { root, scratch }) → the absolute folders a background skill run may write in: its scratch folder and the state folders its skill writes
|
|
@@ -61,6 +61,13 @@
|
|
|
61
61
|
* `metric-draft:<ws>:<scope>:<id>:<run>`. It reads the repository, the stored reads and, where the PM's own settings allow it, the PM's sources through
|
|
62
62
|
* connectors; its only write is `pmos metrics draft`, pinned by the server to that scope and run. Only the PM's ✓ keep writes a record. It sends nothing
|
|
63
63
|
* and never runs in a pane.
|
|
64
|
+
* The `impact` kind is Claude's daily read of the PM's impact (batch 16 item 7, Your impact): origin `impact:<run>`. It reads the stored reads, the
|
|
65
|
+
* repository and, where the PM's own settings allow it, the PM's sources through connectors, for what people and systems did in reaction to the
|
|
66
|
+
* PM's work; its only write is `pmos impact add`, pinned by the server to this run and the person's own ledger. It sends nothing, posts nothing,
|
|
67
|
+
* reacts to nothing, and never runs in a pane.
|
|
68
|
+
* The `metric-read` kind is Claude reading the goals by themselves (feedback batch 16 item 6): origin `metric-read:<ws>:<run>`. It reads each goal's
|
|
69
|
+
* recipe through the PM's own connectors, where the PM's own settings allow it; its only write is `pmos metrics reading`, pinned by the server to
|
|
70
|
+
* that run and those goals: the value lands on the kr-metrics record with its source and time. It sends nothing and never runs in a pane.
|
|
64
71
|
* The `report-structure` and `report-structure-dry` kinds are the report structure step (initiative report-structure): origins `report-structure:<id>` and
|
|
65
72
|
* `report-structure-dry:<id>`. A turn proposes or refines the plan of a report (sources, charts, outline); a dry run tries a saved version on the last complete
|
|
66
73
|
* period. Each reads the repository and, where the PM's own Claude Code settings allow it, reads through connectors (none is named in the list, as for
|
|
@@ -107,6 +114,11 @@ const PROPOSE_ORIGINS = Object.freeze(['propose:']);
|
|
|
107
114
|
// batch 15 item 1: Claude drafts the metrics of a product, a program or an initiative (origin `metric-draft:<ws>:<scope>:<id>:<run>`,
|
|
108
115
|
// lib/metric-draft-runs.js). Its only write is `pmos metrics draft`, pinned by the server to that scope and run.
|
|
109
116
|
const METRIC_DRAFT_ORIGINS = Object.freeze(['metric-draft:']);
|
|
117
|
+
// batch 16 item 7: Claude's daily impact read (origin `impact:<run>`, lib/impact-runs.js). Its only write is `pmos impact add`, pinned to that run.
|
|
118
|
+
const IMPACT_ORIGINS = Object.freeze(['impact:']);
|
|
119
|
+
// batch 16 item 6: Claude reads the goals with their recipes (origin `metric-read:<ws>:<run>`, lib/metric-read-runs.js). Its only write is
|
|
120
|
+
// `pmos metrics reading`, pinned by the server to that run and those goals.
|
|
121
|
+
const METRIC_READ_ORIGINS = Object.freeze(['metric-read:']);
|
|
110
122
|
// report-design-studio: a studio turn, a cycle render or a re-render to match (origin `report-design:<cadence>`).
|
|
111
123
|
const REPORT_DESIGN_ORIGINS = Object.freeze(['report-design:']);
|
|
112
124
|
// report-design-studio: reading ONE linked Google or Confluence file through the PM's own connectors (origin `report-sample-fetch:<cadence>:<sampleId>`).
|
|
@@ -166,6 +178,14 @@ const TOOLS = Object.freeze({
|
|
|
166
178
|
// no web fetch, nothing that sends; it never writes a record (only the PM's ✓ keep does).
|
|
167
179
|
'metric-draft': Object.freeze(['Read', 'Glob', 'Grep', 'Bash(pmos metrics draft *)', 'Bash(pmos initiative export *)', 'Bash(pmos initiative list *)',
|
|
168
180
|
'Bash(pmos source show *)', 'Bash(pmos source status *)', 'Bash(git log *)', 'Bash(date *)']),
|
|
181
|
+
// The impact run (lib/impact-runs.js): read and search the repository and the stored reads, and the one verb that files an item. The PM's
|
|
182
|
+
// Slack, mail and Jira are read through the PM's own connectors only where the PM's settings allow it. No Write, no Edit, no web fetch,
|
|
183
|
+
// nothing that sends, posts or reacts.
|
|
184
|
+
impact: Object.freeze(['Read', 'Glob', 'Grep', 'Bash(pmos impact *)', 'Bash(pmos source show *)', 'Bash(pmos source status *)', 'Bash(pmos initiative list *)',
|
|
185
|
+
'Bash(pmos initiative export *)', 'Bash(git log *)', 'Bash(date *)']),
|
|
186
|
+
// The reading run (lib/metric-read-runs.js): read and search, and the one verb that files a reading. The PM's analytics and Jira are read through
|
|
187
|
+
// the PM's own connectors only where the PM's settings allow it. No Write, no Edit, no web fetch, nothing that sends.
|
|
188
|
+
'metric-read': Object.freeze(['Read', 'Glob', 'Grep', 'Bash(pmos metrics reading *)', 'Bash(pmos source show *)', 'Bash(pmos source status *)', 'Bash(date *)']),
|
|
169
189
|
// The design run: read and search only. Its one write, the render file, is added per run by argsFor (writePaths). No Bash, no web, nothing that sends.
|
|
170
190
|
'report-design': Object.freeze(['Read', 'Glob', 'Grep']),
|
|
171
191
|
// The link fetch run: Read, and its one write (the text copy of the linked file) is added per run by argsFor. No Bash, no web, no connector tool named.
|
|
@@ -204,6 +224,8 @@ function kindFor({ agent, origin, skill, env } = {}) {
|
|
|
204
224
|
if (MS_REVIEW_ORIGINS.some((p) => o.startsWith(p))) return 'ms-review';
|
|
205
225
|
if (PROPOSE_ORIGINS.some((p) => o.startsWith(p))) return 'propose';
|
|
206
226
|
if (METRIC_DRAFT_ORIGINS.some((p) => o.startsWith(p))) return 'metric-draft';
|
|
227
|
+
if (IMPACT_ORIGINS.some((p) => o.startsWith(p))) return 'impact';
|
|
228
|
+
if (METRIC_READ_ORIGINS.some((p) => o.startsWith(p))) return 'metric-read';
|
|
207
229
|
if (REPORT_DESIGN_ORIGINS.some((p) => o.startsWith(p))) return 'report-design';
|
|
208
230
|
if (REPORT_SAMPLE_FETCH_ORIGINS.some((p) => o.startsWith(p))) return 'report-sample-fetch';
|
|
209
231
|
// 'report-structure-dry:' is not a prefix of 'report-structure:' (the colon differs), so the two are told apart by their prefix alone
|
|
@@ -365,4 +387,4 @@ function logLines(r, exitCode) {
|
|
|
365
387
|
return out;
|
|
366
388
|
}
|
|
367
389
|
|
|
368
|
-
module.exports = { 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, TOOLS, SKILL_WRITE_DIRS, DEFAULT_TIMEOUT_MS, kindFor, argsFor, skillWriteDirs, timeoutMs, parseResult, streamLines, outcomeOf, signedOut, SIGNED_OUT_WHY, logLines, switchedOff };
|
|
390
|
+
module.exports = { 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 };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* impact-cli.js — `pmos impact`: the one write of Claude's impact run (feedback batch 16 item 7; lib/impact.js, lib/impact-runs.js).
|
|
3
|
+
* What it files waits for the PM's ✓ or ✕ in the weekly check in Home's chat. Only a ✓ item counts.
|
|
4
|
+
*
|
|
5
|
+
* pmos impact add --json <file|-> one item, or a list of them: { kind, text, who, at, source: { url, type, label } }
|
|
6
|
+
* pmos impact end [--error "<why>"] the run is done
|
|
7
|
+
* pmos impact status what the ledger holds for this week and the last: so the run does not file the same thing twice
|
|
8
|
+
*
|
|
9
|
+
* The server pins the run and the ledger in the run's environment (PMOS_IMPACT_FILE, PMOS_IMPACT_RUN); outside such a run the verb
|
|
10
|
+
* refuses. An item the PM checked is not filed again. Exit codes: 0 filed, 1 refused, 2 usage. It sends nothing. */
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const IM = require('./impact.js');
|
|
13
|
+
|
|
14
|
+
const COMMANDS = { impact: ['add', 'end', 'status'] };
|
|
15
|
+
const SUBS = COMMANDS.impact;
|
|
16
|
+
const USAGE = [
|
|
17
|
+
'usage: pmos impact add|end|status — what Claude\'s impact run files for the PM to check (✓ real, ✕ not real)',
|
|
18
|
+
' pmos impact add --json <file|->',
|
|
19
|
+
' { "kind": "' + IM.KINDS.join('" | "') + '", "text": "<one plain sentence, no counts>", "who": "<a name, or empty>",',
|
|
20
|
+
' "at": "<ISO 8601, when it happened>", "source": { "url": "<https link>", "type": "' + IM.SOURCE_TYPES.join('" | "') + '", "label": "Slack · #idpf-data" } }',
|
|
21
|
+
' pmos impact end [--error "<why the run could not finish>"]',
|
|
22
|
+
' pmos impact status',
|
|
23
|
+
'Only what a person or a system outside you did in reaction to your work. Never Claude\'s own work. No source, no item. Nothing is sent.',
|
|
24
|
+
];
|
|
25
|
+
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; };
|
|
26
|
+
function readJson(src, stdin) {
|
|
27
|
+
let text;
|
|
28
|
+
try { text = src === '-' ? (stdin !== undefined ? String(stdin) : fs.readFileSync(0, 'utf8')) : fs.readFileSync(src, 'utf8'); } catch (e) { return { error: `could not read ${src}: ${String((e && e.message) || e).slice(0, 120)}` }; }
|
|
29
|
+
try { return { body: JSON.parse(text) }; } catch { return { error: 'the input is not JSON' }; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function run(argv, { say = (s) => console.log(s), env = process.env, stdin, now = Date.now() } = {}) {
|
|
33
|
+
const args = argv[0] === 'impact' ? argv.slice(1) : argv.slice();
|
|
34
|
+
const sub = args[0];
|
|
35
|
+
if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
|
|
36
|
+
if (!SUBS.includes(sub)) { say(`unknown impact command "${sub}". Use one of: ${SUBS.join(', ')}`); return 2; }
|
|
37
|
+
const file = env.PMOS_IMPACT_FILE, runId = env.PMOS_IMPACT_RUN;
|
|
38
|
+
if (!file || !runId) { say('✗ pmos impact is for Claude\'s impact run. The PM checks each item in Home\'s chat.'); return 1; }
|
|
39
|
+
const F = IM.fold(IM.readLines(file));
|
|
40
|
+
const at = new Date(now).toISOString();
|
|
41
|
+
const line = (ev) => { fs.appendFileSync(file, JSON.stringify({ at, by: null, run: runId, ...ev }) + '\n', { mode: 0o600 }); };
|
|
42
|
+
|
|
43
|
+
if (sub === 'status') {
|
|
44
|
+
const today = IM.dayOf(now), week = IM.weekOf(today), last = IM.addDays(week, -7);
|
|
45
|
+
const mine = [...F.items.values()].filter((it) => IM.weekOf(IM.dayOf(Date.parse(it.at))) >= last);
|
|
46
|
+
if (!mine.length) say('nothing filed since ' + last);
|
|
47
|
+
for (const it of mine) say(`${it.real === true ? 'real ' : it.real === false ? 'not ' : 'open '} ${it.id} · ${it.kind} · ${it.text} · ${it.source.url}`);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
const r = F.runs.find((x) => x.run === runId);
|
|
51
|
+
if (!r || r.ended) { say('✗ this run is not reading now. It ended. File nothing more.'); return 1; }
|
|
52
|
+
if (sub === 'end') { const e = flag(args, 'error'); line({ kind: 'end', ok: typeof e !== 'string', ...(typeof e === 'string' ? { error: e.slice(0, 200) } : {}) }); say('done'); return 0; }
|
|
53
|
+
|
|
54
|
+
const src = flag(args, 'json');
|
|
55
|
+
if (typeof src !== 'string') { say('usage: pmos impact add --json <file|->'); return 2; }
|
|
56
|
+
const j = readJson(src, stdin);
|
|
57
|
+
if (j.error) { say('✗ ' + j.error); return 2; }
|
|
58
|
+
const list = Array.isArray(j.body) ? j.body : [j.body];
|
|
59
|
+
if (!list.length || list.length > 40) { say('✗ file 1 to 40 items at once'); return 2; }
|
|
60
|
+
let bad = 0;
|
|
61
|
+
for (const x of list) {
|
|
62
|
+
const c = IM.clean(x);
|
|
63
|
+
if (c.error) { bad++; say('✗ ' + c.error + (x && x.text ? ' · ' + String(x.text).slice(0, 60) : '')); continue; }
|
|
64
|
+
const was = F.items.get(c.item.id);
|
|
65
|
+
if (was && was.real !== null) { say(`· ${c.item.id} was checked already: not filed again`); continue; }
|
|
66
|
+
line({ kind: 'item', item: c.item });
|
|
67
|
+
say(`filed ${c.item.id} · ${c.item.kind} · ${c.item.text}`);
|
|
68
|
+
}
|
|
69
|
+
return bad ? 1 : 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = { run, COMMANDS, USAGE, SUBS };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* impact-runs.js — Claude's daily impact run (feedback batch 16 item 7; lib/impact.js, skill impact-detect).
|
|
3
|
+
*
|
|
4
|
+
* off(env) → true when PMOS_IMPACT=off (or 0, false, no)
|
|
5
|
+
* dueOf(F, today) PURE → true when no run started today and the switch is on (the caller checks the switch)
|
|
6
|
+
* sinceOf(F, today) PURE → the first day the run reads from: the day of the last run that ended well, else 8 days back
|
|
7
|
+
* promptOf(skill, o) → the prompt. o: { run, today, since, facts: [line], filed: [line], notReal: [line] }
|
|
8
|
+
* create(deps) → { tick(opts), start({ now, press }), active() }
|
|
9
|
+
*
|
|
10
|
+
* ONE RUN A DAY, for the person (not per product): headless kind `impact`, origin `impact:<run>`, in the home workspace. It reads the
|
|
11
|
+
* stored reads (`pmos source show`), the repository and, where the PM's own Claude Code settings allow it, the PM's connectors, for what
|
|
12
|
+
* people and systems outside the PM did in reaction to the PM's work. Its only write is `pmos impact add`, pinned by the server to this run
|
|
13
|
+
* and the person's ledger (PMOS_IMPACT_FILE, PMOS_IMPACT_RUN). It sends nothing, posts nothing and reacts to nothing.
|
|
14
|
+
*
|
|
15
|
+
* It never runs when Settings › General › Your impact is off (deps.on() false), when PMOS_IMPACT or PMOS_HEADLESS is off, or outside the
|
|
16
|
+
* day-check window. A run that failed tries again the next day.
|
|
17
|
+
*
|
|
18
|
+
* deps: { runtime() → the runtime folder, on() → bool (impact.on), homeWs() → w, open(now) → bool, headlessOff() → bool, env,
|
|
19
|
+
* promptFor(skillId) → skill body | null, facts() → [line], spawn(spec), spawnNow(spec), stop(session), warn(what, err) }
|
|
20
|
+
*/
|
|
21
|
+
const crypto = require('crypto');
|
|
22
|
+
const IM = require('./impact.js');
|
|
23
|
+
|
|
24
|
+
const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
|
|
25
|
+
const off = (env) => flagOff((env || process.env).PMOS_IMPACT);
|
|
26
|
+
const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
|
|
27
|
+
const BACK_DAYS = 8;
|
|
28
|
+
|
|
29
|
+
const dayAt = (at) => { const t = Date.parse(at); return Number.isFinite(t) ? IM.dayOf(t) : ''; };
|
|
30
|
+
function dueOf(F, today) { return !(F.runs || []).some((r) => dayAt(r.at) === today); }
|
|
31
|
+
function sinceOf(F, today) {
|
|
32
|
+
const ok = (F.runs || []).filter((r) => r.ended && r.ok).map((r) => dayAt(r.at)).filter(Boolean).sort();
|
|
33
|
+
const floor = IM.addDays(today, -BACK_DAYS);
|
|
34
|
+
return ok.length && ok[ok.length - 1] > floor ? ok[ok.length - 1] : floor;
|
|
35
|
+
}
|
|
36
|
+
function promptOf(skill, o) {
|
|
37
|
+
const list = (a, none) => (a && a.length ? a.map((x) => '- ' + x).join('\n') : '- ' + none);
|
|
38
|
+
return `${skill}\n\nThis run:\n- Run: ${o.run}\n- Today: ${o.today}\n- Read from: ${o.since} to today\n`
|
|
39
|
+
+ `- What PMOS knows:\n${list(o.facts, 'nothing more')}\n`
|
|
40
|
+
+ `- Filed already (do not file these again):\n${list(o.filed, 'none')}\n`
|
|
41
|
+
+ `- The PM said these were not real (do not file anything like them):\n${list(o.notReal, 'none')}\n\n`
|
|
42
|
+
+ 'File with `pmos impact add` only (the server pins this run). End with `pmos impact end`. Send nothing.';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function create(deps) {
|
|
46
|
+
const warn = deps.warn || (() => {});
|
|
47
|
+
let active = null; // { run, dir, session }
|
|
48
|
+
const dirNow = () => IM.dirOf(deps.runtime && deps.runtime());
|
|
49
|
+
const isOn = () => { try { return !!deps.on(); } catch { return false; } };
|
|
50
|
+
|
|
51
|
+
function ended(run, r, now = Date.now()) {
|
|
52
|
+
if (!active || active.run !== run) return;
|
|
53
|
+
const dir = active.dir; active = null;
|
|
54
|
+
const x = IM.read(dir).runs.find((y) => y.run === run);
|
|
55
|
+
if (!x || x.ended) return; // `pmos impact end` wrote it already
|
|
56
|
+
const res = (r && r.result) || {};
|
|
57
|
+
const ok = !!(r && !r.timedOut && !r.stopped && r.code === 0 && res.ok !== false && !res.isError);
|
|
58
|
+
try { IM.append(dir, null, { kind: 'end', run, ok, ...(ok ? {} : { error: one((r && r.note) || res.text || 'the run failed', 200) }) }, new Date(now).toISOString()); } catch (e) { warn('impact end', e); }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Start the run now. → { ok, run } | { ok: false, error, held? } */
|
|
62
|
+
function start({ now = Date.now(), press = false } = {}) {
|
|
63
|
+
if (!isOn()) return { ok: false, error: 'Your impact is off in Settings.' };
|
|
64
|
+
if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { ok: false, error: 'Background runs are off (PMOS_IMPACT or PMOS_HEADLESS).' };
|
|
65
|
+
if (active) return { ok: true, run: active.run, already: true };
|
|
66
|
+
const dir = dirNow(); if (!dir) return { ok: false, error: 'There is no runtime folder.' };
|
|
67
|
+
const w = deps.homeWs && deps.homeWs(); if (!w) return { ok: false, error: 'There is no workspace to run in.' };
|
|
68
|
+
const skill = deps.promptFor('impact-detect');
|
|
69
|
+
if (!skill) return { ok: false, error: 'The impact-detect skill is not installed.' };
|
|
70
|
+
const F = IM.read(dir), today = IM.dayOf(now);
|
|
71
|
+
const run = 'im' + now.toString(36) + crypto.randomBytes(3).toString('hex');
|
|
72
|
+
const recent = [...F.items.values()].filter((it) => dayAt(it.at) >= IM.addDays(today, -21));
|
|
73
|
+
const line = (it) => it.kind + ' · ' + it.text + ' · ' + it.source.url;
|
|
74
|
+
let facts = [];
|
|
75
|
+
try { facts = (deps.facts && deps.facts()) || []; } catch { facts = []; }
|
|
76
|
+
const prompt = promptOf(skill, { run, today, since: sinceOf(F, today), facts, filed: recent.filter((x) => x.real !== false).map(line), notReal: recent.filter((x) => x.real === false).map(line) });
|
|
77
|
+
const go = press && deps.spawnNow ? deps.spawnNow : deps.spawn;
|
|
78
|
+
active = { run, dir, session: null };
|
|
79
|
+
let session = null;
|
|
80
|
+
try {
|
|
81
|
+
session = go({ name: 'Reading your impact', ws: w.id, origin: 'impact:' + run, initialInput: prompt + '\r',
|
|
82
|
+
env: { PMOS_IMPACT_FILE: IM.ledgerFile(dir), PMOS_IMPACT_RUN: run }, onDone: (r) => ended(run, r) });
|
|
83
|
+
} catch (e) { warn('impact run', e); }
|
|
84
|
+
if (session && session.held) { active = null; return { ok: false, held: true, error: 'Claude is busy with other runs. It tries again later.' }; }
|
|
85
|
+
IM.append(dir, null, { kind: 'run', run }, new Date(now).toISOString());
|
|
86
|
+
if (!session || session.state === 'exited' || session.headless !== 'impact') {
|
|
87
|
+
if (session && session.headless !== 'impact' && session.state !== 'exited' && deps.stop) { try { deps.stop(session); } catch { /* best effort */ } }
|
|
88
|
+
ended(run, { code: 1, note: (session && session.note) || 'the run could not start in the background', result: {} }, now);
|
|
89
|
+
return { ok: false, error: (session && session.note) || 'Claude could not start reading.' };
|
|
90
|
+
}
|
|
91
|
+
if (active) active.session = session;
|
|
92
|
+
return { ok: true, run };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function tick({ now = Date.now() } = {}) {
|
|
96
|
+
if (!isOn()) { stopAll(); return { off: true }; } // the switch went off: a run that is reading stops at the next tick
|
|
97
|
+
if (off(deps.env) || (deps.headlessOff && deps.headlessOff())) return { off: true };
|
|
98
|
+
if (active) return { running: true };
|
|
99
|
+
let open = true;
|
|
100
|
+
try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
|
|
101
|
+
if (!open) return { started: null, closed: true };
|
|
102
|
+
const dir = dirNow(); if (!dir) return { started: null };
|
|
103
|
+
if (!dueOf(IM.read(dir), IM.dayOf(now))) return { started: null };
|
|
104
|
+
const r = start({ now });
|
|
105
|
+
return r.ok ? { started: r.run } : { started: null, error: r.error, held: !!r.held };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The switch went off: stop a run that is reading. */
|
|
109
|
+
function stopAll() { if (active && active.session && deps.stop) { try { deps.stop(active.session); } catch { /* best effort */ } } }
|
|
110
|
+
|
|
111
|
+
return { tick, start, stopAll, active: () => (active ? active.run : null) };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
module.exports = { off, dueOf, sinceOf, promptOf, create, BACK_DAYS };
|