@moxt-ai/mobius 0.0.139 → 0.0.141
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/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +10 -1
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/cli.js +108 -16
- package/dist/cli.js.map +3 -3
- package/dist/index.js +107 -15
- 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 +96 -11
- package/dist/native-sessions/codex-history.js.map +1 -1
- package/dist/runtime.js +107 -15
- package/dist/runtime.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -34048,6 +34048,7 @@ var APPROVAL_TIMEOUT_MILLISECONDS2 = 36e5;
|
|
|
34048
34048
|
var CODEX_AGENT_VERSION = "0.154.0";
|
|
34049
34049
|
var SESSION_LIST_TIMEOUT_MILLISECONDS = 3e4;
|
|
34050
34050
|
var CODEX_COMMANDS = Object.freeze([{ description: "Compact the conversation context", name: "compact" }]);
|
|
34051
|
+
var COMPACT_COMPLETED_MESSAGE = "Context compacted.";
|
|
34051
34052
|
var APPROVAL_OPTIONS = Object.freeze([
|
|
34052
34053
|
{ kind: "allow_once", name: "Allow once", optionId: "accept" },
|
|
34053
34054
|
{ kind: "allow_always", name: "Allow for this session", optionId: "acceptForSession" },
|
|
@@ -34740,7 +34741,15 @@ var CodexAcpAgent = class {
|
|
|
34740
34741
|
this.#turn = turn;
|
|
34741
34742
|
try {
|
|
34742
34743
|
await this.#appServer.request("thread/compact/start", { threadId: this.#nativeSessionId }, signal);
|
|
34743
|
-
|
|
34744
|
+
const result = await completion.promise;
|
|
34745
|
+
if (result.stopReason !== "cancelled") {
|
|
34746
|
+
await this.#emit({
|
|
34747
|
+
content: { text: COMPACT_COMPLETED_MESSAGE, type: "text" },
|
|
34748
|
+
messageId: turn.turn.id.length > 0 ? turn.turn.id : "compact-completed",
|
|
34749
|
+
sessionUpdate: "agent_message_chunk"
|
|
34750
|
+
});
|
|
34751
|
+
}
|
|
34752
|
+
return result;
|
|
34744
34753
|
} finally {
|
|
34745
34754
|
signal.removeEventListener("abort", aborted2);
|
|
34746
34755
|
if (this.#turn === turn) {
|
|
@@ -38991,6 +39000,69 @@ function errorMessage(value) {
|
|
|
38991
39000
|
function messageSize(message) {
|
|
38992
39001
|
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
38993
39002
|
}
|
|
39003
|
+
var SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT = Math.floor(SESSION_HISTORY_CHARACTER_LIMIT / 2);
|
|
39004
|
+
function fitActivity(activity2, maximumCharacters) {
|
|
39005
|
+
const truncate5 = (limit) => ({
|
|
39006
|
+
...activity2,
|
|
39007
|
+
input: bounded(activity2.input, limit),
|
|
39008
|
+
locations: activity2.locations.map((location) => bounded(location, Math.max(1, limit))),
|
|
39009
|
+
name: bounded(activity2.name, limit),
|
|
39010
|
+
output: bounded(activity2.output, limit),
|
|
39011
|
+
title: bounded(activity2.title, limit),
|
|
39012
|
+
toolKind: bounded(activity2.toolKind, limit)
|
|
39013
|
+
});
|
|
39014
|
+
let minimum = 1;
|
|
39015
|
+
let maximum = 1e5;
|
|
39016
|
+
let fitted = truncate5(0);
|
|
39017
|
+
while (minimum <= maximum) {
|
|
39018
|
+
const limit = Math.floor((minimum + maximum) / 2);
|
|
39019
|
+
const candidate = truncate5(limit);
|
|
39020
|
+
if (JSON.stringify(candidate).length <= maximumCharacters) {
|
|
39021
|
+
fitted = candidate;
|
|
39022
|
+
minimum = limit + 1;
|
|
39023
|
+
} else {
|
|
39024
|
+
maximum = limit - 1;
|
|
39025
|
+
}
|
|
39026
|
+
}
|
|
39027
|
+
return fitted;
|
|
39028
|
+
}
|
|
39029
|
+
function fitActivities(activities, maximumCharacters) {
|
|
39030
|
+
if (activities.length === 0) {
|
|
39031
|
+
return activities;
|
|
39032
|
+
}
|
|
39033
|
+
const arrayCharacters = 2 + activities.length - 1;
|
|
39034
|
+
const maximumActivityCharacters = Math.floor(Math.max(0, maximumCharacters - arrayCharacters) / activities.length);
|
|
39035
|
+
return activities.map((activity2) => fitActivity(activity2, maximumActivityCharacters));
|
|
39036
|
+
}
|
|
39037
|
+
function fitHistoryMessage(message) {
|
|
39038
|
+
const text2 = message.text.slice(-SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
|
|
39039
|
+
if (message.role === "user") {
|
|
39040
|
+
return {
|
|
39041
|
+
message: { ...message, text: text2 },
|
|
39042
|
+
truncated: text2.length < message.text.length
|
|
39043
|
+
};
|
|
39044
|
+
}
|
|
39045
|
+
let activities = message.activities;
|
|
39046
|
+
const content = message.content;
|
|
39047
|
+
let fitted = { ...message, activities, content, text: text2 };
|
|
39048
|
+
if (messageSize(fitted) > SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT && activities.length > 0) {
|
|
39049
|
+
const maximumCharacters = SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT - text2.length - JSON.stringify(content).length;
|
|
39050
|
+
activities = fitActivities(activities, maximumCharacters);
|
|
39051
|
+
fitted = { ...fitted, activities };
|
|
39052
|
+
}
|
|
39053
|
+
const excess = Math.max(0, messageSize(fitted) - SESSION_HISTORY_MESSAGE_CHARACTER_LIMIT);
|
|
39054
|
+
if (excess > 0) {
|
|
39055
|
+
const maximumTextLength = Math.max(0, fitted.text.length - excess);
|
|
39056
|
+
fitted = {
|
|
39057
|
+
...fitted,
|
|
39058
|
+
text: maximumTextLength === 0 ? "" : fitted.text.slice(-maximumTextLength)
|
|
39059
|
+
};
|
|
39060
|
+
}
|
|
39061
|
+
return {
|
|
39062
|
+
message: fitted,
|
|
39063
|
+
truncated: fitted.text.length < message.text.length || JSON.stringify(activities).length < JSON.stringify(message.activities).length
|
|
39064
|
+
};
|
|
39065
|
+
}
|
|
38994
39066
|
function turnOutcome(status) {
|
|
38995
39067
|
switch (status) {
|
|
38996
39068
|
case "completed":
|
|
@@ -39017,14 +39089,20 @@ function decodeHistory(thread, value, options) {
|
|
|
39017
39089
|
for (const turn of page.data.toReversed()) {
|
|
39018
39090
|
const outcome = turnOutcome(turn.status);
|
|
39019
39091
|
const activities = [];
|
|
39092
|
+
let assignedActivityCount = 0;
|
|
39020
39093
|
let sequence = 0;
|
|
39021
39094
|
let assistantMessageIndex = null;
|
|
39095
|
+
const activitySlice = () => {
|
|
39096
|
+
const assigned = activities.slice(assignedActivityCount).slice(-100);
|
|
39097
|
+
assignedActivityCount = activities.length;
|
|
39098
|
+
return assigned;
|
|
39099
|
+
};
|
|
39022
39100
|
for (const item of turn.items) {
|
|
39023
39101
|
const { type } = itemTypeSchema.parse(item);
|
|
39024
39102
|
let message;
|
|
39025
39103
|
if (type === "userMessage") {
|
|
39026
39104
|
const { content } = userMessageSchema.parse(item);
|
|
39027
|
-
const
|
|
39105
|
+
const text2 = content.map((block) => {
|
|
39028
39106
|
const { type: type2 } = itemTypeSchema.parse(block);
|
|
39029
39107
|
if (type2 === "text") {
|
|
39030
39108
|
return textSchema.parse(block).text;
|
|
@@ -39036,7 +39114,7 @@ function decodeHistory(thread, value, options) {
|
|
|
39036
39114
|
}).join("");
|
|
39037
39115
|
message = {
|
|
39038
39116
|
role: "user",
|
|
39039
|
-
text:
|
|
39117
|
+
text: text2
|
|
39040
39118
|
};
|
|
39041
39119
|
} else if (type === "agentMessage") {
|
|
39042
39120
|
const agent = agentMessageSchema.parse(item);
|
|
@@ -39057,7 +39135,7 @@ function decodeHistory(thread, value, options) {
|
|
|
39057
39135
|
}
|
|
39058
39136
|
continue;
|
|
39059
39137
|
}
|
|
39060
|
-
message = { activities:
|
|
39138
|
+
message = { activities: activitySlice(), content: [], role: "assistant", text: agent.text };
|
|
39061
39139
|
} else if (type === "reasoning" && options.detail === "rich") {
|
|
39062
39140
|
const reasoning = reasoningSchema.parse(item);
|
|
39063
39141
|
const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
|
|
@@ -39098,16 +39176,16 @@ function decodeHistory(thread, value, options) {
|
|
|
39098
39176
|
} else {
|
|
39099
39177
|
continue;
|
|
39100
39178
|
}
|
|
39101
|
-
const
|
|
39102
|
-
if (
|
|
39179
|
+
const fitted = fitHistoryMessage(message);
|
|
39180
|
+
if (fitted.message.text.length === 0 && (fitted.message.images?.length ?? 0) === 0) {
|
|
39103
39181
|
continue;
|
|
39104
39182
|
}
|
|
39105
|
-
truncated ||=
|
|
39106
|
-
messages.push(
|
|
39183
|
+
truncated ||= fitted.truncated;
|
|
39184
|
+
messages.push(fitted.message);
|
|
39107
39185
|
if (message.role === "assistant") {
|
|
39108
39186
|
assistantMessageIndex = messages.length - 1;
|
|
39109
39187
|
}
|
|
39110
|
-
characters += messageSize(
|
|
39188
|
+
characters += messageSize(fitted.message);
|
|
39111
39189
|
}
|
|
39112
39190
|
if (options.detail === "rich" && turn.error != null) {
|
|
39113
39191
|
activities.push(
|
|
@@ -39122,17 +39200,29 @@ function decodeHistory(thread, value, options) {
|
|
|
39122
39200
|
})
|
|
39123
39201
|
);
|
|
39124
39202
|
}
|
|
39203
|
+
if (options.detail === "rich" && activities.length > assignedActivityCount) {
|
|
39204
|
+
const message = {
|
|
39205
|
+
activities: activitySlice(),
|
|
39206
|
+
content: [],
|
|
39207
|
+
role: "assistant",
|
|
39208
|
+
text: ""
|
|
39209
|
+
};
|
|
39210
|
+
messages.push(message);
|
|
39211
|
+
assistantMessageIndex = messages.length - 1;
|
|
39212
|
+
characters += messageSize(message);
|
|
39213
|
+
}
|
|
39125
39214
|
if (assistantMessageIndex !== null) {
|
|
39126
39215
|
const assistant = messages[assistantMessageIndex];
|
|
39127
39216
|
if (assistant?.role === "assistant") {
|
|
39128
39217
|
characters -= messageSize(assistant);
|
|
39129
39218
|
const updated = {
|
|
39130
39219
|
...assistant,
|
|
39131
|
-
...outcome === void 0 ? {} : { outcome }
|
|
39132
|
-
activities: activities.slice(-100)
|
|
39220
|
+
...outcome === void 0 ? {} : { outcome }
|
|
39133
39221
|
};
|
|
39134
|
-
|
|
39135
|
-
|
|
39222
|
+
const fitted = fitHistoryMessage(updated);
|
|
39223
|
+
truncated ||= fitted.truncated;
|
|
39224
|
+
messages[assistantMessageIndex] = fitted.message;
|
|
39225
|
+
characters += messageSize(fitted.message);
|
|
39136
39226
|
}
|
|
39137
39227
|
} else if (activities.length > 0 || outcome !== void 0) {
|
|
39138
39228
|
const message = {
|
|
@@ -39142,8 +39232,10 @@ function decodeHistory(thread, value, options) {
|
|
|
39142
39232
|
...outcome === void 0 ? {} : { outcome },
|
|
39143
39233
|
text: ""
|
|
39144
39234
|
};
|
|
39145
|
-
|
|
39146
|
-
|
|
39235
|
+
const fitted = fitHistoryMessage(message);
|
|
39236
|
+
truncated ||= fitted.truncated;
|
|
39237
|
+
messages.push(fitted.message);
|
|
39238
|
+
characters += messageSize(fitted.message);
|
|
39147
39239
|
}
|
|
39148
39240
|
while (messages.length > (options.detail === "rich" ? SESSION_HISTORY_MESSAGE_LIMIT : SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT) || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
39149
39241
|
const removed = messages.shift();
|