@moxt-ai/mobius 0.0.73 → 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.map +1 -1
- package/dist/acp/codex/agent.js +103 -3
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/acp/codex/app-server-protocol.d.ts +34 -0
- package/dist/acp/codex/app-server-protocol.d.ts.map +1 -1
- package/dist/acp/codex/app-server-protocol.js +26 -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 +6 -1
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +4 -4
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/cli.js +380 -47
- package/dist/cli.js.map +4 -4
- package/dist/index.js +380 -46
- package/dist/index.js.map +4 -4
- 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/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 +88 -6
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +379 -46
- package/dist/runtime.js.map +4 -4
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -21148,6 +21148,11 @@ var threadStartResponseSchema = external_exports.object({
|
|
|
21148
21148
|
serviceTier: boundedText(256).nullish(),
|
|
21149
21149
|
thread: external_exports.object({ id: boundedText(256) })
|
|
21150
21150
|
});
|
|
21151
|
+
var threadResumeResponseSchema = external_exports.object({
|
|
21152
|
+
model: boundedText(256).nullish(),
|
|
21153
|
+
reasoningEffort: boundedText(256).nullish(),
|
|
21154
|
+
thread: external_exports.object({ id: boundedText(256) }).nullish()
|
|
21155
|
+
});
|
|
21151
21156
|
var reasoningEffortOptionSchema = external_exports.object({
|
|
21152
21157
|
description: boundedText(4096).nullish(),
|
|
21153
21158
|
reasoningEffort: boundedText(256)
|
|
@@ -21165,6 +21170,19 @@ var modelListResponseSchema = external_exports.object({
|
|
|
21165
21170
|
data: external_exports.array(modelSchema).max(1e3),
|
|
21166
21171
|
nextCursor: boundedText(1024).nullish()
|
|
21167
21172
|
});
|
|
21173
|
+
var threadSchema = external_exports.object({
|
|
21174
|
+
createdAt: external_exports.number().nullish(),
|
|
21175
|
+
cwd: boundedText(4096).nullish(),
|
|
21176
|
+
id: boundedText(256),
|
|
21177
|
+
name: boundedText(4096).nullish(),
|
|
21178
|
+
preview: boundedText(4096).nullish(),
|
|
21179
|
+
updatedAt: external_exports.number().nullish()
|
|
21180
|
+
});
|
|
21181
|
+
var threadListResponseSchema = external_exports.object({
|
|
21182
|
+
data: external_exports.array(threadSchema).max(1e4),
|
|
21183
|
+
nextCursor: boundedText(1024).nullish()
|
|
21184
|
+
});
|
|
21185
|
+
var turnSteerResponseSchema = external_exports.object({ turnId: boundedText(256) });
|
|
21168
21186
|
|
|
21169
21187
|
// src/acp/codex/app-server-client.ts
|
|
21170
21188
|
var INITIALIZE_TIMEOUT_MILLISECONDS = 3e4;
|
|
@@ -21504,6 +21522,7 @@ function agentMessageMeta(phase) {
|
|
|
21504
21522
|
var APPROVAL_REASON_CHARACTER_LIMIT = 500;
|
|
21505
21523
|
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
21506
21524
|
var CODEX_AGENT_VERSION = "0.154.0";
|
|
21525
|
+
var STEERING_METHOD = "_session/steering";
|
|
21507
21526
|
var MODEL_SETTING_ID = "model";
|
|
21508
21527
|
var REASONING_EFFORT_SETTING_ID = "reasoning_effort";
|
|
21509
21528
|
var MODE_SETTING_ID = "mode";
|
|
@@ -21554,6 +21573,26 @@ function initialMode(environment) {
|
|
|
21554
21573
|
function capitalize(value) {
|
|
21555
21574
|
return value.length === 0 ? value : value.charAt(0).toUpperCase() + value.slice(1);
|
|
21556
21575
|
}
|
|
21576
|
+
function threadTitle(thread) {
|
|
21577
|
+
const named = thread.name?.trim() ?? "";
|
|
21578
|
+
if (named.length > 0) {
|
|
21579
|
+
return named;
|
|
21580
|
+
}
|
|
21581
|
+
return thread.preview?.trim() ?? "";
|
|
21582
|
+
}
|
|
21583
|
+
function isoTimestamp(seconds) {
|
|
21584
|
+
if (seconds == null || !Number.isFinite(seconds)) {
|
|
21585
|
+
return null;
|
|
21586
|
+
}
|
|
21587
|
+
return new Date(seconds * 1e3).toISOString();
|
|
21588
|
+
}
|
|
21589
|
+
function steeringParams(params) {
|
|
21590
|
+
const prompt = typeof params === "object" && params !== null ? Reflect.get(params, "prompt") : void 0;
|
|
21591
|
+
if (!Array.isArray(prompt)) {
|
|
21592
|
+
throw new AcpExecutionError("The steering prompt is invalid", {}, "steering_failed");
|
|
21593
|
+
}
|
|
21594
|
+
return { prompt };
|
|
21595
|
+
}
|
|
21557
21596
|
var APPROVAL_OPTIONS = Object.freeze([
|
|
21558
21597
|
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
21559
21598
|
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
@@ -21727,10 +21766,12 @@ var CodexAcpAgent = class {
|
|
|
21727
21766
|
agentCapabilities: {
|
|
21728
21767
|
loadSession: false,
|
|
21729
21768
|
promptCapabilities: { embeddedContext: true, image: true },
|
|
21730
|
-
sessionCapabilities: { close: {} }
|
|
21769
|
+
sessionCapabilities: { close: {}, delete: {}, list: {}, resume: {} }
|
|
21731
21770
|
},
|
|
21732
21771
|
agentInfo: { name: "Codex", version: CODEX_AGENT_VERSION },
|
|
21733
21772
|
authMethods: [],
|
|
21773
|
+
// Mobius reads this to decide whether mid-turn steering can be attempted at all.
|
|
21774
|
+
_meta: { steering: { supported: true } },
|
|
21734
21775
|
protocolVersion: PROTOCOL_VERSION
|
|
21735
21776
|
})).onRequest(methods.agent.session.new, async (context) => {
|
|
21736
21777
|
const created = threadStartResponseSchema.parse(
|
|
@@ -21747,6 +21788,54 @@ var CodexAcpAgent = class {
|
|
|
21747
21788
|
model: created.model ?? ""
|
|
21748
21789
|
};
|
|
21749
21790
|
return { configOptions: this.#configOptions(), sessionId: created.thread.id };
|
|
21791
|
+
}).onRequest(methods.agent.session.resume, async (context) => {
|
|
21792
|
+
const resumed = threadResumeResponseSchema.parse(
|
|
21793
|
+
await this.#appServer.request(
|
|
21794
|
+
"thread/resume",
|
|
21795
|
+
{ cwd: context.params.cwd, threadId: context.params.sessionId },
|
|
21796
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21797
|
+
)
|
|
21798
|
+
);
|
|
21799
|
+
if (resumed.thread == null) {
|
|
21800
|
+
throw new AcpExecutionError(
|
|
21801
|
+
"Codex no longer has the native session this conversation belongs to",
|
|
21802
|
+
{},
|
|
21803
|
+
"session_restore_unsupported"
|
|
21804
|
+
);
|
|
21805
|
+
}
|
|
21806
|
+
this.#nativeSessionId = resumed.thread.id;
|
|
21807
|
+
this.#selection = {
|
|
21808
|
+
...this.#selection,
|
|
21809
|
+
effort: resumed.reasoningEffort ?? this.#selection.effort,
|
|
21810
|
+
model: resumed.model ?? this.#selection.model
|
|
21811
|
+
};
|
|
21812
|
+
return { configOptions: this.#configOptions() };
|
|
21813
|
+
}).onRequest(methods.agent.session.list, async (context) => {
|
|
21814
|
+
const listed = threadListResponseSchema.parse(
|
|
21815
|
+
await this.#appServer.request(
|
|
21816
|
+
"thread/list",
|
|
21817
|
+
context.params.cursor === void 0 || context.params.cursor === null ? {} : { cursor: context.params.cursor },
|
|
21818
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21819
|
+
)
|
|
21820
|
+
);
|
|
21821
|
+
return {
|
|
21822
|
+
nextCursor: listed.nextCursor ?? null,
|
|
21823
|
+
sessions: listed.data.map((thread) => ({
|
|
21824
|
+
// The thread id is a UUID, which satisfies the native session id contract.
|
|
21825
|
+
additionalDirectories: [],
|
|
21826
|
+
cwd: thread.cwd ?? "",
|
|
21827
|
+
sessionId: thread.id,
|
|
21828
|
+
title: threadTitle(thread),
|
|
21829
|
+
updatedAt: isoTimestamp(thread.updatedAt)
|
|
21830
|
+
}))
|
|
21831
|
+
};
|
|
21832
|
+
}).onRequest(methods.agent.session.delete, async (context) => {
|
|
21833
|
+
await this.#appServer.request(
|
|
21834
|
+
"thread/archive",
|
|
21835
|
+
{ threadId: context.params.sessionId },
|
|
21836
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21837
|
+
);
|
|
21838
|
+
return {};
|
|
21750
21839
|
}).onRequest(methods.agent.session.setConfigOption, async (context) => {
|
|
21751
21840
|
this.#applySelection(context.params.configId, context.params.value);
|
|
21752
21841
|
return { configOptions: this.#configOptions() };
|
|
@@ -21755,6 +21844,30 @@ var CodexAcpAgent = class {
|
|
|
21755
21844
|
return {};
|
|
21756
21845
|
}).onRequest(methods.agent.session.prompt, async (context) => {
|
|
21757
21846
|
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
21847
|
+
}).onRequest(STEERING_METHOD, steeringParams, async (context) => {
|
|
21848
|
+
const turn = this.#turn;
|
|
21849
|
+
if (turn === null || turn.turn.id.length === 0) {
|
|
21850
|
+
return { outcome: "promptRequired" };
|
|
21851
|
+
}
|
|
21852
|
+
try {
|
|
21853
|
+
const steered = turnSteerResponseSchema.parse(
|
|
21854
|
+
await this.#appServer.request(
|
|
21855
|
+
"turn/steer",
|
|
21856
|
+
{
|
|
21857
|
+
expectedTurnId: turn.turn.id,
|
|
21858
|
+
input: promptInput(context.params.prompt),
|
|
21859
|
+
threadId: this.#nativeSessionId
|
|
21860
|
+
},
|
|
21861
|
+
AbortSignal.any([context.signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS)])
|
|
21862
|
+
)
|
|
21863
|
+
);
|
|
21864
|
+
return { outcome: steered.turnId === turn.turn.id ? "injected" : "startedNewTurn" };
|
|
21865
|
+
} catch (error62) {
|
|
21866
|
+
if (error62 instanceof CodexAppServerError) {
|
|
21867
|
+
return { outcome: "promptRequired" };
|
|
21868
|
+
}
|
|
21869
|
+
throw error62;
|
|
21870
|
+
}
|
|
21758
21871
|
}).onRequest(methods.agent.session.close, async () => {
|
|
21759
21872
|
await this.#interruptTurn();
|
|
21760
21873
|
}).onNotification(methods.agent.session.cancel, async () => {
|
|
@@ -24567,6 +24680,7 @@ var RUNTIME_DELIVERY_COMMITTED_KIND = "runtime.delivery.committed";
|
|
|
24567
24680
|
var SESSION_STARTED_KIND = "session.started";
|
|
24568
24681
|
var AGENT_MESSAGE_DELTA_KIND = "agent.message.delta";
|
|
24569
24682
|
var AGENT_ACTIVITY_KIND = "agent.activity";
|
|
24683
|
+
var AGENT_ACTIVITY_NARRATION_KIND = "agent.activity.narration";
|
|
24570
24684
|
var AGENT_ACTIVITY_DETAIL_LIMIT = 5e5;
|
|
24571
24685
|
var AGENT_ACTIVITY_RECORDED_FIELD_LIMIT = 4e6;
|
|
24572
24686
|
var AGENT_ACTIVITY_RECORDED_DETAIL_LIMIT = 6e6;
|
|
@@ -24588,6 +24702,7 @@ var MAX_PROMPT_ATTACHMENT_LENGTH = 6e6;
|
|
|
24588
24702
|
var MAX_EVENT_TEXT_LENGTH = 1e5;
|
|
24589
24703
|
var MAX_RUNTIME_DELIVERY_PAYLOAD_LENGTH = 8 * 1024 * 1024;
|
|
24590
24704
|
var ACTIVITY_TYPES = /* @__PURE__ */ new Set(["plan", "progress", "reasoning", "tool"]);
|
|
24705
|
+
var NARRATION_ACTIVITY_TYPES = /* @__PURE__ */ new Set(["progress", "reasoning"]);
|
|
24591
24706
|
var ACTIVITY_STATUSES = /* @__PURE__ */ new Set(["pending", "running", "completed", "failed"]);
|
|
24592
24707
|
var TOOL_KINDS = /* @__PURE__ */ new Set([
|
|
24593
24708
|
"",
|
|
@@ -25011,6 +25126,20 @@ function encodeRuntimeDeliveryReceived(message) {
|
|
|
25011
25126
|
function encodeRuntimeDeliveryCommitted(message) {
|
|
25012
25127
|
return JSON.stringify(decodeRuntimeDeliveryCommitted(JSON.stringify(message)));
|
|
25013
25128
|
}
|
|
25129
|
+
function decodeAgentActivityNarrationEvent(encoded) {
|
|
25130
|
+
const value = parseJson2(encoded);
|
|
25131
|
+
assertExactKeys(value, ["activityId", "activityType", "commandId", "kind", "sequence", "sessionId", "text"]);
|
|
25132
|
+
assertKind(value, AGENT_ACTIVITY_NARRATION_KIND);
|
|
25133
|
+
return {
|
|
25134
|
+
activityId: readIdentifier(value, "activityId"),
|
|
25135
|
+
activityType: readAllowedString(value, "activityType", NARRATION_ACTIVITY_TYPES),
|
|
25136
|
+
commandId: readIdentifier(value, "commandId"),
|
|
25137
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
25138
|
+
sequence: readSequence(value, "sequence"),
|
|
25139
|
+
sessionId: readIdentifier(value, "sessionId"),
|
|
25140
|
+
text: readText(value, "text", MAX_EVENT_TEXT_LENGTH)
|
|
25141
|
+
};
|
|
25142
|
+
}
|
|
25014
25143
|
|
|
25015
25144
|
// ../protocol/src/session-history.ts
|
|
25016
25145
|
var SESSION_HISTORY_CHARACTER_LIMIT = 256e3;
|
|
@@ -25359,6 +25488,8 @@ function decodeRecordedSessionEvent(encoded) {
|
|
|
25359
25488
|
switch (kind) {
|
|
25360
25489
|
case AGENT_ACTIVITY_KIND:
|
|
25361
25490
|
return decodeAgentActivityEvent(encoded);
|
|
25491
|
+
case AGENT_ACTIVITY_NARRATION_KIND:
|
|
25492
|
+
return decodeAgentActivityNarrationEvent(encoded);
|
|
25362
25493
|
case AGENT_CONTENT_KIND:
|
|
25363
25494
|
return decodeAgentContentEvent(encoded);
|
|
25364
25495
|
case AGENT_MESSAGE_DELTA_KIND:
|
|
@@ -26044,6 +26175,18 @@ async function replaceImageMarkers(text3, replace) {
|
|
|
26044
26175
|
|
|
26045
26176
|
// src/acp/activity.ts
|
|
26046
26177
|
var TRUNCATION_MARKER = "\n\u2026 output truncated by Mobius";
|
|
26178
|
+
var AcpActivityNarration = class {
|
|
26179
|
+
activityId;
|
|
26180
|
+
activityType;
|
|
26181
|
+
sequence;
|
|
26182
|
+
text;
|
|
26183
|
+
constructor(activityId, activityType, sequence, text3) {
|
|
26184
|
+
this.activityId = activityId;
|
|
26185
|
+
this.activityType = activityType;
|
|
26186
|
+
this.sequence = sequence;
|
|
26187
|
+
this.text = text3;
|
|
26188
|
+
}
|
|
26189
|
+
};
|
|
26047
26190
|
function isRecord5(value) {
|
|
26048
26191
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
26049
26192
|
}
|
|
@@ -26376,12 +26519,15 @@ function isProgressMessage(content3) {
|
|
|
26376
26519
|
var AcpActivityTracker = class {
|
|
26377
26520
|
#activities = /* @__PURE__ */ new Map();
|
|
26378
26521
|
#identities = /* @__PURE__ */ new Map();
|
|
26522
|
+
#narrations = /* @__PURE__ */ new Map();
|
|
26379
26523
|
#onActivity;
|
|
26524
|
+
#onNarration;
|
|
26380
26525
|
#prepareContent;
|
|
26381
26526
|
#activeNarrativeKey = "";
|
|
26382
26527
|
#nextSequence = 0;
|
|
26383
|
-
constructor(onActivity, prepareContent = (content3) => Promise.resolve(content3)) {
|
|
26528
|
+
constructor(onActivity, onNarration, prepareContent = (content3) => Promise.resolve(content3)) {
|
|
26384
26529
|
this.#onActivity = onActivity;
|
|
26530
|
+
this.#onNarration = onNarration;
|
|
26385
26531
|
this.#prepareContent = prepareContent;
|
|
26386
26532
|
}
|
|
26387
26533
|
recordNarrative = async (activityType, messageId, text3) => {
|
|
@@ -26389,26 +26535,34 @@ var AcpActivityTracker = class {
|
|
|
26389
26535
|
if (this.#activeNarrativeKey !== key) {
|
|
26390
26536
|
await this.finishNarrative();
|
|
26391
26537
|
}
|
|
26392
|
-
const previous2 = this.#activities.get(key);
|
|
26393
26538
|
const identity2 = this.#identity(key);
|
|
26394
|
-
const
|
|
26395
|
-
|
|
26396
|
-
identity2.id,
|
|
26539
|
+
const previous2 = this.#narrations.get(key);
|
|
26540
|
+
this.#narrations.set(key, {
|
|
26541
|
+
activityId: identity2.id,
|
|
26397
26542
|
activityType,
|
|
26398
|
-
""
|
|
26399
|
-
|
|
26400
|
-
|
|
26401
|
-
|
|
26402
|
-
identity2
|
|
26403
|
-
|
|
26404
|
-
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
26405
|
-
activityType === "reasoning" ? "think" : "",
|
|
26406
|
-
[],
|
|
26407
|
-
captureActivityDetail([], "", fullOutput)
|
|
26408
|
-
);
|
|
26409
|
-
await this.#record(key, activity2);
|
|
26543
|
+
output: `${previous2?.output ?? ""}${text3}`,
|
|
26544
|
+
sequence: identity2.sequence
|
|
26545
|
+
});
|
|
26546
|
+
if (previous2 === void 0) {
|
|
26547
|
+
await this.#record(key, this.#narrativeSnapshot(identity2, activityType, "", "running"));
|
|
26548
|
+
}
|
|
26410
26549
|
this.#activeNarrativeKey = key;
|
|
26550
|
+
if (text3.length > 0) {
|
|
26551
|
+
await this.#onNarration(new AcpActivityNarration(identity2.id, activityType, identity2.sequence, text3));
|
|
26552
|
+
}
|
|
26411
26553
|
};
|
|
26554
|
+
#narrativeSnapshot = (identity2, activityType, output2, status) => new AcpActivity(
|
|
26555
|
+
identity2.id,
|
|
26556
|
+
activityType,
|
|
26557
|
+
"",
|
|
26558
|
+
[],
|
|
26559
|
+
"",
|
|
26560
|
+
truncate2(output2, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
26561
|
+
identity2.sequence,
|
|
26562
|
+
status,
|
|
26563
|
+
activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
26564
|
+
activityType === "reasoning" ? "think" : ""
|
|
26565
|
+
);
|
|
26412
26566
|
recordPlan = async (plan) => {
|
|
26413
26567
|
await this.finishNarrative();
|
|
26414
26568
|
await this.#recordPlanEntries("plan:default", plan.entries);
|
|
@@ -26528,17 +26682,13 @@ var AcpActivityTracker = class {
|
|
|
26528
26682
|
return;
|
|
26529
26683
|
}
|
|
26530
26684
|
this.#activeNarrativeKey = "";
|
|
26531
|
-
|
|
26532
|
-
if (activity2 === void 0) {
|
|
26533
|
-
return;
|
|
26534
|
-
}
|
|
26535
|
-
const completed = activity2.complete();
|
|
26536
|
-
if (completed !== activity2) {
|
|
26537
|
-
await this.#record(key, completed);
|
|
26538
|
-
}
|
|
26685
|
+
await this.#completeNarrative(key);
|
|
26539
26686
|
};
|
|
26540
26687
|
finish = async () => {
|
|
26541
26688
|
await this.finishNarrative();
|
|
26689
|
+
for (const key of this.#narrations.keys()) {
|
|
26690
|
+
await this.#completeNarrative(key);
|
|
26691
|
+
}
|
|
26542
26692
|
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
26543
26693
|
for (const [key, activity2] of entries) {
|
|
26544
26694
|
const completed = activity2.complete();
|
|
@@ -26547,6 +26697,34 @@ var AcpActivityTracker = class {
|
|
|
26547
26697
|
}
|
|
26548
26698
|
}
|
|
26549
26699
|
};
|
|
26700
|
+
// Materialize a streamed narration as one completed snapshot activity. The
|
|
26701
|
+
// incremental events carried the text; this final event gives consumers the
|
|
26702
|
+
// whole narration with its terminal status, as a single bounded item.
|
|
26703
|
+
#completeNarrative = async (key) => {
|
|
26704
|
+
const narration = this.#narrations.get(key);
|
|
26705
|
+
if (narration === void 0) {
|
|
26706
|
+
return;
|
|
26707
|
+
}
|
|
26708
|
+
this.#narrations.delete(key);
|
|
26709
|
+
const previous2 = this.#activities.get(key);
|
|
26710
|
+
await this.#record(
|
|
26711
|
+
key,
|
|
26712
|
+
new AcpActivity(
|
|
26713
|
+
narration.activityId,
|
|
26714
|
+
narration.activityType,
|
|
26715
|
+
"",
|
|
26716
|
+
[],
|
|
26717
|
+
"",
|
|
26718
|
+
truncate2(narration.output, AGENT_ACTIVITY_DETAIL_LIMIT),
|
|
26719
|
+
narration.sequence,
|
|
26720
|
+
"completed",
|
|
26721
|
+
narration.activityType === "reasoning" ? "Reasoning" : "Progress update",
|
|
26722
|
+
narration.activityType === "reasoning" ? "think" : "",
|
|
26723
|
+
previous2?.content ?? [],
|
|
26724
|
+
captureActivityDetail([], "", narration.output)
|
|
26725
|
+
)
|
|
26726
|
+
);
|
|
26727
|
+
};
|
|
26550
26728
|
#identity = (key) => {
|
|
26551
26729
|
const existing = this.#identities.get(key);
|
|
26552
26730
|
if (existing !== void 0) {
|
|
@@ -34190,17 +34368,22 @@ var AcpHistoryReplay = class {
|
|
|
34190
34368
|
#activities = /* @__PURE__ */ new Map();
|
|
34191
34369
|
#messages = [];
|
|
34192
34370
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
34193
|
-
#activityTracker = new AcpActivityTracker(
|
|
34194
|
-
|
|
34195
|
-
|
|
34196
|
-
|
|
34197
|
-
|
|
34198
|
-
|
|
34199
|
-
|
|
34200
|
-
|
|
34201
|
-
|
|
34202
|
-
|
|
34203
|
-
|
|
34371
|
+
#activityTracker = new AcpActivityTracker(
|
|
34372
|
+
async (activity2) => {
|
|
34373
|
+
this.#activities.set(activity2.activityId, activity2);
|
|
34374
|
+
this.#turnActivityIds.add(activity2.activityId);
|
|
34375
|
+
const latest = this.#messages.at(-1);
|
|
34376
|
+
if (latest?.role === "assistant") {
|
|
34377
|
+
this.#messages[this.#messages.length - 1] = {
|
|
34378
|
+
...latest,
|
|
34379
|
+
activityIds: [...this.#turnActivityIds]
|
|
34380
|
+
};
|
|
34381
|
+
}
|
|
34382
|
+
},
|
|
34383
|
+
// History replay folds each narration into its snapshot activity, so no
|
|
34384
|
+
// separate incremental event is produced here.
|
|
34385
|
+
() => Promise.resolve()
|
|
34386
|
+
);
|
|
34204
34387
|
#lastMessageId = null;
|
|
34205
34388
|
#characters = 0;
|
|
34206
34389
|
#truncated = false;
|
|
@@ -35019,7 +35202,10 @@ var AcpTurnState = class {
|
|
|
35019
35202
|
var IdleAcpTurn = class extends AcpTurnState {
|
|
35020
35203
|
commandId = SESSION_CONTROL_COMMAND_ID;
|
|
35021
35204
|
running = false;
|
|
35022
|
-
activities = new AcpActivityTracker(
|
|
35205
|
+
activities = new AcpActivityTracker(
|
|
35206
|
+
() => Promise.resolve(),
|
|
35207
|
+
() => Promise.resolve()
|
|
35208
|
+
);
|
|
35023
35209
|
onText = () => Promise.resolve();
|
|
35024
35210
|
};
|
|
35025
35211
|
var RunningAcpTurn = class extends AcpTurnState {
|
|
@@ -35027,10 +35213,10 @@ var RunningAcpTurn = class extends AcpTurnState {
|
|
|
35027
35213
|
running = true;
|
|
35028
35214
|
activities;
|
|
35029
35215
|
onText;
|
|
35030
|
-
constructor(commandId, onActivity, onText, prepareContent) {
|
|
35216
|
+
constructor(commandId, onActivity, onNarration, onText, prepareContent) {
|
|
35031
35217
|
super();
|
|
35032
35218
|
this.commandId = commandId;
|
|
35033
|
-
this.activities = new AcpActivityTracker(onActivity, prepareContent);
|
|
35219
|
+
this.activities = new AcpActivityTracker(onActivity, onNarration ?? (() => Promise.resolve()), prepareContent);
|
|
35034
35220
|
this.onText = onText;
|
|
35035
35221
|
}
|
|
35036
35222
|
};
|
|
@@ -35835,6 +36021,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35835
36021
|
const running = new RunningAcpTurn(
|
|
35836
36022
|
options.commandId,
|
|
35837
36023
|
options.onActivity,
|
|
36024
|
+
options.onNarration,
|
|
35838
36025
|
options.onText,
|
|
35839
36026
|
this.prepareAgentContent
|
|
35840
36027
|
);
|
|
@@ -38503,7 +38690,7 @@ var responseSchema = external_exports.union([
|
|
|
38503
38690
|
external_exports.object({ id: external_exports.number(), result: external_exports.unknown() }),
|
|
38504
38691
|
external_exports.object({ method: external_exports.string() })
|
|
38505
38692
|
]);
|
|
38506
|
-
var
|
|
38693
|
+
var threadSchema2 = external_exports.object({
|
|
38507
38694
|
thread: external_exports.object({
|
|
38508
38695
|
id: nativeSessionIdSchema,
|
|
38509
38696
|
cwd: external_exports.string().min(1).max(2048).refine((path2) => !path2.includes("\0"))
|
|
@@ -38807,7 +38994,7 @@ async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal,
|
|
|
38807
38994
|
});
|
|
38808
38995
|
break;
|
|
38809
38996
|
case "metadata": {
|
|
38810
|
-
const { thread } =
|
|
38997
|
+
const { thread } = threadSchema2.parse(message.result);
|
|
38811
38998
|
state = { kind: "turns", requestId: 3, thread };
|
|
38812
38999
|
send2({
|
|
38813
39000
|
id: state.requestId,
|
|
@@ -39517,6 +39704,59 @@ async function resolvePromptArtifacts(config2, command, signal) {
|
|
|
39517
39704
|
return new ResolvedPromptArtifacts(images, resources);
|
|
39518
39705
|
}
|
|
39519
39706
|
|
|
39707
|
+
// src/relay-connection/coalescing-narration-publisher.ts
|
|
39708
|
+
var CoalescingNarrationPublisher = class {
|
|
39709
|
+
#coalescingMilliseconds;
|
|
39710
|
+
#maximumTextLength;
|
|
39711
|
+
#publish;
|
|
39712
|
+
#timer;
|
|
39713
|
+
#pending = /* @__PURE__ */ new Map();
|
|
39714
|
+
#scheduled = null;
|
|
39715
|
+
constructor(timer, publish, coalescingMilliseconds, maximumTextLength) {
|
|
39716
|
+
this.#publish = publish;
|
|
39717
|
+
this.#timer = timer;
|
|
39718
|
+
this.#coalescingMilliseconds = coalescingMilliseconds;
|
|
39719
|
+
this.#maximumTextLength = maximumTextLength;
|
|
39720
|
+
}
|
|
39721
|
+
/** Emit every buffered increment now, cancelling the pending flush. */
|
|
39722
|
+
flush = () => {
|
|
39723
|
+
this.#scheduled?.cancel();
|
|
39724
|
+
this.#scheduled = null;
|
|
39725
|
+
const increments = [...this.#pending.entries()].map(
|
|
39726
|
+
([activityId, pending]) => ({
|
|
39727
|
+
activityId,
|
|
39728
|
+
activityType: pending.activityType,
|
|
39729
|
+
sequence: pending.sequence,
|
|
39730
|
+
text: pending.text
|
|
39731
|
+
})
|
|
39732
|
+
);
|
|
39733
|
+
this.#pending.clear();
|
|
39734
|
+
for (const increment of increments) {
|
|
39735
|
+
this.#publish(increment);
|
|
39736
|
+
}
|
|
39737
|
+
};
|
|
39738
|
+
/**
|
|
39739
|
+
* Buffer an increment, emitting the buffered text when it would exceed the
|
|
39740
|
+
* protocol's per-event text limit so no event is rejected by the codec.
|
|
39741
|
+
*/
|
|
39742
|
+
record = (increment) => {
|
|
39743
|
+
if (increment.text.length === 0) {
|
|
39744
|
+
return;
|
|
39745
|
+
}
|
|
39746
|
+
const previous2 = this.#pending.get(increment.activityId);
|
|
39747
|
+
if (previous2 !== void 0 && previous2.text.length + increment.text.length > this.#maximumTextLength) {
|
|
39748
|
+
this.flush();
|
|
39749
|
+
}
|
|
39750
|
+
const current = this.#pending.get(increment.activityId);
|
|
39751
|
+
this.#pending.set(increment.activityId, {
|
|
39752
|
+
activityType: increment.activityType,
|
|
39753
|
+
sequence: increment.sequence,
|
|
39754
|
+
text: `${current?.text ?? ""}${increment.text}`
|
|
39755
|
+
});
|
|
39756
|
+
this.#scheduled ??= this.#timer.schedule(this.flush, this.#coalescingMilliseconds);
|
|
39757
|
+
};
|
|
39758
|
+
};
|
|
39759
|
+
|
|
39520
39760
|
// src/relay-connection/coalescing-text-publisher.ts
|
|
39521
39761
|
var CoalescingTextPublisher = class {
|
|
39522
39762
|
#coalescingMilliseconds;
|
|
@@ -40254,6 +40494,19 @@ var SessionEventOutbox = class {
|
|
|
40254
40494
|
return this.#enqueueBounded(sessionId, payload, attemptId ?? "", this.#limits.standardEventBytes);
|
|
40255
40495
|
};
|
|
40256
40496
|
enqueueCritical = (sessionId, payload, attemptId = "") => this.#enqueueBounded(sessionId, payload, attemptId, this.#limits.criticalEventBytes);
|
|
40497
|
+
/**
|
|
40498
|
+
* Bytes still available to standard Session events. The daemon uses this to shed
|
|
40499
|
+
* superseded streaming events instead of filling the durable outbox, so a long Turn
|
|
40500
|
+
* behind a slow Relay cannot make the next enqueue throw.
|
|
40501
|
+
*/
|
|
40502
|
+
standardCapacityRemaining = () => {
|
|
40503
|
+
const state = this.#database.prepare(
|
|
40504
|
+
`SELECT total_bytes
|
|
40505
|
+
FROM relay_session_event_outbox_state
|
|
40506
|
+
WHERE singleton = 1`
|
|
40507
|
+
).get();
|
|
40508
|
+
return this.#limits.standardEventBytes - rowNumber(state, "total_bytes");
|
|
40509
|
+
};
|
|
40257
40510
|
claimRuntimeDelivery = (delivery) => {
|
|
40258
40511
|
const payloadBytes = new TextEncoder().encode(delivery.payload).byteLength;
|
|
40259
40512
|
this.#database.exec("BEGIN IMMEDIATE");
|
|
@@ -40862,6 +41115,12 @@ var ConnectedDaemonSessionEventState = class extends DaemonSessionEventConnectio
|
|
|
40862
41115
|
var SESSION_EVENT_REPLAY_WINDOW = 16;
|
|
40863
41116
|
var SESSION_EVENT_SOURCE_REPLAY_WINDOW = 4;
|
|
40864
41117
|
var SESSION_EVENT_REPLAY_BYTE_LIMIT = 32 * 1024 * 1024;
|
|
41118
|
+
function reservesSessionEventCapacity(event) {
|
|
41119
|
+
if (event.kind === SESSION_COMPLETED_KIND || event.kind === SESSION_FAILED_KIND) {
|
|
41120
|
+
return true;
|
|
41121
|
+
}
|
|
41122
|
+
return event.kind === AGENT_ACTIVITY_KIND && (event.activityType === "progress" || event.activityType === "reasoning") && (event.status === "completed" || event.status === "failed");
|
|
41123
|
+
}
|
|
40865
41124
|
var InFlightSessionEvent = class {
|
|
40866
41125
|
byteLength;
|
|
40867
41126
|
sourceKey;
|
|
@@ -40877,6 +41136,7 @@ var DaemonSessionEventPublisher = class {
|
|
|
40877
41136
|
#outbox;
|
|
40878
41137
|
#inFlightEvents = /* @__PURE__ */ new Map();
|
|
40879
41138
|
#pausedSources = /* @__PURE__ */ new Map();
|
|
41139
|
+
#shedEventKinds = /* @__PURE__ */ new Set();
|
|
40880
41140
|
#timer;
|
|
40881
41141
|
#inFlightBytes = 0;
|
|
40882
41142
|
#connection = new DisconnectedDaemonSessionEventState();
|
|
@@ -40898,17 +41158,64 @@ var DaemonSessionEventPublisher = class {
|
|
|
40898
41158
|
};
|
|
40899
41159
|
recordAttempt = (sessionId, event, attemptId) => {
|
|
40900
41160
|
const encoded = encodeRecordedSessionEvent(event);
|
|
40901
|
-
if (event
|
|
40902
|
-
this.#
|
|
41161
|
+
if (reservesSessionEventCapacity(event)) {
|
|
41162
|
+
this.#enqueueReserved(sessionId, encoded, attemptId, event.kind);
|
|
40903
41163
|
} else {
|
|
40904
|
-
this.#
|
|
41164
|
+
this.#enqueueStandard(sessionId, encoded, attemptId, event.kind);
|
|
40905
41165
|
}
|
|
40906
41166
|
this.#publishNextBatch();
|
|
40907
41167
|
};
|
|
40908
41168
|
recordRuntime = (sessionId, event) => {
|
|
40909
|
-
this.#
|
|
41169
|
+
this.#enqueueStandard(sessionId, encodeRecordedSessionEvent(event), "", event.kind);
|
|
40910
41170
|
this.#publishNextBatch();
|
|
40911
41171
|
};
|
|
41172
|
+
/**
|
|
41173
|
+
* Enqueue a standard event, shedding it instead of ending the daemon when the
|
|
41174
|
+
* durable outbox is full.
|
|
41175
|
+
*
|
|
41176
|
+
* A capacity error used to escape the coalescing timer that publishes activities,
|
|
41177
|
+
* so the process exited and every restart died on the same retained backlog. A full
|
|
41178
|
+
* outbox is a recoverable runtime condition, not a fatal one: narration increments are
|
|
41179
|
+
* superseded by the completed snapshot, so they are shed first, and any other streaming
|
|
41180
|
+
* event is shed only at the wall rather than terminating the daemon.
|
|
41181
|
+
*/
|
|
41182
|
+
#enqueueStandard = (sessionId, encoded, attemptId, kind) => {
|
|
41183
|
+
if (kind === AGENT_ACTIVITY_NARRATION_KIND && this.#outbox.standardCapacityRemaining() <= 0) {
|
|
41184
|
+
this.#reportShedEvent(kind);
|
|
41185
|
+
return;
|
|
41186
|
+
}
|
|
41187
|
+
try {
|
|
41188
|
+
this.#outbox.enqueue(sessionId, encoded, attemptId);
|
|
41189
|
+
} catch (error62) {
|
|
41190
|
+
if (!(error62 instanceof SessionEventOutboxCapacityError)) {
|
|
41191
|
+
throw error62;
|
|
41192
|
+
}
|
|
41193
|
+
this.#reportShedEvent(kind);
|
|
41194
|
+
}
|
|
41195
|
+
};
|
|
41196
|
+
/**
|
|
41197
|
+
* Enqueue on the reserved budget, degrading to a reported drop instead of raising.
|
|
41198
|
+
* Streaming events are shed before this budget is reached, so a Turn's terminal
|
|
41199
|
+
* events and the completed snapshot that carries its narration still land; a drop
|
|
41200
|
+
* here is the last resort for a backlog no acknowledgement can drain.
|
|
41201
|
+
*/
|
|
41202
|
+
#enqueueReserved = (sessionId, encoded, attemptId, kind) => {
|
|
41203
|
+
try {
|
|
41204
|
+
this.#outbox.enqueueCritical(sessionId, encoded, attemptId);
|
|
41205
|
+
} catch (error62) {
|
|
41206
|
+
if (!(error62 instanceof SessionEventOutboxCapacityError)) {
|
|
41207
|
+
throw error62;
|
|
41208
|
+
}
|
|
41209
|
+
this.#reportShedEvent(kind);
|
|
41210
|
+
}
|
|
41211
|
+
};
|
|
41212
|
+
#reportShedEvent = (kind) => {
|
|
41213
|
+
if (this.#shedEventKinds.has(kind)) {
|
|
41214
|
+
return;
|
|
41215
|
+
}
|
|
41216
|
+
this.#shedEventKinds.add(kind);
|
|
41217
|
+
console.warn(`Mobius daemon is dropping durable "${kind}" events because the Session event outbox is full`);
|
|
41218
|
+
};
|
|
40912
41219
|
acknowledge = (acknowledgement) => {
|
|
40913
41220
|
if (!this.#outbox.acknowledge(acknowledgement)) {
|
|
40914
41221
|
return;
|
|
@@ -41635,6 +41942,26 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
41635
41942
|
const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
|
|
41636
41943
|
publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
|
|
41637
41944
|
});
|
|
41945
|
+
const narration = new CoalescingNarrationPublisher(
|
|
41946
|
+
timer,
|
|
41947
|
+
(increment) => {
|
|
41948
|
+
publisher.recordAttempt(
|
|
41949
|
+
command.sessionId,
|
|
41950
|
+
{
|
|
41951
|
+
activityId: increment.activityId,
|
|
41952
|
+
activityType: increment.activityType,
|
|
41953
|
+
commandId: command.commandId,
|
|
41954
|
+
kind: AGENT_ACTIVITY_NARRATION_KIND,
|
|
41955
|
+
sequence: increment.sequence,
|
|
41956
|
+
sessionId: command.sessionId,
|
|
41957
|
+
text: increment.text
|
|
41958
|
+
},
|
|
41959
|
+
attemptId
|
|
41960
|
+
);
|
|
41961
|
+
},
|
|
41962
|
+
AGENT_ACTIVITY_COALESCING_MILLISECONDS,
|
|
41963
|
+
AGENT_TEXT_MAXIMUM_LENGTH
|
|
41964
|
+
);
|
|
41638
41965
|
const text3 = new CoalescingTextPublisher(
|
|
41639
41966
|
timer,
|
|
41640
41967
|
(messageId, delta) => {
|
|
@@ -41739,6 +42066,10 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
41739
42066
|
disposition: command.disposition,
|
|
41740
42067
|
images: attachments.images,
|
|
41741
42068
|
onActivity: activities.record,
|
|
42069
|
+
onNarration: (increment) => {
|
|
42070
|
+
narration.record(increment);
|
|
42071
|
+
return Promise.resolve();
|
|
42072
|
+
},
|
|
41742
42073
|
onText: (delta, messageId) => {
|
|
41743
42074
|
text3.record(messageId, delta);
|
|
41744
42075
|
return Promise.resolve();
|
|
@@ -41752,6 +42083,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
41752
42083
|
stopReason = result.stopReason;
|
|
41753
42084
|
}
|
|
41754
42085
|
text3.flush();
|
|
42086
|
+
narration.flush();
|
|
41755
42087
|
activities.flush();
|
|
41756
42088
|
publisher.recordAttempt(
|
|
41757
42089
|
command.sessionId,
|
|
@@ -41771,6 +42103,7 @@ async function executePrompt(outbox, publisher, command, config2, directories, a
|
|
|
41771
42103
|
});
|
|
41772
42104
|
} catch (error62) {
|
|
41773
42105
|
text3.flush();
|
|
42106
|
+
narration.flush();
|
|
41774
42107
|
activities.flush();
|
|
41775
42108
|
audit.record({
|
|
41776
42109
|
commandId: command.commandId,
|