@moxt-ai/mobius 0.0.78 → 0.0.79
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.map +1 -1
- package/dist/acp/session-history.js +62 -27
- package/dist/acp/session-history.js.map +1 -1
- package/dist/cli.js +222 -26
- package/dist/cli.js.map +2 -2
- package/dist/index.js +221 -25
- package/dist/index.js.map +2 -2
- package/dist/run-daemon.d.ts.map +1 -1
- package/dist/run-daemon.js +131 -1
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +221 -25
- package/dist/runtime.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21256,6 +21256,8 @@ var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSession
|
|
|
21256
21256
|
// ../protocol/src/session-live-history.ts
|
|
21257
21257
|
var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
|
|
21258
21258
|
var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
|
|
21259
|
+
var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
|
|
21260
|
+
var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
|
|
21259
21261
|
var identifier2 = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/);
|
|
21260
21262
|
var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
|
|
21261
21263
|
var sessionLiveHistoryLoadSchema = external_exports.strictObject({
|
|
@@ -21273,6 +21275,23 @@ var sessionLiveHistoryLoadedSchema = external_exports.strictObject({
|
|
|
21273
21275
|
requestId: identifier2,
|
|
21274
21276
|
sessionId: identifier2
|
|
21275
21277
|
}).readonly();
|
|
21278
|
+
var sessionLiveHistoryPageLoadSchema = external_exports.strictObject({
|
|
21279
|
+
additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
|
|
21280
|
+
agentId: identifier2,
|
|
21281
|
+
bindingId: identifier2,
|
|
21282
|
+
cursor: external_exports.string().min(1).max(512).nullable(),
|
|
21283
|
+
directoryId: directoryIdentifier,
|
|
21284
|
+
kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOAD_KIND),
|
|
21285
|
+
limit: external_exports.number().int().min(1).max(100),
|
|
21286
|
+
requestId: identifier2,
|
|
21287
|
+
sessionId: identifier2
|
|
21288
|
+
}).readonly();
|
|
21289
|
+
var sessionLiveHistoryPageLoadedSchema = external_exports.strictObject({
|
|
21290
|
+
kind: external_exports.literal(SESSION_LIVE_HISTORY_PAGE_LOADED_KIND),
|
|
21291
|
+
page: nativeMessagePageSchema,
|
|
21292
|
+
requestId: identifier2,
|
|
21293
|
+
sessionId: identifier2
|
|
21294
|
+
}).readonly();
|
|
21276
21295
|
function decode6(schema, encoded) {
|
|
21277
21296
|
try {
|
|
21278
21297
|
const value = JSON.parse(encoded);
|
|
@@ -21285,6 +21304,10 @@ var decodeSessionLiveHistoryLoad = (encoded) => decode6(sessionLiveHistoryLoadSc
|
|
|
21285
21304
|
var decodeSessionLiveHistoryLoaded = (encoded) => decode6(sessionLiveHistoryLoadedSchema, encoded);
|
|
21286
21305
|
var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
|
|
21287
21306
|
var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
|
|
21307
|
+
var decodeSessionLiveHistoryPageLoad = (encoded) => decode6(sessionLiveHistoryPageLoadSchema, encoded);
|
|
21308
|
+
var decodeSessionLiveHistoryPageLoaded = (encoded) => decode6(sessionLiveHistoryPageLoadedSchema, encoded);
|
|
21309
|
+
var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
|
|
21310
|
+
var encodeSessionLiveHistoryPageLoaded = (value) => JSON.stringify(sessionLiveHistoryPageLoadedSchema.parse(value));
|
|
21288
21311
|
|
|
21289
21312
|
// ../protocol/src/daemon-transport.ts
|
|
21290
21313
|
function defineMessageSignature(kind, encoder, decoder) {
|
|
@@ -21388,6 +21411,11 @@ var serviceToDaemonSignatures = {
|
|
|
21388
21411
|
encodeSessionLiveHistoryLoad,
|
|
21389
21412
|
decodeSessionLiveHistoryLoad
|
|
21390
21413
|
),
|
|
21414
|
+
[SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
|
|
21415
|
+
SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
|
|
21416
|
+
encodeSessionLiveHistoryPageLoad,
|
|
21417
|
+
decodeSessionLiveHistoryPageLoad
|
|
21418
|
+
),
|
|
21391
21419
|
[SESSION_PERMISSION_RESPOND_KIND]: defineMessageSignature(
|
|
21392
21420
|
SESSION_PERMISSION_RESPOND_KIND,
|
|
21393
21421
|
encodeSessionPermissionRespondCommand,
|
|
@@ -21498,6 +21526,11 @@ var daemonToServiceSignatures = {
|
|
|
21498
21526
|
encodeSessionLiveHistoryLoaded,
|
|
21499
21527
|
decodeSessionLiveHistoryLoaded
|
|
21500
21528
|
),
|
|
21529
|
+
[SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
|
|
21530
|
+
SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
|
|
21531
|
+
encodeSessionLiveHistoryPageLoaded,
|
|
21532
|
+
decodeSessionLiveHistoryPageLoaded
|
|
21533
|
+
),
|
|
21501
21534
|
[SESSION_READY_KIND]: defineMessageSignature(SESSION_READY_KIND, encodeSessionReadyEvent, decodeSessionReadyEvent),
|
|
21502
21535
|
[WORKSPACE_ENTRIES_KIND]: defineMessageSignature(
|
|
21503
21536
|
WORKSPACE_ENTRIES_KIND,
|
|
@@ -30876,6 +30909,29 @@ function sessionConfigProtocolForAgent(agentId) {
|
|
|
30876
30909
|
}
|
|
30877
30910
|
|
|
30878
30911
|
// src/acp/session-history.ts
|
|
30912
|
+
var HISTORY_ACTIVITY_FIELD_LIMIT = 1e5;
|
|
30913
|
+
var HISTORY_ACTIVITY_LIMIT = 100;
|
|
30914
|
+
function historyActivity(activity2) {
|
|
30915
|
+
return {
|
|
30916
|
+
activityId: activity2.activityId.slice(0, 128),
|
|
30917
|
+
activityType: activity2.activityType.slice(0, 128),
|
|
30918
|
+
content: activity2.content.slice(0, 100),
|
|
30919
|
+
input: activity2.input.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
|
|
30920
|
+
locations: activity2.locations.slice(0, 100).map((location) => location.slice(0, 2048)),
|
|
30921
|
+
name: activity2.name.slice(0, 128),
|
|
30922
|
+
output: activity2.output.slice(0, HISTORY_ACTIVITY_FIELD_LIMIT),
|
|
30923
|
+
sequence: activity2.sequence,
|
|
30924
|
+
status: activity2.status.slice(0, 64),
|
|
30925
|
+
title: activity2.title.slice(0, 500),
|
|
30926
|
+
toolKind: activity2.toolKind.slice(0, 64)
|
|
30927
|
+
};
|
|
30928
|
+
}
|
|
30929
|
+
function historyContentCharacters(messages) {
|
|
30930
|
+
return messages.reduce(
|
|
30931
|
+
(total, message) => total + message.text.length + (message.role === "assistant" ? JSON.stringify(message.activities).length + JSON.stringify(message.content).length : 0),
|
|
30932
|
+
0
|
|
30933
|
+
);
|
|
30934
|
+
}
|
|
30879
30935
|
var AcpHistoryReplay = class {
|
|
30880
30936
|
#activities = /* @__PURE__ */ new Map();
|
|
30881
30937
|
#messages = [];
|
|
@@ -30982,33 +31038,45 @@ var AcpHistoryReplay = class {
|
|
|
30982
31038
|
};
|
|
30983
31039
|
snapshot = async () => {
|
|
30984
31040
|
await this.#activityTracker.finish();
|
|
31041
|
+
const messages = this.#messages.map((message) => {
|
|
31042
|
+
if (message.role === "user") {
|
|
31043
|
+
return message;
|
|
31044
|
+
}
|
|
31045
|
+
const activities = message.activityIds.flatMap((id) => {
|
|
31046
|
+
const activity2 = this.#activities.get(id);
|
|
31047
|
+
return activity2 === void 0 ? [] : [historyActivity(activity2)];
|
|
31048
|
+
});
|
|
31049
|
+
if (activities.length > HISTORY_ACTIVITY_LIMIT) {
|
|
31050
|
+
this.#truncated = true;
|
|
31051
|
+
}
|
|
31052
|
+
return {
|
|
31053
|
+
role: "assistant",
|
|
31054
|
+
text: message.text,
|
|
31055
|
+
content: message.content.slice(0, 100),
|
|
31056
|
+
activities: activities.slice(-HISTORY_ACTIVITY_LIMIT)
|
|
31057
|
+
};
|
|
31058
|
+
});
|
|
31059
|
+
while (historyContentCharacters(messages) > SESSION_HISTORY_CHARACTER_LIMIT) {
|
|
31060
|
+
const richIndex = messages.findIndex(
|
|
31061
|
+
(message) => message.role === "assistant" && (message.activities.length > 0 || message.content.length > 0)
|
|
31062
|
+
);
|
|
31063
|
+
if (richIndex === -1) {
|
|
31064
|
+
messages.shift();
|
|
31065
|
+
} else {
|
|
31066
|
+
const message = messages[richIndex];
|
|
31067
|
+
if (message?.role === "assistant") {
|
|
31068
|
+
messages[richIndex] = {
|
|
31069
|
+
...message,
|
|
31070
|
+
activities: message.activities.length > 0 ? message.activities.slice(1) : message.activities,
|
|
31071
|
+
content: message.activities.length === 0 && message.content.length > 0 ? message.content.slice(1) : message.content
|
|
31072
|
+
};
|
|
31073
|
+
}
|
|
31074
|
+
}
|
|
31075
|
+
this.#truncated = true;
|
|
31076
|
+
}
|
|
30985
31077
|
return {
|
|
30986
31078
|
status: "available",
|
|
30987
|
-
messages
|
|
30988
|
-
(message) => message.role === "user" ? message : {
|
|
30989
|
-
role: "assistant",
|
|
30990
|
-
text: message.text,
|
|
30991
|
-
content: message.content,
|
|
30992
|
-
activities: message.activityIds.flatMap((id) => {
|
|
30993
|
-
const activity2 = this.#activities.get(id);
|
|
30994
|
-
return activity2 === void 0 ? [] : [
|
|
30995
|
-
{
|
|
30996
|
-
activityId: activity2.activityId,
|
|
30997
|
-
activityType: activity2.activityType,
|
|
30998
|
-
content: activity2.content,
|
|
30999
|
-
input: activity2.input,
|
|
31000
|
-
locations: activity2.locations,
|
|
31001
|
-
name: activity2.name,
|
|
31002
|
-
output: activity2.output,
|
|
31003
|
-
sequence: activity2.sequence,
|
|
31004
|
-
status: activity2.status,
|
|
31005
|
-
title: activity2.title,
|
|
31006
|
-
toolKind: activity2.toolKind
|
|
31007
|
-
}
|
|
31008
|
-
];
|
|
31009
|
-
})
|
|
31010
|
-
}
|
|
31011
|
-
),
|
|
31079
|
+
messages,
|
|
31012
31080
|
truncated: this.#truncated,
|
|
31013
31081
|
coveredCommandIds: [],
|
|
31014
31082
|
coveredMessageIds: []
|
|
@@ -42933,6 +43001,70 @@ async function executeSessionPrepare(publisher, socket, command, config2, direct
|
|
|
42933
43001
|
reportOperationFailure(socket, command.requestId, command.sessionId, error62, metrics.snapshot());
|
|
42934
43002
|
}
|
|
42935
43003
|
}
|
|
43004
|
+
function liveHistoryCursor(sessionId, endIndex) {
|
|
43005
|
+
return Buffer.from(JSON.stringify({ endIndex, sessionId }), "utf8").toString("base64url");
|
|
43006
|
+
}
|
|
43007
|
+
function liveHistoryEndIndex(cursor, sessionId) {
|
|
43008
|
+
try {
|
|
43009
|
+
if (!/^[A-Za-z0-9_-]{1,512}$/u.test(cursor)) {
|
|
43010
|
+
throw new Error("Invalid cursor alphabet");
|
|
43011
|
+
}
|
|
43012
|
+
const value = JSON.parse(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
43013
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
43014
|
+
throw new Error("Invalid cursor shape");
|
|
43015
|
+
}
|
|
43016
|
+
const record2 = Object.fromEntries(Object.entries(value));
|
|
43017
|
+
if (Object.keys(record2).sort().join(",") !== "endIndex,sessionId" || record2["sessionId"] !== sessionId || typeof record2["endIndex"] !== "number" || !Number.isSafeInteger(record2["endIndex"]) || record2["endIndex"] < 0) {
|
|
43018
|
+
throw new Error("Invalid cursor target");
|
|
43019
|
+
}
|
|
43020
|
+
return record2["endIndex"];
|
|
43021
|
+
} catch (cause) {
|
|
43022
|
+
throw new AcpExecutionError("The native Session history cursor is invalid", { cause }, "invalid_cursor");
|
|
43023
|
+
}
|
|
43024
|
+
}
|
|
43025
|
+
function liveHistoryCoveredTurnRanges(history) {
|
|
43026
|
+
const ranges = [];
|
|
43027
|
+
let historyIndex = history.messages.length;
|
|
43028
|
+
for (const commandId of history.coveredCommandIds) {
|
|
43029
|
+
let assistantStartIndex = historyIndex;
|
|
43030
|
+
while (assistantStartIndex > 0 && history.messages[assistantStartIndex - 1]?.role === "assistant") {
|
|
43031
|
+
assistantStartIndex -= 1;
|
|
43032
|
+
}
|
|
43033
|
+
const userIndex = assistantStartIndex - 1;
|
|
43034
|
+
if (assistantStartIndex === historyIndex || history.messages[userIndex]?.role !== "user") {
|
|
43035
|
+
break;
|
|
43036
|
+
}
|
|
43037
|
+
ranges.push({ assistantEndIndex: historyIndex, assistantStartIndex, commandId, userIndex });
|
|
43038
|
+
historyIndex = userIndex;
|
|
43039
|
+
}
|
|
43040
|
+
return ranges;
|
|
43041
|
+
}
|
|
43042
|
+
function paginateLiveSessionHistory(history, sessionId, cursor, limit) {
|
|
43043
|
+
if (history.status === "unavailable") {
|
|
43044
|
+
if (cursor !== null) {
|
|
43045
|
+
throw new AcpExecutionError("Unavailable native Session history has no cursor", {}, "invalid_cursor");
|
|
43046
|
+
}
|
|
43047
|
+
return { cause: history.cause, nextCursor: null, status: "unavailable" };
|
|
43048
|
+
}
|
|
43049
|
+
const endIndex = cursor === null ? history.messages.length : liveHistoryEndIndex(cursor, sessionId);
|
|
43050
|
+
if (endIndex > history.messages.length) {
|
|
43051
|
+
throw new AcpExecutionError("The native Session history cursor is invalid", {}, "invalid_cursor");
|
|
43052
|
+
}
|
|
43053
|
+
const startIndex = Math.max(0, endIndex - limit);
|
|
43054
|
+
const coveredMessageIds = new Set(history.coveredMessageIds);
|
|
43055
|
+
const ranges = liveHistoryCoveredTurnRanges(history);
|
|
43056
|
+
return {
|
|
43057
|
+
coveredCommandIds: ranges.filter((range) => range.userIndex >= startIndex && range.assistantEndIndex <= endIndex).map((range) => range.commandId),
|
|
43058
|
+
coveredMessageIds: ranges.flatMap((range) => [
|
|
43059
|
+
...range.userIndex >= startIndex && range.userIndex < endIndex && coveredMessageIds.has(`${range.commandId}:user`) ? [`${range.commandId}:user`] : [],
|
|
43060
|
+
...range.assistantStartIndex >= startIndex && range.assistantEndIndex <= endIndex && coveredMessageIds.has(`${range.commandId}:agent`) ? [`${range.commandId}:agent`] : []
|
|
43061
|
+
]),
|
|
43062
|
+
messages: history.messages.slice(startIndex, endIndex),
|
|
43063
|
+
nextCursor: startIndex > 0 ? liveHistoryCursor(sessionId, startIndex) : null,
|
|
43064
|
+
status: "available",
|
|
43065
|
+
truncated: history.truncated
|
|
43066
|
+
};
|
|
43067
|
+
}
|
|
42936
43068
|
async function executeSessionLiveHistoryLoad(socket, command, config2, directories, audit, sessions, signal) {
|
|
42937
43069
|
try {
|
|
42938
43070
|
const resolved = await resolveSessionDirectories(
|
|
@@ -42982,6 +43114,57 @@ async function executeSessionLiveHistoryLoad(socket, command, config2, directori
|
|
|
42982
43114
|
});
|
|
42983
43115
|
}
|
|
42984
43116
|
}
|
|
43117
|
+
async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, signal) {
|
|
43118
|
+
try {
|
|
43119
|
+
const resolved = await resolveSessionDirectories(
|
|
43120
|
+
directories,
|
|
43121
|
+
config2.bindingId,
|
|
43122
|
+
command.directoryId,
|
|
43123
|
+
command.additionalDirectoryIds,
|
|
43124
|
+
signal
|
|
43125
|
+
);
|
|
43126
|
+
const history = await sessions.loadSessionHistory({
|
|
43127
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
43128
|
+
agent: config2.catalog.find(command.agentId),
|
|
43129
|
+
cwd: resolved.cwd,
|
|
43130
|
+
sessionId: command.sessionId,
|
|
43131
|
+
signal
|
|
43132
|
+
});
|
|
43133
|
+
signal.throwIfAborted();
|
|
43134
|
+
const page = paginateLiveSessionHistory(history, command.sessionId, command.cursor, command.limit);
|
|
43135
|
+
audit.record({
|
|
43136
|
+
commandId: command.requestId,
|
|
43137
|
+
event: "session_history_loaded",
|
|
43138
|
+
sessionId: command.sessionId
|
|
43139
|
+
});
|
|
43140
|
+
send(socket, {
|
|
43141
|
+
kind: "session.live-history.page.loaded",
|
|
43142
|
+
page,
|
|
43143
|
+
requestId: command.requestId,
|
|
43144
|
+
sessionId: command.sessionId
|
|
43145
|
+
});
|
|
43146
|
+
} catch (error62) {
|
|
43147
|
+
if (signal.aborted) {
|
|
43148
|
+
return;
|
|
43149
|
+
}
|
|
43150
|
+
audit.record({
|
|
43151
|
+
commandId: command.requestId,
|
|
43152
|
+
details: { code: operationErrorCode(error62) },
|
|
43153
|
+
event: "session_history_unavailable",
|
|
43154
|
+
sessionId: command.sessionId
|
|
43155
|
+
});
|
|
43156
|
+
send(socket, {
|
|
43157
|
+
kind: "session.live-history.page.loaded",
|
|
43158
|
+
page: {
|
|
43159
|
+
status: "unavailable",
|
|
43160
|
+
cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) },
|
|
43161
|
+
nextCursor: null
|
|
43162
|
+
},
|
|
43163
|
+
requestId: command.requestId,
|
|
43164
|
+
sessionId: command.sessionId
|
|
43165
|
+
});
|
|
43166
|
+
}
|
|
43167
|
+
}
|
|
42985
43168
|
async function executeSessionConfigure(publisher, socket, command, config2, directories, audit, sessions, signal) {
|
|
42986
43169
|
try {
|
|
42987
43170
|
const resolved = await resolveSessionDirectories(
|
|
@@ -43841,6 +44024,19 @@ async function runRelayConnection(config2, directories, audit, sessions, install
|
|
|
43841
44024
|
);
|
|
43842
44025
|
return;
|
|
43843
44026
|
}
|
|
44027
|
+
if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
|
|
44028
|
+
const command2 = decodeSessionLiveHistoryPageLoad(encoded);
|
|
44029
|
+
void executeSessionLiveHistoryPageLoad(
|
|
44030
|
+
socket,
|
|
44031
|
+
command2,
|
|
44032
|
+
config2,
|
|
44033
|
+
directories,
|
|
44034
|
+
audit,
|
|
44035
|
+
sessions,
|
|
44036
|
+
connectionController.signal
|
|
44037
|
+
);
|
|
44038
|
+
return;
|
|
44039
|
+
}
|
|
43844
44040
|
if (kind === NATIVE_SESSION_CANCEL_KIND) {
|
|
43845
44041
|
const command2 = message;
|
|
43846
44042
|
const pending = nativeRequests.get(command2.requestId);
|