@moxt-ai/mobius 0.0.104 → 0.0.106
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/dist/acp/process-session.d.ts.map +1 -1
- package/dist/acp/process-session.js +11 -6
- package/dist/acp/process-session.js.map +1 -1
- package/dist/acp/session-manager.d.ts +2 -0
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +5 -0
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/acp/session-store.d.ts +5 -1
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +6 -1
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +349 -1263
- package/dist/cli.js.map +4 -4
- package/dist/daemon-manager.d.ts.map +1 -1
- package/dist/daemon-manager.js +2 -9
- package/dist/daemon-manager.js.map +1 -1
- package/dist/daemon-session-commands.d.ts +6 -6
- package/dist/daemon-session-commands.d.ts.map +1 -1
- package/dist/daemon-session-commands.js +43 -30
- package/dist/daemon-session-commands.js.map +1 -1
- package/dist/daemon-turn-reconciliation.d.ts +3 -2
- package/dist/daemon-turn-reconciliation.d.ts.map +1 -1
- package/dist/daemon-turn-reconciliation.js +8 -3
- package/dist/daemon-turn-reconciliation.js.map +1 -1
- package/dist/index.js +346 -1253
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/service.d.ts +2 -1
- package/dist/native-sessions/service.d.ts.map +1 -1
- package/dist/native-sessions/service.js +27 -0
- package/dist/native-sessions/service.js.map +1 -1
- package/dist/relay-connection/coalescing-narration-publisher.d.ts +3 -3
- package/dist/relay-connection/coalescing-narration-publisher.js +3 -3
- package/dist/relay-connection/coalescing-text-publisher.d.ts +3 -4
- package/dist/relay-connection/coalescing-text-publisher.d.ts.map +1 -1
- package/dist/relay-connection/coalescing-text-publisher.js +3 -4
- package/dist/relay-connection/coalescing-text-publisher.js.map +1 -1
- package/dist/relay-connection/daemon-operation-state.d.ts +18 -0
- package/dist/relay-connection/daemon-operation-state.d.ts.map +1 -0
- package/dist/relay-connection/daemon-operation-state.js +69 -0
- package/dist/relay-connection/daemon-operation-state.js.map +1 -0
- package/dist/relay-connection/session-event-publisher.d.ts +3 -9
- package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
- package/dist/relay-connection/session-event-publisher.js +30 -224
- package/dist/relay-connection/session-event-publisher.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +49 -254
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +350 -1257
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
- package/dist/relay-connection/session-event-outbox.d.ts +0 -61
- package/dist/relay-connection/session-event-outbox.d.ts.map +0 -1
- package/dist/relay-connection/session-event-outbox.js +0 -546
- package/dist/relay-connection/session-event-outbox.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-event-publisher.js","sourceRoot":"","sources":["../../src/relay-connection/session-event-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,
|
|
1
|
+
{"version":3,"file":"session-event-publisher.js","sourceRoot":"","sources":["../../src/relay-connection/session-event-publisher.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,4BAA4B,EAC5B,0BAA0B,EAE1B,kBAAkB,GACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEnC,MAAM,6BAA6B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEvD,6GAA6G;AAC7G,MAAM,OAAO,2BAA2B;IACpC,OAAO,GAAqB,IAAI,CAAC;IACjC,aAAa,GAAG,KAAK,CAAC;IAEb,OAAO,GAAG,CAAC,MAAiB,EAAQ,EAAE;QAC3C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;IAC/B,CAAC,CAAC;IAEO,UAAU,GAAG,CAAC,MAAiB,EAAQ,EAAE;QAC9C,IAAI,IAAI,CAAC,OAAO,KAAK,MAAM,EAAE,CAAC;YAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACxB,CAAC;IACL,CAAC,CAAC;IAEO,OAAO,GAAG,CAAC,SAAiB,EAAE,KAA2B,EAAQ,EAAE;QACxE,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;YAC1D,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO;QACX,CAAC;QACD,IAAI,MAAM,CAAC,cAAc,IAAI,6BAA6B,EAAE,CAAC;YACzD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;YAC9C,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO;QACX,CAAC;QACD,IAAI,CAAC;YACD,MAAM,CAAC,IAAI,CACP,4BAA4B,CAAC;gBACzB,IAAI,EAAE,kBAAkB;gBACxB,OAAO,EAAE,0BAA0B,CAAC,KAAK,CAAC;gBAC1C,SAAS;aACZ,CAAC,CACL,CAAC;QACN,CAAC;QAAC,MAAM,CAAC;YACL,IAAI,CAAC,WAAW,EAAE,CAAC;QACvB,CAAC;IACL,CAAC,CAAC;IAEO,KAAK,GAAG,GAAS,EAAE;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACxB,CAAC,CAAC;IAEO,WAAW,GAAG,GAAS,EAAE;QAC9B,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,OAAO;QACX,CAAC;QACD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,2EAA2E,CAAC,CAAC;IAC9F,CAAC,CAAC;CACL"}
|
package/dist/run-daemon.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-daemon.d.ts","sourceRoot":"","sources":["../src/run-daemon.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run-daemon.d.ts","sourceRoot":"","sources":["../src/run-daemon.ts"],"names":[],"mappings":"AAiDA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,KAAK,YAAY,EAA6C,MAAM,aAAa,CAAC;AA2B3F,OAAO,EAAE,KAAK,WAAW,EAAqB,MAAM,6BAA6B,CAAC;AAsFlF,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,GAAG,cAAc,KAAK,IAAI,CAAC;IAC1E,QAAQ,CAAC,8BAA8B,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;CAC3G;AAi9BD,wBAAsB,SAAS,CAC3B,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,WAAW,EACnB,KAAK,GAAE,WAA+B,EACtC,OAAO,GAAE,gBAAqB,GAC/B,OAAO,CAAC,IAAI,CAAC,CA0Lf"}
|
package/dist/run-daemon.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { styleText } from "node:util";
|
|
3
|
-
import { AGENT_CATALOG_REFRESH_FAILED_KIND, AGENT_CATALOG_REFRESH_KIND, AGENT_CATALOG_REFRESHED_KIND, AGENT_INSTALL_CANCEL_KIND, AGENT_INSTALL_REQUEST_KIND, AGENT_SETTINGS_DISCOVER_KIND, AGENT_SETTINGS_DISCOVERY_FAILED_KIND, decodeServiceToDaemonMessage, decodeSessionLiveHistoryLoad, decodeSessionLiveHistoryPageLoad, FILE_FAILED_KIND, FILE_READ_KIND, NATIVE_SESSION_CANCEL_KIND, NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_TURN_FORK_KIND,
|
|
3
|
+
import { AGENT_CATALOG_REFRESH_FAILED_KIND, AGENT_CATALOG_REFRESH_KIND, AGENT_CATALOG_REFRESHED_KIND, AGENT_INSTALL_CANCEL_KIND, AGENT_INSTALL_REQUEST_KIND, AGENT_SETTINGS_DISCOVER_KIND, AGENT_SETTINGS_DISCOVERY_FAILED_KIND, decodeServiceToDaemonMessage, decodeSessionLiveHistoryLoad, decodeSessionLiveHistoryPageLoad, FILE_FAILED_KIND, FILE_READ_KIND, NATIVE_SESSION_CANCEL_KIND, NATIVE_SESSION_REQUEST_KIND, NATIVE_SESSION_TURN_FORK_KIND, RUNTIME_HEARTBEAT_ACK_KIND, RUNTIME_LIVENESS_READY_KIND, SESSION_CANCEL_KIND, SESSION_CONFIGURE_KIND, SESSION_ELICITATION_RESPOND_KIND, SESSION_LIVE_HISTORY_LOAD_KIND, SESSION_LIVE_HISTORY_PAGE_LOAD_KIND, SESSION_PERMISSION_RESPOND_KIND, SESSION_PREPARE_KIND, SESSION_PROMPT_KIND, SessionPromptDisposition, WORKSPACE_LIST_KIND, } from "@moxt-ai/mobius-protocol";
|
|
4
4
|
import { WebSocket } from "undici";
|
|
5
5
|
import { AcpConfigurationValueUnavailableError, AcpExecutionError, AcpSessionManager } from "./acp/session-manager.js";
|
|
6
6
|
import { MemoryAcpSessionStore } from "./acp/session-store.js";
|
|
@@ -15,16 +15,16 @@ import { WorkspaceDirectoryService } from "./authorization/workspace-directory.j
|
|
|
15
15
|
import { DaemonLocalContext, withDaemonEnvironment } from "./config.js";
|
|
16
16
|
import { DaemonDiagnosticLog } from "./daemon-diagnostic-log.js";
|
|
17
17
|
import { AuditInstallationEvents, DaemonAcpObserver, DaemonInstallationObserver } from "./daemon-observers.js";
|
|
18
|
-
import { agentSettingsFailureDetails, executePrompt, executeSessionConfigure, executeSessionLiveHistoryLoad, executeSessionLiveHistoryPageLoad, executeSessionPrepare, executeWorkspaceList, operationErrorCode, operationErrorMessage,
|
|
18
|
+
import { agentSettingsFailureDetails, executePrompt, executeSessionConfigure, executeSessionLiveHistoryLoad, executeSessionLiveHistoryPageLoad, executeSessionPrepare, executeWorkspaceList, operationErrorCode, operationErrorMessage, reportOperationFailure, send, settleAbandonedTurn, } from "./daemon-session-commands.js";
|
|
19
19
|
import { ActiveDaemonTurn, ActiveTurnReconciliationError, reconcileActiveTurns } from "./daemon-turn-reconciliation.js";
|
|
20
20
|
import { readCodexFullHistory } from "./native-sessions/codex-history.js";
|
|
21
21
|
import { NativeSessionService } from "./native-sessions/service.js";
|
|
22
22
|
import { revalidateExecutable } from "./process/executable.js";
|
|
23
23
|
import { connectRelay } from "./relay-connection/connect.js";
|
|
24
|
+
import { DaemonOperationState } from "./relay-connection/daemon-operation-state.js";
|
|
24
25
|
import { RelayConnectionDiagnostics } from "./relay-connection/diagnostics.js";
|
|
25
26
|
import { RelayConnectionLiveness } from "./relay-connection/liveness.js";
|
|
26
27
|
import { isRuntimeRelayRevocation, RuntimeRelayRevokedError } from "./relay-connection/runtime-revocation.js";
|
|
27
|
-
import { RuntimeDeliveryInboxCapacityError, SessionEventOutbox } from "./relay-connection/session-event-outbox.js";
|
|
28
28
|
import { DaemonSessionEventPublisher } from "./relay-connection/session-event-publisher.js";
|
|
29
29
|
import { systemDaemonTimer } from "./relay-connection/timer.js";
|
|
30
30
|
const RELAY_RECONNECT_DELAY_MILLISECONDS = 500;
|
|
@@ -137,9 +137,8 @@ async function refreshAgentCatalog(config, resolveEnvironment, signal) {
|
|
|
137
137
|
throw error;
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions,
|
|
140
|
+
async function runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, operations, publisher, activeTurns, connectionEpoch, diagnostics, onConnected, signal, timer, resolveAgentCatalogEnvironment) {
|
|
141
141
|
const relayUrl = new URL(config.relayUrl);
|
|
142
|
-
relayUrl.searchParams.set("deliveryReceipts", "1");
|
|
143
142
|
relayUrl.searchParams.set("liveness", "1");
|
|
144
143
|
const socket = await connectRelay(relayUrl, signal);
|
|
145
144
|
const reconnectingTurns = [...activeTurns.values()];
|
|
@@ -190,197 +189,48 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
190
189
|
closeRelaySocket(socket, code, reason);
|
|
191
190
|
rejectConnection(failure);
|
|
192
191
|
};
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
reportFailure(publisher, command, "agent_execution_interrupted", "The local Agent execution was interrupted before it completed", receipt.attemptId);
|
|
215
|
-
outbox.transitionExecution(command.commandId, "failed");
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
if (receipt.state !== "dispatching") {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const turn = new ActiveDaemonTurn(command, receipt.attemptId);
|
|
223
|
-
activeTurns.set(command.commandId, turn);
|
|
224
|
-
const activateAttempt = () => {
|
|
225
|
-
const stream = turn.accept();
|
|
226
|
-
if (trackActiveAttempt) {
|
|
227
|
-
activeAttemptIds.set(command.sessionId, receipt.attemptId);
|
|
228
|
-
}
|
|
229
|
-
return stream;
|
|
230
|
-
};
|
|
231
|
-
try {
|
|
232
|
-
await execute(receipt.attemptId, activateAttempt, turn.signal, turn);
|
|
233
|
-
}
|
|
234
|
-
finally {
|
|
235
|
-
activeTurns.delete(command.commandId);
|
|
236
|
-
if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
|
|
237
|
-
activeAttemptIds.delete(command.sessionId);
|
|
238
|
-
}
|
|
239
|
-
turn.finish();
|
|
240
|
-
}
|
|
192
|
+
const waitForTurnCompletion = (turn, waitSignal) => {
|
|
193
|
+
waitSignal.throwIfAborted();
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
let settled = false;
|
|
196
|
+
const finish = (result) => {
|
|
197
|
+
if (settled) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
settled = true;
|
|
201
|
+
waitSignal.removeEventListener("abort", onAbort);
|
|
202
|
+
if (result.kind === "completed") {
|
|
203
|
+
resolve();
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
reject(result.error);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
const onAbort = () => finish({ error: waitSignal.reason, kind: "failed" });
|
|
210
|
+
waitSignal.addEventListener("abort", onAbort, { once: true });
|
|
211
|
+
void turn.completion.then(() => finish({ kind: "completed" }), (error) => finish({ error, kind: "failed" }));
|
|
212
|
+
});
|
|
241
213
|
};
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (kind === SESSION_CANCEL_KIND) {
|
|
246
|
-
const cancellation = message;
|
|
247
|
-
if (cancellation.sessionId !== delivery.sessionId) {
|
|
248
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
249
|
-
}
|
|
250
|
-
const turn = activeTurns.get(cancellation.commandId);
|
|
251
|
-
if (turn === undefined || !turn.matches(cancellation)) {
|
|
252
|
-
settleAbandonedTurn(publisher, outbox, audit, cancellation);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
if (!turn.requestCancellation()) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
audit.record({
|
|
259
|
-
commandId: cancellation.commandId,
|
|
260
|
-
event: "session_cancellation_requested",
|
|
261
|
-
sessionId: cancellation.sessionId,
|
|
262
|
-
});
|
|
263
|
-
await sessions.cancelPrompt(cancellation.sessionId);
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
if (kind === SESSION_CONFIGURE_KIND) {
|
|
267
|
-
const command = message;
|
|
268
|
-
if (command.sessionId !== delivery.sessionId) {
|
|
269
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
270
|
-
}
|
|
271
|
-
await executeSessionConfigure(publisher, socket, command, config, directories, audit, sessions, connectionController.signal);
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
if (kind === SESSION_PERMISSION_RESPOND_KIND) {
|
|
275
|
-
const command = message;
|
|
276
|
-
if (command.sessionId !== delivery.sessionId) {
|
|
277
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
278
|
-
}
|
|
279
|
-
try {
|
|
280
|
-
await sessions.respondPermission(command);
|
|
281
|
-
audit.record({
|
|
282
|
-
commandId: command.interactionId,
|
|
283
|
-
event: "session_permission_resolved",
|
|
284
|
-
sessionId: command.sessionId,
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
catch (error) {
|
|
288
|
-
reportOperationFailure(socket, command.interactionId, command.sessionId, error);
|
|
289
|
-
}
|
|
290
|
-
return;
|
|
214
|
+
const waitForSessionAvailability = async (command, waitSignal) => {
|
|
215
|
+
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
216
|
+
return "available";
|
|
291
217
|
}
|
|
292
|
-
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
commandId: command.interactionId,
|
|
301
|
-
event: "session_elicitation_resolved",
|
|
302
|
-
sessionId: command.sessionId,
|
|
303
|
-
});
|
|
218
|
+
for (;;) {
|
|
219
|
+
const first = [...activeTurns.values()].find((turn) => turn.command.sessionId === command.sessionId &&
|
|
220
|
+
turn.command.disposition !== SessionPromptDisposition.Steer);
|
|
221
|
+
if (first === undefined || first.command.commandId === command.commandId) {
|
|
222
|
+
return command.disposition !== SessionPromptDisposition.Queue ||
|
|
223
|
+
operations.isTerminalExecution(command.targetCommandId, command.sessionId)
|
|
224
|
+
? "available"
|
|
225
|
+
: "queue-target-unavailable";
|
|
304
226
|
}
|
|
305
|
-
|
|
306
|
-
|
|
227
|
+
if (command.disposition !== SessionPromptDisposition.Queue) {
|
|
228
|
+
return "busy";
|
|
307
229
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (kind === SESSION_PROMPT_KIND) {
|
|
311
|
-
const command = message;
|
|
312
|
-
await processDeliveredPrompt(delivery, command, command.disposition !== SessionPromptDisposition.Steer, (attemptId, activateAttempt, executionSignal, turn) => executePrompt(outbox, publisher, command, config, directories, audit, sessions, attemptId, activateAttempt, () => sessionAvailable(command), timer, executionSignal, turn.recordText));
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
316
|
-
};
|
|
317
|
-
const processRuntimeDelivery = (delivery, state) => {
|
|
318
|
-
if (state === "processed" || processingDeliveryIds.has(delivery.deliveryId)) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
processingDeliveryIds.add(delivery.deliveryId);
|
|
322
|
-
void processDeliveredPayload(delivery)
|
|
323
|
-
.then(() => {
|
|
324
|
-
outbox.markRuntimeDeliveryProcessed(delivery.deliveryId, delivery.sessionId);
|
|
325
|
-
})
|
|
326
|
-
.catch((error) => {
|
|
327
|
-
if (connectionController.signal.aborted) {
|
|
328
|
-
return;
|
|
230
|
+
if (first.command.commandId !== command.targetCommandId) {
|
|
231
|
+
return "queue-target-unavailable";
|
|
329
232
|
}
|
|
330
|
-
|
|
331
|
-
failAndClose(new Error("Runtime delivery processing failed", { cause: error }), 4008, "Invalid Runtime delivery", "delivery");
|
|
332
|
-
})
|
|
333
|
-
.finally(() => processingDeliveryIds.delete(delivery.deliveryId));
|
|
334
|
-
};
|
|
335
|
-
const receiveRuntimeDelivery = (delivery) => {
|
|
336
|
-
const payload = decodeServiceToDaemonMessage(delivery.payload);
|
|
337
|
-
const payloadKind = payload.kind;
|
|
338
|
-
let payloadSessionId = "";
|
|
339
|
-
if (payloadKind === SESSION_CANCEL_KIND) {
|
|
340
|
-
payloadSessionId = payload.sessionId;
|
|
341
|
-
}
|
|
342
|
-
else if (payloadKind === SESSION_CONFIGURE_KIND) {
|
|
343
|
-
payloadSessionId = payload.sessionId;
|
|
344
|
-
}
|
|
345
|
-
else if (payloadKind === SESSION_PERMISSION_RESPOND_KIND) {
|
|
346
|
-
payloadSessionId = payload.sessionId;
|
|
347
|
-
}
|
|
348
|
-
else if (payloadKind === SESSION_ELICITATION_RESPOND_KIND) {
|
|
349
|
-
payloadSessionId = payload.sessionId;
|
|
350
|
-
}
|
|
351
|
-
else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
352
|
-
payloadSessionId = payload.sessionId;
|
|
353
|
-
}
|
|
354
|
-
else {
|
|
355
|
-
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
356
|
-
}
|
|
357
|
-
if (payloadSessionId !== delivery.sessionId) {
|
|
358
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
359
|
-
}
|
|
360
|
-
const stored = outbox.claimRuntimeDelivery(delivery);
|
|
361
|
-
send(socket, {
|
|
362
|
-
deliveryId: delivery.deliveryId,
|
|
363
|
-
kind: RUNTIME_DELIVERY_RECEIVED_KIND,
|
|
364
|
-
sessionId: delivery.sessionId,
|
|
365
|
-
});
|
|
366
|
-
processRuntimeDelivery(delivery, stored.state);
|
|
367
|
-
};
|
|
368
|
-
const resumeRuntimeDeliveries = () => {
|
|
369
|
-
for (const stored of outbox.runtimeDeliveries()) {
|
|
370
|
-
const delivery = {
|
|
371
|
-
deliveryId: stored.deliveryId,
|
|
372
|
-
kind: RUNTIME_DELIVERY_KIND,
|
|
373
|
-
payload: stored.payload,
|
|
374
|
-
sessionId: stored.sessionId,
|
|
375
|
-
};
|
|
376
|
-
if (stored.state !== "relay_committed") {
|
|
377
|
-
send(socket, {
|
|
378
|
-
deliveryId: stored.deliveryId,
|
|
379
|
-
kind: RUNTIME_DELIVERY_RECEIVED_KIND,
|
|
380
|
-
sessionId: stored.sessionId,
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
processRuntimeDelivery(delivery, stored.state);
|
|
233
|
+
await waitForTurnCompletion(first, waitSignal);
|
|
384
234
|
}
|
|
385
235
|
};
|
|
386
236
|
const connectionLiveness = new RelayConnectionLiveness(timer, {
|
|
@@ -435,40 +285,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
435
285
|
try {
|
|
436
286
|
const message = decodeServiceToDaemonMessage(encoded);
|
|
437
287
|
const kind = message.kind;
|
|
438
|
-
if (kind === RUNTIME_DELIVERY_COMMITTED_KIND) {
|
|
439
|
-
const committed = message;
|
|
440
|
-
if (!outbox.markRuntimeDeliveryCommitted(committed.deliveryId, committed.sessionId)) {
|
|
441
|
-
console.warn("Mobius daemon ignored confirmation for an unknown Runtime delivery");
|
|
442
|
-
}
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
if (kind === RUNTIME_DELIVERY_KIND) {
|
|
446
|
-
receiveRuntimeDelivery(message);
|
|
447
|
-
return;
|
|
448
|
-
}
|
|
449
|
-
if (kind === SESSION_EVENT_ACK_KIND) {
|
|
450
|
-
publisher.acknowledge(message);
|
|
451
|
-
return;
|
|
452
|
-
}
|
|
453
|
-
if (kind === SESSION_EVENT_DEFERRED_KIND) {
|
|
454
|
-
publisher.defer(message);
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
457
|
-
if (kind === SESSION_EVENT_REJECTED_KIND) {
|
|
458
|
-
const rejection = message;
|
|
459
|
-
if (publisher.quarantine(rejection)) {
|
|
460
|
-
audit.record({
|
|
461
|
-
commandId: rejection.eventId,
|
|
462
|
-
details: { code: rejection.code },
|
|
463
|
-
event: "session_event_rejected",
|
|
464
|
-
sessionId: rejection.sessionId,
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
console.warn("Mobius daemon ignored a rejection for an unknown session event");
|
|
469
|
-
}
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
288
|
if (kind === SESSION_LIVE_HISTORY_LOAD_KIND) {
|
|
473
289
|
const command = decodeSessionLiveHistoryLoad(encoded);
|
|
474
290
|
void executeSessionLiveHistoryLoad(socket, command, config, directories, audit, sessions, connectionController.signal);
|
|
@@ -828,7 +644,7 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
828
644
|
const cancellation = message;
|
|
829
645
|
const turn = activeTurns.get(cancellation.commandId);
|
|
830
646
|
if (turn === undefined || !turn.matches(cancellation)) {
|
|
831
|
-
settleAbandonedTurn(publisher,
|
|
647
|
+
settleAbandonedTurn(publisher, operations, audit, cancellation);
|
|
832
648
|
return;
|
|
833
649
|
}
|
|
834
650
|
if (!turn.requestCancellation()) {
|
|
@@ -912,36 +728,23 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
912
728
|
if (activeTurns.has(command.commandId)) {
|
|
913
729
|
return;
|
|
914
730
|
}
|
|
915
|
-
const receipt =
|
|
731
|
+
const receipt = operations.claimExecution(command.commandId, command.sessionId, encoded);
|
|
916
732
|
if (receipt.kind === "duplicate") {
|
|
917
733
|
return;
|
|
918
734
|
}
|
|
919
735
|
const turn = new ActiveDaemonTurn(command, receipt.attemptId);
|
|
920
736
|
activeTurns.set(command.commandId, turn);
|
|
921
|
-
void executePrompt(
|
|
922
|
-
const stream = turn.accept();
|
|
923
|
-
if (command.disposition !== SessionPromptDisposition.Steer) {
|
|
924
|
-
activeAttemptIds.set(command.sessionId, receipt.attemptId);
|
|
925
|
-
}
|
|
926
|
-
return stream;
|
|
927
|
-
}, () => sessionAvailable(command), timer, turn.signal, turn.recordText)
|
|
737
|
+
void executePrompt(operations, publisher, command, config, directories, audit, sessions, receipt.attemptId, turn.accept, (waitSignal) => waitForSessionAvailability(command, waitSignal), timer, turn.signal, turn.recordText, turn.cancellationRequested)
|
|
928
738
|
.catch((error) => {
|
|
929
739
|
console.error("Mobius daemon turn failed", error);
|
|
930
740
|
})
|
|
931
741
|
.finally(() => {
|
|
932
742
|
activeTurns.delete(command.commandId);
|
|
933
|
-
if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
|
|
934
|
-
activeAttemptIds.delete(command.sessionId);
|
|
935
|
-
}
|
|
936
743
|
turn.finish();
|
|
937
744
|
});
|
|
938
745
|
}
|
|
939
746
|
catch (error) {
|
|
940
747
|
console.error("Mobius daemon rejected a message", error);
|
|
941
|
-
if (error instanceof RuntimeDeliveryInboxCapacityError) {
|
|
942
|
-
failAndClose(error, 4013, "Runtime delivery queue full", "delivery_backpressure");
|
|
943
|
-
return;
|
|
944
|
-
}
|
|
945
748
|
failAndClose(new Error("Relay sent an invalid protocol message", { cause: error }), 4008, "Invalid protocol message", "protocol");
|
|
946
749
|
}
|
|
947
750
|
};
|
|
@@ -953,7 +756,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
953
756
|
return;
|
|
954
757
|
}
|
|
955
758
|
publisher.connect(socket);
|
|
956
|
-
resumeRuntimeDeliveries();
|
|
957
759
|
}, (error) => {
|
|
958
760
|
if (finished) {
|
|
959
761
|
return;
|
|
@@ -969,7 +771,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
969
771
|
turn.abortDaemon();
|
|
970
772
|
}
|
|
971
773
|
publisher.connect(socket);
|
|
972
|
-
resumeRuntimeDeliveries();
|
|
973
774
|
return;
|
|
974
775
|
}
|
|
975
776
|
failAndClose(new Error("Active Agent turn reconciliation failed", { cause: error }), ACTIVE_TURN_RECONCILIATION_CLOSE_CODE, "Active Agent turn reconciliation failed", "reconciliation");
|
|
@@ -1001,17 +802,11 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
1001
802
|
stateDirectory,
|
|
1002
803
|
});
|
|
1003
804
|
const sessionStore = new MemoryAcpSessionStore();
|
|
1004
|
-
const
|
|
1005
|
-
const publisher = new DaemonSessionEventPublisher(
|
|
805
|
+
const operations = new DaemonOperationState();
|
|
806
|
+
const publisher = new DaemonSessionEventPublisher();
|
|
1006
807
|
const activeTurns = new Map();
|
|
1007
|
-
const activeAttemptIds = new Map();
|
|
1008
808
|
const recordSessionEvent = (sessionId, event) => {
|
|
1009
|
-
|
|
1010
|
-
if (attemptId === undefined) {
|
|
1011
|
-
publisher.recordRuntime(sessionId, event);
|
|
1012
|
-
return;
|
|
1013
|
-
}
|
|
1014
|
-
publisher.recordAttempt(sessionId, event, attemptId);
|
|
809
|
+
publisher.publish(sessionId, event);
|
|
1015
810
|
};
|
|
1016
811
|
const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
|
|
1017
812
|
read: async (options, nativeSessionId) => options.agent.id === "codex"
|
|
@@ -1089,7 +884,7 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
1089
884
|
while (!signal.aborted) {
|
|
1090
885
|
connectionEpoch += 1;
|
|
1091
886
|
try {
|
|
1092
|
-
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions,
|
|
887
|
+
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, operations, publisher, activeTurns, connectionEpoch, diagnostics, () => {
|
|
1093
888
|
if (catalogPublished) {
|
|
1094
889
|
options.onConnectionStatus?.("online");
|
|
1095
890
|
}
|
|
@@ -1135,7 +930,7 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
1135
930
|
publisher.close();
|
|
1136
931
|
}
|
|
1137
932
|
finally {
|
|
1138
|
-
|
|
933
|
+
operations.close();
|
|
1139
934
|
}
|
|
1140
935
|
}
|
|
1141
936
|
}
|