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

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 (68) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +10 -0
  3. package/lib/agent-dispatch-tool.js +20 -0
  4. package/lib/build-changes.js +79 -0
  5. package/lib/build-identity.js +192 -0
  6. package/lib/build-monitor.js +125 -0
  7. package/lib/build-sha.json +2 -2
  8. package/lib/build-update-offer.js +141 -0
  9. package/lib/build-update-restart.js +142 -0
  10. package/lib/build-update-standing.js +184 -0
  11. package/lib/cli/daemon-launch.js +8 -5
  12. package/lib/cli/ipc-subcommands.js +6 -0
  13. package/lib/cli/session-subcommands.js +122 -0
  14. package/lib/cli-sessions.js +8 -1
  15. package/lib/codex-defaults.js +8 -2
  16. package/lib/daemon-projects.js +19 -0
  17. package/lib/daemon.js +166 -127
  18. package/lib/memory-shed.js +13 -32
  19. package/lib/project-connection.js +14 -0
  20. package/lib/project-external-trigger.js +91 -123
  21. package/lib/project-loop.js +5 -4
  22. package/lib/project-prompt-responses.js +5 -4
  23. package/lib/project-sessions.js +43 -68
  24. package/lib/project-user-message.js +7 -20
  25. package/lib/project.js +23 -5
  26. package/lib/prompt-registry.js +7 -0
  27. package/lib/public/css/diagnostics.css +30 -0
  28. package/lib/public/modules/agent-dispatch-tool.js +9 -0
  29. package/lib/public/modules/app-messages.js +7 -2
  30. package/lib/public/modules/app-panels.js +0 -1
  31. package/lib/public/modules/build-update-detail.js +54 -0
  32. package/lib/public/modules/diagnostics.js +126 -20
  33. package/lib/public/modules/tools.js +14 -2
  34. package/lib/public/modules/vendor-picker.js +2 -2
  35. package/lib/public/modules/vendor-registry.js +11 -2
  36. package/lib/sdk-bridge.js +62 -15
  37. package/lib/sdk-message-processor.js +11 -20
  38. package/lib/sdk-skill-discovery.js +65 -60
  39. package/lib/server.js +15 -2
  40. package/lib/session-id.js +33 -0
  41. package/lib/session-input-ipc.js +32 -0
  42. package/lib/session-input.js +379 -0
  43. package/lib/session-reclaim.js +284 -0
  44. package/lib/session-resume.js +172 -0
  45. package/lib/sessions.js +16 -2
  46. package/lib/supervisor.js +39 -0
  47. package/lib/turn-initiator.js +108 -0
  48. package/lib/vendor-registry-message.js +1 -0
  49. package/lib/ws-schema.js +3 -1
  50. package/lib/yoke/adapters/claude-vendor.js +0 -1
  51. package/lib/yoke/adapters/claude-worker.js +6 -4
  52. package/lib/yoke/adapters/claude.js +34 -34
  53. package/lib/yoke/adapters/codex-capabilities.js +9 -6
  54. package/lib/yoke/adapters/codex-vendor.js +15 -15
  55. package/lib/yoke/adapters/codex.js +121 -61
  56. package/lib/yoke/auth-checks.js +8 -21
  57. package/lib/yoke/codex-app-server.js +27 -71
  58. package/lib/yoke/codex-binary.js +254 -0
  59. package/lib/yoke/codex-command.js +122 -0
  60. package/lib/yoke/codex-protocol.js +96 -0
  61. package/lib/yoke/codex-version.js +135 -0
  62. package/lib/yoke/index.js +20 -4
  63. package/lib/yoke/install-probe.js +21 -6
  64. package/lib/yoke/interface.js +11 -5
  65. package/lib/yoke/registry.js +41 -4
  66. package/package.json +1 -2
  67. package/scripts/verify-installed-build.js +59 -17
  68. package/lib/lore-attestation.js +0 -73
