@clagentic/console 1.10.0-beta.2 → 1.10.0-beta.3

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 (42) hide show
  1. package/lib/activity-clock.js +23 -0
  2. package/lib/build-sha.json +2 -2
  3. package/lib/cli-transcript-title.js +131 -0
  4. package/lib/debug-log.js +17 -0
  5. package/lib/exit-flush.js +44 -0
  6. package/lib/grant-keys.js +179 -0
  7. package/lib/log-field.js +34 -0
  8. package/lib/project-http.js +2 -0
  9. package/lib/project-notifications.js +4 -0
  10. package/lib/project-prompt-responses.js +2 -1
  11. package/lib/project-session-grants.js +73 -0
  12. package/lib/project-sessions.js +12 -0
  13. package/lib/project-user-message.js +6 -5
  14. package/lib/project.js +2 -0
  15. package/lib/prompt-kinds/permission.js +18 -0
  16. package/lib/prompt-label.js +60 -0
  17. package/lib/prompt-registry.js +116 -13
  18. package/lib/prompt-source.js +65 -0
  19. package/lib/public/css/notifications-center.css +15 -0
  20. package/lib/public/css/overlays.css +18 -0
  21. package/lib/public/css/rewind.css +8 -0
  22. package/lib/public/modules/app-messages.js +3 -0
  23. package/lib/public/modules/app-notifications.js +9 -1
  24. package/lib/public/modules/prompt-banner.js +12 -0
  25. package/lib/public/modules/prompt-kinds/permission-choices.js +6 -1
  26. package/lib/public/modules/prompt-kinds/permission.js +15 -0
  27. package/lib/public/modules/prompt-label.js +44 -0
  28. package/lib/public/modules/prompts.js +9 -0
  29. package/lib/public/modules/session-grants.js +131 -0
  30. package/lib/public/modules/sidebar-sessions.js +11 -0
  31. package/lib/runtime-env.js +1 -1
  32. package/lib/sdk-bridge.js +53 -101
  33. package/lib/sdk-message-processor.js +14 -67
  34. package/lib/session-ai-title.js +80 -0
  35. package/lib/session-input.js +32 -2
  36. package/lib/sessions.js +14 -18
  37. package/lib/utils.js +9 -47
  38. package/lib/ws-schema.js +6 -3
  39. package/lib/yoke/adapters/claude.js +0 -57
  40. package/lib/yoke/adapters/codex.js +4 -75
  41. package/lib/yoke/interface.js +3 -7
  42. package/package.json +1 -1
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ // The one writer of session.lastActivityAt, the clock the idle reaper compares
4
+ // against (startIdleReaper in lib/sdk-bridge.js). Every bump names its source
5
+ // and, with CLAGENTIC_CONSOLE_DEBUG set, logs it, so a session that is never
6
+ // reaped can be traced to the event that kept resetting its clock.
7
+
8
+ var { debugLog } = require("./debug-log");
9
+ var { logField } = require("./log-field");
10
+
11
+ /**
12
+ * @param {object} session
13
+ * @param {string} source - what moved the clock (a fixed vocabulary at the call
14
+ * sites, e.g. "turn-result", "subagent-stream", "task_progress").
15
+ * @param {string} slug - the owning project; console session ids repeat across
16
+ * projects.
17
+ */
18
+ function bumpLastActivity(session, source, slug) {
19
+ session.lastActivityAt = Date.now();
20
+ debugLog("[activity] lastActivityAt bump: project=" + logField(slug) + " session=" + logField(session.localId) + " source=" + logField(source));
21
+ }
22
+
23
+ module.exports = { bumpLastActivity: bumpLastActivity };
@@ -1,4 +1,4 @@
1
1
  {
2
- "sha": "1e4c285f1bfb4f164e33781a01e713c038b29ac3",
3
- "writtenAt": "2026-10-14T16:34:23.977Z"
2
+ "sha": "fed91a544d850e066830fd24c98e9f4a28d85422",
3
+ "writtenAt": "2026-10-15T11:55:56.872Z"
4
4
  }
