create-pmos 0.420.0 → 0.422.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 +59 -3
- package/workspace/briefing-premium-board-test.js +1 -1
- 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 +6 -2
- package/workspace/guide/programs.md +4 -3
- package/workspace/home-other-product-test.js +55 -0
- package/workspace/lib/board-premium.js +18 -4
- package/workspace/lib/briefing-premium-agent.js +8 -0
- package/workspace/lib/doc-live-root.js +37 -0
- package/workspace/lib/engine/anchor-resolve.js +93 -15
- package/workspace/lib/engine/boards.js +7 -2
- package/workspace/lib/engine/intake.js +1 -1
- package/workspace/lib/first-input.js +13 -6
- package/workspace/lib/hold-spans.js +24 -10
- package/workspace/lib/kg.js +1 -1
- package/workspace/lib/report-draft.js +3 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-board-premium.js +6 -0
- package/workspace/lib/routes-boards.js +48 -9
- package/workspace/lib/routes-doc-sheet.js +29 -1
- package/workspace/lib/routes-programs.js +44 -5
- package/workspace/lib/routes-task-plans.js +333 -0
- package/workspace/lib/task-cli.js +16 -9
- package/workspace/lib/task-items.js +1 -1
- package/workspace/lib/task-plans.js +232 -0
- package/workspace/lib/transcript-read.js +29 -1
- 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-viewer-test.js +1 -1
- package/workspace/premium-vw-doc-test.js +26 -3
- package/workspace/program-leave-test.js +203 -0
- package/workspace/public/pm/bd-acts.js +5 -2
- package/workspace/public/pm/bd-ini-panel.js +20 -7
- package/workspace/public/pm/bd-prog-panel.js +22 -7
- package/workspace/public/pm/bd-span.js +177 -24
- package/workspace/public/pm/cozy-board.css +80 -0
- package/workspace/public/pm/cozy-home.css +3 -0
- package/workspace/public/pm/cozy-live-pill.js +1 -1
- package/workspace/public/pm/cozy-nav.js +1 -1
- package/workspace/public/pm/cozy-steps.js +1 -1
- package/workspace/public/pm/cozy-xv.js +1 -1
- package/workspace/public/pm/doc-follow.js +36 -0
- package/workspace/public/pm/home-app.js +38 -7
- package/workspace/public/pm/home-ask.js +7 -0
- package/workspace/public/pm/home-ini.js +13 -4
- package/workspace/public/pm/home-line.js +1 -1
- package/workspace/public/pm/home-list.js +2 -2
- package/workspace/public/pm/home-today.js +3 -1
- package/workspace/public/pm/ini-tasks.js +81 -16
- package/workspace/public/pm/ini-versions.js +343 -0
- package/workspace/public/pm/ini-view-model.js +27 -41
- package/workspace/public/pm/ini-view.css +82 -0
- package/workspace/public/pm/ini-view.js +18 -11
- package/workspace/public/pm/premium-board.js +109 -18
- package/workspace/public/pm/premium-insights.js +1 -1
- package/workspace/public/pm/premium-mtg-present.js +2 -2
- package/workspace/public/pm/premium-report-read.js +21 -2
- package/workspace/public/pm/premium-report-tab.js +1 -1
- package/workspace/public/pm/premium-shell.js +29 -4
- package/workspace/public/pm/premium-viewer.js +3 -3
- package/workspace/public/pm/premium-vw-doc.js +46 -11
- package/workspace/public/pm/premium-vw-mtg.js +1 -1
- package/workspace/public/pm/premium-vw-open.js +1 -1
- package/workspace/public/pm/premium-vw-slides.js +1 -1
- package/workspace/public/pm/prog-move.js +69 -0
- package/workspace/public/pm/prog-order.js +1 -1
- package/workspace/public/pm/task-card.css +3 -0
- package/workspace/public/pm/task-card.js +10 -3
- package/workspace/public/pm/tk-send.js +1 -1
- package/workspace/server.js +26 -2
- package/workspace/task-milestones-test.js +176 -0
- package/workspace/task-plans-test.js +175 -0
- package/workspace/task-views-test.js +2 -2
- package/workspace/test-lists/program-leave.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 +70 -5
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]
|
|
6
6
|
* a new task, by the same function as the page's Add a task (lib/routes-boards.js taskAdd, POST /api/boards/tasks/add)
|
|
7
7
|
* pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start …|none] [--owner <who>] [--notes <text>]
|
|
8
|
+
* [--milestone|--no-milestone]
|
|
8
9
|
* place tasks under a workflow stage of their initiative, or change their dates, owner or notes, by the same function as the Viewer's
|
|
9
10
|
* edit (lib/routes-boards.js taskEdit, POST /api/boards/tasks/edit). The Tasks section groups tasks by stage (feedback batch 6:
|
|
10
11
|
* an agent asked to group tasks by stage had no command for it).
|
|
@@ -33,7 +34,9 @@ const USAGE = [
|
|
|
33
34
|
' pmos task add <initiative> "<title>" [--stage <stage>] [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]',
|
|
34
35
|
' Add a task. Every new task goes here; pmos item add is the older breakdown record.',
|
|
35
36
|
' pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>]',
|
|
37
|
+
' [--milestone|--no-milestone]',
|
|
36
38
|
' Group tasks under a stage of the initiative\'s workflow (key or name; none takes it out), or change dates, owner or notes.',
|
|
39
|
+
' --milestone makes a task a milestone: its due date shows as ◇ on the Board and the timeline. Set it only when the PM asks.',
|
|
37
40
|
' pmos task list <initiative> [--all] its open tasks; --all adds Done, Won\'t do and Archived',
|
|
38
41
|
' pmos task remove <task> [<task> …] [--why <text>]',
|
|
39
42
|
' Delete a task added by mistake (a placeholder, a duplicate) when the PM asks. It goes from every list; the page\'s Undo brings',
|
|
@@ -46,7 +49,7 @@ const USAGE = [
|
|
|
46
49
|
' moves the initiative. Move the initiative with pmos workflow move.',
|
|
47
50
|
' every command: [--json] [--root <dir>]. Nothing is sent.',
|
|
48
51
|
];
|
|
49
|
-
const BOOL = new Set(['json', 'help', 'all']);
|
|
52
|
+
const BOOL = new Set(['json', 'help', 'all', 'milestone', 'no-milestone']);
|
|
50
53
|
const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes', 'stage']);
|
|
51
54
|
const ONLY = { add: ['due', 'start', 'owner', 'notes', 'stage'], list: ['all'], state: ['to', 'why'], remove: ['why'], set: ['due', 'start', 'owner', 'notes', 'stage'] };
|
|
52
55
|
const OPEN = new Set(['To do', 'In progress']);
|
|
@@ -90,7 +93,7 @@ function boardsCtx(root, stateDir) {
|
|
|
90
93
|
const w = { id: driver.wsIdOf(root), name: path.basename(root), root };
|
|
91
94
|
return { w, ctx: { getWs: () => w, workspaceList: () => [w], stateDirFor: () => stateDir, selfRoot: path.resolve(__dirname, '..', '..') } };
|
|
92
95
|
}
|
|
93
|
-
const line = (t) => `${t.id} · ${t.state} · ${t.title}${t.kind === 'Epic' ? ' (epic)' : ''}${t.stage ? ' · under ' + t.stage : ''}${t.due ? ' · due ' + t.due : ''}`;
|
|
96
|
+
const line = (t) => `${t.id} · ${t.state} · ${t.title}${t.kind === 'Epic' ? ' (epic)' : ''}${t.milestone ? ' · ◇ milestone' : ''}${t.stage ? ' · under ' + t.stage : ''}${t.due ? ' · due ' + t.due : ''}`;
|
|
94
97
|
/** The workflow row of an initiative, deriving the rows when they are still being read. */
|
|
95
98
|
function rowOf(boards, ctx, w, id) {
|
|
96
99
|
let r = boards.initiativeWorkflow(ctx, w, id);
|
|
@@ -114,6 +117,8 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
114
117
|
const fail = (error, code = 1) => { if (json) say(JSON.stringify({ ok: false, error })); else say(`✗ ${error}`); return code; };
|
|
115
118
|
for (const k of Object.keys(flags)) if (VALUE.has(k) && k !== 'root' && !ONLY[verb].includes(k)) return fail(`--${k} is not an option of ${verb}`, 2);
|
|
116
119
|
if (flags.all && verb !== 'list') return fail(`--all is not an option of ${verb}`, 2);
|
|
120
|
+
for (const k of ['milestone', 'no-milestone']) if (flags[k] && verb !== 'set') return fail(`--${k} is not an option of ${verb}`, 2);
|
|
121
|
+
if (flags.milestone && flags['no-milestone']) return fail('--milestone and --no-milestone contradict each other', 2);
|
|
117
122
|
const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
|
|
118
123
|
const stateDir = driver.stateDirOf(root, { create: verb !== 'list' });
|
|
119
124
|
if (!stateDir) return fail('this repository has no PMOS state folder (pmos/state, state or .pmos)');
|
|
@@ -126,10 +131,11 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
126
131
|
const tasksOf = (id) => {
|
|
127
132
|
const r = rowOf(boards, ctx, w, id);
|
|
128
133
|
const board = r.ok ? r.board.id : null;
|
|
129
|
-
const F = boards.foldOf(ctx, w), S = F.sections || new Map();
|
|
134
|
+
const F = boards.foldOf(ctx, w), S = F.sections || new Map(), MS = F.milestones || new Map();
|
|
135
|
+
const msOf = (tid, own) => (MS.has(tid) ? MS.get(tid) : !!own); // the PM's ◇ flag (feedback batch 11 item 3)
|
|
130
136
|
const stageOf = (tid, from) => (S.has(tid) ? S.get(tid) : (from && from.stage) || ''); // the group the Tasks section shows it under
|
|
131
|
-
const own = [...(F.tasks || new Map()).values()].filter((t) => t.initiative === id).map((t) => ({ ...t, stage: stageOf(t.id, t.from) }));
|
|
132
|
-
const items = TI.rowsOf(root, new Set([id]), board).map((x) => ({ id: x.uid, board, kind: 'Task', title: x.title, state: x.status, owner: x.owner, due: x.end, store: 'item', stage: stageOf(x.uid) }));
|
|
137
|
+
const own = [...(F.tasks || new Map()).values()].filter((t) => t.initiative === id).map((t) => ({ ...t, stage: stageOf(t.id, t.from), milestone: msOf(t.id) }));
|
|
138
|
+
const items = TI.rowsOf(root, new Set([id]), board).map((x) => ({ id: x.uid, board, kind: 'Task', title: x.title, state: x.status, owner: x.owner, due: x.end, store: 'item', stage: stageOf(x.uid), milestone: msOf(x.uid, x.milestone) }));
|
|
133
139
|
return own.concat(items);
|
|
134
140
|
};
|
|
135
141
|
|
|
@@ -160,7 +166,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
160
166
|
try { boards.seedInitiative(ctx, w, id); } catch { /* the To finish tasks are made on the next read */ }
|
|
161
167
|
const all = tasksOf(id);
|
|
162
168
|
const shown = flags.all ? all : all.filter((t) => OPEN.has(t.state));
|
|
163
|
-
if (json) { say(JSON.stringify({ ok: true, tasks: shown.map((t) => ({ id: t.id, board: t.board, kind: t.kind, title: t.title, state: t.state, owner: t.owner, due: t.due, stage: t.stage || '', ...(t.from ? { from: t.from } : {}) })) })); return 0; }
|
|
169
|
+
if (json) { say(JSON.stringify({ ok: true, tasks: shown.map((t) => ({ id: t.id, board: t.board, kind: t.kind, title: t.title, state: t.state, owner: t.owner, due: t.due, stage: t.stage || '', ...(t.milestone ? { milestone: true } : {}), ...(t.from ? { from: t.from } : {}) })) })); return 0; }
|
|
164
170
|
if (!shown.length) { say(all.length ? `No open task on ${id}. --all lists the ${all.length} closed.` : `No task on ${id}.`); return 0; }
|
|
165
171
|
for (const t of shown) say(line(t));
|
|
166
172
|
return 0;
|
|
@@ -178,8 +184,8 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
178
184
|
};
|
|
179
185
|
|
|
180
186
|
if (verb === 'set') {
|
|
181
|
-
const keys = ['stage', 'due', 'start', 'owner', 'notes'].filter((k) => flags[k] !== undefined);
|
|
182
|
-
if (!pos.length || !keys.length) { say('usage: pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>]'); return 2; }
|
|
187
|
+
const keys = ['stage', 'due', 'start', 'owner', 'notes'].filter((k) => flags[k] !== undefined).concat(flags.milestone || flags['no-milestone'] ? ['milestone'] : []);
|
|
188
|
+
if (!pos.length || !keys.length) { say('usage: pmos task set <task> [<task> …] [--stage <stage>|none] [--due YYYY-MM-DD|none] [--start YYYY-MM-DD|none] [--owner <who>] [--notes <text>] [--milestone|--no-milestone]'); return 2; }
|
|
183
189
|
const folded = boards.foldOf(ctx, w);
|
|
184
190
|
const done = [], refused = [];
|
|
185
191
|
for (const id of pos) {
|
|
@@ -195,11 +201,12 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
195
201
|
}
|
|
196
202
|
for (const k of ['due', 'start']) if (flags[k] !== undefined) body[k] = String(flags[k]).toLowerCase() === 'none' ? '' : flags[k];
|
|
197
203
|
for (const k of ['owner', 'notes']) if (flags[k] !== undefined) body[k] = flags[k];
|
|
204
|
+
if (flags.milestone || flags['no-milestone']) body.milestone = !!flags.milestone;
|
|
198
205
|
const e = boards.taskEdit(ctx, body, g);
|
|
199
206
|
if (!e.body || e.body.ok !== true) refused.push({ task: id, error: (e.body && e.body.error) || 'the write was refused' });
|
|
200
207
|
else done.push({ task: id, title: t.title, set: Object.fromEntries(keys.map((k) => [k, k === 'stage' ? body.section : body[k]])) });
|
|
201
208
|
}
|
|
202
|
-
const what = (x) => Object.entries(x).map(([k, v]) => (k === 'stage' ? (v ? 'under ' + v : 'under no stage') : v === '' ? 'no ' + k : k + ' ' + v)).join(', ');
|
|
209
|
+
const what = (x) => Object.entries(x).map(([k, v]) => (k === 'stage' ? (v ? 'under ' + v : 'under no stage') : k === 'milestone' ? (v ? 'a milestone' : 'not a milestone') : v === '' ? 'no ' + k : k + ' ' + v)).join(', ');
|
|
203
210
|
if (json) say(JSON.stringify({ ok: !refused.length, done, refused }));
|
|
204
211
|
else {
|
|
205
212
|
for (const d of done) say(`✓ ${d.task} ${what(d.set)}: ${d.title}`);
|
|
@@ -54,7 +54,7 @@ function rowsOf(root, ids, board) {
|
|
|
54
54
|
const it = f.items[id];
|
|
55
55
|
if (!it || it.proposed || !ids.has(it.initiative)) continue;
|
|
56
56
|
out.push({ uid: it.id, key: '', kind: 'Task', src: 'pmos', store: 'item', title: it.title, status: STATE_OF[it.state] || 'To do', blocked: !!it.blocked, owner: ownerName(it.owner),
|
|
57
|
-
notes: it.note || '', ini: it.initiative, epic: null, start: it.start || null, end: it.due || null, ref: it.id, board,
|
|
57
|
+
notes: it.note || '', ini: it.initiative, epic: null, start: it.start || null, end: it.due || null, ref: it.id, board, ...(it.milestone ? { milestone: true } : {}),
|
|
58
58
|
// the breakdown's own stage (plan-tree) and order: the one view places the item in the workflow stage of the same name
|
|
59
59
|
...(it.stage ? { itemStage: it.stage } : {}), ...(Number.isFinite(it.order) ? { order: it.order } : {}) });
|
|
60
60
|
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* task-plans.js — planned versus actual (feedback batch 11 item 8; canvas In development, row "Planned vs actual": PvaACGrill, PvaAC1Live,
|
|
3
|
+
* PvaAC2Menu, PvaAC3Draft, PvaAC4Board, PvaAC5Phone). THE ONE WRITER and THE ONE FOLD of <state>/task-plans.jsonl, beside boards.jsonl.
|
|
4
|
+
*
|
|
5
|
+
* Two records, both append-only:
|
|
6
|
+
* A DRAFT is a named copy of an initiative's PMOS tasks (title, stage, dates, owner, milestone flag). It changes nothing in Live, on the
|
|
7
|
+
* Board or in Jira; Jira tickets are not copied. Every task in it is an assumption. An initiative with no saved plan keeps a new task in an
|
|
8
|
+
* automatic draft named "Proposal". "Make live" applies a draft to Live (lib/routes-task-plans.js) and saves a plan named after it; the
|
|
9
|
+
* initiative's other open drafts go to Not chosen (kept, folded).
|
|
10
|
+
* A SAVED PLAN is a frozen copy of each Live task's start and due day: made by Make live, by "Save Live as a plan", and once by PMOS when
|
|
11
|
+
* the initiative enters Build with no plan yet. The timelines draw it as the thin line under each bar.
|
|
12
|
+
*
|
|
13
|
+
* THE LEDGER. One line per change, { at, by, kind, ... }:
|
|
14
|
+
* draft-new { draft, board, initiative, name, auto?, from: 'live' | 'empty' | <draft id>, tasks: [task] } task: { k, src, title, section,
|
|
15
|
+
* from, itemStage, start, due, owner, milestone, status } — `src` is the Live task it copies (null for a new one); its fields at
|
|
16
|
+
* the copy are its `base`, so Make live knows what the draft changed and what Live changed since
|
|
17
|
+
* draft-task { draft, k, add: {fields} | set: {fields} | drop: true | undrop: true }
|
|
18
|
+
* draft-name { draft, name } · draft-delete { draft } · draft-restore { draft }
|
|
19
|
+
* draft-live { draft, plan, undo: { added: [uid], changed: [{ uid, item, from }], dropped: [{ uid, item, from }], unchosen: [draft id] } }
|
|
20
|
+
* draft-unlive { draft } the Undo of Make live (the route writes the reverse lines in boards.jsonl and the plan-items ledger)
|
|
21
|
+
* plan { plan, board, initiative, name, source: 'draft' | 'live' | 'build', tasks: [{ uid, title, start, due }] }
|
|
22
|
+
* plan-remove { plan } the Undo of a save
|
|
23
|
+
*
|
|
24
|
+
* ledgerFile(dir) · read(dir) → fold · append(dir, actor, line) → the line
|
|
25
|
+
* fold(lines) → { drafts: Map, plans: Map, t } PURE
|
|
26
|
+
* taskOfLive(x) → a draft task copied from a Live task (the work-item shape of routes-boards itemsOf)
|
|
27
|
+
* versionsOf(F, ini, live) → { t, drafts, notChosen, plans } | null what the Tasks header chip reads (null: nothing to show)
|
|
28
|
+
* planTasksOf(live) → [{ uid, title, start, due }] the frozen dates of the Live tasks that count (no Won't do, no Archived)
|
|
29
|
+
* stepsOf(draft, live) → { add, change, drop, conflicts } PURE: what Make live writes
|
|
30
|
+
* summaryOf(steps) → { added, moved, dropped, conflicts: [title] }
|
|
31
|
+
* spanOf(tasks) → { start, end } | null
|
|
32
|
+
* dayDiff(a, b) → whole days from a to b
|
|
33
|
+
*/
|
|
34
|
+
const fs = require('fs');
|
|
35
|
+
const path = require('path');
|
|
36
|
+
const crypto = require('crypto');
|
|
37
|
+
|
|
38
|
+
const LEDGER = 'task-plans.jsonl';
|
|
39
|
+
const KINDS = new Set(['draft-new', 'draft-task', 'draft-name', 'draft-delete', 'draft-restore', 'draft-live', 'draft-unlive', 'plan', 'plan-remove']);
|
|
40
|
+
const FIELDS = ['title', 'section', 'start', 'due', 'owner', 'milestone', 'status'];
|
|
41
|
+
const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
|
|
42
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
43
|
+
const DAY = /^\d{4}-\d{2}-\d{2}$/;
|
|
44
|
+
const newId = (stem) => stem + '-' + crypto.randomBytes(5).toString('hex');
|
|
45
|
+
const newKey = () => 'k' + crypto.randomBytes(4).toString('hex');
|
|
46
|
+
|
|
47
|
+
function ledgerFile(dir) { return dir ? path.join(dir, LEDGER) : null; }
|
|
48
|
+
function readLines(file) {
|
|
49
|
+
if (!file) return [];
|
|
50
|
+
let text = '';
|
|
51
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
52
|
+
const out = [];
|
|
53
|
+
for (const raw of text.split('\n')) { if (!raw.trim()) continue; try { const l = JSON.parse(raw); if (isObj(l) && KINDS.has(l.kind)) out.push(l); } catch { /* a torn line is skipped */ } }
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
function read(dir) { return fold(readLines(ledgerFile(dir))); }
|
|
57
|
+
function append(dir, actor, ev) {
|
|
58
|
+
const line = { at: new Date().toISOString(), by: (actor && actor.by) || null, ...ev };
|
|
59
|
+
fs.appendFileSync(ledgerFile(dir), JSON.stringify(line) + '\n');
|
|
60
|
+
return line;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One draft task's fields, cleaned: the strings it may hold, a day or '' for start and due. */
|
|
64
|
+
function clean(t) {
|
|
65
|
+
const o = {};
|
|
66
|
+
for (const k of FIELDS) {
|
|
67
|
+
if (!(k in t)) continue;
|
|
68
|
+
if (k === 'milestone') o.milestone = t.milestone === true;
|
|
69
|
+
else if (k === 'start' || k === 'due') o[k] = DAY.test(str(t[k])) ? t[k] : '';
|
|
70
|
+
else o[k] = str(t[k]);
|
|
71
|
+
}
|
|
72
|
+
return o;
|
|
73
|
+
}
|
|
74
|
+
/** A draft task as the ledger holds it: its fields and where it came from. A copy of a draft also carries the base and the drop it had. */
|
|
75
|
+
function taskLine(t) {
|
|
76
|
+
const f = clean(t);
|
|
77
|
+
return { k: str(t.k) || newKey(), src: typeof t.src === 'string' && t.src ? t.src : null, ...f,
|
|
78
|
+
...(isObj(t.from) ? { from: { stage: str(t.from.stage), finish: str(t.from.finish) } } : {}), ...(t.itemStage ? { itemStage: str(t.itemStage) } : {}), ...(t.item ? { item: true } : {}) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function fold(lines) {
|
|
82
|
+
const drafts = new Map(), plans = new Map();
|
|
83
|
+
let t = '';
|
|
84
|
+
for (const e of Array.isArray(lines) ? lines : []) {
|
|
85
|
+
if (!isObj(e) || !KINDS.has(e.kind)) continue;
|
|
86
|
+
if (e.at && e.at > t) t = e.at;
|
|
87
|
+
if (e.kind === 'draft-new' && typeof e.draft === 'string' && typeof e.initiative === 'string' && !drafts.has(e.draft)) {
|
|
88
|
+
const tasks = new Map();
|
|
89
|
+
for (const x of Array.isArray(e.tasks) ? e.tasks : []) {
|
|
90
|
+
if (!isObj(x) || typeof x.k !== 'string') continue;
|
|
91
|
+
const f = clean(x);
|
|
92
|
+
tasks.set(x.k, { ...x, ...f, base: x.src ? (isObj(x.base) ? clean(x.base) : { ...f }) : null, drop: x.drop === true && !!x.src });
|
|
93
|
+
}
|
|
94
|
+
drafts.set(e.draft, { id: e.draft, board: str(e.board), ini: e.initiative, name: str(e.name) || 'Draft', auto: e.auto === true, from: str(e.from) || 'live',
|
|
95
|
+
at: e.at || null, by: e.by || null, state: 'open', tasks, liveAt: null, plan: null });
|
|
96
|
+
} else if (e.kind === 'draft-task' && drafts.has(e.draft) && typeof e.k === 'string') {
|
|
97
|
+
const d = drafts.get(e.draft), x = d.tasks.get(e.k);
|
|
98
|
+
if (isObj(e.add) && !x) d.tasks.set(e.k, { k: e.k, src: null, title: '', section: '', start: '', due: '', owner: '', milestone: false, status: 'To do', ...clean(e.add), base: null, drop: false, addedAt: e.at || null });
|
|
99
|
+
else if (x && isObj(e.set)) Object.assign(x, clean(e.set));
|
|
100
|
+
else if (x && e.drop === true) { if (x.src) x.drop = true; else d.tasks.delete(e.k); }
|
|
101
|
+
else if (x && e.undrop === true) x.drop = false;
|
|
102
|
+
} else if (e.kind === 'draft-name' && drafts.has(e.draft) && str(e.name).trim()) {
|
|
103
|
+
drafts.get(e.draft).name = e.name.trim();
|
|
104
|
+
} else if (e.kind === 'draft-delete' && drafts.has(e.draft)) {
|
|
105
|
+
const d = drafts.get(e.draft); d.was = d.state; d.state = 'deleted';
|
|
106
|
+
} else if (e.kind === 'draft-restore' && drafts.has(e.draft) && drafts.get(e.draft).state === 'deleted') {
|
|
107
|
+
const d = drafts.get(e.draft); d.state = d.was || 'open';
|
|
108
|
+
} else if (e.kind === 'draft-live' && drafts.has(e.draft)) {
|
|
109
|
+
const d = drafts.get(e.draft), u = isObj(e.undo) ? e.undo : {};
|
|
110
|
+
d.state = 'live'; d.liveAt = e.at || null; d.plan = str(e.plan) || null; d.undo = u;
|
|
111
|
+
for (const id of Array.isArray(u.unchosen) ? u.unchosen : []) { const o = drafts.get(id); if (o && o.state === 'open') o.state = 'not-chosen'; }
|
|
112
|
+
} else if (e.kind === 'draft-unlive' && drafts.has(e.draft) && drafts.get(e.draft).state === 'live') {
|
|
113
|
+
const d = drafts.get(e.draft), u = d.undo || {};
|
|
114
|
+
d.state = 'open'; d.liveAt = null; d.plan = null;
|
|
115
|
+
for (const id of Array.isArray(u.unchosen) ? u.unchosen : []) { const o = drafts.get(id); if (o && o.state === 'not-chosen') o.state = 'open'; }
|
|
116
|
+
} else if (e.kind === 'plan' && typeof e.plan === 'string' && typeof e.initiative === 'string' && !plans.has(e.plan)) {
|
|
117
|
+
plans.set(e.plan, { id: e.plan, board: str(e.board), ini: e.initiative, name: str(e.name) || 'Plan', source: str(e.source) || 'live', at: e.at || null, by: e.by || null,
|
|
118
|
+
tasks: (Array.isArray(e.tasks) ? e.tasks : []).filter((x) => isObj(x) && typeof x.uid === 'string').map((x) => ({ uid: x.uid, title: str(x.title), start: DAY.test(str(x.start)) ? x.start : '', due: DAY.test(str(x.due)) ? x.due : '' })) });
|
|
119
|
+
} else if (e.kind === 'plan-remove' && plans.has(e.plan)) {
|
|
120
|
+
plans.delete(e.plan);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return { drafts, plans, t };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A Live task (routes-boards itemsOf's work item, or board-premium's r.tasks row) as a draft task's fields. */
|
|
127
|
+
function taskOfLive(x) {
|
|
128
|
+
return taskLine({ src: x.uid, title: x.title || '', section: typeof x.section === 'string' ? x.section : '', start: x.start || '', due: x.end || x.due || '', owner: x.owner || '',
|
|
129
|
+
milestone: x.milestone === true, status: x.status || 'To do', from: x.from || null, itemStage: x.itemStage || '', item: x.store === 'item' || x.item === true });
|
|
130
|
+
}
|
|
131
|
+
const counts = (x) => x && x.status !== "Won't do" && x.status !== 'Archived';
|
|
132
|
+
/** The frozen dates of a plan: every Live task that counts, with a date. */
|
|
133
|
+
function planTasksOf(live) {
|
|
134
|
+
return (live || []).filter((x) => x && x.uid && counts(x) && (x.start || x.end || x.due)).map((x) => ({ uid: x.uid, title: x.title || '', start: x.start || '', due: x.end || x.due || '' }));
|
|
135
|
+
}
|
|
136
|
+
function spanOf(tasks) {
|
|
137
|
+
let a = '', b = '';
|
|
138
|
+
for (const x of tasks || []) {
|
|
139
|
+
const s = x.start || x.due || x.end || '', e = x.due || x.end || x.start || '';
|
|
140
|
+
if (s && (!a || s < a)) a = s;
|
|
141
|
+
if (e && (!b || e > b)) b = e;
|
|
142
|
+
}
|
|
143
|
+
return a ? { start: a, end: b } : null;
|
|
144
|
+
}
|
|
145
|
+
const dayNo = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? Math.round(Date.UTC(+m[1], +m[2] - 1, +m[3]) / 864e5) : null; };
|
|
146
|
+
function dayDiff(a, b) { const x = dayNo(a), y = dayNo(b); return x == null || y == null ? null : y - x; }
|
|
147
|
+
|
|
148
|
+
/** A draft's tasks in the shape r.tasks has (board-premium), so the one view draws a draft as it draws Live: uid `dt:<draft>:<k>`. */
|
|
149
|
+
function draftRows(d) {
|
|
150
|
+
const out = [];
|
|
151
|
+
for (const x of d.tasks.values()) {
|
|
152
|
+
if (x.drop) continue;
|
|
153
|
+
out.push({ uid: 'dt:' + d.id + ':' + x.k, title: x.title, status: x.status || 'To do', owner: x.owner || '', start: x.start || '', end: x.due || '',
|
|
154
|
+
...(x.section ? { section: x.section } : {}), ...(x.from && x.from.stage ? { from: x.from } : {}), ...(x.itemStage ? { itemStage: x.itemStage } : {}),
|
|
155
|
+
...(x.milestone ? { milestone: true } : {}), ...(x.src ? { src: x.src } : { added: true }), draft: true });
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
/** Whether Live changed a task of the draft since the copy (the draft row's blue dot). */
|
|
160
|
+
function liveChanged(d, liveBy) {
|
|
161
|
+
for (const x of d.tasks.values()) {
|
|
162
|
+
if (!x.src || !x.base) continue;
|
|
163
|
+
const l = liveBy.get(x.src);
|
|
164
|
+
if (!l) return true;
|
|
165
|
+
const now = taskOfLive(l);
|
|
166
|
+
if (['title', 'start', 'due', 'owner'].some((k) => (now[k] || '') !== (x.base[k] || ''))) return true;
|
|
167
|
+
}
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
/** What the Tasks header chip reads for one initiative. null when there is no draft, no Not chosen and no saved plan (the chip hides). */
|
|
171
|
+
function versionsOf(F, ini, live) {
|
|
172
|
+
const liveBy = new Map((live || []).map((x) => [x.uid, x]));
|
|
173
|
+
const ds = [...F.drafts.values()].filter((d) => d.ini === ini);
|
|
174
|
+
const plans = [...F.plans.values()].filter((p) => p.ini === ini).sort((a, b) => String(a.at || '').localeCompare(String(b.at || '')));
|
|
175
|
+
const open = ds.filter((d) => d.state === 'open'), nc = ds.filter((d) => d.state === 'not-chosen');
|
|
176
|
+
if (!open.length && !nc.length && !plans.length) return null;
|
|
177
|
+
const one = (d) => { const rows = draftRows(d); return { id: d.id, name: d.name, auto: d.auto, from: d.from, at: d.at, liveChanged: d.from !== 'empty' && liveChanged(d, liveBy), tasks: rows, span: spanOf(rows) }; };
|
|
178
|
+
return { t: F.t, drafts: open.map(one), notChosen: nc.map(one),
|
|
179
|
+
plans: plans.map((p) => ({ id: p.id, name: p.name, source: p.source, at: p.at, tasks: p.tasks, span: spanOf(p.tasks) })).reverse() };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** What Make live writes for draft d against Live (the work items of the initiative, by uid). Pure.
|
|
183
|
+
* add: the draft's new tasks · change: a copied task whose fields the draft changed (the draft wins; `conflict` when Live changed the same
|
|
184
|
+
* field since the copy) · drop: a copied task the draft dropped, still open in Live (it becomes Won't do, never deleted). */
|
|
185
|
+
function stepsOf(d, live) {
|
|
186
|
+
const by = new Map((live || []).map((x) => [x.uid, x]));
|
|
187
|
+
const add = [], change = [], drop = [], conflicts = [];
|
|
188
|
+
for (const x of d.tasks.values()) {
|
|
189
|
+
if (!x.src) { if (!x.drop) add.push(x); continue; }
|
|
190
|
+
const l = by.get(x.src);
|
|
191
|
+
if (!l) continue; // gone from Live since the copy: nothing to change
|
|
192
|
+
const now = taskOfLive(l);
|
|
193
|
+
if (x.drop) { if (now.status !== "Won't do" && now.status !== 'Archived' && now.status !== 'Done') drop.push({ uid: x.src, item: !!now.item, title: now.title, from: now.status }); continue; }
|
|
194
|
+
const set = {}, from = {};
|
|
195
|
+
let clash = false;
|
|
196
|
+
for (const k of ['title', 'start', 'due', 'owner', 'section']) {
|
|
197
|
+
const base = (x.base && x.base[k]) || '', mine = x[k] || '', theirs = now[k] || '';
|
|
198
|
+
if (mine === base) continue; // the draft did not change it: Live keeps its own
|
|
199
|
+
if (mine === theirs) continue;
|
|
200
|
+
if (theirs !== base) clash = true;
|
|
201
|
+
set[k] = mine; from[k] = theirs;
|
|
202
|
+
}
|
|
203
|
+
if (Object.keys(set).length) { change.push({ uid: x.src, item: !!now.item, title: x.title || now.title, set, from, moved: 'start' in set || 'due' in set }); if (clash) conflicts.push(x.title || now.title); }
|
|
204
|
+
}
|
|
205
|
+
return { add, change, drop, conflicts };
|
|
206
|
+
}
|
|
207
|
+
function summaryOf(s) {
|
|
208
|
+
return { added: s.add.length, moved: s.change.filter((c) => c.moved).length, changed: s.change.length, dropped: s.drop.length, conflicts: s.conflicts.slice(0, 20),
|
|
209
|
+
milestones: s.add.filter((x) => x.milestone).map((x) => ({ title: x.title, due: x.due || '' })).slice(0, 10) };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The Board's rows (board-premium) with what planned versus actual adds: r.versions (the Tasks header chip), r.plan (the newest saved plan's
|
|
213
|
+
* span and the end slip, for the thin line under the bar) and r.draft (an initiative with drafts only: its newest draft, drawn dashed).
|
|
214
|
+
* Zero is silence: nothing is added to a row with no draft and no plan. Mutates and returns rows. */
|
|
215
|
+
function decorate(rows, F) {
|
|
216
|
+
for (const r of rows || []) {
|
|
217
|
+
if (!r || !r.id || r.versions !== undefined) continue;
|
|
218
|
+
const live = r.tasks || [], v = versionsOf(F, r.id, live);
|
|
219
|
+
if (!v) continue;
|
|
220
|
+
r.versions = v;
|
|
221
|
+
const cnt = live.filter(counts), ls = spanOf(cnt), p = v.plans[0];
|
|
222
|
+
if (p && p.span) r.plan = { id: p.id, name: p.name, start: p.span.start, end: p.span.end, slip: ls ? dayDiff(p.span.end, ls.end) : null };
|
|
223
|
+
if (!cnt.length && v.drafts.length) {
|
|
224
|
+
const ds = v.drafts.slice().sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')));
|
|
225
|
+
const top = ds.find((d) => d.span) || ds[0];
|
|
226
|
+
if (top && top.span) r.draft = { id: top.id, name: top.name, start: top.span.start, end: top.span.end, others: ds.filter((d) => d !== top).map((d) => ({ name: d.name, end: d.span ? d.span.end : '' })) };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return rows;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
module.exports = { decorate, LEDGER, ledgerFile, read, readLines, append, fold, taskLine, taskOfLive, planTasksOf, versionsOf, draftRows, stepsOf, summaryOf, spanOf, dayDiff, newId, newKey };
|
|
@@ -530,5 +530,33 @@ function permissionAsk(screen, clean = (x) => x) {
|
|
|
530
530
|
return options.length >= 2 ? { question: clean(lines[at]).slice(0, 200), options } : null;
|
|
531
531
|
}
|
|
532
532
|
|
|
533
|
-
|
|
533
|
+
/*
|
|
534
|
+
* Claude Code's folder trust prompt, read from the pane's visible screen the same way (feedback batch 10 item 1). A folder that
|
|
535
|
+
* Claude Code (under the profile the session runs with) was never told to trust opens with "Is this a project you trust?" or
|
|
536
|
+
* "Do you trust the files in this folder?", with "No, exit" as an answer. Typing the chat's first message into it chose an answer
|
|
537
|
+
* and the session ended within seconds, so the chat showed nothing. Returns { question, options, trust: true } or null.
|
|
538
|
+
*/
|
|
539
|
+
const TRUST_RE = /(trust the files in this folder|project you (?:created or one you )?trust|trust this (?:folder|project))/i;
|
|
540
|
+
const SEL_RE = /^[❯›>]\s+/;
|
|
541
|
+
const NUM_RE = /^\d[.)]\s+/;
|
|
542
|
+
/** The menu's answers: the lines next to the selected one (❯), up to a blank line. Each answer's n is its place (1 first) and sel is the
|
|
543
|
+
* place of the selected one, so the page can move the selection to an answer (arrow keys) and press Enter. The answers may or may not
|
|
544
|
+
* carry numbers. */
|
|
545
|
+
function trustAsk(screen, clean = (x) => x) {
|
|
546
|
+
const lines = String(screen || '').split('\n').map((l) => l.replace(/[│┃╭╮╰╯]/g, ' ').replace(/\s+$/, '').trim());
|
|
547
|
+
let k = -1;
|
|
548
|
+
for (let i = lines.length - 1; i >= 0; i--) if (SEL_RE.test(lines[i])) { k = i; break; }
|
|
549
|
+
if (k < 0) return null;
|
|
550
|
+
let a = k, b = k;
|
|
551
|
+
while (a > 0 && lines[a - 1] && !TRUST_RE.test(lines[a - 1]) && a > k - 6) a--;
|
|
552
|
+
while (b + 1 < lines.length && lines[b + 1] && !/^Enter to confirm/i.test(lines[b + 1]) && b < k + 6) b++;
|
|
553
|
+
const block = lines.slice(a, b + 1).map((l) => l.replace(SEL_RE, '').replace(NUM_RE, '').trim());
|
|
554
|
+
if (block.length < 2 || block.length > 6 || !block.some((l) => /\bexit\b/i.test(l))) return null;
|
|
555
|
+
let q = null;
|
|
556
|
+
for (let i = a - 1; i >= 0 && i >= a - 12; i--) if (TRUST_RE.test(lines[i])) { q = lines[i]; break; }
|
|
557
|
+
if (!q && !block.some((l) => /trust/i.test(l))) return null;
|
|
558
|
+
return { question: clean(q || 'Do you trust the files in this folder?').slice(0, 200), options: block.map((l, i) => ({ n: String(i + 1), label: clean(l).slice(0, 160) })), sel: k - a + 1, trust: true };
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
module.exports = { trustAsk, permissionAsk, askQuestions, claudeHomes, callTarget, findTranscript, readHarness, readConversation, CONV_LIMIT, prettyTool, slugFor, resolvePid, descendants,
|
|
534
562
|
MAX_BYTES, MAX_WALK_DEPTH, PS_SNAPSHOT_MS, defaultChildren };
|
|
@@ -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) {
|
|
@@ -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
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.422.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.422.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED
|
@@ -82,7 +82,7 @@ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
|
82
82
|
ok('R1 vwConfirm draws a card with the question in the shown item', (await page.textContent('#czViewer .vcf p')) === 'Undo all 3 edits?');
|
|
83
83
|
await page.click('#czViewer .vcf [data-a="1"]');
|
|
84
84
|
ok('R1 vwConfirm resolves true on the yes button and removes the card', (await yes) === true && !(await page.$('.vcf')));
|
|
85
|
-
ok('R1 vwStyle adds the view\'s stylesheet link once', await page.evaluate(() => { window.__premiumViewer.vwStyle('none-such'); window.__premiumViewer.vwStyle('none-such'); window.__premiumViewer.vwStyle('../x'); const l = document.querySelectorAll('link[data-vw-css="none-such"]'); return l.length === 1 && l[0].getAttribute('href')
|
|
85
|
+
ok('R1 vwStyle adds the view\'s stylesheet link once', await page.evaluate(() => { window.__premiumViewer.vwStyle('none-such'); window.__premiumViewer.vwStyle('none-such'); window.__premiumViewer.vwStyle('../x'); const l = document.querySelectorAll('link[data-vw-css="none-such"]'); return l.length === 1 && /\/pm\/premium-vw-none-such\.css$/.test(l[0].getAttribute('href')) && !document.querySelector('link[href*="/x.css"]'); }));
|
|
86
86
|
await page.click('#czViewer [data-cz-vw="close"]');
|
|
87
87
|
s = await st(page);
|
|
88
88
|
ok('R1 Close empties and hides the card', !s.open && s.panes.length === 0, JSON.stringify(s));
|