@moxt-ai/mobius 0.0.143 → 0.0.145
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/cli.js +351 -132
- package/dist/cli.js.map +3 -3
- package/dist/daemon-active-turn.d.ts +1 -0
- package/dist/daemon-active-turn.d.ts.map +1 -1
- package/dist/daemon-active-turn.js +37 -8
- package/dist/daemon-active-turn.js.map +1 -1
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +1 -0
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/daemon-prompt-executor.d.ts +2 -1
- package/dist/daemon-prompt-executor.d.ts.map +1 -1
- package/dist/daemon-prompt-executor.js +8 -1
- package/dist/daemon-prompt-executor.js.map +1 -1
- package/dist/daemon-turn-registry.d.ts +13 -8
- package/dist/daemon-turn-registry.d.ts.map +1 -1
- package/dist/daemon-turn-registry.js +4 -0
- package/dist/daemon-turn-registry.js.map +1 -1
- package/dist/index.js +350 -131
- package/dist/index.js.map +3 -3
- package/dist/native-sessions/codex-history.d.ts.map +1 -1
- package/dist/native-sessions/codex-history.js +254 -94
- package/dist/native-sessions/codex-history.js.map +1 -1
- package/dist/native-sessions/live-history-page.d.ts.map +1 -1
- package/dist/native-sessions/live-history-page.js +34 -17
- package/dist/native-sessions/live-history-page.js.map +1 -1
- package/dist/runtime.js +350 -131
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -21000,6 +21000,23 @@ var activeTurnActivitySchema = external_exports.strictObject({
|
|
|
21000
21000
|
title: external_exports.string().max(500),
|
|
21001
21001
|
toolKind: external_exports.string().max(64)
|
|
21002
21002
|
}).readonly();
|
|
21003
|
+
var activeTurnUserMessageSchema = external_exports.strictObject({
|
|
21004
|
+
id: identifierStringSchema,
|
|
21005
|
+
images: external_exports.array(promptImageSchema).max(8).readonly().optional(),
|
|
21006
|
+
role: external_exports.literal("user"),
|
|
21007
|
+
text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT)
|
|
21008
|
+
}).readonly();
|
|
21009
|
+
var activeTurnAssistantMessageSchema = external_exports.strictObject({
|
|
21010
|
+
activities: external_exports.array(activeTurnActivitySchema).max(100).readonly().default([]),
|
|
21011
|
+
content: external_exports.array(displayContentSchema).max(100).readonly().default([]),
|
|
21012
|
+
id: identifierStringSchema,
|
|
21013
|
+
role: external_exports.literal("assistant"),
|
|
21014
|
+
text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT)
|
|
21015
|
+
}).readonly();
|
|
21016
|
+
var activeTurnMessageSchema = external_exports.discriminatedUnion("role", [
|
|
21017
|
+
activeTurnUserMessageSchema,
|
|
21018
|
+
activeTurnAssistantMessageSchema
|
|
21019
|
+
]);
|
|
21003
21020
|
var activeTurnSnapshotSchema = external_exports.strictObject({
|
|
21004
21021
|
activities: external_exports.array(activeTurnActivitySchema).readonly(),
|
|
21005
21022
|
commandId: identifierStringSchema,
|
|
@@ -21009,7 +21026,7 @@ var activeTurnSnapshotSchema = external_exports.strictObject({
|
|
|
21009
21026
|
truncated: external_exports.boolean(),
|
|
21010
21027
|
epoch: identifierStringSchema,
|
|
21011
21028
|
interaction: external_exports.discriminatedUnion("kind", [sessionPermissionRequestedEventSchema, sessionElicitationRequestedEventSchema]).nullable(),
|
|
21012
|
-
messages: external_exports.array(
|
|
21029
|
+
messages: external_exports.array(activeTurnMessageSchema).max(SESSION_HISTORY_MESSAGE_LIMIT).readonly(),
|
|
21013
21030
|
sequence: external_exports.number().int().nonnegative(),
|
|
21014
21031
|
state: external_exports.literal("running")
|
|
21015
21032
|
}).readonly();
|
|
@@ -37780,7 +37797,7 @@ var ActiveDaemonTurn = class {
|
|
|
37780
37797
|
#text = "";
|
|
37781
37798
|
#activities = /* @__PURE__ */ new Map();
|
|
37782
37799
|
#content = /* @__PURE__ */ new Map();
|
|
37783
|
-
#timeline
|
|
37800
|
+
#timeline;
|
|
37784
37801
|
#sequence = 0;
|
|
37785
37802
|
#interaction = null;
|
|
37786
37803
|
#epoch = decodeIdentifier(randomUUID());
|
|
@@ -37789,6 +37806,9 @@ var ActiveDaemonTurn = class {
|
|
|
37789
37806
|
this.command = command;
|
|
37790
37807
|
this.#controller = new AbortController();
|
|
37791
37808
|
this.#dispatch = { kind: "pending" };
|
|
37809
|
+
this.#timeline = [
|
|
37810
|
+
{ id: decodeIdentifier(command.commandId), images: command.images, kind: "user", text: command.prompt }
|
|
37811
|
+
];
|
|
37792
37812
|
}
|
|
37793
37813
|
enqueue = () => {
|
|
37794
37814
|
if (this.#dispatch.kind !== "pending") {
|
|
@@ -37832,7 +37852,10 @@ var ActiveDaemonTurn = class {
|
|
|
37832
37852
|
}
|
|
37833
37853
|
if (event.kind === AGENT_ACTIVITY_KIND) {
|
|
37834
37854
|
if (!this.#activities.has(event.activityId)) {
|
|
37835
|
-
this.#timeline = [
|
|
37855
|
+
this.#timeline = [
|
|
37856
|
+
...this.#timeline,
|
|
37857
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID()), kind: "activity" }
|
|
37858
|
+
];
|
|
37836
37859
|
}
|
|
37837
37860
|
this.#activities.set(event.activityId, {
|
|
37838
37861
|
activityId: event.activityId,
|
|
@@ -37850,7 +37873,10 @@ var ActiveDaemonTurn = class {
|
|
|
37850
37873
|
} else if (event.kind === AGENT_ACTIVITY_NARRATION_KIND) {
|
|
37851
37874
|
const previous = this.#activities.get(event.activityId);
|
|
37852
37875
|
if (previous === void 0) {
|
|
37853
|
-
this.#timeline = [
|
|
37876
|
+
this.#timeline = [
|
|
37877
|
+
...this.#timeline,
|
|
37878
|
+
{ activityId: event.activityId, id: decodeIdentifier(randomUUID()), kind: "activity" }
|
|
37879
|
+
];
|
|
37854
37880
|
}
|
|
37855
37881
|
this.#activities.set(event.activityId, {
|
|
37856
37882
|
activityId: event.activityId,
|
|
@@ -37868,15 +37894,16 @@ var ActiveDaemonTurn = class {
|
|
|
37868
37894
|
} else if (event.kind === AGENT_CONTENT_KIND) {
|
|
37869
37895
|
this.#content.set(event.contentId, event.content);
|
|
37870
37896
|
const target = this.#timeline.findLastIndex(
|
|
37871
|
-
(entry) => entry.kind === "message" && entry.
|
|
37897
|
+
(entry) => entry.kind === "message" && entry.sourceMessageId === event.messageId
|
|
37872
37898
|
);
|
|
37873
37899
|
if (target < 0) {
|
|
37874
37900
|
this.#timeline = [
|
|
37875
37901
|
...this.#timeline,
|
|
37876
37902
|
{
|
|
37877
37903
|
content: /* @__PURE__ */ new Map([[event.contentId, event.content]]),
|
|
37904
|
+
id: decodeIdentifier(randomUUID()),
|
|
37878
37905
|
kind: "message",
|
|
37879
|
-
|
|
37906
|
+
sourceMessageId: event.messageId,
|
|
37880
37907
|
text: ""
|
|
37881
37908
|
}
|
|
37882
37909
|
];
|
|
@@ -37899,7 +37926,7 @@ var ActiveDaemonTurn = class {
|
|
|
37899
37926
|
let remaining = text2;
|
|
37900
37927
|
while (remaining.length > 0) {
|
|
37901
37928
|
const latest = this.#timeline.at(-1);
|
|
37902
|
-
if (latest?.kind === "message" && latest.
|
|
37929
|
+
if (latest?.kind === "message" && latest.sourceMessageId === messageId) {
|
|
37903
37930
|
const available = SESSION_HISTORY_CHARACTER_LIMIT - latest.text.length;
|
|
37904
37931
|
if (available > 0) {
|
|
37905
37932
|
this.#timeline = [
|
|
@@ -37914,28 +37941,43 @@ var ActiveDaemonTurn = class {
|
|
|
37914
37941
|
...this.#timeline,
|
|
37915
37942
|
{
|
|
37916
37943
|
content: /* @__PURE__ */ new Map(),
|
|
37944
|
+
id: decodeIdentifier(randomUUID()),
|
|
37917
37945
|
kind: "message",
|
|
37918
|
-
messageId,
|
|
37946
|
+
sourceMessageId: messageId,
|
|
37919
37947
|
text: remaining.slice(0, SESSION_HISTORY_CHARACTER_LIMIT)
|
|
37920
37948
|
}
|
|
37921
37949
|
];
|
|
37922
37950
|
remaining = remaining.slice(SESSION_HISTORY_CHARACTER_LIMIT);
|
|
37923
37951
|
}
|
|
37924
37952
|
}
|
|
37953
|
+
recordSteeringPrompt = (command) => {
|
|
37954
|
+
if (this.#dispatch.kind !== "running" || command.sessionId !== this.command.sessionId || command.targetCommandId !== this.command.commandId) {
|
|
37955
|
+
return null;
|
|
37956
|
+
}
|
|
37957
|
+
this.#timeline = [
|
|
37958
|
+
...this.#timeline,
|
|
37959
|
+
{ id: decodeIdentifier(command.commandId), images: command.images, kind: "user", text: command.prompt }
|
|
37960
|
+
];
|
|
37961
|
+
return this.updated();
|
|
37962
|
+
};
|
|
37925
37963
|
timelineMessages() {
|
|
37926
37964
|
return this.#timeline.flatMap((entry) => {
|
|
37965
|
+
if (entry.kind === "user") {
|
|
37966
|
+
return [{ id: entry.id, images: entry.images, role: "user", text: entry.text }];
|
|
37967
|
+
}
|
|
37927
37968
|
if (entry.kind === "message") {
|
|
37928
37969
|
return [
|
|
37929
37970
|
{
|
|
37930
37971
|
activities: [],
|
|
37931
37972
|
content: [...entry.content.values()],
|
|
37973
|
+
id: entry.id,
|
|
37932
37974
|
role: "assistant",
|
|
37933
37975
|
text: entry.text
|
|
37934
37976
|
}
|
|
37935
37977
|
];
|
|
37936
37978
|
}
|
|
37937
37979
|
const activity2 = this.#activities.get(entry.activityId);
|
|
37938
|
-
return activity2 === void 0 ? [] : [{ activities: [activity2], content: [], role: "assistant", text: "" }];
|
|
37980
|
+
return activity2 === void 0 ? [] : [{ activities: [activity2], content: [], id: entry.id, role: "assistant", text: "" }];
|
|
37939
37981
|
});
|
|
37940
37982
|
}
|
|
37941
37983
|
updated = () => {
|
|
@@ -38045,6 +38087,10 @@ var DaemonTurnRegistry = class {
|
|
|
38045
38087
|
}
|
|
38046
38088
|
return event;
|
|
38047
38089
|
};
|
|
38090
|
+
recordSteeringPrompt = (command) => {
|
|
38091
|
+
const target = this.#turns.get(command.targetCommandId);
|
|
38092
|
+
return target?.recordSteeringPrompt(command) ?? null;
|
|
38093
|
+
};
|
|
38048
38094
|
executionSnapshot = async (matches) => {
|
|
38049
38095
|
const matching = [];
|
|
38050
38096
|
for (const turn of this.#turns.values()) {
|
|
@@ -38151,15 +38197,21 @@ var turnsSchema = external_exports.object({
|
|
|
38151
38197
|
});
|
|
38152
38198
|
var itemTypeSchema = external_exports.object({ type: external_exports.string().min(1).max(80) });
|
|
38153
38199
|
var userMessageSchema = external_exports.object({
|
|
38154
|
-
content: external_exports.array(external_exports.unknown()).max(1e4)
|
|
38200
|
+
content: external_exports.array(external_exports.unknown()).max(1e4),
|
|
38201
|
+
type: external_exports.literal("userMessage")
|
|
38155
38202
|
});
|
|
38156
38203
|
var textSchema = external_exports.object({ text: external_exports.string() });
|
|
38157
38204
|
var imageSchema = external_exports.object({ url: external_exports.string() });
|
|
38158
|
-
var agentMessageSchema = textSchema.extend({
|
|
38205
|
+
var agentMessageSchema = textSchema.extend({
|
|
38206
|
+
id: external_exports.string().optional(),
|
|
38207
|
+
phase: external_exports.string().nullish(),
|
|
38208
|
+
type: external_exports.literal("agentMessage")
|
|
38209
|
+
});
|
|
38159
38210
|
var reasoningSchema = external_exports.object({
|
|
38160
38211
|
id: external_exports.string(),
|
|
38161
38212
|
summary: external_exports.array(external_exports.string()).max(1e4),
|
|
38162
|
-
content: external_exports.array(external_exports.string()).max(1e4)
|
|
38213
|
+
content: external_exports.array(external_exports.string()).max(1e4),
|
|
38214
|
+
type: external_exports.literal("reasoning")
|
|
38163
38215
|
});
|
|
38164
38216
|
var commandExecutionSchema = external_exports.object({
|
|
38165
38217
|
id: external_exports.string(),
|
|
@@ -38168,8 +38220,45 @@ var commandExecutionSchema = external_exports.object({
|
|
|
38168
38220
|
status: external_exports.string(),
|
|
38169
38221
|
commandActions: external_exports.array(external_exports.object({ type: external_exports.string() }).passthrough()).max(100),
|
|
38170
38222
|
aggregatedOutput: external_exports.string().nullish(),
|
|
38171
|
-
exitCode: external_exports.number().int().nullish()
|
|
38223
|
+
exitCode: external_exports.number().int().nullish(),
|
|
38224
|
+
type: external_exports.literal("commandExecution")
|
|
38172
38225
|
});
|
|
38226
|
+
var fileChangeSchema = external_exports.object({
|
|
38227
|
+
changes: external_exports.array(external_exports.object({ diff: external_exports.string(), path: external_exports.string() })).max(1e4),
|
|
38228
|
+
id: external_exports.string(),
|
|
38229
|
+
status: external_exports.string(),
|
|
38230
|
+
type: external_exports.literal("fileChange")
|
|
38231
|
+
});
|
|
38232
|
+
var mcpToolCallSchema = external_exports.object({
|
|
38233
|
+
arguments: external_exports.unknown().optional(),
|
|
38234
|
+
error: external_exports.unknown().nullish(),
|
|
38235
|
+
id: external_exports.string(),
|
|
38236
|
+
result: external_exports.unknown().nullish(),
|
|
38237
|
+
server: external_exports.string(),
|
|
38238
|
+
status: external_exports.string(),
|
|
38239
|
+
tool: external_exports.string(),
|
|
38240
|
+
type: external_exports.literal("mcpToolCall")
|
|
38241
|
+
});
|
|
38242
|
+
var dynamicToolCallSchema = external_exports.object({
|
|
38243
|
+
arguments: external_exports.unknown().optional(),
|
|
38244
|
+
contentItems: external_exports.array(external_exports.unknown()).max(1e4).nullish(),
|
|
38245
|
+
id: external_exports.string(),
|
|
38246
|
+
namespace: external_exports.string().nullish(),
|
|
38247
|
+
status: external_exports.string(),
|
|
38248
|
+
tool: external_exports.string(),
|
|
38249
|
+
type: external_exports.literal("dynamicToolCall")
|
|
38250
|
+
});
|
|
38251
|
+
var planSchema = external_exports.object({ id: external_exports.string(), text: external_exports.string(), type: external_exports.literal("plan") });
|
|
38252
|
+
var historyItemSchema = external_exports.discriminatedUnion("type", [
|
|
38253
|
+
userMessageSchema,
|
|
38254
|
+
agentMessageSchema,
|
|
38255
|
+
reasoningSchema,
|
|
38256
|
+
commandExecutionSchema,
|
|
38257
|
+
fileChangeSchema,
|
|
38258
|
+
mcpToolCallSchema,
|
|
38259
|
+
dynamicToolCallSchema,
|
|
38260
|
+
planSchema
|
|
38261
|
+
]);
|
|
38173
38262
|
function bounded(value, maximum) {
|
|
38174
38263
|
return value.slice(0, maximum);
|
|
38175
38264
|
}
|
|
@@ -38200,6 +38289,33 @@ function errorMessage(value) {
|
|
|
38200
38289
|
}
|
|
38201
38290
|
return JSON.stringify(value) ?? "Codex stopped before completing this turn.";
|
|
38202
38291
|
}
|
|
38292
|
+
function formatted(value) {
|
|
38293
|
+
if (value === void 0) {
|
|
38294
|
+
return "";
|
|
38295
|
+
}
|
|
38296
|
+
if (typeof value === "string") {
|
|
38297
|
+
return value;
|
|
38298
|
+
}
|
|
38299
|
+
return JSON.stringify(value) ?? "";
|
|
38300
|
+
}
|
|
38301
|
+
function toolStatus(status) {
|
|
38302
|
+
return status === "inProgress" ? "running" : status === "completed" ? "completed" : "failed";
|
|
38303
|
+
}
|
|
38304
|
+
function diffDisplayContent(path2, newText) {
|
|
38305
|
+
return {
|
|
38306
|
+
artifactId: "",
|
|
38307
|
+
data: "",
|
|
38308
|
+
mimeType: "",
|
|
38309
|
+
name: "",
|
|
38310
|
+
newText,
|
|
38311
|
+
oldText: "",
|
|
38312
|
+
path: path2,
|
|
38313
|
+
terminalId: "",
|
|
38314
|
+
text: "",
|
|
38315
|
+
type: "diff",
|
|
38316
|
+
uri: ""
|
|
38317
|
+
};
|
|
38318
|
+
}
|
|
38203
38319
|
function messageSize(message) {
|
|
38204
38320
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
38205
38321
|
}
|
|
@@ -38237,8 +38353,8 @@ function fitActivities(activities, maximumCharacters) {
|
|
|
38237
38353
|
const maximumActivityCharacters = Math.floor(Math.max(0, maximumCharacters - arrayCharacters) / activities.length);
|
|
38238
38354
|
return activities.map((activity2) => fitActivity(activity2, maximumActivityCharacters));
|
|
38239
38355
|
}
|
|
38240
|
-
function fitHistoryMessage(message) {
|
|
38241
|
-
const text2 = message.text.slice(-
|
|
38356
|
+
function fitHistoryMessage(message, maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT) {
|
|
38357
|
+
const text2 = message.text.slice(-maximumCharacters);
|
|
38242
38358
|
if (message.role === "user") {
|
|
38243
38359
|
return {
|
|
38244
38360
|
message: { ...message, text: text2 },
|
|
@@ -38248,12 +38364,12 @@ function fitHistoryMessage(message) {
|
|
|
38248
38364
|
let activities = message.activities;
|
|
38249
38365
|
const content = message.content;
|
|
38250
38366
|
let fitted = { ...message, activities, content, text: text2 };
|
|
38251
|
-
if (messageSize(fitted) >
|
|
38252
|
-
const
|
|
38253
|
-
activities = fitActivities(activities,
|
|
38367
|
+
if (messageSize(fitted) > maximumCharacters && activities.length > 0) {
|
|
38368
|
+
const maximumActivityCharacters = maximumCharacters - text2.length - JSON.stringify(content).length;
|
|
38369
|
+
activities = fitActivities(activities, maximumActivityCharacters);
|
|
38254
38370
|
fitted = { ...fitted, activities };
|
|
38255
38371
|
}
|
|
38256
|
-
const excess = Math.max(0, messageSize(fitted) -
|
|
38372
|
+
const excess = Math.max(0, messageSize(fitted) - maximumCharacters);
|
|
38257
38373
|
if (excess > 0) {
|
|
38258
38374
|
const maximumTextLength = Math.max(0, fitted.text.length - excess);
|
|
38259
38375
|
fitted = {
|
|
@@ -38291,128 +38407,209 @@ function decodeHistory(thread, value, options) {
|
|
|
38291
38407
|
let truncated = page.nextCursor != null;
|
|
38292
38408
|
for (const turn of page.data.toReversed()) {
|
|
38293
38409
|
const outcome = turnOutcome(turn.status);
|
|
38294
|
-
const
|
|
38295
|
-
|
|
38410
|
+
const turnMessageCharacterLimit = Math.max(
|
|
38411
|
+
1,
|
|
38412
|
+
Math.floor(SESSION_HISTORY_CHARACTER_LIMIT / Math.max(1, turn.items.length + (turn.error == null ? 0 : 1)))
|
|
38413
|
+
);
|
|
38296
38414
|
let sequence = 0;
|
|
38297
38415
|
let assistantMessageIndex = null;
|
|
38298
|
-
const
|
|
38299
|
-
const
|
|
38300
|
-
|
|
38301
|
-
|
|
38416
|
+
const append = (message) => {
|
|
38417
|
+
const fitted = fitHistoryMessage(message, turnMessageCharacterLimit);
|
|
38418
|
+
if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0 && (fitted.message.role === "user" || fitted.message.activities.length === 0 && fitted.message.content.length === 0)) {
|
|
38419
|
+
return;
|
|
38420
|
+
}
|
|
38421
|
+
truncated ||= fitted.truncated;
|
|
38422
|
+
messages.push(fitted.message);
|
|
38423
|
+
if (fitted.message.role === "assistant") {
|
|
38424
|
+
assistantMessageIndex = messages.length - 1;
|
|
38425
|
+
}
|
|
38426
|
+
characters += messageSize(fitted.message);
|
|
38302
38427
|
};
|
|
38303
38428
|
for (const item of turn.items) {
|
|
38304
|
-
const
|
|
38305
|
-
|
|
38306
|
-
|
|
38307
|
-
|
|
38308
|
-
|
|
38309
|
-
|
|
38310
|
-
|
|
38429
|
+
const decoded = historyItemSchema.safeParse(item);
|
|
38430
|
+
if (!decoded.success) {
|
|
38431
|
+
continue;
|
|
38432
|
+
}
|
|
38433
|
+
const historyItem = decoded.data;
|
|
38434
|
+
if (historyItem.type === "userMessage") {
|
|
38435
|
+
const text2 = historyItem.content.map((block) => {
|
|
38436
|
+
const { type } = itemTypeSchema.parse(block);
|
|
38437
|
+
if (type === "text") {
|
|
38311
38438
|
return textSchema.parse(block).text;
|
|
38312
38439
|
}
|
|
38313
|
-
if (
|
|
38440
|
+
if (type === "image") {
|
|
38314
38441
|
return `[@image](${imageSchema.parse(block).url})`;
|
|
38315
38442
|
}
|
|
38316
38443
|
return "[Attachment]";
|
|
38317
38444
|
}).join("");
|
|
38318
|
-
|
|
38445
|
+
append({
|
|
38319
38446
|
role: "user",
|
|
38320
38447
|
text: text2
|
|
38321
|
-
};
|
|
38322
|
-
} else if (type === "agentMessage") {
|
|
38323
|
-
|
|
38324
|
-
|
|
38325
|
-
|
|
38326
|
-
|
|
38327
|
-
|
|
38448
|
+
});
|
|
38449
|
+
} else if (historyItem.type === "agentMessage") {
|
|
38450
|
+
if (historyItem.phase === "commentary") {
|
|
38451
|
+
if (options.detail === "rich" && historyItem.text.length > 0) {
|
|
38452
|
+
append({
|
|
38453
|
+
activities: [
|
|
38454
|
+
activity(historyItem.id ?? `progress-${sequence.toString()}`, "progress", sequence, {
|
|
38455
|
+
input: "",
|
|
38456
|
+
locations: [],
|
|
38457
|
+
name: "",
|
|
38458
|
+
output: historyItem.text,
|
|
38459
|
+
status: "completed",
|
|
38460
|
+
title: "Progress",
|
|
38461
|
+
toolKind: ""
|
|
38462
|
+
})
|
|
38463
|
+
],
|
|
38464
|
+
content: [],
|
|
38465
|
+
role: "assistant",
|
|
38466
|
+
text: ""
|
|
38467
|
+
});
|
|
38468
|
+
sequence += 1;
|
|
38469
|
+
}
|
|
38470
|
+
continue;
|
|
38471
|
+
}
|
|
38472
|
+
append({ activities: [], content: [], role: "assistant", text: historyItem.text });
|
|
38473
|
+
} else if (historyItem.type === "reasoning" && options.detail === "rich") {
|
|
38474
|
+
const output2 = (historyItem.summary.length > 0 ? historyItem.summary : historyItem.content).join(
|
|
38475
|
+
"\n\n"
|
|
38476
|
+
);
|
|
38477
|
+
if (output2.length > 0) {
|
|
38478
|
+
append({
|
|
38479
|
+
activities: [
|
|
38480
|
+
activity(historyItem.id, "reasoning", sequence, {
|
|
38328
38481
|
input: "",
|
|
38329
38482
|
locations: [],
|
|
38330
38483
|
name: "",
|
|
38331
|
-
output:
|
|
38484
|
+
output: output2,
|
|
38332
38485
|
status: "completed",
|
|
38333
|
-
title: "
|
|
38486
|
+
title: "Reasoning",
|
|
38334
38487
|
toolKind: ""
|
|
38335
38488
|
})
|
|
38336
|
-
|
|
38337
|
-
|
|
38338
|
-
|
|
38339
|
-
|
|
38489
|
+
],
|
|
38490
|
+
content: [],
|
|
38491
|
+
role: "assistant",
|
|
38492
|
+
text: ""
|
|
38493
|
+
});
|
|
38494
|
+
sequence += 1;
|
|
38340
38495
|
}
|
|
38341
|
-
|
|
38342
|
-
|
|
38343
|
-
|
|
38344
|
-
|
|
38345
|
-
|
|
38346
|
-
|
|
38347
|
-
|
|
38496
|
+
} else if (historyItem.type === "commandExecution" && options.detail === "rich") {
|
|
38497
|
+
const action = historyItem.commandActions[0]?.type ?? "execute";
|
|
38498
|
+
append({
|
|
38499
|
+
activities: [
|
|
38500
|
+
activity(historyItem.id, "tool", sequence, {
|
|
38501
|
+
input: JSON.stringify({ command: historyItem.command, cwd: historyItem.cwd }),
|
|
38502
|
+
locations: [historyItem.cwd],
|
|
38503
|
+
name: "",
|
|
38504
|
+
output: JSON.stringify({
|
|
38505
|
+
formatted_output: historyItem.aggregatedOutput ?? "",
|
|
38506
|
+
...historyItem.exitCode == null ? {} : { exit_code: historyItem.exitCode }
|
|
38507
|
+
}),
|
|
38508
|
+
status: toolStatus(historyItem.status),
|
|
38509
|
+
title: historyItem.command,
|
|
38510
|
+
toolKind: action
|
|
38511
|
+
})
|
|
38512
|
+
],
|
|
38513
|
+
content: [],
|
|
38514
|
+
role: "assistant",
|
|
38515
|
+
text: ""
|
|
38516
|
+
});
|
|
38517
|
+
sequence += 1;
|
|
38518
|
+
} else if (historyItem.type === "fileChange" && options.detail === "rich") {
|
|
38519
|
+
const paths = historyItem.changes.map((change) => change.path);
|
|
38520
|
+
const content = historyItem.changes.map(
|
|
38521
|
+
(change) => diffDisplayContent(change.path, change.diff)
|
|
38522
|
+
);
|
|
38523
|
+
append({
|
|
38524
|
+
activities: [
|
|
38525
|
+
activity(historyItem.id, "tool", sequence, {
|
|
38526
|
+
input: JSON.stringify({ changes: paths }),
|
|
38527
|
+
locations: paths,
|
|
38528
|
+
name: "",
|
|
38529
|
+
output: "",
|
|
38530
|
+
status: toolStatus(historyItem.status),
|
|
38531
|
+
title: paths.join(", "),
|
|
38532
|
+
toolKind: "edit"
|
|
38533
|
+
})
|
|
38534
|
+
].map((entry) => ({ ...entry, content })),
|
|
38535
|
+
content: [],
|
|
38536
|
+
role: "assistant",
|
|
38537
|
+
text: ""
|
|
38538
|
+
});
|
|
38539
|
+
sequence += 1;
|
|
38540
|
+
} else if (historyItem.type === "mcpToolCall" && options.detail === "rich") {
|
|
38541
|
+
append({
|
|
38542
|
+
activities: [
|
|
38543
|
+
activity(historyItem.id, "tool", sequence, {
|
|
38544
|
+
input: formatted(historyItem.arguments),
|
|
38545
|
+
locations: [],
|
|
38546
|
+
name: historyItem.tool,
|
|
38547
|
+
output: formatted(historyItem.error ?? historyItem.result),
|
|
38548
|
+
status: toolStatus(historyItem.status),
|
|
38549
|
+
title: `${historyItem.server}/${historyItem.tool}`,
|
|
38550
|
+
toolKind: "other"
|
|
38551
|
+
})
|
|
38552
|
+
],
|
|
38553
|
+
content: [],
|
|
38554
|
+
role: "assistant",
|
|
38555
|
+
text: ""
|
|
38556
|
+
});
|
|
38557
|
+
sequence += 1;
|
|
38558
|
+
} else if (historyItem.type === "dynamicToolCall" && options.detail === "rich") {
|
|
38559
|
+
append({
|
|
38560
|
+
activities: [
|
|
38561
|
+
activity(historyItem.id, "tool", sequence, {
|
|
38562
|
+
input: formatted(historyItem.arguments),
|
|
38563
|
+
locations: [],
|
|
38564
|
+
name: historyItem.tool,
|
|
38565
|
+
output: formatted(historyItem.contentItems),
|
|
38566
|
+
status: toolStatus(historyItem.status),
|
|
38567
|
+
title: historyItem.namespace == null ? historyItem.tool : `${historyItem.namespace}/${historyItem.tool}`,
|
|
38568
|
+
toolKind: "other"
|
|
38569
|
+
})
|
|
38570
|
+
],
|
|
38571
|
+
content: [],
|
|
38572
|
+
role: "assistant",
|
|
38573
|
+
text: ""
|
|
38574
|
+
});
|
|
38575
|
+
sequence += 1;
|
|
38576
|
+
} else if (historyItem.type === "plan" && options.detail === "rich") {
|
|
38577
|
+
append({
|
|
38578
|
+
activities: [
|
|
38579
|
+
activity(historyItem.id, "plan", sequence, {
|
|
38348
38580
|
input: "",
|
|
38349
38581
|
locations: [],
|
|
38350
38582
|
name: "",
|
|
38351
|
-
output:
|
|
38583
|
+
output: historyItem.text,
|
|
38352
38584
|
status: "completed",
|
|
38353
|
-
title: "
|
|
38585
|
+
title: "Plan",
|
|
38354
38586
|
toolKind: ""
|
|
38355
38587
|
})
|
|
38356
|
-
|
|
38357
|
-
|
|
38358
|
-
|
|
38359
|
-
|
|
38360
|
-
|
|
38361
|
-
const command = commandExecutionSchema.parse(item);
|
|
38362
|
-
const action = command.commandActions[0]?.type ?? "execute";
|
|
38363
|
-
activities.push(
|
|
38364
|
-
activity(command.id, "tool", sequence, {
|
|
38365
|
-
input: JSON.stringify({ command: command.command, cwd: command.cwd }),
|
|
38366
|
-
locations: [command.cwd],
|
|
38367
|
-
name: "",
|
|
38368
|
-
output: JSON.stringify({
|
|
38369
|
-
formatted_output: command.aggregatedOutput ?? "",
|
|
38370
|
-
...command.exitCode == null ? {} : { exit_code: command.exitCode }
|
|
38371
|
-
}),
|
|
38372
|
-
status: command.status === "completed" ? "completed" : "failed",
|
|
38373
|
-
title: command.command,
|
|
38374
|
-
toolKind: action
|
|
38375
|
-
})
|
|
38376
|
-
);
|
|
38588
|
+
],
|
|
38589
|
+
content: [],
|
|
38590
|
+
role: "assistant",
|
|
38591
|
+
text: ""
|
|
38592
|
+
});
|
|
38377
38593
|
sequence += 1;
|
|
38378
|
-
continue;
|
|
38379
|
-
} else {
|
|
38380
|
-
continue;
|
|
38381
38594
|
}
|
|
38382
|
-
const fitted = fitHistoryMessage(message);
|
|
38383
|
-
if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0) {
|
|
38384
|
-
continue;
|
|
38385
|
-
}
|
|
38386
|
-
truncated ||= fitted.truncated;
|
|
38387
|
-
messages.push(fitted.message);
|
|
38388
|
-
if (message.role === "assistant") {
|
|
38389
|
-
assistantMessageIndex = messages.length - 1;
|
|
38390
|
-
}
|
|
38391
|
-
characters += messageSize(fitted.message);
|
|
38392
38595
|
}
|
|
38393
38596
|
if (options.detail === "rich" && turn.error != null) {
|
|
38394
|
-
|
|
38395
|
-
|
|
38396
|
-
|
|
38397
|
-
|
|
38398
|
-
|
|
38399
|
-
|
|
38400
|
-
|
|
38401
|
-
|
|
38402
|
-
|
|
38403
|
-
|
|
38404
|
-
|
|
38405
|
-
|
|
38406
|
-
if (options.detail === "rich" && activities.length > assignedActivityCount) {
|
|
38407
|
-
const message = {
|
|
38408
|
-
activities: activitySlice(),
|
|
38597
|
+
append({
|
|
38598
|
+
activities: [
|
|
38599
|
+
activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
|
|
38600
|
+
input: "",
|
|
38601
|
+
locations: [],
|
|
38602
|
+
name: "",
|
|
38603
|
+
output: errorMessage(turn.error),
|
|
38604
|
+
status: "failed",
|
|
38605
|
+
title: "Agent error",
|
|
38606
|
+
toolKind: "other"
|
|
38607
|
+
})
|
|
38608
|
+
],
|
|
38409
38609
|
content: [],
|
|
38410
38610
|
role: "assistant",
|
|
38411
38611
|
text: ""
|
|
38412
|
-
};
|
|
38413
|
-
messages.push(message);
|
|
38414
|
-
assistantMessageIndex = messages.length - 1;
|
|
38415
|
-
characters += messageSize(message);
|
|
38612
|
+
});
|
|
38416
38613
|
}
|
|
38417
38614
|
if (assistantMessageIndex !== null) {
|
|
38418
38615
|
const assistant = messages[assistantMessageIndex];
|
|
@@ -38422,20 +38619,20 @@ function decodeHistory(thread, value, options) {
|
|
|
38422
38619
|
...assistant,
|
|
38423
38620
|
...outcome === void 0 ? {} : { outcome }
|
|
38424
38621
|
};
|
|
38425
|
-
const fitted = fitHistoryMessage(updated);
|
|
38622
|
+
const fitted = fitHistoryMessage(updated, turnMessageCharacterLimit);
|
|
38426
38623
|
truncated ||= fitted.truncated;
|
|
38427
38624
|
messages[assistantMessageIndex] = fitted.message;
|
|
38428
38625
|
characters += messageSize(fitted.message);
|
|
38429
38626
|
}
|
|
38430
|
-
} else if (
|
|
38627
|
+
} else if (outcome !== void 0) {
|
|
38431
38628
|
const message = {
|
|
38432
|
-
activities:
|
|
38629
|
+
activities: [],
|
|
38433
38630
|
content: [],
|
|
38434
38631
|
role: "assistant",
|
|
38435
38632
|
...outcome === void 0 ? {} : { outcome },
|
|
38436
38633
|
text: ""
|
|
38437
38634
|
};
|
|
38438
|
-
const fitted = fitHistoryMessage(message);
|
|
38635
|
+
const fitted = fitHistoryMessage(message, turnMessageCharacterLimit);
|
|
38439
38636
|
truncated ||= fitted.truncated;
|
|
38440
38637
|
messages.push(fitted.message);
|
|
38441
38638
|
characters += messageSize(fitted.message);
|
|
@@ -40303,6 +40500,14 @@ function boundedActiveMessages(messages, messageLimit, characterLimit) {
|
|
|
40303
40500
|
truncated: selected.length !== messages.length
|
|
40304
40501
|
};
|
|
40305
40502
|
}
|
|
40503
|
+
function nativeActiveMessage(message) {
|
|
40504
|
+
return message.role === "user" ? { role: "user", text: message.text } : {
|
|
40505
|
+
activities: message.activities,
|
|
40506
|
+
content: message.content,
|
|
40507
|
+
role: "assistant",
|
|
40508
|
+
text: message.text
|
|
40509
|
+
};
|
|
40510
|
+
}
|
|
40306
40511
|
function paginateAcpSessionHistory(history, sessionId, cursor, limit) {
|
|
40307
40512
|
if (history.status === "unavailable") {
|
|
40308
40513
|
if (cursor !== null) {
|
|
@@ -40335,20 +40540,27 @@ function paginateLiveSessionHistory(history, activeTurn, sessionId, cursor, limi
|
|
|
40335
40540
|
}
|
|
40336
40541
|
if (history.status === "unavailable") {
|
|
40337
40542
|
const bounded3 = boundedActiveMessages(
|
|
40338
|
-
activeTurn.messages,
|
|
40339
|
-
|
|
40340
|
-
|
|
40543
|
+
activeTurn.messages.map(nativeActiveMessage),
|
|
40544
|
+
limit,
|
|
40545
|
+
SESSION_HISTORY_CHARACTER_LIMIT
|
|
40341
40546
|
);
|
|
40342
40547
|
return {
|
|
40343
40548
|
coveredCommandIds: [],
|
|
40344
40549
|
coveredMessageIds: [],
|
|
40345
|
-
messages:
|
|
40550
|
+
messages: bounded3.messages,
|
|
40346
40551
|
nextCursor: null,
|
|
40347
40552
|
status: "available",
|
|
40348
40553
|
truncated: activeTurn.truncated || bounded3.truncated
|
|
40349
40554
|
};
|
|
40350
40555
|
}
|
|
40351
|
-
const
|
|
40556
|
+
const activeRoot = activeTurn.messages.find(
|
|
40557
|
+
(message) => message.role === "user" && message.id === activeTurn.commandId
|
|
40558
|
+
);
|
|
40559
|
+
const coveredActiveRoot = history.coveredCommandIds.includes(activeTurn.commandId);
|
|
40560
|
+
const matchingActiveUserIndex = coveredActiveRoot ? history.messages.findLastIndex(
|
|
40561
|
+
(message) => message.role === "user" && message.text === (activeRoot?.text ?? activeTurn.prompt)
|
|
40562
|
+
) : -1;
|
|
40563
|
+
const activeUserIndex = matchingActiveUserIndex >= 0 ? matchingActiveUserIndex : liveHistoryCoveredTurnRanges(history).find((range) => range.commandId === activeTurn.commandId)?.userIndex ?? -1;
|
|
40352
40564
|
if (activeUserIndex >= 0) {
|
|
40353
40565
|
history = {
|
|
40354
40566
|
...history,
|
|
@@ -40360,19 +40572,13 @@ function paginateLiveSessionHistory(history, activeTurn, sessionId, cursor, limi
|
|
|
40360
40572
|
};
|
|
40361
40573
|
}
|
|
40362
40574
|
const latestNativeMessage = history.messages.at(-1);
|
|
40363
|
-
const
|
|
40364
|
-
const
|
|
40365
|
-
|
|
40366
|
-
|
|
40367
|
-
Math.max(0, SESSION_HISTORY_CHARACTER_LIMIT - (includeActivePrompt ? activeTurn.prompt.length : 0))
|
|
40368
|
-
);
|
|
40369
|
-
const activeMessages = [
|
|
40370
|
-
...includeActivePrompt ? [{ role: "user", text: activeTurn.prompt }] : [],
|
|
40371
|
-
...bounded2.messages
|
|
40372
|
-
];
|
|
40575
|
+
const firstActiveMessage = activeTurn.messages[0];
|
|
40576
|
+
const preserveNativeRoot = activeUserIndex >= 0 || firstActiveMessage?.role === "user" && latestNativeMessage?.role === "user" && latestNativeMessage.text === firstActiveMessage.text;
|
|
40577
|
+
const activeMessages = activeTurn.messages.slice(preserveNativeRoot ? 1 : 0).map(nativeActiveMessage);
|
|
40578
|
+
const bounded2 = boundedActiveMessages(activeMessages, limit, SESSION_HISTORY_CHARACTER_LIMIT);
|
|
40373
40579
|
let historicalMessageCount = 0;
|
|
40374
|
-
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT - bounded2.characters
|
|
40375
|
-
const historicalMessageLimit = Math.max(0, limit -
|
|
40580
|
+
let remainingCharacters = SESSION_HISTORY_CHARACTER_LIMIT - bounded2.characters;
|
|
40581
|
+
const historicalMessageLimit = Math.max(0, limit - bounded2.messages.length);
|
|
40376
40582
|
for (let index = history.messages.length - 1; index >= 0 && historicalMessageCount < historicalMessageLimit; index -= 1) {
|
|
40377
40583
|
const message = history.messages[index];
|
|
40378
40584
|
if (message === void 0) {
|
|
@@ -40395,7 +40601,7 @@ function paginateLiveSessionHistory(history, activeTurn, sessionId, cursor, limi
|
|
|
40395
40601
|
} : paginateAcpSessionHistory(history, sessionId, null, historicalMessageCount);
|
|
40396
40602
|
return {
|
|
40397
40603
|
...page,
|
|
40398
|
-
messages: [...page.messages, ...
|
|
40604
|
+
messages: [...page.messages, ...bounded2.messages],
|
|
40399
40605
|
truncated: page.truncated || activeTurn.truncated || bounded2.truncated
|
|
40400
40606
|
};
|
|
40401
40607
|
}
|
|
@@ -40846,6 +41052,7 @@ async function executePrompt({
|
|
|
40846
41052
|
timer,
|
|
40847
41053
|
signal,
|
|
40848
41054
|
recordLiveEvent,
|
|
41055
|
+
recordSteeringPrompt,
|
|
40849
41056
|
cancellationRequested
|
|
40850
41057
|
}) {
|
|
40851
41058
|
const events = new CoalescingAgentEventPublisher(timer, (event) => {
|
|
@@ -40926,6 +41133,17 @@ async function executePrompt({
|
|
|
40926
41133
|
sessionId: command.sessionId
|
|
40927
41134
|
});
|
|
40928
41135
|
operations.transitionExecution(command.commandId, "running");
|
|
41136
|
+
if (availability.disposition === SessionPromptDisposition.Steer) {
|
|
41137
|
+
const updated = recordSteeringPrompt();
|
|
41138
|
+
if (updated === null) {
|
|
41139
|
+
throw new AcpExecutionError(
|
|
41140
|
+
"The steering target is unavailable",
|
|
41141
|
+
{},
|
|
41142
|
+
"prompt_queue_target_unavailable"
|
|
41143
|
+
);
|
|
41144
|
+
}
|
|
41145
|
+
publisher.publish(command.sessionId, updated);
|
|
41146
|
+
}
|
|
40929
41147
|
const stream = activateAttempt();
|
|
40930
41148
|
publisher.publish(command.sessionId, {
|
|
40931
41149
|
commandId: command.commandId,
|
|
@@ -41545,6 +41763,7 @@ function createDaemonCommandHandler({
|
|
|
41545
41763
|
timer,
|
|
41546
41764
|
signal: turn.signal,
|
|
41547
41765
|
recordLiveEvent: turn.recordEvent,
|
|
41766
|
+
recordSteeringPrompt: () => activeTurns.recordSteeringPrompt(command),
|
|
41548
41767
|
cancellationRequested: turn.cancellationRequested
|
|
41549
41768
|
}).catch((error62) => {
|
|
41550
41769
|
console.error("Mobius daemon turn failed", error62);
|