create-pmos 0.398.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 +13 -13
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +18 -14
- package/workspace/briefing-premium-board-test.js +80 -48
- package/workspace/briefing-premium-calendar-2-test.js +36 -36
- package/workspace/briefing-premium-calendar-3-test.js +39 -39
- package/workspace/briefing-premium-calendar-test.js +23 -24
- package/workspace/briefing-premium-doc-edit-test.js +6 -2
- package/workspace/briefing-premium-initiative-test.js +38 -16
- package/workspace/briefing-premium-insights-test.js +114 -37
- package/workspace/briefing-premium-metrics-test.js +6 -4
- package/workspace/briefing-premium-products-test.js +10 -7
- package/workspace/briefing-premium-sources-test.js +25 -22
- package/workspace/briefing-premium-test.js +46 -42
- package/workspace/briefing-premium-work-test.js +9 -9
- package/workspace/changelog.json +12 -0
- package/workspace/ev-everywhere-test.js +210 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +11 -6
- package/workspace/guide/home.md +39 -18
- package/workspace/guide/index.md +1 -1
- package/workspace/lib/board-grill.js +63 -0
- package/workspace/lib/board-premium.js +36 -5
- package/workspace/lib/initiative-layout.js +77 -0
- package/workspace/lib/insights-premium.js +3 -2
- package/workspace/lib/insights-records.js +21 -7
- 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 +8 -0
- package/workspace/lib/routes-board-docs.js +46 -0
- package/workspace/lib/routes-board-grill.js +90 -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 +4 -1
- package/workspace/lib/routes-insights-records.js +8 -4
- package/workspace/lib/routes-meeting-points.js +37 -0
- package/workspace/lib/routes-news.js +57 -0
- package/workspace/lib/routes-notes.js +2 -1
- package/workspace/lib/routes-report-confirm.js +31 -0
- package/workspace/lib/routes-search.js +38 -0
- package/workspace/lib/search-index.js +176 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +86 -50
- package/workspace/premium-briefing-depth-test.js +55 -54
- package/workspace/premium-chat-chart-tab-test.js +4 -2
- package/workspace/premium-chat-report-tab-test.js +16 -2
- package/workspace/premium-core-doc-issue-test.js +15 -13
- package/workspace/premium-phone-card-test.js +5 -3
- package/workspace/premium-report-read-test.js +55 -18
- package/workspace/premium-vw-backlog-test.js +2 -2
- package/workspace/premium-vw-cal-test.js +50 -35
- package/workspace/premium-vw-doc-test.js +9 -3
- package/workspace/premium-vw-item-test.js +1 -1
- package/workspace/premium-vw-jira-test.js +2 -2
- package/workspace/premium-vw-meet-test.js +37 -40
- package/workspace/premium-vw-notes-test.js +21 -19
- package/workspace/premium-vw-rec-test.js +11 -12
- package/workspace/premium-welcome-test.js +3 -3
- package/workspace/premium-work-depth-test.js +3 -3
- package/workspace/public/pm/bd-acts.js +303 -225
- 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 +49 -13
- package/workspace/public/pm/bd-views.js +169 -0
- package/workspace/public/pm/cozy-board.css +301 -0
- 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-insights.css +148 -10
- package/workspace/public/pm/cozy-nav.js +103 -39
- package/workspace/public/pm/cozy-news.js +140 -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.js +1 -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/home-adddoc.js +5 -5
- package/workspace/public/pm/home-app.js +329 -55
- package/workspace/public/pm/home-around.js +24 -126
- package/workspace/public/pm/home-chat.js +67 -14
- package/workspace/public/pm/home-data.js +6 -6
- package/workspace/public/pm/home-dictate.js +54 -0
- package/workspace/public/pm/home-draft.js +6 -6
- 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 +17 -134
- package/workspace/public/pm/home-phone-card.js +4 -4
- 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 +54 -26
- package/workspace/public/pm/premium-board.js +163 -39
- package/workspace/public/pm/premium-chart-tab.js +4 -5
- package/workspace/public/pm/premium-first.js +5 -7
- package/workspace/public/pm/premium-insights.js +499 -202
- 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-report-read.js +216 -52
- package/workspace/public/pm/premium-report-tab.js +44 -19
- package/workspace/public/pm/premium-shell.js +7 -7
- package/workspace/public/pm/premium-vw-cal.js +150 -60
- package/workspace/public/pm/premium-vw-mtg.js +488 -261
- package/workspace/public/pm/premium-vw-notes.js +61 -0
- package/workspace/public/pm/rp-parts.js +269 -0
- package/workspace/public/premium-board.html +4 -3
- package/workspace/public/premium-insights.html +10 -10
- package/workspace/public/premium.html +3 -1
- 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/test-lists/initiative-layout.json +9 -0
- package/workspace/test-lists/premium-uncovered-meetings.json +9 -0
- package/workspace/test-lists/premium-uncovered-reports.json +9 -0
- 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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* report-confirm.js — what the PM confirmed on a report's Brief tab (initiative premium-uncovered-features, workstream reports; canvas RpBrief
|
|
3
|
+
* "Please confirm": Confirm, Use it). File mode, one line per press of <runtime>/report-confirms.jsonl, beside the Viewer's other runtime records
|
|
4
|
+
* (lib/viewer-meeting.js).
|
|
5
|
+
*
|
|
6
|
+
* confirmsOf(dir, path) → [key] the keys confirmed for one report file; a later 'undo' line takes one back
|
|
7
|
+
* confirm(dir, { path, key, act }) → { ok } | { ok: false, status, error } act: confirm | use | undo
|
|
8
|
+
*
|
|
9
|
+
* A key is the check and a hash of its words (public/pm/rp-parts.js confirmKey), so a check that says something new asks again. Nothing here
|
|
10
|
+
* changes the report file: a Confirm is the PM's word that the figure stands, kept for the Brief. */
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const FILE = 'report-confirms.jsonl';
|
|
15
|
+
const ACTS = ['confirm', 'use', 'undo'];
|
|
16
|
+
const str = (v, n) => String(v == null ? '' : v).trim().slice(0, n);
|
|
17
|
+
const REL = /^(?!\/)(?!.*\.\.)[^\0]{1,400}\.md$/;
|
|
18
|
+
|
|
19
|
+
function readLines(file) {
|
|
20
|
+
let text = '';
|
|
21
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
22
|
+
const out = [];
|
|
23
|
+
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 */ } }
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function confirmsOf(dir, rel) {
|
|
28
|
+
if (!dir || !REL.test(String(rel || ''))) return [];
|
|
29
|
+
const on = new Set();
|
|
30
|
+
for (const l of readLines(path.join(dir, FILE))) {
|
|
31
|
+
if (l.path !== rel || typeof l.key !== 'string') continue;
|
|
32
|
+
if (l.act === 'undo') on.delete(l.key); else on.add(l.key);
|
|
33
|
+
}
|
|
34
|
+
return [...on];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function confirm(dir, { path: rel, key, act } = {}) {
|
|
38
|
+
if (!dir) return { ok: false, status: 409, error: 'this server has no runtime folder, so a confirm cannot be kept' };
|
|
39
|
+
if (!REL.test(String(rel || ''))) return { ok: false, status: 400, error: 'path is a report file (.md) inside the workspace' };
|
|
40
|
+
const k = str(key, 120);
|
|
41
|
+
if (!/^[a-z0-9-]+:[a-z0-9]+$/.test(k)) return { ok: false, status: 400, error: 'key is a check id and a hash, like check-figures:1x2y3z' };
|
|
42
|
+
const a = ACTS.includes(act) ? act : 'confirm';
|
|
43
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
44
|
+
fs.appendFileSync(path.join(dir, FILE), JSON.stringify({ v: 1, path: String(rel), key: k, act: a, at: new Date().toISOString() }) + '\n');
|
|
45
|
+
return { ok: true };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { confirmsOf, confirm, FILE };
|
|
@@ -53,12 +53,18 @@ const MODULES = Object.freeze([
|
|
|
53
53
|
'routes-my-work-premium', // briefing-premium-work: the premium My work page's model from the Work page's own list (read-only)
|
|
54
54
|
'routes-board-premium', // briefing-premium-board: the premium Board page's model from the Initiatives page's own routes (read-only)
|
|
55
55
|
'routes-board-trail', // premium-agreed-design: what the Agreed Board draws beside each initiative, derived from the repository (read-only)
|
|
56
|
+
'routes-board-docs', // premium-uncovered-features (Board): when each document of the Documents tab changed and by whom, from git (read-only)
|
|
57
|
+
'routes-board-grill', // premium-uncovered-features (Board): a new initiative's Why, material and first questions (page press; file mode)
|
|
56
58
|
'routes-insights-premium', // briefing-premium-insights: the premium Insights page's model from the KR metric records and report files (read-only)
|
|
57
59
|
'routes-home-desk', // premium-agreed-design (Home): seen marks, queued messages, the weekly update's recipients and sends, stakeholders (page press; file mode)
|
|
60
|
+
'routes-home-review', // premium-uncovered-features (Home): the weekly review's four steps and the untouched work looked at (page press; file mode)
|
|
58
61
|
'routes-initiative-premium', // briefing-premium-initiative: the premium initiative page's model from the Initiatives sheet's own routes (read-only)
|
|
62
|
+
'routes-initiative-layout', // premium-uncovered-features (Initiative): Moves on by itself, held stages, task groups and saved group sets (page press; file mode)
|
|
59
63
|
'routes-brief-page', // console3 Briefing as the brief: Today agenda, Needs you and Mentions (read-only; writes go through routes-pm-items)
|
|
60
64
|
'routes-mentions', // console3 Briefing Mentions: the PM's read marks (page press only)
|
|
61
65
|
'routes-inbox', // premium-agent-inbox: the bell's agent results and the PM's seen marks (page press only)
|
|
66
|
+
'routes-search', // premium-uncovered-features (E1): Search across the repository and every worktree (read-only)
|
|
67
|
+
'routes-news', // premium-uncovered-features (E2): New for you, the FYI items, and their seen marks (page press only)
|
|
62
68
|
'routes-phone-day', // phone companion: the agent's finished drafts, the evening recap and tomorrow at a glance (read-only)
|
|
63
69
|
'routes-report-facts', // console3 D: GET /api/report-families/facts (read-only, real data only)
|
|
64
70
|
'routes-records', // console3 E1a: ideas, hypotheses, decisions, KR metrics, bets (GET list; page-press add/edit/reading)
|
|
@@ -79,7 +85,9 @@ const MODULES = Object.freeze([
|
|
|
79
85
|
'routes-meeting-focus', // console3 Meeting focus: the meeting, its note's talk, the companion's notes (GET); topic corrections and Ask PMOS quietly (page press)
|
|
80
86
|
'routes-meeting-replay', // meeting-material-replay: the note, the Focus state and the shots joined for the Replay page (GET, read-only)
|
|
81
87
|
'routes-meeting-material', // meeting-material-replay: the material the PM links to a meeting (GET list and suggest; page-press POST add and remove; meeting-material.jsonl)
|
|
88
|
+
'routes-meeting-points', // premium-uncovered-features (meetings): the Replay's Confirm and Not right on a meeting's key points (meeting-points.jsonl)
|
|
82
89
|
'routes-viewer', // premium-agreed-design (viewer): agenda minutes, what recording listens to, a next step made a drafted ticket, the report's Issue checks
|
|
90
|
+
'routes-report-confirm', // premium-uncovered-features (reports): the Brief tab's Confirm and Use it (report-confirms.jsonl in the runtime folder)
|
|
83
91
|
'routes-stage-tools', // stage-tools-records: the records the PM edits per stage, what PMOS holds per stage, the sprint burndown
|
|
84
92
|
'routes-orchestrator', // agent-orchestrator: the status of the capacity governor and the PM's stop switch (orchestrator-stop.json)
|
|
85
93
|
'routes-driver', // initiative-driver: the Agent strip's data, Keep, Send back, Drop, Pause and the board mode (driver.jsonl)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-board-docs.js — GET /api/board-docs?ws=<id>&paths=<path,path,…> (initiative premium-uncovered-features, Board: BdDocs).
|
|
3
|
+
*
|
|
4
|
+
* 200 { ok, docs: { [path]: { changed, at, by, log: [{ at, by, subject }] } } } when each document last changed, by whom, and its last five commits
|
|
5
|
+
* 400 { ok: false, error } — no path, or a path outside the repository · 404 — the workspace is not registered
|
|
6
|
+
* Read-only: `git log` on the workspace's repository. A path git has no history for (a new file, no repository) is left out, so the
|
|
7
|
+
* Documents tab shows "—" for it rather than a guess. At most 40 paths per call. */
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { execFileSync } = require('child_process');
|
|
10
|
+
|
|
11
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
12
|
+
const day = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? Number(m[3]) + ' ' + MON[Number(m[2]) - 1] : ''; };
|
|
13
|
+
const PATH_RE = /^[\w@][\w@ .()/-]{0,300}$/;
|
|
14
|
+
|
|
15
|
+
/** The last commits of one file, newest first. → [{ at, by, subject }] (empty when git knows none). */
|
|
16
|
+
function logOf(root, rel) {
|
|
17
|
+
let out = '';
|
|
18
|
+
try { out = execFileSync('git', ['log', '-n', '5', '--format=%cI%x09%an%x09%s', '--', rel], { cwd: root, encoding: 'utf8', timeout: 4000, stdio: ['ignore', 'pipe', 'ignore'] }); } catch { return []; }
|
|
19
|
+
return out.split('\n').filter(Boolean).map((l) => { const [at, by, ...s] = l.split('\t'); return { at, by, subject: s.join('\t').slice(0, 160) }; });
|
|
20
|
+
}
|
|
21
|
+
/** The answer for a list of paths. Pure over `log` (a stand-in in the unit test). */
|
|
22
|
+
function docsOf(root, paths, log = logOf) {
|
|
23
|
+
const docs = {};
|
|
24
|
+
for (const p of paths) {
|
|
25
|
+
const L = log(root, p);
|
|
26
|
+
if (!L.length) continue;
|
|
27
|
+
docs[p] = { changed: day(L[0].at), at: L[0].at, by: L[0].by, log: L.map((x) => ({ at: day(x.at), by: x.by, subject: x.subject })) };
|
|
28
|
+
}
|
|
29
|
+
return docs;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
prefixes: ['/api/board-docs'],
|
|
34
|
+
docsOf,
|
|
35
|
+
handle: async (req, res, url, ctx) => {
|
|
36
|
+
if (url.pathname !== '/api/board-docs') return false;
|
|
37
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
38
|
+
const paths = String(url.searchParams.get('paths') || '').split(',').map((s) => s.trim()).filter(Boolean).slice(0, 40);
|
|
39
|
+
if (!paths.length) { ctx.json(res, { ok: false, error: 'name the documents: paths=<path,path,…>' }, 400); return true; }
|
|
40
|
+
if (!paths.every((p) => PATH_RE.test(p) && !p.split('/').includes('..') && !path.isAbsolute(p))) { ctx.json(res, { ok: false, error: 'a path must stay inside the repository' }, 400); return true; }
|
|
41
|
+
const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
|
|
42
|
+
if (!w || !w.root) { ctx.json(res, { ok: false, error: 'that workspace is not registered' }, 404); return true; }
|
|
43
|
+
ctx.json(res, { ok: true, docs: docsOf(w.root, paths) });
|
|
44
|
+
return true;
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-board-grill.js — the first questions of a new initiative on the Board (initiative premium-uncovered-features, Board: BdNew, BdGrill).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/board-grill?ws=<id>&id=<initiative> → { ok, id, why, material, questions, summary }
|
|
5
|
+
* GET /api/board-grill?ws=<id>&ids=<id,id,…> → { ok, items: { [id]: summary } } only the initiatives with a line in the file
|
|
6
|
+
* POST /api/board-grill/start { ws, id, why?, links?: [{ url, label? }] } the New initiative panel's Why and links
|
|
7
|
+
* POST /api/board-grill/file { ws, id, name, type?, data } one file (base64, at most 4 MB) kept under <state>/material/<id>/
|
|
8
|
+
* POST /api/board-grill/answer { ws, id, q, answer } one answer; an empty answer clears it
|
|
9
|
+
* POST /api/board-grill/later { ws, id } keep the open questions as the next step
|
|
10
|
+
* lib/board-grill.js holds the rules. FILE MODE ONLY: <state>/triage-answers.jsonl, append-only. Every POST is a page press
|
|
11
|
+
* (pm-guard requirePagePress). Nothing is sent anywhere. */
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const guard = require('./pm-guard.js');
|
|
15
|
+
const pmItems = require('./pm-items.js');
|
|
16
|
+
const G = require('./board-grill.js');
|
|
17
|
+
|
|
18
|
+
const ID_RE = /^[a-z0-9][\w.-]{0,80}$/i;
|
|
19
|
+
const MAX_FILE = 4 * 1024 * 1024;
|
|
20
|
+
const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
|
|
21
|
+
function stateDir(ctx, w) {
|
|
22
|
+
let d = null;
|
|
23
|
+
try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create: true }) : null; } catch { d = null; }
|
|
24
|
+
return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
|
|
25
|
+
}
|
|
26
|
+
const fileOf = (sd) => path.join(sd, 'triage-answers.jsonl');
|
|
27
|
+
const read = (f) => { try { return pmItems.readLines(f).filter(Boolean); } catch { return []; } };
|
|
28
|
+
const linkOk = (u) => /^https?:\/\/[^\s]{3,}$/i.test(String(u || ''));
|
|
29
|
+
const one = (lines, id) => { const st = G.fold(lines, id); return { ok: true, id, why: st.why, material: st.material, questions: G.questionsOf(st), summary: G.summaryOf(st) }; };
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
prefixes: ['/api/board-grill'],
|
|
33
|
+
handle: async (req, res, url, ctx) => {
|
|
34
|
+
const p = url.pathname;
|
|
35
|
+
if (!p.startsWith('/api/board-grill')) return false;
|
|
36
|
+
const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
|
|
37
|
+
if (p === '/api/board-grill') {
|
|
38
|
+
if (req.method !== 'GET') return bad('GET only', 405);
|
|
39
|
+
const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
|
|
40
|
+
if (!w || !w.root) return bad('that workspace is not registered', 404);
|
|
41
|
+
const sd = stateDir(ctx, w), lines = sd ? read(fileOf(sd)) : [];
|
|
42
|
+
const ids = String(url.searchParams.get('ids') || '').split(',').map((s) => s.trim()).filter(Boolean).slice(0, 150);
|
|
43
|
+
if (ids.length) {
|
|
44
|
+
if (!ids.every((x) => ID_RE.test(x))) return bad('a bad initiative id');
|
|
45
|
+
const items = {};
|
|
46
|
+
for (const id of ids) if (lines.some((l) => l && l.initiative === id)) items[id] = G.summaryOf(G.fold(lines, id));
|
|
47
|
+
ctx.json(res, { ok: true, items });
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const id = url.searchParams.get('id') || '';
|
|
51
|
+
if (!ID_RE.test(id)) return bad('name the initiative: id=<id>');
|
|
52
|
+
ctx.json(res, one(lines, id));
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
if (req.method !== 'POST') return bad('POST only', 405);
|
|
56
|
+
const got = await ctx.readJson(req);
|
|
57
|
+
if (!got.ok) return bad('invalid JSON body');
|
|
58
|
+
const b = got.body || {};
|
|
59
|
+
const g = guard.requirePagePress(req, b);
|
|
60
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
61
|
+
const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
|
|
62
|
+
if (!w || !w.root) return bad('that workspace is not registered', 404);
|
|
63
|
+
if (!ID_RE.test(String(b.id || ''))) return bad('id must name the initiative');
|
|
64
|
+
const sd = stateDir(ctx, w);
|
|
65
|
+
if (!sd) return bad('this workspace has no state folder', 409);
|
|
66
|
+
const f = fileOf(sd), now = new Date();
|
|
67
|
+
if (p === '/api/board-grill/start') {
|
|
68
|
+
const links = (Array.isArray(b.links) ? b.links : []).slice(0, 20).map((k) => ({ url: str(k && k.url, 600), label: str(k && (k.label || k.url), 160) }));
|
|
69
|
+
if (links.some((k) => !linkOk(k.url))) return bad('a link must start with http:// or https://');
|
|
70
|
+
pmItems.appendEvent(f, { kind: 'start', initiative: b.id, why: str(b.why, 400), links }, now);
|
|
71
|
+
} else if (p === '/api/board-grill/file') {
|
|
72
|
+
const name = path.basename(str(b.name, 120)).replace(/[^\w .()-]+/g, '_');
|
|
73
|
+
if (!name || name.startsWith('.')) return bad('name the file');
|
|
74
|
+
const buf = Buffer.from(String(b.data || ''), 'base64');
|
|
75
|
+
if (!buf.length) return bad('the file is empty');
|
|
76
|
+
if (buf.length > MAX_FILE) return bad('a file can be at most 4 MB');
|
|
77
|
+
const dir = path.join(sd, 'material', b.id);
|
|
78
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
79
|
+
fs.writeFileSync(path.join(dir, name), buf);
|
|
80
|
+
pmItems.appendEvent(f, { kind: 'file', initiative: b.id, name, type: str(b.type, 80), size: buf.length, path: path.relative(w.root, path.join(dir, name)).split(path.sep).join('/') }, now);
|
|
81
|
+
} else if (p === '/api/board-grill/answer') {
|
|
82
|
+
if (!G.QUESTIONS.some((x) => x.key === b.q)) return bad('q must name a question');
|
|
83
|
+
pmItems.appendEvent(f, { kind: 'answer', initiative: b.id, q: b.q, answer: str(b.answer, 500) }, now);
|
|
84
|
+
} else if (p === '/api/board-grill/later') {
|
|
85
|
+
pmItems.appendEvent(f, { kind: 'later', initiative: b.id }, now);
|
|
86
|
+
} else return bad('no such route', 404);
|
|
87
|
+
ctx.json(res, one(read(f), b.id));
|
|
88
|
+
return true;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-home-review.js — the PM's weekly review on Home (initiative premium-uncovered-features, H1; canvas HmReview).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/home-review?ws=<id>
|
|
5
|
+
* → { ok, week, steps: { [step]: { note, at } }, kept: { [initiative]: { how, at } }, last: { week, at, minutes } | null }
|
|
6
|
+
* POST /api/home-review/step { ws, week, step, note? } one of the four steps is done this week ("4 sorted · 1 kept")
|
|
7
|
+
* POST /api/home-review/keep { ws, week, initiative, how } an untouched initiative was looked at: kept going, or asked in chat
|
|
8
|
+
*
|
|
9
|
+
* The review has four steps: sort (what came in), wait (what the PM waits on), untouched (work with no change for 14 days or more) and
|
|
10
|
+
* pick (next week's three). A week is named by its Monday (YYYY-MM-DD). "last" is the newest earlier week with all four steps done, and how
|
|
11
|
+
* long it took from its first step to its last.
|
|
12
|
+
*
|
|
13
|
+
* FILE MODE ONLY, append-only JSONL (D64/D66): <state>/weekly-review.jsonl in the workspace's state folder (stateDirFor). Nothing is
|
|
14
|
+
* rewritten; the last line for a step or an initiative in a week wins when read back. Every POST is a page press (pm-guard
|
|
15
|
+
* requirePagePress): an agent session cannot write the review. Nothing here sends anything to anyone. */
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const guard = require('./pm-guard.js');
|
|
18
|
+
const pmItems = require('./pm-items.js');
|
|
19
|
+
|
|
20
|
+
const STEPS = ['sort', 'wait', 'untouched', 'pick'];
|
|
21
|
+
const HOWS = ['kept', 'asked', 'held'];
|
|
22
|
+
const WEEK_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
23
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
|
|
24
|
+
const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
|
|
25
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
26
|
+
|
|
27
|
+
/** The Monday of the week that holds `now`, as YYYY-MM-DD in local time. */
|
|
28
|
+
function weekOf(now) {
|
|
29
|
+
const d = new Date(now); d.setHours(0, 0, 0, 0);
|
|
30
|
+
d.setDate(d.getDate() - ((d.getDay() + 6) % 7));
|
|
31
|
+
return d.getFullYear() + '-' + pad(d.getMonth() + 1) + '-' + pad(d.getDate());
|
|
32
|
+
}
|
|
33
|
+
const fileOf = (sd) => path.join(sd, 'weekly-review.jsonl');
|
|
34
|
+
function stateDir(ctx, w) {
|
|
35
|
+
let d = null;
|
|
36
|
+
try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create: true }) : null; } catch { d = null; }
|
|
37
|
+
return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
|
|
38
|
+
}
|
|
39
|
+
const read = (f) => { try { return pmItems.readLines(f).filter(Boolean); } catch { return []; } };
|
|
40
|
+
|
|
41
|
+
/** This week's review and the last full one before it. Pure over the lines. */
|
|
42
|
+
function foldReview(lines, week) {
|
|
43
|
+
const weeks = new Map();
|
|
44
|
+
const of = (w) => weeks.get(w) || weeks.set(w, { steps: {}, kept: {} }).get(w);
|
|
45
|
+
for (const l of lines) {
|
|
46
|
+
if (!l || !WEEK_RE.test(String(l.week || ''))) continue;
|
|
47
|
+
const W = of(l.week);
|
|
48
|
+
if (l.kind === 'step' && STEPS.includes(l.step)) W.steps[l.step] = { note: l.note || '', at: l.at };
|
|
49
|
+
if (l.kind === 'keep' && ID_RE.test(String(l.initiative || '')) && HOWS.includes(l.how)) W.kept[l.initiative] = { how: l.how, at: l.at };
|
|
50
|
+
}
|
|
51
|
+
const cur = weeks.get(week) || { steps: {}, kept: {} };
|
|
52
|
+
let last = null;
|
|
53
|
+
for (const [w, W] of weeks) {
|
|
54
|
+
if (w >= week || !STEPS.every((s) => W.steps[s])) continue;
|
|
55
|
+
const at = STEPS.map((s) => Date.parse(W.steps[s].at)).filter((x) => !Number.isNaN(x));
|
|
56
|
+
if (!last || w > last.week) last = { week: w, at: at.length ? new Date(Math.max(...at)).toISOString() : null, minutes: at.length ? Math.max(1, Math.round((Math.max(...at) - Math.min(...at)) / 60000)) : null };
|
|
57
|
+
}
|
|
58
|
+
return { week, steps: cur.steps, kept: cur.kept, last };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function body(req, ctx, res) {
|
|
62
|
+
const got = await ctx.readJson(req);
|
|
63
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return null; }
|
|
64
|
+
const b = got.body || {};
|
|
65
|
+
const g = guard.requirePagePress(req, b);
|
|
66
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return null; }
|
|
67
|
+
return b;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
prefixes: ['/api/home-review'],
|
|
72
|
+
STEPS, HOWS, weekOf, foldReview,
|
|
73
|
+
handle: async (req, res, url, ctx) => {
|
|
74
|
+
const p = url.pathname;
|
|
75
|
+
if (p !== '/api/home-review' && !p.startsWith('/api/home-review/')) return false;
|
|
76
|
+
const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
|
|
77
|
+
const now = ctx.now ? ctx.now() : Date.now();
|
|
78
|
+
if (p === '/api/home-review') {
|
|
79
|
+
if (req.method !== 'GET') return bad('GET only', 405);
|
|
80
|
+
const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
|
|
81
|
+
const sd = w ? stateDir(ctx, w) : null;
|
|
82
|
+
const week = weekOf(now);
|
|
83
|
+
ctx.json(res, { ok: true, ws: w ? w.id : null, ...foldReview(sd ? read(fileOf(sd)) : [], week) });
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (p !== '/api/home-review/step' && p !== '/api/home-review/keep') return bad('no such route', 404);
|
|
87
|
+
if (req.method !== 'POST') return bad('POST only', 405);
|
|
88
|
+
const b = await body(req, ctx, res);
|
|
89
|
+
if (!b) return true;
|
|
90
|
+
const week = b.week == null || b.week === '' ? weekOf(now) : String(b.week);
|
|
91
|
+
if (!WEEK_RE.test(week)) return bad('week must be a date (YYYY-MM-DD)');
|
|
92
|
+
const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
|
|
93
|
+
if (!w) return bad('that workspace is not registered', 404);
|
|
94
|
+
const sd = stateDir(ctx, w);
|
|
95
|
+
if (!sd) return bad('this workspace has no state folder', 409);
|
|
96
|
+
const at = new Date(now);
|
|
97
|
+
if (p === '/api/home-review/step') {
|
|
98
|
+
if (!STEPS.includes(b.step)) return bad('step must be one of: ' + STEPS.join(', '));
|
|
99
|
+
pmItems.appendEvent(fileOf(sd), { kind: 'step', week, step: b.step, note: str(b.note, 200) }, at);
|
|
100
|
+
} else {
|
|
101
|
+
if (!ID_RE.test(String(b.initiative || ''))) return bad('initiative must name an initiative');
|
|
102
|
+
if (!HOWS.includes(b.how)) return bad('how must be one of: ' + HOWS.join(', '));
|
|
103
|
+
pmItems.appendEvent(fileOf(sd), { kind: 'keep', week, initiative: b.initiative, how: b.how }, at);
|
|
104
|
+
}
|
|
105
|
+
ctx.json(res, { ok: true, ...foldReview(read(fileOf(sd)), week) });
|
|
106
|
+
return true;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-initiative-layout.js — the PM's layout choices for one initiative inside Home (initiative premium-uncovered-features, Initiative).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/initiative-layout?ws=<id>&initiative=<id>
|
|
5
|
+
* → { ok, initiative, auto, held, by, names, of, stage, sets: [{ name, names }] }
|
|
6
|
+
* POST /api/initiative-layout { ws, kind, initiative?, ... } one press (lib/initiative-layout.js eventOf):
|
|
7
|
+
* auto { on } · hold { stage } · by { by } · groups { names } · rename { from, to } · place { task, group } · stage { task, stage }
|
|
8
|
+
* set { name, names } · unset { name }
|
|
9
|
+
* → the same answer as GET, after the line is written
|
|
10
|
+
*
|
|
11
|
+
* FILE MODE ONLY, append-only JSONL (D64/D66): <state>/initiative-layout.jsonl in the workspace's state folder (stateDirFor).
|
|
12
|
+
* Every POST is a page press (pm-guard requirePagePress): an agent session cannot write it. */
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const guard = require('./pm-guard.js');
|
|
15
|
+
const pmItems = require('./pm-items.js');
|
|
16
|
+
const L = require('./initiative-layout.js');
|
|
17
|
+
|
|
18
|
+
const ID_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
|
|
19
|
+
function stateDir(ctx, w) {
|
|
20
|
+
let d = null;
|
|
21
|
+
try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create: true }) : null; } catch { d = null; }
|
|
22
|
+
return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
|
|
23
|
+
}
|
|
24
|
+
const fileOf = (sd) => path.join(sd, 'initiative-layout.jsonl');
|
|
25
|
+
const read = (f) => { try { return pmItems.readLines(f).filter(Boolean); } catch { return []; } };
|
|
26
|
+
const answer = (lines, ini) => ({ ok: true, initiative: ini || null, ...(ini ? L.fold(lines, ini) : {}), sets: L.foldSets(lines) });
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
prefixes: ['/api/initiative-layout'],
|
|
30
|
+
handle: async (req, res, url, ctx) => {
|
|
31
|
+
if (url.pathname !== '/api/initiative-layout') { if (url.pathname.startsWith('/api/initiative-layout')) { ctx.json(res, { ok: false, error: 'no such route' }, 404); return true; } return false; }
|
|
32
|
+
const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
|
|
33
|
+
if (req.method === 'GET') {
|
|
34
|
+
const ini = url.searchParams.get('initiative') || '';
|
|
35
|
+
if (ini && !ID_RE.test(ini)) return bad('initiative must name an initiative');
|
|
36
|
+
const w = ctx.getWs ? ctx.getWs(url.searchParams.get('ws') || null) : null;
|
|
37
|
+
const sd = w ? stateDir(ctx, w) : null;
|
|
38
|
+
ctx.json(res, answer(sd ? read(fileOf(sd)) : [], ini));
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (req.method !== 'POST') return bad('GET or POST only', 405);
|
|
42
|
+
const got = await ctx.readJson(req);
|
|
43
|
+
if (!got.ok) return bad('invalid JSON body');
|
|
44
|
+
const b = got.body || {};
|
|
45
|
+
const g = guard.requirePagePress(req, b);
|
|
46
|
+
if (!g.ok) return bad(g.error, g.status);
|
|
47
|
+
const ev = L.eventOf(b);
|
|
48
|
+
if (!ev.ok) return bad(ev.error);
|
|
49
|
+
const w = ctx.getWs ? ctx.getWs(b.ws || null) : null;
|
|
50
|
+
if (!w) return bad('that workspace is not registered', 404);
|
|
51
|
+
const sd = stateDir(ctx, w);
|
|
52
|
+
if (!sd) return bad('this workspace has no state folder', 409);
|
|
53
|
+
pmItems.appendEvent(fileOf(sd), ev.event, new Date());
|
|
54
|
+
ctx.json(res, answer(read(fileOf(sd)), ev.event.initiative || (ID_RE.test(String(b.initiative || '')) ? b.initiative : '')));
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -88,8 +88,11 @@ module.exports = {
|
|
|
88
88
|
try { ins = require('./insights-records.js').read(root); } catch { missing.push('insights records'); }
|
|
89
89
|
try { budgets = require('./insights-goals.js').parseBudgets(require('fs').readFileSync(require('path').join(root, 'planning', 'okrs', 'health-budgets.md'), 'utf8')); } catch { budgets = null; }
|
|
90
90
|
}
|
|
91
|
+
// premium-uncovered-features (IsMenus): the product picker says how many goals each product's workspace records; a workspace that cannot be read says none
|
|
92
|
+
const counts = new Map();
|
|
93
|
+
const goalsIn = (w) => { if (!counts.has(w)) { let n = null; try { n = w === ws ? outcomes.length : require(repoScript('records/index.js')).list(recordsDirFor(ctx, w), 'kr-metrics').length; } catch { n = null; } counts.set(w, n); } return counts.get(w) === null ? {} : { goals: counts.get(w) }; };
|
|
91
94
|
const model = Insights.build({
|
|
92
|
-
now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Insights' }, boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })),
|
|
95
|
+
now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Insights' }, boards: all.map((x) => Object.assign({ ws: x.ws, id: x.id, name: x.name }, goalsIn(x.ws))),
|
|
93
96
|
outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
|
|
94
97
|
setups: setupsOk ? su.body : null, pinned, leads, archived, initiatives, goalMeta, ins, budgets,
|
|
95
98
|
});
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* POST /api/insights-records/describe { ws, text } → { ok, name, question, goals, range, said } reads the goals; writes nothing
|
|
12
12
|
* POST /api/insights-records/verdict { ws, board, ini, verdict, learned, goal } → { ok, verdict } one verdict line; the Board is not changed
|
|
13
13
|
* POST /api/insights-records/target { ws, key: late | scope, target } → { ok, targets }
|
|
14
|
+
* POST /api/insights-records/tile { ws, key, dir: at least | at most | none, from, chip } → { ok, tiles } how a Delivery trends target is
|
|
15
|
+
* read (premium-uncovered-features, IsTarget): its direction, the day it counts from and whether the Board chip shows it
|
|
14
16
|
* GET /api/insights-records/export?ws=&board= → text/csv of the goals the page shows
|
|
15
17
|
*
|
|
16
18
|
* WHO WRITES. As routes-premium-dashboards.js: an agent session header is refused (403), and pm-guard requirePagePress checks the launch nonce and the
|
|
@@ -50,7 +52,7 @@ async function handle(req, res, url, ctx) {
|
|
|
50
52
|
res.end(IG.exportCsv(m.goals || []));
|
|
51
53
|
return true;
|
|
52
54
|
}
|
|
53
|
-
if (!['goal', 'steps', 'dashboard', 'chart', 'describe', 'verdict', 'target'].includes(what)) return send(bad(404, 'no such insights-records route'));
|
|
55
|
+
if (!['goal', 'steps', 'dashboard', 'chart', 'describe', 'verdict', 'target', 'tile'].includes(what)) return send(bad(404, 'no such insights-records route'));
|
|
54
56
|
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
55
57
|
const read = await ctx.readJson(req);
|
|
56
58
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
@@ -85,9 +87,11 @@ async function handle(req, res, url, ctx) {
|
|
|
85
87
|
const r = records().addReading(root, cur.rid, { at: today(), value: n }, UI(), 'Steps done, from Insights');
|
|
86
88
|
return send(r.ok ? { status: 200, body: { ok: true, done: n } } : bad(400, r.reasons.join('; ')));
|
|
87
89
|
}
|
|
88
|
-
if (what === 'target') {
|
|
89
|
-
const r = IR.append(w.root,
|
|
90
|
-
|
|
90
|
+
if (what === 'target' || what === 'tile') {
|
|
91
|
+
const r = IR.append(w.root, what, body, g.actor, { now });
|
|
92
|
+
if (!r.ok) return send(bad(r.status, r.error));
|
|
93
|
+
const R = IR.read(w.root);
|
|
94
|
+
return send({ status: 200, body: what === 'target' ? { ok: true, targets: R.targets } : { ok: true, tiles: R.tiles } });
|
|
91
95
|
}
|
|
92
96
|
const ids = dashRoutes.boardIds(ctx, w);
|
|
93
97
|
if (!ids) return send(bad(503, 'The boards could not be read. Try again in a moment.'));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-meeting-points.js — the Replay's Confirm and Not right (initiative premium-uncovered-features, area meetings; lib/route-modules.js).
|
|
3
|
+
* The data is kept by lib/meeting-points.js.
|
|
4
|
+
*
|
|
5
|
+
* GET /api/meeting-points?note=<id> → { ok, points: { [pointId]: 'confirmed' | 'wrong' } }
|
|
6
|
+
* POST /api/meeting-points { note, ids: [pointId], verdict } → { ok, points } verdict confirmed | wrong | null (Undo)
|
|
7
|
+
* The POST is a page press (lib/pm-guard.js requirePagePress). Handlers are pure over (q | body, ctx) so a test needs no server. */
|
|
8
|
+
const MP = require('./meeting-points.js');
|
|
9
|
+
const guard = require('./pm-guard.js');
|
|
10
|
+
|
|
11
|
+
const fail = (status, error) => ({ status, body: { ok: false, error } });
|
|
12
|
+
|
|
13
|
+
function read(q, ctx) {
|
|
14
|
+
if (!/^[A-Za-z0-9_-]{1,80}$/.test(String(q.note || ''))) return fail(400, 'note is the id of a meeting note');
|
|
15
|
+
return { status: 200, body: { ok: true, points: MP.pointsOf(ctx.runtimeDir, String(q.note)) } };
|
|
16
|
+
}
|
|
17
|
+
function write(req, body, ctx) {
|
|
18
|
+
const g = guard.requirePagePress(req, body);
|
|
19
|
+
if (!g.ok) return fail(g.status, g.error);
|
|
20
|
+
const r = MP.setPoints(ctx.runtimeDir, body);
|
|
21
|
+
return r.ok ? { status: 200, body: { ok: true, points: r.points } } : fail(r.status || 400, r.error);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
|
|
25
|
+
|
|
26
|
+
module.exports = {
|
|
27
|
+
prefixes: ['/api/meeting-points'],
|
|
28
|
+
read, write,
|
|
29
|
+
handle: async (req, res, url, ctx) => {
|
|
30
|
+
if (url.pathname !== '/api/meeting-points') return false;
|
|
31
|
+
if (req.method === 'GET') return respond(ctx, res, read(Object.fromEntries(url.searchParams), ctx));
|
|
32
|
+
if (req.method !== 'POST') return respond(ctx, res, fail(405, 'GET or POST'));
|
|
33
|
+
const got = await ctx.readJson(req);
|
|
34
|
+
if (!got.ok || !got.body || typeof got.body !== 'object' || Array.isArray(got.body)) return respond(ctx, res, fail(400, 'the body must be a JSON object'));
|
|
35
|
+
return respond(ctx, res, write(req, got.body, ctx));
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-news.js — New for you (initiative premium-uncovered-features, E2; lib/news-for-you.js).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/news-for-you → { ok, count, groups, read } the FYI items not seen yet: mentions, tasks given to you, finished work
|
|
5
|
+
* POST /api/news-for-you/seen { ids } → { ok } one line in <runtime>/news-seen.jsonl; the agent inbox's own ids also go to its seen file,
|
|
6
|
+
* so its count agrees. A page press only (pm-guard requirePagePress).
|
|
7
|
+
*
|
|
8
|
+
* The read asks the routes the pages already read, answered by their own handlers: GET /api/inbox, GET /api/brief-page (its mentions) and
|
|
9
|
+
* GET /api/pm-items (the Work lists). A route that cannot be read gives no items and says so in `read`. Nothing here sends anything. */
|
|
10
|
+
const guard = require('./pm-guard.js');
|
|
11
|
+
const News = require('./news-for-you.js');
|
|
12
|
+
|
|
13
|
+
/** One GET answered by a route module's own handler, as routes-my-work-premium.js listView does. null when it did not answer. */
|
|
14
|
+
async function ask(mod, req, ctx, p) {
|
|
15
|
+
let body = null;
|
|
16
|
+
const c = Object.assign({}, ctx, { json: (res, obj) => { body = obj; } });
|
|
17
|
+
try { await require(mod).handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, new URL('http://local' + p), c); } catch { body = null; }
|
|
18
|
+
return body;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = {
|
|
22
|
+
prefixes: ['/api/news-for-you'],
|
|
23
|
+
handle: async (req, res, url, ctx) => {
|
|
24
|
+
const p = url.pathname;
|
|
25
|
+
if (p === '/api/news-for-you/seen') {
|
|
26
|
+
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
27
|
+
const got = await ctx.readJson(req);
|
|
28
|
+
if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
|
|
29
|
+
const b = got.body || {};
|
|
30
|
+
const g = guard.requirePagePress(req, b);
|
|
31
|
+
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
32
|
+
const err = News.badSeen(b);
|
|
33
|
+
if (err) { ctx.json(res, { ok: false, error: err }, 400); return true; }
|
|
34
|
+
if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'no runtime folder' }, 500); return true; }
|
|
35
|
+
News.appendSeen(ctx.runtimeDir, b.ids);
|
|
36
|
+
const ib = News.inboxIds(b.ids);
|
|
37
|
+
for (let i = 0; i < ib.length; i += 100) require('./agent-inbox.js').appendSeen(ctx.runtimeDir, { ids: ib.slice(i, i + 100) });
|
|
38
|
+
ctx.json(res, { ok: true });
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (p !== '/api/news-for-you') return false;
|
|
42
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
43
|
+
const ws = url.searchParams.get('ws');
|
|
44
|
+
const [inbox, brief, work] = await Promise.all([
|
|
45
|
+
ask('./routes-inbox.js', req, ctx, '/api/inbox'),
|
|
46
|
+
ask('./routes-brief-page.js', req, ctx, '/api/brief-page' + (ws ? '?ws=' + encodeURIComponent(ws) : '')),
|
|
47
|
+
ask('./routes-pm-items.js', req, ctx, '/api/pm-items'),
|
|
48
|
+
]);
|
|
49
|
+
const out = News.build({
|
|
50
|
+
inbox, mentions: brief && brief.ok !== false ? brief.mentions : null, work: work && work.ok !== false ? work : null,
|
|
51
|
+
seen: ctx.runtimeDir ? News.readSeen(ctx.runtimeDir) : new Set(),
|
|
52
|
+
});
|
|
53
|
+
out.read.mentions = !!(brief && brief.ok !== false); // no brief for today is read too: it has no mentions
|
|
54
|
+
ctx.json(res, { ok: true, ...out });
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -70,7 +70,8 @@
|
|
|
70
70
|
* POST /api/notes/final-edit { id, sec: 'overview'|'decision'|'action'|'question', i?, text, field?: 'owner'|'due'|'why' } → { ok, final_notes } the PM's correction
|
|
71
71
|
* GET /api/notes also answers `series_open`: { <series key>: { open, carried } }, the actions each meeting series carries open.
|
|
72
72
|
* GET /api/notes/series?key= → { ok, series } one regular meeting's notes together (lib/notes-series.js thread)
|
|
73
|
-
* GET /api/notes/search?q= → { ok, ids }
|
|
73
|
+
* GET /api/notes/search?q= → { ok, ids, hits: [{ id, snip, open }] } the notes whose title, notes or transcript hold every word (a private
|
|
74
|
+
* note: its title); each hit with the passage that holds a word, and whether it is an open step or question
|
|
74
75
|
* POST /api/notes/series-done { key, text, kind: 'action'|'question', done? } → { ok } the PM marks a carried action done, a question answered
|
|
75
76
|
* POST /api/notes/series-bring { key, text } → { ok, line } · POST /api/notes/series-unbring { key, id } → { ok } lines to bring up next time
|
|
76
77
|
* POST /api/notes/series-member { id, key: '<series key>'|'off'|null } → { ok, series } put a note in a series, take it out, or back to automatic
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-report-confirm.js — the Brief tab's Confirm and Use it (initiative premium-uncovered-features, workstream reports; lib/route-modules.js).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/report-confirm?path=<report file> → { ok, keys: [key] }
|
|
5
|
+
* POST /api/report-confirm { path, key, act } → { ok } act: confirm | use | undo; a page press (lib/pm-guard.js requirePagePress)
|
|
6
|
+
* The records are lib/report-confirm.js, in the runtime folder. Handlers are pure over (q | body, ctx) so a test needs no server. */
|
|
7
|
+
const RC = require('./report-confirm.js');
|
|
8
|
+
const guard = require('./pm-guard.js');
|
|
9
|
+
|
|
10
|
+
const fail = (status, error) => ({ status, body: { ok: false, error } });
|
|
11
|
+
function read(q, ctx) { return { status: 200, body: { ok: true, keys: RC.confirmsOf(ctx.runtimeDir, String(q.path || '')) } }; }
|
|
12
|
+
function post(req, body, ctx) {
|
|
13
|
+
const g = guard.requirePagePress(req, body);
|
|
14
|
+
if (!g.ok) return fail(g.status, g.error);
|
|
15
|
+
const r = RC.confirm(ctx.runtimeDir, body);
|
|
16
|
+
return r.ok ? { status: 200, body: { ok: true } } : fail(r.status || 400, r.error);
|
|
17
|
+
}
|
|
18
|
+
const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
prefixes: ['/api/report-confirm'],
|
|
22
|
+
read, post,
|
|
23
|
+
handle: async (req, res, url, ctx) => {
|
|
24
|
+
if (url.pathname !== '/api/report-confirm') return false;
|
|
25
|
+
if (req.method === 'GET') return respond(ctx, res, read(Object.fromEntries(url.searchParams), ctx));
|
|
26
|
+
if (req.method !== 'POST') return respond(ctx, res, fail(405, 'GET or POST only'));
|
|
27
|
+
const got = await ctx.readJson(req);
|
|
28
|
+
if (!got.ok || !got.body || typeof got.body !== 'object' || Array.isArray(got.body)) return respond(ctx, res, fail(400, 'the body must be a JSON object'));
|
|
29
|
+
return respond(ctx, res, post(req, got.body, ctx));
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* routes-search.js — Search across the repository and every worktree (initiative premium-uncovered-features, E1; lib/search-index.js).
|
|
3
|
+
*
|
|
4
|
+
* GET /api/find?q=<words>&ws=<id>&wt=<id,id> → { ok, q, worktrees, counts, results, more } wt: the worktrees to search (none: all)
|
|
5
|
+
* GET /api/find/file?ws=<id>&wt=<id>&path=<p> → { ok, wt, branch, main, path, text, mtime } one file of a listed worktree, for the Viewer
|
|
6
|
+
*
|
|
7
|
+
* Read-only: nothing here writes or calls anything outside this machine. The repository is the workspace's own (ws, else the home one). */
|
|
8
|
+
const Search = require('./search-index.js');
|
|
9
|
+
|
|
10
|
+
function wsOf(ctx, id) {
|
|
11
|
+
const w = typeof ctx.getWs === 'function' ? ctx.getWs(id || '') : null;
|
|
12
|
+
return w && (!id || w.id === id) ? w : null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
prefixes: ['/api/find'],
|
|
17
|
+
handle: async (req, res, url, ctx) => {
|
|
18
|
+
const p = url.pathname;
|
|
19
|
+
if (p !== '/api/find' && p !== '/api/find/file') return false;
|
|
20
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
21
|
+
const w = wsOf(ctx, url.searchParams.get('ws'));
|
|
22
|
+
if (!w || !w.root) { ctx.json(res, { ok: false, error: 'no such workspace' }, 404); return true; }
|
|
23
|
+
if (p === '/api/find/file') {
|
|
24
|
+
const r = Search.readFile({ root: w.root, wt: url.searchParams.get('wt') || 'main', path: url.searchParams.get('path') || '' });
|
|
25
|
+
ctx.json(res, r.ok ? r : { ok: false, error: r.error }, r.ok ? 200 : r.status || 400);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
let notes = [];
|
|
29
|
+
try { const l = ctx.runtimeDir ? require('./notes.js').list(ctx.runtimeDir) : null; notes = l && l.ok ? l.notes : []; } catch { notes = []; }
|
|
30
|
+
const only = (url.searchParams.get('wt') || '').split(',').map((x) => x.trim()).filter(Boolean);
|
|
31
|
+
try {
|
|
32
|
+
ctx.json(res, { ws: w.id, ...Search.search({ root: w.root, q: url.searchParams.get('q') || '', only, notes }) });
|
|
33
|
+
} catch (e) {
|
|
34
|
+
ctx.json(res, { ok: false, error: 'the search could not run: ' + String((e && e.message) || e).slice(0, 160) }, 500);
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
},
|
|
38
|
+
};
|