create-pmos 0.397.0 → 0.399.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/briefing-premium-adddoc-test.js +105 -52
- package/workspace/briefing-premium-board-test.js +284 -128
- package/workspace/briefing-premium-calendar-2-test.js +135 -198
- package/workspace/briefing-premium-calendar-3-test.js +143 -418
- package/workspace/briefing-premium-calendar-test.js +85 -196
- package/workspace/briefing-premium-doc-edit-test.js +99 -83
- package/workspace/briefing-premium-initiative-test.js +175 -290
- package/workspace/briefing-premium-insights-test.js +414 -219
- package/workspace/briefing-premium-metrics-test.js +55 -97
- package/workspace/briefing-premium-products-test.js +44 -28
- package/workspace/briefing-premium-sources-test.js +70 -49
- package/workspace/briefing-premium-test.js +155 -648
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +24 -0
- package/workspace/ev-everywhere-test.js +210 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +187 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +68 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-grill.js +63 -0
- package/workspace/lib/board-premium.js +121 -24
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/initiative-layout.js +77 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +64 -15
- package/workspace/lib/insights-records.js +115 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/meeting-points.js +52 -0
- package/workspace/lib/news-for-you.js +88 -0
- package/workspace/lib/notes-series.js +29 -6
- package/workspace/lib/report-confirm.js +48 -0
- package/workspace/lib/route-modules.js +12 -0
- package/workspace/lib/routes-board-docs.js +46 -0
- package/workspace/lib/routes-board-grill.js +90 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-home-review.js +108 -0
- package/workspace/lib/routes-initiative-layout.js +57 -0
- package/workspace/lib/routes-insights-premium.js +16 -4
- package/workspace/lib/routes-insights-records.js +133 -0
- package/workspace/lib/routes-meeting-points.js +37 -0
- package/workspace/lib/routes-news.js +57 -0
- package/workspace/lib/routes-notes.js +3 -1
- package/workspace/lib/routes-report-confirm.js +31 -0
- package/workspace/lib/routes-search.js +38 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/search-index.js +176 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/viewer-meeting.js +205 -0
- package/workspace/lib/viewer-report.js +89 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +128 -82
- package/workspace/premium-briefing-depth-test.js +104 -90
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +37 -37
- package/workspace/premium-chat-context-test.js +19 -18
- package/workspace/premium-chat-goal-view-test.js +23 -23
- package/workspace/premium-chat-notes-test.js +26 -31
- package/workspace/premium-chat-report-tab-test.js +46 -28
- package/workspace/premium-chat-term-test.js +16 -16
- package/workspace/premium-chat-viewer-test.js +60 -59
- package/workspace/premium-core-doc-issue-test.js +52 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +10 -3
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +152 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -33
- package/workspace/premium-vw-cal-test.js +97 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +17 -10
- package/workspace/premium-vw-item-test.js +50 -49
- package/workspace/premium-vw-jira-test.js +53 -27
- package/workspace/premium-vw-meet-test.js +115 -187
- package/workspace/premium-vw-notes-test.js +88 -109
- package/workspace/premium-vw-rec-test.js +71 -194
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +61 -53
- package/workspace/public/pm/bd-acts.js +383 -0
- package/workspace/public/pm/bd-asks.js +261 -0
- package/workspace/public/pm/bd-pop.js +59 -0
- package/workspace/public/pm/bd-span.js +222 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- package/workspace/public/pm/bd-views.js +169 -0
- package/workspace/public/pm/c3-doc-sheet.js +1 -1
- package/workspace/public/pm/c3-md.js +3 -395
- package/workspace/public/pm/c3-phone-detail.js +1 -1
- package/workspace/public/pm/c3-phone-model.js +3 -68
- package/workspace/public/pm/chat-term.js +3 -3
- package/workspace/public/pm/cozy-board.css +798 -230
- package/workspace/public/pm/cozy-ev.css +228 -0
- package/workspace/public/pm/cozy-evmodel.js +106 -0
- package/workspace/public/pm/cozy-evui.js +47 -0
- package/workspace/public/pm/cozy-home.css +570 -142
- package/workspace/public/pm/cozy-home.js +5 -3
- package/workspace/public/pm/cozy-insights.css +437 -170
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +104 -29
- package/workspace/public/pm/cozy-news.js +140 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-search.js +203 -0
- package/workspace/public/pm/cozy-settings.js +198 -0
- package/workspace/public/pm/cozy-sources.js +89 -0
- package/workspace/public/pm/cozy-today.css +217 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +145 -0
- package/workspace/public/pm/cozy-vw-mtg.css +350 -0
- package/workspace/public/pm/cozy-vw-rp.css +152 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +83 -1
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +1179 -0
- package/workspace/public/pm/home-around.js +413 -0
- package/workspace/public/pm/home-chat.js +512 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-dictate.js +54 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-ini-model.js +190 -0
- package/workspace/public/pm/home-ini.css +171 -0
- package/workspace/public/pm/home-ini.js +456 -0
- package/workspace/public/pm/home-list.js +276 -0
- package/workspace/public/pm/home-more.js +132 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-review.js +104 -0
- package/workspace/public/pm/home-task.js +67 -0
- package/workspace/public/pm/home-today.js +144 -0
- package/workspace/public/pm/home-work.js +547 -0
- package/workspace/public/pm/phone-moment.js +69 -0
- package/workspace/public/pm/pm-work-view.js +1 -1
- package/workspace/public/pm/premium-attach.js +4 -0
- package/workspace/public/pm/premium-board.js +548 -395
- package/workspace/public/pm/premium-chart-tab.js +109 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +23 -21
- package/workspace/public/pm/premium-insights.js +1102 -581
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-mtg-present.js +138 -0
- package/workspace/public/pm/premium-mtg-replay.js +142 -0
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +669 -476
- package/workspace/public/pm/premium-report-tab.js +116 -67
- package/workspace/public/pm/premium-shell.js +76 -123
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +277 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +958 -0
- package/workspace/public/pm/premium-vw-notes.js +116 -68
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -218
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/rp-parts.js +269 -0
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +29 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +26 -64
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +18 -107
- package/workspace/r/m1.png +0 -0
- package/workspace/r/m2.png +0 -0
- package/workspace/r/m3.png +0 -0
- package/workspace/r/nl.png +0 -0
- package/workspace/server.js +18 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/initiative-layout.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
- package/workspace/test-lists/premium-uncovered-reports.json +9 -0
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/test-lists/uf-everywhere.json +15 -0
- package/workspace/test-lists/uf-home.json +9 -0
- package/workspace/test-lists/uncovered-board.json +9 -0
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* search-index.js — Search across the repository and every worktree (initiative premium-uncovered-features, E1; canvas EvSearch, EvPhone).
|
|
3
|
+
*
|
|
4
|
+
* worktrees(root) → [{ id, name, path, branch, head, main }] `git worktree list --porcelain`; the first is the main one
|
|
5
|
+
* kindOf(relPath) → 'initiative' | 'document' | 'slides' | 'report' | 'artifact' | 'file' | null PURE
|
|
6
|
+
* titleOf(text, relPath) → the frontmatter title, else the first "# " heading, else the file name PURE
|
|
7
|
+
* search({ root, q, only, notes, now }) → { ok, q, worktrees, counts, results, more } READ-ONLY
|
|
8
|
+
* readFile({ root, wt, path }) → { ok, text, path, wt } | { ok: false, status, error } one file of a listed worktree, read-only
|
|
9
|
+
*
|
|
10
|
+
* What is searched. Every file git knows in the main worktree (tracked, plus untracked files that are not ignored), and in each other worktree
|
|
11
|
+
* only the files that differ from the main worktree's HEAD (changed, committed on its branch, or new). So a file shows once, from main, unless
|
|
12
|
+
* a worktree holds another version of it: then that version shows too, marked with the worktree, so a draft that is not merged can be found.
|
|
13
|
+
* A file matches by its path or name, or by its text (git grep, case-insensitive, fixed string). Meetings are the note titles (lib/notes.js).
|
|
14
|
+
* Nothing here writes. Every git call has a time limit and a size limit; a worktree that cannot be read is listed with its error. */
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const { execFileSync } = require('child_process');
|
|
18
|
+
|
|
19
|
+
const KINDS = ['initiative', 'document', 'slides', 'report', 'artifact', 'meeting'];
|
|
20
|
+
const MAX_FILES = 40000;
|
|
21
|
+
const MAX_PER_KIND = 30;
|
|
22
|
+
const SKIP = /(^|\/)(node_modules|\.git|vendor|dist|build|coverage|\.next|\.claude\/worktrees)(\/|$)/;
|
|
23
|
+
const BINARY = /\.(png|jpe?g|gif|webp|ico|woff2?|ttf|otf|mp3|mp4|wav|webm|zip|gz|tgz|lock)$/i;
|
|
24
|
+
const DESIGN = /\.(html?|svg|pdf|fig|sketch)$/i;
|
|
25
|
+
const SLIDES = /\.(pptx|key|odp)$/i;
|
|
26
|
+
const CODE = /\.(m?js|cjs|ts|tsx|jsx|css|py|sh|json|jsonl|ya?ml|go|rb|rs|java|kt|swift|sql)$/i;
|
|
27
|
+
|
|
28
|
+
function git(cwd, args, { timeout = 8000, max = 32 * 1024 * 1024 } = {}) {
|
|
29
|
+
return execFileSync('git', args, { cwd, encoding: 'utf8', timeout, maxBuffer: max, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The worktrees of the repository at root, the main one first. Each id is stable and safe in a URL: 'main' or the folder name. */
|
|
33
|
+
function worktrees(root) {
|
|
34
|
+
let out = '';
|
|
35
|
+
try { out = git(root, ['worktree', 'list', '--porcelain']); } catch { return [{ id: 'main', name: 'main', path: path.resolve(root), branch: '', head: '', main: true }]; }
|
|
36
|
+
const list = [];
|
|
37
|
+
let cur = null;
|
|
38
|
+
for (const line of out.split('\n')) {
|
|
39
|
+
if (line.startsWith('worktree ')) { cur = { path: line.slice(9).trim(), branch: '', head: '', bare: false }; list.push(cur); }
|
|
40
|
+
else if (!cur) continue;
|
|
41
|
+
else if (line.startsWith('HEAD ')) cur.head = line.slice(5).trim();
|
|
42
|
+
else if (line.startsWith('branch ')) cur.branch = line.slice(7).trim().replace(/^refs\/heads\//, '');
|
|
43
|
+
else if (line === 'bare') cur.bare = true;
|
|
44
|
+
}
|
|
45
|
+
const used = new Set();
|
|
46
|
+
return list.filter((w) => !w.bare).map((w, i) => {
|
|
47
|
+
let id = i === 0 ? 'main' : path.basename(w.path).replace(/[^A-Za-z0-9._-]/g, '-').slice(0, 80) || 'wt' + i;
|
|
48
|
+
while (used.has(id)) id += '-' + i;
|
|
49
|
+
used.add(id);
|
|
50
|
+
return { id, name: i === 0 ? (w.branch || 'main') : (w.branch || path.basename(w.path)), path: w.path, branch: w.branch, head: w.head, main: i === 0 };
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The kind of a file, from its path alone. null: not something Search lists. Pure. */
|
|
55
|
+
function kindOf(rel) {
|
|
56
|
+
const p = String(rel || '').replace(/\\/g, '/');
|
|
57
|
+
if (!p || SKIP.test(p) || BINARY.test(p)) return null;
|
|
58
|
+
const base = p.split('/').pop();
|
|
59
|
+
if (/^planning\/initiatives\/[^/]+\.md$/.test(p)) return 'initiative';
|
|
60
|
+
if (SLIDES.test(p) || /(^|[-_.])(deck|slides)([-_.]|$)/i.test(base)) return 'slides';
|
|
61
|
+
if (/(^|\/)reports\//.test(p) && /\.(md|html?|pdf)$/i.test(p)) return 'report';
|
|
62
|
+
if (/\.(md|mdx|txt|docx?)$/i.test(p)) return 'document';
|
|
63
|
+
if (DESIGN.test(p)) return 'artifact';
|
|
64
|
+
if (CODE.test(p)) return 'file';
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
/** The group a kind is counted in: a code file is counted with the artifacts (EvSearch "Artifacts and designs"). */
|
|
68
|
+
const groupOf = (kind) => (kind === 'file' ? 'artifact' : kind);
|
|
69
|
+
|
|
70
|
+
/** A document's title: its frontmatter title, else its first "# " heading, else its file name without the extension. Pure. */
|
|
71
|
+
function titleOf(text, rel) {
|
|
72
|
+
const t = String(text || '');
|
|
73
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(t);
|
|
74
|
+
if (fm) { const m = /^title:\s*["']?(.+?)["']?\s*$/m.exec(fm[1]); if (m && m[1].trim()) return m[1].trim().slice(0, 160); }
|
|
75
|
+
const h = /^#\s+(.+)$/m.exec(t);
|
|
76
|
+
if (h) return h[1].trim().slice(0, 160);
|
|
77
|
+
const base = String(rel || '').split('/').pop() || '';
|
|
78
|
+
return base.replace(/\.[^.]+$/, '') || base;
|
|
79
|
+
}
|
|
80
|
+
const fmField = (text, key) => { const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(String(text || '')); if (!fm) return ''; const m = new RegExp('^' + key + ':\\s*["\']?(.+?)["\']?\\s*$', 'm').exec(fm[1]); return m ? m[1].trim().slice(0, 80) : ''; };
|
|
81
|
+
|
|
82
|
+
/** The files of one worktree that Search reads. Main: every file git knows. Another: the files that differ from main's HEAD. */
|
|
83
|
+
function filesOf(wt, mainHead) {
|
|
84
|
+
const lines = (s) => s.split('\n').map((x) => x.trim()).filter(Boolean);
|
|
85
|
+
if (wt.main) return lines(git(wt.path, ['ls-files', '-co', '--exclude-standard'])).slice(0, MAX_FILES);
|
|
86
|
+
// since the branch left main (its merge base), so a file main changed later is not shown as this worktree's draft
|
|
87
|
+
let base = '';
|
|
88
|
+
if (mainHead) { try { base = git(wt.path, ['merge-base', 'HEAD', mainHead]).trim(); } catch { base = mainHead; } }
|
|
89
|
+
const changed = base ? lines(git(wt.path, ['diff', '--name-only', '--diff-filter=ACMR', base])) : [];
|
|
90
|
+
const fresh = lines(git(wt.path, ['ls-files', '-o', '--exclude-standard']));
|
|
91
|
+
return [...new Set(changed.concat(fresh))].slice(0, MAX_FILES);
|
|
92
|
+
}
|
|
93
|
+
/** The files whose text holds q (case-insensitive, fixed string), among `among`. */
|
|
94
|
+
function textHits(wt, q, among) {
|
|
95
|
+
if (!among.length) return new Set();
|
|
96
|
+
const args = ['grep', '-I', '-l', '-i', '-F', '--untracked', '-e', q, '--'];
|
|
97
|
+
const out = new Set();
|
|
98
|
+
for (let i = 0; i < among.length; i += 400) { // a long list goes in parts, so the command line stays short
|
|
99
|
+
try { for (const l of git(wt.path, args.concat(among.slice(i, i + 400)), { timeout: 10000 }).split('\n')) if (l.trim()) out.add(l.trim()); }
|
|
100
|
+
catch (e) { if (!(e && e.status === 1)) throw e; } // 1: no match
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
/** The first line of text that holds q, shortened around it. */
|
|
105
|
+
function lineOf(text, q) {
|
|
106
|
+
const low = q.toLowerCase();
|
|
107
|
+
const l = String(text || '').split('\n').find((x) => x.toLowerCase().includes(low));
|
|
108
|
+
if (!l) return '';
|
|
109
|
+
const s = l.replace(/^[#>*\-\s]+/, '').trim(), at = s.toLowerCase().indexOf(low);
|
|
110
|
+
return (at > 60 ? '…' + s.slice(at - 40) : s).slice(0, 120);
|
|
111
|
+
}
|
|
112
|
+
const readText = (abs, max = 256 * 1024) => { try { const st = fs.statSync(abs); if (!st.isFile() || st.size > max) return { text: '', mtime: st.mtimeMs }; return { text: fs.readFileSync(abs, 'utf8'), mtime: st.mtimeMs }; } catch { return { text: '', mtime: 0 }; } };
|
|
113
|
+
|
|
114
|
+
/** Search one query. only: worktree ids to search ([] or null: all). notes: lib/notes.js list rows, for meetings. */
|
|
115
|
+
function search({ root, q, only = null, notes = [], now = Date.now() } = {}) {
|
|
116
|
+
const query = String(q || '').trim().slice(0, 120);
|
|
117
|
+
const all = worktrees(root);
|
|
118
|
+
const pick = Array.isArray(only) && only.length ? all.filter((w) => w.main || only.includes(w.id)) : all;
|
|
119
|
+
const counts = Object.fromEntries(KINDS.map((k) => [k, 0]));
|
|
120
|
+
const shownWt = all.map((w) => ({ id: w.id, name: w.name, branch: w.branch, main: w.main, on: pick.includes(w) }));
|
|
121
|
+
if (query.length < 2) return { ok: true, q: query, worktrees: shownWt, counts, results: [], more: 0 };
|
|
122
|
+
const mainHead = (all[0] && all[0].head) || '';
|
|
123
|
+
const low = query.toLowerCase();
|
|
124
|
+
const results = [];
|
|
125
|
+
const errors = [];
|
|
126
|
+
const day = new Date(now).toDateString();
|
|
127
|
+
for (const wt of pick) {
|
|
128
|
+
let files;
|
|
129
|
+
try { files = filesOf(wt, mainHead); } catch (e) { errors.push({ wt: wt.id, error: 'could not be read' }); const s = shownWt.find((x) => x.id === wt.id); if (s) s.error = 'could not be read'; continue; }
|
|
130
|
+
const kinds = new Map();
|
|
131
|
+
for (const f of files) { const k = kindOf(f); if (k) kinds.set(f, k); }
|
|
132
|
+
const byName = [...kinds.keys()].filter((f) => f.toLowerCase().includes(low));
|
|
133
|
+
let byText = new Set();
|
|
134
|
+
try { byText = textHits(wt, query, [...kinds.keys()].filter((f) => /\.(md|mdx|txt|html?)$/i.test(f))); } catch { byText = new Set(); }
|
|
135
|
+
for (const f of new Set(byName.concat([...byText]))) {
|
|
136
|
+
const kind = kinds.get(f); if (!kind) continue;
|
|
137
|
+
const abs = path.join(wt.path, f);
|
|
138
|
+
const { text, mtime } = /\.(md|mdx|txt|html?)$/i.test(f) ? readText(abs) : { text: '', mtime: (() => { try { return fs.statSync(abs).mtimeMs; } catch { return 0; } })() };
|
|
139
|
+
const title = /\.(md|mdx|txt)$/i.test(f) ? titleOf(text, f) : f.split('/').pop();
|
|
140
|
+
const named = f.toLowerCase().includes(low) || title.toLowerCase().includes(low);
|
|
141
|
+
const r = { kind, group: groupOf(kind), title, path: f, dir: path.posix.dirname(f), wt: wt.id, branch: wt.branch || '', main: wt.main, why: named ? 'name' : 'text' };
|
|
142
|
+
if (!named) r.line = lineOf(text, query);
|
|
143
|
+
if (kind === 'initiative') { r.id = path.posix.basename(f, '.md'); r.lane = fmField(text, 'lane'); }
|
|
144
|
+
if (!wt.main) r.draft = true;
|
|
145
|
+
if (mtime && new Date(mtime).toDateString() === day) r.today = true;
|
|
146
|
+
results.push(r);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
for (const n of notes || []) {
|
|
150
|
+
const t = String((n && n.title) || '');
|
|
151
|
+
if (!n || !n.id || !t.toLowerCase().includes(low)) continue;
|
|
152
|
+
results.push({ kind: 'meeting', group: 'meeting', title: t, id: n.id, at: (n.meeting && n.meeting.start) || n.created_at || null, summary: !!n.summary, private: !!n.private, why: 'name' });
|
|
153
|
+
}
|
|
154
|
+
// the order: a name match before a text match, main before a worktree, then the shorter path (the nearer file)
|
|
155
|
+
results.sort((a, b) => (a.why === b.why ? 0 : a.why === 'name' ? -1 : 1) || (a.main === b.main ? 0 : a.main === false ? 1 : -1) || String(a.path || '').length - String(b.path || '').length);
|
|
156
|
+
const shown = [];
|
|
157
|
+
let more = 0;
|
|
158
|
+
for (const r of results) { counts[r.group] = (counts[r.group] || 0) + 1; if (shown.filter((x) => x.group === r.group).length < MAX_PER_KIND) shown.push(r); else more++; }
|
|
159
|
+
return { ok: true, q: query, worktrees: shownWt, counts, results: shown, more, errors };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** One file of a listed worktree, for the Viewer. The path must be a relative path inside the worktree; nothing outside it is read. */
|
|
163
|
+
function readFile({ root, wt, path: rel } = {}) {
|
|
164
|
+
const w = worktrees(root).find((x) => x.id === (wt || 'main'));
|
|
165
|
+
if (!w) return { ok: false, status: 404, error: 'no such worktree' };
|
|
166
|
+
const p = String(rel || '').replace(/\\/g, '/');
|
|
167
|
+
if (!p || p.startsWith('/') || p.split('/').includes('..') || SKIP.test(p)) return { ok: false, status: 400, error: 'path must be a relative path inside the worktree' };
|
|
168
|
+
const abs = path.resolve(w.path, p);
|
|
169
|
+
if (!abs.startsWith(path.resolve(w.path) + path.sep)) return { ok: false, status: 400, error: 'path must be a relative path inside the worktree' };
|
|
170
|
+
let st; try { st = fs.statSync(abs); } catch { return { ok: false, status: 404, error: 'The file moved or was renamed after it was found.' }; }
|
|
171
|
+
if (!st.isFile()) return { ok: false, status: 404, error: 'not a file' };
|
|
172
|
+
if (st.size > 1024 * 1024 || BINARY.test(p)) return { ok: false, status: 413, error: 'This file is too large or not text, so it is not shown here.' };
|
|
173
|
+
return { ok: true, wt: w.id, branch: w.branch, main: w.main, path: p, text: fs.readFileSync(abs, 'utf8'), mtime: new Date(st.mtimeMs).toISOString() };
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
module.exports = { KINDS, worktrees, kindOf, groupOf, titleOf, lineOf, search, readFile };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* transcript-steps.js — what Home's chat draws while an agent works, read from the session's own transcript
|
|
3
|
+
* (initiative premium-agreed-design, Home: the agent step checklist, the run strip and the permission card's before → after).
|
|
4
|
+
*
|
|
5
|
+
* readSteps(file, clean, root) → { steps: [{ text, state: done|now|next }] | null, stepsAt, change: { system, what, from, to, tool } | null }
|
|
6
|
+
*
|
|
7
|
+
* steps the newest TodoWrite list of the session (Claude Code's own plan of its turn): completed → done, in_progress → now,
|
|
8
|
+
* pending → next. null when the session never wrote one: the chat then draws no checklist, never an invented one.
|
|
9
|
+
* A step also carries what the transcript holds about it, and nothing more: a done step that was seen in progress has
|
|
10
|
+
* `sub` ("3 tool calls · 9s", its calls and the time from in progress to completed), and the step in progress has `call`, its
|
|
11
|
+
* newest tool call ("jira.search project = PAY"). Neither is set when the transcript does not show it.
|
|
12
|
+
* change the input of the newest tool call that has no result yet, as a change the PM can read before Allow: the system
|
|
13
|
+
* (File, Jira, Confluence, Slack, Terminal, or the tool's server), the item, and the value before and after where the
|
|
14
|
+
* input holds both (Edit: the old and the new text; a Jira edit: the field's new value). null when no call is open.
|
|
15
|
+
* Only the named fields of an input are read, every string goes through `clean` (server.js scrub, D08), and each is cut short. */
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const MAX_BYTES = 4 * 1024 * 1024;
|
|
20
|
+
const cut = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1) + '…' : t; };
|
|
21
|
+
|
|
22
|
+
function tail(file) {
|
|
23
|
+
const st = fs.statSync(file);
|
|
24
|
+
const start = Math.max(0, st.size - MAX_BYTES);
|
|
25
|
+
const fd = fs.openSync(file, 'r');
|
|
26
|
+
try {
|
|
27
|
+
const buf = Buffer.allocUnsafe(st.size - start);
|
|
28
|
+
fs.readSync(fd, buf, 0, buf.length, start);
|
|
29
|
+
let raw = buf.toString('utf8');
|
|
30
|
+
if (start > 0) raw = raw.slice(raw.indexOf('\n') + 1);
|
|
31
|
+
return raw;
|
|
32
|
+
} finally { fs.closeSync(fd); }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** One open call's input as a change. Pure. */
|
|
36
|
+
function changeOf(name, input, clean = (x) => x, root = null) {
|
|
37
|
+
const i = input && typeof input === 'object' ? input : {};
|
|
38
|
+
const n = String(name || '');
|
|
39
|
+
const rel = (p) => { const s = String(p || ''); const r = root && path.isAbsolute(s) ? path.relative(root, s) : ''; return r && !r.startsWith('..') ? r : s; };
|
|
40
|
+
const out = (system, what, from, to) => ({ system, what: clean(cut(what, 160)), from: from ? clean(cut(from, 120)) : '', to: to ? clean(cut(to, 120)) : '', tool: clean(cut(n, 80)) });
|
|
41
|
+
if (n === 'Edit' || n === 'MultiEdit') {
|
|
42
|
+
const e = n === 'MultiEdit' && Array.isArray(i.edits) && i.edits[0] ? i.edits[0] : i;
|
|
43
|
+
return out('File', rel(i.file_path), String(e.old_string || '').split('\n')[0], String(e.new_string || '').split('\n')[0]);
|
|
44
|
+
}
|
|
45
|
+
if (n === 'Write') return out('File', rel(i.file_path), '', 'New content · ' + String(i.content || '').split('\n').length + ' lines');
|
|
46
|
+
if (n === 'Bash') return out('Terminal', String(i.command || '').split('\n')[0], '', '');
|
|
47
|
+
const m = /^mcp__(.+?)__(.+)$/.exec(n);
|
|
48
|
+
if (m) {
|
|
49
|
+
const server = m[1].replace(/_/g, ' '), verb = m[2];
|
|
50
|
+
const key = i.issueIdOrKey || i.issueKey || i.issue_key || i.pageId || i.channel_id || i.channel || '';
|
|
51
|
+
if (/jira/i.test(verb) || /atlassian/i.test(server) && key && /^[A-Z][A-Z0-9]+-\d+$/.test(String(key))) {
|
|
52
|
+
if (/transition/i.test(verb)) return out('Jira', key, '', 'Status · ' + ((i.transition && (i.transition.name || i.transition.id)) || i.transitionId || 'a new status'));
|
|
53
|
+
const f = i.fields && typeof i.fields === 'object' ? i.fields : {};
|
|
54
|
+
const k0 = Object.keys(f)[0];
|
|
55
|
+
const v0 = k0 == null ? '' : typeof f[k0] === 'object' ? (f[k0] && (f[k0].name || f[k0].value || f[k0].id)) || JSON.stringify(f[k0]) : f[k0];
|
|
56
|
+
return out('Jira', (key ? key + ' · ' : '') + (i.summary || (k0 ? k0 : verb)), '', v0 ? String(v0) : '');
|
|
57
|
+
}
|
|
58
|
+
if (/confluence/i.test(verb)) return out('Confluence', i.title || key || verb, '', '');
|
|
59
|
+
if (/slack/i.test(server) || /slack/i.test(verb)) return out('Slack', key ? '#' + key : verb, '', cut(i.text || i.message || '', 120));
|
|
60
|
+
return out(server.charAt(0).toUpperCase() + server.slice(1), key || verb, '', '');
|
|
61
|
+
}
|
|
62
|
+
return out(n || 'Tool', i.file_path ? rel(i.file_path) : i.path ? rel(i.path) : i.url || i.pattern || '', '', '');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A call as one short line: the tool ("jira.search" for an MCP tool, else its name) and its main input. */
|
|
66
|
+
function callLine(name, input, clean = (x) => x, root = null) {
|
|
67
|
+
const i = input && typeof input === 'object' ? input : {};
|
|
68
|
+
const n = String(name || '');
|
|
69
|
+
const m = /^mcp__(.+?)__(.+)$/.exec(n);
|
|
70
|
+
const tool = m ? m[1].toLowerCase().replace(/[^a-z0-9]+/g, '') + '.' + m[2].replace(/^(jira|confluence|slack)_?/i, '').replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase().split('_')[0] : n;
|
|
71
|
+
const rel = (p) => { const x = String(p || ''); const r = root && path.isAbsolute(x) ? path.relative(root, x) : ''; return r && !r.startsWith('..') ? r : x; };
|
|
72
|
+
const arg = i.command ? String(i.command).split('\n')[0] : i.file_path ? rel(i.file_path) : i.path ? rel(i.path) : i.jql || i.query || i.cql || i.pattern || i.url || i.issueIdOrKey || i.issueKey || i.pageId || '';
|
|
73
|
+
return clean(cut(tool + (arg ? ' ' + arg : ''), 90));
|
|
74
|
+
}
|
|
75
|
+
const secs = (a, b) => { const t = (Date.parse(b) - Date.parse(a)) / 1000; return Number.isFinite(t) && t >= 0 ? (t < 60 ? Math.round(t) + 's' : t < 3600 ? Math.round(t / 60) + ' min' : Math.floor(t / 3600) + ' h ' + Math.round((t % 3600) / 60) + ' min') : ''; };
|
|
76
|
+
|
|
77
|
+
/** The steps and the open change from a transcript's text. Pure over the text. */
|
|
78
|
+
function stepsOf(raw, clean = (x) => x, root = null) {
|
|
79
|
+
let todos = null, todosAt = null;
|
|
80
|
+
const open = new Map();
|
|
81
|
+
const seen = new Map(); // a step's content → { start, end, calls, last }: what the transcript shows of it
|
|
82
|
+
let doing = null; // the content of the step in progress now
|
|
83
|
+
for (const line of String(raw || '').split('\n')) {
|
|
84
|
+
if (!line) continue;
|
|
85
|
+
let r; try { r = JSON.parse(line); } catch { continue; }
|
|
86
|
+
if (r.isSidechain) continue;
|
|
87
|
+
const content = r.message && Array.isArray(r.message.content) ? r.message.content : [];
|
|
88
|
+
if (r.type === 'user') { for (const c of content) if (c && c.type === 'tool_result' && c.tool_use_id) open.delete(c.tool_use_id); continue; }
|
|
89
|
+
if (r.type !== 'assistant') continue;
|
|
90
|
+
for (const c of content) {
|
|
91
|
+
if (!c || c.type !== 'tool_use') continue;
|
|
92
|
+
if (c.name === 'TodoWrite' && c.input && Array.isArray(c.input.todos)) {
|
|
93
|
+
todos = c.input.todos; todosAt = r.timestamp || null; doing = null;
|
|
94
|
+
for (const t of todos) {
|
|
95
|
+
if (!t || !t.content) continue;
|
|
96
|
+
const k = String(t.content), st = seen.get(k) || {};
|
|
97
|
+
if (t.status === 'in_progress') { if (!st.start) st.start = r.timestamp || null; doing = k; }
|
|
98
|
+
if (t.status === 'completed' && st.start && !st.end) st.end = r.timestamp || null;
|
|
99
|
+
seen.set(k, st);
|
|
100
|
+
}
|
|
101
|
+
} else if (doing && c.name !== 'AskUserQuestion') { const st = seen.get(doing); st.calls = (st.calls || 0) + 1; st.last = { name: c.name, input: c.input }; }
|
|
102
|
+
if (c.id) open.set(c.id, { name: c.name, input: c.input });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const steps = todos ? todos.slice(0, 12).map((t) => {
|
|
106
|
+
const s = { text: clean(cut(t && (t.status === 'in_progress' && t.activeForm ? t.activeForm : t.content), 140)),
|
|
107
|
+
state: t && t.status === 'completed' ? 'done' : t && t.status === 'in_progress' ? 'now' : 'next' };
|
|
108
|
+
const st = t && t.content ? seen.get(String(t.content)) : null;
|
|
109
|
+
if (st && s.state === 'done' && st.start && st.end) s.sub = [st.calls ? st.calls + (st.calls === 1 ? ' tool call' : ' tool calls') : '', secs(st.start, st.end)].filter(Boolean).join(' · ');
|
|
110
|
+
if (st && s.state === 'now' && st.last) s.call = callLine(st.last.name, st.last.input, clean, root);
|
|
111
|
+
if (!s.sub) delete s.sub;
|
|
112
|
+
return s;
|
|
113
|
+
}).filter((s) => s.text) : null;
|
|
114
|
+
let last = null; for (const [, v] of open) last = v;
|
|
115
|
+
const change = last && last.name !== 'TodoWrite' && last.name !== 'AskUserQuestion' ? changeOf(last.name, last.input, clean, root) : null;
|
|
116
|
+
return { steps: steps && steps.length ? steps : null, stepsAt: todosAt, change };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function readSteps(file, clean = (x) => x, root = null) {
|
|
120
|
+
try { return stepsOf(tail(file), clean, root); } catch { return { steps: null, stepsAt: null, change: null }; }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = { readSteps, stepsOf, changeOf };
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* viewer-meeting.js — the data the Viewer's meeting needs that no other record held (initiative premium-agreed-design, area viewer).
|
|
3
|
+
* The Agreed design (Main.dc.html, AgPrep / AgMeetLive / AgMeeting) draws four things PMOS kept nowhere. Each is kept here, file mode,
|
|
4
|
+
* in the per-user runtime folder beside the notes (lib/notes.js keeps its notes there too):
|
|
5
|
+
*
|
|
6
|
+
* AGENDA MINUTES "Agenda · 3 topics · 30 min" with the minutes of each topic.
|
|
7
|
+
* agendaOf(dir, { key, topics, length_min }) → { topics: [{ n, text, min, set }], total }
|
|
8
|
+
* A topic's minutes are, in order: what the PM set for it (setAgenda), the minutes its own text names ("5 min: what changed"),
|
|
9
|
+
* else an even share of what the meeting has left, rounded to 5 minutes (set: false says it is that share).
|
|
10
|
+
* setAgenda(dir, { key, topic, min }) → { ok } one line of <runtime>/viewer-agenda.jsonl; min 0 forgets it
|
|
11
|
+
* The key is the meeting's series when it has one, else its calendar event id, else its title (keyOf).
|
|
12
|
+
*
|
|
13
|
+
* WHAT RECORDING LISTENS TO "Listening to Zoom app · microphone and meeting · Change" and "4 screen shots · Pause shots".
|
|
14
|
+
* captureOf(dir, id) → { app, shots } setCapture(dir, { id, app?, shots? }) → { ok, capture } shotsPaused(dir, id) → boolean
|
|
15
|
+
* One line of <runtime>/viewer-capture.jsonl per change. While shots are paused, POST /api/notes/screen keeps no frame for the note
|
|
16
|
+
* (lib/routes-notes.js asks shotsPaused). app is one of listen-sources.js APPS (zoom, meet, other).
|
|
17
|
+
*
|
|
18
|
+
* A NEXT STEP THAT BECOMES A WORK-ITEM "Becomes V.4" (PM 2026-10-22: a ticket Drafted in PMOS, shown on the Board's Drafted in PMOS,
|
|
19
|
+
* never pushed to Jira without the Commit gate).
|
|
20
|
+
* stepKey(text) → 8 hex the step's key: its words, folded
|
|
21
|
+
* stepLinks(root, initiative, noteId) → { [stepKey]: ticketId } derived from the ticket draft: a ticket made from a step names the note
|
|
22
|
+
* and the step in its Refs ("- Meeting note: <id> · step <key>"). Nothing else is stored.
|
|
23
|
+
* makeWorkItem(root, initiative, { note, step }) → { ok, ticket, created } appends one ticket to <state>/tracker/jira/<initiative>-tickets.md
|
|
24
|
+
* (lib/jira-tickets.js's draft file) with no Jira key and no approval. A second press on the same step
|
|
25
|
+
* answers the ticket it already made.
|
|
26
|
+
* nextTicketId(ids, title) → 'V.4' the next id in the draft's own numbering, or the initiative's initial and 1.
|
|
27
|
+
*
|
|
28
|
+
* Nothing here sends anything, and nothing here writes the calendar. */
|
|
29
|
+
const fs = require('fs');
|
|
30
|
+
const path = require('path');
|
|
31
|
+
const crypto = require('crypto');
|
|
32
|
+
|
|
33
|
+
const AGENDA = 'viewer-agenda.jsonl';
|
|
34
|
+
const CAPTURE = 'viewer-capture.jsonl';
|
|
35
|
+
const APPS = ['zoom', 'meet', 'other'];
|
|
36
|
+
const NOTE_ID = /^[A-Za-z0-9_-]{1,80}$/;
|
|
37
|
+
const str = (v, n) => String(v == null ? '' : v).replace(/\s+/g, ' ').trim().slice(0, n || 300);
|
|
38
|
+
const norm = (s) => str(s, 400).toLowerCase().replace(/[^a-z0-9 ]+/g, ' ').replace(/\s+/g, ' ').trim();
|
|
39
|
+
|
|
40
|
+
function readLines(file) {
|
|
41
|
+
let text = '';
|
|
42
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const l of text.split('\n')) { if (!l.trim()) continue; try { const o = JSON.parse(l); if (o && typeof o === 'object') out.push(o); } catch { /* a torn line is skipped */ } }
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
function append(file, line) {
|
|
48
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
49
|
+
fs.appendFileSync(file, JSON.stringify({ v: 1, ...line, at: new Date().toISOString() }) + '\n');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* ── agenda minutes ─────────────────────────────────────────────────────────────────────────────────────────── */
|
|
53
|
+
|
|
54
|
+
/** The key the minutes of a meeting are kept under: its series, else its event id, else its title. '' when none is given. */
|
|
55
|
+
function keyOf({ series, event, title } = {}) {
|
|
56
|
+
if (str(series, 200)) return 's:' + str(series, 200);
|
|
57
|
+
if (str(event, 120)) return 'e:' + str(event, 120);
|
|
58
|
+
if (norm(title)) return 't:' + norm(title).slice(0, 200);
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
/** "5 min: what changed", "What changed (5 min)", "What changed - 5m" → { text, min }; a text with no minutes → { text, min: null }. */
|
|
62
|
+
function parseTopic(raw) {
|
|
63
|
+
const t = str(raw, 300);
|
|
64
|
+
let m = /^(\d{1,3})\s*(?:min|mins|minutes|m)\b\s*[:·\-–—]?\s*(.+)$/i.exec(t);
|
|
65
|
+
if (m) return { text: m[2].trim(), min: +m[1] };
|
|
66
|
+
m = /^(.+?)\s*[(\[·\-–—,]\s*(\d{1,3})\s*(?:min|mins|minutes|m)\s*[)\]]?\s*$/i.exec(t);
|
|
67
|
+
if (m) return { text: m[1].trim(), min: +m[2] };
|
|
68
|
+
return { text: t, min: null };
|
|
69
|
+
}
|
|
70
|
+
/** What the PM set, per topic, for one key: { [norm(topic)]: min }. A later line wins; 0 forgets. */
|
|
71
|
+
function setMinutes(dir, key) {
|
|
72
|
+
const out = {};
|
|
73
|
+
for (const l of readLines(path.join(dir, AGENDA))) {
|
|
74
|
+
if (l.key !== key || !l.topic) continue;
|
|
75
|
+
if (l.min > 0) out[norm(l.topic)] = l.min; else delete out[norm(l.topic)];
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
const round5 = (n) => Math.max(5, Math.round(n / 5) * 5);
|
|
80
|
+
/** The agenda with each topic's minutes. topics are strings (or { text }); length_min is the meeting's length, when known. */
|
|
81
|
+
function agendaOf(dir, { key, topics, length_min } = {}) {
|
|
82
|
+
const set = dir && key ? setMinutes(dir, key) : {};
|
|
83
|
+
const list = (Array.isArray(topics) ? topics : []).map((x) => (x && typeof x === 'object' ? x.text : x)).filter((x) => str(x)).slice(0, 20).map(parseTopic);
|
|
84
|
+
const rows = list.map((t, i) => {
|
|
85
|
+
const pm = set[norm(t.text)];
|
|
86
|
+
return { n: i + 1, text: t.text, min: pm || t.min || null, set: !!(pm || t.min) };
|
|
87
|
+
});
|
|
88
|
+
const known = rows.filter((r) => r.min).reduce((a, r) => a + r.min, 0), open = rows.filter((r) => !r.min);
|
|
89
|
+
const len = Number(length_min) > 0 ? Number(length_min) : 0;
|
|
90
|
+
if (open.length && len > known) { const share = round5((len - known) / open.length); open.forEach((r) => { r.min = share; }); }
|
|
91
|
+
return { topics: rows, total: rows.reduce((a, r) => a + (r.min || 0), 0) };
|
|
92
|
+
}
|
|
93
|
+
function setAgenda(dir, { key, topic, min } = {}) {
|
|
94
|
+
if (!dir) return { ok: false, status: 409, error: 'this server has no runtime folder, so the minutes cannot be kept' };
|
|
95
|
+
if (!str(key, 260)) return { ok: false, status: 400, error: 'key is required: the meeting\'s series, event or title' };
|
|
96
|
+
if (!str(topic, 300)) return { ok: false, status: 400, error: 'topic is required' };
|
|
97
|
+
const m = Number(min);
|
|
98
|
+
if (!Number.isInteger(m) || m < 0 || m > 600) return { ok: false, status: 400, error: 'min is a whole number of minutes, 0 to 600' };
|
|
99
|
+
append(path.join(dir, AGENDA), { key: str(key, 260), topic: str(topic, 300), min: m });
|
|
100
|
+
return { ok: true };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* ── what recording listens to ──────────────────────────────────────────────────────────────────────────────── */
|
|
104
|
+
|
|
105
|
+
function captureOf(dir, id) {
|
|
106
|
+
const out = { app: null, shots: 'on' };
|
|
107
|
+
if (!dir || !NOTE_ID.test(String(id || ''))) return out;
|
|
108
|
+
for (const l of readLines(path.join(dir, CAPTURE))) {
|
|
109
|
+
if (l.id !== id) continue;
|
|
110
|
+
if (APPS.includes(l.app)) out.app = l.app;
|
|
111
|
+
if (l.shots === 'on' || l.shots === 'paused') out.shots = l.shots;
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
const shotsPaused = (dir, id) => captureOf(dir, id).shots === 'paused';
|
|
116
|
+
function setCapture(dir, { id, app, shots } = {}) {
|
|
117
|
+
if (!dir) return { ok: false, status: 409, error: 'this server has no runtime folder' };
|
|
118
|
+
if (!NOTE_ID.test(String(id || ''))) return { ok: false, status: 400, error: 'id is the note\'s id' };
|
|
119
|
+
const line = { id };
|
|
120
|
+
if (app !== undefined) { if (!APPS.includes(app)) return { ok: false, status: 400, error: 'app is one of ' + APPS.join(', ') }; line.app = app; }
|
|
121
|
+
if (shots !== undefined) { if (shots !== 'on' && shots !== 'paused') return { ok: false, status: 400, error: 'shots is on or paused' }; line.shots = shots; }
|
|
122
|
+
if (line.app === undefined && line.shots === undefined) return { ok: false, status: 400, error: 'nothing to change: send app or shots' };
|
|
123
|
+
append(path.join(dir, CAPTURE), line);
|
|
124
|
+
return { ok: true, capture: captureOf(dir, id) };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* ── a next step that becomes a work-item ───────────────────────────────────────────────────────────────────── */
|
|
128
|
+
|
|
129
|
+
const stepKey = (text) => crypto.createHash('sha256').update(norm(text)).digest('hex').slice(0, 8);
|
|
130
|
+
const REF_RE = /^- Meeting note: ([A-Za-z0-9_-]{1,80}) · step ([0-9a-f]{8})\b/m;
|
|
131
|
+
const jt = () => require('./jira-tickets.js');
|
|
132
|
+
|
|
133
|
+
/** { [stepKey]: ticketId } for the tickets of `initiative` made from a step of note `noteId`. */
|
|
134
|
+
function stepLinks(root, initiative, noteId) {
|
|
135
|
+
const out = {};
|
|
136
|
+
let d = null;
|
|
137
|
+
try { d = jt().readDraft(root, initiative); } catch { d = null; }
|
|
138
|
+
for (const t of (d && d.tickets) || []) {
|
|
139
|
+
const m = REF_RE.exec(String((t.sections && t.sections.refs) || ''));
|
|
140
|
+
if (m && m[1] === noteId && !out[m[2]]) out[m[2]] = t.id;
|
|
141
|
+
}
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/** The next ticket id: the draft's most used "<prefix><n>" plus one, keeping its padding; with no ticket, the initiative's initial, a dot and 1. */
|
|
145
|
+
function nextTicketId(ids, title) {
|
|
146
|
+
const seen = new Map();
|
|
147
|
+
for (const id of ids || []) {
|
|
148
|
+
const m = /^(.*?)(\d+)$/.exec(String(id || ''));
|
|
149
|
+
if (!m) continue;
|
|
150
|
+
const k = m[1], v = seen.get(k) || { n: 0, max: 0, pad: m[2].length };
|
|
151
|
+
v.n++; v.max = Math.max(v.max, +m[2]); v.pad = Math.max(v.pad, m[2].length); seen.set(k, v);
|
|
152
|
+
}
|
|
153
|
+
if (seen.size) {
|
|
154
|
+
const [pre, v] = [...seen.entries()].sort((a, b) => b[1].n - a[1].n)[0];
|
|
155
|
+
return pre + String(v.max + 1).padStart(v.pad, '0');
|
|
156
|
+
}
|
|
157
|
+
const init = (String(title || '').match(/[A-Za-z]/) || ['T'])[0].toUpperCase();
|
|
158
|
+
return init + '.1';
|
|
159
|
+
}
|
|
160
|
+
const oneLine = (s) => str(s, 250);
|
|
161
|
+
/** The ticket block, in the draft file's own form (lib/jira-tickets.js renderDraft): fields, then the seven sections, "—" for an empty one. */
|
|
162
|
+
function ticketBlock(t) {
|
|
163
|
+
const lines = [`## ${t.id} · ${oneLine(t.summary)}`, `- type: ${t.type}`, `- priority: ${t.priority}`, `- drafted: ${t.drafted}`, ''];
|
|
164
|
+
for (const [k, head] of jt().SECTIONS) lines.push(`### ${head}`, '', String(t.sections[k] || '').trim() || '—', '');
|
|
165
|
+
return lines.join('\n');
|
|
166
|
+
}
|
|
167
|
+
function makeWorkItem(root, initiative, { note, step } = {}) {
|
|
168
|
+
const T = jt();
|
|
169
|
+
if (!root) return { ok: false, status: 409, error: 'the note\'s repository is not registered here' };
|
|
170
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/.test(String(initiative || ''))) return { ok: false, status: 400, error: 'the note is not linked to an initiative' };
|
|
171
|
+
if (!note || !NOTE_ID.test(String(note.id || ''))) return { ok: false, status: 400, error: 'note is { id, title }' };
|
|
172
|
+
const text = oneLine(step && step.text);
|
|
173
|
+
if (!text) return { ok: false, status: 400, error: 'step.text is required' };
|
|
174
|
+
const rfm = T.recordFm(root, initiative);
|
|
175
|
+
if (!rfm) return { ok: false, status: 404, error: `no initiative ${initiative} in this repository` };
|
|
176
|
+
const key = stepKey(text);
|
|
177
|
+
const had = stepLinks(root, initiative, note.id)[key];
|
|
178
|
+
if (had) return { ok: true, ticket: had, created: false };
|
|
179
|
+
const d = T.readDraft(root, initiative);
|
|
180
|
+
const id = nextTicketId(d ? d.tickets.map((x) => x.id) : [], rfm.title || initiative);
|
|
181
|
+
const day = str(note.day, 40);
|
|
182
|
+
const who = [str(step.owner, 60) && 'Owner: ' + str(step.owner, 60), /^\d{4}-\d{2}-\d{2}$/.test(String(step.due || '')) && 'Due: ' + step.due].filter(Boolean).join(' · ');
|
|
183
|
+
const t = { id, summary: text, type: 'Task', priority: 'Medium', estimate: null, depends: [], sections: {} };
|
|
184
|
+
for (const [k] of T.SECTIONS) t.sections[k] = '';
|
|
185
|
+
t.sections.context = `A next step of the meeting "${str(note.title, 160) || 'Untitled note'}"${day ? ' (' + day + ')' : ''}.${who ? ' ' + who + '.' : ''}`;
|
|
186
|
+
t.sections.refs = `- Meeting note: ${note.id} · step ${key}`;
|
|
187
|
+
t.drafted = T.contentHash(t);
|
|
188
|
+
const file = T.draftPath(root, initiative);
|
|
189
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
190
|
+
let text0 = '';
|
|
191
|
+
try { text0 = fs.readFileSync(file, 'utf8'); } catch { text0 = ''; }
|
|
192
|
+
if (!text0) {
|
|
193
|
+
const ts = new Date().toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
194
|
+
text0 = ['---', 'type: Reference', `title: "Jira tickets: ${initiative}"`, `timestamp: ${ts}`, '---', '', `# Jira tickets: ${initiative}`, '',
|
|
195
|
+
'Drafted in PMOS. Read and edit them on the initiative\'s Jira tickets tab, or here. Check the ones that are ready and press Push: only checked tickets are sent.', '',
|
|
196
|
+
'PMOS owns the text of these tickets and Jira owns their status.', ''].join('\n');
|
|
197
|
+
}
|
|
198
|
+
const out = text0.replace(/\n*$/, '\n') + '\n' + ticketBlock(t);
|
|
199
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
200
|
+
fs.writeFileSync(tmp, out);
|
|
201
|
+
fs.renameSync(tmp, file);
|
|
202
|
+
return { ok: true, ticket: id, created: true, draft: T.draftRel(root, initiative) };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
module.exports = { AGENDA, CAPTURE, APPS, keyOf, parseTopic, agendaOf, setAgenda, captureOf, setCapture, shotsPaused, stepKey, stepLinks, nextTicketId, makeWorkItem };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* viewer-report.js — the three checks the Viewer's report panel shows before Issue (initiative premium-agreed-design, area viewer;
|
|
3
|
+
* ReportPanel.dc.html AgRptIssue: "All 3 sources reached · data from Oct 19", "5 slides, every section filled", "The 81% figure is 2 days old.
|
|
4
|
+
* Refresh it first?").
|
|
5
|
+
*
|
|
6
|
+
* issueChecks(markdown, { now, slot }) → [{ id, ok, text }] pure: the report's own text, read as it is
|
|
7
|
+
*
|
|
8
|
+
* sources The draft's "Sources reached and not reached" section (lib/report-draft.js writes it): every source reached, or the ones that
|
|
9
|
+
* were not, by name. The data date is the newest "as of" date the text names, else the cycle's date (slot).
|
|
10
|
+
* sections Each "## " section holds words. An empty one ("—", "none", or nothing) is named.
|
|
11
|
+
* figures The oldest figure that carries its date ("as of 2026-10-19", "Data: 19 Oct 2026"): its age in days. A figure is a number with a
|
|
12
|
+
* unit or a percent sign on the same line. With no dated figure the check passes and says so.
|
|
13
|
+
* A check that passes has ok: true; ok: false is a warning the PM reads before pressing Issue it. Nothing blocks the press. */
|
|
14
|
+
|
|
15
|
+
const MON = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
16
|
+
const MONN = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
17
|
+
const body = (t) => String(t || '').replace(/\r/g, '').replace(/^---\n[\s\S]*?\n---\n?/, '');
|
|
18
|
+
const DAY = 86400000;
|
|
19
|
+
/** "Oct 19", from a date in ms. */
|
|
20
|
+
const short = (ms) => { const d = new Date(ms); return MONN[d.getUTCMonth()] + ' ' + d.getUTCDate(); };
|
|
21
|
+
|
|
22
|
+
/** Every date a line names, in ms (UTC midnight): 2026-10-19, 19 Oct 2026, 19 October 2026, Oct 19 2026. */
|
|
23
|
+
function datesIn(line) {
|
|
24
|
+
const out = [];
|
|
25
|
+
for (const m of String(line).matchAll(/\b(\d{4})-(\d{2})-(\d{2})\b/g)) out.push(Date.UTC(+m[1], +m[2] - 1, +m[3]));
|
|
26
|
+
for (const m of String(line).matchAll(/\b(\d{1,2})\s+([A-Za-z]{3,9})\.?\s+(\d{4})\b/g)) { const i = MON.indexOf(m[2].slice(0, 3).toLowerCase()); if (i >= 0) out.push(Date.UTC(+m[3], i, +m[1])); }
|
|
27
|
+
for (const m of String(line).matchAll(/\b([A-Za-z]{3,9})\.?\s+(\d{1,2}),?\s+(\d{4})\b/g)) { const i = MON.indexOf(m[1].slice(0, 3).toLowerCase()); if (i >= 0) out.push(Date.UTC(+m[3], i, +m[2])); }
|
|
28
|
+
return out.filter(Number.isFinite);
|
|
29
|
+
}
|
|
30
|
+
/** The sections of the text: [{ h, lines }]. The text before the first "## " is not a section. */
|
|
31
|
+
function sectionsOf(text) {
|
|
32
|
+
const out = []; let cur = null;
|
|
33
|
+
for (const l of body(text).split('\n')) {
|
|
34
|
+
const h = /^##\s+(.*)$/.exec(l);
|
|
35
|
+
if (h) { cur = { h: h[1].trim(), lines: [] }; out.push(cur); continue; }
|
|
36
|
+
if (cur) cur.lines.push(l);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
const filled = (lines) => lines.some((l) => { const t = l.replace(/<!--.*?-->/g, '').replace(/^[\s>*\-–—|:]+$/, '').trim(); return t && !/^(none|n\/a|tbd|todo|—|-)\.?$/i.test(t.replace(/^[-*]\s+/, '')); });
|
|
41
|
+
|
|
42
|
+
function sourcesCheck(S, text, slot, now) {
|
|
43
|
+
const src = S.find((s) => /^sources\b/i.test(s.h));
|
|
44
|
+
const all = body(text).split('\n');
|
|
45
|
+
const asOf = all.filter((l) => /\bas of\b|\bdata\s*:/i.test(l)).flatMap(datesIn).filter((t) => t <= now + DAY);
|
|
46
|
+
const slotMs = /^\d{4}-\d{2}-\d{2}$/.test(String(slot || '')) ? Date.parse(slot + 'T00:00:00Z') : null;
|
|
47
|
+
const dataAt = asOf.length ? Math.max(...asOf) : slotMs;
|
|
48
|
+
const from = dataAt ? ' · data from ' + short(dataAt) : '';
|
|
49
|
+
if (!src) return { id: 'sources', ok: true, text: 'The report names no sources section' + from };
|
|
50
|
+
let part = '', reached = [], missed = [];
|
|
51
|
+
for (const l of src.lines) {
|
|
52
|
+
if (/^\*\*\s*reached\s*\*\*/i.test(l.trim())) { part = 'r'; continue; }
|
|
53
|
+
if (/^\*\*\s*not reached\s*\*\*/i.test(l.trim())) { part = 'n'; continue; }
|
|
54
|
+
const b = /^\s*[-*]\s+(.*)$/.exec(l); if (!b || /^none\.?$/i.test(b[1].trim())) continue;
|
|
55
|
+
if (part === 'n') missed.push(b[1].split(':')[0].trim()); else reached.push(b[1].trim());
|
|
56
|
+
}
|
|
57
|
+
const n = reached.length + missed.length;
|
|
58
|
+
if (!n) return { id: 'sources', ok: true, text: 'No sources are listed' + from };
|
|
59
|
+
if (!missed.length) return { id: 'sources', ok: true, text: (n === 1 ? 'The 1 source' : 'All ' + n + ' sources') + ' reached' + from };
|
|
60
|
+
return { id: 'sources', ok: false, text: missed.length + ' of ' + n + (n === 1 ? ' source' : ' sources') + ' not reached: ' + missed.slice(0, 3).join(', ') + from };
|
|
61
|
+
}
|
|
62
|
+
function sectionsCheck(S) {
|
|
63
|
+
if (!S.length) return { id: 'sections', ok: false, text: 'The report has no sections yet' };
|
|
64
|
+
const empty = S.filter((s) => !filled(s.lines)).map((s) => s.h);
|
|
65
|
+
const slides = S.length + 1; // a title slide, then one per section (premium-report-read.js slides)
|
|
66
|
+
if (!empty.length) return { id: 'sections', ok: true, text: slides + ' slides, every section filled' };
|
|
67
|
+
return { id: 'sections', ok: false, text: (empty.length === 1 ? '1 section is empty: ' : empty.length + ' sections are empty: ') + empty.slice(0, 3).join(', ') };
|
|
68
|
+
}
|
|
69
|
+
function figuresCheck(text, now) {
|
|
70
|
+
let oldest = null;
|
|
71
|
+
for (const l of body(text).split('\n')) {
|
|
72
|
+
if (!/\bas of\b|\bdata\s*:|\bmeasured\b/i.test(l)) continue;
|
|
73
|
+
const fig = /(\d+(?:[.,]\d+)?\s?%|\d+(?:[.,]\d+)?\s?(?:pp|ms|s|h|d|days|pts|points)\b)/i.exec(l.replace(/\b\d{4}-\d{2}-\d{2}\b/g, ' '));
|
|
74
|
+
const ds = datesIn(l).filter((t) => t <= now + DAY);
|
|
75
|
+
if (!fig || !ds.length) continue;
|
|
76
|
+
const at = Math.min(...ds);
|
|
77
|
+
if (!oldest || at < oldest.at) oldest = { at, fig: fig[1].replace(/\s+/g, '') };
|
|
78
|
+
}
|
|
79
|
+
if (!oldest) return { id: 'figures', ok: true, text: 'No figure carries an older date' };
|
|
80
|
+
const days = Math.floor((Date.UTC(new Date(now).getUTCFullYear(), new Date(now).getUTCMonth(), new Date(now).getUTCDate()) - oldest.at) / DAY);
|
|
81
|
+
if (days <= 1) return { id: 'figures', ok: true, text: 'The ' + oldest.fig + ' figure is from ' + (days <= 0 ? 'today' : 'yesterday') };
|
|
82
|
+
return { id: 'figures', ok: false, text: 'The ' + oldest.fig + ' figure is ' + days + ' days old. Refresh it first?' };
|
|
83
|
+
}
|
|
84
|
+
function issueChecks(markdown, { now = Date.now(), slot = '' } = {}) {
|
|
85
|
+
const S = sectionsOf(markdown);
|
|
86
|
+
return [sourcesCheck(S, markdown, slot, now), sectionsCheck(S), figuresCheck(markdown, now)];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = { issueChecks, sectionsOf, datesIn };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pmos-workspace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.399.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pmos-workspace",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.399.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/workspace/package.json
CHANGED