create-pmos 0.629.0 → 0.631.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.
@@ -79,7 +79,14 @@ async function handle(req, res, url, ctx) {
79
79
  ctx.json(res, { ok: true, source: src.id, started: 'rebuild' });
80
80
  return true;
81
81
  }
82
- const r = ctx.startSkill(w.id, src.skill, `${src.label} · refresh`);
82
+ // "read it from Jira now" for one closed sprint PMOS never saw (initiative sprint-snapshots, SpH3): the Jira read of that sprint only
83
+ let opts;
84
+ if (body.sprint != null) {
85
+ const name = typeof body.sprint === 'string' ? body.sprint.replace(/[\r\n\t"`\\]+/g, ' ').replace(/\s{2,}/g, ' ').trim() : '';
86
+ if (src.id !== 'jira' || !name || name.length > 80) { ctx.json(res, { ok: false, error: 'sprint goes with source jira and names one sprint (at most 80 characters)' }, 400); return true; }
87
+ opts = { notes: { [src.skill]: `This check: sprint "${name}".` } };
88
+ }
89
+ const r = opts ? ctx.startSkill(w.id, src.skill, `${src.label} · ${body.sprint.slice(0, 40)}`, undefined, opts) : ctx.startSkill(w.id, src.skill, `${src.label} · refresh`);
83
90
  if (!r.ok) { ctx.json(res, { ok: false, error: r.error }, r.status || 500); return true; }
84
91
  ctx.json(res, { ok: true, source: src.id, started: 'session', session: r.session });
85
92
  return true;
@@ -0,0 +1,294 @@
1
+ 'use strict';
2
+ /* sprint-history.js — every ticket a sprint held, kept (initiative sprint-snapshots; brief sprint-overview/snapshots-build-brief.md;
3
+ * boards SpH1 to SpH3 on Exploring 2, page "Sprint overview on the Backlog").
4
+ *
5
+ * WHY. The whole-sprint read (lib/jira-status.js syncSprints) keeps only the latest read, and each ticket under one sprint. When a sprint
6
+ * closes, Jira moves its open tickets to the next sprint, so the old sprint lost them (Sprint 114 kept 39 of its 120), and a sprint that
7
+ * opened and closed between two reads was never seen (116, 117). This file keeps an append-only record of each read, per sprint, so a
8
+ * closed sprint keeps every ticket it held, with its state at close.
9
+ *
10
+ * THE FILE. <state>/tracker/jira/_sprint-history.jsonl, append-only, written only by append() (from `pmos jira sync --sprints`). One line
11
+ * per sprint per read, written only when something changed since that sprint's last line:
12
+ * { at, by: read|late|backfill, sprint: { name, id?, state, start?, end?, completed?, goal? },
13
+ * t: [{ k, n (title), s (status), c (todo|doing|done), p? (points), e? (parent key), en? (parent name), r? (resolved day), pv? (the
14
+ * sprint before this one in the ticket's sprint list: carried in), nx? (the sprint after it: carried to) }] }
15
+ * by: read an ordinary read while the sprint was open, or the first read after it closed
16
+ * late the first read of a sprint PMOS never saw open (its state at close is worked out from each ticket's resolved day)
17
+ * backfill the PM pressed "read it from Jira now" for that sprint (SpH3)
18
+ * A closed sprint is frozen at its first closed line: later reads add nothing to it, except a backfill.
19
+ *
20
+ * append(root, readings, { at, backfill, dryRun }) → { ok, lines, closedNow: [name] }
21
+ * read(root) → [line]
22
+ * snapshotOf(lines, name) → the sprint as kept: its rows with their state at close and the counts (fold, pure)
23
+ * closeOf(lines, name) → { done, total, carried, carriedTo, carriedIn, points } | null PMOS's own close numbers (never the agent's)
24
+ * listOf({ lines, notes, whole, pmNotes, projects }) → the sprint picker (SpH1): every sprint PMOS knows of, newest first
25
+ * detailOf(name, same inputs) → one sprint for the frozen view (SpH2) or the never-seen view (SpH3)
26
+ * trendOf(list) → { line, bars } the carried-over work across the kept sprints; null when there is nothing to say
27
+ *
28
+ * BOUNDARY. No network, no child process. Reads Jira only through the files the read path saved; writes only the history file. */
29
+ const fs = require('fs');
30
+ const path = require('path');
31
+ const jiraTickets = require('./jira-tickets.js');
32
+
33
+ const FILE = '_sprint-history.jsonl';
34
+ const fileOf = (root) => path.join(jiraTickets.jiraDir(root), FILE);
35
+ const isStr = (v) => typeof v === 'string';
36
+ const RANK = { future: 0, active: 1, closed: 2 };
37
+ const num = (name) => { const m = /(\d+)\s*$/.exec(String(name || '')); return m ? Number(m[1]) : null; };
38
+ /** Newest first: the start day when both have one, else the number at the end of the name, else the name. */
39
+ const newestFirst = (a, b) => ((a.start && b.start && a.start !== b.start) ? b.start.localeCompare(a.start)
40
+ : (num(a.name) != null && num(b.name) != null && num(a.name) !== num(b.name)) ? num(b.name) - num(a.name) : String(b.name).localeCompare(String(a.name)));
41
+
42
+ function read(root) {
43
+ let raw = '';
44
+ try { raw = fs.readFileSync(fileOf(root), 'utf8'); } catch { return []; }
45
+ const out = [];
46
+ for (const l of raw.split('\n')) {
47
+ if (!l.trim()) continue;
48
+ try { const o = JSON.parse(l); if (o && o.sprint && isStr(o.sprint.name) && Array.isArray(o.t)) out.push(o); } catch { /* a torn line has no effect */ }
49
+ }
50
+ return out;
51
+ }
52
+
53
+ /** A reading's sprints, oldest first: the full list when the read kept it, else its one sprint. */
54
+ const listOfReading = (r) => (Array.isArray(r.sprints) && r.sprints.length ? r.sprints : r.sprint ? [r.sprint] : []).filter((s) => s && isStr(s.name) && s.name);
55
+ const SPRINT_KEYS = ['id', 'start', 'end', 'completed', 'goal'];
56
+ const sigOf = (line) => line.sprint.state + '\n' + line.t.map((x) => [x.k, x.c, x.s, x.p == null ? '' : x.p].join('\t')).join('\n');
57
+
58
+ /** Save one read: a line per sprint it holds, when something changed since that sprint's last line. A closed sprint already kept is left
59
+ * alone, except by a backfill of that sprint. → { ok, lines, closedNow } */
60
+ function append(root, readings, { at, backfill = null, dryRun = false } = {}) {
61
+ const prev = read(root);
62
+ const last = new Map(), closed = new Set(), open = new Set();
63
+ for (const l of prev) {
64
+ last.set(l.sprint.name, l);
65
+ if (l.sprint.state === 'closed') closed.add(l.sprint.name); else if (l.by === 'read') open.add(l.sprint.name);
66
+ }
67
+ const groups = new Map();
68
+ for (const r of readings || []) {
69
+ if (!r || !isStr(r.key)) continue;
70
+ const list = listOfReading(r);
71
+ list.forEach((s, i) => {
72
+ if (backfill && s.name !== backfill) return;
73
+ if (!groups.has(s.name)) groups.set(s.name, { sprint: { name: s.name, state: s.state || 'future' }, t: [] });
74
+ const g = groups.get(s.name);
75
+ if ((RANK[s.state] || 0) > (RANK[g.sprint.state] || 0)) g.sprint.state = s.state; // the readings agree; the furthest state wins
76
+ for (const k of SPRINT_KEYS) if (s[k] != null && g.sprint[k] == null) g.sprint[k] = s[k];
77
+ if (g.t.some((x) => x.k === r.key)) return;
78
+ g.t.push({ k: r.key, n: String(r.summary || '').slice(0, 250), s: String(r.status || ''), c: r.category || 'todo',
79
+ ...(r.points != null ? { p: r.points } : {}), ...(r.parent ? { e: r.parent } : {}), ...(r.parentName ? { en: r.parentName } : {}),
80
+ ...(r.resolved ? { r: r.resolved } : {}), ...(i > 0 ? { pv: list[i - 1].name } : {}), ...(i < list.length - 1 ? { nx: list[i + 1].name } : {}) });
81
+ });
82
+ }
83
+ const lines = [], closedNow = [];
84
+ for (const g of groups.values()) {
85
+ const name = g.sprint.name;
86
+ if (!backfill && closed.has(name)) continue; // frozen at its first closed line
87
+ g.t.sort((a, b) => a.k.localeCompare(b.k, undefined, { numeric: true }));
88
+ const by = backfill ? 'backfill' : (g.sprint.state === 'closed' && !open.has(name)) ? 'late' : 'read';
89
+ const line = { at, by, sprint: g.sprint, t: g.t };
90
+ const was = last.get(name);
91
+ if (!backfill && was && sigOf(was) === sigOf(line)) continue;
92
+ if (g.sprint.state === 'closed' && open.has(name) && !closed.has(name)) closedNow.push(name);
93
+ lines.push(line);
94
+ }
95
+ if (!dryRun && lines.length) {
96
+ const file = fileOf(root);
97
+ fs.mkdirSync(path.dirname(file), { recursive: true });
98
+ fs.appendFileSync(file, lines.map((l) => JSON.stringify(l)).join('\n') + '\n');
99
+ }
100
+ return { ok: true, lines: lines.map((l) => ({ name: l.sprint.name, state: l.sprint.state, by: l.by, tickets: l.t.length })), closedNow };
101
+ }
102
+
103
+ /* ── the fold ──────────────────────────────────────────────────────────────────────────────────────────────── */
104
+ /** One sprint as kept. → null when no line names it, else { name, sprint, seenOpen, keptAt, by, rows, counts } */
105
+ function snapshotOf(lines, name) {
106
+ const L = (lines || []).filter((l) => l.sprint.name === name);
107
+ if (!L.length) return null;
108
+ const sprint = { name, state: 'future' };
109
+ for (const l of L) {
110
+ if ((RANK[l.sprint.state] || 0) >= (RANK[sprint.state] || 0)) sprint.state = l.sprint.state;
111
+ for (const k of SPRINT_KEYS) if (l.sprint[k] != null) sprint[k] = l.sprint[k];
112
+ }
113
+ const reads = L.filter((l) => l.by === 'read');
114
+ const seenOpen = reads.some((l) => l.sprint.state !== 'closed');
115
+ const closeAt = L.findIndex((l) => l.sprint.state === 'closed');
116
+ const closedLine = closeAt >= 0 ? L[closeAt] : null;
117
+ // the reads that make the sprint: every ordinary read up to and including the first closed one
118
+ const main = L.filter((l, i) => l.by === 'read' && (closeAt < 0 || i <= closeAt));
119
+ const firstOpen = main.find((l) => l.sprint.state !== 'closed') || null;
120
+ const lastMain = main.length ? main[main.length - 1] : null;
121
+ const rows = new Map();
122
+ main.forEach((l) => { for (const x of l.t) rows.set(x.k, { ...(rows.get(x.k) || {}), ...x, from: 'read', seen: l.at }); });
123
+ // a late or backfill line only fills a ticket the reads never held, with its state at close worked out from its resolved day
124
+ const end = sprint.completed || sprint.end || null;
125
+ for (const l of L) {
126
+ if (l.by === 'read') continue;
127
+ for (const x of l.t) {
128
+ if (rows.has(x.k)) continue;
129
+ const doneAtClose = x.c === 'done' && (!end || !x.r || x.r <= end);
130
+ rows.set(x.k, { ...x, c: doneAtClose ? 'done' : x.c === 'done' ? 'doing' : x.c, from: l.by, seen: l.at });
131
+ }
132
+ }
133
+ const inFirst = new Set(firstOpen ? firstOpen.t.map((x) => x.k) : []);
134
+ const inLast = new Set(lastMain ? lastMain.t.map((x) => x.k) : []);
135
+ const isClosed = sprint.state === 'closed';
136
+ const out = [];
137
+ for (const x of rows.values()) {
138
+ // removed: an open ticket the latest read (or the read at close) no longer holds. A done ticket stays done in this sprint.
139
+ const removed = x.from === 'read' && lastMain && !inLast.has(x.k) && x.c !== 'done';
140
+ const done = x.c === 'done';
141
+ out.push({ key: x.k, title: x.n || '', status: x.s || '', category: x.c || 'todo', points: x.p == null ? null : x.p, epic: x.e || null, epicName: x.en || null,
142
+ planned: seenOpen && inFirst.has(x.k), added: seenOpen && x.from === 'read' && !inFirst.has(x.k), removed: !!removed,
143
+ carried: isClosed && !done && !removed, carriedTo: isClosed && !done && !removed ? (x.nx || null) : null, carriedIn: x.pv || null, from: x.from });
144
+ }
145
+ out.sort((a, b) => a.key.localeCompare(b.key, undefined, { numeric: true }));
146
+ return { name, sprint, seenOpen, keptAt: closedLine ? closedLine.at : null, lastAt: L[L.length - 1].at,
147
+ by: seenOpen ? 'read' : L.some((l) => l.by === 'backfill') ? 'backfill' : 'late', rows: out, counts: countsOf(out) };
148
+ }
149
+ function countsOf(rows) {
150
+ const held = rows.filter((r) => !r.removed);
151
+ const done = held.filter((r) => r.category === 'done');
152
+ const carried = held.filter((r) => r.carried);
153
+ const to = new Map(); for (const r of carried) if (r.carriedTo) to.set(r.carriedTo, (to.get(r.carriedTo) || 0) + 1);
154
+ const pts = held.filter((r) => r.points != null);
155
+ const sum = (L) => Math.round(L.reduce((a, r) => a + r.points, 0) * 10) / 10;
156
+ return { total: held.length, done: done.length, carried: carried.length, carriedTo: [...to.entries()].sort((a, b) => b[1] - a[1]).map(([n]) => n)[0] || null,
157
+ carriedIn: held.filter((r) => r.carriedIn).length, added: held.filter((r) => r.added).length, removed: rows.filter((r) => r.removed).length,
158
+ points: pts.length ? { done: sum(pts.filter((r) => r.category === 'done')), total: sum(pts) } : null };
159
+ }
160
+ /** PMOS's own close numbers for a sprint it saw open and then closed: what `pmos jira summary` writes, never the agent's count. */
161
+ function closeOf(lines, name) {
162
+ const s = snapshotOf(lines, name);
163
+ if (!s || !s.seenOpen || s.sprint.state !== 'closed') return null;
164
+ const c = s.counts;
165
+ return { done: c.done, total: c.total, carried: c.carried, carriedTo: c.carriedTo, carriedIn: c.carriedIn, points: c.points ? `${c.points.done} of ${c.points.total}` : null };
166
+ }
167
+
168
+ /* ── the picker and the views ─────────────────────────────────────────────────────────────────────────────── */
169
+ const projectOf = (key) => String(key || '').split('-')[0].toUpperCase();
170
+ const wholeList = (whole) => (whole && whole.tickets ? (whole.tickets instanceof Map ? [...whole.tickets.values()] : Array.isArray(whole.tickets) ? whole.tickets : []) : []);
171
+ /** Everything PMOS knows of each sprint on this board. inputs: { lines, notes: [jira sprint note], whole: the whole-sprint read, pmNotes:
172
+ * { [sprint]: folded PM edits }, projects: [Jira project key] | null } */
173
+ function gather(inp) {
174
+ const P = inp.projects && inp.projects.length ? new Set(inp.projects) : null;
175
+ const mine = (keys) => !P || keys.some((k) => P.has(projectOf(k)));
176
+ const by = new Map();
177
+ const at = (name) => { if (!by.has(name)) by.set(name, { name, snap: null, note: null, whole: [], pm: null, seenIn: [] }); return by.get(name); };
178
+ const lines = inp.lines || [];
179
+ for (const name of new Set(lines.map((l) => l.sprint.name))) {
180
+ const s = snapshotOf(lines, name);
181
+ if (s && mine(s.rows.map((r) => r.key))) at(name).snap = s;
182
+ }
183
+ const W = wholeList(inp.whole);
184
+ for (const t of W) {
185
+ if (!t || !t.key || !mine([t.key])) continue;
186
+ if (t.sprint && t.sprint.name) at(t.sprint.name).whole.push(t);
187
+ // the other sprints a ticket was in: a sprint PMOS never read is still known to have existed
188
+ for (const s of Array.isArray(t.sprints) ? t.sprints : []) if (s && s.name && s.name !== (t.sprint && t.sprint.name)) at(s.name).seenIn.push(t.key);
189
+ }
190
+ for (const n of inp.notes || []) {
191
+ if (!n || !n.name) continue;
192
+ const hit = by.get(n.name);
193
+ if (hit || !P || (n.themes || []).length || n.closed) at(n.name).note = n;
194
+ }
195
+ for (const [name, pm] of Object.entries(inp.pmNotes || {})) {
196
+ if (!pm || !['goals', 'doing', 'next', 'happened', 'lessons'].some((k) => pm[k])) continue;
197
+ at(name).pm = pm;
198
+ }
199
+ return by;
200
+ }
201
+ const stateOf = (g) => (g.snap && g.snap.sprint.state) || (g.whole[0] && g.whole[0].sprint.state) || (g.note && g.note.state) || 'closed';
202
+ const datesOf = (g) => {
203
+ const s = (g.snap && g.snap.sprint) || {}, w = (g.whole[0] && g.whole[0].sprint) || {}, n = g.note || {};
204
+ return { start: s.start || w.start || n.start || null, end: s.end || w.end || n.end || null, completed: s.completed || w.completed || n.completed || null };
205
+ };
206
+ /** How one closed sprint is kept, with the numbers its row and its view show. */
207
+ function keptOf(g) {
208
+ const nc = g.note && g.note.state === 'closed' && g.note.closed && g.note.closed.total ? g.note.closed : null;
209
+ if (g.snap && g.snap.seenOpen) {
210
+ const c = g.snap.counts;
211
+ return { kept: 'full', done: c.done, total: c.total, carried: c.carried, carriedTo: c.carriedTo, carriedIn: c.carriedIn, points: c.points, keptAt: g.snap.keptAt };
212
+ }
213
+ if (nc) {
214
+ const m = /(\d+(?:\.\d+)?)\s*of\s*(\d+(?:\.\d+)?)/.exec(String(nc.points || ''));
215
+ return { kept: 'note', done: nc.done, total: nc.total, carried: nc.carried, carriedTo: nc.carriedTo || null, carriedIn: null,
216
+ points: m ? { done: Number(m[1]), total: Number(m[2]) } : null, keptAt: g.note.writtenAt || null };
217
+ }
218
+ if (g.snap) {
219
+ const c = g.snap.counts;
220
+ return { kept: g.snap.by, done: c.done, total: c.total, carried: c.carried, carriedTo: c.carriedTo, carriedIn: c.carriedIn, points: c.points, keptAt: g.snap.lastAt };
221
+ }
222
+ return { kept: 'none' };
223
+ }
224
+ const WHY = {
225
+ notes: 'only your notes are kept',
226
+ between: 'opened and closed between two Jira reads',
227
+ };
228
+ /** The picker (SpH1): the current sprint first, then the past ones newest first. */
229
+ function listOf(inp) {
230
+ const by = gather(inp);
231
+ const out = [];
232
+ for (const g of by.values()) {
233
+ const state = stateOf(g);
234
+ const d = datesOf(g);
235
+ if (state === 'active' || state === 'future') {
236
+ const n = g.whole.length || (g.snap ? g.snap.counts.total : 0);
237
+ out.push({ name: g.name, state, ...d, tickets: n });
238
+ continue;
239
+ }
240
+ const k = keptOf(g);
241
+ out.push({ name: g.name, state: 'closed', ...d, ...k, ...(k.kept === 'none' ? { why: g.pm ? WHY.notes : WHY.between } : {}), notes: !!g.pm,
242
+ hit: g.note && g.note.hit ? g.note.hit : null });
243
+ }
244
+ const order = { active: 0, future: 2, closed: 1 };
245
+ return out.filter((x) => x.state !== 'future').sort((a, b) => (order[a.state] - order[b.state]) || newestFirst(a, b));
246
+ }
247
+ /** The carried-over line and its bars (SpH1): the kept closed sprints, oldest first. Zero is silence: null when fewer than two. */
248
+ function trendOf(list) {
249
+ const K = (list || []).filter((x) => x.state === 'closed' && x.kept !== 'none' && Number.isInteger(x.carried)).slice().reverse();
250
+ if (K.length < 2) return null;
251
+ const bars = K.slice(-12).map((x) => ({ name: x.name, carried: x.carried }));
252
+ const first = bars[0], peak = bars.reduce((a, b) => (b.carried > a.carried ? b : a), first), lastB = bars[bars.length - 1];
253
+ const t = (n) => n + (n === 1 ? ' ticket' : ' tickets');
254
+ let line = null;
255
+ if (peak !== first && peak.carried >= Math.max(first.carried * 1.5, first.carried + 3)) line = `Work carried to the next sprint grew from ${t(first.carried)} (${first.name}) to ${peak.carried} (${peak.name}).`;
256
+ else if (lastB.carried * 1.5 <= first.carried && first.carried - lastB.carried >= 3) line = `Work carried to the next sprint fell from ${t(first.carried)} (${first.name}) to ${lastB.carried} (${lastB.name}).`;
257
+ return bars.some((b) => b.carried) ? { line, bars } : null;
258
+ }
259
+ const sentences = (s) => String(s || '').split(/(?<=[.!?])\s+(?=[A-Z0-9])/).map((x) => x.trim()).filter(Boolean);
260
+ /** One sprint for its view: SpH2 (kept) or SpH3 (not kept). → null when PMOS knows no sprint of that name. */
261
+ function detailOf(name, inp) {
262
+ const by = gather(inp);
263
+ const g = by.get(name);
264
+ if (!g) return null;
265
+ const state = stateOf(g), d = datesOf(g);
266
+ const base = { name, state, ...d, notes: g.pm || null };
267
+ if (state !== 'closed') return { ...base, kept: 'now' };
268
+ const k = keptOf(g);
269
+ if (k.kept === 'none') return { ...base, kept: 'none', why: g.pm ? WHY.notes : WHY.between };
270
+ // the rows: the kept record's, then the whole read's for an old sprint the record never held
271
+ const rows = new Map();
272
+ for (const r of g.snap ? g.snap.rows.filter((x) => !x.removed) : []) rows.set(r.key, { ...r });
273
+ for (const t of g.whole) {
274
+ if (rows.has(t.key)) continue;
275
+ rows.set(t.key, { key: t.key, title: t.summary || '', status: t.status || '', category: t.category || 'todo', points: t.points == null ? null : t.points,
276
+ epic: t.parent || null, epicName: t.parentName || null, carried: t.category !== 'done', carriedTo: t.category !== 'done' ? (k.carriedTo || null) : null, from: 'whole', url: t.url || null });
277
+ }
278
+ for (const t of g.whole) { const r = rows.get(t.key); if (r && !r.url && t.url) r.url = t.url; }
279
+ const R = [...rows.values()].sort((a, b) => a.key.localeCompare(b.key, undefined, { numeric: true }));
280
+ const removed = g.snap ? g.snap.rows.filter((x) => x.removed) : [];
281
+ // rows the snapshot cannot show (old data): the note counted more than PMOS kept, said once, on one quiet row
282
+ const gotDone = R.filter((r) => r.category === 'done').length, gotCarried = R.filter((r) => r.category !== 'done').length;
283
+ const missing = k.kept === 'full' ? null : (() => {
284
+ const md = Math.max(0, (k.done || 0) - gotDone), mc = Math.max(0, (k.carried || 0) - gotCarried);
285
+ return md || mc ? { done: md, carried: mc } : null;
286
+ })();
287
+ const n = g.note && g.note.state === 'closed' ? g.note : null;
288
+ const themes = n ? (n.themes || []).map((t) => ({ title: t.title, tickets: t.tickets || 0, done: t.done || 0, keys: Array.isArray(t.keys) ? t.keys.filter((x) => rows.has(x)) : [] })) : [];
289
+ return { ...base, ...k, hit: n && n.hit ? n.hit : null, got: n && n.got ? n.got : null, themes,
290
+ happened: n ? sentences(n.summary).slice(0, 5) : [], rows: R, removed: removed.map((r) => ({ key: r.key, title: r.title })), missing,
291
+ addedLater: g.snap && g.snap.seenOpen ? g.snap.counts.added : null };
292
+ }
293
+
294
+ module.exports = { FILE, fileOf, read, append, snapshotOf, closeOf, listOf, detailOf, trendOf, WHY };
@@ -23,7 +23,7 @@ const MODEL = 'claude-sonnet-5-5';
23
23
  const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read' }]);
24
24
  const TIMEOUT_MS = 240000;
25
25
  const SPARE = 'Everything else';
26
- const BLOCKS = ['goals', 'doing', 'next'];
26
+ const BLOCKS = ['goals', 'doing', 'next', 'happened', 'lessons']; // happened, lessons: a past sprint's (initiative sprint-snapshots)
27
27
  const MOVING = new Set(['In progress', 'In review']);
28
28
  const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1) + '…' : t; };
