@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/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import { mkdir as mkdir6 } from "node:fs/promises";
|
|
|
11
11
|
// package.json
|
|
12
12
|
var package_default = {
|
|
13
13
|
name: "@moxt-ai/mobius",
|
|
14
|
-
version: "0.0.
|
|
14
|
+
version: "0.0.74",
|
|
15
15
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
16
16
|
type: "module",
|
|
17
17
|
bin: {
|
|
@@ -21268,8 +21268,49 @@ var mcpElicitationParamsSchema = external_exports.object({
|
|
|
21268
21268
|
url: external_exports.string().optional()
|
|
21269
21269
|
});
|
|
21270
21270
|
var threadStartResponseSchema = external_exports.object({
|
|
21271
|
+
approvalPolicy: external_exports.unknown().optional(),
|
|
21272
|
+
approvalsReviewer: external_exports.unknown().optional(),
|
|
21273
|
+
model: boundedText(256).nullish(),
|
|
21274
|
+
reasoningEffort: boundedText(256).nullish(),
|
|
21275
|
+
sandbox: external_exports.unknown().optional(),
|
|
21276
|
+
serviceTier: boundedText(256).nullish(),
|
|
21271
21277
|
thread: external_exports.object({ id: boundedText(256) })
|
|
21272
21278
|
});
|
|
21279
|
+
var threadResumeResponseSchema = external_exports.object({
|
|
21280
|
+
model: boundedText(256).nullish(),
|
|
21281
|
+
reasoningEffort: boundedText(256).nullish(),
|
|
21282
|
+
thread: external_exports.object({ id: boundedText(256) }).nullish()
|
|
21283
|
+
});
|
|
21284
|
+
var reasoningEffortOptionSchema = external_exports.object({
|
|
21285
|
+
description: boundedText(4096).nullish(),
|
|
21286
|
+
reasoningEffort: boundedText(256)
|
|
21287
|
+
});
|
|
21288
|
+
var modelSchema = external_exports.object({
|
|
21289
|
+
additionalSpeedTiers: external_exports.array(boundedText(256)).max(100).nullish(),
|
|
21290
|
+
defaultReasoningEffort: boundedText(256).nullish(),
|
|
21291
|
+
description: boundedText(4096).nullish(),
|
|
21292
|
+
displayName: boundedText(256).nullish(),
|
|
21293
|
+
id: boundedText(256),
|
|
21294
|
+
isDefault: external_exports.boolean().nullish(),
|
|
21295
|
+
supportedReasoningEfforts: external_exports.array(reasoningEffortOptionSchema).max(100).nullish()
|
|
21296
|
+
});
|
|
21297
|
+
var modelListResponseSchema = external_exports.object({
|
|
21298
|
+
data: external_exports.array(modelSchema).max(1e3),
|
|
21299
|
+
nextCursor: boundedText(1024).nullish()
|
|
21300
|
+
});
|
|
21301
|
+
var threadSchema = external_exports.object({
|
|
21302
|
+
createdAt: external_exports.number().nullish(),
|
|
21303
|
+
cwd: boundedText(4096).nullish(),
|
|
21304
|
+
id: boundedText(256),
|
|
21305
|
+
name: boundedText(4096).nullish(),
|
|
21306
|
+
preview: boundedText(4096).nullish(),
|
|
21307
|
+
updatedAt: external_exports.number().nullish()
|
|
21308
|
+
});
|
|
21309
|
+
var threadListResponseSchema = external_exports.object({
|
|
21310
|
+
data: external_exports.array(threadSchema).max(1e4),
|
|
21311
|
+
nextCursor: boundedText(1024).nullish()
|
|
21312
|
+
});
|
|
21313
|
+
var turnSteerResponseSchema = external_exports.object({ turnId: boundedText(256) });
|
|
21273
21314
|
|
|
21274
21315
|
// src/acp/codex/app-server-client.ts
|
|
21275
21316
|
var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
|
|
@@ -21609,6 +21650,77 @@ function agentMessageMeta(phase) {
|
|
|
21609
21650
|
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
21610
21651
|
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
21611
21652
|
var CODEX_AGENT_VERSION = "0.154.0";
|
|
21653
|
+
var STEERING_METHOD = "_session/steering";
|
|
21654
|
+
var MODEL_SETTING_ID = "model";
|
|
21655
|
+
var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
|
|
21656
|
+
var MODE_SETTING_ID = "mode";
|
|
21657
|
+
var FAST_MODE_SETTING_ID = "fast-mode";
|
|
21658
|
+
var MODEL_CATALOG_LIMIT = 1e3;
|
|
21659
|
+
var FAST_TIER = "fast";
|
|
21660
|
+
var SERVICE_TIER_FAST = "priority";
|
|
21661
|
+
var WORKSPACE_WRITE_POLICY = Object.freeze({
|
|
21662
|
+
excludeSlashTmp: false,
|
|
21663
|
+
excludeTmpdirEnvVar: false,
|
|
21664
|
+
networkAccess: false,
|
|
21665
|
+
type: "workspaceWrite",
|
|
21666
|
+
writableRoots: []
|
|
21667
|
+
});
|
|
21668
|
+
var READ_ONLY_MODE = Object.freeze({
|
|
21669
|
+
approvalPolicy: "on-request",
|
|
21670
|
+
approvalsReviewer: "user",
|
|
21671
|
+
description: "Always ask to edit external files and use the internet",
|
|
21672
|
+
id: "read-only",
|
|
21673
|
+
name: "Ask for approval",
|
|
21674
|
+
sandboxPolicy: WORKSPACE_WRITE_POLICY
|
|
21675
|
+
});
|
|
21676
|
+
var AGENT_MODE = Object.freeze({
|
|
21677
|
+
approvalPolicy: "on-request",
|
|
21678
|
+
approvalsReviewer: "auto_review",
|
|
21679
|
+
description: "Only ask for actions detected as potentially unsafe",
|
|
21680
|
+
id: "agent",
|
|
21681
|
+
name: "Approve for me",
|
|
21682
|
+
sandboxPolicy: WORKSPACE_WRITE_POLICY
|
|
21683
|
+
});
|
|
21684
|
+
var FULL_ACCESS_MODE = Object.freeze({
|
|
21685
|
+
approvalPolicy: "never",
|
|
21686
|
+
approvalsReviewer: "user",
|
|
21687
|
+
description: "Unrestricted access to the internet and any file on your computer",
|
|
21688
|
+
id: "agent-full-access",
|
|
21689
|
+
name: "Full access",
|
|
21690
|
+
sandboxPolicy: { type: "dangerFullAccess" }
|
|
21691
|
+
});
|
|
21692
|
+
var AGENT_MODES = Object.freeze([READ_ONLY_MODE, AGENT_MODE, FULL_ACCESS_MODE]);
|
|
21693
|
+
var DEFAULT_MODE = AGENT_MODE;
|
|
21694
|
+
function initialMode(environment) {
|
|
21695
|
+
const requested = environment["INITIAL_AGENT_MODE"];
|
|
21696
|
+
if (requested === void 0) {
|
|
21697
|
+
return DEFAULT_MODE.id;
|
|
21698
|
+
}
|
|
21699
|
+
return AGENT_MODES.some((mode) => mode.id === requested) ? requested : DEFAULT_MODE.id;
|
|
21700
|
+
}
|
|
21701
|
+
function capitalize(value) {
|
|
21702
|
+
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
21703
|
+
}
|
|
21704
|
+
function threadTitle(thread) {
|
|
21705
|
+
const named = thread.name?.trim() ?? "";
|
|
21706
|
+
if (named.length > 0) {
|
|
21707
|
+
return named;
|
|
21708
|
+
}
|
|
21709
|
+
return thread.preview?.trim() ?? "";
|
|
21710
|
+
}
|
|
21711
|
+
function isoTimestamp(seconds) {
|
|
21712
|
+
if (seconds == null || !Number.isFinite(seconds)) {
|
|
21713
|
+
return null;
|
|
21714
|
+
}
|
|
21715
|
+
return new Date(seconds * 1e3).toISOString();
|
|
21716
|
+
}
|
|
21717
|
+
function steeringParams(params) {
|
|
21718
|
+
const prompt = typeof params === "object" && params !== null ? Reflect.get(params, "prompt") : void 0;
|
|
21719
|
+
if (!Array.isArray(prompt)) {
|
|
21720
|
+
throw new AcpExecutionError("The steering prompt is invalid", {}, "steering_failed");
|
|
21721
|
+
}
|
|
21722
|
+
return { prompt };
|
|
21723
|
+
}
|
|
21612
21724
|
var APPROVAL_OPTIONS = Object.freeze([
|
|
21613
21725
|
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
21614
21726
|
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
@@ -21646,6 +21758,84 @@ function promptInput(prompt) {
|
|
|
21646
21758
|
}
|
|
21647
21759
|
return input2;
|
|
21648
21760
|
}
|
|
21761
|
+
function modelValues(models) {
|
|
21762
|
+
return models.map((model) => ({
|
|
21763
|
+
description: model.description ?? "",
|
|
21764
|
+
name: model.displayName ?? model.id,
|
|
21765
|
+
value: model.id
|
|
21766
|
+
}));
|
|
21767
|
+
}
|
|
21768
|
+
function effortValues(model) {
|
|
21769
|
+
return (model?.supportedReasoningEfforts ?? []).map((option) => ({
|
|
21770
|
+
description: option.description ?? "",
|
|
21771
|
+
name: capitalize(option.reasoningEffort),
|
|
21772
|
+
value: option.reasoningEffort
|
|
21773
|
+
}));
|
|
21774
|
+
}
|
|
21775
|
+
function modelSetting(models, currentValue) {
|
|
21776
|
+
const values = modelValues(models);
|
|
21777
|
+
const current = currentValue.length > 0 ? currentValue : models.find((model) => model.isDefault === true)?.id ?? values[0]?.value ?? "";
|
|
21778
|
+
if (current.length === 0) {
|
|
21779
|
+
return null;
|
|
21780
|
+
}
|
|
21781
|
+
const options = values.some((value) => value.value === current) ? values : [{ description: "", name: current, value: current }, ...values];
|
|
21782
|
+
return {
|
|
21783
|
+
category: "model",
|
|
21784
|
+
currentValue: current,
|
|
21785
|
+
description: "Model Codex uses for the session",
|
|
21786
|
+
id: MODEL_SETTING_ID,
|
|
21787
|
+
name: "Model",
|
|
21788
|
+
options,
|
|
21789
|
+
type: "select"
|
|
21790
|
+
};
|
|
21791
|
+
}
|
|
21792
|
+
function modeSetting(currentValue) {
|
|
21793
|
+
return {
|
|
21794
|
+
category: "mode",
|
|
21795
|
+
currentValue,
|
|
21796
|
+
description: "Approval and sandboxing preset for the session",
|
|
21797
|
+
id: MODE_SETTING_ID,
|
|
21798
|
+
name: "Mode",
|
|
21799
|
+
options: AGENT_MODES.map((mode) => ({
|
|
21800
|
+
description: mode.description,
|
|
21801
|
+
name: mode.name,
|
|
21802
|
+
value: mode.id
|
|
21803
|
+
})),
|
|
21804
|
+
type: "select"
|
|
21805
|
+
};
|
|
21806
|
+
}
|
|
21807
|
+
function fastModeSetting(model, enabled) {
|
|
21808
|
+
if (model?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
21809
|
+
return null;
|
|
21810
|
+
}
|
|
21811
|
+
return {
|
|
21812
|
+
category: "model_config",
|
|
21813
|
+
currentValue: enabled,
|
|
21814
|
+
description: "1.5x speed, increased usage",
|
|
21815
|
+
id: FAST_MODE_SETTING_ID,
|
|
21816
|
+
name: "Fast mode",
|
|
21817
|
+
type: "boolean"
|
|
21818
|
+
};
|
|
21819
|
+
}
|
|
21820
|
+
function effortSetting(model, currentValue) {
|
|
21821
|
+
const values = effortValues(model);
|
|
21822
|
+
if (values.length === 0) {
|
|
21823
|
+
return null;
|
|
21824
|
+
}
|
|
21825
|
+
const current = values.some((value) => value.value === currentValue) ? currentValue : values[0]?.value ?? "";
|
|
21826
|
+
if (current.length === 0) {
|
|
21827
|
+
return null;
|
|
21828
|
+
}
|
|
21829
|
+
return {
|
|
21830
|
+
category: "thought_level",
|
|
21831
|
+
currentValue: current,
|
|
21832
|
+
description: "How much reasoning effort the model should use",
|
|
21833
|
+
id: REASONING_EFFORT_SETTING_ID,
|
|
21834
|
+
name: "Reasoning effort",
|
|
21835
|
+
options: values,
|
|
21836
|
+
type: "select"
|
|
21837
|
+
};
|
|
21838
|
+
}
|
|
21649
21839
|
function userInputSchema(questions) {
|
|
21650
21840
|
const properties = {};
|
|
21651
21841
|
const required2 = [];
|
|
@@ -21670,10 +21860,21 @@ var CodexAcpAgent = class {
|
|
|
21670
21860
|
#app;
|
|
21671
21861
|
#appServer;
|
|
21672
21862
|
#connection = null;
|
|
21863
|
+
#models = [];
|
|
21673
21864
|
#nativeSessionId = "";
|
|
21865
|
+
// Whether the current turn must carry a policy at all. Until the user picks a mode, Codex's own
|
|
21866
|
+
// configuration decides, so `turn/start` omits the fields and inherits what the host set up.
|
|
21867
|
+
#policySelected = false;
|
|
21868
|
+
#selection;
|
|
21674
21869
|
#turn = null;
|
|
21675
21870
|
#updateTail = Promise.resolve();
|
|
21676
21871
|
constructor(options) {
|
|
21872
|
+
this.#selection = {
|
|
21873
|
+
effort: "",
|
|
21874
|
+
fastMode: false,
|
|
21875
|
+
mode: initialMode(options.environment),
|
|
21876
|
+
model: ""
|
|
21877
|
+
};
|
|
21677
21878
|
this.#appServer = new CodexAppServerClient({
|
|
21678
21879
|
command: options.command,
|
|
21679
21880
|
cwd: options.cwd,
|
|
@@ -21693,10 +21894,12 @@ var CodexAcpAgent = class {
|
|
|
21693
21894
|
agentCapabilities: {
|
|
21694
21895
|
loadSession: false,
|
|
21695
21896
|
promptCapabilities: { embeddedContext: true, image: true },
|
|
21696
|
-
sessionCapabilities: { close: {} }
|
|
21897
|
+
sessionCapabilities: { close: {}, delete: {}, list: {}, resume: {} }
|
|
21697
21898
|
},
|
|
21698
21899
|
agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
|
|
21699
21900
|
authMethods: [],
|
|
21901
|
+
// Mobius reads this to decide whether mid-turn steering can be attempted at all.
|
|
21902
|
+
_meta: { steering: { supported: true } },
|
|
21700
21903
|
protocolVersion: PROTOCOL_VERSION
|
|
21701
21904
|
})).onRequest(methods.agent.session.new, async (context) => {
|
|
21702
21905
|
const created = threadStartResponseSchema.parse(
|
|
@@ -21707,9 +21910,92 @@ var CodexAcpAgent = class {
|
|
|
21707
21910
|
)
|
|
21708
21911
|
);
|
|
21709
21912
|
this.#nativeSessionId = created.thread.id;
|
|
21710
|
-
|
|
21913
|
+
this.#selection = {
|
|
21914
|
+
...this.#selection,
|
|
21915
|
+
effort: created.reasoningEffort ?? "",
|
|
21916
|
+
model: created.model ?? ""
|
|
21917
|
+
};
|
|
21918
|
+
return { configOptions: this.#configOptions(), sessionId: created.thread.id };
|
|
21919
|
+
}).onRequest(methods.agent.session.resume, async (context) => {
|
|
21920
|
+
const resumed = threadResumeResponseSchema.parse(
|
|
21921
|
+
await this.#appServer.request(
|
|
21922
|
+
"thread/resume",
|
|
21923
|
+
{ cwd: context.params.cwd, threadId: context.params.sessionId },
|
|
21924
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21925
|
+
)
|
|
21926
|
+
);
|
|
21927
|
+
if (resumed.thread == null) {
|
|
21928
|
+
throw new AcpExecutionError(
|
|
21929
|
+
"Codex no longer has the native session this conversation belongs to",
|
|
21930
|
+
{},
|
|
21931
|
+
"session_restore_unsupported"
|
|
21932
|
+
);
|
|
21933
|
+
}
|
|
21934
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
21935
|
+
this.#selection = {
|
|
21936
|
+
...this.#selection,
|
|
21937
|
+
effort: resumed.reasoningEffort ?? this.#selection.effort,
|
|
21938
|
+
model: resumed.model ?? this.#selection.model
|
|
21939
|
+
};
|
|
21940
|
+
return { configOptions: this.#configOptions() };
|
|
21941
|
+
}).onRequest(methods.agent.session.list, async (context) => {
|
|
21942
|
+
const listed = threadListResponseSchema.parse(
|
|
21943
|
+
await this.#appServer.request(
|
|
21944
|
+
"thread/list",
|
|
21945
|
+
context.params.cursor === void 0 || context.params.cursor === null ? {} : { cursor: context.params.cursor },
|
|
21946
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21947
|
+
)
|
|
21948
|
+
);
|
|
21949
|
+
return {
|
|
21950
|
+
nextCursor: listed.nextCursor ?? null,
|
|
21951
|
+
sessions: listed.data.map((thread) => ({
|
|
21952
|
+
// The thread id is a UUID, which satisfies the native session id contract.
|
|
21953
|
+
additionalDirectories: [],
|
|
21954
|
+
cwd: thread.cwd ?? "",
|
|
21955
|
+
sessionId: thread.id,
|
|
21956
|
+
title: threadTitle(thread),
|
|
21957
|
+
updatedAt: isoTimestamp(thread.updatedAt)
|
|
21958
|
+
}))
|
|
21959
|
+
};
|
|
21960
|
+
}).onRequest(methods.agent.session.delete, async (context) => {
|
|
21961
|
+
await this.#appServer.request(
|
|
21962
|
+
"thread/archive",
|
|
21963
|
+
{ threadId: context.params.sessionId },
|
|
21964
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21965
|
+
);
|
|
21966
|
+
return {};
|
|
21967
|
+
}).onRequest(methods.agent.session.setConfigOption, async (context) => {
|
|
21968
|
+
this.#applySelection(context.params.configId, context.params.value);
|
|
21969
|
+
return { configOptions: this.#configOptions() };
|
|
21970
|
+
}).onRequest(methods.agent.session.setMode, async (context) => {
|
|
21971
|
+
this.#applySelection(MODE_SETTING_ID, context.params.modeId);
|
|
21972
|
+
return {};
|
|
21711
21973
|
}).onRequest(methods.agent.session.prompt, async (context) => {
|
|
21712
21974
|
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
21975
|
+
}).onRequest(STEERING_METHOD, steeringParams, async (context) => {
|
|
21976
|
+
const turn = this.#turn;
|
|
21977
|
+
if (turn === null || turn.turn.id.length === 0) {
|
|
21978
|
+
return { outcome: "promptRequired" };
|
|
21979
|
+
}
|
|
21980
|
+
try {
|
|
21981
|
+
const steered = turnSteerResponseSchema.parse(
|
|
21982
|
+
await this.#appServer.request(
|
|
21983
|
+
"turn/steer",
|
|
21984
|
+
{
|
|
21985
|
+
expectedTurnId: turn.turn.id,
|
|
21986
|
+
input: promptInput(context.params.prompt),
|
|
21987
|
+
threadId: this.#nativeSessionId
|
|
21988
|
+
},
|
|
21989
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21990
|
+
)
|
|
21991
|
+
);
|
|
21992
|
+
return { outcome: steered.turnId === turn.turn.id ? "injected" : "startedNewTurn" };
|
|
21993
|
+
} catch (error62) {
|
|
21994
|
+
if (error62 instanceof CodexAppServerError) {
|
|
21995
|
+
return { outcome: "promptRequired" };
|
|
21996
|
+
}
|
|
21997
|
+
throw error62;
|
|
21998
|
+
}
|
|
21713
21999
|
}).onRequest(methods.agent.session.close, async () => {
|
|
21714
22000
|
await this.#interruptTurn();
|
|
21715
22001
|
}).onNotification(methods.agent.session.cancel, async () => {
|
|
@@ -21718,9 +22004,10 @@ var CodexAcpAgent = class {
|
|
|
21718
22004
|
}
|
|
21719
22005
|
/** The ACP agent app Mobius connects its own ACP client to, in-process. */
|
|
21720
22006
|
app = () => this.#app;
|
|
21721
|
-
/** Starts the app-server
|
|
22007
|
+
/** Starts the app-server, performs its handshake, and reads the model catalog Codex offers. */
|
|
21722
22008
|
initialize = async (signal) => {
|
|
21723
22009
|
await this.#appServer.initialize(signal);
|
|
22010
|
+
await this.#loadModels(signal);
|
|
21724
22011
|
};
|
|
21725
22012
|
/**
|
|
21726
22013
|
* Releases the app-server and every process it started. Mirrors the adapter path's teardown so a
|
|
@@ -21732,6 +22019,129 @@ var CodexAcpAgent = class {
|
|
|
21732
22019
|
this.#appServer.detach();
|
|
21733
22020
|
await stopProcessTree(child, captured);
|
|
21734
22021
|
};
|
|
22022
|
+
/**
|
|
22023
|
+
* Reads the model catalog once per app-server. A failure leaves the catalog empty, which costs
|
|
22024
|
+
* the Run settings panel its model selector; it must not cost the conversation itself, so the
|
|
22025
|
+
* turn lifecycle continues without settings rather than failing initialization.
|
|
22026
|
+
*/
|
|
22027
|
+
#loadModels = async (signal) => {
|
|
22028
|
+
const models = [];
|
|
22029
|
+
let cursor = null;
|
|
22030
|
+
try {
|
|
22031
|
+
do {
|
|
22032
|
+
const decoded = modelListResponseSchema.parse(
|
|
22033
|
+
await this.#appServer.request(
|
|
22034
|
+
"model/list",
|
|
22035
|
+
{ cursor, limit: null },
|
|
22036
|
+
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
22037
|
+
)
|
|
22038
|
+
);
|
|
22039
|
+
models.push(...decoded.data);
|
|
22040
|
+
cursor = decoded.nextCursor ?? null;
|
|
22041
|
+
} while (cursor !== null && models.length < MODEL_CATALOG_LIMIT);
|
|
22042
|
+
} catch (error62) {
|
|
22043
|
+
signal.throwIfAborted();
|
|
22044
|
+
process.stderr.write(`[codex-acp] model catalog unavailable: ${String(error62)}
|
|
22045
|
+
`);
|
|
22046
|
+
}
|
|
22047
|
+
this.#models = Object.freeze(models.slice(0, MODEL_CATALOG_LIMIT));
|
|
22048
|
+
};
|
|
22049
|
+
#model = (id) => this.#models.find((model) => model.id === id);
|
|
22050
|
+
/** The ACP settings Mobius discovers and renders in Run settings. */
|
|
22051
|
+
#configOptions = () => {
|
|
22052
|
+
const options = [];
|
|
22053
|
+
const model = modelSetting(this.#models, this.#selection.model);
|
|
22054
|
+
if (model !== null) {
|
|
22055
|
+
options.push(model);
|
|
22056
|
+
}
|
|
22057
|
+
const effort = effortSetting(this.#model(this.#selection.model), this.#selection.effort);
|
|
22058
|
+
if (effort !== null) {
|
|
22059
|
+
options.push(effort);
|
|
22060
|
+
}
|
|
22061
|
+
const fastMode = fastModeSetting(this.#model(this.#selection.model), this.#selection.fastMode);
|
|
22062
|
+
if (fastMode !== null) {
|
|
22063
|
+
options.push(fastMode);
|
|
22064
|
+
}
|
|
22065
|
+
options.push(modeSetting(this.#selection.mode));
|
|
22066
|
+
return options;
|
|
22067
|
+
};
|
|
22068
|
+
/**
|
|
22069
|
+
* Applies one `session/set_config_option`. Switching models re-resolves the effort the way Codex
|
|
22070
|
+
* does — the current effort when the new model supports it, otherwise the model's own default —
|
|
22071
|
+
* so the reply never advertises an effort the selected model cannot run.
|
|
22072
|
+
*/
|
|
22073
|
+
#applySelection = (configId, value) => {
|
|
22074
|
+
if (configId === FAST_MODE_SETTING_ID) {
|
|
22075
|
+
if (typeof value !== "boolean") {
|
|
22076
|
+
throw new AcpExecutionError(
|
|
22077
|
+
"The requested Codex setting is invalid",
|
|
22078
|
+
{},
|
|
22079
|
+
"invalid_session_configuration"
|
|
22080
|
+
);
|
|
22081
|
+
}
|
|
22082
|
+
if (value && this.#model(this.#selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) !== true) {
|
|
22083
|
+
throw new AcpExecutionError(
|
|
22084
|
+
"The selected Codex model has no fast mode",
|
|
22085
|
+
{},
|
|
22086
|
+
"invalid_session_configuration"
|
|
22087
|
+
);
|
|
22088
|
+
}
|
|
22089
|
+
this.#selection = { ...this.#selection, fastMode: value };
|
|
22090
|
+
return;
|
|
22091
|
+
}
|
|
22092
|
+
if (typeof value !== "string") {
|
|
22093
|
+
throw new AcpExecutionError("The requested Codex setting is invalid", {}, "invalid_session_configuration");
|
|
22094
|
+
}
|
|
22095
|
+
if (configId === MODE_SETTING_ID) {
|
|
22096
|
+
if (!AGENT_MODES.some((mode) => mode.id === value)) {
|
|
22097
|
+
throw new AcpExecutionError(
|
|
22098
|
+
"The requested Codex mode is unavailable",
|
|
22099
|
+
{},
|
|
22100
|
+
"invalid_session_configuration"
|
|
22101
|
+
);
|
|
22102
|
+
}
|
|
22103
|
+
this.#selection = { ...this.#selection, mode: value };
|
|
22104
|
+
this.#policySelected = true;
|
|
22105
|
+
return;
|
|
22106
|
+
}
|
|
22107
|
+
if (configId === MODEL_SETTING_ID) {
|
|
22108
|
+
if (value === this.#selection.model) {
|
|
22109
|
+
return;
|
|
22110
|
+
}
|
|
22111
|
+
const model = this.#model(value);
|
|
22112
|
+
if (model === void 0) {
|
|
22113
|
+
throw new AcpExecutionError(
|
|
22114
|
+
"The requested Codex model is unavailable",
|
|
22115
|
+
{},
|
|
22116
|
+
"invalid_session_configuration"
|
|
22117
|
+
);
|
|
22118
|
+
}
|
|
22119
|
+
const supported = (model.supportedReasoningEfforts ?? []).map((option) => option.reasoningEffort);
|
|
22120
|
+
const effort = supported.includes(this.#selection.effort) ? this.#selection.effort : model.defaultReasoningEffort ?? supported[0] ?? "";
|
|
22121
|
+
this.#selection = {
|
|
22122
|
+
...this.#selection,
|
|
22123
|
+
effort,
|
|
22124
|
+
fastMode: this.#selection.fastMode && model.additionalSpeedTiers?.includes(FAST_TIER) === true,
|
|
22125
|
+
model: value
|
|
22126
|
+
};
|
|
22127
|
+
return;
|
|
22128
|
+
}
|
|
22129
|
+
if (configId === REASONING_EFFORT_SETTING_ID) {
|
|
22130
|
+
const supported = (this.#model(this.#selection.model)?.supportedReasoningEfforts ?? []).map(
|
|
22131
|
+
(option) => option.reasoningEffort
|
|
22132
|
+
);
|
|
22133
|
+
if (!supported.includes(value)) {
|
|
22134
|
+
throw new AcpExecutionError(
|
|
22135
|
+
"The requested Codex reasoning effort is unavailable",
|
|
22136
|
+
{},
|
|
22137
|
+
"invalid_session_configuration"
|
|
22138
|
+
);
|
|
22139
|
+
}
|
|
22140
|
+
this.#selection = { ...this.#selection, effort: value };
|
|
22141
|
+
return;
|
|
22142
|
+
}
|
|
22143
|
+
throw new AcpExecutionError("The requested Codex setting is unavailable", {}, "invalid_session_configuration");
|
|
22144
|
+
};
|
|
21735
22145
|
#emit = async (update) => {
|
|
21736
22146
|
const connection = this.#connection;
|
|
21737
22147
|
if (connection === null || this.#nativeSessionId.length === 0) {
|
|
@@ -21937,10 +22347,27 @@ var CodexAcpAgent = class {
|
|
|
21937
22347
|
const turn = { completion, turn: { id: "" } };
|
|
21938
22348
|
this.#turn = turn;
|
|
21939
22349
|
try {
|
|
22350
|
+
const selection = this.#selection;
|
|
22351
|
+
const mode = AGENT_MODES.find((candidate) => candidate.id === selection.mode) ?? DEFAULT_MODE;
|
|
22352
|
+
const supportsFast = this.#model(selection.model)?.additionalSpeedTiers?.includes(FAST_TIER) === true;
|
|
21940
22353
|
const started = turnSchema.parse(
|
|
21941
22354
|
(await this.#appServer.request(
|
|
21942
22355
|
"turn/start",
|
|
21943
|
-
{
|
|
22356
|
+
{
|
|
22357
|
+
// Until a mode is chosen, `config.toml` decides the sandbox and approval
|
|
22358
|
+
// policy, and those fields stay off the turn so the host's own setup is
|
|
22359
|
+
// inherited rather than overridden.
|
|
22360
|
+
...this.#policySelected ? {
|
|
22361
|
+
approvalPolicy: mode.approvalPolicy,
|
|
22362
|
+
approvalsReviewer: mode.approvalsReviewer,
|
|
22363
|
+
sandboxPolicy: mode.sandboxPolicy
|
|
22364
|
+
} : {},
|
|
22365
|
+
...selection.effort.length === 0 ? {} : { effort: selection.effort },
|
|
22366
|
+
input: input2,
|
|
22367
|
+
...selection.model.length === 0 ? {} : { model: selection.model },
|
|
22368
|
+
...selection.fastMode && supportsFast ? { serviceTier: SERVICE_TIER_FAST } : {},
|
|
22369
|
+
threadId: this.#nativeSessionId
|
|
22370
|
+
},
|
|
21944
22371
|
signal
|
|
21945
22372
|
)).turn
|
|
21946
22373
|
);
|
|
@@ -24333,6 +24760,7 @@ var RUNTIME_DELIVERY_COMMITTED_KIND = "runtime.delivery.committed";
|
|
|
24333
24760
|
var SESSION_STARTED_KIND = "session.started";
|
|
24334
24761
|
var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
|
|
24335
24762
|
var AGENT_ACTIVITY_KIND = "agent.activity";
|
|
24763
|
+
var AGENT_ACTIVITY_NARRATION_KIND = "agent.activity.narration";
|
|
24336
24764
|
var AGENT_ACTIVITY_DETAIL_LIMIT = 5e5;
|
|
24337
24765
|
var AGENT_ACTIVITY_RECORDED_FIELD_LIMIT = 4e6;
|
|
24338
24766
|
var AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT = 6e6;
|
|
@@ -24354,6 +24782,7 @@ var MAX_PROMPT_ATTACHMENT_LENGTH = 6e6;
|
|
|
24354
24782
|
var MAX_EVENT_TEXT_LENGTH = 1e5;
|
|
24355
24783
|
var MAX_RUNTIME_DELIVERY_PAYLOAD_LENGTH = 8 * 1024 * 1024;
|
|
24356
24784
|
var ACTIVITY_TYPES = /* @__PURE__ */ new Set(["plan", "progress", "reasoning", "tool"]);
|
|
24785
|
+
var NARRATION_ACTIVITY_TYPES = /* @__PURE__ */ new Set(["progress", "reasoning"]);
|
|
24357
24786
|
var ACTIVITY_STATUSES = /* @__PURE__ */ new Set(["pending", "running", "completed", "failed"]);
|
|
24358
24787
|
var TOOL_KINDS = /* @__PURE__ */ new Set([
|
|
24359
24788
|
"",
|
|
@@ -24777,6 +25206,20 @@ function encodeRuntimeDeliveryReceived(message) {
|
|
|
24777
25206
|
function encodeRuntimeDeliveryCommitted(message) {
|
|
24778
25207
|
return JSON.stringify(decodeRuntimeDeliveryCommitted(JSON.stringify(message)));
|
|
24779
25208
|
}
|
|
25209
|
+
function decodeAgentActivityNarrationEvent(encoded) {
|
|
25210
|
+
const value = parseJson2(encoded);
|
|
25211
|
+
assertExactKeys(value, ["activityId", "activityType", "commandId", "kind", "sequence", "sessionId", "text"]);
|
|
25212
|
+
assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
|
|
25213
|
+
return {
|
|
25214
|
+
activityId: readIdentifier(value, "activityId"),
|
|
25215
|
+
activityType: readAllowedString(value, "activityType", NARRATION_ACTIVITY_TYPES),
|
|
25216
|
+
commandId: readIdentifier(value, "commandId"),
|
|
25217
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
25218
|
+
sequence: readSequence(value, "sequence"),
|
|
25219
|
+
sessionId: readIdentifier(value, "sessionId"),
|
|
25220
|
+
text: readText(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
25221
|
+
};
|
|
25222
|
+
}
|
|
24780
25223
|
|
|
24781
25224
|
// ../protocol/src/session-history.ts
|
|
24782
25225
|
var SESSION_HISTORY_CHARACTER_LIMIT = 256e3;
|
|
@@ -24912,6 +25355,26 @@ var nativeSessionTurnForkCommandSchema = external_exports.strictObject({
|
|
|
24912
25355
|
messageOccurrence: external_exports.number().int().positive(),
|
|
24913
25356
|
title: external_exports.string().max(500)
|
|
24914
25357
|
}).readonly();
|
|
25358
|
+
var nativeSessionRequestSchema = external_exports.discriminatedUnion("action", [
|
|
25359
|
+
external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
|
|
25360
|
+
external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
|
|
25361
|
+
external_exports.strictObject({
|
|
25362
|
+
...identity,
|
|
25363
|
+
action: external_exports.literal("list"),
|
|
25364
|
+
cursor: identifier.nullable()
|
|
25365
|
+
}).readonly(),
|
|
25366
|
+
external_exports.strictObject({
|
|
25367
|
+
...identity,
|
|
25368
|
+
action: external_exports.enum(["import", "fork"]),
|
|
25369
|
+
entryId: identifier,
|
|
25370
|
+
targetSessionId: identifier
|
|
25371
|
+
}).readonly(),
|
|
25372
|
+
external_exports.strictObject({
|
|
25373
|
+
...identity,
|
|
25374
|
+
action: external_exports.literal("delete"),
|
|
25375
|
+
entryId: identifier
|
|
25376
|
+
}).readonly()
|
|
25377
|
+
]);
|
|
24915
25378
|
var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
24916
25379
|
external_exports.strictObject({ ...identity, action: external_exports.literal("preview"), entryId: identifier }).readonly(),
|
|
24917
25380
|
external_exports.strictObject({ ...identity, action: external_exports.literal("find"), nativeSessionId: identifier }).readonly(),
|
|
@@ -24926,6 +25389,12 @@ var nativeSessionCommandSchema = external_exports.discriminatedUnion("action", [
|
|
|
24926
25389
|
entryId: identifier,
|
|
24927
25390
|
targetSessionId: identifier
|
|
24928
25391
|
}).readonly(),
|
|
25392
|
+
external_exports.strictObject({
|
|
25393
|
+
...identity,
|
|
25394
|
+
action: external_exports.enum(["import-only", "fork-only"]),
|
|
25395
|
+
entryId: identifier,
|
|
25396
|
+
targetSessionId: identifier
|
|
25397
|
+
}).readonly(),
|
|
24929
25398
|
external_exports.strictObject({
|
|
24930
25399
|
...identity,
|
|
24931
25400
|
action: external_exports.literal("delete"),
|
|
@@ -25099,6 +25568,8 @@ function decodeRecordedSessionEvent(encoded) {
|
|
|
25099
25568
|
switch (kind) {
|
|
25100
25569
|
case AGENT_ACTIVITY_KIND:
|
|
25101
25570
|
return decodeAgentActivityEvent(encoded);
|
|
25571
|
+
case AGENT_ACTIVITY_NARRATION_KIND:
|
|
25572
|
+
return decodeAgentActivityNarrationEvent(encoded);
|
|
25102
25573
|
case AGENT_CONTENT_KIND:
|
|
25103
25574
|
return decodeAgentContentEvent(encoded);
|
|
25104
25575
|
case AGENT_MESSAGE_DELTA_KIND:
|
|
@@ -26699,6 +27170,18 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
26699
27170
|
|
|
26700
27171
|
// src/acp/activity.ts
|
|
26701
27172
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
27173
|
+
var AcpActivityNarration = class {
|
|
27174
|
+
activityId;
|
|
27175
|
+
activityType;
|
|
27176
|
+
sequence;
|
|
27177
|
+
text;
|
|
27178
|
+
constructor(activityId, activityType, sequence, text3) {
|
|
27179
|
+
this.activityId = activityId;
|
|
27180
|
+
this.activityType = activityType;
|
|
27181
|
+
this.sequence = sequence;
|
|
27182
|
+
this.text = text3;
|
|
27183
|
+
}
|
|
27184
|
+
};
|
|
26702
27185
|
function isRecord7(value) {
|
|
26703
27186
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26704
27187
|
}
|
|
@@ -27031,12 +27514,15 @@ function isProgressMessage(content3) {
|
|
|
27031
27514
|
var AcpActivityTracker = class {
|
|
27032
27515
|
#activities = /* @__PURE__ */ new Map();
|
|
27033
27516
|
#identities = /* @__PURE__ */ new Map();
|
|
27517
|
+
#narrations = /* @__PURE__ */ new Map();
|
|
27034
27518
|
#onActivity;
|
|
27519
|
+
#onNarration;
|
|
27035
27520
|
#prepareContent;
|
|
27036
27521
|
#activeNarrativeKey = "";
|
|
27037
27522
|
#nextSequence = 0;
|
|
27038
|
-
constructor(onActivity, prepareContent = (content3) => Promise.resolve(content3)) {
|
|
27523
|
+
constructor(onActivity, onNarration, prepareContent = (content3) => Promise.resolve(content3)) {
|
|
27039
27524
|
this.#onActivity = onActivity;
|
|
27525
|
+
this.#onNarration = onNarration;
|
|
27040
27526
|
this.#prepareContent = prepareContent;
|
|
27041
27527
|
}
|
|
27042
27528
|
recordNarrative = async (activityType, messageId, text3) => {
|
|
@@ -27044,26 +27530,34 @@ var AcpActivityTracker = class {
|
|
|
27044
27530
|
if (this.#activeNarrativeKey !== key) {
|
|
27045
27531
|
await this.finishNarrative();
|
|
27046
27532
|
}
|
|
27047
|
-
const previous2 = this.#activities.get(key);
|
|
27048
27533
|
const identity2 = this.#identity(key);
|
|
27049
|
-
const
|
|
27050
|
-
|
|
27051
|
-
identity2.id,
|
|
27534
|
+
const previous2 = this.#narrations.get(key);
|
|
27535
|
+
this.#narrations.set(key, {
|
|
27536
|
+
activityId: identity2.id,
|
|
27052
27537
|
activityType,
|
|
27053
|
-
""
|
|
27054
|
-
|
|
27055
|
-
|
|
27056
|
-
|
|
27057
|
-
identity2
|
|
27058
|
-
|
|
27059
|
-
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27060
|
-
activityType === "reasoning" ? "think" : "",
|
|
27061
|
-
[],
|
|
27062
|
-
captureActivityDetail([], "", fullOutput)
|
|
27063
|
-
);
|
|
27064
|
-
await this.#record(key, activity2);
|
|
27538
|
+
output: `${previous2?.output ?? ""}${text3}`,
|
|
27539
|
+
sequence: identity2.sequence
|
|
27540
|
+
});
|
|
27541
|
+
if (previous2 === void 0) {
|
|
27542
|
+
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
27543
|
+
}
|
|
27065
27544
|
this.#activeNarrativeKey = key;
|
|
27545
|
+
if (text3.length > 0) {
|
|
27546
|
+
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text3));
|
|
27547
|
+
}
|
|
27066
27548
|
};
|
|
27549
|
+
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
27550
|
+
identity2.id,
|
|
27551
|
+
activityType,
|
|
27552
|
+
"",
|
|
27553
|
+
[],
|
|
27554
|
+
"",
|
|
27555
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27556
|
+
identity2.sequence,
|
|
27557
|
+
status,
|
|
27558
|
+
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27559
|
+
activityType === "reasoning" ? "think" : ""
|
|
27560
|
+
);
|
|
27067
27561
|
recordPlan = async (plan) => {
|
|
27068
27562
|
await this.finishNarrative();
|
|
27069
27563
|
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
@@ -27183,17 +27677,13 @@ var AcpActivityTracker = class {
|
|
|
27183
27677
|
return;
|
|
27184
27678
|
}
|
|
27185
27679
|
this.#activeNarrativeKey = "";
|
|
27186
|
-
|
|
27187
|
-
if (activity2 === void 0) {
|
|
27188
|
-
return;
|
|
27189
|
-
}
|
|
27190
|
-
const completed = activity2.complete();
|
|
27191
|
-
if (completed !== activity2) {
|
|
27192
|
-
await this.#record(key, completed);
|
|
27193
|
-
}
|
|
27680
|
+
await this.#completeNarrative(key);
|
|
27194
27681
|
};
|
|
27195
27682
|
finish = async () => {
|
|
27196
27683
|
await this.finishNarrative();
|
|
27684
|
+
for (const key of this.#narrations.keys()) {
|
|
27685
|
+
await this.#completeNarrative(key);
|
|
27686
|
+
}
|
|
27197
27687
|
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
27198
27688
|
for (const [key, activity2] of entries) {
|
|
27199
27689
|
const completed = activity2.complete();
|
|
@@ -27202,6 +27692,34 @@ var AcpActivityTracker = class {
|
|
|
27202
27692
|
}
|
|
27203
27693
|
}
|
|
27204
27694
|
};
|
|
27695
|
+
// Materialize a streamed narration as one completed snapshot activity. The
|
|
27696
|
+
// incremental events carried the text; this final event gives consumers the
|
|
27697
|
+
// whole narration with its terminal status, as a single bounded item.
|
|
27698
|
+
#completeNarrative = async (key) => {
|
|
27699
|
+
const narration = this.#narrations.get(key);
|
|
27700
|
+
if (narration === void 0) {
|
|
27701
|
+
return;
|
|
27702
|
+
}
|
|
27703
|
+
this.#narrations.delete(key);
|
|
27704
|
+
const previous2 = this.#activities.get(key);
|
|
27705
|
+
await this.#record(
|
|
27706
|
+
key,
|
|
27707
|
+
new AcpActivity(
|
|
27708
|
+
narration.activityId,
|
|
27709
|
+
narration.activityType,
|
|
27710
|
+
"",
|
|
27711
|
+
[],
|
|
27712
|
+
"",
|
|
27713
|
+
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
27714
|
+
narration.sequence,
|
|
27715
|
+
"completed",
|
|
27716
|
+
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
27717
|
+
narration.activityType === "reasoning" ? "think" : "",
|
|
27718
|
+
previous2?.content ?? [],
|
|
27719
|
+
captureActivityDetail([], "", narration.output)
|
|
27720
|
+
)
|
|
27721
|
+
);
|
|
27722
|
+
};
|
|
27205
27723
|
#identity = (key) => {
|
|
27206
27724
|
const existing = this.#identities.get(key);
|
|
27207
27725
|
if (existing !== void 0) {
|
|
@@ -34845,17 +35363,22 @@ var AcpHistoryReplay = class {
|
|
|
34845
35363
|
#activities = /* @__PURE__ */ new Map();
|
|
34846
35364
|
#messages = [];
|
|
34847
35365
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
34848
|
-
#activityTracker = new AcpActivityTracker(
|
|
34849
|
-
|
|
34850
|
-
|
|
34851
|
-
|
|
34852
|
-
|
|
34853
|
-
|
|
34854
|
-
|
|
34855
|
-
|
|
34856
|
-
|
|
34857
|
-
|
|
34858
|
-
|
|
35366
|
+
#activityTracker = new AcpActivityTracker(
|
|
35367
|
+
async (activity2) => {
|
|
35368
|
+
this.#activities.set(activity2.activityId, activity2);
|
|
35369
|
+
this.#turnActivityIds.add(activity2.activityId);
|
|
35370
|
+
const latest = this.#messages.at(-1);
|
|
35371
|
+
if (latest?.role === "assistant") {
|
|
35372
|
+
this.#messages[this.#messages.length - 1] = {
|
|
35373
|
+
...latest,
|
|
35374
|
+
activityIds: [...this.#turnActivityIds]
|
|
35375
|
+
};
|
|
35376
|
+
}
|
|
35377
|
+
},
|
|
35378
|
+
// History replay folds each narration into its snapshot activity, so no
|
|
35379
|
+
// separate incremental event is produced here.
|
|
35380
|
+
() => Promise.resolve()
|
|
35381
|
+
);
|
|
34859
35382
|
#lastMessageId = null;
|
|
34860
35383
|
#characters = 0;
|
|
34861
35384
|
#truncated = false;
|
|
@@ -35215,6 +35738,15 @@ var MAX_PRE_SESSION_UPDATES = 100;
|
|
|
35215
35738
|
var MAX_PRE_SESSION_UPDATE_BYTES = 1024 * 1024;
|
|
35216
35739
|
var SESSION_CONTROL_COMMAND_ID = "session-control";
|
|
35217
35740
|
var SESSION_CONTROL_TIMEOUT_MILLISECONDS = 3e4;
|
|
35741
|
+
function nativeHistoryNotRetained() {
|
|
35742
|
+
return {
|
|
35743
|
+
cause: {
|
|
35744
|
+
code: "native_history_not_retained",
|
|
35745
|
+
message: "Native message history is not retained in the cloud for this Session."
|
|
35746
|
+
},
|
|
35747
|
+
status: "unavailable"
|
|
35748
|
+
};
|
|
35749
|
+
}
|
|
35218
35750
|
var NullAcpSessionObserver = class {
|
|
35219
35751
|
onCommands = () => Promise.resolve();
|
|
35220
35752
|
onConfig = () => Promise.resolve();
|
|
@@ -35665,7 +36197,10 @@ var AcpTurnState = class {
|
|
|
35665
36197
|
var IdleAcpTurn = class extends AcpTurnState {
|
|
35666
36198
|
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
35667
36199
|
running = false;
|
|
35668
|
-
activities = new AcpActivityTracker(
|
|
36200
|
+
activities = new AcpActivityTracker(
|
|
36201
|
+
() => Promise.resolve(),
|
|
36202
|
+
() => Promise.resolve()
|
|
36203
|
+
);
|
|
35669
36204
|
onText = () => Promise.resolve();
|
|
35670
36205
|
};
|
|
35671
36206
|
var RunningAcpTurn = class extends AcpTurnState {
|
|
@@ -35673,10 +36208,10 @@ var RunningAcpTurn = class extends AcpTurnState {
|
|
|
35673
36208
|
running = true;
|
|
35674
36209
|
activities;
|
|
35675
36210
|
onText;
|
|
35676
|
-
constructor(commandId, onActivity, onText, prepareContent) {
|
|
36211
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
35677
36212
|
super();
|
|
35678
36213
|
this.commandId = commandId;
|
|
35679
|
-
this.activities = new AcpActivityTracker(onActivity, prepareContent);
|
|
36214
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
35680
36215
|
this.onText = onText;
|
|
35681
36216
|
}
|
|
35682
36217
|
};
|
|
@@ -36481,6 +37016,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
36481
37016
|
const running = new RunningAcpTurn(
|
|
36482
37017
|
options.commandId,
|
|
36483
37018
|
options.onActivity,
|
|
37019
|
+
options.onNarration,
|
|
36484
37020
|
options.onText,
|
|
36485
37021
|
this.prepareAgentContent
|
|
36486
37022
|
);
|
|
@@ -37880,7 +38416,7 @@ var AcpSessionManager = class {
|
|
|
37880
38416
|
this.#endSessionUse(options.sessionId);
|
|
37881
38417
|
}
|
|
37882
38418
|
};
|
|
37883
|
-
openNativeSession = async (options, origin) => {
|
|
38419
|
+
openNativeSession = async (options, origin, loadHistory) => {
|
|
37884
38420
|
const key = `${options.agent.id}:${origin.nativeSessionId}`;
|
|
37885
38421
|
if (this.#nativeOperations.has(key)) {
|
|
37886
38422
|
throw new AcpExecutionError("The native session is being managed", {}, "session_busy");
|
|
@@ -37910,7 +38446,7 @@ var AcpSessionManager = class {
|
|
|
37910
38446
|
}
|
|
37911
38447
|
this.#nativeOperations.add(key);
|
|
37912
38448
|
try {
|
|
37913
|
-
const history = await runtime.loadHistory(options.signal);
|
|
38449
|
+
const history = loadHistory ? await runtime.loadHistory(options.signal) : nativeHistoryNotRetained();
|
|
37914
38450
|
return {
|
|
37915
38451
|
prepared: runtime.prepared(),
|
|
37916
38452
|
sessionId: existing.sessionId,
|
|
@@ -37941,7 +38477,7 @@ var AcpSessionManager = class {
|
|
|
37941
38477
|
const openedKey = `${options.agent.id}:${runtime.nativeSessionId()}`;
|
|
37942
38478
|
this.#nativeOperations.add(openedKey);
|
|
37943
38479
|
try {
|
|
37944
|
-
const history = await runtime.loadHistory(options.signal);
|
|
38480
|
+
const history = loadHistory ? await runtime.loadHistory(options.signal) : nativeHistoryNotRetained();
|
|
37945
38481
|
return {
|
|
37946
38482
|
sessionId: options.sessionId,
|
|
37947
38483
|
prepared: runtime.prepared(),
|
|
@@ -39091,6 +39627,54 @@ var WorkspaceDirectoryService = class {
|
|
|
39091
39627
|
};
|
|
39092
39628
|
};
|
|
39093
39629
|
|
|
39630
|
+
// src/daemon-diagnostic-log.ts
|
|
39631
|
+
import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync, statSync as statSync3, writeFileSync } from "node:fs";
|
|
39632
|
+
import { join as join17 } from "node:path";
|
|
39633
|
+
var MAXIMUM_DAEMON_LOG_BYTES = 1 * 1024 * 1024;
|
|
39634
|
+
var DaemonDiagnosticLog = class {
|
|
39635
|
+
#directory;
|
|
39636
|
+
#path;
|
|
39637
|
+
#maximumBytes;
|
|
39638
|
+
constructor(stateDirectory, maximumBytes = MAXIMUM_DAEMON_LOG_BYTES) {
|
|
39639
|
+
this.#directory = join17(stateDirectory, "logs");
|
|
39640
|
+
this.#path = join17(this.#directory, "daemon.log");
|
|
39641
|
+
this.#maximumBytes = maximumBytes;
|
|
39642
|
+
}
|
|
39643
|
+
record = (diagnostic) => {
|
|
39644
|
+
const encoded = `${diagnostic.replace(/[\r\n]+/gu, " ").trim()}
|
|
39645
|
+
`;
|
|
39646
|
+
const encodedBytes = Buffer.byteLength(encoded);
|
|
39647
|
+
mkdirSync3(this.#directory, { mode: 448, recursive: true });
|
|
39648
|
+
let existingBytes = 0;
|
|
39649
|
+
try {
|
|
39650
|
+
existingBytes = statSync3(this.#path).size;
|
|
39651
|
+
} catch (cause) {
|
|
39652
|
+
if (!(cause instanceof Error && Reflect.get(cause, "code") === "ENOENT")) {
|
|
39653
|
+
throw cause;
|
|
39654
|
+
}
|
|
39655
|
+
}
|
|
39656
|
+
if (existingBytes + encodedBytes <= this.#maximumBytes) {
|
|
39657
|
+
appendFileSync(this.#path, encoded, { encoding: "utf8", mode: 384 });
|
|
39658
|
+
return;
|
|
39659
|
+
}
|
|
39660
|
+
const lines = `${existingBytes === 0 ? "" : readFileSync2(this.#path, "utf8")}${encoded}`.split("\n").filter((line) => line.length > 0);
|
|
39661
|
+
let totalBytes = lines.reduce((total, line) => total + Buffer.byteLength(line) + 1, 0);
|
|
39662
|
+
while (totalBytes > this.#maximumBytes && lines.length > 0) {
|
|
39663
|
+
const oldest = lines.shift();
|
|
39664
|
+
if (oldest !== void 0) {
|
|
39665
|
+
totalBytes -= Buffer.byteLength(oldest) + 1;
|
|
39666
|
+
}
|
|
39667
|
+
}
|
|
39668
|
+
const temporaryPath = `${this.#path}.tmp`;
|
|
39669
|
+
writeFileSync(temporaryPath, lines.length === 0 ? "" : `${lines.join("\n")}
|
|
39670
|
+
`, {
|
|
39671
|
+
encoding: "utf8",
|
|
39672
|
+
mode: 384
|
|
39673
|
+
});
|
|
39674
|
+
renameSync(temporaryPath, this.#path);
|
|
39675
|
+
};
|
|
39676
|
+
};
|
|
39677
|
+
|
|
39094
39678
|
// src/native-sessions/codex-history.ts
|
|
39095
39679
|
import { spawn as spawn5 } from "node:child_process";
|
|
39096
39680
|
var responseSchema = external_exports.union([
|
|
@@ -39101,7 +39685,7 @@ var responseSchema = external_exports.union([
|
|
|
39101
39685
|
external_exports.object({ id: external_exports.number(), result: external_exports.unknown() }),
|
|
39102
39686
|
external_exports.object({ method: external_exports.string() })
|
|
39103
39687
|
]);
|
|
39104
|
-
var
|
|
39688
|
+
var threadSchema2 = external_exports.object({
|
|
39105
39689
|
thread: external_exports.object({
|
|
39106
39690
|
id: nativeSessionIdSchema,
|
|
39107
39691
|
cwd: external_exports.string().min(1).max(2048).refine((path2) => !path2.includes("\0"))
|
|
@@ -39405,7 +39989,7 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
|
|
|
39405
39989
|
});
|
|
39406
39990
|
break;
|
|
39407
39991
|
case "metadata": {
|
|
39408
|
-
const { thread } =
|
|
39992
|
+
const { thread } = threadSchema2.parse(message.result);
|
|
39409
39993
|
state = { kind: "turns", requestId: 3, thread };
|
|
39410
39994
|
send2({
|
|
39411
39995
|
id: state.requestId,
|
|
@@ -39677,10 +40261,11 @@ var NativeSessionService = class {
|
|
|
39677
40261
|
deletedSessionIds
|
|
39678
40262
|
};
|
|
39679
40263
|
}
|
|
39680
|
-
|
|
40264
|
+
const action = command.action === "import-only" ? "import" : command.action === "fork-only" ? "fork" : command.action;
|
|
40265
|
+
if (action === "import" && !prepared.capabilities.loadSession && !prepared.capabilities.resumeSession) {
|
|
39681
40266
|
throw new AcpExecutionError("This Agent cannot import native sessions", {}, "native_session_unsupported");
|
|
39682
40267
|
}
|
|
39683
|
-
if (
|
|
40268
|
+
if (action === "fork" && !prepared.capabilities.unstableForkSession) {
|
|
39684
40269
|
throw new AcpExecutionError(
|
|
39685
40270
|
"This Agent does not support session forking",
|
|
39686
40271
|
{},
|
|
@@ -39701,7 +40286,8 @@ var NativeSessionService = class {
|
|
|
39701
40286
|
sessionId: command.targetSessionId,
|
|
39702
40287
|
additionalDirectories: target.additionalDirectories
|
|
39703
40288
|
},
|
|
39704
|
-
{ kind:
|
|
40289
|
+
{ kind: action, nativeSessionId: target.info.sessionId },
|
|
40290
|
+
command.action !== "import-only" && command.action !== "fork-only"
|
|
39705
40291
|
);
|
|
39706
40292
|
signal.throwIfAborted();
|
|
39707
40293
|
const ready = {
|
|
@@ -39719,10 +40305,10 @@ var NativeSessionService = class {
|
|
|
39719
40305
|
restored: true,
|
|
39720
40306
|
sessionId: opened.sessionId
|
|
39721
40307
|
};
|
|
39722
|
-
this.record(command,
|
|
40308
|
+
this.record(command, action === "fork" ? "native_session_forked" : "native_session_imported");
|
|
39723
40309
|
return {
|
|
39724
40310
|
...envelope2,
|
|
39725
|
-
action
|
|
40311
|
+
action,
|
|
39726
40312
|
ready,
|
|
39727
40313
|
targetSessionId: command.targetSessionId,
|
|
39728
40314
|
title: target.info.title ?? "Untitled session",
|
|
@@ -40113,6 +40699,59 @@ async function resolvePromptArtifacts(config2, command, signal) {
|
|
|
40113
40699
|
return new ResolvedPromptArtifacts(images, resources);
|
|
40114
40700
|
}
|
|
40115
40701
|
|
|
40702
|
+
// src/relay-connection/coalescing-narration-publisher.ts
|
|
40703
|
+
var CoalescingNarrationPublisher = class {
|
|
40704
|
+
#coalescingMilliseconds;
|
|
40705
|
+
#maximumTextLength;
|
|
40706
|
+
#publish;
|
|
40707
|
+
#timer;
|
|
40708
|
+
#pending = /* @__PURE__ */ new Map();
|
|
40709
|
+
#scheduled = null;
|
|
40710
|
+
constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
|
|
40711
|
+
this.#publish = publish;
|
|
40712
|
+
this.#timer = timer;
|
|
40713
|
+
this.#coalescingMilliseconds = coalescingMilliseconds;
|
|
40714
|
+
this.#maximumTextLength = maximumTextLength;
|
|
40715
|
+
}
|
|
40716
|
+
/** Emit every buffered increment now, cancelling the pending flush. */
|
|
40717
|
+
flush = () => {
|
|
40718
|
+
this.#scheduled?.cancel();
|
|
40719
|
+
this.#scheduled = null;
|
|
40720
|
+
const increments = [...this.#pending.entries()].map(
|
|
40721
|
+
([activityId, pending]) => ({
|
|
40722
|
+
activityId,
|
|
40723
|
+
activityType: pending.activityType,
|
|
40724
|
+
sequence: pending.sequence,
|
|
40725
|
+
text: pending.text
|
|
40726
|
+
})
|
|
40727
|
+
);
|
|
40728
|
+
this.#pending.clear();
|
|
40729
|
+
for (const increment of increments) {
|
|
40730
|
+
this.#publish(increment);
|
|
40731
|
+
}
|
|
40732
|
+
};
|
|
40733
|
+
/**
|
|
40734
|
+
* Buffer an increment, emitting the buffered text when it would exceed the
|
|
40735
|
+
* protocol's per-event text limit so no event is rejected by the codec.
|
|
40736
|
+
*/
|
|
40737
|
+
record = (increment) => {
|
|
40738
|
+
if (increment.text.length === 0) {
|
|
40739
|
+
return;
|
|
40740
|
+
}
|
|
40741
|
+
const previous2 = this.#pending.get(increment.activityId);
|
|
40742
|
+
if (previous2 !== void 0 && previous2.text.length + increment.text.length > this.#maximumTextLength) {
|
|
40743
|
+
this.flush();
|
|
40744
|
+
}
|
|
40745
|
+
const current = this.#pending.get(increment.activityId);
|
|
40746
|
+
this.#pending.set(increment.activityId, {
|
|
40747
|
+
activityType: increment.activityType,
|
|
40748
|
+
sequence: increment.sequence,
|
|
40749
|
+
text: `${current?.text ?? ""}${increment.text}`
|
|
40750
|
+
});
|
|
40751
|
+
this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
|
|
40752
|
+
};
|
|
40753
|
+
};
|
|
40754
|
+
|
|
40116
40755
|
// src/relay-connection/coalescing-text-publisher.ts
|
|
40117
40756
|
var CoalescingTextPublisher = class {
|
|
40118
40757
|
#coalescingMilliseconds;
|
|
@@ -40322,13 +40961,15 @@ function addFailureDetails(details, failure2) {
|
|
|
40322
40961
|
var RelayConnectionDiagnostics = class {
|
|
40323
40962
|
#audit;
|
|
40324
40963
|
#channelId;
|
|
40964
|
+
#localLog;
|
|
40325
40965
|
#lastClosedEpoch = 0;
|
|
40326
40966
|
#lastFailedEpoch = 0;
|
|
40327
40967
|
#relayOrigin;
|
|
40328
40968
|
#route;
|
|
40329
|
-
constructor(audit, channelId, relayUrl) {
|
|
40969
|
+
constructor(audit, channelId, relayUrl, localLog) {
|
|
40330
40970
|
this.#audit = audit;
|
|
40331
40971
|
this.#channelId = channelId;
|
|
40972
|
+
this.#localLog = localLog;
|
|
40332
40973
|
this.#relayOrigin = relayUrl.origin;
|
|
40333
40974
|
this.#route = describeEnvironmentProxyRoute(relayUrl);
|
|
40334
40975
|
}
|
|
@@ -40415,6 +41056,20 @@ var RelayConnectionDiagnostics = class {
|
|
|
40415
41056
|
true
|
|
40416
41057
|
);
|
|
40417
41058
|
};
|
|
41059
|
+
daemonDiagnostic = (event, requestId, details, failure2) => {
|
|
41060
|
+
const recordedDetails = { ...details };
|
|
41061
|
+
if (failure2 !== void 0) {
|
|
41062
|
+
addFailureDetails(recordedDetails, failure2);
|
|
41063
|
+
}
|
|
41064
|
+
this.#localLog.record(
|
|
41065
|
+
`Mobius daemon diagnostic ${JSON.stringify({
|
|
41066
|
+
channelId: this.#channelId,
|
|
41067
|
+
event,
|
|
41068
|
+
requestId,
|
|
41069
|
+
...recordedDetails
|
|
41070
|
+
})}`
|
|
41071
|
+
);
|
|
41072
|
+
};
|
|
40418
41073
|
#record = (event, commandId, details, warning) => {
|
|
40419
41074
|
this.#audit.record({
|
|
40420
41075
|
commandId,
|
|
@@ -40423,6 +41078,7 @@ var RelayConnectionDiagnostics = class {
|
|
|
40423
41078
|
sessionId: this.#channelId
|
|
40424
41079
|
});
|
|
40425
41080
|
const encoded = JSON.stringify({ channelId: this.#channelId, event, ...details });
|
|
41081
|
+
this.#localLog.record(`Mobius relay diagnostic ${encoded}`);
|
|
40426
41082
|
if (warning) {
|
|
40427
41083
|
process.stderr.write(`Mobius relay diagnostic ${encoded}
|
|
40428
41084
|
`);
|
|
@@ -40540,7 +41196,7 @@ var RelayConnectionLiveness = class {
|
|
|
40540
41196
|
};
|
|
40541
41197
|
|
|
40542
41198
|
// src/relay-connection/session-event-outbox.ts
|
|
40543
|
-
import { mkdirSync as
|
|
41199
|
+
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
40544
41200
|
import { dirname as dirname7 } from "node:path";
|
|
40545
41201
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
40546
41202
|
var DEFAULT_OUTBOX_LIMITS = {
|
|
@@ -40607,7 +41263,7 @@ var SessionEventOutbox = class {
|
|
|
40607
41263
|
constructor(path2, limits = DEFAULT_OUTBOX_LIMITS) {
|
|
40608
41264
|
validateLimits(limits);
|
|
40609
41265
|
this.#limits = limits;
|
|
40610
|
-
|
|
41266
|
+
mkdirSync4(dirname7(path2), { recursive: true });
|
|
40611
41267
|
this.#database = new DatabaseSync3(path2);
|
|
40612
41268
|
this.#database.exec(`
|
|
40613
41269
|
CREATE TABLE IF NOT EXISTS relay_session_event_outbox (
|
|
@@ -40833,6 +41489,19 @@ var SessionEventOutbox = class {
|
|
|
40833
41489
|
return this.#enqueueBounded(sessionId, payload, attemptId ?? "", this.#limits.standardEventBytes);
|
|
40834
41490
|
};
|
|
40835
41491
|
enqueueCritical = (sessionId, payload, attemptId = "") => this.#enqueueBounded(sessionId, payload, attemptId, this.#limits.criticalEventBytes);
|
|
41492
|
+
/**
|
|
41493
|
+
* Bytes still available to standard Session events. The daemon uses this to shed
|
|
41494
|
+
* superseded streaming events instead of filling the durable outbox, so a long Turn
|
|
41495
|
+
* behind a slow Relay cannot make the next enqueue throw.
|
|
41496
|
+
*/
|
|
41497
|
+
standardCapacityRemaining = () => {
|
|
41498
|
+
const state = this.#database.prepare(
|
|
41499
|
+
`SELECT total_bytes
|
|
41500
|
+
FROM relay_session_event_outbox_state
|
|
41501
|
+
WHERE singleton = 1`
|
|
41502
|
+
).get();
|
|
41503
|
+
return this.#limits.standardEventBytes - rowNumber(state, "total_bytes");
|
|
41504
|
+
};
|
|
40836
41505
|
claimRuntimeDelivery = (delivery) => {
|
|
40837
41506
|
const payloadBytes = new TextEncoder().encode(delivery.payload).byteLength;
|
|
40838
41507
|
this.#database.exec("BEGIN IMMEDIATE");
|
|
@@ -41441,6 +42110,12 @@ var ConnectedDaemonSessionEventState = class extends DaemonSessionEventConnectio
|
|
|
41441
42110
|
var SESSION_EVENT_REPLAY_WINDOW = 16;
|
|
41442
42111
|
var SESSION_EVENT_SOURCE_REPLAY_WINDOW = 4;
|
|
41443
42112
|
var SESSION_EVENT_REPLAY_BYTE_LIMIT = 32 * 1024 * 1024;
|
|
42113
|
+
function reservesSessionEventCapacity(event) {
|
|
42114
|
+
if (event.kind === SESSION_COMPLETED_KIND || event.kind === SESSION_FAILED_KIND) {
|
|
42115
|
+
return true;
|
|
42116
|
+
}
|
|
42117
|
+
return event.kind === AGENT_ACTIVITY_KIND && (event.activityType === "progress" || event.activityType === "reasoning") && (event.status === "completed" || event.status === "failed");
|
|
42118
|
+
}
|
|
41444
42119
|
var InFlightSessionEvent = class {
|
|
41445
42120
|
byteLength;
|
|
41446
42121
|
sourceKey;
|
|
@@ -41456,6 +42131,7 @@ var DaemonSessionEventPublisher = class {
|
|
|
41456
42131
|
#outbox;
|
|
41457
42132
|
#inFlightEvents = /* @__PURE__ */ new Map();
|
|
41458
42133
|
#pausedSources = /* @__PURE__ */ new Map();
|
|
42134
|
+
#shedEventKinds = /* @__PURE__ */ new Set();
|
|
41459
42135
|
#timer;
|
|
41460
42136
|
#inFlightBytes = 0;
|
|
41461
42137
|
#connection = new DisconnectedDaemonSessionEventState();
|
|
@@ -41477,17 +42153,64 @@ var DaemonSessionEventPublisher = class {
|
|
|
41477
42153
|
};
|
|
41478
42154
|
recordAttempt = (sessionId, event, attemptId) => {
|
|
41479
42155
|
const encoded = encodeRecordedSessionEvent(event);
|
|
41480
|
-
if (event
|
|
41481
|
-
this.#
|
|
42156
|
+
if (reservesSessionEventCapacity(event)) {
|
|
42157
|
+
this.#enqueueReserved(sessionId, encoded, attemptId, event.kind);
|
|
41482
42158
|
} else {
|
|
41483
|
-
this.#
|
|
42159
|
+
this.#enqueueStandard(sessionId, encoded, attemptId, event.kind);
|
|
41484
42160
|
}
|
|
41485
42161
|
this.#publishNextBatch();
|
|
41486
42162
|
};
|
|
41487
42163
|
recordRuntime = (sessionId, event) => {
|
|
41488
|
-
this.#
|
|
42164
|
+
this.#enqueueStandard(sessionId, encodeRecordedSessionEvent(event), "", event.kind);
|
|
41489
42165
|
this.#publishNextBatch();
|
|
41490
42166
|
};
|
|
42167
|
+
/**
|
|
42168
|
+
* Enqueue a standard event, shedding it instead of ending the daemon when the
|
|
42169
|
+
* durable outbox is full.
|
|
42170
|
+
*
|
|
42171
|
+
* A capacity error used to escape the coalescing timer that publishes activities,
|
|
42172
|
+
* so the process exited and every restart died on the same retained backlog. A full
|
|
42173
|
+
* outbox is a recoverable runtime condition, not a fatal one: narration increments are
|
|
42174
|
+
* superseded by the completed snapshot, so they are shed first, and any other streaming
|
|
42175
|
+
* event is shed only at the wall rather than terminating the daemon.
|
|
42176
|
+
*/
|
|
42177
|
+
#enqueueStandard = (sessionId, encoded, attemptId, kind) => {
|
|
42178
|
+
if (kind === AGENT_ACTIVITY_NARRATION_KIND && this.#outbox.standardCapacityRemaining() <= 0) {
|
|
42179
|
+
this.#reportShedEvent(kind);
|
|
42180
|
+
return;
|
|
42181
|
+
}
|
|
42182
|
+
try {
|
|
42183
|
+
this.#outbox.enqueue(sessionId, encoded, attemptId);
|
|
42184
|
+
} catch (error62) {
|
|
42185
|
+
if (!(error62 instanceof SessionEventOutboxCapacityError)) {
|
|
42186
|
+
throw error62;
|
|
42187
|
+
}
|
|
42188
|
+
this.#reportShedEvent(kind);
|
|
42189
|
+
}
|
|
42190
|
+
};
|
|
42191
|
+
/**
|
|
42192
|
+
* Enqueue on the reserved budget, degrading to a reported drop instead of raising.
|
|
42193
|
+
* Streaming events are shed before this budget is reached, so a Turn's terminal
|
|
42194
|
+
* events and the completed snapshot that carries its narration still land; a drop
|
|
42195
|
+
* here is the last resort for a backlog no acknowledgement can drain.
|
|
42196
|
+
*/
|
|
42197
|
+
#enqueueReserved = (sessionId, encoded, attemptId, kind) => {
|
|
42198
|
+
try {
|
|
42199
|
+
this.#outbox.enqueueCritical(sessionId, encoded, attemptId);
|
|
42200
|
+
} catch (error62) {
|
|
42201
|
+
if (!(error62 instanceof SessionEventOutboxCapacityError)) {
|
|
42202
|
+
throw error62;
|
|
42203
|
+
}
|
|
42204
|
+
this.#reportShedEvent(kind);
|
|
42205
|
+
}
|
|
42206
|
+
};
|
|
42207
|
+
#reportShedEvent = (kind) => {
|
|
42208
|
+
if (this.#shedEventKinds.has(kind)) {
|
|
42209
|
+
return;
|
|
42210
|
+
}
|
|
42211
|
+
this.#shedEventKinds.add(kind);
|
|
42212
|
+
console.warn(`Mobius daemon is dropping durable "${kind}" events because the Session event outbox is full`);
|
|
42213
|
+
};
|
|
41491
42214
|
acknowledge = (acknowledgement) => {
|
|
41492
42215
|
if (!this.#outbox.acknowledge(acknowledgement)) {
|
|
41493
42216
|
return;
|
|
@@ -42214,6 +42937,26 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42214
42937
|
const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
|
|
42215
42938
|
publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
|
|
42216
42939
|
});
|
|
42940
|
+
const narration = new CoalescingNarrationPublisher(
|
|
42941
|
+
timer,
|
|
42942
|
+
(increment) => {
|
|
42943
|
+
publisher.recordAttempt(
|
|
42944
|
+
command.sessionId,
|
|
42945
|
+
{
|
|
42946
|
+
activityId: increment.activityId,
|
|
42947
|
+
activityType: increment.activityType,
|
|
42948
|
+
commandId: command.commandId,
|
|
42949
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
42950
|
+
sequence: increment.sequence,
|
|
42951
|
+
sessionId: command.sessionId,
|
|
42952
|
+
text: increment.text
|
|
42953
|
+
},
|
|
42954
|
+
attemptId
|
|
42955
|
+
);
|
|
42956
|
+
},
|
|
42957
|
+
AGENT_ACTIVITY_COALESCING_MILLISECONDS,
|
|
42958
|
+
AGENT_TEXT_MAXIMUM_LENGTH
|
|
42959
|
+
);
|
|
42217
42960
|
const text3 = new CoalescingTextPublisher(
|
|
42218
42961
|
timer,
|
|
42219
42962
|
(messageId, delta) => {
|
|
@@ -42318,6 +43061,10 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42318
43061
|
disposition: command.disposition,
|
|
42319
43062
|
images: attachments.images,
|
|
42320
43063
|
onActivity: activities.record,
|
|
43064
|
+
onNarration: (increment) => {
|
|
43065
|
+
narration.record(increment);
|
|
43066
|
+
return Promise.resolve();
|
|
43067
|
+
},
|
|
42321
43068
|
onText: (delta, messageId) => {
|
|
42322
43069
|
text3.record(messageId, delta);
|
|
42323
43070
|
return Promise.resolve();
|
|
@@ -42331,6 +43078,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42331
43078
|
stopReason = result.stopReason;
|
|
42332
43079
|
}
|
|
42333
43080
|
text3.flush();
|
|
43081
|
+
narration.flush();
|
|
42334
43082
|
activities.flush();
|
|
42335
43083
|
publisher.recordAttempt(
|
|
42336
43084
|
command.sessionId,
|
|
@@ -42350,6 +43098,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
42350
43098
|
});
|
|
42351
43099
|
} catch (error62) {
|
|
42352
43100
|
text3.flush();
|
|
43101
|
+
narration.flush();
|
|
42353
43102
|
activities.flush();
|
|
42354
43103
|
audit.record({
|
|
42355
43104
|
commandId: command.commandId,
|
|
@@ -43071,6 +43820,11 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43071
43820
|
event: "agent_settings_model_unsupported",
|
|
43072
43821
|
sessionId: `agent-settings:${command2.agentId}`
|
|
43073
43822
|
});
|
|
43823
|
+
diagnostics.daemonDiagnostic(
|
|
43824
|
+
"agent_settings_model_unsupported",
|
|
43825
|
+
command2.requestId,
|
|
43826
|
+
details
|
|
43827
|
+
);
|
|
43074
43828
|
process.stderr.write(
|
|
43075
43829
|
`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_model_unsupported", requestId: command2.requestId, ...details })}
|
|
43076
43830
|
`
|
|
@@ -43101,6 +43855,12 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43101
43855
|
event: "agent_settings_discovery_failed",
|
|
43102
43856
|
sessionId: `agent-settings:${command2.agentId}`
|
|
43103
43857
|
});
|
|
43858
|
+
diagnostics.daemonDiagnostic(
|
|
43859
|
+
"agent_settings_discovery_failed",
|
|
43860
|
+
command2.requestId,
|
|
43861
|
+
details,
|
|
43862
|
+
failure2
|
|
43863
|
+
);
|
|
43104
43864
|
if (failure2 instanceof AcpConfigurationValueUnavailableError) {
|
|
43105
43865
|
process.stderr.write(
|
|
43106
43866
|
`Mobius daemon diagnostic ${JSON.stringify({ event: "agent_settings_discovery_failed", requestId: command2.requestId, ...details })}
|
|
@@ -43178,6 +43938,12 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43178
43938
|
event: "agent_catalog_refresh_failed",
|
|
43179
43939
|
sessionId: "agent-catalog"
|
|
43180
43940
|
});
|
|
43941
|
+
diagnostics.daemonDiagnostic(
|
|
43942
|
+
"agent_catalog_refresh_failed",
|
|
43943
|
+
command2.requestId,
|
|
43944
|
+
{ code: operationErrorCode(failure2) },
|
|
43945
|
+
failure2
|
|
43946
|
+
);
|
|
43181
43947
|
if (socket.readyState === WebSocket2.OPEN) {
|
|
43182
43948
|
send(socket, {
|
|
43183
43949
|
code: operationErrorCode(failure2),
|
|
@@ -43262,6 +44028,17 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43262
44028
|
event: "native_session_operation_failed",
|
|
43263
44029
|
details: { code: operationErrorCode(failure2) }
|
|
43264
44030
|
});
|
|
44031
|
+
diagnostics.daemonDiagnostic(
|
|
44032
|
+
"native_session_operation_failed",
|
|
44033
|
+
command2.requestId,
|
|
44034
|
+
{
|
|
44035
|
+
action: command2.action,
|
|
44036
|
+
agentId: command2.agentId,
|
|
44037
|
+
code: operationErrorCode(failure2),
|
|
44038
|
+
sessionId: command2.sessionId
|
|
44039
|
+
},
|
|
44040
|
+
failure2
|
|
44041
|
+
);
|
|
43265
44042
|
reportOperationFailure(socket, command2.requestId, command2.sessionId, failure2);
|
|
43266
44043
|
} finally {
|
|
43267
44044
|
timeout.cancel();
|
|
@@ -43342,6 +44119,16 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43342
44119
|
event: "native_session_turn_fork_failed",
|
|
43343
44120
|
sessionId: command2.sessionId
|
|
43344
44121
|
});
|
|
44122
|
+
diagnostics.daemonDiagnostic(
|
|
44123
|
+
"native_session_turn_fork_failed",
|
|
44124
|
+
command2.requestId,
|
|
44125
|
+
{
|
|
44126
|
+
agentId: command2.agentId,
|
|
44127
|
+
code: operationErrorCode(failure2),
|
|
44128
|
+
sessionId: command2.sessionId
|
|
44129
|
+
},
|
|
44130
|
+
failure2
|
|
44131
|
+
);
|
|
43345
44132
|
reportOperationFailure(socket, command2.requestId, command2.sessionId, failure2);
|
|
43346
44133
|
} finally {
|
|
43347
44134
|
timeout.cancel();
|
|
@@ -43614,7 +44401,12 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
43614
44401
|
});
|
|
43615
44402
|
const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
|
|
43616
44403
|
const installationObserver = new DaemonInstallationObserver();
|
|
43617
|
-
const diagnostics = new RelayConnectionDiagnostics(
|
|
44404
|
+
const diagnostics = new RelayConnectionDiagnostics(
|
|
44405
|
+
audit,
|
|
44406
|
+
config2.channelId,
|
|
44407
|
+
config2.relayUrl,
|
|
44408
|
+
new DaemonDiagnosticLog(stateDirectory)
|
|
44409
|
+
);
|
|
43618
44410
|
const nativeSessions = new NativeSessionService(config2, directories, sessions, audit);
|
|
43619
44411
|
const installations = new AgentInstallationManager(
|
|
43620
44412
|
specifications,
|