@clagentic/console 1.10.0 → 1.11.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/bin/cli.js +15 -3
- package/lib/agents.js +1 -55
- package/lib/bash-auto-approve.js +133 -0
- package/lib/build-identity.js +23 -5
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +0 -62
- package/lib/build-update-offer.js +23 -13
- package/lib/build-update-restart.js +59 -43
- package/lib/cli/schedule-input-subcommands.js +327 -0
- package/lib/cli/session-subcommands.js +100 -17
- package/lib/client-build-id.js +56 -0
- package/lib/daemon.js +20 -5
- package/lib/injected-sender.js +225 -0
- package/lib/message-sender-record.js +133 -0
- package/lib/pending-prompts.js +55 -0
- package/lib/permission-mode-policy.js +63 -0
- package/lib/permission-summary.js +67 -0
- package/lib/project-connection.js +2 -1
- package/lib/project-external-trigger.js +9 -1
- package/lib/project-loop.js +26 -20
- package/lib/project-prompt-responses.js +20 -14
- package/lib/project-sessions.js +73 -21
- package/lib/project-user-message.js +18 -47
- package/lib/project.js +36 -62
- package/lib/public/app.js +3 -5
- package/lib/public/css/channel-layout.css +20 -0
- package/lib/public/css/diagnostics.css +7 -0
- package/lib/public/css/input.css +78 -0
- package/lib/public/css/menus.css +17 -0
- package/lib/public/modules/app-connection.js +18 -1
- package/lib/public/modules/app-messages.js +19 -17
- package/lib/public/modules/app-panels.js +9 -2
- package/lib/public/modules/app-rate-limit.js +63 -87
- package/lib/public/modules/app-rendering.js +37 -6
- package/lib/public/modules/at-agents.js +8 -0
- package/lib/public/modules/build-guard.js +61 -0
- package/lib/public/modules/build-update-detail.js +1 -4
- package/lib/public/modules/diagnostics.js +98 -9
- package/lib/public/modules/injected-identity.js +78 -0
- package/lib/public/modules/injected-label.js +62 -0
- package/lib/public/modules/input.js +64 -114
- package/lib/public/modules/mode-options.js +19 -16
- package/lib/public/modules/rate-limit-state.js +47 -22
- package/lib/public/modules/schedule-panel.js +234 -0
- package/lib/public/modules/schedule-time.js +193 -0
- package/lib/public/modules/scheduled-input-actions.js +19 -0
- package/lib/runtime-env.js +4 -0
- package/lib/scheduled-input/ipc.js +92 -0
- package/lib/scheduled-input/rate-limit-resume.js +53 -0
- package/lib/scheduled-input/records.js +350 -0
- package/lib/scheduled-input/service.js +743 -0
- package/lib/scheduled-input/store.js +132 -0
- package/lib/scheduled-input/ws.js +194 -0
- package/lib/sdk-bridge.js +137 -152
- package/lib/sdk-message-processor.js +13 -5
- package/lib/sdk-skill-discovery.js +17 -0
- package/lib/sender-ref.js +109 -0
- package/lib/server.js +28 -8
- package/lib/session-directory.js +224 -0
- package/lib/session-file-scan.js +55 -0
- package/lib/session-input-ipc.js +20 -0
- package/lib/session-input.js +355 -19
- package/lib/session-name-holder.js +82 -0
- package/lib/session-resume.js +1 -0
- package/lib/sessions.js +44 -0
- package/lib/turn-initiator.js +6 -2
- package/lib/ws-schema.js +15 -7
- package/lib/yoke/adapters/claude-worker.js +3 -1
- package/lib/yoke/adapters/claude.js +13 -7
- package/lib/yoke/adapters/codex.js +18 -5
- package/lib/yoke/adapters/permission-relay.js +9 -0
- package/lib/yoke/interface.js +7 -1
- package/package.json +1 -1
- package/scripts/check-test-count.js +1 -1
- package/scripts/install-local-test.js +45 -1
- package/scripts/postinstall.js +1 -0
package/lib/sessions.js
CHANGED
|
@@ -9,6 +9,9 @@ var { isVisibleHistoryEvent } = require("./history-visibility");
|
|
|
9
9
|
var { createPromptRegistry } = require("./prompt-registry");
|
|
10
10
|
var { registerExitFlush } = require("./exit-flush");
|
|
11
11
|
var sessionReclaim = require("./session-reclaim");
|
|
12
|
+
var sessionFileScan = require("./session-file-scan");
|
|
13
|
+
var { findNameHolder } = require("./session-name-holder");
|
|
14
|
+
var { createSenderRecorder } = require("./message-sender-record");
|
|
12
15
|
|
|
13
16
|
// lr-2ea2a7: hard cap on how many history entries a session may hold in the
|
|
14
17
|
// heap array, regardless of isProcessing state. On-disk JSONL remains the
|
|
@@ -74,6 +77,10 @@ function createSessionManager(opts) {
|
|
|
74
77
|
// wire cross-project unread tracking (e.g. tests constructing a bare
|
|
75
78
|
// SessionManager).
|
|
76
79
|
var onSessionDeleted = opts.onSessionDeleted || function () {};
|
|
80
|
+
// Called with the session object as it was, after it left the manager, for a
|
|
81
|
+
// listener that needs more than the id: scheduled input ends the records
|
|
82
|
+
// bound to the session's vendor session id.
|
|
83
|
+
var onSessionRemoved = opts.onSessionRemoved || function () {};
|
|
77
84
|
|
|
78
85
|
// daemon.json knob `historyInMemMax` (lr-2ea2a7): operators may override the
|
|
79
86
|
// in-heap tail cap. TRIM_TO is derived as 80% of the configured max so the
|
|
@@ -116,6 +123,8 @@ function createSessionManager(opts) {
|
|
|
116
123
|
});
|
|
117
124
|
var capabilitiesByVendor = null; // set by sdk-bridge after adapter init
|
|
118
125
|
var defaultVendor = null; // set by sdk-bridge
|
|
126
|
+
// Publishes who sent each user message (lib/message-sender-record.js).
|
|
127
|
+
var senderRecorder = createSenderRecorder({ getBaseDir: function () { return opts.senderRecordDir || config.CONFIG_DIR; } });
|
|
119
128
|
var codexApproval = CODEX_DEFAULTS.approval;
|
|
120
129
|
var codexSandbox = CODEX_DEFAULTS.sandbox;
|
|
121
130
|
var codexWebSearch = CODEX_DEFAULTS.webSearch;
|
|
@@ -145,6 +154,7 @@ function createSessionManager(opts) {
|
|
|
145
154
|
if (typeof session.favoriteOrder === "number") metaObj.favoriteOrder = session.favoriteOrder;
|
|
146
155
|
if (session.lastRewindUuid) metaObj.lastRewindUuid = session.lastRewindUuid;
|
|
147
156
|
if (session.agentName) metaObj.agentName = session.agentName;
|
|
157
|
+
if (session.sessionName) metaObj.sessionName = session.sessionName;
|
|
148
158
|
if (session.loop) metaObj.loop = session.loop;
|
|
149
159
|
// lr-db0437: persist the session's own model choice so it survives a
|
|
150
160
|
// daemon restart / resume. Without this, session.model only ever lived
|
|
@@ -291,6 +301,10 @@ function createSessionManager(opts) {
|
|
|
291
301
|
// pre-existing lr-f940 contract where such a push is detected via the
|
|
292
302
|
// historyMatchesDisk() length mismatch, not counted as already-durable.
|
|
293
303
|
function recordHistoryEntry(session, obj, persisted) {
|
|
304
|
+
// Every user message the console sends passes here, whichever writer built
|
|
305
|
+
// it, so the published per-message sender record covers all of them. Before
|
|
306
|
+
// the history-loaded check: the record does not depend on the heap window.
|
|
307
|
+
if (obj && obj.type === "user_message") senderRecorder.note(session, obj, defaultVendor);
|
|
294
308
|
if (!session._historyLoaded) return;
|
|
295
309
|
session.history.push(obj);
|
|
296
310
|
if (persisted !== false) {
|
|
@@ -763,6 +777,7 @@ function createSessionManager(opts) {
|
|
|
763
777
|
};
|
|
764
778
|
if (m.vendor) session.vendor = m.vendor;
|
|
765
779
|
if (m.agentName) session.agentName = m.agentName;
|
|
780
|
+
if (m.sessionName) session.sessionName = m.sessionName;
|
|
766
781
|
if (m.loop) session.loop = m.loop;
|
|
767
782
|
// lr-db0437: restore the session's own model choice across a daemon
|
|
768
783
|
// restart — see buildMetaLine's write side above for why this must
|
|
@@ -907,6 +922,7 @@ function createSessionManager(opts) {
|
|
|
907
922
|
favoriteOrder: null,
|
|
908
923
|
vendor: (sessionOpts && sessionOpts.vendor) || null,
|
|
909
924
|
agentName: (sessionOpts && sessionOpts.agentName) || null,
|
|
925
|
+
sessionName: (sessionOpts && sessionOpts.sessionName) || null,
|
|
910
926
|
};
|
|
911
927
|
sessions.set(localId, session);
|
|
912
928
|
switchSession(localId, targetWs);
|
|
@@ -1224,6 +1240,7 @@ function createSessionManager(opts) {
|
|
|
1224
1240
|
sessions.delete(localId);
|
|
1225
1241
|
broadcastSessionDeleted(localId);
|
|
1226
1242
|
onSessionDeleted(localId);
|
|
1243
|
+
onSessionRemoved(session);
|
|
1227
1244
|
|
|
1228
1245
|
if (activeSessionId === localId) {
|
|
1229
1246
|
var remaining = [...sessions.keys()];
|
|
@@ -1268,6 +1285,7 @@ function createSessionManager(opts) {
|
|
|
1268
1285
|
}
|
|
1269
1286
|
sessions.delete(localId);
|
|
1270
1287
|
onSessionDeleted(localId);
|
|
1288
|
+
onSessionRemoved(session);
|
|
1271
1289
|
}
|
|
1272
1290
|
|
|
1273
1291
|
function deleteSessionsBulk(localIds, targetWs) {
|
|
@@ -1424,6 +1442,17 @@ function createSessionManager(opts) {
|
|
|
1424
1442
|
};
|
|
1425
1443
|
if (opts && opts.vendor) session.vendor = opts.vendor;
|
|
1426
1444
|
if (opts && opts.agentName) session.agentName = opts.agentName;
|
|
1445
|
+
if (opts && opts.sessionName) {
|
|
1446
|
+
// The resume is never refused over a name: when another session holds it,
|
|
1447
|
+
// this one comes back unnamed and saveSessionFile below clears the meta.
|
|
1448
|
+
var nameHolder = findNameHolder(sessions, opts.sessionName, localId);
|
|
1449
|
+
if (nameHolder) {
|
|
1450
|
+
console.warn("[sessions] resume of " + cliSessionId + ": name " + JSON.stringify(opts.sessionName) +
|
|
1451
|
+
" is held by session " + nameHolder.localId + "; resumed unnamed");
|
|
1452
|
+
} else {
|
|
1453
|
+
session.sessionName = opts.sessionName;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1427
1456
|
if (opts && opts.sessionVisibility) session.sessionVisibility = opts.sessionVisibility;
|
|
1428
1457
|
if (opts && opts.ownerId) session.ownerId = opts.ownerId;
|
|
1429
1458
|
sessions.set(localId, session);
|
|
@@ -1465,6 +1494,15 @@ function createSessionManager(opts) {
|
|
|
1465
1494
|
return _parseSessionFileLines(session).lines;
|
|
1466
1495
|
}
|
|
1467
1496
|
|
|
1497
|
+
// The newest stored history entry `accept` takes, or null. A bounded reverse
|
|
1498
|
+
// read of the session file: memory is the chunk, not the history, and no
|
|
1499
|
+
// session state is touched. Throws when the file cannot be read.
|
|
1500
|
+
function findNewestHistoryEntry(session, accept) {
|
|
1501
|
+
if (!session.cliSessionId) return null;
|
|
1502
|
+
flushSessionBuffer(session);
|
|
1503
|
+
return sessionFileScan.findNewestEntry(sessionFilePath(session.cliSessionId), accept);
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1468
1506
|
// canSee (optional): predicate over a session; a session it rejects is
|
|
1469
1507
|
// skipped before its title or any of its content is examined.
|
|
1470
1508
|
function searchSessions(query, canSee) {
|
|
@@ -1714,6 +1752,11 @@ function createSessionManager(opts) {
|
|
|
1714
1752
|
// lr-2ea2a7: the single choke point every session.history.push() site
|
|
1715
1753
|
// must route through — see the grep-guard test.
|
|
1716
1754
|
recordHistoryEntry: recordHistoryEntry,
|
|
1755
|
+
// Per-message sender record (lib/message-sender-record.js): the processor
|
|
1756
|
+
// flushes a session's held records once its vendor session id is known and
|
|
1757
|
+
// binds a vendor turn id to the message that started it.
|
|
1758
|
+
flushSenderRecords: function (session) { senderRecorder.flush(session, defaultVendor); },
|
|
1759
|
+
bindSenderTurn: function (session, messageId, turnId) { senderRecorder.bindTurn(session, messageId, turnId, defaultVendor); },
|
|
1717
1760
|
HISTORY_INMEM_MAX: HISTORY_INMEM_MAX,
|
|
1718
1761
|
HISTORY_INMEM_TRIM_TO: HISTORY_INMEM_TRIM_TO,
|
|
1719
1762
|
LRU_HISTORY_LIMIT: LRU_HISTORY_LIMIT,
|
|
@@ -1735,6 +1778,7 @@ function createSessionManager(opts) {
|
|
|
1735
1778
|
// (project-filesystem.js's fs_file_history) so they don't have to call
|
|
1736
1779
|
// loadSessionHistory()/mutate session state just to scan for a match.
|
|
1737
1780
|
readSessionHistoryFromDisk: readSessionHistoryFromDisk,
|
|
1781
|
+
findNewestHistoryEntry: findNewestHistoryEntry,
|
|
1738
1782
|
// lr-2ea2a7 observability: per-session heap footprint + top-5 by
|
|
1739
1783
|
// heapEntries, consumed by project-sessions.js's process_stats handler
|
|
1740
1784
|
// so a future incident is diagnosable without a heap snapshot.
|
package/lib/turn-initiator.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
var pkg = require("../package.json");
|
|
16
16
|
var runtimeEnv = require("./runtime-env");
|
|
17
|
+
var senderRef = require("./sender-ref");
|
|
17
18
|
// Required for its constant only: nothing of the identity surface runs from here.
|
|
18
19
|
var IDENTITY_DIR_ENV = require("./identity/contract").IDENTITY_DIR_ENV;
|
|
19
20
|
|
|
@@ -94,8 +95,11 @@ function claudeHostEnv() {
|
|
|
94
95
|
// console never issued for this process, and a consumer would trust it. It is
|
|
95
96
|
// removed always; `identity` ({ dir: <delivery directory> | null }, present only
|
|
96
97
|
// when an identity provider is configured) is the only way it comes back.
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
//
|
|
99
|
+
// `sessionRef` ({ project, sessionId }) is the console's reference to the session
|
|
100
|
+
// this process belongs to (lib/sender-ref.js), set whatever the provider is.
|
|
101
|
+
function claudeProcessEnv(base, overlay, identity, sessionRef) {
|
|
102
|
+
var env = Object.assign(runtimeEnv.composeRuntimeEnv(base, overlay), claudeHostEnv(), senderRef.envFor(sessionRef));
|
|
99
103
|
delete env[IDENTITY_DIR_ENV];
|
|
100
104
|
if (identity && typeof identity === "object" && typeof identity.dir === "string" && identity.dir) {
|
|
101
105
|
env[IDENTITY_DIR_ENV] = identity.dir;
|
package/lib/ws-schema.js
CHANGED
|
@@ -78,10 +78,13 @@ 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). 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" },
|
|
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. A message with persistent:true is a state, not a notice: its toast has no timer and a repeat replaces the earlier card of the same source" },
|
|
82
82
|
|
|
83
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" },
|
|
84
84
|
|
|
85
|
+
"restart_for_build_update": { direction: "c2s", handler: "lib/project-sessions.js", description: "Admin request to adopt the installed build. Without confirmToken it asks for the offer (what a restart would end) and restarts nothing; with the token of an offer the daemon issued it schedules the restart. The client sets requestId (a string of at most 64 characters) on every request so it can match the answer to the pending click" },
|
|
86
|
+
"restart_for_build_update_result": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Answer to restart_for_build_update. ok:true means the restart is scheduled or already was (any request while one waits gets ok:true and the pending-restart diagnostic, never another offer); otherwise the request was refused (unknown or expired token) and a fresh offer may follow as a diagnostic; a changed session set is never a refusal, and the client gives its action buttons back. requestId is echoed unchanged from the request (absent if the request carried none or an over-long one); a client settles only the pending slot with the matching requestId and ignores any other answer" },
|
|
87
|
+
|
|
85
88
|
// -----------------------------------------------------------------------
|
|
86
89
|
// Thinking
|
|
87
90
|
// -----------------------------------------------------------------------
|
|
@@ -174,12 +177,17 @@ var schema = {
|
|
|
174
177
|
// -----------------------------------------------------------------------
|
|
175
178
|
"rate_limit": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Rate limit hit, includes wait time" },
|
|
176
179
|
"rate_limit_usage": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Current rate limit usage stats" },
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"
|
|
181
|
-
"
|
|
182
|
-
"
|
|
180
|
+
// Scheduled input (lib/scheduled-input/): a once message or a recurring
|
|
181
|
+
// input with an end. The scheduled_message_* names are the original ones, kept;
|
|
182
|
+
// a current client takes its state from scheduled_input_list alone.
|
|
183
|
+
"schedule_message": { direction: "c2s", handler: "lib/scheduled-input/ws.js", description: "Schedule input for the session on screen: once ({ text, resetsAt }) or recurring ({ text, kind, every, until | count })" },
|
|
184
|
+
"send_scheduled_now": { direction: "c2s", handler: "lib/scheduled-input/ws.js", description: "Send a scheduled input immediately ({ id? }), into a running turn if need be" },
|
|
185
|
+
"cancel_scheduled_message": { direction: "c2s", handler: "lib/scheduled-input/ws.js", description: "Cancel a scheduled input ({ id? })" },
|
|
186
|
+
"scheduled_input_list_request": { direction: "c2s", handler: "lib/scheduled-input/ws.js", description: "Ask for the armed scheduled inputs of the session on screen" },
|
|
187
|
+
"scheduled_input_list": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "The armed scheduled inputs of a session, in full, after every change" },
|
|
188
|
+
"scheduled_message_queued": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A scheduled input was queued (older clients draw their bubble from it; also carries id, kind, every, until, count)" },
|
|
189
|
+
"scheduled_message_sent": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A scheduled input was sent (carries id, kind and final)" },
|
|
190
|
+
"scheduled_message_cancelled": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "A scheduled input was cancelled or ended (carries id and reason)" },
|
|
183
191
|
"auto_continue_scheduled": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Auto-continue was scheduled after rate limit" },
|
|
184
192
|
"auto_continue_fired": { direction: "s2c", handler: "lib/public/modules/app-messages.js", description: "Auto-continue timer fired" },
|
|
185
193
|
|
|
@@ -108,9 +108,11 @@ function applyRuntimeEnv(options) {
|
|
|
108
108
|
delete options.runtimeEnv;
|
|
109
109
|
var identity = options.identity;
|
|
110
110
|
delete options.identity;
|
|
111
|
+
var sessionRef = options.sessionRef;
|
|
112
|
+
delete options.sessionRef;
|
|
111
113
|
// Always built: the product identity and host declaration are part of every
|
|
112
114
|
// Claude process's environment.
|
|
113
|
-
options.env = turnInitiator.claudeProcessEnv(process.env, overlay, identity);
|
|
115
|
+
options.env = turnInitiator.claudeProcessEnv(process.env, overlay, identity, sessionRef);
|
|
114
116
|
return options;
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -345,7 +345,9 @@ function flattenEvent(raw) {
|
|
|
345
345
|
|
|
346
346
|
// The streamed user message for one turn, stamped with who initiated it. Shared
|
|
347
347
|
// by the in-process and worker handles so both deliver the same provenance.
|
|
348
|
-
|
|
348
|
+
// `messageId`, when given, is the message's own id (the SDK's uuid field), so the
|
|
349
|
+
// vendor transcript line for this message carries the id the console recorded.
|
|
350
|
+
function buildUserMessage(text, images, initiator, messageId) {
|
|
349
351
|
var content = [];
|
|
350
352
|
if (images && images.length > 0) {
|
|
351
353
|
for (var i = 0; i < images.length; i++) {
|
|
@@ -356,7 +358,9 @@ function buildUserMessage(text, images, initiator) {
|
|
|
356
358
|
}
|
|
357
359
|
}
|
|
358
360
|
if (text) content.push({ type: "text", text: text });
|
|
359
|
-
|
|
361
|
+
var message = turnInitiator.stampClaudeUserMessage({ type: "user", message: { role: "user", content: content } }, initiator);
|
|
362
|
+
if (typeof messageId === "string" && messageId) message.uuid = messageId;
|
|
363
|
+
return message;
|
|
360
364
|
}
|
|
361
365
|
|
|
362
366
|
// --- QueryHandle ---
|
|
@@ -380,8 +384,8 @@ function createQueryHandle(rawQuery, messageQueue, abortController) {
|
|
|
380
384
|
};
|
|
381
385
|
},
|
|
382
386
|
|
|
383
|
-
pushMessage: function(text, images, initiator) {
|
|
384
|
-
messageQueue.push(buildUserMessage(text, images, initiator));
|
|
387
|
+
pushMessage: function(text, images, initiator, messageId) {
|
|
388
|
+
messageQueue.push(buildUserMessage(text, images, initiator, messageId));
|
|
385
389
|
},
|
|
386
390
|
|
|
387
391
|
setModel: function(model) {
|
|
@@ -1104,8 +1108,8 @@ function createWorkerQueryHandle(worker, canUseTool, onElicitation, callMcpTool)
|
|
|
1104
1108
|
};
|
|
1105
1109
|
},
|
|
1106
1110
|
|
|
1107
|
-
pushMessage: function(text, images, initiator) {
|
|
1108
|
-
worker.send({ type: "push_message", content: buildUserMessage(text, images, initiator) });
|
|
1111
|
+
pushMessage: function(text, images, initiator, messageId) {
|
|
1112
|
+
worker.send({ type: "push_message", content: buildUserMessage(text, images, initiator, messageId) });
|
|
1109
1113
|
},
|
|
1110
1114
|
|
|
1111
1115
|
// lr-f22787: correlated by requestId (mirrors rewindFiles below) so the
|
|
@@ -1650,7 +1654,7 @@ function createClaudeAdapter(opts) {
|
|
|
1650
1654
|
// options.env REPLACES the subprocess environment, so the query is handed
|
|
1651
1655
|
// the whole environment (the process's own, the Settings variables, and
|
|
1652
1656
|
// the product identity and host declaration), not the additions.
|
|
1653
|
-
sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.identity);
|
|
1657
|
+
sdkOptions.env = turnInitiator.claudeProcessEnv(process.env, queryOpts.runtimeEnv, queryOpts.identity, queryOpts.sessionRef);
|
|
1654
1658
|
|
|
1655
1659
|
var rawQuery = sdk.query({ prompt: mq, options: sdkOptions });
|
|
1656
1660
|
return createQueryHandle(rawQuery, mq, ac);
|
|
@@ -1770,6 +1774,8 @@ function createClaudeAdapter(opts) {
|
|
|
1770
1774
|
// Present only when an identity provider is configured; the worker adds the
|
|
1771
1775
|
// delivery directory to the Claude process's environment.
|
|
1772
1776
|
if (queryOpts.identity) queryOptions.identity = queryOpts.identity;
|
|
1777
|
+
// The console's reference to this session; the worker adds it to the environment.
|
|
1778
|
+
if (queryOpts.sessionRef) queryOptions.sessionRef = queryOpts.sessionRef;
|
|
1773
1779
|
|
|
1774
1780
|
if (queryOpts.toolServerDescriptors) queryOptions.mcpServerDescriptors = queryOpts.toolServerDescriptors;
|
|
1775
1781
|
if (queryOpts.model) queryOptions.model = queryOpts.model;
|
|
@@ -195,7 +195,15 @@ function flattenEvent(notification, state) {
|
|
|
195
195
|
if (method === "turn/started") {
|
|
196
196
|
state.turnStarted = true;
|
|
197
197
|
var userUuid = generateUuid();
|
|
198
|
-
|
|
198
|
+
var turnStart = { yokeType: "turn_start", uuid: userUuid, messageType: "user" };
|
|
199
|
+
// The app-server's own id for the turn, and the console's id for the message
|
|
200
|
+
// that started it: together they join a message to the Codex rollout.
|
|
201
|
+
var startedTurn = params.turn && params.turn.id ? params.turn.id : params.turnId;
|
|
202
|
+
if (startedTurn && state.currentMessageId) {
|
|
203
|
+
turnStart.turnId = String(startedTurn);
|
|
204
|
+
turnStart.messageId = state.currentMessageId;
|
|
205
|
+
}
|
|
206
|
+
events.push(turnStart);
|
|
199
207
|
return events;
|
|
200
208
|
}
|
|
201
209
|
|
|
@@ -963,9 +971,10 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
963
971
|
}
|
|
964
972
|
|
|
965
973
|
// --- Main query loop ---
|
|
966
|
-
async function runQueryLoop(initialMessage, initialInitiator) {
|
|
974
|
+
async function runQueryLoop(initialMessage, initialInitiator, initialMessageId) {
|
|
967
975
|
// Who started the turn being sent, per turn (turn-initiator.js).
|
|
968
976
|
var currentInitiator = initialInitiator;
|
|
977
|
+
var currentMessageId = initialMessageId;
|
|
969
978
|
// Prepend system prompt (project instructions from YOKE layer) to first message.
|
|
970
979
|
// initialMessage may be a string (text-only) or an array of content items
|
|
971
980
|
// (e.g. [{ type: "text", text: "..." }, ...] when images/attachments are present).
|
|
@@ -1043,6 +1052,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
1043
1052
|
while (!isCancelled()) {
|
|
1044
1053
|
// Reset per-turn state
|
|
1045
1054
|
state.turnStarted = false;
|
|
1055
|
+
// Named on the turn_start event so the console can publish which turn
|
|
1056
|
+
// this message started.
|
|
1057
|
+
state.currentMessageId = currentMessageId || null;
|
|
1046
1058
|
state.textBlocks = {};
|
|
1047
1059
|
state.textLengths = {};
|
|
1048
1060
|
state.thinkingBlocks = {};
|
|
@@ -1159,6 +1171,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
1159
1171
|
if (nextMsg === null) break;
|
|
1160
1172
|
currentMessage = nextMsg.input;
|
|
1161
1173
|
currentInitiator = nextMsg.initiator;
|
|
1174
|
+
currentMessageId = nextMsg.messageId;
|
|
1162
1175
|
}
|
|
1163
1176
|
} catch (e) {
|
|
1164
1177
|
// Suppress AbortError when the user stopped the query.
|
|
@@ -1201,7 +1214,7 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
1201
1214
|
};
|
|
1202
1215
|
},
|
|
1203
1216
|
|
|
1204
|
-
pushMessage: function(text, images, initiator) {
|
|
1217
|
+
pushMessage: function(text, images, initiator, messageId) {
|
|
1205
1218
|
var input;
|
|
1206
1219
|
if (images && images.length > 0) {
|
|
1207
1220
|
input = [];
|
|
@@ -1234,9 +1247,9 @@ function createCodexQueryHandle(appServer, queryOpts) {
|
|
|
1234
1247
|
|
|
1235
1248
|
if (!state.loopStarted) {
|
|
1236
1249
|
state.loopStarted = true;
|
|
1237
|
-
runQueryLoop(input, initiator);
|
|
1250
|
+
runQueryLoop(input, initiator, messageId);
|
|
1238
1251
|
} else {
|
|
1239
|
-
pushMessageToQueue({ input: input, initiator: initiator });
|
|
1252
|
+
pushMessageToQueue({ input: input, initiator: initiator, messageId: messageId });
|
|
1240
1253
|
}
|
|
1241
1254
|
},
|
|
1242
1255
|
|
|
@@ -32,6 +32,11 @@ function toRequestMessage(requestId, toolName, input, opts) {
|
|
|
32
32
|
if (opts.suppressAlwaysAllowRule === true) msg.suppressAlwaysAllowRule = true;
|
|
33
33
|
if (opts.defaultToNo === true) msg.defaultToNo = true;
|
|
34
34
|
if (opts.matchedAskRule) msg.matchedAskRule = opts.matchedAskRule;
|
|
35
|
+
// Which MCP server serves the tool and where its definition came from: the
|
|
36
|
+
// daemon keys MCP auto-approval on it, so it must cross the process boundary.
|
|
37
|
+
if (opts.mcpServer && typeof opts.mcpServer === "object") {
|
|
38
|
+
msg.mcpServer = { name: String(opts.mcpServer.name), source: String(opts.mcpServer.source) };
|
|
39
|
+
}
|
|
35
40
|
return msg;
|
|
36
41
|
}
|
|
37
42
|
|
|
@@ -49,6 +54,10 @@ function toCanUseToolOptions(msg, signal) {
|
|
|
49
54
|
if (msg.suppressAlwaysAllowRule === true) opts.suppressAlwaysAllowRule = true;
|
|
50
55
|
if (msg.defaultToNo === true) opts.defaultToNo = true;
|
|
51
56
|
if (msg.matchedAskRule) opts.matchedAskRule = typeof msg.matchedAskRule === "object" ? msg.matchedAskRule : {};
|
|
57
|
+
if (msg.mcpServer && typeof msg.mcpServer === "object"
|
|
58
|
+
&& typeof msg.mcpServer.name === "string" && typeof msg.mcpServer.source === "string") {
|
|
59
|
+
opts.mcpServer = { name: msg.mcpServer.name, source: msg.mcpServer.source };
|
|
60
|
+
}
|
|
52
61
|
return opts;
|
|
53
62
|
}
|
|
54
63
|
|
package/lib/yoke/interface.js
CHANGED
|
@@ -81,7 +81,13 @@ var TOOL_POLICIES = ["ask", "allow-all"];
|
|
|
81
81
|
*
|
|
82
82
|
* QueryHandle shape:
|
|
83
83
|
* [Symbol.asyncIterator]() - yields SDK events (raw in Phase 3, normalized later)
|
|
84
|
-
* .pushMessage(text, images, initiator) - initiator optional, per
|
|
84
|
+
* .pushMessage(text, images, initiator, messageId) - initiator optional, per
|
|
85
|
+
* turn; messageId optional: the id the console
|
|
86
|
+
* recorded for the message, which an adapter
|
|
87
|
+
* carries to its vendor where the vendor lets a
|
|
88
|
+
* client name a message (the Claude adapter sets
|
|
89
|
+
* the SDK message uuid) and otherwise reports back
|
|
90
|
+
* on the turn_start event (turnId, messageId)
|
|
85
91
|
* .setModel(model)
|
|
86
92
|
* .setEffort(effort) - Promise; settles once the running query has
|
|
87
93
|
* taken the change and rejects (with a message
|
package/package.json
CHANGED
|
@@ -297,7 +297,7 @@ function classifyRun(result, files, resultsByFile, totalTests, floor) {
|
|
|
297
297
|
reason: (
|
|
298
298
|
missingFiles.length + " test file(s) reported ZERO test results — " +
|
|
299
299
|
"treated as a truncated/incomplete run, not a pass, regardless of the overall exit code. This is " +
|
|
300
|
-
"exactly the failure class lr-795882 fixed (
|
|
300
|
+
"exactly the failure class lr-795882 fixed (lr-a7b03e): a file whose tests silently vanish " +
|
|
301
301
|
"while the overall run still exits 0.\n " + missingFiles.join("\n ")
|
|
302
302
|
),
|
|
303
303
|
};
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
// trailing JSON array specifically (the only valid JSON substring `npm pack
|
|
16
16
|
// --json` ever emits), rather than trusting the whole stdout to be clean.
|
|
17
17
|
|
|
18
|
+
const fs = require('fs');
|
|
19
|
+
const path = require('path');
|
|
18
20
|
const { execFileSync } = require('child_process');
|
|
21
|
+
const { createTreeHasher } = require('../lib/build-identity');
|
|
19
22
|
|
|
20
23
|
// Extracts the packed tarball filename from `npm pack --json`'s raw stdout.
|
|
21
24
|
// Exported (not just used internally) so tests can exercise the parsing
|
|
@@ -66,7 +69,48 @@ function packAndGetFilename() {
|
|
|
66
69
|
return extractTarballFilename(raw);
|
|
67
70
|
}
|
|
68
71
|
|
|
72
|
+
// A same-sha reinstall replaces the installed files with new inodes under a
|
|
73
|
+
// running daemon, so it can only do harm: the daemon is already running that
|
|
74
|
+
// build. True when the installed build has this tree's sha and the same files.
|
|
75
|
+
// `read` is injectable for tests; it must return { headSha, installedSha,
|
|
76
|
+
// repoHash, installedHash } and any of them may be null when unknown.
|
|
77
|
+
function installedMatchesTree(read) {
|
|
78
|
+
const s = read();
|
|
79
|
+
return !!(s.headSha && s.installedSha === s.headSha &&
|
|
80
|
+
s.repoHash && s.installedHash === s.repoHash);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readTreeState() {
|
|
84
|
+
const repoRoot = path.join(__dirname, '..');
|
|
85
|
+
const headSha = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: repoRoot, encoding: 'utf8' }).trim();
|
|
86
|
+
const globalRoot = execFileSync('npm', ['root', '-g'], { encoding: 'utf8' }).trim();
|
|
87
|
+
const installedRoot = path.join(globalRoot, '@clagentic', 'console');
|
|
88
|
+
const installedSha = JSON.parse(fs.readFileSync(path.join(installedRoot, 'lib', 'build-sha.json'), 'utf8')).sha;
|
|
89
|
+
return {
|
|
90
|
+
headSha,
|
|
91
|
+
installedSha,
|
|
92
|
+
repoHash: createTreeHasher(repoRoot).hash(),
|
|
93
|
+
installedHash: createTreeHasher(installedRoot).hash(),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Any failure to establish the match (nothing installed yet, unreadable
|
|
98
|
+
// tree) means "install", never "skip".
|
|
99
|
+
function shouldSkipInstall(read) {
|
|
100
|
+
try {
|
|
101
|
+
return installedMatchesTree(read || readTreeState);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.log(`[install-local-test] could not compare with the installed build (${err.message}); installing`);
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
69
108
|
function main() {
|
|
109
|
+
if (!process.argv.includes('--force') && shouldSkipInstall()) {
|
|
110
|
+
console.log('[install-local-test] ok: this build is already installed with identical files; nothing to do (--force reinstalls)');
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
70
114
|
let tarball;
|
|
71
115
|
try {
|
|
72
116
|
tarball = packAndGetFilename();
|
|
@@ -90,7 +134,7 @@ function main() {
|
|
|
90
134
|
console.log('[install-local-test] ok: installed');
|
|
91
135
|
}
|
|
92
136
|
|
|
93
|
-
module.exports = { extractTarballFilename };
|
|
137
|
+
module.exports = { extractTarballFilename, installedMatchesTree, shouldSkipInstall };
|
|
94
138
|
|
|
95
139
|
if (require.main === module) {
|
|
96
140
|
main();
|
package/scripts/postinstall.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
// postinstall.js — installs/updates the systemd service unit on Linux global npm installs.
|
|
5
|
+
// It never reads or writes Claude Code settings.
|
|
5
6
|
// Runs automatically after `npm install -g @clagentic/console`.
|
|
6
7
|
// Does nothing on non-Linux platforms, on non-global installs (a local `npm ci` /
|
|
7
8
|
// `npm install` in a dev checkout or worktree must never touch /etc/systemd or
|