29
29
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.629.0",
3
+ "version": "0.631.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.629.0",
9
+ "version": "0.631.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/sdk": "^1.3.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.629.0",
3
+ "version": "0.631.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -193,6 +193,40 @@ textarea.bk-rvl-ed, .bk-rvl textarea.bd { resize: vertical; min-height: 180px; }
193
193
  .sbo-p .x em { font-style: normal; margin-left: 8px; font-size: var(--fs-meta); color: var(--cz-ink3); }
194
194
  .sbo-t:focus-visible, .sbo-ta:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
195
195
  @media (hover: hover) { .sbo-t:hover:not(.on) { background: var(--cz-well); } }
196
+ /* past sprints (initiative sprint-snapshots; boards SpH1 to SpH3): the picker, the frozen snapshot, a sprint PMOS never saw */
197
+ .sbo-pw { position: relative; display: inline-flex; }
198
+ .sbo-pk { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px 0 14px; border-radius: 999px; box-shadow: inset 0 0 0 1px var(--cz-hair); font-size: var(--fs-panel); font-weight: var(--fw-strong); color: var(--cz-ink); }
199
+ .sbo-pk svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; }
200
+ .sbo-menu { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: min(560px, calc(100vw - 32px)); padding: 8px 0; border-radius: 16px; background: var(--cz-card); box-shadow: inset 0 0 0 1px var(--cz-hair), var(--cz-float); }
201
+ .sbo-mi { all: unset; box-sizing: border-box; cursor: pointer; display: grid; grid-template-columns: 112px 112px minmax(0, 1fr) 104px; gap: 12px; align-items: center; width: 100%; min-height: 40px; padding: 0 18px; font-size: var(--fs-meta); color: var(--cz-ink3); }
202
+ .sbo-mi b { font-size: var(--fs-row); font-weight: var(--fw-strong); color: var(--cz-ink); }
203
+ .sbo-mi.on { background: var(--cz-bluebg); }
204
+ .sbo-mq { grid-column: span 2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
205
+ .sbo-mr { text-align: right; white-space: nowrap; }
206
+ .sbo-mo { all: unset; cursor: pointer; display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 18px; font-size: var(--fs-meta); color: var(--cz-ink3); }
207
+ .sbo-mo svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; }
208
+ .sbo-tr { margin-top: 6px; padding: 12px 18px 4px; box-shadow: inset 0 1px 0 var(--cz-hair); }
209
+ .sbo-bars { display: flex; align-items: flex-end; gap: 8px; height: 76px; margin-top: 10px; }
210
+ .sbo-bc { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; width: 28px; height: 100%; }
211
+ .sbo-bc i { display: block; width: 100%; border-radius: 3px 3px 0 0; background: color-mix(in srgb, var(--cz-risk) 55%, var(--cz-card)); }
212
+ .sbo-bc em { font-style: normal; font-size: var(--fs-meta); color: var(--cz-ink3); }
213
+ .sbo-lk { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; background: var(--cz-well); color: var(--cz-ink2); }
214
+ .sbo-lk svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; }
215
+ .sbo-goal { margin: 12px 0 0; font-size: var(--fs-row); color: var(--cz-ink); }
216
+ .sbo-past .sbo-h .sbo-meta { margin: 0; }
217
+ .sbo-t.st { cursor: default; }
218
+ .sbo-b ul.q li span { color: var(--cz-ink3); }
219
+ .sbo-b li .bk-lnk { margin-left: 8px; font-size: var(--fs-meta); }
220
+ .sbo-warn { display: flex; align-items: center; gap: 12px; margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: var(--cz-riskbg); box-shadow: inset 0 0 0 1px var(--cz-hair); font-size: var(--fs-row); color: var(--cz-ink); }
221
+ .sbo-warn p { flex: 1; margin: 0; }
222
+ .sbo-two { grid-template-columns: 1fr 1fr 1fr; }
223
+ .sbo-miss { margin: 0; padding: 12px 16px 12px 52px; border-radius: 0 0 16px 16px; background: var(--cz-riskbg); font-size: var(--fs-meta); color: var(--cz-ink2); box-shadow: inset 0 1px 0 var(--cz-hair); }
224
+ .bk-gs { align-self: center; font-size: var(--fs-meta); color: var(--cz-ink3); }
225
+ .bk-past .bk-t { cursor: text; }
226
+ .bk-past a.bk-t { cursor: pointer; }
227
+ .bk-past .bk-more { box-sizing: border-box; width: 100%; }
228
+ .sbo-pk:focus-visible, .sbo-mi:focus-visible, .sbo-mo:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
229
+ @media (hover: hover) { .sbo-mi:hover:not(.on) { background: var(--cz-well); } }
196
230
  @media (max-width: 1100px) { .sbo-pl { grid-template-columns: 1fr 1fr; } }