@@ -0,0 +1,131 @@
1
+ // cli-transcript-title.js - reads the title the Claude Code CLI wrote for a
2
+ // session into its own transcript.
3
+ //
4
+ // The CLI appends a record of this shape to <claudeDir>/projects/<cwd>/<id>.jsonl
5
+ // each time it titles the session, and the last one wins:
6
+ //
7
+ // {"type":"ai-title","aiTitle":"...","sessionId":"<id>"}
8
+ //
9
+ // The SDK message stream does not carry it (sdk.d.ts has no message for it), so
10
+ // the transcript is the only source. Nothing here writes to the transcript.
11
+
12
+ var fs = require("fs");
13
+ var path = require("path");
14
+ var utils = require("./utils");
15
+ var { isSafeSessionId, sessionPathWithin } = require("./session-id");
16
+
17
+ // A transcript can be large and the record is normally near its end, so the
18
+ // file is read backwards in chunks and the scan stops at the first match.
19
+ var CHUNK_BYTES = 64 * 1024;
20
+ var MAX_SCAN_BYTES = 16 * 1024 * 1024;
21
+ var MAX_TITLE_CHARS = 100;
22
+
23
+ var NEWLINE = 0x0a;
24
+
25
+ function normalize(title) {
26
+ if (typeof title !== "string") return null;
27
+ var t = title.replace(/\s+/g, " ").trim();
28
+ return t ? t.substring(0, MAX_TITLE_CHARS) : null;
29
+ }
30
+
31
+ function aiTitleOfLine(line, sessionId) {
32
+ if (line.indexOf('"ai-title"') === -1) return null;
33
+ var obj;
34
+ try { obj = JSON.parse(line); } catch (e) { return null; }
35
+ if (!obj || obj.type !== "ai-title") return null;
36
+ // A record naming another session is not this session's title.
37
+ if (obj.sessionId && obj.sessionId !== sessionId) return null;
38
+ return normalize(obj.aiTitle);
39
+ }
40
+
41
+ // Resolves the latest ai-title in the transcript at filePath for sessionId, or
42
+ // null when there is none or the file cannot be read.
43
+ function readLatestAiTitle(filePath, sessionId) {
44
+ return fs.promises.open(filePath, "r").then(function (fh) {
45
+ function scan() {
46
+ return fh.stat().then(function (st) {
47
+ var pos = st.size;
48
+ var scanned = 0;
49
+ var carry = Buffer.alloc(0);
50
+
51
+ function step() {
52
+ if (pos <= 0 || scanned >= MAX_SCAN_BYTES) {
53
+ // pos === 0: carry is the first line of the file.
54
+ return Promise.resolve(pos <= 0 && carry.length ? aiTitleOfLine(carry.toString("utf8"), sessionId) : null);
55
+ }
56
+ var len = Math.min(CHUNK_BYTES, pos);
57
+ pos -= len;
58
+ scanned += len;
59
+ var chunk = Buffer.alloc(len);
60
+ return fh.read(chunk, 0, len, pos).then(function () {
61
+ var buf = Buffer.concat([chunk, carry]);
62
+ // Lines are split on bytes so a multibyte character cut by the
63
+ // chunk edge is never decoded half-way.
64
+ var end = buf.length;
65
+ var found = null;
66
+ for (var i = buf.length - 1; i >= 0 && found === null; i--) {
67
+ if (buf[i] === NEWLINE) {
68
+ if (end > i + 1) found = aiTitleOfLine(buf.toString("utf8", i + 1, end), sessionId);
69
+ end = i;
70
+ }
71
+ }
72
+ if (found !== null) return found;
73
+ carry = buf.subarray(0, end);
74
+ return step();
75
+ });
76
+ }
77
+ return step();
78
+ });
79
+ }
80
+ return scan().then(
81
+ function (v) { return fh.close().then(function () { return v; }); },
82
+ function (e) { return fh.close().then(function () { throw e; }); }
83
+ );
84
+ }).catch(function () { return null; });
85
+ }
86
+
87
+ // Finds <claudeDir>/projects/*/<sessionId>.jsonl. The directory named for a
88
+ // cwd in cwds is tried first; any other project directory is searched after,
89
+ // because the CLI names the directory for the cwd the query ran in.
90
+ // Resolves the path or null.
91
+ function findTranscript(claudeDir, cwds, sessionId) {
92
+ if (!isSafeSessionId(sessionId)) return Promise.resolve(null);
93
+ var projectsDir = path.join(claudeDir, "projects");
94
+
95
+ function exists(p) {
96
+ return fs.promises.stat(p).then(function (st) { return st.isFile(); }, function () { return false; });
97
+ }
98
+
99
+ var tried = {};
100
+ var candidates = [];
101
+ (cwds || []).forEach(function (c) {
102
+ if (typeof c !== "string" || !c) return;
103
+ var dir = path.join(projectsDir, utils.encodeCwd(c));
104
+ if (!tried[dir]) { tried[dir] = true; candidates.push(dir); }
105
+ });
106
+
107
+ function tryDirs(i) {
108
+ if (i >= candidates.length) return Promise.resolve(null);
109
+ var p = sessionPathWithin(candidates[i], sessionId, ".jsonl");
110
+ return exists(p).then(function (ok) { return ok ? p : tryDirs(i + 1); });
111
+ }
112
+
113
+ return tryDirs(0).then(function (hit) {
114
+ if (hit) return hit;
115
+ return fs.promises.readdir(projectsDir).then(function (names) {
116
+ function next(i) {
117
+ if (i >= names.length) return Promise.resolve(null);
118
+ var dir = path.join(projectsDir, names[i]);
119
+ if (tried[dir]) return next(i + 1);
120
+ var p = sessionPathWithin(dir, sessionId, ".jsonl");
121
+ return exists(p).then(function (ok) { return ok ? p : next(i + 1); });
122
+ }
123
+ return next(0);
124
+ }, function () { return null; });
125
+ });
126
+ }
127
+
128
+ module.exports = {
129
+ readLatestAiTitle: readLatestAiTitle,
130
+ findTranscript: findTranscript,
131
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ // Lines worth keeping off the journal by default: they fire per stream event.
4
+ // Set CLAGENTIC_CONSOLE_DEBUG to see them. The variable is read at each call so
5
+ // an operator can start the daemon with it and a test can set it for one case.
6
+
7
+ var { readConsoleEnv } = require("./env-compat");
8
+
9
+ function debugEnabled() {
10
+ return !!readConsoleEnv("CLAGENTIC_CONSOLE_DEBUG");
11
+ }
12
+
13
+ function debugLog(line) {
14
+ if (debugEnabled()) console.log(line);
15
+ }
16
+
17
+ module.exports = { debugLog: debugLog, debugEnabled: debugEnabled };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ // Everything that must be written before the process ends, behind ONE
4
+ // process "exit" listener however many callers register.
5
+ //
6
+ // Each project's session manager used to add its own listener, so a daemon with
7
+ // fifty projects added fifty to `process` at startup and tripped Node's
8
+ // MaxListenersExceededWarning (the default cap is 10; the daemon raises it, and
9
+ // raising it again would only move the line). The listener is installed when
10
+ // the first flusher registers and removed when the last one unregisters, so a
11
+ // daemon that opens and closes projects does not accumulate any.
12
+
13
+ var flushers = new Set();
14
+ var installed = false;
15
+
16
+ function flushAll() {
17
+ flushers.forEach(function (flush) {
18
+ // One flusher failing must not stop the others: this is the last chance
19
+ // any of them gets to write.
20
+ try { flush(); }
21
+ catch (e) { console.error("[exit-flush] flush failed:", e && e.message ? e.message : e); }
22
+ });
23
+ }
24
+
25
+ /**
26
+ * @param {function(): void} flush - runs synchronously when the process exits.
27
+ * @returns {function(): void} unregister; safe to call more than once.
28
+ */
29
+ function registerExitFlush(flush) {
30
+ flushers.add(flush);
31
+ if (!installed) {
32
+ process.on("exit", flushAll);
33
+ installed = true;
34
+ }
35
+ return function unregister() {
36
+ flushers.delete(flush);
37
+ if (installed && flushers.size === 0) {
38
+ process.removeListener("exit", flushAll);
39
+ installed = false;
40
+ }
41
+ };
42
+ }
43
+
44
+ module.exports = { registerExitFlush: registerExitFlush };
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+
3
+ // What an "Allow for Session" answer grants, and how a later tool call is
4
+ // matched against it. One function builds the key for a call; the same key is
5
+ // what is stored when the operator grants it and what a later call is looked
6
+ // up by, so a grant covers exactly the calls that map to its key and no more.
7
+ //
8
+ // Key shapes (stored as keys of session.allowedTools, persisted in the session
9
+ // meta record, always with the value true):
10
+ // <Tool> whole tool. Older sessions hold these (the grant used
11
+ // to be the whole tool); they stay readable and in
12
+ // force until revoked. New grants never take this
13
+ // shape for a tool that has a narrower one.
14
+ // Bash=<command> exactly this command line and nothing wider. A line
15
+ // too long to keep has no key. Bash:<anything> (the
16
+ // retired prefix shape) is dropped on load.
17
+ // Skill:<name> one skill.
18
+ // <other tool> tool name (MCP tools already carry server and tool).
19
+ //
20
+ // File tools (Write, Edit, MultiEdit, NotebookEdit, the codex file change)
21
+ // have no key at all: every call is answered on its own, and only a legacy
22
+ // whole-tool grant persisted by an older session is honoured.
23
+ //
24
+ // A call with no usable key (a file-tool call, a command too long to persist)
25
+ // has key null: it can be allowed once, never for the session.
26
+
27
+ // The session meta record is read back from a 4 KiB chunk, so a grant map that
28
+ // grew without bound would make the whole session unloadable after a restart.
29
+ var MAX_KEY_LENGTH = 160;
30
+ var MAX_GRANTS = 16;
31
+ var MAX_GRANT_BYTES = 1600;
32
+
33
+ // Binding a file grant to the filesystem (lexical paths, then realpaths) left
34
+ // a new hole at every review, so file tools never produce a session grant: no
35
+ // key, no stored value, no filesystem read.
36
+ var FILE_TOOLS = Object.create(null);
37
+ FILE_TOOLS.Write = true;
38
+ FILE_TOOLS.Edit = true;
39
+ FILE_TOOLS.MultiEdit = true;
40
+ FILE_TOOLS.NotebookEdit = true;
41
+
42
+ function isFileTool(toolName) {
43
+ return FILE_TOOLS[toolName] === true;
44
+ }
45
+
46
+ // The one table of tools that have scoped keys, or (file tools) none. A
47
+ // bare-name key for any of them is the legacy whole-tool grant that older
48
+ // sessions persisted; isGranted honours it for every tool listed here, so
49
+ // changing a tool's keys cannot silently drop its persisted grants.
50
+ var SCOPED_TOOLS = Object.create(null);
51
+ SCOPED_TOOLS.Bash = true;
52
+ SCOPED_TOOLS.Skill = true;
53
+ Object.keys(FILE_TOOLS).forEach(function (t) { SCOPED_TOOLS[t] = true; });
54
+
55
+ function hasNarrowKey(toolName) {
56
+ return SCOPED_TOOLS[toolName] === true;
57
+ }
58
+
59
+ // Deriving a prefix from the command text (lexical rules over a shell grammar)
60
+ // missed shell semantics at two successive reviews, so a Bash grant is the
61
+ // exact line and nothing wider. The command is used byte for byte: any
62
+ // transform (trim, whitespace collapse, normalization) would let two different
63
+ // command strings, which bash runs differently, share one key.
64
+ function bashKey(input) {
65
+ var command = input && typeof input.command === "string" ? input.command : "";
66
+ if (command === "") return null;
67
+ return command.length + 5 <= MAX_KEY_LENGTH ? "Bash=" + command : null;
68
+ }
69
+
70
+ // Key shapes older sessions persisted that no call produces any more: a file
71
+ // tool key (Write:<path> in any form) and a Bash prefix key (Bash:<command>).
72
+ // They are dropped on load, never honoured.
73
+ function isRetiredKey(key) {
74
+ var m = /^([^:=]+)([:=])/.exec(key);
75
+ if (m === null) return false;
76
+ return isFileTool(m[1]) || (m[1] === "Bash" && m[2] === ":");
77
+ }
78
+
79
+ /**
80
+ * Whether a persisted value is one a grant under this key can hold: true, and
81
+ * never under a retired key.
82
+ */
83
+ function isGrantValue(key, value) {
84
+ return value === true && !isRetiredKey(key);
85
+ }
86
+
87
+ /**
88
+ * The key a call is granted and matched by, or null when it cannot be granted
89
+ * for the session.
90
+ * @param {string} toolName
91
+ * @param {?object} input
92
+ * @returns {?string}
93
+ */
94
+ function permissionGrantKey(toolName, input) {
95
+ if (toolName === "Bash") return bashKey(input);
96
+ if (isFileTool(toolName)) return null;
97
+ // The Skill tool is one name over many skills; a bare "Skill" key would
98
+ // authorize every one of them. Falls back to the bare name only when the
99
+ // call names no skill.
100
+ if (toolName === "Skill" && input && typeof input.skill === "string" && input.skill) {
101
+ return "Skill:" + input.skill;
102
+ }
103
+ return toolName;
104
+ }
105
+
106
+ /**
107
+ * Describe a stored key for the operator.
108
+ * @param {string} key
109
+ * @returns {{key: string, tool: string, wholeTool: boolean, text: string}}
110
+ */
111
+ function describeGrantKey(key) {
112
+ var m = /^([^:=]+)([:=])([\s\S]*)$/.exec(key);
113
+ if (!m) {
114
+ return {
115
+ key: key, tool: key, wholeTool: true,
116
+ text: "Every " + key + " call, whatever it does (whole-tool grant)",
117
+ };
118
+ }
119
+ var tool = m[1];
120
+ var value = m[3];
121
+ var text;
122
+ if (tool === "Bash") {
123
+ text = "Bash: exactly this command: " + value;
124
+ } else if (tool === "Skill") {
125
+ text = "Skill " + value;
126
+ } else {
127
+ text = key;
128
+ }
129
+ return { key: key, tool: tool, wholeTool: false, text: text };
130
+ }
131
+
132
+ /**
133
+ * The sentence the card and banner show before the click, or null when the
134
+ * call cannot be granted for the session.
135
+ * @returns {?string}
136
+ */
137
+ function grantScopeText(toolName, input) {
138
+ var key = permissionGrantKey(toolName, input);
139
+ if (key === null) return null;
140
+ var d = describeGrantKey(key);
141
+ if (d.wholeTool) return "Allow every " + toolName + " call in this session";
142
+ if (d.tool === "Bash") {
143
+ return "Allow only this exact command in this session";
144
+ }
145
+ if (d.tool === "Skill") return "Allow the " + key.slice(6) + " skill in this session";
146
+ return null;
147
+ }
148
+
149
+ /** Whether a call is covered by a grant in the session's map. */
150
+ function isGranted(allowedTools, toolName, input) {
151
+ if (!allowedTools) return false;
152
+ var own = function (k) { return Object.prototype.hasOwnProperty.call(allowedTools, k); };
153
+ var key = permissionGrantKey(toolName, input);
154
+ if (key !== null && own(key) && isGrantValue(key, allowedTools[key])) return true;
155
+ // A whole-tool grant from before grants were scoped.
156
+ return hasNarrowKey(toolName) && own(toolName) && allowedTools[toolName] === true;
157
+ }
158
+
159
+ /** Whether one more grant fits in the persisted record. */
160
+ function fitsBudget(allowedTools, key) {
161
+ var keys = Object.keys(allowedTools || {});
162
+ if (keys.indexOf(key) !== -1) return true;
163
+ if (keys.length >= MAX_GRANTS) return false;
164
+ var size = function (k) { return Buffer.byteLength(k) + 8; };
165
+ var bytes = keys.reduce(function (n, k) { return n + size(k); }, 0);
166
+ return bytes + size(key) <= MAX_GRANT_BYTES;
167
+ }
168
+
169
+ module.exports = {
170
+ permissionGrantKey: permissionGrantKey,
171
+ describeGrantKey: describeGrantKey,
172
+ grantScopeText: grantScopeText,
173
+ isGranted: isGranted,
174
+ isFileTool: isFileTool,
175
+ isGrantValue: isGrantValue,
176
+ fitsBudget: fitsBudget,
177
+ MAX_KEY_LENGTH: MAX_KEY_LENGTH,
178
+ MAX_GRANTS: MAX_GRANTS,
179
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ // One value for a key=value log line. Session titles, tool names, user ids and
4
+ // project slugs can come from outside the daemon, so nothing that could end a
5
+ // line or split a field survives: every character outside a small allowlist
6
+ // becomes "_", and the value is cut to maxLen. Never pass prompt text through
7
+ // here: the answer to "may this be logged?" is decided by the caller, this
8
+ // only keeps a permitted value on one line.
9
+
10
+ var DISALLOWED = /[^A-Za-z0-9._:@\/+-]/g;
11
+
12
+ // Control characters plus the Unicode line and paragraph separators. Built from
13
+ // char codes so the pattern never holds a raw line-terminator character.
14
+ var LINE_BREAKERS = new RegExp(
15
+ "[" + String.fromCharCode(0) + "-" + String.fromCharCode(0x1f) +
16
+ String.fromCharCode(0x7f) + String.fromCharCode(0x2028) + String.fromCharCode(0x2029) + "]+",
17
+ "g"
18
+ );
19
+
20
+ function logField(value, maxLen) {
21
+ if (value === undefined || value === null || value === "") return "-";
22
+ return String(value).replace(DISALLOWED, "_").slice(0, maxLen || 64);
23
+ }
24
+
25
+ // Free text that has to be readable (a refusal reason), for the END of a line:
26
+ // anything that could end the line or forge another becomes a space, and the
27
+ // text is cut to maxLen.
28
+ function logText(value, maxLen) {
29
+ return String(value === undefined || value === null ? "" : value)
30
+ .replace(LINE_BREAKERS, " ")
31
+ .slice(0, maxLen || 200);
32
+ }
33
+
34
+ module.exports = { logField: logField, logText: logText };
@@ -7,6 +7,7 @@ var { fsAsUser } = require("./os-users");
7
7
  var usersModule = require("./users");
8
8
  var { promptsFor } = require("./prompt-registry");
9
9
  var { mayAnswerPrompt } = require("./prompt-access");
10
+ var promptSource = require("./prompt-source");
10
11
  var fileScope = require("./project-file-scope");
11
12
 
12
13
  var IMAGE_EXTS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".bmp", ".ico"]);
