create-pmos 0.492.0 → 0.494.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.
Files changed (102) hide show
  1. package/package.json +75 -27
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/mods/pmos-cockpit/README.md +1 -1
  4. package/payload/mods/pmos-cockpit/hooks/lib/guard.mjs +2 -2
  5. package/payload/planning/evals/eval-calibration.md +1 -1
  6. package/payload/planning/okrs/health-budgets.md +1 -1
  7. package/payload/state/discoveries.md +1 -1
  8. package/workspace/briefing-premium-initiative-test.js +2 -1
  9. package/workspace/changelog.json +74 -0
  10. package/workspace/fixtures/initiatives-api/list.json +0 -4
  11. package/workspace/fixtures/initiatives-api/roadmap.json +255 -275
  12. package/workspace/fixtures/initiatives-api/sheet.json +2 -3
  13. package/workspace/fixtures/report-api/draft.json +4 -4
  14. package/workspace/fixtures/reports-page/draft-biweekly-2026-10-16.md +4 -4
  15. package/workspace/guide/board.md +2 -2
  16. package/workspace/guide/briefing-premium.md +2 -0
  17. package/workspace/guide/claude-proposes.md +2 -2
  18. package/workspace/guide/data-freshness.md +3 -1
  19. package/workspace/guide/index.md +2 -2
  20. package/workspace/guide/initiative-boards.md +2 -2
  21. package/workspace/guide/initiatives-roadmap.md +38 -39
  22. package/workspace/guide/initiatives-screen.md +22 -20
  23. package/workspace/guide/initiatives-timeline.md +7 -9
  24. package/workspace/guide/integrated-work.md +7 -8
  25. package/workspace/guide/layout.md +2 -2
  26. package/workspace/guide/lifecycle.md +2 -2
  27. package/workspace/guide/notes.md +1 -1
  28. package/workspace/guide/pm-only-acts.md +5 -5
  29. package/workspace/guide/pm-only-lines.md +3 -3
  30. package/workspace/guide/report-slides.md +14 -1
  31. package/workspace/guide/reports.md +4 -2
  32. package/workspace/guide/today.md +2 -2
  33. package/workspace/guide/your-impact.md +6 -7
  34. package/workspace/lib/board-cli.js +1 -1
  35. package/workspace/lib/board-fold.js +6 -6
  36. package/workspace/lib/board-premium.js +3 -3
  37. package/workspace/lib/board-trail.js +30 -3
  38. package/workspace/lib/calendar-tidy.js +1 -1
  39. package/workspace/lib/core-docs.js +2 -2
  40. package/workspace/lib/engine/boards.js +11 -11
  41. package/workspace/lib/engine/signals/detectors.js +13 -13
  42. package/workspace/lib/engine/signals/facts.js +5 -3
  43. package/workspace/lib/git-shape.js +21 -0
  44. package/workspace/lib/grill-runs.js +21 -6
  45. package/workspace/lib/grill.js +1 -1
  46. package/workspace/lib/health-rules-factory.js +13 -14
  47. package/workspace/lib/health-rules-plan.js +8 -7
  48. package/workspace/lib/impact.js +29 -16
  49. package/workspace/lib/initiative-cli.js +59 -63
  50. package/workspace/lib/initiative-needs.js +6 -6
  51. package/workspace/lib/initiative-premium.js +2 -2
  52. package/workspace/lib/initiative-writer.js +2 -2
  53. package/workspace/lib/lifecycle-stage.js +39 -0
  54. package/workspace/lib/page-warm.js +68 -0
  55. package/workspace/lib/placements.js +117 -95
  56. package/workspace/lib/plan-rules.js +7 -5
  57. package/workspace/lib/pm-guard.js +1 -3
  58. package/workspace/lib/pm-lines-needs.js +1 -1
  59. package/workspace/lib/report-design.js +6 -1
  60. package/workspace/lib/report-draft.js +17 -16
  61. package/workspace/lib/report-export.js +148 -9
  62. package/workspace/lib/report-pyramid.js +434 -0
  63. package/workspace/lib/report-slides-data.js +11 -7
  64. package/workspace/lib/report-structure.js +5 -1
  65. package/workspace/lib/report-templates.js +81 -20
  66. package/workspace/lib/routes-boards.js +9 -8
  67. package/workspace/lib/routes-brief-page.js +20 -3
  68. package/workspace/lib/routes-grill.js +10 -4
  69. package/workspace/lib/routes-impact.js +12 -4
  70. package/workspace/lib/routes-initiatives.js +29 -43
  71. package/workspace/lib/routes-notes.js +24 -15
  72. package/workspace/lib/routes-programs.js +6 -4
  73. package/workspace/lib/routes-report-design.js +15 -0
  74. package/workspace/lib/routes-report-flow.js +106 -17
  75. package/workspace/lib/routes-report-setups.js +2 -1
  76. package/workspace/lib/routes-report-structure.js +3 -0
  77. package/workspace/lib/split-merge.js +2 -3
  78. package/workspace/lib/wf-bridge.js +5 -3
  79. package/workspace/package-lock.json +2 -2
  80. package/workspace/package.json +1 -1
  81. package/workspace/premium-chat-report-tab-test.js +5 -1
  82. package/workspace/public/pm/cozy-vw-rp.css +12 -0
  83. package/workspace/public/pm/fetch-share.js +38 -0
  84. package/workspace/public/pm/home-app.js +21 -3
  85. package/workspace/public/pm/home-chat.js +5 -4
  86. package/workspace/public/pm/home-impact.css +23 -13
  87. package/workspace/public/pm/home-impact.js +49 -32
  88. package/workspace/public/pm/home-ini.css +2 -0
  89. package/workspace/public/pm/http.js +1 -1
  90. package/workspace/public/pm/ini-view.css +55 -0
  91. package/workspace/public/pm/ini-view.js +5 -2
  92. package/workspace/public/pm/premium-board.js +1 -0
  93. package/workspace/public/pm/premium-insights.js +1 -0
  94. package/workspace/public/pm/premium-report-read.js +25 -6
  95. package/workspace/public/pm/premium-report-tab.js +69 -14
  96. package/workspace/public/pm/report-flow.js +93 -10
  97. package/workspace/public/pm/view-notes.js +8 -8
  98. package/workspace/replaced-tests.json +14 -0
  99. package/workspace/server.js +24 -3
  100. package/workspace/skills/report-template.skill +8 -0
  101. package/workspace/test-lists/page-open-speed.json +5 -0
  102. package/workspace/test-lists/report-pyramid.json +9 -0
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+ /* page-warm.js — the first page after a start opens as fast as a later one (page-open-speed).
3
+ *
4
+ * warm({ host, port, paths, env, get }) → Promise<{ ran, ok } | { skipped }>
5
+ *
6
+ * Nothing is read until a page asks, so the first Home after PMOS starts made the server read every record cold: about 3 s against
7
+ * about 1.5 s for a later open (bench on the PM's data, 2026-11-02). A few seconds after the start, the server asks itself for the
8
+ * heaviest answers Home and the Board read, ONE AT A TIME over loopback, exactly as a page asks for them, so their read caches are
9
+ * filled before the PM opens a page. Only GET routes that write no "seen" or "read" mark are on the list: a warm-up is not the PM
10
+ * looking. PMOS_WARM=off stops it; a state folder under the system temp folder (a suite's) does not warm unless PMOS_WARM=on. */
11
+ const PATHS = [
12
+ '/api/board-premium',
13
+ '/api/my-work-premium',
14
+ '/api/news-for-you',
15
+ '/api/briefing-premium/products',
16
+ '/api/programs',
17
+ '/api/sources',
18
+ '/api/notes',
19
+ '/api/live',
20
+ '/api/insights-premium',
21
+ ];
22
+
23
+ function httpGet(host, port, p) {
24
+ return new Promise((resolve) => {
25
+ const req = require('http').get({ host, port, path: p, headers: { accept: 'application/json' }, timeout: 30000 }, (res) => {
26
+ res.resume(); res.on('end', () => resolve(res.statusCode)); res.on('error', () => resolve(0));
27
+ });
28
+ req.on('timeout', () => { req.destroy(); resolve(0); });
29
+ req.on('error', () => resolve(0));
30
+ });
31
+ }
32
+
33
+ async function warm({ host, port, paths = PATHS, env = process.env, get = httpGet } = {}) {
34
+ if (String(env.PMOS_WARM || '').toLowerCase() === 'off') return { skipped: 'off' };
35
+ if (!host || !port) return { skipped: 'no loopback address' };
36
+ let ok = 0;
37
+ for (const p of paths) { const code = await get(host, port, p); if (code >= 200 && code < 300) ok++; }
38
+ return { ran: paths.length, ok };
39
+ }
40
+
41
+ /** The loopback address among the server's binds, or null when it listens on none (a tailnet-only bind is not asked). */
42
+ function loopbackOf(binds) {
43
+ const b = (binds || []).find((a) => a === '127.0.0.1' || a === 'localhost' || a === '::1' || a === '0.0.0.0' || a === '::');
44
+ if (!b) return null;
45
+ return b === '::1' || b === '::' ? '::1' : '127.0.0.1';
46
+ }
47
+
48
+ /** The server's wiring: when `start`, one warm-up DELAY_MS after the boot (the server is listening by then; a request that finds it not
49
+ * yet up just fails and the page reads as before). The timer is unref'd, so it never holds a process open. */
50
+ const DELAY_MS = 5000;
51
+ /** Whether a start warms: PMOS_WARM=on or off decides; unset, a state folder under the system temp folder (every suite's, test-run.js)
52
+ * does not warm, so no suite's server reads, or writes a forecast line, while the suite does. The PM's own state folder warms. */
53
+ function shouldWarm(env, stateDir) {
54
+ const v = String(env.PMOS_WARM || '').toLowerCase();
55
+ if (v === 'off') return false;
56
+ if (v === 'on') return true;
57
+ if (!stateDir) return true;
58
+ const os = require('os'), path = require('path');
59
+ const rel = path.relative(path.resolve(os.tmpdir()), path.resolve(stateDir));
60
+ return !(rel && !rel.startsWith('..') && !path.isAbsolute(rel));
61
+ }
62
+ function create({ binds, port, stateDir = null, start = true, env = process.env, delayMs = DELAY_MS } = {}) {
63
+ const run = () => warm({ host: loopbackOf(binds), port: typeof port === 'function' ? port() : port, env }).catch(() => ({ failed: true }));
64
+ if (start && shouldWarm(env, stateDir)) { const t = setTimeout(run, delayMs); if (t.unref) t.unref(); }
65
+ return { run };
66
+ }
67
+
68
+ module.exports = { create, warm, shouldWarm, loopbackOf, PATHS };
@@ -1,62 +1,65 @@
1
1
  'use strict';
