create-pmos 0.630.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.630.0",
3
+ "version": "0.631.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -33,6 +33,19 @@
33
33
  "audit"
34
34
  ],
35
35
  "pmosChanges": [
36
+ {
37
+ "v": "0.631.0",
38
+ "at": "2026-11-19T11:03:25.147Z",
39
+ "f": 4,
40
+ "prs": [
41
+ {
42
+ "n": 1412,
43
+ "t": "Keep a snapshot of every past sprint, with a sprint picker on the Backlog",
44
+ "s": "Keep a snapshot of every past sprint, with a sprint picker on the Backlog",
45
+ "k": "new"
46
+ }
47
+ ]
48
+ },
36
49
  {
37
50
  "v": "0.630.0",
38
51
  "at": "2026-11-19T08:05:45.827Z",
@@ -441,19 +454,6 @@
441
454
  "k": "new"
442
455
  }
443
456
  ]
444
- },
445
- {
446
- "v": "0.609.0",
447
- "at": "2026-11-18T14:50:56.888Z",
448
- "f": 4,
449
- "prs": [
450
- {
451
- "n": 1357,
452
- "t": "No Specimens line or prototype file once every version is deleted",
453
- "s": "No Specimens line or prototype file once every version is deleted",
454
- "k": "fix"
455
- }
456
- ]
457
457
  }
458
458
  ]