@@ -244,6 +245,7 @@ function attachHTTP(ctx) {
244
245
  : prompts.respond(requestId, { decision: decision }, {
245
246
  kinds: ["permission", "plan"],
246
247
  denyMessage: "Denied via push notification",
248
+ source: promptSource.fromPush(req, decision),
247
249
  });
248
250
  if (outcome.status === "resolved") {
249
251
  res.writeHead(200, { "Content-Type": "application/json" });
@@ -75,6 +75,10 @@ var formatters = {
75
75
  // So the banner offers the answers the card does (see prompt-banner.js).
76
76
  suppressAlwaysAllowRule: data.suppressAlwaysAllowRule === true ? true : undefined,
77
77
  defaultToNo: data.defaultToNo === true ? true : undefined,
78
+ // Who asked and what Allow for session would grant: a banner reaches
79
+ // every client whatever project it is viewing.
80
+ label: data.label || null,
81
+ grantScope: typeof data.grantScope === "string" ? data.grantScope : null,
78
82
  },
79
83
  };
80
84
  },
@@ -16,6 +16,7 @@ var promptKinds = require("./prompt-kinds");
16
16
  var { mayAnswerPrompt } = require("./prompt-access");
17
17
  var { ownValue } = require("./prompt-kinds/codecs");
18
18
  var { INITIATORS } = require("./turn-initiator");
