@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/runtime.js
CHANGED
|
@@ -23701,11 +23701,32 @@ function parseNativeHistoryText(text3) {
|
|
|
23701
23701
|
});
|
|
23702
23702
|
return { text: plainText, images };
|
|
23703
23703
|
}
|
|
23704
|
-
var
|
|
23705
|
-
|
|
23704
|
+
var nativeMessageActivitySchema = external_exports.strictObject({
|
|
23705
|
+
activityId: external_exports.string().min(1).max(128),
|
|
23706
|
+
activityType: external_exports.string().min(1).max(128),
|
|
23707
|
+
content: external_exports.array(displayContentSchema).max(100).readonly(),
|
|
23708
|
+
input: external_exports.string().max(1e5),
|
|
23709
|
+
locations: external_exports.array(external_exports.string().min(1).max(2048)).max(100).readonly(),
|
|
23710
|
+
name: external_exports.string().max(128),
|
|
23711
|
+
output: external_exports.string().max(1e5),
|
|
23712
|
+
sequence: external_exports.number().int().nonnegative(),
|
|
23713
|
+
status: external_exports.string().min(1).max(64),
|
|
23714
|
+
title: external_exports.string().max(500),
|
|
23715
|
+
toolKind: external_exports.string().max(64)
|
|
23716
|
+
}).readonly();
|
|
23717
|
+
var userHistoryMessage = external_exports.strictObject({
|
|
23718
|
+
role: external_exports.literal("user"),
|
|
23706
23719
|
text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
|
|
23707
23720
|
images: external_exports.array(historyImage).max(8).readonly().optional()
|
|
23708
23721
|
}).readonly();
|
|
23722
|
+
var assistantHistoryMessage = external_exports.strictObject({
|
|
23723
|
+
activities: external_exports.array(nativeMessageActivitySchema).max(100).readonly().default([]),
|
|
23724
|
+
content: external_exports.array(displayContentSchema).max(100).readonly().default([]),
|
|
23725
|
+
role: external_exports.literal("assistant"),
|
|
23726
|
+
text: external_exports.string().max(SESSION_HISTORY_CHARACTER_LIMIT),
|
|
23727
|
+
images: external_exports.array(historyImage).max(8).readonly().optional()
|
|
23728
|
+
}).readonly();
|
|
23729
|
+
var historyMessage = external_exports.discriminatedUnion("role", [userHistoryMessage, assistantHistoryMessage]);
|
|
23709
23730
|
var availableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
23710
23731
|
status: external_exports.literal("available"),
|
|
23711
23732
|
messages: external_exports.array(historyMessage).max(SESSION_HISTORY_MESSAGE_LIMIT).readonly(),
|
|
@@ -23714,19 +23735,28 @@ var availableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
|
23714
23735
|
coveredMessageIds: external_exports.array(external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}:(?:user|agent)$/)).max(2e4).readonly().default([])
|
|
23715
23736
|
});
|
|
23716
23737
|
var availableSessionHistorySchema = availableSessionHistoryObjectSchema.readonly();
|
|
23717
|
-
var unavailableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
23738
|
+
var unavailableSessionHistoryObjectSchema = external_exports.strictObject({
|
|
23739
|
+
status: external_exports.literal("unavailable"),
|
|
23740
|
+
cause: external_exports.strictObject({
|
|
23741
|
+
code: external_exports.string().regex(/^[a-z][a-z0-9_]{0,127}$/),
|
|
23742
|
+
message: external_exports.string().min(1).max(1e3)
|
|
23743
|
+
}).readonly()
|
|
23744
|
+
});
|
|
23718
23745
|
var unavailableSessionHistorySchema = unavailableSessionHistoryObjectSchema.readonly();
|
|
23719
23746
|
function withinHistoryContentLimits(history) {
|
|
23720
23747
|
if (history.status === "unavailable" || history.messages === void 0) {
|
|
23721
23748
|
return true;
|
|
23722
23749
|
}
|
|
23723
|
-
return history.messages.reduce(
|
|
23750
|
+
return history.messages.reduce(
|
|
23751
|
+
(total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
|
|
23752
|
+
0
|
|
23753
|
+
) <= SESSION_HISTORY_CHARACTER_LIMIT && history.messages.reduce(
|
|
23724
23754
|
(total, message) => total + (message.images ?? []).reduce((size, image) => size + image.data.length, 0),
|
|
23725
23755
|
0
|
|
23726
23756
|
) <= SESSION_HISTORY_IMAGE_CHARACTER_LIMIT;
|
|
23727
23757
|
}
|
|
23728
23758
|
var sessionHistorySchema = external_exports.discriminatedUnion("status", [availableSessionHistorySchema, unavailableSessionHistorySchema]).refine(withinHistoryContentLimits);
|
|
23729
|
-
var
|
|
23759
|
+
var nativeMessagePageSchema = external_exports.discriminatedUnion("status", [
|
|
23730
23760
|
availableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.string().max(512).nullable() }).readonly(),
|
|
23731
23761
|
unavailableSessionHistoryObjectSchema.extend({ nextCursor: external_exports.null() }).readonly()
|
|
23732
23762
|
]).refine(withinHistoryContentLimits);
|
|
@@ -24774,8 +24804,8 @@ function captureActivityDetail(content3, input2, output2) {
|
|
|
24774
24804
|
originalBytes
|
|
24775
24805
|
};
|
|
24776
24806
|
}
|
|
24777
|
-
function recordedDetail(
|
|
24778
|
-
return
|
|
24807
|
+
function recordedDetail(activity2) {
|
|
24808
|
+
return activity2?.detail.kind === "recorded" ? activity2.detail : null;
|
|
24779
24809
|
}
|
|
24780
24810
|
function emptyDisplayContent(type) {
|
|
24781
24811
|
return {
|
|
@@ -24993,7 +25023,7 @@ var AcpActivityTracker = class {
|
|
|
24993
25023
|
const previous2 = this.#activities.get(key);
|
|
24994
25024
|
const identity2 = this.#identity(key);
|
|
24995
25025
|
const fullOutput = `${recordedDetail(previous2)?.output ?? previous2?.output ?? ""}${text3}`;
|
|
24996
|
-
const
|
|
25026
|
+
const activity2 = new AcpActivity(
|
|
24997
25027
|
identity2.id,
|
|
24998
25028
|
activityType,
|
|
24999
25029
|
"",
|
|
@@ -25007,7 +25037,7 @@ var AcpActivityTracker = class {
|
|
|
25007
25037
|
[],
|
|
25008
25038
|
captureActivityDetail([], "", fullOutput)
|
|
25009
25039
|
);
|
|
25010
|
-
await this.#record(key,
|
|
25040
|
+
await this.#record(key, activity2);
|
|
25011
25041
|
this.#activeNarrativeKey = key;
|
|
25012
25042
|
};
|
|
25013
25043
|
recordPlan = async (plan) => {
|
|
@@ -25129,21 +25159,21 @@ var AcpActivityTracker = class {
|
|
|
25129
25159
|
return;
|
|
25130
25160
|
}
|
|
25131
25161
|
this.#activeNarrativeKey = "";
|
|
25132
|
-
const
|
|
25133
|
-
if (
|
|
25162
|
+
const activity2 = this.#activities.get(key);
|
|
25163
|
+
if (activity2 === void 0) {
|
|
25134
25164
|
return;
|
|
25135
25165
|
}
|
|
25136
|
-
const completed =
|
|
25137
|
-
if (completed !==
|
|
25166
|
+
const completed = activity2.complete();
|
|
25167
|
+
if (completed !== activity2) {
|
|
25138
25168
|
await this.#record(key, completed);
|
|
25139
25169
|
}
|
|
25140
25170
|
};
|
|
25141
25171
|
finish = async () => {
|
|
25142
25172
|
await this.finishNarrative();
|
|
25143
25173
|
const entries = [...this.#activities.entries()].sort((left, right) => left[1].sequence - right[1].sequence);
|
|
25144
|
-
for (const [key,
|
|
25145
|
-
const completed =
|
|
25146
|
-
if (completed !==
|
|
25174
|
+
for (const [key, activity2] of entries) {
|
|
25175
|
+
const completed = activity2.complete();
|
|
25176
|
+
if (completed !== activity2) {
|
|
25147
25177
|
await this.#record(key, completed);
|
|
25148
25178
|
}
|
|
25149
25179
|
}
|
|
@@ -25158,9 +25188,9 @@ var AcpActivityTracker = class {
|
|
|
25158
25188
|
this.#identities.set(key, identity2);
|
|
25159
25189
|
return identity2;
|
|
25160
25190
|
};
|
|
25161
|
-
#record = async (key,
|
|
25162
|
-
this.#activities.set(key,
|
|
25163
|
-
await this.#onActivity(
|
|
25191
|
+
#record = async (key, activity2) => {
|
|
25192
|
+
this.#activities.set(key, activity2);
|
|
25193
|
+
await this.#onActivity(activity2);
|
|
25164
25194
|
};
|
|
25165
25195
|
#recordPlanEntries = async (key, entries) => {
|
|
25166
25196
|
const identity2 = this.#identity(key);
|
|
@@ -32788,19 +32818,74 @@ function sessionConfigProtocolForAgent(agentId) {
|
|
|
32788
32818
|
|
|
32789
32819
|
// src/acp/session-history.ts
|
|
32790
32820
|
var AcpHistoryReplay = class {
|
|
32821
|
+
#activities = /* @__PURE__ */ new Map();
|
|
32791
32822
|
#messages = [];
|
|
32823
|
+
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
32824
|
+
#activityTracker = new AcpActivityTracker(async (activity2) => {
|
|
32825
|
+
this.#activities.set(activity2.activityId, activity2);
|
|
32826
|
+
this.#turnActivityIds.add(activity2.activityId);
|
|
32827
|
+
const latest = this.#messages.at(-1);
|
|
32828
|
+
if (latest?.role === "assistant") {
|
|
32829
|
+
this.#messages[this.#messages.length - 1] = {
|
|
32830
|
+
...latest,
|
|
32831
|
+
activityIds: [...this.#turnActivityIds]
|
|
32832
|
+
};
|
|
32833
|
+
}
|
|
32834
|
+
});
|
|
32792
32835
|
#lastMessageId = null;
|
|
32793
32836
|
#characters = 0;
|
|
32794
32837
|
#truncated = false;
|
|
32795
|
-
record = (update) => {
|
|
32838
|
+
record = async (update) => {
|
|
32839
|
+
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
32840
|
+
if (update.content.type === "text") {
|
|
32841
|
+
await this.#activityTracker.recordNarrative(
|
|
32842
|
+
"reasoning",
|
|
32843
|
+
update.messageId ?? "current",
|
|
32844
|
+
update.content.text
|
|
32845
|
+
);
|
|
32846
|
+
}
|
|
32847
|
+
return;
|
|
32848
|
+
}
|
|
32849
|
+
if (update.sessionUpdate === "tool_call") {
|
|
32850
|
+
await this.#activityTracker.recordToolCall(update);
|
|
32851
|
+
return;
|
|
32852
|
+
}
|
|
32853
|
+
if (update.sessionUpdate === "tool_call_update") {
|
|
32854
|
+
await this.#activityTracker.recordToolCallUpdate(update);
|
|
32855
|
+
return;
|
|
32856
|
+
}
|
|
32857
|
+
if (update.sessionUpdate === "plan") {
|
|
32858
|
+
await this.#activityTracker.recordPlan(update);
|
|
32859
|
+
return;
|
|
32860
|
+
}
|
|
32861
|
+
if (update.sessionUpdate === "plan_update") {
|
|
32862
|
+
await this.#activityTracker.recordPlanUpdate(update);
|
|
32863
|
+
return;
|
|
32864
|
+
}
|
|
32865
|
+
if (update.sessionUpdate === "plan_removed") {
|
|
32866
|
+
await this.#activityTracker.removePlan(update);
|
|
32867
|
+
return;
|
|
32868
|
+
}
|
|
32796
32869
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
32797
32870
|
return;
|
|
32798
32871
|
}
|
|
32799
32872
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
32873
|
+
if (update.content.type === "text") {
|
|
32874
|
+
await this.#activityTracker.recordNarrative(
|
|
32875
|
+
"progress",
|
|
32876
|
+
update.messageId ?? "current",
|
|
32877
|
+
update.content.text
|
|
32878
|
+
);
|
|
32879
|
+
}
|
|
32800
32880
|
return;
|
|
32801
32881
|
}
|
|
32802
32882
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
32803
32883
|
const content3 = update.content;
|
|
32884
|
+
if (role === "assistant" && content3.type !== "text") {
|
|
32885
|
+
await this.#activityTracker.finishNarrative();
|
|
32886
|
+
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content3));
|
|
32887
|
+
return;
|
|
32888
|
+
}
|
|
32804
32889
|
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]`;
|
|
32805
32890
|
if (text3.length === 0) {
|
|
32806
32891
|
return;
|
|
@@ -32808,19 +32893,84 @@ var AcpHistoryReplay = class {
|
|
|
32808
32893
|
const previous2 = this.#messages.at(-1);
|
|
32809
32894
|
const id = update.messageId ?? null;
|
|
32810
32895
|
const continuation = previous2?.role === role && id === this.#lastMessageId;
|
|
32896
|
+
if (role === "user" && !continuation) {
|
|
32897
|
+
await this.#activityTracker.finish();
|
|
32898
|
+
this.#turnActivityIds.clear();
|
|
32899
|
+
}
|
|
32811
32900
|
const combined = continuation ? `${previous2.text}${text3}` : text3;
|
|
32812
32901
|
if (continuation) {
|
|
32813
32902
|
this.#messages.pop();
|
|
32814
32903
|
this.#characters -= previous2.text.length;
|
|
32815
32904
|
}
|
|
32816
|
-
const
|
|
32817
|
-
this.#truncated ||=
|
|
32818
|
-
this.#messages.push(
|
|
32819
|
-
role,
|
|
32820
|
-
|
|
32821
|
-
|
|
32822
|
-
|
|
32905
|
+
const bounded2 = combined.slice(-SESSION_HISTORY_CHARACTER_LIMIT);
|
|
32906
|
+
this.#truncated ||= bounded2.length < combined.length;
|
|
32907
|
+
this.#messages.push(
|
|
32908
|
+
role === "user" ? { role, text: bounded2 } : {
|
|
32909
|
+
activityIds: [...this.#turnActivityIds],
|
|
32910
|
+
content: previous2?.role === "assistant" ? previous2.content : [],
|
|
32911
|
+
role,
|
|
32912
|
+
text: bounded2
|
|
32913
|
+
}
|
|
32914
|
+
);
|
|
32915
|
+
this.#characters += bounded2.length;
|
|
32823
32916
|
this.#lastMessageId = id;
|
|
32917
|
+
this.trimMessages();
|
|
32918
|
+
};
|
|
32919
|
+
snapshot = async () => {
|
|
32920
|
+
await this.#activityTracker.finish();
|
|
32921
|
+
return {
|
|
32922
|
+
status: "available",
|
|
32923
|
+
messages: this.#messages.map(
|
|
32924
|
+
(message) => message.role === "user" ? message : {
|
|
32925
|
+
role: "assistant",
|
|
32926
|
+
text: message.text,
|
|
32927
|
+
content: message.content,
|
|
32928
|
+
activities: message.activityIds.flatMap((id) => {
|
|
32929
|
+
const activity2 = this.#activities.get(id);
|
|
32930
|
+
return activity2 === void 0 ? [] : [
|
|
32931
|
+
{
|
|
32932
|
+
activityId: activity2.activityId,
|
|
32933
|
+
activityType: activity2.activityType,
|
|
32934
|
+
content: activity2.content,
|
|
32935
|
+
input: activity2.input,
|
|
32936
|
+
locations: activity2.locations,
|
|
32937
|
+
name: activity2.name,
|
|
32938
|
+
output: activity2.output,
|
|
32939
|
+
sequence: activity2.sequence,
|
|
32940
|
+
status: activity2.status,
|
|
32941
|
+
title: activity2.title,
|
|
32942
|
+
toolKind: activity2.toolKind
|
|
32943
|
+
}
|
|
32944
|
+
];
|
|
32945
|
+
})
|
|
32946
|
+
}
|
|
32947
|
+
),
|
|
32948
|
+
truncated: this.#truncated,
|
|
32949
|
+
coveredCommandIds: [],
|
|
32950
|
+
coveredMessageIds: []
|
|
32951
|
+
};
|
|
32952
|
+
};
|
|
32953
|
+
recordAssistantContent = (messageId, content3) => {
|
|
32954
|
+
const previous2 = this.#messages.at(-1);
|
|
32955
|
+
const continuation = previous2?.role === "assistant" && messageId === this.#lastMessageId;
|
|
32956
|
+
if (continuation) {
|
|
32957
|
+
this.#messages[this.#messages.length - 1] = {
|
|
32958
|
+
...previous2,
|
|
32959
|
+
activityIds: [...this.#turnActivityIds],
|
|
32960
|
+
content: [...previous2.content, content3]
|
|
32961
|
+
};
|
|
32962
|
+
} else {
|
|
32963
|
+
this.#messages.push({
|
|
32964
|
+
activityIds: [...this.#turnActivityIds],
|
|
32965
|
+
content: [content3],
|
|
32966
|
+
role: "assistant",
|
|
32967
|
+
text: ""
|
|
32968
|
+
});
|
|
32969
|
+
}
|
|
32970
|
+
this.#lastMessageId = messageId;
|
|
32971
|
+
this.trimMessages();
|
|
32972
|
+
};
|
|
32973
|
+
trimMessages = () => {
|
|
32824
32974
|
while (this.#messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || this.#characters > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
32825
32975
|
const removed = this.#messages.shift();
|
|
32826
32976
|
if (removed !== void 0) {
|
|
@@ -32829,13 +32979,6 @@ var AcpHistoryReplay = class {
|
|
|
32829
32979
|
this.#truncated = true;
|
|
32830
32980
|
}
|
|
32831
32981
|
};
|
|
32832
|
-
snapshot = () => ({
|
|
32833
|
-
status: "available",
|
|
32834
|
-
messages: [...this.#messages],
|
|
32835
|
-
truncated: this.#truncated,
|
|
32836
|
-
coveredCommandIds: [],
|
|
32837
|
-
coveredMessageIds: []
|
|
32838
|
-
});
|
|
32839
32982
|
};
|
|
32840
32983
|
|
|
32841
32984
|
// src/acp/session-store.ts
|
|
@@ -33761,7 +33904,13 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
33761
33904
|
);
|
|
33762
33905
|
loadHistory = async (signal) => {
|
|
33763
33906
|
if (!this.#capabilities.loadSession) {
|
|
33764
|
-
return {
|
|
33907
|
+
return {
|
|
33908
|
+
status: "unavailable",
|
|
33909
|
+
cause: {
|
|
33910
|
+
code: "native_history_unsupported",
|
|
33911
|
+
message: "This Agent restores context but does not provide message history."
|
|
33912
|
+
}
|
|
33913
|
+
};
|
|
33765
33914
|
}
|
|
33766
33915
|
const history = new AcpHistoryReplay();
|
|
33767
33916
|
this.#replay = { kind: "capture", history };
|
|
@@ -33782,7 +33931,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
33782
33931
|
);
|
|
33783
33932
|
await this.#updateTail;
|
|
33784
33933
|
signal.throwIfAborted();
|
|
33785
|
-
return await embedLocalHistoryImages(history.snapshot(), signal);
|
|
33934
|
+
return await embedLocalHistoryImages(await history.snapshot(), signal);
|
|
33786
33935
|
} finally {
|
|
33787
33936
|
this.#replay = { kind: "idle" };
|
|
33788
33937
|
}
|
|
@@ -34626,7 +34775,7 @@ var AcpProcessSession = class _AcpProcessSession {
|
|
|
34626
34775
|
this.assertNativeSession(notification.sessionId);
|
|
34627
34776
|
const update = notification.update;
|
|
34628
34777
|
if (this.#replay.kind === "capture") {
|
|
34629
|
-
this.#replay.history.record(update);
|
|
34778
|
+
await this.#replay.history.record(update);
|
|
34630
34779
|
}
|
|
34631
34780
|
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")) {
|
|
34632
34781
|
return;
|
|
@@ -34917,10 +35066,12 @@ var AcpSessionManager = class {
|
|
|
34917
35066
|
#startingProcessCount = 0;
|
|
34918
35067
|
#transientProcessCount = 0;
|
|
34919
35068
|
#store;
|
|
35069
|
+
#nativeHistoryReader;
|
|
34920
35070
|
#observer;
|
|
34921
|
-
constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore()) {
|
|
35071
|
+
constructor(observer = new NullAcpSessionObserver(), store = new MemoryAcpSessionStore(), nativeHistoryReader = null) {
|
|
34922
35072
|
this.#observer = observer;
|
|
34923
35073
|
this.#store = store;
|
|
35074
|
+
this.#nativeHistoryReader = nativeHistoryReader;
|
|
34924
35075
|
}
|
|
34925
35076
|
setObserver = (observer) => {
|
|
34926
35077
|
this.#observer = observer;
|
|
@@ -35682,7 +35833,15 @@ var AcpSessionManager = class {
|
|
|
35682
35833
|
loadSessionHistory = async (options) => {
|
|
35683
35834
|
this.#beginSessionUse(options.sessionId);
|
|
35684
35835
|
try {
|
|
35685
|
-
|
|
35836
|
+
const runtime = await this.ensureSession(options);
|
|
35837
|
+
const stored = this.#store.read(options.sessionId);
|
|
35838
|
+
if (stored instanceof FoundAcpStoredSession && this.#nativeHistoryReader !== null) {
|
|
35839
|
+
const history = await this.#nativeHistoryReader.read(options, stored.session.nativeSessionId);
|
|
35840
|
+
if (history !== null) {
|
|
35841
|
+
return history;
|
|
35842
|
+
}
|
|
35843
|
+
}
|
|
35844
|
+
return await runtime.loadHistory(options.signal);
|
|
35686
35845
|
} finally {
|
|
35687
35846
|
this.#endSessionUse(options.sessionId);
|
|
35688
35847
|
}
|
|
@@ -36898,10 +37057,6 @@ var WorkspaceDirectoryService = class {
|
|
|
36898
37057
|
};
|
|
36899
37058
|
};
|
|
36900
37059
|
|
|
36901
|
-
// src/native-sessions/service.ts
|
|
36902
|
-
import { randomUUID } from "node:crypto";
|
|
36903
|
-
import { basename as basename5 } from "node:path";
|
|
36904
|
-
|
|
36905
37060
|
// src/native-sessions/codex-history.ts
|
|
36906
37061
|
import { spawn as spawn4 } from "node:child_process";
|
|
36907
37062
|
var responseSchema = external_exports.union([
|
|
@@ -36919,7 +37074,12 @@ var threadSchema = external_exports.object({
|
|
|
36919
37074
|
})
|
|
36920
37075
|
});
|
|
36921
37076
|
var turnsSchema = external_exports.object({
|
|
36922
|
-
data: external_exports.array(
|
|
37077
|
+
data: external_exports.array(
|
|
37078
|
+
external_exports.object({
|
|
37079
|
+
error: external_exports.unknown().nullish(),
|
|
37080
|
+
items: external_exports.array(external_exports.unknown()).max(1e5)
|
|
37081
|
+
})
|
|
37082
|
+
).max(SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT),
|
|
36923
37083
|
nextCursor: external_exports.string().nullish()
|
|
36924
37084
|
});
|
|
36925
37085
|
var itemTypeSchema = external_exports.object({ type: external_exports.string().min(1).max(80) });
|
|
@@ -36929,12 +37089,62 @@ var userMessageSchema = external_exports.object({
|
|
|
36929
37089
|
var textSchema = external_exports.object({ text: external_exports.string() });
|
|
36930
37090
|
var imageSchema = external_exports.object({ url: external_exports.string() });
|
|
36931
37091
|
var agentMessageSchema = textSchema.extend({ phase: external_exports.string().nullish() });
|
|
36932
|
-
|
|
37092
|
+
var reasoningSchema = external_exports.object({
|
|
37093
|
+
id: external_exports.string(),
|
|
37094
|
+
summary: external_exports.array(external_exports.string()).max(1e4),
|
|
37095
|
+
content: external_exports.array(external_exports.string()).max(1e4)
|
|
37096
|
+
});
|
|
37097
|
+
var commandExecutionSchema = external_exports.object({
|
|
37098
|
+
id: external_exports.string(),
|
|
37099
|
+
command: external_exports.string(),
|
|
37100
|
+
cwd: external_exports.string(),
|
|
37101
|
+
status: external_exports.string(),
|
|
37102
|
+
commandActions: external_exports.array(external_exports.object({ type: external_exports.string() }).passthrough()).max(100),
|
|
37103
|
+
aggregatedOutput: external_exports.string().nullish(),
|
|
37104
|
+
exitCode: external_exports.number().int().nullish()
|
|
37105
|
+
});
|
|
37106
|
+
function bounded(value, maximum) {
|
|
37107
|
+
return value.slice(0, maximum);
|
|
37108
|
+
}
|
|
37109
|
+
function activity(activityId, activityType, sequence, fields) {
|
|
37110
|
+
return {
|
|
37111
|
+
activityId: bounded(activityId, 128) || `history-${sequence.toString()}`,
|
|
37112
|
+
activityType,
|
|
37113
|
+
content: [],
|
|
37114
|
+
input: bounded(fields.input, 1e5),
|
|
37115
|
+
locations: fields.locations.filter((location) => location.length > 0).map((location) => bounded(location, 2048)).slice(0, 100),
|
|
37116
|
+
name: bounded(fields.name, 128),
|
|
37117
|
+
output: bounded(fields.output, 1e5),
|
|
37118
|
+
sequence,
|
|
37119
|
+
status: bounded(fields.status, 64),
|
|
37120
|
+
title: bounded(fields.title, 500),
|
|
37121
|
+
toolKind: bounded(fields.toolKind, 64)
|
|
37122
|
+
};
|
|
37123
|
+
}
|
|
37124
|
+
function errorMessage(value) {
|
|
37125
|
+
if (typeof value === "string") {
|
|
37126
|
+
return value;
|
|
37127
|
+
}
|
|
37128
|
+
if (typeof value === "object" && value !== null) {
|
|
37129
|
+
const message = Reflect.get(value, "message");
|
|
37130
|
+
if (typeof message === "string") {
|
|
37131
|
+
return message;
|
|
37132
|
+
}
|
|
37133
|
+
}
|
|
37134
|
+
return JSON.stringify(value) ?? "Codex stopped before completing this turn.";
|
|
37135
|
+
}
|
|
37136
|
+
function messageSize(message) {
|
|
37137
|
+
return message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0);
|
|
37138
|
+
}
|
|
37139
|
+
function decodeHistory(thread, value, options) {
|
|
36933
37140
|
const page = turnsSchema.parse(value);
|
|
36934
37141
|
const messages = [];
|
|
36935
37142
|
let characters = 0;
|
|
36936
37143
|
let truncated = page.nextCursor != null;
|
|
36937
37144
|
for (const turn of page.data.toReversed()) {
|
|
37145
|
+
const activities = [];
|
|
37146
|
+
let sequence = 0;
|
|
37147
|
+
let assistantMessageIndex = null;
|
|
36938
37148
|
for (const item of turn.items) {
|
|
36939
37149
|
const { type } = itemTypeSchema.parse(item);
|
|
36940
37150
|
let message;
|
|
@@ -36957,9 +37167,60 @@ function decodeHistory(thread, value) {
|
|
|
36957
37167
|
} else if (type === "agentMessage") {
|
|
36958
37168
|
const agent = agentMessageSchema.parse(item);
|
|
36959
37169
|
if (agent.phase === "commentary") {
|
|
37170
|
+
if (options.detail === "rich" && agent.text.length > 0) {
|
|
37171
|
+
activities.push(
|
|
37172
|
+
activity(`progress-${sequence.toString()}`, "progress", sequence, {
|
|
37173
|
+
input: "",
|
|
37174
|
+
locations: [],
|
|
37175
|
+
name: "",
|
|
37176
|
+
output: agent.text,
|
|
37177
|
+
status: "completed",
|
|
37178
|
+
title: "Progress",
|
|
37179
|
+
toolKind: ""
|
|
37180
|
+
})
|
|
37181
|
+
);
|
|
37182
|
+
sequence += 1;
|
|
37183
|
+
}
|
|
36960
37184
|
continue;
|
|
36961
37185
|
}
|
|
36962
|
-
message = { role: "assistant", text: agent.text };
|
|
37186
|
+
message = { activities: activities.slice(-100), content: [], role: "assistant", text: agent.text };
|
|
37187
|
+
} else if (type === "reasoning" && options.detail === "rich") {
|
|
37188
|
+
const reasoning = reasoningSchema.parse(item);
|
|
37189
|
+
const output2 = (reasoning.summary.length > 0 ? reasoning.summary : reasoning.content).join("\n\n");
|
|
37190
|
+
if (output2.length > 0) {
|
|
37191
|
+
activities.push(
|
|
37192
|
+
activity(reasoning.id, "reasoning", sequence, {
|
|
37193
|
+
input: "",
|
|
37194
|
+
locations: [],
|
|
37195
|
+
name: "",
|
|
37196
|
+
output: output2,
|
|
37197
|
+
status: "completed",
|
|
37198
|
+
title: "Reasoning",
|
|
37199
|
+
toolKind: ""
|
|
37200
|
+
})
|
|
37201
|
+
);
|
|
37202
|
+
sequence += 1;
|
|
37203
|
+
}
|
|
37204
|
+
continue;
|
|
37205
|
+
} else if (type === "commandExecution" && options.detail === "rich") {
|
|
37206
|
+
const command = commandExecutionSchema.parse(item);
|
|
37207
|
+
const action = command.commandActions[0]?.type ?? "execute";
|
|
37208
|
+
activities.push(
|
|
37209
|
+
activity(command.id, "tool", sequence, {
|
|
37210
|
+
input: JSON.stringify({ command: command.command, cwd: command.cwd }),
|
|
37211
|
+
locations: [command.cwd],
|
|
37212
|
+
name: "",
|
|
37213
|
+
output: JSON.stringify({
|
|
37214
|
+
formatted_output: command.aggregatedOutput ?? "",
|
|
37215
|
+
...command.exitCode == null ? {} : { exit_code: command.exitCode }
|
|
37216
|
+
}),
|
|
37217
|
+
status: command.status === "completed" ? "completed" : "failed",
|
|
37218
|
+
title: command.command,
|
|
37219
|
+
toolKind: action
|
|
37220
|
+
})
|
|
37221
|
+
);
|
|
37222
|
+
sequence += 1;
|
|
37223
|
+
continue;
|
|
36963
37224
|
} else {
|
|
36964
37225
|
continue;
|
|
36965
37226
|
}
|
|
@@ -36969,14 +37230,48 @@ function decodeHistory(thread, value) {
|
|
|
36969
37230
|
}
|
|
36970
37231
|
truncated ||= text3.length < message.text.length;
|
|
36971
37232
|
messages.push({ ...message, text: text3 });
|
|
36972
|
-
|
|
36973
|
-
|
|
36974
|
-
|
|
36975
|
-
|
|
36976
|
-
|
|
36977
|
-
|
|
36978
|
-
|
|
37233
|
+
if (message.role === "assistant") {
|
|
37234
|
+
assistantMessageIndex = messages.length - 1;
|
|
37235
|
+
}
|
|
37236
|
+
characters += messageSize({ ...message, text: text3 });
|
|
37237
|
+
}
|
|
37238
|
+
if (options.detail === "rich" && turn.error != null) {
|
|
37239
|
+
activities.push(
|
|
37240
|
+
activity(`agent-error-${sequence.toString()}`, "tool", sequence, {
|
|
37241
|
+
input: "",
|
|
37242
|
+
locations: [],
|
|
37243
|
+
name: "",
|
|
37244
|
+
output: errorMessage(turn.error),
|
|
37245
|
+
status: "failed",
|
|
37246
|
+
title: "Agent error",
|
|
37247
|
+
toolKind: "other"
|
|
37248
|
+
})
|
|
37249
|
+
);
|
|
37250
|
+
}
|
|
37251
|
+
if (assistantMessageIndex !== null) {
|
|
37252
|
+
const assistant = messages[assistantMessageIndex];
|
|
37253
|
+
if (assistant?.role === "assistant") {
|
|
37254
|
+
characters -= messageSize(assistant);
|
|
37255
|
+
const updated = { ...assistant, activities: activities.slice(-100) };
|
|
37256
|
+
messages[assistantMessageIndex] = updated;
|
|
37257
|
+
characters += messageSize(updated);
|
|
37258
|
+
}
|
|
37259
|
+
} else if (activities.length > 0) {
|
|
37260
|
+
const message = {
|
|
37261
|
+
activities: activities.slice(-100),
|
|
37262
|
+
content: [],
|
|
37263
|
+
role: "assistant",
|
|
37264
|
+
text: ""
|
|
37265
|
+
};
|
|
37266
|
+
messages.push(message);
|
|
37267
|
+
characters += messageSize(message);
|
|
37268
|
+
}
|
|
37269
|
+
while (messages.length > SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT || characters > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
37270
|
+
const removed = messages.shift();
|
|
37271
|
+
if (removed !== void 0) {
|
|
37272
|
+
characters -= messageSize(removed);
|
|
36979
37273
|
}
|
|
37274
|
+
truncated = true;
|
|
36980
37275
|
}
|
|
36981
37276
|
}
|
|
36982
37277
|
return {
|
|
@@ -36991,7 +37286,7 @@ function decodeHistory(thread, value) {
|
|
|
36991
37286
|
}
|
|
36992
37287
|
};
|
|
36993
37288
|
}
|
|
36994
|
-
async function
|
|
37289
|
+
async function readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, options) {
|
|
36995
37290
|
signal.throwIfAborted();
|
|
36996
37291
|
nativeSessionIdSchema.parse(nativeSessionId);
|
|
36997
37292
|
if (agent.id !== "codex" || !await revalidateExecutable(agent.agentIdentity)) {
|
|
@@ -37085,13 +37380,13 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
|
|
|
37085
37380
|
threadId: nativeSessionId,
|
|
37086
37381
|
limit: SESSION_HISTORY_PREVIEW_MESSAGE_LIMIT,
|
|
37087
37382
|
sortDirection: "desc",
|
|
37088
|
-
itemsView: "summary"
|
|
37383
|
+
itemsView: options.detail === "rich" ? "full" : "summary"
|
|
37089
37384
|
}
|
|
37090
37385
|
});
|
|
37091
37386
|
break;
|
|
37092
37387
|
}
|
|
37093
37388
|
case "turns":
|
|
37094
|
-
response.resolve(decodeHistory(state.thread, message.result));
|
|
37389
|
+
response.resolve(decodeHistory(state.thread, message.result, options));
|
|
37095
37390
|
return;
|
|
37096
37391
|
default: {
|
|
37097
37392
|
const unhandled = state;
|
|
@@ -37148,8 +37443,12 @@ async function readCodexHistory(agent, cwd, nativeSessionId, signal) {
|
|
|
37148
37443
|
child.removeListener("exit", onExit);
|
|
37149
37444
|
}
|
|
37150
37445
|
}
|
|
37446
|
+
var readCodexHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "messages" });
|
|
37447
|
+
var readCodexFullHistory = async (agent, cwd, nativeSessionId, signal) => await readCodexHistoryWithOptions(agent, cwd, nativeSessionId, signal, { detail: "rich" });
|
|
37151
37448
|
|
|
37152
37449
|
// src/native-sessions/service.ts
|
|
37450
|
+
import { randomUUID } from "node:crypto";
|
|
37451
|
+
import { basename as basename5 } from "node:path";
|
|
37153
37452
|
var NativeSessionService = class {
|
|
37154
37453
|
#entries = /* @__PURE__ */ new Map();
|
|
37155
37454
|
#cursors = /* @__PURE__ */ new Map();
|
|
@@ -39272,28 +39571,28 @@ var CoalescingDaemonActivityPublisher = class {
|
|
|
39272
39571
|
}
|
|
39273
39572
|
this.#pending.clear();
|
|
39274
39573
|
this.#scheduled.clear();
|
|
39275
|
-
for (const
|
|
39276
|
-
this.#publish(
|
|
39574
|
+
for (const activity2 of activities) {
|
|
39575
|
+
this.#publish(activity2);
|
|
39277
39576
|
}
|
|
39278
39577
|
};
|
|
39279
|
-
record = (
|
|
39280
|
-
if (
|
|
39281
|
-
this.#discardPending(
|
|
39282
|
-
this.#publishedActivityIds.add(
|
|
39283
|
-
this.#publish(
|
|
39578
|
+
record = (activity2) => {
|
|
39579
|
+
if (activity2.status !== "pending" && activity2.status !== "running") {
|
|
39580
|
+
this.#discardPending(activity2.activityId);
|
|
39581
|
+
this.#publishedActivityIds.add(activity2.activityId);
|
|
39582
|
+
this.#publish(activity2);
|
|
39284
39583
|
return Promise.resolve();
|
|
39285
39584
|
}
|
|
39286
|
-
if (!this.#publishedActivityIds.has(
|
|
39287
|
-
this.#publishedActivityIds.add(
|
|
39288
|
-
this.#publish(
|
|
39585
|
+
if (!this.#publishedActivityIds.has(activity2.activityId)) {
|
|
39586
|
+
this.#publishedActivityIds.add(activity2.activityId);
|
|
39587
|
+
this.#publish(activity2);
|
|
39289
39588
|
return Promise.resolve();
|
|
39290
39589
|
}
|
|
39291
|
-
this.#pending.set(
|
|
39292
|
-
if (!this.#scheduled.has(
|
|
39590
|
+
this.#pending.set(activity2.activityId, activity2);
|
|
39591
|
+
if (!this.#scheduled.has(activity2.activityId)) {
|
|
39293
39592
|
this.#scheduled.set(
|
|
39294
|
-
|
|
39593
|
+
activity2.activityId,
|
|
39295
39594
|
this.#timer.schedule(
|
|
39296
|
-
() => this.#flushActivity(
|
|
39595
|
+
() => this.#flushActivity(activity2.activityId),
|
|
39297
39596
|
AGENT_ACTIVITY_COALESCING_MILLISECONDS
|
|
39298
39597
|
)
|
|
39299
39598
|
);
|
|
@@ -39306,30 +39605,30 @@ var CoalescingDaemonActivityPublisher = class {
|
|
|
39306
39605
|
this.#pending.delete(activityId);
|
|
39307
39606
|
};
|
|
39308
39607
|
#flushActivity = (activityId) => {
|
|
39309
|
-
const
|
|
39608
|
+
const activity2 = this.#pending.get(activityId);
|
|
39310
39609
|
this.#discardPending(activityId);
|
|
39311
|
-
if (
|
|
39312
|
-
this.#publish(
|
|
39610
|
+
if (activity2 !== void 0) {
|
|
39611
|
+
this.#publish(activity2);
|
|
39313
39612
|
}
|
|
39314
39613
|
};
|
|
39315
39614
|
};
|
|
39316
|
-
function daemonActivity(command,
|
|
39615
|
+
function daemonActivity(command, activity2) {
|
|
39317
39616
|
return {
|
|
39318
|
-
activityId:
|
|
39319
|
-
activityType:
|
|
39617
|
+
activityId: activity2.activityId,
|
|
39618
|
+
activityType: activity2.activityType,
|
|
39320
39619
|
commandId: command.commandId,
|
|
39321
|
-
content:
|
|
39322
|
-
detail:
|
|
39323
|
-
input:
|
|
39620
|
+
content: activity2.content,
|
|
39621
|
+
detail: activity2.detail,
|
|
39622
|
+
input: activity2.input,
|
|
39324
39623
|
kind: AGENT_ACTIVITY_KIND,
|
|
39325
|
-
locations:
|
|
39326
|
-
name:
|
|
39327
|
-
output:
|
|
39328
|
-
sequence:
|
|
39624
|
+
locations: activity2.locations,
|
|
39625
|
+
name: activity2.name,
|
|
39626
|
+
output: activity2.output,
|
|
39627
|
+
sequence: activity2.sequence,
|
|
39329
39628
|
sessionId: command.sessionId,
|
|
39330
|
-
status:
|
|
39331
|
-
title:
|
|
39332
|
-
toolKind:
|
|
39629
|
+
status: activity2.status,
|
|
39630
|
+
title: activity2.title,
|
|
39631
|
+
toolKind: activity2.toolKind
|
|
39333
39632
|
};
|
|
39334
39633
|
}
|
|
39335
39634
|
function reportFailure(publisher, command, code, message, attemptId) {
|
|
@@ -39828,7 +40127,10 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
|
|
|
39828
40127
|
sessionId: command.sessionId
|
|
39829
40128
|
});
|
|
39830
40129
|
send(socket, {
|
|
39831
|
-
history: {
|
|
40130
|
+
history: {
|
|
40131
|
+
status: "unavailable",
|
|
40132
|
+
cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) }
|
|
40133
|
+
},
|
|
39832
40134
|
kind: "session.live-history.loaded",
|
|
39833
40135
|
requestId: command.requestId,
|
|
39834
40136
|
sessionId: command.sessionId
|
|
@@ -39875,8 +40177,8 @@ async function executeSessionConfigure(publisher, socket, command, config2, dire
|
|
|
39875
40177
|
}
|
|
39876
40178
|
}
|
|
39877
40179
|
async function executePrompt(outbox, publisher, command, config2, directories, audit, sessions, attemptId, activateAttempt, timer, signal) {
|
|
39878
|
-
const activities = new CoalescingDaemonActivityPublisher(timer, (
|
|
39879
|
-
publisher.recordAttempt(command.sessionId, daemonActivity(command,
|
|
40180
|
+
const activities = new CoalescingDaemonActivityPublisher(timer, (activity2) => {
|
|
40181
|
+
publisher.recordAttempt(command.sessionId, daemonActivity(command, activity2), attemptId);
|
|
39880
40182
|
});
|
|
39881
40183
|
const text3 = new CoalescingTextPublisher(
|
|
39882
40184
|
timer,
|
|
@@ -41273,7 +41575,9 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
41273
41575
|
}
|
|
41274
41576
|
publisher.recordAttempt(sessionId, event, attemptId);
|
|
41275
41577
|
};
|
|
41276
|
-
const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore
|
|
41578
|
+
const sessions = new AcpSessionManager(new DaemonAcpObserver(recordSessionEvent), sessionStore, {
|
|
41579
|
+
read: async (options2, nativeSessionId) => options2.agent.id === "codex" ? (await readCodexFullHistory(options2.agent, options2.cwd, nativeSessionId, options2.signal)).history : null
|
|
41580
|
+
});
|
|
41277
41581
|
const directories = new WorkspaceDirectoryService(config2.bindingId, config2.defaultWorkspace);
|
|
41278
41582
|
const installationObserver = new DaemonInstallationObserver();
|
|
41279
41583
|
const diagnostics = new RelayConnectionDiagnostics(audit, config2.channelId, config2.relayUrl);
|