create-pmos 0.443.0 → 0.445.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 +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/adler-moments-test.js +8 -0
- package/workspace/adler-seasons-art-test.js +3 -0
- package/workspace/board-columns-test.js +168 -0
- package/workspace/board-programs-test.js +1 -1
- package/workspace/briefing-premium-board-test.js +91 -8
- package/workspace/briefing-premium-insights-test.js +83 -38
- package/workspace/briefing-premium-test.js +2 -1
- package/workspace/calm-timeline-test.js +3 -1
- package/workspace/changelog.json +24 -0
- package/workspace/goals-clear-ui-test.js +34 -20
- package/workspace/guide/home.md +5 -0
- package/workspace/guide/jira.md +13 -1
- package/workspace/guide/ready-made-dashboards.md +2 -2
- package/workspace/intel-report-ui-test.js +1 -1
- package/workspace/lib/board-fold.js +33 -5
- package/workspace/lib/board-premium.js +1 -1
- package/workspace/lib/console-state.js +5 -1
- package/workspace/lib/engine/boards.js +9 -2
- package/workspace/lib/factory-join.js +46 -14
- package/workspace/lib/freshness.js +14 -1
- package/workspace/lib/initiative-rows.js +38 -4
- package/workspace/lib/issues.js +8 -1
- package/workspace/lib/jira-cli.js +18 -2
- package/workspace/lib/jira-moves.js +119 -0
- package/workspace/lib/jira-tickets.js +23 -4
- package/workspace/lib/notes.js +4 -2
- package/workspace/lib/offloop.js +75 -29
- package/workspace/lib/page-build.js +97 -0
- package/workspace/lib/plan-items.js +24 -3
- package/workspace/lib/plan-tree.js +62 -9
- package/workspace/lib/ready-reports.js +22 -8
- package/workspace/lib/refresh.js +14 -2
- package/workspace/lib/routes-board-premium.js +9 -1
- package/workspace/lib/routes-boards.js +114 -16
- package/workspace/lib/routes-brief-page.js +3 -1
- package/workspace/lib/routes-calendar-import.js +13 -1
- package/workspace/lib/routes-ready-reports.js +28 -5
- package/workspace/lib/task-links.js +12 -1
- package/workspace/lib/workflows-store.js +14 -3
- package/workspace/live-pill-round-test.js +178 -0
- package/workspace/milestone-pins-test.js +1 -1
- package/workspace/okr-goals-ui-test.js +21 -19
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/panels-test.js +375 -0
- package/workspace/premium-rec-tab-test.js +2 -1
- package/workspace/premium-vw-item-test.js +10 -2
- package/workspace/premium-vw-jira-test.js +3 -0
- package/workspace/program-panel-test.js +6 -6
- package/workspace/public/pm/bd-cols.js +149 -0
- package/workspace/public/pm/bd-ini-panel.js +3 -2
- package/workspace/public/pm/bd-pane.js +41 -0
- package/workspace/public/pm/bd-span.js +29 -11
- package/workspace/public/pm/cozy-adler.js +21 -0
- package/workspace/public/pm/cozy-board.css +45 -0
- package/workspace/public/pm/cozy-divider.css +32 -0
- package/workspace/public/pm/cozy-divider.js +45 -0
- package/workspace/public/pm/cozy-insights.css +22 -0
- package/workspace/public/pm/cozy-live-pill.css +17 -22
- package/workspace/public/pm/cozy-live-pill.js +38 -18
- package/workspace/public/pm/cozy-panels.css +80 -0
- package/workspace/public/pm/cozy-panels.js +691 -0
- package/workspace/public/pm/cozy-viewer.js +148 -70
- package/workspace/public/pm/dash-view.js +5 -2
- package/workspace/public/pm/goals-clear.js +9 -2
- package/workspace/public/pm/home-app.js +30 -19
- package/workspace/public/pm/home-ini.js +9 -3
- package/workspace/public/pm/home-today.js +4 -2
- package/workspace/public/pm/ini-edit.js +405 -0
- package/workspace/public/pm/ini-tasks.js +175 -46
- package/workspace/public/pm/ini-versions.js +18 -4
- package/workspace/public/pm/ini-view-model.js +12 -7
- package/workspace/public/pm/ini-view.css +162 -26
- package/workspace/public/pm/ini-view.js +44 -13
- package/workspace/public/pm/ini-wf-model.js +9 -0
- package/workspace/public/pm/ini-wf.js +14 -9
- package/workspace/public/pm/ins-pane.js +55 -0
- package/workspace/public/pm/jira-move.js +50 -0
- package/workspace/public/pm/live-model.js +3 -2
- package/workspace/public/pm/pn-narrow.js +76 -0
- package/workspace/public/pm/premium-board.js +85 -32
- package/workspace/public/pm/premium-insights.js +211 -43
- package/workspace/public/pm/task-card.css +2 -0
- package/workspace/public/pm/task-card.js +4 -1
- package/workspace/public/premium-board.html +2 -0
- package/workspace/ready-dash-ui-test.js +4 -4
- package/workspace/server.js +71 -20
- package/workspace/skills/jira-move.skill +35 -0
- package/workspace/stage-card-tasks-test.js +397 -0
- package/workspace/stage-card-test.js +1 -1
- package/workspace/task-delete-test.js +9 -1
- package/workspace/task-links-test.js +1 -0
- package/workspace/task-milestones-test.js +3 -3
- package/workspace/task-plans-test.js +1 -1
- package/workspace/task-press-test.js +12 -4
- package/workspace/task-views-test.js +166 -13
- package/workspace/test-lists/batch18-live-pill-round.json +10 -0
- package/workspace/test-lists/batch18-panels.json +9 -0
- package/workspace/test-lists/board-columns.json +5 -0
- package/workspace/test-lists/jira-moves.json +11 -0
- package/workspace/test-lists/page-speed-fold.json +5 -0
- package/workspace/test-lists/page-speed-reads.json +5 -0
- package/workspace/test-lists/stage-card-tasks.json +6 -0
- package/workspace/timeline-holds-test.js +1 -1
|
@@ -72,7 +72,7 @@ function workInitiatives(root) {
|
|
|
72
72
|
const def = (pl.defs && pl.defs[pl.lane]) || {};
|
|
73
73
|
let title = id;
|
|
74
74
|
if (pl.record) {
|
|
75
|
-
try { title = String(
|
|
75
|
+
try { title = String(planTree.recordFrontmatter(pl.record).title || '').trim() || id; } catch { title = id; }
|
|
76
76
|
}
|
|
77
77
|
out.push({ id, title, lane: pl.lane, laneLabel: def.label || pl.lane });
|
|
78
78
|
}
|
|
@@ -112,7 +112,7 @@ function factoryView(entry, it) {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
const sha1 = (s) => crypto.createHash('sha1').update(s).digest('hex');
|
|
115
|
-
const statOf = (f) => {
|
|
115
|
+
const statOf = (f) => { const st = planTree.statOnce(f); return st ? `${st.size}:${st.mtimeMs}` : 'none'; };
|
|
116
116
|
|
|
117
117
|
/** The grants a release press made, by target `<initiative>:<batch>`: read only, and only the lines that still hold. A grant
|
|
118
118
|
* holds while it is unexpired, or once it is used (the factory spent it). Expired and unused, it is gone: the PM may press again. */
|
|
@@ -144,7 +144,8 @@ function sideSig(root) {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/** The signature alone, for the page's watcher: the same hash boardFor puts in `sig`, taken without reading the items. */
|
|
147
|
-
function sigFor(w) {
|
|
147
|
+
function sigFor(w) { return planTree.inPass(() => sigRead(w)); }
|
|
148
|
+
function sigRead(w) {
|
|
148
149
|
const root = w.root;
|
|
149
150
|
let itemsSig; let placeSig;
|
|
150
151
|
try { itemsSig = planItems.ledgerSigs([{ id: w.id, root }], '')[w.id].items; } catch { itemsSig = 'unreadable'; }
|
|
@@ -153,7 +154,34 @@ function sigFor(w) {
|
|
|
153
154
|
return sha1([itemsSig, placeSig, JSON.stringify(join.byInit || {}), String((join.flags || []).length), sideSig(root)].join('|'));
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
|
|
157
|
+
/* THE ANSWER MEMO. Home asks for the same fold several times per open (My work, Inbox, News for you, the briefing, each
|
|
158
|
+
* per repository). An answer is reused while (a) the signature is the one it was folded under, so any write to a ledger,
|
|
159
|
+
* a record, the rules or the grants shows on the next read exactly as before, and (b) the caller's clock is at most
|
|
160
|
+
* MEMO_CLOCK_MS past the clock it was folded at: the clock decides only day windows (stall_days, the 14-day Done window,
|
|
161
|
+
* a grant's expiry), so an answer folded seconds earlier is the same answer. The answer keeps its own `now`. Every
|
|
162
|
+
* caller gets its own copy, so nothing a caller does to its answer reaches the next one. */
|
|
163
|
+
const MEMO_CLOCK_MS = 10000;
|
|
164
|
+
const answerMemo = new Map(); // root \0 filter -> { sig, now, out }
|
|
165
|
+
function boardFor(w, opts = {}) {
|
|
166
|
+
return planTree.inPass(() => {
|
|
167
|
+
const now = Number.isFinite(opts.now) ? opts.now : Date.now();
|
|
168
|
+
const f = parseFilter(opts.filter);
|
|
169
|
+
const key = f ? w.root + '\u0000' + canonical(f) : null;
|
|
170
|
+
let sig = null;
|
|
171
|
+
if (key) {
|
|
172
|
+
sig = sigRead(w);
|
|
173
|
+
const hit = answerMemo.get(key);
|
|
174
|
+
if (hit && hit.sig === sig && now >= hit.now && now - hit.now <= MEMO_CLOCK_MS) return structuredClone(hit.out);
|
|
175
|
+
}
|
|
176
|
+
const out = boardRead(w, { ...opts, now });
|
|
177
|
+
if (key && out.ok && out.sig === sig) {
|
|
178
|
+
if (answerMemo.size > 200) answerMemo.clear();
|
|
179
|
+
answerMemo.set(key, { sig, now, out: structuredClone(out) });
|
|
180
|
+
}
|
|
181
|
+
return out;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function boardRead(w, { filter, now = Date.now() } = {}) {
|
|
157
185
|
const f = parseFilter(filter);
|
|
158
186
|
if (!f) return { ok: false, status: 400, error: 'the filter is active, mine or init:<initiative>' };
|
|
159
187
|
const root = w.root;
|
|
@@ -170,7 +198,7 @@ function boardFor(w, { filter, now = Date.now() } = {}) {
|
|
|
170
198
|
const rules = planRules.readRules(root);
|
|
171
199
|
const place = placements.readPlacements(root, { now, rules, records: inits.map((i) => ({ id: i.id, lane: i.lane })) });
|
|
172
200
|
const join = factoryJoin.joinFactory(root);
|
|
173
|
-
const fold = planItems.
|
|
201
|
+
const fold = planItems.readFoldShared(root, { now }); // read only here: plan-tree layout and the join copy what they change
|
|
174
202
|
const stallMs = rules.stall_days * DAY;
|
|
175
203
|
|
|
176
204
|
const rows = inits.map((i) => {
|
|
@@ -316,7 +316,7 @@ function build(f) {
|
|
|
316
316
|
// the start too: the Tasks Timeline draws a bar from the start to the due day (batch 9 item 5b)
|
|
317
317
|
taskBy.get(w.ini).push({ uid: w.uid, title: clip(w.title || '', 160), status: w.status || 'To do', owner: w.owner || '', start: w.start || '', end: w.end || '', ...(w.from ? { from: { stage: w.from.stage, finish: w.from.finish } } : {}),
|
|
318
318
|
// one view (feedback batch 6 item 1): its place in the breakdown, and a breakdown item's own stage and order
|
|
319
|
-
...(typeof w.section === 'string' ? { section: w.section } : {}), ...(w.itemStage ? { itemStage: w.itemStage } : {}), ...(Number.isFinite(w.order) ? { order: w.order } : {}), ...(w.store === 'item' ? { item: true } : {}), ...(w.milestone ? { milestone: true } : {}) });
|
|
319
|
+
...(typeof w.section === 'string' ? { section: w.section } : {}), ...(w.itemStage ? { itemStage: w.itemStage } : {}), ...(Number.isFinite(w.order) ? { order: w.order } : {}), ...(Number.isFinite(w.rank) ? { rank: w.rank } : {}), ...(w.store === 'item' ? { item: true } : {}), ...(w.milestone ? { milestone: true } : {}) });
|
|
320
320
|
}
|
|
321
321
|
// the milestones of each initiative (feedback batch 11 item 3): its tasks flagged ◇, PMOS and Jira alike, at their due dates. Won't do and
|
|
322
322
|
// Archived take one off the timeline; one with no due date is not drawn (the Tasks list asks for the date)
|
|
@@ -149,11 +149,15 @@ const ENGINE_PATHS = [
|
|
|
149
149
|
path.join(__dirname, '..', '..', 'scripts', 'workflow-state.js'),
|
|
150
150
|
path.join(__dirname, 'engine', 'workflow-state.js'),
|
|
151
151
|
];
|
|
152
|
+
// A loaded engine stays loaded: require() caches the module, so only the path probe is skipped on the next call. Board and My
|
|
153
|
+
// work ask for it once per initiative record on every read (hundreds of existsSync per request before this).
|
|
154
|
+
let loadedEngine = null;
|
|
152
155
|
function loadEngine() {
|
|
156
|
+
if (loadedEngine && ENGINE_PATHS.includes(loadedEngine.from)) return loadedEngine;
|
|
153
157
|
const tried = [];
|
|
154
158
|
for (const p of ENGINE_PATHS) {
|
|
155
159
|
if (!fs.existsSync(p)) { tried.push(p); continue; }
|
|
156
|
-
try {
|
|
160
|
+
try { loadedEngine = { ok: true, engine: require(p), from: p }; return loadedEngine; }
|
|
157
161
|
catch (e) {
|
|
158
162
|
return { ok: false, error: `the workflow engine at ${p} is installed but failed to load — ${String((e && e.message) || e).slice(0, 160)}` };
|
|
159
163
|
}
|
|
@@ -46,6 +46,9 @@
|
|
|
46
46
|
* task-pin { task, pinned } the PM's pin on a milestone (feedback batch 13 item 4, XcalmA5Milestones):
|
|
47
47
|
* true draws it on the Board timeline, false hides it, null goes back to the rule (only the initiative's last milestone).
|
|
48
48
|
* `task` is a Board task, a breakdown item or a Jira key; the last line wins.
|
|
49
|
+
* task-order { initiative, section, tasks: [id] } the PM's order of the open tasks inside one stage of an
|
|
50
|
+
* initiative's breakdown (feedback batch 18 item 16, a drag in the stage list): the ids top to bottom. A task not named sorts after
|
|
51
|
+
* them. An empty list takes the order out (the urgency again). It never changes a task's status, dates or place; the last line wins.
|
|
49
52
|
* ticket-dates { ref, start, due } the PM's own start and due days for a Jira ticket (feedback batch 11
|
|
50
53
|
* 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.
|
|
51
54
|
* ini-delete { id, title, tasks, items } the PM's Delete of an initiative (feedback batch 16 item 5d): it
|
|
@@ -171,7 +174,7 @@ function foundOf(f) {
|
|
|
171
174
|
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 })) : [];
|
|
172
175
|
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 };
|
|
173
176
|
}
|
|
174
|
-
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', 'task-pin', 'ticket-dates',
|
|
177
|
+
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', 'task-pin', 'ticket-dates', 'task-order',
|
|
175
178
|
// 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
|
|
176
179
|
'ticket-move', 'ini-split', 'ini-merge', 'ini-sm-undo', 'ini-suggest',
|
|
177
180
|
// Delete an initiative with its tasks, and its Undo (feedback batch 16 item 5d)
|
|
@@ -206,6 +209,7 @@ function fold(events) {
|
|
|
206
209
|
const tasks = new Map(); // task id → { id, board, initiative, title, epic, owner, state, start, due, at, by, history }
|
|
207
210
|
const sections = new Map(); // task id → the stage key its breakdown section is ('' = Not in a stage); the last task-section line wins
|
|
208
211
|
const milestones = new Map(); // task id (or Jira key) → true | false: the PM's milestone flag; the last task-milestone line wins
|
|
212
|
+
const orders = new Map(); // key(initiative, section) → the task ids in the PM's order inside that stage; the last task-order line wins
|
|
209
213
|
const pins = new Map(); // task id (or Jira key) → true | false: the PM's pin on a milestone; a null line takes it out (the rule again)
|
|
210
214
|
const removed = new Map(); // task id → the task a task-remove took out, so a task-restore (Delete's Undo) puts it back
|
|
211
215
|
const ticketNotes = new Map(); // key(board, Jira key) → the PM's notes on that ticket (the last ticket-note line wins)
|
|
@@ -301,6 +305,9 @@ function fold(events) {
|
|
|
301
305
|
sections.set(e.task, e.section);
|
|
302
306
|
} else if (e.kind === 'task-milestone' && typeof e.task === 'string' && e.task && typeof e.milestone === 'boolean') {
|
|
303
307
|
milestones.set(e.task, e.milestone);
|
|
308
|
+
} else if (e.kind === 'task-order' && typeof e.initiative === 'string' && e.initiative && typeof e.section === 'string' && Array.isArray(e.tasks)) {
|
|
309
|
+
const ids = e.tasks.filter((x) => typeof x === 'string' && x);
|
|
310
|
+
if (ids.length) orders.set(key(e.initiative, e.section), ids); else orders.delete(key(e.initiative, e.section));
|
|
304
311
|
} else if (e.kind === 'task-pin' && typeof e.task === 'string' && e.task && (typeof e.pinned === 'boolean' || e.pinned === null)) {
|
|
305
312
|
if (e.pinned === null) pins.delete(e.task); else pins.set(e.task, e.pinned);
|
|
306
313
|
} else if (e.kind === 'ticket-dates' && b && typeof e.ref === 'string' && JIRA_KEY_RE.test(e.ref)) {
|
|
@@ -366,7 +373,7 @@ function fold(events) {
|
|
|
366
373
|
suggestNo.set(e.id, { kind: e.of === 'merge' ? 'merge' : 'split', fp: e.fp, at: e.at || null });
|
|
367
374
|
}
|
|
368
375
|
}
|
|
369
|
-
return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, removed, sections, milestones, pins, ticketNotes, ticketDates, epics, archives, deleted, notDup, iniWf, ends, judged, autoOver, ticketMoves, smOps, smUndone, suggestNo, events: list };
|
|
376
|
+
return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, removed, sections, orders, milestones, pins, ticketNotes, ticketDates, epics, archives, deleted, notDup, iniWf, ends, judged, autoOver, ticketMoves, smOps, smUndone, suggestNo, events: list };
|
|
370
377
|
}
|
|
371
378
|
|
|
372
379
|
/** The stages an initiative runs on a board: its own workflow when one is recorded, else the board's. */
|
|
@@ -48,7 +48,10 @@
|
|
|
48
48
|
* - 4D's Board and work-check-needs (Review and Release rows);
|
|
49
49
|
* - 5A's blocks (factory progress when present).
|
|
50
50
|
*
|
|
51
|
-
*
|
|
51
|
+
* One memo, on the ledger's stat: the derived fold and the line facts of an unchanged work-items.jsonl are reused (Board's
|
|
52
|
+
* layout asks once per initiative, hundreds of times a read). The fold depends on the clock only through claim expiry,
|
|
53
|
+
* so a memo holds while the clock has not passed the earliest live claim's expires_at; a write to the ledger, or that
|
|
54
|
+
* instant, folds it again. No network, no git.
|
|
52
55
|
*/
|
|
53
56
|
const fs = require('fs');
|
|
54
57
|
const path = require('path');
|
|
@@ -57,10 +60,12 @@ const WORK_ITEM_PATHS = [path.join(__dirname, '..', '..', 'scripts', 'work-item.
|
|
|
57
60
|
const READY = new Set(['verified', 'integrated']);
|
|
58
61
|
const PR_RE = /^(?:https?:\/\/\S+\/pull\/\d+\S*|pr:#?\d+)$/i;
|
|
59
62
|
|
|
63
|
+
let loadedWorkItem = null;
|
|
60
64
|
function loadWorkItem() {
|
|
65
|
+
if (loadedWorkItem) return loadedWorkItem;
|
|
61
66
|
for (const p of WORK_ITEM_PATHS) {
|
|
62
67
|
if (!fs.existsSync(p)) continue;
|
|
63
|
-
try {
|
|
68
|
+
try { loadedWorkItem = { ok: true, mod: require(p) }; return loadedWorkItem; }
|
|
64
69
|
catch (e) { return { ok: false, error: `scripts/work-item.js is present but failed to load — ${String((e && e.message) || e).slice(0, 160)}` }; }
|
|
65
70
|
}
|
|
66
71
|
return { ok: false, error: 'the work-item fold (scripts/work-item.js) is not in this install, so factory work cannot be read here' };
|
|
@@ -95,36 +100,63 @@ function batchId(at) {
|
|
|
95
100
|
return `b${digits.endsWith('000') ? digits.slice(0, 14) : digits}`;
|
|
96
101
|
}
|
|
97
102
|
|
|
103
|
+
const ledgerMemo = new Map(); // file -> { key, at, until, text, derived, facts }
|
|
104
|
+
const statKey = (file) => { try { const st = fs.statSync(file); return `${st.ino}:${st.size}:${st.mtimeMs}:${st.ctimeMs}`; } catch { return null; } };
|
|
105
|
+
|
|
106
|
+
/** The earliest instant at which a live claim in this fold expires (and its item's state turns), or Infinity. */
|
|
107
|
+
function nextExpiry(derived) {
|
|
108
|
+
let t = Infinity;
|
|
109
|
+
for (const it of derived.items) {
|
|
110
|
+
if (it.state !== 'claimed' || !it.claim) continue;
|
|
111
|
+
const e = Date.parse(it.claim.expires_at);
|
|
112
|
+
if (Number.isFinite(e) && e < t) t = e;
|
|
113
|
+
}
|
|
114
|
+
return t;
|
|
115
|
+
}
|
|
116
|
+
|
|
98
117
|
function joinFactory(root, { initiative, fold } = {}) {
|
|
99
118
|
const out = { ok: true, byInit: {}, flags: [] };
|
|
100
119
|
const unreadable = (kind, why) => { out.flags.push({ kind, id: null, why }); out.unreadable = why; return out; };
|
|
101
120
|
const file = path.join(mainTreeOf(root), 'planning', 'work-items.jsonl');
|
|
121
|
+
const nowMs = Date.now();
|
|
122
|
+
const key = statKey(file);
|
|
123
|
+
let hit = ledgerMemo.get(file);
|
|
124
|
+
if (!(key && hit && hit.key === key && nowMs >= hit.at && nowMs < hit.until)) hit = null;
|
|
102
125
|
let text = '';
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
126
|
+
if (hit) text = hit.text;
|
|
127
|
+
else {
|
|
128
|
+
try { text = fs.readFileSync(file, 'utf8'); }
|
|
129
|
+
catch (e) {
|
|
130
|
+
if (!(e && e.code === 'ENOENT')) return unreadable('unreadable', `planning/work-items.jsonl cannot be read (${(e && e.code) || e})`);
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
107
133
|
}
|
|
108
134
|
if (!text.trim()) return out;
|
|
109
135
|
const W = loadWorkItem();
|
|
110
136
|
if (!W.ok) return unreadable('engine-missing', W.error);
|
|
111
137
|
|
|
112
|
-
let derived;
|
|
113
|
-
|
|
114
|
-
|
|
138
|
+
let derived; let facts;
|
|
139
|
+
if (hit) ({ derived, facts } = hit);
|
|
140
|
+
else {
|
|
141
|
+
try { derived = W.mod.deriveItems(text, { now: new Date(nowMs).toISOString() }); }
|
|
142
|
+
catch (e) { return unreadable('unreadable', `the work-item fold failed: ${String((e && e.message) || e).slice(0, 160)}`); }
|
|
143
|
+
facts = lineFacts(text);
|
|
144
|
+
// the stat is taken before the read, so a write during it leaves an older key at worst: one more read, never a hidden change
|
|
145
|
+
if (key) { if (ledgerMemo.size > 200) ledgerMemo.clear(); ledgerMemo.set(file, { key, at: nowMs, until: nextExpiry(derived), text, derived, facts }); }
|
|
146
|
+
}
|
|
115
147
|
for (const d of derived.defects) out.flags.push({ kind: d.kind, id: d.item_id || null, why: `line ${d.line}: ${d.detail}` });
|
|
116
148
|
|
|
117
149
|
let planFold = fold || null;
|
|
118
|
-
|
|
150
|
+
const narrowed = initiative ? derived.items.filter((it) => it.initiative_id === initiative) : derived.items;
|
|
151
|
+
if (!planFold && narrowed.some((it) => typeof it.plan_item === 'string')) {
|
|
119
152
|
try { planFold = require('./plan-items.js').readFold(root); }
|
|
120
153
|
catch (e) { out.flags.push({ kind: 'plan-items-unreadable', id: null, why: `the plan-items ledger cannot be read, so no plan_item is checked: ${String((e && e.message) || e).slice(0, 160)}` }); }
|
|
121
154
|
}
|
|
122
|
-
const known = planFold
|
|
155
|
+
const known = planFold && narrowed.some((it) => typeof it.plan_item === 'string')
|
|
156
|
+
? new Set([...Object.keys(planFold.items || {}), ...(planFold.withdrawnIds || [])]) : null;
|
|
123
157
|
|
|
124
|
-
const facts = lineFacts(text);
|
|
125
158
|
const batchesOf = new Map();
|
|
126
|
-
for (const it of
|
|
127
|
-
if (initiative && it.initiative_id !== initiative) continue;
|
|
159
|
+
for (const it of narrowed) {
|
|
128
160
|
const id = it.item_id;
|
|
129
161
|
const f = facts.get(id) || {};
|
|
130
162
|
const planItem = typeof it.plan_item === 'string' ? it.plan_item : null;
|
|
@@ -49,9 +49,22 @@ const mtime = (f) => { try { return fs.statSync(f).mtimeMs; } catch { return 0;
|
|
|
49
49
|
const readJson = (f, dflt) => { try { return JSON.parse(fs.readFileSync(f, 'utf8')); } catch { return dflt; } };
|
|
50
50
|
|
|
51
51
|
/** The newest `fetched_at` among the imported calendar events (scripts/calendar-import.js ledger), in ms, or 0. */
|
|
52
|
+
// Read again only when the ledger's size or time changed (page-speed): Sources and the freshness rows ask on every page load, and the
|
|
53
|
+
// ledger is megabytes.
|
|
54
|
+
const calSeen = new Map(); // file -> { sig, best }
|
|
52
55
|
function calendarAsOf(stateDir) {
|
|
56
|
+
const f = path.join(stateDir, 'calendar-import', 'events.jsonl');
|
|
57
|
+
let st; try { st = fs.statSync(f); } catch { calSeen.delete(f); return 0; }
|
|
58
|
+
const sig = st.size + ':' + st.mtimeMs + ':' + st.ino;
|
|
59
|
+
const hit = calSeen.get(f);
|
|
60
|
+
if (hit && hit.sig === sig) return hit.best;
|
|
61
|
+
const best = calendarAsOfText(f);
|
|
62
|
+
calSeen.set(f, { sig, best });
|
|
63
|
+
return best;
|
|
64
|
+
}
|
|
65
|
+
function calendarAsOfText(f) {
|
|
53
66
|
let text = '';
|
|
54
|
-
try { text = fs.readFileSync(
|
|
67
|
+
try { text = fs.readFileSync(f, 'utf8'); } catch { return 0; }
|
|
55
68
|
let best = 0;
|
|
56
69
|
for (const line of text.split('\n')) {
|
|
57
70
|
if (!line.includes('fetched_at')) continue;
|
|
@@ -39,6 +39,33 @@ const cache = new Map(); // root -> { sig, at, value, error }
|
|
|
39
39
|
const inflight = new Map(); // root -> true
|
|
40
40
|
let background = true; // false in a one-shot process (`pmos today` with no server): nothing would read the answer
|
|
41
41
|
|
|
42
|
+
// KEPT ON DISK (page-speed), as lib/facts-async.js keeps the facts: configure({ stateDir }) names the runtime state folder, and
|
|
43
|
+
// each derivation that lands is written to <stateDir>/initiative-rows/<hash of root>.json. After a restart (the reload after an
|
|
44
|
+
// update) the first read answers those rows by the usual rule, `stale` unless the signature still holds, and starts a derivation,
|
|
45
|
+
// instead of `pending` for the seconds a derivation takes. Unconfigured (a suite, the CLI), nothing is written. Never into the
|
|
46
|
+
// repository.
|
|
47
|
+
let stateDir = null;
|
|
48
|
+
function configure(o = {}) { stateDir = o.stateDir || null; }
|
|
49
|
+
const diskOf = (root) => (stateDir ? path.join(stateDir, 'initiative-rows', crypto.createHash('sha1').update(String(root)).digest('hex').slice(0, 16) + '.json') : null);
|
|
50
|
+
function loadDisk(root) {
|
|
51
|
+
const f = diskOf(root);
|
|
52
|
+
if (!f) return null;
|
|
53
|
+
try {
|
|
54
|
+
const e = JSON.parse(fs.readFileSync(f, 'utf8'));
|
|
55
|
+
return e && e.root === root && typeof e.sig === 'string' && typeof e.at === 'number' && Array.isArray(e.value) ? { sig: e.sig, at: e.at, value: e.value, error: null } : null;
|
|
56
|
+
} catch { return null; }
|
|
57
|
+
}
|
|
58
|
+
function saveDisk(root, entry) {
|
|
59
|
+
const f = diskOf(root);
|
|
60
|
+
if (!f || !entry || entry.error || !Array.isArray(entry.value)) return;
|
|
61
|
+
try {
|
|
62
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
63
|
+
const tmp = f + '.' + process.pid + '.tmp';
|
|
64
|
+
fs.writeFileSync(tmp, JSON.stringify({ root, sig: entry.sig, at: entry.at, value: entry.value }));
|
|
65
|
+
fs.renameSync(tmp, f);
|
|
66
|
+
} catch { /* the memory entry still serves */ }
|
|
67
|
+
}
|
|
68
|
+
|
|
42
69
|
function enginePath() {
|
|
43
70
|
const loaded = consoleState.loadEngine();
|
|
44
71
|
if (!loaded.ok) throw new Error(loaded.error);
|
|
@@ -106,7 +133,9 @@ function refresh(root, sig) {
|
|
|
106
133
|
// must not vanish from Today for one poll and come back on the next
|
|
107
134
|
const prev = cache.get(root);
|
|
108
135
|
if (entry.error && prev && prev.value) return;
|
|
109
|
-
|
|
136
|
+
const e = { sig, at: Date.now(), ...entry };
|
|
137
|
+
cache.set(root, e);
|
|
138
|
+
saveDisk(root, e);
|
|
110
139
|
};
|
|
111
140
|
try {
|
|
112
141
|
const { from } = enginePath();
|
|
@@ -144,7 +173,8 @@ function deriveNow(root) {
|
|
|
144
173
|
function peek(root) { return read(root, false); }
|
|
145
174
|
function read(root, derive) {
|
|
146
175
|
const sig = recordsSig(root);
|
|
147
|
-
|
|
176
|
+
let hit = cache.get(root);
|
|
177
|
+
if (!hit && !inflight.get(root)) { hit = loadDisk(root); if (hit) cache.set(root, hit); }
|
|
148
178
|
const fresh = hit && hit.sig === sig && Date.now() - hit.at < MAX_AGE_MS;
|
|
149
179
|
if (!fresh && derive && background) refresh(root, sig);
|
|
150
180
|
if (!hit) return { pending: true };
|
|
@@ -175,7 +205,11 @@ function rescan(root) {
|
|
|
175
205
|
return { started: true, running: true };
|
|
176
206
|
}
|
|
177
207
|
/** Test and maintenance seam. */
|
|
178
|
-
function invalidate(root) {
|
|
208
|
+
function invalidate(root) {
|
|
209
|
+
// the kept copy goes too: a write that invalidates must not get the rows from before it back from the disk
|
|
210
|
+
const drop = (r) => { const f = diskOf(r); if (f) { try { fs.unlinkSync(f); } catch { /* none kept */ } } };
|
|
211
|
+
if (root) { cache.delete(root); inflight.delete(root); drop(root); } else { for (const r of cache.keys()) drop(r); cache.clear(); inflight.clear(); }
|
|
212
|
+
}
|
|
179
213
|
|
|
180
214
|
// ── anchors ──────────────────────────────────────────────────────────────────────────────────────
|
|
181
215
|
function anchorLib(from) {
|
|
@@ -254,4 +288,4 @@ function anchorsOf(root) {
|
|
|
254
288
|
return { resolve, list, period, error, ok: !!(index && index.ok) };
|
|
255
289
|
}
|
|
256
290
|
|
|
257
|
-
module.exports = { deriveSync, rowsFor, rescan, peek, setBackground, isDeriving, deriveNow, answerSig, cachedSig, recordsSig, invalidate, anchorsOf, workGroupOf, periodLabel, narrow };
|
|
291
|
+
module.exports = { configure, deriveSync, rowsFor, rescan, peek, setBackground, isDeriving, deriveNow, answerSig, cachedSig, recordsSig, invalidate, anchorsOf, workGroupOf, periodLabel, narrow };
|
package/workspace/lib/issues.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* isIssued(result, cadence, slot) → true when that slot is frozen (Redraft is refused)
|
|
14
14
|
* appendFromUi(root, events, { actor, now }) → { ok, written } | { ok: false, status, error, index }
|
|
15
15
|
* appendFromCli(root, events, { actor, now }) → the same
|
|
16
|
+
* appendFromSchedule(root, events, { now }) → the same, as agent:unknown: a calm weekly that goes by itself
|
|
16
17
|
*
|
|
17
18
|
* Issue is a PM-only act (R25): the route takes its actor from pm-guard.js requirePmPress({ act: 'issue' }), and the
|
|
18
19
|
* CLI from pm-guard.js requirePmCli({ act: 'issue' }). The biweekly's window is `since_last_issue`: from lastIssue's
|
|
@@ -204,4 +205,10 @@ function appendFromCli(root, events, { actor, now } = {}) {
|
|
|
204
205
|
return append(root, events, actor, 'cli', { now });
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
|
|
208
|
+
/** The schedule: a calm weekly that goes by itself (lib/routes-ready-reports.js, Wawan 2026-10-28). No session runs it, so the line names
|
|
209
|
+
* `agent:unknown` (D98: an agent's line keeps its own `by`, so the PM sees it was not their press), on the server's call path. */
|
|
210
|
+
function appendFromSchedule(root, events, { now } = {}) {
|
|
211
|
+
return append(root, events, { by: 'agent:unknown', via: 'cli' }, 'cli', { now });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
module.exports = { readIssues, lastIssue, isIssued, pmOnly, appendFromUi, appendFromCli, appendFromSchedule, lineErr, blobSha, reportPathOk, MAX_LINES };
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* pmos jira sync --sprints --from <file|-> [--query "<jql>"] a saved whole-sprint search → the Sprints tab (jira-sprint-scope)
|
|
15
15
|
* pmos jira summary [--from <file|->] [--dry-run] the sprints to summarise, or save their goal and summary (sprint-goal-summary)
|
|
16
16
|
* pmos jira which <KEY> the initiative a Jira key belongs to
|
|
17
|
+
* pmos jira moves the status moves the PM asked in PMOS, not answered yet (lib/jira-moves.js)
|
|
18
|
+
* pmos jira moved <move id> --status "<Jira status>" | --refused "<why>" the agent's answer for one move
|
|
17
19
|
* every command: [--json] [--root <dir>]
|
|
18
20
|
*
|
|
19
21
|
* This command never talks to Jira. An agent session does, with the PM's own Atlassian connection (D53, D88), and
|
|
@@ -25,10 +27,11 @@ const { execFileSync } = require('child_process');
|
|
|
25
27
|
const { parseArgs } = require('./schedule-cli');
|
|
26
28
|
const jiraStatus = require('./jira-status.js');
|
|
27
29
|
const jiraTickets = require('./jira-tickets.js');
|
|
30
|
+
const jiraMoves = require('./jira-moves.js');
|
|
28
31
|
const planItems = require('./plan-items.js');
|
|
29
32
|
const guard = require('./pm-guard.js');
|
|
30
33
|
|
|
31
|
-
const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which'] };
|
|
34
|
+
const COMMANDS = { jira: ['draft', 'show', 'epic', 'approve', 'pending', 'record', 'query', 'sync', 'summary', 'which', 'moves', 'moved'] };
|
|
32
35
|
const USAGE = [
|
|
33
36
|
'usage: pmos jira draft|show|epic|approve|pending|record|query|sync|summary|which — Jira tickets from the PRD, and their status',
|
|
34
37
|
' pmos jira draft <initiative> [--dry-run] draft one ticket per PRD item, in the ticket template',
|
|
@@ -44,11 +47,13 @@ const USAGE = [
|
|
|
44
47
|
' pmos jira summary the sprints that need a goal and summary written',
|
|
45
48
|
' pmos jira summary --from <file|-> [--dry-run] save each sprint\'s goal, summary and themes (a closed sprint is kept once written)',
|
|
46
49
|
' pmos jira which <KEY> the initiative a Jira key belongs to',
|
|
50
|
+
' pmos jira moves the status moves asked in PMOS that wait for Jira',
|
|
51
|
+
' pmos jira moved <move id> --status "<status>" | --refused "<why>" what Jira did with one move',
|
|
47
52
|
' every command: [--json] [--root <dir>]',
|
|
48
53
|
'This command never calls Jira. Your agent reads and writes Jira with your own connection.',
|
|
49
54
|
];
|
|
50
55
|
const BOOL = new Set(['json', 'dry-run', 'help', 'sprints']);
|
|
51
|
-
const VALUE = new Set(['from', 'query', 'root', 'epic', 'updated', 'group']);
|
|
56
|
+
const VALUE = new Set(['from', 'query', 'root', 'epic', 'updated', 'group', 'status', 'refused']);
|
|
52
57
|
const FLAG_TEXT = { 'prd-changed': 'PRD changed', removed: 'Removed from PRD', blocked: 'Blocked', incomplete: 'Missing text', pushing: 'Selected, waiting for the push', edited: 'Edited, not in Jira yet' };
|
|
53
58
|
|
|
54
59
|
function parse(argv) {
|
|
@@ -146,6 +151,17 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
146
151
|
const all = jiraStatus.linkedInitiatives(root).filter((x) => x.linked);
|
|
147
152
|
return out({ ok: true, initiatives: all }, all.length ? all.map((x) => `${x.initiative}\t${x.query}`) : ['no initiative has a ticket in Jira yet']);
|
|
148
153
|
}
|
|
154
|
+
if (verb === 'moves') {
|
|
155
|
+
const P = jiraMoves.pending(jiraMoves.read(root));
|
|
156
|
+
return out({ ok: true, moves: P }, P.length ? P.map((m) => `${m.id}\t${m.key}\t${m.from || '?'} → ${m.to}${m.fromRaw ? `\t(Jira showed ${m.fromRaw})` : ''}`) : ['no move waits for Jira']);
|
|
157
|
+
}
|
|
158
|
+
if (verb === 'moved') {
|
|
159
|
+
const id = pos[0];
|
|
160
|
+
if (!id || (flags.status == null) === (flags.refused == null)) return need('<move id> --status "<the status Jira shows now>" | --refused "<why Jira refused>"');
|
|
161
|
+
const r = jiraMoves.answer(root, id, flags.refused != null ? { why: flags.refused } : { status: flags.status }, 'agent', now);
|
|
162
|
+
if (!r.ok) return fail(r.error);
|
|
163
|
+
return out(r, [r.move.state === 'moved' ? `${r.move.key} · ${r.move.status} in Jira` : `${r.move.key} · refused: ${r.move.why}`]);
|
|
164
|
+
}
|
|
149
165
|
if (verb === 'which') {
|
|
150
166
|
if (!initiative) return need('<KEY>');
|
|
151
167
|
const r = jiraStatus.which(root, initiative);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* jira-moves.js — a Jira ticket's status moved from PMOS (Wawan 2026-10-29 "why can't move Jira task here on PMOS?"; canvas page
|
|
3
|
+
* "Exploring · Move Jira tasks", JmA1Kanban, JmA3States). THE ONE WRITER and THE ONE FOLD of <state>/tracker/jira/moves.jsonl.
|
|
4
|
+
*
|
|
5
|
+
* PMOS still holds no Jira credential and the workspace server makes no request to Jira (D53, D88). A move is ASKED here (a Kanban drag, or
|
|
6
|
+
* the status press on the List or the Timeline); an agent session with the PM's own Atlassian connection (skill jira-move) reads the asked
|
|
7
|
+
* moves with `pmos jira moves`, moves each ticket through its workflow, and answers with `pmos jira moved`. Until it answers, the ticket shows
|
|
8
|
+
* the status it was moved to, marked as moving. Jira's answer wins: a refusal puts the ticket back where Jira keeps it, with Jira's reason.
|
|
9
|
+
*
|
|
10
|
+
* THE LEDGER. One line per change, append-only:
|
|
11
|
+
* ask { v, kind: 'ask', id, key, ini, to, from, fromRaw, at, by } to/from: To do | In progress | Done (PMOS's three)
|
|
12
|
+
* moved { v, kind: 'moved', id, key, status, at, by } status: Jira's own status name after the move ("In Review")
|
|
13
|
+
* refused { v, kind: 'refused', id, key, why, at, by } why: Jira's reason, in a few plain words
|
|
14
|
+
*
|
|
15
|
+
* file(root) · read(root) → fold · ask(root, m, by) · answer(root, id, r, by) · pending(F) · decorate(rows, F)
|
|
16
|
+
* fold(lines) → Map key → { id, key, ini, to, from, fromRaw, state: 'moving' | 'moved' | 'refused', status, why, at, askedAt } PURE
|
|
17
|
+
*/
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const crypto = require('crypto');
|
|
21
|
+
const jiraTickets = require('./jira-tickets.js');
|
|
22
|
+
|
|
23
|
+
const FILE = 'moves.jsonl';
|
|
24
|
+
const TO = ['To do', 'In progress', 'Done'];
|
|
25
|
+
const KEY_RE = /^[A-Z][A-Z0-9_]{0,30}-\d{1,9}$/;
|
|
26
|
+
const ID_RE = /^mv-[0-9a-f]{10}$/;
|
|
27
|
+
const CLS = { 'To do': '', 'In progress': 'ip', Done: 'dn' }; // board-premium.js TK_CLS
|
|
28
|
+
const STALE_MS = 15 * 60 * 1000; // an ask no agent answered in 15 minutes is shown as not reached
|
|
29
|
+
const oneLine = (s, n) => { const t = String(s == null ? '' : s).replace(/[\r\n\t]+/g, ' ').replace(/\s{2,}/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).trimEnd() + '…' : t; };
|
|
30
|
+
|
|
31
|
+
function file(root) { return path.join(jiraTickets.jiraDir(root), FILE); }
|
|
32
|
+
function lines(root) {
|
|
33
|
+
let txt = '';
|
|
34
|
+
try { txt = fs.readFileSync(file(root), 'utf8'); } catch { return []; }
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const l of txt.split('\n')) { if (!l.trim()) continue; try { out.push(JSON.parse(l)); } catch { /* a torn line is skipped */ } }
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
function append(root, line) {
|
|
40
|
+
fs.mkdirSync(path.dirname(file(root)), { recursive: true });
|
|
41
|
+
fs.appendFileSync(file(root), JSON.stringify(line) + '\n');
|
|
42
|
+
return line;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** PURE: the latest move of each ticket. An answer counts only for the ask it names, and only while that ask is the ticket's latest. */
|
|
46
|
+
function fold(ls) {
|
|
47
|
+
const by = new Map(), ids = new Map();
|
|
48
|
+
for (const l of ls || []) {
|
|
49
|
+
if (!l || !KEY_RE.test(String(l.key || ''))) continue;
|
|
50
|
+
if (l.kind === 'ask' && ID_RE.test(String(l.id || '')) && TO.includes(l.to)) {
|
|
51
|
+
const m = { id: l.id, key: l.key, ini: l.ini || '', to: l.to, from: TO.includes(l.from) ? l.from : '', fromRaw: oneLine(l.fromRaw, 60), state: 'moving', status: '', why: '', at: l.at || '', askedAt: l.at || '' };
|
|
52
|
+
by.set(l.key, m); ids.set(l.id, m);
|
|
53
|
+
} else if ((l.kind === 'moved' || l.kind === 'refused') && ids.has(l.id)) {
|
|
54
|
+
const m = ids.get(l.id);
|
|
55
|
+
if (by.get(m.key) !== m || m.state !== 'moving') continue;
|
|
56
|
+
m.state = l.kind; m.at = l.at || m.at;
|
|
57
|
+
if (l.kind === 'moved') m.status = oneLine(l.status, 60) || m.to; else m.why = oneLine(l.why, 200) || 'Jira did not say why';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return by;
|
|
61
|
+
}
|
|
62
|
+
function read(root) { return fold(lines(root)); }
|
|
63
|
+
|
|
64
|
+
/** Ask a move. m: { key, initiative, to, from, fromRaw }. Moving a ticket to where it already is asks nothing. */
|
|
65
|
+
function ask(root, m, by, now = Date.now()) {
|
|
66
|
+
const key = String((m && m.key) || '').toUpperCase();
|
|
67
|
+
if (!KEY_RE.test(key)) return { ok: false, status: 400, error: 'name a Jira key, for example MSD-4376' };
|
|
68
|
+
if (!TO.includes(m.to)) return { ok: false, status: 400, error: 'a Jira ticket moves to To do, In progress or Done' };
|
|
69
|
+
if (m.from && m.from === m.to) return { ok: true, id: null, unchanged: true };
|
|
70
|
+
const line = { v: 1, kind: 'ask', id: 'mv-' + crypto.randomBytes(5).toString('hex'), key, ini: String(m.initiative || ''), to: m.to,
|
|
71
|
+
from: TO.includes(m.from) ? m.from : '', fromRaw: oneLine(m.fromRaw, 60), at: new Date(now).toISOString(), by: by || 'pm' };
|
|
72
|
+
append(root, line);
|
|
73
|
+
return { ok: true, id: line.id, move: fold([line]).get(key) };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The agent's answer. r: { status } when Jira moved it, { why } when Jira refused or could not be reached. */
|
|
77
|
+
function answer(root, id, r, by, now = Date.now()) {
|
|
78
|
+
if (!ID_RE.test(String(id || ''))) return { ok: false, status: 400, error: 'name a move id, for example mv-0a1b2c3d4e' };
|
|
79
|
+
const F = read(root), m = [...F.values()].find((x) => x.id === id);
|
|
80
|
+
if (!m) return { ok: false, status: 404, error: `${id} is not the latest move of any ticket: a newer move replaced it, or it does not exist` };
|
|
81
|
+
if (m.state !== 'moving') return { ok: false, status: 409, error: `${m.key} already has an answer (${m.state})` };
|
|
82
|
+
const refused = r && r.why != null;
|
|
83
|
+
if (!refused && !(r && oneLine(r.status, 60))) return { ok: false, status: 400, error: 'give the status Jira shows now (--status), or the reason Jira refused (--refused)' };
|
|
84
|
+
const line = refused ? { v: 1, kind: 'refused', id, key: m.key, why: oneLine(r.why, 200), at: new Date(now).toISOString(), by: by || 'agent' }
|
|
85
|
+
: { v: 1, kind: 'moved', id, key: m.key, status: oneLine(r.status, 60), at: new Date(now).toISOString(), by: by || 'agent' };
|
|
86
|
+
append(root, line);
|
|
87
|
+
return { ok: true, move: fold([...lines(root)]).get(m.key) };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The asks no agent has answered yet, oldest first. */
|
|
91
|
+
const pending = (F) => [...F.values()].filter((m) => m.state === 'moving').sort((a, b) => String(a.askedAt).localeCompare(String(b.askedAt)));
|
|
92
|
+
|
|
93
|
+
/** The status a Kanban column, a List box and a Timeline bar draw for a ticket, from a move:
|
|
94
|
+
* moving → the status it was moved to, marked moving (stale after 15 minutes: "not reached");
|
|
95
|
+
* moved → Jira's answer, until a new reading shows the ticket somewhere other than where it was when the move was asked;
|
|
96
|
+
* refused → the reading stands, with Jira's reason once. PURE but for now. */
|
|
97
|
+
function overlay(t, m, now = Date.now()) {
|
|
98
|
+
if (!t || !m) return t;
|
|
99
|
+
const read0 = String(t.raw || t.status || '');
|
|
100
|
+
// with no reading to compare, Jira's answer stands for a day; after that the reading wins
|
|
101
|
+
const stillOld = m.fromRaw ? read0 === m.fromRaw : now - Date.parse(m.at || 0) < 24 * 3600 * 1000;
|
|
102
|
+
if (m.state === 'moving') {
|
|
103
|
+
const stale = now - Date.parse(m.askedAt || 0) > STALE_MS;
|
|
104
|
+
return stale ? { ...t, move: { id: m.id, state: 'stale', to: m.to } } : { ...t, status: m.to, cls: CLS[m.to], move: { id: m.id, state: 'moving', to: m.to, from: m.from } };
|
|
105
|
+
}
|
|
106
|
+
if (m.state === 'moved') return stillOld ? { ...t, status: m.to, cls: CLS[m.to], raw: m.status, move: { id: m.id, state: 'moved', to: m.to, from: m.from } } : t;
|
|
107
|
+
return { ...t, move: { id: m.id, state: 'refused', why: m.why, from: m.from, to: m.to } };
|
|
108
|
+
}
|
|
109
|
+
/** Every row's tickets (r.track.tickets) wear their latest move. */
|
|
110
|
+
function decorate(rows, F, now = Date.now()) {
|
|
111
|
+
if (!F || !F.size) return;
|
|
112
|
+
for (const r of rows || []) {
|
|
113
|
+
const tk = r && r.track && Array.isArray(r.track.tickets) ? r.track.tickets : null;
|
|
114
|
+
if (!tk) continue;
|
|
115
|
+
for (let i = 0; i < tk.length; i++) { const m = F.get(tk[i] && tk[i].key); if (m) tk[i] = overlay(tk[i], m, now); }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = { FILE, TO, KEY_RE, ID_RE, STALE_MS, file, read, fold, ask, answer, pending, overlay, decorate };
|
|
@@ -90,10 +90,18 @@ function engine() {
|
|
|
90
90
|
}
|
|
91
91
|
const mainRoot = (root) => planItems.ledgerRoot(root);
|
|
92
92
|
const stateDir = (root) => path.dirname(engine().layout(mainRoot(root)).initiatives);
|
|
93
|
+
// A record's front matter is parsed again only when the file changed (page-speed): the Board reads it several times per initiative.
|
|
94
|
+
const fmSeen = new Map(); // record file -> { sig, fm }
|
|
93
95
|
function recordFm(root, initiative) {
|
|
94
96
|
const file = planTree.recordPath(root, initiative);
|
|
95
97
|
if (!file) return null;
|
|
96
|
-
try {
|
|
98
|
+
let sig = null; try { const st = fs.statSync(file); sig = st.size + ':' + st.mtimeMs + ':' + st.ino; } catch { /* read below says */ }
|
|
99
|
+
const hit = sig && fmSeen.get(file);
|
|
100
|
+
if (hit && hit.sig === sig) return { ...hit.fm };
|
|
101
|
+
let fm;
|
|
102
|
+
try { fm = engine().parseLeadingFrontmatter(fs.readFileSync(file, 'utf8')) || {}; } catch { return {}; }
|
|
103
|
+
if (sig) fmSeen.set(file, { sig, fm });
|
|
104
|
+
return { ...fm };
|
|
97
105
|
}
|
|
98
106
|
/** The PRD of an initiative: `prd_path` in a code repository, `doc_path` (the lane's draft) in a document repository. */
|
|
99
107
|
function prdOf(rfm) {
|
|
@@ -482,7 +490,7 @@ function gateOf(root, initiative, d, rfm) {
|
|
|
482
490
|
if (!stages.some((s) => s.id === 'handoff')) return { open: true, why: 'this lane has no handoff stage' };
|
|
483
491
|
if (isStr(rfm.handed_off) && rfm.handed_off.trim()) return { open: true, why: 'handed off' };
|
|
484
492
|
let fold = null;
|
|
485
|
-
try { fold = planItems.readFold(root); } catch { fold = null; }
|
|
493
|
+
try { fold = (planItems.readFoldShared || planItems.readFold)(root); } catch { fold = null; }
|
|
486
494
|
const mine = fold ? (fold.order || []).map((id) => fold.items[id])
|
|
487
495
|
.filter((it) => it && it.initiative === initiative && it.stage === 'handoff' && !it.proposed && it.state !== 'withdrawn') : [];
|
|
488
496
|
if (mine.length && mine.every((it) => it.state === 'done')) return { open: true, why: 'every Handoff item is done' };
|
|
@@ -760,12 +768,23 @@ function pushedTickets(root, initiative) {
|
|
|
760
768
|
}
|
|
761
769
|
/** The Jira epics the PM linked on the initiative page: the boards ledger's `ini-epics` lines (lib/routes-boards.js),
|
|
762
770
|
* folded by scripts/boards.js. Map initiative id → keys; an initiative the PM never linked is absent. */
|
|
771
|
+
// The fold is kept until the ledger's size or time changes (page-speed): the Board asks once per initiative (epicKeysOf's default),
|
|
772
|
+
// and each ask folded the whole boards ledger again. The map is shared, so a caller must not change it.
|
|
773
|
+
const epicsSeen = new Map(); // ledger file -> { sig, epics }
|
|
763
774
|
function linkedEpics(root) {
|
|
764
775
|
const base = mainRoot(root);
|
|
765
776
|
for (const rel of [['pmos', 'state'], ['state'], ['.pmos']]) {
|
|
777
|
+
const f = path.join(base, ...rel, 'boards.jsonl');
|
|
778
|
+
let st; try { st = fs.statSync(f); } catch { continue; }
|
|
779
|
+
const sig = st.size + ':' + st.mtimeMs + ':' + st.ino;
|
|
780
|
+
const hit = epicsSeen.get(f);
|
|
781
|
+
if (hit && hit.sig === sig) return hit.epics;
|
|
766
782
|
let text;
|
|
767
|
-
try { text = fs.readFileSync(
|
|
768
|
-
|
|
783
|
+
try { text = fs.readFileSync(f, 'utf8'); } catch { continue; }
|
|
784
|
+
let epics;
|
|
785
|
+
try { epics = require(repoScript('boards.js')).fold(text.split('\n').filter(Boolean)).epics || new Map(); } catch { return new Map(); }
|
|
786
|
+
epicsSeen.set(f, { sig, epics });
|
|
787
|
+
return epics;
|
|
769
788
|
}
|
|
770
789
|
return new Map();
|
|
771
790
|
}
|
package/workspace/lib/notes.js
CHANGED
|
@@ -301,11 +301,13 @@ function sameEvent(meeting, e) {
|
|
|
301
301
|
const a = minuteOf(meeting.start); const b = minuteOf(e.start);
|
|
302
302
|
return a !== null && a === b && normTitle(meeting.title) === normTitle(e.title);
|
|
303
303
|
}
|
|
304
|
-
/** The note already linked to this calendar event, or null.
|
|
304
|
+
/** The note already linked to this calendar event, or null. Read through the list's cache: Home asks once per meeting of the day,
|
|
305
|
+
* and parsing every note (transcripts and all) for each meeting held the server for most of a second (page-speed). The note is
|
|
306
|
+
* shared with the cache, so a caller must not change it. */
|
|
305
307
|
function findByEvent(dir, e) {
|
|
306
308
|
let names = [];
|
|
307
309
|
try { names = fs.readdirSync(notesDir(dir)).filter((f) => f.endsWith('.json')); } catch { return null; }
|
|
308
|
-
const hits = names.map((f) =>
|
|
310
|
+
const hits = names.map((f) => loadCached(dir, f.slice(0, -5))).filter((n) => n && sameEvent(n.meeting, e));
|
|
309
311
|
hits.sort((a, b) => String(b.updated_at).localeCompare(String(a.updated_at)));
|
|
310
312
|
return hits[0] || null;
|
|
311
313
|
}
|