create-pmos 0.409.0 → 0.411.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 -30
- 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 +1 -1
- package/workspace/briefing-premium-initiative-test.js +9 -15
- package/workspace/changelog.json +24 -0
- package/workspace/chat-asks-test.js +146 -0
- package/workspace/guide/briefing-premium.md +1 -1
- package/workspace/guide/home.md +25 -0
- package/workspace/guide/programs.md +2 -1
- package/workspace/home-rows-test.js +149 -56
- package/workspace/ini-workflow-test.js +4 -4
- package/workspace/lib/briefing-premium-agent.js +8 -1
- package/workspace/lib/engine/boards.js +3 -1
- package/workspace/lib/goal-chat.js +94 -30
- package/workspace/lib/mention-cli.js +70 -0
- package/workspace/lib/mention-store.js +307 -0
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/routes-boards.js +12 -0
- package/workspace/lib/routes-briefing-premium.js +2 -2
- package/workspace/lib/routes-mentions.js +62 -9
- package/workspace/lib/session-files.js +132 -0
- package/workspace/lib/session-name.js +103 -0
- package/workspace/lib/source-reads.js +4 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +10 -8
- package/workspace/premium-chat-goal-setup-test.js +203 -0
- package/workspace/premium-chat-goal-view-test.js +28 -23
- package/workspace/premium-chat-line-test.js +189 -0
- package/workspace/premium-vw-backlog-test.js +1 -1
- package/workspace/premium-vw-item-test.js +1 -1
- package/workspace/premium-vw-jira-test.js +1 -1
- package/workspace/public/pm/bd-prog-panel.js +3 -1
- package/workspace/public/pm/bd-prog.js +4 -2
- package/workspace/public/pm/chat-ask.js +17 -9
- package/workspace/public/pm/cozy-home-rows.css +39 -1
- package/workspace/public/pm/cozy-home.css +112 -12
- package/workspace/public/pm/cozy-search.js +2 -1
- package/workspace/public/pm/cozy-steps.css +69 -0
- package/workspace/public/pm/cozy-steps.js +90 -0
- package/workspace/public/pm/goal-chat.js +141 -23
- package/workspace/public/pm/home-app.js +71 -35
- package/workspace/public/pm/home-ask.js +121 -0
- package/workspace/public/pm/home-chat.js +120 -68
- package/workspace/public/pm/home-data.js +10 -2
- package/workspace/public/pm/home-goal.js +159 -0
- package/workspace/public/pm/home-ini.css +35 -0
- package/workspace/public/pm/home-ini.js +50 -19
- package/workspace/public/pm/home-line.css +59 -0
- package/workspace/public/pm/home-line.js +200 -0
- package/workspace/public/pm/home-list.js +7 -4
- package/workspace/public/pm/home-mentions.js +303 -111
- package/workspace/public/pm/home-ses-name.js +65 -0
- package/workspace/public/pm/home-stage-card.js +94 -0
- package/workspace/public/pm/home-sweep.js +112 -0
- package/workspace/public/pm/home-today.js +8 -3
- package/workspace/public/pm/premium-initiative-head.js +8 -4
- package/workspace/public/pm/program-model.js +4 -1
- package/workspace/public/pm/rename-press.js +24 -0
- package/workspace/public/pm/wf-page.css +3 -0
- package/workspace/public/pm/wf-page.js +2 -1
- package/workspace/public/premium-workflows.html +1 -0
- package/workspace/server.js +125 -11
- package/workspace/session-names-test.js +144 -0
- package/workspace/skills/jira-push.skill +1 -0
- package/workspace/skills/morning-brief.skill +2 -1
- package/workspace/skills/report-daily.skill +1 -0
- package/workspace/skills/report-monthly.skill +1 -0
- package/workspace/skills/report-weekly.skill +1 -0
- package/workspace/skills/sources-read.skill +3 -2
- package/workspace/stage-card-test.js +203 -0
- package/workspace/test-lists/chat-asks.json +13 -0
- package/workspace/test-lists/chat-progress.json +13 -0
- package/workspace/test-lists/mentions-a-plus.json +9 -0
- package/workspace/test-lists/premium-chat-goal-setup.json +9 -0
- package/workspace/test-lists/session-files.json +5 -0
- package/workspace/test-lists/session-names.json +13 -0
- package/workspace/test-lists/stage-card.json +6 -0
- package/workspace/tk-tasks-test.js +1 -1
- package/workspace/workflows-setup-test.js +17 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/* goal-chat — `/goal` in the premium chat panel (initiative premium-chat-session, slice 2; PRD G2–G7).
|
|
3
|
-
* `/goal <text>` turns into a PMOS grilling prompt typed into the panel's own Claude Code session: Claude reads the records,
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* `/goal <text>` turns into a PMOS grilling prompt typed into the panel's own Claude Code session: Claude reads the records, picks the
|
|
4
|
+
* questioning method that fits the goal (METHODS; the PM can change it), asks one question at a time, and ends each message with a fenced
|
|
5
|
+
* `pmos-goal` JSON block the panel draws as a dots row, answer chips or the plan card. Start, Change, Cancel, a skipped point and a replaced
|
|
6
|
+
* goal are the PM's presses. The record is append-only: goal-runs.jsonl in the state folder. */
|
|
6
7
|
const fs = require('fs');
|
|
7
8
|
const path = require('path');
|
|
8
9
|
const crypto = require('crypto');
|
|
@@ -11,7 +12,17 @@ const RUNS = 'goal-runs.jsonl';
|
|
|
11
12
|
const LIMIT = 12;
|
|
12
13
|
const MAX_TEXT = 1000;
|
|
13
14
|
// The first line of every message PMOS types for a goal. The panel reads it to show the PM's turn as typed (public/pm/goal-chat.js).
|
|
14
|
-
const MARK = { grill: '[PMOS /goal]', start: '[PMOS /goal start]', cancel: '[PMOS /goal cancel]' };
|
|
15
|
+
const MARK = { grill: '[PMOS /goal]', start: '[PMOS /goal start]', cancel: '[PMOS /goal cancel]', method: '[PMOS /goal method]', plan: '[PMOS /goal plan]', skip: '[PMOS /goal skip]', unskip: '[PMOS /goal unskip]' };
|
|
16
|
+
/* The questioning methods Claude picks from (Wawan, 2026-10-25: SMART is one method, not the only one). Each names the points it needs; the
|
|
17
|
+
* dots row over a question has one dot per point. public/pm/goal-chat.js keeps the same list for the Change menu (goal-chat.test.js M1). */
|
|
18
|
+
const METHODS = [
|
|
19
|
+
{ id: 'done-criteria', name: 'Done criteria', fits: 'it ends in a deliverable, such as a document or a release', points: ['What it delivers', 'The done points', 'By when', 'What it may do'] },
|
|
20
|
+
{ id: 'pre-mortem', name: 'Pre-mortem', fits: 'a risky launch or change', points: ['What ships', 'How it could fail', 'What prevents each failure', 'By when'] },
|
|
21
|
+
{ id: 'outcome', name: 'Outcome and measure', fits: 'it moves a metric', points: ['The outcome', 'The measure and its target', 'The baseline', 'By when'] },
|
|
22
|
+
{ id: 'problem', name: 'Problem statement', fits: 'discovery, while the problem is not clear yet', points: ['The problem', 'Who has it', 'The evidence', 'What we want to learn'] },
|
|
23
|
+
{ id: 'smart', name: 'SMART', fits: 'any other goal', points: ['Specific', 'Measurable', 'Achievable', 'Relevant', 'Time-bound'] },
|
|
24
|
+
];
|
|
25
|
+
const methodOf = (id) => METHODS.find((m) => m.id === id) || null;
|
|
15
26
|
|
|
16
27
|
/** '/goal Ship X' → { text: 'Ship X' }; '/goal' → { text: '' }; anything else → null. */
|
|
17
28
|
function parseCommand(s) {
|
|
@@ -23,18 +34,37 @@ function grillPrompt(text) {
|
|
|
23
34
|
return [
|
|
24
35
|
MARK.grill + ' The PM set a goal: ' + text,
|
|
25
36
|
'',
|
|
26
|
-
'
|
|
27
|
-
'1.
|
|
28
|
-
|
|
29
|
-
'
|
|
30
|
-
'
|
|
37
|
+
'Agree this goal with the PM before any work. Do not start the work: nothing runs until the PM presses Start on the page.',
|
|
38
|
+
'1. Pick the questioning method that fits this goal best, from this list. The page shows your pick in one line, and the PM can change it.',
|
|
39
|
+
...METHODS.map((m) => ' - ' + m.id + ' (' + m.name + '): when ' + m.fits + '. Its points: ' + m.points.join('; ') + '.'),
|
|
40
|
+
'2. Read the records first (this repository\'s planning/ folder, its initiatives and OKRs, open pull requests where you can) and fill what you can of the method\'s points. Done points are always checkable.',
|
|
41
|
+
'3. Ask the PM only about the points you could not fill. One question per message, at most 5 questions in all. Each question offers 2 or 3 short answers; mark one as recommended. The PM can also type their own answer.',
|
|
42
|
+
'4. Stop asking when every point is agreed, after 5 questions, or when the PM says "start with defaults". A value the PM did not give takes a sensible default and is listed in "assumed".',
|
|
43
|
+
'5. If the goal needs something you cannot do here (for example sending mail that is not set up), say so and propose what you can do instead.',
|
|
44
|
+
'6. A message that starts with ' + MARK.method + ' changes the method: keep what is already agreed where it fits, and ask from there. A message that starts with ' + MARK.plan + ' is the plan as the PM edited it.',
|
|
31
45
|
'',
|
|
32
46
|
'End every message of this exchange with one fenced code block with the language tag pmos-goal, holding one JSON object. The page draws it; keep the words before it short.',
|
|
33
|
-
'- While asking: {"step":"question","
|
|
34
|
-
'- When ready: {"step":"ready","draft":{...}}',
|
|
35
|
-
'The draft: {"goal":"one sentence","done":["checkable point", "..."],"may":"what you may do","serves":"initiative or KR","by":"deadline, ISO 8601 date and time","limit":' + LIMIT + ',"assumed":["by"]}. Leave out the keys you do not know yet.',
|
|
47
|
+
'- While asking: {"step":"question","method":"done-criteria","why":"it ends in a document","points":[{"name":"What it delivers","agreed":true},{"name":"The done points","agreed":false}],"question":"What must be true for it to be done?","options":[{"label":"PR green and checklist ticked","recommended":true},{"label":"PR merged"}],"draft":{...what is known so far}}',
|
|
48
|
+
'- When ready: {"step":"ready","method":"done-criteria","points":[...every point, agreed],"draft":{...}}',
|
|
49
|
+
'"why" is a few words on why the method fits this goal. The draft: {"goal":"one sentence","done":["checkable point", "..."],"may":"what you may do","serves":"initiative or KR","by":"deadline, ISO 8601 date and time","limit":' + LIMIT + ',"assumed":["by"]}. Leave out the keys you do not know yet.',
|
|
36
50
|
].join('\n');
|
|
37
51
|
}
|
|
52
|
+
/** The PM's Change on the method line: the message the panel sends. Unknown ids give null. */
|
|
53
|
+
function methodMessage(id) {
|
|
54
|
+
const m = methodOf(id); if (!m) return null;
|
|
55
|
+
return MARK.method + ' Use the ' + m.name + ' method for this goal instead. Its points: ' + m.points.join('; ') + '. Keep what is already agreed where it fits, and ask from there.';
|
|
56
|
+
}
|
|
57
|
+
/** The plan as the PM edited it in place. running: the goal works, so the change applies after the current step. */
|
|
58
|
+
function planMessage(draft, running = false) {
|
|
59
|
+
return [
|
|
60
|
+
MARK.plan + ' The PM changed the plan in place' + (running ? ' while you work. Apply it after your current step.' : '.'),
|
|
61
|
+
JSON.stringify(draft),
|
|
62
|
+
running ? 'Work to this plan from now on. Do not repeat it back.'
|
|
63
|
+
: 'Read it again. Write one line only if a done point has no way to check it; otherwise write nothing but the block. End with a ready pmos-goal block that holds exactly this plan.',
|
|
64
|
+
].join('\n');
|
|
65
|
+
}
|
|
66
|
+
const skipMessage = (point) => MARK.skip + ' The PM skipped the done point "' + point + '". Drop it after your current step and do not work on it. It no longer counts.';
|
|
67
|
+
const unskipMessage = (point) => MARK.unskip + ' The PM took the skip back: the done point "' + point + '" counts again.';
|
|
38
68
|
|
|
39
69
|
function startMessage(draft) {
|
|
40
70
|
return [
|
|
@@ -71,10 +101,14 @@ function goalOf(runtimeDir, key) {
|
|
|
71
101
|
if (!e || e.key !== key) continue;
|
|
72
102
|
if (e.event === 'grilling') g = { id: e.id, state: 'grilling', text: e.text, at: e.at };
|
|
73
103
|
else if (!g || e.id !== g.id) continue;
|
|
74
|
-
else if (e.event === 'started') g = { ...g, state: 'started', draft: e.draft, startedAt: e.at, rounds: 0, met: [], open: (e.draft && e.draft.done) || [], at: e.at };
|
|
104
|
+
else if (e.event === 'started') g = { ...g, state: 'started', draft: e.draft, startedAt: e.at, roundAt: e.at, rounds: 0, met: [], open: (e.draft && e.draft.done) || [], at: e.at };
|
|
75
105
|
else if (e.event === 'cancelled') g = { ...g, state: 'cancelled', at: e.at };
|
|
76
|
-
else if (e.event === 'round') g = { ...g, rounds: e.n, met: e.met || [], open: e.open || [], at: e.at };
|
|
106
|
+
else if (e.event === 'round') g = { ...g, rounds: e.n, met: e.met || [], open: e.open || [], at: e.at, roundAt: e.at };
|
|
77
107
|
else if (e.event === 'seen') g = { ...g, seen: true };
|
|
108
|
+
else if (e.event === 'planned') g = { ...g, plan: e.draft, planAt: e.at }; // the PM's in-place edit before Start
|
|
109
|
+
else if (e.event === 'edited') g = { ...g, draft: e.draft, open: ((e.draft && e.draft.done) || []).filter((x) => !(g.met || []).includes(x)) }; // ... and while it works
|
|
110
|
+
else if (e.event === 'skip') g = { ...g, skipped: [...new Set((g.skipped || []).concat(e.point))], skipAt: { ...(g.skipAt || {}), [e.point]: e.at } };
|
|
111
|
+
else if (e.event === 'unskip') g = { ...g, skipped: (g.skipped || []).filter((x) => x !== e.point) };
|
|
78
112
|
else if (e.event === 'resumed') g = { ...g, state: 'started', reason: undefined, at: e.at };
|
|
79
113
|
else if (['done', 'stopped', 'waiting'].includes(e.event)) g = { ...g, state: e.event, ...(e.reason ? { reason: e.reason } : {}), met: e.met || g.met, open: e.open || g.open, at: e.at };
|
|
80
114
|
}
|
|
@@ -96,7 +130,9 @@ function statesAt(runtimeDir) {
|
|
|
96
130
|
* goal done or needs the PM, at the deadline, after the round limit, or after NO_PROGRESS rounds that met no new point.
|
|
97
131
|
* The done check is Claude's own report (a pmos-goal progress block), so the page calls it unverified. */
|
|
98
132
|
const NO_PROGRESS = 3;
|
|
99
|
-
|
|
133
|
+
/** The done points that still count: the draft's, less the ones the PM skipped. */
|
|
134
|
+
const requiredOf = (g) => ((g.draft && g.draft.done) || []).filter((x) => !(g.skipped || []).includes(x));
|
|
135
|
+
const REASON = { deadline: 'The deadline has passed.', limit: 'It used all its rounds.', 'no-progress': 'Three rounds in a row met no new done point.', pm: 'You stopped it.', replaced: 'You replaced it with a new goal.' };
|
|
100
136
|
/** The last fenced pmos-goal block in a message, parsed, or null. */
|
|
101
137
|
function blockOf(text) {
|
|
102
138
|
const re = /```pmos-goal[^\n]*\n([\s\S]*?)```/g;
|
|
@@ -120,9 +156,9 @@ const roundsOf = (runtimeDir, id) => {
|
|
|
120
156
|
function onStop({ runtimeDir, key, message, now = new Date() }) {
|
|
121
157
|
const g = key && goalOf(runtimeDir, key);
|
|
122
158
|
if (!g || g.state !== 'started' || !g.draft) return {};
|
|
123
|
-
const d = g.draft, b = blockOf(message), all =
|
|
124
|
-
const met = (b && b.step === 'progress' && strs(b.met)) || g.met || [];
|
|
125
|
-
const open = (b && b.step === 'progress' && strs(b.open)) || all.filter((x) => !met.includes(x));
|
|
159
|
+
const d = g.draft, b = blockOf(message), all = requiredOf(g), skipped = g.skipped || [];
|
|
160
|
+
const met = ((b && b.step === 'progress' && strs(b.met)) || g.met || []).filter((x) => !skipped.includes(x));
|
|
161
|
+
const open = ((b && b.step === 'progress' && strs(b.open)) || all.filter((x) => !met.includes(x))).filter((x) => !skipped.includes(x));
|
|
126
162
|
const base = { id: g.id, key, met, open, at: now.toISOString() };
|
|
127
163
|
if (b && b.step === 'progress' && (b.state === 'done' || (open.length === 0 && met.length > 0))) { append(runtimeDir, { event: 'done', ...base }); return {}; }
|
|
128
164
|
if (b && b.step === 'progress' && b.state === 'needs-you') { append(runtimeDir, { event: 'waiting', ...base }); return {}; }
|
|
@@ -163,7 +199,7 @@ function goalRowsAt(runtimeDir, now = Date.now()) {
|
|
|
163
199
|
if (!g || !g.draft || !ROW_TITLE[g.state] || g.seen) continue;
|
|
164
200
|
const at = Date.parse(g.at || '');
|
|
165
201
|
if (Number.isFinite(at) && now - at > ROW_DAYS * 86400000) continue;
|
|
166
|
-
const all = g
|
|
202
|
+
const all = requiredOf(g), met = (g.met || []).filter((x) => all.includes(x)).length;
|
|
167
203
|
const why = g.state === 'stopped' ? (REASON[g.reason] || 'It stopped.') : g.state === 'waiting' ? 'Claude asked you something in the conversation.' : 'Claude reports every done point met. It checked its own work.';
|
|
168
204
|
out.push({
|
|
169
205
|
kind: 'goal', key: 'goal:' + key, chatKey: key, goalState: g.state, title: ROW_TITLE[g.state], subject: clip(g.draft.goal, 90),
|
|
@@ -175,7 +211,7 @@ function goalRowsAt(runtimeDir, now = Date.now()) {
|
|
|
175
211
|
say: clip(g.draft.goal, 200) + ': ' + why, head: 'The goal',
|
|
176
212
|
facts: [['State', ROW_TITLE[g.state]], ['Done points', met + ' of ' + all.length + ' met, unverified'], ['By', g.draft.by], ['Rounds', String(g.rounds || 0)]].filter((x) => x[1]),
|
|
177
213
|
opts: [], sel: null, nodef: 'The goal card is in the conversation beside this. Write there to answer Claude or to go on.',
|
|
178
|
-
pane: { label: 'Goal', file: 'goal-runs.jsonl', h: clip(g.draft.goal, 90), intro: why, rows:
|
|
214
|
+
pane: { label: 'Goal', file: 'goal-runs.jsonl', h: clip(g.draft.goal, 90), intro: why, rows: (g.draft.done || []).map((x) => [(g.skipped || []).includes(x) ? 'Skipped' : (g.met || []).includes(x) ? 'Met' : 'Open', x]), paras: [] },
|
|
179
215
|
},
|
|
180
216
|
});
|
|
181
217
|
}
|
|
@@ -215,30 +251,58 @@ function begin({ runtimeDir, key, text, now = new Date() }) {
|
|
|
215
251
|
if (!t) return { error: 'Write the goal after /goal, for example: /goal Ship the Board metrics card.' };
|
|
216
252
|
if (t.length > MAX_TEXT) return { error: 'The goal is too long (' + MAX_TEXT + ' characters at most).' };
|
|
217
253
|
const id = 'goal-' + crypto.randomBytes(6).toString('hex');
|
|
254
|
+
// one goal runs in a chat at a time: the panel asks first (In a new chat, or Here instead); a /goal that lands here replaces the working one
|
|
255
|
+
const cur = goalOf(runtimeDir, key);
|
|
256
|
+
if (cur && (cur.state === 'started' || cur.state === 'waiting')) append(runtimeDir, { event: 'stopped', reason: 'replaced', id: cur.id, key, at: now.toISOString() });
|
|
218
257
|
append(runtimeDir, { event: 'grilling', id, key, text: t, at: now.toISOString() });
|
|
219
258
|
return { id, prompt: grillPrompt(t) };
|
|
220
259
|
}
|
|
221
260
|
|
|
222
261
|
const fail = (status, error) => ({ status, body: { ok: false, error } });
|
|
223
|
-
/** The PM's Start or Cancel on the
|
|
224
|
-
|
|
262
|
+
/** The PM's presses on the goal: Start or Cancel on the plan card, Stop, the plan edited in place (plan), a done point skipped or kept
|
|
263
|
+
* (skip, unskip), and a working goal replaced by a new /goal here (replace). sessions: { alive(id), type(id, text), keys?(id, k) };
|
|
264
|
+
* session: the key's chat session id. */
|
|
265
|
+
const ACTS = ['start', 'cancel', 'stop', 'plan', 'skip', 'unskip', 'replace'];
|
|
266
|
+
function decide({ runtimeDir, key, id, act, draft, point, session, sessions, now = new Date() }) {
|
|
225
267
|
if (!runtimeDir) return fail(409, 'this workspace has no state folder to keep the goal in');
|
|
226
|
-
if (!
|
|
268
|
+
if (!ACTS.includes(act)) return fail(400, 'act must be one of ' + ACTS.join(', '));
|
|
227
269
|
const g = goalOf(runtimeDir, key);
|
|
228
270
|
if (!g || g.id !== id) return fail(404, 'That goal is not the one this conversation is on.');
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
271
|
+
const at = now.toISOString(), working = g.state === 'started' || g.state === 'waiting';
|
|
272
|
+
const alive = !!(session && sessions && sessions.alive(session));
|
|
273
|
+
if (act === 'stop' || act === 'replace') { // U5: the PM's Stop on a working goal: Esc in the session, and the goal ends
|
|
274
|
+
if (act === 'stop' ? g.state !== 'started' : !working) return fail(409, 'This goal is not working.');
|
|
275
|
+
if (alive && sessions.keys) sessions.keys(session, '\x1b');
|
|
276
|
+
append(runtimeDir, { event: 'stopped', reason: act === 'stop' ? 'pm' : 'replaced', id, key, at });
|
|
233
277
|
return { status: 200, body: { ok: true, id, state: 'stopped' } };
|
|
234
278
|
}
|
|
279
|
+
if (act === 'skip' || act === 'unskip') {
|
|
280
|
+
if (!working) return fail(409, 'Only a working goal has points to skip.');
|
|
281
|
+
const p = clip(point, 200), all = (g.draft && g.draft.done) || [], skipped = g.skipped || [];
|
|
282
|
+
if (!all.includes(p)) return fail(400, 'That point is not in this goal.');
|
|
283
|
+
if (act === 'skip' && (skipped.includes(p) || (g.met || []).includes(p))) return fail(409, 'That point is already ' + (skipped.includes(p) ? 'skipped.' : 'met.'));
|
|
284
|
+
if (act === 'skip' && requiredOf(g).length <= 1) return fail(409, 'A goal keeps at least one done point. Stop it instead.');
|
|
285
|
+
if (act === 'unskip' && !skipped.includes(p)) return fail(409, 'That point is not skipped.');
|
|
286
|
+
if (act === 'unskip' && Date.parse((g.skipAt || {})[p] || '') <= Date.parse(g.roundAt || '')) return fail(409, 'Claude has already dropped that point. Tell Claude to pick it up again.');
|
|
287
|
+
// a queued instruction: typed while Claude works, so Claude reads it after its current step
|
|
288
|
+
if (!alive || !sessions.type(session, act === 'skip' ? skipMessage(p) : unskipMessage(p))) return fail(409, 'The message did not reach the session. Open it in Sessions.');
|
|
289
|
+
append(runtimeDir, { event: act, point: p, id, key, at });
|
|
290
|
+
return { status: 200, body: { ok: true, id, state: g.state } };
|
|
291
|
+
}
|
|
292
|
+
if (act === 'plan') { // the plan edited in place: before Start it is the newest plan; while it works it applies after the current step
|
|
293
|
+
if (g.state !== 'grilling' && !working) return fail(409, 'This goal has ended. Send /goal to set a new one.');
|
|
294
|
+
const d = cleanDraft(draft); if (!d) return fail(400, 'The plan needs a sentence and at least one done point.');
|
|
295
|
+
if (!alive || !sessions.type(session, planMessage(d, working))) return fail(409, 'The message did not reach the session. Open it in Sessions.');
|
|
296
|
+
append(runtimeDir, { event: working ? 'edited' : 'planned', id, key, draft: d, at });
|
|
297
|
+
return { status: 200, body: { ok: true, id, state: g.state } };
|
|
298
|
+
}
|
|
235
299
|
if (g.state !== 'grilling') return fail(409, g.state === 'cancelled' ? 'This goal was cancelled.' : 'This goal has already started.');
|
|
236
|
-
if (!
|
|
300
|
+
if (!alive) return fail(409, 'No session is running for this conversation. Send /goal again to start one.');
|
|
237
301
|
let d = null;
|
|
238
302
|
if (act === 'start') { d = cleanDraft(draft); if (!d) return fail(400, 'The goal needs a sentence and at least one done point before it can start.'); }
|
|
239
303
|
if (!sessions.type(session, act === 'start' ? startMessage(d) : cancelMessage())) return fail(409, 'The message did not reach the session. Open it in Sessions.');
|
|
240
|
-
append(runtimeDir, { event: act === 'start' ? 'started' : 'cancelled', id, key, ...(d ? { draft: d } : {}), at
|
|
304
|
+
append(runtimeDir, { event: act === 'start' ? 'started' : 'cancelled', id, key, ...(d ? { draft: d } : {}), at });
|
|
241
305
|
return { status: 200, body: { ok: true, id, state: act === 'start' ? 'started' : 'cancelled' } };
|
|
242
306
|
}
|
|
243
307
|
|
|
244
|
-
module.exports = { parseCommand, grillPrompt, startMessage, cancelMessage, cleanDraft, goalOf, statesAt, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, askToolReply, ASK_TOOL, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
|
|
308
|
+
module.exports = { parseCommand, grillPrompt, methodMessage, planMessage, skipMessage, unskipMessage, METHODS, startMessage, cancelMessage, cleanDraft, goalOf, statesAt, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, askToolReply, ASK_TOOL, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* mention-cli.js — `pmos mention …`: Home's Mentions from a terminal (canvas XmsDeskRefine, agreed A+).
|
|
3
|
+
* pmos mention list [--json] what waits on you, oldest first, then the last 7 days
|
|
4
|
+
* pmos mention draft <id> --text "<reply>" | --file <path|-> [--json] change the proposed reply the Mentions Viewer shows
|
|
5
|
+
* Claude runs `draft` from the chat where the PM changes a reply ("Reply to Arif"): the Viewer shows the new reply on its next read.
|
|
6
|
+
* The mark is one line in <runtime>/mentions/marks.jsonl with by: agent. This command posts nothing: the PM sends the reply where the
|
|
7
|
+
* mention is. */
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const stateRoot = require('./state-root');
|
|
11
|
+
const store = require('./mention-store.js');
|
|
12
|
+
|
|
13
|
+
const COMMANDS = { mention: ['list', 'draft'] };
|
|
14
|
+
const USAGE = [
|
|
15
|
+
'usage: pmos mention list|draft — Home\'s Mentions',
|
|
16
|
+
' pmos mention list what waits on you, oldest first, then the last 7 days',
|
|
17
|
+
' pmos mention draft <id> --text "<reply>" change the proposed reply of one mention (or --file <path|->)',
|
|
18
|
+
' every command: [--json]',
|
|
19
|
+
'This command never posts. You send the reply where the mention is.',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function parseArgs(argv) {
|
|
23
|
+
const out = { _: [] };
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const t = argv[i];
|
|
26
|
+
if (!t.startsWith('--')) { out._.push(t); continue; }
|
|
27
|
+
const key = t.slice(2);
|
|
28
|
+
if (key === 'json' || key === 'help') out[key] = true;
|
|
29
|
+
else if (argv[i + 1] !== undefined) out[key] = argv[++i];
|
|
30
|
+
else out[key] = '';
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function run(argv, { say = console.log, env = process.env, stateDir, cwd = process.cwd(), now = () => new Date(), stdin } = {}) {
|
|
36
|
+
const a = parseArgs(argv.slice(1));
|
|
37
|
+
const sub = a._[0];
|
|
38
|
+
const out = (o, line) => { if (a.json) say(JSON.stringify(o)); else say(line); };
|
|
39
|
+
if (!sub || a.help || sub === 'help') { USAGE.forEach((l) => say(l)); return sub || a.help ? 0 : 2; }
|
|
40
|
+
if (!COMMANDS.mention.includes(sub)) { say(`✗ pmos mention ${sub} is not a command`); USAGE.forEach((l) => say(l)); return 2; }
|
|
41
|
+
const dir = stateDir || stateRoot.defaultRoot({ env });
|
|
42
|
+
|
|
43
|
+
if (sub === 'list') {
|
|
44
|
+
const v = require('./routes-mentions.js').answer(dir, { now: now().getTime(), cwd });
|
|
45
|
+
if (a.json) { say(JSON.stringify(v)); return 0; }
|
|
46
|
+
if (!v.waiting.length && !v.recent.length) { say('Nobody mentioned you in the last 7 days.'); return 0; }
|
|
47
|
+
say(v.waiting.length ? `${v.waiting.length} wait on your reply` : 'Nothing waits on you');
|
|
48
|
+
for (const m of v.waiting) say(` ${m.id} ${m.who || m.source} · ${m.where || m.source} · since ${m.since || '?'}${m.count > 1 ? ' · ' + m.count + ' asks' : ''}: ${m.text}`);
|
|
49
|
+
if (v.recent.length) say('Last 7 days');
|
|
50
|
+
for (const m of v.recent) say(` ${m.id} ${m.who || m.source} · ${m.where || m.source}${m.status ? ' · ' + m.status : ''}: ${m.text}`);
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
// draft
|
|
54
|
+
const id = a._[1];
|
|
55
|
+
if (!id || !/^[0-9a-f]{12}$/.test(id)) { out({ ok: false, error: 'the mention id is 12 hex characters (pmos mention list shows it)' }, '✗ the mention id is 12 hex characters (pmos mention list shows it)'); return 2; }
|
|
56
|
+
let text = a.text;
|
|
57
|
+
if (text === undefined && a.file !== undefined) {
|
|
58
|
+
try { text = a.file === '-' ? (stdin !== undefined ? stdin : fs.readFileSync(0, 'utf8')) : fs.readFileSync(path.resolve(cwd, a.file), 'utf8'); }
|
|
59
|
+
catch (e) { out({ ok: false, error: `could not read ${a.file}: ${e.message}` }, `✗ could not read ${a.file}`); return 1; }
|
|
60
|
+
}
|
|
61
|
+
if (typeof text !== 'string' || !text.trim()) { out({ ok: false, error: '--text "<reply>" or --file <path|-> is required' }, '✗ --text "<reply>" or --file <path|-> is required'); return 2; }
|
|
62
|
+
const known = JSON.parse(JSON.stringify(require('./routes-mentions.js').answer(dir, { now: now().getTime(), cwd })));
|
|
63
|
+
if (![...known.waiting, ...known.recent].some((m) => m.id === id)) { out({ ok: false, error: `no mention ${id}` }, `✗ no mention ${id}. pmos mention list shows them.`); return 1; }
|
|
64
|
+
const r = store.mark(dir, { id, act: 'draft', text }, now(), 'agent');
|
|
65
|
+
if (!r.ok) { out(r, `✗ refused: ${r.error}`); return 1; }
|
|
66
|
+
out({ ok: true, id }, `saved the proposed reply of ${id}. The Mentions Viewer shows it; you send it where the mention is.`);
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { run, COMMANDS, USAGE };
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/* mention-store.js — the PM's mentions for Home's Mentions (premium-agreed-design; canvas XmsMentionsGrill, XmsDeskList/One/Refine, agreed A+).
|
|
3
|
+
*
|
|
4
|
+
* WHY ITS OWN STORE. The brief holds at most 30 items, shared by priorities, worth asking and mentions, so a busy day crowded the mentions
|
|
5
|
+
* out, and Home showed only today's. A source read (source-reads.js) is replaced whole by the next read. So every mention a read or a brief
|
|
6
|
+
* carries is copied here, and kept while it waits on the PM (whatever its age) or for 14 days after it stopped waiting.
|
|
7
|
+
*
|
|
8
|
+
* ingestRead(runtimeDir, record) a source read just saved (source-reads.js write calls it): its items that say `mention: true`
|
|
9
|
+
* ingestBrief(runtimeDir, brief) a brief's mention items: they add what the brief judged (found, draft, initiative)
|
|
10
|
+
* mark(runtimeDir, { id, act, until?, task?, text?, to? }, now, by) one appended line in <runtime>/mentions/marks.jsonl; by: 'pm' | 'agent'
|
|
11
|
+
* view(runtimeDir, { now, me, missing }) → { ok, waiting, recent, count, gaps, as_of } what GET /api/mentions answers
|
|
12
|
+
* build(entries, marks, { now, me }) → { waiting, recent } the pure part of view
|
|
13
|
+
* ACTS · MENTION_SOURCES · keyOf(source, link, title)
|
|
14
|
+
*
|
|
15
|
+
* A MENTION waits on the PM when it asks something (reply_needed, not @channel, @here, a team handle or a bot) and an ask in its thread is
|
|
16
|
+
* newer than everything that covered it: the PM's own reply in the thread (a message by the PM's name, or the read's `replied: true`),
|
|
17
|
+
* Mark answered, Not an ask, or Make it a task. A new ask after any of these makes it wait again; its age counts from that ask.
|
|
18
|
+
* Remind me tomorrow hides it until 09:00 the next morning. Nothing here posts anywhere: PMOS never replies for the PM.
|
|
19
|
+
*
|
|
20
|
+
* FILES (per-user runtime folder, never a repository): mentions/store.json (replaced whole, atomic rename) and mentions/marks.jsonl
|
|
21
|
+
* (append-only; the last line for an id and act wins; 'undo' takes back that id's last mark). mentions/read.jsonl (routes-mentions.js)
|
|
22
|
+
* still says which FYIs the PM opened. */
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
const crypto = require('crypto');
|
|
26
|
+
|
|
27
|
+
const MENTION_SOURCES = Object.freeze(['slack', 'jira', 'confluence', 'mail']);
|
|
28
|
+
const ACTS = Object.freeze(['answered', 'notask', 'snooze', 'task', 'keep', 'drafted', 'draft', 'read', 'closed', 'undo']);
|
|
29
|
+
const NOT_UNDONE = new Set(['read', 'draft', 'closed']); // what Undo never takes back: opening, Claude's reply, a task closed by a reply
|
|
30
|
+
const DAY = 86400000;
|
|
31
|
+
const KEEP_DAYS = 14; // a mention that stopped waiting is kept this long (Last 7 days shows 7 of them)
|
|
32
|
+
const MAX_WAIT_DAYS = 365; // an ask older than this is dropped, waiting or not
|
|
33
|
+
const MAX = 600;
|
|
34
|
+
const ID_RE = /^[0-9a-f]{12}$/;
|
|
35
|
+
const clip = (s, n) => { const t = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return t.length > n ? t.slice(0, n - 1).trimEnd() + '…' : t; };
|
|
36
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
37
|
+
|
|
38
|
+
/** The id of a mention: the source and its link (else its title), as source-reads.js ids an item, so a read and a brief agree. */
|
|
39
|
+
function keyOf(source, link, title) { return crypto.createHash('sha1').update(String(source) + '\n' + String(link || title || '')).digest('hex').slice(0, 12); }
|
|
40
|
+
|
|
41
|
+
/** A message time as ISO: an ISO time as it is; "HH:MM" on the day of `ref` (the day before when that is later than `ref`). null when neither. */
|
|
42
|
+
function timeOf(at, ref) {
|
|
43
|
+
const s = String(at == null ? '' : at).trim(); if (!s) return null;
|
|
44
|
+
const hm = /^(\d{1,2}):(\d{2})$/.exec(s);
|
|
45
|
+
const r = new Date(ref || Date.now());
|
|
46
|
+
if (hm) {
|
|
47
|
+
const d = new Date(r.getFullYear(), r.getMonth(), r.getDate(), +hm[1], +hm[2]);
|
|
48
|
+
if (d.getTime() > r.getTime() + 60000) d.setDate(d.getDate() - 1);
|
|
49
|
+
return d.toISOString();
|
|
50
|
+
}
|
|
51
|
+
const t = Date.parse(s);
|
|
52
|
+
return Number.isFinite(t) ? new Date(t).toISOString() : null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const dirOf = (rt) => path.join(rt, 'mentions');
|
|
56
|
+
const storeFile = (rt) => path.join(dirOf(rt), 'store.json');
|
|
57
|
+
const marksFile = (rt) => path.join(dirOf(rt), 'marks.jsonl');
|
|
58
|
+
const readsFile = (rt) => path.join(dirOf(rt), 'read.jsonl');
|
|
59
|
+
|
|
60
|
+
function load(rt) {
|
|
61
|
+
try { const j = JSON.parse(fs.readFileSync(storeFile(rt), 'utf8')); return j && typeof j.items === 'object' && j.items ? j.items : {}; } catch { return {}; }
|
|
62
|
+
}
|
|
63
|
+
function save(rt, items) {
|
|
64
|
+
const f = storeFile(rt);
|
|
65
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
66
|
+
const tmp = `${f}.${process.pid}.${Date.now()}.tmp`;
|
|
67
|
+
fs.writeFileSync(tmp, JSON.stringify({ v: 1, items }) + '\n');
|
|
68
|
+
fs.renameSync(tmp, f);
|
|
69
|
+
}
|
|
70
|
+
function lines(file) {
|
|
71
|
+
try { return fs.readFileSync(file, 'utf8').split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean); } catch { return []; }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** One mention as the store keeps it, from a read or brief item. `ref` is when it was read (for "HH:MM" times). */
|
|
75
|
+
function entryOf(x, source, ref, o = {}) {
|
|
76
|
+
const thread = (Array.isArray(x.thread) ? x.thread : []).filter((m) => m && (m.text || m.who))
|
|
77
|
+
.map((m) => ({ who: clip(m.who || '', 80), at: timeOf(m.at, ref), text: clip(m.text || '', 400) }));
|
|
78
|
+
const e = {
|
|
79
|
+
id: o.id || (ID_RE.test(String(x.id || '')) && !o.brief ? x.id : keyOf(source, x.link, x.title)),
|
|
80
|
+
source, who: clip(x.who || '', 120), where: clip(x.where || '', 120), title: clip(x.title || '', 140),
|
|
81
|
+
text: clip(x.quote || x.ask || x.about || x.title || '', 280), ask: clip(x.ask || '', 240), about: clip(x.about || '', 480),
|
|
82
|
+
at: timeOf(x.at, ref), seen: new Date(ref).toISOString(), reply_needed: x.reply_needed === true,
|
|
83
|
+
broadcast: x.broadcast === true || x.bot === true, thread,
|
|
84
|
+
};
|
|
85
|
+
if (/^https:\/\/\S+$/i.test(String(x.link || '')) && String(x.link).length <= 500) e.link = x.link;
|
|
86
|
+
if (typeof x.initiative_id === 'string' && x.initiative_id) e.initiative = x.initiative_id;
|
|
87
|
+
if (x.replied === true) { e.replied = true; e.replied_seen = e.seen; }
|
|
88
|
+
return e;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** What a brief item adds: What I found (refs and checks) and the proposed reply (send.suggest). */
|
|
92
|
+
function briefExtras(x) {
|
|
93
|
+
const found = [];
|
|
94
|
+
for (const r of Array.isArray(x.refs) ? x.refs : []) {
|
|
95
|
+
if (!r || !r.label) continue;
|
|
96
|
+
const f = { label: clip(r.label, 120), text: clip((Array.isArray(r.lines) ? r.lines : []).join(' '), 240) };
|
|
97
|
+
if (/^https:\/\/\S+$/.test(String(r.link || ''))) f.link = r.link;
|
|
98
|
+
found.push(f);
|
|
99
|
+
}
|
|
100
|
+
for (const c of Array.isArray(x.checks) ? x.checks : []) { const t = clip(typeof c === 'string' ? c : c && c.text, 240); if (t) found.push({ text: t }); }
|
|
101
|
+
const out = {};
|
|
102
|
+
if (found.length) out.found = found.slice(0, 6);
|
|
103
|
+
const sug = x.send && Array.isArray(x.send.suggest) ? x.send.suggest.find((s) => typeof s === 'string' && s.trim()) : null;
|
|
104
|
+
if (sug) out.draft = clip(sug, 900);
|
|
105
|
+
if (x.send && x.send.to) out.send_to = clip(x.send.to, 120);
|
|
106
|
+
if (x.why_now) out.why = clip(x.why_now, 240);
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Merge a newer copy of a mention into the stored one: the newer fields win, the thread keeps every message once, in time order. */
|
|
111
|
+
function merge(old, nu) {
|
|
112
|
+
if (!old) return nu;
|
|
113
|
+
const out = { ...old };
|
|
114
|
+
for (const [k, v] of Object.entries(nu)) {
|
|
115
|
+
if (k === 'thread' || k === 'seen') continue;
|
|
116
|
+
if (v === '' || v == null || (Array.isArray(v) && !v.length)) continue;
|
|
117
|
+
out[k] = v;
|
|
118
|
+
}
|
|
119
|
+
out.first_seen = old.first_seen || old.seen;
|
|
120
|
+
out.seen = nu.seen > (old.seen || '') ? nu.seen : old.seen;
|
|
121
|
+
const seen = new Set(); const th = [];
|
|
122
|
+
for (const m of [...(old.thread || []), ...(nu.thread || [])]) { const k = (m.who || '') + '|' + (m.at || '') + '|' + m.text; if (seen.has(k)) continue; seen.add(k); th.push(m); }
|
|
123
|
+
th.sort((a, b) => (Date.parse(a.at || '') || 0) - (Date.parse(b.at || '') || 0));
|
|
124
|
+
out.thread = th.slice(-8);
|
|
125
|
+
// the read said the PM replied: every ask up to that read is answered (a later ask makes it wait again)
|
|
126
|
+
if (nu.replied) { out.replied = true; out.replied_seen = nu.seen; }
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function upsert(rt, list) {
|
|
131
|
+
if (!rt || !list.length) return 0;
|
|
132
|
+
const items = load(rt);
|
|
133
|
+
const byLink = new Map(Object.values(items).filter((x) => x.link).map((x) => [x.source + '\n' + x.link, x.id]));
|
|
134
|
+
for (const e0 of list) {
|
|
135
|
+
// the same conversation from a read and from a brief is one mention, whatever id each gave it
|
|
136
|
+
const e = e0.link && byLink.has(e0.source + '\n' + e0.link) ? { ...e0, id: byLink.get(e0.source + '\n' + e0.link) } : e0;
|
|
137
|
+
if (e.link) byLink.set(e.source + '\n' + e.link, e.id);
|
|
138
|
+
const was = items[e.id]; items[e.id] = merge(was, { ...e, first_seen: was ? was.first_seen || was.seen : e.seen }); }
|
|
139
|
+
// pruned against the newest read, so a store nobody read for weeks keeps what it had
|
|
140
|
+
save(rt, prune(items, Math.max(...Object.values(items).map((x) => T(x.seen)))));
|
|
141
|
+
return list.length;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function ingestRead(rt, rec) {
|
|
145
|
+
if (!rt || !rec || rec.state !== 'read' || !MENTION_SOURCES.includes(rec.source)) return 0;
|
|
146
|
+
const ref = Date.parse(rec.read_at) || Date.now();
|
|
147
|
+
return upsert(rt, (rec.items || []).filter((x) => x && x.mention).map((x) => entryOf(x, rec.source, ref)));
|
|
148
|
+
}
|
|
149
|
+
function ingestBrief(rt, brief) {
|
|
150
|
+
if (!rt || !brief) return 0;
|
|
151
|
+
const ref = Date.parse(brief.generated_at || brief.created_at || '') || (brief.date ? Date.parse(brief.date + 'T12:00:00') : Date.now());
|
|
152
|
+
const list = [];
|
|
153
|
+
for (const k of ['priorities', 'worth_asking', 'items']) for (const x of Array.isArray(brief[k]) ? brief[k] : []) {
|
|
154
|
+
if (!x || !x.mention || !MENTION_SOURCES.includes(x.source)) continue;
|
|
155
|
+
const ex = briefExtras(x);
|
|
156
|
+
if (ex.draft) ex.draft_at = new Date(ref).toISOString();
|
|
157
|
+
list.push({ ...entryOf(x, x.source, ref, { brief: true }), ...ex });
|
|
158
|
+
}
|
|
159
|
+
return upsert(rt, list);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* ── marks ── */
|
|
163
|
+
function mark(rt, b, now = new Date(), by = 'pm') {
|
|
164
|
+
if (!b || !ID_RE.test(String(b.id || ''))) return { ok: false, error: 'id must be a mention id (12 hex characters)' };
|
|
165
|
+
if (!ACTS.includes(b.act)) return { ok: false, error: 'act must be one of ' + ACTS.join(', ') };
|
|
166
|
+
const line = { id: b.id, act: b.act, by: by === 'agent' ? 'agent' : 'pm', at: now.toISOString() };
|
|
167
|
+
if (b.act === 'snooze') {
|
|
168
|
+
const u = b.until ? Date.parse(b.until) : NaN;
|
|
169
|
+
line.until = Number.isFinite(u) ? new Date(u).toISOString() : nineTomorrow(now).toISOString();
|
|
170
|
+
}
|
|
171
|
+
if (b.act === 'task') {
|
|
172
|
+
if (!b.task || typeof b.task !== 'object') return { ok: false, error: 'task must say where the task is: { id, ws?, board?, initiative?, kind }' };
|
|
173
|
+
line.task = { id: clip(b.task.id, 80), kind: b.task.kind === 'board' ? 'board' : 'item', ws: b.task.ws ? clip(b.task.ws, 80) : undefined, board: b.task.board ? clip(b.task.board, 80) : undefined, initiative: b.task.initiative ? clip(b.task.initiative, 80) : undefined, title: clip(b.task.title || '', 200) };
|
|
174
|
+
if (!line.task.id) return { ok: false, error: 'task.id is required' };
|
|
175
|
+
}
|
|
176
|
+
if (b.act === 'draft') {
|
|
177
|
+
if (typeof b.text !== 'string' || !b.text.trim()) return { ok: false, error: 'text is the reply, one to 900 characters' };
|
|
178
|
+
if (b.text.length > 900) return { ok: false, error: 'the reply is over 900 characters: say it shorter' };
|
|
179
|
+
line.text = b.text.trim();
|
|
180
|
+
}
|
|
181
|
+
if (b.act === 'drafted' && b.to) line.to = clip(b.to, 120);
|
|
182
|
+
fs.mkdirSync(dirOf(rt), { recursive: true });
|
|
183
|
+
fs.appendFileSync(marksFile(rt), JSON.stringify(line) + '\n');
|
|
184
|
+
return { ok: true, mark: line };
|
|
185
|
+
}
|
|
186
|
+
function nineTomorrow(now) { const d = new Date(now); d.setDate(d.getDate() + 1); d.setHours(9, 0, 0, 0); return d; }
|
|
187
|
+
|
|
188
|
+
/** The marks per id: the last of each act, after the undos took theirs back. Pure. */
|
|
189
|
+
function foldMarks(list) {
|
|
190
|
+
const per = new Map();
|
|
191
|
+
for (const m of list || []) {
|
|
192
|
+
if (!m || !ID_RE.test(String(m.id || '')) || !ACTS.includes(m.act)) continue;
|
|
193
|
+
if (!per.has(m.id)) per.set(m.id, []);
|
|
194
|
+
const st = per.get(m.id);
|
|
195
|
+
if (m.act === 'undo') { for (let i = st.length - 1; i >= 0; i--) if (!NOT_UNDONE.has(st[i].act)) { st.splice(i, 1); break; } continue; }
|
|
196
|
+
st.push(m);
|
|
197
|
+
}
|
|
198
|
+
const out = new Map();
|
|
199
|
+
for (const [id, st] of per) { const o = {}; for (const m of st) o[m.act] = m; out.set(id, o); }
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/* ── the view ── */
|
|
204
|
+
const T = (iso) => (iso ? Date.parse(iso) || 0 : 0);
|
|
205
|
+
function isMe(who, me) {
|
|
206
|
+
const w = String(who || '').trim().toLowerCase(); if (!w) return false;
|
|
207
|
+
if (w === 'me' || w === 'you' || w === 'pm') return true;
|
|
208
|
+
return (me || []).some((n) => n && (w === n || w.split(/\s+/)[0] === n));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** One mention judged: waiting or not, since when, how many asks, and what covered it. Pure. */
|
|
212
|
+
function judge(e, mk, now, me) {
|
|
213
|
+
const th = e.thread || [];
|
|
214
|
+
const asker = (m) => !isMe(m.who, me) && (!e.who || !m.who || m.who === e.who);
|
|
215
|
+
const askTimes = th.filter((m) => m.at && asker(m)).map((m) => T(m.at)).filter(Boolean);
|
|
216
|
+
if (!askTimes.length) askTimes.push(T(e.at) || T(e.first_seen) || T(e.seen));
|
|
217
|
+
askTimes.sort((a, b) => a - b);
|
|
218
|
+
const mine = th.filter((m) => m.at && isMe(m.who, me)).map((m) => T(m.at));
|
|
219
|
+
const lastMe = mine.length ? Math.max(...mine) : 0;
|
|
220
|
+
// the read's replied: true covers every ask the store knew when that read came
|
|
221
|
+
const before = e.replied ? askTimes.filter((t) => t <= T(e.replied_seen) + 1) : [];
|
|
222
|
+
const repliedUpto = before.length ? Math.max(...before) : 0;
|
|
223
|
+
const cover = [['replied', Math.max(lastMe, repliedUpto)], ['answered', mk.answered ? T(mk.answered.at) : 0], ['notask', mk.notask ? T(mk.notask.at) : 0], ['task', mk.task ? T(mk.task.at) : 0]];
|
|
224
|
+
const upto = Math.max(...cover.map((c) => c[1]));
|
|
225
|
+
const how = upto ? cover.filter((c) => c[1] === upto)[0][0] : '';
|
|
226
|
+
const pending = askTimes.filter((t) => t > upto);
|
|
227
|
+
const ask = e.reply_needed && !e.broadcast;
|
|
228
|
+
const snoozed = mk.snooze && T(mk.snooze.until) > now && T(mk.snooze.at) >= (pending[pending.length - 1] || 0);
|
|
229
|
+
const waiting = ask && pending.length > 0 && !snoozed;
|
|
230
|
+
const since = pending.length ? pending[0] : 0;
|
|
231
|
+
const last = Math.max(askTimes[askTimes.length - 1] || 0, lastMe, ...['answered', 'notask', 'task'].map((k) => (mk[k] ? T(mk[k].at) : 0)));
|
|
232
|
+
return { ask, waiting, snoozed: !!snoozed, since, count: pending.length, last, how: ask && !pending.length ? how : '', lastMe };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function rowOf(e, j, mk, reads, now) {
|
|
236
|
+
const r = { id: e.id, source: e.source, who: e.who, where: e.where, text: e.text, ask: e.ask || undefined, about: e.about || undefined, link: e.link,
|
|
237
|
+
initiative: e.initiative, waiting: j.waiting, since: j.since ? new Date(j.since).toISOString() : null, last: j.last ? new Date(j.last).toISOString() : null,
|
|
238
|
+
count: j.count, fyi: !j.ask, broadcast: !!e.broadcast, thread: e.thread && e.thread.length ? e.thread : undefined };
|
|
239
|
+
if (!j.waiting && j.how) r.status = j.how; // replied | answered | notask | task
|
|
240
|
+
if (mk.task) r.task = mk.task.task;
|
|
241
|
+
if (mk.closed) r.task_closed = true;
|
|
242
|
+
const d = mk.draft && (!e.draft_at || T(mk.draft.at) >= T(e.draft_at)) ? mk.draft.text : e.draft;
|
|
243
|
+
if (d) r.draft = d;
|
|
244
|
+
if (e.found) r.found = e.found;
|
|
245
|
+
if (e.why) r.why = e.why;
|
|
246
|
+
if (e.send_to) r.send_to = e.send_to;
|
|
247
|
+
if (mk.drafted && T(mk.drafted.at) >= j.since) r.drafted = mk.drafted.to || true;
|
|
248
|
+
if (j.waiting && j.since && now - j.since >= 30 * DAY && !(mk.keep && now - T(mk.keep.at) < 30 * DAY)) r.check = true; // asks once: "Did you answer this already?"
|
|
249
|
+
r.read = (reads && reads.get(e.id) === true) || !!mk.read;
|
|
250
|
+
return r;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** The pure view. entries: the store's mentions; marks: marks.jsonl lines; o: { now, me: [lower-case names], reads: Map id → read }. */
|
|
254
|
+
function build(entries, marks, o = {}) {
|
|
255
|
+
const now = o.now || Date.now();
|
|
256
|
+
const me = (o.me || []).map((n) => String(n).toLowerCase());
|
|
257
|
+
const mks = foldMarks(marks);
|
|
258
|
+
const start = new Date(now); start.setHours(0, 0, 0, 0); start.setDate(start.getDate() - 6);
|
|
259
|
+
const waiting = []; const recent = [];
|
|
260
|
+
for (const e of entries || []) {
|
|
261
|
+
if (!e || !ID_RE.test(String(e.id || ''))) continue;
|
|
262
|
+
const mk = mks.get(e.id) || {};
|
|
263
|
+
const j = judge(e, mk, now, me);
|
|
264
|
+
if (j.snoozed) continue; // Remind me tomorrow: hidden until then
|
|
265
|
+
const r = rowOf(e, j, mk, o.reads, now);
|
|
266
|
+
if (j.waiting) waiting.push(r);
|
|
267
|
+
else if (j.last >= start.getTime()) recent.push(r);
|
|
268
|
+
}
|
|
269
|
+
// oldest first; a tie: a direct message or a ticket first, then by time
|
|
270
|
+
const direct = (r) => (/\bDM\b|direct/i.test(r.where || '') || r.source === 'jira' ? 0 : 1);
|
|
271
|
+
waiting.sort((a, b) => T(a.since) - T(b.since) || direct(a) - direct(b) || T(a.last) - T(b.last));
|
|
272
|
+
recent.sort((a, b) => T(b.last) - T(a.last));
|
|
273
|
+
return { waiting, recent };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Drop what nobody needs: stopped waiting and quiet for KEEP_DAYS, or older than MAX_WAIT_DAYS. Keeps at most MAX. */
|
|
277
|
+
function prune(items, now, marks = []) {
|
|
278
|
+
const mks = foldMarks(marks);
|
|
279
|
+
const keep = Object.values(items).filter((e) => {
|
|
280
|
+
const j = judge(e, mks.get(e.id) || {}, now, []);
|
|
281
|
+
const age = now - (j.last || T(e.seen));
|
|
282
|
+
if (now - T(e.first_seen || e.seen) > MAX_WAIT_DAYS * DAY && age > KEEP_DAYS * DAY) return false;
|
|
283
|
+
return j.waiting || age <= KEEP_DAYS * DAY || T(e.seen) > now - KEEP_DAYS * DAY;
|
|
284
|
+
}).sort((a, b) => T(b.seen) - T(a.seen)).slice(0, MAX);
|
|
285
|
+
return Object.fromEntries(keep.map((e) => [e.id, e]));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** GET /api/mentions. o: { now, me, missing: [{ source, state, why }], reads: { source: read } (the stored source reads, ingested first),
|
|
289
|
+
* brief (today's brief, ingested too) }. */
|
|
290
|
+
function view(rt, o = {}) {
|
|
291
|
+
const now = o.now || Date.now();
|
|
292
|
+
for (const r of Object.values(o.reads || {})) { try { ingestRead(rt, r); } catch { /* a bad read is skipped */ } }
|
|
293
|
+
if (o.brief) { try { ingestBrief(rt, o.brief); } catch { /* the same */ } }
|
|
294
|
+
const reads = new Map();
|
|
295
|
+
for (const l of lines(readsFile(rt))) if (l && ID_RE.test(String(l.id || '')) && typeof l.read === 'boolean') reads.set(l.id, l.read);
|
|
296
|
+
const { waiting, recent } = build(Object.values(load(rt)), lines(marksFile(rt)), { now, me: o.me, reads });
|
|
297
|
+
// honest gaps, said once at the end: a mention source not reached, and a check that has not run today
|
|
298
|
+
const gaps = [];
|
|
299
|
+
for (const m of o.missing || []) if (MENTION_SOURCES.includes(m.source) && m.state !== 'off') gaps.push({ kind: 'source', source: m.source, state: m.state });
|
|
300
|
+
const readAt = Object.values(o.reads || {}).filter((r) => r && MENTION_SOURCES.includes(r.source) && r.state === 'read').map((r) => T(r.read_at)).filter(Boolean);
|
|
301
|
+
const as_of = readAt.length ? new Date(Math.max(...readAt)).toISOString() : null;
|
|
302
|
+
const day0 = new Date(now); day0.setHours(0, 0, 0, 0);
|
|
303
|
+
if (as_of && T(as_of) < day0.getTime()) gaps.push({ kind: 'stale', upto: as_of });
|
|
304
|
+
return { ok: true, waiting, recent, count: waiting.length, gaps, as_of, now: new Date(now).toISOString() };
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
module.exports = { MENTION_SOURCES, ACTS, keyOf, timeOf, entryOf, briefExtras, merge, ingestRead, ingestBrief, mark, foldMarks, judge, build, prune, view, nineTomorrow, _files: { storeFile, marksFile } };
|
|
@@ -56,6 +56,9 @@ const VERBS = Object.freeze({
|
|
|
56
56
|
// Not a pm-os-absorb verb (run: null): briefing-source-flow added it through the same table.
|
|
57
57
|
source: Object.freeze({ module: 'source-cli.js', run: null, guide: 'data-freshness.md',
|
|
58
58
|
help: 'pmos source save|status|show — the stored read of each tool the Briefing uses: Mail, Slack, Confluence and the rest (pmos source help)' }),
|
|
59
|
+
// Not a pm-os-absorb verb (run: null): Home's Mentions A+ (premium-agreed-design) added it through the same table.
|
|
60
|
+
mention: Object.freeze({ module: 'mention-cli.js', run: null, guide: 'home.md',
|
|
61
|
+
help: 'pmos mention list|draft — Home\'s Mentions: what waits on you, and the proposed reply Claude changes from a chat (pmos mention help)' }),
|
|
59
62
|
// Not a pm-os-absorb verb (run: null): the popup context work (premium-chat-session slice 7) added it through the same table.
|
|
60
63
|
lead: Object.freeze({ module: 'lead-cli.js', run: null, guide: 'briefing-premium.md',
|
|
61
64
|
help: 'pmos lead put|show|due — Claude\'s short lead for a popup, written ahead from stored reads (pmos lead help)' }),
|