create-pmos 0.611.0 → 0.613.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 +105 -27
- 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/briefing-premium-board-test.js +1 -1
- package/workspace/briefing-premium-calendar-2-test.js +3 -2
- package/workspace/briefing-premium-calendar-3-test.js +1 -1
- package/workspace/briefing-premium-calendar-test.js +1 -1
- package/workspace/briefing-premium-insights-test.js +1 -1
- package/workspace/briefing-premium-test.js +1 -1
- package/workspace/changelog.json +104 -0
- package/workspace/guide/layout.md +52 -18
- package/workspace/guide/programs.md +3 -3
- package/workspace/guide/routine.md +28 -13
- package/workspace/guide/settings-and-switches.md +1 -1
- package/workspace/lib/board-premium.js +12 -4
- package/workspace/lib/cos-chat.js +1 -0
- package/workspace/lib/doc-library.js +43 -12
- package/workspace/lib/doc-path.js +30 -0
- package/workspace/lib/engine/boards.js +4 -2
- package/workspace/lib/events-place.js +190 -38
- package/workspace/lib/events-stated.js +129 -0
- package/workspace/lib/initiative-chat.js +1 -0
- package/workspace/lib/insights-premium.js +13 -1
- package/workspace/lib/library-find.js +162 -0
- package/workspace/lib/library-items.js +196 -24
- package/workspace/lib/notes.js +3 -0
- package/workspace/lib/plan-items.js +17 -3
- package/workspace/lib/routes-artefacts.js +5 -2
- package/workspace/lib/routes-boards.js +6 -2
- package/workspace/lib/routes-doc-sheet.js +1 -0
- package/workspace/lib/routes-events-place.js +47 -10
- package/workspace/lib/routes-library.js +74 -8
- package/workspace/lib/routes-report-setups.js +13 -2
- package/workspace/lib/routine-reports.js +36 -4
- package/workspace/lib/status-when.js +36 -0
- package/workspace/lib/task-items.js +5 -3
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-vw-meet-test.js +2 -1
- package/workspace/premium-vw-notes-test.js +3 -2
- package/workspace/public/pm/artefact-kind.js +87 -0
- package/workspace/public/pm/bd-ini-panel.js +6 -6
- package/workspace/public/pm/bd-span.js +7 -1
- package/workspace/public/pm/bd-work.css +62 -0
- package/workspace/public/pm/bd-work.js +195 -68
- package/workspace/public/pm/cozy-bar.css +11 -0
- package/workspace/public/pm/cozy-bar.js +99 -0
- package/workspace/public/pm/cozy-day-pick.css +27 -0
- package/workspace/public/pm/cozy-day-pick.js +97 -0
- package/workspace/public/pm/cozy-ev.css +0 -4
- package/workspace/public/pm/cozy-events-view.js +165 -33
- package/workspace/public/pm/cozy-events.css +75 -3
- package/workspace/public/pm/cozy-events.js +86 -18
- package/workspace/public/pm/cozy-goals.css +172 -0
- package/workspace/public/pm/cozy-library.css +106 -17
- package/workspace/public/pm/cozy-nav.js +2 -3
- package/workspace/public/pm/cozy-pick.css +3 -0
- package/workspace/public/pm/cozy-pop-work.css +83 -24
- package/workspace/public/pm/cozy-pop-work.js +313 -72
- package/workspace/public/pm/cozy-popup.css +11 -2
- package/workspace/public/pm/cozy-popup.js +67 -9
- package/workspace/public/pm/cozy-routine-job.js +203 -0
- package/workspace/public/pm/cozy-routine-model.js +139 -31
- package/workspace/public/pm/cozy-routine-pop.js +164 -42
- package/workspace/public/pm/cozy-routine.css +61 -8
- package/workspace/public/pm/cozy-routine.js +207 -28
- package/workspace/public/pm/cozy-settings.js +1 -5
- package/workspace/public/pm/cozy-status-when.js +48 -0
- package/workspace/public/pm/cozy-viewer.js +19 -8
- package/workspace/public/pm/cozy-vw-mtg.css +39 -0
- package/workspace/public/pm/goals-model.js +205 -0
- package/workspace/public/pm/goals-open.js +124 -0
- package/workspace/public/pm/home-chat.js +4 -2
- package/workspace/public/pm/home-ini.js +8 -6
- package/workspace/public/pm/ini-edit.js +3 -1
- package/workspace/public/pm/ini-view-model.js +1 -1
- package/workspace/public/pm/library-model.js +170 -42
- package/workspace/public/pm/library-open.js +8 -5
- package/workspace/public/pm/page-chat.js +12 -2
- package/workspace/public/pm/pop-work-model.js +199 -41
- package/workspace/public/pm/premium-board.js +108 -43
- package/workspace/public/pm/premium-goals.js +213 -0
- package/workspace/public/pm/premium-library.js +376 -62
- package/workspace/public/pm/premium-shell.js +1 -1
- package/workspace/public/pm/premium-vw-mtg.js +79 -1
- package/workspace/public/pm/scope-chip.js +207 -0
- package/workspace/public/premium-events.html +3 -1
- package/workspace/public/premium-goals.html +37 -0
- package/workspace/public/premium-library.html +15 -7
- package/workspace/public/premium-routine.html +2 -0
- package/workspace/server.js +2 -1
- package/workspace/test-lists/doc-path.json +9 -0
- package/workspace/test-lists/goals-place.json +9 -0
- package/workspace/test-lists/status-when.json +9 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* library-find.js — the Library's search by meaning (initiative library-place, Library round 2, point 7).
|
|
3
|
+
*
|
|
4
|
+
* Two steps, so a title match stays instant and the meaning results arrive under it:
|
|
5
|
+
* shortlist({ roots, items, q }) → [{ id, passage, words }] READ ONLY. The content words of the question (no stop words, a plain stem)
|
|
6
|
+
* are found in the listed items' text: `git grep` over each product's tracked markdown files, and a meeting note's summary lines. A file
|
|
7
|
+
* scores by how many of the words it holds, then how often; its passage is the line that holds the most of them. No index is kept.
|
|
8
|
+
* rank(ctx, q, list, items) → { ok, results: [{ id, passage, idea }] } | { ok: false, why }
|
|
9
|
+
* One normal PMOS session (`claude -p`, a read-only ask run: the same path as the document chat; no new dependency, no new service)
|
|
10
|
+
* reads the question and the shortlist (name, kind, about, passage) and keeps the ones that are about the question, best first, each with
|
|
11
|
+
* the few words of its passage that carry the matching idea (the page shows them in bold). Answers are kept in memory for 10 minutes.
|
|
12
|
+
* What the session sees is what the shortlist already holds: names and one passage each, from the PM's own repositories and notes. */
|
|
13
|
+
const { execFileSync } = require('child_process');
|
|
14
|
+
const crypto = require('crypto');
|
|
15
|
+
|
|
16
|
+
const STOP = new Set(('the a an and or of to in on for with at by from is are was were be been this that these those we our us it its as about into up '
|
|
17
|
+
+ 'out what which who whom how why when where did do does done any anything something there their them they you your i me my can could should would '
|
|
18
|
+
+ 'will shall may might must have has had not no yes all some more most than then so if but also just only over under after before again new').split(' '));
|
|
19
|
+
const stem = (w) => w.replace(/(ies)$/, 'y').replace(/(ing|ed|es|s)$/, '').replace(/(.)\1$/, '$1');
|
|
20
|
+
/** The content words of a question, stemmed, at most 8. */
|
|
21
|
+
function wordsOf(q) {
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const w of String(q || '').toLowerCase().split(/[^a-z0-9]+/)) {
|
|
24
|
+
if (w.length < 3 || STOP.has(w)) continue;
|
|
25
|
+
const s = stem(w).length >= 3 ? stem(w) : w;
|
|
26
|
+
if (!out.includes(s)) out.push(s);
|
|
27
|
+
}
|
|
28
|
+
return out.slice(0, 8);
|
|
29
|
+
}
|
|
30
|
+
const MAX = 24;
|
|
31
|
+
const clip = (s, n) => { const t = String(s || '').replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).replace(/\s+\S*$/, '') + '…' : t; };
|
|
32
|
+
/** Strip markdown marks from a line so the passage reads as prose. */
|
|
33
|
+
const plain = (l) => String(l || '').replace(/^\s*\|\s*|\s*\|\s*$/g, '').replace(/\s*\|\s*/g, ' · ').replace(/^\s*(?:#+|[-*+>]|\d+[.)])\s*/, '').replace(/\*\*|__|`|\[([^\]]*)\]\([^)]*\)/g, (m, a) => a || '').trim();
|
|
34
|
+
|
|
35
|
+
function grep(root, words) {
|
|
36
|
+
const args = ['grep', '-I', '-i', '-n', '--no-color'];
|
|
37
|
+
for (const w of words) args.push('-e', w);
|
|
38
|
+
args.push('--', '*.md');
|
|
39
|
+
try { return execFileSync('git', args, { cwd: root, encoding: 'utf8', timeout: 8000, maxBuffer: 32 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] }); }
|
|
40
|
+
catch (e) { return (e && typeof e.stdout === 'string') ? e.stdout : ''; } // git grep exits 1 when nothing matches
|
|
41
|
+
}
|
|
42
|
+
/* a word counts at the start of a word only: "sms" is not in "mechanisms" */
|
|
43
|
+
const reOf = (w) => new RegExp('(^|[^a-z0-9])' + w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
|
|
44
|
+
function has(line, w) { return reOf(w).test(line); }
|
|
45
|
+
function scoreLine(line, words) {
|
|
46
|
+
let n = 0;
|
|
47
|
+
for (const w of words) if (has(line, w)) n++;
|
|
48
|
+
return n;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* roots: [{ ws, root }]; items: the Library's items (lib/library-items.js); q: the question.
|
|
52
|
+
* → [{ id, passage, words, score }] best first, at most 24. Only items in `items` are found, so a filter or a gate rule the page applies holds.
|
|
53
|
+
*/
|
|
54
|
+
function shortlist({ roots = [], items = [], q = '' } = {}) {
|
|
55
|
+
const words = wordsOf(q);
|
|
56
|
+
if (!words.length) return [];
|
|
57
|
+
const byPath = new Map();
|
|
58
|
+
for (const x of items) if (x.kind === 'doc' && x.open && x.open.doc) byPath.set(x.open.doc.ws + '|' + x.open.doc.path, x);
|
|
59
|
+
const hits = new Map(); // id → { x, have: Set, n, best, bestN }
|
|
60
|
+
const take = (x, line) => {
|
|
61
|
+
const t = plain(line); if (!t || /^[a-z_]+:\s/i.test(t) && t.length < 60) return; // a frontmatter line is not a passage
|
|
62
|
+
const n = scoreLine(t, words); if (!n) return;
|
|
63
|
+
let h = hits.get(x.id);
|
|
64
|
+
if (!h) { h = { x, have: new Set(), n: 0, best: '', bestN: 0 }; hits.set(x.id, h); }
|
|
65
|
+
for (const w of words) if (has(t, w)) h.have.add(w);
|
|
66
|
+
h.n++;
|
|
67
|
+
if (n > h.bestN || (n === h.bestN && t.length > h.best.length && h.best.length < 60)) { h.best = t; h.bestN = n; }
|
|
68
|
+
};
|
|
69
|
+
for (const { ws, root } of roots) {
|
|
70
|
+
if (!root) continue;
|
|
71
|
+
for (const raw of grep(root, words).split('\n')) {
|
|
72
|
+
const m = /^(.+?):(\d+):(.*)$/.exec(raw); if (!m) continue;
|
|
73
|
+
const x = byPath.get(ws + '|' + m[1]); if (x) take(x, m[3]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const x of items) {
|
|
77
|
+
if (x.kind === 'meeting') for (const l of x.gist || []) take(x, l);
|
|
78
|
+
// the record itself counts too (name, kind, about), so a short note with a matching name is found
|
|
79
|
+
take(x, [x.name, x.sub, x.kindText, x.about && x.about.title, x.about && x.about.programTitle].filter(Boolean).join(' · '));
|
|
80
|
+
}
|
|
81
|
+
return [...hits.values()]
|
|
82
|
+
.map((h) => ({ id: h.x.id, passage: clip(h.best, 240), words: [...h.have], score: h.have.size * 100 + Math.min(h.n, 50) }))
|
|
83
|
+
.filter((h) => h.words.length >= Math.min(2, words.length))
|
|
84
|
+
.sort((a, b) => b.score - a.score)
|
|
85
|
+
.slice(0, MAX);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* ── the ranking run ───────────────────────────────────────────────────────────────────────── */
|
|
89
|
+
const MODEL = 'claude-sonnet-5-5';
|
|
90
|
+
const LEAN = Object.freeze([{ flag: '--strict-mcp-config' }, { flag: '--disable-slash-commands' }, { flag: '--setting-sources', value: 'user' }, { flag: '--tools', value: 'Read' }]);
|
|
91
|
+
const TIMEOUT_MS = 60000;
|
|
92
|
+
const kept = new Map(); // key → { at, value }
|
|
93
|
+
const KEEP_MS = 10 * 60000;
|
|
94
|
+
|
|
95
|
+
function promptOf(q, list, byId) {
|
|
96
|
+
const lines = list.map((h, i) => {
|
|
97
|
+
const x = byId.get(h.id) || {};
|
|
98
|
+
const about = [x.about && x.about.programTitle, x.about && x.about.title].filter(Boolean).join(' › ');
|
|
99
|
+
return `${i + 1}. ${clip(x.name, 120)} [${x.kindText || ''}${about ? '; ' + clip(about, 80) : ''}]\n ${h.passage}`;
|
|
100
|
+
});
|
|
101
|
+
return [
|
|
102
|
+
'You rank search results in a product manager\'s library by meaning. Do not use any tool. Answer with JSON only.',
|
|
103
|
+
`The question: "${clip(q, 300)}"`,
|
|
104
|
+
'The candidates, each with the passage of its text that shares words with the question:',
|
|
105
|
+
lines.join('\n'),
|
|
106
|
+
'Keep only the candidates whose passage is really about the question (the same idea, not only the same words). Order them best first.',
|
|
107
|
+
'For each, copy the few words (2 to 8) of its passage that carry the idea, exactly as they are written in the passage.',
|
|
108
|
+
'Answer: {"keep":[{"n":<candidate number>,"idea":"<words copied from its passage>"}]}',
|
|
109
|
+
].join('\n\n');
|
|
110
|
+
}
|
|
111
|
+
function parse(text, list) {
|
|
112
|
+
const t = String(text || '');
|
|
113
|
+
const at = t.indexOf('{'), end = t.lastIndexOf('}');
|
|
114
|
+
if (at < 0 || end < at) return null;
|
|
115
|
+
let o; try { o = JSON.parse(t.slice(at, end + 1)); } catch { return null; }
|
|
116
|
+
if (!o || !Array.isArray(o.keep)) return null;
|
|
117
|
+
const out = [], seen = new Set();
|
|
118
|
+
for (const k of o.keep) {
|
|
119
|
+
const i = Number(k && k.n) - 1, h = list[i];
|
|
120
|
+
if (!h || seen.has(i)) continue;
|
|
121
|
+
seen.add(i);
|
|
122
|
+
const idea = String((k && k.idea) || '').trim();
|
|
123
|
+
// the idea is shown in bold inside the passage, so it must be words of the passage
|
|
124
|
+
out.push({ id: h.id, passage: h.passage, idea: idea && h.passage.toLowerCase().includes(idea.toLowerCase()) ? idea : '' });
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
function viaSession(ctx, prompt, key) {
|
|
129
|
+
if (typeof ctx.askClaude === 'function') return Promise.resolve(ctx.askClaude(prompt, { job: 'library-find', key })).catch(() => null);
|
|
130
|
+
const headless = require('./headless.js');
|
|
131
|
+
const origin = 'briefing-ask:library-find:' + key;
|
|
132
|
+
if (typeof ctx.spawnSession !== 'function' || headless.kindFor({ agent: 'claude', origin }) !== 'ask') return Promise.resolve(null);
|
|
133
|
+
return new Promise((resolve) => {
|
|
134
|
+
let settled = false; const done = (v) => { if (settled) return; settled = true; clearTimeout(t); resolve(v); };
|
|
135
|
+
const t = setTimeout(() => done(null), TIMEOUT_MS);
|
|
136
|
+
let s = null;
|
|
137
|
+
try {
|
|
138
|
+
s = ctx.spawnSession({ name: 'library: find by meaning', agent: 'claude', origin, initialInput: prompt,
|
|
139
|
+
modelAsk: { explicit: { model: MODEL, effort: 'low' } }, launchFlags: LEAN.map((f) => ({ ...f })),
|
|
140
|
+
onDone: (d) => { const r = d && d.result; done(r && r.ok && !r.isError ? String(r.text || '') : null); } });
|
|
141
|
+
} catch { s = null; }
|
|
142
|
+
if (!s || s.state === 'exited') done(null);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** Rank a shortlist by meaning. → { ok, results } or { ok: false, why } (the page then keeps the word ranking and says so). */
|
|
146
|
+
async function rank(ctx, q, list, items) {
|
|
147
|
+
if (!list.length) return { ok: true, results: [] };
|
|
148
|
+
const key = crypto.createHash('sha1').update(q + '\n' + list.map((h) => h.id + h.passage).join('\n')).digest('hex').slice(0, 12);
|
|
149
|
+
const k = kept.get(key);
|
|
150
|
+
if (k && Date.now() - k.at < KEEP_MS) return k.value;
|
|
151
|
+
const byId = new Map(items.map((x) => [x.id, x]));
|
|
152
|
+
const text = await viaSession(ctx, promptOf(q, list, byId), key);
|
|
153
|
+
if (text == null) return { ok: false, why: 'PMOS could not start a session to read for meaning' };
|
|
154
|
+
const results = parse(text, list);
|
|
155
|
+
if (!results) return { ok: false, why: 'the answer could not be read' };
|
|
156
|
+
const value = { ok: true, results };
|
|
157
|
+
kept.set(key, { at: Date.now(), value });
|
|
158
|
+
if (kept.size > 50) kept.delete(kept.keys().next().value);
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = { wordsOf, shortlist, rank, promptOf, parse };
|
|
@@ -2,26 +2,144 @@
|
|
|
2
2
|
/* library-items.js — what was made, as one list (initiative library-place, slice 7 of the six-place navigation; boards StLibrary,
|
|
3
3
|
* StLibMeetings, StLibDocs on Exploring 2). PURE: no file, no clock, no network.
|
|
4
4
|
*
|
|
5
|
-
* build({ products, notes }) → [item] newest first
|
|
5
|
+
* build({ products, notes, programs }) → [item] newest first
|
|
6
6
|
* products: [{ ws, name, titles: Map|{} initiative id → title, files, links, rounds }]
|
|
7
|
-
* files lib/doc-library.js library().files that an initiative owns: [{ path, title, category, date, initiative }]
|
|
7
|
+
* files lib/doc-library.js library().files that an initiative owns: [{ path, title, category, date, initiative, status, type, by }]
|
|
8
8
|
* links lib/custom-docs.js rows with a link: [{ id, scope, title, link: { kind, url }, at }]
|
|
9
9
|
* rounds prototype rounds: [{ id, ini, name, at, made, board }] (lib/idle-lab.js roundsOf, named by the round's brief)
|
|
10
|
-
* notes: lib/notes.js list().notes, with `came` (rowOf)
|
|
11
|
-
* ITEM
|
|
10
|
+
* notes: lib/notes.js list().notes, with `came` (rowOf); programs: lib/routes-programs.js all()
|
|
11
|
+
* ITEM (one catalogue record, Library round 2)
|
|
12
|
+
* { id, kind, name, sub, kindText, type, family, state, v, gate, came, by, ed, product, scope, about, updated, held, open, named?, suggest?, path?, note? }
|
|
12
13
|
* kind 'doc' | 'link' | 'meeting' | 'proto'
|
|
13
|
-
* kindText the Kind column:
|
|
14
|
-
*
|
|
14
|
+
* kindText the Kind column, specific: PRD, Strategic brief, Design brief, Done test, Meeting notes, Prototype, Link · Confluence …; from the
|
|
15
|
+
* frontmatter `type` first, then a title prefix ("Brief:"), then where the file lives. "Document" only when nothing says more.
|
|
16
|
+
* A title prefix that repeats the Kind leaves the name ("Brief: Scarlet lucky draw" → "Scarlet lucky draw"); `sub` keeps the title.
|
|
17
|
+
* family the Kind chip's family: plans · briefs · meetings · protos · checks · links (FAMILIES)
|
|
18
|
+
* state 'Draft' | 'Final' | 'Issued' for a document (frontmatter status, or DRAFT in the title, which leaves the name); '' otherwise
|
|
19
|
+
* v the edition a name or path says (v3), or null; ed: the key that folds editions of one document under one row
|
|
20
|
+
* gate PMOS's own gate records (done test, rubric, eval, retro …): grouped by New they fold into one "Checks · N" row per initiative
|
|
21
|
+
* by 'You' | 'PMOS' | a person's name (the last commit's author; an agent co-author is PMOS)
|
|
22
|
+
* product the product's name; about: { ws, product, ini, title, program, programTitle } (About = "Program › Initiative")
|
|
23
|
+
* scope the tokens pm/scope-chip.js filters by: 'p:<ws>', 'g:<program>', 'j:<ws>|<initiative>'
|
|
24
|
+
* named a meeting note with no title, which PMOS named ("CEM standup, 17 Nov"): ✦ until the PM accepts or renames it
|
|
25
|
+
* gist a meeting note's summary lines (none for a private note): the preview's first lines, and what search by meaning reads
|
|
26
|
+
* suggest a meeting note with no work: { ws, ini, title } the initiative its words point to, for a ✦ link (or null)
|
|
15
27
|
* came the "Came out of it" column of a meeting: '2 decisions · 3 tasks' ('' for a private note)
|
|
16
28
|
* updated ISO date or time of the last change; held: the meeting's start
|
|
17
29
|
* open what the page's opener needs: { doc: { ws, path } } | { url } | { note, ws } | { proto: { ws, board, id } }
|
|
18
30
|
* narrow(items, { ws, initiative }) → the items of one product or one initiative (slice 3's Artefacts table reads ?initiative=)
|
|
19
31
|
* Reports are not here (they repeat, so they live in Routine); Lab findings are not here (they go to Today as suggestions). */
|
|
20
32
|
|
|
21
|
-
/*
|
|
22
|
-
|
|
33
|
+
/* ── Kind: what one thing is (round 2, point 1) ─────────────────────────────────────────────────────────────────────── */
|
|
34
|
+
/* the frontmatter `type` as a Kind; a type not here reads as itself, in sentence case ("strategic-brief" → "Strategic brief") */
|
|
35
|
+
const BY_TYPE = {
|
|
36
|
+
prd: 'PRD', spec: 'Spec', specification: 'Spec', 'strategic brief': 'Strategic brief', brief: 'Strategic brief', 'design brief': 'Design brief',
|
|
37
|
+
'prototype brief': 'Prototype brief', 'content brief': 'Content brief', 'spike brief': 'Spike brief', strategy: 'Strategy', roadmap: 'Roadmap',
|
|
38
|
+
'risk list': 'Risk list', risks: 'Risk list', 'risk register': 'Risk list', rubric: 'Rubric', eval: 'Eval', verdict: 'Eval', retro: 'Retro',
|
|
39
|
+
retrospective: 'Retro', 'done test': 'Done test', research: 'Research', design: 'Design', prototype: 'Prototype brief', story: 'Story',
|
|
40
|
+
handover: 'Handover', review: 'Review', checklist: 'Checklist', calibration: 'Calibration', decision: 'Decision', adr: 'Decision',
|
|
41
|
+
explainer: 'Explainer', guide: 'Guide', concept: 'Knowledge', reference: 'Reference', playbook: 'Playbook', template: 'Template', okr: 'OKR',
|
|
42
|
+
radar: 'Radar', principle: 'Principle', debt: 'Debt', discovery: 'Discovery', sheet: 'Sheet', spreadsheet: 'Sheet', incident: 'Incident',
|
|
43
|
+
'user stories': 'User stories', stories: 'User stories', critique: 'Grilling critique', grilling: 'Grilling critique', 'grilling critique': 'Grilling critique',
|
|
44
|
+
minutes: 'Minutes', 'pre read': 'Pre-read', preread: 'Pre-read', update: 'Update note', 'update note': 'Update note', 'api spec': 'API spec',
|
|
45
|
+
'api specification': 'API spec', guideline: 'Guideline', guidelines: 'Guideline', anchor: 'Anchor', report: 'Report', note: 'Note',
|
|
46
|
+
};
|
|
47
|
+
/* the Kind from the category doc-library gives a file, when nothing else says more */
|
|
48
|
+
const TYPE = { spec: 'PRD', eval: 'Rubric', res: 'Research', exp: 'Explainer', dec: 'Decision', know: 'Knowledge', guide: 'Guide', proto: 'Prototype brief' };
|
|
49
|
+
/* a title prefix that names the kind: "Brief: …", "Design Brief: …", "Done test — …" (the prefix leaves the name) */
|
|
50
|
+
const PREFIX = [
|
|
51
|
+
[/^design\s+brief/i, 'Design brief'], [/^prototype\s+brief/i, 'Prototype brief'], [/^content\s+brief/i, 'Content brief'], [/^spike(\s+brief)?/i, 'Spike brief'],
|
|
52
|
+
[/^(strategic\s+)?brief/i, 'Strategic brief'], [/^done[\s-]+test/i, 'Done test'], [/^prd/i, 'PRD'], [/^rubric/i, 'Rubric'], [/^retro(spective)?/i, 'Retro'],
|
|
53
|
+
[/^design(?!\s+brief)/i, 'Design'], [/^roadmap/i, 'Roadmap'], [/^strategy/i, 'Strategy'], [/^risks?(\s+(list|register))?/i, 'Risk list'], [/^spec(ification)?/i, 'Spec'],
|
|
54
|
+
];
|
|
55
|
+
const SEP = String.raw`\s*(?::|—|–|\s-\s)\s*`;
|
|
56
|
+
/** The kind a title's prefix names, and the name without it. null when the title has no such prefix. */
|
|
57
|
+
function prefixOf(title) {
|
|
58
|
+
const t = String(title || '').trim();
|
|
59
|
+
for (const [re, kind] of PREFIX) {
|
|
60
|
+
const m = new RegExp('^(?:' + re.source.slice(1) + ')' + SEP, 'i').exec(t);
|
|
61
|
+
if (m && t.length > m[0].length) return { kind, name: t.slice(m[0].length).trim() };
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const sentence = (s) => { const t = String(s || '').replace(/[-_]+/g, ' ').replace(/\s+/g, ' ').trim().toLowerCase(); return t ? t[0].toUpperCase() + t.slice(1) : ''; };
|
|
66
|
+
/** A frontmatter type as a Kind, or '' when it says nothing (Initiative, Document). */
|
|
67
|
+
function kindOfType(type) {
|
|
68
|
+
const k = String(type || '').replace(/[-_]+/g, ' ').replace(/([a-z])([A-Z])/g, '$1 $2').trim().toLowerCase();
|
|
69
|
+
if (!k || k === 'document' || k === 'doc' || k === 'initiative' || k === 'other') return '';
|
|
70
|
+
return BY_TYPE[k] || sentence(k);
|
|
71
|
+
}
|
|
72
|
+
/* PMOS's own gate records: the agent writes them for the gates; grouped by New they fold into one "Checks · N" row per initiative */
|
|
73
|
+
const GATE = new Set(['Done test', 'Rubric', 'Eval', 'Retro', 'Run log', 'Incident', 'Out of scope', 'Record', 'Prototype brief', 'Calibration']);
|
|
74
|
+
/* the Kind families of the Kind chip, in its order */
|
|
75
|
+
const FAMILIES = [['plans', 'Plans and specs'], ['briefs', 'Briefs'], ['meetings', 'Meeting notes'], ['protos', 'Prototypes and designs'], ['checks', 'Checks'], ['links', 'Links']];
|
|
76
|
+
const BROAD = new Set(['Research', 'Reference', 'Knowledge', 'Guide', 'Story', 'Concept']);
|
|
77
|
+
const BRIEFS = new Set(['Strategic brief', 'Design brief', 'Content brief', 'Spike brief', 'Brief', 'Pre-read']);
|
|
78
|
+
function familyOf(kind, gate, k) {
|
|
79
|
+
if (k === 'meeting' || kind === 'Minutes') return 'meetings';
|
|
80
|
+
if (k === 'link') return 'links';
|
|
81
|
+
if (k === 'proto' || kind === 'Design' || kind === 'Prototype') return 'protos';
|
|
82
|
+
if (gate) return 'checks';
|
|
83
|
+
return BRIEFS.has(kind) ? 'briefs' : 'plans';
|
|
84
|
+
}
|
|
85
|
+
const under = (p, dir) => new RegExp('(^|/)planning/' + dir + '/').test(p);
|
|
86
|
+
/** THE KIND RESOLVER the Library and the popup's Artefacts share: kindOf({ path, title, type, category }) → { type, gate, name }.
|
|
87
|
+
* Where a gate record lives (done tests, evals …), then a specific frontmatter type, then a title prefix that names the kind ("Brief:",
|
|
88
|
+
* "PRD:"), then the file name (user-stories.md, *-minutes.md), then the folder (briefs/, design/), then a broad frontmatter type
|
|
89
|
+
* (Research, Reference), then the doc-library category; the last fallback is "Note", never "Document". `name` is the title without a
|
|
90
|
+
* prefix that only repeats the kind. */
|
|
91
|
+
function typeOf(f) {
|
|
92
|
+
const p = String(f.path || ''), t = String(f.title || '');
|
|
93
|
+
const pre = prefixOf(t);
|
|
94
|
+
let type = '';
|
|
95
|
+
if (under(p, 'done-tests')) type = 'Done test';
|
|
96
|
+
else if (under(p, 'evals')) type = /rubric/i.test(p) ? 'Rubric' : 'Eval';
|
|
97
|
+
else if (/\bretro\b|retrospective/i.test(t) || /(^|[/-])retro([-.]|$)/i.test(p)) type = 'Retro';
|
|
98
|
+
else if (under(p, 'runs')) type = 'Run log';
|
|
99
|
+
else if (under(p, 'incidents')) type = 'Incident';
|
|
100
|
+
else if (under(p, 'out-of-scope')) type = 'Out of scope';
|
|
101
|
+
else if (under(p, 'data-export') || under(p, 'batches')) type = 'Record';
|
|
102
|
+
else if (f.category === 'proto') type = 'Prototype brief';
|
|
103
|
+
else {
|
|
104
|
+
// a specific frontmatter type wins; a broad one (Research, Reference …) gives way to a title prefix that names the kind ("Brief: …")
|
|
105
|
+
// and to the folder (planning/briefs/, planning/design/)
|
|
106
|
+
const ft = kindOfType(f.type);
|
|
107
|
+
const dir = under(p, 'briefs') ? 'Strategic brief' : under(p, 'design') ? 'Design' : '';
|
|
108
|
+
// file-name rules for kinds that live by name: user-stories.md, *-minutes.md, *-api-spec.md, *-critique.md
|
|
109
|
+
const base = p.split('/').pop().toLowerCase();
|
|
110
|
+
const byName = /user-?stories/.test(base) ? 'User stories' : /minutes/.test(base) ? 'Minutes' : /api-?spec/.test(base) ? 'API spec' : /critique|grill/.test(base) ? 'Grilling critique' : /pre-?read/.test(base) ? 'Pre-read' : '';
|
|
111
|
+
type = (ft && !BROAD.has(ft) ? ft : '') || (pre && pre.kind) || byName || dir || ft || TYPE[f.category] || 'Note';
|
|
112
|
+
}
|
|
113
|
+
// a prefix that only repeats the kind leaves the name
|
|
114
|
+
const name = pre && (pre.kind === type || (BRIEFS.has(pre.kind) && BRIEFS.has(type))) ? pre.name : t;
|
|
115
|
+
return { type, gate: GATE.has(type), name };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* ── State and edition ─────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
119
|
+
const DRAFT_RE = /\s*(?:\(\s*DRAFT\s*\)|\[\s*DRAFT\s*\]|[,·—–-]\s*DRAFT\b)|\bDRAFT\b\s*[:—–-]?\s*/;
|
|
120
|
+
const ISSUED_RE = /^(issued|approved|accepted|published|released|ratified|shipped|signed off|signed-off|live)$/i;
|
|
121
|
+
/** The name without its DRAFT mark, and the State: Draft, Issued or Final. */
|
|
122
|
+
function stateOf(f, name) {
|
|
123
|
+
const st = String(f.status || '').trim();
|
|
124
|
+
const draft = /^(draft|wip|in progress|in-progress)$/i.test(st) || /\bDRAFT\b/.test(name);
|
|
125
|
+
const clean = name.replace(/\(([^()]*?),\s*DRAFT\s*\)/, '($1)').replace(DRAFT_RE, ' ').replace(/\s{2,}/g, ' ').replace(/\s+([)\]])/g, '$1').trim();
|
|
126
|
+
return { name: clean || name, state: draft ? 'Draft' : ISSUED_RE.test(st) ? 'Issued' : 'Final' };
|
|
127
|
+
}
|
|
128
|
+
const VER_RE = /\s*(?:[(\[]\s*)?\b(?:v|version|rev|r)\s*\.?\s*(\d{1,3})\b(?:\s*[)\]])?/i;
|
|
129
|
+
/** The version a name or a path says ("v3", "(version 2)", "-v2.md"), and the name without it. */
|
|
130
|
+
function versionOf(name, path) {
|
|
131
|
+
const m = VER_RE.exec(String(name || ''));
|
|
132
|
+
const pm = /[-_.]v(\d{1,3})(?=\.md$)/i.exec(String(path || ''));
|
|
133
|
+
const v = m ? Number(m[1]) : pm ? Number(pm[1]) : null;
|
|
134
|
+
const bare = m ? String(name).replace(m[0], ' ').replace(/\s{2,}/g, ' ').replace(/\s*[—–:-]\s*$/, '').trim() : String(name || '');
|
|
135
|
+
return { v, bare };
|
|
136
|
+
}
|
|
137
|
+
const keyOf = (s) => String(s || '').toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
|
|
138
|
+
|
|
23
139
|
const { shortTitle: short } = require('./doc-library.js'); // a pure function of that module
|
|
24
140
|
const plural = (n, one, many) => (n === 1 ? '1 ' + one : n + ' ' + many);
|
|
141
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
142
|
+
const dayOf = (iso) => { const d = new Date(String(iso || '')); return Number.isFinite(d.getTime()) ? d.getUTCDate() + ' ' + MON[d.getUTCMonth()] : ''; };
|
|
25
143
|
|
|
26
144
|
/** "2 decisions · 3 tasks", "No decision · 2 tasks", '' when nothing came out of it (or the note is private). */
|
|
27
145
|
function cameText(c) {
|
|
@@ -33,30 +151,80 @@ function cameText(c) {
|
|
|
33
151
|
const get = (m, k) => (!k ? '' : m instanceof Map ? m.get(k) || '' : (m && m[k]) || '');
|
|
34
152
|
const iniOfScope = (scope) => { const m = /^initiative:(.+)$/.exec(String(scope || '')); return m ? m[1] : null; };
|
|
35
153
|
|
|
36
|
-
|
|
154
|
+
/* ── a note PMOS names (round 2, point 5) ──────────────────────────────────────────────────────────────────────────────── */
|
|
155
|
+
const STOP = new Set('the a an and or of to in on for with at by from is are was were be this that we our it its as about into up out new call meeting meetings notes note sync'.split(' '));
|
|
156
|
+
const wordsOf = (s) => keyOf(s).split(' ').filter((w) => w.length > 2 && !STOP.has(w));
|
|
157
|
+
/** A name for a note with no title: the meeting's own title, else the first words of its summary, then the day ("CEM standup, 17 Nov"). */
|
|
158
|
+
function noteName(n) {
|
|
159
|
+
const day = dayOf((n.meeting && n.meeting.start) || n.created_at);
|
|
160
|
+
const m = n.meeting && n.meeting.title ? String(n.meeting.title).trim() : '';
|
|
161
|
+
let head = m;
|
|
162
|
+
if (!head) {
|
|
163
|
+
const line = String((n.summary_lines || [])[0] || '').trim();
|
|
164
|
+
head = line.split(/[.:;!?(—–]|\s-\s|,\s/)[0].trim().split(/\s+/).slice(0, 5).join(' ');
|
|
165
|
+
}
|
|
166
|
+
head = head ? head[0].toUpperCase() + head.slice(1) : 'Meeting';
|
|
167
|
+
return day ? head + ', ' + day : head;
|
|
168
|
+
}
|
|
169
|
+
/** The initiative a note talks about, by the words its title and summary share with the initiatives' titles: { ws, ini, title } or null.
|
|
170
|
+
* It asks at least two shared words that are half the initiative title's words or more, and one initiative ahead of the next; otherwise PMOS suggests nothing. */
|
|
171
|
+
function suggestFor(n, products) {
|
|
172
|
+
const words = new Set(wordsOf([n.title, ...(n.summary_lines || [])].join(' ')));
|
|
173
|
+
if (words.size < 2) return null;
|
|
174
|
+
const scored = [];
|
|
175
|
+
for (const p of products) {
|
|
176
|
+
const T = p.titles instanceof Map ? [...p.titles] : Object.entries(p.titles || {});
|
|
177
|
+
for (const [id, title] of T) {
|
|
178
|
+
const tw = wordsOf(title), hit = tw.filter((w) => words.has(w)).length;
|
|
179
|
+
// two shared words at least, and most of the initiative's own words: a common word or two is not a link
|
|
180
|
+
if (hit >= 2 && hit * 2 >= tw.length) scored.push({ ws: p.ws, ini: id, title: short(title) || id, hit });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
scored.sort((a, b) => b.hit - a.hit);
|
|
184
|
+
if (!scored.length || (scored[1] && scored[1].hit === scored[0].hit)) return null;
|
|
185
|
+
const { hit, ...s } = scored[0];
|
|
186
|
+
return s;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* build({ products, notes, programs }) → [item], newest first.
|
|
191
|
+
* programs: lib/routes-programs.js all(): [{ id, title, members: [{ ws, initiative }] }]
|
|
192
|
+
*/
|
|
193
|
+
function build({ products = [], notes = [], programs = [] } = {}) {
|
|
37
194
|
const out = [];
|
|
38
195
|
const byWs = new Map(products.map((p) => [p.ws, p]));
|
|
39
|
-
|
|
40
|
-
const
|
|
196
|
+
const progOf = new Map();
|
|
197
|
+
for (const g of programs || []) for (const m of g.members || []) { const k = m.ws + '|' + m.initiative; if (!progOf.has(k)) progOf.set(k, { id: g.id, title: g.title || g.id }); }
|
|
198
|
+
// About is "Program › Initiative": the initiative named short, as the Board does ("Tender new CIAM", not the PRD's full title)
|
|
199
|
+
const about = (p, ini, title) => {
|
|
200
|
+
const prog = p && ini ? progOf.get(p.ws + '|' + ini) || null : null;
|
|
201
|
+
return { ws: p ? p.ws : null, product: p ? p.name : '', ini: ini || null, title: (ini && (short(title || get(p && p.titles, ini)) || ini)) || '',
|
|
202
|
+
program: prog ? prog.id : null, programTitle: prog ? prog.title : '' };
|
|
203
|
+
};
|
|
204
|
+
const scope = (a) => [a.ws ? 'p:' + a.ws : null, a.program ? 'g:' + a.program : null, a.ws && a.ini ? 'j:' + a.ws + '|' + a.ini : null].filter(Boolean);
|
|
205
|
+
const push = (x) => { x.scope = scope(x.about); x.product = x.about.product; out.push(x); };
|
|
41
206
|
for (const p of products) {
|
|
42
207
|
for (const f of p.files || []) {
|
|
43
208
|
if (!f || !f.path || !f.initiative || f.category === 'ini') continue; // the initiative record is the work itself, not a thing made for it
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
209
|
+
const T = typeOf(f), title = T.name || f.title || f.path.split('/').pop(), S = stateOf(f, title), V = versionOf(S.name, f.path);
|
|
210
|
+
// the edition leaves the name and shows in State ("Final · v3")
|
|
211
|
+
const name = V.v && V.bare ? V.bare : S.name;
|
|
212
|
+
push({ id: 'doc:' + p.ws + ':' + f.path, kind: 'doc', name, sub: (f.title || '') !== name ? f.title || '' : '',
|
|
213
|
+
kindText: T.type, type: T.type, family: familyOf(T.type, T.gate, 'doc'), state: S.state, v: V.v, gate: T.gate, came: '', by: f.by || null,
|
|
214
|
+
ed: p.ws + '|' + f.initiative + '|' + T.type + '|' + keyOf(V.bare), about: about(p, f.initiative), updated: f.date || null, held: null,
|
|
215
|
+
path: f.path, open: { doc: { ws: p.ws, path: f.path } } });
|
|
48
216
|
}
|
|
49
217
|
for (const l of p.links || []) {
|
|
50
218
|
if (!l || !l.link || !l.link.url) continue;
|
|
51
|
-
const ini = iniOfScope(l.scope);
|
|
52
|
-
|
|
53
|
-
about: about(p, ini), updated: l.at || null, held: null, open: { url: l.link.url } });
|
|
219
|
+
const ini = iniOfScope(l.scope), src = String(l.link.kind || '').trim();
|
|
220
|
+
push({ id: 'link:' + p.ws + ':' + l.id, kind: 'link', name: l.title, sub: '', kindText: 'Link · ' + src, type: 'Link · ' + src, family: 'links', source: src,
|
|
221
|
+
state: '', v: null, gate: false, came: '', by: l.by && l.by !== 'pm' ? String(l.by) : 'You', ed: null, about: about(p, ini), updated: l.at || null, held: null, open: { url: l.link.url } });
|
|
54
222
|
}
|
|
55
223
|
for (const r of p.rounds || []) {
|
|
56
224
|
if (!r || !r.id) continue;
|
|
57
|
-
|
|
58
|
-
came: r.made ? plural(r.made, 'version', 'versions') : '', about: about(p, r.ini),
|
|
59
|
-
open: { proto: { ws: p.ws, board: r.board || '', id: r.id } } });
|
|
225
|
+
push({ id: 'proto:' + p.ws + ':' + r.id, kind: 'proto', name: r.name || 'Prototype', sub: '', kindText: 'Prototype', type: 'Prototype', family: 'protos',
|
|
226
|
+
state: '', v: r.made > 1 ? r.made : null, gate: false, came: r.made ? plural(r.made, 'version', 'versions') : '', by: 'PMOS', ed: null, about: about(p, r.ini),
|
|
227
|
+
updated: r.at || null, held: null, open: { proto: { ws: p.ws, board: r.board || '', id: r.id } } });
|
|
60
228
|
}
|
|
61
229
|
}
|
|
62
230
|
for (const n of notes) {
|
|
@@ -64,8 +232,12 @@ function build({ products = [], notes = [] } = {}) {
|
|
|
64
232
|
const ini = n.initiative && n.initiative.id ? n.initiative : null;
|
|
65
233
|
const p = byWs.get((ini && ini.ws) || n.ws) || null;
|
|
66
234
|
const held = (n.meeting && n.meeting.start) || n.created_at || null;
|
|
67
|
-
|
|
68
|
-
|
|
235
|
+
const untitled = !String(n.title || '').trim() || n.title === 'Untitled note';
|
|
236
|
+
// a note with no title is named by PMOS and marked ✦ until the PM accepts or renames it; a note with no work gets a ✦ link to suggest
|
|
237
|
+
const sg = !ini && !n.private ? suggestFor(n, products) : null;
|
|
238
|
+
push({ id: 'meeting:' + n.id, kind: 'meeting', name: untitled ? noteName(n) : n.title, named: untitled, sub: '', kindText: 'Meeting notes', type: 'Meeting notes',
|
|
239
|
+
family: 'meetings', state: '', v: null, gate: false, came: n.private ? '' : cameText(n.came), by: n.recorded_from || n.summary ? 'PMOS' : 'You', ed: null,
|
|
240
|
+
about: ini ? about(p, ini.id, ini.title) : about(p, null), suggest: sg, gist: n.private ? [] : (n.summary_lines || []).slice(0, 3), updated: n.updated_at || held, held, note: n.id,
|
|
69
241
|
open: { note: n.id, ws: (p && p.ws) || n.ws || '' } });
|
|
70
242
|
}
|
|
71
243
|
return out.sort((a, b) => String(b.updated || '').localeCompare(String(a.updated || '')) || a.name.localeCompare(b.name));
|
|
@@ -75,4 +247,4 @@ function narrow(items, { ws, initiative } = {}) {
|
|
|
75
247
|
return items.filter((x) => (!ws || x.about.ws === ws) && (!initiative || x.about.ini === initiative));
|
|
76
248
|
}
|
|
77
249
|
|
|
78
|
-
module.exports = { build, narrow, cameText, TYPE };
|
|
250
|
+
module.exports = { build, narrow, cameText, TYPE, FAMILIES, typeOf, kindOf: typeOf, prefixOf, kindOfType, stateOf, versionOf, noteName, suggestFor };
|
package/workspace/lib/notes.js
CHANGED
|
@@ -207,6 +207,9 @@ function rowOf(n, now = Date.now(), resumeMs = RESUME_MS) {
|
|
|
207
207
|
}
|
|
208
208
|
/** What came out of a meeting (Library's "Came out of it", initiative library-place): the decisions and tasks among the agent's bullets. */
|
|
209
209
|
function cameOf(n) {
|
|
210
|
+
// the final notes after Stop, as the meeting card reads them (premium-vw-meet.js partsOf); else the bullets caught live
|
|
211
|
+
const f = n.final_notes;
|
|
212
|
+
if (f && (Array.isArray(f.decisions) || Array.isArray(f.actions))) return { decisions: (f.decisions || []).length, tasks: (f.actions || []).length };
|
|
210
213
|
const b = (n.bullets || []).filter((x) => x && !x.dropped);
|
|
211
214
|
return { decisions: b.filter((x) => x.cat === 'decision').length, tasks: b.filter((x) => x.cat === 'action').length };
|
|
212
215
|
}
|
|
@@ -33,6 +33,7 @@ const path = require('path');
|
|
|
33
33
|
const crypto = require('crypto');
|
|
34
34
|
const { createSinkGuard } = require('./sink.js');
|
|
35
35
|
const planTree = require('./plan-tree.js');
|
|
36
|
+
const statusWhen = require('./status-when.js'); // the day a move really happened (popup round 3 point 18)
|
|
36
37
|
const consoleState = require('./console-state');
|
|
37
38
|
const actorLib = require('./actor.js');
|
|
38
39
|
|
|
@@ -212,6 +213,7 @@ function lineErr(r) {
|
|
|
212
213
|
if (!STATES.includes(r.to)) return 'to is not todo, doing, review or done';
|
|
213
214
|
if (r.evidence !== undefined && evidenceErr(r.evidence)) return evidenceErr(r.evidence);
|
|
214
215
|
if (r.override !== undefined && r.override !== true) return 'override is written only as true';
|
|
216
|
+
if (r.happened !== undefined && !/^\d{4}-\d{2}-\d{2}$/.test(String(r.happened))) return 'happened is a day, YYYY-MM-DD';
|
|
215
217
|
// The writer computes override for a pm: actor only, so an agent line that carries it was not written by the writer.
|
|
216
218
|
if (r.override !== undefined && !String(r.by).startsWith('pm:')) return 'override is written only on a pm: line';
|
|
217
219
|
return null;
|
|
@@ -278,11 +280,17 @@ function historyOf(rec) {
|
|
|
278
280
|
const h = { eid: rec.eid, ev: rec.ev, by: rec.by, via: rec.via, at: rec.at };
|
|
279
281
|
if (rec.ev === 'planned') h.stage = rec.stage;
|
|
280
282
|
if (rec.ev === 'set') h.fields = { ...rec.fields };
|
|
281
|
-
if (rec.ev === 'moved') { h.to = rec.to; if (rec.evidence) h.evidence = { ...rec.evidence }; if (rec.override) h.override = true; }
|
|
283
|
+
if (rec.ev === 'moved') { h.to = rec.to; if (rec.evidence) h.evidence = { ...rec.evidence }; if (rec.override) h.override = true; if (rec.happened) h.happened = rec.happened; }
|
|
282
284
|
if (rec.ev === 'flagged') { h.blocked = rec.blocked; if (rec.blocked) h.reason = rec.reason; }
|
|
283
285
|
if (rec.ev === 'withdrawn' && rec.why) h.why = rec.why;
|
|
284
286
|
return h;
|
|
285
287
|
}
|
|
288
|
+
/** The day of an item's last move, its real day first (round 3 point 18), else the day it was made: read from its history, so the
|
|
289
|
+
* item's own shape (the plan API's layout) does not change. */
|
|
290
|
+
function sinceOf(it) {
|
|
291
|
+
const m = (it.history || []).filter((h) => h.ev === 'moved').pop();
|
|
292
|
+
return m ? m.happened || String(m.at || '').slice(0, 10) : String(it.createdAt || '').slice(0, 10) || null;
|
|
293
|
+
}
|
|
286
294
|
const touch = (it, rec) => { it.updatedBy = rec.by; it.updatedVia = rec.via; it.updatedAt = rec.at; it.history.push(historyOf(rec)); };
|
|
287
295
|
|
|
288
296
|
/** A mutable fold state, so the writer can apply the events of one call to a working copy as it checks them. */
|
|
@@ -549,7 +557,7 @@ function buildRecord(ctx, ev, index) {
|
|
|
549
557
|
const allowed = {
|
|
550
558
|
planned: ['ev', 'initiative', 'title', 'stage', 'order', 'owner', 'after', 'start', 'due', 'milestone', 'note'],
|
|
551
559
|
set: ['ev', 'item', 'initiative', 'fields'],
|
|
552
|
-
moved: ['ev', 'item', 'initiative', 'to', 'evidence'],
|
|
560
|
+
moved: ['ev', 'item', 'initiative', 'to', 'evidence', 'happened'],
|
|
553
561
|
flagged: ['ev', 'item', 'initiative', 'blocked', 'reason'],
|
|
554
562
|
withdrawn: ['ev', 'item', 'initiative', 'why'],
|
|
555
563
|
restored: ['ev', 'item', 'initiative'],
|
|
@@ -673,9 +681,15 @@ function buildRecord(ctx, ev, index) {
|
|
|
673
681
|
if (e) return refuse(400, e, index);
|
|
674
682
|
evidence = { kind: evidence.kind, ref: evidence.ref };
|
|
675
683
|
}
|
|
684
|
+
// happened: the day the move really happened, when the person says it was earlier than now (lib/status-when.js)
|
|
685
|
+
if (ev.happened !== undefined && ev.happened !== null) {
|
|
686
|
+
const e = statusWhen.checkHappened(ev.happened, { floor: sinceOf(it) });
|
|
687
|
+
if (e) return refuse(400, e, index);
|
|
688
|
+
}
|
|
676
689
|
const rec = common(init, it.id, it.updatedAt);
|
|
677
690
|
rec.to = ev.to;
|
|
678
691
|
if (evidence) rec.evidence = evidence;
|
|
692
|
+
if (ev.happened != null) rec.happened = ev.happened;
|
|
679
693
|
// override: the PM moved an item the agent owns. Computed here, never accepted from a caller. Attaching
|
|
680
694
|
// evidence is not a move, so it is never an override.
|
|
681
695
|
if (actor.by.startsWith('pm:') && it.owner === 'agent' && !attach) rec.override = true;
|
|
@@ -938,6 +952,6 @@ function handoffPrompt(item, initiativeId, stageLabel) {
|
|
|
938
952
|
module.exports = {
|
|
939
953
|
LEDGER, EVENTS, STATES, PM_SLUG, ID_RE, INIT_RE, SESSION_RE,
|
|
940
954
|
ledgerRoot, ledgerPath, newItemId, newEventId, initiativeOf,
|
|
941
|
-
readLines, parseText, fold, readFold, readFoldShared, progressOf, progressLabel, lineErr,
|
|
955
|
+
readLines, parseText, fold, readFold, readFoldShared, progressOf, progressLabel, lineErr, sinceOf,
|
|
942
956
|
actorFromCli, appendFromUi, appendFromCli, needsFor, ledgerSigs, readLayout, handoffPrompt, parseEvidence,
|
|
943
957
|
};
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* POST /api/artefacts/set { ws, scope, artefact, field, text } → { ok, line } the PM edits one line from the Viewer (board AwB: "You edit
|
|
23
23
|
* any line"). A page press (pm-guard requirePagePress); the actor is the PM, so Claude asks before it
|
|
24
24
|
* changes that line again (lib/artefacts.js pmEdited, lib/driver-decide.js autoApply).
|
|
25
|
+
* POST /api/artefacts/undo { ws, ref } → { ok, line } the Undo of that edit (the popup's Overview, nav slice 3 round 3): the PM's set line
|
|
26
|
+
* `ref` no longer counts. The same page press and PM-only rule as set; the mirror follows it.
|
|
25
27
|
*
|
|
26
28
|
* THE MIGRATION. Every read of a repository carries its older records (core documents, kept driver proposals,
|
|
27
29
|
* report drafts) under their artefacts: lib/artefacts.js migrateRepo. It is idempotent and only appends pointers; nothing is deleted or
|
|
@@ -43,7 +45,7 @@ const pageBy = (x) => (x && x.by ? { ...x, by: actorLib.pageName(x.by) } : x);
|
|
|
43
45
|
async function handle(req, res, url, ctx) {
|
|
44
46
|
const send = (status, body) => { ctx.json(res, body, status); return true; };
|
|
45
47
|
const sub = url.pathname.replace(/^\/api\/artefacts\/?/, '');
|
|
46
|
-
if (sub === 'set' && req.method === 'POST') {
|
|
48
|
+
if ((sub === 'set' || sub === 'undo') && req.method === 'POST') {
|
|
47
49
|
const read = await ctx.readJson(req);
|
|
48
50
|
if (!read.ok) return send(400, { ok: false, error: 'the body is not JSON' });
|
|
49
51
|
const b = read.body || {};
|
|
@@ -54,7 +56,8 @@ async function handle(req, res, url, ctx) {
|
|
|
54
56
|
if (!w || !w.root) return send(404, { ok: false, error: 'no such workspace' });
|
|
55
57
|
let dir;
|
|
56
58
|
try { dir = A.dirOf(w.root); } catch (e) { return send(409, { ok: false, error: String((e && e.message) || e) }); }
|
|
57
|
-
const r = A.
|
|
59
|
+
const r = sub === 'undo' ? A.undo(A.file(dir), { ref: b.ref }, g.actor)
|
|
60
|
+
: A.set(A.file(dir), { scope: b.scope, artefact: b.artefact, field: b.field, text: typeof b.text === 'string' ? b.text : '' }, g.actor);
|
|
58
61
|
if (!r.ok) return send(r.status, { ok: false, error: r.error });
|
|
59
62
|
// a done test or kill condition lands on the record too, so the gates count it (launch simulation W6, lib/artefact-mirror.js)
|
|
60
63
|
const mirror = require('./artefact-mirror.js').after(w.root, r.line, A.file(dir));
|
|
@@ -99,6 +99,7 @@ const B = require(repoScript('boards.js'));
|
|
|
99
99
|
const WF = require(repoScript('workflows.js'));
|
|
100
100
|
const WS = require('./workflows-store.js');
|
|
101
101
|
const TI = require('./task-items.js');
|
|
102
|
+
const SW = require('./status-when.js');
|
|
102
103
|
const TS = require('./task-store.js');
|
|
103
104
|
const holdSpans = require('./hold-spans.js');
|
|
104
105
|
const ledgers = require('./plan-ledgers.js');
|
|
@@ -1466,12 +1467,15 @@ const WRITES = {
|
|
|
1466
1467
|
if (!state) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
|
|
1467
1468
|
const it = itemOnBoard(ctx, res, p, body.task);
|
|
1468
1469
|
if (!it) return;
|
|
1469
|
-
return itemWrite(ctx, res, p, it, TI.stateEvents(it, state, body.why), g);
|
|
1470
|
+
return itemWrite(ctx, res, p, it, TI.stateEvents(it, state, body.why, body.happened || null), g);
|
|
1470
1471
|
}
|
|
1471
1472
|
if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
|
|
1472
1473
|
if (!state) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
|
|
1474
|
+
// happened: the day the move really happened (round 3 point 18), never in the future and never before the previous move
|
|
1475
|
+
const happened = body.happened == null || body.happened === '' ? null : body.happened;
|
|
1476
|
+
if (happened) { const e = SW.checkHappened(happened, { floor: SW.floorOf(t) }); if (e) return fail(ctx, res, 400, e); }
|
|
1473
1477
|
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
1474
|
-
append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, state, why: typeof body.why === 'string' && body.why.trim() ? body.why.trim().slice(0, 300) : 'status move' });
|
|
1478
|
+
append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, state, why: typeof body.why === 'string' && body.why.trim() ? body.why.trim().slice(0, 300) : 'status move', ...(happened ? { happened } : {}) });
|
|
1475
1479
|
const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
|
|
1476
1480
|
ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t2)])[0] });
|
|
1477
1481
|
},
|
|
@@ -62,6 +62,7 @@ function inside(root, full) {
|
|
|
62
62
|
// The same guard /api/doc/save uses: resolve under the root, markdown only, refuse anything outside.
|
|
63
63
|
function resolveDoc(root, rel) {
|
|
64
64
|
if (typeof rel !== 'string' || !rel.trim() || rel.includes('\0')) return { error: fail(400, 'path is required') };
|
|
65
|
+
rel = require('./doc-path.js').resolve(root, rel); // the same resolver as GET /api/doc: with or without the kit's "pmos/"
|
|
65
66
|
const full = path.resolve(root, rel);
|
|
66
67
|
if (!full.startsWith(path.resolve(root) + path.sep) || !inside(root, path.dirname(full))) return { error: fail(404, 'outside workspace') };
|
|
67
68
|
if (!/\.md$/i.test(full)) return { error: fail(400, 'only markdown documents are editable here') };
|