197
231
  @media (max-width: 760px) {
198
232
  .sbo-band { padding: 16px; }
@@ -200,4 +234,8 @@ textarea.bk-rvl-ed, .bk-rvl textarea.bd { resize: vertical; min-height: 180px; }
200
234
  .sbo-thl { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-flow: row; }
201
235
  .sbo-t { min-height: 44px; grid-template-columns: minmax(0, 1fr) 40px 52px; gap: 10px; }
202
236
  .sbo-p { flex-wrap: wrap; padding: 8px 0; }
237
+ .sbo-mi { grid-template-columns: 1fr auto; row-gap: 2px; min-height: 52px; padding: 6px 16px; }
238
+ .sbo-mi .sbo-bar { grid-column: 1 / -1; }
239
+ .sbo-mq { grid-column: 1 / -1; white-space: normal; }
240
+ .sbo-two { grid-template-columns: 1fr; }
203
241
  }
@@ -14,6 +14,7 @@
14
14
  * Every write is a route's own (lib/routes-backlog.js, and the Board's task routes for a person, a date, an initiative and Archive) and comes
15
15
  * with Undo where the route has one. The words say PMOS, never the model's name. pm/premium-board.js calls sync() after each read of the board. */
16
16
  import * as BM from './bk-model.js';
17
+ import { productName } from './scope-chip.js'; // the product's display name ("IDPF"), never its folder id
17
18
  import * as SP from './bd-sprint.js'; // the sprint overview while "This sprint" is on (initiative sprint-overview)