@@ -0,0 +1,172 @@
1
+ // session-resume.js - bring a stored session back into a project's session
2
+ // manager on its own vendor and agent. One implementation for the browser's
3
+ // resume_session message and for input injected from outside (session-input.js).
4
+ //
5
+ // A failure is reported as a failure: every function here either answers
6
+ // positively (a session, or a verified absence) or rejects with an Error whose
7
+ // `retryable` says whether trying again can help. An unreadable store and a
8
+ // history that cannot be loaded are never read as "no such session" or as an
9
+ // empty history.
10
+
11
+ var fs = require("fs");
12
+ var utils = require("./utils");
13
+ var sessionIdGuard = require("./session-id");
14
+
15
+ var isSafeSessionId = sessionIdGuard.isSafeSessionId;
16
+
17
+ function messageOf(err) {
18
+ return err && err.message ? err.message : String(err);
19
+ }
20
+
21
+ function resumeError(message, retryable) {
22
+ var err = new Error(message);
23
+ err.retryable = retryable;
24
+ return err;
25
+ }
26
+
27
+ // An unsafe id is refused, never read as "no such session" and passed on.
28
+ function assertSafeSessionId(cliSessionId) {
29
+ if (!isSafeSessionId(cliSessionId)) {
30
+ throw resumeError("unsafe session id " + JSON.stringify(String(cliSessionId).slice(0, 64)) + " refused", false);
31
+ }
32
+ }
33
+
34
+ // A record is a JSON object; null, numbers, strings and arrays are not.
35
+ function isRecord(value) {
36
+ return value !== null && typeof value === "object" && !Array.isArray(value);
37
+ }
38
+
39
+ // Reads the console's own record of a session: its meta line and its history.
40
+ // Returns null only when there is no such file. An unsafe id, a file that is
41
+ // there but cannot be read, or one whose records are damaged, throws (see
42
+ // resumeError).
43
+ //
44
+ // Every history line must parse to a JSON object, wherever it is: skipping or
45
+ // accepting anything else would hand the vendor a history with a hole in it.
46
+ // The only thing tolerated besides records is the single newline that ends the
47
+ // file, which the console's writer always adds.
48
+ function readStoredSession(sessionsDir, cliSessionId) {
49
+ assertSafeSessionId(cliSessionId);
50
+ if (!sessionsDir) return null;
51
+ var file;
52
+ try { file = sessionIdGuard.sessionPathWithin(sessionsDir, cliSessionId, ".jsonl"); }
53
+ catch (e) { throw resumeError(messageOf(e), false); }
54
+ var raw;
55
+ try { raw = fs.readFileSync(file, "utf8"); }
56
+ catch (e) {
57
+ if (e && e.code === "ENOENT") return null;
58
+ throw resumeError("cannot read stored session " + cliSessionId + ": " + messageOf(e), true);
59
+ }
60
+ var lines = (raw.endsWith("\n") ? raw.slice(0, -1) : raw).split("\n");
61
+ var meta;
62
+ try { meta = JSON.parse(lines[0]); }
63
+ catch (e) { throw resumeError("stored session " + cliSessionId + " is damaged: its meta record is not valid JSON", false); }
64
+ if (!isRecord(meta) || meta.type !== "meta") {
65
+ throw resumeError("stored session " + cliSessionId + " is damaged: its first record is not a meta record", false);
66
+ }
67
+ var history = [];
68
+ for (var i = 1; i < lines.length; i++) {
69
+ var record;
70
+ try { record = JSON.parse(lines[i]); }
71
+ catch (e) {
72
+ throw resumeError("stored session " + cliSessionId + " is damaged: line " + (i + 1) + " is malformed", false);
73
+ }
74
+ if (!isRecord(record)) {
75
+ throw resumeError("stored session " + cliSessionId + " is damaged: line " + (i + 1) + " is not a JSON object", false);
76
+ }
77
+ history.push(record);
78
+ }
79
+ return { meta: meta, history: history };
80
+ }
81
+
82
+ // Whether the console's own store holds a session. Sessions the vendor holds
83
+ // but the console never recorded are not addressable by injected input.
84
+ // Rejects when the record is there but unreadable or damaged.
85
+ function sessionExistsInStore(sm, cliSessionId) {
86
+ return Promise.resolve().then(function () {
87
+ return readStoredSession(sm.sessionsDir, cliSessionId) !== null;
88
+ });
89
+ }
90
+
91
+ function titleFromHistory(history) {
92
+ for (var i = 0; i < history.length; i++) {
93
+ if (history[i].type === "user_message" && history[i].text) return history[i].text.substring(0, 50);
94
+ }
95
+ return "Resumed session";
96
+ }
97
+
98
+ function defaultReadHistory(cwd, cliSessionId) {
99
+ return require("./cli-sessions").readCliSessionHistory(cwd, cliSessionId);
100
+ }
101
+
102
+ // Resumes cliSessionId into deps.sm and resolves the session (null when the
103
+ // session manager declines). Rejects, with `retryable` set, when the stored
104
+ // record or the vendor's history cannot be loaded: a session is never resumed
105
+ // on a history that failed to load.
106
+ // Vendor, agent, owner, visibility and granted tools come from the stored
107
+ // meta record so the session continues as what it was, not as the project's
108
+ // default. Without a console record the vendor's own history is used.
109
+ //
110
+ // deps: { sm, adapter, cwd, readHistory? } readHistory(cwd, id) -> Promise<history[]>
111
+ // opts: { ws, activate } ws is the requesting browser connection, if any;
112
+ // activate:false keeps every connected client on the session it is viewing.
113
+ function resumeStoredSession(deps, cliSessionId, opts) {
114
+ var sm = deps.sm;
115
+ var ws = (opts && opts.ws) || undefined;
116
+ var activate = !(opts && opts.activate === false);
117
+
118
+ return Promise.resolve().then(function () {
119
+ // First, before the id reaches the store, the adapter or the vendor's files.
120
+ assertSafeSessionId(cliSessionId);
121
+ var stored = readStoredSession(sm.sessionsDir, cliSessionId);
122
+ var meta = stored && stored.meta;
123
+ var resumeOpts = { activate: activate };
124
+ if (meta) {
125
+ if (meta.vendor) resumeOpts.vendor = meta.vendor;
126
+ if (meta.agentName) resumeOpts.agentName = meta.agentName;
127
+ if (meta.ownerId) resumeOpts.ownerId = meta.ownerId;
128
+ if (meta.sessionVisibility) resumeOpts.sessionVisibility = meta.sessionVisibility;
129
+ // Sanitized so a crafted meta record cannot auto-approve a tool.
130
+ if (meta.allowedTools) resumeOpts.allowedTools = utils.sanitizeAllowedTools(meta.allowedTools);
131
+ }
132
+
133
+ function finish(extra) {
134
+ var session = sm.resumeSession(cliSessionId, Object.assign(resumeOpts, extra), ws);
135
+ if (session && typeof sm.retrimHistory === "function") sm.retrimHistory(session);
136
+ return session || null;
137
+ }
138
+
139
+ if (stored) {
140
+ return finish({
141
+ history: stored.history,
142
+ title: meta.title || titleFromHistory(stored.history),
143
+ });
144
+ }
145
+
146
+ var readHistory = deps.readHistory || defaultReadHistory;
147
+ // The summary only names the resumed session; a lookup that fails leaves
148
+ // the title taken from the history instead and does not affect delivery.
149
+ var titlePromise = Promise.resolve()
150
+ .then(function () { return deps.adapter.getSessionInfo(cliSessionId, { dir: deps.cwd }); })
151
+ .then(function (info) { return (info && info.summary) ? info.summary.substring(0, 100) : null; })
152
+ .catch(function () { return null; });
153
+
154
+ var historyPromise = Promise.resolve()
155
+ .then(function () { return readHistory(deps.cwd, cliSessionId); })
156
+ .catch(function (err) {
157
+ throw resumeError("could not load the history of session " + cliSessionId + ": " + messageOf(err), true);
158
+ });
159
+
160
+ return Promise.all([historyPromise, titlePromise]).then(function (results) {
161
+ var history = results[0];
162
+ return finish({ history: history, title: results[1] || titleFromHistory(history) });
163
+ });
164
+ });
165
+ }
166
+
167
+ module.exports = {
168
+ isSafeSessionId: isSafeSessionId,
169
+ readStoredSession: readStoredSession,
170
+ sessionExistsInStore: sessionExistsInStore,
171
+ resumeStoredSession: resumeStoredSession,
172
+ };
package/lib/sessions.js CHANGED
@@ -2,10 +2,12 @@ var fs = require("fs");
2
2
  var path = require("path");
