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

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 (59) hide show
  1. package/lib/activity-clock.js +23 -0
  2. package/lib/build-sha.json +2 -2
  3. package/lib/build-update-offer.js +29 -0
  4. package/lib/cli-transcript-title.js +131 -0
  5. package/lib/daemon.js +5 -9
  6. package/lib/debug-log.js +17 -0
  7. package/lib/exit-flush.js +44 -0
  8. package/lib/grant-keys.js +66 -0
  9. package/lib/identity/config.js +118 -0
  10. package/lib/identity/contract.js +61 -0
  11. package/lib/identity/delivery.js +224 -0
  12. package/lib/identity/holder.js +87 -0
  13. package/lib/identity/index.js +229 -0
  14. package/lib/identity/jose.js +13 -0
  15. package/lib/identity/origin.js +28 -0
  16. package/lib/identity/owner.js +30 -0
  17. package/lib/identity/providers/gatekeeper.js +91 -0
  18. package/lib/identity/providers/jwks-self.js +85 -0
  19. package/lib/identity/providers/module.js +98 -0
  20. package/lib/identity/providers/signing-key.js +118 -0
  21. package/lib/identity/record.js +23 -0
  22. package/lib/identity/unavailable.js +29 -0
  23. package/lib/log-field.js +34 -0
  24. package/lib/project-http.js +2 -0
  25. package/lib/project-notifications.js +3 -0
  26. package/lib/project-prompt-responses.js +2 -1
  27. package/lib/project-session-grants.js +73 -0
  28. package/lib/project-sessions.js +12 -0
  29. package/lib/project-user-message.js +6 -5
  30. package/lib/project.js +2 -0
  31. package/lib/prompt-label.js +60 -0
  32. package/lib/prompt-registry.js +105 -10
  33. package/lib/prompt-source.js +65 -0
  34. package/lib/public/css/notifications-center.css +9 -0
  35. package/lib/public/css/overlays.css +18 -0
  36. package/lib/public/css/rewind.css +7 -0
  37. package/lib/public/modules/app-messages.js +3 -0
  38. package/lib/public/modules/app-notifications.js +5 -0
  39. package/lib/public/modules/build-notice-gate.js +73 -0
  40. package/lib/public/modules/diagnostics.js +43 -1
  41. package/lib/public/modules/prompt-label.js +44 -0
  42. package/lib/public/modules/prompts.js +9 -0
  43. package/lib/public/modules/session-grants.js +131 -0
  44. package/lib/public/modules/sidebar-sessions.js +11 -0
  45. package/lib/runtime-env.js +1 -1
  46. package/lib/sdk-bridge.js +135 -104
  47. package/lib/sdk-message-processor.js +14 -67
  48. package/lib/session-ai-title.js +80 -0
  49. package/lib/session-input.js +32 -2
  50. package/lib/sessions.js +21 -18
  51. package/lib/turn-initiator.js +29 -14
  52. package/lib/utils.js +5 -46
  53. package/lib/ws-schema.js +6 -3
  54. package/lib/yoke/adapters/claude-worker.js +5 -5
  55. package/lib/yoke/adapters/claude.js +5 -62
  56. package/lib/yoke/adapters/codex.js +4 -75
  57. package/lib/yoke/interface.js +3 -7
  58. package/package.json +3 -1
  59. package/scripts/vendor-identity-vectors.js +52 -0