2
- /* placements.js — THE ONE WRITER and THE ONE FOLD of placements.jsonl: where each initiative sits on the Roadmap
3
- * (Now, Next, Later), in what order, and its check-by date (pm-os-absorb, PRD R20 A, R23, R24, R26; D86).
2
+ /* placements.js — THE ONE WRITER and THE ONE FOLD of placements.jsonl: where each initiative ranks on the Roadmap, and
3
+ * its check-by date (pm-os-absorb, PRD R20 A, R23, R24, R26; D86; D105).
4
+ *
5
+ * D105 (2026-11-02) retired Now / Next / Later. The Roadmap is ONE ranked list: Prioritize's output, "Ranked on the
6
+ * roadmap". The lifecycle stage (Triage … Evaluate) says where an initiative is; the rank says what comes first.
4
7
  *
5
8
  * readPlacements(root, { now, rules, records }) → {
6
9
  * ok: true,
7
- * byInit: { [id]: { horizon: 'now'|'next'|'later', rank, after, check_by, confirmed, dormant, source } },
8
- * order: { now: [id…], next: [id…], later: [id…] }, ranked, first is top
9
- * proposals: [{ eid, init, horizon, after, by, at }], agent lines (proposed:true) not yet adopted or dropped
10
- * moves: [{ init, from, to, at, by, via }], every horizon change, oldest first
10
+ * byInit: { [id]: { rank, after, check_by, confirmed, dormant, source } },
11
+ * ranked: [id…], the one Roadmap order, first is top
12
+ * proposals: [{ eid, init, after, by, at }], agent lines (proposed:true) not yet adopted or dropped
13
+ * moves: [{ init, from, to, at, by, via }], every applied line, oldest first: rank before and after (1 = top)
11
14
  * flags: [{ kind, eid, init, why }],
12
15
  * }
13
- * horizonOf(result, id) → the initiative's horizon; 'later' when it has no placement
16
+ * rankOf(result, id) → the initiative's rank (0 = top), or null when it has no place
14
17
  * appendFromUi(root, events, { actor, now }) → { ok, written, lines } | { ok: false, status, error, index }
15
18
  * appendFromCli(root, events, { actor, now }) → the same
16
19
  *
17
20
  * `records` is the list of workflow rows ({ id, lane, last_activity, accepted, stopped, group? }, scripts/workflow-state.js
18
- * --json) the day-one derivation (R26) reads; `rules` is lib/plan-rules.js readRules(root). A consumer that needs a
19
- * horizon reads it through horizonOf, never from the file.
21
+ * --json) the day-one derivation (R26) reads; `rules` is lib/plan-rules.js readRules(root).
22
+ *
23
+ * The actor is never chosen by the caller of a route: the route takes it from actor.js (or pm-guard.js for adopt); the
24
+ * CLI from actor.fromCli or requirePmCli. D98: an agent's line applies like the PM's and keeps the agent's `by`, so the
25
+ * PM sees who moved what and can move it back.
20
26
  *
21
- * The actor is never chosen by the caller of a route: the route takes it from pm-guard.js (Move to Now, adopt) or
22
- * actor.js (every other press); the CLI from actor.fromCli or requirePmCli. D98: an agent's line applies like the PM's
23
- * (Now and adopt included) and keeps the agent's `by`, so the PM sees who moved what and can move it back. The writer
24
- * no longer writes `proposed: true`; such a line from before D98 stays a proposal until it is adopted or dropped.
27
+ * THE `ranked` LINE (D105; what the writer writes now):
28
+ * { v: 1, eid, ev: 'ranked', initiative, after: <initiative id> | null, check_by?: 'YYYY-MM-DD' | null, by, via, at }
29
+ * `after: null` is the top of the Roadmap; an `after` that is not on the Roadmap puts it at the end. A line without
30
+ * `check_by` keeps the previous one; `check_by: null` clears it.
25
31
  *
26
- * THE `placed` LINE (the shared contract; 2C may add events, never change this one):
27
- * { v: 1, eid, ev: 'placed', initiative, horizon: 'now'|'next'|'later', after: <initiative id> | null,
28
- * check_by?: 'YYYY-MM-DD' | null, proposed?: true, by, via, at }
29
- * `after: null` is the top of the horizon; an `after` that is not in that horizon puts it at the end. A line without
30
- * `check_by` keeps the previous one; `check_by: null` clears it. A `proposed` line moves nothing: it is a proposal.
32
+ * THE OLD `placed` LINE (before D105; read, never written again, never rewritten):
33
+ * { v: 1, eid, ev: 'placed', initiative, horizon: 'now'|'next'|'later', after, check_by?, proposed?, by, via, at }
34
+ * The fold keeps the order such a line gave: every row carries the band of the horizon it was last placed in (Now 0,
35
+ * Next 1, Later 2) and the one list stays sorted by band, so the old Now rows come first, then Next, then Later, each
36
+ * in its old order. A `placed` line goes where it went before inside its band. A `ranked` line takes the band of the
37
+ * row it comes after (the top is band 0), so it never breaks that order. Nothing in the ledger changes: the mapping is
38
+ * made at read time, and nothing that was ranked is lost. The writer refuses a new `placed` line.
31
39
  *
32
- * THE EVENTS 2C ADDED (each with the same envelope):
33
- * { ev: 'created', initiative, from?: 'capture-YYYY-MM-DD-<n>' } the initiative writer's landing line: top of
34
- * Later, so a new record never reads Now through day one (R16, R23: what an agent creates lands in Later).
35
- * Any actor; only for an initiative with no line yet. `from` names the capture it came from (triage reads it).
36
- * { ev: 'adopted', proposal: <eid> } the PM or an agent keeps an open proposal: its placement applies.
40
+ * THE OTHER EVENTS (each with the same envelope):
41
+ * { ev: 'created', initiative, from?: 'capture-YYYY-MM-DD-<n>' } the initiative writer's landing line: the end of
42
+ * the Roadmap (R16, R23). Any actor; only for an initiative with no line yet. `from` names the capture it came from.
43
+ * { ev: 'adopted', proposal: <eid> } the PM keeps an open proposal (written before D98): its placement applies.
37
44
  * { ev: 'dropped', proposal: <eid> } the proposal is closed unapplied (the PM or any agent, D98).
38
- * pmOnly(rec) → true for a line that was PM-only before D98: a non-proposed `placed` into Now, and `adopted`. The
39
- * checker (scripts/check-pm-lines.js, 2B) asks this function and never reads the schema itself.
45
+ * pmOnly(rec) → true for a line that was PM-only: an old `placed` line into Now, and `adopted`. The checker
46
+ * (scripts/check-pm-lines.js) asks this function and never reads the schema itself.
40
47
  *
41
- * DAY ONE (R26), with no migration. An initiative of a work lane with no line in the ledger is placed by its activity:
42
- * active within `stall_days` reads Now, unconfirmed (`confirmed: false`, `source: 'day-one'`, outside any cap); every
43
- * other one reads Later, newest activity first. Day one's rows are seeded into their horizon before the ledger lines
44
- * apply: a line with `after: null` goes above them, and a line whose `after` names a day-one row lands right after it
45
- * (the page and the CLI send `after` from the displayed order). A finished initiative (accepted, or stopped by a lifecycle line) never
46
- * reads Now: it leaves Now by itself (R3) and goes to the end of Later. In Later, an initiative untouched for
47
- * `dormant_days` is `dormant: true` (the page folds it behind "N dormant"). Without `records` there is no day one and no
48
- * lane filter: the fold answers the ledger alone.
48
+ * DAY ONE (R26), with no migration. An initiative of a work lane with no line in the ledger is ranked by its activity:
49
+ * the ones active within `stall_days` first (`confirmed: false`, `source: 'day-one'`), then the rest, newest activity
50
+ * first. Day one's rows are seeded before the ledger lines apply: a line with `after: null` goes above them, and a line
51
+ * whose `after` names a day-one row lands right after it. A finished initiative (accepted, or stopped by a lifecycle
52
+ * line) goes to the end of the Roadmap by itself (R3). An open initiative untouched for `dormant_days` that no line
53
+ * ranked is `dormant: true` (the page folds it behind "N dormant"); one a line ranked stays in view. Without
54
+ * `records` there is no day one and no lane filter.
49
55
  *
50
56
  * WORK LANES ONLY (D86 point 4). With `records`, an initiative whose lane is not in the `work` group of
51
- * scripts/lane-defs.js (read through the engine's lanesFor, never a list kept here) is left out of every answer, and
52
- * so are its proposals. A placement of an initiative that has no record any more is left out with a flag.
57
+ * scripts/lane-defs.js is left out of every answer, and so are its proposals. A placement of an initiative that has no
58
+ * record any more is left out with a flag.
53
59
  *
54
60
  * THE FOLD IS ORDER-FREE, like lib/plan-items.js: byte-identical duplicate lines (a union merge leaves them) count
55
61
  * once, lines apply in (at, eid) order, and one eid with two contents keeps the first and flags the second. A later
56
- * PM `placed` line for an initiative closes that initiative's open proposals (they are superseded, not adopted).
57
- *
58
- * HONEST LIMIT. The fold tells an agent's line by its `by`, and since D98 applies it either way; the `by` is the
59
- * record of who acted. A forged `pm:` line is caught only by scripts/check-pm-lines.js (2B), not here.
62
+ * line for an initiative closes that initiative's open proposals (they are superseded, not adopted).
60
63
  *
61
64
  * The ledger is one per repository: lib/plan-ledgers.js ledgerPath(root, 'placements'). Nothing is cached (D33).
62
65
  */
