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
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
/* pm-guard.js — THE GUARDED WRITER'S FRONT DOOR: every act
|
|
3
|
-
* R25, D86 point 2).
|
|
2
|
+
/* pm-guard.js — THE GUARDED WRITER'S FRONT DOOR: every act that was PM-only passes here first (pm-os-absorb, PRD
|
|
3
|
+
* R25, D86 point 2, amended by D98).
|
|
4
|
+
*
|
|
5
|
+
* D98: an agent session finishes the work it was asked to do. It may take every act below without a typed
|
|
6
|
+
* confirmation, and the guard answers with the agent's own actor, so every line it writes says `by: agent:…` and the PM
|
|
7
|
+
* sees who acted and can return or undo it. What stays: the Origin and launch-nonce checks (another website cannot
|
|
8
|
+
* write), the writer fields, and the PM's own typed confirmation at a terminal.
|
|
4
9
|
*
|
|
5
10
|
* requirePmPress(req, body, { act }) → { ok: true, actor } | { ok: false, status, error }
|
|
6
11
|
* requirePmCli({ act, expect, isTTY, env, ask }) → Promise of the same shape
|
|
@@ -33,8 +38,10 @@
|
|
|
33
38
|
* another port, so another launch): 403. A socket request with no Host header is refused too, because there is
|
|
34
39
|
* nothing to match. Only a caller with no socket and no Host (a unit test's plain object) skips the Host match;
|
|
35
40
|
* - once server.js has called setLaunchNonce, a missing or wrong x-pmos-nonce header: 403.
|
|
36
|
-
* The terminal side
|
|
37
|
-
* that does not match
|
|
41
|
+
* The terminal side lets an agent session through at once with its own actor (D98). The PM at a terminal types `expect`;
|
|
42
|
+
* a typed text that does not match is 403, and with no `ask` function there is no way to confirm, so it is refused (X12).
|
|
43
|
+
* A request that carries an `x-pmos-session` token (an agent's hook or curl) and passes the Origin and nonce checks is
|
|
44
|
+
* answered with that agent's actor, never the PM's.
|
|
38
45
|
*
|
|
39
46
|
* RESIDUAL (named, not closed). A process that runs as the PM's own user can read the nonce from GET / and send it with
|
|
40
47
|
* an Origin that matches. A process that fakes a terminal (`script`) and types the expected id is the PM to this file.
|
|
@@ -73,6 +80,7 @@ const ACT_PHRASE = Object.freeze({
|
|
|
73
80
|
const WRITER_FIELDS = Object.freeze(['v', 'eid', 'by', 'via', 'at', 'override', 'pm', 'actor', 'nonce', 'grant']);
|
|
74
81
|
|
|
75
82
|
const NONCE_HEADER = 'x-pmos-nonce';
|
|
83
|
+
const SESSION_HEADER = 'x-pmos-session';
|
|
76
84
|
const NONCE_META = 'pmos-nonce';
|
|
77
85
|
let NONCE = '';
|
|
78
86
|
/** server.js calls this once at start (2A). The value never goes into a PTY environment or a log (D08). */
|
|
@@ -109,6 +117,10 @@ function pageChecks(req, who) {
|
|
|
109
117
|
// A wrong value is almost always a page from an earlier start of the workspace; a missing one is not the page at all.
|
|
110
118
|
if (NONCE && !h[NONCE_HEADER]) return refuse(403, `${who}; this request does not come from the workspace page`);
|
|
111
119
|
if (NONCE && h[NONCE_HEADER] !== NONCE) return refuse(403, `${who}; the workspace restarted, so reload the page, then try again`);
|
|
120
|
+
// D98: an agent session's call is allowed and keeps the agent's name on the line it writes.
|
|
121
|
+
const tok = Array.isArray(h[SESSION_HEADER]) ? h[SESSION_HEADER][0] : h[SESSION_HEADER];
|
|
122
|
+
// A header that is not a well-formed token is still an agent's call: it is agent:unknown, never the PM.
|
|
123
|
+
if (typeof tok === 'string' && tok) return { ok: true, actor: { by: actor.SESSION_RE.test(tok) ? `agent:${tok}` : 'agent:unknown', via: 'ui' } };
|
|
112
124
|
return { ok: true, actor: actor.fromUi() };
|
|
113
125
|
}
|
|
114
126
|
|
|
@@ -149,7 +161,8 @@ async function requirePmCli({ act, expect, isTTY, env, ask } = {}) {
|
|
|
149
161
|
if (!knownAct(act)) return refuse(500, `pm-guard: ${JSON.stringify(act)} is not a PM-only act`);
|
|
150
162
|
if (typeof expect !== 'string' || !expect.trim()) return refuse(500, 'pm-guard: a PM-only verb needs the text the PM must type');
|
|
151
163
|
const who = actor.fromCli({ isTTY, env });
|
|
152
|
-
|
|
164
|
+
// D98: an agent does what it was asked, with no typed confirmation; the line it writes names the agent.
|
|
165
|
+
if (actor.isAgent(who)) return { ok: true, actor: who };
|
|
153
166
|
if (!actor.isPm(who)) return refuse(403, `only the PM can ${ACT_PHRASE[act]}, at an interactive terminal`);
|
|
154
167
|
if (typeof ask !== 'function') return refuse(403, `to ${ACT_PHRASE[act]}, type a confirmation at the terminal`);
|
|
155
168
|
let typed;
|
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
* grant-mismatch a PM-only line that cites a grant that does not cover it: a lifecycle line needs a lifecycle-bulk
|
|
15
15
|
* grant whose target names its state and its initiative, and every line's `at` falls inside the grant's
|
|
16
16
|
* window (at to expires_at). A copied id of a merge grant, or of another batch, is flagged;
|
|
17
|
-
* not-pm a
|
|
18
|
-
*
|
|
17
|
+
* not-pm a line in a D86 ledger whose `by` names neither the PM nor an agent session (D98 lets an agent write
|
|
18
|
+
* these lines; its `by` is the record of who acted);
|
|
19
|
+
* agent-commit a line that claims the PM (not an agent's own `by`, D98) and arrived in an agent-authored commit (a Co-Authored-By trailer that names an agent,
|
|
19
20
|
* a session trailer, or an agent's address). This catches a line written by a script and then committed
|
|
20
21
|
* (bypass e) and a patch applied with `git apply` (bypass f).
|
|
21
22
|
* agent-basis an agent's acceptance (D87) that the Review Gate does not back: no eval row for its run, a verdict that
|
|
@@ -256,10 +257,13 @@ function scan(root, { runsDir, rules, rulesFile, now = Date.now(), arrival = tru
|
|
|
256
257
|
const why = grantMismatch(src.ledger, rec, grants.get(cites));
|
|
257
258
|
if (why) say('grant-mismatch', `${what[src.ledger](rec)} cites a grant that does not cover it`, why);
|
|
258
259
|
}
|
|
259
|
-
|
|
260
|
-
|
|
260
|
+
// D98: an agent session may write these lines; its `by` is the record of who acted, so it is not flagged.
|
|
261
|
+
if (D86.has(src.ledger) && typeof rec.by === 'string' && !/^(?:pm|agent):/.test(rec.by)) {
|
|
262
|
+
say('not-pm', `${what[src.ledger](rec)} names no PM or agent session`, 'a line whose by is neither the PM nor an agent session');
|
|
261
263
|
}
|
|
262
|
-
|
|
264
|
+
// An agent's own line (D98) arrives in an agent's commit by design; a line that claims the PM there is still flagged.
|
|
265
|
+
const ownAgentLine = typeof rec.by === 'string' && rec.by.startsWith('agent:');
|
|
266
|
+
if (a && !a.boundary && a.agent && !isOlder && !ownAgentLine) {
|
|
263
267
|
say('agent-commit', `${what[src.ledger](rec)} arrived in an agent-authored commit`, `arrived in the agent-authored commit ${a.sha.slice(0, 8)}`);
|
|
264
268
|
}
|
|
265
269
|
if (isOlder && viaMissing && src.viaChecked) olderCount++;
|
|
@@ -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)' }),
|
|
@@ -191,8 +191,8 @@ function reportWorkspace(verb, { pos, flags, root, json, say, fail, isTTY, env,
|
|
|
191
191
|
}
|
|
192
192
|
const who = actorLib.fromCli({ ...(isTTY === undefined ? {} : { isTTY }), ...(env === undefined ? {} : { env }) });
|
|
193
193
|
if (verb === 'finder') {
|
|
194
|
-
//
|
|
195
|
-
if (!actorLib.isPm(who)) return fail(
|
|
194
|
+
// D98: the PM or an agent session turns the finder or a source on or off; the line names who.
|
|
195
|
+
if (!actorLib.isPm(who) && !actorLib.isAgent(who)) return fail('only the PM or an agent session can change the report finder');
|
|
196
196
|
const file = RS.ledgerFile(root);
|
|
197
197
|
let r;
|
|
198
198
|
if (pos[0] === 'source') {
|
|
@@ -19,7 +19,6 @@ async function handle(req, res, url, ctx) {
|
|
|
19
19
|
const read = await ctx.readJson(req);
|
|
20
20
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
21
21
|
const body = read.body || {};
|
|
22
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot set a target. Only a press on the page does'));
|
|
23
22
|
const g = guard.requirePagePress(req, body);
|
|
24
23
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
25
24
|
const id = typeof body.ws === 'string' ? body.ws : '';
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
* POST /api/boards/tasks/add { ws, board, initiative, title, type?, epic?, start?, due?, owner? } → { ok, item }
|
|
28
28
|
* POST /api/boards/tasks/state { ws, board, task, state } → { ok, item }
|
|
29
29
|
* POST /api/boards/tasks/reschedule { ws, board, task, days } → { ok, item }
|
|
30
|
+
* POST /api/boards/tasks/undo-add { ws, board, task } → { ok } takes back a task added in the last 2 minutes, still To do
|
|
30
31
|
* POST /api/boards/tasks/rename { ws, board, task, title } → { ok, from, item } only the title changes
|
|
31
32
|
* POST /api/boards/archive { ws, board, id, archived, reason? } → { ok, row } archive (hidden everywhere, kept whole) or restore;
|
|
32
33
|
* restoring a merged initiative moves its epics and tasks back
|
|
@@ -976,6 +977,17 @@ const WRITES = {
|
|
|
976
977
|
const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
|
|
977
978
|
ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t2)])[0] });
|
|
978
979
|
},
|
|
980
|
+
'/api/boards/tasks/undo-add': (ctx, res, body, g) => {
|
|
981
|
+
// the Undo of a task just added (Mentions' Make it a task, XmsMentionsGrill): only a task this board made in the last 2 minutes, still To do
|
|
982
|
+
const p = postFrame(ctx, res, body);
|
|
983
|
+
if (!p) return;
|
|
984
|
+
const t = B.taskOf(p.fr.folded, body.task);
|
|
985
|
+
if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
|
|
986
|
+
if (t.state !== 'To do' || !(Date.now() - Date.parse(t.at || '') <= 120000)) return fail(ctx, res, 409, 'only a task added in the last 2 minutes, still To do, can be taken back');
|
|
987
|
+
if (!p.file) return fail(ctx, res, 409, NO_STATE);
|
|
988
|
+
append(p.file, g.actor, { kind: 'task-remove', board: p.board.id, task: t.id, why: 'undo of add' });
|
|
989
|
+
ctx.json(res, { ok: true });
|
|
990
|
+
},
|
|
979
991
|
'/api/boards/tasks/rename': (ctx, res, body, g) => {
|
|
980
992
|
// tap the title to rename it (canvas RnATask): only the title changes; Undo is the same press with the old name
|
|
981
993
|
const p = postFrame(ctx, res, body);
|
|
@@ -56,7 +56,6 @@ const rootOf = (url, ctx) => {
|
|
|
56
56
|
/** The PM's own calls (initiative briefing-premium-writes). Each appends one record and answers with the rebuilt model. */
|
|
57
57
|
async function post(req, res, url, ctx) {
|
|
58
58
|
const act = url.pathname.slice('/api/briefing-premium/'.length);
|
|
59
|
-
if (req.headers && req.headers['x-pmos-session']) { ctx.json(res, { ok: false, error: 'an agent session cannot record the PM\'s decision' }, 403); return true; }
|
|
60
59
|
const got = await ctx.readJson(req);
|
|
61
60
|
if (!got.ok) { ctx.json(res, { ok: false, error: 'body must be JSON' }, 400); return true; }
|
|
62
61
|
const b = got.body;
|
|
@@ -83,9 +82,9 @@ async function post(req, res, url, ctx) {
|
|
|
83
82
|
ctx.json(res, a.body, a.status);
|
|
84
83
|
return true;
|
|
85
84
|
}
|
|
86
|
-
if (act === 'goal') { // premium-chat-session G6: the PM's Start
|
|
85
|
+
if (act === 'goal') { // premium-chat-session G6: the PM's presses on the goal (Start, Cancel, Stop, the plan edited, a point skipped, replace)
|
|
87
86
|
if (!Ag.KEY_RE.test(String(b.key || ''))) { ctx.json(res, { ok: false, error: 'key must name a row' }, 400); return true; }
|
|
88
|
-
const a = Goal.decide({ runtimeDir, key: b.key, id: b.id, act: b.act, draft: b.draft, session: runtimeDir && Ag.chatSessionOf(runtimeDir, b.key), sessions: ctx.chatSessions });
|
|
87
|
+
const a = Goal.decide({ runtimeDir, key: b.key, id: b.id, act: b.act, draft: b.draft, point: b.point, session: runtimeDir && Ag.chatSessionOf(runtimeDir, b.key), sessions: ctx.chatSessions });
|
|
89
88
|
ctx.json(res, a.body, a.status);
|
|
90
89
|
return true;
|
|
91
90
|
}
|
|
@@ -100,9 +99,10 @@ async function post(req, res, url, ctx) {
|
|
|
100
99
|
return true;
|
|
101
100
|
}
|
|
102
101
|
let r;
|
|
102
|
+
const agentBy = actor.isAgent(g.actor) ? actor.pageName(g.actor.by) : undefined; // D98: an agent's decision names it
|
|
103
103
|
try {
|
|
104
|
-
if (act === 'decide') r = Wr.decide({ root, key: sk ? sk.base : b.key, choice: b.choice, why: b.why });
|
|
105
|
-
else if (act === 'put-off') r = Wr.putOff({ runtimeDir, key: b.key, until: b.until });
|
|
104
|
+
if (act === 'decide') r = Wr.decide({ root, key: sk ? sk.base : b.key, choice: b.choice, why: b.why, by: agentBy });
|
|
105
|
+
else if (act === 'put-off') r = Wr.putOff({ runtimeDir, key: b.key, until: b.until, by: agentBy });
|
|
106
106
|
else r = Wr.returnRun({ root, runtimeDir, run: b.run, reason: b.reason, correctionEvent, appendOutbox });
|
|
107
107
|
} catch (e) { r = { ok: false, status: 500, error: 'the record could not be written: ' + String((e && e.message) || e).slice(0, 160) }; }
|
|
108
108
|
if (!r.ok) { ctx.json(res, { ok: false, error: r.error }, r.status || 400); return true; }
|
|
@@ -140,7 +140,6 @@ async function chatFile(req, res, url, ctx) {
|
|
|
140
140
|
return true;
|
|
141
141
|
}
|
|
142
142
|
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
143
|
-
if (req.headers && req.headers['x-pmos-session']) { ctx.json(res, { ok: false, error: 'an agent session cannot attach a file to the PM\'s message' }, 403); return true; }
|
|
144
143
|
const g = guard.requirePagePress(req, {});
|
|
145
144
|
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
146
145
|
if (url.pathname === '/api/chat-file/notes' || url.pathname === '/api/chat-file/notes/remove') { // premium-chat-notes: save or delete one note
|
|
@@ -204,7 +203,6 @@ module.exports = {
|
|
|
204
203
|
if (url.pathname === '/api/briefing-premium/seen') {
|
|
205
204
|
// popup context slice 3b: a popup the PM opened, with what it showed, so the leads session after a refresh writes its lead. Starts nothing.
|
|
206
205
|
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
207
|
-
if (req.headers && req.headers['x-pmos-session']) { ctx.json(res, { ok: false, error: 'an agent session cannot record what the PM opened' }, 403); return true; }
|
|
208
206
|
const got = await ctx.readJson(req);
|
|
209
207
|
if (!got.ok || !got.body || typeof got.body !== 'object') { ctx.json(res, { ok: false, error: 'body must be JSON' }, 400); return true; }
|
|
210
208
|
const g = guard.requirePagePress(req, got.body);
|
|
@@ -199,7 +199,6 @@ async function handle(req, res, url, ctx) {
|
|
|
199
199
|
const read = await ctx.readJson(req);
|
|
200
200
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
201
201
|
const body = read.body || {};
|
|
202
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot draft, issue or drop a core document. Only a press on the page does'));
|
|
203
202
|
const g = sub === 'draft' ? guard.requirePagePress(req, body) : guard.requirePmPress(req, body, { act: 'issue' });
|
|
204
203
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
205
204
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -44,7 +44,6 @@ async function handle(req, res, url, ctx) {
|
|
|
44
44
|
const read = await ctx.readJson(req);
|
|
45
45
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
46
46
|
const body = read.body || {};
|
|
47
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot add a document. Only a press on the page does'));
|
|
48
47
|
const g = guard.requirePagePress(req, body);
|
|
49
48
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
50
49
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -118,7 +118,6 @@ async function handle(req, res, url, ctx) {
|
|
|
118
118
|
const read = await ctx.readJson(req);
|
|
119
119
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
120
120
|
const body = read.body;
|
|
121
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot keep, send back, drop, pause or change the mode of the driver'));
|
|
122
121
|
const g = guard.requirePagePress(req, body);
|
|
123
122
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
124
123
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* · seen and queued are the PM's per-machine marks, so they are runtime state: <runtime>/home/seen.jsonl, <runtime>/home/queued.jsonl
|
|
16
16
|
* · recipients, sent updates and stakeholders are product records, so they go in the workspace's state folder (stateDirFor):
|
|
17
17
|
* <state>/product-updates.jsonl and <state>/stakeholders.jsonl. The last line for a key wins when read back.
|
|
18
|
-
* Every POST is a page press (pm-guard requirePagePress): an agent session
|
|
18
|
+
* Every POST is a page press (pm-guard requirePagePress): an agent session writes these too, under its own name (D98). Nothing here sends mail, Slack or
|
|
19
19
|
* anything else: Send on the weekly update opens a mail draft in the PM's own mail app, and this route only records that it was opened. */
|
|
20
20
|
const path = require('path');
|
|
21
21
|
const guard = require('./pm-guard.js');
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* FILE MODE ONLY, append-only JSONL (D64/D66): <state>/weekly-review.jsonl in the workspace's state folder (stateDirFor). Nothing is
|
|
14
14
|
* rewritten; the last line for a step or an initiative in a week wins when read back. Every POST is a page press (pm-guard
|
|
15
|
-
* requirePagePress): an agent session
|
|
15
|
+
* requirePagePress): an agent session writes it too, under its own name (D98). Nothing here sends anything to anyone. */
|
|
16
16
|
const path = require('path');
|
|
17
17
|
const guard = require('./pm-guard.js');
|
|
18
18
|
const pmItems = require('./pm-items.js');
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* → the same answer as GET, after the line is written
|
|
10
10
|
*
|
|
11
11
|
* FILE MODE ONLY, append-only JSONL (D64/D66): <state>/initiative-layout.jsonl in the workspace's state folder (stateDirFor).
|
|
12
|
-
* Every POST is a page press (pm-guard requirePagePress): an agent session
|
|
12
|
+
* Every POST is a page press (pm-guard requirePagePress): an agent session writes it too, under its own name (D98). */
|
|
13
13
|
const path = require('path');
|
|
14
14
|
const guard = require('./pm-guard.js');
|
|
15
15
|
const pmItems = require('./pm-items.js');
|
|
@@ -57,7 +57,6 @@ async function handle(req, res, url, ctx) {
|
|
|
57
57
|
const read = await ctx.readJson(req);
|
|
58
58
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
59
59
|
const body = read.body || {};
|
|
60
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change Insights. Only a press on the page does'));
|
|
61
60
|
const g = guard.requirePagePress(req, body);
|
|
62
61
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
63
62
|
const w = dashRoutes.wsOf(ctx, text(body.ws));
|
|
@@ -150,7 +150,6 @@ async function file(req, res, url, ctx) {
|
|
|
150
150
|
return true;
|
|
151
151
|
}
|
|
152
152
|
if (req.method !== 'POST') return respond(ctx, res, fail(405, 'GET or POST only'));
|
|
153
|
-
if (req.headers && req.headers['x-pmos-session']) return respond(ctx, res, fail(403, 'an agent session cannot add material to a meeting'));
|
|
154
153
|
const g = guard.requirePagePress(req, {});
|
|
155
154
|
if (!g.ok) return respond(ctx, res, fail(g.status, g.error));
|
|
156
155
|
const raw = await readRaw(req, files.MAX_BYTES);
|
|
@@ -1,35 +1,88 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
/* routes-mentions.js —
|
|
2
|
+
/* routes-mentions.js — Home's Mentions (canvas XmsMentionsGrill, XmsDeskList/One/Refine, agreed A+; initiative c3-brief-summary-mentions).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* GET /api/mentions[?now=ISO] → { ok, waiting, recent, count, gaps, as_of, now } lib/mention-store.js view: every ask that waits
|
|
5
|
+
* on the PM (any age, oldest first) and the last 7 days of what does not wait (newest first)
|
|
6
|
+
* POST /api/mentions/act { id, act, until?, task?, text?, to? } → { ok, mark } act: answered | notask | snooze | task | keep | drafted | closed |
|
|
7
|
+
* draft | read | undo (undo takes back the id's last mark, so every one-tap act has its Undo)
|
|
8
|
+
* POST /api/mentions/read { id, read } → { ok } the PM opened an FYI (read: false undoes it); one line in <runtime>/mentions/read.jsonl
|
|
9
|
+
*
|
|
10
|
+
* The writes are the page press only (pm-guard requirePagePress). `pmos mention draft` is how Claude changes a proposed reply from a chat
|
|
11
|
+
* (mention-cli.js; logged as by: agent). Nothing is sent to Slack, Jira, Confluence or mail: PMOS never posts for the PM. */
|
|
12
|
+
const fs = require('fs');
|
|
7
13
|
const path = require('path');
|
|
8
14
|
const guard = require('./pm-guard.js');
|
|
9
15
|
const pmItems = require('./pm-items.js');
|
|
10
|
-
const
|
|
16
|
+
const store = require('./mention-store.js');
|
|
17
|
+
const { MENTION_ID, firstName } = require('./routes-brief-page.js');
|
|
11
18
|
|
|
12
|
-
/** The check of a body: null when it is good, else the reason. Pure. */
|
|
19
|
+
/** The check of a read body: null when it is good, else the reason. Pure. */
|
|
13
20
|
function badBody(b) {
|
|
14
21
|
if (!b || !MENTION_ID.test(String(b.id || ''))) return 'id must be a mention id (12 hex characters)';
|
|
15
22
|
if (typeof b.read !== 'boolean') return 'read must be true or false';
|
|
16
23
|
return null;
|
|
17
24
|
}
|
|
18
25
|
|
|
26
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
27
|
+
const localDate = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
|
28
|
+
|
|
29
|
+
/** The PM's Settings, as proactive.js reads them (its defaults when none are saved). */
|
|
30
|
+
function settingsOf(rt) {
|
|
31
|
+
const P = require('./proactive.js');
|
|
32
|
+
let raw = {}; try { raw = JSON.parse(fs.readFileSync(path.join(rt, 'proactive-settings.json'), 'utf8')); } catch { raw = {}; }
|
|
33
|
+
const n = P.normalizeSettings(raw);
|
|
34
|
+
return n.ok ? n.settings : P.normalizeSettings({}).settings;
|
|
35
|
+
}
|
|
36
|
+
/** The PM's names, lower case, so the PM's own reply in a thread is seen: the Settings name and git's user.name. */
|
|
37
|
+
function myNames(rt, cwd, s = settingsOf(rt)) {
|
|
38
|
+
const out = new Set();
|
|
39
|
+
const n = String((s && s.name) || '').trim();
|
|
40
|
+
if (n) { out.add(n.toLowerCase()); out.add(n.split(/\s+/)[0].toLowerCase()); }
|
|
41
|
+
const g = firstName(cwd); if (g) out.add(g.toLowerCase());
|
|
42
|
+
return [...out];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The whole GET, as a function of the runtime folder, so a test needs no server. */
|
|
46
|
+
function answer(rt, { now = Date.now(), cwd } = {}) {
|
|
47
|
+
const SR = require('./source-reads.js');
|
|
48
|
+
const reads = SR.all(rt);
|
|
49
|
+
const set = settingsOf(rt);
|
|
50
|
+
const on = set.briefSources || {};
|
|
51
|
+
const want = store.MENTION_SOURCES.filter((s) => on[s] === true); // a source the PM switched off is the PM's choice: not a gap
|
|
52
|
+
const missing = want.map((s) => (reads[s] ? (reads[s].state === 'read' ? null : { source: s, state: reads[s].state }) : { source: s, state: 'never' })).filter(Boolean);
|
|
53
|
+
let brief = null; try { brief = JSON.parse(fs.readFileSync(path.join(rt, 'briefs', localDate(new Date(now)) + '.json'), 'utf8')); } catch { brief = null; }
|
|
54
|
+
return store.view(rt, { now, me: myNames(rt, cwd, set), missing, reads, brief });
|
|
55
|
+
}
|
|
56
|
+
|
|
19
57
|
module.exports = {
|
|
20
58
|
prefixes: ['/api/mentions'],
|
|
21
|
-
badBody,
|
|
59
|
+
badBody, answer, myNames,
|
|
22
60
|
handle: async (req, res, url, ctx) => {
|
|
23
|
-
|
|
61
|
+
const p = url.pathname;
|
|
62
|
+
if (p === '/api/mentions') {
|
|
63
|
+
if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
|
|
64
|
+
if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'no runtime folder' }, 500); return true; }
|
|
65
|
+
const q = url.searchParams.get('now');
|
|
66
|
+
const now = q && Number.isFinite(Date.parse(q)) ? Date.parse(q) : Date.now();
|
|
67
|
+
try { ctx.json(res, answer(ctx.runtimeDir, { now, cwd: ctx.selfRoot || process.cwd() })); }
|
|
68
|
+
catch (e) { ctx.json(res, { ok: false, error: 'the mentions could not be read: ' + String((e && e.message) || e).slice(0, 200) }, 500); }
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (p !== '/api/mentions/read' && p !== '/api/mentions/act') return false;
|
|
24
72
|
if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
|
|
25
73
|
const got = await ctx.readJson(req);
|
|
26
74
|
if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
|
|
27
75
|
const b = got.body || {};
|
|
28
76
|
const g = guard.requirePagePress(req, b);
|
|
29
77
|
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
78
|
+
if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'no runtime folder' }, 500); return true; }
|
|
79
|
+
if (p === '/api/mentions/act') {
|
|
80
|
+
const r = store.mark(ctx.runtimeDir, b, new Date(), 'pm');
|
|
81
|
+
ctx.json(res, r, r.ok ? 200 : 400);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
30
84
|
const err = badBody(b);
|
|
31
85
|
if (err) { ctx.json(res, { ok: false, error: err }, 400); return true; }
|
|
32
|
-
if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'no runtime folder' }, 500); return true; }
|
|
33
86
|
pmItems.appendEvent(path.join(ctx.runtimeDir, 'mentions', 'read.jsonl'), { id: b.id, read: b.read }, new Date());
|
|
34
87
|
ctx.json(res, { ok: true });
|
|
35
88
|
return true;
|
|
@@ -34,9 +34,11 @@ const today = () => new Date().toISOString().slice(0, 10);
|
|
|
34
34
|
const bad = (status, error) => ({ status, body: { ok: false, error } });
|
|
35
35
|
const len = (v) => (Array.isArray(v) ? v.length : Number(v) || 0);
|
|
36
36
|
|
|
37
|
-
/** pm:<slug> from the press becomes human:<slug> for the onboarding ledger
|
|
37
|
+
/** pm:<slug> from the press becomes human:<slug> for the onboarding ledger; an agent session keeps its agent:… (D98).
|
|
38
|
+
* Null for anything else. */
|
|
38
39
|
function humanOf(actor) {
|
|
39
40
|
const by = actor && typeof actor.by === 'string' ? actor.by : '';
|
|
41
|
+
if (/^agent:(?:unknown|sess-\d+\.[0-9a-f]{8})$/.test(by)) return { by, via: actor.via || 'ui' };
|
|
40
42
|
return /^pm:[a-z0-9_-]{1,40}$/.test(by) ? { by: 'human:' + by.slice(3), via: actor.via || 'ui' } : null;
|
|
41
43
|
}
|
|
42
44
|
|
|
@@ -33,7 +33,6 @@ async function handle(req, res, url, ctx) {
|
|
|
33
33
|
if (req.method !== 'POST') return send(bad(405, 'POST only'));
|
|
34
34
|
const read = await ctx.readJson(req);
|
|
35
35
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
36
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot stop or resume the orchestrator'));
|
|
37
36
|
const g = guard.requirePagePress(req, read.body);
|
|
38
37
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
39
38
|
const r = o.gate.setStopped(sub === 'stop', actorLib.pageName ? actorLib.pageName(g.actor) : 'pm');
|
|
@@ -22,7 +22,6 @@ async function handle(req, res, url, ctx) {
|
|
|
22
22
|
const read = await ctx.readJson(req);
|
|
23
23
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
24
24
|
const body = read.body || {};
|
|
25
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change a chart. Only a press on the page does'));
|
|
26
25
|
const g = guard.requirePagePress(req, body);
|
|
27
26
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
28
27
|
const w = wsOf(ctx, typeof body.ws === 'string' ? body.ws : '');
|
|
@@ -42,7 +42,6 @@ async function handle(req, res, url, ctx) {
|
|
|
42
42
|
const read = await ctx.readJson(req);
|
|
43
43
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
44
44
|
const body = read.body || {};
|
|
45
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change a dashboard. Only a press on the page does'));
|
|
46
45
|
const g = guard.requirePagePress(req, body);
|
|
47
46
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
48
47
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* POST /api/programs/archive { ws, program }
|
|
14
14
|
*
|
|
15
15
|
* FILE MODE ONLY (D64/D66): <state>/programs.jsonl of the workspace named by `ws`, append-only. Every POST is a page press (pm-guard
|
|
16
|
-
* requirePagePress): an agent session
|
|
16
|
+
* requirePagePress): an agent session may make, join or archive a program too (D98). Nothing here writes to Jira. */
|
|
17
17
|
const path = require('path');
|
|
18
18
|
const guard = require('./pm-guard.js');
|
|
19
19
|
const pmItems = require('./pm-items.js');
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* POST /api/records/kr-metrics/reading { rid, at, value } → { ok } one actual reading of a KR metric
|
|
8
8
|
*
|
|
9
9
|
* STATE: planning/records/<kind>.jsonl, written only through scripts/records (which uses scripts/trust/ledger.js).
|
|
10
|
-
* WHO WRITES: every POST passes pm-guard requirePagePress; an agent session
|
|
10
|
+
* WHO WRITES: every POST passes pm-guard requirePagePress; an agent session adds and edits them too, under its own name (D98).
|
|
11
11
|
*/
|
|
12
12
|
const path = require('path');
|
|
13
13
|
const guard = require('./pm-guard.js');
|
|
@@ -384,6 +384,11 @@ function rememberStudio(ctx, w, id) {
|
|
|
384
384
|
return true;
|
|
385
385
|
} catch { return false; }
|
|
386
386
|
}
|
|
387
|
+
/** Who a note line names: 'pm', or an agent session's page name (D98; never its token). */
|
|
388
|
+
const logBy = (a) => {
|
|
389
|
+
const m = a && typeof a.by === 'string' ? /^(agent:(?:unknown|sess-\d+))/.exec(a.by) : null;
|
|
390
|
+
return m ? m[1] : 'pm';
|
|
391
|
+
};
|
|
387
392
|
function editLog(ctx, row) {
|
|
388
393
|
if (!ctx.runtimeDir) return false;
|
|
389
394
|
try {
|
|
@@ -484,7 +489,6 @@ async function handle(req, res, url, ctx) {
|
|
|
484
489
|
const read = await ctx.readJson(req);
|
|
485
490
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
486
491
|
const body = read.body || {};
|
|
487
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change a report design, its cycles or its notes. Only a press on the page does'));
|
|
488
492
|
const g = guard.requirePagePress(req, body);
|
|
489
493
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
490
494
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -500,7 +504,7 @@ async function handle(req, res, url, ctx) {
|
|
|
500
504
|
} else {
|
|
501
505
|
const r = D.pinOp(root, d.c.rel, body, { by: 'you' });
|
|
502
506
|
if (!r.ok) return fail(r);
|
|
503
|
-
editLog(ctx, { event: 'pin', path: d.c.rel, by:
|
|
507
|
+
editLog(ctx, { event: 'pin', path: d.c.rel, by: logBy(g.actor), op: r.op, id: r.pin.id, slide: r.pin.slide, text: r.pin.text, ...(r.pin.section ? { section: r.pin.section } : {}) });
|
|
504
508
|
}
|
|
505
509
|
return send({ status: 200, body: D.notesOf(root, d.c.rel) });
|
|
506
510
|
}
|
|
@@ -534,7 +538,7 @@ async function handle(req, res, url, ctx) {
|
|
|
534
538
|
const r = D.decideCycle(root, c.rel, { diff: diff.id, choice, newVersion });
|
|
535
539
|
if (!r.ok) return fail(r);
|
|
536
540
|
D.append(root, c.cadence, { ev: 'cycle-decision', path: c.rel, slot: c.slot, diff: diff.id, choice }, { actor: g.actor });
|
|
537
|
-
editLog(ctx, { event: 'design', path: c.rel, by:
|
|
541
|
+
editLog(ctx, { event: 'design', path: c.rel, by: logBy(g.actor), choice, diff: diff.id, what: diff.what });
|
|
538
542
|
return send({ status: 200, body: { ...cycleAnswer(w, c), cycle: r.cycle } });
|
|
539
543
|
}
|
|
540
544
|
|
|
@@ -309,7 +309,6 @@ async function handle(req, res, url, ctx) {
|
|
|
309
309
|
const read = await ctx.readJson(req);
|
|
310
310
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
311
311
|
const body = read.body || {};
|
|
312
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot set up, change or dismiss a report. Only a press on the page does'));
|
|
313
312
|
const g = guard.requirePagePress(req, body);
|
|
314
313
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
315
314
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -697,7 +697,6 @@ async function handle(req, res, url, ctx) {
|
|
|
697
697
|
const read = await ctx.readJson(req);
|
|
698
698
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
699
699
|
const body = read.body || {};
|
|
700
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change a report structure, add a source, start a check or save a chart. Only a press on the page does'));
|
|
701
700
|
const g = guard.requirePagePress(req, body);
|
|
702
701
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
703
702
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
const fs = require('fs');
|
|
12
12
|
const path = require('path');
|
|
13
13
|
const guard = require('./pm-guard.js');
|
|
14
|
-
const actor = require('./actor.js');
|
|
15
14
|
const runAnswers = require('./run-answers.js');
|
|
16
15
|
const { repoScript } = require('./repo-script.js');
|
|
17
16
|
const { groupSessions } = require(repoScript('sessions-list.js'));
|
|
@@ -126,9 +125,7 @@ async function handle(req, res, url, ctx) {
|
|
|
126
125
|
const got = await ctx.readJson(req);
|
|
127
126
|
if (!got.ok) { ctx.json(res, { ok: false, error: 'body must be JSON' }, 400); return true; }
|
|
128
127
|
const body = got.body;
|
|
129
|
-
const
|
|
130
|
-
if (tok) { ctx.json(res, { ok: false, error: 'an agent session cannot answer a run' }, 403); return true; }
|
|
131
|
-
const g = guard.requirePagePress(req, body);
|
|
128
|
+
const g = guard.requirePagePress(req, body); // D98: an agent session may answer too; g.actor names it
|
|
132
129
|
if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
|
|
133
130
|
if (p === '/api/runs/answer') {
|
|
134
131
|
// An answer to the agent's own question must be one of the options it offered (the contract's answerLine).
|
|
@@ -140,7 +137,7 @@ async function handle(req, res, url, ctx) {
|
|
|
140
137
|
if (al.error) { ctx.json(res, { ok: false, error: al.error }, 400); return true; }
|
|
141
138
|
}
|
|
142
139
|
}
|
|
143
|
-
const r = runAnswers.recordAnswer(runAnswers.answersFile(ctx.runtimeDir), body, actor
|
|
140
|
+
const r = runAnswers.recordAnswer(runAnswers.answersFile(ctx.runtimeDir), body, g.actor);
|
|
144
141
|
ctx.json(res, r.ok ? { ok: true } : { ok: false, error: r.error }, r.ok ? 200 : r.status);
|
|
145
142
|
return true;
|
|
146
143
|
}
|
|
@@ -190,7 +190,6 @@ async function handle(req, res, url, ctx) {
|
|
|
190
190
|
const read = await ctx.readJson(req);
|
|
191
191
|
if (!read.ok) return send(bad(400, 'the body is not JSON'));
|
|
192
192
|
const body = read.body;
|
|
193
|
-
if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot change the watch list, the scan setting or a proposal, start a scan or stop one'));
|
|
194
193
|
const g = guard.requirePagePress(req, body);
|
|
195
194
|
if (!g.ok) return send(bad(g.status, g.error));
|
|
196
195
|
const w = wsOf(ctx, text(body.ws));
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* Briefing from those reads (briefing-source-flow, slice 3); a press while one runs joins it
|
|
12
12
|
* POST /api/sources/watch { ws, on } → { ok, watch } the change detector on or off for this repository
|
|
13
13
|
*
|
|
14
|
-
* Both POSTs pass pm-guard requirePagePress: the
|
|
14
|
+
* Both POSTs pass pm-guard requirePagePress: the press from the page (an agent session's too, D98), which may start a refresh or
|
|
15
15
|
* switch the detector off. A refresh of `repository` or `initiatives` rebuilds the facts in a child process; a refresh of
|
|
16
16
|
* an external source starts that source's skill as a session in the workspace, with the PM's own connections. The server
|
|
17
17
|
* itself calls nothing outside this machine.
|
|
@@ -29,11 +29,13 @@ function requestIdOf(body) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function recordAnswer(file, input, who, now = new Date()) {
|
|
32
|
-
|
|
32
|
+
// D98: an agent session answers too; the line keeps its `by`, so the PM sees who answered.
|
|
33
|
+
if (!actor.isPm(who) && !actor.isAgent(who)) return { ok: false, status: 403, error: 'only the PM or an agent session can answer a run' };
|
|
33
34
|
const i = input && typeof input === 'object' ? input : {};
|
|
34
35
|
if (typeof i.run !== 'string' || !RUN_RE.test(i.run)) return { ok: false, status: 400, error: 'run must be a session id' };
|
|
35
36
|
if (typeof i.request !== 'string' || !i.request || i.request.length > 120) return { ok: false, status: 400, error: 'request must be a short id' };
|
|
36
37
|
if (!BEHAVIORS.includes(i.behavior)) return { ok: false, status: 400, error: 'behavior must be one of ' + BEHAVIORS.join(', ') };
|
|
38
|
+
if (ownRun(who.by, i.run)) return { ok: false, status: 403, error: 'a run does not answer its own question or permission request' };
|
|
37
39
|
const message = typeof i.message === 'string' ? i.message.slice(0, 400) : '';
|
|
38
40
|
const line = { type: 'answer', run: i.run, request: i.request, behavior: i.behavior, message, by: who.by };
|
|
39
41
|
appendOutbox(file, line, now);
|
|
@@ -45,20 +47,27 @@ function readAnswers(file) {
|
|
|
45
47
|
catch { return []; }
|
|
46
48
|
}
|
|
47
49
|
|
|
50
|
+
const answerer = (by) => typeof by === 'string' && (by.startsWith('pm:') || by.startsWith('agent:'));
|
|
51
|
+
/** True when `by` is the agent session of run `run` itself. Kept through D98: a run that answered its own permission
|
|
52
|
+
* request would make the request mean nothing. Any other agent session may answer it. */
|
|
53
|
+
const ownRun = (by, run) => typeof by === 'string' && typeof run === 'string' && by.startsWith('agent:' + run + '.');
|
|
54
|
+
const counts = (l, run) => answerer(l.by) && !ownRun(l.by, run);
|
|
55
|
+
|
|
48
56
|
function answerFor(run, requestId, lines = []) {
|
|
49
57
|
let found = null;
|
|
50
58
|
for (const l of lines) {
|
|
51
|
-
if (l && l.type === 'answer' && l.run === run && l.request === requestId &&
|
|
59
|
+
if (l && l.type === 'answer' && l.run === run && l.request === requestId && counts(l, run)) found = l;
|
|
52
60
|
}
|
|
53
61
|
return found;
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
// The
|
|
57
|
-
// permission request.
|
|
64
|
+
// The recorded answers as the contract's own events (reply-contract.js fold): an answer to an ask, a decision on a
|
|
65
|
+
// permission request. Lines written by the PM or another agent session (D98) become events, in the contract's answerer role
|
|
66
|
+
// (`by: 'pm'`); the run-answers line itself keeps who wrote it. The fold then checks the ids against what is open.
|
|
58
67
|
function asEvents(run, lines = []) {
|
|
59
68
|
const out = [];
|
|
60
69
|
for (const l of lines) {
|
|
61
|
-
if (!l || l.type !== 'answer' || l.run !== run.id ||
|
|
70
|
+
if (!l || l.type !== 'answer' || l.run !== run.id || !counts(l, run.id)) continue;
|
|
62
71
|
if (l.behavior === 'answer') out.push({ kind: 'answer', run: run.id, session: run.session, ask_id: l.request, answer: l.message, by: 'pm' });
|
|
63
72
|
else if (l.behavior === 'allow' || l.behavior === 'deny') out.push({ kind: 'decision', run: run.id, session: run.session, perm_id: l.request, decision: l.behavior, by: 'pm', at: l.at });
|
|
64
73
|
}
|
|
@@ -130,7 +130,8 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
|
|
|
130
130
|
if (!file) file = S.ledgerFile(D.stateDirOf(flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd)));
|
|
131
131
|
const noState = () => fail('this repository has no PMOS state folder (pmos/state, state or .pmos), so the scan has nowhere to keep its ledger');
|
|
132
132
|
const actor = actorLib.fromCli(who);
|
|
133
|
-
|
|
133
|
+
// D98: an agent session may do it too; the ledger line carries its own `by`.
|
|
134
|
+
const pmOnly = (act) => (actorLib.isPm(actor) || actorLib.isAgent(actor) ? { ok: true } : { ok: false, error: `only the PM or an agent session can ${act}` });
|
|
134
135
|
const openScan = (state, id, mode) => {
|
|
135
136
|
const sc = id ? state.scans.get(id) : null;
|
|
136
137
|
if (!sc || sc.end || (mode && sc.mode !== mode)) return null;
|