create-pmos 0.421.0 → 0.423.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -25
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/anchor-resolve.js +93 -15
- package/payload/state/discoveries.md +1 -1
- package/workspace/board-programs-test.js +87 -3
- package/workspace/briefing-premium-adddoc-test.js +1 -1
- package/workspace/briefing-premium-board-test.js +13 -11
- package/workspace/briefing-premium-initiative-test.js +30 -38
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/report-api/draft.json +2 -1
- package/workspace/guide/briefing-premium.md +2 -1
- package/workspace/guide/home.md +14 -4
- package/workspace/guide/programs.md +5 -3
- package/workspace/guide/workflows.md +5 -1
- package/workspace/home-other-product-test.js +55 -0
- package/workspace/ini-workflow-test.js +4 -4
- package/workspace/lib/board-premium.js +21 -6
- package/workspace/lib/custom-docs.js +65 -3
- package/workspace/lib/doc-live-root.js +37 -0
- package/workspace/lib/engine/anchor-resolve.js +93 -15
- package/workspace/lib/engine/boards.js +30 -2
- package/workspace/lib/engine/intake.js +1 -1
- package/workspace/lib/hold-spans.js +24 -10
- package/workspace/lib/initiative-writer.js +63 -1
- package/workspace/lib/kg.js +1 -1
- package/workspace/lib/plan-items.js +36 -5
- package/workspace/lib/programs.js +11 -3
- package/workspace/lib/report-draft.js +3 -0
- package/workspace/lib/route-modules.js +2 -0
- package/workspace/lib/routes-board-premium.js +28 -0
- package/workspace/lib/routes-boards.js +92 -13
- package/workspace/lib/routes-doc-sheet.js +29 -1
- package/workspace/lib/routes-initiatives.js +12 -0
- package/workspace/lib/routes-programs.js +44 -5
- package/workspace/lib/routes-task-links.js +329 -0
- package/workspace/lib/routes-task-plans.js +333 -0
- package/workspace/lib/split-merge-suggest.js +162 -0
- package/workspace/lib/split-merge.js +379 -0
- package/workspace/lib/task-cli.js +73 -13
- package/workspace/lib/task-items.js +15 -3
- package/workspace/lib/task-links.js +422 -0
- package/workspace/lib/task-plans.js +232 -0
- package/workspace/lib/vendor/scripts/anchor-resolve.js +93 -15
- package/workspace/lib/vendor/scripts/intake.js +1 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +2 -2
- package/workspace/premium-core-doc-issue-test.js +2 -2
- package/workspace/premium-vw-backlog-test.js +3 -3
- package/workspace/premium-vw-doc-test.js +26 -3
- package/workspace/premium-vw-item-test.js +3 -3
- package/workspace/premium-vw-jira-test.js +6 -6
- package/workspace/product-lane-test.js +165 -0
- package/workspace/program-leave-test.js +203 -0
- package/workspace/program-panel-test.js +1 -1
- package/workspace/public/pm/bd-acts.js +5 -2
- package/workspace/public/pm/bd-ini-panel.js +32 -9
- package/workspace/public/pm/bd-prog-panel.js +22 -7
- package/workspace/public/pm/bd-prog.js +6 -1
- package/workspace/public/pm/bd-span.js +234 -30
- package/workspace/public/pm/bd-views.js +3 -2
- package/workspace/public/pm/cozy-board.css +90 -0
- package/workspace/public/pm/cozy-home.css +3 -0
- package/workspace/public/pm/doc-follow.js +36 -0
- package/workspace/public/pm/home-app.js +62 -14
- package/workspace/public/pm/home-ini-model.js +0 -34
- package/workspace/public/pm/home-ini.js +81 -204
- package/workspace/public/pm/home-list.js +2 -2
- package/workspace/public/pm/home-today.js +3 -1
- package/workspace/public/pm/ini-groups.js +228 -0
- package/workspace/public/pm/ini-links.js +561 -0
- package/workspace/public/pm/ini-tasks.js +131 -30
- package/workspace/public/pm/ini-versions.js +348 -0
- package/workspace/public/pm/ini-view-model.js +113 -43
- package/workspace/public/pm/ini-view.css +341 -18
- package/workspace/public/pm/ini-view.js +153 -38
- package/workspace/public/pm/premium-board.js +160 -21
- package/workspace/public/pm/premium-report-read.js +20 -1
- package/workspace/public/pm/premium-shell.js +29 -4
- package/workspace/public/pm/premium-vw-doc.js +46 -11
- package/workspace/public/pm/prog-move.js +69 -0
- package/workspace/public/pm/split-merge.css +77 -0
- package/workspace/public/pm/split-merge.js +265 -0
- package/workspace/public/pm/stage-line.js +414 -0
- package/workspace/public/pm/task-card.css +3 -0
- package/workspace/public/pm/task-card.js +15 -6
- package/workspace/public/pm/wf-page.css +2 -0
- package/workspace/public/pm/wf-page.js +2 -0
- package/workspace/public/pm/wf-stage.js +2 -1
- package/workspace/server.js +15 -1
- package/workspace/split-merge-ui-test.js +175 -0
- package/workspace/stage-card-test.js +12 -11
- package/workspace/task-card-test.js +3 -2
- package/workspace/task-delete-test.js +126 -0
- package/workspace/task-links-test.js +227 -0
- package/workspace/task-milestones-test.js +176 -0
- package/workspace/task-plans-test.js +181 -0
- package/workspace/task-views-test.js +3 -3
- package/workspace/test-lists/bd-ini-panel.json +8 -2
- package/workspace/test-lists/product-lane.json +6 -0
- package/workspace/test-lists/program-leave.json +6 -0
- package/workspace/test-lists/split-merge.json +15 -0
- package/workspace/test-lists/task-delete.json +5 -0
- package/workspace/test-lists/task-links.json +6 -0
- package/workspace/test-lists/task-milestones.json +6 -0
- package/workspace/test-lists/task-plans.json +6 -0
- package/workspace/test-lists/viewer-live-file.json +9 -0
- package/workspace/timeline-holds-test.js +61 -4
- package/workspace/tk-tasks-test.js +173 -57
- package/workspace/workflows-setup-test.js +4 -3
|
@@ -7,11 +7,17 @@
|
|
|
7
7
|
* check(input) → { ok: true, value } | { ok: false, status, error } PURE
|
|
8
8
|
* list(root, scope) → [{ id, scope, title, writer, phase, link, at }] in the order they were added
|
|
9
9
|
* add(root, input, actor, { now }) → { ok: true, doc } | { ok: false, status, error }
|
|
10
|
+
* move(root, ids, scope, actor) → { ok: true, moved: [{ id, from }] } documents taken to another initiative (a split or a merge,
|
|
11
|
+
* feedback batch 11 item 14); Undo is the same call back to `from`
|
|
12
|
+
* drop(root, id, actor) → { ok: true, dropped } the Undo of addFile
|
|
13
|
+
* addFile(root, { scope, title, file, phase? }, actor) → { ok: true, doc } a PMOS file joins an initiative's documents: the PRD of an
|
|
14
|
+
* initiative merged into another (the one that stays keeps its own PRD)
|
|
10
15
|
*
|
|
11
16
|
* THE LEDGER. Lines { v: 1, ev: 'add', id, scope, title, writer, phase, link, actor, at }. `scope` is board:<id> or initiative:<id>. `writer` is
|
|
12
17
|
* drafts | you. `phase` is a phase name for an initiative and null for a board. `link` is { kind, url } or null. `actor` is the actor of the call
|
|
13
18
|
* path (lib/actor.js), never an argument. Nothing here reads or syncs a linked page: the record holds the address and the date it was added.
|
|
14
|
-
* The file is never rewritten. A line that does not parse, or has no title, is skipped.
|
|
19
|
+
* The file is never rewritten. A line that does not parse, or has no title, is skipped. A `move` line { v: 1, ev: 'move', id, scope, actor, at } puts
|
|
20
|
+
* a document in another scope (the last one wins); an add with `file` (a repository path) names a document PMOS holds, not a link.
|
|
15
21
|
*/
|
|
16
22
|
const fs = require('fs');
|
|
17
23
|
const path = require('path');
|
|
@@ -40,7 +46,21 @@ function readLines(file) {
|
|
|
40
46
|
if (!raw.trim()) continue;
|
|
41
47
|
try { const l = JSON.parse(raw); if (isObj(l) && l.ev === 'add' && typeof l.scope === 'string' && typeof l.title === 'string' && l.title && typeof l.id === 'string') out.push(l); } catch { /* a torn line is skipped */ }
|
|
42
48
|
}
|
|
43
|
-
return out;
|
|
49
|
+
return withMoves(out, text);
|
|
50
|
+
}
|
|
51
|
+
/** The adds with each one's scope after the move lines (a split or a merge took it to another initiative). */
|
|
52
|
+
function withMoves(adds, text) {
|
|
53
|
+
if (!text.includes('"move"') && !text.includes('"drop"')) return adds;
|
|
54
|
+
const to = new Map(), gone = new Set();
|
|
55
|
+
for (const raw of text.split('\n')) {
|
|
56
|
+
if (!raw.includes('"move"') && !raw.includes('"drop"')) continue;
|
|
57
|
+
try {
|
|
58
|
+
const l = JSON.parse(raw);
|
|
59
|
+
if (isObj(l) && l.ev === 'move' && typeof l.id === 'string' && SCOPE_RE.test(String(l.scope || ''))) to.set(l.id, l.scope);
|
|
60
|
+
if (isObj(l) && l.ev === 'drop' && typeof l.id === 'string') gone.add(l.id);
|
|
61
|
+
} catch { /* skipped */ }
|
|
62
|
+
}
|
|
63
|
+
return adds.filter((l) => !gone.has(l.id)).map((l) => (to.has(l.id) ? { ...l, scope: to.get(l.id) } : l));
|
|
44
64
|
}
|
|
45
65
|
|
|
46
66
|
/** Check the fields of an add. The scope's existence is the route's check; this one is about the shape. */
|
|
@@ -78,9 +98,49 @@ function list(root, scope) {
|
|
|
78
98
|
return readLines(ledgerFile(root)).filter((l) => l.scope === scope).map((l) => ({
|
|
79
99
|
id: l.id, scope: l.scope, title: l.title, writer: WRITERS.includes(l.writer) ? l.writer : null, phase: PHASES.includes(l.phase) ? l.phase : null,
|
|
80
100
|
link: isObj(l.link) && KINDS.includes(l.link.kind) && typeof l.link.url === 'string' ? { kind: l.link.kind, url: l.link.url } : null, at: l.at || null,
|
|
101
|
+
...(typeof l.file === 'string' && l.file ? { file: l.file } : {}),
|
|
81
102
|
}));
|
|
82
103
|
}
|
|
83
104
|
|
|
105
|
+
/** Documents to another scope: one move line each. `ids` not in the ledger are skipped. */
|
|
106
|
+
function move(root, ids, scope, actor) {
|
|
107
|
+
if (!SCOPE_RE.test(String(scope || ''))) return refuse(400, 'scope must be board:<id> or initiative:<id>');
|
|
108
|
+
const file = ledgerFile(root);
|
|
109
|
+
const have = new Map(readLines(file).map((l) => [l.id, l]));
|
|
110
|
+
const moved = [];
|
|
111
|
+
const t = Date.now();
|
|
112
|
+
for (const id of [...new Set(ids || [])]) {
|
|
113
|
+
const l = have.get(id);
|
|
114
|
+
if (!l || l.scope === scope) continue;
|
|
115
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
116
|
+
fs.appendFileSync(file, JSON.stringify({ v: 1, ev: 'move', id, scope, actor: actor || null, at: new Date(t).toISOString() }) + '\n');
|
|
117
|
+
moved.push({ id, from: l.scope });
|
|
118
|
+
}
|
|
119
|
+
return { ok: true, moved };
|
|
120
|
+
}
|
|
121
|
+
/** Take back a document a merge added (its Undo): one drop line. */
|
|
122
|
+
function drop(root, id, actor) {
|
|
123
|
+
const file = ledgerFile(root);
|
|
124
|
+
if (!readLines(file).some((l) => l.id === id)) return { ok: true, dropped: false };
|
|
125
|
+
fs.appendFileSync(file, JSON.stringify({ v: 1, ev: 'drop', id, actor: actor || null, at: new Date().toISOString() }) + '\n');
|
|
126
|
+
return { ok: true, dropped: true };
|
|
127
|
+
}
|
|
128
|
+
/** A PMOS file as one of an initiative's documents (the closing initiative's PRD on a merge). */
|
|
129
|
+
function addFile(root, input, actor) {
|
|
130
|
+
const i = isObj(input) ? input : {};
|
|
131
|
+
if (!SCOPE_RE.test(String(i.scope || ''))) return refuse(400, 'scope must be board:<id> or initiative:<id>');
|
|
132
|
+
const file = typeof i.file === 'string' ? i.file.trim() : '';
|
|
133
|
+
if (!file || file.length > URL_MAX || path.isAbsolute(file) || file.split(/[\\/]/).includes('..')) return refuse(400, 'file is a path inside the repository');
|
|
134
|
+
const title = String(i.title || '').trim().replace(/\s+/g, ' ').slice(0, TITLE_MAX);
|
|
135
|
+
if (!title) return refuse(400, 'Give the document a title.');
|
|
136
|
+
const f = ledgerFile(root), have = readLines(f).filter((l) => l.scope === i.scope);
|
|
137
|
+
const t = Date.now();
|
|
138
|
+
const line = { v: 1, ev: 'add', id: 'cd-' + t.toString(36) + '-' + (have.length + 1), scope: i.scope, title, writer: 'you', phase: PHASES.includes(i.phase) ? i.phase : null, link: null, file, actor: actor || null, at: new Date(t).toISOString() };
|
|
139
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
140
|
+
fs.appendFileSync(f, JSON.stringify(line) + '\n');
|
|
141
|
+
return { ok: true, doc: { id: line.id, scope: line.scope, title, file, at: line.at } };
|
|
142
|
+
}
|
|
143
|
+
|
|
84
144
|
/** THE SINGLE WRITER of custom-docs.jsonl. `v`, `id` and `at` are set here. */
|
|
85
145
|
function add(root, input, actor, { now } = {}) {
|
|
86
146
|
const c = check(input);
|
|
@@ -99,9 +159,11 @@ function add(root, input, actor, { now } = {}) {
|
|
|
99
159
|
/** One added document as a row of the Core documents card. PURE. `st` is `missing` (no link) or `linked`; never `ok`: PMOS cannot read a linked page.
|
|
100
160
|
* `added` is the day it was added (YYYY-MM-DD) and the only date the row holds. */
|
|
101
161
|
function rowOf(d) {
|
|
162
|
+
// a PMOS file that joined from a merged initiative opens like a core document
|
|
163
|
+
if (d.file) return { key: 'custom:' + d.id, title: d.title, what: 'Joined on a merge.', st: 'ok', state: 'Saved', by: '', cat: d.phase || null, link: null, path: d.file, added: d.at ? String(d.at).slice(0, 10) : '', custom: true, act: null };
|
|
102
164
|
const linked = !!d.link;
|
|
103
165
|
return { key: 'custom:' + d.id, title: d.title, what: linked ? 'Lives in ' + d.link.kind + ': ' + d.link.url : 'Added by you.', st: linked ? 'linked' : 'missing', state: linked ? 'Linked' : 'Not started',
|
|
104
166
|
by: d.writer === 'you' ? 'You write it' : d.writer === 'drafts' ? 'PMOS drafts it' : '', cat: d.phase || null, link: d.link, added: d.at ? String(d.at).slice(0, 10) : '', custom: true, act: null };
|
|
105
167
|
}
|
|
106
168
|
|
|
107
|
-
module.exports = { rowOf, KINDS, PHASES, WRITERS, TITLE_MAX, URL_MAX, ledgerFile, readLines, check, list, add };
|
|
169
|
+
module.exports = { rowOf, KINDS, PHASES, WRITERS, TITLE_MAX, URL_MAX, ledgerFile, readLines, check, list, add, move, addFile, drop };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* doc-live-root.js — which workspace holds the live copy of an initiative's document (feedback batch 11, item 1; PM, 2026-10-26: "When chat make update
|
|
3
|
+
* on the file that being shown on the current viewer, I should not need to refresh page. I should not need to manually commit as well").
|
|
4
|
+
* A chat about an initiative runs in that initiative's own git worktree on `initiative/<id>` (lib/start-policy.js), which spawnWithBranch registers as a
|
|
5
|
+
* workspace. Its edits are in that folder and not committed, so the Viewer reads the document there and not in the shared checkout.
|
|
6
|
+
*
|
|
7
|
+
* liveWs({ base, ini, rel, workspaces, worktreesOf, topOf, has }) -> the workspace to read, `base` when no other applies
|
|
8
|
+
* base the workspace the page asked for ({ id, root })
|
|
9
|
+
* ini the initiative id, or nothing
|
|
10
|
+
* rel the document's path inside the workspace
|
|
11
|
+
* workspaces the registered workspaces [{ id, root }]
|
|
12
|
+
* worktreesOf(top) -> [{ dir, branch }] git worktree list of the repository at `top`
|
|
13
|
+
* topOf(root) -> the repository's top folder, or null
|
|
14
|
+
* has(root, rel) -> true when the file is there
|
|
15
|
+
* Only a REGISTERED workspace is answered, so this never opens a folder the server does not already serve. A worktree that does not hold the file
|
|
16
|
+
* (the document was never on that branch) leaves the page on `base`. */
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const INI_RX = /^[A-Za-z0-9][\w.-]{0,120}$/;
|
|
20
|
+
|
|
21
|
+
function liveWs({ base, ini, rel, workspaces = [], worktreesOf = () => [], topOf = () => null, has = () => false } = {}) {
|
|
22
|
+
if (!base || !base.root || !ini || !INI_RX.test(String(ini))) return base;
|
|
23
|
+
const top = topOf(base.root);
|
|
24
|
+
if (!top) return base;
|
|
25
|
+
let trees; try { trees = worktreesOf(top) || []; } catch { trees = []; }
|
|
26
|
+
const t = trees.find((x) => x && x.branch === 'initiative/' + ini);
|
|
27
|
+
if (!t || !t.dir) return base;
|
|
28
|
+
// a workspace registered at a subfolder of its repository lands in the same subfolder of the worktree (spawnWithBranch mirrors it)
|
|
29
|
+
const sub = path.relative(path.resolve(top), path.resolve(base.root));
|
|
30
|
+
const want = path.resolve(t.dir, sub.startsWith('..') ? '' : sub);
|
|
31
|
+
if (want === path.resolve(base.root)) return base;
|
|
32
|
+
const w = workspaces.find((x) => x && x.root && path.resolve(x.root) === want);
|
|
33
|
+
if (!w || (rel && !has(w.root, rel))) return base;
|
|
34
|
+
return w;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { liveWs };
|
|
@@ -73,20 +73,45 @@ const ACCEPTED_FORMS = [
|
|
|
73
73
|
* called `okrs` that every subsequent KR would then attach to. The shape is therefore pinned:
|
|
74
74
|
* an objective is `O` + digits, or `O-` + a word; a KR is `KR` + digits, or `KR-` + a word.
|
|
75
75
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
/*
|
|
77
|
+
* Batch 11 item 6 (2026-10-26): the OKR document as people write it. `## Objective 1 — title` is
|
|
78
|
+
* objective `o1`, the same objective as `## O1 — title`; and `KR1.2` (KR 2 of objective 1) is its own
|
|
79
|
+
* KR `kr1.2`. Before, the heading matched nothing — so no objective was read at all — and `KR1.2`
|
|
80
|
+
* matched as `KR1` with a name starting `.2`: a silent collapse of two KRs into one. The dotted part is
|
|
81
|
+
* digits only, and the token is followed by a lookahead, so `KR1.2` can never be read as `KR1`.
|
|
82
|
+
* `Objective` needs a number after it: `## Objectives` and the H1 `# OKRs — …` stay non-objectives.
|
|
83
|
+
*/
|
|
84
|
+
const OBJ_TOKEN = '(O\\d+|O-[A-Za-z][A-Za-z0-9-]*|[Oo]bjective\\s*\\d+)';
|
|
85
|
+
const KR_TOKEN = '(KR\\d+(?:\\.\\d+)*|KR-[A-Za-z][A-Za-z0-9-]*)';
|
|
86
|
+
const TOKEN_END = '(?![A-Za-z0-9]|\\.\\d)';
|
|
78
87
|
const PERIOD = '((?:q|Q)[1-4]-\\d{4})';
|
|
79
88
|
|
|
80
|
-
const RE_OBJ_HEADING = new RegExp('^#{1,3}\\s+' + OBJ_TOKEN + '
|
|
81
|
-
|
|
89
|
+
const RE_OBJ_HEADING = new RegExp('^#{1,3}\\s+(?:\\*\\*)?' + OBJ_TOKEN + TOKEN_END + '(?:\\*\\*)?\\s*(?:[—–:-]\\s*(.*))?$');
|
|
90
|
+
/* A KR bullet: `- **KR1 — name.** more`, `- **KR1.2** — name`, `- KR1.2: name`, `- KR-C — name`. The
|
|
91
|
+
* name is the bolded text when the bold wraps the id and the name, else the rest of the line. */
|
|
92
|
+
const RE_KR_BULLET = new RegExp('^\\s*[-*]\\s*(\\*\\*)?\\s*' + KR_TOKEN + TOKEN_END + '(.*)$');
|
|
93
|
+
|
|
94
|
+
function krBullet(line) {
|
|
95
|
+
const m = RE_KR_BULLET.exec(line);
|
|
96
|
+
if (!m) return null;
|
|
97
|
+
let rest = m[3];
|
|
98
|
+
const sep = /^\s*[—–:.-]?\s*/;
|
|
99
|
+
let name;
|
|
100
|
+
if (m[1] && /^\s*\*\*/.test(rest)) name = rest.replace(/^\s*\*\*/, '').replace(sep, ''); // **KR1.2** — name
|
|
101
|
+
else if (m[1]) { rest = rest.replace(sep, ''); const end = rest.indexOf('**'); name = end >= 0 ? rest.slice(0, end) : rest; }
|
|
102
|
+
else name = rest.replace(sep, '');
|
|
103
|
+
return { token: m[2], name: name.replace(/\*\*/g, '').trim() };
|
|
104
|
+
}
|
|
82
105
|
|
|
83
106
|
// Anchor forms. Order matters only in that the colon forms are tried before the looser ones.
|
|
84
107
|
const RE_HEALTH = /^health:([a-z0-9_-]+)/i; // START-anchored — rule 2
|
|
85
108
|
const RE_DOMAIN = /^domain:([a-z0-9][a-z0-9_-]*)/i; // D67 — the third anchor class
|
|
86
|
-
const RE_COLON_KR = new RegExp('^(?:okrs-)?' + PERIOD + ':([a-z0-9][a-z0-9-]*):(kr-?[a-z0-9-]+)$', 'i');
|
|
109
|
+
const RE_COLON_KR = new RegExp('^(?:okrs-)?' + PERIOD + ':([a-z0-9][a-z0-9-]*):(kr-?[a-z0-9-]+(?:\\.\\d+)*)$', 'i');
|
|
87
110
|
const RE_COLON_OBJ = new RegExp('^(?:okrs-)?' + PERIOD + ':([a-z0-9][a-z0-9-]*)$', 'i');
|
|
88
111
|
const RE_ARROW = new RegExp('^(?:okrs-)?' + PERIOD + '\\s*(?:→|->)\\s*' + OBJ_TOKEN + '(?:\\.' + KR_TOKEN + ')?$', 'i');
|
|
89
112
|
const RE_BARE = new RegExp('^' + OBJ_TOKEN + '(?:\\.' + KR_TOKEN + ')?$', 'i');
|
|
113
|
+
// A KR on its own (`KR1.2`, `KR3`): it names its objective only by being declared under exactly one.
|
|
114
|
+
const RE_BARE_KR = new RegExp('^' + KR_TOKEN + '$', 'i');
|
|
90
115
|
|
|
91
116
|
/** Strip markdown emphasis and trailing commentary. `(`, `#` and `/` never appear inside an id. */
|
|
92
117
|
function stripCommentary(raw) {
|
|
@@ -101,6 +126,8 @@ function stripCommentary(raw) {
|
|
|
101
126
|
* the heading token minus a leading `O-`, lower-cased. */
|
|
102
127
|
function objectiveId(token) {
|
|
103
128
|
const t = String(token || '').trim();
|
|
129
|
+
const n = /^objective\s*(\d+)$/i.exec(t);
|
|
130
|
+
if (n) return 'o' + n[1];
|
|
104
131
|
const m = /^O-(.+)$/i.exec(t);
|
|
105
132
|
return (m ? m[1] : t).toLowerCase();
|
|
106
133
|
}
|
|
@@ -110,6 +137,28 @@ function krId(token) {
|
|
|
110
137
|
return String(token || '').trim().toLowerCase();
|
|
111
138
|
}
|
|
112
139
|
|
|
140
|
+
/*
|
|
141
|
+
* The OKR period, in the order a reader would look for it: a `period:` line (front matter or body),
|
|
142
|
+
* then the H1 (`# OKRs — Q3 2026`), then the filename (`okrs-q3-2026.md`). Each accepts `2026-Q3`,
|
|
143
|
+
* `Q3 2026` and `q3-2026`. → `q3-2026` or null. Only the canonical form needs it; resolution does not.
|
|
144
|
+
*/
|
|
145
|
+
function periodOf(text) {
|
|
146
|
+
const s = String(text || '');
|
|
147
|
+
let m = /(\d{4})[\s_-]*(Q[1-4])(?![0-9])/i.exec(s);
|
|
148
|
+
if (m) return `${m[2].toLowerCase()}-${m[1]}`;
|
|
149
|
+
m = /(?<![A-Za-z])(Q[1-4])[\s_-]*(\d{4})(?![0-9])/i.exec(s);
|
|
150
|
+
return m ? `${m[1].toLowerCase()}-${m[2]}` : null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function filePeriod(text, file) {
|
|
154
|
+
const line = /^\s*[-*]?\s*\**period\**\s*:\s*(.+)$/im.exec(text);
|
|
155
|
+
if (line && periodOf(line[1])) return { period: periodOf(line[1]), from: 'period line' };
|
|
156
|
+
const h1 = /^#\s+(.+)$/m.exec(text);
|
|
157
|
+
if (h1 && periodOf(h1[1])) return { period: periodOf(h1[1]), from: 'title' };
|
|
158
|
+
const name = periodOf(path.basename(file, '.md'));
|
|
159
|
+
return name ? { period: name, from: 'file name' } : null;
|
|
160
|
+
}
|
|
161
|
+
|
|
113
162
|
function listOkrFiles(root) {
|
|
114
163
|
const out = [];
|
|
115
164
|
const seen = new Set();
|
|
@@ -150,41 +199,54 @@ function parseOkrIndex(root) {
|
|
|
150
199
|
const objectives = [];
|
|
151
200
|
const byId = new Map();
|
|
152
201
|
let period = null;
|
|
202
|
+
let periodFrom = null;
|
|
203
|
+
const noPeriod = [];
|
|
153
204
|
for (const file of files) {
|
|
154
205
|
let text;
|
|
155
206
|
try { text = fs.readFileSync(file, 'utf8'); }
|
|
156
207
|
catch (e) {
|
|
157
208
|
return { ok: false, objectives: [], files, error: `could not read ${file}: ${String((e && e.message) || e).slice(0, 120)}` };
|
|
158
209
|
}
|
|
210
|
+
const fp = filePeriod(text, file);
|
|
211
|
+
let declaresObjective = false;
|
|
159
212
|
let cur = null;
|
|
160
213
|
for (const line of text.split('\n')) {
|
|
161
|
-
if (!period) {
|
|
162
|
-
const p = /^\s*[-*]?\s*period\s*:\s*(\d{4})-(Q[1-4])\s*$/i.exec(line);
|
|
163
|
-
if (p) period = `${p[2].toLowerCase()}-${p[1]}`;
|
|
164
|
-
}
|
|
165
214
|
const o = RE_OBJ_HEADING.exec(line);
|
|
166
215
|
if (o) {
|
|
216
|
+
declaresObjective = true;
|
|
167
217
|
const id = objectiveId(o[1]);
|
|
168
218
|
cur = byId.get(id);
|
|
169
219
|
if (!cur) {
|
|
170
|
-
cur = { id, token: o[1], name: (o[2] || '').replace(/\*\*/g, '').trim(), krs: [], file: path.relative(root, file) };
|
|
220
|
+
cur = { id, token: o[1].replace(/\s+/g, ' '), name: (o[2] || '').replace(/\*\*/g, '').trim(), krs: [], file: path.relative(root, file), period: fp ? fp.period : null };
|
|
171
221
|
byId.set(id, cur);
|
|
172
222
|
objectives.push(cur);
|
|
173
223
|
}
|
|
174
224
|
continue;
|
|
175
225
|
}
|
|
176
|
-
const k =
|
|
226
|
+
const k = krBullet(line);
|
|
177
227
|
// A KR with no open objective stays UNATTACHED (rule 3) — never inherited from a previous one.
|
|
178
|
-
if (k && cur && !cur.krs.some((x) => x.id === krId(k
|
|
179
|
-
cur.krs.push({ id: krId(k
|
|
228
|
+
if (k && cur && !cur.krs.some((x) => x.id === krId(k.token))) {
|
|
229
|
+
cur.krs.push({ id: krId(k.token), token: k.token, name: k.name });
|
|
180
230
|
continue;
|
|
181
231
|
}
|
|
182
232
|
// the KR's own measure — its `baseline: … → target: …` sub-bullet (overhaul-r2 B4)
|
|
183
233
|
const bl = /^\s+[-*]\s*baseline\s*:\s*(.+)$/i.exec(line);
|
|
184
234
|
if (bl && cur && cur.krs.length && !cur.krs[cur.krs.length - 1].line) cur.krs[cur.krs.length - 1].line = bl[1].trim();
|
|
185
235
|
}
|
|
236
|
+
if (!declaresObjective) continue; // health-budgets.md, domains.md: not OKR documents, no period expected
|
|
237
|
+
if (fp && !period) { period = fp.period; periodFrom = `${fp.from} of ${path.relative(root, file)}`; }
|
|
238
|
+
if (!fp) noPeriod.push(path.relative(root, file));
|
|
239
|
+
}
|
|
240
|
+
const rels = files.map((f) => path.relative(root, f));
|
|
241
|
+
// What is missing, named with its fix, so a caller never has to guess why a field is empty.
|
|
242
|
+
const missing = [];
|
|
243
|
+
if (!objectives.length) {
|
|
244
|
+
missing.push(`no objective headings were read from ${rels.join(', ')} — write each objective as \`## O1 — title\` or \`## Objective 1 — title\``);
|
|
245
|
+
}
|
|
246
|
+
if (!period && objectives.length) {
|
|
247
|
+
missing.push(`no period found in ${noPeriod.join(', ') || rels.join(', ')} — add a line \`period: 2026-Q3\`, or put the quarter in the title (\`# OKRs — Q3 2026\`) or the file name (\`okrs-q3-2026.md\`)`);
|
|
186
248
|
}
|
|
187
|
-
return { ok: true, objectives, files:
|
|
249
|
+
return { ok: true, objectives, files: rels, period: period || null, period_from: periodFrom, missing, error: null };
|
|
188
250
|
}
|
|
189
251
|
|
|
190
252
|
function readBudgets(root) {
|
|
@@ -298,18 +360,34 @@ function resolveAnchor(raw, index, budgets) {
|
|
|
298
360
|
else if ((m = RE_COLON_OBJ.exec(s))) { period = m[1].toLowerCase(); objTok = m[2]; form = 'q3-2026:<objective>'; }
|
|
299
361
|
else if ((m = RE_ARROW.exec(s))) { period = m[1].toLowerCase(); objTok = m[2]; krTok = m[3] || null; form = 'legacy arrow'; }
|
|
300
362
|
else if ((m = RE_BARE.exec(s))) { objTok = m[1]; krTok = m[2] || null; form = 'legacy bare'; }
|
|
363
|
+
else if ((m = RE_BARE_KR.exec(s))) { krTok = m[1]; form = 'bare KR'; }
|
|
301
364
|
else {
|
|
302
365
|
return Object.assign(base, { kind: 'okr', status: 'unresolvable', form: 'unrecognised', reason: `'${s}' matches no accepted anchor form` });
|
|
303
366
|
}
|
|
304
367
|
|
|
305
368
|
const out = Object.assign({}, base, {
|
|
306
369
|
kind: 'okr', form, period,
|
|
307
|
-
objective: objectiveId(objTok),
|
|
370
|
+
objective: objTok ? objectiveId(objTok) : null,
|
|
308
371
|
kr: krTok ? krId(krTok) : null,
|
|
309
372
|
});
|
|
310
373
|
|
|
311
374
|
if (!index) return Object.assign(out, { status: 'unknown', reason: 'OKR index not supplied to the resolver' });
|
|
312
375
|
if (!index.ok) return Object.assign(out, { status: 'unknown', reason: index.error || 'OKR documents unreadable' });
|
|
376
|
+
if (!index.objectives.length) {
|
|
377
|
+
return Object.assign(out, { status: 'unresolvable', reason: (index.missing && index.missing[0]) || `no objectives declared in ${index.files.join(', ')}` });
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (!out.objective) {
|
|
381
|
+
// A bare KR: its objective is the one objective that declares it. Two objectives with the same KR
|
|
382
|
+
// id is ambiguous, and the reader is told how to write it — never a guess.
|
|
383
|
+
const holders = index.objectives.filter((o) => o.krs.some((k) => k.id === out.kr));
|
|
384
|
+
if (holders.length !== 1) {
|
|
385
|
+
return Object.assign(out, { status: 'unresolvable', reason: holders.length
|
|
386
|
+
? `KR '${out.kr}' is declared under ${holders.map((o) => o.id).join(' and ')} — write it with its objective, e.g. ${holders[0].token}.${krTok}`
|
|
387
|
+
: `no objective declares KR '${out.kr}' in ${index.files.join(', ')}` });
|
|
388
|
+
}
|
|
389
|
+
out.objective = holders[0].id;
|
|
390
|
+
}
|
|
313
391
|
|
|
314
392
|
const obj = index.objectives.find((o) => o.id === out.objective);
|
|
315
393
|
if (!obj) {
|
|
@@ -41,6 +41,10 @@
|
|
|
41
41
|
* task-section { task, section } a task's place in the breakdown (one view, feedback batch 6 item 1): the key
|
|
42
42
|
* of a stage of its initiative's workflow, '' for "Not in a stage". It is the task's place, never its state, and moving a task
|
|
43
43
|
* never moves the initiative. `task` is a Board task or a breakdown item; the last line wins.
|
|
44
|
+
* task-milestone { task, milestone } a task flagged as a milestone (feedback batch 11 item 3): its due
|
|
45
|
+
* date is the milestone's date and Done is its done. `task` is a Board task, a breakdown item or a Jira key; the last line wins.
|
|
46
|
+
* ticket-dates { ref, start, due } the PM's own start and due days for a Jira ticket (feedback batch 11
|
|
47
|
+
* item 23): kept in PMOS only, never written to Jira; '' clears one. They win over Jira's dates on the timeline; the last line wins.
|
|
44
48
|
* Nothing is deleted. A line that is not an object with a known kind is skipped.
|
|
45
49
|
*
|
|
46
50
|
* STAGE OF AN INITIATIVE on a team board: the last move recorded for it on that board (a workflow edit's `moved` and an
|
|
@@ -161,7 +165,9 @@ function foundOf(f) {
|
|
|
161
165
|
const sources = Array.isArray(f.sources) ? f.sources.filter((x) => x && typeof x.ref === 'string').slice(0, 8).map((x) => ({ label: String(x.label || ''), ref: x.ref })) : [];
|
|
162
166
|
return { why: typeof f.why === 'string' ? f.why : '', sources, match: typeof f.match === 'string' && f.match ? f.match : null, scan: typeof f.scan === 'string' ? f.scan : null, run: typeof f.run === 'string' ? f.run : null };
|
|
163
167
|
}
|
|
164
|
-
const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'task-remove', 'task-restore', 'ticket-note', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto', 'task-section'
|
|
168
|
+
const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'task-remove', 'task-restore', 'ticket-note', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto', 'task-section', 'task-milestone', 'ticket-dates',
|
|
169
|
+
// split or merge initiatives (feedback batch 11 item 14): a Jira ticket moved to another initiative, the split and merge records with their Undo, Claude's suggestion dismissed
|
|
170
|
+
'ticket-move', 'ini-split', 'ini-merge', 'ini-sm-undo', 'ini-suggest']);
|
|
165
171
|
// A task's state is its only stage (Wawan, 2026-10-25): the same five every workflow ends in. An old 'In review' reads as In progress (taskState).
|
|
166
172
|
const TASK_STATES = Object.freeze(['To do', 'In progress', 'Done', "Won't do", 'Archived']);
|
|
167
173
|
const taskState = (s) => (s === 'In review' ? 'In progress' : TASK_STATES.includes(s) ? s : null);
|
|
@@ -191,8 +197,10 @@ function fold(events) {
|
|
|
191
197
|
const iniWorkflows = new Map(); // key(board, id) → { template, stages } (the initiative's own workflow)
|
|
192
198
|
const tasks = new Map(); // task id → { id, board, initiative, title, epic, owner, state, start, due, at, by, history }
|
|
193
199
|
const sections = new Map(); // task id → the stage key its breakdown section is ('' = Not in a stage); the last task-section line wins
|
|
200
|
+
const milestones = new Map(); // task id (or Jira key) → true | false: the PM's milestone flag; the last task-milestone line wins
|
|
194
201
|
const removed = new Map(); // task id → the task a task-remove took out, so a task-restore (Delete's Undo) puts it back
|
|
195
202
|
const ticketNotes = new Map(); // key(board, Jira key) → the PM's notes on that ticket (the last ticket-note line wins)
|
|
203
|
+
const ticketDates = new Map(); // key(board, Jira key) → { start, due } the PM keeps in PMOS for that ticket (the last ticket-dates line wins)
|
|
196
204
|
const epics = new Map(); // initiative id → the Jira epic keys the PM linked to it (the last ini-epics line wins)
|
|
197
205
|
const archives = new Map(); // initiative id → { at, by, reason, into, moved } while archived (an `archived: false` line restores it)
|
|
198
206
|
const notDup = new Map(); // initiative id → Set of initiative ids the PM said it is not a duplicate of
|
|
@@ -201,6 +209,12 @@ function fold(events) {
|
|
|
201
209
|
const ends = new Map(); // key(board, id) → { as: 'wontdo', reason, note, at, by } while it is out (a `back` line brings it back to Triage)
|
|
202
210
|
const judged = new Map(); // key(board, id) → { [stageKey]: { runs, why, cite, at, by } } (an `undo` line drops the reading)
|
|
203
211
|
const autoOver = new Map(); // key(board, id) → { [stageKey]: true|false } the PM's own Moves on by itself for one initiative
|
|
212
|
+
// split or merge (batch 11 item 14): Jira key → the initiative it moved to (a split or a merge; `to: null` sends it back to where Jira puts it),
|
|
213
|
+
// op id → the ini-split / ini-merge line (its `undo` says how to put everything back), the ops undone, and the PM's ✕ on Claude's suggestion
|
|
214
|
+
const ticketMoves = new Map();
|
|
215
|
+
const smOps = new Map();
|
|
216
|
+
const smUndone = new Set();
|
|
217
|
+
const suggestNo = new Map(); // initiative id → { kind, fp, at } (the last ✕; a suggestion with another fingerprint shows again)
|
|
204
218
|
const list = [];
|
|
205
219
|
for (let e of Array.isArray(events) ? events : []) {
|
|
206
220
|
if (typeof e === 'string') { try { e = JSON.parse(e); } catch { continue; } }
|
|
@@ -275,6 +289,12 @@ function fold(events) {
|
|
|
275
289
|
t.history.push({ at: e.at || null, by: e.by || null, state: e.state || null, start: e.start || null, due: e.due || null, why: e.why || '' });
|
|
276
290
|
} else if (e.kind === 'task-section' && typeof e.task === 'string' && e.task && typeof e.section === 'string') {
|
|
277
291
|
sections.set(e.task, e.section);
|
|
292
|
+
} else if (e.kind === 'task-milestone' && typeof e.task === 'string' && e.task && typeof e.milestone === 'boolean') {
|
|
293
|
+
milestones.set(e.task, e.milestone);
|
|
294
|
+
} else if (e.kind === 'ticket-dates' && b && typeof e.ref === 'string' && JIRA_KEY_RE.test(e.ref)) {
|
|
295
|
+
const d = (v) => (typeof v === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(v) ? v : '');
|
|
296
|
+
const v = { start: d(e.start), due: d(e.due) };
|
|
297
|
+
if (v.start || v.due) ticketDates.set(key(b, e.ref.toUpperCase()), v); else ticketDates.delete(key(b, e.ref.toUpperCase()));
|
|
278
298
|
} else if (e.kind === 'ticket-note' && b && typeof e.ref === 'string' && typeof e.notes === 'string') {
|
|
279
299
|
if (e.notes) ticketNotes.set(key(b, e.ref), e.notes); else ticketNotes.delete(key(b, e.ref));
|
|
280
300
|
} else if (e.kind === 'task-remove' && typeof e.task === 'string' && tasks.has(e.task)) {
|
|
@@ -319,9 +339,17 @@ function fold(events) {
|
|
|
319
339
|
const a = asks.get(e.ask);
|
|
320
340
|
if (a.state !== 'open') continue;
|
|
321
341
|
Object.assign(a, { state: 'declined', why: e.why || '', closedAt: e.at || null });
|
|
342
|
+
} else if (e.kind === 'ticket-move' && typeof e.key === 'string' && JIRA_KEY_RE.test(e.key)) {
|
|
343
|
+
if (typeof e.to === 'string' && e.to) ticketMoves.set(e.key.toUpperCase(), e.to); else ticketMoves.delete(e.key.toUpperCase());
|
|
344
|
+
} else if ((e.kind === 'ini-split' || e.kind === 'ini-merge') && typeof e.op === 'string' && e.op && !smOps.has(e.op)) {
|
|
345
|
+
smOps.set(e.op, e);
|
|
346
|
+
} else if (e.kind === 'ini-sm-undo' && typeof e.op === 'string' && smOps.has(e.op)) {
|
|
347
|
+
smUndone.add(e.op);
|
|
348
|
+
} else if (e.kind === 'ini-suggest' && typeof e.id === 'string' && e.answer === 'dismiss' && typeof e.fp === 'string') {
|
|
349
|
+
suggestNo.set(e.id, { kind: e.of === 'merge' ? 'merge' : 'split', fp: e.fp, at: e.at || null });
|
|
322
350
|
}
|
|
323
351
|
}
|
|
324
|
-
return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, sections, ticketNotes, epics, archives, notDup, iniWf, ends, judged, autoOver, events: list };
|
|
352
|
+
return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, sections, milestones, ticketNotes, ticketDates, epics, archives, notDup, iniWf, ends, judged, autoOver, ticketMoves, smOps, smUndone, suggestNo, events: list };
|
|
325
353
|
}
|
|
326
354
|
|
|
327
355
|
/** The stages an initiative runs on a board: its own workflow when one is recorded, else the board's. */
|
|
@@ -57,7 +57,7 @@ function priorRejections(root, text) {
|
|
|
57
57
|
|
|
58
58
|
// anchor: only an explicit `health:<id>` or `KR<n>` typed in the line; the caller must still confirm it.
|
|
59
59
|
function suggestAnchor(line) {
|
|
60
|
-
const m = String(line || '').match(/\bhealth:[a-z0-9-]+\b/i) || String(line || '').match(/\bKR\d
|
|
60
|
+
const m = String(line || '').match(/\bhealth:[a-z0-9-]+\b/i) || String(line || '').match(/\bKR\d+(?:\.\d+)*\b/);
|
|
61
61
|
return m ? m[0] : null;
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
//
|
|
5
5
|
// holdsOf(lines) → Map id → [{ from, to, back, reason }] every hold of every initiative, oldest first
|
|
6
6
|
// readHolds(file) → the same, read from a lifecycle.jsonl file ({} when it is missing)
|
|
7
|
-
// planGaps(spans, minDays) → [{ from, to }] the stretches of at least minDays (
|
|
7
|
+
// planGaps(spans, minDays) → [{ from, to, before?, after? }] the stretches of at least minDays (14) that no dated work covers
|
|
8
|
+
// stageSpans(spans) → [{ stage, start, due }] the first start and last due of the dated work in each stage
|
|
8
9
|
//
|
|
9
10
|
// No new record (XtiAGrill 1). A hold is the lifecycle lines PMOS already writes (D70): `on-hold` with `at` and an optional `back`
|
|
10
11
|
// (YYYY-MM-DD), and `active`, `closed` or `cancelled` after it. The latest line still decides the state (scripts/workflow-state.js
|
|
@@ -14,7 +15,8 @@
|
|
|
14
15
|
// - `active`, `closed` or `cancelled` ends the open hold on the day of its `at`. `to` stays null while the hold is open.
|
|
15
16
|
// - A line with no readable day is left out: a hold cannot be drawn without its start.
|
|
16
17
|
// planGaps reads the dated work-items and tasks as { start, due }: a gap is a stretch inside them that none covers, of minDays or more
|
|
17
|
-
// (XtiAGrill 13). It is "nothing planned", never a hold, so it carries no reason.
|
|
18
|
+
// (XtiAGrill 13). It is "nothing planned", never a hold, so it carries no reason. Batch 11 item 13 (XgapAGrill): 2 weeks, not 4, and a gap names
|
|
19
|
+
// the stage of the work on each side (`before`, `after`) when that work has one, so a skipped stage between them can be marked » on it.
|
|
18
20
|
const fs = require('fs');
|
|
19
21
|
|
|
20
22
|
const DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -48,17 +50,29 @@ function readHolds(file) {
|
|
|
48
50
|
return holdsOf(lines);
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
const datedOf = (spans) => (Array.isArray(spans) ? spans : []).map((s) => [dayOf(s && s.start), dayOf(s && (s.due || s.end)), (s && s.stage) || null])
|
|
54
|
+
.map(([a, b, k]) => [a || b, b || a, k]).filter(([a]) => a).sort((x, y) => (x[0] < y[0] ? -1 : x[0] > y[0] ? 1 : 0));
|
|
55
|
+
|
|
51
56
|
function planGaps(spans, minDays) {
|
|
52
|
-
const min = Number.isFinite(minDays) ? minDays :
|
|
53
|
-
const list = (Array.isArray(spans) ? spans : []).map((s) => [dayOf(s && s.start), dayOf(s && (s.due || s.end))])
|
|
54
|
-
.map(([a, b]) => [a || b, b || a]).filter(([a]) => a).sort((x, y) => (x[0] < y[0] ? -1 : x[0] > y[0] ? 1 : 0));
|
|
57
|
+
const min = Number.isFinite(minDays) ? minDays : 14;
|
|
55
58
|
const out = [];
|
|
56
|
-
let end = null;
|
|
57
|
-
for (const [a, b] of
|
|
58
|
-
if (end && dayNum(a) - dayNum(end) >= min) out.push({ from: end, to: a });
|
|
59
|
-
if (!end || b > end) end = b;
|
|
59
|
+
let end = null, endStage = null;
|
|
60
|
+
for (const [a, b, k] of datedOf(spans)) {
|
|
61
|
+
if (end && dayNum(a) - dayNum(end) >= min) out.push({ from: end, to: a, ...(endStage ? { before: endStage } : {}), ...(k ? { after: k } : {}) });
|
|
62
|
+
if (!end || b > end) { end = b; endStage = k; }
|
|
60
63
|
}
|
|
61
64
|
return out;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
function stageSpans(spans) {
|
|
68
|
+
const by = new Map();
|
|
69
|
+
for (const [a, b, k] of datedOf(spans)) {
|
|
70
|
+
if (!k) continue;
|
|
71
|
+
const x = by.get(k);
|
|
72
|
+
if (!x) by.set(k, { stage: k, start: a, due: b });
|
|
73
|
+
else if (b > x.due) x.due = b;
|
|
74
|
+
}
|
|
75
|
+
return [...by.values()];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = { holdsOf, readHolds, planGaps, stageSpans };
|
|
@@ -36,6 +36,14 @@
|
|
|
36
36
|
* RENAME (testing feedback 2026-10-24, canvas RnAIni). Only the record's `title:` line changes, and its `# <title>` heading
|
|
37
37
|
* when that heading is the old title. The id, the file name and every other line stay as they are, so links, the
|
|
38
38
|
* placements and the gates keep reading the same record. Same refusals for the title as a new record; no record → 404.
|
|
39
|
+
*
|
|
40
|
+
* setAnchor(root, id, anchor, { actor }) → { ok: true, id, from, anchor } | { ok: false, … }
|
|
41
|
+
* withdrawSplit(root, id, sha, { actor }) → { ok: true, removed } | { ok: false, … }
|
|
42
|
+
*
|
|
43
|
+
* SPLIT AND MERGE (feedback batch 11 item 14). A merge can keep the closing initiative's anchor: only the `parent_kr:` line changes, to an
|
|
44
|
+
* anchor the OKR files or the health budgets declare (D59, the same check as a new record), and Undo sets the old one back. The Undo of a
|
|
45
|
+
* split takes back the record the split made, only while the file still holds exactly what the split wrote (its sha256): a record the PM
|
|
46
|
+
* has edited since stays, and the Undo says so.
|
|
39
47
|
*/
|
|
40
48
|
const fs = require('fs');
|
|
41
49
|
const path = require('path');
|
|
@@ -182,4 +190,58 @@ function renameInitiative(root, id, title, { actor } = {}) {
|
|
|
182
190
|
return { ok: true, id, path: path.relative(realRoot, file).split(path.sep).join('/'), from, title: name };
|
|
183
191
|
}
|
|
184
192
|
|
|
185
|
-
|
|
193
|
+
/** The record file of an initiative inside the resolved initiatives folder, or a refusal. */
|
|
194
|
+
function recordFile(root, id) {
|
|
195
|
+
if (typeof id !== 'string' || !ID_RE.test(id) || id.includes('..') || id.length > MAX_ID) return refuse(400, 'name the initiative by its id', 'id');
|
|
196
|
+
const loaded = consoleState.loadEngine();
|
|
197
|
+
if (!loaded.ok) return refuse(500, loaded.error);
|
|
198
|
+
let realDir, realRoot;
|
|
199
|
+
try { realDir = fs.realpathSync(loaded.engine.layout(root).initiatives); realRoot = fs.realpathSync(path.resolve(root)); }
|
|
200
|
+
catch { return refuse(404, `no initiative ${id}`, 'id'); }
|
|
201
|
+
if (realDir !== realRoot && !realDir.startsWith(realRoot + path.sep)) return refuse(500, 'the initiatives folder resolves outside the repository — nothing was saved');
|
|
202
|
+
const file = path.join(realDir, `${id}.md`);
|
|
203
|
+
let st;
|
|
204
|
+
try { st = fs.lstatSync(file); } catch { return refuse(404, `no initiative ${id}`, 'id'); }
|
|
205
|
+
if (!st.isFile()) return refuse(409, `the record of ${id} is not a plain file — nothing was saved`, 'id');
|
|
206
|
+
return { ok: true, file, realRoot };
|
|
207
|
+
}
|
|
208
|
+
const sha = (text) => require('crypto').createHash('sha256').update(text).digest('hex');
|
|
209
|
+
/** The sha256 of a record as it is on disk now, or null. A split keeps it, so its Undo can tell an untouched record from an edited one. */
|
|
210
|
+
function recordSha(root, id) {
|
|
211
|
+
const f = recordFile(root, id);
|
|
212
|
+
if (!f.ok) return null;
|
|
213
|
+
try { return sha(fs.readFileSync(f.file, 'utf8')); } catch { return null; }
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function setAnchor(root, id, anchor, { actor } = {}) {
|
|
217
|
+
if (!actorLib.valid(actor)) return refuse(500, 'initiative-writer: the caller must pass the actor from pm-guard.js or actor.js');
|
|
218
|
+
const text0 = typeof anchor === 'string' ? anchor.trim() : '';
|
|
219
|
+
if (!text0 || !ONE_LINE(text0, 120)) return refuse(400, 'an initiative needs an anchor: a KR, or health:<id> from the health budgets (D59)', 'anchor');
|
|
220
|
+
if (rows.anchorsOf(root).resolve(text0).status !== 'resolved') return refuse(400, `the anchor "${text0}" is not declared in the OKR files or the health budgets (D59)`, 'anchor');
|
|
221
|
+
const f = recordFile(root, id);
|
|
222
|
+
if (!f.ok) return f;
|
|
223
|
+
const text = fs.readFileSync(f.file, 'utf8');
|
|
224
|
+
const m = /^---\r?\n([\s\S]*?)\r?\n---(\r?\n|$)/.exec(text);
|
|
225
|
+
if (!m) return refuse(409, `the record of ${id} has no front matter — nothing was saved`, 'id');
|
|
226
|
+
const lines = m[1].split(/\r?\n/);
|
|
227
|
+
const at = lines.findIndex((l) => /^parent_kr:/.test(l));
|
|
228
|
+
const from = at >= 0 ? unquote(lines[at].slice(10)) : '';
|
|
229
|
+
if (from === text0) return { ok: true, id, from, anchor: text0, same: true };
|
|
230
|
+
const line = `parent_kr: ${PLAIN(text0) ? text0 : q(text0)}`;
|
|
231
|
+
if (at >= 0) lines[at] = line; else lines.push(line);
|
|
232
|
+
try { fs.writeFileSync(f.file, '---\n' + lines.join('\n') + '\n---' + m[2] + text.slice(m[0].length), { flag: 'w' }); } catch { return refuse(500, 'the record could not be written — nothing was saved'); }
|
|
233
|
+
return { ok: true, id, from, anchor: text0 };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function withdrawSplit(root, id, want, { actor } = {}) {
|
|
237
|
+
if (!actorLib.valid(actor)) return refuse(500, 'initiative-writer: the caller must pass the actor from pm-guard.js or actor.js');
|
|
238
|
+
const f = recordFile(root, id);
|
|
239
|
+
if (!f.ok) return f.status === 404 ? { ok: true, removed: false } : f;
|
|
240
|
+
let text = '';
|
|
241
|
+
try { text = fs.readFileSync(f.file, 'utf8'); } catch { return refuse(500, 'the record could not be read'); }
|
|
242
|
+
if (!want || sha(text) !== want) return { ok: true, removed: false, edited: true };
|
|
243
|
+
try { fs.unlinkSync(f.file); } catch { return refuse(500, 'the record could not be removed'); }
|
|
244
|
+
return { ok: true, removed: true };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
module.exports = { createInitiative, renameInitiative, setAnchor, withdrawSplit, recordSha, slugOf, ID_RE, INPUT_KEYS };
|
package/workspace/lib/kg.js
CHANGED
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
const adrFor = new Map();
|
|
105
105
|
for (const p of have) { const m = /^okf\/products\/pmos\/adr\/d(\d{2,3})-/.exec(p); if (m) adrFor.set('D' + m[1], p); }
|
|
106
106
|
const krFile = new Map();
|
|
107
|
-
for (const f of list) if (f.path.startsWith('planning/okrs/')) for (const m of f.text.matchAll(/\bO\d+\.KR\d
|
|
107
|
+
for (const f of list) if (f.path.startsWith('planning/okrs/')) for (const m of f.text.matchAll(/\bO\d+\.KR\d+(?:\.\d+)*\b/g)) if (!krFile.has(m[0])) krFile.set(m[0], f.path);
|
|
108
108
|
const budgets = have.has('planning/okrs/health-budgets.md') ? 'planning/okrs/health-budgets.md' : null;
|
|
109
109
|
|
|
110
110
|
const named = DC ? DC.namedFromRecords(list.filter((f) => /(^|\/)initiatives\//.test(f.path)).map((f) => ({ rel: f.path, fm: readFm ? readFm(f.text) : {} }))) : new Map();
|