@@ -68,8 +71,11 @@ const planTree = require('./plan-tree.js');
68
71
  const actorLib = require('./actor.js');
69
72
  const { createSinkGuard } = require('./sink.js');
70
73
 
71
- const HORIZONS = Object.freeze(['now', 'next', 'later']);
72
- const EVENTS = Object.freeze(['placed', 'created', 'adopted', 'dropped']);
74
+ /** The retired horizons (D105), read from old `placed` lines only. Their index is the band. */
75
+ const LEGACY_HORIZONS = Object.freeze(['now', 'next', 'later']);
76
+ const EVENTS = Object.freeze(['ranked', 'placed', 'created', 'adopted', 'dropped']);
77
+ /** What the writer still writes: an old `placed` line is read, never written. */
78
+ const WRITABLE = Object.freeze(['ranked', 'created', 'adopted', 'dropped']);
73
79
  const MAX_LINES = 50;
74
80
  const DAY = 86400000;
75
81
  const INIT_RE = planTree.INIT_RE;
@@ -81,6 +87,7 @@ const CAPTURE_RE = /^capture-\d{4}-\d{2}-\d{2}-[1-9]\d{0,3}$/;
81
87
  const WRITER_SET = Object.freeze(['v', 'eid', 'by', 'via', 'at', 'override', 'pm', 'actor', 'nonce', 'proposed']);
