create-pmos 0.410.0 → 0.412.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 +2 -2
- package/workspace/briefing-premium-initiative-test.js +9 -15
- package/workspace/briefing-premium-insights-test.js +2 -2
- package/workspace/briefing-premium-test.js +3 -3
- package/workspace/changelog.json +24 -0
- package/workspace/chat-asks-test.js +146 -0
- package/workspace/guide/board.md +1 -1
- package/workspace/guide/breakdown.md +6 -13
- package/workspace/guide/briefing-premium.md +1 -1
- package/workspace/guide/home.md +24 -0
- package/workspace/guide/index.md +1 -1
- package/workspace/guide/initiative-driver.md +1 -1
- package/workspace/guide/initiatives-screen.md +1 -1
- package/workspace/guide/pm-only-acts.md +23 -24
- package/workspace/guide/today.md +1 -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/briefing-premium-writes.js +5 -4
- package/workspace/lib/coredoc-cli.js +1 -1
- package/workspace/lib/driver-cli.js +2 -1
- package/workspace/lib/driver-decide.js +3 -2
- package/workspace/lib/driver.js +2 -1
- package/workspace/lib/engine/boards.js +3 -1
- package/workspace/lib/goal-chat.js +94 -30
- package/workspace/lib/grant-mint.js +3 -2
- package/workspace/lib/initiative-cli.js +9 -9
- package/workspace/lib/issues.js +5 -4
- package/workspace/lib/mention-cli.js +70 -0
- package/workspace/lib/mention-store.js +307 -0
- package/workspace/lib/people-store.js +1 -1
- package/workspace/lib/people.js +3 -1
- package/workspace/lib/placements.js +13 -15
- package/workspace/lib/plan-items.js +17 -48
- package/workspace/lib/pm-guard.js +18 -5
- package/workspace/lib/pm-lines-needs.js +9 -5
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/report-cli.js +2 -2
- package/workspace/lib/routes-board-metric-targets.js +0 -1
- package/workspace/lib/routes-boards.js +12 -0
- package/workspace/lib/routes-briefing-premium.js +5 -7
- package/workspace/lib/routes-core-docs.js +0 -1
- package/workspace/lib/routes-custom-docs.js +0 -1
- package/workspace/lib/routes-driver.js +0 -1
- package/workspace/lib/routes-home-desk.js +1 -1
- package/workspace/lib/routes-home-review.js +1 -1
- package/workspace/lib/routes-initiative-layout.js +1 -1
- package/workspace/lib/routes-insights-records.js +0 -1
- package/workspace/lib/routes-meeting-material.js +0 -1
- package/workspace/lib/routes-mentions.js +62 -9
- package/workspace/lib/routes-onboarding.js +3 -1
- package/workspace/lib/routes-orchestrator.js +0 -1
- package/workspace/lib/routes-premium-charts.js +0 -1
- package/workspace/lib/routes-premium-dashboards.js +0 -1
- package/workspace/lib/routes-programs.js +1 -1
- package/workspace/lib/routes-records.js +1 -1
- package/workspace/lib/routes-report-design.js +7 -3
- package/workspace/lib/routes-report-setups.js +0 -1
- package/workspace/lib/routes-report-structure.js +0 -1
- package/workspace/lib/routes-runs.js +2 -5
- package/workspace/lib/routes-scan.js +0 -1
- package/workspace/lib/routes-sources.js +1 -1
- package/workspace/lib/run-answers.js +14 -5
- package/workspace/lib/scan-cli.js +2 -1
- package/workspace/lib/scan.js +2 -1
- 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/lib/vendor/scripts/onboarding/proposals.js +7 -3
- 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-core-doc-issue-test.js +1 -1
- package/workspace/premium-viewer-share-test.js +5 -2
- 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/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 +68 -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 +2 -2
- 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 +7 -2
- package/workspace/public/pm/premium-initiative-head.js +8 -4
- 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/replaced-tests.json +101 -0
- package/workspace/server.js +133 -20
- 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
|
@@ -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 } };
|
|
@@ -128,7 +128,7 @@ const noteId = () => 'n-' + crypto.randomBytes(6).toString('base64').replace(/[^
|
|
|
128
128
|
*/
|
|
129
129
|
function decide(root, { actor, body, now = Date.now() } = {}) {
|
|
130
130
|
const by = actor && typeof actor.by === 'string' ? actor.by : null;
|
|
131
|
-
if (!by || !/^pm:/.test(by)) return { ok: false, error: 'only the PM decides who is a person' };
|
|
131
|
+
if (!by || !/^(?:pm|agent):/.test(by)) return { ok: false, error: 'only the PM or an agent session decides who is a person' }; // D98
|
|
132
132
|
const b = body && typeof body === 'object' ? { ...body } : {};
|
|
133
133
|
if (b.act === 'note' && !b.id) b.id = noteId();
|
|
134
134
|
const c = P.checkDecision(b);
|
package/workspace/lib/people.js
CHANGED
|
@@ -36,6 +36,7 @@ const DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
|
|
|
36
36
|
const ID_RE = /^[a-z0-9][a-z0-9-]{0,59}$/;
|
|
37
37
|
const NOTE_ID_RE = /^n-[0-9a-z]{4,16}$/;
|
|
38
38
|
const PM_BY_RE = /^pm:[a-z0-9_-]{1,40}$/;
|
|
39
|
+
const AGENT_BY_RE = /^agent:(?:unknown|sess-\d+\.[0-9a-f]{8})$/;
|
|
39
40
|
const TONE_WINDOW = 10;
|
|
40
41
|
|
|
41
42
|
const isObj = (x) => !!x && typeof x === 'object' && !Array.isArray(x);
|
|
@@ -221,7 +222,8 @@ function matchPeople(people, hay) {
|
|
|
221
222
|
|
|
222
223
|
const sightKey = (r) => [handleKey(r.handle), r.interaction ? r.interaction.date : '', r.interaction ? r.interaction.pointer : '', r.interaction ? r.interaction.text : ''].join('\u0000');
|
|
223
224
|
const pairKey = (a, b) => [handleKey(a), handleKey(b)].sort().join('\u0000');
|
|
224
|
-
|
|
225
|
+
// D98: a decision by the PM or an agent session takes effect; the row keeps who decided.
|
|
226
|
+
const isPm = (r) => typeof r.by === 'string' && (PM_BY_RE.test(r.by) || AGENT_BY_RE.test(r.by));
|
|
225
227
|
const DECISION_KINDS = new Set(['add', 'ignore', 'remove', 'merge', 'keep-separate', 'edit', 'tone', 'note', 'note-remove', 'setting']);
|
|
226
228
|
|
|
227
229
|
/**
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
* --json) the day-one derivation (R26) reads; `rules` is lib/plan-rules.js readRules(root). A consumer that needs a
|
|
19
19
|
* horizon reads it through horizonOf, never from the file.
|
|
20
20
|
*
|
|
21
|
-
* The actor is never chosen by the caller of a route: the route takes it from pm-guard.js (Move to Now, adopt
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* The actor is never chosen by the caller of a route: the route takes it from pm-guard.js (Move to Now, adopt) or
|
|
22
|
+
* actor.js (every other press); the CLI from actor.fromCli or requirePmCli. D98: an agent's line applies like the PM's
|
|
23
|
+
* (Now and adopt included) and keeps the agent's `by`, so the PM sees who moved what and can move it back. The writer
|
|
24
|
+
* no longer writes `proposed: true`; such a line from before D98 stays a proposal until it is adopted or dropped.
|
|
24
25
|
*
|
|
25
26
|
* THE `placed` LINE (the shared contract; 2C may add events, never change this one):
|
|
26
27
|
* { v: 1, eid, ev: 'placed', initiative, horizon: 'now'|'next'|'later', after: <initiative id> | null,
|
|
@@ -32,10 +33,10 @@
|
|
|
32
33
|
* { ev: 'created', initiative, from?: 'capture-YYYY-MM-DD-<n>' } the initiative writer's landing line: top of
|
|
33
34
|
* Later, so a new record never reads Now through day one (R16, R23: what an agent creates lands in Later).
|
|
34
35
|
* Any actor; only for an initiative with no line yet. `from` names the capture it came from (triage reads it).
|
|
35
|
-
* { ev: 'adopted', proposal: <eid> } the PM
|
|
36
|
-
* { ev: 'dropped', proposal: <eid> } the proposal is closed unapplied (the PM
|
|
37
|
-
* pmOnly(rec) → true for a line
|
|
38
|
-
* (scripts/check-pm-lines.js, 2B) asks this function and never reads the schema itself.
|
|
36
|
+
* { ev: 'adopted', proposal: <eid> } the PM or an agent keeps an open proposal: its placement applies.
|
|
37
|
+
* { ev: 'dropped', proposal: <eid> } the proposal is closed unapplied (the PM or any agent, D98).
|
|
38
|
+
* pmOnly(rec) → true for a line that was PM-only before D98: a non-proposed `placed` into Now, and `adopted`. The
|
|
39
|
+
* checker (scripts/check-pm-lines.js, 2B) asks this function and never reads the schema itself.
|
|
39
40
|
*
|
|
40
41
|
* DAY ONE (R26), with no migration. An initiative of a work lane with no line in the ledger is placed by its activity:
|
|
41
42
|
* active within `stall_days` reads Now, unconfirmed (`confirmed: false`, `source: 'day-one'`, outside any cap); every
|
|
@@ -54,9 +55,8 @@
|
|
|
54
55
|
* once, lines apply in (at, eid) order, and one eid with two contents keeps the first and flags the second. A later
|
|
55
56
|
* PM `placed` line for an initiative closes that initiative's open proposals (they are superseded, not adopted).
|
|
56
57
|
*
|
|
57
|
-
* HONEST LIMIT. The fold tells an agent's line by its `by
|
|
58
|
-
*
|
|
59
|
-
* agent is ignored and flagged. A forged `pm:` line is caught only by scripts/check-pm-lines.js (2B), not here.
|
|
58
|
+
* HONEST LIMIT. The fold tells an agent's line by its `by`, and since D98 applies it either way; the `by` is the
|
|
59
|
+
* record of who acted. A forged `pm:` line is caught only by scripts/check-pm-lines.js (2B), not here.
|
|
60
60
|
*
|
|
61
61
|
* The ledger is one per repository: lib/plan-ledgers.js ledgerPath(root, 'placements'). Nothing is cached (D33).
|
|
62
62
|
*/
|
|
@@ -97,7 +97,9 @@ const ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
|
97
97
|
|
|
98
98
|
const isStr = (v) => typeof v === 'string';
|
|
99
99
|
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
100
|
-
|
|
100
|
+
// D98: a line by the PM or an agent session takes effect (placed, adopted, dropped); the line keeps who wrote it.
|
|
101
|
+
// A line marked `proposed` (written before D98) is still a proposal until someone adopts or drops it.
|
|
102
|
+
const isPmBy = (by) => isStr(by) && (by.startsWith('pm:') || by.startsWith('agent:'));
|
|
101
103
|
const dateOk = (v) => isStr(v) && DATE_RE.test(v) && !Number.isNaN(Date.parse(v + 'T00:00:00Z'))
|
|
102
104
|
&& new Date(v + 'T00:00:00Z').toISOString().slice(0, 10) === v;
|
|
103
105
|
|
|
@@ -355,7 +357,6 @@ function buildRecord(root, ev, i, actor, state) {
|
|
|
355
357
|
if (!has(CALLER_KEYS, ev.ev)) return refuse(400, `ev must be one of ${EVENTS.join(', ')}`, i);
|
|
356
358
|
const extra = Object.keys(ev).filter((k) => k !== 'ev' && !CALLER_KEYS[ev.ev].includes(k));
|
|
357
359
|
if (extra.length) return refuse(400, `a ${ev.ev} line has no field ${extra.join(', ')}`, i);
|
|
358
|
-
const agent = !actorLib.isPm(actor);
|
|
359
360
|
const rec = { ev: ev.ev };
|
|
360
361
|
if (ev.ev === 'placed' || ev.ev === 'created') {
|
|
361
362
|
if (!isStr(ev.initiative) || !INIT_RE.test(ev.initiative)) return refuse(400, 'initiative must be an initiative id', i);
|
|
@@ -373,7 +374,6 @@ function buildRecord(root, ev, i, actor, state) {
|
|
|
373
374
|
if (ev.check_by !== null && !dateOk(ev.check_by)) return refuse(400, 'check_by must be YYYY-MM-DD, or null to clear it', i);
|
|
374
375
|
rec.check_by = ev.check_by;
|
|
375
376
|
}
|
|
376
|
-
if (agent) rec.proposed = true; // an agent's placement is a proposal, whatever it names (R23)
|
|
377
377
|
} else if (ev.ev === 'created') {
|
|
378
378
|
if (has(ev, 'from')) {
|
|
379
379
|
if (!(isStr(ev.from) && CAPTURE_RE.test(ev.from))) return refuse(400, 'from must name a capture note, like capture-2026-10-04-1', i);
|
|
@@ -384,8 +384,6 @@ function buildRecord(root, ev, i, actor, state) {
|
|
|
384
384
|
if (!isStr(ev.proposal) || !EID_RE.test(ev.proposal)) return refuse(400, 'proposal must be the eid of a proposal', i);
|
|
385
385
|
const p = state.open.get(ev.proposal);
|
|
386
386
|
if (!p) return refuse(404, `${ev.proposal} is not an open proposal`, i);
|
|
387
|
-
if (ev.ev === 'adopted' && agent) return refuse(403, 'only the PM adopts a proposal', i);
|
|
388
|
-
if (ev.ev === 'dropped' && agent && actor.by !== p.by) return refuse(403, 'an agent drops only its own proposal', i);
|
|
389
387
|
rec.proposal = ev.proposal;
|
|
390
388
|
}
|
|
391
389
|
return { ok: true, rec };
|
|
@@ -16,11 +16,10 @@
|
|
|
16
16
|
*
|
|
17
17
|
* WHO IS WHO COMES FROM lib/actor.js (Run 2, slice 2A). The server route runs lib/pm-guard.js first (Origin, the
|
|
18
18
|
* per-launch nonce, writer fields; act `keep` when the call carries a Keep) and passes the guard's actor on;
|
|
19
|
-
* `pmos item` takes actor.fromCli.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* evidence (R23 "finishes"). Item-change proposals are not built (deferred, named in the run PR).
|
|
19
|
+
* `pmos item` takes actor.fromCli. D98 (amends R23): an agent finishes the work it was asked to do. Its items are live
|
|
20
|
+
* at once (never proposed, so there is nothing to Keep), and it may set, flag, move and withdraw any item, the PM's
|
|
21
|
+
* included. Every line keeps the agent's own `by`, so the PM sees who acted and can move or withdraw it back. Keep
|
|
22
|
+
* lines written before D98 name items that are already live; the fold skips them silently.
|
|
24
23
|
*
|
|
25
24
|
* HONEST LIMIT (rubric anti-optimism). A process that runs as the PM's own user can still read the nonce from the
|
|
26
25
|
* page, or fake a terminal with no PMOS_SESSION, and be recorded as the PM. The fold flags a `kept` line whose `via`
|
|
@@ -36,7 +35,6 @@ const { createSinkGuard } = require('./sink.js');
|
|
|
36
35
|
const planTree = require('./plan-tree.js');
|
|
37
36
|
const consoleState = require('./console-state');
|
|
38
37
|
const actorLib = require('./actor.js');
|
|
39
|
-
const stateRoot = require('./state-root');
|
|
40
38
|
|
|
41
39
|
const LEDGER = 'plan-items.jsonl';
|
|
42
40
|
const EVENTS = ['planned', 'set', 'moved', 'flagged', 'withdrawn', 'kept'];
|
|
@@ -268,7 +266,7 @@ function freshItem(rec) {
|
|
|
268
266
|
after: rec.after.slice(), start: rec.start, due: rec.due, milestone: rec.milestone, note: rec.note == null ? '' : rec.note,
|
|
269
267
|
state: 'todo', blocked: null, evidence: null, noEvidence: false, doneAt: null,
|
|
270
268
|
movedBy: null, movedVia: null, override: false, overrideShown: false,
|
|
271
|
-
proposed:
|
|
269
|
+
proposed: false, kept: false, // D98: an agent's item is live at once; nothing waits for a Keep
|
|
272
270
|
createdBy: rec.by, createdVia: rec.via, createdAt: rec.at,
|
|
273
271
|
updatedBy: rec.by, updatedVia: rec.via, updatedAt: rec.at,
|
|
274
272
|
history: [],
|
|
@@ -303,9 +301,10 @@ function applyLine(S, rec, n) {
|
|
|
303
301
|
}
|
|
304
302
|
if (rec.ev === 'kept') {
|
|
305
303
|
if (rec.via !== 'ui') { flag(S, 'kept-not-ui', rec, n, `a Keep line was written with via "${rec.via}", not from the workspace page — it has no effect`); return; }
|
|
306
|
-
if (!rec.by.startsWith('pm:')) { flag(S, 'kept-not-pm', rec, n, `a Keep line was written by ${rec.by}, not the PM — it has no effect`); return; }
|
|
307
304
|
for (const id of rec.items) {
|
|
308
305
|
const it = S.items.get(id);
|
|
306
|
+
// A Keep written before D98: the item is already live (agent items are no longer proposed), so it needs nothing.
|
|
307
|
+
if (it && !it.proposed && it.createdBy === rec.batch && it.initiative === rec.initiative) continue;
|
|
309
308
|
if (!it || !it.proposed || it.createdBy !== rec.batch || it.initiative !== rec.initiative) {
|
|
310
309
|
S.flags.push({ kind: 'kept-mismatch', line: n == null ? null : n, eid: rec.eid, item: id, initiative: rec.initiative,
|
|
311
310
|
message: `${id} is not a proposed item of ${rec.batch} on ${rec.initiative} — this part of the Keep has no effect` });
|
|
@@ -482,8 +481,6 @@ function actorFromCli(opts = {}) {
|
|
|
482
481
|
|
|
483
482
|
// ── the writer ────────────────────────────────────────────────────────────────────────────────────
|
|
484
483
|
const refuse = (status, error, index) => ({ ok: false, status, error, index: index == null ? null : index });
|
|
485
|
-
const PM_ITEM_HINT = 'this item is the PM\'s (owner you) — an agent does not change it; ask the PM';
|
|
486
|
-
const PM_MOVE_HINT = 'this item is the PM\'s (owner you) and the PM did not hand it to this session — ask the PM to hand it to you';
|
|
487
484
|
|
|
488
485
|
/** Does adding `from → each of after` make a loop in the predecessor graph of `items`? */
|
|
489
486
|
function makesLoop(items, from, after) {
|
|
@@ -505,7 +502,7 @@ function makesLoop(items, from, after) {
|
|
|
505
502
|
* The record's keys are emitted common-first, then the payload, in the order of the plan's §1.2.
|
|
506
503
|
*/
|
|
507
504
|
function buildRecord(ctx, ev, index) {
|
|
508
|
-
const { S, actor, allowKept, root, stagesCache, nextAt
|
|
505
|
+
const { S, actor, allowKept, root, stagesCache, nextAt } = ctx;
|
|
509
506
|
if (!ev || typeof ev !== 'object' || Array.isArray(ev)) return refuse(400, 'each line must be an object', index);
|
|
510
507
|
for (const k of WRITER_FIELDS) if (k in ev) return refuse(400, `field ${k} is set by the writer`, index);
|
|
511
508
|
if (!EVENTS.includes(ev.ev)) return refuse(400, `unknown event ${JSON.stringify(ev.ev)} — one of ${EVENTS.join(', ')}`, index);
|
|
@@ -529,8 +526,6 @@ function buildRecord(ctx, ev, index) {
|
|
|
529
526
|
Object.assign(rec, { initiative, by: actor.by, via: actor.via, at: nextAt(floor) });
|
|
530
527
|
return rec;
|
|
531
528
|
};
|
|
532
|
-
// R23 (X35): the PM's items (owner `you`) are the PM's to change. An agent asks; it does not set or flag them.
|
|
533
|
-
const agentOnPmItem = (it) => actor.by.startsWith('agent:') && it.owner === 'you';
|
|
534
529
|
const stagesOf = (initiative) => {
|
|
535
530
|
if (!stagesCache.has(initiative)) stagesCache.set(initiative, planTree.stagesFor(root, initiative));
|
|
536
531
|
return stagesCache.get(initiative);
|
|
@@ -603,7 +598,6 @@ function buildRecord(ctx, ev, index) {
|
|
|
603
598
|
case 'set': {
|
|
604
599
|
const ex = existing(); if (ex.ok === false) return ex;
|
|
605
600
|
const { it, init } = ex;
|
|
606
|
-
if (agentOnPmItem(it)) return refuse(403, PM_ITEM_HINT, index);
|
|
607
601
|
const f = ev.fields;
|
|
608
602
|
if (!f || typeof f !== 'object' || Array.isArray(f) || !Object.keys(f).length) return refuse(400, 'fields must name at least one of ' + SET_FIELDS.join(', '), index);
|
|
609
603
|
const out = {};
|
|
@@ -629,7 +623,6 @@ function buildRecord(ctx, ev, index) {
|
|
|
629
623
|
const ex = existing(); if (ex.ok === false) return ex;
|
|
630
624
|
const { it, init } = ex;
|
|
631
625
|
if (!STATES.includes(ev.to)) return refuse(400, `to must be one of ${STATES.join(', ')}`, index);
|
|
632
|
-
if (agentOnPmItem(it) && !handedTo(it.id)) return refuse(403, PM_MOVE_HINT, index);
|
|
633
626
|
/* done → done with evidence attaches it to an item that reads Done without evidence: the way to correct an agent
|
|
634
627
|
* Done that forgot --evidence, from the CLI or the item sheet. Any other same-state move is refused. */
|
|
635
628
|
const attach = ev.to === 'done' && it.state === 'done' && ev.evidence != null && (it.noEvidence || !it.evidence);
|
|
@@ -652,7 +645,6 @@ function buildRecord(ctx, ev, index) {
|
|
|
652
645
|
case 'flagged': {
|
|
653
646
|
const ex = existing(); if (ex.ok === false) return ex;
|
|
654
647
|
const { it, init } = ex;
|
|
655
|
-
if (agentOnPmItem(it)) return refuse(403, PM_ITEM_HINT, index);
|
|
656
648
|
if (ev.blocked === true) {
|
|
657
649
|
if (!oneLine(ev.reason, 200)) return refuse(400, 'a block reason is 1 to 200 characters on one line', index);
|
|
658
650
|
const rec = common(init, it.id, it.updatedAt);
|
|
@@ -670,11 +662,7 @@ function buildRecord(ctx, ev, index) {
|
|
|
670
662
|
}
|
|
671
663
|
case 'withdrawn': {
|
|
672
664
|
const ex = existing(); if (ex.ok === false) return ex;
|
|
673
|
-
|
|
674
|
-
* The PM's items, and another session's, are the PM's to withdraw. */
|
|
675
|
-
if (actor.by.startsWith('agent:') && ex.it.createdBy !== actor.by) {
|
|
676
|
-
return refuse(403, 'an agent withdraws only the items it planned — the PM withdraws the rest', index);
|
|
677
|
-
}
|
|
665
|
+
// D98: any actor withdraws any item; the line names who did it.
|
|
678
666
|
return { rec: common(ex.init, ex.it.id, ex.it.updatedAt) };
|
|
679
667
|
}
|
|
680
668
|
case 'kept': {
|
|
@@ -714,7 +702,7 @@ function parseEvidence(s) {
|
|
|
714
702
|
return { kind: m[1], ref: m[2] };
|
|
715
703
|
}
|
|
716
704
|
|
|
717
|
-
function append(root, events, actor, { now, allowKept
|
|
705
|
+
function append(root, events, actor, { now, allowKept }) {
|
|
718
706
|
if (!Array.isArray(events) || !events.length) return refuse(400, 'send at least one line', null);
|
|
719
707
|
if (events.length > MAX_LINES) return refuse(413, `send at most ${MAX_LINES} lines at once`, null);
|
|
720
708
|
let read;
|
|
@@ -744,7 +732,7 @@ function append(root, events, actor, { now, allowKept, handedTo = () => false })
|
|
|
744
732
|
last = t;
|
|
745
733
|
return new Date(t).toISOString();
|
|
746
734
|
};
|
|
747
|
-
const ctx = { S, actor, allowKept, root, stagesCache: new Map(), nextAt
|
|
735
|
+
const ctx = { S, actor, allowKept, root, stagesCache: new Map(), nextAt };
|
|
748
736
|
const recs = [];
|
|
749
737
|
for (let i = 0; i < events.length; i++) {
|
|
750
738
|
let r;
|
|
@@ -772,37 +760,20 @@ function append(root, events, actor, { now, allowKept, handedTo = () => false })
|
|
|
772
760
|
|
|
773
761
|
/**
|
|
774
762
|
* The workspace page's route. The only path that accepts `kept`. The route passes the actor lib/pm-guard.js answered;
|
|
775
|
-
* with none, actor.fromUi().
|
|
763
|
+
* with none, actor.fromUi(). D98: an agent session's call through the route keeps its own `by`; the line says `ui`.
|
|
776
764
|
*/
|
|
777
765
|
function appendFromUi(root, events, { now, actor } = {}) {
|
|
778
766
|
const who = actor === undefined ? actorLib.fromUi() : actor;
|
|
779
|
-
if (!actorLib.
|
|
767
|
+
if (!actorLib.valid(who)) return refuse(403, 'the page writes only after the guard', null);
|
|
780
768
|
return append(root, events, { by: who.by, via: 'ui' }, { now, allowKept: true });
|
|
781
769
|
}
|
|
782
770
|
/** `pmos item`. The actor comes from the terminal and PMOS_SESSION, never from an argument. Refuses `kept`. */
|
|
783
|
-
function appendFromCli(root, events, { now, isTTY, env
|
|
771
|
+
function appendFromCli(root, events, { now, isTTY, env } = {}) {
|
|
784
772
|
const opts = {};
|
|
785
773
|
if (isTTY !== undefined) opts.isTTY = isTTY;
|
|
786
774
|
if (env !== undefined) opts.env = env;
|
|
787
775
|
const who = actorFromCli(opts);
|
|
788
|
-
return append(root, events, who, { now, allowKept: false
|
|
789
|
-
}
|
|
790
|
-
/**
|
|
791
|
-
* itemId → true when the PM handed that item to the actor's session (R23). The session meta lives in the workspace's
|
|
792
|
-
* runtime state (`<state root>/sessions`), resolved from the environment the way the server resolves it; a test passes
|
|
793
|
-
* `sessDir`. The meta is read at most once per call.
|
|
794
|
-
*/
|
|
795
|
-
function handedToSession(who, env, sessDir) {
|
|
796
|
-
const token = actorLib.sessionOf(who);
|
|
797
|
-
if (!token) return () => false;
|
|
798
|
-
let s;
|
|
799
|
-
return (itemId) => {
|
|
800
|
-
if (s === undefined) {
|
|
801
|
-
const dir = sessDir || path.join(stateRoot.defaultRoot({ env: env || process.env }), 'sessions');
|
|
802
|
-
s = actorLib.sessionForToken(token, { sessDir: dir });
|
|
803
|
-
}
|
|
804
|
-
return !!s && s.plan_item === itemId;
|
|
805
|
-
};
|
|
776
|
+
return append(root, events, who, { now, allowKept: false });
|
|
806
777
|
}
|
|
807
778
|
|
|
808
779
|
// ── needs-you rows (Keep cards, agent Done with no evidence, forged Keep lines) ─────────────────────
|
|
@@ -823,11 +794,9 @@ function needsFor(root, { now } = {}) {
|
|
|
823
794
|
question: `"${it.title}" reads Done with no evidence`, doc: null, item: id });
|
|
824
795
|
}
|
|
825
796
|
for (const f of r.flags) {
|
|
826
|
-
if (f.kind !== 'kept-not-ui'
|
|
797
|
+
if (f.kind !== 'kept-not-ui') continue;
|
|
827
798
|
rows.push({ run_id: `plan-flag:${f.eid}`, initiative_id: f.initiative, kind: 'plan-flag', derived: true,
|
|
828
|
-
question:
|
|
829
|
-
? 'A Keep line in plan-items.jsonl was not written from the workspace page. It has no effect.'
|
|
830
|
-
: 'A Keep line in plan-items.jsonl was not written by the PM. It has no effect.',
|
|
799
|
+
question: 'A Keep line in plan-items.jsonl was not written from the workspace page. It has no effect.',
|
|
831
800
|
doc: null, flag: { kind: f.kind, eid: f.eid, line: f.line } });
|
|
832
801
|
}
|
|
833
802
|
return rows;
|