19
+ var promptSource = require("./prompt-source");
19
20
 
20
21
  // alias type -> { toPrompt(msg), kinds it may answer, stale reply type }
21
22
  var LEGACY_RESPONSES = {
@@ -178,7 +179,7 @@ function attachPromptResponses(ctx) {
178
179
  function answer(ws, msg, kinds, staleReplyType) {
179
180
  var answerable = kinds.every(promptKinds.operatorMayAnswer) && mayAnswer(ws, msg.requestId);
180
181
  var outcome = answerable
181
- ? promptsFor(sm).respond(msg.requestId, msg, { session: getSessionForWs(ws), kinds: kinds, responder: ws })
182
+ ? promptsFor(sm).respond(msg.requestId, msg, { session: getSessionForWs(ws), kinds: kinds, responder: ws, source: promptSource.fromWs(ws) })
182
183
  : { status: "stale" };
183
184
  if (outcome.status === "resolved") return;
184
185
  // Refused as it stands: still pending, so re-offer it to the responder,
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ // WS entry point for a session's "Allow for Session" grants: list them and
4
+ // revoke one. The grants themselves live in the prompt registry
5
+ // (lib/prompt-registry.js, session.allowedTools); this module only maps the
6
+ // wire messages onto it and applies the same access rule as answering a
7
+ // prompt (lib/prompt-access.js), because revoking is the operator's decision
8
+ // about that session and listing shows what its agent may do unasked.
9
+
10
+ var { promptsFor } = require("./prompt-registry");
11
+ var { mayAnswerPrompt } = require("./prompt-access");
12
+
13
+ /**
14
+ * ctx fields: sm, sendTo, sendToSessionOthers, getSessionForWs
15
+ */
16
+ function attachSessionGrants(ctx) {
17
+ var sm = ctx.sm;
18
+ var sendTo = ctx.sendTo;
19
+ var sendToSessionOthers = ctx.sendToSessionOthers;
20
+ var getSessionForWs = ctx.getSessionForWs;
21
+
22
+ // The session a message names (the connection's own when it names none), if
23
+ // the connection may act on it.
24
+ function sessionFor(ws, msg) {
25
+ var session = msg.sessionId === undefined || msg.sessionId === null
26
+ ? getSessionForWs(ws)
27
+ : (typeof msg.sessionId === "number" && sm.sessions ? sm.sessions.get(msg.sessionId) : null);
28
+ if (!session || !mayAnswerPrompt(ws && ws._clagenticUser, session)) return null;
29
+ return session;
30
+ }
31
+
32
+ function grantsMessage(session) {
33
+ return { type: "session_grants", sessionId: session.localId, grants: promptsFor(sm).listGrants(session) };
34
+ }
35
+
36
+ // Said, not dropped, so the client can re-enable its button. It names nothing
37
+ // about the session, which this user may not see.
38
+ function unavailableMessage(msg) {
39
+ return { type: "session_grants", sessionId: msg.sessionId, error: "that session is not available to you" };
40
+ }
41
+
42
+ /** Returns true when msg was a grants message (handled). */
43
+ function handleGrantMessage(ws, msg) {
44
+ if (msg.type === "list_session_grants") {
45
+ var listed = sessionFor(ws, msg);
46
+ if (!listed) {
47
+ sendTo(ws, unavailableMessage(msg));
48
+ return true;
49
+ }
50
+ sendTo(ws, grantsMessage(listed));
51
+ return true;
52
+ }
53
+ if (msg.type === "revoke_session_grant") {
54
+ var session = sessionFor(ws, msg);
55
+ if (!session) {
56
+ sendTo(ws, unavailableMessage(msg));
57
+ return true;
58
+ }
59
+ promptsFor(sm).revokeGrant(session, msg.key);
60
+ // Every client viewing the session sees the list as it now is, whether
61
+ // or not the key was still there.
62
+ var now = grantsMessage(session);
63
+ sendTo(ws, now);
64
+ sendToSessionOthers(ws, session.localId, now);
65
+ return true;
66
+ }
67
+ return false;
68
+ }
69
+
70
+ return { handleGrantMessage: handleGrantMessage };
71
+ }
72
+
73
+ module.exports = { attachSessionGrants: attachSessionGrants };
@@ -11,7 +11,9 @@ var agentsFavorites = require("./agents-favorites");
11
11
  var sessionActivity = require("./session-activity");
12
12
  var { promptsFor } = require("./prompt-registry");
13
13
  var { attachPromptResponses } = require("./project-prompt-responses");
14
+ var { attachSessionGrants } = require("./project-session-grants");
14
15
  var { ownValue } = require("./prompt-kinds/codecs");
16
+ var { logField, logText } = require("./log-field");
15
17
  var { isKnownVendor } = require("./yoke");
16
18
  var sessionCapabilities = require("./session-capabilities");
17
19
  // Kick off SDK agent discovery in the background at module load.
@@ -149,6 +151,12 @@ function attachSessions(ctx) {
149
151
  onProcessingChanged: onProcessingChanged,
150
152
  ensureProjectAccessForSession: ensureProjectAccessForSession,
151
153
  });
154
+ var sessionGrants = attachSessionGrants({
155
+ sm: sm,
156
+ sendTo: sendTo,
157
+ sendToSessionOthers: sendToSessionOthers,
158
+ getSessionForWs: getSessionForWs,
159
+ });
152
160
 
153
161
  function sessionAcceptsMode(session, mode) {
154
162
  if (!ownValue(CAPABILITY_GATED_MODES, mode)) return true;
@@ -159,6 +167,7 @@ function attachSessions(ctx) {
159
167
  function handleSessionsMessage(ws, msg) {
160
168
 
161
169
  if (promptResponses.handlePromptMessage(ws, msg)) return true;
170
+ if (sessionGrants.handleGrantMessage(ws, msg)) return true;
162
171
 
163
172
  if (msg.type === "push_subscribe") {
164
173
  var _pushUserId = ws._clagenticUser ? ws._clagenticUser.id : null;
@@ -494,6 +503,9 @@ function attachSessions(ctx) {
494
503
  require("./session-resume").resumeStoredSession({ sm: sm, adapter: adapter, cwd: cwd }, msg.cliSessionId, { ws: ws }).then(function (resumed) {
495
504
  if (resumed) ws._clagenticActiveSession = resumed.localId;
496
505
  }, function (err) {
506
+ console.error("[project-sessions] resume_session failed: project=" + logField(slug)
507
+ + " session=" + logField(msg.cliSessionId) + " reason="
508
+ + logText(err && err.message ? err.message : err));
497
509
  sendTo(ws, { type: "error", text: "Could not resume this session: " + (err && err.message ? err.message : err) });
498
510
  });
499
511
  return true;
@@ -4,6 +4,7 @@ var { promptsFor } = require("./prompt-registry");
4
4
  var { putOwn } = require("./prompt-kinds/codecs");
5
5
  var { isKnownVendor } = require("./yoke");
6
6
  var { INITIATORS } = require("./turn-initiator");
7
+ var promptSource = require("./prompt-source");
7
8
 
8
9
  /**
9
10
  * Attach user-message handler and remaining small handlers
@@ -49,7 +50,7 @@ function truncateCodePointSafe(str, maxLen) {
49
50
  }
50
51
 
51
52
  // lr-62157d: pure helper — derives the FIRST-message provisional title
52
- // (before any turn has completed / before autoGenerateTitle can run).
53
+ // (before any turn has completed / before the CLI has written its own title).
53
54
  // Prefers real message text; falls back to the first paste when text is
54
55
  // empty (a >=500-char paste is diverted server-side into msg.pastes[] with
55
56
  // msg.text empty by the client's paste-chip handling — see input.js — so
@@ -298,7 +299,7 @@ function attachUserMessage(ctx) {
298
299
  // authenticated client's extension_result is ignored.
299
300
  if (msg.type === "extension_result") {
300
301
  if (!mayAnswerExtensionCommand(msg.requestId, ws)) return true;
301
- promptsFor(sm).respond(msg.requestId, { result: msg.result }, { kinds: ["extension"] });
302
+ promptsFor(sm).respond(msg.requestId, { result: msg.result }, { kinds: ["extension"], source: promptSource.fromWs(ws) });
302
303
  return true;
303
304
  }
304
305
 
@@ -429,9 +430,9 @@ function attachUserMessage(ctx) {
429
430
 
430
431
  if (!session.title) {
431
432
  session.title = deriveProvisionalTitle(msg);
432
- // This is only a provisional title — autoGenerateTitle (sdk-bridge.js)
433
- // is allowed to overwrite it once a real LLM-generated title is ready,
434
- // as long as the user hasn't manually renamed the session since.
433
+ // This is only a provisional title — session-ai-title.js replaces it
434
+ // once the CLI has written its own title, as long as the user hasn't
435
+ // manually renamed the session since.
435
436
  session.titleProvisional = true;
436
437
  sm.saveSessionFile(session);
437
438
  sm.broadcastSessionList();
package/lib/project.js CHANGED
@@ -442,6 +442,8 @@ function createProjectContext(opts) {
442
442
  historyInMemMax: historyInMemMax,
443
443
  getNotificationsModule: function () { return _notifications; },
444
444
  onProcessingChanged: onProcessingChanged,
445
+ getProjectName: function () { return title || project; },
446
+ getProjectSlug: function () { return slug; },
445
447
  });
446
448
  sm.availableVendors = Object.keys(adapters);
447
449
  sm.defaultVendor = defaultVendor;