@@ -0,0 +1,80 @@
1
+ // session-ai-title.js - gives a session the title its vendor CLI wrote for it.
2
+ //
3
+ // The console never asks a model for a title. The Claude Code CLI titles each
4
+ // session itself and records it in the session's transcript
5
+ // (cli-transcript-title.js); this module copies the latest such title onto the
6
+ // console session, which is the one place every surface (the picker, prompt
7
+ // cards, banners and push, the restart interrupt list, CLI listings) reads a
8
+ // title from.
9
+ //
10
+ // Precedence: a title the operator set by rename always wins; otherwise the
11
+ // CLI's title replaces whatever the first-line fallback put there; a session
12
+ // whose transcript holds no title keeps the first-line title.
13
+
14
+ var path = require("path");
15
+ var transcriptTitle = require("./cli-transcript-title");
16
+ var runtimeEnv = require("./runtime-env");
17
+
18
+ // Vendors whose sessions have a Claude Code transcript. Another vendor's
19
+ // thread id names no transcript here, so it is never looked up.
20
+ function hasCliTranscript(session) {
21
+ return !session.vendor || session.vendor === "claude";
22
+ }
23
+
24
+ // deps: {
25
+ // sm session manager (saveSessionFile, broadcastSessionList)
26
+ // cwd the project directory
27
+ // resolveHome(session) the session owner's home, or null for the daemon's own
28
+ // daemonHome the daemon user's home
29
+ // getRuntimeEnvOverlay?(session) the Settings variables the session's Claude
30
+ // process was started with, or null
31
+ // claudeDir? overrides the transcript root (tests)
32
+ // }
33
+ // Returns refresh(session): Promise<boolean>, true when the title changed.
34
+ function createAiTitleRefresher(deps) {
35
+ var sm = deps.sm;
36
+
37
+ // The CLAUDE_CONFIG_DIR the session's process was given by Settings. Read
38
+ // through composeRuntimeEnv so a name the runtime drops is dropped here too.
39
+ function overlayConfigDir(session) {
40
+ var overlay = deps.getRuntimeEnvOverlay ? deps.getRuntimeEnvOverlay(session) : null;
41
+ if (!overlay) return null;
42
+ var dir = runtimeEnv.composeRuntimeEnv({}, overlay).CLAUDE_CONFIG_DIR;
43
+ return dir || null;
44
+ }
45
+
46
+ // Same order the session's process resolves its config: Settings overlay,
47
+ // then the owner's home, then the daemon's own variable and home.
48
+ function claudeDirFor(session) {
49
+ if (deps.claudeDir) return deps.claudeDir;
50
+ var overlayDir = overlayConfigDir(session);
51
+ if (overlayDir) return overlayDir;
52
+ var ownerHome = deps.resolveHome ? deps.resolveHome(session) : null;
53
+ if (ownerHome) return path.join(ownerHome, ".claude");
54
+ return process.env.CLAUDE_CONFIG_DIR || path.join(deps.daemonHome, ".claude");
55
+ }
56
+
57
+ return function refresh(session) {
58
+ if (!session || !session.cliSessionId || session.titleManuallySet) return Promise.resolve(false);
59
+ if (!hasCliTranscript(session)) return Promise.resolve(false);
60
+ var sessionId = session.cliSessionId;
61
+ return transcriptTitle.findTranscript(claudeDirFor(session), [session.cwd, deps.cwd], sessionId)
62
+ .then(function (file) { return file ? transcriptTitle.readLatestAiTitle(file, sessionId) : null; })
63
+ .then(function (title) {
64
+ // Re-checked after the read: a rename can land while the file is read.
65
+ if (!title || session.titleManuallySet || session.title === title) return false;
66
+ session.title = title;
67
+ session.titleAutoGenerated = true;
68
+ session.titleProvisional = false;
69
+ sm.saveSessionFile(session);
70
+ sm.broadcastSessionList();
71
+ return true;
72
+ })
73
+ .catch(function (e) {
74
+ console.error("[ai-title] could not read the session title:", e && e.message ? e.message : e);
75
+ return false;
76
+ });
77
+ };
78
+ }
79
+
80
+ module.exports = { createAiTitleRefresher: createAiTitleRefresher };
@@ -17,6 +17,7 @@ var { isKnownVendor } = require("./yoke");
17
17
  var { getNewWorkRefusal } = require("./new-work-gate");
18
18
  var agentsModule = require("./agents");
19
19
  var sessionResume = require("./session-resume");
20
+ var { logField, logText } = require("./log-field");
20
21
 
21
22
  // The result vocabulary reported to the caller. "error" is not a verdict on
22
23
  // the request: delivery was attempted and failed, so a caller may retry.
@@ -128,6 +129,33 @@ function neverThrows(fn) {
128
129
  };
129
130
  }
130
131
 
132
+ // One line per request, whichever caller made it (IPC verb or file drop): the
133
+ // project, the console session and the result, with the reason when the
134
+ // request was refused or failed. The prompt, the context note and the request
135
+ // body are never part of it; a reason only quotes a bounded identifier.
136
+ function logResult(verb, req, out) {
137
+ req = req || {};
138
+ out = out || {};
139
+ var line = "[session-input] " + verb + ": project=" + logField(req.projectSlug)
140
+ + " session=" + logField(out.consoleSessionId || req.sessionId)
141
+ + " result=" + logField(out.result);
142
+ if (out.retryable === true) line += " retryable=true";
143
+ // Last, because it is free text.
144
+ if (out.reason) line += " reason=" + logText(out.reason);
145
+ console.log(line);
146
+ }
147
+
148
+ function logged(verb, fn) {
149
+ return function (req) {
150
+ var out = fn(req);
151
+ if (out && typeof out.then === "function") {
152
+ return out.then(function (result) { logResult(verb, req, result); return result; });
153
+ }
154
+ logResult(verb, req, out);
155
+ return out;
156
+ };
157
+ }
158
+
131
159
  // deps:
132
160
  // getProject(slug) -> project context | null
133
161
  // agentCatalog(project) -> [{ name }] named agents on offer (default: the picker's catalog)
@@ -354,12 +382,14 @@ function createSessionInput(deps) {
354
382
  // Recorded once, only now that the query has started: a rejected start
355
383
  // leaves no history entry for a prompt that never ran.
356
384
  recordInjected(project, sess, req, init.initiator);
357
- console.log("[session-input] session opened: project=" + req.projectSlug + " session=" + sess.localId);
358
385
  return opened();
359
386
  }, openStartFailure);
360
387
  }
361
388
 
362
- return { openSession: neverThrows(openSession), sendInput: neverThrows(sendInput) };
389
+ return {
390
+ openSession: logged("open_session", neverThrows(openSession)),
391
+ sendInput: logged("send_session_input", neverThrows(sendInput)),
392
+ };
363
393
  }
364
394
 
365
395
  // sendInput and openSession answer synchronously when nothing has to wait and
