create-pmos 0.432.0 → 0.434.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/guide/home.md +1 -1
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/metric-drafts.md +21 -1
- package/workspace/guide/programs.md +1 -1
- 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/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/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/route-modules.js +3 -0
- 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-records.js +2 -0
- package/workspace/lib/settings-store.js +3 -0
- package/workspace/milestone-pins-test.js +8 -3
- package/workspace/okr-goals-ui-test.js +175 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/product-lane-test.js +5 -5
- package/workspace/public/pm/bd-ini-panel.js +10 -2
- package/workspace/public/pm/bd-span.js +5 -4
- 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/home-app.js +61 -8
- package/workspace/public/pm/home-impact.css +16 -0
- package/workspace/public/pm/home-impact.js +72 -0
- 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 +222 -238
- package/workspace/public/pm/premium-vw-mtg.js +4 -1
- package/workspace/public/pm/stage-line.js +4 -3
- package/workspace/public/premium-intelligence.html +3 -2
- package/workspace/public/premium.html +1 -0
- package/workspace/server.js +56 -2
- package/workspace/skills/impact-detect.skill +46 -0
- package/workspace/skills/metric-read.skill +32 -0
- package/workspace/task-milestones-test.js +4 -3
- 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
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* metrics-cli.js — `pmos metrics draft`: the one write of Claude's metric-draft run (batch 15 item 1; lib/metric-drafts.js, lib/metric-draft-runs.js).
|
|
3
|
-
* What it files waits on the page as a draft until the PM's ✓ keep, which alone writes the kr-metrics record.
|
|
3
|
+
* What it files waits on the page as a draft until the PM's ✓ keep, which alone writes the kr-metrics record. And `pmos metrics reading`: the one
|
|
4
|
+
* write of Claude's reading run (batch 16 item 6; lib/metric-reads.js, lib/metric-read-runs.js).
|
|
4
5
|
*
|
|
5
6
|
* pmos metrics draft read "<source>" --found "<one line>" [--state done|now|wait] one source read, for the strip's first step
|
|
6
7
|
* pmos metrics draft step shape|measure|target|ready the strip moves on
|
|
7
8
|
* pmos metrics draft row --json <file|-> one drafted row, or a list of them
|
|
8
9
|
* pmos metrics draft end --head "<line>" [--sub "<line>"] [--src "<a · b · c>"] the run is done: what the page says on top
|
|
9
10
|
* pmos metrics draft status what this scope holds: open, kept and dropped
|
|
11
|
+
* pmos metrics draft fix --json <file|-> one fix row, or a list (kinds: lib/metric-drafts.js FIXES)
|
|
12
|
+
*
|
|
13
|
+
* pmos metrics reading list the goals this run reads, with their recipes
|
|
14
|
+
* pmos metrics reading <rid> <value> --source "<connector · what>" [--day YYYY-MM-DD] one value read: on the record, with its source and time
|
|
15
|
+
* pmos metrics reading <rid> --cant "<why>" [--fix connect|recipe --connector <name> [--query "<q>" --cadence daily|weekly|monthly]]
|
|
16
|
+
* could not read it, said honestly, with the drafted fix
|
|
17
|
+
* The reading run's environment pins its ledger, its records folder, its run and its goals (PMOS_METRIC_READ_FILE, _RECORDS, _DRAFTS, _WS, _RUN,
|
|
18
|
+
* _RIDS, _TEST). In a test run (before the PM keeps a draft) a value lands only in the ledger, never on a record.
|
|
10
19
|
*
|
|
11
20
|
* The server pins the scope, the run and the ledger in the run's environment (PMOS_METRIC_DRAFT_FILE, _WS, _SCOPE, _ID, _RUN); outside such
|
|
12
21
|
* a run the verb refuses: the PM keeps and drops on the page. A row the PM kept is not filed again. Exit codes: 0 filed, 1 refused, 2 usage.
|
|
13
22
|
* It writes no record and sends nothing. */
|
|
14
23
|
const fs = require('fs');
|
|
15
24
|
const MD = require('./metric-drafts.js');
|
|
25
|
+
const MR = require('./metric-reads.js');
|
|
16
26
|
|
|
17
|
-
const COMMANDS = { metrics: ['draft'] };
|
|
18
|
-
const SUBS = ['read', 'step', 'row', 'end', 'status'];
|
|
27
|
+
const COMMANDS = { metrics: ['draft', 'reading'] };
|
|
28
|
+
const SUBS = ['read', 'step', 'row', 'fix', 'end', 'status'];
|
|
19
29
|
const USAGE = [
|
|
20
30
|
'usage: pmos metrics draft read|step|row|end|status — the metrics Claude drafts for the PM to keep or drop',
|
|
21
31
|
' pmos metrics draft read "<source>" --found "<what it says, one line>" [--state done|now|wait]',
|
|
@@ -27,8 +37,75 @@ const USAGE = [
|
|
|
27
37
|
' "direction"?: "up" | "down", "unit"?, "pillar"? (Key results) }',
|
|
28
38
|
' pmos metrics draft end --head "<I drafted …>" [--sub "<where it comes from>"] [--src "<Product brief · Amplitude>"]',
|
|
29
39
|
' pmos metrics draft status',
|
|
40
|
+
' pmos metrics draft fix --json <file|->',
|
|
41
|
+
' { "kind": "' + MD.FIXES.join('" | "') + '", "goal": "<kr-metrics rid, or the KR anchor for outcome>", "text": "<the fix, one line>",',
|
|
42
|
+
' "why": "<the evidence, one line>", "old"?, "metric"? (outcome, next-quarter: a Key results row), "recipe"? { "connector", "query", "cadence" },',
|
|
43
|
+
' "connector"? (connect), "to", "body" (chase), "ticket"? { "title", "text", "project"? }, "by"?, "target"? (carry), "owner"? { "name", "from" } }',
|
|
44
|
+
' pmos metrics reading list',
|
|
45
|
+
' pmos metrics reading <rid> <value> --source "<connector · what you read>" [--day YYYY-MM-DD]',
|
|
46
|
+
' pmos metrics reading <rid> --cant "<why>" [--fix connect|recipe --connector <name> [--query "<q>" --cadence daily|weekly|monthly]]',
|
|
30
47
|
'Every number comes from a real reading. The PM keeps or drops each row on the page. Nothing is sent.',
|
|
31
48
|
];
|
|
49
|
+
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
50
|
+
const localDay = (ms) => { const d = new Date(ms); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
51
|
+
|
|
52
|
+
/** `pmos metrics reading`: the reading run's one write. */
|
|
53
|
+
function reading(args, { say, env, now }) {
|
|
54
|
+
const file = env.PMOS_METRIC_READ_FILE, runId = env.PMOS_METRIC_READ_RUN, root = env.PMOS_METRIC_READ_RECORDS, ws = env.PMOS_METRIC_READ_WS;
|
|
55
|
+
const rids = String(env.PMOS_METRIC_READ_RIDS || '').split(',').filter(Boolean), test = !!env.PMOS_METRIC_READ_TEST;
|
|
56
|
+
if (!args[0] || ['help', '--help', '-h'].includes(args[0])) { for (const l of USAGE.filter((x) => /reading|Every/.test(x))) say(l); return args[0] ? 0 : 1; }
|
|
57
|
+
if (!file || !runId || !rids.length || (!test && !root)) { say('✗ pmos metrics reading is for Claude\'s reading run. The PM adds a reading on the goal\'s page.'); return 1; }
|
|
58
|
+
const F = MR.fold(MR.readLines(file)), R = F.runs.get(runId);
|
|
59
|
+
if (!R || R.ended) { say('✗ this run is not reading now. It ended, or the PM pressed Stop. File nothing more.'); return 1; }
|
|
60
|
+
const records = () => require(require('./repo-script.js').repoScript('records/index.js'));
|
|
61
|
+
if (args[0] === 'list') {
|
|
62
|
+
let recs = []; if (!test) { try { recs = records().list(root, 'kr-metrics'); } catch { recs = []; } }
|
|
63
|
+
for (const rid of rids) { const r = recs.find((x) => x.rid === rid); say(rid + (r ? ' · ' + r.metric + (r.recipe ? ' · ' + r.recipe.connector + ': ' + r.recipe.query : '') : test ? ' · a drafted goal (test read)' : ' · no such record')); }
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
const rid = args[0];
|
|
67
|
+
if (!rids.includes(rid)) { say(`✗ ${rid} is not one of the goals this run reads: ${rids.join(', ')}`); return 1; }
|
|
68
|
+
const at = new Date(now).toISOString();
|
|
69
|
+
const lineOut = (ev) => { require('fs').appendFileSync(file, JSON.stringify({ at, by: null, run: runId, rid, ...(test ? { test: true } : {}), ...ev }) + '\n'); };
|
|
70
|
+
const cant = flag(args, 'cant');
|
|
71
|
+
if (cant !== undefined) {
|
|
72
|
+
if (typeof cant !== 'string' || !cant.trim()) { say('usage: pmos metrics reading <rid> --cant "<why>" [--fix connect|recipe --connector <name>]'); return 2; }
|
|
73
|
+
let fixId = null;
|
|
74
|
+
const fk = flag(args, 'fix');
|
|
75
|
+
if (fk !== undefined) {
|
|
76
|
+
if (fk !== 'connect' && fk !== 'recipe') { say('✗ --fix is connect or recipe'); return 2; }
|
|
77
|
+
const drafts = env.PMOS_METRIC_READ_DRAFTS, connector = flag(args, 'connector');
|
|
78
|
+
if (!drafts || !ws) { say('✗ this run has no drafts ledger, so it cannot draft a fix. Say the fix in your answer.'); return 1; }
|
|
79
|
+
const why = cant.replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
80
|
+
const input = fk === 'connect'
|
|
81
|
+
? { kind: 'connect', goal: test ? null : rid, connector, text: 'Connect ' + (typeof connector === 'string' ? connector : 'the source') + ' so I can read this goal.', why }
|
|
82
|
+
: { kind: 'recipe', goal: rid, text: 'Read it another way: ' + (typeof connector === 'string' ? connector : '') + '.', why, recipe: { connector, query: flag(args, 'query'), cadence: flag(args, 'cadence') || 'weekly' } };
|
|
83
|
+
const c = MD.cleanFix('product', ws, input);
|
|
84
|
+
if (c.error) { say('✗ refused: ' + c.error); return 1; }
|
|
85
|
+
require('fs').appendFileSync(drafts, JSON.stringify({ at, by: null, kind: 'fix', scope: 'product', id: ws, row: c.row, src: 'read' }) + '\n');
|
|
86
|
+
fixId = c.row.id;
|
|
87
|
+
}
|
|
88
|
+
lineOut({ kind: 'cant', why: cant.replace(/\s+/g, ' ').trim().slice(0, 200), ...(fixId ? { fix: fixId } : {}) });
|
|
89
|
+
say(`not read ${rid}${fixId ? ' · fix ' + fixId + ' drafted' : ''}`);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
const v = Number(args[1]);
|
|
93
|
+
if (args[1] === undefined || !Number.isFinite(v)) { say('usage: pmos metrics reading <rid> <value> --source "<connector · what>" [--day YYYY-MM-DD]'); return 2; }
|
|
94
|
+
const source = flag(args, 'source');
|
|
95
|
+
if (typeof source !== 'string' || !source.trim()) { say('✗ a reading names where it was read: --source "Amplitude · checkout_login_success / checkout_view"'); return 1; }
|
|
96
|
+
const day = flag(args, 'day') === undefined ? localDay(now) : String(flag(args, 'day'));
|
|
97
|
+
if (!DAY_RE.test(day) || day > localDay(now)) { say('✗ --day is YYYY-MM-DD, today or before'); return 2; }
|
|
98
|
+
const src = source.replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
99
|
+
if (!test) {
|
|
100
|
+
const L = require(require('./repo-script.js').repoScript('trust/ledger.js'));
|
|
101
|
+
const actor = L.actorFrom({ env, isTTY: !!(process.stdout && process.stdout.isTTY) }) || { by: 'claude-code/metric-read', via: 'cli' };
|
|
102
|
+
let r; try { r = records().addReading(root, rid, { at: day, value: v, source: src, via: 'run', read_at: at }, actor, 'Claude read it with its recipe'); } catch (e) { r = { ok: false, reasons: [String((e && e.message) || e).slice(0, 160)] }; }
|
|
103
|
+
if (!r.ok) { say('✗ refused: ' + r.reasons.join('; ')); return 1; }
|
|
104
|
+
}
|
|
105
|
+
lineOut({ kind: 'read', value: v, day, source: src });
|
|
106
|
+
say(`${test ? 'test read' : 'read'} ${rid} · ${v} on ${day} · ${src}`);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
32
109
|
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; };
|
|
33
110
|
function readJson(src, stdin) {
|
|
34
111
|
let text;
|
|
@@ -39,7 +116,8 @@ function readJson(src, stdin) {
|
|
|
39
116
|
async function run(argv, { say = (s) => console.log(s), env = process.env, stdin, now = Date.now() } = {}) {
|
|
40
117
|
const args = argv[0] === 'metrics' ? argv.slice(1) : argv.slice();
|
|
41
118
|
if (!args[0] || ['help', '--help', '-h'].includes(args[0])) { for (const l of USAGE) say(l); return args[0] ? 0 : 1; }
|
|
42
|
-
if (args[0]
|
|
119
|
+
if (args[0] === 'reading') return reading(args.slice(1), { say, env, now });
|
|
120
|
+
if (args[0] !== 'draft') { say(`unknown metrics command "${args[0]}". Use: pmos metrics draft ${SUBS.join('|')}, or pmos metrics reading`); return 2; }
|
|
43
121
|
const sub = args[1];
|
|
44
122
|
if (!sub || ['help', '--help', '-h'].includes(sub)) { for (const l of USAGE) say(l); return sub ? 0 : 1; }
|
|
45
123
|
if (!SUBS.includes(sub)) { say(`unknown draft command "${sub}". Use one of: ${SUBS.join(', ')}`); return 2; }
|
|
@@ -51,7 +129,7 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
|
|
|
51
129
|
|
|
52
130
|
if (sub === 'status') {
|
|
53
131
|
if (!s || !s.rows.size) say('nothing drafted for ' + scope + ' ' + id);
|
|
54
|
-
else for (const r of s.rows.values()) say(`${r.state.padEnd(7)} ${r.id} · ${r.group} · ${r.name} · now ${r.nowTxt} · target ${r.targetTxt}`);
|
|
132
|
+
else for (const r of s.rows.values()) say(r.kind && r.kind !== 'metric' ? `${r.state.padEnd(7)} ${r.id} · ${r.kind} · ${r.text}` : `${r.state.padEnd(7)} ${r.id} · ${r.group} · ${r.name} · now ${r.nowTxt} · target ${r.targetTxt}`);
|
|
55
133
|
return 0;
|
|
56
134
|
}
|
|
57
135
|
if (!s || !s.run || s.run.run !== runId || s.run.ended) { say('✗ this run is not drafting now. It ended, or the PM pressed Stop. File nothing more.'); return 1; }
|
|
@@ -81,6 +159,23 @@ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin
|
|
|
81
159
|
say('ended: ready for the PM');
|
|
82
160
|
return 0;
|
|
83
161
|
}
|
|
162
|
+
if (sub === 'fix') {
|
|
163
|
+
const jsonAt = args.indexOf('--json'), src = jsonAt >= 0 ? args[jsonAt + 1] : null;
|
|
164
|
+
if (!src) { say('usage: pmos metrics draft fix --json <file|->'); return 2; }
|
|
165
|
+
const r = readJson(src, stdin); if (r.error) { say('✗ ' + r.error); return 1; }
|
|
166
|
+
let bad = 0, n = MD.fixesIn(s, runId);
|
|
167
|
+
for (const x of Array.isArray(r.body) ? r.body : [r.body]) {
|
|
168
|
+
const c = MD.cleanFix(scope, id, x);
|
|
169
|
+
if (c.error) { say(`✗ refused: ${c.error}`); bad++; continue; }
|
|
170
|
+
const was = s.rows.get(c.row.id);
|
|
171
|
+
if (was && was.state !== 'open') { say(`${was.state} ${c.row.id}: the PM ${was.state} it already. Draft something new.`); continue; }
|
|
172
|
+
if (!(was && was.run === runId) && n >= MD.FIX_LIMIT) { say(`✗ refused: one run files at most ${MD.FIX_LIMIT} fixes`); bad++; continue; }
|
|
173
|
+
line({ kind: 'row', row: c.row });
|
|
174
|
+
if (!(was && was.run === runId)) n++;
|
|
175
|
+
say(`filed ${c.row.id} · ${c.row.kind} · ${c.row.text}`);
|
|
176
|
+
}
|
|
177
|
+
return bad ? 1 : 0;
|
|
178
|
+
}
|
|
84
179
|
// row
|
|
85
180
|
const jsonAt = args.indexOf('--json'), src = jsonAt >= 0 ? args[jsonAt + 1] : null;
|
|
86
181
|
if (!src) { say('usage: pmos metrics draft row --json <file|->'); return 2; }
|
|
@@ -80,7 +80,10 @@ const VERBS = Object.freeze({
|
|
|
80
80
|
help: 'pmos propose look|found|date|done|name|status … — what Claude\'s run files under an initiative\'s ✦ for the PM to keep or drop (pmos propose help)' }),
|
|
81
81
|
// Not a pm-os-absorb verb (run: null): batch 15 item 1 (Claude drafts metrics without being asked) added it through the same table.
|
|
82
82
|
metrics: Object.freeze({ module: 'metrics-cli.js', run: null, guide: 'metric-drafts.md',
|
|
83
|
-
help: 'pmos metrics draft read|step|row|end|status … — what Claude\'s metric-draft run files for the PM to keep or drop (pmos metrics help)' }),
|
|
83
|
+
help: 'pmos metrics draft read|step|row|fix|end|status … — what Claude\'s metric-draft run files for the PM to keep or drop; pmos metrics reading … — what Claude\'s reading run reads (pmos metrics help)' }),
|
|
84
|
+
// Not a pm-os-absorb verb (run: null): batch 16 item 7 (Your impact) added it through the same table.
|
|
85
|
+
impact: Object.freeze({ module: 'impact-cli.js', run: null, guide: 'your-impact.md',
|
|
86
|
+
help: 'pmos impact add|end|status … — what Claude\'s impact run files for you to check, ✓ real or ✕ not real (pmos impact help)' }),
|
|
84
87
|
driver: Object.freeze({ module: 'driver-cli.js', run: null, guide: 'initiative-driver.md',
|
|
85
88
|
help: 'pmos driver propose|status|keep|return|drop|pause|resume|mode … — the Initiative Driver: drafts for you to keep, send back or drop (pmos driver help)' }),
|
|
86
89
|
// Not a pm-os-absorb verb (run: null): initiative horizon-scan added it through the same table; horizon-scan-portfolio added section, propose, setting and --boards.
|
|
@@ -103,7 +103,10 @@ const MODULES = Object.freeze([
|
|
|
103
103
|
'routes-insight-moves', // batch 16 item 1: the ✓ and Undo of a drafted move on the Intelligence ✦ strip (insight-moves.jsonl; date, anchor, chase to the outbox)
|
|
104
104
|
'routes-page-opens', // batch 16 item 1: the pages the PM opens, by day, local only (runtime page-opens.jsonl); drives the weekly report proposal
|
|
105
105
|
'routes-metric-drafts', // batch 15 item 1: the metrics Claude drafts unasked for a product, a program or an initiative; ✓ keep writes kr-metrics (metric-drafts.jsonl; page-press POST)
|
|
106
|
+
'routes-impact', // batch 16 item 7: Your impact, private to the PM: the week, the log, the weekly check and its ✓/✕ (runtime impact/impact.jsonl; page-press POST)
|
|
107
|
+
'routes-goal-status', // batch 16 item 6: the goals' one status from readings (product page), notify choice, recipe, Read now, test read, CSV readings
|
|
106
108
|
'routes-refresh', // data-refresh-settings: Settings › Data refresh: what refreshes, when, the refresh log, Refresh now
|
|
109
|
+
'routes-impact-views', // batch 16 item 7 (Your impact, Phase 4): the chapter card's read, a stage that closed this week (boards.jsonl; read-only)
|
|
107
110
|
]);
|
|
108
111
|
const PM_DIR = path.join(__dirname, '..', 'public', 'pm');
|
|
109
112
|
const MODULE_NAME = /^[a-z0-9][a-z0-9-]*\.js$/;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-goal-status.js — the goals' readings and their watch (feedback batch 16 item 6, "Claude runs the OKRs"). The status is lib/goal-status.js,
|
|
3
|
+
* the reading ledger lib/metric-reads.js, the runs lib/metric-read-runs.js (ctx.metricReadRuns), the alerts and the standing fixes lib/goal-watch.js.
|
|
4
|
+
*
|
|
5
|
+
* GET /api/goal-status?ws=<id> → { ok, on, behind: [title], broken: [title], close: [title], none, dots: [{ id, title, dot }], line }
|
|
6
|
+
* the product page's Goals line: the same status as Intelligence's goal list, never initiative risk
|
|
7
|
+
* POST /api/goals/notify { ws, id, notify: push | intel | quiet } → { ok } the goal Viewer ⋯: how a broken limit reaches the PM
|
|
8
|
+
* POST /api/goal-status/recipe { ws, id, recipe: { connector, query, cadence } | null, close_band? } → { ok } how the goal is read, and its band
|
|
9
|
+
* POST /api/goal-status/read { ws, id? } → { ok, run, rids } Read now: one goal, or every goal with a recipe
|
|
10
|
+
* POST /api/goal-status/test { ws, rows: [draft row id] } → { ok, run, rids } a test read of drafted rows before the ✓ (no record is written)
|
|
11
|
+
* POST /api/goal-status/csv { ws, id, csv, source? } → { ok, added, skipped } the fallback: a CSV or sheet export's readings, via csv
|
|
12
|
+
*
|
|
13
|
+
* WHO WRITES. As lib/routes-metric-drafts.js: a POST with an agent session header is refused (403), and pm-guard requirePagePress checks the
|
|
14
|
+
* launch nonce and the page's origin. A record write goes through scripts/records (planning/records/kr-metrics.jsonl of the workspace). */
|
|
15
|
+
const guard = require('./pm-guard.js');
|
|
16
|
+
const GS = require('./goal-status.js');
|
|
17
|
+
const MR = require('./metric-reads.js');
|
|
18
|
+
const MD = require('./metric-drafts.js');
|
|
19
|
+
const GW = require('./goal-watch.js');
|
|
20
|
+
const { repoScript } = require('./repo-script.js');
|
|
21
|
+
const { recordsDirFor } = require('./records-dir.js');
|
|
22
|
+
|
|
23
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
24
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
25
|
+
const records = () => require(repoScript('records/index.js'));
|
|
26
|
+
const UI = () => require(repoScript('trust/ledger.js')).actorFrom({ ui: true });
|
|
27
|
+
const todayIso = () => { const d = new Date(); return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0'); };
|
|
28
|
+
const dirOf = (ctx, w) => { try { return ctx.stateDirFor ? ctx.stateDirFor(w) : null; } catch { return null; } };
|
|
29
|
+
const wsOf = (ctx, ws) => { let w = null; try { w = ctx.getWs(ws || null); } catch { w = null; } return ws && w && w.id !== ws ? null : w; };
|
|
30
|
+
/** The goals the product page shows: the product's own (North Star, key results, guardrails, budgets), not what Claude only watches and not a
|
|
31
|
+
* program's or an initiative's own measure. */
|
|
32
|
+
const PRODUCT_ROLES = new Set(['north-star', 'input', 'guardrail', 'kr']);
|
|
33
|
+
const liveRecords = (ctx, w) => records().list(recordsDirFor(ctx, w.id), 'kr-metrics').filter((r) => r && r.retired !== true);
|
|
34
|
+
|
|
35
|
+
function summaryFor(ctx, w, today) {
|
|
36
|
+
const goals = liveRecords(ctx, w).filter((r) => !r.role || PRODUCT_ROLES.has(r.role) || r.budget).map((r) => ({ id: r.rid, title: String(r.metric || r.rid), reading: GS.readingOf(r, today) }));
|
|
37
|
+
return GS.summaryOf(goals);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** After readings landed: the alert check, the bell for a push, and the standing read fixes cleared (lib/goal-watch.js). */
|
|
41
|
+
function afterRead(ctx, w, rids, now = Date.now()) {
|
|
42
|
+
const dir = dirOf(ctx, w); if (!dir) return [];
|
|
43
|
+
return GW.afterRead({ dir, ws: w.id, records: liveRecords(ctx, w), rids, today: todayIso(), at: new Date(now).toISOString(),
|
|
44
|
+
tell: (rec, reading) => { if (ctx.tellGoalAlert) ctx.tellGoalAlert(w, rec, reading); } });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function handle(req, res, url, ctx) {
|
|
48
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
49
|
+
if (url.pathname === '/api/goal-status') {
|
|
50
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
51
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
52
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
53
|
+
try { return send({ status: 200, body: { ok: true, ...summaryFor(ctx, w, todayIso()) } }); } catch (e) { return send(bad(500, 'The goals could not be read: ' + String((e && e.message) || e).slice(0, 160))); }
|
|
54
|
+
}
|
|
55
|
+
const what = url.pathname === '/api/goals/notify' ? 'notify' : url.pathname.replace(/^\/api\/goal-status\/?/, '');
|
|
56
|
+
if (!['notify', 'recipe', 'read', 'test', 'csv'].includes(what)) return send(bad(404, 'no such goal-status route'));
|
|
57
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
58
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'Only the PM changes how a goal is read or told, from the page. A run files readings with pmos metrics reading.'));
|
|
59
|
+
const got = await ctx.readJson(req);
|
|
60
|
+
if (!got.ok) return send(bad(400, 'the body is not JSON'));
|
|
61
|
+
const body = got.body || {};
|
|
62
|
+
const g = guard.requirePagePress(req, body);
|
|
63
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
64
|
+
const w = wsOf(ctx, text(body.ws));
|
|
65
|
+
if (!w) return send(bad(404, 'no such workspace'));
|
|
66
|
+
const root = recordsDirFor(ctx, w.id), id = text(body.id);
|
|
67
|
+
const rec = id ? liveRecords(ctx, w).find((r) => r.rid === id) : null;
|
|
68
|
+
const edit = (fields, why) => { let e; try { e = records().edit(root, 'kr-metrics', id, fields, UI(), why); } catch (x) { e = { ok: false, reasons: [String((x && x.message) || x).slice(0, 160)] }; } return e.ok ? { status: 200, body: { ok: true } } : bad(400, (e.reasons || []).join('; ')); };
|
|
69
|
+
|
|
70
|
+
if (what === 'notify') {
|
|
71
|
+
if (!rec) return send(bad(404, 'There is no such goal.'));
|
|
72
|
+
if (!['push', 'intel', 'quiet'].includes(body.notify)) return send(bad(400, 'notify is push, intel or quiet'));
|
|
73
|
+
return send(edit({ notify: body.notify }, 'How a broken limit reaches you'));
|
|
74
|
+
}
|
|
75
|
+
if (what === 'recipe') {
|
|
76
|
+
if (!rec) return send(bad(404, 'There is no such goal.'));
|
|
77
|
+
const set = {};
|
|
78
|
+
if (body.recipe === null) set.recipe = null;
|
|
79
|
+
else if (body.recipe !== undefined) { const r = MD.recipeOf(body.recipe); if (r.error) return send(bad(400, r.error)); set.recipe = r.recipe; }
|
|
80
|
+
if (body.close_band !== undefined) { const b = Number(body.close_band); if (!Number.isFinite(b) || b < 0) return send(bad(400, 'close_band is a number, 0 or more')); set.close_band = b; }
|
|
81
|
+
if (!Object.keys(set).length) return send(bad(400, 'Say the recipe or the close band.'));
|
|
82
|
+
return send(edit(set, 'How Claude reads this goal'));
|
|
83
|
+
}
|
|
84
|
+
if (what === 'read' || what === 'test') {
|
|
85
|
+
if (!ctx.metricReadRuns) return send(bad(503, 'Claude\'s runs are off on this server.'));
|
|
86
|
+
let rids;
|
|
87
|
+
if (what === 'test') {
|
|
88
|
+
rids = Array.isArray(body.rows) ? body.rows.filter((x) => typeof x === 'string').slice(0, 8) : [];
|
|
89
|
+
if (!rids.length) return send(bad(400, 'rows names the drafts to test-read.'));
|
|
90
|
+
} else rids = rec ? [rec.rid] : id ? [] : liveRecords(ctx, w).filter((r) => r.recipe && r.recipe.connector).map((r) => r.rid);
|
|
91
|
+
if (!rids.length) return send(bad(id ? 404 : 409, id ? 'There is no such goal.' : 'No goal has a way to be read yet.'));
|
|
92
|
+
const r = ctx.metricReadRuns.start({ ws: w.id, rids, why: what === 'test' ? 'test' : 'press' });
|
|
93
|
+
return send(r && r.ok ? { status: 200, body: { ok: true, run: r.run, rids: r.rids } } : bad(409, (r && r.error) || 'Claude could not start reading.'));
|
|
94
|
+
}
|
|
95
|
+
// csv: the fallback when no connector reads it
|
|
96
|
+
if (!rec) return send(bad(404, 'There is no such goal.'));
|
|
97
|
+
const p = MR.parseCsv(text(body.csv));
|
|
98
|
+
if (p.error) return send(bad(400, p.error));
|
|
99
|
+
const have = new Set((rec.readings || []).map((x) => String(x.at).slice(0, 10)));
|
|
100
|
+
const source = (text(body.source).replace(/\s+/g, ' ').trim() || 'CSV upload').slice(0, 120), readAt = new Date().toISOString();
|
|
101
|
+
let added = 0, skipped = 0;
|
|
102
|
+
for (const row of p.rows) {
|
|
103
|
+
if (have.has(row.at) || row.at > todayIso()) { skipped++; continue; }
|
|
104
|
+
const r = records().addReading(root, rec.rid, { at: row.at, value: row.value, source, via: 'csv', read_at: readAt }, UI(), 'Read from a file the PM gave');
|
|
105
|
+
if (r.ok) added++; else skipped++;
|
|
106
|
+
}
|
|
107
|
+
if (added) { try { afterRead(ctx, w, [rec.rid]); } catch { /* the readings stand */ } }
|
|
108
|
+
return send({ status: 200, body: { ok: true, added, skipped } });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = { prefixes: ['/api/goal-status', '/api/goals/notify'], handle, summaryFor, afterRead, PRODUCT_ROLES };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-impact-views.js — what Your impact's chapter card reads (feedback batch 16 item 7, Phase 4; canvas GmP4Chapter). Read-only.
|
|
3
|
+
*
|
|
4
|
+
* GET /api/impact-views/chapter?ws=<id> → { ok, week, chapters: [{ ws, board, id, closed, now, at, then: { at, line } }] }
|
|
5
|
+
*
|
|
6
|
+
* A chapter is a stage that really closed this week: a PM's own `move` line in boards.jsonl (scripts/boards.js fold `moves`, via 'move')
|
|
7
|
+
* from one stage to another, at or after this week's Monday. "Then" is the initiative's first line on the board: the triage ask it was
|
|
8
|
+
* accepted from (its words and day), else its first move. The newest close per initiative wins. Without ws, every workspace is read.
|
|
9
|
+
* Home draws the card on a Friday only, and only while Your impact is on (pm/impact.js chapterHtml). Titles come from Home's own rows.
|
|
10
|
+
* The ledger behind Your impact (lib/impact.js, GET /api/impact/*) is another thread's; this file reads only the boards ledger and writes
|
|
11
|
+
* nothing. No number value is in the body (the Your impact rule): dates are ISO strings. */
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const { repoScript } = require('./repo-script.js');
|
|
15
|
+
const B = require(repoScript('boards.js'));
|
|
16
|
+
|
|
17
|
+
const ONE = (s, n) => String(s || '').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
18
|
+
function lines(ctx, w) {
|
|
19
|
+
const d = ctx.stateDirFor ? ctx.stateDirFor(w) : null;
|
|
20
|
+
if (!d) return [];
|
|
21
|
+
try { return fs.readFileSync(path.join(d, 'boards.jsonl'), 'utf8').split('\n').filter(Boolean); } catch { return []; }
|
|
22
|
+
}
|
|
23
|
+
/** This week's Monday at 00:00, local time (Settings › Time › week start is the Board's; Your impact's weeks start on Monday). */
|
|
24
|
+
function monday(now) { const d = new Date(now); d.setHours(0, 0, 0, 0); d.setDate(d.getDate() - ((d.getDay() + 6) % 7)); return d; }
|
|
25
|
+
const isoDay = (d) => d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
|
|
26
|
+
|
|
27
|
+
/** The chapters of one folded ledger. Pure: f is scripts/boards.js fold(); since a Date. */
|
|
28
|
+
function chaptersOf(f, since, ws) {
|
|
29
|
+
const first = new Map(), out = new Map();
|
|
30
|
+
for (const m of f.moves || []) {
|
|
31
|
+
if (!m || !m.id) continue;
|
|
32
|
+
if (!first.has(m.id) && m.at) first.set(m.id, { at: m.at, line: '' });
|
|
33
|
+
const at = Date.parse(m.at || '');
|
|
34
|
+
if (m.via !== 'move' || !m.from || !m.to || m.from === m.to || !(at >= since.getTime())) continue;
|
|
35
|
+
out.set(m.id, { ws, board: m.board || '', id: m.id, closed: ONE(m.from, 60), now: ONE(m.to, 60), at: m.at });
|
|
36
|
+
}
|
|
37
|
+
for (const a of (f.asks && f.asks.values ? f.asks.values() : [])) {
|
|
38
|
+
if (a && a.state === 'accepted' && a.initiative && a.line) first.set(a.initiative, { at: a.at || (first.get(a.initiative) || {}).at || null, line: ONE(a.line, 200) });
|
|
39
|
+
}
|
|
40
|
+
return [...out.values()].map((c) => ({ ...c, then: first.get(c.id) || { at: null, line: '' } }));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
prefixes: ['/api/impact-views'],
|
|
45
|
+
chaptersOf,
|
|
46
|
+
handle: async (req, res, url, ctx) => {
|
|
47
|
+
if (url.pathname !== '/api/impact-views/chapter') return false;
|
|
48
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
49
|
+
const since = monday(Date.now()), wsId = url.searchParams.get('ws');
|
|
50
|
+
const list = ctx.workspaceList ? ctx.workspaceList() : [];
|
|
51
|
+
const ws = wsId ? [ctx.getWs ? ctx.getWs(wsId) : list.find((x) => x.id === wsId)].filter(Boolean) : list;
|
|
52
|
+
const chapters = [];
|
|
53
|
+
for (const w of ws) { let f; try { f = B.fold(lines(ctx, w)); } catch { continue; } chapters.push(...chaptersOf(f, since, w.id || '')); }
|
|
54
|
+
chapters.sort((a, b) => String(b.at).localeCompare(String(a.at)));
|
|
55
|
+
ctx.json(res, { ok: true, week: isoDay(since), chapters: chapters.slice(0, 10) });
|
|
56
|
+
return true;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-impact.js — "Your impact" over HTTP (feedback batch 16 item 7; contract next16/briefs/7-impact-api.md). The fold is lib/impact.js;
|
|
3
|
+
* the daily run is lib/impact-runs.js. The ledger is the person's own, in the runtime folder (<runtime>/impact/impact.jsonl): outside every
|
|
4
|
+
* repository, so nobody else reads it. Nothing here sends anything.
|
|
5
|
+
*
|
|
6
|
+
* GET /api/impact/week?week=YYYY-MM-DD → { ok, on, live, first, week, from, to, label, grow, celebrate, quiet, items } Home's Adler, the Viewer
|
|
7
|
+
* GET /api/impact/weeks → { ok, on, live, weeks: [{ week, from, to, label, quiet, items }] } the log, newest first
|
|
8
|
+
* GET /api/impact/check → { ok, on, due, week, label, items, gate } the weekly check in Home's chat
|
|
9
|
+
* POST /api/impact/verdict { id, real } → { ok } ✓ (true) or ✕ (false) one row
|
|
10
|
+
* POST /api/impact/verdict-all { week } → { ok } ✓✓ every row of that week not checked yet
|
|
11
|
+
* POST /api/impact/undo { id } → { ok } the row back to not checked
|
|
12
|
+
* POST /api/impact/seen { ids } → { ok } read on a Phase 2 surface; ends its one celebration
|
|
13
|
+
* `ws` is accepted on every route and ignored: the ledger is per person, across products.
|
|
14
|
+
*
|
|
15
|
+
* THE SWITCH. Settings › General › Your impact (impact.on, lib/settings-store.js). Off: every GET answers { ok, on: false } and nothing else,
|
|
16
|
+
* every POST answers 409, and the daily run does not start.
|
|
17
|
+
*
|
|
18
|
+
* NO NUMBERS. No body carries a number value (impact-ui-test and impact.test.js check it): growth and the gate are words.
|
|
19
|
+
*
|
|
20
|
+
* WHO WRITES. As routes-metric-drafts.js: a POST that carries an agent session header is refused (403), and pm-guard requirePagePress
|
|
21
|
+
* checks the launch nonce and the page's origin. After a verdict, a change of the gate is written to the ledger with its rate. */
|
|
22
|
+
const guard = require('./pm-guard.js');
|
|
23
|
+
const IM = require('./impact.js');
|
|
24
|
+
const store = require('./settings-store.js');
|
|
25
|
+
|
|
26
|
+
const text = (v) => (typeof v === 'string' ? v : '');
|
|
27
|
+
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
28
|
+
const nowMs = (ctx) => { const t = Date.parse((ctx.env || process.env).PMOS_IMPACT_NOW || ''); return Number.isFinite(t) ? t : Date.now(); };
|
|
29
|
+
const isOn = (ctx) => { try { return store.get(ctx.runtimeDir, 'impact.on') !== false; } catch { return true; } };
|
|
30
|
+
const startOf = (ctx) => { try { return store.get(ctx.runtimeDir, 'time.weekStart') === 'sun' ? 'sun' : 'mon'; } catch { return 'mon'; } };
|
|
31
|
+
const optsOf = (ctx, extra) => ({ today: IM.dayOf(nowMs(ctx)), start: startOf(ctx), ...extra });
|
|
32
|
+
|
|
33
|
+
/** The gate after a verdict: written once each time it changes (the brief's "record the rate"). Open stays open. */
|
|
34
|
+
function noteGate(ctx, dir) {
|
|
35
|
+
const F = IM.read(dir), o = optsOf(ctx);
|
|
36
|
+
const g = IM.gateOf(F, IM.weekOf(o.today, o.start), o.start);
|
|
37
|
+
const was = F.gate ? F.gate.state : 'measuring';
|
|
38
|
+
if (g.state !== was && was !== 'open') IM.append(dir, null, { kind: 'gate', state: g.state, real: g.real, judged: g.judged, weeks: g.weeks }, new Date(nowMs(ctx)).toISOString());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function handle(req, res, url, ctx) {
|
|
42
|
+
const send = (r) => { ctx.json(res, r.body, r.status); return true; };
|
|
43
|
+
const what = url.pathname.replace(/^\/api\/impact\/?/, '');
|
|
44
|
+
const dir = IM.dirOf(ctx.runtimeDir);
|
|
45
|
+
if (['week', 'weeks', 'check'].includes(what)) {
|
|
46
|
+
if (req.method !== 'GET') return send(bad(405, 'GET only'));
|
|
47
|
+
if (!isOn(ctx)) return send({ status: 200, body: { ok: true, on: false } });
|
|
48
|
+
const F = dir ? IM.read(dir) : IM.fold([]);
|
|
49
|
+
const body = what === 'week' ? IM.weekView(F, optsOf(ctx, { week: url.searchParams.get('week') || '' }))
|
|
50
|
+
: what === 'weeks' ? IM.weeksView(F, optsOf(ctx)) : IM.checkView(F, optsOf(ctx));
|
|
51
|
+
return send({ status: 200, body: { ok: true, on: true, ...body } });
|
|
52
|
+
}
|
|
53
|
+
if (!['verdict', 'verdict-all', 'undo', 'seen'].includes(what)) return send(bad(404, 'no such impact route'));
|
|
54
|
+
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
55
|
+
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'Only you check your impact, from the page. Claude\'s run files items with pmos impact.'));
|
|
56
|
+
const rd = await ctx.readJson(req);
|
|
57
|
+
if (!rd.ok) return send(bad(400, 'the body is not JSON'));
|
|
58
|
+
const body = rd.body || {};
|
|
59
|
+
const g = guard.requirePagePress(req, body);
|
|
60
|
+
if (!g.ok) return send(bad(g.status, g.error));
|
|
61
|
+
if (!isOn(ctx)) return send(bad(409, 'Your impact is off in Settings.'));
|
|
62
|
+
if (!dir) return send(bad(409, 'There is no runtime folder.'));
|
|
63
|
+
const F = IM.read(dir), at = new Date(nowMs(ctx)).toISOString(), by = { by: 'pm' };
|
|
64
|
+
|
|
65
|
+
if (what === 'seen') {
|
|
66
|
+
const ids = (Array.isArray(body.ids) ? body.ids : []).map(String).filter((id) => { const it = F.items.get(id); return it && it.real === true && !it.read; }).slice(0, 100);
|
|
67
|
+
if (ids.length) IM.append(dir, by, { kind: 'seen', ids }, at);
|
|
68
|
+
return send({ status: 200, body: { ok: true } });
|
|
69
|
+
}
|
|
70
|
+
if (what === 'verdict-all') {
|
|
71
|
+
const week = text(body.week), o = optsOf(ctx);
|
|
72
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(week)) return send(bad(400, 'week is the first day of the week, YYYY-MM-DD'));
|
|
73
|
+
const open = [...F.items.values()].filter((it) => it.real === null && IM.weekOf(IM.dayOf(Date.parse(it.at)), o.start) === week);
|
|
74
|
+
for (const it of open) IM.append(dir, by, { kind: 'verdict', id: it.id, real: true }, at);
|
|
75
|
+
noteGate(ctx, dir);
|
|
76
|
+
return send({ status: 200, body: { ok: true } });
|
|
77
|
+
}
|
|
78
|
+
const id = text(body.id), it = F.items.get(id);
|
|
79
|
+
if (!it) return send(bad(404, 'There is no such item.'));
|
|
80
|
+
if (what === 'verdict') {
|
|
81
|
+
if (typeof body.real !== 'boolean') return send(bad(400, 'real is true (✓ real) or false (✕ not real)'));
|
|
82
|
+
IM.append(dir, by, { kind: 'verdict', id, real: body.real }, at);
|
|
83
|
+
} else {
|
|
84
|
+
if (it.real === null) return send(bad(409, 'This item is not checked yet.'));
|
|
85
|
+
IM.append(dir, by, { kind: 'undo', id }, at);
|
|
86
|
+
}
|
|
87
|
+
noteGate(ctx, dir);
|
|
88
|
+
return send({ status: 200, body: { ok: true } });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { prefixes: ['/api/impact'], handle };
|
|
@@ -41,6 +41,8 @@ function leadsOf(ctx, ws, list) {
|
|
|
41
41
|
}
|
|
42
42
|
return out;
|
|
43
43
|
}
|
|
44
|
+
/** The product's open drafts: the ✦ line's ✓✓ count (lib/metric-drafts.js). */
|
|
45
|
+
const openDrafts = (dir, ws) => { const MD = require('./metric-drafts.js'), S = MD.read(dir).scopes.get(MD.keyOf('product', ws)); return S ? [...S.rows.values()].filter((r) => r.state === 'open').length : 0; };
|
|
44
46
|
const qs = (o) => '?' + Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
45
47
|
|
|
46
48
|
module.exports = {
|
|
@@ -92,7 +94,18 @@ module.exports = {
|
|
|
92
94
|
// premium-uncovered-features (IsMenus): the product picker says how many goals each product's workspace records; a workspace that cannot be read says none
|
|
93
95
|
const counts = new Map();
|
|
94
96
|
const goalsIn = (w) => { if (!counts.has(w)) { let n = null; try { n = w === ws ? outcomes.length : require(repoScript('records/index.js')).list(recordsDirFor(ctx, w), 'kr-metrics').length; } catch { n = null; } counts.set(w, n); } return counts.get(w) === null ? {} : { goals: counts.get(w) }; };
|
|
97
|
+
// batch 16 item 6 ("Claude runs the OKRs"): the reading ledger, each record's own history, and the product's open drafts
|
|
98
|
+
let watch = null, wdir = null;
|
|
99
|
+
if (pick) {
|
|
100
|
+
try {
|
|
101
|
+
wdir = ctx.stateDirFor ? ctx.stateDirFor(ctx.getWs(pick.ws)) : null;
|
|
102
|
+
const R = require(repoScript('records/index.js')), lines = R.readLines(R.fileOf(recordsDirFor(ctx, ws), 'kr-metrics')), GW = require('./goal-watch.js');
|
|
103
|
+
const history = Object.fromEntries(Object.keys(goalMeta).map((rid) => [rid, GW.historyOf(lines, rid)]));
|
|
104
|
+
watch = { reads: wdir ? require('./metric-reads.js').read(wdir) : null, history, drafts: wdir ? openDrafts(wdir, pick.ws) : 0 };
|
|
105
|
+
} catch { watch = null; }
|
|
106
|
+
}
|
|
95
107
|
const model = Insights.build({
|
|
108
|
+
watch,
|
|
96
109
|
now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Intelligence' }, boards: all.map((x) => Object.assign({ ws: x.ws, id: x.id, name: x.name }, goalsIn(x.ws))),
|
|
97
110
|
outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
|
|
98
111
|
setups: setupsOk ? su.body : null, pinned, leads, archived, initiatives, goalMeta, ins, budgets,
|
|
@@ -105,6 +118,13 @@ module.exports = {
|
|
|
105
118
|
require('./insight-moves.js').draftAll(model, { initiatives: initiatives || [], today: model.today, anchorOk: (t) => A.resolve(t).status === 'resolved', ledger: dir ? require('./insight-moves.js').read(dir) : new Map() });
|
|
106
119
|
} catch { /* no move is drafted: the strip says the finding without a ✓ */ }
|
|
107
120
|
}
|
|
121
|
+
// batch 16 item 6: the owner, chase and rollback-ticket fixes the goals call for now, filed standing (drafts only: nothing is sent)
|
|
122
|
+
if (wdir && pick) {
|
|
123
|
+
try {
|
|
124
|
+
const r = require('./goal-watch.js').syncFixes({ dir: wdir, ws: pick.ws, goals: model.goals, at: new Date().toISOString() });
|
|
125
|
+
if (r.filed || r.cleared) model.okr = Insights.okrOf(model, openDrafts(wdir, pick.ws));
|
|
126
|
+
} catch { /* the goals stand without the fixes */ }
|
|
127
|
+
}
|
|
108
128
|
ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
|
|
109
129
|
return true;
|
|
110
130
|
} catch (e) { return fail((e && e.message) || e); }
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* GET /api/metric-drafts?ws=&scope=&id= → { ok, scope, id, title, when, run: { state: idle|running|ready|failed|off, step, reads },
|
|
7
7
|
* rows, head, sub, src } rows [] and run.state idle when nothing is drafted
|
|
8
8
|
* POST /api/metric-drafts/keep { ws, scope, id, row } → { ok, rid } ✓ one row: the record and, when now is known, one reading
|
|
9
|
+
* a fix row (batch 16 item 6): outcome, next-quarter add a record (the test read is its first reading); recipe,
|
|
10
|
+
* carry, owner edit the goal's record; chase, ticket → { ok, outbox } (nothing is sent until the PM's Send in the
|
|
11
|
+
* outbox); connect → { ok, open: 'settings:connectors', connector }
|
|
9
12
|
* POST /api/metric-drafts/keep-all { ws, scope, id } → { ok, kept: n, failed } ✓ every open row
|
|
10
13
|
* POST /api/metric-drafts/drop { ws, scope, id, row } → { ok } ✕
|
|
11
14
|
* POST /api/metric-drafts/edit { ws, scope, id, row, name?, target?, source? } → { ok, row } the inline edit of an open row (batch 16 item 1)
|
|
@@ -99,7 +102,46 @@ async function handle(req, res, url, ctx) {
|
|
|
99
102
|
}
|
|
100
103
|
const s = S();
|
|
101
104
|
const root = recordsDirFor(ctx, w.id), today = todayIso();
|
|
105
|
+
// batch 16 item 6: a fix row's ✓ (lib/metric-drafts.js FIXES). → { rid?, outbox?, open?, connector? } | { error }
|
|
106
|
+
const editRec = (rid, fields, why) => { let e; try { e = records().edit(root, 'kr-metrics', rid, fields, UI(), why); } catch (x) { e = { ok: false, reasons: [String((x && x.message) || x).slice(0, 160)] }; } return e.ok ? null : 'The goal could not be changed: ' + (e.reasons || []).join('; '); };
|
|
107
|
+
const toOutbox = (channel, recipient, subject, body) => {
|
|
108
|
+
if (!ctx.runtimeDir) return { error: 'This workspace has no outbox, so it could not be drafted.' };
|
|
109
|
+
try {
|
|
110
|
+
const e = require(repoScript('outbox.js')).draftOutbox({ channel, recipient, subject, body, origin: 'pm' });
|
|
111
|
+
const entry = { id: 'out-' + require('crypto').randomBytes(6).toString('hex'), ...e };
|
|
112
|
+
require('./outbox-store.js').appendEvent(ctx.runtimeDir, { event: 'queued', ...entry }, new Date());
|
|
113
|
+
return { id: entry.id };
|
|
114
|
+
} catch (x) { return { error: 'It could not go to the outbox: ' + String((x && x.message) || x).slice(0, 160) }; }
|
|
115
|
+
};
|
|
116
|
+
const keepFix = (row) => {
|
|
117
|
+
const k = row.kind, done = (extra) => { MD.append(dir, g.actor, { kind: 'keep', scope, id, row: row.id, rid: extra.rid || null, ...(extra.before ? { before: extra.before } : {}), ...(extra.outbox ? { outbox: extra.outbox } : {}) }, at()); const { before, ...out } = extra; return out; };
|
|
118
|
+
const cur = (rid) => (records().list(root, 'kr-metrics').find((r) => r.rid === rid) || null);
|
|
119
|
+
const beforeOf = (rid, keys) => { const c = cur(rid) || {}; return Object.fromEntries(keys.map((x) => [x, c[x] === undefined ? null : c[x]])); };
|
|
120
|
+
if (k === 'outcome' || k === 'next-quarter') {
|
|
121
|
+
const kf = MD.keepFields(scope, id, row.metric, { today });
|
|
122
|
+
if (kf.error) return { error: kf.error };
|
|
123
|
+
if (k === 'outcome') Object.assign(kf.fields, { kr: row.goal, was: row.old || '' });
|
|
124
|
+
if (row.recipe) kf.fields.recipe = row.recipe;
|
|
125
|
+
kf.fields.draft = row.id;
|
|
126
|
+
let r; try { r = records().add(root, 'kr-metrics', kf.fields, UI(), k === 'outcome' ? 'Kept the outcome Claude drafted for a project-shaped goal' : 'Kept next quarter\'s goal Claude drafted'); } catch (e) { return { error: 'The record could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
127
|
+
if (!r.ok) return { error: r.reasons.join('; ') };
|
|
128
|
+
// the test read (lib/metric-reads.js), else the reading it was drafted from, is the first reading, with its source
|
|
129
|
+
let test = null; try { const x = require('./metric-reads.js').read(dir).rids.get(row.id); test = x && x.test && x.test.ok ? x.test : null; } catch { test = null; }
|
|
130
|
+
const first = test ? { at: test.day, value: test.value, source: test.source, via: 'run', read_at: test.at } : kf.reading;
|
|
131
|
+
if (first) { try { records().addReading(root, r.rid, first, UI(), test ? 'The test read before you kept it' : 'The reading Claude drafted it from'); } catch { /* the record stands */ } }
|
|
132
|
+
return done({ rid: r.rid });
|
|
133
|
+
}
|
|
134
|
+
if (k === 'connect') return done({ open: 'settings:connectors', connector: row.connector });
|
|
135
|
+
const editKeep = (fields, why) => { if (!cur(row.goal)) return { error: 'The goal this fix repairs is not recorded any more.' }; const before = beforeOf(row.goal, Object.keys(fields)); const e = editRec(row.goal, fields, why); return e ? { error: e } : done({ rid: row.goal, before }); };
|
|
136
|
+
if (k === 'recipe') return editKeep({ recipe: row.recipe }, 'Kept how Claude reads this goal');
|
|
137
|
+
if (k === 'carry') return editKeep({ by: row.by, ...(typeof row.target === 'number' ? { target: row.target } : {}) }, 'Carried on to next quarter');
|
|
138
|
+
if (k === 'owner') return editKeep({ owner: row.owner.name, owner_from: row.owner.from }, 'Kept the owner Claude proposed');
|
|
139
|
+
if (k === 'chase') { const o = row.channel === 'jira-write' ? toOutbox('jira-write', row.epic, 'About ' + row.goal, row.body) : toOutbox('team-note', row.to, 'A note on ' + row.goal, row.body); return o.error ? o : done({ rid: row.goal, outbox: o.id }); }
|
|
140
|
+
if (k === 'ticket') { const o = toOutbox('jira-write', (row.ticket && row.ticket.project) || null, row.ticket.title, row.ticket.text); return o.error ? o : done({ rid: row.goal, outbox: o.id }); }
|
|
141
|
+
return { error: 'This draft cannot be kept.' };
|
|
142
|
+
};
|
|
102
143
|
const keepOne = (row) => {
|
|
144
|
+
if (row.kind && row.kind !== 'metric') return keepFix(row);
|
|
103
145
|
const k = MD.keepFields(scope, id, row, { today });
|
|
104
146
|
if (k.error) return { error: k.error };
|
|
105
147
|
let r;
|
|
@@ -113,7 +155,7 @@ async function handle(req, res, url, ctx) {
|
|
|
113
155
|
const open = s ? [...s.rows.values()].filter((r) => r.state === 'open') : [];
|
|
114
156
|
if (!open.length) return send(bad(409, 'There is nothing open to keep.'));
|
|
115
157
|
let kept = 0; const failed = [];
|
|
116
|
-
for (const row of open) { const r = keepOne(row); if (r.
|
|
158
|
+
for (const row of open) { const r = keepOne(row); if (!r.error) kept++; else failed.push({ row: row.id, error: r.error }); }
|
|
117
159
|
return send(kept ? { status: 200, body: { ok: true, kept, failed } } : bad(400, failed[0].error));
|
|
118
160
|
}
|
|
119
161
|
const row = s && s.rows.get(text(body.row));
|
|
@@ -121,11 +163,13 @@ async function handle(req, res, url, ctx) {
|
|
|
121
163
|
if (what === 'keep') {
|
|
122
164
|
if (row.state !== 'open') return send(bad(409, row.state === 'kept' ? 'You kept it already.' : 'You dropped it. Undo first.'));
|
|
123
165
|
const r = keepOne(row);
|
|
124
|
-
|
|
166
|
+
if (r.error) return send(bad(400, r.error));
|
|
167
|
+
const out = { ok: true, rid: r.rid || null }; for (const k of ['outbox', 'open', 'connector']) if (r[k]) out[k] = r[k];
|
|
168
|
+
return send({ status: 200, body: out });
|
|
125
169
|
}
|
|
126
170
|
if (what === 'edit') {
|
|
127
171
|
if (row.state !== 'open') return send(bad(409, row.state === 'kept' ? 'You kept it. Undo it first, then edit.' : 'You dropped it. Undo first.'));
|
|
128
|
-
const pick = {}; for (const k of ['name', 'target', 'source']) if (body[k] !== undefined) pick[k] = body[k];
|
|
172
|
+
const pick = {}; for (const k of ['name', 'target', 'source', 'text', 'body']) if (body[k] !== undefined) pick[k] = body[k];
|
|
129
173
|
const e = MD.editOf(row, pick);
|
|
130
174
|
if (e.error) return send(bad(400, e.error));
|
|
131
175
|
if (Object.keys(e.set).length) MD.append(dir, g.actor, { kind: 'edit', scope, id, row: row.id, set: e.set }, at());
|
|
@@ -138,7 +182,14 @@ async function handle(req, res, url, ctx) {
|
|
|
138
182
|
}
|
|
139
183
|
// undo: a kept row's record is retired (readers skip it), a dropped row comes back
|
|
140
184
|
if (row.state === 'open') return send(bad(409, 'There is nothing to undo.'));
|
|
141
|
-
if (row.state === 'kept' && row.rid) {
|
|
185
|
+
if (row.state === 'kept' && row.before && row.rid) { // a fix that edited a goal: its fields go back
|
|
186
|
+
const back = {}; for (const [k, v] of Object.entries(row.before)) back[k] = v;
|
|
187
|
+
const e = editRec(row.rid, back, 'Undo of a kept fix');
|
|
188
|
+
if (e) return send(bad(400, e));
|
|
189
|
+
} else if (row.state === 'kept' && row.outbox) { // a chase or a ticket: out of the outbox, unless it was sent
|
|
190
|
+
const r = require('./routes-outbox.js').discard(req, { id: row.outbox }, ctx.runtimeDir);
|
|
191
|
+
if (r.status !== 200) return send(bad(r.status === 409 ? 409 : 400, (r.body && r.body.error) === 'a sent entry is a record and is not discarded' ? 'It was sent already, so it cannot be taken back.' : 'It could not be taken out of the outbox.'));
|
|
192
|
+
} else if (row.state === 'kept' && row.rid && (!row.kind || row.kind === 'metric' || row.kind === 'outcome' || row.kind === 'next-quarter')) {
|
|
142
193
|
let e;
|
|
143
194
|
try { e = records().edit(root, 'kr-metrics', row.rid, { retired: true }, UI(), 'Undo of a kept draft'); } catch (x) { e = { ok: false, reasons: [String((x && x.message) || x).slice(0, 160)] }; }
|
|
144
195
|
if (!e.ok && !(e.reasons || []).some((m) => /no such record/.test(m))) return send(bad(400, 'The record could not be retired: ' + (e.reasons || []).join('; ')));
|
|
@@ -58,6 +58,8 @@ module.exports = {
|
|
|
58
58
|
const r = verb === 'add' ? addRecord(writeRootOf(ctx, body), kind, body)
|
|
59
59
|
: verb === 'edit' ? editRecord(writeRootOf(ctx, body), kind, body)
|
|
60
60
|
: kind === 'kr-metrics' ? readingRecord(writeRootOf(ctx, body), body) : bad(404, 'readings belong to kr-metrics');
|
|
61
|
+
// batch 16 item 6: a typed reading is a reading too: the limit alert and the standing read fixes follow it (lib/goal-watch.js)
|
|
62
|
+
if (verb === 'reading' && r.status === 200 && body.rid) { try { const w = ctx.getWs(body.ws || null); if (w) require('./routes-goal-status.js').afterRead(ctx, w, [String(body.rid)]); } catch { /* the reading stands */ } }
|
|
61
63
|
ctx.json(res, r.body, r.status);
|
|
62
64
|
return true;
|
|
63
65
|
},
|
|
@@ -76,6 +76,9 @@ const DEFS = Object.freeze({
|
|
|
76
76
|
'adler.motion': one('adler', 'computer', ['system', 'still'], 'system'),
|
|
77
77
|
'adler.celebrate': one('adler', 'computer', ['real', 'never'], 'real'),
|
|
78
78
|
'adler.quiet': one('adler', 'computer', ['22', 'never'], '22'),
|
|
79
|
+
// Settings > General > Your impact (feedback batch 16 item 7, canvas GmP1Switch): the one switch. Off hides every impact surface, Adler's
|
|
80
|
+
// leaf included, and stops the daily impact run (lib/routes-impact.js, lib/impact-runs.js).
|
|
81
|
+
'impact.on': bool('general', 'computer', true),
|
|
79
82
|
});
|
|
80
83
|
|
|
81
84
|
/* The environment variables that win over a setting, here or in a setting's own store. `key` names the setting the page
|