create-pmos 0.409.0 → 0.411.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/package.json +25 -30
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-adddoc-test.js +1 -1
  7. package/workspace/briefing-premium-initiative-test.js +9 -15
  8. package/workspace/changelog.json +24 -0
  9. package/workspace/chat-asks-test.js +146 -0
  10. package/workspace/guide/briefing-premium.md +1 -1
  11. package/workspace/guide/home.md +25 -0
  12. package/workspace/guide/programs.md +2 -1
  13. package/workspace/home-rows-test.js +149 -56
  14. package/workspace/ini-workflow-test.js +4 -4
  15. package/workspace/lib/briefing-premium-agent.js +8 -1
  16. package/workspace/lib/engine/boards.js +3 -1
  17. package/workspace/lib/goal-chat.js +94 -30
  18. package/workspace/lib/mention-cli.js +70 -0
  19. package/workspace/lib/mention-store.js +307 -0
  20. package/workspace/lib/pmos-verbs.js +3 -0
  21. package/workspace/lib/routes-boards.js +12 -0
  22. package/workspace/lib/routes-briefing-premium.js +2 -2
  23. package/workspace/lib/routes-mentions.js +62 -9
  24. package/workspace/lib/session-files.js +132 -0
  25. package/workspace/lib/session-name.js +103 -0
  26. package/workspace/lib/source-reads.js +4 -1
  27. package/workspace/package-lock.json +2 -2
  28. package/workspace/package.json +1 -1
  29. package/workspace/premium-board-actions-test.js +10 -8
  30. package/workspace/premium-chat-goal-setup-test.js +203 -0
  31. package/workspace/premium-chat-goal-view-test.js +28 -23
  32. package/workspace/premium-chat-line-test.js +189 -0
  33. package/workspace/premium-vw-backlog-test.js +1 -1
  34. package/workspace/premium-vw-item-test.js +1 -1
  35. package/workspace/premium-vw-jira-test.js +1 -1
  36. package/workspace/public/pm/bd-prog-panel.js +3 -1
  37. package/workspace/public/pm/bd-prog.js +4 -2
  38. package/workspace/public/pm/chat-ask.js +17 -9
  39. package/workspace/public/pm/cozy-home-rows.css +39 -1
  40. package/workspace/public/pm/cozy-home.css +112 -12
  41. package/workspace/public/pm/cozy-search.js +2 -1
  42. package/workspace/public/pm/cozy-steps.css +69 -0
  43. package/workspace/public/pm/cozy-steps.js +90 -0
  44. package/workspace/public/pm/goal-chat.js +141 -23
  45. package/workspace/public/pm/home-app.js +71 -35
  46. package/workspace/public/pm/home-ask.js +121 -0
  47. package/workspace/public/pm/home-chat.js +120 -68
  48. package/workspace/public/pm/home-data.js +10 -2
  49. package/workspace/public/pm/home-goal.js +159 -0
  50. package/workspace/public/pm/home-ini.css +35 -0
  51. package/workspace/public/pm/home-ini.js +50 -19
  52. package/workspace/public/pm/home-line.css +59 -0
  53. package/workspace/public/pm/home-line.js +200 -0
  54. package/workspace/public/pm/home-list.js +7 -4
  55. package/workspace/public/pm/home-mentions.js +303 -111
  56. package/workspace/public/pm/home-ses-name.js +65 -0
  57. package/workspace/public/pm/home-stage-card.js +94 -0
  58. package/workspace/public/pm/home-sweep.js +112 -0
  59. package/workspace/public/pm/home-today.js +8 -3
  60. package/workspace/public/pm/premium-initiative-head.js +8 -4
  61. package/workspace/public/pm/program-model.js +4 -1
  62. package/workspace/public/pm/rename-press.js +24 -0
  63. package/workspace/public/pm/wf-page.css +3 -0
  64. package/workspace/public/pm/wf-page.js +2 -1
  65. package/workspace/public/premium-workflows.html +1 -0
  66. package/workspace/server.js +125 -11
  67. package/workspace/session-names-test.js +144 -0
  68. package/workspace/skills/jira-push.skill +1 -0
  69. package/workspace/skills/morning-brief.skill +2 -1
  70. package/workspace/skills/report-daily.skill +1 -0
  71. package/workspace/skills/report-monthly.skill +1 -0
  72. package/workspace/skills/report-weekly.skill +1 -0
  73. package/workspace/skills/sources-read.skill +3 -2
  74. package/workspace/stage-card-test.js +203 -0
  75. package/workspace/test-lists/chat-asks.json +13 -0
  76. package/workspace/test-lists/chat-progress.json +13 -0
  77. package/workspace/test-lists/mentions-a-plus.json +9 -0
  78. package/workspace/test-lists/premium-chat-goal-setup.json +9 -0
  79. package/workspace/test-lists/session-files.json +5 -0
  80. package/workspace/test-lists/session-names.json +13 -0
  81. package/workspace/test-lists/stage-card.json +6 -0
  82. package/workspace/tk-tasks-test.js +1 -1
  83. package/workspace/workflows-setup-test.js +17 -0