package/lib/sessions.js CHANGED
@@ -7,6 +7,7 @@ var users = require("./users");
7
7
  var { CODEX_DEFAULTS } = require("./codex-defaults");
8
8
  var { isVisibleHistoryEvent } = require("./history-visibility");
9
9
  var { createPromptRegistry } = require("./prompt-registry");
10
+ var { registerExitFlush } = require("./exit-flush");
10
11
  var sessionReclaim = require("./session-reclaim");
11
12
 
12
13
  // lr-2ea2a7: hard cap on how many history entries a session may hold in the
@@ -110,6 +111,8 @@ function createSessionManager(opts) {
110
111
  saveSessionFile: function (session) { return saveSessionFile(session); },
111
112
  getNotificationsModule: opts.getNotificationsModule,
112
113
  onProcessingChanged: opts.onProcessingChanged,
114
+ getProjectName: opts.getProjectName,
115
+ getProjectSlug: opts.getProjectSlug,
113
116
  });
114
117
  var capabilitiesByVendor = null; // set by sdk-bridge after adapter init
115
118
  var defaultVendor = null; // set by sdk-bridge
@@ -170,22 +173,18 @@ function createSessionManager(opts) {
170
173
  var resumeAgents = sessionReclaim.sanitizeAgentLabels(session.pendingAutoResumeAgents);
171
174
  if (resumeAgents) metaObj.pendingAutoResumeAgents = resumeAgents;
172
175
  }
173
- // lr-62157d: durable auto-title state. Without this, titleAutoGenerated
174
- // and titleManuallySet lived in memory only — every daemon restart reset
175
- // both to false, so the "already auto-titled" / "user renamed it" guards
176
- // at sdk-message-processor.js and sdk-bridge.js were guarding against
177
- // state that could never actually be true after a restart. turnCount is
178
- // persisted alongside them because the turn-threshold gate (see the
179
- // '>=' fix at sdk-message-processor.js) depends on it surviving too —
180
- // a restarted session that lost its turn count would silently miss the
181
- // auto-title window forever instead of catching up on a later turn.
176
+ // Durable title state: titleManuallySet (the operator renamed the session,
177
+ // which always wins) and titleAutoGenerated (the title is the CLI's own,
178
+ // see session-ai-title.js) must survive a daemon restart.
182
179
  // titleProvisional marks a title set from the raw first-message
183
- // truncation (project-user-message.js) so autoGenerateTitle knows it is
184
- // safe to overwrite even though the flags above look "not yet set".
180
+ // truncation (project-user-message.js).
185
181
  if (session.titleAutoGenerated) metaObj.titleAutoGenerated = true;
186
182
  if (session.titleManuallySet) metaObj.titleManuallySet = true;
187
183
  if (session.titleProvisional) metaObj.titleProvisional = true;
188
184
  if (typeof session.turnCount === "number" && session.turnCount > 0) metaObj.turnCount = session.turnCount;
185
+ // Which identity provider vouched for the session and at what grade. Only
186
+ // present when a provider is configured: a plain session has no such field.
187
+ if (session.identity) metaObj.identity = session.identity;
189
188
  return JSON.stringify(metaObj);
190
189
  }
191
190
 
@@ -788,6 +787,10 @@ function createSessionManager(opts) {
788
787
  session.titleManuallySet = !!m.titleManuallySet;
789
788
  session.titleProvisional = !!m.titleProvisional;
790
789
  session.turnCount = typeof m.turnCount === "number" ? m.turnCount : 0;
790
+ if (m.identity) {
791
+ var identityRecord = require("./identity/record").sanitizeRecord(m.identity);
792
+ if (identityRecord) session.identity = identityRecord;
793
+ }
791
794
  sessions.set(localId, session);
792
795
  }
793
796
  }
