@moxt-ai/mobius 0.0.169 → 0.0.172
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/agent-session.d.ts.map +1 -1
- package/dist/acp/agent-session.js +141 -42
- package/dist/acp/agent-session.js.map +1 -1
- package/dist/acp/codex/agent.d.ts.map +1 -1
- package/dist/acp/codex/agent.js +56 -31
- package/dist/acp/codex/agent.js.map +1 -1
- package/dist/acp/codex/items.d.ts +0 -9
- package/dist/acp/codex/items.d.ts.map +1 -1
- package/dist/acp/codex/items.js +0 -11
- package/dist/acp/codex/items.js.map +1 -1
- package/dist/acp/run-prompt.d.ts.map +1 -1
- package/dist/acp/run-prompt.js +7 -1
- package/dist/acp/run-prompt.js.map +1 -1
- package/dist/acp/session-contracts.d.ts +9 -4
- package/dist/acp/session-contracts.d.ts.map +1 -1
- package/dist/acp/session-contracts.js +1 -1
- package/dist/acp/session-contracts.js.map +1 -1
- package/dist/acp/session-history.d.ts +6 -3
- package/dist/acp/session-history.d.ts.map +1 -1
- package/dist/acp/session-history.js +41 -17
- package/dist/acp/session-history.js.map +1 -1
- package/dist/acp/session-interactions.d.ts +2 -0
- package/dist/acp/session-interactions.d.ts.map +1 -1
- package/dist/acp/session-interactions.js +36 -8
- package/dist/acp/session-interactions.js.map +1 -1
- package/dist/acp/session-store.d.ts +0 -13
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +3 -65
- package/dist/acp/session-store.js.map +1 -1
- package/dist/cli.js +350 -511
- package/dist/cli.js.map +4 -4
- package/dist/daemon-command-handler.d.ts.map +1 -1
- package/dist/daemon-command-handler.js +3 -8
- package/dist/daemon-command-handler.js.map +1 -1
- package/dist/daemon-history-commands.d.ts +3 -3
- package/dist/daemon-history-commands.d.ts.map +1 -1
- package/dist/daemon-history-commands.js +10 -66
- package/dist/daemon-history-commands.js.map +1 -1
- package/dist/daemon-observers.d.ts +3 -3
- package/dist/daemon-observers.d.ts.map +1 -1
- package/dist/daemon-observers.js +2 -18
- package/dist/daemon-observers.js.map +1 -1
- package/dist/daemon-prompt-executor.d.ts.map +1 -1
- package/dist/daemon-prompt-executor.js +3 -1
- package/dist/daemon-prompt-executor.js.map +1 -1
- package/dist/index.js +356 -511
- package/dist/index.js.map +4 -4
- package/dist/native-sessions/codex-history.js +3 -3
- package/dist/native-sessions/codex-history.js.map +1 -1
- package/dist/native-sessions/live-history-page.d.ts +0 -1
- package/dist/native-sessions/live-history-page.d.ts.map +1 -1
- package/dist/native-sessions/live-history-page.js +0 -14
- package/dist/native-sessions/live-history-page.js.map +1 -1
- package/dist/relay-connection/session-event-publisher.d.ts +1 -6
- package/dist/relay-connection/session-event-publisher.d.ts.map +1 -1
- package/dist/relay-connection/session-event-publisher.js +2 -7
- package/dist/relay-connection/session-event-publisher.js.map +1 -1
- package/dist/run-daemon.js +2 -2
- package/dist/run-daemon.js.map +1 -1
- package/dist/runtime.js +353 -514
- package/dist/runtime.js.map +4 -4
- package/dist/session-event-log-v2.d.ts +18 -9
- package/dist/session-event-log-v2.d.ts.map +1 -1
- package/dist/session-event-log-v2.js +39 -156
- package/dist/session-event-log-v2.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21520,10 +21520,7 @@ var lifecycleMetadataV2Schema = external_exports.discriminatedUnion("kind", [
|
|
|
21520
21520
|
external_exports.object({ kind: external_exports.literal("session.queue.changed") }).readonly(),
|
|
21521
21521
|
external_exports.object({ event: sessionPermissionRequestedEventSchema, kind: external_exports.literal("session.permission.requested") }).readonly(),
|
|
21522
21522
|
external_exports.object({ event: sessionPermissionResolvedEventSchema, kind: external_exports.literal("session.permission.resolved") }).readonly(),
|
|
21523
|
-
external_exports.object({
|
|
21524
|
-
event: sessionElicitationRequestedEventSchema,
|
|
21525
|
-
kind: external_exports.literal("session.elicitation.requested")
|
|
21526
|
-
}).readonly(),
|
|
21523
|
+
external_exports.object({ event: sessionElicitationRequestedEventSchema, kind: external_exports.literal("session.elicitation.requested") }).readonly(),
|
|
21527
21524
|
external_exports.object({ event: sessionElicitationResolvedEventSchema, kind: external_exports.literal("session.elicitation.resolved") }).readonly(),
|
|
21528
21525
|
external_exports.object({
|
|
21529
21526
|
...lifecycleBase,
|
|
@@ -21625,6 +21622,7 @@ var mobiusSessionExportV2Schema = external_exports.object({
|
|
|
21625
21622
|
}).readonly();
|
|
21626
21623
|
var sessionEventEnvelopeV2Schema = external_exports.object({ event: sessionEventV2Schema, kind: external_exports.literal(SESSION_EVENT_V2_KIND) }).readonly();
|
|
21627
21624
|
var sessionEventLogPageV2Schema = external_exports.object({
|
|
21625
|
+
daemonGenerationId: identifierStringSchema,
|
|
21628
21626
|
events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
|
|
21629
21627
|
nextCursor: external_exports.string().min(1).max(512).nullable(),
|
|
21630
21628
|
tailCursor: external_exports.string().max(512),
|
|
@@ -21632,17 +21630,13 @@ var sessionEventLogPageV2Schema = external_exports.object({
|
|
|
21632
21630
|
version: external_exports.literal(2)
|
|
21633
21631
|
}).readonly();
|
|
21634
21632
|
var nativeEventPageRequestV2Schema = external_exports.object({ cursor: external_exports.string().min(1).max(512).nullable(), eventLimit: external_exports.number().int().min(1).max(1e4) }).readonly();
|
|
21635
|
-
var
|
|
21636
|
-
attemptId: identifierStringSchema,
|
|
21633
|
+
var queuedPromptRequestEventLogV2Schema = external_exports.object({
|
|
21637
21634
|
commandId: identifierStringSchema,
|
|
21638
|
-
|
|
21639
|
-
events: external_exports.array(sessionEventV2Schema).max(MAX_EVENT_COUNT).readonly(),
|
|
21640
|
-
tailCursor: external_exports.string().max(512),
|
|
21641
|
-
truncated: external_exports.boolean()
|
|
21635
|
+
content: external_exports.array(contentBlockV2Schema).min(1).max(100).readonly()
|
|
21642
21636
|
}).readonly();
|
|
21643
21637
|
var nativeSessionEventsV2Schema = external_exports.object({
|
|
21644
|
-
|
|
21645
|
-
|
|
21638
|
+
events: sessionEventLogPageV2Schema,
|
|
21639
|
+
queuedPromptRequests: external_exports.array(queuedPromptRequestEventLogV2Schema).max(MAX_COLLECTION_SIZE).readonly()
|
|
21646
21640
|
}).readonly();
|
|
21647
21641
|
function inputValue(value) {
|
|
21648
21642
|
if (typeof value !== "string") {
|
|
@@ -21666,7 +21660,6 @@ function decode5(value, schema) {
|
|
|
21666
21660
|
function encode4(value, schema) {
|
|
21667
21661
|
return JSON.stringify(decode5(value, schema));
|
|
21668
21662
|
}
|
|
21669
|
-
var decodeSessionEventV2 = (value) => decode5(value, sessionEventV2Schema);
|
|
21670
21663
|
var decodeSessionEventEnvelopeV2 = (value) => decode5(value, sessionEventEnvelopeV2Schema);
|
|
21671
21664
|
var encodeSessionEventEnvelopeV2 = (value) => encode4(value, sessionEventEnvelopeV2Schema);
|
|
21672
21665
|
var decodeAcpSessionUpdateV2 = (value) => decode5(value, acpSessionUpdateV2Schema);
|
|
@@ -21760,28 +21753,11 @@ function decodeRecordedSessionEvent(encoded) {
|
|
|
21760
21753
|
var encodeRecordedSessionEvent = (event) => JSON.stringify(decodeRecordedSessionEvent(JSON.stringify(event)));
|
|
21761
21754
|
|
|
21762
21755
|
// ../protocol/src/session-live-history.ts
|
|
21763
|
-
var SESSION_LIVE_HISTORY_LOAD_KIND = "session.live-history.load";
|
|
21764
|
-
var SESSION_LIVE_HISTORY_LOADED_KIND = "session.live-history.loaded";
|
|
21765
21756
|
var SESSION_LIVE_HISTORY_PAGE_LOAD_KIND = "session.live-history.page.load";
|
|
21766
21757
|
var SESSION_LIVE_HISTORY_PAGE_LOADED_KIND = "session.live-history.page.loaded";
|
|
21767
21758
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOAD_KIND = "session.live-history.v2.page.load";
|
|
21768
21759
|
var SESSION_LIVE_HISTORY_V2_PAGE_LOADED_KIND = "session.live-history.v2.page.loaded";
|
|
21769
21760
|
var directoryIdentifier = external_exports.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,2047}$/);
|
|
21770
|
-
var sessionLiveHistoryLoadSchema = external_exports.object({
|
|
21771
|
-
additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
|
|
21772
|
-
agentId: identifierStringSchema,
|
|
21773
|
-
bindingId: identifierStringSchema,
|
|
21774
|
-
directoryId: directoryIdentifier,
|
|
21775
|
-
kind: external_exports.literal(SESSION_LIVE_HISTORY_LOAD_KIND),
|
|
21776
|
-
requestId: identifierStringSchema,
|
|
21777
|
-
sessionId: identifierStringSchema
|
|
21778
|
-
}).readonly();
|
|
21779
|
-
var sessionLiveHistoryLoadedSchema = external_exports.object({
|
|
21780
|
-
history: sessionHistorySchema,
|
|
21781
|
-
kind: external_exports.literal(SESSION_LIVE_HISTORY_LOADED_KIND),
|
|
21782
|
-
requestId: identifierStringSchema,
|
|
21783
|
-
sessionId: identifierStringSchema
|
|
21784
|
-
}).readonly();
|
|
21785
21761
|
var sessionLiveHistoryPageLoadSchema = external_exports.object({
|
|
21786
21762
|
additionalDirectoryIds: external_exports.array(directoryIdentifier).max(16).readonly(),
|
|
21787
21763
|
agentId: identifierStringSchema,
|
|
@@ -21824,10 +21800,6 @@ function decode7(schema, encoded) {
|
|
|
21824
21800
|
throw new ProtocolMessageError("Invalid live Session history message", { cause });
|
|
21825
21801
|
}
|
|
21826
21802
|
}
|
|
21827
|
-
var decodeSessionLiveHistoryLoad = (encoded) => decode7(sessionLiveHistoryLoadSchema, encoded);
|
|
21828
|
-
var decodeSessionLiveHistoryLoaded = (encoded) => decode7(sessionLiveHistoryLoadedSchema, encoded);
|
|
21829
|
-
var encodeSessionLiveHistoryLoad = (value) => JSON.stringify(sessionLiveHistoryLoadSchema.parse(value));
|
|
21830
|
-
var encodeSessionLiveHistoryLoaded = (value) => JSON.stringify(sessionLiveHistoryLoadedSchema.parse(value));
|
|
21831
21803
|
var decodeSessionLiveHistoryPageLoad = (encoded) => decode7(sessionLiveHistoryPageLoadSchema, encoded);
|
|
21832
21804
|
var decodeSessionLiveHistoryPageLoaded = (encoded) => decode7(sessionLiveHistoryPageLoadedSchema, encoded);
|
|
21833
21805
|
var encodeSessionLiveHistoryPageLoad = (value) => JSON.stringify(sessionLiveHistoryPageLoadSchema.parse(value));
|
|
@@ -21910,11 +21882,6 @@ var serviceToDaemonSignatures = {
|
|
|
21910
21882
|
encodeSessionElicitationRespondCommand,
|
|
21911
21883
|
decodeSessionElicitationRespondCommand
|
|
21912
21884
|
),
|
|
21913
|
-
[SESSION_LIVE_HISTORY_LOAD_KIND]: defineMessageSignature(
|
|
21914
|
-
SESSION_LIVE_HISTORY_LOAD_KIND,
|
|
21915
|
-
encodeSessionLiveHistoryLoad,
|
|
21916
|
-
decodeSessionLiveHistoryLoad
|
|
21917
|
-
),
|
|
21918
21885
|
[SESSION_LIVE_HISTORY_PAGE_LOAD_KIND]: defineMessageSignature(
|
|
21919
21886
|
SESSION_LIVE_HISTORY_PAGE_LOAD_KIND,
|
|
21920
21887
|
encodeSessionLiveHistoryPageLoad,
|
|
@@ -22055,11 +22022,6 @@ var daemonToServiceSignatures = {
|
|
|
22055
22022
|
encodeSessionOperationFailedEvent,
|
|
22056
22023
|
decodeSessionOperationFailedEvent
|
|
22057
22024
|
),
|
|
22058
|
-
[SESSION_LIVE_HISTORY_LOADED_KIND]: defineMessageSignature(
|
|
22059
|
-
SESSION_LIVE_HISTORY_LOADED_KIND,
|
|
22060
|
-
encodeSessionLiveHistoryLoaded,
|
|
22061
|
-
decodeSessionLiveHistoryLoaded
|
|
22062
|
-
),
|
|
22063
22025
|
[SESSION_LIVE_HISTORY_PAGE_LOADED_KIND]: defineMessageSignature(
|
|
22064
22026
|
SESSION_LIVE_HISTORY_PAGE_LOADED_KIND,
|
|
22065
22027
|
encodeSessionLiveHistoryPageLoaded,
|
|
@@ -24512,7 +24474,7 @@ function sessionConfigProtocolForAgent(_agentId) {
|
|
|
24512
24474
|
|
|
24513
24475
|
// src/acp/session-contracts.ts
|
|
24514
24476
|
var NullAcpSessionObserver = class {
|
|
24515
|
-
|
|
24477
|
+
onSessionEventV2 = (_sessionId, _event, _position) => Promise.resolve();
|
|
24516
24478
|
onCommands = () => Promise.resolve();
|
|
24517
24479
|
onConfig = () => Promise.resolve();
|
|
24518
24480
|
onContent = () => Promise.resolve();
|
|
@@ -24637,7 +24599,8 @@ function historyContentCharacters(messages) {
|
|
|
24637
24599
|
var AcpHistoryReplay = class {
|
|
24638
24600
|
#activities = /* @__PURE__ */ new Map();
|
|
24639
24601
|
#messages = [];
|
|
24640
|
-
#
|
|
24602
|
+
#events = [];
|
|
24603
|
+
#records = [];
|
|
24641
24604
|
#turnActivityIds = /* @__PURE__ */ new Set();
|
|
24642
24605
|
#activityTracker = new AcpActivityTracker(
|
|
24643
24606
|
async (activity2) => {
|
|
@@ -24659,8 +24622,10 @@ var AcpHistoryReplay = class {
|
|
|
24659
24622
|
#firstMessageIndex = 0;
|
|
24660
24623
|
#characters = 0;
|
|
24661
24624
|
#truncated = false;
|
|
24662
|
-
record = async (update, rawUpdate) => {
|
|
24663
|
-
this.#
|
|
24625
|
+
record = async (update, rawUpdate, onRecorded = () => Promise.resolve()) => {
|
|
24626
|
+
this.#records.push({ kind: "acp", rawUpdate, update });
|
|
24627
|
+
this.#events.push({ payload: rawUpdate, type: "acp" });
|
|
24628
|
+
await onRecorded(this.#events.length);
|
|
24664
24629
|
if (update.sessionUpdate === "agent_thought_chunk") {
|
|
24665
24630
|
if (update.content.type === "text") {
|
|
24666
24631
|
await this.#activityTracker.recordNarrative(
|
|
@@ -24669,30 +24634,30 @@ var AcpHistoryReplay = class {
|
|
|
24669
24634
|
update.content.text
|
|
24670
24635
|
);
|
|
24671
24636
|
}
|
|
24672
|
-
return;
|
|
24637
|
+
return this.#events.length;
|
|
24673
24638
|
}
|
|
24674
24639
|
if (update.sessionUpdate === "tool_call") {
|
|
24675
24640
|
await this.#activityTracker.recordToolCall(update);
|
|
24676
|
-
return;
|
|
24641
|
+
return this.#events.length;
|
|
24677
24642
|
}
|
|
24678
24643
|
if (update.sessionUpdate === "tool_call_update") {
|
|
24679
24644
|
await this.#activityTracker.recordToolCallUpdate(update);
|
|
24680
|
-
return;
|
|
24645
|
+
return this.#events.length;
|
|
24681
24646
|
}
|
|
24682
24647
|
if (update.sessionUpdate === "plan") {
|
|
24683
24648
|
await this.#activityTracker.recordPlan(update);
|
|
24684
|
-
return;
|
|
24649
|
+
return this.#events.length;
|
|
24685
24650
|
}
|
|
24686
24651
|
if (update.sessionUpdate === "plan_update") {
|
|
24687
24652
|
await this.#activityTracker.recordPlanUpdate(update);
|
|
24688
|
-
return;
|
|
24653
|
+
return this.#events.length;
|
|
24689
24654
|
}
|
|
24690
24655
|
if (update.sessionUpdate === "plan_removed") {
|
|
24691
24656
|
await this.#activityTracker.removePlan(update);
|
|
24692
|
-
return;
|
|
24657
|
+
return this.#events.length;
|
|
24693
24658
|
}
|
|
24694
24659
|
if (update.sessionUpdate !== "user_message_chunk" && update.sessionUpdate !== "agent_message_chunk") {
|
|
24695
|
-
return;
|
|
24660
|
+
return this.#events.length;
|
|
24696
24661
|
}
|
|
24697
24662
|
if (update.sessionUpdate === "agent_message_chunk" && isProgressMessage(update)) {
|
|
24698
24663
|
if (update.content.type === "text") {
|
|
@@ -24702,18 +24667,18 @@ var AcpHistoryReplay = class {
|
|
|
24702
24667
|
update.content.text
|
|
24703
24668
|
);
|
|
24704
24669
|
}
|
|
24705
|
-
return;
|
|
24670
|
+
return this.#events.length;
|
|
24706
24671
|
}
|
|
24707
24672
|
const role = update.sessionUpdate === "user_message_chunk" ? "user" : "assistant";
|
|
24708
24673
|
const content = update.content;
|
|
24709
24674
|
if (role === "assistant" && content.type !== "text") {
|
|
24710
24675
|
await this.#activityTracker.finishNarrative();
|
|
24711
24676
|
this.recordAssistantContent(update.messageId ?? null, normalizeContentBlock(content));
|
|
24712
|
-
return;
|
|
24677
|
+
return this.#events.length;
|
|
24713
24678
|
}
|
|
24714
24679
|
const text2 = content.type === "text" ? content.text : content.type === "image" ? content.data.length > 0 ? `[@image](data:${content.mimeType};base64,${content.data})` : content.uri != null && content.uri.length > 0 ? `[@image](${content.uri})` : "[image attachment]" : `[${content.type} attachment]`;
|
|
24715
24680
|
if (text2.length === 0) {
|
|
24716
|
-
return;
|
|
24681
|
+
return this.#events.length;
|
|
24717
24682
|
}
|
|
24718
24683
|
const previous = this.#messages.at(-1);
|
|
24719
24684
|
const id = update.messageId ?? null;
|
|
@@ -24740,10 +24705,30 @@ var AcpHistoryReplay = class {
|
|
|
24740
24705
|
this.#characters += bounded2.length;
|
|
24741
24706
|
this.#lastMessageId = id;
|
|
24742
24707
|
this.trimMessages();
|
|
24708
|
+
return this.#events.length;
|
|
24743
24709
|
};
|
|
24744
|
-
|
|
24745
|
-
|
|
24746
|
-
|
|
24710
|
+
recordLifecycle = (event) => {
|
|
24711
|
+
if (event.type !== "lifecycle-metadata") {
|
|
24712
|
+
throw new Error("Lifecycle history only accepts lifecycle metadata");
|
|
24713
|
+
}
|
|
24714
|
+
this.#records.push({ event, kind: "lifecycle" });
|
|
24715
|
+
this.#events.push(event);
|
|
24716
|
+
return this.#events.length;
|
|
24717
|
+
};
|
|
24718
|
+
eventCount = () => this.#events.length;
|
|
24719
|
+
append = async (replay) => {
|
|
24720
|
+
for (const record2 of replay.#records) {
|
|
24721
|
+
if (record2.kind === "acp") {
|
|
24722
|
+
await this.record(record2.update, record2.rawUpdate);
|
|
24723
|
+
} else {
|
|
24724
|
+
this.recordLifecycle(record2.event);
|
|
24725
|
+
}
|
|
24726
|
+
}
|
|
24727
|
+
};
|
|
24728
|
+
eventPage = (eventLimit, cursor, appended = null) => {
|
|
24729
|
+
const events = appended === null ? this.#events : [...this.#events, ...appended.#events];
|
|
24730
|
+
const parsedCursor = cursor === null ? events.length : Number(cursor);
|
|
24731
|
+
if (!Number.isSafeInteger(parsedCursor) || parsedCursor < 0 || parsedCursor > events.length) {
|
|
24747
24732
|
throw new Error("The native event cursor is invalid");
|
|
24748
24733
|
}
|
|
24749
24734
|
const endUpdate = parsedCursor;
|
|
@@ -24752,7 +24737,7 @@ var AcpHistoryReplay = class {
|
|
|
24752
24737
|
nextCursor: startUpdate === 0 ? null : startUpdate.toString(),
|
|
24753
24738
|
startPosition: startUpdate + 1,
|
|
24754
24739
|
truncated: startUpdate > 0,
|
|
24755
|
-
|
|
24740
|
+
events: events.slice(startUpdate, endUpdate)
|
|
24756
24741
|
};
|
|
24757
24742
|
};
|
|
24758
24743
|
snapshot = async () => {
|
|
@@ -25139,6 +25124,34 @@ var AcpSessionInteractions = class {
|
|
|
25139
25124
|
constructor(context) {
|
|
25140
25125
|
this.#context = context;
|
|
25141
25126
|
}
|
|
25127
|
+
#notifyPermissionRequested = async (event) => {
|
|
25128
|
+
await this.#context.recordSessionEventV2({
|
|
25129
|
+
payload: { event, kind: "session.permission.requested" },
|
|
25130
|
+
type: "lifecycle-metadata"
|
|
25131
|
+
});
|
|
25132
|
+
await this.#context.observer().onPermission(event);
|
|
25133
|
+
};
|
|
25134
|
+
#notifyPermissionResolved = async (event) => {
|
|
25135
|
+
await this.#context.recordSessionEventV2({
|
|
25136
|
+
payload: { event, kind: "session.permission.resolved" },
|
|
25137
|
+
type: "lifecycle-metadata"
|
|
25138
|
+
});
|
|
25139
|
+
await this.#context.observer().onPermissionResolved(event);
|
|
25140
|
+
};
|
|
25141
|
+
#notifyElicitationRequested = async (event) => {
|
|
25142
|
+
await this.#context.recordSessionEventV2({
|
|
25143
|
+
payload: { event, kind: "session.elicitation.requested" },
|
|
25144
|
+
type: "lifecycle-metadata"
|
|
25145
|
+
});
|
|
25146
|
+
await this.#context.observer().onElicitation(event);
|
|
25147
|
+
};
|
|
25148
|
+
#notifyElicitationResolved = async (event) => {
|
|
25149
|
+
await this.#context.recordSessionEventV2({
|
|
25150
|
+
payload: { event, kind: "session.elicitation.resolved" },
|
|
25151
|
+
type: "lifecycle-metadata"
|
|
25152
|
+
});
|
|
25153
|
+
await this.#context.observer().onElicitationResolved(event);
|
|
25154
|
+
};
|
|
25142
25155
|
respondPermission = async (options) => {
|
|
25143
25156
|
const pending = this.#pendingPermissions.get(options.interactionId);
|
|
25144
25157
|
if (pending === void 0) {
|
|
@@ -25164,7 +25177,7 @@ var AcpSessionInteractions = class {
|
|
|
25164
25177
|
);
|
|
25165
25178
|
}
|
|
25166
25179
|
this.#pendingPermissions.delete(options.interactionId);
|
|
25167
|
-
await this.#
|
|
25180
|
+
await this.#notifyPermissionResolved({
|
|
25168
25181
|
interactionId: options.interactionId,
|
|
25169
25182
|
kind: SESSION_PERMISSION_RESOLVED_KIND,
|
|
25170
25183
|
optionId: options.outcome === "selected" ? options.optionId : "",
|
|
@@ -25204,7 +25217,7 @@ var AcpSessionInteractions = class {
|
|
|
25204
25217
|
);
|
|
25205
25218
|
}
|
|
25206
25219
|
this.#pendingElicitations.delete(options.interactionId);
|
|
25207
|
-
await this.#
|
|
25220
|
+
await this.#notifyElicitationResolved({
|
|
25208
25221
|
action: options.action,
|
|
25209
25222
|
interactionId: options.interactionId,
|
|
25210
25223
|
kind: SESSION_ELICITATION_RESOLVED_KIND,
|
|
@@ -25233,7 +25246,7 @@ var AcpSessionInteractions = class {
|
|
|
25233
25246
|
};
|
|
25234
25247
|
signal.addEventListener("abort", abort, { once: true });
|
|
25235
25248
|
try {
|
|
25236
|
-
await this.#
|
|
25249
|
+
await this.#notifyPermissionRequested({
|
|
25237
25250
|
commandId: this.#context.commandId(),
|
|
25238
25251
|
interactionId,
|
|
25239
25252
|
kind: SESSION_PERMISSION_REQUESTED_KIND,
|
|
@@ -25278,7 +25291,7 @@ var AcpSessionInteractions = class {
|
|
|
25278
25291
|
};
|
|
25279
25292
|
signal.addEventListener("abort", abort, { once: true });
|
|
25280
25293
|
try {
|
|
25281
|
-
await this.#
|
|
25294
|
+
await this.#notifyElicitationRequested({
|
|
25282
25295
|
accepted: false,
|
|
25283
25296
|
commandId: this.#context.commandId(),
|
|
25284
25297
|
elicitationId,
|
|
@@ -25302,7 +25315,7 @@ var AcpSessionInteractions = class {
|
|
|
25302
25315
|
return;
|
|
25303
25316
|
}
|
|
25304
25317
|
this.#acceptedUrlElicitations.delete(notification.elicitationId);
|
|
25305
|
-
await this.#
|
|
25318
|
+
await this.#notifyElicitationResolved({
|
|
25306
25319
|
action: "complete",
|
|
25307
25320
|
interactionId,
|
|
25308
25321
|
kind: SESSION_ELICITATION_RESOLVED_KIND,
|
|
@@ -25315,7 +25328,7 @@ var AcpSessionInteractions = class {
|
|
|
25315
25328
|
return;
|
|
25316
25329
|
}
|
|
25317
25330
|
this.#pendingPermissions.delete(interactionId);
|
|
25318
|
-
await this.#
|
|
25331
|
+
await this.#notifyPermissionResolved({
|
|
25319
25332
|
interactionId,
|
|
25320
25333
|
kind: SESSION_PERMISSION_RESOLVED_KIND,
|
|
25321
25334
|
optionId: "",
|
|
@@ -25329,7 +25342,7 @@ var AcpSessionInteractions = class {
|
|
|
25329
25342
|
return;
|
|
25330
25343
|
}
|
|
25331
25344
|
this.#pendingElicitations.delete(interactionId);
|
|
25332
|
-
await this.#
|
|
25345
|
+
await this.#notifyElicitationResolved({
|
|
25333
25346
|
action: "cancel",
|
|
25334
25347
|
interactionId,
|
|
25335
25348
|
kind: SESSION_ELICITATION_RESOLVED_KIND,
|
|
@@ -25348,7 +25361,7 @@ var AcpSessionInteractions = class {
|
|
|
25348
25361
|
await this.cancelElicitation(interactionId);
|
|
25349
25362
|
}
|
|
25350
25363
|
for (const interactionId of acceptedElicitationIds) {
|
|
25351
|
-
await this.#
|
|
25364
|
+
await this.#notifyElicitationResolved({
|
|
25352
25365
|
action: "cancel",
|
|
25353
25366
|
interactionId,
|
|
25354
25367
|
kind: SESSION_ELICITATION_RESOLVED_KIND,
|
|
@@ -30283,21 +30296,9 @@ var DeletedAcpStoredSession = class extends AcpStoredSessionLookup {
|
|
|
30283
30296
|
var MemoryAcpSessionStore = class {
|
|
30284
30297
|
#sessions = /* @__PURE__ */ new Map();
|
|
30285
30298
|
#deleted = /* @__PURE__ */ new Set();
|
|
30286
|
-
#eventsV2 = /* @__PURE__ */ new Map();
|
|
30287
|
-
appendExecutingPromptEventV2 = (event) => {
|
|
30288
|
-
const events = this.#eventsV2.get(event.sessionId);
|
|
30289
|
-
if (events === void 0) {
|
|
30290
|
-
throw new Error("The executing prompt event log has not started");
|
|
30291
|
-
}
|
|
30292
|
-
events.push(event);
|
|
30293
|
-
};
|
|
30294
|
-
clearExecutingPromptEventsV2 = (sessionId) => {
|
|
30295
|
-
this.#eventsV2.delete(sessionId);
|
|
30296
|
-
};
|
|
30297
30299
|
close = () => {
|
|
30298
30300
|
this.#sessions.clear();
|
|
30299
30301
|
this.#deleted.clear();
|
|
30300
|
-
this.#eventsV2.clear();
|
|
30301
30302
|
};
|
|
30302
30303
|
findNative = (agentId, nativeSessionId) => [...this.#sessions.values()].filter(
|
|
30303
30304
|
(session) => session.agentId === agentId && session.nativeSessionId === nativeSessionId
|
|
@@ -30308,7 +30309,6 @@ var MemoryAcpSessionStore = class {
|
|
|
30308
30309
|
for (const id of ids) {
|
|
30309
30310
|
this.#sessions.delete(id);
|
|
30310
30311
|
this.#deleted.add(id);
|
|
30311
|
-
this.#eventsV2.delete(id);
|
|
30312
30312
|
}
|
|
30313
30313
|
return ids;
|
|
30314
30314
|
};
|
|
@@ -30321,13 +30321,6 @@ var MemoryAcpSessionStore = class {
|
|
|
30321
30321
|
};
|
|
30322
30322
|
remove = (sessionId) => {
|
|
30323
30323
|
this.#sessions.delete(sessionId);
|
|
30324
|
-
this.#eventsV2.delete(sessionId);
|
|
30325
|
-
};
|
|
30326
|
-
readExecutingPromptEventsV2 = (sessionId) => [
|
|
30327
|
-
...this.#eventsV2.get(sessionId) ?? []
|
|
30328
|
-
];
|
|
30329
|
-
startExecutingPromptEventsV2 = (sessionId, events) => {
|
|
30330
|
-
this.#eventsV2.set(sessionId, [...events]);
|
|
30331
30324
|
};
|
|
30332
30325
|
write = (session) => {
|
|
30333
30326
|
this.#sessions.set(session.sessionId, session);
|
|
@@ -30406,30 +30399,6 @@ var SqliteAcpSessionStore = class {
|
|
|
30406
30399
|
close = () => {
|
|
30407
30400
|
this.#sqliteDatabase.close();
|
|
30408
30401
|
};
|
|
30409
|
-
appendExecutingPromptEventV2 = (event) => {
|
|
30410
|
-
this.#database.insert(sessionEventV2).values({
|
|
30411
|
-
eventId: event.eventId,
|
|
30412
|
-
eventJson: JSON.stringify(event),
|
|
30413
|
-
position: Number(event.position),
|
|
30414
|
-
sessionId: event.sessionId
|
|
30415
|
-
}).run();
|
|
30416
|
-
};
|
|
30417
|
-
clearExecutingPromptEventsV2 = (sessionId) => {
|
|
30418
|
-
this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
|
|
30419
|
-
};
|
|
30420
|
-
startExecutingPromptEventsV2 = (sessionId, events) => {
|
|
30421
|
-
this.#transaction(() => {
|
|
30422
|
-
this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
|
|
30423
|
-
for (const event of events) {
|
|
30424
|
-
this.#database.insert(sessionEventV2).values({
|
|
30425
|
-
eventId: event.eventId,
|
|
30426
|
-
eventJson: JSON.stringify(event),
|
|
30427
|
-
position: Number(event.position),
|
|
30428
|
-
sessionId: event.sessionId
|
|
30429
|
-
}).run();
|
|
30430
|
-
}
|
|
30431
|
-
});
|
|
30432
|
-
};
|
|
30433
30402
|
findNative = (agentId, nativeSessionId) => this.#database.select().from(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).all().map(decodeStoredSession);
|
|
30434
30403
|
list = () => this.#database.select().from(acpSession).orderBy(desc(acpSession.updatedAt)).all().map(decodeStoredSession);
|
|
30435
30404
|
markDeleted = (agentId, nativeSessionId) => {
|
|
@@ -30438,7 +30407,6 @@ var SqliteAcpSessionStore = class {
|
|
|
30438
30407
|
this.#database.delete(acpSession).where(and(eq(acpSession.agentId, agentId), eq(acpSession.nativeSessionId, nativeSessionId))).run();
|
|
30439
30408
|
for (const id of ids) {
|
|
30440
30409
|
this.#database.insert(deletedAcpSession).values({ sessionId: id }).onConflictDoNothing().run();
|
|
30441
|
-
this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, id)).run();
|
|
30442
30410
|
}
|
|
30443
30411
|
});
|
|
30444
30412
|
return ids;
|
|
@@ -30452,12 +30420,8 @@ var SqliteAcpSessionStore = class {
|
|
|
30452
30420
|
const row = this.#database.select().from(acpSession).where(eq(acpSession.sessionId, sessionId)).get();
|
|
30453
30421
|
return row === void 0 ? new MissingAcpStoredSession() : new FoundAcpStoredSession(decodeStoredSession(row));
|
|
30454
30422
|
};
|
|
30455
|
-
readExecutingPromptEventsV2 = (sessionId) => this.#database.select({ eventJson: sessionEventV2.eventJson }).from(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).orderBy(asc(sessionEventV2.position)).all().map((row) => decodeSessionEventV2(row.eventJson));
|
|
30456
30423
|
remove = (sessionId) => {
|
|
30457
|
-
this.#
|
|
30458
|
-
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
30459
|
-
this.#database.delete(sessionEventV2).where(eq(sessionEventV2.sessionId, sessionId)).run();
|
|
30460
|
-
});
|
|
30424
|
+
this.#database.delete(acpSession).where(eq(acpSession.sessionId, sessionId)).run();
|
|
30461
30425
|
};
|
|
30462
30426
|
write = (session) => {
|
|
30463
30427
|
const value = {
|
|
@@ -30527,6 +30491,7 @@ var AgentSession = class _AgentSession {
|
|
|
30527
30491
|
#sessionTitle = null;
|
|
30528
30492
|
#sessionUpdatedAt = "";
|
|
30529
30493
|
#turn = new IdleAcpTurn();
|
|
30494
|
+
#turnHistory = null;
|
|
30530
30495
|
constructor(agent, cwd, additionalDirectories, mobiusSessionId, getObserver, store, metrics, contentExternalizer) {
|
|
30531
30496
|
this.#updates = new AgentUpdateStream((notification) => this.#processUpdate(notification));
|
|
30532
30497
|
this.#additionalDirectories = [...additionalDirectories];
|
|
@@ -30544,7 +30509,8 @@ var AgentSession = class _AgentSession {
|
|
|
30544
30509
|
sessionId: () => this.#mobiusSessionId,
|
|
30545
30510
|
commandId: () => this.#turn.commandId,
|
|
30546
30511
|
assertNativeSession: (sessionId) => this.assertNativeSession(sessionId),
|
|
30547
|
-
observer: getObserver
|
|
30512
|
+
observer: getObserver,
|
|
30513
|
+
recordSessionEventV2: this.#recordLifecycleEventV2
|
|
30548
30514
|
});
|
|
30549
30515
|
this.#connection = new AgentConnection(agent, cwd, this);
|
|
30550
30516
|
this.#contentExternalizer = contentExternalizer;
|
|
@@ -30640,13 +30606,10 @@ var AgentSession = class _AgentSession {
|
|
|
30640
30606
|
}
|
|
30641
30607
|
};
|
|
30642
30608
|
}
|
|
30643
|
-
const
|
|
30644
|
-
return await embedLocalHistoryImages(await
|
|
30609
|
+
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
30610
|
+
return await embedLocalHistoryImages(await history.snapshot(), signal);
|
|
30645
30611
|
};
|
|
30646
30612
|
loadHistoryEventsV2 = async (eventLimit, cursor, signal) => {
|
|
30647
|
-
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
30648
|
-
return new AcpHistoryReplay().eventPage(eventLimit, cursor);
|
|
30649
|
-
}
|
|
30650
30613
|
if (!this.#capabilities.loadSession) {
|
|
30651
30614
|
throw new AcpExecutionError(
|
|
30652
30615
|
"This Agent restores context but does not provide message history.",
|
|
@@ -30654,9 +30617,20 @@ var AgentSession = class _AgentSession {
|
|
|
30654
30617
|
"native_history_unsupported"
|
|
30655
30618
|
);
|
|
30656
30619
|
}
|
|
30657
|
-
const
|
|
30658
|
-
return
|
|
30620
|
+
const history = await this.#completedHistory(signal, "ACP agent exited while loading history");
|
|
30621
|
+
return history.eventPage(eventLimit, cursor, this.#turnHistory);
|
|
30659
30622
|
};
|
|
30623
|
+
async #completedHistory(signal, exitMessage) {
|
|
30624
|
+
if (!this.#prompted && this.#nativeHistoryOwnership.kind === "fresh-session") {
|
|
30625
|
+
if (this.#sessionLoad.kind === "not-requested") {
|
|
30626
|
+
this.#sessionLoad = { history: new AcpHistoryReplay(), kind: "loaded", response: {} };
|
|
30627
|
+
}
|
|
30628
|
+
if (this.#sessionLoad.kind === "loaded") {
|
|
30629
|
+
return this.#sessionLoad.history;
|
|
30630
|
+
}
|
|
30631
|
+
}
|
|
30632
|
+
return (await this.#loadSession(signal, exitMessage)).history;
|
|
30633
|
+
}
|
|
30660
30634
|
async #loadSession(signal, exitMessage) {
|
|
30661
30635
|
if (this.#sessionLoad.kind === "loaded") {
|
|
30662
30636
|
return this.#sessionLoad;
|
|
@@ -31140,19 +31114,7 @@ var AgentSession = class _AgentSession {
|
|
|
31140
31114
|
if (this.#turn.running) {
|
|
31141
31115
|
throw new AcpExecutionError("Another prompt is already running in this conversation", {}, "session_busy");
|
|
31142
31116
|
}
|
|
31143
|
-
|
|
31144
|
-
case "not-requested":
|
|
31145
|
-
break;
|
|
31146
|
-
case "loaded":
|
|
31147
|
-
this.#sessionLoad = { kind: "not-requested" };
|
|
31148
|
-
break;
|
|
31149
|
-
case "capturing":
|
|
31150
|
-
throw new AcpExecutionError("Session history is still loading", {}, "session_busy");
|
|
31151
|
-
default: {
|
|
31152
|
-
const unexpected = this.#sessionLoad;
|
|
31153
|
-
throw new Error(`Unexpected Session load state: ${JSON.stringify(unexpected)}`);
|
|
31154
|
-
}
|
|
31155
|
-
}
|
|
31117
|
+
const completedHistory = this.#capabilities.loadSession ? await this.#completedHistory(options.signal, "ACP agent exited while loading history before a prompt") : null;
|
|
31156
31118
|
const prompt = this.buildPrompt(options);
|
|
31157
31119
|
if (this.#sessionTitle === null || this.#sessionTitle.length === 0) {
|
|
31158
31120
|
this.#sessionTitle = truncate2(options.prompt, 500);
|
|
@@ -31179,6 +31141,23 @@ var AgentSession = class _AgentSession {
|
|
|
31179
31141
|
this.prepareAgentContent
|
|
31180
31142
|
);
|
|
31181
31143
|
this.#turn = running;
|
|
31144
|
+
this.#turnHistory = completedHistory === null ? null : new AcpHistoryReplay();
|
|
31145
|
+
const lifecycleV2 = options.lifecycleV2;
|
|
31146
|
+
if (lifecycleV2 !== void 0) {
|
|
31147
|
+
await this.#recordLifecycleEventV2({
|
|
31148
|
+
payload: { commandId: options.commandId, content: lifecycleV2.content, kind: "prompt.requested" },
|
|
31149
|
+
type: "lifecycle-metadata"
|
|
31150
|
+
});
|
|
31151
|
+
await this.#recordLifecycleEventV2({
|
|
31152
|
+
payload: {
|
|
31153
|
+
attemptId: lifecycleV2.attemptId,
|
|
31154
|
+
commandId: options.commandId,
|
|
31155
|
+
epoch: lifecycleV2.epoch,
|
|
31156
|
+
kind: "prompt.started"
|
|
31157
|
+
},
|
|
31158
|
+
type: "lifecycle-metadata"
|
|
31159
|
+
});
|
|
31160
|
+
}
|
|
31182
31161
|
this.#nativePrompt = {
|
|
31183
31162
|
commandId: options.commandId,
|
|
31184
31163
|
previousTurnId: this.#connection.inProcessAgent?.nativeTurnId?.() ?? null
|
|
@@ -31233,16 +31212,37 @@ var AgentSession = class _AgentSession {
|
|
|
31233
31212
|
this.#lastTerminalCommandId
|
|
31234
31213
|
)
|
|
31235
31214
|
);
|
|
31215
|
+
if (lifecycleV2 !== void 0) {
|
|
31216
|
+
await this.#recordLifecycleEventV2({
|
|
31217
|
+
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: result.stopReason },
|
|
31218
|
+
type: "lifecycle-metadata"
|
|
31219
|
+
});
|
|
31220
|
+
}
|
|
31236
31221
|
return result;
|
|
31237
31222
|
} catch (error62) {
|
|
31238
31223
|
await running.activities.finish();
|
|
31224
|
+
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
31225
|
+
if (lifecycleV2 !== void 0) {
|
|
31226
|
+
await this.#recordLifecycleEventV2({
|
|
31227
|
+
payload: {
|
|
31228
|
+
attemptId: lifecycleV2.attemptId,
|
|
31229
|
+
code: failure2.code,
|
|
31230
|
+
commandId: options.commandId,
|
|
31231
|
+
kind: "prompt.failed",
|
|
31232
|
+
message: truncate2(failure2.message, 500)
|
|
31233
|
+
},
|
|
31234
|
+
type: "lifecycle-metadata"
|
|
31235
|
+
});
|
|
31236
|
+
}
|
|
31239
31237
|
if (error62 instanceof AcpExecutionError) {
|
|
31240
31238
|
throw error62;
|
|
31241
31239
|
}
|
|
31242
|
-
throw
|
|
31243
|
-
cause: error62
|
|
31244
|
-
});
|
|
31240
|
+
throw failure2;
|
|
31245
31241
|
} finally {
|
|
31242
|
+
if (completedHistory !== null && this.#turnHistory !== null) {
|
|
31243
|
+
await completedHistory.append(this.#turnHistory);
|
|
31244
|
+
}
|
|
31245
|
+
this.#turnHistory = null;
|
|
31246
31246
|
this.#turn = new IdleAcpTurn();
|
|
31247
31247
|
}
|
|
31248
31248
|
};
|
|
@@ -31258,41 +31258,80 @@ var AgentSession = class _AgentSession {
|
|
|
31258
31258
|
throw new AcpExecutionError("The target turn is no longer active", {}, "steering_target_unavailable");
|
|
31259
31259
|
}
|
|
31260
31260
|
const prompt = this.buildPrompt(options);
|
|
31261
|
-
const
|
|
31262
|
-
|
|
31263
|
-
|
|
31264
|
-
prompt,
|
|
31265
|
-
|
|
31266
|
-
})
|
|
31267
|
-
|
|
31268
|
-
|
|
31269
|
-
|
|
31270
|
-
|
|
31261
|
+
const lifecycleV2 = options.lifecycleV2;
|
|
31262
|
+
if (lifecycleV2 !== void 0) {
|
|
31263
|
+
await this.#recordLifecycleEventV2({
|
|
31264
|
+
payload: { commandId: options.commandId, content: lifecycleV2.content, kind: "prompt.requested" },
|
|
31265
|
+
type: "lifecycle-metadata"
|
|
31266
|
+
});
|
|
31267
|
+
await this.#recordLifecycleEventV2({
|
|
31268
|
+
payload: {
|
|
31269
|
+
attemptId: lifecycleV2.attemptId,
|
|
31270
|
+
commandId: options.commandId,
|
|
31271
|
+
epoch: lifecycleV2.epoch,
|
|
31272
|
+
kind: "prompt.started"
|
|
31273
|
+
},
|
|
31274
|
+
type: "lifecycle-metadata"
|
|
31275
|
+
});
|
|
31276
|
+
}
|
|
31277
|
+
try {
|
|
31278
|
+
const response = await this.race(
|
|
31279
|
+
this.#connection.connection.agent.request("_session/steering", {
|
|
31280
|
+
_meta: { steering: { idleBehavior: "promptRequired" } },
|
|
31281
|
+
prompt,
|
|
31282
|
+
sessionId: this.#updates.sessionId()
|
|
31283
|
+
}),
|
|
31284
|
+
"ACP agent exited during steering",
|
|
31285
|
+
options.signal
|
|
31286
|
+
);
|
|
31287
|
+
if (!isRecord4(response)) {
|
|
31288
|
+
throw new AcpExecutionError(
|
|
31289
|
+
"ACP agent returned an invalid steering response",
|
|
31290
|
+
{},
|
|
31291
|
+
"acp_invalid_steering_response"
|
|
31292
|
+
);
|
|
31293
|
+
}
|
|
31294
|
+
const outcome = response["outcome"];
|
|
31295
|
+
if (outcome === "injected" || outcome === "startedNewTurn") {
|
|
31296
|
+
if (lifecycleV2 !== void 0) {
|
|
31297
|
+
await this.#recordLifecycleEventV2({
|
|
31298
|
+
payload: { commandId: options.commandId, kind: "prompt.completed", stopReason: "steered" },
|
|
31299
|
+
type: "lifecycle-metadata"
|
|
31300
|
+
});
|
|
31301
|
+
}
|
|
31302
|
+
return outcome;
|
|
31303
|
+
}
|
|
31304
|
+
if (outcome === "promptRequired") {
|
|
31305
|
+
throw new AcpExecutionError(
|
|
31306
|
+
"The target turn finished before steering could be injected",
|
|
31307
|
+
{},
|
|
31308
|
+
"steering_target_unavailable"
|
|
31309
|
+
);
|
|
31310
|
+
}
|
|
31311
|
+
if (outcome === "failed") {
|
|
31312
|
+
throw new AcpExecutionError("The Agent could not inject steering", {}, "steering_failed");
|
|
31313
|
+
}
|
|
31271
31314
|
throw new AcpExecutionError(
|
|
31272
31315
|
"ACP agent returned an invalid steering response",
|
|
31273
31316
|
{},
|
|
31274
31317
|
"acp_invalid_steering_response"
|
|
31275
31318
|
);
|
|
31319
|
+
} catch (error62) {
|
|
31320
|
+
const failure2 = error62 instanceof AcpExecutionError ? error62 : new AcpExecutionError("ACP agent execution failed", { cause: error62 });
|
|
31321
|
+
if (lifecycleV2 !== void 0) {
|
|
31322
|
+
await this.#recordLifecycleEventV2({
|
|
31323
|
+
payload: {
|
|
31324
|
+
attemptId: lifecycleV2.attemptId,
|
|
31325
|
+
code: failure2.code,
|
|
31326
|
+
commandId: options.commandId,
|
|
31327
|
+
kind: "prompt.failed",
|
|
31328
|
+
message: truncate2(failure2.message, 500)
|
|
31329
|
+
},
|
|
31330
|
+
type: "lifecycle-metadata"
|
|
31331
|
+
});
|
|
31332
|
+
}
|
|
31333
|
+
throw failure2;
|
|
31276
31334
|
}
|
|
31277
|
-
const outcome = response["outcome"];
|
|
31278
|
-
if (outcome === "injected" || outcome === "startedNewTurn") {
|
|
31279
|
-
return outcome;
|
|
31280
|
-
}
|
|
31281
|
-
if (outcome === "promptRequired") {
|
|
31282
|
-
throw new AcpExecutionError(
|
|
31283
|
-
"The target turn finished before steering could be injected",
|
|
31284
|
-
{},
|
|
31285
|
-
"steering_target_unavailable"
|
|
31286
|
-
);
|
|
31287
|
-
}
|
|
31288
|
-
if (outcome === "failed") {
|
|
31289
|
-
throw new AcpExecutionError("The Agent could not inject steering", {}, "steering_failed");
|
|
31290
|
-
}
|
|
31291
|
-
throw new AcpExecutionError(
|
|
31292
|
-
"ACP agent returned an invalid steering response",
|
|
31293
|
-
{},
|
|
31294
|
-
"acp_invalid_steering_response"
|
|
31295
|
-
);
|
|
31296
31335
|
};
|
|
31297
31336
|
cancel = async () => {
|
|
31298
31337
|
const capturedProcesses = await this.#connection.captureProcessTree();
|
|
@@ -31313,6 +31352,13 @@ var AgentSession = class _AgentSession {
|
|
|
31313
31352
|
onElicitation = (request, signal) => this.#interactions.onElicitation(request, signal);
|
|
31314
31353
|
onElicitationComplete = (notification) => this.#interactions.onElicitationComplete(notification);
|
|
31315
31354
|
onUpdate = (notification) => this.#updates.receive(notification);
|
|
31355
|
+
#recordLifecycleEventV2 = async (event) => {
|
|
31356
|
+
if (event.type !== "lifecycle-metadata" || this.#sessionLoad.kind !== "loaded") {
|
|
31357
|
+
return;
|
|
31358
|
+
}
|
|
31359
|
+
const position = this.#turnHistory === null ? this.#sessionLoad.history.recordLifecycle(event) : this.#sessionLoad.history.eventCount() + this.#turnHistory.recordLifecycle(event);
|
|
31360
|
+
await this.#getObserver().onSessionEventV2?.(this.#mobiusSessionId, event, position);
|
|
31361
|
+
};
|
|
31316
31362
|
selectNativeSession = (sessionId) => {
|
|
31317
31363
|
this.#updates.select(sessionId);
|
|
31318
31364
|
this.#nativeHistoryOwnership = { kind: "agent-owned" };
|
|
@@ -31329,9 +31375,20 @@ var AgentSession = class _AgentSession {
|
|
|
31329
31375
|
if (this.#sessionLoad.kind === "capturing") {
|
|
31330
31376
|
await this.#sessionLoad.history.record(update, rawUpdate);
|
|
31331
31377
|
} else {
|
|
31332
|
-
const
|
|
31333
|
-
if (
|
|
31334
|
-
|
|
31378
|
+
const onSessionEventV2 = this.#getObserver().onSessionEventV2;
|
|
31379
|
+
if (this.#turnHistory !== null) {
|
|
31380
|
+
const completedEventCount = this.#sessionLoad.kind === "loaded" ? this.#sessionLoad.history.eventCount() : 0;
|
|
31381
|
+
await this.#turnHistory.record(update, rawUpdate, async (turnPosition) => {
|
|
31382
|
+
await onSessionEventV2?.(
|
|
31383
|
+
this.#mobiusSessionId,
|
|
31384
|
+
{ payload: rawUpdate, type: "acp" },
|
|
31385
|
+
completedEventCount + turnPosition
|
|
31386
|
+
);
|
|
31387
|
+
});
|
|
31388
|
+
} else if (this.#sessionLoad.kind === "loaded") {
|
|
31389
|
+
await this.#sessionLoad.history.record(update, rawUpdate, async (position) => {
|
|
31390
|
+
await onSessionEventV2?.(this.#mobiusSessionId, { payload: rawUpdate, type: "acp" }, position);
|
|
31391
|
+
});
|
|
31335
31392
|
}
|
|
31336
31393
|
}
|
|
31337
31394
|
if (this.#sessionLoad.kind === "capturing" && (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")) {
|
|
@@ -33025,13 +33082,19 @@ var AgentRuntimeManager = class {
|
|
|
33025
33082
|
// src/acp/run-prompt.ts
|
|
33026
33083
|
async function runAcpPrompt(options) {
|
|
33027
33084
|
const agentRuntime = new AgentRuntimeManager();
|
|
33085
|
+
const commandId = crypto.randomUUID();
|
|
33028
33086
|
try {
|
|
33029
33087
|
return await agentRuntime.runPrompt({
|
|
33030
33088
|
additionalDirectories: [],
|
|
33031
33089
|
agent: new LocalAgentDefinition("test-agent", "Test agent", options.agentCommand, options.agentArguments),
|
|
33032
33090
|
cwd: options.cwd,
|
|
33033
|
-
commandId
|
|
33091
|
+
commandId,
|
|
33034
33092
|
images: [],
|
|
33093
|
+
lifecycleV2: {
|
|
33094
|
+
attemptId: crypto.randomUUID(),
|
|
33095
|
+
content: [{ text: options.prompt, type: "text" }],
|
|
33096
|
+
epoch: crypto.randomUUID()
|
|
33097
|
+
},
|
|
33035
33098
|
onActivity: options.onActivity,
|
|
33036
33099
|
...options.onNarration === void 0 ? {} : { onNarration: options.onNarration },
|
|
33037
33100
|
onText: options.onText,
|
|
@@ -34140,7 +34203,6 @@ var CodexAppServerClient = class {
|
|
|
34140
34203
|
// src/acp/codex/items.ts
|
|
34141
34204
|
var TOOL_OUTPUT_CHARACTER_LIMIT = 32768;
|
|
34142
34205
|
var TITLE_CHARACTER_LIMIT = 500;
|
|
34143
|
-
var CODEX_META_KEY = "codex";
|
|
34144
34206
|
function truncate4(value, limit) {
|
|
34145
34207
|
return value.length <= limit ? value : value.slice(0, limit);
|
|
34146
34208
|
}
|
|
@@ -34279,12 +34341,6 @@ function reasoningText(item) {
|
|
|
34279
34341
|
}
|
|
34280
34342
|
return boundedParagraphs(item.summary.length > 0 ? item.summary : item.content, TOOL_OUTPUT_CHARACTER_LIMIT);
|
|
34281
34343
|
}
|
|
34282
|
-
function agentMessageMeta(phase) {
|
|
34283
|
-
if (phase == null) {
|
|
34284
|
-
return null;
|
|
34285
|
-
}
|
|
34286
|
-
return { [CODEX_META_KEY]: { phase } };
|
|
34287
|
-
}
|
|
34288
34344
|
|
|
34289
34345
|
// src/acp/codex/settings.ts
|
|
34290
34346
|
var APPROVAL_TIMEOUT_MILLISECONDS = 36e5;
|
|
@@ -34729,8 +34785,8 @@ function promptInput(prompt) {
|
|
|
34729
34785
|
function isCompactPrompt(prompt) {
|
|
34730
34786
|
return prompt.length === 1 && prompt[0]?.type === "text" && prompt[0].text.trim() === "/compact";
|
|
34731
34787
|
}
|
|
34732
|
-
function
|
|
34733
|
-
const
|
|
34788
|
+
function steeringPrompt(prompt) {
|
|
34789
|
+
const blocks = [];
|
|
34734
34790
|
for (const block of prompt) {
|
|
34735
34791
|
if (typeof block !== "object" || block === null) {
|
|
34736
34792
|
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
@@ -34741,7 +34797,7 @@ function steeringPromptInput(prompt) {
|
|
|
34741
34797
|
if (typeof text2 !== "string") {
|
|
34742
34798
|
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
34743
34799
|
}
|
|
34744
|
-
|
|
34800
|
+
blocks.push({ content: { text: text2, type: "text" }, input: { text: text2, text_elements: [], type: "text" } });
|
|
34745
34801
|
continue;
|
|
34746
34802
|
}
|
|
34747
34803
|
if (type === "image") {
|
|
@@ -34750,7 +34806,10 @@ function steeringPromptInput(prompt) {
|
|
|
34750
34806
|
if (typeof data !== "string" || typeof mimeType !== "string") {
|
|
34751
34807
|
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
34752
34808
|
}
|
|
34753
|
-
|
|
34809
|
+
blocks.push({
|
|
34810
|
+
content: { data, mimeType, type: "image" },
|
|
34811
|
+
input: { type: "image", url: `data:${mimeType};base64,${data}` }
|
|
34812
|
+
});
|
|
34754
34813
|
continue;
|
|
34755
34814
|
}
|
|
34756
34815
|
if (type === "resource") {
|
|
@@ -34758,24 +34817,40 @@ function steeringPromptInput(prompt) {
|
|
|
34758
34817
|
if (typeof resource !== "object" || resource === null) {
|
|
34759
34818
|
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
34760
34819
|
}
|
|
34820
|
+
const uri = Reflect.get(resource, "uri");
|
|
34761
34821
|
const text2 = Reflect.get(resource, "text");
|
|
34762
|
-
|
|
34822
|
+
const blob2 = Reflect.get(resource, "blob");
|
|
34823
|
+
if (typeof uri !== "string" || typeof text2 !== "string" && typeof blob2 !== "string" || text2 !== void 0 && typeof text2 !== "string" || blob2 !== void 0 && typeof blob2 !== "string") {
|
|
34763
34824
|
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
34764
34825
|
}
|
|
34765
|
-
|
|
34826
|
+
blocks.push({
|
|
34827
|
+
content: typeof text2 === "string" ? { resource: { text: text2, uri }, type: "resource" } : { resource: { blob: blob2, uri }, type: "resource" },
|
|
34828
|
+
input: { text: text2 ?? "", text_elements: [], type: "text" }
|
|
34829
|
+
});
|
|
34766
34830
|
continue;
|
|
34767
34831
|
}
|
|
34768
34832
|
if (type === "resource_link") {
|
|
34833
|
+
const name2 = Reflect.get(block, "name");
|
|
34769
34834
|
const uri = Reflect.get(block, "uri");
|
|
34770
|
-
if (typeof uri !== "string") {
|
|
34835
|
+
if (typeof name2 !== "string" || typeof uri !== "string") {
|
|
34771
34836
|
throw new AcpExecutionError("Codex received an invalid steering prompt", {}, "invalid_request");
|
|
34772
34837
|
}
|
|
34773
|
-
|
|
34838
|
+
blocks.push({
|
|
34839
|
+
content: { name: name2, type: "resource_link", uri },
|
|
34840
|
+
input: { text: `Resource: ${uri}`, text_elements: [], type: "text" }
|
|
34841
|
+
});
|
|
34774
34842
|
continue;
|
|
34775
34843
|
}
|
|
34776
34844
|
throw new AcpExecutionError("Codex received an unsupported steering prompt", {}, "invalid_request");
|
|
34777
34845
|
}
|
|
34778
|
-
return
|
|
34846
|
+
return blocks;
|
|
34847
|
+
}
|
|
34848
|
+
function agentMessageUpdate(messageId, text2, phase) {
|
|
34849
|
+
return {
|
|
34850
|
+
content: { text: text2, type: "text" },
|
|
34851
|
+
messageId,
|
|
34852
|
+
sessionUpdate: phase === "commentary" ? "agent_thought_chunk" : "agent_message_chunk"
|
|
34853
|
+
};
|
|
34779
34854
|
}
|
|
34780
34855
|
function userInputSchema(questions) {
|
|
34781
34856
|
const properties = {};
|
|
@@ -34915,6 +34990,14 @@ var CodexAcpAgent = class {
|
|
|
34915
34990
|
if (isCompactPrompt(context.params.prompt)) {
|
|
34916
34991
|
return await this.#compact(context.signal);
|
|
34917
34992
|
}
|
|
34993
|
+
const messageId = crypto.randomUUID();
|
|
34994
|
+
for (const content of context.params.prompt) {
|
|
34995
|
+
await this.#emit({
|
|
34996
|
+
content,
|
|
34997
|
+
messageId,
|
|
34998
|
+
sessionUpdate: "user_message_chunk"
|
|
34999
|
+
});
|
|
35000
|
+
}
|
|
34918
35001
|
return await this.#runTurn(promptInput(context.params.prompt), context.signal);
|
|
34919
35002
|
}).onRequest(
|
|
34920
35003
|
"_session/steering",
|
|
@@ -35002,12 +35085,7 @@ var CodexAcpAgent = class {
|
|
|
35002
35085
|
continue;
|
|
35003
35086
|
}
|
|
35004
35087
|
if (item.type === "agentMessage") {
|
|
35005
|
-
await this.#emit(
|
|
35006
|
-
_meta: agentMessageMeta(item.phase),
|
|
35007
|
-
content: { text: item.text, type: "text" },
|
|
35008
|
-
messageId: item.id,
|
|
35009
|
-
sessionUpdate: "agent_message_chunk"
|
|
35010
|
-
});
|
|
35088
|
+
await this.#emit(agentMessageUpdate(item.id, item.text, item.phase));
|
|
35011
35089
|
continue;
|
|
35012
35090
|
}
|
|
35013
35091
|
const update = toolCallUpdate(item, "snapshot");
|
|
@@ -35144,12 +35222,7 @@ var CodexAcpAgent = class {
|
|
|
35144
35222
|
const phase = this.#agentMessages.get(decoded.data.itemId)?.phase;
|
|
35145
35223
|
this.#agentMessages.set(decoded.data.itemId, { phase, kind: "streaming" });
|
|
35146
35224
|
await this.#enqueue(async () => {
|
|
35147
|
-
await this.#emit(
|
|
35148
|
-
_meta: agentMessageMeta(phase),
|
|
35149
|
-
content: { text: decoded.data.delta, type: "text" },
|
|
35150
|
-
messageId: decoded.data.itemId,
|
|
35151
|
-
sessionUpdate: "agent_message_chunk"
|
|
35152
|
-
});
|
|
35225
|
+
await this.#emit(agentMessageUpdate(decoded.data.itemId, decoded.data.delta, phase));
|
|
35153
35226
|
});
|
|
35154
35227
|
}
|
|
35155
35228
|
return;
|
|
@@ -35172,12 +35245,7 @@ var CodexAcpAgent = class {
|
|
|
35172
35245
|
return;
|
|
35173
35246
|
}
|
|
35174
35247
|
await this.#enqueue(async () => {
|
|
35175
|
-
await this.#emit(
|
|
35176
|
-
_meta: agentMessageMeta(item.phase),
|
|
35177
|
-
content: { text: item.text, type: "text" },
|
|
35178
|
-
messageId: item.id,
|
|
35179
|
-
sessionUpdate: "agent_message_chunk"
|
|
35180
|
-
});
|
|
35248
|
+
await this.#emit(agentMessageUpdate(item.id, item.text, item.phase));
|
|
35181
35249
|
});
|
|
35182
35250
|
return;
|
|
35183
35251
|
}
|
|
@@ -35411,14 +35479,22 @@ var CodexAcpAgent = class {
|
|
|
35411
35479
|
if (sessionId !== this.#nativeSessionId || active === null || active.turn.id.length === 0) {
|
|
35412
35480
|
return { outcome: "promptRequired", reason: "noRunningTurn" };
|
|
35413
35481
|
}
|
|
35414
|
-
const
|
|
35415
|
-
if (
|
|
35482
|
+
const steering = steeringPrompt(prompt);
|
|
35483
|
+
if (steering.length === 0) {
|
|
35416
35484
|
throw new AcpExecutionError("Codex received an empty steering request", {}, "invalid_request");
|
|
35417
35485
|
}
|
|
35486
|
+
const messageId = crypto.randomUUID();
|
|
35487
|
+
for (const block of steering) {
|
|
35488
|
+
await this.#emit({ content: block.content, messageId, sessionUpdate: "user_message_chunk" });
|
|
35489
|
+
}
|
|
35418
35490
|
const response = turnSteerResponseSchema.parse(
|
|
35419
35491
|
await this.#appServer.request(
|
|
35420
35492
|
"turn/steer",
|
|
35421
|
-
{
|
|
35493
|
+
{
|
|
35494
|
+
expectedTurnId: active.turn.id,
|
|
35495
|
+
input: steering.map((block) => block.input),
|
|
35496
|
+
threadId: this.#nativeSessionId
|
|
35497
|
+
},
|
|
35422
35498
|
AbortSignal.any([signal, AbortSignal.timeout(APPROVAL_TIMEOUT_MILLISECONDS2)])
|
|
35423
35499
|
)
|
|
35424
35500
|
);
|
|
@@ -38098,7 +38174,7 @@ function isRuntimeRelayRevocation(closeCode, closeReason) {
|
|
|
38098
38174
|
}
|
|
38099
38175
|
|
|
38100
38176
|
// src/run-daemon.ts
|
|
38101
|
-
import { createHash as createHash8, randomUUID as
|
|
38177
|
+
import { createHash as createHash8, randomUUID as randomUUID9 } from "node:crypto";
|
|
38102
38178
|
import { join as join19 } from "node:path";
|
|
38103
38179
|
import { styleText } from "node:util";
|
|
38104
38180
|
|
|
@@ -39179,8 +39255,8 @@ var DaemonAcpObserver = class {
|
|
|
39179
39255
|
this.#record = record2;
|
|
39180
39256
|
this.#recordV2 = recordV2;
|
|
39181
39257
|
}
|
|
39182
|
-
|
|
39183
|
-
this.#recordV2(sessionId,
|
|
39258
|
+
onSessionEventV2 = (sessionId, event, position) => {
|
|
39259
|
+
this.#recordV2(sessionId, event, position);
|
|
39184
39260
|
return Promise.resolve();
|
|
39185
39261
|
};
|
|
39186
39262
|
onCommands = (event) => {
|
|
@@ -39197,18 +39273,10 @@ var DaemonAcpObserver = class {
|
|
|
39197
39273
|
};
|
|
39198
39274
|
onElicitation = (event) => {
|
|
39199
39275
|
this.#record(event.sessionId, event);
|
|
39200
|
-
this.#recordV2(event.sessionId, {
|
|
39201
|
-
payload: { event, kind: "session.elicitation.requested" },
|
|
39202
|
-
type: "lifecycle-metadata"
|
|
39203
|
-
});
|
|
39204
39276
|
return Promise.resolve();
|
|
39205
39277
|
};
|
|
39206
39278
|
onElicitationResolved = (event) => {
|
|
39207
39279
|
this.#record(event.sessionId, event);
|
|
39208
|
-
this.#recordV2(event.sessionId, {
|
|
39209
|
-
payload: { event, kind: "session.elicitation.resolved" },
|
|
39210
|
-
type: "lifecycle-metadata"
|
|
39211
|
-
});
|
|
39212
39280
|
return Promise.resolve();
|
|
39213
39281
|
};
|
|
39214
39282
|
onInfo = (event) => {
|
|
@@ -39217,18 +39285,10 @@ var DaemonAcpObserver = class {
|
|
|
39217
39285
|
};
|
|
39218
39286
|
onPermission = (event) => {
|
|
39219
39287
|
this.#record(event.sessionId, event);
|
|
39220
|
-
this.#recordV2(event.sessionId, {
|
|
39221
|
-
payload: { event, kind: "session.permission.requested" },
|
|
39222
|
-
type: "lifecycle-metadata"
|
|
39223
|
-
});
|
|
39224
39288
|
return Promise.resolve();
|
|
39225
39289
|
};
|
|
39226
39290
|
onPermissionResolved = (event) => {
|
|
39227
39291
|
this.#record(event.sessionId, event);
|
|
39228
|
-
this.#recordV2(event.sessionId, {
|
|
39229
|
-
payload: { event, kind: "session.permission.resolved" },
|
|
39230
|
-
type: "lifecycle-metadata"
|
|
39231
|
-
});
|
|
39232
39292
|
return Promise.resolve();
|
|
39233
39293
|
};
|
|
39234
39294
|
onUsage = (event) => {
|
|
@@ -40063,14 +40123,14 @@ function decodeHistory(thread, value, options) {
|
|
|
40063
40123
|
if (options.detail === "rich" && historyItem.text.length > 0) {
|
|
40064
40124
|
append({
|
|
40065
40125
|
activities: [
|
|
40066
|
-
activity(historyItem.id ?? `
|
|
40126
|
+
activity(historyItem.id ?? `reasoning-${sequence.toString()}`, "reasoning", sequence, {
|
|
40067
40127
|
input: "",
|
|
40068
40128
|
locations: [],
|
|
40069
40129
|
name: "",
|
|
40070
40130
|
output: historyItem.text,
|
|
40071
40131
|
status: "completed",
|
|
40072
|
-
title: "
|
|
40073
|
-
toolKind: ""
|
|
40132
|
+
title: "Reasoning",
|
|
40133
|
+
toolKind: "think"
|
|
40074
40134
|
})
|
|
40075
40135
|
],
|
|
40076
40136
|
content: [],
|
|
@@ -42088,9 +42148,6 @@ async function streamLocalFile(command, send2, signal, workingDirectory, externa
|
|
|
42088
42148
|
});
|
|
42089
42149
|
}
|
|
42090
42150
|
|
|
42091
|
-
// src/daemon-history-commands.ts
|
|
42092
|
-
import { createHash as createHash7 } from "node:crypto";
|
|
42093
|
-
|
|
42094
42151
|
// src/authorization/resolve-session-directories.ts
|
|
42095
42152
|
import { basename as basename7 } from "node:path";
|
|
42096
42153
|
var ResolvedSessionDirectories = class {
|
|
@@ -42358,72 +42415,8 @@ function paginateLiveSessionHistory(history, activeTurn, sessionId, encodedCurso
|
|
|
42358
42415
|
}
|
|
42359
42416
|
return paginateActiveTurn(historical, activeTurn, sessionId, cursor?.endIndex ?? activeTurn.messages.length, limit);
|
|
42360
42417
|
}
|
|
42361
|
-
function mergeLiveSessionHistory(history, activeTurn, sessionId) {
|
|
42362
|
-
const page = paginateLiveSessionHistory(history, activeTurn, sessionId, null, 1e3);
|
|
42363
|
-
if (page.status === "unavailable") {
|
|
42364
|
-
return { cause: page.cause, status: "unavailable" };
|
|
42365
|
-
}
|
|
42366
|
-
return {
|
|
42367
|
-
coveredCommandIds: page.coveredCommandIds,
|
|
42368
|
-
...page.streamPosition === void 0 ? {} : { streamPosition: page.streamPosition },
|
|
42369
|
-
coveredMessageIds: page.coveredMessageIds,
|
|
42370
|
-
messages: page.messages,
|
|
42371
|
-
status: "available",
|
|
42372
|
-
truncated: page.truncated || page.nextCursor !== null
|
|
42373
|
-
};
|
|
42374
|
-
}
|
|
42375
42418
|
|
|
42376
42419
|
// src/daemon-history-commands.ts
|
|
42377
|
-
async function executeSessionLiveHistoryLoad(socket, command, config2, directories, audit, sessions, activeTurn, signal) {
|
|
42378
|
-
try {
|
|
42379
|
-
const resolved = await resolveSessionDirectories(
|
|
42380
|
-
directories,
|
|
42381
|
-
config2.bindingId,
|
|
42382
|
-
command.directoryId,
|
|
42383
|
-
command.additionalDirectoryIds,
|
|
42384
|
-
signal
|
|
42385
|
-
);
|
|
42386
|
-
const history = await sessions.loadSessionHistory({
|
|
42387
|
-
additionalDirectories: resolved.additionalDirectories,
|
|
42388
|
-
agent: config2.catalog.find(command.agentId),
|
|
42389
|
-
cwd: resolved.cwd,
|
|
42390
|
-
sessionId: command.sessionId,
|
|
42391
|
-
signal
|
|
42392
|
-
});
|
|
42393
|
-
signal.throwIfAborted();
|
|
42394
|
-
const mergedHistory = mergeLiveSessionHistory(history, activeTurn(command.sessionId), command.sessionId);
|
|
42395
|
-
audit.record({
|
|
42396
|
-
commandId: command.requestId,
|
|
42397
|
-
event: "session_history_loaded",
|
|
42398
|
-
sessionId: command.sessionId
|
|
42399
|
-
});
|
|
42400
|
-
send(socket, {
|
|
42401
|
-
history: mergedHistory,
|
|
42402
|
-
kind: "session.live-history.loaded",
|
|
42403
|
-
requestId: command.requestId,
|
|
42404
|
-
sessionId: command.sessionId
|
|
42405
|
-
});
|
|
42406
|
-
} catch (error62) {
|
|
42407
|
-
if (signal.aborted) {
|
|
42408
|
-
return;
|
|
42409
|
-
}
|
|
42410
|
-
audit.record({
|
|
42411
|
-
commandId: command.requestId,
|
|
42412
|
-
details: { code: operationErrorCode(error62) },
|
|
42413
|
-
event: "session_history_unavailable",
|
|
42414
|
-
sessionId: command.sessionId
|
|
42415
|
-
});
|
|
42416
|
-
send(socket, {
|
|
42417
|
-
history: {
|
|
42418
|
-
status: "unavailable",
|
|
42419
|
-
cause: { code: operationErrorCode(error62), message: operationErrorMessage(error62) }
|
|
42420
|
-
},
|
|
42421
|
-
kind: "session.live-history.loaded",
|
|
42422
|
-
requestId: command.requestId,
|
|
42423
|
-
sessionId: command.sessionId
|
|
42424
|
-
});
|
|
42425
|
-
}
|
|
42426
|
-
}
|
|
42427
42420
|
async function executeSessionLiveHistoryPageLoad(socket, command, config2, directories, audit, sessions, activeTurn, signal) {
|
|
42428
42421
|
try {
|
|
42429
42422
|
const resolved = await resolveSessionDirectories(
|
|
@@ -42481,20 +42474,7 @@ async function executeSessionLiveHistoryPageLoad(socket, command, config2, direc
|
|
|
42481
42474
|
});
|
|
42482
42475
|
}
|
|
42483
42476
|
}
|
|
42484
|
-
function
|
|
42485
|
-
const encoded = JSON.stringify(update);
|
|
42486
|
-
const eventId = `native-${createHash7("sha256").update(sessionId).update(":").update(position.toString()).update(":").update(encoded).digest("hex")}`;
|
|
42487
|
-
return {
|
|
42488
|
-
eventId,
|
|
42489
|
-
payload: update,
|
|
42490
|
-
position: position.toString(),
|
|
42491
|
-
provenance: { kind: "original" },
|
|
42492
|
-
recordedAt: "1970-01-01T00:00:00.000Z",
|
|
42493
|
-
sessionId,
|
|
42494
|
-
type: "acp"
|
|
42495
|
-
};
|
|
42496
|
-
}
|
|
42497
|
-
async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, diagnostics, sessions, executingPromptRequest, signal) {
|
|
42477
|
+
async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, directories, audit, diagnostics, sessions, eventLogV2, signal) {
|
|
42498
42478
|
try {
|
|
42499
42479
|
const resolved = await resolveSessionDirectories(
|
|
42500
42480
|
directories,
|
|
@@ -42503,20 +42483,18 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
42503
42483
|
command.additionalDirectoryIds,
|
|
42504
42484
|
signal
|
|
42505
42485
|
);
|
|
42506
|
-
const
|
|
42507
|
-
|
|
42508
|
-
|
|
42509
|
-
|
|
42510
|
-
|
|
42511
|
-
|
|
42512
|
-
|
|
42513
|
-
|
|
42514
|
-
|
|
42515
|
-
command.cursor
|
|
42516
|
-
);
|
|
42486
|
+
const loadOptions = {
|
|
42487
|
+
additionalDirectories: resolved.additionalDirectories,
|
|
42488
|
+
agent: config2.catalog.find(command.agentId),
|
|
42489
|
+
cwd: resolved.cwd,
|
|
42490
|
+
sessionId: command.sessionId,
|
|
42491
|
+
signal
|
|
42492
|
+
};
|
|
42493
|
+
const recovery = eventLogV2.promptRequestRecovery(command.sessionId);
|
|
42494
|
+
const replay = await sessions.loadSessionEventsV2(loadOptions, command.eventLimit, command.cursor);
|
|
42517
42495
|
signal.throwIfAborted();
|
|
42518
|
-
const events = replay.
|
|
42519
|
-
(
|
|
42496
|
+
const events = replay.events.map(
|
|
42497
|
+
(event, index2) => eventLogV2.event(command.sessionId, replay.startPosition + index2, event, "1970-01-01T00:00:00.000Z")
|
|
42520
42498
|
);
|
|
42521
42499
|
const tailCursor = events.at(-1)?.eventId ?? "";
|
|
42522
42500
|
audit.record({
|
|
@@ -42526,14 +42504,15 @@ async function executeSessionLiveHistoryV2PageLoad(socket, command, config2, dir
|
|
|
42526
42504
|
});
|
|
42527
42505
|
send(socket, {
|
|
42528
42506
|
events: {
|
|
42529
|
-
|
|
42530
|
-
|
|
42507
|
+
events: {
|
|
42508
|
+
daemonGenerationId: eventLogV2.daemonGenerationId,
|
|
42531
42509
|
events,
|
|
42532
42510
|
nextCursor: replay.nextCursor,
|
|
42533
42511
|
tailCursor,
|
|
42534
42512
|
truncated: replay.truncated,
|
|
42535
42513
|
version: 2
|
|
42536
|
-
}
|
|
42514
|
+
},
|
|
42515
|
+
queuedPromptRequests: recovery.queuedPromptRequests
|
|
42537
42516
|
},
|
|
42538
42517
|
kind: "session.live-history.v2.page.loaded",
|
|
42539
42518
|
requestId: command.requestId,
|
|
@@ -42983,7 +42962,7 @@ async function executePrompt({
|
|
|
42983
42962
|
}
|
|
42984
42963
|
}
|
|
42985
42964
|
const stream = activateAttempt();
|
|
42986
|
-
eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
|
|
42965
|
+
const lifecycleV2 = eventLogV2.started(command.sessionId, command.commandId, attemptId, stream.epoch);
|
|
42987
42966
|
if (!prepared.prompted) {
|
|
42988
42967
|
const listing = await directories.list(config2.bindingId, command.directoryId, signal);
|
|
42989
42968
|
publisher.publish(command.sessionId, {
|
|
@@ -43020,6 +42999,7 @@ async function executePrompt({
|
|
|
43020
42999
|
commandId: command.commandId,
|
|
43021
43000
|
cwd: resolved.cwd,
|
|
43022
43001
|
images: attachments.images,
|
|
43002
|
+
lifecycleV2,
|
|
43023
43003
|
prompt: command.prompt,
|
|
43024
43004
|
resources: attachments.resources,
|
|
43025
43005
|
sessionId: command.sessionId,
|
|
@@ -43035,6 +43015,7 @@ async function executePrompt({
|
|
|
43035
43015
|
cwd: resolved.cwd,
|
|
43036
43016
|
disposition: availability.disposition,
|
|
43037
43017
|
images: attachments.images,
|
|
43018
|
+
lifecycleV2,
|
|
43038
43019
|
onActivity: events.recordActivity,
|
|
43039
43020
|
onNarration: events.recordNarration,
|
|
43040
43021
|
onText: events.recordText,
|
|
@@ -43426,20 +43407,6 @@ function createDaemonCommandHandler({
|
|
|
43426
43407
|
return {
|
|
43427
43408
|
handle: (message) => {
|
|
43428
43409
|
const kind = message.kind;
|
|
43429
|
-
if (kind === SESSION_LIVE_HISTORY_LOAD_KIND) {
|
|
43430
|
-
const command2 = message;
|
|
43431
|
-
void executeSessionLiveHistoryLoad(
|
|
43432
|
-
socket,
|
|
43433
|
-
command2,
|
|
43434
|
-
config2,
|
|
43435
|
-
directories,
|
|
43436
|
-
audit,
|
|
43437
|
-
sessions,
|
|
43438
|
-
activeTurnRecovery,
|
|
43439
|
-
signal
|
|
43440
|
-
);
|
|
43441
|
-
return;
|
|
43442
|
-
}
|
|
43443
43410
|
if (kind === SESSION_LIVE_HISTORY_PAGE_LOAD_KIND) {
|
|
43444
43411
|
const command2 = message;
|
|
43445
43412
|
void executeSessionLiveHistoryPageLoad(
|
|
@@ -43463,7 +43430,7 @@ function createDaemonCommandHandler({
|
|
|
43463
43430
|
audit,
|
|
43464
43431
|
diagnostics,
|
|
43465
43432
|
sessions,
|
|
43466
|
-
eventLogV2
|
|
43433
|
+
eventLogV2,
|
|
43467
43434
|
signal
|
|
43468
43435
|
);
|
|
43469
43436
|
return;
|
|
@@ -44116,10 +44083,6 @@ import { WebSocket as WebSocket9 } from "undici";
|
|
|
44116
44083
|
var MAX_BUFFERED_BYTES = 32 * 1024 * 1024;
|
|
44117
44084
|
var DaemonSessionEventPublisher = class {
|
|
44118
44085
|
#socket = null;
|
|
44119
|
-
#store;
|
|
44120
|
-
constructor(store) {
|
|
44121
|
-
this.#store = store;
|
|
44122
|
-
}
|
|
44123
44086
|
connect = (socket) => {
|
|
44124
44087
|
this.#socket = socket;
|
|
44125
44088
|
};
|
|
@@ -44171,7 +44134,6 @@ var DaemonSessionEventPublisher = class {
|
|
|
44171
44134
|
}
|
|
44172
44135
|
};
|
|
44173
44136
|
publishV2 = (event) => {
|
|
44174
|
-
this.#store.appendExecutingPromptEventV2(event);
|
|
44175
44137
|
const socket = this.#socket;
|
|
44176
44138
|
if (socket === null || socket.readyState !== WebSocket9.OPEN) {
|
|
44177
44139
|
return;
|
|
@@ -44198,7 +44160,7 @@ var SystemDaemonTimer = class {
|
|
|
44198
44160
|
var systemDaemonTimer = new SystemDaemonTimer();
|
|
44199
44161
|
|
|
44200
44162
|
// src/session-event-log-v2.ts
|
|
44201
|
-
|
|
44163
|
+
import { createHash as createHash7, randomUUID as randomUUID8 } from "node:crypto";
|
|
44202
44164
|
function promptContent(command) {
|
|
44203
44165
|
const content = [];
|
|
44204
44166
|
if (command.prompt.length > 0) {
|
|
@@ -44222,176 +44184,59 @@ function promptContent(command) {
|
|
|
44222
44184
|
}
|
|
44223
44185
|
return content;
|
|
44224
44186
|
}
|
|
44187
|
+
function sessionEventV22(daemonGenerationId, sessionId, position, event, recordedAt) {
|
|
44188
|
+
const sessionPrefix = createHash7("sha256").update(sessionId).digest("hex").slice(0, 16);
|
|
44189
|
+
return {
|
|
44190
|
+
eventId: `event-${daemonGenerationId}-${sessionPrefix}-${position.toString().padStart(16, "0")}`,
|
|
44191
|
+
...event,
|
|
44192
|
+
position: position.toString(),
|
|
44193
|
+
provenance: { kind: "original" },
|
|
44194
|
+
recordedAt,
|
|
44195
|
+
sessionId
|
|
44196
|
+
};
|
|
44197
|
+
}
|
|
44225
44198
|
var DaemonSessionEventLogV2 = class {
|
|
44226
|
-
|
|
44227
|
-
#requests = /* @__PURE__ */ new Map();
|
|
44228
|
-
#loadedRequestSessions = /* @__PURE__ */ new Set();
|
|
44199
|
+
daemonGenerationId = randomUUID8();
|
|
44229
44200
|
#publisher;
|
|
44230
|
-
#
|
|
44231
|
-
constructor(publisher
|
|
44201
|
+
#queued = /* @__PURE__ */ new Map();
|
|
44202
|
+
constructor(publisher) {
|
|
44232
44203
|
this.#publisher = publisher;
|
|
44233
|
-
this.#store = store;
|
|
44234
44204
|
}
|
|
44235
|
-
#loadStoredEvents = (sessionId) => {
|
|
44236
|
-
const stored = this.#store.readExecutingPromptEventsV2(sessionId);
|
|
44237
|
-
const lastPosition = stored.at(-1)?.position;
|
|
44238
|
-
if (lastPosition !== void 0) {
|
|
44239
|
-
this.#positions.set(sessionId, Number(lastPosition));
|
|
44240
|
-
}
|
|
44241
|
-
return stored;
|
|
44242
|
-
};
|
|
44243
|
-
#loadRequests = (sessionId) => {
|
|
44244
|
-
if (this.#loadedRequestSessions.has(sessionId)) {
|
|
44245
|
-
return;
|
|
44246
|
-
}
|
|
44247
|
-
for (const event of this.#loadStoredEvents(sessionId)) {
|
|
44248
|
-
if (event.type === "acp") {
|
|
44249
|
-
continue;
|
|
44250
|
-
}
|
|
44251
|
-
const payload = event.payload;
|
|
44252
|
-
if (payload.kind === "prompt.requested") {
|
|
44253
|
-
this.#requests.set(payload.commandId, {
|
|
44254
|
-
commandId: payload.commandId,
|
|
44255
|
-
kind: "requested",
|
|
44256
|
-
sessionId
|
|
44257
|
-
});
|
|
44258
|
-
continue;
|
|
44259
|
-
}
|
|
44260
|
-
if ("event" in payload) {
|
|
44261
|
-
continue;
|
|
44262
|
-
}
|
|
44263
|
-
if (!("commandId" in payload)) {
|
|
44264
|
-
continue;
|
|
44265
|
-
}
|
|
44266
|
-
const state = this.#requests.get(payload.commandId);
|
|
44267
|
-
if (state === void 0) {
|
|
44268
|
-
continue;
|
|
44269
|
-
}
|
|
44270
|
-
if (payload.kind === "prompt.started") {
|
|
44271
|
-
this.#requests.set(payload.commandId, {
|
|
44272
|
-
attemptId: payload.attemptId,
|
|
44273
|
-
commandId: payload.commandId,
|
|
44274
|
-
epoch: payload.epoch,
|
|
44275
|
-
kind: "executing",
|
|
44276
|
-
sessionId
|
|
44277
|
-
});
|
|
44278
|
-
} else if (payload.kind === "prompt.completed" || payload.kind === "prompt.failed" || payload.kind === "prompt.failed-before-start") {
|
|
44279
|
-
this.#requests.delete(payload.commandId);
|
|
44280
|
-
}
|
|
44281
|
-
}
|
|
44282
|
-
this.#loadedRequestSessions.add(sessionId);
|
|
44283
|
-
};
|
|
44284
|
-
#append = (sessionId, payload) => {
|
|
44285
|
-
this.#loadRequests(sessionId);
|
|
44286
|
-
const position = (this.#positions.get(sessionId) ?? 0) + 1;
|
|
44287
|
-
const event = {
|
|
44288
|
-
eventId: `event-${crypto.randomUUID()}`,
|
|
44289
|
-
...payload,
|
|
44290
|
-
position: position.toString(),
|
|
44291
|
-
provenance: { kind: "original" },
|
|
44292
|
-
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
44293
|
-
sessionId
|
|
44294
|
-
};
|
|
44295
|
-
this.#publisher.publishV2(event);
|
|
44296
|
-
this.#positions.set(sessionId, position);
|
|
44297
|
-
return event;
|
|
44298
|
-
};
|
|
44299
44205
|
requested = (command) => {
|
|
44300
|
-
|
|
44301
|
-
this.#append(command.sessionId, {
|
|
44302
|
-
payload: { commandId: command.commandId, content, kind: "prompt.requested" },
|
|
44303
|
-
type: "lifecycle-metadata"
|
|
44304
|
-
});
|
|
44305
|
-
this.#requests.set(command.commandId, {
|
|
44206
|
+
this.#queued.set(command.commandId, {
|
|
44306
44207
|
commandId: command.commandId,
|
|
44307
|
-
|
|
44208
|
+
content: promptContent(command),
|
|
44308
44209
|
sessionId: command.sessionId
|
|
44309
44210
|
});
|
|
44310
44211
|
};
|
|
44311
44212
|
started = (sessionId, commandId, attemptId, epoch) => {
|
|
44312
|
-
this.#
|
|
44313
|
-
|
|
44314
|
-
|
|
44315
|
-
return;
|
|
44213
|
+
const request = this.#queued.get(commandId);
|
|
44214
|
+
if (request?.sessionId === sessionId) {
|
|
44215
|
+
this.#queued.delete(commandId);
|
|
44216
|
+
return { attemptId, content: request.content, epoch };
|
|
44316
44217
|
}
|
|
44317
|
-
|
|
44318
|
-
payload: { attemptId, commandId, epoch, kind: "prompt.started" },
|
|
44319
|
-
type: "lifecycle-metadata"
|
|
44320
|
-
});
|
|
44321
|
-
this.#requests.set(commandId, {
|
|
44322
|
-
attemptId,
|
|
44323
|
-
commandId,
|
|
44324
|
-
epoch,
|
|
44325
|
-
kind: "executing",
|
|
44326
|
-
sessionId
|
|
44327
|
-
});
|
|
44218
|
+
throw new Error("The executing prompt was not registered in the V2 queue");
|
|
44328
44219
|
};
|
|
44329
|
-
record = (sessionId,
|
|
44330
|
-
this.#
|
|
44331
|
-
this.#append(sessionId, payload);
|
|
44220
|
+
record = (sessionId, event, position) => {
|
|
44221
|
+
this.#publisher.publishV2(this.event(sessionId, position, event, (/* @__PURE__ */ new Date()).toISOString()));
|
|
44332
44222
|
};
|
|
44333
|
-
|
|
44334
|
-
|
|
44335
|
-
|
|
44223
|
+
event = (sessionId, position, event, recordedAt) => sessionEventV22(this.daemonGenerationId, sessionId, position, event, recordedAt);
|
|
44224
|
+
queueChanged = (_sessionId) => void 0;
|
|
44225
|
+
completed = (sessionId, commandId, _stopReason) => {
|
|
44226
|
+
const request = this.#queued.get(commandId);
|
|
44227
|
+
if (request?.sessionId === sessionId) {
|
|
44228
|
+
this.#queued.delete(commandId);
|
|
44336
44229
|
}
|
|
44337
44230
|
};
|
|
44338
|
-
|
|
44339
|
-
this.#
|
|
44340
|
-
|
|
44341
|
-
|
|
44342
|
-
});
|
|
44343
|
-
};
|
|
44344
|
-
completed = (sessionId, commandId, stopReason) => {
|
|
44345
|
-
this.#loadRequests(sessionId);
|
|
44346
|
-
this.#append(sessionId, {
|
|
44347
|
-
payload: { commandId, kind: "prompt.completed", stopReason },
|
|
44348
|
-
type: "lifecycle-metadata"
|
|
44349
|
-
});
|
|
44350
|
-
this.#requests.delete(commandId);
|
|
44351
|
-
this.#clearCompletedSession(sessionId);
|
|
44352
|
-
};
|
|
44353
|
-
failed = (sessionId, commandId, code, message) => {
|
|
44354
|
-
this.#loadRequests(sessionId);
|
|
44355
|
-
const request = this.#requests.get(commandId);
|
|
44356
|
-
if (request?.kind === "executing" && request.commandId === commandId) {
|
|
44357
|
-
this.#append(sessionId, {
|
|
44358
|
-
payload: {
|
|
44359
|
-
attemptId: request.attemptId,
|
|
44360
|
-
code,
|
|
44361
|
-
commandId,
|
|
44362
|
-
kind: "prompt.failed",
|
|
44363
|
-
message
|
|
44364
|
-
},
|
|
44365
|
-
type: "lifecycle-metadata"
|
|
44366
|
-
});
|
|
44367
|
-
} else {
|
|
44368
|
-
this.#append(sessionId, {
|
|
44369
|
-
payload: { code, commandId, kind: "prompt.failed-before-start", message },
|
|
44370
|
-
type: "lifecycle-metadata"
|
|
44371
|
-
});
|
|
44372
|
-
}
|
|
44373
|
-
this.#requests.delete(commandId);
|
|
44374
|
-
this.#clearCompletedSession(sessionId);
|
|
44375
|
-
};
|
|
44376
|
-
executingPromptRequest = (sessionId) => {
|
|
44377
|
-
this.#loadRequests(sessionId);
|
|
44378
|
-
const request = [...this.#requests.values()].find(
|
|
44379
|
-
(candidate) => candidate.sessionId === sessionId && candidate.kind === "executing"
|
|
44380
|
-
);
|
|
44381
|
-
if (request?.kind !== "executing") {
|
|
44382
|
-
return null;
|
|
44231
|
+
failed = (sessionId, commandId, _code, _message) => {
|
|
44232
|
+
const request = this.#queued.get(commandId);
|
|
44233
|
+
if (request?.sessionId === sessionId) {
|
|
44234
|
+
this.#queued.delete(commandId);
|
|
44383
44235
|
}
|
|
44384
|
-
const requestEvents = this.#store.readExecutingPromptEventsV2(sessionId);
|
|
44385
|
-
const events = requestEvents.slice(-EXECUTING_PROMPT_EVENT_LIMIT);
|
|
44386
|
-
return {
|
|
44387
|
-
attemptId: request.attemptId,
|
|
44388
|
-
commandId: request.commandId,
|
|
44389
|
-
epoch: request.epoch,
|
|
44390
|
-
events,
|
|
44391
|
-
tailCursor: events.at(-1)?.eventId ?? "",
|
|
44392
|
-
truncated: events.length < requestEvents.length
|
|
44393
|
-
};
|
|
44394
44236
|
};
|
|
44237
|
+
promptRequestRecovery = (sessionId) => ({
|
|
44238
|
+
queuedPromptRequests: [...this.#queued.values()].filter((request) => request.sessionId === sessionId).map(({ commandId, content }) => ({ commandId, content }))
|
|
44239
|
+
});
|
|
44395
44240
|
};
|
|
44396
44241
|
|
|
44397
44242
|
// src/run-daemon.ts
|
|
@@ -44442,7 +44287,7 @@ async function installDetectedAgentIntegrations(config2, installations, signal)
|
|
|
44442
44287
|
{
|
|
44443
44288
|
agentId: agent.id,
|
|
44444
44289
|
kind: AGENT_INSTALL_REQUEST_KIND,
|
|
44445
|
-
requestId: `automatic-integration-${
|
|
44290
|
+
requestId: `automatic-integration-${randomUUID9()}`
|
|
44446
44291
|
},
|
|
44447
44292
|
signal
|
|
44448
44293
|
);
|
|
@@ -44465,8 +44310,8 @@ async function runDaemon(config2, audit, signal, timer = systemDaemonTimer, opti
|
|
|
44465
44310
|
);
|
|
44466
44311
|
await using externalContent = new LocalExternalContentStore(stateDirectory);
|
|
44467
44312
|
const operations = new DaemonOperationState();
|
|
44468
|
-
const publisher = new DaemonSessionEventPublisher(
|
|
44469
|
-
const eventLogV2 = new DaemonSessionEventLogV2(publisher
|
|
44313
|
+
const publisher = new DaemonSessionEventPublisher();
|
|
44314
|
+
const eventLogV2 = new DaemonSessionEventLogV2(publisher);
|
|
44470
44315
|
const activeTurns = new DaemonTurnRegistry(operations);
|
|
44471
44316
|
const recordSessionEvent = (sessionId, event) => {
|
|
44472
44317
|
publisher.publish(sessionId, activeTurns.recordEvent(event));
|