@@ -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);
@@ -83,9 +83,9 @@ async function post(req, res, url, ctx) {
83
83
  ctx.json(res, a.body, a.status);
84
84
  return true;
85
85
  }
86
- if (act === 'goal') { // premium-chat-session G6: the PM's Start or Cancel on the goal card
86
+ 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
87
  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 });
88
+ 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
89
  ctx.json(res, a.body, a.status);
90
90
  return true;
91
91
  }
@@ -1,35 +1,88 @@
1
1
  'use strict';
2
- /* routes-mentions.js — POST /api/mentions/read { id, read } → { ok } (initiative c3-brief-summary-mentions)
2
+ /* routes-mentions.js — Home's Mentions (canvas XmsMentionsGrill, XmsDeskList/One/Refine, agreed A+; initiative c3-brief-summary-mentions).
3
3
  *
4
- * The PM marked a mention of today's brief read on the Briefing (read: false undoes it). One appended line in <runtime>/mentions/read.jsonl:
5
- * { id, read, at }. GET /api/brief-page reads the file back (routes-brief-page.js readMarks: the last line for an id wins).
6
- * The page press only (pm-guard requirePagePress). Nothing is sent to Slack, Jira, Confluence or mail. */
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 { MENTION_ID } = require('./routes-brief-page.js');
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
- if (url.pathname !== '/api/mentions/read') return false;
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;
@@ -0,0 +1,132 @@
1
+ 'use strict';
2
+ /* session-files.js — a file outside every workspace that one session may still show in the viewer (PM, 2026-10-25: "Should be able to read any
3
+ * file, even outside workspace", on a session's scratchpad file that answered "Not in a workspace"). The phone reaches the workspace over the
4
+ * network, so this is NOT an arbitrary-path read. Two kinds of file only, both tied to the session the chat belongs to:
5
+ * - a file Claude itself named in that session (its words or its tool calls in the transcript; never a tool result, which can hold any text),
6
+ * - a file in that session's own scratchpad folder (<tmp>/claude-<uid>/<project slug>/<session id>/scratchpad).
7
+ * Read-only: the server sends the text and the viewer shows it sandboxed or offers it as a download. Nothing is run.
8
+ *
9
+ * allow({ path, transcript, sessionId, base, home, tmpRoots, uid }) -> { ok: true, real, name, size, mtime, via } | { ok: false, reason, why }
10
+ * path what Claude wrote: absolute, ~/… or relative to the session's folder (base).
11
+ * transcript the session's transcript file (.jsonl). Without one, nothing is allowed.
12
+ * via 'scratchpad' | 'named'.
13
+ * reason: 'outside' (not named and not in the scratchpad), 'missing', 'not-file', 'private', 'large', 'bad'.
14
+ * The path is resolved to its real path and the rules are checked again on that path, so a symlink cannot lead to a file nobody named. */
15
+ const fs = require('fs');
16
+ const os = require('os');
17
+ const path = require('path');
18
+ const { cleanPath } = require('./chat-file-locate.js');
19
+
20
+ const MAX_FILE_BYTES = 2 * 1024 * 1024; // the same cap as a workspace read of an unknown text file
21
+ const MAX_TRANSCRIPT_BYTES = 32 * 1024 * 1024; // only the newest part of a very long transcript is read
22
+
23
+ const inside = (root, p) => p === root || p.startsWith(root.endsWith(path.sep) ? root : root + path.sep);
24
+ const real = (p) => { try { return fs.realpathSync(p); } catch { return null; } };
25
+
26
+ // Files that hold keys or passwords stay closed even when a session named them.
27
+ const PRIVATE_DIRS = new Set(['.ssh', '.gnupg', '.aws', '.azure', '.kube', '.docker', '.password-store', 'Keychains', '.config/gcloud']);
28
+ const PRIVATE_NAME = /^(\.env(\..+)?|\.netrc|\.npmrc|\.pypirc|\.git-credentials|id_(rsa|dsa|ecdsa|ed25519)(\.pub)?|credentials(\.json)?)$/i;
29
+ const SYSTEM = ['/dev', '/proc', '/sys'];
30
+ function isPrivate(p) {
31
+ if (SYSTEM.some((s) => inside(s, p))) return true;
32
+ const parts = p.split(path.sep);
33
+ if (parts.some((s) => PRIVATE_DIRS.has(s))) return true;
34
+ if (/\/\.config\/gcloud(\/|$)/.test(p)) return true;
35
+ return PRIVATE_NAME.test(path.basename(p));
36
+ }
37
+
38
+ /* What Claude itself wrote in the session: the text and tool-call inputs of assistant records, as one string. Memoised per file size and time. */
39
+ const said = new Map(); // file -> { stamp, text }
40
+ function claudeSaid(file) {
41
+ let st; try { st = fs.statSync(file); } catch { return ''; }
42
+ const stamp = st.size + ':' + st.mtimeMs;
43
+ const hit = said.get(file);
44
+ if (hit && hit.stamp === stamp) return hit.text;
45
+ let raw = '';
46
+ try {
47
+ const fd = fs.openSync(file, 'r');
48
+ try {
49
+ const len = Math.min(st.size, MAX_TRANSCRIPT_BYTES);
50
+ const buf = Buffer.alloc(len);
51
+ fs.readSync(fd, buf, 0, len, st.size - len);
52
+ raw = buf.toString('utf8');
53
+ } finally { fs.closeSync(fd); }
54
+ } catch { return ''; }
55
+ const out = [];
56
+ for (const line of raw.split('\n')) {
57
+ if (!line.includes('"assistant"')) continue;
58
+ let r; try { r = JSON.parse(line); } catch { continue; }
59
+ if (!r || r.type !== 'assistant' || !r.message) continue;
60
+ const c = r.message.content;
61
+ if (typeof c === 'string') { out.push(c); continue; }
62
+ for (const b of Array.isArray(c) ? c : []) {
63
+ if (b && b.type === 'text' && typeof b.text === 'string') out.push(b.text);
64
+ else if (b && b.type === 'tool_use' && b.input) out.push(...Object.values(b.input).filter((v) => typeof v === 'string'));
65
+ }
66
+ }
67
+ const text = out.join('\n');
68
+ if (said.size > 50) said.clear();
69
+ said.set(file, { stamp, text });
70
+ return text;
71
+ }
72
+
73
+ /** True when `p` stands in `text` as a whole path: not as the start of a longer one (`/a/b` in `/a/bc` or `/a/b/c`). Pure. */
74
+ function names(text, p) {
75
+ if (!p || !text) return false;
76
+ let i = text.indexOf(p);
77
+ while (i !== -1) {
78
+ const before = i === 0 ? '' : text[i - 1];
79
+ const after = text.slice(i + p.length, i + p.length + 2);
80
+ const okBefore = !before || !/[A-Za-z0-9_.\-/~]/.test(before);
81
+ const okAfter = !after || !/^([A-Za-z0-9_\-/]|\.[A-Za-z0-9_])/.test(after);
82
+ if (okBefore && okAfter) return true;
83
+ i = text.indexOf(p, i + 1);
84
+ }
85
+ return false;
86
+ }
87
+
88
+ /** The session's scratchpad folders that exist, as real paths. The slug is the transcript's own project folder name. */
89
+ function scratchpads({ transcript, sessionId, tmpRoots, uid }) {
90
+ if (!transcript || !sessionId || !/^[A-Za-z0-9-]+$/.test(sessionId)) return [];
91
+ const slug = path.basename(path.dirname(transcript));
92
+ if (!slug || slug === '.' || slug === '..') return [];
93
+ const out = [];
94
+ for (const t of tmpRoots) {
95
+ const r = real(path.join(t, 'claude-' + uid, slug, sessionId, 'scratchpad'));
96
+ if (r && !out.includes(r)) out.push(r);
97
+ }
98
+ return out;
99
+ }
100
+
101
+ function allow({ path: raw, transcript = null, sessionId = null, base = null, home = os.homedir(), tmpRoots = ['/tmp', '/private/tmp', os.tmpdir()], uid = typeof process.getuid === 'function' ? process.getuid() : 0 } = {}) {
102
+ const p = cleanPath(raw);
103
+ if (!p || p.length > 4096 || p.includes('\0')) return { ok: false, reason: 'bad', why: 'There is no file path to open.' };
104
+ const outside = { ok: false, reason: 'outside', why: 'This file is not in a workspace PMOS serves, and this session did not name it, so it is not shown here.' };
105
+ if (!transcript) return outside;
106
+ let abs;
107
+ if (p === '~' || p.startsWith('~/')) abs = home ? path.join(home, p.slice(2)) : null;
108
+ else if (path.isAbsolute(p)) abs = path.resolve(p);
109
+ else abs = base ? path.resolve(base, p) : null;
110
+ if (!abs) return outside;
111
+ const r = real(abs);
112
+ const pads = scratchpads({ transcript, sessionId, tmpRoots, uid });
113
+ const text = claudeSaid(transcript);
114
+ // named: the real path, or the path as written when only its folders are links (macOS /tmp is /private/tmp) and the file itself is not
115
+ const parent = real(path.dirname(abs));
116
+ const fileIsLink = !!(r && parent && path.join(parent, path.basename(abs)) !== r);
117
+ const named = !!r && (names(text, r) || (!fileIsLink && names(text, abs)));
118
+ const inPad = !!(r && pads.some((d) => inside(d, r) && r !== d));
119
+ if (!r) {
120
+ // a missing file says so only when the session could have opened it, so the answer never tells whether some other path exists
121
+ if (names(text, abs) || (parent && pads.some((d) => inside(d, parent)))) return { ok: false, reason: 'missing', why: 'There is no such file. It may have been moved or not written yet.' };
122
+ return outside;
123
+ }
124
+ if (!named && !inPad) return outside;
125
+ if (isPrivate(r) || isPrivate(abs)) return { ok: false, reason: 'private', why: 'This file can hold keys or passwords, so PMOS does not show it.' };
126
+ let st; try { st = fs.statSync(r); } catch { return { ok: false, reason: 'missing', why: 'The file could not be read.' }; }
127
+ if (!st.isFile()) return { ok: false, reason: 'not-file', why: 'This is not a file.' };
128
+ if (st.size > MAX_FILE_BYTES) return { ok: false, reason: 'large', why: 'The file is larger than 2 MB, so it is not shown here.' };
129
+ return { ok: true, real: r, name: path.basename(r), size: st.size, mtime: st.mtimeMs, via: inPad ? 'scratchpad' : 'named' };
130
+ }
131
+
132
+ module.exports = { allow, names, scratchpads, isPrivate, claudeSaid, MAX_FILE_BYTES };
@@ -0,0 +1,103 @@
1
+ 'use strict';
2
+ /* session-name.js — what a session is called, and Claude naming it by itself (testing feedback 2026-10-25, canvas XmsNames, agreed A).
3
+ *
4
+ * shownName(s) → the name every surface shows: the PM's own name when they gave one, else Claude's, else the
5
+ * CLI's opening title, else the name the session was started with
6
+ * due(s, { hx, automatic }) → 'first' | 'recheck' | null whether Claude should name the session now
7
+ * promptFor({ first, last, answer, current }) → the one prompt the namer reads
8
+ * parseName(text) → a clean name of at most NAME_MAX characters, 'KEEP', or null
9
+ * argv() → the argv after `claude` for the one-shot naming run
10
+ * apply(s, name, turns, at) → true when the record changed: Claude's name lands, or KEEP marks the check; never over the
11
+ * PM's own name
12
+ *
13
+ * The rules (Wawan, canvas comment 2026-10-25 01:53 "no need to ask, just rename"):
14
+ * - Claude names the session after its FIRST REAL ANSWER (the model finished a turn with words), not after the first prompt, and says
15
+ * nothing about it: no chip, no question.
16
+ * - It names it again only if the job changed. Every RECHECK_TURNS real turns it is asked once more, with the name it has, and keeps it
17
+ * (KEEP) unless the work has clearly moved on.
18
+ * - A name the PM typed always wins and locks it (s.nameBy === 'pm'): Claude never renames that session again.
19
+ *
20
+ * The naming run is `claude -p` with no tools and no saved session: it reads the PM's first message, the latest one and Claude's latest
21
+ * answer, and prints a name. It runs under the PM's own login, like every headless job (D75). Pure: no I/O, no process; server.js runs it.
22
+ */
23
+
24
+ const NAME_MAX = 60;
25
+ const RECHECK_TURNS = 12; // real model turns between two "does the name still fit?" checks
26
+ const MIN_ANSWER = 20; // an answer shorter than this ("OK.", "On it.") is not a real answer yet
27
+ const RETRY_MS = 10 * 60 * 1000; // a failed run is tried again after this long
28
+
29
+ const clip = (t, n) => { const s = String(t == null ? '' : t).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1) + '…' : s; };
30
+
31
+ /** The name every surface shows for a session row (the server's own record or the wire row). */
32
+ function shownName(s) {
33
+ if (!s) return '';
34
+ const by = s.nameBy || s.name_by;
35
+ const auto = s.autoName ? s.autoName.text : s.auto_name;
36
+ const cli = s.hx && s.hx.title;
37
+ if (by === 'pm') return s.name || auto || cli || '';
38
+ return auto || cli || s.name || '';
39
+ }
40
+
41
+ /**
42
+ * Whether Claude should name this session now. `hx` is the harness read (lib/transcript-read.js): `turns` counts real model turns and
43
+ * `turn === 'user'` means the model finished speaking. `automatic` is true for a job the workspace started (a skill, a schedule): those
44
+ * are named by what started them.
45
+ */
46
+ function due(s, { hx, automatic = false, now = Date.now() } = {}) {
47
+ if (!s || s.nameBy === 'pm') return null;
48
+ if (s.agent !== 'claude' || s.headless || automatic || s.state === 'exited') return null;
49
+ if (!hx || !hx.turns || hx.turn !== 'user') return null;
50
+ if (s.nameFail && now - s.nameFail.at < RETRY_MS && s.nameFail.turns === hx.turns) return null;
51
+ if (!s.autoName) return 'first';
52
+ const last = s.autoName.checked || s.autoName.turns || 0;
53
+ return hx.turns - last >= RECHECK_TURNS ? 'recheck' : null;
54
+ }
55
+
56
+ function promptFor({ first, last, answer, current }) {
57
+ const lines = [
58
+ 'Name this working session in 2 to 6 words, the way a person titles a to-do: sentence case, starting with a verb, naming the job (for example: Shortlist CIAM tender vendors).',
59
+ 'No quotes, no ending period, no session or chat words. Reply with the name only, on one line.',
60
+ ];
61
+ if (current) lines.push(`Its name now is: ${clip(current, NAME_MAX)}. If that still names the job, reply KEEP. Give a new name only when the job has clearly changed.`);
62
+ lines.push('', 'The PM first asked:', clip(first, 600));
63
+ if (last && last !== first) lines.push('', 'The PM most recently asked:', clip(last, 400));
64
+ lines.push('', 'Claude answered:', clip(answer, 800));
65
+ return lines.join('\n');
66
+ }
67
+
68
+ /** The first line of the run's text, cleaned: quotes, a leading "Name:" and an ending period are dropped. */
69
+ function parseName(text) {
70
+ let t = String(text == null ? '' : text).split('\n').map((l) => l.trim()).find(Boolean) || '';
71
+ t = t.replace(/^(?:session\s+)?(?:name|title)\s*:\s*/i, '').replace(/^["'“‘`*_]+|["'”’`*_]+$/g, '').replace(/[.。]+$/, '').replace(/[\u0000-\u001f\u007f]/g, '').trim();
72
+ if (!t) return null;
73
+ if (/^keep$/i.test(t)) return 'KEEP';
74
+ if (t.length > NAME_MAX) t = t.slice(0, NAME_MAX).replace(/\s+\S*$/, '') || t.slice(0, NAME_MAX);
75
+ return t;
76
+ }
77
+
78
+ /** The PM's first message, the latest one, and Claude's latest answer, from a conversation read; null until there is a real answer. */
79
+ function exchangeOf(messages) {
80
+ const ms = Array.isArray(messages) ? messages : [];
81
+ const users = ms.filter((m) => m && m.role === 'user' && m.text);
82
+ let answer = null;
83
+ for (let i = ms.length - 1; i >= 0; i--) if (ms[i] && ms[i].role === 'assistant' && ms[i].text) { answer = ms[i].text; break; }
84
+ if (!users.length || !answer || String(answer).trim().length < MIN_ANSWER) return null;
85
+ return { first: users[0].text, last: users[users.length - 1].text, answer };
86
+ }
87
+
88
+ /** What the naming run's answer does to the session record. The PM's name always wins, even over a run that started before it. */
89
+ function apply(s, name, turns, at) {
90
+ if (!s || !name || s.nameBy === 'pm') return false;
91
+ if (name === 'KEEP' || (s.autoName && name === s.autoName.text)) {
92
+ if (!s.autoName) return false; // nothing to keep: the first run must give a name
93
+ s.autoName = { ...s.autoName, checked: turns };
94
+ return true;
95
+ }
96
+ s.autoName = { text: name, at, turns };
97
+ return true;
98
+ }
99
+
100
+ /** No tools, nothing saved, JSON out: the run can only print a name. */
101
+ const argv = () => ['-p', '--output-format', 'json', '--no-session-persistence', '--tools', ''];
102
+
103
+ module.exports = { shownName, due, promptFor, parseName, exchangeOf, argv, apply, NAME_MAX, RECHECK_TURNS, MIN_ANSWER, RETRY_MS };
@@ -71,7 +71,8 @@ function item(x, source, i) {
71
71
  const at = `item ${i + 1} of ${source}`;
72
72
  if (!isObj(x)) return { ok: false, error: `${at} must be an object` };
73
73
  const r = fields(x, [['title', T(LIMITS.title)], ['link', (v) => link(v, at + ' link')], ['where', T(LIMITS.short)], ['who', T(LIMITS.short)],
74
- ['at', T(40)], ['about', T(LIMITS.about)], ['ask', T(LIMITS.ask)], ['due', T(40)], ['mention', B], ['reply_needed', B]]);
74
+ ['at', T(40)], ['about', T(LIMITS.about)], ['ask', T(LIMITS.ask)], ['due', T(40)], ['mention', B], ['reply_needed', B],
75
+ ['replied', B], ['broadcast', B]]);
75
76
  if (!r.ok) return { ok: false, error: `${at}: ${r.error}` };
76
77
  if (!r.v.title) return { ok: false, error: `${at} has no title` };
77
78
  if (x.initiative_id !== undefined) {
@@ -166,6 +167,8 @@ function write(runtimeDir, r, now = new Date()) {
166
167
  const tmp = `${f}.${process.pid}.tmp`;
167
168
  fs.writeFileSync(tmp, JSON.stringify(rec) + '\n');
168
169
  fs.renameSync(tmp, f);
170
+ // its mentions are kept apart, so the next read (which replaces this one) cannot lose one that still waits on the PM
171
+ try { require('./mention-store.js').ingestRead(runtimeDir, rec); } catch { /* the read is saved; Mentions reads it again on its next GET */ }
169
172
  return rec;
170
173
  }
171
174
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.409.0",
3
+ "version": "0.411.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.409.0",
9
+ "version": "0.411.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.409.0",
3
+ "version": "0.411.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -188,7 +188,7 @@ const ALLOWED = /^\/api\/(?:boards\/(?:asks\/(?:add|accept|decline)|move|archive
188
188
  const I = await open('/premium-initiative.html?id=pa-one&ws=' + encodeURIComponent(B.ws) + '&board=' + encodeURIComponent(B.id));
189
189
  const ip = I.page;
190
190
  const viaMore = async (pg, label) => { await pg.click('#czViewer:not([hidden]) [data-cz-vw="more"]'); await until(() => pg.evaluate(() => !!document.querySelector('#czViewer .cz-vw-menu'))); await pg.click(`#czViewer .cz-vw-menu [role="menuitem"]:has(> span:first-child:text-is("${label}"))`); }; // the Overview's other views, Open the full record and Sprint sit under ⋯ (XvATasks)
191
- const landed = await until(() => ip.evaluate(() => { const q = new URLSearchParams(location.search); return location.pathname === '/premium.html' && q.get('ini') === 'pa-one' && !!q.get('ws') && !!q.get('board') && !!document.querySelector('.hm-card [data-hm-ov]'); }), 60000);
191
+ const landed = await until(() => ip.evaluate(() => { const q = new URLSearchParams(location.search); return location.pathname === '/premium.html' && q.get('ini') === 'pa-one' && !!q.get('ws') && !!q.get('board') && !!document.querySelector('.hm-card .cz-sl'); }), 60000);
192
192
  ok('I0 the expand link lands on Home with the initiative selected, ws and board kept', !!landed, await ip.evaluate(() => location.href));
193
193
  await ip.click('#czViewer .hi-pgh [data-hi-addtask]'); // the initiative's page (canvas HbC): its + drills into Tasks
194
194
  await until(() => ip.evaluate(() => !!document.querySelector('#czViewer:not([hidden]) [data-hi-v]')), 60000);
@@ -206,21 +206,23 @@ const ALLOWED = /^\/api\/(?:boards\/(?:asks\/(?:add|accept|decline)|move|archive
206
206
  await ip.click('#czViewer [data-ov-life-no]');
207
207
  ok('I3 Not now takes the question back', await until(() => ip.evaluate(() => !document.querySelector('#czViewer #ovWhy') && !!document.querySelector('#czViewer [data-ov-life="on-hold"]'))));
208
208
  await ip.click('#czViewer [data-cz-vw="back"]'); // ← from Stage: the initiative's page again (canvas HbCDrill)
209
- // the card: Back always asks for a reason, and the move line carries it (InStage)
210
- const back = await until(() => ip.evaluate(() => !!document.querySelector('.hm-card [data-hi-back]')), 30000);
211
- ok('I4 the card has Move to the next stage and Back', back && await ip.evaluate(() => /^Move to /.test((document.querySelector('.hm-card [data-hi-move]') || {}).textContent || '')));
209
+ // the card (stage card D): its last node, the next stage, opens the move popover with Move now and Back; Back always asks for a reason,
210
+ // and the move line carries it (InStage)
211
+ const openNext = async () => { await until(() => ip.evaluate(() => !!document.querySelector('.hm-card [data-hi-next]')), 30000); await ip.click('.hm-card [data-hi-next]'); return until(() => ip.evaluate(() => !!document.querySelector('.hi-pop [data-hi-goback]'))); };
212
+ const back = await openNext();
213
+ ok('I4 the card\'s next stage opens Move to the next stage now and Back', back && await ip.evaluate(() => /^Move to .+ now$/.test(((document.querySelector('.hi-pop [data-hi-go]') || {}).textContent || '').trim())));
212
214
  if (back) {
213
215
  const m0 = lines('boards.jsonl').filter((l) => l.kind === 'move').length;
214
- await ip.click('.hm-card [data-hi-back]');
216
+ await ip.click('.hi-pop [data-hi-goback]');
215
217
  const asked = await until(() => ip.evaluate(() => { const d = document.querySelector('.hi-pop[role="dialog"]'); return d ? { go: d.querySelector('[data-hi-go]').disabled, chips: d.querySelectorAll('[data-hi-why]').length } : null; }));
216
218
  ok('I4 Back asks why first: Move back waits for a reason and records nothing yet', !!asked && asked.go === true && asked.chips === 4 && lines('boards.jsonl').filter((l) => l.kind === 'move').length === m0, JSON.stringify(asked));
217
219
  await ip.click('.hi-pop [data-hi-why="New research"]'); await ip.fill('.hi-pop #hiWhy', 'Interviews changed the scope');
218
220
  await ip.click('.hi-pop [data-hi-go]');
219
221
  ok('I4 Move back records one move line with the reason as its why', await until(() => { const L = lines('boards.jsonl').filter((l) => l.kind === 'move'); const x = L[L.length - 1]; return L.length === m0 + 1 && x.id === 'pa-one' && x.to === bar.cur && x.why === 'Back: New research. Interviews changed the scope'; }), JSON.stringify(lines('boards.jsonl').filter((l) => l.kind === 'move').slice(-1)));
220
222
  ok('I4 the Undo toast shows after the move', await until(() => ip.evaluate(() => { const t = document.querySelector('#hiToast'); return !!t && !t.hidden && /moved to/.test(t.textContent) && !!t.querySelector('[data-hi-undo]'); })));
221
- await until(() => ip.evaluate(() => !!document.querySelector('.hm-card [data-hi-auto]')), 30000);
222
- await ip.click('.hm-card [data-hi-auto]');
223
- ok('I5 the Moves on by itself switch is a file-mode record of the initiative', await until(() => lines('initiative-layout.jsonl').some((l) => l.kind === 'auto' && l.initiative === 'pa-one' && l.on === false)) && await until(() => ip.evaluate(() => (document.querySelector('.hm-card [data-hi-auto]') || {}).getAttribute && document.querySelector('.hm-card [data-hi-auto]').getAttribute('aria-checked') === 'false')));
223
+ await openNext();
224
+ await ip.click('.hi-pop [data-hi-auto]');
225
+ ok('I5 the Moves on by itself switch is a file-mode record of the initiative', await until(() => lines('initiative-layout.jsonl').some((l) => l.kind === 'auto' && l.initiative === 'pa-one' && l.on === false)) && await until(() => ip.evaluate(() => (document.querySelector('.hi-pop [data-hi-auto]') || {}).getAttribute && document.querySelector('.hi-pop [data-hi-auto]').getAttribute('aria-checked') === 'false')));
224
226
  }
225
227
 
226
228
  /* S the PMOS-self board: the model says self, the page offers no move and no New initiative */