@moxt-ai/mobius 0.0.103 → 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 +362 -1249
- 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 +8 -5
- package/dist/daemon-session-commands.d.ts.map +1 -1
- package/dist/daemon-session-commands.js +50 -31
- package/dist/daemon-session-commands.js.map +1 -1
- package/dist/daemon-turn-reconciliation.d.ts +7 -3
- package/dist/daemon-turn-reconciliation.d.ts.map +1 -1
- package/dist/daemon-turn-reconciliation.js +9 -3
- package/dist/daemon-turn-reconciliation.js.map +1 -1
- package/dist/index.js +359 -1239
- 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 -244
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +363 -1243
- 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,188 +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
|
-
const turn = new ActiveDaemonTurn(command, receipt.attemptId);
|
|
215
|
-
activeTurns.set(command.commandId, turn);
|
|
216
|
-
const activateAttempt = () => {
|
|
217
|
-
turn.accept();
|
|
218
|
-
if (trackActiveAttempt) {
|
|
219
|
-
activeAttemptIds.set(command.sessionId, receipt.attemptId);
|
|
220
|
-
}
|
|
221
|
-
};
|
|
222
|
-
try {
|
|
223
|
-
await execute(receipt.attemptId, activateAttempt, turn.signal, turn);
|
|
224
|
-
}
|
|
225
|
-
finally {
|
|
226
|
-
activeTurns.delete(command.commandId);
|
|
227
|
-
if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
|
|
228
|
-
activeAttemptIds.delete(command.sessionId);
|
|
229
|
-
}
|
|
230
|
-
turn.finish();
|
|
231
|
-
}
|
|
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
|
+
});
|
|
232
213
|
};
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (kind === SESSION_CANCEL_KIND) {
|
|
237
|
-
const cancellation = message;
|
|
238
|
-
if (cancellation.sessionId !== delivery.sessionId) {
|
|
239
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
240
|
-
}
|
|
241
|
-
const turn = activeTurns.get(cancellation.commandId);
|
|
242
|
-
if (turn === undefined || !turn.matches(cancellation)) {
|
|
243
|
-
settleAbandonedTurn(publisher, outbox, audit, cancellation);
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (!turn.requestCancellation()) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
audit.record({
|
|
250
|
-
commandId: cancellation.commandId,
|
|
251
|
-
event: "session_cancellation_requested",
|
|
252
|
-
sessionId: cancellation.sessionId,
|
|
253
|
-
});
|
|
254
|
-
await sessions.cancelPrompt(cancellation.sessionId);
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
if (kind === SESSION_CONFIGURE_KIND) {
|
|
258
|
-
const command = message;
|
|
259
|
-
if (command.sessionId !== delivery.sessionId) {
|
|
260
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
261
|
-
}
|
|
262
|
-
await executeSessionConfigure(publisher, socket, command, config, directories, audit, sessions, connectionController.signal);
|
|
263
|
-
return;
|
|
214
|
+
const waitForSessionAvailability = async (command, waitSignal) => {
|
|
215
|
+
if (command.disposition === SessionPromptDisposition.Steer) {
|
|
216
|
+
return "available";
|
|
264
217
|
}
|
|
265
|
-
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
commandId: command.interactionId,
|
|
274
|
-
event: "session_permission_resolved",
|
|
275
|
-
sessionId: command.sessionId,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
catch (error) {
|
|
279
|
-
reportOperationFailure(socket, command.interactionId, command.sessionId, error);
|
|
280
|
-
}
|
|
281
|
-
return;
|
|
282
|
-
}
|
|
283
|
-
if (kind === SESSION_ELICITATION_RESPOND_KIND) {
|
|
284
|
-
const command = message;
|
|
285
|
-
if (command.sessionId !== delivery.sessionId) {
|
|
286
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
287
|
-
}
|
|
288
|
-
try {
|
|
289
|
-
await sessions.respondElicitation(command);
|
|
290
|
-
audit.record({
|
|
291
|
-
commandId: command.interactionId,
|
|
292
|
-
event: "session_elicitation_resolved",
|
|
293
|
-
sessionId: command.sessionId,
|
|
294
|
-
});
|
|
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";
|
|
295
226
|
}
|
|
296
|
-
|
|
297
|
-
|
|
227
|
+
if (command.disposition !== SessionPromptDisposition.Queue) {
|
|
228
|
+
return "busy";
|
|
298
229
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if (kind === SESSION_PROMPT_KIND) {
|
|
302
|
-
const command = message;
|
|
303
|
-
await processDeliveredPrompt(delivery, command, command.disposition !== SessionPromptDisposition.Steer, (attemptId, activateAttempt, executionSignal, turn) => executePrompt(outbox, publisher, command, config, directories, audit, sessions, attemptId, activateAttempt, timer, executionSignal, turn.recordText));
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
307
|
-
};
|
|
308
|
-
const processRuntimeDelivery = (delivery, state) => {
|
|
309
|
-
if (state === "processed" || processingDeliveryIds.has(delivery.deliveryId)) {
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
processingDeliveryIds.add(delivery.deliveryId);
|
|
313
|
-
void processDeliveredPayload(delivery)
|
|
314
|
-
.then(() => {
|
|
315
|
-
outbox.markRuntimeDeliveryProcessed(delivery.deliveryId, delivery.sessionId);
|
|
316
|
-
})
|
|
317
|
-
.catch((error) => {
|
|
318
|
-
if (connectionController.signal.aborted) {
|
|
319
|
-
return;
|
|
230
|
+
if (first.command.commandId !== command.targetCommandId) {
|
|
231
|
+
return "queue-target-unavailable";
|
|
320
232
|
}
|
|
321
|
-
|
|
322
|
-
failAndClose(new Error("Runtime delivery processing failed", { cause: error }), 4008, "Invalid Runtime delivery", "delivery");
|
|
323
|
-
})
|
|
324
|
-
.finally(() => processingDeliveryIds.delete(delivery.deliveryId));
|
|
325
|
-
};
|
|
326
|
-
const receiveRuntimeDelivery = (delivery) => {
|
|
327
|
-
const payload = decodeServiceToDaemonMessage(delivery.payload);
|
|
328
|
-
const payloadKind = payload.kind;
|
|
329
|
-
let payloadSessionId = "";
|
|
330
|
-
if (payloadKind === SESSION_CANCEL_KIND) {
|
|
331
|
-
payloadSessionId = payload.sessionId;
|
|
332
|
-
}
|
|
333
|
-
else if (payloadKind === SESSION_CONFIGURE_KIND) {
|
|
334
|
-
payloadSessionId = payload.sessionId;
|
|
335
|
-
}
|
|
336
|
-
else if (payloadKind === SESSION_PERMISSION_RESPOND_KIND) {
|
|
337
|
-
payloadSessionId = payload.sessionId;
|
|
338
|
-
}
|
|
339
|
-
else if (payloadKind === SESSION_ELICITATION_RESPOND_KIND) {
|
|
340
|
-
payloadSessionId = payload.sessionId;
|
|
341
|
-
}
|
|
342
|
-
else if (payloadKind === SESSION_PROMPT_KIND) {
|
|
343
|
-
payloadSessionId = payload.sessionId;
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
throw new Error("Runtime delivery contains an unsupported protocol message");
|
|
347
|
-
}
|
|
348
|
-
if (payloadSessionId !== delivery.sessionId) {
|
|
349
|
-
throw new Error("Runtime delivery Session identity does not match its payload");
|
|
350
|
-
}
|
|
351
|
-
const stored = outbox.claimRuntimeDelivery(delivery);
|
|
352
|
-
send(socket, {
|
|
353
|
-
deliveryId: delivery.deliveryId,
|
|
354
|
-
kind: RUNTIME_DELIVERY_RECEIVED_KIND,
|
|
355
|
-
sessionId: delivery.sessionId,
|
|
356
|
-
});
|
|
357
|
-
processRuntimeDelivery(delivery, stored.state);
|
|
358
|
-
};
|
|
359
|
-
const resumeRuntimeDeliveries = () => {
|
|
360
|
-
for (const stored of outbox.runtimeDeliveries()) {
|
|
361
|
-
const delivery = {
|
|
362
|
-
deliveryId: stored.deliveryId,
|
|
363
|
-
kind: RUNTIME_DELIVERY_KIND,
|
|
364
|
-
payload: stored.payload,
|
|
365
|
-
sessionId: stored.sessionId,
|
|
366
|
-
};
|
|
367
|
-
if (stored.state !== "relay_committed") {
|
|
368
|
-
send(socket, {
|
|
369
|
-
deliveryId: stored.deliveryId,
|
|
370
|
-
kind: RUNTIME_DELIVERY_RECEIVED_KIND,
|
|
371
|
-
sessionId: stored.sessionId,
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
processRuntimeDelivery(delivery, stored.state);
|
|
233
|
+
await waitForTurnCompletion(first, waitSignal);
|
|
375
234
|
}
|
|
376
235
|
};
|
|
377
236
|
const connectionLiveness = new RelayConnectionLiveness(timer, {
|
|
@@ -426,40 +285,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
426
285
|
try {
|
|
427
286
|
const message = decodeServiceToDaemonMessage(encoded);
|
|
428
287
|
const kind = message.kind;
|
|
429
|
-
if (kind === RUNTIME_DELIVERY_COMMITTED_KIND) {
|
|
430
|
-
const committed = message;
|
|
431
|
-
if (!outbox.markRuntimeDeliveryCommitted(committed.deliveryId, committed.sessionId)) {
|
|
432
|
-
console.warn("Mobius daemon ignored confirmation for an unknown Runtime delivery");
|
|
433
|
-
}
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if (kind === RUNTIME_DELIVERY_KIND) {
|
|
437
|
-
receiveRuntimeDelivery(message);
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
if (kind === SESSION_EVENT_ACK_KIND) {
|
|
441
|
-
publisher.acknowledge(message);
|
|
442
|
-
return;
|
|
443
|
-
}
|
|
444
|
-
if (kind === SESSION_EVENT_DEFERRED_KIND) {
|
|
445
|
-
publisher.defer(message);
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
if (kind === SESSION_EVENT_REJECTED_KIND) {
|
|
449
|
-
const rejection = message;
|
|
450
|
-
if (publisher.quarantine(rejection)) {
|
|
451
|
-
audit.record({
|
|
452
|
-
commandId: rejection.eventId,
|
|
453
|
-
details: { code: rejection.code },
|
|
454
|
-
event: "session_event_rejected",
|
|
455
|
-
sessionId: rejection.sessionId,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
console.warn("Mobius daemon ignored a rejection for an unknown session event");
|
|
460
|
-
}
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
288
|
if (kind === SESSION_LIVE_HISTORY_LOAD_KIND) {
|
|
464
289
|
const command = decodeSessionLiveHistoryLoad(encoded);
|
|
465
290
|
void executeSessionLiveHistoryLoad(socket, command, config, directories, audit, sessions, connectionController.signal);
|
|
@@ -819,7 +644,7 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
819
644
|
const cancellation = message;
|
|
820
645
|
const turn = activeTurns.get(cancellation.commandId);
|
|
821
646
|
if (turn === undefined || !turn.matches(cancellation)) {
|
|
822
|
-
settleAbandonedTurn(publisher,
|
|
647
|
+
settleAbandonedTurn(publisher, operations, audit, cancellation);
|
|
823
648
|
return;
|
|
824
649
|
}
|
|
825
650
|
if (!turn.requestCancellation()) {
|
|
@@ -903,35 +728,23 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
903
728
|
if (activeTurns.has(command.commandId)) {
|
|
904
729
|
return;
|
|
905
730
|
}
|
|
906
|
-
const receipt =
|
|
731
|
+
const receipt = operations.claimExecution(command.commandId, command.sessionId, encoded);
|
|
907
732
|
if (receipt.kind === "duplicate") {
|
|
908
733
|
return;
|
|
909
734
|
}
|
|
910
735
|
const turn = new ActiveDaemonTurn(command, receipt.attemptId);
|
|
911
736
|
activeTurns.set(command.commandId, turn);
|
|
912
|
-
void executePrompt(
|
|
913
|
-
turn.accept();
|
|
914
|
-
if (command.disposition !== SessionPromptDisposition.Steer) {
|
|
915
|
-
activeAttemptIds.set(command.sessionId, receipt.attemptId);
|
|
916
|
-
}
|
|
917
|
-
}, 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)
|
|
918
738
|
.catch((error) => {
|
|
919
739
|
console.error("Mobius daemon turn failed", error);
|
|
920
740
|
})
|
|
921
741
|
.finally(() => {
|
|
922
742
|
activeTurns.delete(command.commandId);
|
|
923
|
-
if (activeAttemptIds.get(command.sessionId) === receipt.attemptId) {
|
|
924
|
-
activeAttemptIds.delete(command.sessionId);
|
|
925
|
-
}
|
|
926
743
|
turn.finish();
|
|
927
744
|
});
|
|
928
745
|
}
|
|
929
746
|
catch (error) {
|
|
930
747
|
console.error("Mobius daemon rejected a message", error);
|
|
931
|
-
if (error instanceof RuntimeDeliveryInboxCapacityError) {
|
|
932
|
-
failAndClose(error, 4013, "Runtime delivery queue full", "delivery_backpressure");
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
748
|
failAndClose(new Error("Relay sent an invalid protocol message", { cause: error }), 4008, "Invalid protocol message", "protocol");
|
|
936
749
|
}
|
|
937
750
|
};
|
|
@@ -943,7 +756,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
943
756
|
return;
|
|
944
757
|
}
|
|
945
758
|
publisher.connect(socket);
|
|
946
|
-
resumeRuntimeDeliveries();
|
|
947
759
|
}, (error) => {
|
|
948
760
|
if (finished) {
|
|
949
761
|
return;
|
|
@@ -959,7 +771,6 @@ async function runRelayConnection(config, directories, audit, sessions, installa
|
|
|
959
771
|
turn.abortDaemon();
|
|
960
772
|
}
|
|
961
773
|
publisher.connect(socket);
|
|
962
|
-
resumeRuntimeDeliveries();
|
|
963
774
|
return;
|
|
964
775
|
}
|
|
965
776
|
failAndClose(new Error("Active Agent turn reconciliation failed", { cause: error }), ACTIVE_TURN_RECONCILIATION_CLOSE_CODE, "Active Agent turn reconciliation failed", "reconciliation");
|
|
@@ -991,17 +802,11 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
991
802
|
stateDirectory,
|
|
992
803
|
});
|
|
993
804
|
const sessionStore = new MemoryAcpSessionStore();
|
|
994
|
-
const
|
|
995
|
-
const publisher = new DaemonSessionEventPublisher(
|
|
805
|
+
const operations = new DaemonOperationState();
|
|
806
|
+
const publisher = new DaemonSessionEventPublisher();
|
|
996
807
|
const activeTurns = new Map();
|
|
997
|
-
const activeAttemptIds = new Map();
|
|
998
808
|
const recordSessionEvent = (sessionId, event) => {
|
|
999
|
-
|
|
1000
|
-
if (attemptId === undefined) {
|
|
1001
|
-
publisher.recordRuntime(sessionId, event);
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
|
-
publisher.recordAttempt(sessionId, event, attemptId);
|
|
809
|
+
publisher.publish(sessionId, event);
|
|
1005
810
|
};
|
|
1006
811
|
const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
|
|
1007
812
|
read: async (options, nativeSessionId) => options.agent.id === "codex"
|
|
@@ -1079,7 +884,7 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
1079
884
|
while (!signal.aborted) {
|
|
1080
885
|
connectionEpoch += 1;
|
|
1081
886
|
try {
|
|
1082
|
-
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions,
|
|
887
|
+
await runRelayConnection(config, directories, audit, sessions, installations, installationObserver, nativeSessions, operations, publisher, activeTurns, connectionEpoch, diagnostics, () => {
|
|
1083
888
|
if (catalogPublished) {
|
|
1084
889
|
options.onConnectionStatus?.("online");
|
|
1085
890
|
}
|
|
@@ -1125,7 +930,7 @@ export async function runDaemon(config, audit, signal, timer = systemDaemonTimer
|
|
|
1125
930
|
publisher.close();
|
|
1126
931
|
}
|
|
1127
932
|
finally {
|
|
1128
|
-
|
|
933
|
+
operations.close();
|
|
1129
934
|
}
|
|
1130
935
|
}
|
|
1131
936
|
}
|