18
19
 
19
20
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[c]);
@@ -77,7 +78,7 @@ export async function load() {
77
78
  const ok = got.filter(Boolean);
78
79
  // the oldest Jira read of the pick (the sprint band says when Jira was last read) and the PM's edits of each sprint's overview
79
80
  const reads = ok.map((r) => r.readAt).filter(Boolean).sort();
80
- DATA = { readAt: reads[0] || null, notes: Object.fromEntries(ok.map((r) => [r.ws + '|' + r.board, r.sprintNotes || {}])), tasks: ok.flatMap((r) => r.tasks || []), modes: ok.map((r) => ({ product: r.product, mode: r.mode, label: r.modeLabel, kinds: r.kinds || null })), inis: ok.flatMap((r) => (r.inis || []).map((x) => ({ ...x, ws: r.ws, board: r.board, product: r.product }))),
81
+ DATA = { readAt: reads[0] || null, hist: ok.map((r) => ({ ws: r.ws, board: r.board, list: r.sprintList || [], trend: r.sprintTrend || null })), notes: Object.fromEntries(ok.map((r) => [r.ws + '|' + r.board, r.sprintNotes || {}])), tasks: ok.flatMap((r) => r.tasks || []), modes: ok.map((r) => ({ product: productName(r.ws, r.product), mode: r.mode, label: r.modeLabel, kinds: r.kinds || null })), inis: ok.flatMap((r) => (r.inis || []).map((x) => ({ ...x, ws: r.ws, board: r.board, product: productName(r.ws, r.product) }))),
81
82
  err: ok.length ? (ok.length < S.length ? 'One product could not be read; its tasks are not here.' : '') : 'The tasks could not be read. Try again in a moment.', many: S.length > 1 };
82
83
  // ?ini=<initiative id> (the initiative popup's "Open in Backlog"): the Initiative facet starts on that initiative, once
83
84
  if (!iniApplied) {
@@ -121,21 +122,26 @@ function draw() {
121
122
  const said = SAID ? `<p class="bk-said" role="status">${esc(SAID.text)}${SAID.undo ? ' <button type="button" class="bk-lnk" data-bksaid>Undo</button>' : ''}</p>` : '';
122
123
  const sh = BM.showingLine(T, { chips: CHIPS, pick: PICK, partB: partB() });
123
124
  const showing = sh ? `<p class="bk-show">${esc(sh.text)}${sh.hidden ? ` · ${sh.hidden} hidden` : ''} · <button type="button" class="bk-lnk" data-bkall>Show all</button></p>` : '';
124
- const band = CHIPS.has('sprint') ? SP.bandHtml({ tasks: T.filter(BM.isOpen), all: T, inis: DATA.inis, readAt: DATA.readAt, notes: DATA.notes }, spDeps()) : '';
125
+ const band = CHIPS.has('sprint') ? SP.bandHtml({ tasks: T.filter(BM.isOpen), all: T, inis: DATA.inis, readAt: DATA.readAt, notes: DATA.notes, hist: DATA.hist }, spDeps()) : '';
125
126
  const th = band ? SP.themeOf() : null;
126
127
  // a theme pressed in the band: the list is its tickets only, in one group with "Show all" (board SpA2)
127
128
  const G = th ? [{ k: 'theme', n: th.name, sub: '', open: true, total: th.total,
128
129
  rows: BM.sortRows(T.filter((t) => th.uids.has(uidOf(t)) && BM.keeps(t, CHIPS, PICK, partB())), SORT) }]
129
130
  : BM.groupsOf(T, { chips: CHIPS, pick: PICK, sort: SORT, partB: partB() });
130
- const head = headHtml(COLS);
131
- const body = G.map((g) => groupHtml(g)).join('') || `<p class="bk-none">${T.length ? 'No task matches these filters.' : 'No open task here. A task added to an initiative, or a Jira ticket of a sprint, shows here.'}</p>`;
131
+ const cols = colsOf(T, COLS);
132
+ const head = headHtml(cols);
133
+ const body = G.map((g) => groupHtml(g, cols)).join('') || `<p class="bk-none">${T.length ? 'No task matches these filters.' : 'No open task here. A task added to an initiative, or a Jira ticket of a sprint, shows here.'}</p>`;
134
+ // a past sprint picked in the band: the list is that sprint's tickets as they were at close (initiative sprint-snapshots, SpH2)
135
+ const past = band && SP.pastOn() ? SP.pastListHtml() : null;
132
136
  host.innerHTML = `<div class="bk-chips" role="group" aria-label="Show">${chips}</div>${mode}${showing}${said}${DATA.err ? `<p class="bk-err">${esc(DATA.err)}</p>` : ''}${band}`
133
- + `<div class="bk" role="table" aria-label="Backlog">${head}${body}</div>`;
137
+ + (past != null ? past : `<div class="bk" role="table" aria-label="Backlog" style="--bk-cols: ${colsCss(cols)}">${head}${body}</div>`);
134
138
  drawBar();
135
139
  }
136
140
  /* ── the columns: Task first and the actions last, always; the ones between are a list, so the initiative popup can leave Initiative out ── */
137
141
  export const COLS = ['jira', 'epic', 'ini', 'who', 'state'];
138
142
  const COL = { jira: ['Jira ticket', '104px'], epic: ['Epic', 'minmax(80px, 130px)'], ini: ['Initiative', 'minmax(110px, 160px)'], who: ['Who', '76px'], due: ['Due', 'minmax(80px, 150px)'], state: ['State', 'minmax(200px, 290px)'] };
143
+ /** Zero is silence (same rule as Work): a Jira or Epic column with no value in the whole list is not drawn. */
144
+ export const colsOf = (tasks, cols) => cols.filter((c) => (c === 'jira' ? tasks.some((t) => t.key) : c === 'epic' ? tasks.some((t) => t.epic) : true));
139
145
  const colsCss = (cols) => `40px minmax(240px, 1fr) ${cols.map((c) => COL[c][1]).join(' ')} 72px`;
140
146
  function headHtml(cols) {
141
147
  return `<div class="bk-r bk-h" role="row"><span class="c-ck"></span><span class="c-n">Task</span>${cols.map((c) => `<span class="c-${c}">${COL[c][0]}</span>`).join('')}<span class="c-a"></span></div>`;
@@ -191,7 +197,7 @@ function rowHtml(t, gk, cols = COLS) {
191
197
  }
192
198
 
193
199
  /** What the sprint band (pm/bd-sprint.js) needs from the Backlog and its page. */
194
- const spDeps = () => ({ post, say: (m, u) => AP().say(m, u), draw, load, reload: () => AP().reload(), taskOf,
200
+ const spDeps = () => ({ post, tasks: () => (DATA ? DATA.tasks.filter(BM.isOpen) : []), say: (m, u) => AP().say(m, u), draw, load, reload: () => AP().reload(), taskOf,
195
201
  readJira: A && A.readJira ? () => A.readJira() : null, newInitiative: A && A.newInitiative ? (name, from) => A.newInitiative(name, from) : null });
196
202
 
197
203
  /* ── the bar under ticked rows (board BkSelect) ───────────────────────────────────────────────────────────────── */
@@ -402,7 +408,7 @@ function closeRv() { if (rv) { rv.remove(); rv = null; } }
402
408
  const taskOf = (u) => (SC ? SC.tasks() : DATA ? DATA.tasks : []).find((t) => uidOf(t) === u) || null;
403
409
  async function press(e, emb) {
404
410
  const t0 = e.target;
405
- if (!emb && t0.closest('.sbo-band, [data-spall]') && await SP.press(e, spDeps())) return;
411
+ if (!emb && t0.closest('.sbo-band, .bk-past, [data-spall]') && await SP.press(e, spDeps())) return;
406
412
  const chip = t0.closest('[data-bkchip]');
407
413
  if (chip) { const k = chip.dataset.bkchip; if (k === 'all') CHIPS.clear(); else if (CHIPS.has(k)) CHIPS.delete(k); else CHIPS.add(k); draw(); const n = host.querySelector(`[data-bkchip="${k}"]`); if (n) n.focus(); return; }
408
414
  if (t0.closest('[data-bkall]')) { CHIPS.clear(); PICK = {}; SP.clearTheme(); draw(); return; }
@@ -485,7 +491,7 @@ function kindsPop(at) {
485
491
  * list (the rows of GET /api/backlog). After a press it calls api.reload(); the page reads again and draws listHtml anew. No tick boxes
486
492
  * and no bar in an embedded list: ticking is the Backlog's. */
487
493
  export function listHtml(tasks, o = {}) {
488
- const cols = (Array.isArray(o.cols) ? o.cols : COLS).filter((c) => COL[c]);
494
+ const cols = colsOf(tasks || [], (Array.isArray(o.cols) ? o.cols : COLS).filter((c) => COL[c]));
489
495
  const G = BM.groupsOf(tasks || [], { ini: o.ini, sort: o.sort || 'due', partB: o.partB !== false });
490
496
  const keep = FOLD, more = MORE;
491
497
  FOLD = o.fold || {}; MORE = o.more || new Set();