@@ -797,14 +800,15 @@ function createSessionManager(opts) {
797
800
 
798
801
  // Drain all write buffers synchronously on process exit to prevent trailing
799
802
  // event loss when the daemon shuts down cleanly.
800
- // Named so it can be deregistered via sm.destroy() when the project is torn
801
- // down — avoids accumulating one listener per project open (lr-daca).
803
+ // Registered with the shared exit flusher, not as a listener of its own:
804
+ // one process listener per project tripped the MaxListeners warning at
805
+ // startup. sm.destroy() unregisters it when the project is torn down.
802
806
  function _onProcessExit() {
803
807
  sessions.forEach(function(session) {
804
808
  flushSessionBuffer(session);
805
809
  });
806
810
  }
807
- process.on("exit", _onProcessExit);
811
+ var unregisterExitFlush = registerExitFlush(_onProcessExit);
808
812
 
809
813
  function getActiveSession() {
810
814
  return sessions.get(activeSessionId) || null;
@@ -1834,13 +1838,12 @@ function createSessionManager(opts) {
1834
1838
  effectiveSessionModel: function (session) { return effectiveSessionModel(session, _instance); },
1835
1839
  // Called when the project owning this session manager is torn down. No
1836
1840
  // prompt resolver outlives it, so every pending prompt ends here and its
1837
- // outcome is flushed to disk; then the process-level exit listener
1838
- // registered above is removed so listeners do not accumulate across
1839
- // project open/close cycles.
1841
+ // outcome is flushed to disk; then the exit flusher registered above is
1842
+ // unregistered so nothing accumulates across project open/close cycles.
1840
1843
  destroy: function() {
1841
1844
  prompts.shutdown();
1842
1845
  _onProcessExit();
1843
- process.removeListener("exit", _onProcessExit);
1846
+ unregisterExitFlush();
1844
1847
  },
1845
1848
  };
1846
1849
  _instance.prompts = prompts;
@@ -14,6 +14,8 @@
14
14
 
15
15
  var pkg = require("../package.json");
16
16
  var runtimeEnv = require("./runtime-env");
17
+ // Required for its constant only: nothing of the identity surface runs from here.
18
+ var IDENTITY_DIR_ENV = require("./identity/contract").IDENTITY_DIR_ENV;
17
19
 
18
20
  var INITIATORS = Object.freeze({
19
21
  // Text a person typed into the console.
@@ -60,14 +62,6 @@ function isClientComposed(initiator) {
60
62
  return isInitiator(initiator) && initiator !== INITIATORS.HUMAN;
61
63
  }
62
64
 
63
- // The CLI keeps a host-declared origin only when it is human, or the
64
- // scheduled-trigger kind in a process started with this variable. Every
65
- // automated turn uses the latter, so a process whose first turn is anything but
66
- // a typed one gets it.
67
- function isScheduledInitiator(initiator) {
68
- return isClientComposed(initiator);
69
- }
70
-
71
65
  // Identifies this product to the Claude Agent SDK ("<app>/<version>").
72
66
  function clientAppId() {
73
67
  return "clagentic-console/" + pkg.version;
@@ -75,17 +69,38 @@ function clientAppId() {
75
69
 
76
70
  // The environment additions the console always makes for a Claude process.
77
71
  // Laid over the process's own environment by the caller, never in place of it.
78
- function claudeHostEnv(initiator) {
79
- var env = { CLAUDE_AGENT_SDK_CLIENT_APP: clientAppId() };
80
- if (isScheduledInitiator(initiator)) env.CLAUDE_CODE_HOST_SCHEDULED_RUN = "1";
81
- return env;
72
+ //
73
+ // CLAUDE_CODE_HOST_SCHEDULED_RUN is declared on every process, whatever turn
74
+ // starts it. The CLI keeps a host-declared scheduled-trigger origin only in a
75
+ // process started with it, and the environment cannot change once the process
76
+ // runs, while turns of any initiator reach a live process (a typed turn starts
77
+ // it, a trigger or scheduled turn is pushed in later; messages buffered between
78
+ // turns are replayed into whichever process starts next). A typed turn's human
79
+ // origin is kept regardless of the variable. The variable's only other effect
80
+ // in the CLI is to switch off an oversized-attachment diagnostic event.
81
+ function claudeHostEnv() {
82
+ return {
83
+ CLAUDE_AGENT_SDK_CLIENT_APP: clientAppId(),
84
+ CLAUDE_CODE_HOST_SCHEDULED_RUN: "1",
85
+ };
82
86
  }
83
87
 
84
88
  // The complete environment for a Claude process: the process's own, then the
85
89
  // Settings overlay, then the console's additions. The SDK replaces the CLI's
86
90
  // environment with options.env, so this is always the whole environment.
87
- function claudeProcessEnv(base, overlay, initiator) {
88
- return Object.assign(runtimeEnv.composeRuntimeEnv(base, overlay), claudeHostEnv(initiator));
91
+ //
92
+ // CLAGENTIC_IDENTITY_DIR is the console's alone to set: an inherited value (from
93
+ // the daemon's own environment or from Settings) would name a directory the
94
+ // console never issued for this process, and a consumer would trust it. It is
95
+ // removed always; `identity` ({ dir: <delivery directory> | null }, present only
96
+ // when an identity provider is configured) is the only way it comes back.
97
+ function claudeProcessEnv(base, overlay, identity) {
98
+ var env = Object.assign(runtimeEnv.composeRuntimeEnv(base, overlay), claudeHostEnv());
99
+ delete env[IDENTITY_DIR_ENV];
100
+ if (identity && typeof identity === "object" && typeof identity.dir === "string" && identity.dir) {
101
+ env[IDENTITY_DIR_ENV] = identity.dir;
102
+ }
103
+ return env;
89
104
  }
90
105
 
91
106
  // A streamed Claude user message for a turn, with its provenance stamped.
package/lib/utils.js CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  var fs = require("fs");
6
+ var grantKeys = require("./grant-keys");
6
7
 
7
8
  /**
8
9
  * Encode a cwd path into a filesystem-safe directory/file name.
@@ -66,7 +67,8 @@ function resolveEncodedFile(baseDir, cwd, ext) {
66
67
  * handleCanUseTool check (lib/sdk-bridge.js:691).
67
68
  *
68
69
  * Keeps only entries whose key is a string and whose value is strictly
69
- * boolean `true`; drops everything else. A non-object input (including
70
+ * boolean `true` (see grantKeys.isGrantValue for the one retired key shape
71
+ * that is also dropped); drops everything else. A non-object input (including
70
72
  * null/undefined/arrays) yields an empty map rather than throwing. The map
71
73
  * has no prototype: its keys are tool names, and a name like "constructor"
72
74
  * must not be found as an inherited entry.
@@ -76,54 +78,11 @@ function sanitizeAllowedTools(value) {
76
78
  if (!value || typeof value !== "object" || Array.isArray(value)) return out;
77
79
  for (var key in value) {
78
80
  if (!Object.prototype.hasOwnProperty.call(value, key)) continue;
79
- if (typeof key === "string" && value[key] === true) out[key] = true;
81
+ if (typeof key === "string" && grantKeys.isGrantValue(key, value[key])) out[key] = true;
80
82
  }
81
83
  return out;
82
84
  }
83
85
 
84
- /**
85
- * Compute the key used to index a session's "allow for session" grant map
86
- * (session.allowedTools) for a given tool call (lr-f969dc).
87
- *
88
- * Most tools are correctly discriminated by bare tool name alone — MCP tools
89
- * already fold server + tool identity into the name itself (e.g.
90
- * "mcp__browser__navigate" vs "mcp__browser__screenshot" are already
91
- * distinct keys), so approving one MCP tool must not silently approve a
92
- * different one, and bare-name keying already gives that.
93
- *
94
- * The Claude `Skill` tool is the one exception found so far: every distinct
95
- * skill invocation arrives as the SAME toolName "Skill" with a different
96
- * `input.skill` discriminator. Keying on bare "Skill" means granting one
97
- * skill silently authorizes every other skill for the rest of the session —
98
- * a security regression, not the "doesn't stick" fix the grant was meant to
99
- * provide. Fold the discriminator into the key so a grant is scoped to the
100
- * specific skill that was actually approved.
101
- *
102
- * This repo is vendor-agnostic via the YOKE adapter layer (lib/yoke/), so a
103
- * bare "Skill" literal here is a deliberate, checked exception, not a
104
- * default pattern for future tools. Verified (lr-f969dc): Codex's approval
105
- * RPCs (exec/file/MCP, lib/yoke/adapters/codex.js) route through this same
106
- * function via the identical vendor-neutral canUseTool wiring, and all of
107
- * them already send correctly-flat tool names — Codex has no tool today
108
- * whose identity fans out under one shared name the way Skill does, so no
109
- * generalization is needed for vendor parity right now. If a second vendor
110
- * or a renamed/restructured tool introduces another input-discriminated
111
- * tool, extend this with another explicit branch (or a small declarative
112
- * toolName -> discriminator-field table if a third case appears) rather
113
- * than reaching for a config knob nobody would otherwise set.
114
- *
115
- * Falls back to the bare tool name when the expected discriminator is
116
- * missing or not a string (fails closed to the pre-existing per-tool grant
117
- * rather than throwing or producing an unstable key). Never hardcodes an
118
- * individual skill name — only the shared "Skill" tool identifier.
119
- */
120
- function permissionGrantKey(toolName, input) {
121
- if (toolName === "Skill" && input && typeof input.skill === "string" && input.skill) {
122
- return "Skill:" + input.skill;
123
- }
124
- return toolName;
125
- }
126
-
127
86
  /**
128
87
  * Default hard cap for readCappedBody() call sites that don't pass their own
129
88
  * maxBytes: these are small JSON-only pre-auth endpoints (login, PIN
@@ -183,7 +142,7 @@ module.exports = {
183
142
  resolveEncodedDir: resolveEncodedDir,
184
143
  resolveEncodedFile: resolveEncodedFile,
185
144
  sanitizeAllowedTools: sanitizeAllowedTools,
186
- permissionGrantKey: permissionGrantKey,
145
+ permissionGrantKey: grantKeys.permissionGrantKey,
187
146
  readCappedBody: readCappedBody,
188
147
  DEFAULT_BODY_CAP_BYTES: DEFAULT_BODY_CAP_BYTES,
189
148
  };
package/lib/ws-schema.js CHANGED
@@ -122,10 +122,10 @@ var schema = {
122
122
  // suppressAlwaysAllowRule, defaultToNo, matchedAskRule; ask_user: input; elicitation: serverName,
123
123
  // message, mode, url, elicitationId, requestedSchema).
124
124
  // -----------------------------------------------------------------------
125
- "prompt_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt awaits the operator: {requestId, kind, toolUseId, ...kind fields}. On history replay it carries promptState {state: pending|resolved|cancelled, decision|answers|skipped|action, reason}, the server's authoritative state for the prompt at replay time" },
125
+ "prompt_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt awaits the operator: {requestId, kind, toolUseId, label: {project, session, agent}, ...kind fields} (label names whose prompt it is; agent is empty unless a background agent raised it). On history replay it carries promptState {state: pending|resolved|cancelled, decision|answers|skipped|action, reason}, the server's authoritative state for the prompt at replay time" },
126
126
  "prompt_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt still awaiting the operator, re-presented on connect and session switch; same fields as prompt_request" },
127
- "prompt_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "The operator's answer: {requestId, kind, ...} with decision (+ feedback, planContent) for permission/plan, answers or decision:\"skip\" for ask_user (answers keyed by question index; each a label or text, or for a multi-select question the list of chosen labels), action (+ content, held to the requested schema) for elicitation. The kind is required and must match the prompt's. Decision allow_always to a permission prompt that carries suppressAlwaysAllowRule settles nothing: the prompt is sent again as prompt_pending. A prompt of the extension kind is never answered this way" },
128
- "prompt_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt was answered: {requestId, kind, decision|answers|skipped|action}; a permission prompt forced by a user ask rule also carries matchedAskRule" },
127
+ "prompt_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "The operator's answer: {requestId, kind, ...} with decision (+ feedback, planContent) for permission/plan, answers or decision:\"skip\" for ask_user (answers keyed by question index; each a label or text, or for a multi-select question the list of chosen labels), action (+ content, held to the requested schema) for elicitation. The kind is required and must match the prompt's. Decision allow_always grants the whole tool (Skill: the one skill) for the rest of the session, and to a permission prompt that carries suppressAlwaysAllowRule settles nothing: the prompt is sent again as prompt_pending. A prompt of the extension kind is never answered this way" },
128
+ "prompt_resolved": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt was answered: {requestId, kind, decision|answers|skipped|action, source?}; a permission prompt forced by a user ask rule also carries matchedAskRule. source says who answered, as {kind:\"ws\", clientId, user} for a browser connection (clientId is a per-connection label, user the user id or null) or {kind:\"push\", action, user} for a push notification answer; it is absent when the answering path named none. The same source is written to the journal line the settle logs. Prompt content is never part of a source" },
129
129
  "prompt_cancel": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A prompt ended without an answer: {requestId, kind, reason}; reason is aborted, expired, turn_ended, query_ended, rewind, cleared or shutdown. Reason \"stale\" is sent only to a client whose prompt_response named a prompt the server no longer holds, and is not recorded in history" },
130
130
 
131
131
  // Aliases kept for compatibility: the s2c types appear in history recorded
@@ -134,6 +134,9 @@ var schema = {
134
134
  // before an upgrade. Nothing records or sends the s2c aliases any more,
135
135
  // except permission_cancel {reason: "stale"} in reply to a
136
136
  // permission_response.
137
+ "list_session_grants": { direction: "c2s", handler: "lib/project-session-grants.js", description: "Ask for a session's Allow for Session grants: {sessionId?} (the connection's own session when absent). Answered with session_grants to the asker; refused silently for a session the user may not see" },
138
+ "revoke_session_grant": { direction: "c2s", handler: "lib/project-session-grants.js", description: "Revoke one Allow for Session grant: {sessionId?, key}. Persisted at once and in force on the session's next tool call; every client viewing the session gets the resulting session_grants. Authorized by mayAnswerPrompt (lib/prompt-access.js), the rule that lets a user answer the session's prompts. For a session that rule refuses, the asker alone gets session_grants with an error string and no grants" },
139
+ "session_grants": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A session's grants as {sessionId, grants: [{key, tool, wholeTool, text}]}; wholeTool marks a grant that covers every call of the tool (every grant except a Skill one). A refused revoke is {sessionId, error} with no grants" },
137
140
  "permission_request": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_request (kind permission or plan); history carries permissionState or promptState" },
138
141
  "permission_request_pending": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Alias of prompt_pending (kind permission or plan)" },
139
142
  "permission_response": { direction: "c2s", handler: "lib/project-prompt-responses.js", description: "Alias of prompt_response for kinds permission and plan: {requestId, decision, feedback, planContent}" },
@@ -105,12 +105,12 @@ function applyWorkerClaudeBinary(options) {
105
105
  function applyRuntimeEnv(options) {
106
106
  if (!options) return options;
107
107
  var overlay = options.runtimeEnv;
108
- var initiator = options.initiator;
109
108
  delete options.runtimeEnv;
110
- delete options.initiator;
111
- // Always built: the product identity is part of every Claude process's
112
- // environment, with the initiator of the turn that starts the query.
113
- options.env = turnInitiator.claudeProcessEnv(process.env, overlay, initiator);
109
+ var identity = options.identity;
110
+ delete options.identity;
111
+ // Always built: the product identity and host declaration are part of every
112
+ // Claude process's environment.
113
+ options.env = turnInitiator.claudeProcessEnv(process.env, overlay, identity);
114
114
  return options;
115
115
  }
116
116
 
@@ -1649,71 +1649,13 @@ function createClaudeAdapter(opts) {
1649
1649
 
1650
1650
  // options.env REPLACES the subprocess environment, so the query is handed
1651
1651
  // the whole environment (the process's own, the Settings variables, and
1652
- // the product identity), not the additions. queryOpts.initiator is the
1653
- // initiator of the turn that starts this process.
1654
- sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.initiator);
1652
+ // the product identity and host declaration), not the additions.
1653
+ sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.identity);
1655
1654
 
1656
1655
  var rawQuery = sdk.query({ prompt: mq, options: sdkOptions });
1657
1656
  return createQueryHandle(rawQuery, mq, ac);
1658
1657
  },
1659
1658
 
1660
- // --- Title generation ---
1661
- generateTitle: async function(messages, opts) {
1662
- console.log("[auto-title/claude] generateTitle called with " + messages.length + " messages");
1663
- var systemPrompt = "You are a title generator. Output only a short title (3-8 words). No quotes, no punctuation at the end, no explanation.";
1664
- var prompt = "Below is a conversation between a user and an AI assistant. Generate a short, descriptive title (3-8 words) that captures the main topic. Reply with ONLY the title, nothing else.\n\n";
1665
- for (var i = 0; i < messages.length; i++) {
1666
- prompt += "User message " + (i + 1) + ": " + messages[i] + "\n";
1667
- }
1668
- var ac = new AbortController();
1669
- console.log("[auto-title/claude] Creating query with model=haiku...");
1670
- var handle = await adapter.createQuery({
1671
- cwd: (opts && opts.cwd) || _cwd,
1672
- systemPrompt: systemPrompt,
1673
- model: "haiku",
1674
- adapterOptions: {
1675
- CLAUDE: {
1676
- settingSources: ["user"],
1677
- // A title needs no tool. bypassPermissions makes the SDK pass
1678
- // --dangerously-skip-permissions, which the CLI refuses under
1679
- // root, so every title failed there; dontAsk denies anything
1680
- // not pre-approved and starts the same under any uid.
1681
- permissionMode: "dontAsk",
1682
- }
1683
- },
1684
- abortController: ac,
1685
- runtimeEnv: opts && opts.runtimeEnv,
1686
- });
1687
- console.log("[auto-title/claude] Query created, pushing message...");
1688
- handle.pushMessage(prompt);
1689
- var title = "";
1690
- var streamed = false;
1691
- try {
1692
- for await (var msg of handle) {
1693
- if (msg.yokeType === "text_delta" && msg.text) {
1694
- streamed = true;
1695
- title += msg.text;
1696
- } else if (msg.yokeType === "message" && msg.messageRole === "assistant" && !streamed && msg.content) {
1697
- // Fallback: extract text from non-streamed message content
1698
- var content = msg.content;
1699
- if (Array.isArray(content)) {
1700
- for (var ci = 0; ci < content.length; ci++) {
1701
- if (content[ci].type === "text" && content[ci].text) {
1702
- title += content[ci].text;
1703
- }
1704
- }
1705
- }
1706
- } else if (msg.yokeType === "result") {
1707
- break;
1708
- }
1709
- }
1710
- } finally {
1711
- handle.close();
1712
- }
1713
- console.log("[auto-title/claude] Generated: " + title.substring(0, 80));
1714
- return title.replace(/[\r\n]+/g, " ").replace(/^["'\s]+|["'\s.]+$/g, "").trim();
1715
- },
1716
-
1717
1659
  // --- Session management ---
1718
1660
  // These delegate to SDK module-level functions.
1719
1661
 
@@ -1825,8 +1767,9 @@ function createClaudeAdapter(opts) {
1825
1767
  // The worker lays these over its own environment (the OS user's), then
1826
1768
  // hands the SDK the complete result.
1827
1769
  if (runtimeEnv.hasOverlay(queryOpts.runtimeEnv)) queryOptions.runtimeEnv = queryOpts.runtimeEnv;
1828
- // The worker builds the environment (see applyRuntimeEnv in claude-worker.js).
1829
- if (queryOpts.initiator) queryOptions.initiator = queryOpts.initiator;
1770
+ // Present only when an identity provider is configured; the worker adds the
1771
+ // delivery directory to the Claude process's environment.
1772
+ if (queryOpts.identity) queryOptions.identity = queryOpts.identity;
1830
1773
 
1831
1774
  if (queryOpts.toolServerDescriptors) queryOptions.mcpServerDescriptors = queryOpts.toolServerDescriptors;
1832
1775
  if (queryOpts.model) queryOptions.model = queryOpts.model;
@@ -633,27 +633,6 @@ function _test_resolveModel(queryOpts) {
633
633
  return queryOpts.model || queryOpts.defaultModel || "gpt-5.5";
634
634
  }
635
635
 
636
- // Selects the model used for background title generation.
637
- //
638
- // The live "model/list" RPC's Model objects (see the model/list handler
639
- // below, and the shape of an instance's models) carry no cost-tier field — only
640
- // value/displayName/supportedEffortLevels/isLatest ("isLatest" means "not
641
- // superseded by an upgrade", not "cheap"). There is no robust signal in the
642
- // live catalog to identify a mini/small-tier model, and this codebase does
643
- // not substring-match displayName/value for a tier (that class of fragile
644
- // string matching was deliberately removed elsewhere — see the Context
645
- // meter section of docs/guides/architecture.md).
646
- //
647
- // So titling — a trivial 3-8 word job — falls back to the server's default
648
- // model, the adapter's only non-staling model identifier (refreshed from the live
649
- // model/list response). This is a deliberate cost/staleness tradeoff: every
650
- // auto-title now runs on the user's main model instead of a cheaper
651
- // mini-tier one, in exchange for auto-titling never breaking silently when
652
- // OpenAI retires a pinned mini snapshot. See PR body for the reasoning.
653
- function resolveTitleModel(defaultModel) {
654
- return defaultModel || "gpt-5.5";
655
- }
656
-
657
636
  function createCodexQueryHandle(appServer, queryOpts) {
658
637
  var abortController = queryOpts.abortController;
659
638
  var systemPrompt = queryOpts.systemPrompt || "";
@@ -886,9 +865,10 @@ function createCodexQueryHandle(appServer, queryOpts) {
886
865
  if (isAllowAll()) {
887
866
  appServer.respond(msg.id, { decision: "accept" });
888
867
  } else if (canUseTool) {
889
- var changeInfo = (fcParams.changes || []).map(function(c) { return c.kind + " " + c.path; }).join(", ");
868
+ var fcChanges = Array.isArray(fcParams.changes) ? fcParams.changes : [];
869
+ var changeInfo = fcChanges.map(function(c) { return c.kind + " " + c.path; }).join(", ");
890
870
  awaitApproval(msg.id, function (signal) {
891
- return canUseTool("Edit", { changes: changeInfo, path: fcParams.path }, { signal: signal });
871
+ return canUseTool("Edit", { changes: changeInfo }, { signal: signal });
892
872
  }, function (decision) {
893
873
  appServer.respond(msg.id, { decision: isApproved(decision) ? "accept" : "decline" });
894
874
  }, function (err) {
@@ -1056,7 +1036,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
1056
1036
  if (threadResult && threadResult.thread) {
1057
1037
  state.threadId = threadResult.thread.id;
1058
1038
  // Narrow the handler to only receive events for this thread so other
1059
- // concurrent queries (e.g. auto-title) are not routed to us.
1039
+ // concurrent queries are not routed to us.
1060
1040
  appServer.updateHandlerThreadId(_handlerEntry, state.threadId);
1061
1041
  }
1062
1042
 
@@ -2138,53 +2118,6 @@ function createCodexAdapter(opts) {
2138
2118
  return handle;
2139
2119
  },
2140
2120
 
2141
- // --- Title generation ---
2142
- generateTitle: async function(messages, opts) {
2143
- var systemPrompt = "You are a title generator. Output only a short title (3-8 words). No quotes, no punctuation at the end, no explanation.";
2144
- var prompt = "Below is a conversation between a user and an AI assistant. Generate a short, descriptive title (3-8 words) that captures the main topic. Reply with ONLY the title, nothing else.\n\n";
2145
- for (var i = 0; i < messages.length; i++) {
2146
- prompt += "User message " + (i + 1) + ": " + messages[i] + "\n";
2147
- }
2148
- var ac = new AbortController();
2149
- // The title is generated on the server of the caller's environment, and
2150
- // with that server's own default model.
2151
- var envOpts = { runtimeEnv: opts && opts.runtimeEnv };
2152
- var titleInst = await acquireInstance(envOpts, fingerprintFor(envOpts, "generateTitle"));
2153
- var handle = await adapter.createQuery({
2154
- cwd: (opts && opts.cwd) || _cwd,
2155
- systemPrompt: systemPrompt,
2156
- model: resolveTitleModel(titleInst.defaultModel),
2157
- abortController: ac,
2158
- canUseTool: function() { return Promise.resolve({ behavior: "deny", message: "No tools." }); },
2159
- runtimeEnv: envOpts.runtimeEnv,
2160
- });
2161
- handle.pushMessage(prompt);
2162
- var title = "";
2163
- var streamed = false;
2164
- try {
2165
- for await (var msg of handle) {
2166
- if (msg.yokeType === "text_delta" && msg.text) {
2167
- streamed = true;
2168
- title += msg.text;
2169
- } else if (msg.yokeType === "message" && msg.messageRole === "assistant" && !streamed && msg.content) {
2170
- var content = msg.content;
2171
- if (Array.isArray(content)) {
2172
- for (var ci = 0; ci < content.length; ci++) {
2173
- if (content[ci].type === "text" && content[ci].text) {
2174
- title += content[ci].text;
2175
- }
2176
- }
2177
- }
2178
- } else if (msg.yokeType === "result") {
2179
- break;
2180
- }
2181
- }
2182
- } finally {
2183
- handle.close();
2184
- }
2185
- return title.replace(/[\r\n]+/g, " ").replace(/^["'\s]+|["'\s.]+$/g, "").trim();
2186
- },
2187
-
2188
2121
  // Codex has session persistence via thread IDs
2189
2122
  getSessionInfo: function(sessionId) {
2190
2123
  return Promise.resolve(null);
@@ -2240,10 +2173,6 @@ function createCodexAdapter(opts) {
2240
2173
  module.exports = {
2241
2174
  createCodexAdapter: createCodexAdapter,
2242
2175
  _test_resolveModel: _test_resolveModel,
2243
- // Exported so tests exercise the real title-generation model selection
2244
- // (including the catalog-unavailable fallback) rather than reimplementing
2245
- // a copy of it.
2246
- _test_resolveTitleModel: resolveTitleModel,
2247
2176
  // lr-f7a4 — exported so tests can drive the real approval-routing and
2248
2177
  // setToolPolicy logic against a fake appServer, rather than reimplementing
2249
2178
  // a copy of handleServerEvent's approval branches inline.