82
88
  /** What a caller may send, per event (besides `ev`). */
83
89
  const CALLER_KEYS = Object.freeze({
90
+ ranked: ['initiative', 'after', 'check_by'],
84
91
  placed: ['initiative', 'horizon', 'after', 'check_by'],
85
92
  created: ['initiative', 'from'],
86
93
  adopted: ['proposal'],
@@ -88,6 +95,7 @@ const CALLER_KEYS = Object.freeze({
88
95
  });
89
96
  const ENVELOPE = ['v', 'eid', 'ev', 'by', 'via', 'at'];
90
97
  const STORED_KEYS = Object.freeze({
98
+ ranked: [...ENVELOPE, ...CALLER_KEYS.ranked],
91
99
  placed: [...ENVELOPE, ...CALLER_KEYS.placed, 'proposed'],
92
100
  created: [...ENVELOPE, ...CALLER_KEYS.created],
93
101
  adopted: [...ENVELOPE, ...CALLER_KEYS.adopted],
@@ -126,11 +134,11 @@ function lineErr(r) {
126
134
  if (!isStr(r.at) || !AT_RE.test(r.at)) return 'at must be an ISO UTC time';
127
135
  const extra = Object.keys(r).filter((k) => !STORED_KEYS[r.ev].includes(k));
128
136
  if (extra.length) return `a ${r.ev} line has no field ${extra.join(', ')}`;
129
- if (r.ev === 'placed' || r.ev === 'created') {
137
+ if (r.ev === 'placed' || r.ev === 'ranked' || r.ev === 'created') {
130
138
  if (!isStr(r.initiative) || !INIT_RE.test(r.initiative)) return 'initiative must be a record name';
131
139
  }
132
- if (r.ev === 'placed') {
133
- if (!HORIZONS.includes(r.horizon)) return 'horizon must be now, next or later';
140
+ if (r.ev === 'placed' && !LEGACY_HORIZONS.includes(r.horizon)) return 'horizon must be now, next or later';
141
+ if (r.ev === 'placed' || r.ev === 'ranked') {
134
142
  if (r.after !== null && !(isStr(r.after) && INIT_RE.test(r.after))) return 'after must be an initiative id or null';
135
143
  if (r.after === r.initiative) return 'an initiative cannot come after itself';
136
144
  if (has(r, 'check_by') && r.check_by !== null && !dateOk(r.check_by)) return 'check_by must be YYYY-MM-DD or null';
@@ -143,7 +151,7 @@ function lineErr(r) {
143
151
 
144
152
  // ── the fold ────────────────────────────────────────────────────────────────────────────────────────
145
153
  function emptyResult() {
146
- return { ok: true, byInit: {}, order: { now: [], next: [], later: [] }, proposals: [], moves: [], flags: [] };
154
+ return { ok: true, byInit: {}, ranked: [], proposals: [], moves: [], flags: [] };
147
155
  }
148
156
 
149
157
  /** Sort, de-duplicate and validate the raw lines: [{ rec }] in (at, eid) order. Flags go into `out.flags`. */
@@ -169,32 +177,50 @@ function orderLines(lines, out) {
169
177
  return outLines;
170
178
  }
171
179
 
172
- function place(out, id, horizon, after, checkBy, { confirmed, source, rec }) {
180
+ /** Where a row goes in the one list. `band` is a number (an old `placed` line: its horizon's band) or null (a `ranked`
181
+ * line: the band of the row it comes after; the top is band 0; the end is the last band). The list stays sorted by band. */
182
+ function place(out, bands, id, band, after, checkBy, { confirmed, source, rec }) {
173
183
  // A row seeded only as an anchor (it has a ledger line of its own, below) was never placed: its first line is its
174
184
  // first placement, as when it was not seeded.
175
185
  const prev = out.byInit[id] && !out.byInit[id].anchorOnly ? out.byInit[id] : null;
176
- for (const h of HORIZONS) out.order[h] = out.order[h].filter((x) => x !== id);
177
- const list = out.order[horizon];
178
- const k = after ? list.indexOf(after) : -1;
179
- if (!after) list.unshift(id); else if (k === -1) list.push(id); else list.splice(k + 1, 0, id);
186
+ const from = prev ? out.ranked.indexOf(id) : -1;
187
+ const list = out.ranked.filter((x) => x !== id);
188
+ let k;
189
+ if (band === null) {
190
+ const j = after ? list.indexOf(after) : -1;
191
+ if (!after) { k = 0; band = 0; }
192
+ else if (j === -1) { k = list.length; band = LEGACY_HORIZONS.length - 1; }
193
+ else { k = j + 1; band = bands.get(after); }
194
+ } else {
195
+ const j = after ? list.indexOf(after) : -1;
196
+ if (j !== -1 && bands.get(after) === band) k = j + 1;
197
+ else if (!after) { k = list.findIndex((x) => bands.get(x) >= band); if (k === -1) k = list.length; }
198
+ else { k = list.findIndex((x) => bands.get(x) > band); if (k === -1) k = list.length; }
199
+ }
200
+ list.splice(k, 0, id);
201
+ out.ranked = list;
202
+ bands.set(id, band);
180
203
  out.byInit[id] = {
181
- horizon, rank: 0, after: after || null,
204
+ rank: 0, after: after || null,
182
205
  check_by: checkBy === undefined ? (prev ? prev.check_by : null) : checkBy,
183
206
  confirmed, dormant: false, source,
184
207
  };
185
- if (rec && (!prev || prev.horizon !== horizon)) out.moves.push({ init: id, from: prev ? prev.horizon : null, to: horizon, at: rec.at, by: rec.by, via: rec.via });
208
+ if (rec && (!prev || from !== k)) out.moves.push({ init: id, from: prev ? from + 1 : null, to: k + 1, at: rec.at, by: rec.by, via: rec.via });
186
209
  }
210
+ const bandOfLine = (rec) => (rec.ev === 'placed' ? LEGACY_HORIZONS.indexOf(rec.horizon) : null);
187
211
 
188
212
  /** Every line applied in order. `open` is the map of open proposals by eid (the writer reads it). `seed` is day one's
189
- * rows ({ now: [id…], later: [id…] }, initiatives with no ledger line), placed BEFORE the lines apply, so a line whose
190
- * `after` names a day-one row finds it in the horizon. Without `seed` it is the ledger alone. */
213
+ * rows ({ now: [id…], later: [id…] }, initiatives with no ledger line; `now` is the active ones), placed BEFORE the
214
+ * lines apply, so a line whose `after` names a day-one row finds it. Without `seed` it is the ledger alone. */
191
215
  function foldLines(lines, seed) {
192
216
  const out = emptyResult();
217
+ const bands = new Map();
193
218
  if (seed) {
194
- for (const h of HORIZONS) {
219
+ for (const [band, h] of [[0, 'now'], [LEGACY_HORIZONS.length - 1, 'later']]) {
195
220
  for (const id of seed[h] || []) {
196
- out.order[h].push(id);
197
- out.byInit[id] = { horizon: h, rank: 0, after: null, check_by: null, confirmed: false, dormant: false, source: 'day-one' };
221
+ out.ranked.push(id);
222
+ bands.set(id, band);
223
+ out.byInit[id] = { rank: 0, after: null, check_by: null, confirmed: false, dormant: false, source: 'day-one' };
198
224
  if (seed.anchorOnly && seed.anchorOnly.has(id)) out.byInit[id].anchorOnly = true;
199
225
  }
200
226
  }
@@ -203,19 +229,20 @@ function foldLines(lines, seed) {
203
229
  const touched = new Set();
204
230
  const created = new Map(); // initiative -> capture id it came from (or null)
205
231
  for (const { n, rec } of orderLines(lines, out)) {
206
- if (rec.ev === 'placed') {
232
+ if (rec.ev === 'placed' || rec.ev === 'ranked') {
207
233
  const agentLine = !isPmBy(rec.by);
208
234
  if (rec.proposed === true || agentLine) {
209
235
  if (agentLine && rec.proposed !== true) out.flags.push({ kind: 'agent-not-proposed', eid: rec.eid, init: rec.initiative, why: `line ${n}: an agent's placement is a proposal; this one moved nothing` });
210
- open.set(rec.eid, { eid: rec.eid, init: rec.initiative, horizon: rec.horizon, after: rec.after || null, check_by: has(rec, 'check_by') ? rec.check_by : undefined, by: rec.by, at: rec.at });
236
+ open.set(rec.eid, { eid: rec.eid, init: rec.initiative, band: bandOfLine(rec), after: rec.after || null, check_by: has(rec, 'check_by') ? rec.check_by : undefined, by: rec.by, at: rec.at });
211
237
  continue;
212
238
  }
213
- for (const [eid, p] of open) if (p.init === rec.initiative) open.delete(eid); // superseded by the PM's own line
214
- place(out, rec.initiative, rec.horizon, rec.after, has(rec, 'check_by') ? rec.check_by : undefined, { confirmed: true, source: 'ledger', rec });
239
+ for (const [eid, p] of open) if (p.init === rec.initiative) open.delete(eid); // superseded by a later line
240
+ place(out, bands, rec.initiative, bandOfLine(rec), rec.after, has(rec, 'check_by') ? rec.check_by : undefined, { confirmed: true, source: 'ledger', rec });
215
241
  touched.add(rec.initiative);
216
242
  } else if (rec.ev === 'created') {
217
243
  if (touched.has(rec.initiative)) { out.flags.push({ kind: 'created-twice', eid: rec.eid, init: rec.initiative, why: `line ${n}: ${rec.initiative} already had a placement; this landing line moved nothing` }); continue; }
218
- place(out, rec.initiative, 'later', null, undefined, { confirmed: isPmBy(rec.by), source: 'created', rec });
244
+ // The end of the Roadmap (an `after` that is on no list); the old line said "top of Later", which was a band, not a place.
245
+ place(out, bands, rec.initiative, LEGACY_HORIZONS.length - 1, null, undefined, { confirmed: isPmBy(rec.by), source: 'created', rec });
219
246
  touched.add(rec.initiative);
220
247
  created.set(rec.initiative, rec.from || null);
221
248
  } else {
@@ -225,7 +252,7 @@ function foldLines(lines, seed) {
225
252
  if (!isPmBy(rec.by)) { out.flags.push({ kind: 'adopt-not-pm', eid: rec.eid, init: p.init, why: `line ${n}: only the PM adopts a proposal; this line moved nothing` }); continue; }
226
253
  open.delete(rec.proposal);
227
254
  for (const [eid, q] of open) if (q.init === p.init) open.delete(eid);
228
- place(out, p.init, p.horizon, p.after, p.check_by, { confirmed: true, source: 'ledger', rec });
255
+ place(out, bands, p.init, p.band, p.after, p.check_by, { confirmed: true, source: 'ledger', rec });
229
256
  touched.add(p.init);
230
257
  } else {
231
258
  if (!isPmBy(rec.by) && rec.by !== p.by) { out.flags.push({ kind: 'drop-not-allowed', eid: rec.eid, init: p.init, why: `line ${n}: only the PM or the agent that proposed it drops a proposal` }); continue; }
@@ -235,6 +262,8 @@ function foldLines(lines, seed) {
235
262
  }
236
263
  return { out, open, created };
237
264
  }
265
+ const proposalOut = (p) => ({ eid: p.eid, init: p.init, after: p.after, by: p.by, at: p.at });
266
+ const numberRanks = (out) => { out.ranked.forEach((id, i) => { out.byInit[id].rank = i; }); };
238
267
 
239
268
  const activityMs = (r) => {
240
269
  const v = r && r.last_activity;
@@ -264,8 +293,8 @@ function readPlacements(root, { now, rules, records } = {}) {
264
293
  if (!Array.isArray(records)) {
265
294
  const { out, open } = ledgerOnly;
266
295
  for (const b of bad) out.flags.unshift({ kind: 'unreadable', eid: null, init: null, why: `line ${b.n}: ${b.why}` });
267
- out.proposals = [...open.values()].map((p) => ({ eid: p.eid, init: p.init, horizon: p.horizon, after: p.after, by: p.by, at: p.at }));
268
- for (const h of HORIZONS) out.order[h].forEach((id, i) => { out.byInit[id].rank = i; });
296
+ out.proposals = [...open.values()].map(proposalOut);
297
+ numberRanks(out);
269
298
  return out;
270
299
  }
271
300
 
@@ -279,15 +308,15 @@ function readPlacements(root, { now, rules, records } = {}) {
279
308
  for (const r of records) if (r && isStr(r.id) && r.ok !== false) rows.set(r.id, r);
280
309
  const isWork = (id) => rows.has(id) && groupOf(rows.get(id)) === 'work';
281
310
 
282
- // Day one's rows: a work initiative with no line the ledger applied, placed by its activity. They are seeded into
283
- // their horizon before the ledger lines apply, so a line placed `after` a day-one row (the page and the CLI send the
311
+ // Day one's rows: a work initiative with no line the ledger applied, ranked by its activity (the active ones first).
312
+ // They are seeded before the ledger lines apply, so a line placed `after` a day-one row (the page and the CLI send the
284
313
  // displayed order) lands next to it. A ledger line with `after: null` still goes above them.
285
314
  const byActivity = (a, b) => ((activityMs(rows.get(b)) || 0) - (activityMs(rows.get(a)) || 0)) || (a < b ? -1 : 1);
286
315
  // A row that has a line of its own is seeded too, as an ANCHOR only: a line written while it was still a day-one row
287
316
  // named it as `after`, and that line must find it where it stood then. Its own line moves it when it applies. Seeding
288
317
  // only the rows with no line lost that anchor the moment the row got a line (the earlier line then appended its row
289
- // at the end of the horizon), so one reorder could scramble rows it never touched.
290
- const seed = { now: [], next: [], later: [], anchorOnly: new Set() };
318
+ // at the end of the list), so one reorder could scramble rows it never touched.
319
+ const seed = { now: [], later: [], anchorOnly: new Set() };
291
320
  for (const id of [...rows.keys()].filter((x) => isWork(x)).sort(byActivity)) {
292
321
  const r = rows.get(id);
293
322
  const ms = activityMs(r);
@@ -297,32 +326,25 @@ function readPlacements(root, { now, rules, records } = {}) {
297
326
  const { out, open } = foldLines(lines, seed);
298
327
  for (const id of Object.keys(out.byInit)) if (out.byInit[id].anchorOnly) delete out.byInit[id].anchorOnly;
299
328
  for (const b of bad) out.flags.unshift({ kind: 'unreadable', eid: null, init: null, why: `line ${b.n}: ${b.why}` });
300
- const proposalsOf = (keep) => [...open.values()].filter((p) => keep(p.init))
301
- .map((p) => ({ eid: p.eid, init: p.init, horizon: p.horizon, after: p.after, by: p.by, at: p.at }));
329
+ const proposalsOf = (keep) => [...open.values()].filter((p) => keep(p.init)).map(proposalOut);
302
330
 
303
331
  for (const id of Object.keys(out.byInit)) {
304
332
  if (isWork(id)) continue;
305
333
  if (!rows.has(id)) out.flags.push({ kind: 'no-record', eid: null, init: id, why: `${id} has a placement but no initiative record; it is left out` });
306
334
  delete out.byInit[id];
307
- for (const h of HORIZONS) out.order[h] = out.order[h].filter((x) => x !== id);
335
+ out.ranked = out.ranked.filter((x) => x !== id);
308
336
  }
309
337
  out.moves = out.moves.filter((m) => isWork(m.init));
310
338
  out.proposals = proposalsOf(isWork);
311
339
 
312
- // A finished initiative leaves Now by itself (R3): to the end of Later, whatever the ledger says.
313
- for (const id of out.order.now.slice()) {
314
- if (!finished(rows.get(id))) continue;
315
- out.order.now = out.order.now.filter((x) => x !== id);
316
- out.order.later.push(id);
317
- out.byInit[id].horizon = 'later';
318
- }
319
- // Finished initiatives sit at the end of Later, in the order they were in.
320
- out.order.later = [...out.order.later.filter((id) => !finished(rows.get(id))), ...out.order.later.filter((id) => finished(rows.get(id)))];
321
- for (const id of out.order.later) {
340
+ // A finished initiative goes to the end of the Roadmap by itself (R3), in the order it was in.
341
+ out.ranked = [...out.ranked.filter((id) => !finished(rows.get(id))), ...out.ranked.filter((id) => finished(rows.get(id)))];
342
+ for (const id of out.ranked) {
322
343
  const ms = activityMs(rows.get(id));
323
- out.byInit[id].dormant = ms !== null && t - ms >= dormantMs;
344
+ // A row a line ranked never folds away: the PM (or an agent) put it there. Day one's and a landing line's rows do.
345
+ out.byInit[id].dormant = !finished(rows.get(id)) && out.byInit[id].source !== 'ledger' && ms !== null && t - ms >= dormantMs;
324
346
  }
325
- for (const h of HORIZONS) out.order[h].forEach((id, i) => { out.byInit[id].rank = i; });
347
+ numberRanks(out);
326
348
  return out;
327
349
  }
328
350
 
@@ -332,9 +354,10 @@ function pmOnly(rec) {
332
354
  return rec.ev === 'placed' && rec.horizon === 'now' && rec.proposed !== true;
333
355
  }
334
356
 
335
- function horizonOf(result, id) {
357
+ /** The initiative's rank on the Roadmap (0 = top), or null when it has no place. */
358
+ function rankOf(result, id) {
336
359
  const p = result && result.byInit && Object.prototype.hasOwnProperty.call(result.byInit, id) ? result.byInit[id] : null;
337
- return p && HORIZONS.includes(p.horizon) ? p.horizon : 'later';
360
+ return p && Number.isInteger(p.rank) ? p.rank : null;
338
361
  }
339
362
 
340
363
  /** The capture notes an initiative was created from: { [captureId]: initiativeId } (lib/triage.js reads it). */
@@ -354,21 +377,20 @@ function buildRecord(root, ev, i, actor, state) {
354
377
  if (!ev || typeof ev !== 'object' || Array.isArray(ev)) return refuse(400, 'each line must be a JSON object', i);
355
378
  const sent = WRITER_SET.find((k) => has(ev, k));
356
379
  if (sent) return refuse(400, `the writer sets "${sent}"; do not send it`, i);
357
- if (!has(CALLER_KEYS, ev.ev)) return refuse(400, `ev must be one of ${EVENTS.join(', ')}`, i);
380
+ if (ev.ev === 'placed') return refuse(400, 'Now, Next and Later are retired (D105): send a ranked line { ev: "ranked", initiative, after } instead', i);
381
+ if (!WRITABLE.includes(ev.ev)) return refuse(400, `ev must be one of ${WRITABLE.join(', ')}`, i);
358
382
  const extra = Object.keys(ev).filter((k) => k !== 'ev' && !CALLER_KEYS[ev.ev].includes(k));
359
383
  if (extra.length) return refuse(400, `a ${ev.ev} line has no field ${extra.join(', ')}`, i);
360
384
  const rec = { ev: ev.ev };
361
- if (ev.ev === 'placed' || ev.ev === 'created') {
385
+ if (ev.ev === 'ranked' || ev.ev === 'created') {
362
386
  if (!isStr(ev.initiative) || !INIT_RE.test(ev.initiative)) return refuse(400, 'initiative must be an initiative id', i);
363
387
  if (!planTree.recordPath(root, ev.initiative)) return refuse(404, `no initiative ${ev.initiative} in this repository`, i);
364
388
  rec.initiative = ev.initiative;
365
389
  }
366
- if (ev.ev === 'placed') {
367
- if (!HORIZONS.includes(ev.horizon)) return refuse(400, 'horizon must be now, next or later', i);
390
+ if (ev.ev === 'ranked') {
368
391
  const after = ev.after == null ? null : ev.after;
369
392
  if (after !== null && !(isStr(after) && INIT_RE.test(after))) return refuse(400, 'after must be an initiative id or null', i);
370
393
  if (after === ev.initiative) return refuse(400, 'an initiative cannot come after itself', i);
371
- rec.horizon = ev.horizon;
372
394
  rec.after = after;
373
395
  if (has(ev, 'check_by')) {
374
396
  if (ev.check_by !== null && !dateOk(ev.check_by)) return refuse(400, 'check_by must be YYYY-MM-DD, or null to clear it', i);
@@ -427,12 +449,12 @@ function append(root, events, actor, { now } = {}) {
427
449
  return { ok: true, written: recs.length, lines: recs.map((r) => ({ eid: r.eid, ev: r.ev, initiative: r.initiative || null, proposed: r.proposed === true })) };
428
450
  }
429
451
 
430
- /** A page press. The actor is the guard's (requirePmPress for Now and adopt, requirePagePress otherwise). */
452
+ /** A page press. The actor is the guard's (requirePmPress for adopt, requirePagePress otherwise). */
431
453
  function appendFromUi(root, events, { actor, now } = {}) { return append(root, events, actor, { now }); }
432
- /** `pmos initiative`. The actor is requirePmCli's (Now, adopt) or actor.fromCli's. */
454
+ /** `pmos initiative`. The actor is requirePmCli's (adopt) or actor.fromCli's. */
433
455
  function appendFromCli(root, events, { actor, now } = {}) { return append(root, events, actor, { now }); }
434
456
 
435
457
  module.exports = {
436
- HORIZONS, EVENTS, MAX_LINES, CAPTURE_RE,
437
- readPlacements, horizonOf, pmOnly, createdFrom, lineErr, appendFromUi, appendFromCli,
458
+ LEGACY_HORIZONS, EVENTS, WRITABLE, MAX_LINES, CAPTURE_RE,
459
+ readPlacements, rankOf, pmOnly, createdFrom, lineErr, appendFromUi, appendFromCli,
438
460
  };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
  /* plan-rules.js — the numbers the planning layer reads (pm-os-absorb, PRD R24): planning/plan-rules.json.
3
3
  *
4
- * readRules(root) → { stall_days, dormant_days, report_cycle_days, now_cap, via_required_from, …other keys }
4
+ * readRules(root) → { stall_days, dormant_days, report_cycle_days, via_required_from, …other keys }
5
5
  * readRulesDetail(root) → { rules, path, errors, unknown } the same read, with what was wrong with the file
6
6
  *
7
7
  * One reader, so the Today ranking, the health rules, day one and the report window cannot each keep their own copy
@@ -12,7 +12,8 @@
12
12
  * A value that is not valid reads its default, and the reason is in `errors`; readRules never throws, because a
13
13
  * typo in a rules file must not take the Today count or a report down with it. A key this reader does not know is
14
14
  * passed through unchanged and named in `unknown` (a run that adds a key adds it to KEYS with its check). Keys that
15
- * start with `_` are comments. Nothing is cached (D33): the file is small.
15
+ * start with `_` are comments. A RETIRED key is read past in silence: `now_cap`, the cap on Now, went with the horizons
16
+ * (D105), so an older file that still has it is not an error and the key reaches no caller. Nothing is cached (D33).
16
17
  */
17
18
  const fs = require('fs');
18
19
  const path = require('path');
@@ -20,7 +21,9 @@ const path = require('path');
20
21
  // via_required_from (Run 2, R25(4), map-spec X10): the ISO UTC time from which a PM-only line must carry `via`.
21
22
  // scripts/check-pm-lines.js fails a newer line without one and reports each older line once, never failing it.
22
23
  // null means no time is set yet: every PM-only line is older, so none fails for a missing via.
23
- const DEFAULTS = Object.freeze({ stall_days: 5, dormant_days: 45, report_cycle_days: 14, now_cap: null, via_required_from: null });
24
+ const DEFAULTS = Object.freeze({ stall_days: 5, dormant_days: 45, report_cycle_days: 14, via_required_from: null });
25
+ /** Keys a rules file may still carry from before a decision retired them. */
26
+ const RETIRED = Object.freeze(['now_cap']);
24
27
  const posInt = (v) => Number.isInteger(v) && v > 0;
25
28
  const isoUtc = (v) => typeof v === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/.test(v) && !Number.isNaN(Date.parse(v));
26
29
  /** Each known key and the check its value must pass. */
@@ -28,7 +31,6 @@ const KEYS = Object.freeze({
28
31
  stall_days: { ok: posInt, want: 'a whole number of days, 1 or more' },
29
32
  dormant_days: { ok: posInt, want: 'a whole number of days, 1 or more' },
30
33
  report_cycle_days: { ok: posInt, want: 'a whole number of days, 1 or more' },
31
- now_cap: { ok: (v) => v === null || posInt(v), want: 'null (no cap) or a whole number, 1 or more' },
32
34
  via_required_from: { ok: (v) => v === null || isoUtc(v), want: 'null (not set yet) or an ISO UTC time such as 2026-10-20T09:00:00Z' },
33
35
  });
34
36
  const CANDIDATES = [['planning', 'plan-rules.json'], ['pmos', 'state', 'plan-rules.json']];
@@ -49,7 +51,7 @@ function validate(obj) {
49
51
  const unknown = [];
50
52
  if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return { rules, errors: ['the rules file is not a JSON object'], unknown };
51
53
  for (const [k, v] of Object.entries(obj)) {
52
- if (k.startsWith('_')) continue;
54
+ if (k.startsWith('_') || RETIRED.includes(k)) continue;
53
55
  const spec = KEYS[k];
54
56
  if (!spec) { unknown.push(k); rules[k] = v; continue; }
55
57
  if (spec.ok(v)) rules[k] = v;
@@ -55,8 +55,7 @@ const PM_ONLY_ACTS = Object.freeze([
55
55
  'accept', // the Acceptance Gate, the review approve and return, a document approval (/api/gate)
56
56
  'lifecycle', // hold, close, cancel, reopen (/api/lifecycle)
57
57
  'keep', // Keep on an agent batch (/api/plan-items kept)
58
- 'now', // Move to Now (placements)
59
- 'adopt', // adopt an agent's placement proposal
58
+ 'adopt', // adopt an agent's placement proposal (Move to Now, act 'now', was retired with the horizons: D105)
60
59
  'anchor', // change parent_kr (the record, /api/doc/save, /api/align/apply, /api/ingest/confirm)
61
60
  'bind', // bind a session to an initiative (/api/session/initiative)
62
61
  'issue', // Issue a report (issues.jsonl)
@@ -68,7 +67,6 @@ const ACT_PHRASE = Object.freeze({
68
67
  accept: 'accept or return work',
69
68
  lifecycle: 'hold, close, cancel or reopen an initiative',
70
69
  keep: 'keep an agent\'s items',
71
- now: 'move an item to Now',
72
70
  adopt: 'adopt a proposal',
73
71
  anchor: 'change an anchor',
74
72
  bind: 'bind a session to an initiative',
@@ -70,7 +70,7 @@ const QUESTION = 'A PM-only line is not attested';
70
70
 
71
71
  const what = {
72
72
  'plan-items': () => 'A Keep line',
73
- placements: (r) => `A placed line into ${r.horizon === 'now' ? 'Now' : String(r.horizon || 'a horizon')}`,
73
+ placements: (r) => (r.ev === 'adopted' ? 'An adopted proposal' : `An old line into ${r.horizon === 'now' ? 'Now' : String(r.horizon || 'a horizon')} (before D105)`),
74
74
  measurements: () => 'A measured line',
75
75
  issues: () => 'An issued line',
76
76
  acceptances: () => 'An acceptance line',
@@ -28,6 +28,8 @@
28
28
  * version { n, format, turn, answer, from } a job (or an adopted cycle) landed D<n>
29
29
  * accept { n, rules } "This is it": D<n> is the design; brief.md is written
30
30
  * revert { n } the next turn builds on D<n>
31
+ * unsave {} Go back to a template version with the standard look: no design is saved
32
+ * (lib/routes-report-flow.js restore; brief.md is removed, cycles keep their look)
31
33
  * error { text, mode, slot?, sha? } a job failed, timed out or wrote nothing usable
32
34
  * cycle-decision { path, slot, diff, choice } keep | adopt | match on a cycle that differs
33
35
  *
@@ -48,7 +50,7 @@ const zlib = require('zlib');
48
50
  const RD = require('./report-draft.js');
49
51
  const issues = require('./issues.js');
50
52
 
51
- const EVENTS = Object.freeze(['describe', 'sample', 'unsample', 'fetched', 'took', 'turn', 'version', 'accept', 'revert', 'error', 'cycle-decision']);
53
+ const EVENTS = Object.freeze(['describe', 'sample', 'unsample', 'fetched', 'took', 'turn', 'version', 'accept', 'revert', 'unsave', 'error', 'cycle-decision']);
52
54
  const FORMATS = Object.freeze(['deck', 'doc']);
53
55
  const SAMPLE_KINDS = Object.freeze(['pdf', 'pptx', 'docx', 'image', 'pictures', 'link', 'pmos-doc']);
54
56
  const MAX_PICTURES = 12;
@@ -149,6 +151,9 @@ function fold(events) {
149
151
  } else if (l.ev === 'revert') {
150
152
  if (st.versions.has(l.n)) st.current = l.n;
151
153
  st.log.push({ at: l.at, who: 'you', kind: 'revert', text: `Back to D${l.n}. The next turn builds on it.`, version: l.n });
154
+ } else if (l.ev === 'unsave') {
155
+ st.saved = null; st.rules = null;
156
+ st.log.push({ at: l.at, who: whoOf(l), kind: 'unsave', text: 'Back to the standard look (a template went back).' });
152
157
  } else if (l.ev === 'error') {
153
158
  st.errors.push({ at: l.at, text: str(l.text), mode: l.mode || null, slot: l.slot || null, sha: l.sha || null });
154
159
  st.log.push({ at: l.at, who: 'pmos', kind: 'error', text: str(l.text) });