@moxt-ai/mobius 0.0.72 → 0.0.74
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/activity.d.ts +9 -1
- package/dist/acp/activity.d.ts.map +1 -1
- package/dist/acp/activity.js +51 -13
- package/dist/acp/activity.js.map +1 -1
- package/dist/acp/codex/agent.d.ts +1 -1
- package/dist/acp/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +415 -6
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/acp/codex/app-server-protocol.d.ts +68 -0
- package/dist/acp/codex/app-server-protocol.d.ts.map +1 -1
- package/dist/acp/codex/app-server-protocol.js +51 -0
- package/dist/acp/codex/app-server-protocol.js.map +1 -1
- package/dist/acp/run-prompt.d.ts +2 -1
- package/dist/acp/run-prompt.d.ts.map +1 -1
- package/dist/acp/run-prompt.js +1 -0
- package/dist/acp/run-prompt.js.map +1 -1
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +4 -1
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-manager.d.ts +7 -2
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +18 -7
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/cli.js +854 -62
- package/dist/cli.js.map +4 -4
- 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 +856 -63
- package/dist/index.js.map +4 -4
- 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/relay-connection/coalescing-narration-publisher.d.ts +31 -0
- package/dist/relay-connection/coalescing-narration-publisher.d.ts.map +1 -0
- package/dist/relay-connection/coalescing-narration-publisher.js +61 -0
- package/dist/relay-connection/coalescing-narration-publisher.js.map +1 -0
- 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/relay-connection/session-event-outbox.d.ts +6 -0
- package/dist/relay-connection/session-event-outbox.d.ts.map +1 -1
- package/dist/relay-connection/session-event-outbox.js +13 -0
- package/dist/relay-connection/session-event-outbox.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +104 -7
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +866 -74
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -20409,6 +20409,7 @@ var RUNTIME_DELIVERY_COMMITTED_KIND = "runtime.delivery.committed";
|
|
|
20409
20409
|
var SESSION_STARTED_KIND = "session.started";
|
|
20410
20410
|
var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
|
|
20411
20411
|
var AGENT_ACTIVITY_KIND = "agent.activity";
|
|
20412
|
+
var AGENT_ACTIVITY_NARRATION_KIND = "agent.activity.narration";
|
|
20412
20413
|
var AGENT_ACTIVITY_DETAIL_LIMIT = 5e5;
|
|
20413
20414
|
var AGENT_ACTIVITY_RECORDED_FIELD_LIMIT = 4e6;
|
|
20414
20415
|
var AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT = 6e6;
|
|
@@ -20430,6 +20431,7 @@ var MAX_PROMPT_ATTACHMENT_LENGTH = 6e6;
|
|
|
20430
20431
|
var MAX_EVENT_TEXT_LENGTH = 1e5;
|
|
20431
20432
|
var MAX_RUNTIME_DELIVERY_PAYLOAD_LENGTH = 8 * 1024 * 1024;
|
|
20432
20433
|
var ACTIVITY_TYPES = /* @__PURE__ */ new Set(["plan", "progress", "reasoning", "tool"]);
|
|
20434
|
+
var NARRATION_ACTIVITY_TYPES = /* @__PURE__ */ new Set(["progress", "reasoning"]);
|
|
20433
20435
|
var ACTIVITY_STATUSES = /* @__PURE__ */ new Set(["pending", "running", "completed", "failed"]);
|
|
20434
20436
|
var TOOL_KINDS = /* @__PURE__ */ new Set([
|
|
20435
20437
|
"",
|
|
@@ -20853,6 +20855,20 @@ function encodeRuntimeDeliveryReceived(message) {
|
|
|
20853
20855
|
function encodeRuntimeDeliveryCommitted(message) {
|
|
20854
20856
|
return JSON.stringify(decodeRuntimeDeliveryCommitted(JSON.stringify(message)));
|
|
20855
20857
|
}
|
|
20858
|
+
function decodeAgentActivityNarrationEvent(encoded) {
|
|
20859
|
+
const value = parseJson2(encoded);
|
|
20860
|
+
assertExactKeys(value, ["activityId", "activityType", "commandId", "kind", "sequence", "sessionId", "text"]);
|
|
20861
|
+
assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
|
|
20862
|
+
return {
|
|
20863
|
+
activityId: readIdentifier(value, "activityId"),
|
|
20864
|
+
activityType: readAllowedString(value, "activityType", NARRATION_ACTIVITY_TYPES),
|
|
20865
|
+
commandId: readIdentifier(value, "commandId"),
|
|
20866
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
20867
|
+
sequence: readSequence(value, "sequence"),
|
|
20868
|
+
sessionId: readIdentifier(value, "sessionId"),
|
|
20869
|
+
text: readText(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
20870
|
+
};
|
|
20871
|
+
}
|
|
20856
20872
|
|
|
20857
20873
|
// ../protocol/src/session-history.ts
|
|
20858
20874
|
var SESSION_HISTORY_CHARACTER_LIMIT = 256e3;
|
|
@@ -20988,6 +21004,26 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
|
|
|
20988
21004
|
messageOccurrence: external_exports.number().int().positive(),
|
|
20989
21005
|
title: external_exports.string().max(500)
|
|
20990
21006
|
}).readonly();
|
|
21007
|
+
var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
|
|
21008
|
+
external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
|
|
21009
|
+
external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
|
|
21010
|
+
external_exports.strictObject({
|
|
21011
|
+
...identity,
|
|
21012
|
+
action: external_exports.literal("list"),
|
|
21013
|
+
cursor: identifier.nullable()
|
|
21014
|
+
}).readonly(),
|
|
21015
|
+
external_exports.strictObject({
|
|
21016
|
+
...identity,
|
|
21017
|
+
action: external_exports.enum(["import", "fork"]),
|
|
21018
|
+
entryId: identifier,
|
|
21019
|
+
targetSessionId: identifier
|
|
21020
|
+
}).readonly(),
|
|
21021
|
+
external_exports.strictObject({
|
|
21022
|
+
...identity,
|
|
21023
|
+
action: external_exports.literal("delete"),
|
|
21024
|
+
entryId: identifier
|
|
21025
|
+
}).readonly()
|
|
21026
|
+
]);
|
|
20991
21027
|
var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
20992
21028
|
external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
|
|
20993
21029
|
external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
|
|
@@ -21002,6 +21038,12 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
|
21002
21038
|
entryId: identifier,
|
|
21003
21039
|
targetSessionId: identifier
|
|
21004
21040
|
}).readonly(),
|
|
21041
|
+
external_exports.strictObject({
|
|
21042
|
+
...identity,
|
|
21043
|
+
action: external_exports.enum(["import-only", "fork-only"]),
|
|
21044
|
+
entryId: identifier,
|
|
21045
|
+
targetSessionId: identifier
|
|
21046
|
+
}).readonly(),
|
|
21005
21047
|
external_exports.strictObject({
|
|
21006
21048
|
...identity,
|
|
21007
21049
|
action: external_exports.literal("delete"),
|
|
@@ -21175,6 +21217,8 @@ function decodeRecordedSessionEvent(encoded) {
|
|
|
21175
21217
|
switch (kind) {
|
|
21176
21218
|
case AGENT_ACTIVITY_KIND:
|
|
21177
21219
|
return decodeAgentActivityEvent(encoded);
|
|
21220
|
+
case AGENT_ACTIVITY_NARRATION_KIND:
|
|
21221
|
+
return decodeAgentActivityNarrationEvent(encoded);
|
|
21178
21222
|
case AGENT_CONTENT_KIND:
|
|
21179
21223
|
return decodeAgentContentEvent(encoded);
|
|
21180
21224
|
case AGENT_MESSAGE_DELTA_KIND:
|
|
@@ -22643,6 +22687,18 @@ var AcpConfigurationValueUnavailableError = class extends AcpExecutionError {
|
|
|
22643
22687
|
|
|
22644
22688
|
// src/acp/activity.ts
|
|
22645
22689
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
22690
|
+
var AcpActivityNarration = class {
|
|
22691
|
+
activityId;
|
|
22692
|
+
activityType;
|
|
22693
|
+
sequence;
|
|
22694
|
+
text;
|
|
22695
|
+
constructor(activityId, activityType, sequence, text3) {
|
|
22696
|
+
this.activityId = activityId;
|
|
22697
|
+
this.activityType = activityType;
|
|
22698
|
+
this.sequence = sequence;
|
|
22699
|
+
this.text = text3;
|
|
22700
|
+
}
|
|
22701
|
+
};
|
|
22646
22702
|
function isRecord3(value) {
|
|
22647
22703
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22648
22704
|
}
|
|
@@ -22975,12 +23031,15 @@ function isProgressMessage(content3) {
|
|
|
22975
23031
|
var AcpActivityTracker = class {
|
|
22976
23032
|
#activities = /* @__PURE__ */ new Map();
|
|
22977
23033
|
#identities = /* @__PURE__ */ new Map();
|
|
23034
|
+
#narrations = /* @__PURE__ */ new Map();
|
|
22978
23035
|
#onActivity;
|
|
23036
|
+
#onNarration;
|
|
22979
23037
|
#prepareContent;
|
|
22980
23038
|
#activeNarrativeKey = "";
|
|
22981
23039
|
#nextSequence = 0;
|
|
22982
|
-
constructor(onActivity, prepareContent = (content3) => Promise.resolve(content3)) {
|
|
23040
|
+
constructor(onActivity, onNarration, prepareContent = (content3) => Promise.resolve(content3)) {
|
|
22983
23041
|
this.#onActivity = onActivity;
|
|
23042
|
+
this.#onNarration = onNarration;
|
|
22984
23043
|
this.#prepareContent = prepareContent;
|
|
22985
23044
|
}
|
|
22986
23045
|
recordNarrative = async (activityType, messageId, text3) => {
|
|
@@ -22988,26 +23047,34 @@ var AcpActivityTracker = class {
|
|
|
22988
23047
|
if (this.#activeNarrativeKey !== key) {
|
|
22989
23048
|
await this.finishNarrative();
|
|
22990
23049
|
}
|
|
22991
|
-
const previous2 = this.#activities.get(key);
|
|
22992
23050
|
const identity2 = this.#identity(key);
|
|
22993
|
-
const
|
|
22994
|
-
|
|
22995
|
-
identity2.id,
|
|
23051
|
+
const previous2 = this.#narrations.get(key);
|
|
23052
|
+
this.#narrations.set(key, {
|
|
23053
|
+
activityId: identity2.id,
|
|
22996
23054
|
activityType,
|
|
22997
|
-
""
|
|
22998
|
-
|
|
22999
|
-
|
|
23000
|
-
|
|
23001
|
-
identity2
|
|
23002
|
-
|
|
23003
|
-
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
23004
|
-
activityType === "reasoning" ? "think" : "",
|
|
23005
|
-
[],
|
|
23006
|
-
captureActivityDetail([], "", fullOutput)
|
|
23007
|
-
);
|
|
23008
|
-
await this.#record(key, activity2);
|
|
23055
|
+
output: `${previous2?.output ?? ""}${text3}`,
|
|
23056
|
+
sequence: identity2.sequence
|
|
23057
|
+
});
|
|
23058
|
+
if (previous2 === void 0) {
|
|
23059
|
+
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
23060
|
+
}
|
|
23009
23061
|
this.#activeNarrativeKey = key;
|
|
23062
|
+
if (text3.length > 0) {
|
|
23063
|
+
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text3));
|
|
23064
|
+
}
|
|
23010
23065
|
};
|
|
23066
|
+
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
23067
|
+
identity2.id,
|
|
23068
|
+
activityType,
|
|
23069
|
+
"",
|
|
23070
|
+
[],
|
|
23071
|
+
"",
|
|
23072
|
+
truncate(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
23073
|
+
identity2.sequence,
|
|
23074
|
+
status,
|
|
23075
|
+
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
23076
|
+
activityType === "reasoning" ? "think" : ""
|
|
23077
|
+
);
|
|
23011
23078
|
recordPlan = async (plan) => {
|
|
23012
23079
|
await this.finishNarrative();
|
|
23013
23080
|
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
@@ -23127,17 +23194,13 @@ var AcpActivityTracker = class {
|
|
|
23127
23194
|
return;
|
|
23128
23195
|
}
|
|
23129
23196
|
this.#activeNarrativeKey = "";
|
|
23130
|
-
|
|
23131
|
-
if (activity2 === void 0) {
|
|
23132
|
-
return;
|
|
23133
|
-
}
|
|
23134
|
-
const completed = activity2.complete();
|
|
23135
|
-
if (completed !== activity2) {
|
|
23136
|
-
await this.#record(key, completed);
|
|
23137
|
-
}
|
|
23197
|
+
await this.#completeNarrative(key);
|
|
23138
23198
|
};
|
|
23139
23199
|
finish = async () => {
|
|
23140
23200
|
await this.finishNarrative();
|
|
23201
|
+
for (const key of this.#narrations.keys()) {
|
|
23202
|
+
await this.#completeNarrative(key);
|
|
23203
|
+
}
|
|
23141
23204
|
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
23142
23205
|
for (const [key, activity2] of entries) {
|
|
23143
23206
|
const completed = activity2.complete();
|
|
@@ -23146,6 +23209,34 @@ var AcpActivityTracker = class {
|
|
|
23146
23209
|
}
|
|
23147
23210
|
}
|
|
23148
23211
|
};
|
|
23212
|
+
// Materialize a streamed narration as one completed snapshot activity. The
|
|
23213
|
+
// incremental events carried the text; this final event gives consumers the
|
|
23214
|
+
// whole narration with its terminal status, as a single bounded item.
|
|
23215
|
+
#completeNarrative = async (key) => {
|
|
23216
|
+
const narration = this.#narrations.get(key);
|
|
23217
|
+
if (narration === void 0) {
|
|
23218
|
+
return;
|
|
23219
|
+
}
|
|
23220
|
+
this.#narrations.delete(key);
|
|
23221
|
+
const previous2 = this.#activities.get(key);
|
|
23222
|
+
await this.#record(
|
|
23223
|
+
key,
|
|
23224
|
+
new AcpActivity(
|
|
23225
|
+
narration.activityId,
|
|
23226
|
+
narration.activityType,
|
|
23227
|
+
"",
|
|
23228
|
+
[],
|
|
23229
|
+
"",
|
|
23230
|
+
truncate(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
23231
|
+
narration.sequence,
|
|
23232
|
+
"completed",
|
|
23233
|
+
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
23234
|
+
narration.activityType === "reasoning" ? "think" : "",
|
|
23235
|
+
previous2?.content ?? [],
|
|
23236
|
+
captureActivityDetail([], "", narration.output)
|
|
23237
|
+
)
|
|
23238
|
+
);
|
|
23239
|
+
};
|
|
23149
23240
|
#identity = (key) => {
|
|
23150
23241
|
const existing = this.#identities.get(key);
|
|
23151
23242
|
if (existing !== void 0) {
|
|
@@ -30789,17 +30880,22 @@ var AcpHistoryReplay = class {
|
|
|
30789
30880
|
#activities = /* @__PURE__ */ new Map();
|
|
30790
30881
|
#messages = [];
|
|
30791
30882
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
30792
|
-
#activityTracker = new AcpActivityTracker(
|
|
30793
|
-
|
|
30794
|
-
|
|
30795
|
-
|
|
30796
|
-
|
|
30797
|
-
|
|
30798
|
-
|
|
30799
|
-
|
|
30800
|
-
|
|
30801
|
-
|
|
30802
|
-
|
|
30883
|
+
#activityTracker = new AcpActivityTracker(
|
|
30884
|
+
async (activity2) => {
|
|
30885
|
+
this.#activities.set(activity2.activityId, activity2);
|
|
30886
|
+
this.#turnActivityIds.add(activity2.activityId);
|
|
30887
|
+
const latest = this.#messages.at(-1);
|
|
30888
|
+
if (latest?.role === "assistant") {
|
|
30889
|
+
this.#messages[this.#messages.length - 1] = {
|
|
30890
|
+
...latest,
|
|
30891
|
+
activityIds: [...this.#turnActivityIds]
|
|
30892
|
+
};
|
|
30893
|
+
}
|
|
30894
|
+
},
|
|
30895
|
+
// History replay folds each narration into its snapshot activity, so no
|
|
30896
|
+
// separate incremental event is produced here.
|
|
30897
|
+
() => Promise.resolve()
|
|
30898
|
+
);
|
|
30803
30899
|
#lastMessageId = null;
|
|
30804
30900
|
#characters = 0;
|
|
30805
30901
|
#truncated = false;
|
|
@@ -31159,6 +31255,15 @@ var MAX_PRE_SESSION_UPDATES = 100;
|
|
|
31159
31255
|
var MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
|
|
31160
31256
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
31161
31257
|
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
31258
|
+
function nativeHistoryNotRetained() {
|
|
31259
|
+
return {
|
|
31260
|
+
cause: {
|
|
31261
|
+
code: "native_history_not_retained",
|
|
31262
|
+
message: "Native message history is not retained in the cloud for this Session."
|
|
31263
|
+
},
|
|
31264
|
+
status: "unavailable"
|
|
31265
|
+
};
|
|
31266
|
+
}
|
|
31162
31267
|
var NullAcpSessionObserver = class {
|
|
31163
31268
|
onCommands = () => Promise.resolve();
|
|
31164
31269
|
onConfig = () => Promise.resolve();
|
|
@@ -31609,7 +31714,10 @@ var AcpTurnState = class {
|
|
|
31609
31714
|
var IdleAcpTurn = class extends AcpTurnState {
|
|
31610
31715
|
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
31611
31716
|
running = false;
|
|
31612
|
-
activities = new AcpActivityTracker(
|
|
31717
|
+
activities = new AcpActivityTracker(
|
|
31718
|
+
() => Promise.resolve(),
|
|
31719
|
+
() => Promise.resolve()
|
|
31720
|
+
);
|
|
31613
31721
|
onText = () => Promise.resolve();
|
|
31614
31722
|
};
|
|
31615
31723
|
var RunningAcpTurn = class extends AcpTurnState {
|
|
@@ -31617,10 +31725,10 @@ var RunningAcpTurn = class extends AcpTurnState {
|
|
|
31617
31725
|
running = true;
|
|
31618
31726
|
activities;
|
|
31619
31727
|
onText;
|
|
31620
|
-
constructor(commandId, onActivity, onText, prepareContent) {
|
|
31728
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
31621
31729
|
super();
|
|
31622
31730
|
this.commandId = commandId;
|
|
31623
|
-
this.activities = new AcpActivityTracker(onActivity, prepareContent);
|
|
31731
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
31624
31732
|
this.onText = onText;
|
|
31625
31733
|
}
|
|
31626
31734
|
};
|
|
@@ -32425,6 +32533,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
32425
32533
|
const running = new RunningAcpTurn(
|
|
32426
32534
|
options.commandId,
|
|
32427
32535
|
options.onActivity,
|
|
32536
|
+
options.onNarration,
|
|
32428
32537
|
options.onText,
|
|
32429
32538
|
this.prepareAgentContent
|
|
32430
32539
|
);
|
|
@@ -33824,7 +33933,7 @@ var AcpSessionManager = class {
|
|
|
33824
33933
|
this.#endSessionUse(options.sessionId);
|
|
33825
33934
|
}
|
|
33826
33935
|
};
|
|
33827
|
-
openNativeSession = async (options, origin) => {
|
|
33936
|
+
openNativeSession = async (options, origin, loadHistory) => {
|
|
33828
33937
|
const key = `${options.agent.id}:${origin.nativeSessionId}`;
|
|
33829
33938
|
if (this.#nativeOperations.has(key)) {
|
|
33830
33939
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
@@ -33854,7 +33963,7 @@ var AcpSessionManager = class {
|
|
|
33854
33963
|
}
|
|
33855
33964
|
this.#nativeOperations.add(key);
|
|
33856
33965
|
try {
|
|
33857
|
-
const history = await runtime.loadHistory(options.signal);
|
|
33966
|
+
const history = loadHistory ? await runtime.loadHistory(options.signal) : nativeHistoryNotRetained();
|
|
33858
33967
|
return {
|
|
33859
33968
|
prepared: runtime.prepared(),
|
|
33860
33969
|
sessionId: existing.sessionId,
|
|
@@ -33885,7 +33994,7 @@ var AcpSessionManager = class {
|
|
|
33885
33994
|
const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
|
|
33886
33995
|
this.#nativeOperations.add(openedKey);
|
|
33887
33996
|
try {
|
|
33888
|
-
const history = await runtime.loadHistory(options.signal);
|
|
33997
|
+
const history = loadHistory ? await runtime.loadHistory(options.signal) : nativeHistoryNotRetained();
|
|
33889
33998
|
return {
|
|
33890
33999
|
sessionId: options.sessionId,
|
|
33891
34000
|
prepared: runtime.prepared(),
|
|
@@ -34030,6 +34139,7 @@ async function runAcpPrompt(options) {
|
|
|
34030
34139
|
commandId: crypto.randomUUID(),
|
|
34031
34140
|
images: [],
|
|
34032
34141
|
onActivity: options.onActivity,
|
|
34142
|
+
...options.onNarration === void 0 ? {} : { onNarration: options.onNarration },
|
|
34033
34143
|
onText: options.onText,
|
|
34034
34144
|
prompt: options.prompt,
|
|
34035
34145
|
resources: [],
|
|
@@ -34809,8 +34919,49 @@ var mcpElicitationParamsSchema = external_exports.object({
|
|
|
34809
34919
|
url: external_exports.string().optional()
|
|
34810
34920
|
});
|
|
34811
34921
|
var threadStartResponseSchema = external_exports.object({
|
|
34922
|
+
approvalPolicy: external_exports.unknown().optional(),
|
|
34923
|
+
approvalsReviewer: external_exports.unknown().optional(),
|
|
34924
|
+
model: boundedText(256).nullish(),
|
|
34925
|
+
reasoningEffort: boundedText(256).nullish(),
|
|
34926
|
+
sandbox: external_exports.unknown().optional(),
|
|
34927
|
+
serviceTier: boundedText(256).nullish(),
|
|
34812
34928
|
thread: external_exports.object({ id: boundedText(256) })
|
|
34813
34929
|
});
|
|
34930
|
+
var threadResumeResponseSchema = external_exports.object({
|
|
34931
|
+
model: boundedText(256).nullish(),
|
|
34932
|
+
reasoningEffort: boundedText(256).nullish(),
|
|
34933
|
+
thread: external_exports.object({ id: boundedText(256) }).nullish()
|
|
34934
|
+
});
|
|
34935
|
+
var reasoningEffortOptionSchema = external_exports.object({
|
|
34936
|
+
description: boundedText(4096).nullish(),
|
|
34937
|
+
reasoningEffort: boundedText(256)
|
|
34938
|
+
});
|
|
34939
|
+
var modelSchema = external_exports.object({
|
|
34940
|
+
additionalSpeedTiers: external_exports.array(boundedText(256)).max(100).nullish(),
|
|
34941
|
+
defaultReasoningEffort: boundedText(256).nullish(),
|
|
34942
|
+
description: boundedText(4096).nullish(),
|
|
34943
|
+
displayName: boundedText(256).nullish(),
|
|
34944
|
+
id: boundedText(256),
|
|
34945
|
+
isDefault: external_exports.boolean().nullish(),
|
|
34946
|
+
supportedReasoningEfforts: external_exports.array(reasoningEffortOptionSchema).max(100).nullish()
|
|
34947
|
+
});
|
|
34948
|
+
var modelListResponseSchema = external_exports.object({
|
|
34949
|
+
data: external_exports.array(modelSchema).max(1e3),
|
|
34950
|
+
nextCursor: boundedText(1024).nullish()
|
|
34951
|
+
});
|
|
34952
|
+
var threadSchema = external_exports.object({
|
|
34953
|
+
createdAt: external_exports.number().nullish(),
|
|
34954
|
+
cwd: boundedText(4096).nullish(),
|
|
34955
|
+
id: boundedText(256),
|
|
34956
|
+
name: boundedText(4096).nullish(),
|
|
34957
|
+
preview: boundedText(4096).nullish(),
|
|
34958
|
+
updatedAt: external_exports.number().nullish()
|
|
34959
|
+
});
|
|
34960
|
+
var threadListResponseSchema = external_exports.object({
|
|
34961
|
+
data: external_exports.array(threadSchema).max(1e4),
|
|
34962
|
+
nextCursor: boundedText(1024).nullish()
|
|
34963
|
+
});
|
|
34964
|
+
var turnSteerResponseSchema = external_exports.object({ turnId: boundedText(256) });
|
|
34814
34965
|
|
|
34815
34966
|
// src/acp/codex/app-server-client.ts
|
|
34816
34967
|
var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
|
|
@@ -35150,6 +35301,77 @@ function agentMessageMeta(phase) {
|
|
|
35150
35301
|
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
35151
35302
|
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
35152
35303
|
var CODEX_AGENT_VERSION = "0.154.0";
|
|
35304
|
+
var STEERING_METHOD = "_session/steering";
|
|
35305
|
+
var MODEL_SETTING_ID = "model";
|
|
35306
|
+
var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
|
|
35307
|
+
var MODE_SETTING_ID = "mode";
|
|
35308
|
+
var FAST_MODE_SETTING_ID = "fast-mode";
|
|
35309
|
+
var MODEL_CATALOG_LIMIT = 1e3;
|
|
35310
|
+
var FAST_TIER = "fast";
|
|
35311
|
+
var SERVICE_TIER_FAST = "priority";
|
|
35312
|
+
var WORKSPACE_WRITE_POLICY = Object.freeze({
|
|
35313
|
+
excludeSlashTmp: false,
|
|
35314
|
+
excludeTmpdirEnvVar: false,
|
|
35315
|
+
networkAccess: false,
|
|
35316
|
+
type: "workspaceWrite",
|
|
35317
|
+
writableRoots: []
|
|
35318
|
+
});
|
|
35319
|
+
var READ_ONLY_MODE = Object.freeze({
|
|
35320
|
+
approvalPolicy: "on-request",
|
|
35321
|
+
approvalsReviewer: "user",
|
|
35322
|
+
description: "Always ask to edit external files and use the internet",
|
|
35323
|
+
id: "read-only",
|
|
35324
|
+
name: "Ask for approval",
|
|
35325
|
+
sandboxPolicy: WORKSPACE_WRITE_POLICY
|
|
35326
|
+
});
|
|
35327
|
+
var AGENT_MODE = Object.freeze({
|
|
35328
|
+
approvalPolicy: "on-request",
|
|
35329
|
+
approvalsReviewer: "auto_review",
|
|
35330
|
+
description: "Only ask for actions detected as potentially unsafe",
|
|
35331
|
+
id: "agent",
|
|
35332
|
+
name: "Approve for me",
|
|
35333
|
+
sandboxPolicy: WORKSPACE_WRITE_POLICY
|
|
35334
|
+
});
|
|
35335
|
+
var FULL_ACCESS_MODE = Object.freeze({
|
|
35336
|
+
approvalPolicy: "never",
|
|
35337
|
+
approvalsReviewer: "user",
|
|
35338
|
+
description: "Unrestricted access to the internet and any file on your computer",
|
|
35339
|
+
id: "agent-full-access",
|
|
35340
|
+
name: "Full access",
|
|
35341
|
+
sandboxPolicy: { type: "dangerFullAccess" }
|
|
35342
|
+
});
|
|
35343
|
+
var AGENT_MODES = Object.freeze([READ_ONLY_MODE, AGENT_MODE, FULL_ACCESS_MODE]);
|
|
35344
|
+
var DEFAULT_MODE = AGENT_MODE;
|
|
35345
|
+
function initialMode(environment) {
|
|
35346
|
+
const requested = environment["INITIAL_AGENT_MODE"];
|
|
35347
|
+
if (requested === void 0) {
|
|
35348
|
+
return DEFAULT_MODE.id;
|
|
35349
|
+
}
|
|
35350
|
+
return AGENT_MODES.some((mode) => mode.id === requested) ? requested : DEFAULT_MODE.id;
|
|
35351
|
+
}
|
|
35352
|
+
function capitalize(value) {
|
|
35353
|
+
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
35354
|
+
}
|
|
35355
|
+
function threadTitle(thread) {
|
|
35356
|
+
const named = thread.name?.trim() ?? "";
|
|
35357
|
+
if (named.length > 0) {
|
|
35358
|
+
return named;
|
|
35359
|
+
}
|
|
35360
|
+
return thread.preview?.trim() ?? "";
|
|
35361
|
+
}
|
|
35362
|
+
function isoTimestamp(seconds) {
|
|
35363
|
+
if (seconds == null || !Number.isFinite(seconds)) {
|
|
35364
|
+
return null;
|
|
35365
|
+
}
|
|
35366
|
+
return new Date(seconds * 1e3).toISOString();
|
|
35367
|
+
}
|
|
35368
|
+
function steeringParams(params) {
|
|
35369
|
+
const prompt = typeof params === "object" && params !== null ? Reflect.get(params, "prompt") : void 0;
|
|
35370
|
+
if (!Array.isArray(prompt)) {
|
|
35371
|
+
throw new AcpExecutionError("The steering prompt is invalid", {}, "steering_failed");
|
|
35372
|
+
}
|
|
35373
|
+
return { prompt };
|
|
35374
|
+
}
|
|
35153
35375
|
var APPROVAL_OPTIONS = Object.freeze([
|
|
35154
35376
|
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
35155
35377
|
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
@@ -35187,6 +35409,84 @@ function promptInput(prompt) {
|
|
|
35187
35409
|
}
|
|
35188
35410
|
return input2;
|
|
35189
35411
|
}
|
|
35412
|
+
function modelValues(models) {
|
|
35413
|
+
return models.map((model) => ({
|
|
35414
|
+
description: model.description ?? "",
|
|
35415
|
+
name: model.displayName ?? model.id,
|
|
35416
|
+
value: model.id
|
|
35417
|
+
}));
|
|
35418
|
+
}
|
|
35419
|
+
function effortValues(model) {
|
|
35420
|
+
return (model?.supportedReasoningEfforts ?? []).map((option) => ({
|
|
35421
|
+
description: option.description ?? "",
|
|
35422
|
+
name: capitalize(option.reasoningEffort),
|
|
35423
|
+
value: option.reasoningEffort
|
|
35424
|
+
}));
|
|
35425
|
+
}
|
|
35426
|
+
function modelSetting(models, currentValue) {
|
|
35427
|
+
const values = modelValues(models);
|
|
35428
|
+
const current = currentValue.length > 0 ? currentValue : models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "";
|
|
35429
|
+
if (current.length === 0) {
|
|
35430
|
+
return null;
|
|
35431
|
+
}
|
|
35432
|
+
const options = values.some((value) => value.value === current) ? values : [{ description: "", name: current, value: current }, ...values];
|
|
35433
|
+
return {
|
|
35434
|
+
category: "model",
|
|
35435
|
+
currentValue: current,
|
|
35436
|
+
description: "Model Codex uses for the session",
|
|
35437
|
+
id: MODEL_SETTING_ID,
|
|
35438
|
+
name: "Model",
|
|
35439
|
+
options,
|
|
35440
|
+
type: "select"
|
|
35441
|
+
};
|
|
35442
|
+
}
|
|
35443
|
+
function modeSetting(currentValue) {
|
|
35444
|
+
return {
|
|
35445
|
+
category: "mode",
|
|
35446
|
+
currentValue,
|
|
35447
|
+
description: "Approval and sandboxing preset for the session",
|
|
35448
|
+
id: MODE_SETTING_ID,
|
|
35449
|
+
name: "Mode",
|
|
35450
|
+
options: AGENT_MODES.map((mode) => ({
|
|
35451
|
+
description: mode.description,
|
|
35452
|
+
name: mode.name,
|
|
35453
|
+
value: mode.id
|
|
35454
|
+
})),
|
|
35455
|
+
type: "select"
|
|
35456
|
+
};
|
|
35457
|
+
}
|
|
35458
|
+
function fastModeSetting(model, enabled) {
|
|
35459
|
+
if (model?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
35460
|
+
return null;
|
|
35461
|
+
}
|
|
35462
|
+
return {
|
|
35463
|
+
category: "model_config",
|
|
35464
|
+
currentValue: enabled,
|
|
35465
|
+
description: "1.5x speed, increased usage",
|
|
35466
|
+
id: FAST_MODE_SETTING_ID,
|
|
35467
|
+
name: "Fast mode",
|
|
35468
|
+
type: "boolean"
|
|
35469
|
+
};
|
|
35470
|
+
}
|
|
35471
|
+
function effortSetting(model, currentValue) {
|
|
35472
|
+
const values = effortValues(model);
|
|
35473
|
+
if (values.length === 0) {
|
|
35474
|
+
return null;
|
|
35475
|
+
}
|
|
35476
|
+
const current = values.some((value) => value.value === currentValue) ? currentValue : values[0]?.value ?? "";
|
|
35477
|
+
if (current.length === 0) {
|
|
35478
|
+
return null;
|
|
35479
|
+
}
|
|
35480
|
+
return {
|
|
35481
|
+
category: "thought_level",
|
|
35482
|
+
currentValue: current,
|
|
35483
|
+
description: "How much reasoning effort the model should use",
|
|
35484
|
+
id: REASONING_EFFORT_SETTING_ID,
|
|
35485
|
+
name: "Reasoning effort",
|
|
35486
|
+
options: values,
|
|
35487
|
+
type: "select"
|
|
35488
|
+
};
|
|
35489
|
+
}
|
|
35190
35490
|
function userInputSchema(questions) {
|
|
35191
35491
|
const properties = {};
|
|
35192
35492
|
const required2 = [];
|
|
@@ -35211,10 +35511,21 @@ var CodexAcpAgent = class {
|
|
|
35211
35511
|
#app;
|
|
35212
35512
|
#appServer;
|
|
35213
35513
|
#connection = null;
|
|
35514
|
+
#models = [];
|
|
35214
35515
|
#nativeSessionId = "";
|
|
35516
|
+
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
35517
|
+
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
35518
|
+
#policySelected = false;
|
|
35519
|
+
#selection;
|
|
35215
35520
|
#turn = null;
|
|
35216
35521
|
#updateTail = Promise.resolve();
|
|
35217
35522
|
constructor(options) {
|
|
35523
|
+
this.#selection = {
|
|
35524
|
+
effort: "",
|
|
35525
|
+
fastMode: false,
|
|
35526
|
+
mode: initialMode(options.environment),
|
|
35527
|
+
model: ""
|
|
35528
|
+
};
|
|
35218
35529
|
this.#appServer = new CodexAppServerClient({
|
|
35219
35530
|
command: options.command,
|
|
35220
35531
|
cwd: options.cwd,
|
|
@@ -35234,10 +35545,12 @@ var CodexAcpAgent = class {
|
|
|
35234
35545
|
agentCapabilities: {
|
|
35235
35546
|
loadSession: false,
|
|
35236
35547
|
promptCapabilities: { embeddedContext: true, image: true },
|
|
35237
|
-
sessionCapabilities: { close: {} }
|
|
35548
|
+
sessionCapabilities: { close: {}, delete: {}, list: {}, resume: {} }
|
|
35238
35549
|
},
|
|
35239
35550
|
agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
|
|
35240
35551
|
authMethods: [],
|
|
35552
|
+
// Mobius reads this to decide whether mid-turn steering can be attempted at all.
|
|
35553
|
+
_meta: { steering: { supported: true } },
|
|
35241
35554
|
protocolVersion: PROTOCOL_VERSION2
|
|
35242
35555
|
})).onRequest(methods4.agent.session.new, async (context) => {
|
|
35243
35556
|
const created = threadStartResponseSchema.parse(
|
|
@@ -35248,9 +35561,92 @@ var CodexAcpAgent = class {
|
|
|
35248
35561
|
)
|
|
35249
35562
|
);
|
|
35250
35563
|
this.#nativeSessionId = created.thread.id;
|
|
35251
|
-
|
|
35564
|
+
this.#selection = {
|
|
35565
|
+
...this.#selection,
|
|
35566
|
+
effort: created.reasoningEffort ?? "",
|
|
35567
|
+
model: created.model ?? ""
|
|
35568
|
+
};
|
|
35569
|
+
return { configOptions: this.#configOptions(), sessionId: created.thread.id };
|
|
35570
|
+
}).onRequest(methods4.agent.session.resume, async (context) => {
|
|
35571
|
+
const resumed = threadResumeResponseSchema.parse(
|
|
35572
|
+
await this.#appServer.request(
|
|
35573
|
+
"thread/resume",
|
|
35574
|
+
{ cwd: context.params.cwd, threadId: context.params.sessionId },
|
|
35575
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
35576
|
+
)
|
|
35577
|
+
);
|
|
35578
|
+
if (resumed.thread == null) {
|
|
35579
|
+
throw new AcpExecutionError(
|
|
35580
|
+
"Codex no longer has the native session this conversation belongs to",
|
|
35581
|
+
{},
|
|
35582
|
+
"session_restore_unsupported"
|
|
35583
|
+
);
|
|
35584
|
+
}
|
|
35585
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
35586
|
+
this.#selection = {
|
|
35587
|
+
...this.#selection,
|
|
35588
|
+
effort: resumed.reasoningEffort ?? this.#selection.effort,
|
|
35589
|
+
model: resumed.model ?? this.#selection.model
|
|
35590
|
+
};
|
|
35591
|
+
return { configOptions: this.#configOptions() };
|
|
35592
|
+
}).onRequest(methods4.agent.session.list, async (context) => {
|
|
35593
|
+
const listed = threadListResponseSchema.parse(
|
|
35594
|
+
await this.#appServer.request(
|
|
35595
|
+
"thread/list",
|
|
35596
|
+
context.params.cursor === void 0 || context.params.cursor === null ? {} : { cursor: context.params.cursor },
|
|
35597
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
35598
|
+
)
|
|
35599
|
+
);
|
|
35600
|
+
return {
|
|
35601
|
+
nextCursor: listed.nextCursor ?? null,
|
|
35602
|
+
sessions: listed.data.map((thread) => ({
|
|
35603
|
+
// The thread id is a UUID, which satisfies the native session id contract.
|
|
35604
|
+
additionalDirectories: [],
|
|
35605
|
+
cwd: thread.cwd ?? "",
|
|
35606
|
+
sessionId: thread.id,
|
|
35607
|
+
title: threadTitle(thread),
|
|
35608
|
+
updatedAt: isoTimestamp(thread.updatedAt)
|
|
35609
|
+
}))
|
|
35610
|
+
};
|
|
35611
|
+
}).onRequest(methods4.agent.session.delete, async (context) => {
|
|
35612
|
+
await this.#appServer.request(
|
|
35613
|
+
"thread/archive",
|
|
35614
|
+
{ threadId: context.params.sessionId },
|
|
35615
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
35616
|
+
);
|
|
35617
|
+
return {};
|
|
35618
|
+
}).onRequest(methods4.agent.session.setConfigOption, async (context) => {
|
|
35619
|
+
this.#applySelection(context.params.configId, context.params.value);
|
|
35620
|
+
return { configOptions: this.#configOptions() };
|
|
35621
|
+
}).onRequest(methods4.agent.session.setMode, async (context) => {
|
|
35622
|
+
this.#applySelection(MODE_SETTING_ID, context.params.modeId);
|
|
35623
|
+
return {};
|
|
35252
35624
|
}).onRequest(methods4.agent.session.prompt, async (context) => {
|
|
35253
35625
|
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
35626
|
+
}).onRequest(STEERING_METHOD, steeringParams, async (context) => {
|
|
35627
|
+
const turn = this.#turn;
|
|
35628
|
+
if (turn === null || turn.turn.id.length === 0) {
|
|
35629
|
+
return { outcome: "promptRequired" };
|
|
35630
|
+
}
|
|
35631
|
+
try {
|
|
35632
|
+
const steered = turnSteerResponseSchema.parse(
|
|
35633
|
+
await this.#appServer.request(
|
|
35634
|
+
"turn/steer",
|
|
35635
|
+
{
|
|
35636
|
+
expectedTurnId: turn.turn.id,
|
|
35637
|
+
input: promptInput(context.params.prompt),
|
|
35638
|
+
threadId: this.#nativeSessionId
|
|
35639
|
+
},
|
|
35640
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
35641
|
+
)
|
|
35642
|
+
);
|
|
35643
|
+
return { outcome: steered.turnId === turn.turn.id ? "injected" : "startedNewTurn" };
|
|
35644
|
+
} catch (error62) {
|
|
35645
|
+
if (error62 instanceof CodexAppServerError) {
|
|
35646
|
+
return { outcome: "promptRequired" };
|
|
35647
|
+
}
|
|
35648
|
+
throw error62;
|
|
35649
|
+
}
|
|
35254
35650
|
}).onRequest(methods4.agent.session.close, async () => {
|
|
35255
35651
|
await this.#interruptTurn();
|
|
35256
35652
|
}).onNotification(methods4.agent.session.cancel, async () => {
|
|
@@ -35259,9 +35655,10 @@ var CodexAcpAgent = class {
|
|
|
35259
35655
|
}
|
|
35260
35656
|
/** The ACP agent app Mobius connects its own ACP client to, in-process. */
|
|
35261
35657
|
app = () => this.#app;
|
|
35262
|
-
/** Starts the app-server
|
|
35658
|
+
/** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
|
|
35263
35659
|
initialize = async (signal) => {
|
|
35264
35660
|
await this.#appServer.initialize(signal);
|
|
35661
|
+
await this.#loadModels(signal);
|
|
35265
35662
|
};
|
|
35266
35663
|
/**
|
|
35267
35664
|
* Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
|
|
@@ -35273,6 +35670,129 @@ var CodexAcpAgent = class {
|
|
|
35273
35670
|
this.#appServer.detach();
|
|
35274
35671
|
await stopProcessTree(child, captured);
|
|
35275
35672
|
};
|
|
35673
|
+
/**
|
|
35674
|
+
* Reads the model catalog once per app-server. A failure leaves the catalog empty, which costs
|
|
35675
|
+
* the Run settings panel its model selector; it must not cost the conversation itself, so the
|
|
35676
|
+
* turn lifecycle continues without settings rather than failing initialization.
|
|
35677
|
+
*/
|
|
35678
|
+
#loadModels = async (signal) => {
|
|
35679
|
+
const models = [];
|
|
35680
|
+
let cursor = null;
|
|
35681
|
+
try {
|
|
35682
|
+
do {
|
|
35683
|
+
const decoded = modelListResponseSchema.parse(
|
|
35684
|
+
await this.#appServer.request(
|
|
35685
|
+
"model/list",
|
|
35686
|
+
{ cursor, limit: null },
|
|
35687
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
35688
|
+
)
|
|
35689
|
+
);
|
|
35690
|
+
models.push(...decoded.data);
|
|
35691
|
+
cursor = decoded.nextCursor ?? null;
|
|
35692
|
+
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
35693
|
+
} catch (error62) {
|
|
35694
|
+
signal.throwIfAborted();
|
|
35695
|
+
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
35696
|
+
`);
|
|
35697
|
+
}
|
|
35698
|
+
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
35699
|
+
};
|
|
35700
|
+
#model = (id) => this.#models.find((model) => model.id === id);
|
|
35701
|
+
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
35702
|
+
#configOptions = () => {
|
|
35703
|
+
const options = [];
|
|
35704
|
+
const model = modelSetting(this.#models, this.#selection.model);
|
|
35705
|
+
if (model !== null) {
|
|
35706
|
+
options.push(model);
|
|
35707
|
+
}
|
|
35708
|
+
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
35709
|
+
if (effort !== null) {
|
|
35710
|
+
options.push(effort);
|
|
35711
|
+
}
|
|
35712
|
+
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
35713
|
+
if (fastMode !== null) {
|
|
35714
|
+
options.push(fastMode);
|
|
35715
|
+
}
|
|
35716
|
+
options.push(modeSetting(this.#selection.mode));
|
|
35717
|
+
return options;
|
|
35718
|
+
};
|
|
35719
|
+
/**
|
|
35720
|
+
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
35721
|
+
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
35722
|
+
* so the reply never advertises an effort the selected model cannot run.
|
|
35723
|
+
*/
|
|
35724
|
+
#applySelection = (configId, value) => {
|
|
35725
|
+
if (configId === FAST_MODE_SETTING_ID) {
|
|
35726
|
+
if (typeof value !== "boolean") {
|
|
35727
|
+
throw new AcpExecutionError(
|
|
35728
|
+
"The requested Codex setting is invalid",
|
|
35729
|
+
{},
|
|
35730
|
+
"invalid_session_configuration"
|
|
35731
|
+
);
|
|
35732
|
+
}
|
|
35733
|
+
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
35734
|
+
throw new AcpExecutionError(
|
|
35735
|
+
"The selected Codex model has no fast mode",
|
|
35736
|
+
{},
|
|
35737
|
+
"invalid_session_configuration"
|
|
35738
|
+
);
|
|
35739
|
+
}
|
|
35740
|
+
this.#selection = { ...this.#selection, fastMode: value };
|
|
35741
|
+
return;
|
|
35742
|
+
}
|
|
35743
|
+
if (typeof value !== "string") {
|
|
35744
|
+
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
35745
|
+
}
|
|
35746
|
+
if (configId === MODE_SETTING_ID) {
|
|
35747
|
+
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
35748
|
+
throw new AcpExecutionError(
|
|
35749
|
+
"The requested Codex mode is unavailable",
|
|
35750
|
+
{},
|
|
35751
|
+
"invalid_session_configuration"
|
|
35752
|
+
);
|
|
35753
|
+
}
|
|
35754
|
+
this.#selection = { ...this.#selection, mode: value };
|
|
35755
|
+
this.#policySelected = true;
|
|
35756
|
+
return;
|
|
35757
|
+
}
|
|
35758
|
+
if (configId === MODEL_SETTING_ID) {
|
|
35759
|
+
if (value === this.#selection.model) {
|
|
35760
|
+
return;
|
|
35761
|
+
}
|
|
35762
|
+
const model = this.#model(value);
|
|
35763
|
+
if (model === void 0) {
|
|
35764
|
+
throw new AcpExecutionError(
|
|
35765
|
+
"The requested Codex model is unavailable",
|
|
35766
|
+
{},
|
|
35767
|
+
"invalid_session_configuration"
|
|
35768
|
+
);
|
|
35769
|
+
}
|
|
35770
|
+
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
35771
|
+
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
35772
|
+
this.#selection = {
|
|
35773
|
+
...this.#selection,
|
|
35774
|
+
effort,
|
|
35775
|
+
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
35776
|
+
model: value
|
|
35777
|
+
};
|
|
35778
|
+
return;
|
|
35779
|
+
}
|
|
35780
|
+
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
35781
|
+
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
35782
|
+
(option) => option.reasoningEffort
|
|
35783
|
+
);
|
|
35784
|
+
if (!supported.includes(value)) {
|
|
35785
|
+
throw new AcpExecutionError(
|
|
35786
|
+
"The requested Codex reasoning effort is unavailable",
|
|
35787
|
+
{},
|
|
35788
|
+
"invalid_session_configuration"
|
|
35789
|
+
);
|
|
35790
|
+
}
|
|
35791
|
+
this.#selection = { ...this.#selection, effort: value };
|
|
35792
|
+
return;
|
|
35793
|
+
}
|
|
35794
|
+
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
35795
|
+
};
|
|
35276
35796
|
#emit = async (update) => {
|
|
35277
35797
|
const connection = this.#connection;
|
|
35278
35798
|
if (connection === null || this.#nativeSessionId.length === 0) {
|
|
@@ -35478,10 +35998,27 @@ var CodexAcpAgent = class {
|
|
|
35478
35998
|
const turn = { completion, turn: { id: "" } };
|
|
35479
35999
|
this.#turn = turn;
|
|
35480
36000
|
try {
|
|
36001
|
+
const selection = this.#selection;
|
|
36002
|
+
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
36003
|
+
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
35481
36004
|
const started = turnSchema.parse(
|
|
35482
36005
|
(await this.#appServer.request(
|
|
35483
36006
|
"turn/start",
|
|
35484
|
-
{
|
|
36007
|
+
{
|
|
36008
|
+
// Until a mode is chosen, `config.toml` decides the sandbox and approval
|
|
36009
|
+
// policy, and those fields stay off the turn so the host's own setup is
|
|
36010
|
+
// inherited rather than overridden.
|
|
36011
|
+
...this.#policySelected ? {
|
|
36012
|
+
approvalPolicy: mode.approvalPolicy,
|
|
36013
|
+
approvalsReviewer: mode.approvalsReviewer,
|
|
36014
|
+
sandboxPolicy: mode.sandboxPolicy
|
|
36015
|
+
} : {},
|
|
36016
|
+
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
36017
|
+
input: input2,
|
|
36018
|
+
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
36019
|
+
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
|
|
36020
|
+
threadId: this.#nativeSessionId
|
|
36021
|
+
},
|
|
35485
36022
|
signal
|
|
35486
36023
|
)).turn
|
|
35487
36024
|
);
|
|
@@ -39030,6 +39567,54 @@ var WorkspaceDirectoryService = class {
|
|
|
39030
39567
|
};
|
|
39031
39568
|
};
|
|
39032
39569
|
|
|
39570
|
+
// src/daemon-diagnostic-log.ts
|
|
39571
|
+
import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
39572
|
+
import { join as join17 } from "node:path";
|
|
39573
|
+
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
39574
|
+
var DaemonDiagnosticLog = class {
|
|
39575
|
+
#directory;
|
|
39576
|
+
#path;
|
|
39577
|
+
#maximumBytes;
|
|
39578
|
+
constructor(stateDirectory, maximumBytes = MAXIMUM_DAEMON_LOG_BYTES) {
|
|
39579
|
+
this.#directory = join17(stateDirectory, "logs");
|
|
39580
|
+
this.#path = join17(this.#directory, "daemon.log");
|
|
39581
|
+
this.#maximumBytes = maximumBytes;
|
|
39582
|
+
}
|
|
39583
|
+
record = (diagnostic) => {
|
|
39584
|
+
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
39585
|
+
`;
|
|
39586
|
+
const encodedBytes = Buffer.byteLength(encoded);
|
|
39587
|
+
mkdirSync3(this.#directory, { mode: 448, recursive: true });
|
|
39588
|
+
let existingBytes = 0;
|
|
39589
|
+
try {
|
|
39590
|
+
existingBytes = statSync3(this.#path).size;
|
|
39591
|
+
} catch (cause) {
|
|
39592
|
+
if (!(cause instanceof Error && Reflect.get(cause, "code") === "ENOENT")) {
|
|
39593
|
+
throw cause;
|
|
39594
|
+
}
|
|
39595
|
+
}
|
|
39596
|
+
if (existingBytes + encodedBytes <= this.#maximumBytes) {
|
|
39597
|
+
appendFileSync(this.#path, encoded, { encoding: "utf8", mode: 384 });
|
|
39598
|
+
return;
|
|
39599
|
+
}
|
|
39600
|
+
const lines = `${existingBytes === 0 ? "" : readFileSync2(this.#path, "utf8")}${encoded}`.split("\n").filter((line) => line.length > 0);
|
|
39601
|
+
let totalBytes = lines.reduce((total, line) => total + Buffer.byteLength(line) + 1, 0);
|
|
39602
|
+
while (totalBytes > this.#maximumBytes && lines.length > 0) {
|
|
39603
|
+
const oldest = lines.shift();
|
|
39604
|
+
if (oldest !== void 0) {
|
|
39605
|
+
totalBytes -= Buffer.byteLength(oldest) + 1;
|
|
39606
|
+
}
|
|
39607
|
+
}
|
|
39608
|
+
const temporaryPath = `${this.#path}.tmp`;
|
|
39609
|
+
writeFileSync(temporaryPath, lines.length === 0 ? "" : `${lines.join("\n")}
|
|
39610
|
+
`, {
|
|
39611
|
+
encoding: "utf8",
|
|
39612
|
+
mode: 384
|
|
39613
|
+
});
|
|
39614
|
+
renameSync(temporaryPath, this.#path);
|
|
39615
|
+
};
|
|
39616
|
+
};
|
|
39617
|
+
|
|
39033
39618
|
// src/native-sessions/codex-history.ts
|
|
39034
39619
|
import { spawn as spawn5 } from "node:child_process";
|
|
39035
39620
|
var responseSchema = external_exports.union([
|
|
@@ -39040,7 +39625,7 @@ var responseSchema = external_exports.union([
|
|
|
39040
39625
|
external_exports.object({ id: external_exports.number(), result: external_exports.unknown() }),
|
|
39041
39626
|
external_exports.object({ method: external_exports.string() })
|
|
39042
39627
|
]);
|
|
39043
|
-
var
|
|
39628
|
+
var threadSchema2 = external_exports.object({
|
|
39044
39629
|
thread: external_exports.object({
|
|
39045
39630
|
id: nativeSessionIdSchema,
|
|
39046
39631
|
cwd: external_exports.string().min(1).max(2048).refine((path2) => !path2.includes("\0"))
|
|
@@ -39344,7 +39929,7 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
|
|
|
39344
39929
|
});
|
|
39345
39930
|
break;
|
|
39346
39931
|
case "metadata": {
|
|
39347
|
-
const { thread } =
|
|
39932
|
+
const { thread } = threadSchema2.parse(message.result);
|
|
39348
39933
|
state = { kind: "turns", requestId: 3, thread };
|
|
39349
39934
|
send2({
|
|
39350
39935
|
id: state.requestId,
|
|
@@ -39616,10 +40201,11 @@ var NativeSessionService = class {
|
|
|
39616
40201
|
deletedSessionIds
|
|
39617
40202
|
};
|
|
39618
40203
|
}
|
|
39619
|
-
|
|
40204
|
+
const action = command.action === "import-only" ? "import" : command.action === "fork-only" ? "fork" : command.action;
|
|
40205
|
+
if (action === "import" && !prepared.capabilities.loadSession && !prepared.capabilities.resumeSession) {
|
|
39620
40206
|
throw new AcpExecutionError("This Agent cannot import native sessions", {}, "native_session_unsupported");
|
|
39621
40207
|
}
|
|
39622
|
-
if (
|
|
40208
|
+
if (action === "fork" && !prepared.capabilities.unstableForkSession) {
|
|
39623
40209
|
throw new AcpExecutionError(
|
|
39624
40210
|
"This Agent does not support session forking",
|
|
39625
40211
|
{},
|
|
@@ -39640,7 +40226,8 @@ var NativeSessionService = class {
|
|
|
39640
40226
|
sessionId: command.targetSessionId,
|
|
39641
40227
|
additionalDirectories: target.additionalDirectories
|
|
39642
40228
|
},
|
|
39643
|
-
{ kind:
|
|
40229
|
+
{ kind: action, nativeSessionId: target.info.sessionId },
|
|
40230
|
+
command.action !== "import-only" && command.action !== "fork-only"
|
|
39644
40231
|
);
|
|
39645
40232
|
signal.throwIfAborted();
|
|
39646
40233
|
const ready = {
|
|
@@ -39658,10 +40245,10 @@ var NativeSessionService = class {
|
|
|
39658
40245
|
restored: true,
|
|
39659
40246
|
sessionId: opened.sessionId
|
|
39660
40247
|
};
|
|
39661
|
-
this.record(command,
|
|
40248
|
+
this.record(command, action === "fork" ? "native_session_forked" : "native_session_imported");
|
|
39662
40249
|
return {
|
|
39663
40250
|
...envelope2,
|
|
39664
|
-
action
|
|
40251
|
+
action,
|
|
39665
40252
|
ready,
|
|
39666
40253
|
targetSessionId: command.targetSessionId,
|
|
39667
40254
|
title: target.info.title ?? "Untitled session",
|
|
@@ -40052,6 +40639,59 @@ async function resolvePromptArtifacts(config2, command, signal) {
|
|
|
40052
40639
|
return new ResolvedPromptArtifacts(images, resources);
|
|
40053
40640
|
}
|
|
40054
40641
|
|
|
40642
|
+
// src/relay-connection/coalescing-narration-publisher.ts
|
|
40643
|
+
var CoalescingNarrationPublisher = class {
|
|
40644
|
+
#coalescingMilliseconds;
|
|
40645
|
+
#maximumTextLength;
|
|
40646
|
+
#publish;
|
|
40647
|
+
#timer;
|
|
40648
|
+
#pending = /* @__PURE__ */ new Map();
|
|
40649
|
+
#scheduled = null;
|
|
40650
|
+
constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
|
|
40651
|
+
this.#publish = publish;
|
|
40652
|
+
this.#timer = timer;
|
|
40653
|
+
this.#coalescingMilliseconds = coalescingMilliseconds;
|
|
40654
|
+
this.#maximumTextLength = maximumTextLength;
|
|
40655
|
+
}
|
|
40656
|
+
/** Emit every buffered increment now, cancelling the pending flush. */
|
|
40657
|
+
flush = () => {
|
|
40658
|
+
this.#scheduled?.cancel();
|
|
40659
|
+
this.#scheduled = null;
|
|
40660
|
+
const increments = [...this.#pending.entries()].map(
|
|
40661
|
+
([activityId, pending]) => ({
|
|
40662
|
+
activityId,
|
|
40663
|
+
activityType: pending.activityType,
|
|
40664
|
+
sequence: pending.sequence,
|
|
40665
|
+
text: pending.text
|
|
40666
|
+
})
|
|
40667
|
+
);
|
|
40668
|
+
this.#pending.clear();
|
|
40669
|
+
for (const increment of increments) {
|
|
40670
|
+
this.#publish(increment);
|
|
40671
|
+
}
|
|
40672
|
+
};
|
|
40673
|
+
/**
|
|
40674
|
+
* Buffer an increment, emitting the buffered text when it would exceed the
|
|
40675
|
+
* protocol's per-event text limit so no event is rejected by the codec.
|
|
40676
|
+
*/
|
|
40677
|
+
record = (increment) => {
|
|
40678
|
+
if (increment.text.length === 0) {
|
|
40679
|
+
return;
|
|
40680
|
+
}
|
|
40681
|
+
const previous2 = this.#pending.get(increment.activityId);
|
|
40682
|
+
if (previous2 !== void 0 && previous2.text.length + increment.text.length > this.#maximumTextLength) {
|
|
40683
|
+
this.flush();
|
|
40684
|
+
}
|
|
40685
|
+
const current = this.#pending.get(increment.activityId);
|
|
40686
|
+
this.#pending.set(increment.activityId, {
|
|
40687
|
+
activityType: increment.activityType,
|
|
40688
|
+
sequence: increment.sequence,
|
|
40689
|
+
text: `${current?.text ?? ""}${increment.text}`
|
|
40690
|
+
});
|
|
40691
|
+
this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
|
|
40692
|
+
};
|
|
40693
|
+
};
|
|
40694
|
+
|
|
40055
40695
|
// src/relay-connection/coalescing-text-publisher.ts
|
|
40056
40696
|
var CoalescingTextPublisher = class {
|
|
40057
40697
|
#coalescingMilliseconds;
|
|
@@ -40241,13 +40881,15 @@ function addFailureDetails(details, failure2) {
|
|
|
40241
40881
|
var RelayConnectionDiagnostics = class {
|
|
40242
40882
|
#audit;
|
|
40243
40883
|
#channelId;
|
|
40884
|
+
#localLog;
|
|
40244
40885
|
#lastClosedEpoch = 0;
|
|
40245
40886
|
#lastFailedEpoch = 0;
|
|
40246
40887
|
#relayOrigin;
|
|
40247
40888
|
#route;
|
|
40248
|
-
constructor(audit, channelId, relayUrl) {
|
|
40889
|
+
constructor(audit, channelId, relayUrl, localLog) {
|
|
40249
40890
|
this.#audit = audit;
|
|
40250
40891
|
this.#channelId = channelId;
|
|
40892
|
+
this.#localLog = localLog;
|
|
40251
40893
|
this.#relayOrigin = relayUrl.origin;
|
|
40252
40894
|
this.#route = describeEnvironmentProxyRoute(relayUrl);
|
|
40253
40895
|
}
|
|
@@ -40334,6 +40976,20 @@ var RelayConnectionDiagnostics = class {
|
|
|
40334
40976
|
true
|
|
40335
40977
|
);
|
|
40336
40978
|
};
|
|
40979
|
+
daemonDiagnostic = (event, requestId, details, failure2) => {
|
|
40980
|
+
const recordedDetails = { ...details };
|
|
40981
|
+
if (failure2 !== void 0) {
|
|
40982
|
+
addFailureDetails(recordedDetails, failure2);
|
|
40983
|
+
}
|
|
40984
|
+
this.#localLog.record(
|
|
40985
|
+
`Mobius daemon diagnostic ${JSON.stringify({
|
|
40986
|
+
channelId: this.#channelId,
|
|
40987
|
+
event,
|
|
40988
|
+
requestId,
|
|
40989
|
+
...recordedDetails
|
|
40990
|
+
})}`
|
|
40991
|
+
);
|
|
40992
|
+
};
|
|
40337
40993
|
#record = (event, commandId, details, warning) => {
|
|
40338
40994
|
this.#audit.record({
|
|
40339
40995
|
commandId,
|
|
@@ -40342,6 +40998,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
40342
40998
|
sessionId: this.#channelId
|
|
40343
40999
|
});
|
|
40344
41000
|
const encoded = JSON.stringify({ channelId: this.#channelId, event, ...details });
|
|
41001
|
+
this.#localLog.record(`Mobius relay diagnostic ${encoded}`);
|
|
40345
41002
|
if (warning) {
|
|
40346
41003
|
process.stderr.write(`Mobius relay diagnostic ${encoded}
|
|
40347
41004
|
`);
|
|
@@ -40459,7 +41116,7 @@ var RelayConnectionLiveness = class {
|
|
|
40459
41116
|
};
|
|
40460
41117
|
|
|
40461
41118
|
// src/relay-connection/session-event-outbox.ts
|
|
40462
|
-
import { mkdirSync as
|
|
41119
|
+
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
40463
41120
|
import { dirname as dirname7 } from "node:path";
|
|
40464
41121
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
40465
41122
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
@@ -40526,7 +41183,7 @@ var SessionEventOutbox = class {
|
|
|
40526
41183
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
40527
41184
|
validateLimits(limits);
|
|
40528
41185
|
this.#limits = limits;
|
|
40529
|
-
|
|
41186
|
+
mkdirSync4(dirname7(path2), { recursive: true });
|
|
40530
41187
|
this.#database = new DatabaseSync3(path2);
|
|
40531
41188
|
this.#database.exec(`
|
|
40532
41189
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -40752,6 +41409,19 @@ var SessionEventOutbox = class {
|
|
|
40752
41409
|
return this.#enqueueBounded(sessionId, payload, attemptId ?? "", this.#limits.standardEventBytes);
|
|
40753
41410
|
};
|
|
40754
41411
|
enqueueCritical = (sessionId, payload, attemptId = "") => this.#enqueueBounded(sessionId, payload, attemptId, this.#limits.criticalEventBytes);
|
|
41412
|
+
/**
|
|
41413
|
+
* Bytes still available to standard Session events. The daemon uses this to shed
|
|
41414
|
+
* superseded streaming events instead of filling the durable outbox, so a long Turn
|
|
41415
|
+
* behind a slow Relay cannot make the next enqueue throw.
|
|
41416
|
+
*/
|
|
41417
|
+
standardCapacityRemaining = () => {
|
|
41418
|
+
const state = this.#database.prepare(
|
|
41419
|
+
`SELECT total_bytes
|
|
41420
|
+
FROM relay_session_event_outbox_state
|
|
41421
|
+
WHERE singleton = 1`
|
|
41422
|
+
).get();
|
|
41423
|
+
return this.#limits.standardEventBytes - rowNumber(state, "total_bytes");
|
|
41424
|
+
};
|
|
40755
41425
|
claimRuntimeDelivery = (delivery) => {
|
|
40756
41426
|
const payloadBytes = new TextEncoder().encode(delivery.payload).byteLength;
|
|
40757
41427
|
this.#database.exec("BEGIN IMMEDIATE");
|
|
@@ -41360,6 +42030,12 @@ var ConnectedDaemonSessionEventState = class extends DaemonSessionEventConnectio
|
|
|
41360
42030
|
var SESSION_EVENT_REPLAY_WINDOW = 16;
|
|
41361
42031
|
var SESSION_EVENT_SOURCE_REPLAY_WINDOW = 4;
|
|
41362
42032
|
var SESSION_EVENT_REPLAY_BYTE_LIMIT = 32 * 1024 * 1024;
|
|
42033
|
+
function reservesSessionEventCapacity(event) {
|
|
42034
|
+
if (event.kind === SESSION_COMPLETED_KIND || event.kind === SESSION_FAILED_KIND) {
|
|
42035
|
+
return true;
|
|
42036
|
+
}
|
|
42037
|
+
return event.kind === AGENT_ACTIVITY_KIND && (event.activityType === "progress" || event.activityType === "reasoning") && (event.status === "completed" || event.status === "failed");
|
|
42038
|
+
}
|
|
41363
42039
|
var InFlightSessionEvent = class {
|
|
41364
42040
|
byteLength;
|
|
41365
42041
|
sourceKey;
|
|
@@ -41375,6 +42051,7 @@ var DaemonSessionEventPublisher = class {
|
|
|
41375
42051
|
#outbox;
|
|
41376
42052
|
#inFlightEvents = /* @__PURE__ */ new Map();
|
|
41377
42053
|
#pausedSources = /* @__PURE__ */ new Map();
|
|
42054
|
+
#shedEventKinds = /* @__PURE__ */ new Set();
|
|
41378
42055
|
#timer;
|
|
41379
42056
|
#inFlightBytes = 0;
|
|
41380
42057
|
#connection = new DisconnectedDaemonSessionEventState();
|
|
@@ -41396,17 +42073,64 @@ var DaemonSessionEventPublisher = class {
|
|
|
41396
42073
|
};
|
|
41397
42074
|
recordAttempt = (sessionId, event, attemptId) => {
|
|
41398
42075
|
const encoded = encodeRecordedSessionEvent(event);
|
|
41399
|
-
if (event
|
|
41400
|
-
this.#
|
|
42076
|
+
if (reservesSessionEventCapacity(event)) {
|
|
42077
|
+
this.#enqueueReserved(sessionId, encoded, attemptId, event.kind);
|
|
41401
42078
|
} else {
|
|
41402
|
-
this.#
|
|
42079
|
+
this.#enqueueStandard(sessionId, encoded, attemptId, event.kind);
|
|
41403
42080
|
}
|
|
41404
42081
|
this.#publishNextBatch();
|
|
41405
42082
|
};
|
|
41406
42083
|
recordRuntime = (sessionId, event) => {
|
|
41407
|
-
this.#
|
|
42084
|
+
this.#enqueueStandard(sessionId, encodeRecordedSessionEvent(event), "", event.kind);
|
|
41408
42085
|
this.#publishNextBatch();
|
|
41409
42086
|
};
|
|
42087
|
+
/**
|
|
42088
|
+
* Enqueue a standard event, shedding it instead of ending the daemon when the
|
|
42089
|
+
* durable outbox is full.
|
|
42090
|
+
*
|
|
42091
|
+
* A capacity error used to escape the coalescing timer that publishes activities,
|
|
42092
|
+
* so the process exited and every restart died on the same retained backlog. A full
|
|
42093
|
+
* outbox is a recoverable runtime condition, not a fatal one: narration increments are
|
|
42094
|
+
* superseded by the completed snapshot, so they are shed first, and any other streaming
|
|
42095
|
+
* event is shed only at the wall rather than terminating the daemon.
|
|
42096
|
+
*/
|
|
42097
|
+
#enqueueStandard = (sessionId, encoded, attemptId, kind) => {
|
|
42098
|
+
if (kind === AGENT_ACTIVITY_NARRATION_KIND && this.#outbox.standardCapacityRemaining() <= 0) {
|
|
42099
|
+
this.#reportShedEvent(kind);
|
|
42100
|
+
return;
|
|
42101
|
+
}
|
|
42102
|
+
try {
|
|
42103
|
+
this.#outbox.enqueue(sessionId, encoded, attemptId);
|
|
42104
|
+
} catch (error62) {
|
|
42105
|
+
if (!(error62 instanceof SessionEventOutboxCapacityError)) {
|
|
42106
|
+
throw error62;
|
|
42107
|
+
}
|
|
42108
|
+
this.#reportShedEvent(kind);
|
|
42109
|
+
}
|
|
42110
|
+
};
|
|
42111
|
+
/**
|
|
42112
|
+
* Enqueue on the reserved budget, degrading to a reported drop instead of raising.
|
|
42113
|
+
* Streaming events are shed before this budget is reached, so a Turn's terminal
|
|
42114
|
+
* events and the completed snapshot that carries its narration still land; a drop
|
|
42115
|
+
* here is the last resort for a backlog no acknowledgement can drain.
|
|
42116
|
+
*/
|
|
42117
|
+
#enqueueReserved = (sessionId, encoded, attemptId, kind) => {
|
|
42118
|
+
try {
|
|
42119
|
+
this.#outbox.enqueueCritical(sessionId, encoded, attemptId);
|
|
42120
|
+
} catch (error62) {
|
|
42121
|
+
if (!(error62 instanceof SessionEventOutboxCapacityError)) {
|
|
42122
|
+
throw error62;
|
|
42123
|
+
}
|
|
42124
|
+
this.#reportShedEvent(kind);
|
|
42125
|
+
}
|
|
42126
|
+
};
|
|
42127
|
+
#reportShedEvent = (kind) => {
|
|
42128
|
+
if (this.#shedEventKinds.has(kind)) {
|
|
42129
|
+
return;
|
|
42130
|
+
}
|
|
42131
|
+
this.#shedEventKinds.add(kind);
|
|
42132
|
+
console.warn(`Mobius daemon is dropping durable "${kind}" events because the Session event outbox is full`);
|
|
42133
|
+
};
|
|
41410
42134
|
acknowledge = (acknowledgement) => {
|
|
41411
42135
|
if (!this.#outbox.acknowledge(acknowledgement)) {
|
|
41412
42136
|
return;
|
|
@@ -42133,6 +42857,26 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42133
42857
|
const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
|
|
42134
42858
|
publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
|
|
42135
42859
|
});
|
|
42860
|
+
const narration = new CoalescingNarrationPublisher(
|
|
42861
|
+
timer,
|
|
42862
|
+
(increment) => {
|
|
42863
|
+
publisher.recordAttempt(
|
|
42864
|
+
command.sessionId,
|
|
42865
|
+
{
|
|
42866
|
+
activityId: increment.activityId,
|
|
42867
|
+
activityType: increment.activityType,
|
|
42868
|
+
commandId: command.commandId,
|
|
42869
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
42870
|
+
sequence: increment.sequence,
|
|
42871
|
+
sessionId: command.sessionId,
|
|
42872
|
+
text: increment.text
|
|
42873
|
+
},
|
|
42874
|
+
attemptId
|
|
42875
|
+
);
|
|
42876
|
+
},
|
|
42877
|
+
AGENT_ACTIVITY_COALESCING_MILLISECONDS,
|
|
42878
|
+
AGENT_TEXT_MAXIMUM_LENGTH
|
|
42879
|
+
);
|
|
42136
42880
|
const text3 = new CoalescingTextPublisher(
|
|
42137
42881
|
timer,
|
|
42138
42882
|
(messageId, delta) => {
|
|
@@ -42237,6 +42981,10 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42237
42981
|
disposition: command.disposition,
|
|
42238
42982
|
images: attachments.images,
|
|
42239
42983
|
onActivity: activities.record,
|
|
42984
|
+
onNarration: (increment) => {
|
|
42985
|
+
narration.record(increment);
|
|
42986
|
+
return Promise.resolve();
|
|
42987
|
+
},
|
|
42240
42988
|
onText: (delta, messageId) => {
|
|
42241
42989
|
text3.record(messageId, delta);
|
|
42242
42990
|
return Promise.resolve();
|
|
@@ -42250,6 +42998,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42250
42998
|
stopReason = result.stopReason;
|
|
42251
42999
|
}
|
|
42252
43000
|
text3.flush();
|
|
43001
|
+
narration.flush();
|
|
42253
43002
|
activities.flush();
|
|
42254
43003
|
publisher.recordAttempt(
|
|
42255
43004
|
command.sessionId,
|
|
@@ -42269,6 +43018,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42269
43018
|
});
|
|
42270
43019
|
} catch (error62) {
|
|
42271
43020
|
text3.flush();
|
|
43021
|
+
narration.flush();
|
|
42272
43022
|
activities.flush();
|
|
42273
43023
|
audit.record({
|
|
42274
43024
|
commandId: command.commandId,
|
|
@@ -42990,6 +43740,11 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
42990
43740
|
event: "agent_settings_model_unsupported",
|
|
42991
43741
|
sessionId: `agent-settings:${command2.agentId}`
|
|
42992
43742
|
});
|
|
43743
|
+
diagnostics.daemonDiagnostic(
|
|
43744
|
+
"agent_settings_model_unsupported",
|
|
43745
|
+
command2.requestId,
|
|
43746
|
+
details
|
|
43747
|
+
);
|
|
42993
43748
|
process.stderr.write(
|
|
42994
43749
|
`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_model_unsupported", requestId: command2.requestId, ...details })}
|
|
42995
43750
|
`
|
|
@@ -43020,6 +43775,12 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43020
43775
|
event: "agent_settings_discovery_failed",
|
|
43021
43776
|
sessionId: `agent-settings:${command2.agentId}`
|
|
43022
43777
|
});
|
|
43778
|
+
diagnostics.daemonDiagnostic(
|
|
43779
|
+
"agent_settings_discovery_failed",
|
|
43780
|
+
command2.requestId,
|
|
43781
|
+
details,
|
|
43782
|
+
failure2
|
|
43783
|
+
);
|
|
43023
43784
|
if (failure2 instanceof AcpConfigurationValueUnavailableError) {
|
|
43024
43785
|
process.stderr.write(
|
|
43025
43786
|
`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_discovery_failed", requestId: command2.requestId, ...details })}
|
|
@@ -43097,6 +43858,12 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43097
43858
|
event: "agent_catalog_refresh_failed",
|
|
43098
43859
|
sessionId: "agent-catalog"
|
|
43099
43860
|
});
|
|
43861
|
+
diagnostics.daemonDiagnostic(
|
|
43862
|
+
"agent_catalog_refresh_failed",
|
|
43863
|
+
command2.requestId,
|
|
43864
|
+
{ code: operationErrorCode(failure2) },
|
|
43865
|
+
failure2
|
|
43866
|
+
);
|
|
43100
43867
|
if (socket.readyState === WebSocket2.OPEN) {
|
|
43101
43868
|
send(socket, {
|
|
43102
43869
|
code: operationErrorCode(failure2),
|
|
@@ -43181,6 +43948,17 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43181
43948
|
event: "native_session_operation_failed",
|
|
43182
43949
|
details: { code: operationErrorCode(failure2) }
|
|
43183
43950
|
});
|
|
43951
|
+
diagnostics.daemonDiagnostic(
|
|
43952
|
+
"native_session_operation_failed",
|
|
43953
|
+
command2.requestId,
|
|
43954
|
+
{
|
|
43955
|
+
action: command2.action,
|
|
43956
|
+
agentId: command2.agentId,
|
|
43957
|
+
code: operationErrorCode(failure2),
|
|
43958
|
+
sessionId: command2.sessionId
|
|
43959
|
+
},
|
|
43960
|
+
failure2
|
|
43961
|
+
);
|
|
43184
43962
|
reportOperationFailure(socket, command2.requestId, command2.sessionId, failure2);
|
|
43185
43963
|
} finally {
|
|
43186
43964
|
timeout.cancel();
|
|
@@ -43261,6 +44039,16 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43261
44039
|
event: "native_session_turn_fork_failed",
|
|
43262
44040
|
sessionId: command2.sessionId
|
|
43263
44041
|
});
|
|
44042
|
+
diagnostics.daemonDiagnostic(
|
|
44043
|
+
"native_session_turn_fork_failed",
|
|
44044
|
+
command2.requestId,
|
|
44045
|
+
{
|
|
44046
|
+
agentId: command2.agentId,
|
|
44047
|
+
code: operationErrorCode(failure2),
|
|
44048
|
+
sessionId: command2.sessionId
|
|
44049
|
+
},
|
|
44050
|
+
failure2
|
|
44051
|
+
);
|
|
43264
44052
|
reportOperationFailure(socket, command2.requestId, command2.sessionId, failure2);
|
|
43265
44053
|
} finally {
|
|
43266
44054
|
timeout.cancel();
|
|
@@ -43533,7 +44321,12 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
43533
44321
|
});
|
|
43534
44322
|
const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
|
|
43535
44323
|
const installationObserver = new DaemonInstallationObserver();
|
|
43536
|
-
const diagnostics = new RelayConnectionDiagnostics(
|
|
44324
|
+
const diagnostics = new RelayConnectionDiagnostics(
|
|
44325
|
+
audit,
|
|
44326
|
+
config2.channelId,
|
|
44327
|
+
config2.relayUrl,
|
|
44328
|
+
new DaemonDiagnosticLog(stateDirectory)
|
|
44329
|
+
);
|
|
43537
44330
|
const nativeSessions = new NativeSessionService(config2, directories, sessions, audit);
|
|
43538
44331
|
const installations = new AgentInstallationManager(
|
|
43539
44332
|
specifications,
|
|
@@ -43666,7 +44459,7 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
43666
44459
|
|
|
43667
44460
|
// src/runtime.ts
|
|
43668
44461
|
import { mkdir as mkdir6, realpath as realpath10, stat as stat9 } from "node:fs/promises";
|
|
43669
|
-
import { dirname as dirname8, join as
|
|
44462
|
+
import { dirname as dirname8, join as join18, resolve as resolve7 } from "node:path";
|
|
43670
44463
|
var IDENTIFIER_PATTERN7 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
|
|
43671
44464
|
var RUNTIME_CREDENTIAL_PATTERN2 = /^[a-zA-Z0-9_-]{32,256}$/;
|
|
43672
44465
|
var MobiusRuntimeConfigurationError = class extends Error {
|
|
@@ -43723,7 +44516,7 @@ function loadMobiusRuntimeConnection(environment = process.env) {
|
|
|
43723
44516
|
throw new MobiusRuntimeConfigurationError("MOBIUS_CHANNEL_ID is invalid");
|
|
43724
44517
|
}
|
|
43725
44518
|
return Object.freeze({
|
|
43726
|
-
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() ||
|
|
44519
|
+
auditDatabasePath: environment["MOBIUS_AUDIT_DATABASE"]?.trim() || join18(readStateDirectory(environment), "audit", `${channelId}.sqlite`),
|
|
43727
44520
|
channelId,
|
|
43728
44521
|
defaultWorkspace: loadDefaultWorkspace(environment),
|
|
43729
44522
|
relayUrl: requiredEnvironmentValue(environment, "MOBIUS_RELAY_URL"),
|