create-pmos 0.442.0 → 0.444.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-board-test.js +8 -2
- package/workspace/briefing-premium-insights-test.js +40 -38
- package/workspace/briefing-premium-test.js +2 -1
- package/workspace/changelog.json +24 -0
- package/workspace/goals-clear-ui-test.js +263 -0
- package/workspace/guide/home.md +12 -2
- package/workspace/guide/metric-drafts.md +8 -2
- package/workspace/home-railcard-test.js +193 -0
- package/workspace/intel-report-ui-test.js +1 -1
- package/workspace/intelligence-gaps-ui-test.js +16 -14
- package/workspace/lib/board-premium.js +1 -1
- package/workspace/lib/engine/boards.js +9 -2
- package/workspace/lib/engine/records/index.js +9 -2
- package/workspace/lib/initiative-layout.js +3 -1
- package/workspace/lib/insights-premium.js +22 -1
- package/workspace/lib/metric-drafts.js +37 -10
- package/workspace/lib/metric-read-runs.js +20 -13
- package/workspace/lib/metric-reads.js +208 -23
- package/workspace/lib/metrics-cli.js +62 -5
- package/workspace/lib/routes-boards.js +40 -1
- package/workspace/lib/routes-goal-status.js +89 -6
- package/workspace/lib/routes-insights-premium.js +1 -1
- package/workspace/lib/routes-metric-drafts.js +26 -3
- package/workspace/live-pill-round-test.js +178 -0
- package/workspace/metric-drafts-ui-test.js +5 -2
- package/workspace/okr-goals-ui-test.js +27 -23
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/panels-test.js +231 -0
- package/workspace/premium-board-actions-test.js +2 -2
- package/workspace/premium-rec-tab-test.js +2 -1
- package/workspace/premium-vw-item-test.js +10 -2
- package/workspace/premium-vw-jira-test.js +3 -0
- package/workspace/public/pm/bd-ini-panel.js +3 -2
- package/workspace/public/pm/cozy-adler.js +21 -0
- package/workspace/public/pm/cozy-divider.css +32 -0
- package/workspace/public/pm/cozy-divider.js +45 -0
- package/workspace/public/pm/cozy-insights.css +96 -0
- package/workspace/public/pm/cozy-live-pill.css +16 -17
- package/workspace/public/pm/cozy-live-pill.js +28 -17
- package/workspace/public/pm/cozy-panels.css +59 -0
- package/workspace/public/pm/cozy-panels.js +524 -0
- package/workspace/public/pm/cozy-today.css +15 -0
- package/workspace/public/pm/cozy-viewer.js +173 -69
- package/workspace/public/pm/cozy-vw-shell.css +4 -0
- package/workspace/public/pm/goals-clear.js +265 -0
- package/workspace/public/pm/home-app.js +73 -14
- package/workspace/public/pm/home-ini.js +9 -3
- package/workspace/public/pm/home-today.js +55 -12
- package/workspace/public/pm/ini-edit.js +401 -0
- package/workspace/public/pm/ini-groups.js +14 -8
- package/workspace/public/pm/ini-tasks.js +84 -26
- package/workspace/public/pm/ini-versions.js +18 -4
- package/workspace/public/pm/ini-view-model.js +45 -18
- package/workspace/public/pm/ini-view.css +117 -5
- package/workspace/public/pm/ini-view.js +51 -17
- package/workspace/public/pm/metric-drafts.js +4 -1
- package/workspace/public/pm/mission.js +11 -7
- package/workspace/public/pm/premium-board.js +8 -6
- package/workspace/public/pm/premium-insights.js +375 -59
- package/workspace/public/pm/task-card.css +2 -0
- package/workspace/public/pm/task-card.js +4 -1
- package/workspace/server.js +6 -2
- package/workspace/skills/metric-read.skill +7 -5
- package/workspace/stage-card-tasks-test.js +396 -0
- package/workspace/stage-card-test.js +12 -4
- package/workspace/task-delete-test.js +9 -1
- package/workspace/task-milestones-test.js +3 -3
- package/workspace/task-press-test.js +12 -4
- package/workspace/task-views-test.js +198 -5
- package/workspace/test-lists/batch18-live-pill-round.json +10 -0
- package/workspace/test-lists/batch18-panels.json +9 -0
- package/workspace/test-lists/goals-clear.json +15 -0
- package/workspace/test-lists/home-railcard.json +9 -0
- package/workspace/test-lists/stage-card-tasks.json +6 -0
- package/workspace/tk-tasks-test.js +2 -2
|
@@ -3,14 +3,24 @@
|
|
|
3
3
|
* ONE FOLD of <state>/metric-reads.jsonl. lib/metric-read-runs.js starts the runs; `pmos metrics reading` (lib/metrics-cli.js) is what a run
|
|
4
4
|
* files with; lib/routes-goal-status.js reads it. Pure apart from the ledger file, with no clock of its own: every time comes in.
|
|
5
5
|
*
|
|
6
|
-
* A RECIPE is on the kr-metrics record: recipe = { connector, query, cadence: daily | weekly | monthly
|
|
6
|
+
* A RECIPE is on the kr-metrics record: recipe = { connector, query, cadence: hourly | daily | weekly | monthly, at?, day?, counts?, range? }
|
|
7
|
+
* (lib/metric-drafts.js recipeOf). A reading run reads each due recipe through
|
|
7
8
|
* the PM's own Claude Code connectors and files the value with its source and time (the reading lands on the record, scripts/records addReading,
|
|
8
9
|
* with source, via run and read_at). A source it cannot read is said honestly (a `cant` line) and comes with a drafted fix (a standing connect or
|
|
9
10
|
* recipe row in lib/metric-drafts.js). A CSV or sheet export is the fallback when no connector reads it (parseCsv).
|
|
10
11
|
*
|
|
11
12
|
* THE LEDGER. One line per event, { at, by, kind, ... }:
|
|
12
|
-
* start { run, ws, rids, why } a run began; why ∈ due · test · press. A test run reads a drafted row (rid = its row id) before the
|
|
13
|
-
*
|
|
13
|
+
* start { run, ws, rids, why } a run began; why ∈ due · test · press · compare. A test run reads a drafted row (rid = its row id) before the
|
|
14
|
+
* PM keeps it. A press (Read now) or compare run never moves the next scheduled read
|
|
15
|
+
* read { run, rid, value, day, source, num?, den?, segments?, period?, checks?, test? } one value read (a test read lands here only, never on a
|
|
16
|
+
* record). num and den are the two counts ("How it is counted"); segments [{ name, num, den }] its parts
|
|
17
|
+
* held { run, rid, value, day, source, num?, den?, segments?, period?, checks, why, ticket?, test? } batch 18 item 11: a value a check failed
|
|
18
|
+
* on. It is NOT on the record, so it never moves the dot, the line or "target reached"; ticket is the drafted
|
|
19
|
+
* Jira fix row
|
|
20
|
+
* filed { rid, held } the PM's "file it": the held reading (held = its at) went on the record after all
|
|
21
|
+
* compare { rid, value, period, ours, pct } the PM's own number for the goal (or a draft row), against Claude's
|
|
22
|
+
* reason { run?, rid, why, suggest?: { text, keep: mine | yours }, yours?: { what, query } } why the two differ (a segment, or a compare run)
|
|
23
|
+
* pick { rid, pick: mine | yours, before? } the PM's pick; yours rewrote counts.what and the query (before holds what they were)
|
|
14
24
|
* cant { run, rid, why, fix? } the run could not read it; fix is the drafted row's id
|
|
15
25
|
* end { run, ok, error? }
|
|
16
26
|
* broke { rid, day, value, limit } a limit goal went over its limit: ONE push (the episode is open)
|
|
@@ -18,21 +28,38 @@
|
|
|
18
28
|
*
|
|
19
29
|
* ledgerFile(dir) · readLines(file) · read(dir) · append(dir, actor, line, at)
|
|
20
30
|
* fold(lines) PURE → { rids: Map rid → R, runs: Map run → { run, ws, rids, why, at, ended, ok, error } }
|
|
21
|
-
* R: { last: { at, ok, error?, value?, source? } | null, tried: day of the last try,
|
|
22
|
-
*
|
|
31
|
+
* R: { last: { at, ok, error?, value?, source? } | null, tried: day of the last try, triedAt: time of the last scheduled try,
|
|
32
|
+
* good: the last good read | null, failed: { at, why, fix } | null, checks, held: [open held], test: { at, ok, value?, …,
|
|
33
|
+
* checks?, held? } | null, compare: { … } | null, alert: { open, day, value, limit } | null, alerts: [{ kind, day, value }] }
|
|
23
34
|
* lastOf(F, rid) → R.last, the recipe's `last` on the page
|
|
24
|
-
* dueOf(records, F,
|
|
35
|
+
* dueOf(records, F, now, o) PURE → [rid] live records with a recipe whose next scheduled read has come, none of them in a running run. now is a
|
|
36
|
+
* day (YYYY-MM-DD, its local midnight) or a time (ms). o: { only: 'hourly' | 'other', hours: { start, end } }
|
|
37
|
+
* nextAfter(recipe, after, hours) PURE → ms the first scheduled read after `after` (ms). Hourly is on the hour, inside the working hours
|
|
38
|
+
* nextReadOf(rec, F, now, hours) PURE → ISO | null when the goal is read next (never earlier than now)
|
|
39
|
+
* rhythmOf(recipe) PURE → { cadence, at, day, txt, short } | null "every Monday 07:00" / "Every Monday"
|
|
40
|
+
* checksOf(o) PURE → [{ id: zero | jump | den | range, ok, text }] Claude's checks on one value before it is drawn.
|
|
41
|
+
* o: { value, num?, den?, segments?, prior: [value], unit, type, range }
|
|
42
|
+
* compareView(F, rid, unit) PURE → the compare a page draws: { value, txt, period, ours, oursTxt, apart, pct, differs, state, why?, suggest?, yours?, pick? }
|
|
43
|
+
* heldWhy(checks) · compareOf(ours, yours) · segmentReason(last) · fmt(v, unit)
|
|
25
44
|
* alertStep(F, rid, reading) PURE → { kind: 'broke' | 'back', … } | null what to append after a reading (lib/goal-status.js readingOf)
|
|
26
45
|
* parseCsv(text) → { rows: [{ at, value }] } | { error } two columns: a date and a number; a header line is skipped
|
|
27
|
-
* CADENCE_GAP days between two tries of a cadence (daily 1, weekly 7, monthly 30)
|
|
46
|
+
* CADENCE_GAP days between two tries of a cadence (hourly 1/24, daily 1, weekly 7, monthly 30)
|
|
47
|
+
* WORK_HOURS the working hours an hourly goal is read in, when the server gives none (the day-check window's default)
|
|
48
|
+
* MIN_DEN · DIFF_PCT the smallest count below a rate that is trusted (30); the share two numbers may differ by and be the same (2%)
|
|
28
49
|
*/
|
|
29
50
|
const fs = require('fs');
|
|
30
51
|
const path = require('path');
|
|
31
52
|
|
|
32
53
|
const LEDGER = 'metric-reads.jsonl';
|
|
33
|
-
const KINDS = new Set(['start', 'read', 'cant', 'end', 'broke', 'back']);
|
|
34
|
-
const WHYS = ['due', 'test', 'press'];
|
|
35
|
-
const
|
|
54
|
+
const KINDS = new Set(['start', 'read', 'cant', 'end', 'broke', 'back', 'held', 'filed', 'compare', 'reason', 'pick']);
|
|
55
|
+
const WHYS = ['due', 'test', 'press', 'compare'];
|
|
56
|
+
const OFF_RHYTHM = new Set(['press', 'compare']); // a run the PM asked for: it never moves the next scheduled read
|
|
57
|
+
const CADENCE_GAP = Object.freeze({ hourly: 1 / 24, daily: 1, weekly: 7, monthly: 30 });
|
|
58
|
+
const WORK_HOURS = Object.freeze({ start: '09:00', end: '18:00' }); // lib/proactive.js DAY_CHECK_DEFAULT
|
|
59
|
+
const MIN_DEN = 30;
|
|
60
|
+
const DIFF_PCT = 2;
|
|
61
|
+
const JUMP = 3;
|
|
62
|
+
const HOUR = 36e5;
|
|
36
63
|
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
37
64
|
const DAY = 864e5;
|
|
38
65
|
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
@@ -57,9 +84,20 @@ function append(dir, actor, ev, at) {
|
|
|
57
84
|
return line;
|
|
58
85
|
}
|
|
59
86
|
|
|
87
|
+
const segsOf = (v) => (Array.isArray(v) ? v.filter((x) => isObj(x) && str(x.name) && fin(x.num) && fin(x.den)).slice(0, 8).map((x) => ({ name: one(x.name, 40), num: x.num, den: x.den })) : []);
|
|
88
|
+
const checksIn = (v) => (Array.isArray(v) ? v.filter((c) => isObj(c) && str(c.id)).map((c) => ({ id: c.id, ok: !!c.ok, text: one(c.text, 200) })) : null);
|
|
89
|
+
/** What one read or held line says about the value: its counts, parts, period and checks. */
|
|
90
|
+
function valueOf(l, at) {
|
|
91
|
+
const v = { at, ok: true, value: l.value, day: DAY_RE.test(str(l.day)) ? l.day : at.slice(0, 10), source: one(l.source, 200) };
|
|
92
|
+
if (fin(l.num)) v.num = l.num; if (fin(l.den)) v.den = l.den;
|
|
93
|
+
const sg = segsOf(l.segments); if (sg.length) v.segments = sg;
|
|
94
|
+
if (str(l.period)) v.period = one(l.period, 40);
|
|
95
|
+
const ch = checksIn(l.checks); if (ch) v.checks = ch;
|
|
96
|
+
return v;
|
|
97
|
+
}
|
|
60
98
|
function fold(lines) {
|
|
61
99
|
const rids = new Map(), runs = new Map();
|
|
62
|
-
const R = (rid) => { if (!rids.has(rid)) rids.set(rid, { last: null, tried: null, test: null, alert: null, alerts: [] }); return rids.get(rid); };
|
|
100
|
+
const R = (rid) => { if (!rids.has(rid)) rids.set(rid, { last: null, tried: null, triedAt: null, good: null, failed: null, checks: null, held: [], test: null, compare: null, alert: null, alerts: [] }); return rids.get(rid); };
|
|
63
101
|
for (const l of lines || []) {
|
|
64
102
|
if (!isObj(l) || !KINDS.has(l.kind)) continue;
|
|
65
103
|
const at = str(l.at);
|
|
@@ -67,13 +105,28 @@ function fold(lines) {
|
|
|
67
105
|
if (l.kind === 'end' && str(l.run)) { const r = runs.get(l.run); if (r && !r.ended) Object.assign(r, { ended: true, ok: !!l.ok, error: one(l.error, 200), endAt: at }); continue; }
|
|
68
106
|
if (!str(l.rid)) continue;
|
|
69
107
|
const x = R(l.rid), run = runs.get(str(l.run));
|
|
108
|
+
const test = !!l.test || !!(run && run.why === 'test');
|
|
109
|
+
const tried = () => { x.tried = at.slice(0, 10); if (!(run && OFF_RHYTHM.has(run.why))) x.triedAt = at; };
|
|
70
110
|
if (l.kind === 'read' && fin(l.value)) {
|
|
71
|
-
const v =
|
|
72
|
-
if (
|
|
111
|
+
const v = valueOf(l, at);
|
|
112
|
+
if (test) x.test = v; else { x.last = v; x.good = v; x.failed = null; x.checks = v.checks || null; tried(); }
|
|
113
|
+
} else if (l.kind === 'held' && fin(l.value)) {
|
|
114
|
+
const v = { ...valueOf(l, at), why: one(l.why, 300), ...(str(l.ticket) ? { ticket: l.ticket } : {}) };
|
|
115
|
+
if (test) x.test = { ...v, held: true }; else { x.held = x.held.filter((h) => h.at !== at); x.held.push(v); x.failed = null; x.checks = v.checks || null; tried(); }
|
|
116
|
+
} else if (l.kind === 'filed' && str(l.held)) {
|
|
117
|
+
const h = x.held.find((y) => y.at === l.held);
|
|
118
|
+
if (h) { x.held = x.held.filter((y) => y !== h); const v = { ...h, filedAt: at }; delete v.why; delete v.ticket; if (!x.good || String(v.day) >= String(x.good.day)) { x.good = v; x.last = v; } }
|
|
73
119
|
} else if (l.kind === 'cant') {
|
|
74
120
|
const v = { at, ok: false, error: one(l.why, 200), ...(str(l.fix) ? { fix: l.fix } : {}) };
|
|
75
|
-
if (
|
|
76
|
-
} else if (l.kind === '
|
|
121
|
+
if (test) x.test = v; else { x.last = v; x.failed = { at, why: v.error, ...(v.fix ? { fix: v.fix } : {}) }; tried(); }
|
|
122
|
+
} else if (l.kind === 'compare' && fin(l.value) && fin(l.ours)) {
|
|
123
|
+
x.compare = { at, value: l.value, period: one(l.period, 40), ours: l.ours, pct: fin(l.pct) ? l.pct : null, why: '', suggest: null, yours: null, pick: null };
|
|
124
|
+
} else if (l.kind === 'reason' && x.compare) {
|
|
125
|
+
if (str(l.why)) x.compare.why = one(l.why, 400);
|
|
126
|
+
if (isObj(l.suggest) && str(l.suggest.text)) x.compare.suggest = { text: one(l.suggest.text, 300), keep: l.suggest.keep === 'yours' ? 'yours' : 'mine' };
|
|
127
|
+
if (isObj(l.yours) && str(l.yours.what) && str(l.yours.query)) x.compare.yours = { what: one(l.yours.what, 300), query: String(l.yours.query).slice(0, 1200) };
|
|
128
|
+
} else if (l.kind === 'pick' && x.compare && (l.pick === 'mine' || l.pick === 'yours')) { x.compare.pick = l.pick; x.compare.pickAt = at; }
|
|
129
|
+
else if (l.kind === 'broke') { x.alert = { open: true, day: str(l.day), value: l.value, limit: l.limit, at }; x.alerts.push({ kind: 'broke', day: str(l.day), value: l.value, at }); }
|
|
77
130
|
else if (l.kind === 'back') { if (x.alert) x.alert = { ...x.alert, open: false, backDay: str(l.day), backValue: l.value }; x.alerts.push({ kind: 'back', day: str(l.day), value: l.value, at }); }
|
|
78
131
|
}
|
|
79
132
|
return { rids, runs };
|
|
@@ -81,20 +134,152 @@ function fold(lines) {
|
|
|
81
134
|
function read(dir) { return fold(readLines(ledgerFile(dir))); }
|
|
82
135
|
const lastOf = (F, rid) => { const x = F && F.rids.get(rid); return x && x.last ? { at: x.last.at, ok: x.last.ok, ...(x.last.ok ? {} : { error: x.last.error }) } : null; };
|
|
83
136
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
137
|
+
/* ── the rhythm (batch 18 item 11): when a goal is read. Local time, as the PM lives it. ── */
|
|
138
|
+
const hmOf = (v) => { const m = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(String(v || '')); return m ? +m[1] * 60 + +m[2] : null; };
|
|
139
|
+
const WEEK = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
140
|
+
const DAY_NAME = { sun: 'Sunday', mon: 'Monday', tue: 'Tuesday', wed: 'Wednesday', thu: 'Thursday', fri: 'Friday', sat: 'Saturday' };
|
|
141
|
+
const localMs = (v) => { // a day is its local midnight; an ISO time or ms is itself
|
|
142
|
+
if (fin(v)) return v;
|
|
143
|
+
const s = String(v || ''), m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
|
|
144
|
+
if (m) return new Date(+m[1], +m[2] - 1, +m[3]).getTime();
|
|
145
|
+
const t = Date.parse(s); return Number.isFinite(t) ? t : null;
|
|
146
|
+
};
|
|
147
|
+
const at0 = (ms, min) => { const d = new Date(ms); d.setHours(0, 0, 0, 0); d.setMinutes(min || 0); return d.getTime(); };
|
|
148
|
+
const plusDays = (ms, n, min) => { const d = new Date(ms); d.setHours(0, 0, 0, 0); d.setDate(d.getDate() + n); d.setMinutes(min || 0); return d.getTime(); };
|
|
149
|
+
|
|
150
|
+
/** The first scheduled read strictly after `after` (ms). */
|
|
151
|
+
function nextAfter(recipe, after, hours = WORK_HOURS) {
|
|
152
|
+
const c = recipe && recipe.cadence, at = hmOf(recipe && recipe.at);
|
|
153
|
+
if (!fin(after)) return null;
|
|
154
|
+
if (c === 'hourly') {
|
|
155
|
+
const s = hmOf(hours && hours.start), e = hmOf(hours && hours.end);
|
|
156
|
+
let t = Math.floor(after / HOUR) * HOUR + HOUR;
|
|
157
|
+
for (let i = 0; i < 24 * 8; i++, t += HOUR) { const d = new Date(t), m = d.getHours() * 60 + d.getMinutes(); if (s === null || e === null || (m >= s && m < e)) return t; }
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (c === 'daily') { let t = at0(after, at || 0); if (t <= after) t = plusDays(after, 1, at || 0); return t; }
|
|
161
|
+
if (c === 'weekly') {
|
|
162
|
+
if (!WEEK.includes(recipe.day)) return plusDays(after, 7, at || 0); // no day: a week after the last try (as before)
|
|
163
|
+
for (let i = 0; i <= 7; i++) { const t = plusDays(after, i, at === null ? 0 : at); if (t > after && WEEK[new Date(t).getDay()] === recipe.day) return t; }
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (c === 'monthly') {
|
|
167
|
+
if (at === null) return plusDays(after, 30, 0); // no time: thirty days after the last try (as before)
|
|
168
|
+
const d = new Date(after), first = (y, mo) => new Date(y, mo, 1, 0, at).getTime();
|
|
169
|
+
const t = first(d.getFullYear(), d.getMonth()); return t > after ? t : first(d.getFullYear(), d.getMonth() + 1);
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
/** The last scheduled try: the ledger's (not a Read now) or a reading on the record (not one a Read now filed). */
|
|
174
|
+
function lastTryOf(rec, x) {
|
|
175
|
+
const ts = [];
|
|
176
|
+
if (x && x.triedAt) { const t = localMs(x.triedAt); if (t !== null) ts.push(t); }
|
|
177
|
+
for (const r of (rec && rec.readings) || []) {
|
|
178
|
+
if (!r || r.via === 'press') continue;
|
|
179
|
+
const t = r.read_at ? localMs(r.read_at) : localMs(String(r.at || '').slice(0, 10));
|
|
180
|
+
if (t !== null) ts.push(t);
|
|
181
|
+
}
|
|
182
|
+
return ts.length ? Math.max(...ts) : null;
|
|
183
|
+
}
|
|
184
|
+
/** The records a reading run reads now. A try that failed counts as a try: the next one is a rhythm later, so a broken source is not hammered.
|
|
185
|
+
* A Read now does not count: the scheduled read stays where it was. */
|
|
186
|
+
function dueOf(records, F, now, o = {}) {
|
|
187
|
+
const t = localMs(now); if (t === null) return [];
|
|
87
188
|
const busy = new Set(); for (const r of (F && F.runs.values()) || []) if (!r.ended) for (const id of r.rids) busy.add(id);
|
|
88
189
|
const out = [];
|
|
89
190
|
for (const rec of records || []) {
|
|
90
191
|
if (!rec || rec.retired === true || !isObj(rec.recipe) || busy.has(rec.rid)) continue;
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
192
|
+
const c = rec.recipe.cadence; if (!CADENCE_GAP[c]) continue;
|
|
193
|
+
if (o.only === 'hourly' && c !== 'hourly') continue;
|
|
194
|
+
if (o.only === 'other' && c === 'hourly') continue;
|
|
195
|
+
const last = lastTryOf(rec, F && F.rids.get(rec.rid));
|
|
196
|
+
if (last === null) { out.push(rec.rid); continue; }
|
|
197
|
+
const next = nextAfter(rec.recipe, last, o.hours || WORK_HOURS);
|
|
198
|
+
if (next !== null && t >= next) out.push(rec.rid);
|
|
95
199
|
}
|
|
96
200
|
return out;
|
|
97
201
|
}
|
|
202
|
+
/** When the goal is read next: its next scheduled read, never earlier than now (an overdue read happens at the next tick). */
|
|
203
|
+
function nextReadOf(rec, F, now, hours = WORK_HOURS) {
|
|
204
|
+
if (!rec || !isObj(rec.recipe) || !CADENCE_GAP[rec.recipe.cadence]) return null;
|
|
205
|
+
const t = localMs(now); if (t === null) return null;
|
|
206
|
+
const last = lastTryOf(rec, F && F.rids.get(rec.rid));
|
|
207
|
+
let next = last === null ? t : nextAfter(rec.recipe, last, hours);
|
|
208
|
+
if (next === null) return null;
|
|
209
|
+
if (next < t) next = rec.recipe.cadence === 'hourly' ? (nextAfter(rec.recipe, t - 1, hours) || t) : t;
|
|
210
|
+
return new Date(next).toISOString();
|
|
211
|
+
}
|
|
212
|
+
/** How the page says the rhythm: txt for the panel and the Kept toast, short for the table column. */
|
|
213
|
+
function rhythmOf(recipe) {
|
|
214
|
+
if (!isObj(recipe) || !CADENCE_GAP[recipe.cadence]) return null;
|
|
215
|
+
const c = recipe.cadence, at = hmOf(recipe.at) !== null ? recipe.at : null, day = c === 'weekly' && WEEK.includes(recipe.day) ? recipe.day : null;
|
|
216
|
+
const tail = at ? ' ' + at : '';
|
|
217
|
+
let txt, short;
|
|
218
|
+
if (c === 'hourly') { txt = 'every hour in working hours'; short = 'Every hour'; }
|
|
219
|
+
else if (c === 'daily') { txt = 'every day' + tail; short = 'Every day'; }
|
|
220
|
+
else if (c === 'weekly') { txt = day ? 'every ' + DAY_NAME[day] + tail : 'every week'; short = day ? 'Every ' + DAY_NAME[day] : 'Every week'; }
|
|
221
|
+
else { txt = at ? 'on the 1st of each month' + tail : 'every month'; short = 'Every month'; }
|
|
222
|
+
return { cadence: c, at: c === 'hourly' ? null : at, day, txt, short };
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* ── Claude's checks on every reading (batch 18 item 11). A failed check holds the reading: it is filed as `held`, never on the record. ── */
|
|
226
|
+
const fmt = (v, unit) => { if (!fin(v)) return ''; const r = Math.abs(v) >= 100 ? Math.round(v) : Math.round(v * 10) / 10, s = Math.abs(r) >= 1000 ? r.toLocaleString('en-US') : String(r), u = String(unit || '').trim(); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
|
|
227
|
+
const median = (xs) => { const a = xs.slice().sort((p, q) => p - q), n = a.length; return n ? (n % 2 ? a[(n - 1) / 2] : (a[n / 2 - 1] + a[n / 2]) / 2) : null; };
|
|
228
|
+
function checksOf(o = {}) {
|
|
229
|
+
const v = o.value, u = o.unit || '', prior = (o.prior || []).filter(fin), segs = segsOf(o.segments);
|
|
230
|
+
const isPct = u === '%' || o.type === 'Percentage';
|
|
231
|
+
const out = [];
|
|
232
|
+
// 1 a part that always reads 0 (the trial: app webview login success 0 of 904)
|
|
233
|
+
const zero = segs.filter((s) => s.num === 0 && s.den >= MIN_DEN);
|
|
234
|
+
const zeroRun = v === 0 && prior.length >= 2 && prior.slice(-2).every((p) => p === 0);
|
|
235
|
+
out.push(zero.length ? { id: 'zero', ok: false, text: zero[0].name + ' reads 0 of ' + fmt(zero[0].den) + '. It may never send the event, so it can never count.' }
|
|
236
|
+
: zeroRun ? { id: 'zero', ok: false, text: 'It read 0 three times in a row. The event may have stopped.' }
|
|
237
|
+
: { id: 'zero', ok: true, text: segs.length ? 'No part of it reads 0.' : 'It does not keep reading 0.' });
|
|
238
|
+
// 2 a jump: more than 3× or less than a third of the median of the last 3 readings
|
|
239
|
+
const m = median(prior.slice(-3));
|
|
240
|
+
if (m === null || m <= 0 || !fin(v)) out.push({ id: 'jump', ok: true, text: prior.length ? 'There is no usual level to compare it with yet.' : 'This is the first reading, so there is nothing to compare it with.' });
|
|
241
|
+
else if (v > m * JUMP || v < m / JUMP) out.push({ id: 'jump', ok: false, text: 'It reads ' + fmt(v, u) + ' against a usual ' + fmt(m, u) + ' (the middle of the last ' + Math.min(3, prior.length) + '). That is ' + (v > m ? 'more than 3 times higher' : 'less than a third') + '.' });
|
|
242
|
+
else out.push({ id: 'jump', ok: true, text: 'It is near its usual ' + fmt(m, u) + '.' });
|
|
243
|
+
// 3 the count below a rate: 0 or too small to trust
|
|
244
|
+
const den = o.den;
|
|
245
|
+
if (!fin(den)) out.push({ id: 'den', ok: true, text: 'It has no count below it to check.' });
|
|
246
|
+
else if (den === 0) out.push({ id: 'den', ok: false, text: 'It counts 0 ' + (o.den_label || 'in the count below it') + ', so there is nothing to divide.' });
|
|
247
|
+
else if (den < MIN_DEN) out.push({ id: 'den', ok: false, text: 'It counts only ' + fmt(den) + ' ' + (o.den_label || 'below it') + '. That is too few to trust.' });
|
|
248
|
+
else out.push({ id: 'den', ok: true, text: fmt(den) + ' ' + (o.den_label || 'below it') + ' is enough to trust.' });
|
|
249
|
+
// 4 a value it cannot possibly be
|
|
250
|
+
const rg = isObj(o.range) ? o.range : {}, min = fin(rg.min) ? rg.min : (isPct || ['Count', 'Duration'].includes(o.type) ? 0 : null), max = fin(rg.max) ? rg.max : isPct ? 100 : null;
|
|
251
|
+
if (fin(o.num) && fin(den) && den > 0 && o.num > den && (isPct || o.type === 'Percentage')) out.push({ id: 'range', ok: false, text: 'It counts ' + fmt(o.num) + ' ' + (o.num_label || 'above') + ' but only ' + fmt(den) + ' ' + (o.den_label || 'below') + '. The first cannot be more.' });
|
|
252
|
+
else if (fin(v) && ((min !== null && v < min) || (max !== null && v > max))) out.push({ id: 'range', ok: false, text: 'It reads ' + fmt(v, u) + ', outside what it can be (' + (min !== null ? fmt(min, u) : 'any') + ' to ' + (max !== null ? fmt(max, u) : 'any') + ').' });
|
|
253
|
+
else out.push({ id: 'range', ok: true, text: min !== null || max !== null ? 'It is inside what it can be.' : 'It has no limit to be inside.' });
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
const heldWhy = (checks) => (checks || []).filter((c) => !c.ok).map((c) => c.text).join(' ');
|
|
257
|
+
/** The PM's number against Claude's: differs when they are more than DIFF_PCT apart (of the PM's number). */
|
|
258
|
+
function compareOf(ours, yours, unit) {
|
|
259
|
+
if (!fin(ours) || !fin(yours)) return null;
|
|
260
|
+
const d = ours - yours, pct = yours !== 0 ? Math.round(Math.abs(d) / Math.abs(yours) * 1000) / 10 : (d === 0 ? 0 : 100);
|
|
261
|
+
return { ours, yours, diff: d, apart: fmt(Math.abs(d), unit), pct, differs: pct > DIFF_PCT };
|
|
262
|
+
}
|
|
263
|
+
/** A first reason, drafted from the last reading's parts at once: a part that reads 0 pulls the number down. */
|
|
264
|
+
function segmentReason(last, unit) {
|
|
265
|
+
const segs = (last && last.segments) || [];
|
|
266
|
+
const z = segs.find((s) => s.num === 0 && s.den >= MIN_DEN);
|
|
267
|
+
if (!z) return null;
|
|
268
|
+
const rest = segs.filter((s) => s !== z), n = rest.reduce((a, s) => a + s.num, 0), d = rest.reduce((a, s) => a + s.den, 0);
|
|
269
|
+
const without = d > 0 ? Math.round(n / d * 1000) / 10 : null;
|
|
270
|
+
return { why: z.name + ' reads 0 of ' + fmt(z.den) + ': it never sends the success event, so my number counts its ' + fmt(z.den) + ' as failures.' + (without !== null && (unit === '%' || !unit) ? ' Without it, I read ' + without + '%.' : ''),
|
|
271
|
+
suggest: { text: 'I suggest counting without ' + z.name + ' until it sends the event.', keep: 'yours' } };
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/** The compare a page draws (contract §5): the PM's number, Claude's, how far apart, and why. */
|
|
275
|
+
function compareView(F, rid, unit) {
|
|
276
|
+
const x = F && F.rids.get(rid), c = x && x.compare; if (!c) return null;
|
|
277
|
+
const m = compareOf(c.ours, c.value, unit) || {};
|
|
278
|
+
let drafting = false; for (const r of F.runs.values()) if (r.why === 'compare' && !r.ended && r.rids.includes(rid) && r.at >= c.at) drafting = true;
|
|
279
|
+
const state = c.pick ? 'picked' : !m.differs ? 'same' : drafting ? 'drafting' : 'differs';
|
|
280
|
+
return { value: c.value, txt: fmt(c.value, unit), period: c.period, ours: c.ours, oursTxt: fmt(c.ours, unit), apart: m.apart, pct: m.pct, differs: !!m.differs, state,
|
|
281
|
+
...(c.why ? { why: c.why } : {}), ...(c.suggest ? { suggest: c.suggest } : {}), ...(c.yours ? { yours: c.yours } : {}), ...(c.pick ? { pick: c.pick } : {}) };
|
|
282
|
+
}
|
|
98
283
|
|
|
99
284
|
/** After a reading of a limit goal: open an episode when it breaks (one push), close it when it is back. reading: lib/goal-status.js readingOf. */
|
|
100
285
|
function alertStep(F, rid, reading) {
|
|
@@ -126,4 +311,4 @@ function parseCsv(text) {
|
|
|
126
311
|
return { rows: out };
|
|
127
312
|
}
|
|
128
313
|
|
|
129
|
-
module.exports = { LEDGER, WHYS, CADENCE_GAP, ledgerFile, readLines, read, append, fold, lastOf, dueOf, alertStep, parseCsv };
|
|
314
|
+
module.exports = { LEDGER, WHYS, CADENCE_GAP, WORK_HOURS, MIN_DEN, DIFF_PCT, ledgerFile, readLines, read, append, fold, lastOf, dueOf, nextAfter, nextReadOf, lastTryOf, rhythmOf, checksOf, heldWhy, compareOf, compareView, segmentReason, fmt, alertStep, parseCsv };
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
* pmos metrics draft fix --json <file|-> one fix row, or a list (kinds: lib/metric-drafts.js FIXES)
|
|
12
12
|
*
|
|
13
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]
|
|
14
|
+
* pmos metrics reading <rid> <value> --source "<connector · what>" [--day YYYY-MM-DD] [--num N --den D] [--segments "web=597/733,app=0/904"]
|
|
15
|
+
* [--period "<week of 19 Oct>"] one value read: Claude's checks run first (lib/metric-reads.js checksOf). It lands on the
|
|
16
|
+
* record with its source, time and counts; a value a check fails on is HELD (ledger only, with a drafted Jira ticket)
|
|
17
|
+
* pmos metrics reading <rid> --why "<why the PM's number differs>" [--suggest mine|yours --suggest-text "<one line>"]
|
|
18
|
+
* [--yours-what "<how the PM counts it>" --yours-query "<the query that counts it that way>"] a compare run only
|
|
15
19
|
* pmos metrics reading <rid> --cant "<why>" [--fix connect|recipe --connector <name> [--query "<q>" --cadence daily|weekly|monthly]]
|
|
16
20
|
* could not read it, said honestly, with the drafted fix
|
|
17
21
|
* The reading run's environment pins its ledger, its records folder, its run and its goals (PMOS_METRIC_READ_FILE, _RECORDS, _DRAFTS, _WS, _RUN,
|
|
@@ -42,8 +46,9 @@ const USAGE = [
|
|
|
42
46
|
' "why": "<the evidence, one line>", "old"?, "metric"? (outcome, next-quarter: a Key results row), "recipe"? { "connector", "query", "cadence" },',
|
|
43
47
|
' "connector"? (connect), "to", "body" (chase), "ticket"? { "title", "text", "project"? }, "by"?, "target"? (carry), "owner"? { "name", "from" } }',
|
|
44
48
|
' pmos metrics reading list',
|
|
45
|
-
' pmos metrics reading <rid> <value> --source "<connector · what you read>" [--day YYYY-MM-DD]',
|
|
46
|
-
' pmos metrics reading <rid> --
|
|
49
|
+
' pmos metrics reading <rid> <value> --source "<connector · what you read>" [--day YYYY-MM-DD] [--num N --den D] [--segments "web=597/733,app=0/904"] [--period "<week of 19 Oct>"]',
|
|
50
|
+
' pmos metrics reading <rid> --why "<why the numbers differ>" [--suggest mine|yours --suggest-text "<one line>"] [--yours-what "<how the PM counts it>" --yours-query "<query>"] (a compare run)',
|
|
51
|
+
' pmos metrics reading <rid> --cant "<why>" [--fix connect|recipe --connector <name> [--query "<q>" --cadence hourly|daily|weekly|monthly]]',
|
|
47
52
|
'Every number comes from a real reading. The PM keeps or drops each row on the page. Nothing is sent.',
|
|
48
53
|
];
|
|
49
54
|
const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -89,6 +94,19 @@ function reading(args, { say, env, now }) {
|
|
|
89
94
|
say(`not read ${rid}${fixId ? ' · fix ' + fixId + ' drafted' : ''}`);
|
|
90
95
|
return 0;
|
|
91
96
|
}
|
|
97
|
+
const why = flag(args, 'why');
|
|
98
|
+
if (why !== undefined) { // a compare run (batch 18 item 11): why the PM's number and Claude's differ, and how the PM counts it
|
|
99
|
+
if (R.why !== 'compare') { say('✗ --why is for a compare run. This run reads the goals.'); return 1; }
|
|
100
|
+
if (typeof why !== 'string' || !why.trim()) { say('usage: pmos metrics reading <rid> --why "<why the numbers differ>"'); return 2; }
|
|
101
|
+
const sg = flag(args, 'suggest'), st = flag(args, 'suggest-text'), yw = flag(args, 'yours-what'), yq = flag(args, 'yours-query');
|
|
102
|
+
if (sg !== undefined && sg !== 'mine' && sg !== 'yours') { say('✗ --suggest is mine or yours'); return 2; }
|
|
103
|
+
const ev = { kind: 'reason', why: why.replace(/\s+/g, ' ').trim().slice(0, 400) };
|
|
104
|
+
if (sg !== undefined && typeof st === 'string' && st.trim()) ev.suggest = { text: st.replace(/\s+/g, ' ').trim().slice(0, 300), keep: sg };
|
|
105
|
+
if (typeof yw === 'string' && yw.trim() && typeof yq === 'string' && yq.trim()) ev.yours = { what: yw.replace(/\s+/g, ' ').trim().slice(0, 300), query: yq.trim().slice(0, 1200) };
|
|
106
|
+
lineOut(ev);
|
|
107
|
+
say(`why ${rid} differs · filed`);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
92
110
|
const v = Number(args[1]);
|
|
93
111
|
if (args[1] === undefined || !Number.isFinite(v)) { say('usage: pmos metrics reading <rid> <value> --source "<connector · what>" [--day YYYY-MM-DD]'); return 2; }
|
|
94
112
|
const source = flag(args, 'source');
|
|
@@ -96,13 +114,52 @@ function reading(args, { say, env, now }) {
|
|
|
96
114
|
const day = flag(args, 'day') === undefined ? localDay(now) : String(flag(args, 'day'));
|
|
97
115
|
if (!DAY_RE.test(day) || day > localDay(now)) { say('✗ --day is YYYY-MM-DD, today or before'); return 2; }
|
|
98
116
|
const src = source.replace(/\s+/g, ' ').trim().slice(0, 200);
|
|
117
|
+
// the counts, the parts and the period (batch 18 item 11): "How it is counted" files them beside the value; a reading without them still files
|
|
118
|
+
const nf = (k) => { const x = flag(args, k); return x === undefined ? undefined : Number(x); };
|
|
119
|
+
const num = nf('num'), den = nf('den');
|
|
120
|
+
if ((num !== undefined && !(Number.isFinite(num) && num >= 0)) || (den !== undefined && !(Number.isFinite(den) && den >= 0))) { say('✗ --num and --den are counts, 0 or more'); return 2; }
|
|
121
|
+
let segments = [];
|
|
122
|
+
const sf = flag(args, 'segments');
|
|
123
|
+
if (sf !== undefined) {
|
|
124
|
+
for (const part of String(sf === true ? '' : sf).split(',').map((x) => x.trim()).filter(Boolean)) {
|
|
125
|
+
const m = /^(.+?)=(\d+(?:\.\d+)?)\/(\d+(?:\.\d+)?)$/.exec(part);
|
|
126
|
+
if (!m) { say('✗ --segments is "name=num/den,name=num/den", for example "web=597/733,app webview=0/904"'); return 2; }
|
|
127
|
+
segments.push({ name: m[1].trim().slice(0, 40), num: Number(m[2]), den: Number(m[3]) });
|
|
128
|
+
}
|
|
129
|
+
segments = segments.slice(0, 8);
|
|
130
|
+
}
|
|
131
|
+
const period = typeof flag(args, 'period') === 'string' ? flag(args, 'period').replace(/\s+/g, ' ').trim().slice(0, 40) : '';
|
|
132
|
+
// what the checks need: the goal (or the drafted row), its earlier good readings, its unit, type, range and count names
|
|
133
|
+
let goal = null;
|
|
134
|
+
if (test) {
|
|
135
|
+
try { const S = MD.read(require('path').dirname(env.PMOS_METRIC_READ_DRAFTS || '.')).scopes.get(MD.keyOf('product', ws)); const row = S && S.rows.get(rid); if (row) goal = { readings: [], unit: (row.metric && row.metric.unit) || row.unit || '', type: (row.metric && row.metric.type) || row.type, recipe: row.recipe || null }; } catch { goal = null; }
|
|
136
|
+
} else { try { goal = records().list(root, 'kr-metrics').find((x) => x.rid === rid) || null; } catch { goal = null; } }
|
|
137
|
+
const rc = (goal && goal.recipe) || {}, cn = rc.counts || {};
|
|
138
|
+
const checks = MR.checksOf({ value: v, num, den, segments, prior: ((goal && goal.readings) || []).map((x) => Number(x.value)), unit: (goal && goal.unit) || '', type: goal && goal.type, range: rc.range, num_label: cn.num_label, den_label: cn.den_label });
|
|
139
|
+
const extra = { ...(num !== undefined ? { num } : {}), ...(den !== undefined ? { den } : {}), ...(segments.length ? { segments } : {}), ...(period ? { period } : {}), checks };
|
|
140
|
+
const failed = checks.filter((c) => !c.ok);
|
|
141
|
+
if (failed.length) {
|
|
142
|
+
// HELD: never on the record, so it never moves the dot, the line or "target reached". A drafted Jira ticket asks the owner to look.
|
|
143
|
+
const why = MR.heldWhy(checks);
|
|
144
|
+
let ticket = null;
|
|
145
|
+
if (!test && env.PMOS_METRIC_READ_DRAFTS && ws) {
|
|
146
|
+
const name = (goal && goal.metric) || rid;
|
|
147
|
+
const c = MD.cleanFix('product', ws, { kind: 'ticket', goal: rid, text: 'Ask the owner of ' + String(name).slice(0, 60) + ' to check this reading before I draw it.', why: why.slice(0, 200),
|
|
148
|
+
ticket: { title: String(name).slice(0, 80) + ' read strangely on ' + day, text: String(name).slice(0, 80) + ' read ' + v + ' on ' + day + ' (' + src + '). I held it: ' + why.slice(0, 400) + ' Please check the tracking and say if the number is real.' } });
|
|
149
|
+
if (!c.error) { try { require('fs').appendFileSync(env.PMOS_METRIC_READ_DRAFTS, JSON.stringify({ at, by: null, kind: 'fix', scope: 'product', id: ws, row: c.row, src: 'read' }) + '\n'); ticket = c.row.id; } catch { ticket = null; } }
|
|
150
|
+
}
|
|
151
|
+
lineOut({ kind: 'held', value: v, day, source: src, ...extra, why, ...(ticket ? { ticket } : {}) });
|
|
152
|
+
say(`held ${rid} · ${v} on ${day} · ${why}`);
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
99
155
|
if (!test) {
|
|
100
156
|
const L = require(require('./repo-script.js').repoScript('trust/ledger.js'));
|
|
101
157
|
const actor = L.actorFrom({ env, isTTY: !!(process.stdout && process.stdout.isTTY) }) || { by: 'claude-code/metric-read', via: 'cli' };
|
|
102
|
-
|
|
158
|
+
const reading = { at: day, value: v, source: src, via: R.why === 'press' ? 'press' : 'run', read_at: at, ...(num !== undefined ? { num } : {}), ...(den !== undefined ? { den } : {}), ...(period ? { period } : {}) };
|
|
159
|
+
let r; try { r = records().addReading(root, rid, reading, actor, R.why === 'press' ? 'Claude read it now, as the PM asked' : 'Claude read it with its recipe'); } catch (e) { r = { ok: false, reasons: [String((e && e.message) || e).slice(0, 160)] }; }
|
|
103
160
|
if (!r.ok) { say('✗ refused: ' + r.reasons.join('; ')); return 1; }
|
|
104
161
|
}
|
|
105
|
-
lineOut({ kind: 'read', value: v, day, source: src });
|
|
162
|
+
lineOut({ kind: 'read', value: v, day, source: src, ...extra });
|
|
106
163
|
say(`${test ? 'test read' : 'read'} ${rid} · ${v} on ${day} · ${src}`);
|
|
107
164
|
return 0;
|
|
108
165
|
}
|
|
@@ -24,7 +24,10 @@
|
|
|
24
24
|
* POST /api/boards/settings { ws, board, buildDeliver?, jira?, offer?, defTpl? } → { ok, board } jira: one key or a list
|
|
25
25
|
* POST /api/boards/ini-workflow { ws, board, id, template?, stages, moveTo? } → { ok, row, moved }
|
|
26
26
|
* POST /api/boards/ini-epics { ws, board, id, epics: [Jira key] } → { ok, row } the Jira epics of an initiative ([] unlinks)
|
|
27
|
-
* POST /api/boards/tasks/add { ws, board, initiative, title, type?, epic?, start?, due?, owner?, notes? } → { ok, item } also `pmos task add`
|
|
27
|
+
* POST /api/boards/tasks/add { ws, board, initiative, title, type?, epic?, start?, due?, owner?, notes?, section? } → { ok, item } also `pmos task add`
|
|
28
|
+
* (section: the stage it goes under, as tasks/edit's section: the + on a stage of the Tasks list, batch 18 item 16)
|
|
29
|
+
* POST /api/boards/tasks/order { ws, board, initiative, section, tasks: [id] } → { ok, from } the PM's order inside one stage (a drag in the
|
|
30
|
+
* Tasks list, batch 18 item 16): a task-order line; tasks [] takes the order out; Undo sends `from` back
|
|
28
31
|
* POST /api/boards/tasks/state { ws, board, task, state } → { ok, item }
|
|
29
32
|
* POST /api/boards/tasks/reschedule { ws, board, task, days } → { ok, item }
|
|
30
33
|
* POST /api/boards/tasks/undo-add { ws, board, task } → { ok } takes back a task added in the last 2 minutes, still To do
|
|
@@ -549,6 +552,18 @@ function itemsOf(w, fr, board, rows) {
|
|
|
549
552
|
// a task's place in the breakdown (one view): the PM's own choice, else the stage whose To finish entry made it
|
|
550
553
|
const SEC = fr.folded.sections || new Map();
|
|
551
554
|
for (const x of out) if (x.src === 'pmos' && x.kind !== 'Epic') { if (SEC.has(x.uid)) x.section = SEC.get(x.uid); else if (x.from && x.from.stage) x.section = x.from.stage; }
|
|
555
|
+
// the PM's order inside a stage (batch 18 item 16, task-order lines): rank = the place in its stage's list. A task named in two lists (it
|
|
556
|
+
// moved since) takes the list of the stage it sits in now
|
|
557
|
+
const OR = fr.folded.orders || new Map();
|
|
558
|
+
if (OR.size) {
|
|
559
|
+
const byIni = new Map();
|
|
560
|
+
for (const [k, ids] of OR) { const [ini, sec] = k.split('\u0000'); if (!byIni.has(ini)) byIni.set(ini, []); byIni.get(ini).push({ sec, ids }); }
|
|
561
|
+
for (const x of out) {
|
|
562
|
+
if (x.src !== 'pmos' || x.kind === 'Epic' || !byIni.has(x.ini)) continue;
|
|
563
|
+
const L = byIni.get(x.ini), hit = (typeof x.section === 'string' && L.find((o) => o.sec === x.section && o.ids.includes(x.uid))) || L.find((o) => o.ids.includes(x.uid));
|
|
564
|
+
if (hit) x.rank = hit.ids.indexOf(x.uid);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
552
567
|
// a task flagged as a milestone (feedback batch 11 item 3): the PM's flag on the board ledger, else a breakdown item's own plan-items flag
|
|
553
568
|
const MS = fr.folded.milestones || new Map();
|
|
554
569
|
for (const x of out) if (x.kind !== 'Epic') { const on = MS.has(x.uid) ? MS.get(x.uid) : !!x.milestone; if (on) x.milestone = true; else delete x.milestone; }
|
|
@@ -1139,14 +1154,38 @@ const WRITES = {
|
|
|
1139
1154
|
if (!base) return;
|
|
1140
1155
|
const b0 = base.find((r) => r.id === body.initiative);
|
|
1141
1156
|
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.initiative} on this board`);
|
|
1157
|
+
// the + on a stage of the Tasks list (batch 18 item 16): the task goes under that stage
|
|
1158
|
+
if (body.section != null) {
|
|
1159
|
+
if (typeof body.section !== 'string' || body.section.length > 80) return fail(ctx, res, 400, "section is a stage key of the initiative's workflow, or '' for Not in a stage");
|
|
1160
|
+
const st = boardRow(p.board, b0, p.fr.folded).wfStages || [];
|
|
1161
|
+
if (body.section && !st.some((x) => x.key === body.section)) return fail(ctx, res, 400, `"${body.section}" is not a stage of this initiative's workflow: one of ${st.map((x) => x.key).join(', ')}, or ''`);
|
|
1162
|
+
}
|
|
1142
1163
|
const id = `task-${crypto.randomBytes(5).toString('hex')}`;
|
|
1143
1164
|
const start = body.start || (body.due && body.due < B.shiftDay(today(), 1) ? body.due : B.shiftDay(today(), 1));
|
|
1144
1165
|
const due = body.due || B.shiftDay(start, 7);
|
|
1145
1166
|
append(p.file, g.actor, { kind: 'task', board: p.board.id, task: id, type: body.type || 'Task', initiative: body.initiative, title: body.title.trim(), epic: body.epic ? String(body.epic).trim() : null,
|
|
1146
1167
|
owner: body.owner ? String(body.owner).trim() : actorLib.pageName(g.actor.by), state: 'To do', start, due, ...(body.notes && body.notes.trim() ? { notes: body.notes.replace(/\s+$/, '') } : {}) });
|
|
1168
|
+
if (typeof body.section === 'string') append(p.file, g.actor, { kind: 'task-section', board: p.board.id, task: id, section: body.section, why: body.section ? 'placed under ' + body.section : 'placed under no stage' });
|
|
1147
1169
|
const t = B.taskOf(B.fold(readLedger(ctx, p.w)), id);
|
|
1148
1170
|
ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t)])[0] });
|
|
1149
1171
|
},
|
|
1172
|
+
'/api/boards/tasks/order': (ctx, res, body, g) => {
|
|
1173
|
+
// the PM's order inside one stage (batch 18 item 16): a drag in the Tasks list writes the stage's open tasks top to bottom; [] takes it out
|
|
1174
|
+
const p = postFrame(ctx, res, body);
|
|
1175
|
+
if (!p) return;
|
|
1176
|
+
if (typeof body.initiative !== 'string' || !body.initiative) return fail(ctx, res, 400, 'initiative is required');
|
|
1177
|
+
if (typeof body.section !== 'string' || body.section.length > 80) return fail(ctx, res, 400, "section is a stage key of the initiative's workflow, or '' for Not in a stage");
|
|
1178
|
+
if (!Array.isArray(body.tasks) || body.tasks.length > 500 || body.tasks.some((x) => typeof x !== 'string' || !x || x.length > 120)) return fail(ctx, res, 400, 'tasks is a list of at most 500 task ids, top to bottom');
|
|
1179
|
+
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
1180
|
+
const base = needRows(ctx, res, p.w);
|
|
1181
|
+
if (!base) return;
|
|
1182
|
+
const b0 = base.find((r) => r.id === body.initiative);
|
|
1183
|
+
if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.initiative} on this board`);
|
|
1184
|
+
const O0 = p.fr.folded.orders || new Map(), from = O0.get(body.initiative + '\u0000' + body.section) || [];
|
|
1185
|
+
const tasks = [...new Set(body.tasks)];
|
|
1186
|
+
append(p.file, g.actor, { kind: 'task-order', board: p.board.id, initiative: body.initiative, section: body.section, tasks, why: tasks.length ? 'reordered under ' + (body.section || 'no stage') : 'order taken out' });
|
|
1187
|
+
ctx.json(res, { ok: true, from });
|
|
1188
|
+
},
|
|
1150
1189
|
'/api/boards/tasks/state': (ctx, res, body, g) => {
|
|
1151
1190
|
const p = postFrame(ctx, res, body);
|
|
1152
1191
|
if (!p) return;
|