459
459
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@0ca33e7b
1
+ kernel-source: pmos@e295dc6f
2
2
  assembled: 2026-11-19
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-11-19T08:05:42Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-19T11:03:21Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-11-19T08:05:42Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-19T11:03:21Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-11-19T08:05:42Z"}
5
+ generated: {by: process:create-pmos, at: "2026-11-19T11:03:21Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -1,4 +1,17 @@
1
1
  [
2
+ {
3
+ "v": "0.631.0",
4
+ "at": "2026-11-19T11:03:25.147Z",
5
+ "f": 4,
6
+ "prs": [
7
+ {
8
+ "n": 1412,
9
+ "t": "Keep a snapshot of every past sprint, with a sprint picker on the Backlog",
10
+ "s": "Keep a snapshot of every past sprint, with a sprint picker on the Backlog",
11
+ "k": "new"
12
+ }
13
+ ]
14
+ },
2
15
  {
3
16
  "v": "0.630.0",
4
17
  "at": "2026-11-19T08:05:45.827Z",
@@ -603,6 +603,8 @@ The benchmark needs a signed-in agent CLI. It never pushes and never opens a pul
603
603
  - `pmos jira sync <initiative> --from <file|-> [--query "<jql>"] [--dry-run]`
604
604
  - `pmos jira query --sprints`
605
605
  - `pmos jira sync --sprints --from <file|-> [--query "<jql>"] [--dry-run]`
606
+ - `pmos jira query --sprint "<name>"`
607
+ - `pmos jira sync --sprint "<name>" --from <file|-> [--dry-run]`
606
608
  - `pmos jira summary [--from <file|->] [--dry-run]`
607
609
  - `pmos jira which <KEY>`
608
610
  - `pmos jira moves`
@@ -165,6 +165,19 @@ pmos jira query --sprints
165
165
  pmos jira sync --sprints --from <file|-> [--query "<jql>"]
166
166
  ```
167
167
 
168
+ ## Past sprints keep every ticket
169
+
170
+ Each sprint read also goes to an append-only history, `<state>/tracker/jira/_sprint-history.jsonl`. It has one line for each sprint at each read, written only when something changed. A ticket that Jira carried from one sprint to the next stays in both sprints. When a sprint closes, the first read after the close freezes it: later reads add nothing to it. PMOS counts the close numbers itself from this record (done, total, carried in, carried to the next sprint, points). The agent does not count them.
171
+
172
+ The read also asks for the open sprints of the tickets' Jira projects, and for the closed sprints whose tickets changed in the last 21 days. Thus a sprint that opened and closed between two reads is still kept.
173
+
174
+ On Work › Backlog › This sprint, the sprint's name is a picker. Pick a past sprint to see its snapshot and its tickets as they were at close. To keep a sprint that PMOS never saw, press the read icon on it. PMOS then reads that sprint from Jira:
175
+
176
+ ```
177
+ pmos jira query --sprint "<name>"
178
+ pmos jira sync --sprint "<name>" --from <file|->
179
+ ```
180
+
168
181
  ## Each sprint's goal and summary
169
182
 
170
183
  The check then writes a goal and a short summary for each sprint, from the tickets it read. The Sprints tab shows them above the sprint's items, with one row for each group of related work.
@@ -814,6 +814,22 @@ function sprintsOf(snapshots, onBoard = () => true, whole = null, notes = null,
814
814
  byName.set(n.name, { name: n.name, state: 'closed', start: n.start || null, end: n.end || null, issues, counts });
815
815
  }
816
816
  }
817
+ // The active sprint of the board's Jira projects, from the whole-sprint read, even when none of the board's initiatives holds a ticket
818
+ // in it (initiative sprint-snapshots: Sprint 118 was missing, the list came from the initiatives' reads only). opts.projects opts in.
819
+ if (Array.isArray(opts.projects) && opts.projects.length) {
820
+ const P = new Set(opts.projects.map((k) => String(k).toUpperCase()));
821
+ for (const t of wt) {
822
+ if (!t || !t.key || !t.sprint || !t.sprint.name || t.sprint.state !== 'active' || !P.has(String(t.key).split('-')[0].toUpperCase())) continue;
823
+ const name = String(t.sprint.name);
824
+ if (!byName.has(name)) { byName.set(name, { name, state: 'active', start: t.sprint.start || null, end: t.sprint.end || null, issues: [], counts: { todo: 0, doing: 0, done: 0 } }); any = true; }
825
+ const sp = byName.get(name);
826
+ if (sp.issues.some((i) => i.key === t.key)) continue;
827
+ const category = ['todo', 'doing', 'done'].includes(t.category) ? t.category : 'todo';
828
+ sp.issues.push({ key: t.key, summary: t.summary || '', status: t.status || '', category, initiative: null, flagged: !!t.flagged, reason: t.flagged && t.reason ? String(t.reason) : null, points: ptsOf(t), ...urlOf(t) });
829
+ sp.counts[category]++;
830
+ }
831
+ if (any && whole && whole.fetchedAt && (!readAt || whole.fetchedAt < readAt)) readAt = whole.fetchedAt;
832
+ }
817
833
  const jiraGoal = (sp) => {
818
834
  for (const t of wt) if (t && t.sprint && String(t.sprint.name) === sp.name && t.sprint.goal) return String(t.sprint.goal);
819
835
  for (const s of snapshots || []) for (const t of s && s.tickets instanceof Map ? s.tickets.values() : s && Array.isArray(s.tickets) ? s.tickets : []) if (t && t.sprint && String(t.sprint.name) === sp.name && t.sprint.goal) return String(t.sprint.goal);
@@ -12,6 +12,8 @@
12
12
  * pmos jira sync <initiative> --from <file|-> [--query "<jql>"] [--dry-run] a saved search → the status snapshot
13
13
  * pmos jira query --sprints the Jira search for every issue in the sprints the tickets are in
14
14
  * pmos jira sync --sprints --from <file|-> [--query "<jql>"] a saved whole-sprint search → the Sprints tab (jira-sprint-scope)
15
+ * pmos jira query --sprint "<name>" the Jira search for every ticket one sprint held (a sprint PMOS never saw)
16
+ * pmos jira sync --sprint "<name>" --from <file|-> keep that read as the sprint's snapshot (initiative sprint-snapshots)
15
17
  * pmos jira summary [--from <file|->] [--dry-run] the sprints to summarise, or save their goal and summary (sprint-goal-summary)
16
18
  * pmos jira which <KEY> [<KEY> …] the initiative a Jira key belongs to
17
19
  * pmos jira moves the status moves the PM asked in PMOS, not answered yet (lib/jira-moves.js)
@@ -45,6 +47,8 @@ const USAGE = [
45
47
  ' pmos jira sync <initiative> --from <file|-|a,b> [--query "<jql>"] [--dry-run] save the status read from Jira (a,b: one file per page)',
46
48
  ' pmos jira query --sprints the Jira search for every issue in those tickets\' sprints',
47
49
  ' pmos jira sync --sprints --from <file|-> [--query "<jql>"] save every issue of the sprints, for the Sprints tab',
50
+ ' pmos jira query --sprint "<name>" the Jira search for every ticket one sprint held',
51
+ ' pmos jira sync --sprint "<name>" --from <file|-> keep that read as the sprint\'s snapshot',
48
52
  ' pmos jira summary the sprints that need a goal and summary written',
49
53
  ' pmos jira summary --from <file|-> [--dry-run] save each sprint\'s goal, summary and themes (a closed sprint is kept once written)',
50
54
  ' pmos jira which <KEY> [<KEY> …] the initiative a Jira key belongs to',
@@ -54,7 +58,7 @@ const USAGE = [
54
58
  'This command never calls Jira. Your agent reads and writes Jira with your own connection.',
55
59
  ];
56
60
  const BOOL = new Set(['json', 'dry-run', 'help', 'sprints']);
57
- const VALUE = new Set(['from', 'query', 'root', 'epic', 'updated', 'group', 'status', 'refused']);
61
+ const VALUE = new Set(['from', 'query', 'root', 'epic', 'updated', 'group', 'status', 'refused', 'sprint']);
58
62
  const FLAG_TEXT = { 'prd-changed': 'PRD changed', removed: 'Removed from PRD', blocked: 'Blocked', incomplete: 'Missing text', pushing: 'Selected, waiting for the push', edited: 'Edited, not in Jira yet' };
59
63
 
60
64
  function parse(argv) {
@@ -113,6 +117,21 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
113
117
 
114
118
  try {
115
119
  if (flags.sprints && verb !== 'query' && verb !== 'sync') return fail('--sprints goes with query or sync', 2);
120
+ if (flags.sprint != null && verb !== 'query' && verb !== 'sync') return fail('--sprint goes with query or sync', 2);
121
+ if (verb === 'query' && flags.sprint != null) {
122
+ const q = jiraStatus.sprintQueryOne(root, flags.sprint);
123
+ if (!q.ok) return fail(q.error);
124
+ return out(q, [q.query]);
125
+ }
126
+ if (verb === 'sync' && flags.sprint != null) {
127
+ if (!flags.from) return need('--sprint "<name>" --from <file|->');
128
+ let raw;
129
+ try { raw = readSearch(flags.from, cwd, stdin); }
130
+ catch (e) { return fail(`could not read ${flags.from} as JSON — ${String((e && e.message) || e).slice(0, 160)}`); }
131
+ const r = jiraStatus.syncSprints(root, raw, { query: flags.query || undefined, dryRun: !!flags['dry-run'], now, backfill: flags.sprint });
132
+ if (!r.ok) return fail(r.error);
133
+ return out(r, [`${r.backfill} · kept ${r.read} ${r.read === 1 ? 'ticket' : 'tickets'}${r.ignored ? ` · ${r.ignored} not in it, ignored` : ''}${r.dryRun ? ' · dry run, nothing written' : ''}`, ...(r.dryRun ? [] : [`history ${r.snapshot}`])]);
134
+ }
116
135
  if (verb === 'query' && flags.sprints) {
117
136
  const q = jiraStatus.sprintQuery(root);
118
137
  return out(q, [q.linked ? q.query : q.kept.length ? 'every sprint is closed and summarised once — nothing to read' : 'no Jira reading has a sprint yet — run the initiatives\' searches first']);
@@ -126,6 +145,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
126
145
  if (!r.ok) return fail(r.error);
127
146
  const lines = [`sprints · read ${r.read} ${r.read === 1 ? 'issue' : 'issues'}${r.ignored ? ` · ${r.ignored} in no sprint, ignored` : ''}${r.skipped ? ` · ${r.skipped} skipped (no key or summary)` : ''}${r.dryRun ? ' · dry run, nothing written' : ''}`];
128
147
  for (const [name, n] of Object.entries(r.sprints)) lines.push(` ${name} · ${n} ${n === 1 ? 'issue' : 'issues'}`);
148
+ for (const name of r.closedNow || []) lines.push(` ${name} closed since the last read: write its summary now (pmos jira summary)`);
129
149
  if (!r.dryRun) lines.push(`snapshot ${r.snapshot}`);
130
150
  return out(r, lines);
131
151
  }
@@ -133,7 +153,8 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
133
153
  if (!flags.from) {
134
154
  const r = jiraStatus.sprintsToSummarise(root);
135
155
  if (!r.read) return out(r, ['no whole-sprint read yet — run pmos jira query --sprints and sync --sprints first']);
136
- const lines = r.sprints.map((s) => `${s.name}\t${s.state}\t${s.tickets} ${s.tickets === 1 ? 'issue' : 'issues'}\t${s.jiraGoal ? `goal in Jira: ${s.jiraGoal}` : 'no goal in Jira'}`);
156
+ const lines = r.sprints.map((s) => `${s.name}\t${s.state}\t${s.tickets} ${s.tickets === 1 ? 'issue' : 'issues'}\t${s.jiraGoal ? `goal in Jira: ${s.jiraGoal}` : 'no goal in Jira'}`
157
+ + (s.closed ? `\tat close (PMOS's count): ${s.closed.done} of ${s.closed.total} done${s.closed.carriedIn ? `, ${s.closed.carriedIn} carried in` : ''}${s.closed.carried ? `, ${s.closed.carried} carried to ${s.closed.carriedTo || 'the next sprint'}` : ''}` : ''));
137
158
  if (!lines.length) lines.push('no sprint needs a summary');
138
159
  for (const k of r.kept) lines.push(`${k}\tclosed\tkept, summarised once`);
139
160
  return out(r, lines);
@@ -151,13 +151,21 @@ function sprintOf(v) {
151
151
  return all.find((s) => s.state === 'active') || all.find((s) => s.state === 'future') || all[all.length - 1] || null;
152
152
  }
153
153
  /** Jira Cloud keeps the sprint in a custom field: any array of objects that carry a sprint's name and state. */
154
- function sprintIn(fields) {
155
- if ('sprint' in fields) return sprintOf(fields.sprint);
154
+ function sprintField(fields) {
155
+ if ('sprint' in fields) return fields.sprint;
156
156
  for (const v of Object.values(fields)) {
157
- if (Array.isArray(v) && v.length && v.every((x) => x && typeof x === 'object' && 'name' in x && 'state' in x && ('boardId' in x || 'id' in x))) return sprintOf(v);
157
+ if (Array.isArray(v) && v.length && v.every((x) => x && typeof x === 'object' && 'name' in x && 'state' in x && ('boardId' in x || 'id' in x))) return v;
158
158
  }
159
159
  return null;
160
160
  }
161
+ function sprintIn(fields) { const v = sprintField(fields); return v == null ? null : sprintOf(v); }
162
+ /** Every sprint the ticket was in, oldest first, when Jira gave more than one (initiative sprint-snapshots): a ticket carried from Sprint 114
163
+ * to 115 keeps 114 in its list, so the old sprint keeps it (lib/sprint-history.js). {} when there is one or none. */
164
+ function sprintsAll(v) {
165
+ if (!Array.isArray(v) || v.length < 2) return {};
166
+ const all = v.map(sprintOne).filter(Boolean).map((s) => { const { goal, ...rest } = s; void goal; return rest; });
167
+ return all.length > 1 ? { sprints: all } : {};
168
+ }
161
169
  function subtasksOf(v) {
162
170
  if (Array.isArray(v)) {
163
171
  const done = v.filter((s) => {
@@ -211,7 +219,7 @@ function normalizeIssue(x) {
211
219
  const st = f.status || {};
212
220
  const status = nameOf(st) || 'Unknown';
213
221
  const flagged = flaggedIn(f) || /block|impediment|on hold/i.test(status);
214
- return { key, summary, status, category: categoryOf(status, st.statusCategory), sprint: sprintIn(f), subtasks: subtasksOf(f.subtasks), fixVersion: fixVersionsOf(f.fixVersions),
222
+ return { key, summary, status, category: categoryOf(status, st.statusCategory), sprint: sprintIn(f), ...sprintsAll(sprintField(f)), subtasks: subtasksOf(f.subtasks), fixVersion: fixVersionsOf(f.fixVersions),
215
223
  points: pointsIn(f), resolved: dayOf(f.resolutiondate || f.resolved),
216
224
  flagged, reason: flagged ? (flaggedIn(f) ? 'Flagged in Jira' : `Status: ${status}`) : null, url: urlOf(x, key),
217
225
  ...typeParent(f.issuetype, f.parent), ...whoWhen(f.assignee, f.updated) };
@@ -221,7 +229,7 @@ function normalizeIssue(x) {
221
229
  if (!summary) return null;
222
230
  const status = oneLine(x.status) || 'Unknown';
223
231
  const flagged = x.flagged === true || /block|impediment|on hold/i.test(status);
224
- return { key, summary, status, category: categoryOf(status, x.category), sprint: sprintOf(x.sprint), subtasks: subtasksOf(x.subtasks), fixVersion: fixVersionsOf(x.fixVersions != null ? x.fixVersions : x.fixVersion),
232
+ return { key, summary, status, category: categoryOf(status, x.category), sprint: sprintOf(x.sprint), ...sprintsAll(x.sprints != null ? x.sprints : x.sprint), subtasks: subtasksOf(x.subtasks), fixVersion: fixVersionsOf(x.fixVersions != null ? x.fixVersions : x.fixVersion),
225
233
  points: pointsIn(x), resolved: dayOf(x.resolved || x.resolutiondate),
226
234
  flagged, reason: flagged ? clip(oneLine(x.reason || x.flag_reason || (x.flagged === true ? 'Flagged in Jira' : `Status: ${status}`)), 160) : null,
227
235
  url: urlOf(x, key), ...typeParent(x.type != null ? x.type : x.issuetype, x.parent), ...whoWhen(x.assignee, x.updated) };
@@ -340,6 +348,7 @@ function sync(root, initiative, raw, { query, dryRun = false, now } = {}) {
340
348
  // not the sprint. This second read asks Jira for every issue in the sprints those tickets are in, whoever holds them.
341
349
  const SPRINTS_FILE = '_sprints';
342
350
  const jqlName = (n) => `"${String(n).replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
351
+ const CLOSED_DAYS = 21; // a closed sprint is read again while its tickets changed in the last three weeks (initiative sprint-snapshots)
343
352
  function sprintQuery(root) {
344
353
  const frozen = frozenNotes(root);
345
354
  const seen = new Map(); const kept = new Set(); const projectKeys = new Set();
@@ -356,23 +365,42 @@ function sprintQuery(root) {
356
365
  }
357
366
  }
358
367
  const sprints = [...seen.values()].sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true }));
359
- if (!sprints.length) {
360
- // bug 2026-11-19: on a Jira site whose Sprint field is not the usual custom field, the initiatives' reads came back with no sprint,
361
- // so this said "no Jira reading has a sprint yet", the run skipped the sprint read, and the sprint band kept a 28 Oct read. When the
362
- // tickets carry no sprint, read the open sprints of their Jira projects instead.
363
- const projects = [...projectKeys].sort();
364
- if (projects.length && !kept.size) return { ok: true, linked: true, mode: 'open', projects, sprints, kept: [...kept], query: `project in (${projects.join(', ')}) AND sprint in openSprints() ORDER BY key` };
365
- return { ok: true, linked: false, sprints, kept: [...kept], query: null };
366
- }
367
- return { ok: true, linked: true, sprints, kept: [...kept], query: `sprint in (${sprints.map((s) => s.id || jqlName(s.name)).join(', ')}) ORDER BY key` };
368
+ const projects = [...projectKeys].sort();
369
+ // bug 2026-11-19: on a Jira site whose Sprint field is not the usual custom field, the initiatives' reads came back with no sprint, and
370
+ // the band kept a 28 Oct read; and a sprint that opened and closed between two reads was never read (116, 117). So the read always asks
371
+ // for the open sprints of the tickets' Jira projects, and for the closed ones whose tickets changed lately (initiative sprint-snapshots).
372
+ const proj = projects.length ? `project in (${projects.join(', ')}) AND (sprint in openSprints() OR (sprint in closedSprints() AND updated >= -${CLOSED_DAYS}d))` : null;
373
+ const ids = sprints.length ? `sprint in (${sprints.map((s) => s.id || jqlName(s.name)).join(', ')})` : null;
374
+ if (!proj && !ids) return { ok: true, linked: false, sprints, kept: [...kept], query: null };
375
+ const query = proj && ids ? `(${proj}) OR ${ids} ORDER BY key` : `${proj || ids} ORDER BY key`;
376
+ return { ok: true, linked: true, ...(ids ? {} : { mode: 'open' }), projects, sprints, kept: [...kept], query };
377
+ }
378
+ /** The search for one named sprint, every ticket it ever held (Jira's `sprint = X` matches a ticket carried out of it too): the
379
+ * "read it from Jira now" press of a sprint PMOS never saw (SpH3). → { ok, query } | { ok: false, error } */
380
+ function sprintQueryOne(root, name) {
381
+ const n = oneLine(name);
382
+ if (!n || n.length > 80) return { ok: false, error: 'name the sprint, as Jira names it (at most 80 characters)' };
383
+ const p = sprintQuery(root).projects || [];
384
+ return { ok: true, name: n, query: `${p.length ? `project in (${p.join(', ')}) AND ` : ''}sprint = ${jqlName(n)} ORDER BY key` };
368
385
  }
369
386
  /** Save a whole-sprint read. The read replaces the last one whole: an issue moved out of a sprint is gone from it. A closed
370
387
  * sprint that has its summary is not searched again, so its issues are kept from the last read. */
371
- function syncSprints(root, raw, { query, dryRun = false, now } = {}) {
388
+ function syncSprints(root, raw, { query, dryRun = false, now, backfill = null } = {}) {
372
389
  const n = normalize(raw);
373
390
  if (n.error) return { ok: false, error: n.error };
374
- const kept = n.issues.filter((i) => i.sprint && i.sprint.name);
375
391
  const fetchedAt = nowIso(now);
392
+ // every read also goes to the append-only sprint history, which keeps every ticket a sprint held (initiative sprint-snapshots)
393
+ const SH = require('./sprint-history.js');
394
+ if (backfill) {
395
+ // "read it from Jira now" for one closed sprint (SpH3): only the history takes it; the whole-sprint read stays as it was
396
+ const name = oneLine(backfill);
397
+ const mine = n.issues.map((i) => ({ ...i, sprints: (i.sprints && i.sprints.length ? i.sprints : i.sprint ? [i.sprint] : []).map((s) => (s.name === name ? { ...s, state: 'closed' } : s)) }))
398
+ .filter((i) => i.sprints.some((s) => s.name === name));
399
+ const h = SH.append(root, mine, { at: fetchedAt, backfill: name, dryRun });
400
+ return { ok: true, backfill: name, read: mine.length, ignored: n.issues.length - mine.length, skipped: n.skipped, sprints: { [name]: mine.length }, history: h, snapshot: jiraTickets.relOf(root, SH.fileOf(root)), dryRun: !!dryRun, fetchedAt };
401
+ }
402
+ const history = SH.append(root, n.issues, { at: fetchedAt, dryRun });
403
+ const kept = n.issues.filter((i) => i.sprint && i.sprint.name);
376
404
  const prev = readSprints(root);
377
405
  const frozen = frozenNotes(root);
378
406
  if (prev && frozen.length) {
@@ -382,7 +410,7 @@ function syncSprints(root, raw, { query, dryRun = false, now } = {}) {
382
410
  const bySprint = {};
383
411
  for (const i of kept) bySprint[i.sprint.name] = (bySprint[i.sprint.name] || 0) + 1;
384
412
  const result = { ok: true, read: kept.length, ignored: n.issues.length - kept.length, skipped: n.skipped, sprints: bySprint,
385
- was: prev ? prev.tickets.size : null, snapshot: snapshotRel(root, SPRINTS_FILE), dryRun: !!dryRun };
413
+ was: prev ? prev.tickets.size : null, snapshot: snapshotRel(root, SPRINTS_FILE), history, closedNow: history.closedNow, dryRun: !!dryRun };
386
414
  if (dryRun) return result;
387
415
  const file = snapshotPath(root, SPRINTS_FILE);
388
416
  fs.mkdirSync(path.dirname(file), { recursive: true });
@@ -468,7 +496,9 @@ function noteOne(x) {
468
496
  if (tickets == null) return { error: `${name}: theme "${title}" needs a ticket count` };
469
497
  const ini = t.initiative == null || t.initiative === '' ? null : String(t.initiative).trim();
470
498
  if (ini != null && !INI_RE.test(ini)) return { error: `${name}: theme "${title}" has a bad initiative id` };
471
- themes.push({ title, line: text(t.line, 200), tickets, done: Math.min(count(t.done) || 0, tickets), blocked: Math.min(count(t.blocked) || 0, tickets), people: text(t.people, 80), initiative: ini });
499
+ // the theme's ticket keys, when the agent gave them: a closed sprint's snapshot lists a theme's tickets on a press (SpH2)
500
+ const keys = Array.isArray(t.keys) ? [...new Set(t.keys.map((k) => oneLine(k).toUpperCase()).filter((k) => KEY_RE.test(k)))].slice(0, 300) : [];
501
+ themes.push({ title, line: text(t.line, 200), tickets, done: Math.min(count(t.done) || 0, tickets), blocked: Math.min(count(t.blocked) || 0, tickets), people: text(t.people, 80), initiative: ini, ...(keys.length ? { keys } : {}) });
472
502
  }
473
503
  const note = { name, state, goal, summary, themes };
474
504
  // The sprint brief (sprint-goal-summary, mockup-c3-sprint-brief): where the sprint stands, the issues to resolve with a proposed
@@ -505,9 +535,19 @@ function sprintsToSummarise(root) {
505
535
  o.tickets++;
506
536
  if (!o.jiraGoal && sp.goal) o.jiraGoal = sp.goal;
507
537
  }
538
+ // a sprint PMOS saw open and then closed is summarised at close from the kept record, carried-in tickets included, even when the
539
+ // whole-sprint read no longer holds it (initiative sprint-snapshots; Sprint 115's "21 of 23" left out the 56 carried in)
540
+ const SH = require('./sprint-history.js');
541
+ const H = SH.read(root);
542
+ for (const name of new Set(H.map((l) => l.sprint.name))) {
543
+ const c = SH.closeOf(H, name);
544
+ if (!c) continue;
545
+ if (!by.has(name)) by.set(name, { name, state: 'closed', tickets: c.total, jiraGoal: null });
546
+ const o = by.get(name); o.state = 'closed'; o.tickets = c.total; o.closed = c;
547
+ }
508
548
  const all = [...by.values()].sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true }));
509
549
  const isKept = (s) => frozen.some((f) => sameSprint(f, s)); // the note was written when Jira said closed
510
- return { ok: true, read: !!whole, sprints: all.filter((s) => !isKept(s)), kept: all.filter(isKept).map((s) => s.name) };
550
+ return { ok: true, read: !!whole || H.length > 0, sprints: all.filter((s) => !isKept(s)), kept: all.filter(isKept).map((s) => s.name) };
511
551
  }
512
552
  /** Save the notes the agent wrote. A closed sprint already noted keeps its first note. A bad note refuses the whole file. */
513
553
  function saveSprintNotes(root, raw, { dryRun = false, now } = {}) {
@@ -521,7 +561,11 @@ function saveSprintNotes(root, raw, { dryRun = false, now } = {}) {
521
561
  const wt = whole ? [...whole.tickets.values()] : [];
522
562
  const writtenAt = nowIso(now);
523
563
  const saved = []; const kept = [];
564
+ let H = null; try { H = require('./sprint-history.js').read(root); } catch { H = []; }
524
565
  for (const n of got) {
566
+ // a closed sprint PMOS kept from open to close: the close numbers are PMOS's own count, never the agent's (initiative sprint-snapshots)
567
+ const own = n.state === 'closed' ? require('./sprint-history.js').closeOf(H, n.name) : null;
568
+ if (own) n.closed = { done: own.done, total: own.total, carried: own.carried, carriedTo: own.carriedTo || (n.closed && n.closed.carriedTo) || null, carriedIn: own.carriedIn, points: own.points || (n.closed && n.closed.points) || null };
525
569
  const i = notes.findIndex((o) => sameSprint(o, n));
526
570
  if (i >= 0 && notes[i].state === 'closed') { kept.push(n.name); continue; }
527
571
  const mine = wt.filter((t) => t.sprint && sameSprint(t.sprint, n));
@@ -562,5 +606,5 @@ function which(root, key) {
562
606
  return { ok: true, key: k, initiatives: hits };
563
607
  }
564
608
 
565
- module.exports = { queryFor, linkedInitiatives, normalize, sync, readSnapshot, findTicket, which, sprintLabel, snapshotPath, snapshotRel, sprintQuery, syncSprints, readSprints, SPRINTS_FILE,
609
+ module.exports = { queryFor, linkedInitiatives, normalize, sync, readSnapshot, findTicket, which, sprintLabel, snapshotPath, snapshotRel, sprintQuery, sprintQueryOne, syncSprints, readSprints, SPRINTS_FILE,
566
610
  sprintsToSummarise, saveSprintNotes, readSprintNotes, sameSprint, noteOne, NOTES_FILE };
@@ -15,6 +15,9 @@
15
15
  * POST /api/backlog/undo { ws, board, task } the Undo of "Done by PMOS today": the task is open again, PMOS's result stays
16
16
  * in the day run for the record
17
17
  * POST /api/backlog/decline { ws, board, task, undo? } ✕ on "PMOS can take these": not for PMOS (and its Undo)
18
+ * GET /api/backlog/sprint?ws=&board=&sprint= → { ok, sprint } one sprint as PMOS kept it (initiative sprint-snapshots; SpH2, SpH3):
19
+ * lib/sprint-history.js detailOf. GET /api/backlog also carries sprintList (the picker, SpH1) and
20
+ * sprintTrend (the carried-over line and bars).
18
21
  * POST /api/backlog/place { ws, board, key, to } a No home Jira ticket into an initiative (a ticket-move line on the board
19
22
  * ledger, as a split or merge writes it; Jira is not written to, D88). to '' takes it back out.
20
23
  *
@@ -30,6 +33,7 @@ const dayRun = require('./day-run.js');
30
33
  const assigned = require('./work-assigned.js');
31
34
  const WK = require('./work-kind.js');
32
35
  const SO = require('./sprint-overview.js');
36
+ const SH = require('./sprint-history.js');
33
37
  /** The PM's own name for Who (PMOS_PM_NAME, else git's user.name: the name Home greets them by); '' when neither is set. */
34
38
  const pmNameOf = () => { try { return require('./routes-board-publish.js').sharedBy() || ''; } catch { return ''; } };
35
39
 
@@ -122,10 +126,25 @@ function listOf(ctx, wsId, boardId, now) {
122
126
  // the product's display name ("IDPF"), not its folder id ("pmos-idpf"): the board's own name first
123
127
  const product = board.name || board.product || w.name || w.id;
124
128
  let sprintNotes = {}; try { sprintNotes = SO.foldNotes(SO.readNotes(ctx), w.id, board.id); } catch { sprintNotes = {}; }
125
- return { ok: true, ws: w.id, board: board.id, product, mode, sprintNotes, modeLabel: BL.MODE_LABEL[mode], kinds: BL.countKinds(inis.map((x) => x.kind)), factory, readAt, today,
129
+ const sin = sprintInputs(w, board, sprintNotes, tasks, jiraStatus);
130
+ let sprintList = [], sprintTrend = null;
131
+ try { sprintList = SH.listOf(sin); sprintTrend = SH.trendOf(sprintList); } catch { sprintList = []; sprintTrend = null; }
132
+ return { ok: true, ws: w.id, board: board.id, product, mode, sprintNotes, sprintList, sprintTrend, _sin: sin, modeLabel: BL.MODE_LABEL[mode], kinds: BL.countKinds(inis.map((x) => x.kind)), factory, readAt, today,
126
133
  tasks, inis: inis.map((x) => ({ id: x.id, title: x.title, kind: x.kind })), _w: w, _RB: RB, _runTasks: runTasks };
127
134
  }
128
135
 
136
+ /** What lib/sprint-history.js needs for one board: the kept record, the Jira sprint notes, the whole-sprint read, the PM's notes, and the
137
+ * board's Jira projects (its setting, else the keys of its tickets). */
138
+ function sprintInputs(w, board, pmNotes, tasks, jiraStatus) {
139
+ const read = (f) => { try { return f(); } catch { return null; } };
140
+ const projects = new Set();
141
+ const set = board.jira ? (Array.isArray(board.jira) ? board.jira : [board.jira]) : [];
142
+ for (const k of set) if (typeof k === 'string' && k) projects.add(k.toUpperCase());
143
+ if (!projects.size) for (const t of tasks || []) if (t.key) projects.add(String(t.key).split('-')[0].toUpperCase());
144
+ const notes = read(() => jiraStatus.readSprintNotes(w.root));
145
+ return { lines: read(() => SH.read(w.root)) || [], notes: notes ? notes.notes : [], whole: read(() => jiraStatus.readSprints(w.root)), pmNotes: pmNotes || {}, projects: [...projects] };
146
+ }
147
+
129
148
  /** A task PMOS finished by itself (or the PM approved) is closed in PMOS, once: the same write as `pmos task state --to Done`, as the agent. */
130
149
  function settle(ctx, L) {
131
150
  for (const t of L.tasks) {
@@ -137,7 +156,7 @@ function settle(ctx, L) {
137
156
  }
138
157
  }
139
158
 
140
- const strip = (L) => { const { _w, _RB, _runTasks, ...rest } = L; void _w; void _RB; void _runTasks; return rest; };
159
+ const strip = (L) => { const { _w, _RB, _runTasks, _sin, ...rest } = L; void _w; void _RB; void _runTasks; void _sin; return rest; };
141
160
 
142
161
  /** What a give asks the agent to do, written for it. */
143
162
  function specOf(t, take, id) {
@@ -170,6 +189,15 @@ async function handle(req, res, url, ctx) {
170
189
  try { settle(ctx, L); } catch { /* the next read tries again */ }
171
190
  return send({ status: 200, body: strip(L) });
172
191
  }
192
+ if (sub === 'sprint' && req.method === 'GET') {
193
+ const L = listOf(ctx, url.searchParams.get('ws') || null, url.searchParams.get('board') || null, now);
194
+ if (L.pending) return send({ status: 202, body: { ok: true, pending: true, ws: L.ws, board: L.board } });
195
+ if (!L.ok) return send(bad(L.status || 500, L.error));
196
+ const name = text(url.searchParams.get('sprint')).slice(0, 120);
197
+ const d = name ? SH.detailOf(name, L._sin) : null;
198
+ if (!d) return send(bad(404, 'PMOS knows no sprint of that name on this board'));
199
+ return send({ status: 200, body: { ok: true, ws: L.ws, board: L.board, sprint: d } });
200
+ }
173
201
  if (!['give', 'stop', 'decide', 'undo', 'decline', 'place', 'sprint-draft', 'sprint-note'].includes(sub)) return send(bad(404, 'no such route'));
174
202
  if (req.method !== 'POST') return send(bad(405, 'POST only'));
175
203
  const read = await ctx.readJson(req);
@@ -189,7 +217,9 @@ async function handle(req, res, url, ctx) {
189
217
  if (sub === 'sprint-draft' || sub === 'sprint-note') {
190
218
  const sprint = text(body.sprint).slice(0, 120);
191
219
  const T = L.tasks.filter((t) => t.sprint && t.sprint.state === 'active' && t.sprint.name === sprint && t.key);
192
- if (!sprint || !T.length) return send(bad(404, 'no active sprint of that name on this board'));
220
+ // a past sprint takes notes too: What happened and Lessons, kept with its snapshot (initiative sprint-snapshots)
221
+ const past = sub === 'sprint-note' && !T.length && (L.sprintList || []).some((x) => x.name === sprint && x.state === 'closed');
222
+ if (!sprint || (!T.length && !past)) return send(bad(404, 'no active sprint of that name on this board'));
193
223
  if (sub === 'sprint-draft') {
194
224
  const tickets = T.map((t) => ({ key: t.key, title: t.title, state: t.state, parent: t.epic ? t.epic.name || t.epic.key : '' }));
195
225
  const r = SO.draft(ctx, tickets, { again: body.again === true });
@@ -197,7 +227,7 @@ async function handle(req, res, url, ctx) {
197
227
  }
198
228
  const ev = text(body.ev), block = text(body.block), id = text(body.id).slice(0, 200);
199
229
  if (!['note', 'clear', 'keep', 'dismiss', 'undismiss'].includes(ev)) return send(bad(400, 'ev is note, clear, keep, dismiss or undismiss'));
200
- if (['note', 'clear', 'keep'].includes(ev) && !SO.BLOCKS.includes(block)) return send(bad(400, 'block is goals, doing or next'));
230
+ if (['note', 'clear', 'keep'].includes(ev) && !SO.BLOCKS.includes(block)) return send(bad(400, 'block is goals, doing, next, happened or lessons'));
201
231
  if ((ev === 'dismiss' || ev === 'undismiss') && !id) return send(bad(400, 'id names the proposal'));
202
232
  const words = typeof body.text === 'string' ? body.text.split('\n').map((x) => x.trim()).filter(Boolean).slice(0, 8).map((x) => x.slice(0, 200)).join('\n') : '';
203
233
  if (ev === 'note' && !words) return send(bad(400, 'text is the block as you wrote it, one point a line'));
@@ -1020,7 +1020,10 @@ const READS = {
1020
1020
  try { whole = jiraStatus.readSprints(r.w.root); } catch { whole = null; }
1021
1021
  let notes = null;
1022
1022
  try { notes = jiraStatus.readSprintNotes(r.w.root); } catch { notes = null; }
1023
- ctx.json(res, { ok: true, ws: r.w.id, board: r.board.id, ...B.sprintsOf(snaps, (id) => ids.has(id), whole, notes), backlog: B.backlogOf(snaps, (id) => ids.has(id), whole) });
1023
+ // the board's Jira projects (its setting, else its tickets' keys): their active sprint is listed even when no initiative holds a ticket in it
1024
+ const projects = new Set(B.jiraProjectsOf(r.board));
1025
+ if (!projects.size) for (const s of snaps) if (ids.has(s.initiative)) for (const k of s.tickets.keys()) projects.add(String(k).split('-')[0].toUpperCase());
1026
+ ctx.json(res, { ok: true, ws: r.w.id, board: r.board.id, ...B.sprintsOf(snaps, (id) => ids.has(id), whole, notes, { projects: [...projects] }), backlog: B.backlogOf(snaps, (id) => ids.has(id), whole) });
1024
1027
  },
1025
1028
  };
1026
1029
 
@@ -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;