3
3
  var config = require("./config");
4
4
  var utils = require("./utils");
5
+ var sessionIdGuard = require("./session-id");
5
6
  var users = require("./users");
6
7
  var { CODEX_DEFAULTS } = require("./codex-defaults");
7
8
  var { isVisibleHistoryEvent } = require("./history-visibility");
8
9
  var { createPromptRegistry } = require("./prompt-registry");
10
+ var sessionReclaim = require("./session-reclaim");
9
11
 
10
12
  // lr-2ea2a7: hard cap on how many history entries a session may hold in the
11
13
  // heap array, regardless of isProcessing state. On-disk JSONL remains the
@@ -122,7 +124,7 @@ function createSessionManager(opts) {
122
124
  fs.mkdirSync(sessionsDir, { recursive: true });
123
125
 
124
126
  function sessionFilePath(cliSessionId) {
125
- return path.join(sessionsDir, cliSessionId + ".jsonl");
127
+ return sessionIdGuard.sessionPathWithin(sessionsDir, cliSessionId, ".jsonl");
126
128
  }
127
129
 
128
130
  function buildMetaLine(session) {
@@ -163,6 +165,10 @@ function createSessionManager(opts) {
163
165
  if (session.pendingAutoResume) {
164
166
  metaObj.pendingAutoResume = true;
165
167
  if (session.pendingAutoResumeReason) metaObj.pendingAutoResumeReason = session.pendingAutoResumeReason;
168
+ // Names of the agents a daemon shutdown interrupted, for the notice at
169
+ // the next startup (lib/session-reclaim.js).
170
+ var resumeAgents = sessionReclaim.sanitizeAgentLabels(session.pendingAutoResumeAgents);
171
+ if (resumeAgents) metaObj.pendingAutoResumeAgents = resumeAgents;
166
172
  }
167
173
  // lr-62157d: durable auto-title state. Without this, titleAutoGenerated
168
174
  // and titleManuallySet lived in memory only — every daemon restart reset
@@ -772,6 +778,7 @@ function createSessionManager(opts) {
772
778
  if (m.pendingAutoResume) {
773
779
  session.pendingAutoResume = true;
774
780
  session.pendingAutoResumeReason = m.pendingAutoResumeReason || null;
781
+ session.pendingAutoResumeAgents = sessionReclaim.sanitizeAgentLabels(m.pendingAutoResumeAgents);
775
782
  }
776
783
  // lr-62157d: restore auto-title state across a daemon restart — see
777
784
  // buildMetaLine's write side for why this must persist. Without this,
@@ -1366,6 +1373,9 @@ function createSessionManager(opts) {
1366
1373
  }
1367
1374
 
1368
1375
  function resumeSession(cliSessionId, opts, targetWs) {
1376
+ // The id names a file under sessionsDir; declining here keeps an unvalidated
1377
+ // id from reaching saveSessionFile for any caller.
1378
+ if (!sessionIdGuard.isSafeSessionId(cliSessionId)) return null;
1369
1379
  // If a session with this cliSessionId already exists, just switch to it
1370
1380
  var existing = null;
1371
1381
  sessions.forEach(function (s) {
@@ -1409,10 +1419,14 @@ function createSessionManager(opts) {
1409
1419
  favoriteOrder: null,
1410
1420
  };
1411
1421
  if (opts && opts.vendor) session.vendor = opts.vendor;
1422
+ if (opts && opts.agentName) session.agentName = opts.agentName;
1423
+ if (opts && opts.sessionVisibility) session.sessionVisibility = opts.sessionVisibility;
1412
1424
  if (opts && opts.ownerId) session.ownerId = opts.ownerId;
1413
1425
  sessions.set(localId, session);
1414
1426
  saveSessionFile(session);
1415
- switchSession(localId, targetWs);
1427
+ // activate:false is for a resume nobody asked to look at (injected input):
1428
+ // switching would move every connected client off the session it is on.
1429
+ if (!(opts && opts.activate === false)) switchSession(localId, targetWs);
1416
1430
  return session;
1417
1431
  }
1418
1432
 
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ // supervisor.js — is a service manager responsible for this daemon's lifetime?
4
+ //
5
+ // Under systemd the unit restarts the daemon after it exits (Restart=always),
6
+ // and KillMode=mixed removes every other process in the unit's cgroup when the
7
+ // main process exits. A daemon that spawned its own replacement before exiting
8
+ // therefore had the replacement killed with the rest of the cgroup, and the
9
+ // restart worked only because the unit started another one. A supervised
10
+ // restart is an exit with RESTART_EXIT_CODE and nothing else.
11
+
12
+ // Also the code the dev watcher (lib/cli/daemon-launch.js) respawns on.
13
+ var RESTART_EXIT_CODE = 120;
14
+
15
+ // Set by systemd for every process it starts as part of a unit.
16
+ var SUPERVISOR_ENV = ['INVOCATION_ID', 'NOTIFY_SOCKET'];
17
+
18
+ function isSupervised(env) {
19
+ var e = env || process.env;
20
+ return SUPERVISOR_ENV.some(function (name) { return !!e[name]; });
21
+ }
22
+
23
+ /**
24
+ * The environment for a daemon this process starts itself (the CLI's detached
25
+ * start, a self-spawned replacement). That daemon is not the unit's main
26
+ * process, so it must not read the unit's variables, which it would inherit
27
+ * when the CLI itself was run from inside a service.
28
+ */
29
+ function unsupervisedEnv(env) {
30
+ var copy = Object.assign({}, env || process.env);
31
+ SUPERVISOR_ENV.forEach(function (name) { delete copy[name]; });
32
+ return copy;
33
+ }
34
+
35
+ module.exports = {
36
+ RESTART_EXIT_CODE: RESTART_EXIT_CODE,
37
+ isSupervised: isSupervised,
38
+ unsupervisedEnv: unsupervisedEnv,
39
+ };
@@ -0,0 +1,108 @@
1
+ // turn-initiator.js - who started a turn, carried per turn from the entry point
2
+ // that created it to the agent adapter that delivers it.
3
+ //
4
+ // The initiator is a property of ONE turn, never of a session: a session can
5
+ // take a typed turn, then a scheduled one, then a typed one again. Each entry
6
+ // point (the WebSocket "message" handler, the scheduled-message timer, a Ralph
7
+ // loop iteration, an external trigger) names its initiator and passes it with
8
+ // the turn; an adapter maps it to the vendor's own provenance field. A turn
9
+ // whose entry point names none is delivered unstamped.
10
+ //
11
+ // This module owns the console-side vocabulary and the Claude mapping. Where a
12
+ // vendor carries provenance in a different place (the Codex adapter), the
13
+ // adapter maps from the same vocabulary.
14
+
15
+ var pkg = require("../package.json");
16
+ var runtimeEnv = require("./runtime-env");
17
+
18
+ var INITIATORS = Object.freeze({
19
+ // Text a person typed into the console.
20
+ HUMAN: "human",
21
+ // A message the console sent at the time the person scheduled it.
22
+ SCHEDULED: "scheduled",
23
+ // A scheduled message the person chose to send now.
24
+ SCHEDULED_NOW: "scheduled-now",
25
+ // One iteration of an automated loop.
26
+ LOOP: "loop",
27
+ // A turn delivered by an external trigger.
28
+ TRIGGER: "trigger",
29
+ });
30
+
31
+ var KNOWN = Object.keys(INITIATORS).map(function (k) { return INITIATORS[k]; });
32
+
33
+ function isInitiator(value) {
34
+ return KNOWN.indexOf(value) !== -1;
35
+ }
36
+
37
+ // The Claude Agent SDK's SDKMessageOrigin for a turn. Undefined when the turn
38
+ // names no initiator: the SDK treats an absent origin as unattributed, so only
39
+ // a turn the console knows the source of is stamped.
40
+ function claudeOrigin(initiator) {
41
+ switch (initiator) {
42
+ case INITIATORS.HUMAN:
43
+ return { kind: "human" };
44
+ case INITIATORS.SCHEDULED:
45
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "scheduled" };
46
+ case INITIATORS.SCHEDULED_NOW:
47
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "manual" };
48
+ case INITIATORS.LOOP:
49
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "loop" };
50
+ case INITIATORS.TRIGGER:
51
+ return { kind: "task-notification", subkind: "scheduled-trigger", fireReason: "trigger" };
52
+ default:
53
+ return undefined;
54
+ }
55
+ }
56
+
57
+ // Whether the CLI must deliver the turn's text as written (no @path expansion,
58
+ // no slash-command dispatch): true for every turn a person did not type.
59
+ function isClientComposed(initiator) {
60
+ return isInitiator(initiator) && initiator !== INITIATORS.HUMAN;
61
+ }
62
+
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
+ // Identifies this product to the Claude Agent SDK ("<app>/<version>").
72
+ function clientAppId() {
73
+ return "clagentic-console/" + pkg.version;
74
+ }
75
+
76
+ // The environment additions the console always makes for a Claude process.
77
+ // 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;
82
+ }
83
+
84
+ // The complete environment for a Claude process: the process's own, then the
85
+ // Settings overlay, then the console's additions. The SDK replaces the CLI's
86
+ // 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));
89
+ }
90
+
91
+ // A streamed Claude user message for a turn, with its provenance stamped.
92
+ function stampClaudeUserMessage(message, initiator) {
93
+ var origin = claudeOrigin(initiator);
94
+ if (origin) message.origin = origin;
95
+ if (isClientComposed(initiator)) message.client_composed = true;
96
+ return message;
97
+ }
98
+
99
+ module.exports = {
100
+ INITIATORS: INITIATORS,
101
+ isInitiator: isInitiator,
102
+ claudeOrigin: claudeOrigin,
103
+ isClientComposed: isClientComposed,
104
+ clientAppId: clientAppId,
105
+ claudeHostEnv: claudeHostEnv,
106
+ claudeProcessEnv: claudeProcessEnv,
107
+ stampClaudeUserMessage: stampClaudeUserMessage,
108
+ };
@@ -51,6 +51,7 @@ function buildVendorRegistryMessage(sm, linuxUser) {
51
51
  vendors: registry.describeForClient({
52
52
  installed: state.installed,
53
53
  probeFailures: state.failures,
54
+ details: state.details,
54
55
  available: sm.availableVendors || [],
55
56
  capabilities: sm.capabilitiesByVendor || {},
56
57
  }),
package/lib/ws-schema.js CHANGED
@@ -78,7 +78,9 @@ var schema = {
78
78
  // were live, sent types with no documentation entry.
79
79
  "plan_content": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Plan-mode content for the plan card" },
80
80
  "sdk_notification": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Informational notification surfaced from the vendor SDK" },
81
- "diagnostic": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Session-scoped diagnostic toast (settings preflight, memory shedding, adapter warnings)" },
81
+ "diagnostic": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Session-scoped diagnostic toast (settings preflight, memory shedding, adapter warnings). A message with refresh:true updates the entry the client already holds for the same source and action, and is ignored when the client holds none" },
82
+
83
+ "diagnostic_retract": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Withdraws every diagnostic of one source (source) because its condition no longer holds; sent when the installed build is adopted while an update offer is shown, and to a client that connects while no offer stands" },
82
84
 
83
85
  // -----------------------------------------------------------------------
84
86
  // Thinking
@@ -24,7 +24,6 @@ registry.register({
24
24
  needsRuntimeEnv: false,
25
25
  perProjectRuntime: false,
26
26
  activityTokens: false,
27
- attestsHumanSessions: false,
28
27
  ownedEnvNames: ["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN"].concat(providerCredentials.allCredentialNames()),
29
28
  ownedEnvPrefixes: providerCredentials.allCredentialPrefixes(),
30
29
  credentialGroups: providerCredentials.CREDENTIAL_GROUPS,
@@ -21,7 +21,7 @@ var os = require("os");
21
21
  var parseDiagnosticLine = require("./diagnostic-patterns").parseDiagnosticLine;
22
22
  var permissionRelay = require("./permission-relay");
23
23
  var effortControl = require("./effort-control");
24
- var runtimeEnv = require("../../runtime-env");
24
+ var turnInitiator = require("../../turn-initiator");
25
25
  var workerMcpServers = require("./worker-mcp-servers");
26
26
 
27
27
  var socketPath = process.argv[2];
@@ -105,10 +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;
108
109
  delete options.runtimeEnv;
109
- if (runtimeEnv.hasOverlay(overlay)) {
110
- options.env = runtimeEnv.composeRuntimeEnv(process.env, overlay);
111
- }
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);
112
114
  return options;
113
115
  }
114
116
 
@@ -16,6 +16,7 @@ var modelCatalog = require("../../model-catalog");
16
16
  var permissionRelay = require("./permission-relay");
17
17
  var effortControl = require("./effort-control");
18
18
  var runtimeEnv = require("../../runtime-env");
19
+ var turnInitiator = require("../../turn-initiator");
19
20
  var claudeCapabilities = require("./claude-capabilities").claudeCapabilities;
20
21
 
21
22
  // --- SDK loading ---
@@ -342,6 +343,22 @@ function flattenEvent(raw) {
342
343
  return base;
343
344
  }
344
345
 
346
+ // The streamed user message for one turn, stamped with who initiated it. Shared
347
+ // by the in-process and worker handles so both deliver the same provenance.
348
+ function buildUserMessage(text, images, initiator) {
349
+ var content = [];
350
+ if (images && images.length > 0) {
351
+ for (var i = 0; i < images.length; i++) {
352
+ content.push({
353
+ type: "image",
354
+ source: { type: "base64", media_type: images[i].mediaType, data: images[i].data },
355
+ });
356
+ }
357
+ }
358
+ if (text) content.push({ type: "text", text: text });
359
+ return turnInitiator.stampClaudeUserMessage({ type: "user", message: { role: "user", content: content } }, initiator);
360
+ }
361
+
345
362
  // --- QueryHandle ---
346
363
  // Wraps a raw SDK query object with the YOKE QueryHandle interface.
347
364
  // Events are flattened via flattenEvent before yielding.
@@ -363,18 +380,8 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
363
380
  };
364
381
  },
365
382
 
366
- pushMessage: function(text, images) {
367
- var content = [];
368
- if (images && images.length > 0) {
369
- for (var i = 0; i < images.length; i++) {
370
- content.push({
371
- type: "image",
372
- source: { type: "base64", media_type: images[i].mediaType, data: images[i].data },
373
- });
374
- }
375
- }
376
- if (text) content.push({ type: "text", text: text });
377
- messageQueue.push({ type: "user", message: { role: "user", content: content } });
383
+ pushMessage: function(text, images, initiator) {
384
+ messageQueue.push(buildUserMessage(text, images, initiator));
378
385
  },
379
386
 
380
387
  setModel: function(model) {
@@ -1097,19 +1104,8 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
1097
1104
  };
1098
1105
  },
1099
1106
 
1100
- pushMessage: function(text, images) {
1101
- var content = [];
1102
- if (images && images.length > 0) {
1103
- for (var i = 0; i < images.length; i++) {
1104
- content.push({
1105
- type: "image",
1106
- source: { type: "base64", media_type: images[i].mediaType, data: images[i].data },
1107
- });
1108
- }
1109
- }
1110
- if (text) content.push({ type: "text", text: text });
1111
- var userMsg = { type: "user", message: { role: "user", content: content } };
1112
- worker.send({ type: "push_message", content: userMsg });
1107
+ pushMessage: function(text, images, initiator) {
1108
+ worker.send({ type: "push_message", content: buildUserMessage(text, images, initiator) });
1113
1109
  },
1114
1110
 
1115
1111
  // lr-f22787: correlated by requestId (mirrors rewindFiles below) so the
@@ -1651,11 +1647,11 @@ function createClaudeAdapter(opts) {
1651
1647
  if (co.resumeSessionAt) sdkOptions.resumeSessionAt = co.resumeSessionAt;
1652
1648
  if (co.settings) sdkOptions.settings = co.settings;
1653
1649
 
1654
- // options.env REPLACES the subprocess environment, so a query with
1655
- // Settings variables is handed the whole environment, not the additions.
1656
- if (runtimeEnv.hasOverlay(queryOpts.runtimeEnv)) {
1657
- sdkOptions.env = runtimeEnv.composeRuntimeEnv(process.env, queryOpts.runtimeEnv);
1658
- }
1650
+ // options.env REPLACES the subprocess environment, so the query is handed
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);
1659
1655
 
1660
1656
  var rawQuery = sdk.query({ prompt: mq, options: sdkOptions });
1661
1657
  return createQueryHandle(rawQuery, mq, ac);
@@ -1678,7 +1674,11 @@ function createClaudeAdapter(opts) {
1678
1674
  adapterOptions: {
1679
1675
  CLAUDE: {
1680
1676
  settingSources: ["user"],
1681
- permissionMode: "bypassPermissions",
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
1682
  }
1683
1683
  },
1684
1684
  abortController: ac,
@@ -1825,6 +1825,8 @@ function createClaudeAdapter(opts) {
1825
1825
  // The worker lays these over its own environment (the OS user's), then
1826
1826
  // hands the SDK the complete result.
1827
1827
  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;
1828
1830
 
1829
1831
  if (queryOpts.toolServerDescriptors) queryOptions.mcpServerDescriptors = queryOpts.toolServerDescriptors;
1830
1832
  if (queryOpts.model) queryOptions.model = queryOpts.model;
@@ -1874,9 +1876,7 @@ function createClaudeAdapter(opts) {
1874
1876
  warmupOptions.allowDangerouslySkipPermissions = true;
1875
1877
  }
1876
1878
  // The warmup starts the same CLI a query does, so it gets the same environment.
1877
- if (initOpts && runtimeEnv.hasOverlay(initOpts.runtimeEnv)) {
1878
- warmupOptions.env = runtimeEnv.composeRuntimeEnv(process.env, initOpts.runtimeEnv);
1879
- }
1879
+ warmupOptions.env = turnInitiator.claudeProcessEnv(process.env, initOpts && initOpts.runtimeEnv);
1880
1880
 
1881
1881
  var result = {
1882
1882
  models: [],
@@ -2,11 +2,14 @@
2
2
 
3
3
  // What a Codex session can do: the declaration the Codex adapter registers and
4
4
  // the capabilities its init advertises. Every key is one of the YOKE
5
- // capability ledger (lib/yoke/interface.js). A Codex thread is resumed,
6
- // forked and rolled back through the app-server; it has no thinking budget,
7
- // file checkpoints, beta switches or subagents, and no permission modes beyond
8
- // the approval policy Codex owns, so those are declared off and the UI shows
9
- // them disabled.
5
+ // capability ledger (lib/yoke/interface.js). A Codex thread is resumed and
6
+ // forked through the app-server; it has no thinking budget, file checkpoints,
7
+ // beta switches or subagents, and no permission modes beyond the approval
8
+ // policy Codex owns, so those are declared off and the UI shows them disabled.
9
+ //
10
+ // Rewinding a thread in place (rewind, rollback) is not offered: the app-server
11
+ // call the console used was removed from the supported releases, and its
12
+ // replacement cannot be made safe against a turn appended while it runs.
10
13
 
11
14
  function codexCapabilities() {
12
15
  return {
@@ -15,7 +18,7 @@ function codexCapabilities() {
15
18
  effort: true,
16
19
  rewind: false,
17
20
  fork: true,
18
- rollback: true,
21
+ rollback: false,
19
22
  sessionResume: true,
20
23
  sessionList: false,
21
24
  sessionRename: false,
@@ -2,24 +2,17 @@
2
2
  // that asking the registry which agents exist does not load the adapter; it is
3
3
  // required only when an adapter is actually created.
4
4
 
5
- var fs = require("fs");
6
5
  var registry = require("../registry");
7
6
  var authChecks = require("../auth-checks");
7
+ var codexBinary = require("../codex-binary");
8
8
  var codexCapabilities = require("./codex-capabilities").codexCapabilities;
9
9
 
10
- // A bundled app-server binary counts as installed even when no `codex`
11
- // executable is on PATH.
12
- function probeCodexInstalled(ctx) {
13
- var appServer = require("../codex-app-server");
14
- try {
15
- var bundled = appServer.findCodexPath();
16
- if (bundled && fs.existsSync(bundled)) return true;
17
- } catch (e) {
18
- // Only an absent bundle falls through to the PATH lookup; anything else is
19
- // a defect and reaches the probe, which reports it as a failed check.
20
- if (!appServer.isBundleAbsent(e)) throw e;
21
- }
22
- return ctx.lookupBinary("codex");
10
+ // The console ships no Codex: the agent is installed when the user's own Codex
11
+ // resolves and is new enough. When it does not, the picker shows the reason
12
+ // (not installed, too old, an override that points nowhere) and, when one is
13
+ // usable, which binary and version will run.
14
+ function probeCodexInstalled() {
15
+ return codexBinary.describe(codexBinary.resolveCached());
23
16
  }
24
17
 
25
18
  registry.register({
@@ -29,18 +22,25 @@ registry.register({
29
22
  priority: 20,
30
23
  binaryNames: ["codex"],
31
24
  probeInstalled: probeCodexInstalled,
25
+ recheck: codexBinary.invalidate,
32
26
  checkAuth: authChecks.checkCodexAuth,
33
27
  installHint: "Install the Codex CLI (npm install -g @openai/codex), then sign in.",
34
28
  loginCommand: "codex login --device-auth",
29
+ // The app-server is not started per OS user, so under per-user isolation the
30
+ // agent is disabled (yoke/index.js, install-probe.js) and never started.
35
31
  osUsersSupported: false,
36
32
  needsRuntimeEnv: true,
37
33
  perProjectRuntime: true,
38
34
  activityTokens: true,
39
- attestsHumanSessions: true,
40
35
  ownedEnvNames: ["OPENAI_API_KEY", "OPENAI_BASE_URL"],
41
36
  credentialGroups: [{ id: "openai-endpoint", envNames: ["OPENAI_API_KEY", "OPENAI_BASE_URL"] }],
42
37
  nativeInstructionFiles: ["AGENTS.md"],
43
38
  interruptMessage: "■ Conversation interrupted - tell the model what to do differently.",
39
+ // Rewinding a Codex thread in place is not offered yet.
40
+ capabilityReasons: {
41
+ rewind: "Rewind is not available for Codex sessions yet",
42
+ rollback: "Rewind is not available for Codex sessions yet",
43
+ },
44
44
  capabilities: codexCapabilities(),
45
45
  createAdapter: function(opts) { return require("./codex").createCodexAdapter(opts); },
46
46
  });