@moxt-ai/mobius 0.0.71 → 0.0.73
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/acp-error.d.ts +17 -0
- package/dist/acp/acp-error.d.ts.map +1 -0
- package/dist/acp/acp-error.js +28 -0
- package/dist/acp/acp-error.js.map +1 -0
- package/dist/acp/codex/agent.d.ts +26 -0
- package/dist/acp/codex/agent.d.ts.map +1 -0
- package/dist/acp/codex/agent.js +706 -0
- package/dist/acp/codex/agent.js.map +1 -0
- package/dist/acp/codex/app-server-client.d.ts +45 -0
- package/dist/acp/codex/app-server-client.d.ts.map +1 -0
- package/dist/acp/codex/app-server-client.js +195 -0
- package/dist/acp/codex/app-server-client.js.map +1 -0
- package/dist/acp/codex/app-server-protocol.d.ts +225 -0
- package/dist/acp/codex/app-server-protocol.d.ts.map +1 -0
- package/dist/acp/codex/app-server-protocol.js +197 -0
- package/dist/acp/codex/app-server-protocol.js.map +1 -0
- package/dist/acp/codex/items.d.ts +17 -0
- package/dist/acp/codex/items.d.ts.map +1 -0
- package/dist/acp/codex/items.js +141 -0
- package/dist/acp/codex/items.js.map +1 -0
- package/dist/acp/in-process/acp-endpoint.d.ts +33 -0
- package/dist/acp/in-process/acp-endpoint.d.ts.map +1 -0
- package/dist/acp/in-process/acp-endpoint.js +2 -0
- package/dist/acp/in-process/acp-endpoint.js.map +1 -0
- package/dist/acp/session-manager.d.ts +5 -16
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +63 -38
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/agent-catalog/acp-readiness-probe.d.ts +2 -2
- package/dist/agent-catalog/acp-readiness-probe.d.ts.map +1 -1
- package/dist/agent-catalog/acp-readiness-probe.js +55 -0
- package/dist/agent-catalog/acp-readiness-probe.js.map +1 -1
- package/dist/agent-catalog/agent-diagnostics.d.ts.map +1 -1
- package/dist/agent-catalog/agent-diagnostics.js +4 -1
- package/dist/agent-catalog/agent-diagnostics.js.map +1 -1
- package/dist/agent-catalog/agent-discovery.d.ts +4 -4
- package/dist/agent-catalog/agent-discovery.d.ts.map +1 -1
- package/dist/agent-catalog/agent-discovery.js.map +1 -1
- package/dist/agent-catalog/agent-settings-adapter.d.ts +8 -8
- package/dist/agent-catalog/agent-settings-adapter.d.ts.map +1 -1
- package/dist/agent-catalog/agent-settings-adapter.js.map +1 -1
- package/dist/agent-catalog/agent-specification.d.ts +21 -0
- package/dist/agent-catalog/agent-specification.d.ts.map +1 -1
- package/dist/agent-catalog/agent-specification.js +25 -0
- package/dist/agent-catalog/agent-specification.js.map +1 -1
- package/dist/agent-catalog/agents/codex-agent.d.ts +5 -9
- package/dist/agent-catalog/agents/codex-agent.d.ts.map +1 -1
- package/dist/agent-catalog/agents/codex-agent.js +9 -18
- package/dist/agent-catalog/agents/codex-agent.js.map +1 -1
- package/dist/agent-catalog/discover-agent.d.ts.map +1 -1
- package/dist/agent-catalog/discover-agent.js +11 -6
- package/dist/agent-catalog/discover-agent.js.map +1 -1
- package/dist/agent-catalog/executable-discovery.d.ts.map +1 -1
- package/dist/agent-catalog/executable-discovery.js +2 -2
- package/dist/agent-catalog/executable-discovery.js.map +1 -1
- package/dist/agent-catalog/local-agent.d.ts +25 -11
- package/dist/agent-catalog/local-agent.d.ts.map +1 -1
- package/dist/agent-catalog/local-agent.js +32 -12
- package/dist/agent-catalog/local-agent.js.map +1 -1
- package/dist/agent-installation/fixed-installation-executor.d.ts.map +1 -1
- package/dist/agent-installation/fixed-installation-executor.js +3 -1
- package/dist/agent-installation/fixed-installation-executor.js.map +1 -1
- package/dist/cli.js +8045 -6582
- package/dist/cli.js.map +4 -4
- package/dist/config.d.ts +5 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon-diagnostic-log.d.ts +6 -0
- package/dist/daemon-diagnostic-log.d.ts.map +1 -0
- package/dist/daemon-diagnostic-log.js +48 -0
- package/dist/daemon-diagnostic-log.js.map +1 -0
- package/dist/index.js +1630 -167
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/codex-history.d.ts +3 -3
- package/dist/native-sessions/codex-history.d.ts.map +1 -1
- package/dist/native-sessions/codex-history.js +1 -1
- package/dist/native-sessions/codex-history.js.map +1 -1
- package/dist/native-sessions/service.d.ts.map +1 -1
- package/dist/native-sessions/service.js +6 -5
- package/dist/native-sessions/service.js.map +1 -1
- package/dist/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/pairing/pair-local-machine.js.map +1 -1
- package/dist/relay-connection/diagnostics.d.ts +3 -1
- package/dist/relay-connection/diagnostics.d.ts.map +1 -1
- package/dist/relay-connection/diagnostics.js +16 -1
- package/dist/relay-connection/diagnostics.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +17 -2
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +5526 -4063
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20988,6 +20988,26 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
|
|
|
20988
20988
|
messageOccurrence: external_exports.number().int().positive(),
|
|
20989
20989
|
title: external_exports.string().max(500)
|
|
20990
20990
|
}).readonly();
|
|
20991
|
+
var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
|
|
20992
|
+
external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
|
|
20993
|
+
external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
|
|
20994
|
+
external_exports.strictObject({
|
|
20995
|
+
...identity,
|
|
20996
|
+
action: external_exports.literal("list"),
|
|
20997
|
+
cursor: identifier.nullable()
|
|
20998
|
+
}).readonly(),
|
|
20999
|
+
external_exports.strictObject({
|
|
21000
|
+
...identity,
|
|
21001
|
+
action: external_exports.enum(["import", "fork"]),
|
|
21002
|
+
entryId: identifier,
|
|
21003
|
+
targetSessionId: identifier
|
|
21004
|
+
}).readonly(),
|
|
21005
|
+
external_exports.strictObject({
|
|
21006
|
+
...identity,
|
|
21007
|
+
action: external_exports.literal("delete"),
|
|
21008
|
+
entryId: identifier
|
|
21009
|
+
}).readonly()
|
|
21010
|
+
]);
|
|
20991
21011
|
var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
20992
21012
|
external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
|
|
20993
21013
|
external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
|
|
@@ -21002,6 +21022,12 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
|
21002
21022
|
entryId: identifier,
|
|
21003
21023
|
targetSessionId: identifier
|
|
21004
21024
|
}).readonly(),
|
|
21025
|
+
external_exports.strictObject({
|
|
21026
|
+
...identity,
|
|
21027
|
+
action: external_exports.enum(["import-only", "fork-only"]),
|
|
21028
|
+
entryId: identifier,
|
|
21029
|
+
targetSessionId: identifier
|
|
21030
|
+
}).readonly(),
|
|
21005
21031
|
external_exports.strictObject({
|
|
21006
21032
|
...identity,
|
|
21007
21033
|
action: external_exports.literal("delete"),
|
|
@@ -22085,30 +22111,36 @@ function readTrustedIdentity(path2) {
|
|
|
22085
22111
|
metadata.ctimeMs
|
|
22086
22112
|
);
|
|
22087
22113
|
}
|
|
22088
|
-
var
|
|
22089
|
-
adapterIdentity;
|
|
22090
|
-
adapterPath;
|
|
22091
|
-
adapterVersion;
|
|
22114
|
+
var AgentDefinition = class {
|
|
22092
22115
|
agentIdentity;
|
|
22093
22116
|
agentVersion;
|
|
22094
|
-
arguments;
|
|
22095
|
-
command;
|
|
22096
22117
|
capabilities;
|
|
22118
|
+
command;
|
|
22097
22119
|
environment;
|
|
22098
22120
|
id;
|
|
22099
22121
|
label;
|
|
22100
|
-
constructor(id, label,
|
|
22101
|
-
this.adapterIdentity = adapterIdentity;
|
|
22102
|
-
this.adapterPath = adapterIdentity.realPath;
|
|
22103
|
-
this.adapterVersion = adapterVersion;
|
|
22122
|
+
constructor(id, label, _command, environment, agentVersion, agentIdentity, capabilities) {
|
|
22104
22123
|
this.agentIdentity = agentIdentity;
|
|
22105
22124
|
this.agentVersion = agentVersion;
|
|
22106
22125
|
this.capabilities = Object.freeze({ ...capabilities });
|
|
22126
|
+
this.command = agentIdentity.realPath;
|
|
22127
|
+
this.environment = Object.freeze({ ...environment });
|
|
22107
22128
|
this.id = id;
|
|
22108
22129
|
this.label = label;
|
|
22109
|
-
|
|
22130
|
+
}
|
|
22131
|
+
};
|
|
22132
|
+
var LocalAgentDefinition = class _LocalAgentDefinition extends AgentDefinition {
|
|
22133
|
+
kind = "acp-adapter-process";
|
|
22134
|
+
adapterIdentity;
|
|
22135
|
+
adapterPath;
|
|
22136
|
+
adapterVersion;
|
|
22137
|
+
arguments;
|
|
22138
|
+
constructor(id, label, command, arguments_, environment = {}, adapterVersion = "", agentVersion = "", adapterIdentity = readTrustedIdentity(command), agentIdentity = adapterIdentity, capabilities = unsupportedSessionCapabilities()) {
|
|
22139
|
+
super(id, label, command, environment, agentVersion, agentIdentity, capabilities);
|
|
22140
|
+
this.adapterIdentity = adapterIdentity;
|
|
22141
|
+
this.adapterPath = adapterIdentity.realPath;
|
|
22142
|
+
this.adapterVersion = adapterVersion;
|
|
22110
22143
|
this.arguments = Object.freeze([...arguments_]);
|
|
22111
|
-
this.environment = Object.freeze({ ...environment });
|
|
22112
22144
|
}
|
|
22113
22145
|
withEnvironment = (environment) => new _LocalAgentDefinition(
|
|
22114
22146
|
this.id,
|
|
@@ -22123,6 +22155,24 @@ var LocalAgentDefinition = class _LocalAgentDefinition {
|
|
|
22123
22155
|
this.capabilities
|
|
22124
22156
|
);
|
|
22125
22157
|
};
|
|
22158
|
+
var InProcessAcpAgentDefinition = class _InProcessAcpAgentDefinition extends AgentDefinition {
|
|
22159
|
+
kind = "in-process-acp";
|
|
22160
|
+
createEndpoint;
|
|
22161
|
+
constructor(id, label, command, createEndpoint, environment = {}, agentVersion = "", agentIdentity = readTrustedIdentity(command), capabilities = unsupportedSessionCapabilities()) {
|
|
22162
|
+
super(id, label, command, environment, agentVersion, agentIdentity, capabilities);
|
|
22163
|
+
this.createEndpoint = createEndpoint;
|
|
22164
|
+
}
|
|
22165
|
+
withEnvironment = (environment) => new _InProcessAcpAgentDefinition(
|
|
22166
|
+
this.id,
|
|
22167
|
+
this.label,
|
|
22168
|
+
this.command,
|
|
22169
|
+
this.createEndpoint,
|
|
22170
|
+
environment,
|
|
22171
|
+
this.agentVersion,
|
|
22172
|
+
this.agentIdentity,
|
|
22173
|
+
this.capabilities
|
|
22174
|
+
);
|
|
22175
|
+
};
|
|
22126
22176
|
var InstallableAgentDefinition = class {
|
|
22127
22177
|
id;
|
|
22128
22178
|
label;
|
|
@@ -22593,6 +22643,30 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
22593
22643
|
return `${rewritten}${text3.slice(cursor)}`;
|
|
22594
22644
|
}
|
|
22595
22645
|
|
|
22646
|
+
// src/acp/acp-error.ts
|
|
22647
|
+
var AcpExecutionError = class extends Error {
|
|
22648
|
+
code;
|
|
22649
|
+
constructor(message, options = {}, code = "acp_execution_failed") {
|
|
22650
|
+
super(message, options);
|
|
22651
|
+
this.code = code;
|
|
22652
|
+
this.name = "AcpExecutionError";
|
|
22653
|
+
}
|
|
22654
|
+
};
|
|
22655
|
+
var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
|
|
22656
|
+
configId;
|
|
22657
|
+
offeredValueCount;
|
|
22658
|
+
offeredValues;
|
|
22659
|
+
requestedValue;
|
|
22660
|
+
constructor(configId, requestedValue, offeredValues) {
|
|
22661
|
+
super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
|
|
22662
|
+
this.name = "AcpConfigurationValueUnavailableError";
|
|
22663
|
+
this.configId = configId.slice(0, 128);
|
|
22664
|
+
this.requestedValue = requestedValue.slice(0, 128);
|
|
22665
|
+
this.offeredValueCount = offeredValues.length;
|
|
22666
|
+
this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
|
|
22667
|
+
}
|
|
22668
|
+
};
|
|
22669
|
+
|
|
22596
22670
|
// src/acp/activity.ts
|
|
22597
22671
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
22598
22672
|
function isRecord3(value) {
|
|
@@ -31111,6 +31185,15 @@ var MAX_PRE_SESSION_UPDATES = 100;
|
|
|
31111
31185
|
var MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
|
|
31112
31186
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
31113
31187
|
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
31188
|
+
function nativeHistoryNotRetained() {
|
|
31189
|
+
return {
|
|
31190
|
+
cause: {
|
|
31191
|
+
code: "native_history_not_retained",
|
|
31192
|
+
message: "Native message history is not retained in the cloud for this Session."
|
|
31193
|
+
},
|
|
31194
|
+
status: "unavailable"
|
|
31195
|
+
};
|
|
31196
|
+
}
|
|
31114
31197
|
var NullAcpSessionObserver = class {
|
|
31115
31198
|
onCommands = () => Promise.resolve();
|
|
31116
31199
|
onConfig = () => Promise.resolve();
|
|
@@ -31148,28 +31231,6 @@ var AcpAgentSettingsSnapshot = class {
|
|
|
31148
31231
|
this.configOptions = configOptions;
|
|
31149
31232
|
}
|
|
31150
31233
|
};
|
|
31151
|
-
var AcpExecutionError = class extends Error {
|
|
31152
|
-
code;
|
|
31153
|
-
constructor(message, options = {}, code = "acp_execution_failed") {
|
|
31154
|
-
super(message, options);
|
|
31155
|
-
this.code = code;
|
|
31156
|
-
this.name = "AcpExecutionError";
|
|
31157
|
-
}
|
|
31158
|
-
};
|
|
31159
|
-
var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
|
|
31160
|
-
configId;
|
|
31161
|
-
offeredValueCount;
|
|
31162
|
-
offeredValues;
|
|
31163
|
-
requestedValue;
|
|
31164
|
-
constructor(configId, requestedValue, offeredValues) {
|
|
31165
|
-
super("The requested ACP configuration value is unavailable", {}, "invalid_session_configuration");
|
|
31166
|
-
this.name = "AcpConfigurationValueUnavailableError";
|
|
31167
|
-
this.configId = configId.slice(0, 128);
|
|
31168
|
-
this.requestedValue = requestedValue.slice(0, 128);
|
|
31169
|
-
this.offeredValueCount = offeredValues.length;
|
|
31170
|
-
this.offeredValues = Object.freeze(offeredValues.slice(0, 32).map((value) => value.slice(0, 128)));
|
|
31171
|
-
}
|
|
31172
|
-
};
|
|
31173
31234
|
var RetryableAcpInitializationError = class extends AcpExecutionError {
|
|
31174
31235
|
constructor(cause) {
|
|
31175
31236
|
super("ACP agent initialization failed", { cause });
|
|
@@ -31666,16 +31727,18 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31666
31727
|
#additionalDirectories;
|
|
31667
31728
|
#acceptedUrlElicitations = /* @__PURE__ */ new Map();
|
|
31668
31729
|
#agentId;
|
|
31669
|
-
#child;
|
|
31670
31730
|
#connection;
|
|
31671
31731
|
#cwd;
|
|
31672
31732
|
#environment;
|
|
31673
31733
|
#getObserver;
|
|
31734
|
+
#inProcessAgent;
|
|
31674
31735
|
#mobiusSessionId;
|
|
31675
31736
|
#pendingElicitations = /* @__PURE__ */ new Map();
|
|
31676
31737
|
#pendingPermissions = /* @__PURE__ */ new Map();
|
|
31677
31738
|
#preSessionUpdates = [];
|
|
31739
|
+
// The adapter-process topology only. An in-process agent owns the app-server child itself.
|
|
31678
31740
|
#processExit;
|
|
31741
|
+
#runtimeChild;
|
|
31679
31742
|
#metrics;
|
|
31680
31743
|
#sessionConfigProtocol;
|
|
31681
31744
|
#store;
|
|
@@ -31710,18 +31773,33 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31710
31773
|
this.#sessionConfigProtocol = sessionConfigProtocolForAgent(agent.id);
|
|
31711
31774
|
this.#store = store;
|
|
31712
31775
|
this.#verifiedAgentVersion = agent.agentVersion;
|
|
31713
|
-
|
|
31776
|
+
if (agent.kind === "in-process-acp") {
|
|
31777
|
+
const inProcess = agent.createEndpoint({
|
|
31778
|
+
command: agent.command,
|
|
31779
|
+
cwd,
|
|
31780
|
+
environment: agent.environment
|
|
31781
|
+
});
|
|
31782
|
+
this.#inProcessAgent = inProcess;
|
|
31783
|
+
this.#runtimeChild = null;
|
|
31784
|
+
this.#processExit = new Promise(() => {
|
|
31785
|
+
});
|
|
31786
|
+
this.#connection = createAcpClient(this).connect(inProcess.app());
|
|
31787
|
+
return;
|
|
31788
|
+
}
|
|
31789
|
+
this.#inProcessAgent = null;
|
|
31790
|
+
const child = spawn2(agent.adapterPath, [...agent.arguments], {
|
|
31714
31791
|
cwd,
|
|
31715
31792
|
detached: process.platform !== "win32",
|
|
31716
31793
|
env: { ...process.env, ...agent.environment },
|
|
31717
31794
|
shell: false,
|
|
31718
31795
|
stdio: ["pipe", "pipe", "pipe"]
|
|
31719
31796
|
});
|
|
31720
|
-
|
|
31721
|
-
const
|
|
31722
|
-
const
|
|
31797
|
+
this.#runtimeChild = child;
|
|
31798
|
+
const stdin = child.stdin;
|
|
31799
|
+
const stdout = child.stdout;
|
|
31800
|
+
const stderr = child.stderr;
|
|
31723
31801
|
if (stdin === null || stdout === null || stderr === null) {
|
|
31724
|
-
|
|
31802
|
+
child.kill("SIGKILL");
|
|
31725
31803
|
throw new AcpExecutionError("ACP process streams are unavailable");
|
|
31726
31804
|
}
|
|
31727
31805
|
stderr.setEncoding("utf8");
|
|
@@ -31729,8 +31807,8 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31729
31807
|
process.stderr.write(`[${agent.id}-acp] ${chunk}`);
|
|
31730
31808
|
});
|
|
31731
31809
|
this.#processExit = new Promise((resolve8) => {
|
|
31732
|
-
|
|
31733
|
-
|
|
31810
|
+
child.once("error", resolve8);
|
|
31811
|
+
child.once("exit", resolve8);
|
|
31734
31812
|
});
|
|
31735
31813
|
const stream = ndJsonStream(createWritableAcpStream(stdin), readableWebStream(stdout));
|
|
31736
31814
|
this.#connection = createAcpClient(this).connect(stream);
|
|
@@ -31738,15 +31816,16 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31738
31816
|
static async #start(options, getObserver, store, initialize, metrics) {
|
|
31739
31817
|
for (let attempt = 1; attempt <= 2; attempt += 1) {
|
|
31740
31818
|
options.signal.throwIfAborted();
|
|
31741
|
-
const
|
|
31819
|
+
const unchanged = await metrics.measure(
|
|
31742
31820
|
"executable-validation",
|
|
31743
31821
|
async () => await Promise.all([
|
|
31744
|
-
|
|
31822
|
+
// Only the adapter topology has an adapter executable to revalidate.
|
|
31823
|
+
options.agent.kind === "acp-adapter-process" ? revalidateExecutable(options.agent.adapterIdentity) : Promise.resolve(true),
|
|
31745
31824
|
revalidateExecutable(options.agent.agentIdentity)
|
|
31746
31825
|
])
|
|
31747
31826
|
);
|
|
31748
31827
|
options.signal.throwIfAborted();
|
|
31749
|
-
if (
|
|
31828
|
+
if (unchanged.some((result) => !result)) {
|
|
31750
31829
|
throw new AcpExecutionError(
|
|
31751
31830
|
"The local Agent runtime changed; restart Mobius before starting a new conversation",
|
|
31752
31831
|
{},
|
|
@@ -31979,6 +32058,16 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
31979
32058
|
await this.#metrics.measure("agent-initialize", async () => await this.#initializeAgentOperation(signal));
|
|
31980
32059
|
}
|
|
31981
32060
|
async #initializeAgentOperation(signal) {
|
|
32061
|
+
if (this.#inProcessAgent !== null) {
|
|
32062
|
+
await this.race(
|
|
32063
|
+
this.#inProcessAgent.initialize(signal),
|
|
32064
|
+
"The Codex app-server exited during initialization",
|
|
32065
|
+
signal
|
|
32066
|
+
).catch((cause) => {
|
|
32067
|
+
signal.throwIfAborted();
|
|
32068
|
+
throw new RetryableAcpInitializationError(cause);
|
|
32069
|
+
});
|
|
32070
|
+
}
|
|
31982
32071
|
const initialized = await this.race(
|
|
31983
32072
|
this.#connection.agent.request(
|
|
31984
32073
|
methods3.agent.initialize,
|
|
@@ -32471,7 +32560,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32471
32560
|
);
|
|
32472
32561
|
};
|
|
32473
32562
|
cancel = async () => {
|
|
32474
|
-
const capturedProcesses = await captureProcessTree(this.#
|
|
32563
|
+
const capturedProcesses = this.#runtimeChild === null ? [] : await captureProcessTree(this.#runtimeChild);
|
|
32475
32564
|
try {
|
|
32476
32565
|
await this.cancelPendingInteractions();
|
|
32477
32566
|
if (this.#turn.running) {
|
|
@@ -32834,7 +32923,11 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32834
32923
|
};
|
|
32835
32924
|
closeProcess = async (capturedProcesses = []) => {
|
|
32836
32925
|
try {
|
|
32837
|
-
|
|
32926
|
+
if (this.#runtimeChild === null) {
|
|
32927
|
+
await this.#inProcessAgent?.close();
|
|
32928
|
+
return;
|
|
32929
|
+
}
|
|
32930
|
+
await stopProcessTree(this.#runtimeChild, capturedProcesses);
|
|
32838
32931
|
} finally {
|
|
32839
32932
|
this.#connection.close();
|
|
32840
32933
|
}
|
|
@@ -33766,7 +33859,7 @@ var AcpSessionManager = class {
|
|
|
33766
33859
|
this.#endSessionUse(options.sessionId);
|
|
33767
33860
|
}
|
|
33768
33861
|
};
|
|
33769
|
-
openNativeSession = async (options, origin) => {
|
|
33862
|
+
openNativeSession = async (options, origin, loadHistory) => {
|
|
33770
33863
|
const key = `${options.agent.id}:${origin.nativeSessionId}`;
|
|
33771
33864
|
if (this.#nativeOperations.has(key)) {
|
|
33772
33865
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
@@ -33796,7 +33889,7 @@ var AcpSessionManager = class {
|
|
|
33796
33889
|
}
|
|
33797
33890
|
this.#nativeOperations.add(key);
|
|
33798
33891
|
try {
|
|
33799
|
-
const history = await runtime.loadHistory(options.signal);
|
|
33892
|
+
const history = loadHistory ? await runtime.loadHistory(options.signal) : nativeHistoryNotRetained();
|
|
33800
33893
|
return {
|
|
33801
33894
|
prepared: runtime.prepared(),
|
|
33802
33895
|
sessionId: existing.sessionId,
|
|
@@ -33827,7 +33920,7 @@ var AcpSessionManager = class {
|
|
|
33827
33920
|
const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
|
|
33828
33921
|
this.#nativeOperations.add(openedKey);
|
|
33829
33922
|
try {
|
|
33830
|
-
const history = await runtime.loadHistory(options.signal);
|
|
33923
|
+
const history = loadHistory ? await runtime.loadHistory(options.signal) : nativeHistoryNotRetained();
|
|
33831
33924
|
return {
|
|
33832
33925
|
sessionId: options.sessionId,
|
|
33833
33926
|
prepared: runtime.prepared(),
|
|
@@ -34523,6 +34616,21 @@ var DirectAcpAgentDefinition = class extends LocalAgentSpecification {
|
|
|
34523
34616
|
this.managedAgentExecutablePath = this.managedAdapterExecutablePath;
|
|
34524
34617
|
}
|
|
34525
34618
|
};
|
|
34619
|
+
var InProcessAcpAgentDefinition2 = class extends LocalAgentSpecification {
|
|
34620
|
+
launchArguments = Object.freeze([]);
|
|
34621
|
+
adapterOverrideVariable;
|
|
34622
|
+
adapterVersion = "in-process";
|
|
34623
|
+
agentOverrideVariable;
|
|
34624
|
+
managedAdapterExecutablePath;
|
|
34625
|
+
managedAgentExecutablePath;
|
|
34626
|
+
constructor(executableOverrideVariable, managedExecutablePath) {
|
|
34627
|
+
super();
|
|
34628
|
+
this.adapterOverrideVariable = executableOverrideVariable;
|
|
34629
|
+
this.agentOverrideVariable = executableOverrideVariable;
|
|
34630
|
+
this.managedAdapterExecutablePath = Object.freeze([...managedExecutablePath]);
|
|
34631
|
+
this.managedAgentExecutablePath = this.managedAdapterExecutablePath;
|
|
34632
|
+
}
|
|
34633
|
+
};
|
|
34526
34634
|
var BridgedAcpAgentDefinition = class extends LocalAgentSpecification {
|
|
34527
34635
|
launchArguments = Object.freeze([]);
|
|
34528
34636
|
get adapterExecutable() {
|
|
@@ -34564,85 +34672,1277 @@ var ClaudeCodeAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
34564
34672
|
managedAgentExecutablePath = ["agents", "claude", "home", ".local", "bin", "claude"];
|
|
34565
34673
|
};
|
|
34566
34674
|
|
|
34567
|
-
// src/
|
|
34568
|
-
|
|
34569
|
-
|
|
34570
|
-
|
|
34571
|
-
|
|
34572
|
-
|
|
34573
|
-
"@agentclientprotocol/codex-acp",
|
|
34574
|
-
"1.8.0",
|
|
34575
|
-
"codex-acp"
|
|
34576
|
-
);
|
|
34577
|
-
agentExecutable = "codex";
|
|
34578
|
-
agentOverrideVariable = "MOBIUS_CODEX_PATH";
|
|
34579
|
-
id = "codex";
|
|
34580
|
-
label = "Codex";
|
|
34581
|
-
managedAdapterExecutablePath = [
|
|
34582
|
-
"adapters",
|
|
34583
|
-
"codex",
|
|
34584
|
-
"1.8.0",
|
|
34585
|
-
"node_modules",
|
|
34586
|
-
"@agentclientprotocol",
|
|
34587
|
-
"codex-acp",
|
|
34588
|
-
"dist",
|
|
34589
|
-
"index.js"
|
|
34590
|
-
];
|
|
34591
|
-
managedAgentExecutablePath = ["agents", "codex", "bin", "codex"];
|
|
34592
|
-
};
|
|
34675
|
+
// src/acp/codex/agent.ts
|
|
34676
|
+
import {
|
|
34677
|
+
agent as createAgentApp,
|
|
34678
|
+
methods as methods4,
|
|
34679
|
+
PROTOCOL_VERSION as PROTOCOL_VERSION2
|
|
34680
|
+
} from "@agentclientprotocol/sdk";
|
|
34593
34681
|
|
|
34594
|
-
// src/
|
|
34595
|
-
|
|
34682
|
+
// src/acp/codex/app-server-client.ts
|
|
34683
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
34684
|
+
|
|
34685
|
+
// src/acp/codex/app-server-protocol.ts
|
|
34686
|
+
var boundedText = (maximum) => external_exports.string().max(maximum);
|
|
34687
|
+
var jsonValue = external_exports.lazy(() => external_exports.unknown());
|
|
34688
|
+
var requestIdSchema = external_exports.union([external_exports.number(), external_exports.string()]).refine((value) => typeof value === "number" || value.length <= 256);
|
|
34689
|
+
var errorResponseSchema = external_exports.object({
|
|
34690
|
+
error: external_exports.object({ code: external_exports.number(), message: boundedText(4096) }),
|
|
34691
|
+
id: requestIdSchema
|
|
34692
|
+
});
|
|
34693
|
+
var resultResponseSchema = external_exports.object({ id: requestIdSchema, result: external_exports.unknown() });
|
|
34694
|
+
var serverRequestSchema = external_exports.object({
|
|
34695
|
+
id: requestIdSchema,
|
|
34696
|
+
method: external_exports.string(),
|
|
34697
|
+
params: external_exports.unknown().optional()
|
|
34698
|
+
});
|
|
34699
|
+
var serverNotificationSchema = external_exports.object({
|
|
34700
|
+
method: external_exports.string(),
|
|
34701
|
+
params: external_exports.unknown().optional()
|
|
34702
|
+
});
|
|
34703
|
+
function decodeAppServerMessage(value) {
|
|
34704
|
+
const record2 = external_exports.record(external_exports.string(), external_exports.unknown()).parse(value);
|
|
34705
|
+
const error62 = errorResponseSchema.safeParse(record2);
|
|
34706
|
+
if (error62.success) {
|
|
34707
|
+
return {
|
|
34708
|
+
code: error62.data.error.code,
|
|
34709
|
+
id: error62.data.id,
|
|
34710
|
+
kind: "error-response",
|
|
34711
|
+
message: error62.data.error.message
|
|
34712
|
+
};
|
|
34713
|
+
}
|
|
34714
|
+
const result = resultResponseSchema.safeParse(record2);
|
|
34715
|
+
if (result.success) {
|
|
34716
|
+
return { id: result.data.id, kind: "result-response", result: result.data.result };
|
|
34717
|
+
}
|
|
34718
|
+
const request = serverRequestSchema.safeParse(record2);
|
|
34719
|
+
if (request.success) {
|
|
34720
|
+
return {
|
|
34721
|
+
id: request.data.id,
|
|
34722
|
+
kind: "server-request",
|
|
34723
|
+
method: request.data.method,
|
|
34724
|
+
params: request.data.params ?? {}
|
|
34725
|
+
};
|
|
34726
|
+
}
|
|
34727
|
+
const notification = serverNotificationSchema.parse(record2);
|
|
34728
|
+
return { kind: "notification", method: notification.method, params: notification.params ?? {} };
|
|
34729
|
+
}
|
|
34730
|
+
var turnStatusSchema = external_exports.enum(["inProgress", "completed", "interrupted", "failed"]);
|
|
34731
|
+
var messagePhaseSchema = external_exports.enum(["commentary", "final_answer"]);
|
|
34732
|
+
var commandExecutionStatusSchema = external_exports.enum(["inProgress", "completed", "failed", "declined"]);
|
|
34733
|
+
var patchApplyStatusSchema = external_exports.enum(["inProgress", "completed", "failed", "declined"]);
|
|
34734
|
+
var mcpToolCallStatusSchema = external_exports.enum(["inProgress", "completed", "failed"]);
|
|
34735
|
+
var dynamicToolCallStatusSchema = external_exports.enum(["inProgress", "completed", "failed"]);
|
|
34736
|
+
var fileUpdateChangeSchema = external_exports.object({
|
|
34737
|
+
diff: boundedText(1e6),
|
|
34738
|
+
kind: external_exports.unknown(),
|
|
34739
|
+
path: boundedText(4096)
|
|
34740
|
+
});
|
|
34741
|
+
var threadItemSchema = external_exports.discriminatedUnion("type", [
|
|
34742
|
+
external_exports.object({
|
|
34743
|
+
id: boundedText(256),
|
|
34744
|
+
text: boundedText(1e6),
|
|
34745
|
+
type: external_exports.literal("agentMessage"),
|
|
34746
|
+
phase: messagePhaseSchema.nullish()
|
|
34747
|
+
}),
|
|
34748
|
+
external_exports.object({ content: external_exports.array(external_exports.unknown()).max(1e4), id: boundedText(256), type: external_exports.literal("userMessage") }),
|
|
34749
|
+
external_exports.object({
|
|
34750
|
+
aggregatedOutput: boundedText(4e6).nullish(),
|
|
34751
|
+
command: boundedText(32768),
|
|
34752
|
+
cwd: boundedText(4096),
|
|
34753
|
+
durationMs: external_exports.number().nullish(),
|
|
34754
|
+
exitCode: external_exports.number().nullish(),
|
|
34755
|
+
id: boundedText(256),
|
|
34756
|
+
processId: external_exports.string().nullish(),
|
|
34757
|
+
status: commandExecutionStatusSchema,
|
|
34758
|
+
type: external_exports.literal("commandExecution")
|
|
34759
|
+
}),
|
|
34760
|
+
external_exports.object({
|
|
34761
|
+
changes: external_exports.array(fileUpdateChangeSchema).max(1e4),
|
|
34762
|
+
id: boundedText(256),
|
|
34763
|
+
status: patchApplyStatusSchema,
|
|
34764
|
+
type: external_exports.literal("fileChange")
|
|
34765
|
+
}),
|
|
34766
|
+
external_exports.object({
|
|
34767
|
+
arguments: jsonValue.optional(),
|
|
34768
|
+
error: external_exports.unknown().nullish(),
|
|
34769
|
+
id: boundedText(256),
|
|
34770
|
+
result: external_exports.unknown().nullish(),
|
|
34771
|
+
server: boundedText(256),
|
|
34772
|
+
status: mcpToolCallStatusSchema,
|
|
34773
|
+
tool: boundedText(256),
|
|
34774
|
+
type: external_exports.literal("mcpToolCall")
|
|
34775
|
+
}),
|
|
34776
|
+
external_exports.object({
|
|
34777
|
+
arguments: jsonValue.optional(),
|
|
34778
|
+
contentItems: external_exports.array(external_exports.unknown()).max(1e4).nullish(),
|
|
34779
|
+
id: boundedText(256),
|
|
34780
|
+
namespace: external_exports.string().nullish(),
|
|
34781
|
+
status: dynamicToolCallStatusSchema,
|
|
34782
|
+
success: external_exports.boolean().nullish(),
|
|
34783
|
+
tool: boundedText(256),
|
|
34784
|
+
type: external_exports.literal("dynamicToolCall")
|
|
34785
|
+
}),
|
|
34786
|
+
external_exports.object({
|
|
34787
|
+
content: external_exports.array(boundedText(1e6)).max(1e3),
|
|
34788
|
+
id: boundedText(256),
|
|
34789
|
+
summary: external_exports.array(boundedText(1e6)).max(1e3),
|
|
34790
|
+
type: external_exports.literal("reasoning")
|
|
34791
|
+
}),
|
|
34792
|
+
external_exports.object({ id: boundedText(256), text: boundedText(1e6), type: external_exports.literal("plan") })
|
|
34793
|
+
]);
|
|
34794
|
+
var turnSchema = external_exports.object({
|
|
34795
|
+
durationMs: external_exports.number().nullish(),
|
|
34796
|
+
error: external_exports.object({ message: boundedText(4096) }).nullish(),
|
|
34797
|
+
id: boundedText(256),
|
|
34798
|
+
status: turnStatusSchema
|
|
34799
|
+
});
|
|
34800
|
+
var turnNotificationSchema = external_exports.object({
|
|
34801
|
+
thread: external_exports.object({ id: boundedText(256) }).nullish(),
|
|
34802
|
+
threadId: boundedText(256),
|
|
34803
|
+
turn: turnSchema
|
|
34804
|
+
});
|
|
34805
|
+
var commandApprovalParamsSchema = external_exports.object({
|
|
34806
|
+
command: external_exports.string().nullish(),
|
|
34807
|
+
commandActions: external_exports.array(external_exports.unknown()).max(1e3).nullish(),
|
|
34808
|
+
cwd: external_exports.string().nullish(),
|
|
34809
|
+
itemId: boundedText(256),
|
|
34810
|
+
reason: external_exports.string().nullish(),
|
|
34811
|
+
threadId: boundedText(256),
|
|
34812
|
+
turnId: boundedText(256)
|
|
34813
|
+
});
|
|
34814
|
+
var fileChangeApprovalParamsSchema = external_exports.object({
|
|
34815
|
+
grantRoot: external_exports.string().nullish(),
|
|
34816
|
+
itemId: boundedText(256),
|
|
34817
|
+
reason: external_exports.string().nullish(),
|
|
34818
|
+
threadId: boundedText(256),
|
|
34819
|
+
turnId: boundedText(256)
|
|
34820
|
+
});
|
|
34821
|
+
var userInputOptionSchema = external_exports.object({
|
|
34822
|
+
description: boundedText(4096),
|
|
34823
|
+
label: boundedText(1024)
|
|
34824
|
+
});
|
|
34825
|
+
var userInputQuestionSchema = external_exports.object({
|
|
34826
|
+
header: boundedText(1024),
|
|
34827
|
+
id: boundedText(256),
|
|
34828
|
+
options: external_exports.array(userInputOptionSchema).max(1e3).nullish(),
|
|
34829
|
+
question: boundedText(4096)
|
|
34830
|
+
});
|
|
34831
|
+
var requestUserInputParamsSchema = external_exports.object({
|
|
34832
|
+
itemId: boundedText(256).nullish(),
|
|
34833
|
+
questions: external_exports.array(userInputQuestionSchema).max(1e3),
|
|
34834
|
+
threadId: boundedText(256),
|
|
34835
|
+
turnId: boundedText(256)
|
|
34836
|
+
});
|
|
34837
|
+
var mcpElicitationParamsSchema = external_exports.object({
|
|
34838
|
+
message: boundedText(4096),
|
|
34839
|
+
mode: external_exports.enum(["form", "url"]).or(external_exports.string()),
|
|
34840
|
+
requestedSchema: external_exports.unknown().optional(),
|
|
34841
|
+
serverName: boundedText(256),
|
|
34842
|
+
threadId: boundedText(256).nullish(),
|
|
34843
|
+
turnId: boundedText(256).nullish(),
|
|
34844
|
+
url: external_exports.string().optional()
|
|
34845
|
+
});
|
|
34846
|
+
var threadStartResponseSchema = external_exports.object({
|
|
34847
|
+
approvalPolicy: external_exports.unknown().optional(),
|
|
34848
|
+
approvalsReviewer: external_exports.unknown().optional(),
|
|
34849
|
+
model: boundedText(256).nullish(),
|
|
34850
|
+
reasoningEffort: boundedText(256).nullish(),
|
|
34851
|
+
sandbox: external_exports.unknown().optional(),
|
|
34852
|
+
serviceTier: boundedText(256).nullish(),
|
|
34853
|
+
thread: external_exports.object({ id: boundedText(256) })
|
|
34854
|
+
});
|
|
34855
|
+
var reasoningEffortOptionSchema = external_exports.object({
|
|
34856
|
+
description: boundedText(4096).nullish(),
|
|
34857
|
+
reasoningEffort: boundedText(256)
|
|
34858
|
+
});
|
|
34859
|
+
var modelSchema = external_exports.object({
|
|
34860
|
+
additionalSpeedTiers: external_exports.array(boundedText(256)).max(100).nullish(),
|
|
34861
|
+
defaultReasoningEffort: boundedText(256).nullish(),
|
|
34862
|
+
description: boundedText(4096).nullish(),
|
|
34863
|
+
displayName: boundedText(256).nullish(),
|
|
34864
|
+
id: boundedText(256),
|
|
34865
|
+
isDefault: external_exports.boolean().nullish(),
|
|
34866
|
+
supportedReasoningEfforts: external_exports.array(reasoningEffortOptionSchema).max(100).nullish()
|
|
34867
|
+
});
|
|
34868
|
+
var modelListResponseSchema = external_exports.object({
|
|
34869
|
+
data: external_exports.array(modelSchema).max(1e3),
|
|
34870
|
+
nextCursor: boundedText(1024).nullish()
|
|
34871
|
+
});
|
|
34872
|
+
|
|
34873
|
+
// src/acp/codex/app-server-client.ts
|
|
34874
|
+
var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
|
|
34875
|
+
var OUTPUT_LIMIT_BYTES = 32 * 1024 * 1024;
|
|
34876
|
+
var CodexAppServerError = class extends Error {
|
|
34596
34877
|
code;
|
|
34597
34878
|
constructor(code, message, options = {}) {
|
|
34598
34879
|
super(message, options);
|
|
34599
34880
|
this.code = code;
|
|
34600
|
-
this.name = "
|
|
34881
|
+
this.name = "CodexAppServerError";
|
|
34601
34882
|
}
|
|
34602
34883
|
};
|
|
34603
|
-
|
|
34604
|
-
|
|
34605
|
-
|
|
34606
|
-
|
|
34607
|
-
|
|
34608
|
-
|
|
34609
|
-
|
|
34610
|
-
|
|
34611
|
-
|
|
34612
|
-
|
|
34613
|
-
|
|
34614
|
-
|
|
34615
|
-
|
|
34616
|
-
|
|
34617
|
-
|
|
34618
|
-
|
|
34619
|
-
|
|
34620
|
-
|
|
34621
|
-
|
|
34622
|
-
|
|
34623
|
-
|
|
34624
|
-
|
|
34625
|
-
|
|
34626
|
-
|
|
34627
|
-
|
|
34628
|
-
|
|
34629
|
-
|
|
34630
|
-
|
|
34631
|
-
|
|
34632
|
-
|
|
34633
|
-
|
|
34634
|
-
|
|
34635
|
-
|
|
34636
|
-
|
|
34637
|
-
|
|
34638
|
-
|
|
34884
|
+
var CodexAppServerClient = class {
|
|
34885
|
+
#child;
|
|
34886
|
+
#handlers;
|
|
34887
|
+
#pending = /* @__PURE__ */ new Map();
|
|
34888
|
+
#processExit;
|
|
34889
|
+
#failure = null;
|
|
34890
|
+
#nextRequestId = 1;
|
|
34891
|
+
#pendingBuffer = "";
|
|
34892
|
+
#receivedBytes = 0;
|
|
34893
|
+
#closed = false;
|
|
34894
|
+
constructor(options) {
|
|
34895
|
+
this.#handlers = options.handlers;
|
|
34896
|
+
this.#child = spawn3(options.command, ["app-server"], {
|
|
34897
|
+
cwd: options.cwd,
|
|
34898
|
+
detached: process.platform !== "win32",
|
|
34899
|
+
env: { ...process.env, ...options.environment },
|
|
34900
|
+
shell: false,
|
|
34901
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
34902
|
+
});
|
|
34903
|
+
const stdin = this.#child.stdin;
|
|
34904
|
+
const stdout = this.#child.stdout;
|
|
34905
|
+
const stderr = this.#child.stderr;
|
|
34906
|
+
if (stdin === null || stdout === null || stderr === null) {
|
|
34907
|
+
this.#child.kill("SIGKILL");
|
|
34908
|
+
throw new CodexAppServerError("codex_app_server_unavailable", "The Codex app-server is unavailable");
|
|
34909
|
+
}
|
|
34910
|
+
stdout.setEncoding("utf8");
|
|
34911
|
+
stdout.on("data", (chunk) => {
|
|
34912
|
+
this.#consume(chunk);
|
|
34913
|
+
});
|
|
34914
|
+
stderr.setEncoding("utf8");
|
|
34915
|
+
stderr.on("data", (chunk) => {
|
|
34916
|
+
process.stderr.write(`[codex-app-server] ${chunk}`);
|
|
34917
|
+
});
|
|
34918
|
+
this.#processExit = new Promise((resolve8) => {
|
|
34919
|
+
this.#child.once("error", resolve8);
|
|
34920
|
+
this.#child.once("exit", resolve8);
|
|
34921
|
+
});
|
|
34639
34922
|
}
|
|
34640
|
-
|
|
34641
|
-
|
|
34642
|
-
|
|
34643
|
-
|
|
34644
|
-
|
|
34645
|
-
|
|
34923
|
+
child = () => this.#child;
|
|
34924
|
+
#fail = (error62) => {
|
|
34925
|
+
this.#failure ??= error62;
|
|
34926
|
+
for (const [id, pending] of this.#pending) {
|
|
34927
|
+
this.#pending.delete(id);
|
|
34928
|
+
pending.completion.reject(error62);
|
|
34929
|
+
}
|
|
34930
|
+
};
|
|
34931
|
+
#exitedFailure = (method) => this.#failure ?? new CodexAppServerError("codex_app_server_exited", `The Codex app-server stopped during ${method}`);
|
|
34932
|
+
#consume = (chunk) => {
|
|
34933
|
+
try {
|
|
34934
|
+
this.#receivedBytes += Buffer.byteLength(chunk);
|
|
34935
|
+
if (this.#receivedBytes > OUTPUT_LIMIT_BYTES) {
|
|
34936
|
+
throw new CodexAppServerError(
|
|
34937
|
+
"codex_app_server_output_limit",
|
|
34938
|
+
"The Codex app-server produced too much output"
|
|
34939
|
+
);
|
|
34940
|
+
}
|
|
34941
|
+
this.#pendingBuffer += chunk;
|
|
34942
|
+
let newline = this.#pendingBuffer.indexOf("\n");
|
|
34943
|
+
while (newline >= 0) {
|
|
34944
|
+
const line = this.#pendingBuffer.slice(0, newline);
|
|
34945
|
+
this.#pendingBuffer = this.#pendingBuffer.slice(newline + 1);
|
|
34946
|
+
newline = this.#pendingBuffer.indexOf("\n");
|
|
34947
|
+
if (line.trim().length === 0) {
|
|
34948
|
+
continue;
|
|
34949
|
+
}
|
|
34950
|
+
const value = JSON.parse(line);
|
|
34951
|
+
this.#dispatch(decodeAppServerMessage(value));
|
|
34952
|
+
}
|
|
34953
|
+
} catch (error62) {
|
|
34954
|
+
this.#fail(
|
|
34955
|
+
error62 instanceof CodexAppServerError ? error62 : new CodexAppServerError(
|
|
34956
|
+
"codex_app_server_protocol_error",
|
|
34957
|
+
"The Codex app-server sent an unreadable message",
|
|
34958
|
+
{ cause: error62 }
|
|
34959
|
+
)
|
|
34960
|
+
);
|
|
34961
|
+
this.#child.kill("SIGKILL");
|
|
34962
|
+
}
|
|
34963
|
+
};
|
|
34964
|
+
// Handler failures are recorded as the app-server's terminal failure: an ACP client that cannot
|
|
34965
|
+
// accept an update or answer an approval has no way to resume the conversation.
|
|
34966
|
+
#runHandler = (operation) => {
|
|
34967
|
+
void operation.catch((error62) => {
|
|
34968
|
+
this.#fail(
|
|
34969
|
+
error62 instanceof CodexAppServerError ? error62 : new CodexAppServerError(
|
|
34970
|
+
"codex_app_server_client_error",
|
|
34971
|
+
"Mobius could not process a Codex app-server message",
|
|
34972
|
+
{ cause: error62 }
|
|
34973
|
+
)
|
|
34974
|
+
);
|
|
34975
|
+
});
|
|
34976
|
+
};
|
|
34977
|
+
#dispatch = (message) => {
|
|
34978
|
+
if (message.kind === "result-response") {
|
|
34979
|
+
const pending = this.#pending.get(message.id);
|
|
34980
|
+
if (pending === void 0) {
|
|
34981
|
+
return;
|
|
34982
|
+
}
|
|
34983
|
+
this.#pending.delete(message.id);
|
|
34984
|
+
pending.completion.resolve(message.result);
|
|
34985
|
+
return;
|
|
34986
|
+
}
|
|
34987
|
+
if (message.kind === "error-response") {
|
|
34988
|
+
const pending = this.#pending.get(message.id);
|
|
34989
|
+
if (pending === void 0) {
|
|
34990
|
+
return;
|
|
34991
|
+
}
|
|
34992
|
+
this.#pending.delete(message.id);
|
|
34993
|
+
pending.completion.reject(
|
|
34994
|
+
new CodexAppServerError("codex_app_server_request_failed", message.message, {
|
|
34995
|
+
cause: { code: message.code }
|
|
34996
|
+
})
|
|
34997
|
+
);
|
|
34998
|
+
return;
|
|
34999
|
+
}
|
|
35000
|
+
if (message.kind === "server-request") {
|
|
35001
|
+
this.#runHandler(
|
|
35002
|
+
this.#handlers.onServerRequest({ id: message.id, method: message.method, params: message.params })
|
|
35003
|
+
);
|
|
35004
|
+
return;
|
|
35005
|
+
}
|
|
35006
|
+
this.#runHandler(this.#handlers.onNotification(message.method, message.params));
|
|
35007
|
+
};
|
|
35008
|
+
/** Sends a request and waits for its response, bounded by the caller's cancellation signal. */
|
|
35009
|
+
request = async (method, params, signal) => {
|
|
35010
|
+
signal.throwIfAborted();
|
|
35011
|
+
if (this.#closed) {
|
|
35012
|
+
throw new CodexAppServerError("codex_app_server_closed", "The Codex app-server is closed");
|
|
35013
|
+
}
|
|
35014
|
+
const id = this.#nextRequestId;
|
|
35015
|
+
this.#nextRequestId += 1;
|
|
35016
|
+
const completion = Promise.withResolvers();
|
|
35017
|
+
this.#pending.set(id, { completion });
|
|
35018
|
+
const abort = () => {
|
|
35019
|
+
if (this.#pending.delete(id)) {
|
|
35020
|
+
completion.reject(signal.reason ?? new Error("Codex app-server request was cancelled"));
|
|
35021
|
+
}
|
|
35022
|
+
};
|
|
35023
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
35024
|
+
try {
|
|
35025
|
+
this.#write({ id, method, params });
|
|
35026
|
+
return await Promise.race([completion.promise, this.#processExit.then(() => this.#exitedFailure(method))]);
|
|
35027
|
+
} finally {
|
|
35028
|
+
signal.removeEventListener("abort", abort);
|
|
35029
|
+
this.#pending.delete(id);
|
|
35030
|
+
}
|
|
35031
|
+
};
|
|
35032
|
+
notify = (method, params) => {
|
|
35033
|
+
this.#write({ method, params });
|
|
35034
|
+
};
|
|
35035
|
+
respond = (id, result) => {
|
|
35036
|
+
this.#write({ id, result });
|
|
35037
|
+
};
|
|
35038
|
+
respondWithError = (id, code, message) => {
|
|
35039
|
+
this.#write({ error: { code, message }, id });
|
|
35040
|
+
};
|
|
35041
|
+
#write = (message) => {
|
|
35042
|
+
if (this.#closed) {
|
|
35043
|
+
return;
|
|
35044
|
+
}
|
|
35045
|
+
const stdin = this.#child.stdin;
|
|
35046
|
+
if (stdin === null || stdin.destroyed) {
|
|
35047
|
+
throw new CodexAppServerError("codex_app_server_closed", "The Codex app-server input is closed");
|
|
35048
|
+
}
|
|
35049
|
+
stdin.write(`${JSON.stringify(message)}
|
|
35050
|
+
`);
|
|
35051
|
+
};
|
|
35052
|
+
/** Performs the `initialize` / `initialized` handshake. */
|
|
35053
|
+
initialize = async (signal) => {
|
|
35054
|
+
await this.request(
|
|
35055
|
+
"initialize",
|
|
35056
|
+
{ clientInfo: { name: "mobius", version: "1.0.0" } },
|
|
35057
|
+
AbortSignal.any([signal, AbortSignal.timeout(INITIALIZE_TIMEOUT_MILLISECONDS)])
|
|
35058
|
+
);
|
|
35059
|
+
this.notify("initialized", void 0);
|
|
35060
|
+
};
|
|
35061
|
+
/**
|
|
35062
|
+
* Rejects every in-flight request and marks the conversation closed without waiting on the
|
|
35063
|
+
* process. Process teardown stays with the caller, which owns the process tree: it stops the
|
|
35064
|
+
* app-server and every tool subprocess it started.
|
|
35065
|
+
*/
|
|
35066
|
+
detach = () => {
|
|
35067
|
+
if (this.#closed) {
|
|
35068
|
+
return;
|
|
35069
|
+
}
|
|
35070
|
+
this.#closed = true;
|
|
35071
|
+
this.#fail(new CodexAppServerError("codex_app_server_closed", "The Codex app-server is closed"));
|
|
35072
|
+
const stdin = this.#child.stdin;
|
|
35073
|
+
if (stdin !== null && !stdin.destroyed) {
|
|
35074
|
+
stdin.end();
|
|
35075
|
+
}
|
|
35076
|
+
};
|
|
35077
|
+
};
|
|
35078
|
+
|
|
35079
|
+
// src/acp/codex/items.ts
|
|
35080
|
+
var TOOL_OUTPUT_CHARACTER_LIMIT = 32768;
|
|
35081
|
+
var TITLE_CHARACTER_LIMIT = 500;
|
|
35082
|
+
var CODEX_META_KEY = "codex";
|
|
35083
|
+
function truncate4(value, limit) {
|
|
35084
|
+
return value.length <= limit ? value : value.slice(0, limit);
|
|
35085
|
+
}
|
|
35086
|
+
function textContent(text3) {
|
|
35087
|
+
const block = { text: truncate4(text3, TOOL_OUTPUT_CHARACTER_LIMIT), type: "text" };
|
|
35088
|
+
return { content: block, type: "content" };
|
|
35089
|
+
}
|
|
35090
|
+
function firstLine(value) {
|
|
35091
|
+
const line = value.split("\n", 1)[0] ?? "";
|
|
35092
|
+
return line.trim().length > 0 ? line.trim() : value.trim();
|
|
35093
|
+
}
|
|
35094
|
+
function commandStatus(status) {
|
|
35095
|
+
if (status === "inProgress") {
|
|
35096
|
+
return "in_progress";
|
|
35097
|
+
}
|
|
35098
|
+
return status === "completed" ? "completed" : "failed";
|
|
35099
|
+
}
|
|
35100
|
+
function patchStatus(status) {
|
|
35101
|
+
if (status === "inProgress") {
|
|
35102
|
+
return "in_progress";
|
|
35103
|
+
}
|
|
35104
|
+
return status === "completed" ? "completed" : "failed";
|
|
35105
|
+
}
|
|
35106
|
+
function mcpStatus(status) {
|
|
35107
|
+
return status === "inProgress" ? "in_progress" : status === "completed" ? "completed" : "failed";
|
|
35108
|
+
}
|
|
35109
|
+
function presentToolItem(item) {
|
|
35110
|
+
if (item.type === "commandExecution") {
|
|
35111
|
+
const output2 = item.aggregatedOutput ?? "";
|
|
35112
|
+
const content3 = [];
|
|
35113
|
+
if (output2.length > 0) {
|
|
35114
|
+
content3.push(textContent(output2));
|
|
35115
|
+
}
|
|
35116
|
+
if (item.exitCode != null && item.exitCode !== 0) {
|
|
35117
|
+
content3.push(textContent(`Exit code ${item.exitCode}`));
|
|
35118
|
+
}
|
|
35119
|
+
return {
|
|
35120
|
+
content: content3,
|
|
35121
|
+
kind: "execute",
|
|
35122
|
+
locations: [],
|
|
35123
|
+
rawInput: { command: item.command, cwd: item.cwd },
|
|
35124
|
+
rawOutput: { exitCode: item.exitCode, output: truncate4(output2, TOOL_OUTPUT_CHARACTER_LIMIT) },
|
|
35125
|
+
status: commandStatus(item.status),
|
|
35126
|
+
title: truncate4(firstLine(item.command), TITLE_CHARACTER_LIMIT)
|
|
35127
|
+
};
|
|
35128
|
+
}
|
|
35129
|
+
if (item.type === "fileChange") {
|
|
35130
|
+
const paths = item.changes.map((change) => change.path);
|
|
35131
|
+
const content3 = item.changes.map((change) => ({
|
|
35132
|
+
newText: truncate4(change.diff, TOOL_OUTPUT_CHARACTER_LIMIT),
|
|
35133
|
+
path: change.path,
|
|
35134
|
+
type: "diff"
|
|
35135
|
+
}));
|
|
35136
|
+
return {
|
|
35137
|
+
content: content3,
|
|
35138
|
+
kind: "edit",
|
|
35139
|
+
locations: paths.map((path2) => ({ path: path2 })),
|
|
35140
|
+
rawInput: { changes: item.changes.map((change) => change.path) },
|
|
35141
|
+
rawOutput: null,
|
|
35142
|
+
status: patchStatus(item.status),
|
|
35143
|
+
title: truncate4(paths.join(", "), TITLE_CHARACTER_LIMIT)
|
|
35144
|
+
};
|
|
35145
|
+
}
|
|
35146
|
+
if (item.type === "mcpToolCall") {
|
|
35147
|
+
const label = `${item.server}/${item.tool}`;
|
|
35148
|
+
const content3 = [];
|
|
35149
|
+
if (item.result != null) {
|
|
35150
|
+
content3.push(textContent(JSON.stringify(item.result)));
|
|
35151
|
+
}
|
|
35152
|
+
if (item.error != null) {
|
|
35153
|
+
content3.push(textContent(JSON.stringify(item.error)));
|
|
35154
|
+
}
|
|
35155
|
+
return {
|
|
35156
|
+
content: content3,
|
|
35157
|
+
kind: "other",
|
|
35158
|
+
locations: [],
|
|
35159
|
+
rawInput: item.arguments ?? null,
|
|
35160
|
+
rawOutput: item.error ?? item.result ?? null,
|
|
35161
|
+
status: mcpStatus(item.status),
|
|
35162
|
+
title: truncate4(label, TITLE_CHARACTER_LIMIT)
|
|
35163
|
+
};
|
|
35164
|
+
}
|
|
35165
|
+
if (item.type === "dynamicToolCall") {
|
|
35166
|
+
const label = item.namespace == null ? item.tool : `${item.namespace}/${item.tool}`;
|
|
35167
|
+
const content3 = (item.contentItems ?? []).map((entry) => textContent(JSON.stringify(entry)));
|
|
35168
|
+
return {
|
|
35169
|
+
content: content3,
|
|
35170
|
+
kind: "other",
|
|
35171
|
+
locations: [],
|
|
35172
|
+
rawInput: item.arguments ?? null,
|
|
35173
|
+
rawOutput: item.success === true ? null : item.contentItems ?? null,
|
|
35174
|
+
status: mcpStatus(item.status),
|
|
35175
|
+
title: truncate4(label, TITLE_CHARACTER_LIMIT)
|
|
35176
|
+
};
|
|
35177
|
+
}
|
|
35178
|
+
return null;
|
|
35179
|
+
}
|
|
35180
|
+
function toolCallUpdate(item) {
|
|
35181
|
+
const presentation = presentToolItem(item);
|
|
35182
|
+
if (presentation === null) {
|
|
35183
|
+
return null;
|
|
35184
|
+
}
|
|
35185
|
+
return {
|
|
35186
|
+
content: [...presentation.content],
|
|
35187
|
+
kind: presentation.kind,
|
|
35188
|
+
locations: [...presentation.locations],
|
|
35189
|
+
rawInput: presentation.rawInput,
|
|
35190
|
+
rawOutput: presentation.rawOutput,
|
|
35191
|
+
status: presentation.status,
|
|
35192
|
+
title: presentation.title,
|
|
35193
|
+
toolCallId: item.id
|
|
35194
|
+
};
|
|
35195
|
+
}
|
|
35196
|
+
function decodeThreadItem(value) {
|
|
35197
|
+
const decoded = threadItemSchema.safeParse(value);
|
|
35198
|
+
return decoded.success ? decoded.data : null;
|
|
35199
|
+
}
|
|
35200
|
+
function agentMessageMeta(phase) {
|
|
35201
|
+
if (phase == null) {
|
|
35202
|
+
return null;
|
|
35203
|
+
}
|
|
35204
|
+
return { [CODEX_META_KEY]: { phase } };
|
|
35205
|
+
}
|
|
35206
|
+
|
|
35207
|
+
// src/acp/codex/agent.ts
|
|
35208
|
+
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
35209
|
+
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
35210
|
+
var CODEX_AGENT_VERSION = "0.154.0";
|
|
35211
|
+
var MODEL_SETTING_ID = "model";
|
|
35212
|
+
var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
|
|
35213
|
+
var MODE_SETTING_ID = "mode";
|
|
35214
|
+
var FAST_MODE_SETTING_ID = "fast-mode";
|
|
35215
|
+
var MODEL_CATALOG_LIMIT = 1e3;
|
|
35216
|
+
var FAST_TIER = "fast";
|
|
35217
|
+
var SERVICE_TIER_FAST = "priority";
|
|
35218
|
+
var WORKSPACE_WRITE_POLICY = Object.freeze({
|
|
35219
|
+
excludeSlashTmp: false,
|
|
35220
|
+
excludeTmpdirEnvVar: false,
|
|
35221
|
+
networkAccess: false,
|
|
35222
|
+
type: "workspaceWrite",
|
|
35223
|
+
writableRoots: []
|
|
35224
|
+
});
|
|
35225
|
+
var READ_ONLY_MODE = Object.freeze({
|
|
35226
|
+
approvalPolicy: "on-request",
|
|
35227
|
+
approvalsReviewer: "user",
|
|
35228
|
+
description: "Always ask to edit external files and use the internet",
|
|
35229
|
+
id: "read-only",
|
|
35230
|
+
name: "Ask for approval",
|
|
35231
|
+
sandboxPolicy: WORKSPACE_WRITE_POLICY
|
|
35232
|
+
});
|
|
35233
|
+
var AGENT_MODE = Object.freeze({
|
|
35234
|
+
approvalPolicy: "on-request",
|
|
35235
|
+
approvalsReviewer: "auto_review",
|
|
35236
|
+
description: "Only ask for actions detected as potentially unsafe",
|
|
35237
|
+
id: "agent",
|
|
35238
|
+
name: "Approve for me",
|
|
35239
|
+
sandboxPolicy: WORKSPACE_WRITE_POLICY
|
|
35240
|
+
});
|
|
35241
|
+
var FULL_ACCESS_MODE = Object.freeze({
|
|
35242
|
+
approvalPolicy: "never",
|
|
35243
|
+
approvalsReviewer: "user",
|
|
35244
|
+
description: "Unrestricted access to the internet and any file on your computer",
|
|
35245
|
+
id: "agent-full-access",
|
|
35246
|
+
name: "Full access",
|
|
35247
|
+
sandboxPolicy: { type: "dangerFullAccess" }
|
|
35248
|
+
});
|
|
35249
|
+
var AGENT_MODES = Object.freeze([READ_ONLY_MODE, AGENT_MODE, FULL_ACCESS_MODE]);
|
|
35250
|
+
var DEFAULT_MODE = AGENT_MODE;
|
|
35251
|
+
function initialMode(environment) {
|
|
35252
|
+
const requested = environment["INITIAL_AGENT_MODE"];
|
|
35253
|
+
if (requested === void 0) {
|
|
35254
|
+
return DEFAULT_MODE.id;
|
|
35255
|
+
}
|
|
35256
|
+
return AGENT_MODES.some((mode) => mode.id === requested) ? requested : DEFAULT_MODE.id;
|
|
35257
|
+
}
|
|
35258
|
+
function capitalize(value) {
|
|
35259
|
+
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
35260
|
+
}
|
|
35261
|
+
var APPROVAL_OPTIONS = Object.freeze([
|
|
35262
|
+
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
35263
|
+
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
35264
|
+
{ kind: "reject_once", name: "Deny", optionId: "decline" }
|
|
35265
|
+
]);
|
|
35266
|
+
function permissionDecision(optionId) {
|
|
35267
|
+
if (optionId === "accept" || optionId === "acceptForSession" || optionId === "decline") {
|
|
35268
|
+
return optionId;
|
|
35269
|
+
}
|
|
35270
|
+
return "cancel";
|
|
35271
|
+
}
|
|
35272
|
+
function promptInput(prompt) {
|
|
35273
|
+
const input2 = [];
|
|
35274
|
+
for (const block of prompt) {
|
|
35275
|
+
if (block.type === "text") {
|
|
35276
|
+
input2.push({ text: block.text, text_elements: [], type: "text" });
|
|
35277
|
+
continue;
|
|
35278
|
+
}
|
|
35279
|
+
if (block.type === "image") {
|
|
35280
|
+
input2.push({ type: "image", url: `data:${block.mimeType};base64,${block.data}` });
|
|
35281
|
+
continue;
|
|
35282
|
+
}
|
|
35283
|
+
if (block.type === "resource") {
|
|
35284
|
+
const resource = block.resource;
|
|
35285
|
+
input2.push({
|
|
35286
|
+
text: "text" in resource ? resource.text ?? "" : "",
|
|
35287
|
+
text_elements: [],
|
|
35288
|
+
type: "text"
|
|
35289
|
+
});
|
|
35290
|
+
continue;
|
|
35291
|
+
}
|
|
35292
|
+
if (block.type === "resource_link") {
|
|
35293
|
+
input2.push({ text: `Resource: ${block.uri}`, text_elements: [], type: "text" });
|
|
35294
|
+
}
|
|
35295
|
+
}
|
|
35296
|
+
return input2;
|
|
35297
|
+
}
|
|
35298
|
+
function modelValues(models) {
|
|
35299
|
+
return models.map((model) => ({
|
|
35300
|
+
description: model.description ?? "",
|
|
35301
|
+
name: model.displayName ?? model.id,
|
|
35302
|
+
value: model.id
|
|
35303
|
+
}));
|
|
35304
|
+
}
|
|
35305
|
+
function effortValues(model) {
|
|
35306
|
+
return (model?.supportedReasoningEfforts ?? []).map((option) => ({
|
|
35307
|
+
description: option.description ?? "",
|
|
35308
|
+
name: capitalize(option.reasoningEffort),
|
|
35309
|
+
value: option.reasoningEffort
|
|
35310
|
+
}));
|
|
35311
|
+
}
|
|
35312
|
+
function modelSetting(models, currentValue) {
|
|
35313
|
+
const values = modelValues(models);
|
|
35314
|
+
const current = currentValue.length > 0 ? currentValue : models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "";
|
|
35315
|
+
if (current.length === 0) {
|
|
35316
|
+
return null;
|
|
35317
|
+
}
|
|
35318
|
+
const options = values.some((value) => value.value === current) ? values : [{ description: "", name: current, value: current }, ...values];
|
|
35319
|
+
return {
|
|
35320
|
+
category: "model",
|
|
35321
|
+
currentValue: current,
|
|
35322
|
+
description: "Model Codex uses for the session",
|
|
35323
|
+
id: MODEL_SETTING_ID,
|
|
35324
|
+
name: "Model",
|
|
35325
|
+
options,
|
|
35326
|
+
type: "select"
|
|
35327
|
+
};
|
|
35328
|
+
}
|
|
35329
|
+
function modeSetting(currentValue) {
|
|
35330
|
+
return {
|
|
35331
|
+
category: "mode",
|
|
35332
|
+
currentValue,
|
|
35333
|
+
description: "Approval and sandboxing preset for the session",
|
|
35334
|
+
id: MODE_SETTING_ID,
|
|
35335
|
+
name: "Mode",
|
|
35336
|
+
options: AGENT_MODES.map((mode) => ({
|
|
35337
|
+
description: mode.description,
|
|
35338
|
+
name: mode.name,
|
|
35339
|
+
value: mode.id
|
|
35340
|
+
})),
|
|
35341
|
+
type: "select"
|
|
35342
|
+
};
|
|
35343
|
+
}
|
|
35344
|
+
function fastModeSetting(model, enabled) {
|
|
35345
|
+
if (model?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
35346
|
+
return null;
|
|
35347
|
+
}
|
|
35348
|
+
return {
|
|
35349
|
+
category: "model_config",
|
|
35350
|
+
currentValue: enabled,
|
|
35351
|
+
description: "1.5x speed, increased usage",
|
|
35352
|
+
id: FAST_MODE_SETTING_ID,
|
|
35353
|
+
name: "Fast mode",
|
|
35354
|
+
type: "boolean"
|
|
35355
|
+
};
|
|
35356
|
+
}
|
|
35357
|
+
function effortSetting(model, currentValue) {
|
|
35358
|
+
const values = effortValues(model);
|
|
35359
|
+
if (values.length === 0) {
|
|
35360
|
+
return null;
|
|
35361
|
+
}
|
|
35362
|
+
const current = values.some((value) => value.value === currentValue) ? currentValue : values[0]?.value ?? "";
|
|
35363
|
+
if (current.length === 0) {
|
|
35364
|
+
return null;
|
|
35365
|
+
}
|
|
35366
|
+
return {
|
|
35367
|
+
category: "thought_level",
|
|
35368
|
+
currentValue: current,
|
|
35369
|
+
description: "How much reasoning effort the model should use",
|
|
35370
|
+
id: REASONING_EFFORT_SETTING_ID,
|
|
35371
|
+
name: "Reasoning effort",
|
|
35372
|
+
options: values,
|
|
35373
|
+
type: "select"
|
|
35374
|
+
};
|
|
35375
|
+
}
|
|
35376
|
+
function userInputSchema(questions) {
|
|
35377
|
+
const properties = {};
|
|
35378
|
+
const required2 = [];
|
|
35379
|
+
for (const question of questions) {
|
|
35380
|
+
required2.push(question.id);
|
|
35381
|
+
properties[question.id] = {
|
|
35382
|
+
description: question.question,
|
|
35383
|
+
title: question.header,
|
|
35384
|
+
type: "string",
|
|
35385
|
+
...question.options == null || question.options.length === 0 ? {} : {
|
|
35386
|
+
oneOf: question.options.map((option) => ({
|
|
35387
|
+
const: option.label,
|
|
35388
|
+
description: option.description,
|
|
35389
|
+
title: option.label
|
|
35390
|
+
}))
|
|
35391
|
+
}
|
|
35392
|
+
};
|
|
35393
|
+
}
|
|
35394
|
+
return { properties, required: required2, type: "object" };
|
|
35395
|
+
}
|
|
35396
|
+
var CodexAcpAgent = class {
|
|
35397
|
+
#app;
|
|
35398
|
+
#appServer;
|
|
35399
|
+
#connection = null;
|
|
35400
|
+
#models = [];
|
|
35401
|
+
#nativeSessionId = "";
|
|
35402
|
+
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
35403
|
+
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
35404
|
+
#policySelected = false;
|
|
35405
|
+
#selection;
|
|
35406
|
+
#turn = null;
|
|
35407
|
+
#updateTail = Promise.resolve();
|
|
35408
|
+
constructor(options) {
|
|
35409
|
+
this.#selection = {
|
|
35410
|
+
effort: "",
|
|
35411
|
+
fastMode: false,
|
|
35412
|
+
mode: initialMode(options.environment),
|
|
35413
|
+
model: ""
|
|
35414
|
+
};
|
|
35415
|
+
this.#appServer = new CodexAppServerClient({
|
|
35416
|
+
command: options.command,
|
|
35417
|
+
cwd: options.cwd,
|
|
35418
|
+
environment: options.environment,
|
|
35419
|
+
handlers: {
|
|
35420
|
+
onNotification: async (method, params) => {
|
|
35421
|
+
await this.#onNotification(method, params);
|
|
35422
|
+
},
|
|
35423
|
+
onServerRequest: async (request) => {
|
|
35424
|
+
await this.#onServerRequest(request);
|
|
35425
|
+
}
|
|
35426
|
+
}
|
|
35427
|
+
});
|
|
35428
|
+
this.#app = createAgentApp({ name: "mobius-codex" }).onConnect((connection) => {
|
|
35429
|
+
this.#connection = connection;
|
|
35430
|
+
}).onRequest(methods4.agent.initialize, async () => ({
|
|
35431
|
+
agentCapabilities: {
|
|
35432
|
+
loadSession: false,
|
|
35433
|
+
promptCapabilities: { embeddedContext: true, image: true },
|
|
35434
|
+
sessionCapabilities: { close: {} }
|
|
35435
|
+
},
|
|
35436
|
+
agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
|
|
35437
|
+
authMethods: [],
|
|
35438
|
+
protocolVersion: PROTOCOL_VERSION2
|
|
35439
|
+
})).onRequest(methods4.agent.session.new, async (context) => {
|
|
35440
|
+
const created = threadStartResponseSchema.parse(
|
|
35441
|
+
await this.#appServer.request(
|
|
35442
|
+
"thread/start",
|
|
35443
|
+
{ cwd: context.params.cwd },
|
|
35444
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
35445
|
+
)
|
|
35446
|
+
);
|
|
35447
|
+
this.#nativeSessionId = created.thread.id;
|
|
35448
|
+
this.#selection = {
|
|
35449
|
+
...this.#selection,
|
|
35450
|
+
effort: created.reasoningEffort ?? "",
|
|
35451
|
+
model: created.model ?? ""
|
|
35452
|
+
};
|
|
35453
|
+
return { configOptions: this.#configOptions(), sessionId: created.thread.id };
|
|
35454
|
+
}).onRequest(methods4.agent.session.setConfigOption, async (context) => {
|
|
35455
|
+
this.#applySelection(context.params.configId, context.params.value);
|
|
35456
|
+
return { configOptions: this.#configOptions() };
|
|
35457
|
+
}).onRequest(methods4.agent.session.setMode, async (context) => {
|
|
35458
|
+
this.#applySelection(MODE_SETTING_ID, context.params.modeId);
|
|
35459
|
+
return {};
|
|
35460
|
+
}).onRequest(methods4.agent.session.prompt, async (context) => {
|
|
35461
|
+
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
35462
|
+
}).onRequest(methods4.agent.session.close, async () => {
|
|
35463
|
+
await this.#interruptTurn();
|
|
35464
|
+
}).onNotification(methods4.agent.session.cancel, async () => {
|
|
35465
|
+
await this.#interruptTurn();
|
|
35466
|
+
});
|
|
35467
|
+
}
|
|
35468
|
+
/** The ACP agent app Mobius connects its own ACP client to, in-process. */
|
|
35469
|
+
app = () => this.#app;
|
|
35470
|
+
/** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
|
|
35471
|
+
initialize = async (signal) => {
|
|
35472
|
+
await this.#appServer.initialize(signal);
|
|
35473
|
+
await this.#loadModels(signal);
|
|
35474
|
+
};
|
|
35475
|
+
/**
|
|
35476
|
+
* Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
|
|
35477
|
+
* cancelled or closed session cannot leak the tool subprocesses running under the app-server.
|
|
35478
|
+
*/
|
|
35479
|
+
close = async () => {
|
|
35480
|
+
const child = this.#appServer.child();
|
|
35481
|
+
const captured = await captureProcessTree(child);
|
|
35482
|
+
this.#appServer.detach();
|
|
35483
|
+
await stopProcessTree(child, captured);
|
|
35484
|
+
};
|
|
35485
|
+
/**
|
|
35486
|
+
* Reads the model catalog once per app-server. A failure leaves the catalog empty, which costs
|
|
35487
|
+
* the Run settings panel its model selector; it must not cost the conversation itself, so the
|
|
35488
|
+
* turn lifecycle continues without settings rather than failing initialization.
|
|
35489
|
+
*/
|
|
35490
|
+
#loadModels = async (signal) => {
|
|
35491
|
+
const models = [];
|
|
35492
|
+
let cursor = null;
|
|
35493
|
+
try {
|
|
35494
|
+
do {
|
|
35495
|
+
const decoded = modelListResponseSchema.parse(
|
|
35496
|
+
await this.#appServer.request(
|
|
35497
|
+
"model/list",
|
|
35498
|
+
{ cursor, limit: null },
|
|
35499
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
35500
|
+
)
|
|
35501
|
+
);
|
|
35502
|
+
models.push(...decoded.data);
|
|
35503
|
+
cursor = decoded.nextCursor ?? null;
|
|
35504
|
+
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
35505
|
+
} catch (error62) {
|
|
35506
|
+
signal.throwIfAborted();
|
|
35507
|
+
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
35508
|
+
`);
|
|
35509
|
+
}
|
|
35510
|
+
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
35511
|
+
};
|
|
35512
|
+
#model = (id) => this.#models.find((model) => model.id === id);
|
|
35513
|
+
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
35514
|
+
#configOptions = () => {
|
|
35515
|
+
const options = [];
|
|
35516
|
+
const model = modelSetting(this.#models, this.#selection.model);
|
|
35517
|
+
if (model !== null) {
|
|
35518
|
+
options.push(model);
|
|
35519
|
+
}
|
|
35520
|
+
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
35521
|
+
if (effort !== null) {
|
|
35522
|
+
options.push(effort);
|
|
35523
|
+
}
|
|
35524
|
+
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
35525
|
+
if (fastMode !== null) {
|
|
35526
|
+
options.push(fastMode);
|
|
35527
|
+
}
|
|
35528
|
+
options.push(modeSetting(this.#selection.mode));
|
|
35529
|
+
return options;
|
|
35530
|
+
};
|
|
35531
|
+
/**
|
|
35532
|
+
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
35533
|
+
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
35534
|
+
* so the reply never advertises an effort the selected model cannot run.
|
|
35535
|
+
*/
|
|
35536
|
+
#applySelection = (configId, value) => {
|
|
35537
|
+
if (configId === FAST_MODE_SETTING_ID) {
|
|
35538
|
+
if (typeof value !== "boolean") {
|
|
35539
|
+
throw new AcpExecutionError(
|
|
35540
|
+
"The requested Codex setting is invalid",
|
|
35541
|
+
{},
|
|
35542
|
+
"invalid_session_configuration"
|
|
35543
|
+
);
|
|
35544
|
+
}
|
|
35545
|
+
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
35546
|
+
throw new AcpExecutionError(
|
|
35547
|
+
"The selected Codex model has no fast mode",
|
|
35548
|
+
{},
|
|
35549
|
+
"invalid_session_configuration"
|
|
35550
|
+
);
|
|
35551
|
+
}
|
|
35552
|
+
this.#selection = { ...this.#selection, fastMode: value };
|
|
35553
|
+
return;
|
|
35554
|
+
}
|
|
35555
|
+
if (typeof value !== "string") {
|
|
35556
|
+
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
35557
|
+
}
|
|
35558
|
+
if (configId === MODE_SETTING_ID) {
|
|
35559
|
+
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
35560
|
+
throw new AcpExecutionError(
|
|
35561
|
+
"The requested Codex mode is unavailable",
|
|
35562
|
+
{},
|
|
35563
|
+
"invalid_session_configuration"
|
|
35564
|
+
);
|
|
35565
|
+
}
|
|
35566
|
+
this.#selection = { ...this.#selection, mode: value };
|
|
35567
|
+
this.#policySelected = true;
|
|
35568
|
+
return;
|
|
35569
|
+
}
|
|
35570
|
+
if (configId === MODEL_SETTING_ID) {
|
|
35571
|
+
if (value === this.#selection.model) {
|
|
35572
|
+
return;
|
|
35573
|
+
}
|
|
35574
|
+
const model = this.#model(value);
|
|
35575
|
+
if (model === void 0) {
|
|
35576
|
+
throw new AcpExecutionError(
|
|
35577
|
+
"The requested Codex model is unavailable",
|
|
35578
|
+
{},
|
|
35579
|
+
"invalid_session_configuration"
|
|
35580
|
+
);
|
|
35581
|
+
}
|
|
35582
|
+
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
35583
|
+
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
35584
|
+
this.#selection = {
|
|
35585
|
+
...this.#selection,
|
|
35586
|
+
effort,
|
|
35587
|
+
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
35588
|
+
model: value
|
|
35589
|
+
};
|
|
35590
|
+
return;
|
|
35591
|
+
}
|
|
35592
|
+
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
35593
|
+
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
35594
|
+
(option) => option.reasoningEffort
|
|
35595
|
+
);
|
|
35596
|
+
if (!supported.includes(value)) {
|
|
35597
|
+
throw new AcpExecutionError(
|
|
35598
|
+
"The requested Codex reasoning effort is unavailable",
|
|
35599
|
+
{},
|
|
35600
|
+
"invalid_session_configuration"
|
|
35601
|
+
);
|
|
35602
|
+
}
|
|
35603
|
+
this.#selection = { ...this.#selection, effort: value };
|
|
35604
|
+
return;
|
|
35605
|
+
}
|
|
35606
|
+
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
35607
|
+
};
|
|
35608
|
+
#emit = async (update) => {
|
|
35609
|
+
const connection = this.#connection;
|
|
35610
|
+
if (connection === null || this.#nativeSessionId.length === 0) {
|
|
35611
|
+
return;
|
|
35612
|
+
}
|
|
35613
|
+
await connection.client.notify(methods4.client.session.update, {
|
|
35614
|
+
sessionId: this.#nativeSessionId,
|
|
35615
|
+
update
|
|
35616
|
+
});
|
|
35617
|
+
};
|
|
35618
|
+
// Notifications are serialized so two app-server items cannot interleave into one ACP update
|
|
35619
|
+
// stream, and the caller awaits the result: `turn/completed` must not resolve the prompt before
|
|
35620
|
+
// the updates it precedes have reached the client.
|
|
35621
|
+
#enqueue = async (operation) => {
|
|
35622
|
+
const pending = this.#updateTail.then(operation, operation);
|
|
35623
|
+
this.#updateTail = pending;
|
|
35624
|
+
await pending;
|
|
35625
|
+
};
|
|
35626
|
+
#onNotification = async (method, params) => {
|
|
35627
|
+
if (method === "turn/started") {
|
|
35628
|
+
const decoded = turnNotificationSchema.safeParse(params);
|
|
35629
|
+
if (decoded.success && decoded.data.threadId === this.#nativeSessionId && this.#turn !== null) {
|
|
35630
|
+
this.#turn = { completion: this.#turn.completion, turn: { id: decoded.data.turn.id } };
|
|
35631
|
+
}
|
|
35632
|
+
return;
|
|
35633
|
+
}
|
|
35634
|
+
if (method === "turn/completed") {
|
|
35635
|
+
const decoded = turnNotificationSchema.safeParse(params);
|
|
35636
|
+
if (decoded.success && decoded.data.threadId === this.#nativeSessionId) {
|
|
35637
|
+
await this.#completeTurn(decoded.data.turn);
|
|
35638
|
+
}
|
|
35639
|
+
return;
|
|
35640
|
+
}
|
|
35641
|
+
if (method === "thread/name/updated") {
|
|
35642
|
+
const threadName = params.threadName;
|
|
35643
|
+
if (typeof threadName === "string" && threadName.length > 0) {
|
|
35644
|
+
await this.#enqueue(async () => {
|
|
35645
|
+
await this.#emit({ sessionUpdate: "session_info_update", title: threadName });
|
|
35646
|
+
});
|
|
35647
|
+
}
|
|
35648
|
+
return;
|
|
35649
|
+
}
|
|
35650
|
+
if (method === "turn/plan/updated") {
|
|
35651
|
+
const plan = params.plan;
|
|
35652
|
+
if (Array.isArray(plan) && params.threadId === this.#nativeSessionId) {
|
|
35653
|
+
const entries = plan.map((step) => ({
|
|
35654
|
+
content: typeof step === "object" && step !== null && "step" in step ? String(Reflect.get(step, "step")) : "",
|
|
35655
|
+
priority: "medium",
|
|
35656
|
+
status: "in_progress"
|
|
35657
|
+
}));
|
|
35658
|
+
await this.#enqueue(async () => {
|
|
35659
|
+
await this.#emit({ entries, sessionUpdate: "plan" });
|
|
35660
|
+
});
|
|
35661
|
+
}
|
|
35662
|
+
return;
|
|
35663
|
+
}
|
|
35664
|
+
if (method !== "item/started" && method !== "item/completed") {
|
|
35665
|
+
return;
|
|
35666
|
+
}
|
|
35667
|
+
const item = decodeThreadItem(params.item);
|
|
35668
|
+
if (item === null) {
|
|
35669
|
+
return;
|
|
35670
|
+
}
|
|
35671
|
+
if (item.type === "agentMessage") {
|
|
35672
|
+
if (method === "item/started") {
|
|
35673
|
+
return;
|
|
35674
|
+
}
|
|
35675
|
+
await this.#enqueue(async () => {
|
|
35676
|
+
await this.#emit({
|
|
35677
|
+
_meta: agentMessageMeta(item.phase),
|
|
35678
|
+
content: { text: item.text, type: "text" },
|
|
35679
|
+
messageId: item.id,
|
|
35680
|
+
sessionUpdate: "agent_message_chunk"
|
|
35681
|
+
});
|
|
35682
|
+
});
|
|
35683
|
+
return;
|
|
35684
|
+
}
|
|
35685
|
+
const update = toolCallUpdate(item);
|
|
35686
|
+
if (update !== null) {
|
|
35687
|
+
await this.#enqueue(async () => {
|
|
35688
|
+
await this.#emit({ ...update, sessionUpdate: "tool_call_update" });
|
|
35689
|
+
});
|
|
35690
|
+
}
|
|
35691
|
+
};
|
|
35692
|
+
#onServerRequest = async (request) => {
|
|
35693
|
+
if (request.method === "item/commandExecution/requestApproval" || request.method === "item/fileChange/requestApproval") {
|
|
35694
|
+
await this.#requestApproval(request);
|
|
35695
|
+
return;
|
|
35696
|
+
}
|
|
35697
|
+
if (request.method === "item/tool/requestUserInput") {
|
|
35698
|
+
await this.#requestUserInput(request);
|
|
35699
|
+
return;
|
|
35700
|
+
}
|
|
35701
|
+
if (request.method === "mcpServer/elicitation/request") {
|
|
35702
|
+
await this.#requestMcpElicitation(request);
|
|
35703
|
+
return;
|
|
35704
|
+
}
|
|
35705
|
+
this.#appServer.respondWithError(request.id, -32601, `Mobius does not support ${request.method}`);
|
|
35706
|
+
};
|
|
35707
|
+
#askPermission = async (title2, toolCallId, signal) => {
|
|
35708
|
+
const connection = this.#connection;
|
|
35709
|
+
if (connection === null) {
|
|
35710
|
+
return "cancel";
|
|
35711
|
+
}
|
|
35712
|
+
const response = await connection.client.request(
|
|
35713
|
+
methods4.client.session.requestPermission,
|
|
35714
|
+
{
|
|
35715
|
+
options: [...APPROVAL_OPTIONS],
|
|
35716
|
+
sessionId: this.#nativeSessionId,
|
|
35717
|
+
toolCall: { title: title2, toolCallId }
|
|
35718
|
+
},
|
|
35719
|
+
{ cancellationSignal: signal }
|
|
35720
|
+
);
|
|
35721
|
+
return response.outcome.outcome === "selected" ? permissionDecision(response.outcome.optionId) : "cancel";
|
|
35722
|
+
};
|
|
35723
|
+
#requestApproval = async (request) => {
|
|
35724
|
+
const decoded = request.method === "item/commandExecution/requestApproval" ? commandApprovalParamsSchema.safeParse(request.params) : fileChangeApprovalParamsSchema.safeParse(request.params);
|
|
35725
|
+
if (!decoded.success) {
|
|
35726
|
+
this.#appServer.respondWithError(request.id, -32602, "Mobius could not read the approval request");
|
|
35727
|
+
return;
|
|
35728
|
+
}
|
|
35729
|
+
const params = decoded.data;
|
|
35730
|
+
const command = "command" in params ? params.command : void 0;
|
|
35731
|
+
const title2 = (command ?? params.reason ?? "Approve a local change").slice(0, APPROVAL_REASON_CHARACTER_LIMIT);
|
|
35732
|
+
const turn = this.#turn;
|
|
35733
|
+
const decision = await this.#askPermission(
|
|
35734
|
+
title2,
|
|
35735
|
+
params.itemId,
|
|
35736
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
|
|
35737
|
+
);
|
|
35738
|
+
void turn;
|
|
35739
|
+
this.#appServer.respond(request.id, { decision });
|
|
35740
|
+
};
|
|
35741
|
+
#requestUserInput = async (request) => {
|
|
35742
|
+
const decoded = requestUserInputParamsSchema.safeParse(request.params);
|
|
35743
|
+
const connection = this.#connection;
|
|
35744
|
+
if (!decoded.success || connection === null) {
|
|
35745
|
+
this.#appServer.respond(request.id, { answers: {} });
|
|
35746
|
+
return;
|
|
35747
|
+
}
|
|
35748
|
+
const questions = decoded.data.questions;
|
|
35749
|
+
const response = await connection.client.request(
|
|
35750
|
+
methods4.client.elicitation.create,
|
|
35751
|
+
{
|
|
35752
|
+
message: questions.map((question) => question.question).join("\n\n").slice(0, 2e3),
|
|
35753
|
+
mode: "form",
|
|
35754
|
+
requestedSchema: userInputSchema(questions),
|
|
35755
|
+
sessionId: this.#nativeSessionId,
|
|
35756
|
+
...decoded.data.itemId == null ? {} : { toolCallId: decoded.data.itemId }
|
|
35757
|
+
},
|
|
35758
|
+
{ cancellationSignal: AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS) }
|
|
35759
|
+
);
|
|
35760
|
+
const content3 = response.action === "accept" ? Reflect.get(response, "content") : void 0;
|
|
35761
|
+
const answers = {};
|
|
35762
|
+
for (const question of questions) {
|
|
35763
|
+
const value = typeof content3 === "object" && content3 !== null ? Reflect.get(content3, question.id) : void 0;
|
|
35764
|
+
answers[question.id] = { answers: typeof value === "string" && value.length > 0 ? [value] : [] };
|
|
35765
|
+
}
|
|
35766
|
+
this.#appServer.respond(request.id, { answers });
|
|
35767
|
+
};
|
|
35768
|
+
#requestMcpElicitation = async (request) => {
|
|
35769
|
+
const decoded = mcpElicitationParamsSchema.safeParse(request.params);
|
|
35770
|
+
const connection = this.#connection;
|
|
35771
|
+
if (!decoded.success || connection === null) {
|
|
35772
|
+
this.#appServer.respondWithError(request.id, -32602, "Mobius could not read the elicitation request");
|
|
35773
|
+
return;
|
|
35774
|
+
}
|
|
35775
|
+
const params = decoded.data;
|
|
35776
|
+
const signal = AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS);
|
|
35777
|
+
if (params.mode === "url" && params.url !== void 0) {
|
|
35778
|
+
const response2 = await connection.client.request(
|
|
35779
|
+
methods4.client.elicitation.create,
|
|
35780
|
+
{
|
|
35781
|
+
elicitationId: `${this.#nativeSessionId}-${String(request.id)}`,
|
|
35782
|
+
message: params.message,
|
|
35783
|
+
mode: "url",
|
|
35784
|
+
sessionId: this.#nativeSessionId,
|
|
35785
|
+
url: params.url
|
|
35786
|
+
},
|
|
35787
|
+
{ cancellationSignal: signal }
|
|
35788
|
+
);
|
|
35789
|
+
this.#appServer.respond(request.id, { action: response2.action });
|
|
35790
|
+
return;
|
|
35791
|
+
}
|
|
35792
|
+
const response = await connection.client.request(
|
|
35793
|
+
methods4.client.elicitation.create,
|
|
35794
|
+
{
|
|
35795
|
+
message: params.message,
|
|
35796
|
+
mode: "form",
|
|
35797
|
+
requestedSchema: params.requestedSchema ?? { properties: {}, required: [], type: "object" },
|
|
35798
|
+
sessionId: this.#nativeSessionId
|
|
35799
|
+
},
|
|
35800
|
+
{ cancellationSignal: signal }
|
|
35801
|
+
);
|
|
35802
|
+
const content3 = response.action === "accept" ? Reflect.get(response, "content") ?? null : null;
|
|
35803
|
+
this.#appServer.respond(request.id, { action: response.action, content: content3 });
|
|
35804
|
+
};
|
|
35805
|
+
#runTurn = async (input2, signal) => {
|
|
35806
|
+
if (this.#turn !== null) {
|
|
35807
|
+
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
35808
|
+
}
|
|
35809
|
+
const completion = Promise.withResolvers();
|
|
35810
|
+
const turn = { completion, turn: { id: "" } };
|
|
35811
|
+
this.#turn = turn;
|
|
35812
|
+
try {
|
|
35813
|
+
const selection = this.#selection;
|
|
35814
|
+
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
35815
|
+
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
35816
|
+
const started = turnSchema.parse(
|
|
35817
|
+
(await this.#appServer.request(
|
|
35818
|
+
"turn/start",
|
|
35819
|
+
{
|
|
35820
|
+
// Until a mode is chosen, `config.toml` decides the sandbox and approval
|
|
35821
|
+
// policy, and those fields stay off the turn so the host's own setup is
|
|
35822
|
+
// inherited rather than overridden.
|
|
35823
|
+
...this.#policySelected ? {
|
|
35824
|
+
approvalPolicy: mode.approvalPolicy,
|
|
35825
|
+
approvalsReviewer: mode.approvalsReviewer,
|
|
35826
|
+
sandboxPolicy: mode.sandboxPolicy
|
|
35827
|
+
} : {},
|
|
35828
|
+
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
35829
|
+
input: input2,
|
|
35830
|
+
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
35831
|
+
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
|
|
35832
|
+
threadId: this.#nativeSessionId
|
|
35833
|
+
},
|
|
35834
|
+
signal
|
|
35835
|
+
)).turn
|
|
35836
|
+
);
|
|
35837
|
+
if (this.#turn === turn) {
|
|
35838
|
+
turn.turn.id = started.id;
|
|
35839
|
+
}
|
|
35840
|
+
return await completion.promise;
|
|
35841
|
+
} finally {
|
|
35842
|
+
if (this.#turn === turn) {
|
|
35843
|
+
this.#turn = null;
|
|
35844
|
+
}
|
|
35845
|
+
}
|
|
35846
|
+
};
|
|
35847
|
+
#interruptTurn = async () => {
|
|
35848
|
+
const turn = this.#turn;
|
|
35849
|
+
if (turn === null) {
|
|
35850
|
+
return;
|
|
35851
|
+
}
|
|
35852
|
+
this.#turn = null;
|
|
35853
|
+
if (turn.turn.id.length > 0) {
|
|
35854
|
+
try {
|
|
35855
|
+
await this.#appServer.request(
|
|
35856
|
+
"turn/interrupt",
|
|
35857
|
+
{ threadId: this.#nativeSessionId, turnId: turn.turn.id },
|
|
35858
|
+
AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)
|
|
35859
|
+
);
|
|
35860
|
+
} catch {
|
|
35861
|
+
}
|
|
35862
|
+
}
|
|
35863
|
+
turn.completion.resolve({ stopReason: "cancelled" });
|
|
35864
|
+
};
|
|
35865
|
+
#completeTurn = async (turn) => {
|
|
35866
|
+
const active = this.#turn;
|
|
35867
|
+
if (active === null) {
|
|
35868
|
+
return;
|
|
35869
|
+
}
|
|
35870
|
+
this.#turn = null;
|
|
35871
|
+
await this.#updateTail;
|
|
35872
|
+
if (turn.status === "failed") {
|
|
35873
|
+
active.completion.reject(
|
|
35874
|
+
new AcpExecutionError(turn.error?.message ?? "The Codex turn failed", {}, "codex_turn_failed")
|
|
35875
|
+
);
|
|
35876
|
+
return;
|
|
35877
|
+
}
|
|
35878
|
+
active.completion.resolve({ stopReason: turn.status === "interrupted" ? "cancelled" : "end_turn" });
|
|
35879
|
+
};
|
|
35880
|
+
};
|
|
35881
|
+
|
|
35882
|
+
// src/agent-catalog/agents/codex-agent.ts
|
|
35883
|
+
var CodexAgentSpecification = class extends InProcessAcpAgentDefinition2 {
|
|
35884
|
+
versionProbeTimeoutMilliseconds = 1e4;
|
|
35885
|
+
agentExecutable = "codex";
|
|
35886
|
+
createEndpoint = (options) => new CodexAcpAgent(options);
|
|
35887
|
+
id = "codex";
|
|
35888
|
+
label = "Codex";
|
|
35889
|
+
constructor() {
|
|
35890
|
+
super("MOBIUS_CODEX_PATH", ["agents", "codex", "bin", "codex"]);
|
|
35891
|
+
}
|
|
35892
|
+
};
|
|
35893
|
+
|
|
35894
|
+
// src/agent-catalog/agent-probe-error.ts
|
|
35895
|
+
var AgentProbeError = class extends Error {
|
|
35896
|
+
code;
|
|
35897
|
+
constructor(code, message, options = {}) {
|
|
35898
|
+
super(message, options);
|
|
35899
|
+
this.code = code;
|
|
35900
|
+
this.name = "AgentProbeError";
|
|
35901
|
+
}
|
|
35902
|
+
};
|
|
35903
|
+
|
|
35904
|
+
// src/agent-catalog/agents/resolve-user-local-executable.ts
|
|
35905
|
+
import { isAbsolute as isAbsolute3, join as join6 } from "node:path";
|
|
35906
|
+
async function resolveUserLocalExecutable(executableName, context) {
|
|
35907
|
+
context.signal.throwIfAborted();
|
|
35908
|
+
const platform = context.platform ?? process.platform;
|
|
35909
|
+
const homeDirectory = context.environment["HOME"];
|
|
35910
|
+
if (platform === "win32" || homeDirectory === void 0 || !isAbsolute3(homeDirectory)) {
|
|
35911
|
+
return [];
|
|
35912
|
+
}
|
|
35913
|
+
const executable = await resolveExecutablePath(join6(homeDirectory, ".local", "bin", executableName), platform);
|
|
35914
|
+
context.signal.throwIfAborted();
|
|
35915
|
+
return executable === null ? [] : [executable];
|
|
35916
|
+
}
|
|
35917
|
+
|
|
35918
|
+
// src/agent-catalog/agents/verify-session-creation.ts
|
|
35919
|
+
import { methods as methods5 } from "@agentclientprotocol/sdk";
|
|
35920
|
+
async function verifySessionCreation(connection, capabilities, defaultWorkspace, signal, label) {
|
|
35921
|
+
const session = await connection.agent.request(
|
|
35922
|
+
methods5.agent.session.new,
|
|
35923
|
+
{
|
|
35924
|
+
additionalDirectories: [],
|
|
35925
|
+
cwd: defaultWorkspace,
|
|
35926
|
+
mcpServers: []
|
|
35927
|
+
},
|
|
35928
|
+
{ cancellationSignal: signal }
|
|
35929
|
+
);
|
|
35930
|
+
if (session.sessionId.length === 0) {
|
|
35931
|
+
throw new AgentProbeError("acp_incompatible", `${label} returned an invalid ACP session`);
|
|
35932
|
+
}
|
|
35933
|
+
if (capabilities.sessionCapabilities?.close != null) {
|
|
35934
|
+
await connection.agent.request(
|
|
35935
|
+
methods5.agent.session.close,
|
|
35936
|
+
{ sessionId: session.sessionId },
|
|
35937
|
+
{ cancellationSignal: signal }
|
|
35938
|
+
);
|
|
35939
|
+
}
|
|
35940
|
+
}
|
|
35941
|
+
|
|
35942
|
+
// src/agent-catalog/agents/copilot-cli-agent.ts
|
|
35943
|
+
var COPILOT_CLI_TESTED_VERSION = "1.0.83";
|
|
35944
|
+
var CopilotCliAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
35945
|
+
acpProbeTimeoutMilliseconds = 2e4;
|
|
34646
35946
|
adapterVersion = COPILOT_CLI_TESTED_VERSION;
|
|
34647
35947
|
authenticationCommand = () => "copilot login";
|
|
34648
35948
|
agentExecutable = "copilot";
|
|
@@ -35011,7 +36311,7 @@ var HermesAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35011
36311
|
|
|
35012
36312
|
// src/agent-catalog/agents/oh-my-pi-agent.ts
|
|
35013
36313
|
import {
|
|
35014
|
-
methods as
|
|
36314
|
+
methods as methods6
|
|
35015
36315
|
} from "@agentclientprotocol/sdk";
|
|
35016
36316
|
var ACP_PROBE_TIMEOUT_MILLISECONDS2 = 3e4;
|
|
35017
36317
|
var OH_MY_PI_TESTED_VERSION = "18.2.7";
|
|
@@ -35032,7 +36332,7 @@ var OhMyPiAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35032
36332
|
throw new AgentProbeError("acp_incompatible", "Oh My Pi does not support ACP session recovery");
|
|
35033
36333
|
}
|
|
35034
36334
|
const session = await connection.agent.request(
|
|
35035
|
-
|
|
36335
|
+
methods6.agent.session.new,
|
|
35036
36336
|
{ additionalDirectories: [], cwd: defaultWorkspace, mcpServers: [] },
|
|
35037
36337
|
{ cancellationSignal: signal }
|
|
35038
36338
|
);
|
|
@@ -35040,7 +36340,7 @@ var OhMyPiAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35040
36340
|
throw new AgentProbeError("acp_incompatible", "Oh My Pi returned an invalid ACP session");
|
|
35041
36341
|
}
|
|
35042
36342
|
const prompt = await connection.agent.request(
|
|
35043
|
-
|
|
36343
|
+
methods6.agent.session.prompt,
|
|
35044
36344
|
{ prompt: [{ text: "/session", type: "text" }], sessionId: session.sessionId },
|
|
35045
36345
|
{ cancellationSignal: signal }
|
|
35046
36346
|
);
|
|
@@ -35365,7 +36665,7 @@ var OpenCodeAgentSpecification = class extends DirectAcpAgentDefinition {
|
|
|
35365
36665
|
// src/agent-catalog/agents/pi-agent.ts
|
|
35366
36666
|
import { join as join11 } from "node:path";
|
|
35367
36667
|
import {
|
|
35368
|
-
methods as
|
|
36668
|
+
methods as methods7
|
|
35369
36669
|
} from "@agentclientprotocol/sdk";
|
|
35370
36670
|
|
|
35371
36671
|
// src/agent-installation/pi-managed-packages.ts
|
|
@@ -35432,7 +36732,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
35432
36732
|
throw new AgentProbeError("acp_incompatible", "Pi ACP adapter does not support session recovery");
|
|
35433
36733
|
}
|
|
35434
36734
|
const session = await connection.agent.request(
|
|
35435
|
-
|
|
36735
|
+
methods7.agent.session.new,
|
|
35436
36736
|
{
|
|
35437
36737
|
additionalDirectories: [],
|
|
35438
36738
|
cwd: defaultWorkspace,
|
|
@@ -35444,7 +36744,7 @@ var PiAgentSpecification = class extends BridgedAcpAgentDefinition {
|
|
|
35444
36744
|
throw new AgentProbeError("acp_incompatible", "Pi ACP adapter returned an invalid session");
|
|
35445
36745
|
}
|
|
35446
36746
|
const prompt = await connection.agent.request(
|
|
35447
|
-
|
|
36747
|
+
methods7.agent.session.prompt,
|
|
35448
36748
|
{
|
|
35449
36749
|
prompt: [{ text: "/session", type: "text" }],
|
|
35450
36750
|
sessionId: session.sessionId
|
|
@@ -35565,11 +36865,11 @@ function supportedLocalAgentSpecifications() {
|
|
|
35565
36865
|
}
|
|
35566
36866
|
|
|
35567
36867
|
// src/agent-catalog/acp-readiness-probe.ts
|
|
35568
|
-
import { spawn as
|
|
36868
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
35569
36869
|
import {
|
|
35570
|
-
methods as
|
|
36870
|
+
methods as methods8,
|
|
35571
36871
|
ndJsonStream as ndJsonStream2,
|
|
35572
|
-
PROTOCOL_VERSION as
|
|
36872
|
+
PROTOCOL_VERSION as PROTOCOL_VERSION3,
|
|
35573
36873
|
RequestError as RequestError3
|
|
35574
36874
|
} from "@agentclientprotocol/sdk";
|
|
35575
36875
|
var ACP_OUTPUT_LIMIT_BYTES = 1024 * 1024;
|
|
@@ -35642,6 +36942,44 @@ function writableAcpStream(output2) {
|
|
|
35642
36942
|
}
|
|
35643
36943
|
});
|
|
35644
36944
|
}
|
|
36945
|
+
async function probeInProcessReadiness(agent, environment, defaultWorkspace, controller) {
|
|
36946
|
+
const inProcess = agent.createEndpoint({
|
|
36947
|
+
command: agent.command,
|
|
36948
|
+
cwd: defaultWorkspace,
|
|
36949
|
+
environment: { ...filterEnvironment(environment), ...agent.environment }
|
|
36950
|
+
});
|
|
36951
|
+
try {
|
|
36952
|
+
await inProcess.initialize(controller.signal);
|
|
36953
|
+
const connection = createAcpClient(new DiscoveryAcpHandler()).connect(inProcess.app());
|
|
36954
|
+
const initialized = await connection.agent.request(
|
|
36955
|
+
methods8.agent.initialize,
|
|
36956
|
+
{
|
|
36957
|
+
clientCapabilities: {},
|
|
36958
|
+
clientInfo: { name: "mobius", version: "0.0.3" },
|
|
36959
|
+
protocolVersion: PROTOCOL_VERSION3
|
|
36960
|
+
},
|
|
36961
|
+
{ cancellationSignal: controller.signal }
|
|
36962
|
+
);
|
|
36963
|
+
if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
|
|
36964
|
+
throw new AgentProbeError("acp_incompatible", "ACP agent selected an unsupported protocol version");
|
|
36965
|
+
}
|
|
36966
|
+
return new VerifiedAcpReadiness(
|
|
36967
|
+
normalizeVersionOutput(initialized.agentInfo?.version ?? ""),
|
|
36968
|
+
normalizeAcpCapabilities(initialized)
|
|
36969
|
+
);
|
|
36970
|
+
} finally {
|
|
36971
|
+
await inProcess.close();
|
|
36972
|
+
}
|
|
36973
|
+
}
|
|
36974
|
+
function filterEnvironment(environment) {
|
|
36975
|
+
const filtered = {};
|
|
36976
|
+
for (const [name, value] of Object.entries(environment)) {
|
|
36977
|
+
if (typeof value === "string") {
|
|
36978
|
+
filtered[name] = value;
|
|
36979
|
+
}
|
|
36980
|
+
}
|
|
36981
|
+
return filtered;
|
|
36982
|
+
}
|
|
35645
36983
|
async function probeAcpReadiness(specification, agent, environment, defaultWorkspace, signal) {
|
|
35646
36984
|
signal.throwIfAborted();
|
|
35647
36985
|
const controller = new AbortController();
|
|
@@ -35655,7 +36993,23 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
|
|
|
35655
36993
|
if (signal.aborted) {
|
|
35656
36994
|
abort();
|
|
35657
36995
|
}
|
|
35658
|
-
|
|
36996
|
+
if (agent.kind === "in-process-acp") {
|
|
36997
|
+
try {
|
|
36998
|
+
return await probeInProcessReadiness(agent, environment, defaultWorkspace, controller);
|
|
36999
|
+
} catch (error62) {
|
|
37000
|
+
if (signal.aborted) {
|
|
37001
|
+
signal.throwIfAborted();
|
|
37002
|
+
}
|
|
37003
|
+
if (timedOut) {
|
|
37004
|
+
throw new AgentProbeError("adapter_probe_timeout", "ACP agent probe timed out", { cause: error62 });
|
|
37005
|
+
}
|
|
37006
|
+
throw error62;
|
|
37007
|
+
} finally {
|
|
37008
|
+
clearTimeout(timeout);
|
|
37009
|
+
signal.removeEventListener("abort", abort);
|
|
37010
|
+
}
|
|
37011
|
+
}
|
|
37012
|
+
const child = spawn4(agent.adapterPath, [...agent.arguments], {
|
|
35659
37013
|
cwd: defaultWorkspace,
|
|
35660
37014
|
detached: process.platform !== "win32",
|
|
35661
37015
|
env: { ...environment, ...agent.environment },
|
|
@@ -35691,17 +37045,17 @@ async function probeAcpReadiness(specification, agent, environment, defaultWorks
|
|
|
35691
37045
|
try {
|
|
35692
37046
|
const initialized = await Promise.race([
|
|
35693
37047
|
connection.agent.request(
|
|
35694
|
-
|
|
37048
|
+
methods8.agent.initialize,
|
|
35695
37049
|
{
|
|
35696
37050
|
clientCapabilities: {},
|
|
35697
37051
|
clientInfo: { name: "mobius", version: "0.0.3" },
|
|
35698
|
-
protocolVersion:
|
|
37052
|
+
protocolVersion: PROTOCOL_VERSION3
|
|
35699
37053
|
},
|
|
35700
37054
|
{ cancellationSignal: controller.signal }
|
|
35701
37055
|
),
|
|
35702
37056
|
processExit
|
|
35703
37057
|
]);
|
|
35704
|
-
if (initialized.protocolVersion !==
|
|
37058
|
+
if (initialized.protocolVersion !== PROTOCOL_VERSION3) {
|
|
35705
37059
|
throw new AgentProbeError("acp_incompatible", "ACP adapter selected an unsupported protocol version");
|
|
35706
37060
|
}
|
|
35707
37061
|
await specification.verifyAcp(connection, initialized, defaultWorkspace, controller.signal);
|
|
@@ -35876,7 +37230,7 @@ async function resolveAgentExecutables(specification, context) {
|
|
|
35876
37230
|
);
|
|
35877
37231
|
}
|
|
35878
37232
|
async function resolveAdapterExecutables(specification, context) {
|
|
35879
|
-
if (specification instanceof DirectAcpAgentDefinition) {
|
|
37233
|
+
if (specification instanceof DirectAcpAgentDefinition || specification instanceof InProcessAcpAgentDefinition2) {
|
|
35880
37234
|
return await resolveAgentExecutables(specification, context);
|
|
35881
37235
|
}
|
|
35882
37236
|
if (!(specification instanceof BridgedAcpAgentDefinition)) {
|
|
@@ -36021,7 +37375,7 @@ async function discoverAgent(specification, context) {
|
|
|
36021
37375
|
agent.identity.requestedPath,
|
|
36022
37376
|
agentVersion
|
|
36023
37377
|
);
|
|
36024
|
-
if (adapters.length === 0) {
|
|
37378
|
+
if (adapters.length === 0 && !(specification instanceof InProcessAcpAgentDefinition2)) {
|
|
36025
37379
|
return new MissingAdapter(specification, installedAgent);
|
|
36026
37380
|
}
|
|
36027
37381
|
for (const adapter of adapters) {
|
|
@@ -36056,23 +37410,33 @@ async function discoverAgent(specification, context) {
|
|
|
36056
37410
|
lastFailure = integrationProbeFailure(specification, installedAgent, error62);
|
|
36057
37411
|
continue;
|
|
36058
37412
|
}
|
|
36059
|
-
const
|
|
37413
|
+
const buildDefinition = (verifiedAdapterVersion, capabilities) => specification instanceof InProcessAcpAgentDefinition2 ? new InProcessAcpAgentDefinition(
|
|
37414
|
+
specification.id,
|
|
37415
|
+
specification.label,
|
|
37416
|
+
agent.path,
|
|
37417
|
+
specification.createEndpoint,
|
|
37418
|
+
launchEnvironment,
|
|
37419
|
+
agentVersion.length > 0 ? agentVersion : verifiedAdapterVersion,
|
|
37420
|
+
agent.identity,
|
|
37421
|
+
capabilities
|
|
37422
|
+
) : new LocalAgentDefinition(
|
|
36060
37423
|
specification.id,
|
|
36061
37424
|
specification.label,
|
|
36062
37425
|
adapter.path,
|
|
36063
37426
|
specification.launchArguments,
|
|
36064
37427
|
launchEnvironment,
|
|
36065
|
-
|
|
37428
|
+
verifiedAdapterVersion,
|
|
36066
37429
|
agentVersion,
|
|
36067
37430
|
adapter.identity,
|
|
36068
|
-
agent.identity
|
|
37431
|
+
agent.identity,
|
|
37432
|
+
capabilities
|
|
36069
37433
|
);
|
|
36070
37434
|
try {
|
|
36071
37435
|
const readiness = await probeWithRetry(
|
|
36072
37436
|
context.signal,
|
|
36073
37437
|
async () => await probeAcpReadiness(
|
|
36074
37438
|
specification,
|
|
36075
|
-
|
|
37439
|
+
buildDefinition(adapterVersion, unsupportedSessionCapabilities()),
|
|
36076
37440
|
context.environment,
|
|
36077
37441
|
context.defaultWorkspace,
|
|
36078
37442
|
context.signal
|
|
@@ -36084,18 +37448,7 @@ async function discoverAgent(specification, context) {
|
|
|
36084
37448
|
}
|
|
36085
37449
|
return new AvailableAgent(
|
|
36086
37450
|
specification,
|
|
36087
|
-
|
|
36088
|
-
specification.id,
|
|
36089
|
-
specification.label,
|
|
36090
|
-
adapter.path,
|
|
36091
|
-
specification.launchArguments,
|
|
36092
|
-
launchEnvironment,
|
|
36093
|
-
verifiedAdapterVersion,
|
|
36094
|
-
agentVersion,
|
|
36095
|
-
adapter.identity,
|
|
36096
|
-
agent.identity,
|
|
36097
|
-
readiness.capabilities
|
|
36098
|
-
)
|
|
37451
|
+
buildDefinition(verifiedAdapterVersion, readiness.capabilities)
|
|
36099
37452
|
);
|
|
36100
37453
|
} catch (error62) {
|
|
36101
37454
|
if (context.signal.aborted) {
|
|
@@ -37747,7 +39100,7 @@ var FixedInstallationExecutor = class {
|
|
|
37747
39100
|
const verified = inventory.available.find((candidate) => candidate.specification.id === agentId);
|
|
37748
39101
|
if (verified instanceof AvailableAgent) {
|
|
37749
39102
|
this.#audit.record("agent_installation_acp_verified", requestId, agentId, {
|
|
37750
|
-
adapterVersion: verified.agent.adapterVersion,
|
|
39103
|
+
adapterVersion: verified.agent.kind === "acp-adapter-process" ? verified.agent.adapterVersion : verified.agent.agentVersion,
|
|
37751
39104
|
agentVersion: verified.agent.agentVersion
|
|
37752
39105
|
});
|
|
37753
39106
|
await this.#publishDiscoveredAgent(agentId, inventory, environment, signal);
|
|
@@ -38026,8 +39379,56 @@ var WorkspaceDirectoryService = class {
|
|
|
38026
39379
|
};
|
|
38027
39380
|
};
|
|
38028
39381
|
|
|
39382
|
+
// src/daemon-diagnostic-log.ts
|
|
39383
|
+
import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
39384
|
+
import { join as join17 } from "node:path";
|
|
39385
|
+
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
39386
|
+
var DaemonDiagnosticLog = class {
|
|
39387
|
+
#directory;
|
|
39388
|
+
#path;
|
|
39389
|
+
#maximumBytes;
|
|
39390
|
+
constructor(stateDirectory, maximumBytes = MAXIMUM_DAEMON_LOG_BYTES) {
|
|
39391
|
+
this.#directory = join17(stateDirectory, "logs");
|
|
39392
|
+
this.#path = join17(this.#directory, "daemon.log");
|
|
39393
|
+
this.#maximumBytes = maximumBytes;
|
|
39394
|
+
}
|
|
39395
|
+
record = (diagnostic) => {
|
|
39396
|
+
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
39397
|
+
`;
|
|
39398
|
+
const encodedBytes = Buffer.byteLength(encoded);
|
|
39399
|
+
mkdirSync3(this.#directory, { mode: 448, recursive: true });
|
|
39400
|
+
let existingBytes = 0;
|
|
39401
|
+
try {
|
|
39402
|
+
existingBytes = statSync3(this.#path).size;
|
|
39403
|
+
} catch (cause) {
|
|
39404
|
+
if (!(cause instanceof Error && Reflect.get(cause, "code") === "ENOENT")) {
|
|
39405
|
+
throw cause;
|
|
39406
|
+
}
|
|
39407
|
+
}
|
|
39408
|
+
if (existingBytes + encodedBytes <= this.#maximumBytes) {
|
|
39409
|
+
appendFileSync(this.#path, encoded, { encoding: "utf8", mode: 384 });
|
|
39410
|
+
return;
|
|
39411
|
+
}
|
|
39412
|
+
const lines = `${existingBytes === 0 ? "" : readFileSync2(this.#path, "utf8")}${encoded}`.split("\n").filter((line) => line.length > 0);
|
|
39413
|
+
let totalBytes = lines.reduce((total, line) => total + Buffer.byteLength(line) + 1, 0);
|
|
39414
|
+
while (totalBytes > this.#maximumBytes && lines.length > 0) {
|
|
39415
|
+
const oldest = lines.shift();
|
|
39416
|
+
if (oldest !== void 0) {
|
|
39417
|
+
totalBytes -= Buffer.byteLength(oldest) + 1;
|
|
39418
|
+
}
|
|
39419
|
+
}
|
|
39420
|
+
const temporaryPath = `${this.#path}.tmp`;
|
|
39421
|
+
writeFileSync(temporaryPath, lines.length === 0 ? "" : `${lines.join("\n")}
|
|
39422
|
+
`, {
|
|
39423
|
+
encoding: "utf8",
|
|
39424
|
+
mode: 384
|
|
39425
|
+
});
|
|
39426
|
+
renameSync(temporaryPath, this.#path);
|
|
39427
|
+
};
|
|
39428
|
+
};
|
|
39429
|
+
|
|
38029
39430
|
// src/native-sessions/codex-history.ts
|
|
38030
|
-
import { spawn as
|
|
39431
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
38031
39432
|
var responseSchema = external_exports.union([
|
|
38032
39433
|
external_exports.object({
|
|
38033
39434
|
id: external_exports.number(),
|
|
@@ -38266,7 +39667,7 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
|
|
|
38266
39667
|
);
|
|
38267
39668
|
}
|
|
38268
39669
|
signal.throwIfAborted();
|
|
38269
|
-
const child =
|
|
39670
|
+
const child = spawn5(agent.agentIdentity.realPath, ["app-server"], {
|
|
38270
39671
|
cwd,
|
|
38271
39672
|
env: { ...process.env, ...agent.environment },
|
|
38272
39673
|
detached: process.platform !== "win32",
|
|
@@ -38612,10 +40013,11 @@ var NativeSessionService = class {
|
|
|
38612
40013
|
deletedSessionIds
|
|
38613
40014
|
};
|
|
38614
40015
|
}
|
|
38615
|
-
|
|
40016
|
+
const action = command.action === "import-only" ? "import" : command.action === "fork-only" ? "fork" : command.action;
|
|
40017
|
+
if (action === "import" && !prepared.capabilities.loadSession && !prepared.capabilities.resumeSession) {
|
|
38616
40018
|
throw new AcpExecutionError("This Agent cannot import native sessions", {}, "native_session_unsupported");
|
|
38617
40019
|
}
|
|
38618
|
-
if (
|
|
40020
|
+
if (action === "fork" && !prepared.capabilities.unstableForkSession) {
|
|
38619
40021
|
throw new AcpExecutionError(
|
|
38620
40022
|
"This Agent does not support session forking",
|
|
38621
40023
|
{},
|
|
@@ -38636,7 +40038,8 @@ var NativeSessionService = class {
|
|
|
38636
40038
|
sessionId: command.targetSessionId,
|
|
38637
40039
|
additionalDirectories: target.additionalDirectories
|
|
38638
40040
|
},
|
|
38639
|
-
{ kind:
|
|
40041
|
+
{ kind: action, nativeSessionId: target.info.sessionId },
|
|
40042
|
+
command.action !== "import-only" && command.action !== "fork-only"
|
|
38640
40043
|
);
|
|
38641
40044
|
signal.throwIfAborted();
|
|
38642
40045
|
const ready = {
|
|
@@ -38654,10 +40057,10 @@ var NativeSessionService = class {
|
|
|
38654
40057
|
restored: true,
|
|
38655
40058
|
sessionId: opened.sessionId
|
|
38656
40059
|
};
|
|
38657
|
-
this.record(command,
|
|
40060
|
+
this.record(command, action === "fork" ? "native_session_forked" : "native_session_imported");
|
|
38658
40061
|
return {
|
|
38659
40062
|
...envelope2,
|
|
38660
|
-
action
|
|
40063
|
+
action,
|
|
38661
40064
|
ready,
|
|
38662
40065
|
targetSessionId: command.targetSessionId,
|
|
38663
40066
|
title: target.info.title ?? "Untitled session",
|
|
@@ -39237,13 +40640,15 @@ function addFailureDetails(details, failure2) {
|
|
|
39237
40640
|
var RelayConnectionDiagnostics = class {
|
|
39238
40641
|
#audit;
|
|
39239
40642
|
#channelId;
|
|
40643
|
+
#localLog;
|
|
39240
40644
|
#lastClosedEpoch = 0;
|
|
39241
40645
|
#lastFailedEpoch = 0;
|
|
39242
40646
|
#relayOrigin;
|
|
39243
40647
|
#route;
|
|
39244
|
-
constructor(audit, channelId, relayUrl) {
|
|
40648
|
+
constructor(audit, channelId, relayUrl, localLog) {
|
|
39245
40649
|
this.#audit = audit;
|
|
39246
40650
|
this.#channelId = channelId;
|
|
40651
|
+
this.#localLog = localLog;
|
|
39247
40652
|
this.#relayOrigin = relayUrl.origin;
|
|
39248
40653
|
this.#route = describeEnvironmentProxyRoute(relayUrl);
|
|
39249
40654
|
}
|
|
@@ -39330,6 +40735,20 @@ var RelayConnectionDiagnostics = class {
|
|
|
39330
40735
|
true
|
|
39331
40736
|
);
|
|
39332
40737
|
};
|
|
40738
|
+
daemonDiagnostic = (event, requestId, details, failure2) => {
|
|
40739
|
+
const recordedDetails = { ...details };
|
|
40740
|
+
if (failure2 !== void 0) {
|
|
40741
|
+
addFailureDetails(recordedDetails, failure2);
|
|
40742
|
+
}
|
|
40743
|
+
this.#localLog.record(
|
|
40744
|
+
`Mobius daemon diagnostic ${JSON.stringify({
|
|
40745
|
+
channelId: this.#channelId,
|
|
40746
|
+
event,
|
|
40747
|
+
requestId,
|
|
40748
|
+
...recordedDetails
|
|
40749
|
+
})}`
|
|
40750
|
+
);
|
|
40751
|
+
};
|
|
39333
40752
|
#record = (event, commandId, details, warning) => {
|
|
39334
40753
|
this.#audit.record({
|
|
39335
40754
|
commandId,
|
|
@@ -39338,6 +40757,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
39338
40757
|
sessionId: this.#channelId
|
|
39339
40758
|
});
|
|
39340
40759
|
const encoded = JSON.stringify({ channelId: this.#channelId, event, ...details });
|
|
40760
|
+
this.#localLog.record(`Mobius relay diagnostic ${encoded}`);
|
|
39341
40761
|
if (warning) {
|
|
39342
40762
|
process.stderr.write(`Mobius relay diagnostic ${encoded}
|
|
39343
40763
|
`);
|
|
@@ -39455,7 +40875,7 @@ var RelayConnectionLiveness = class {
|
|
|
39455
40875
|
};
|
|
39456
40876
|
|
|
39457
40877
|
// src/relay-connection/session-event-outbox.ts
|
|
39458
|
-
import { mkdirSync as
|
|
40878
|
+
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
39459
40879
|
import { dirname as dirname7 } from "node:path";
|
|
39460
40880
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
39461
40881
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
@@ -39522,7 +40942,7 @@ var SessionEventOutbox = class {
|
|
|
39522
40942
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
39523
40943
|
validateLimits(limits);
|
|
39524
40944
|
this.#limits = limits;
|
|
39525
|
-
|
|
40945
|
+
mkdirSync4(dirname7(path2), { recursive: true });
|
|
39526
40946
|
this.#database = new DatabaseSync3(path2);
|
|
39527
40947
|
this.#database.exec(`
|
|
39528
40948
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -40910,7 +42330,7 @@ function settingsRevision(agent, reportedAgentVersion, settings, modelEffort) {
|
|
|
40910
42330
|
};
|
|
40911
42331
|
return createHash4("sha256").update(
|
|
40912
42332
|
JSON.stringify({
|
|
40913
|
-
adapterVersion: agent.adapterVersion,
|
|
42333
|
+
adapterVersion: agent.kind === "acp-adapter-process" ? agent.adapterVersion : agent.agentVersion,
|
|
40914
42334
|
agentId: agent.id,
|
|
40915
42335
|
agentVersion: agent.agentVersion,
|
|
40916
42336
|
modelEffort: revisionModelEffort,
|
|
@@ -41986,6 +43406,11 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
41986
43406
|
event: "agent_settings_model_unsupported",
|
|
41987
43407
|
sessionId: `agent-settings:${command2.agentId}`
|
|
41988
43408
|
});
|
|
43409
|
+
diagnostics.daemonDiagnostic(
|
|
43410
|
+
"agent_settings_model_unsupported",
|
|
43411
|
+
command2.requestId,
|
|
43412
|
+
details
|
|
43413
|
+
);
|
|
41989
43414
|
process.stderr.write(
|
|
41990
43415
|
`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_model_unsupported", requestId: command2.requestId, ...details })}
|
|
41991
43416
|
`
|
|
@@ -42016,6 +43441,12 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42016
43441
|
event: "agent_settings_discovery_failed",
|
|
42017
43442
|
sessionId: `agent-settings:${command2.agentId}`
|
|
42018
43443
|
});
|
|
43444
|
+
diagnostics.daemonDiagnostic(
|
|
43445
|
+
"agent_settings_discovery_failed",
|
|
43446
|
+
command2.requestId,
|
|
43447
|
+
details,
|
|
43448
|
+
failure2
|
|
43449
|
+
);
|
|
42019
43450
|
if (failure2 instanceof AcpConfigurationValueUnavailableError) {
|
|
42020
43451
|
process.stderr.write(
|
|
42021
43452
|
`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_discovery_failed", requestId: command2.requestId, ...details })}
|
|
@@ -42093,6 +43524,12 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42093
43524
|
event: "agent_catalog_refresh_failed",
|
|
42094
43525
|
sessionId: "agent-catalog"
|
|
42095
43526
|
});
|
|
43527
|
+
diagnostics.daemonDiagnostic(
|
|
43528
|
+
"agent_catalog_refresh_failed",
|
|
43529
|
+
command2.requestId,
|
|
43530
|
+
{ code: operationErrorCode(failure2) },
|
|
43531
|
+
failure2
|
|
43532
|
+
);
|
|
42096
43533
|
if (socket.readyState === WebSocket2.OPEN) {
|
|
42097
43534
|
send(socket, {
|
|
42098
43535
|
code: operationErrorCode(failure2),
|
|
@@ -42177,6 +43614,17 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42177
43614
|
event: "native_session_operation_failed",
|
|
42178
43615
|
details: { code: operationErrorCode(failure2) }
|
|
42179
43616
|
});
|
|
43617
|
+
diagnostics.daemonDiagnostic(
|
|
43618
|
+
"native_session_operation_failed",
|
|
43619
|
+
command2.requestId,
|
|
43620
|
+
{
|
|
43621
|
+
action: command2.action,
|
|
43622
|
+
agentId: command2.agentId,
|
|
43623
|
+
code: operationErrorCode(failure2),
|
|
43624
|
+
sessionId: command2.sessionId
|
|
43625
|
+
},
|
|
43626
|
+
failure2
|
|
43627
|
+
);
|
|
42180
43628
|
reportOperationFailure(socket, command2.requestId, command2.sessionId, failure2);
|
|
42181
43629
|
} finally {
|
|
42182
43630
|
timeout.cancel();
|
|
@@ -42257,6 +43705,16 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42257
43705
|
event: "native_session_turn_fork_failed",
|
|
42258
43706
|
sessionId: command2.sessionId
|
|
42259
43707
|
});
|
|
43708
|
+
diagnostics.daemonDiagnostic(
|
|
43709
|
+
"native_session_turn_fork_failed",
|
|
43710
|
+
command2.requestId,
|
|
43711
|
+
{
|
|
43712
|
+
agentId: command2.agentId,
|
|
43713
|
+
code: operationErrorCode(failure2),
|
|
43714
|
+
sessionId: command2.sessionId
|
|
43715
|
+
},
|
|
43716
|
+
failure2
|
|
43717
|
+
);
|
|
42260
43718
|
reportOperationFailure(socket, command2.requestId, command2.sessionId, failure2);
|
|
42261
43719
|
} finally {
|
|
42262
43720
|
timeout.cancel();
|
|
@@ -42529,7 +43987,12 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42529
43987
|
});
|
|
42530
43988
|
const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
|
|
42531
43989
|
const installationObserver = new DaemonInstallationObserver();
|
|
42532
|
-
const diagnostics = new RelayConnectionDiagnostics(
|
|
43990
|
+
const diagnostics = new RelayConnectionDiagnostics(
|
|
43991
|
+
audit,
|
|
43992
|
+
config2.channelId,
|
|
43993
|
+
config2.relayUrl,
|
|
43994
|
+
new DaemonDiagnosticLog(stateDirectory)
|
|
43995
|
+
);
|
|
42533
43996
|
const nativeSessions = new NativeSessionService(config2, directories, sessions, audit);
|
|
42534
43997
|
const installations = new AgentInstallationManager(
|
|
42535
43998
|
specifications,
|
|
@@ -42662,7 +44125,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42662
44125
|
|
|
42663
44126
|
// src/runtime.ts
|
|
42664
44127
|
import { mkdir as mkdir6, realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
42665
|
-
import { dirname as dirname8, join as
|
|
44128
|
+
import { dirname as dirname8, join as join18, resolve as resolve7 } from "node:path";
|
|
42666
44129
|
var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
42667
44130
|
var RUNTIME_CREDENTIAL_PATTERN2 = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
42668
44131
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
@@ -42719,7 +44182,7 @@ function loadMobiusRuntimeConnection(environment = process.env) {
|
|
|
42719
44182
|
throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
|
|
42720
44183
|
}
|
|
42721
44184
|
return Object.freeze({
|
|
42722
|
-
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() ||
|
|
44185
|
+
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join18(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
|
|
42723
44186
|
channelId,
|
|
42724
44187
|
defaultWorkspace: loadDefaultWorkspace(environment),
|
|
42725
44188
|
relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
|