@moxt-ai/mobius 0.0.69 → 0.0.70
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/session-history.d.ts +4 -2
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +121 -13
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-manager.d.ts +57 -4
- package/dist/acp/session-manager.d.ts.map +1 -1
- package/dist/acp/session-manager.js +21 -5
- package/dist/acp/session-manager.js.map +1 -1
- package/dist/cli.js +395 -91
- package/dist/cli.js.map +4 -4
- package/dist/index.js +394 -90
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/codex-history.d.ts +4 -2
- package/dist/native-sessions/codex-history.d.ts.map +1 -1
- package/dist/native-sessions/codex-history.js +159 -14
- package/dist/native-sessions/codex-history.js.map +1 -1
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +10 -2
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +394 -90
- 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.70",
|
|
15
15
|
description: "Mobius CLI for pairing and running local AI agent services.",
|
|
16
16
|
type: "module",
|
|
17
17
|
bin: {
|
|
@@ -23781,11 +23781,32 @@ function parseNativeHistoryText(text3) {
|
|
|
23781
23781
|
});
|
|
23782
23782
|
return { text: plainText, images };
|
|
23783
23783
|
}
|
|
23784
|
-
var
|
|
23785
|
-
|
|
23784
|
+
var nativeMessageActivitySchema = external_exports.strictObject({
|
|
23785
|
+
activityId: external_exports.string().min(1).max(128),
|
|
23786
|
+
activityType: external_exports.string().min(1).max(128),
|
|
23787
|
+
content: external_exports.array(displayContentSchema).max(100).readonly(),
|
|
23788
|
+
input: external_exports.string().max(1e5),
|
|
23789
|
+
locations: external_exports.array(external_exports.string().min(1).max(2048)).max(100).readonly(),
|
|
23790
|
+
name: external_exports.string().max(128),
|
|
23791
|
+
output: external_exports.string().max(1e5),
|
|
23792
|
+
sequence: external_exports.number().int().nonnegative(),
|
|
23793
|
+
status: external_exports.string().min(1).max(64),
|
|
23794
|
+
title: external_exports.string().max(500),
|
|
23795
|
+
toolKind: external_exports.string().max(64)
|
|
23796
|
+
}).readonly();
|
|
23797
|
+
var userHistoryMessage = external_exports.strictObject({
|
|
23798
|
+
role: external_exports.literal("user"),
|
|
23786
23799
|
text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
|
|
23787
23800
|
images: external_exports.array(historyImage).max(8).readonly().optional()
|
|
23788
23801
|
}).readonly();
|
|
23802
|
+
var assistantHistoryMessage = external_exports.strictObject({
|
|
23803
|
+
activities: external_exports.array(nativeMessageActivitySchema).max(100).readonly().default([]),
|
|
23804
|
+
content: external_exports.array(displayContentSchema).max(100).readonly().default([]),
|
|
23805
|
+
role: external_exports.literal("assistant"),
|
|
23806
|
+
text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
|
|
23807
|
+
images: external_exports.array(historyImage).max(8).readonly().optional()
|
|
23808
|
+
}).readonly();
|
|
23809
|
+
var historyMessage = external_exports.discriminatedUnion("role", [userHistoryMessage, assistantHistoryMessage]);
|
|
23789
23810
|
var availableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
23790
23811
|
status: external_exports.literal("available"),
|
|
23791
23812
|
messages: external_exports.array(historyMessage).max(SESSION_HISTORY_MESSAGE_LIMIT).readonly(),
|
|
@@ -23794,19 +23815,28 @@ var availableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
|
23794
23815
|
coveredMessageIds: external_exports.array(external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}:(?:user|agent)$/)).max(2e4).readonly().default([])
|
|
23795
23816
|
});
|
|
23796
23817
|
var availableSessionHistorySchema = availableSessionHistoryObjectSchema.readonly();
|
|
23797
|
-
var unavailableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
23818
|
+
var unavailableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
23819
|
+
status: external_exports.literal("unavailable"),
|
|
23820
|
+
cause: external_exports.strictObject({
|
|
23821
|
+
code: external_exports.string().regex(/^[a-z][a-z0-9_]{0,127}$/),
|
|
23822
|
+
message: external_exports.string().min(1).max(1e3)
|
|
23823
|
+
}).readonly()
|
|
23824
|
+
});
|
|
23798
23825
|
var unavailableSessionHistorySchema = unavailableSessionHistoryObjectSchema.readonly();
|
|
23799
23826
|
function withinHistoryContentLimits(history) {
|
|
23800
23827
|
if (history.status === "unavailable" || history.messages === void 0) {
|
|
23801
23828
|
return true;
|
|
23802
23829
|
}
|
|
23803
|
-
return history.messages.reduce(
|
|
23830
|
+
return history.messages.reduce(
|
|
23831
|
+
(total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
|
|
23832
|
+
0
|
|
23833
|
+
) <= SESSION_HISTORY_CHARACTER_LIMIT && history.messages.reduce(
|
|
23804
23834
|
(total, message) => total + (message.images ?? []).reduce((size, image) => size + image.data.length, 0),
|
|
23805
23835
|
0
|
|
23806
23836
|
) <= SESSION_HISTORY_IMAGE_CHARACTER_LIMIT;
|
|
23807
23837
|
}
|
|
23808
23838
|
var sessionHistorySchema = external_exports.discriminatedUnion("status", [availableSessionHistorySchema, unavailableSessionHistorySchema]).refine(withinHistoryContentLimits);
|
|
23809
|
-
var
|
|
23839
|
+
var nativeMessagePageSchema = external_exports.discriminatedUnion("status", [
|
|
23810
23840
|
availableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.string().max(512).nullable() }).readonly(),
|
|
23811
23841
|
unavailableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.null() }).readonly()
|
|
23812
23842
|
]).refine(withinHistoryContentLimits);
|
|
@@ -25769,8 +25799,8 @@ function captureActivityDetail(content3, input2, output2) {
|
|
|
25769
25799
|
originalBytes
|
|
25770
25800
|
};
|
|
25771
25801
|
}
|
|
25772
|
-
function recordedDetail(
|
|
25773
|
-
return
|
|
25802
|
+
function recordedDetail(activity2) {
|
|
25803
|
+
return activity2?.detail.kind === "recorded" ? activity2.detail : null;
|
|
25774
25804
|
}
|
|
25775
25805
|
function emptyDisplayContent(type) {
|
|
25776
25806
|
return {
|
|
@@ -25988,7 +26018,7 @@ var AcpActivityTracker = class {
|
|
|
25988
26018
|
const previous2 = this.#activities.get(key);
|
|
25989
26019
|
const identity2 = this.#identity(key);
|
|
25990
26020
|
const fullOutput = `${recordedDetail(previous2)?.output ?? previous2?.output ?? ""}${text3}`;
|
|
25991
|
-
const
|
|
26021
|
+
const activity2 = new AcpActivity(
|
|
25992
26022
|
identity2.id,
|
|
25993
26023
|
activityType,
|
|
25994
26024
|
"",
|
|
@@ -26002,7 +26032,7 @@ var AcpActivityTracker = class {
|
|
|
26002
26032
|
[],
|
|
26003
26033
|
captureActivityDetail([], "", fullOutput)
|
|
26004
26034
|
);
|
|
26005
|
-
await this.#record(key,
|
|
26035
|
+
await this.#record(key, activity2);
|
|
26006
26036
|
this.#activeNarrativeKey = key;
|
|
26007
26037
|
};
|
|
26008
26038
|
recordPlan = async (plan) => {
|
|
@@ -26124,21 +26154,21 @@ var AcpActivityTracker = class {
|
|
|
26124
26154
|
return;
|
|
26125
26155
|
}
|
|
26126
26156
|
this.#activeNarrativeKey = "";
|
|
26127
|
-
const
|
|
26128
|
-
if (
|
|
26157
|
+
const activity2 = this.#activities.get(key);
|
|
26158
|
+
if (activity2 === void 0) {
|
|
26129
26159
|
return;
|
|
26130
26160
|
}
|
|
26131
|
-
const completed =
|
|
26132
|
-
if (completed !==
|
|
26161
|
+
const completed = activity2.complete();
|
|
26162
|
+
if (completed !== activity2) {
|
|
26133
26163
|
await this.#record(key, completed);
|
|
26134
26164
|
}
|
|
26135
26165
|
};
|
|
26136
26166
|
finish = async () => {
|
|
26137
26167
|
await this.finishNarrative();
|
|
26138
26168
|
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
26139
|
-
for (const [key,
|
|
26140
|
-
const completed =
|
|
26141
|
-
if (completed !==
|
|
26169
|
+
for (const [key, activity2] of entries) {
|
|
26170
|
+
const completed = activity2.complete();
|
|
26171
|
+
if (completed !== activity2) {
|
|
26142
26172
|
await this.#record(key, completed);
|
|
26143
26173
|
}
|
|
26144
26174
|
}
|
|
@@ -26153,9 +26183,9 @@ var AcpActivityTracker = class {
|
|
|
26153
26183
|
this.#identities.set(key, identity2);
|
|
26154
26184
|
return identity2;
|
|
26155
26185
|
};
|
|
26156
|
-
#record = async (key,
|
|
26157
|
-
this.#activities.set(key,
|
|
26158
|
-
await this.#onActivity(
|
|
26186
|
+
#record = async (key, activity2) => {
|
|
26187
|
+
this.#activities.set(key, activity2);
|
|
26188
|
+
await this.#onActivity(activity2);
|
|
26159
26189
|
};
|
|
26160
26190
|
#recordPlanEntries = async (key, entries) => {
|
|
26161
26191
|
const identity2 = this.#identity(key);
|
|
@@ -33783,19 +33813,74 @@ function sessionConfigProtocolForAgent(agentId) {
|
|
|
33783
33813
|
|
|
33784
33814
|
// src/acp/session-history.ts
|
|
33785
33815
|
var AcpHistoryReplay = class {
|
|
33816
|
+
#activities = /* @__PURE__ */ new Map();
|
|
33786
33817
|
#messages = [];
|
|
33818
|
+
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
33819
|
+
#activityTracker = new AcpActivityTracker(async (activity2) => {
|
|
33820
|
+
this.#activities.set(activity2.activityId, activity2);
|
|
33821
|
+
this.#turnActivityIds.add(activity2.activityId);
|
|
33822
|
+
const latest = this.#messages.at(-1);
|
|
33823
|
+
if (latest?.role === "assistant") {
|
|
33824
|
+
this.#messages[this.#messages.length - 1] = {
|
|
33825
|
+
...latest,
|
|
33826
|
+
activityIds: [...this.#turnActivityIds]
|
|
33827
|
+
};
|
|
33828
|
+
}
|
|
33829
|
+
});
|
|
33787
33830
|
#lastMessageId = null;
|
|
33788
33831
|
#characters = 0;
|
|
33789
33832
|
#truncated = false;
|
|
33790
|
-
record = (update) => {
|
|
33833
|
+
record = async (update) => {
|
|
33834
|
+
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
33835
|
+
if (update.content.type === "text") {
|
|
33836
|
+
await this.#activityTracker.recordNarrative(
|
|
33837
|
+
"reasoning",
|
|
33838
|
+
update.messageId ?? "current",
|
|
33839
|
+
update.content.text
|
|
33840
|
+
);
|
|
33841
|
+
}
|
|
33842
|
+
return;
|
|
33843
|
+
}
|
|
33844
|
+
if (update.sessionUpdate === "tool_call") {
|
|
33845
|
+
await this.#activityTracker.recordToolCall(update);
|
|
33846
|
+
return;
|
|
33847
|
+
}
|
|
33848
|
+
if (update.sessionUpdate === "tool_call_update") {
|
|
33849
|
+
await this.#activityTracker.recordToolCallUpdate(update);
|
|
33850
|
+
return;
|
|
33851
|
+
}
|
|
33852
|
+
if (update.sessionUpdate === "plan") {
|
|
33853
|
+
await this.#activityTracker.recordPlan(update);
|
|
33854
|
+
return;
|
|
33855
|
+
}
|
|
33856
|
+
if (update.sessionUpdate === "plan_update") {
|
|
33857
|
+
await this.#activityTracker.recordPlanUpdate(update);
|
|
33858
|
+
return;
|
|
33859
|
+
}
|
|
33860
|
+
if (update.sessionUpdate === "plan_removed") {
|
|
33861
|
+
await this.#activityTracker.removePlan(update);
|
|
33862
|
+
return;
|
|
33863
|
+
}
|
|
33791
33864
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
33792
33865
|
return;
|
|
33793
33866
|
}
|
|
33794
33867
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
33868
|
+
if (update.content.type === "text") {
|
|
33869
|
+
await this.#activityTracker.recordNarrative(
|
|
33870
|
+
"progress",
|
|
33871
|
+
update.messageId ?? "current",
|
|
33872
|
+
update.content.text
|
|
33873
|
+
);
|
|
33874
|
+
}
|
|
33795
33875
|
return;
|
|
33796
33876
|
}
|
|
33797
33877
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
33798
33878
|
const content3 = update.content;
|
|
33879
|
+
if (role === "assistant" && content3.type !== "text") {
|
|
33880
|
+
await this.#activityTracker.finishNarrative();
|
|
33881
|
+
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content3));
|
|
33882
|
+
return;
|
|
33883
|
+
}
|
|
33799
33884
|
const text3 = content3.type === "text" ? content3.text : content3.type === "image" ? content3.data.length > 0 ? `[@image](data:${content3.mimeType};base64,${content3.data})` : content3.uri != null && content3.uri.length > 0 ? `[@image](${content3.uri})` : "[image attachment]" : `[${content3.type} attachment]`;
|
|
33800
33885
|
if (text3.length === 0) {
|
|
33801
33886
|
return;
|
|
@@ -33803,19 +33888,84 @@ var AcpHistoryReplay = class {
|
|
|
33803
33888
|
const previous2 = this.#messages.at(-1);
|
|
33804
33889
|
const id = update.messageId ?? null;
|
|
33805
33890
|
const continuation = previous2?.role === role && id === this.#lastMessageId;
|
|
33891
|
+
if (role === "user" && !continuation) {
|
|
33892
|
+
await this.#activityTracker.finish();
|
|
33893
|
+
this.#turnActivityIds.clear();
|
|
33894
|
+
}
|
|
33806
33895
|
const combined = continuation ? `${previous2.text}${text3}` : text3;
|
|
33807
33896
|
if (continuation) {
|
|
33808
33897
|
this.#messages.pop();
|
|
33809
33898
|
this.#characters -= previous2.text.length;
|
|
33810
33899
|
}
|
|
33811
|
-
const
|
|
33812
|
-
this.#truncated ||=
|
|
33813
|
-
this.#messages.push(
|
|
33814
|
-
role,
|
|
33815
|
-
|
|
33816
|
-
|
|
33817
|
-
|
|
33900
|
+
const bounded2 = combined.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
|
|
33901
|
+
this.#truncated ||= bounded2.length < combined.length;
|
|
33902
|
+
this.#messages.push(
|
|
33903
|
+
role === "user" ? { role, text: bounded2 } : {
|
|
33904
|
+
activityIds: [...this.#turnActivityIds],
|
|
33905
|
+
content: previous2?.role === "assistant" ? previous2.content : [],
|
|
33906
|
+
role,
|
|
33907
|
+
text: bounded2
|
|
33908
|
+
}
|
|
33909
|
+
);
|
|
33910
|
+
this.#characters += bounded2.length;
|
|
33818
33911
|
this.#lastMessageId = id;
|
|
33912
|
+
this.trimMessages();
|
|
33913
|
+
};
|
|
33914
|
+
snapshot = async () => {
|
|
33915
|
+
await this.#activityTracker.finish();
|
|
33916
|
+
return {
|
|
33917
|
+
status: "available",
|
|
33918
|
+
messages: this.#messages.map(
|
|
33919
|
+
(message) => message.role === "user" ? message : {
|
|
33920
|
+
role: "assistant",
|
|
33921
|
+
text: message.text,
|
|
33922
|
+
content: message.content,
|
|
33923
|
+
activities: message.activityIds.flatMap((id) => {
|
|
33924
|
+
const activity2 = this.#activities.get(id);
|
|
33925
|
+
return activity2 === void 0 ? [] : [
|
|
33926
|
+
{
|
|
33927
|
+
activityId: activity2.activityId,
|
|
33928
|
+
activityType: activity2.activityType,
|
|
33929
|
+
content: activity2.content,
|
|
33930
|
+
input: activity2.input,
|
|
33931
|
+
locations: activity2.locations,
|
|
33932
|
+
name: activity2.name,
|
|
33933
|
+
output: activity2.output,
|
|
33934
|
+
sequence: activity2.sequence,
|
|
33935
|
+
status: activity2.status,
|
|
33936
|
+
title: activity2.title,
|
|
33937
|
+
toolKind: activity2.toolKind
|
|
33938
|
+
}
|
|
33939
|
+
];
|
|
33940
|
+
})
|
|
33941
|
+
}
|
|
33942
|
+
),
|
|
33943
|
+
truncated: this.#truncated,
|
|
33944
|
+
coveredCommandIds: [],
|
|
33945
|
+
coveredMessageIds: []
|
|
33946
|
+
};
|
|
33947
|
+
};
|
|
33948
|
+
recordAssistantContent = (messageId, content3) => {
|
|
33949
|
+
const previous2 = this.#messages.at(-1);
|
|
33950
|
+
const continuation = previous2?.role === "assistant" && messageId === this.#lastMessageId;
|
|
33951
|
+
if (continuation) {
|
|
33952
|
+
this.#messages[this.#messages.length - 1] = {
|
|
33953
|
+
...previous2,
|
|
33954
|
+
activityIds: [...this.#turnActivityIds],
|
|
33955
|
+
content: [...previous2.content, content3]
|
|
33956
|
+
};
|
|
33957
|
+
} else {
|
|
33958
|
+
this.#messages.push({
|
|
33959
|
+
activityIds: [...this.#turnActivityIds],
|
|
33960
|
+
content: [content3],
|
|
33961
|
+
role: "assistant",
|
|
33962
|
+
text: ""
|
|
33963
|
+
});
|
|
33964
|
+
}
|
|
33965
|
+
this.#lastMessageId = messageId;
|
|
33966
|
+
this.trimMessages();
|
|
33967
|
+
};
|
|
33968
|
+
trimMessages = () => {
|
|
33819
33969
|
while (this.#messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || this.#characters > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
33820
33970
|
const removed = this.#messages.shift();
|
|
33821
33971
|
if (removed !== void 0) {
|
|
@@ -33824,13 +33974,6 @@ var AcpHistoryReplay = class {
|
|
|
33824
33974
|
this.#truncated = true;
|
|
33825
33975
|
}
|
|
33826
33976
|
};
|
|
33827
|
-
snapshot = () => ({
|
|
33828
|
-
status: "available",
|
|
33829
|
-
messages: [...this.#messages],
|
|
33830
|
-
truncated: this.#truncated,
|
|
33831
|
-
coveredCommandIds: [],
|
|
33832
|
-
coveredMessageIds: []
|
|
33833
|
-
});
|
|
33834
33977
|
};
|
|
33835
33978
|
|
|
33836
33979
|
// src/acp/session-store.ts
|
|
@@ -34756,7 +34899,13 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34756
34899
|
);
|
|
34757
34900
|
loadHistory = async (signal) => {
|
|
34758
34901
|
if (!this.#capabilities.loadSession) {
|
|
34759
|
-
return {
|
|
34902
|
+
return {
|
|
34903
|
+
status: "unavailable",
|
|
34904
|
+
cause: {
|
|
34905
|
+
code: "native_history_unsupported",
|
|
34906
|
+
message: "This Agent restores context but does not provide message history."
|
|
34907
|
+
}
|
|
34908
|
+
};
|
|
34760
34909
|
}
|
|
34761
34910
|
const history = new AcpHistoryReplay();
|
|
34762
34911
|
this.#replay = { kind: "capture", history };
|
|
@@ -34777,7 +34926,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34777
34926
|
);
|
|
34778
34927
|
await this.#updateTail;
|
|
34779
34928
|
signal.throwIfAborted();
|
|
34780
|
-
return await embedLocalHistoryImages(history.snapshot(), signal);
|
|
34929
|
+
return await embedLocalHistoryImages(await history.snapshot(), signal);
|
|
34781
34930
|
} finally {
|
|
34782
34931
|
this.#replay = { kind: "idle" };
|
|
34783
34932
|
}
|
|
@@ -35621,7 +35770,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
35621
35770
|
this.assertNativeSession(notification.sessionId);
|
|
35622
35771
|
const update = notification.update;
|
|
35623
35772
|
if (this.#replay.kind === "capture") {
|
|
35624
|
-
this.#replay.history.record(update);
|
|
35773
|
+
await this.#replay.history.record(update);
|
|
35625
35774
|
}
|
|
35626
35775
|
if (this.#replay.kind !== "idle" && (update.sessionUpdate === "user_message_chunk" || update.sessionUpdate === "agent_message_chunk" || update.sessionUpdate === "agent_thought_chunk" || update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update" || update.sessionUpdate === "plan" || update.sessionUpdate === "plan_update" || update.sessionUpdate === "plan_removed")) {
|
|
35627
35776
|
return;
|
|
@@ -35912,10 +36061,12 @@ var AcpSessionManager = class {
|
|
|
35912
36061
|
#startingProcessCount = 0;
|
|
35913
36062
|
#transientProcessCount = 0;
|
|
35914
36063
|
#store;
|
|
36064
|
+
#nativeHistoryReader;
|
|
35915
36065
|
#observer;
|
|
35916
|
-
constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore()) {
|
|
36066
|
+
constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null) {
|
|
35917
36067
|
this.#observer = observer;
|
|
35918
36068
|
this.#store = store;
|
|
36069
|
+
this.#nativeHistoryReader = nativeHistoryReader;
|
|
35919
36070
|
}
|
|
35920
36071
|
setObserver = (observer) => {
|
|
35921
36072
|
this.#observer = observer;
|
|
@@ -36677,7 +36828,15 @@ var AcpSessionManager = class {
|
|
|
36677
36828
|
loadSessionHistory = async (options) => {
|
|
36678
36829
|
this.#beginSessionUse(options.sessionId);
|
|
36679
36830
|
try {
|
|
36680
|
-
|
|
36831
|
+
const runtime = await this.ensureSession(options);
|
|
36832
|
+
const stored = this.#store.read(options.sessionId);
|
|
36833
|
+
if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
|
|
36834
|
+
const history = await this.#nativeHistoryReader.read(options, stored.session.nativeSessionId);
|
|
36835
|
+
if (history !== null) {
|
|
36836
|
+
return history;
|
|
36837
|
+
}
|
|
36838
|
+
}
|
|
36839
|
+
return await runtime.loadHistory(options.signal);
|
|
36681
36840
|
} finally {
|
|
36682
36841
|
this.#endSessionUse(options.sessionId);
|
|
36683
36842
|
}
|
|
@@ -37893,10 +38052,6 @@ var WorkspaceDirectoryService = class {
|
|
|
37893
38052
|
};
|
|
37894
38053
|
};
|
|
37895
38054
|
|
|
37896
|
-
// src/native-sessions/service.ts
|
|
37897
|
-
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
37898
|
-
import { basename as basename6 } from "node:path";
|
|
37899
|
-
|
|
37900
38055
|
// src/native-sessions/codex-history.ts
|
|
37901
38056
|
import { spawn as spawn4 } from "node:child_process";
|
|
37902
38057
|
var responseSchema = external_exports.union([
|
|
@@ -37914,7 +38069,12 @@ var threadSchema = external_exports.object({
|
|
|
37914
38069
|
})
|
|
37915
38070
|
});
|
|
37916
38071
|
var turnsSchema = external_exports.object({
|
|
37917
|
-
data: external_exports.array(
|
|
38072
|
+
data: external_exports.array(
|
|
38073
|
+
external_exports.object({
|
|
38074
|
+
error: external_exports.unknown().nullish(),
|
|
38075
|
+
items: external_exports.array(external_exports.unknown()).max(1e5)
|
|
38076
|
+
})
|
|
38077
|
+
).max(SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT),
|
|
37918
38078
|
nextCursor: external_exports.string().nullish()
|
|
37919
38079
|
});
|
|
37920
38080
|
var itemTypeSchema = external_exports.object({ type: external_exports.string().min(1).max(80) });
|
|
@@ -37924,12 +38084,62 @@ var userMessageSchema = external_exports.object({
|
|
|
37924
38084
|
var textSchema = external_exports.object({ text: external_exports.string() });
|
|
37925
38085
|
var imageSchema = external_exports.object({ url: external_exports.string() });
|
|
37926
38086
|
var agentMessageSchema = textSchema.extend({ phase: external_exports.string().nullish() });
|
|
37927
|
-
|
|
38087
|
+
var reasoningSchema = external_exports.object({
|
|
38088
|
+
id: external_exports.string(),
|
|
38089
|
+
summary: external_exports.array(external_exports.string()).max(1e4),
|
|
38090
|
+
content: external_exports.array(external_exports.string()).max(1e4)
|
|
38091
|
+
});
|
|
38092
|
+
var commandExecutionSchema = external_exports.object({
|
|
38093
|
+
id: external_exports.string(),
|
|
38094
|
+
command: external_exports.string(),
|
|
38095
|
+
cwd: external_exports.string(),
|
|
38096
|
+
status: external_exports.string(),
|
|
38097
|
+
commandActions: external_exports.array(external_exports.object({ type: external_exports.string() }).passthrough()).max(100),
|
|
38098
|
+
aggregatedOutput: external_exports.string().nullish(),
|
|
38099
|
+
exitCode: external_exports.number().int().nullish()
|
|
38100
|
+
});
|
|
38101
|
+
function bounded(value, maximum) {
|
|
38102
|
+
return value.slice(0, maximum);
|
|
38103
|
+
}
|
|
38104
|
+
function activity(activityId, activityType, sequence, fields) {
|
|
38105
|
+
return {
|
|
38106
|
+
activityId: bounded(activityId, 128) || `history-${sequence.toString()}`,
|
|
38107
|
+
activityType,
|
|
38108
|
+
content: [],
|
|
38109
|
+
input: bounded(fields.input, 1e5),
|
|
38110
|
+
locations: fields.locations.filter((location) => location.length > 0).map((location) => bounded(location, 2048)).slice(0, 100),
|
|
38111
|
+
name: bounded(fields.name, 128),
|
|
38112
|
+
output: bounded(fields.output, 1e5),
|
|
38113
|
+
sequence,
|
|
38114
|
+
status: bounded(fields.status, 64),
|
|
38115
|
+
title: bounded(fields.title, 500),
|
|
38116
|
+
toolKind: bounded(fields.toolKind, 64)
|
|
38117
|
+
};
|
|
38118
|
+
}
|
|
38119
|
+
function errorMessage(value) {
|
|
38120
|
+
if (typeof value === "string") {
|
|
38121
|
+
return value;
|
|
38122
|
+
}
|
|
38123
|
+
if (typeof value === "object" && value !== null) {
|
|
38124
|
+
const message = Reflect.get(value, "message");
|
|
38125
|
+
if (typeof message === "string") {
|
|
38126
|
+
return message;
|
|
38127
|
+
}
|
|
38128
|
+
}
|
|
38129
|
+
return JSON.stringify(value) ?? "Codex stopped before completing this turn.";
|
|
38130
|
+
}
|
|
38131
|
+
function messageSize(message) {
|
|
38132
|
+
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
38133
|
+
}
|
|
38134
|
+
function decodeHistory(thread, value, options) {
|
|
37928
38135
|
const page = turnsSchema.parse(value);
|
|
37929
38136
|
const messages = [];
|
|
37930
38137
|
let characters = 0;
|
|
37931
38138
|
let truncated = page.nextCursor != null;
|
|
37932
38139
|
for (const turn of page.data.toReversed()) {
|
|
38140
|
+
const activities = [];
|
|
38141
|
+
let sequence = 0;
|
|
38142
|
+
let assistantMessageIndex = null;
|
|
37933
38143
|
for (const item of turn.items) {
|
|
37934
38144
|
const { type } = itemTypeSchema.parse(item);
|
|
37935
38145
|
let message;
|
|
@@ -37952,9 +38162,60 @@ function decodeHistory(thread, value) {
|
|
|
37952
38162
|
} else if (type === "agentMessage") {
|
|
37953
38163
|
const agent = agentMessageSchema.parse(item);
|
|
37954
38164
|
if (agent.phase === "commentary") {
|
|
38165
|
+
if (options.detail === "rich" && agent.text.length > 0) {
|
|
38166
|
+
activities.push(
|
|
38167
|
+
activity(`progress-${sequence.toString()}`, "progress", sequence, {
|
|
38168
|
+
input: "",
|
|
38169
|
+
locations: [],
|
|
38170
|
+
name: "",
|
|
38171
|
+
output: agent.text,
|
|
38172
|
+
status: "completed",
|
|
38173
|
+
title: "Progress",
|
|
38174
|
+
toolKind: ""
|
|
38175
|
+
})
|
|
38176
|
+
);
|
|
38177
|
+
sequence += 1;
|
|
38178
|
+
}
|
|
37955
38179
|
continue;
|
|
37956
38180
|
}
|
|
37957
|
-
message = { role: "assistant", text: agent.text };
|
|
38181
|
+
message = { activities: activities.slice(-100), content: [], role: "assistant", text: agent.text };
|
|
38182
|
+
} else if (type === "reasoning" && options.detail === "rich") {
|
|
38183
|
+
const reasoning = reasoningSchema.parse(item);
|
|
38184
|
+
const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
|
|
38185
|
+
if (output2.length > 0) {
|
|
38186
|
+
activities.push(
|
|
38187
|
+
activity(reasoning.id, "reasoning", sequence, {
|
|
38188
|
+
input: "",
|
|
38189
|
+
locations: [],
|
|
38190
|
+
name: "",
|
|
38191
|
+
output: output2,
|
|
38192
|
+
status: "completed",
|
|
38193
|
+
title: "Reasoning",
|
|
38194
|
+
toolKind: ""
|
|
38195
|
+
})
|
|
38196
|
+
);
|
|
38197
|
+
sequence += 1;
|
|
38198
|
+
}
|
|
38199
|
+
continue;
|
|
38200
|
+
} else if (type === "commandExecution" && options.detail === "rich") {
|
|
38201
|
+
const command = commandExecutionSchema.parse(item);
|
|
38202
|
+
const action = command.commandActions[0]?.type ?? "execute";
|
|
38203
|
+
activities.push(
|
|
38204
|
+
activity(command.id, "tool", sequence, {
|
|
38205
|
+
input: JSON.stringify({ command: command.command, cwd: command.cwd }),
|
|
38206
|
+
locations: [command.cwd],
|
|
38207
|
+
name: "",
|
|
38208
|
+
output: JSON.stringify({
|
|
38209
|
+
formatted_output: command.aggregatedOutput ?? "",
|
|
38210
|
+
...command.exitCode == null ? {} : { exit_code: command.exitCode }
|
|
38211
|
+
}),
|
|
38212
|
+
status: command.status === "completed" ? "completed" : "failed",
|
|
38213
|
+
title: command.command,
|
|
38214
|
+
toolKind: action
|
|
38215
|
+
})
|
|
38216
|
+
);
|
|
38217
|
+
sequence += 1;
|
|
38218
|
+
continue;
|
|
37958
38219
|
} else {
|
|
37959
38220
|
continue;
|
|
37960
38221
|
}
|
|
@@ -37964,14 +38225,48 @@ function decodeHistory(thread, value) {
|
|
|
37964
38225
|
}
|
|
37965
38226
|
truncated ||= text3.length < message.text.length;
|
|
37966
38227
|
messages.push({ ...message, text: text3 });
|
|
37967
|
-
|
|
37968
|
-
|
|
37969
|
-
|
|
37970
|
-
|
|
37971
|
-
|
|
37972
|
-
|
|
37973
|
-
|
|
38228
|
+
if (message.role === "assistant") {
|
|
38229
|
+
assistantMessageIndex = messages.length - 1;
|
|
38230
|
+
}
|
|
38231
|
+
characters += messageSize({ ...message, text: text3 });
|
|
38232
|
+
}
|
|
38233
|
+
if (options.detail === "rich" && turn.error != null) {
|
|
38234
|
+
activities.push(
|
|
38235
|
+
activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
|
|
38236
|
+
input: "",
|
|
38237
|
+
locations: [],
|
|
38238
|
+
name: "",
|
|
38239
|
+
output: errorMessage(turn.error),
|
|
38240
|
+
status: "failed",
|
|
38241
|
+
title: "Agent error",
|
|
38242
|
+
toolKind: "other"
|
|
38243
|
+
})
|
|
38244
|
+
);
|
|
38245
|
+
}
|
|
38246
|
+
if (assistantMessageIndex !== null) {
|
|
38247
|
+
const assistant = messages[assistantMessageIndex];
|
|
38248
|
+
if (assistant?.role === "assistant") {
|
|
38249
|
+
characters -= messageSize(assistant);
|
|
38250
|
+
const updated = { ...assistant, activities: activities.slice(-100) };
|
|
38251
|
+
messages[assistantMessageIndex] = updated;
|
|
38252
|
+
characters += messageSize(updated);
|
|
38253
|
+
}
|
|
38254
|
+
} else if (activities.length > 0) {
|
|
38255
|
+
const message = {
|
|
38256
|
+
activities: activities.slice(-100),
|
|
38257
|
+
content: [],
|
|
38258
|
+
role: "assistant",
|
|
38259
|
+
text: ""
|
|
38260
|
+
};
|
|
38261
|
+
messages.push(message);
|
|
38262
|
+
characters += messageSize(message);
|
|
38263
|
+
}
|
|
38264
|
+
while (messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
38265
|
+
const removed = messages.shift();
|
|
38266
|
+
if (removed !== void 0) {
|
|
38267
|
+
characters -= messageSize(removed);
|
|
37974
38268
|
}
|
|
38269
|
+
truncated = true;
|
|
37975
38270
|
}
|
|
37976
38271
|
}
|
|
37977
38272
|
return {
|
|
@@ -37986,7 +38281,7 @@ function decodeHistory(thread, value) {
|
|
|
37986
38281
|
}
|
|
37987
38282
|
};
|
|
37988
38283
|
}
|
|
37989
|
-
async function
|
|
38284
|
+
async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, options) {
|
|
37990
38285
|
signal.throwIfAborted();
|
|
37991
38286
|
nativeSessionIdSchema.parse(nativeSessionId);
|
|
37992
38287
|
if (agent.id !== "codex" || !await revalidateExecutable(agent.agentIdentity)) {
|
|
@@ -38080,13 +38375,13 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
|
|
|
38080
38375
|
threadId: nativeSessionId,
|
|
38081
38376
|
limit: SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT,
|
|
38082
38377
|
sortDirection: "desc",
|
|
38083
|
-
itemsView: "summary"
|
|
38378
|
+
itemsView: options.detail === "rich" ? "full" : "summary"
|
|
38084
38379
|
}
|
|
38085
38380
|
});
|
|
38086
38381
|
break;
|
|
38087
38382
|
}
|
|
38088
38383
|
case "turns":
|
|
38089
|
-
response.resolve(decodeHistory(state.thread, message.result));
|
|
38384
|
+
response.resolve(decodeHistory(state.thread, message.result, options));
|
|
38090
38385
|
return;
|
|
38091
38386
|
default: {
|
|
38092
38387
|
const unhandled = state;
|
|
@@ -38143,8 +38438,12 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
|
|
|
38143
38438
|
child.removeListener("exit", onExit);
|
|
38144
38439
|
}
|
|
38145
38440
|
}
|
|
38441
|
+
var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "messages" });
|
|
38442
|
+
var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
|
|
38146
38443
|
|
|
38147
38444
|
// src/native-sessions/service.ts
|
|
38445
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
38446
|
+
import { basename as basename6 } from "node:path";
|
|
38148
38447
|
var NativeSessionService = class {
|
|
38149
38448
|
#entries = /* @__PURE__ */ new Map();
|
|
38150
38449
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -40267,28 +40566,28 @@ var CoalescingDaemonActivityPublisher = class {
|
|
|
40267
40566
|
}
|
|
40268
40567
|
this.#pending.clear();
|
|
40269
40568
|
this.#scheduled.clear();
|
|
40270
|
-
for (const
|
|
40271
|
-
this.#publish(
|
|
40569
|
+
for (const activity2 of activities) {
|
|
40570
|
+
this.#publish(activity2);
|
|
40272
40571
|
}
|
|
40273
40572
|
};
|
|
40274
|
-
record = (
|
|
40275
|
-
if (
|
|
40276
|
-
this.#discardPending(
|
|
40277
|
-
this.#publishedActivityIds.add(
|
|
40278
|
-
this.#publish(
|
|
40573
|
+
record = (activity2) => {
|
|
40574
|
+
if (activity2.status !== "pending" && activity2.status !== "running") {
|
|
40575
|
+
this.#discardPending(activity2.activityId);
|
|
40576
|
+
this.#publishedActivityIds.add(activity2.activityId);
|
|
40577
|
+
this.#publish(activity2);
|
|
40279
40578
|
return Promise.resolve();
|
|
40280
40579
|
}
|
|
40281
|
-
if (!this.#publishedActivityIds.has(
|
|
40282
|
-
this.#publishedActivityIds.add(
|
|
40283
|
-
this.#publish(
|
|
40580
|
+
if (!this.#publishedActivityIds.has(activity2.activityId)) {
|
|
40581
|
+
this.#publishedActivityIds.add(activity2.activityId);
|
|
40582
|
+
this.#publish(activity2);
|
|
40284
40583
|
return Promise.resolve();
|
|
40285
40584
|
}
|
|
40286
|
-
this.#pending.set(
|
|
40287
|
-
if (!this.#scheduled.has(
|
|
40585
|
+
this.#pending.set(activity2.activityId, activity2);
|
|
40586
|
+
if (!this.#scheduled.has(activity2.activityId)) {
|
|
40288
40587
|
this.#scheduled.set(
|
|
40289
|
-
|
|
40588
|
+
activity2.activityId,
|
|
40290
40589
|
this.#timer.schedule(
|
|
40291
|
-
() => this.#flushActivity(
|
|
40590
|
+
() => this.#flushActivity(activity2.activityId),
|
|
40292
40591
|
AGENT_ACTIVITY_COALESCING_MILLISECONDS
|
|
40293
40592
|
)
|
|
40294
40593
|
);
|
|
@@ -40301,30 +40600,30 @@ var CoalescingDaemonActivityPublisher = class {
|
|
|
40301
40600
|
this.#pending.delete(activityId);
|
|
40302
40601
|
};
|
|
40303
40602
|
#flushActivity = (activityId) => {
|
|
40304
|
-
const
|
|
40603
|
+
const activity2 = this.#pending.get(activityId);
|
|
40305
40604
|
this.#discardPending(activityId);
|
|
40306
|
-
if (
|
|
40307
|
-
this.#publish(
|
|
40605
|
+
if (activity2 !== void 0) {
|
|
40606
|
+
this.#publish(activity2);
|
|
40308
40607
|
}
|
|
40309
40608
|
};
|
|
40310
40609
|
};
|
|
40311
|
-
function daemonActivity(command,
|
|
40610
|
+
function daemonActivity(command, activity2) {
|
|
40312
40611
|
return {
|
|
40313
|
-
activityId:
|
|
40314
|
-
activityType:
|
|
40612
|
+
activityId: activity2.activityId,
|
|
40613
|
+
activityType: activity2.activityType,
|
|
40315
40614
|
commandId: command.commandId,
|
|
40316
|
-
content:
|
|
40317
|
-
detail:
|
|
40318
|
-
input:
|
|
40615
|
+
content: activity2.content,
|
|
40616
|
+
detail: activity2.detail,
|
|
40617
|
+
input: activity2.input,
|
|
40319
40618
|
kind: AGENT_ACTIVITY_KIND,
|
|
40320
|
-
locations:
|
|
40321
|
-
name:
|
|
40322
|
-
output:
|
|
40323
|
-
sequence:
|
|
40619
|
+
locations: activity2.locations,
|
|
40620
|
+
name: activity2.name,
|
|
40621
|
+
output: activity2.output,
|
|
40622
|
+
sequence: activity2.sequence,
|
|
40324
40623
|
sessionId: command.sessionId,
|
|
40325
|
-
status:
|
|
40326
|
-
title:
|
|
40327
|
-
toolKind:
|
|
40624
|
+
status: activity2.status,
|
|
40625
|
+
title: activity2.title,
|
|
40626
|
+
toolKind: activity2.toolKind
|
|
40328
40627
|
};
|
|
40329
40628
|
}
|
|
40330
40629
|
function reportFailure(publisher, command, code, message, attemptId) {
|
|
@@ -40823,7 +41122,10 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
|
|
|
40823
41122
|
sessionId: command.sessionId
|
|
40824
41123
|
});
|
|
40825
41124
|
send(socket, {
|
|
40826
|
-
history: {
|
|
41125
|
+
history: {
|
|
41126
|
+
status: "unavailable",
|
|
41127
|
+
cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) }
|
|
41128
|
+
},
|
|
40827
41129
|
kind: "session.live-history.loaded",
|
|
40828
41130
|
requestId: command.requestId,
|
|
40829
41131
|
sessionId: command.sessionId
|
|
@@ -40870,8 +41172,8 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
|
|
|
40870
41172
|
}
|
|
40871
41173
|
}
|
|
40872
41174
|
async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal) {
|
|
40873
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (
|
|
40874
|
-
publisher.recordAttempt(command.sessionId, daemonActivity(command,
|
|
41175
|
+
const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
|
|
41176
|
+
publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
|
|
40875
41177
|
});
|
|
40876
41178
|
const text3 = new CoalescingTextPublisher(
|
|
40877
41179
|
timer,
|
|
@@ -42268,7 +42570,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
42268
42570
|
}
|
|
42269
42571
|
publisher.recordAttempt(sessionId, event, attemptId);
|
|
42270
42572
|
};
|
|
42271
|
-
const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore
|
|
42573
|
+
const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
|
|
42574
|
+
read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
|
|
42575
|
+
});
|
|
42272
42576
|
const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
|
|
42273
42577
|
const installationObserver = new DaemonInstallationObserver();
|
|
42274
42578
|
const diagnostics = new RelayConnectionDiagnostics(audit, config2.channelId, config2.relayUrl);
|