@agentclientprotocol/codex-acp 1.11.1-preview.6 → 1.12.1-preview.1
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/index.js +235 -54
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23921,19 +23921,24 @@ var CodexSubagentEventRouter = class _CodexSubagentEventRouter {
|
|
|
23921
23921
|
closingChildSessions(notification) {
|
|
23922
23922
|
if (!this.supported) return [];
|
|
23923
23923
|
if (notification.method === "turn/completed") {
|
|
23924
|
-
|
|
23925
|
-
|
|
23924
|
+
const state = terminalStateFromTurn(notification.params.turn.status);
|
|
23925
|
+
if (state === void 0) return [];
|
|
23926
|
+
if (notification.params.threadId === this.rootSessionId && state !== "completed") {
|
|
23927
|
+
return [...this.children.keys()].flatMap((threadId) => this.closingChildSession(threadId, state));
|
|
23928
|
+
}
|
|
23929
|
+
return this.closingChildSession(notification.params.threadId, state);
|
|
23926
23930
|
}
|
|
23927
23931
|
if (notification.method !== "item/started" && notification.method !== "item/completed") return [];
|
|
23928
23932
|
const item = notification.params.item;
|
|
23929
23933
|
if (item.type === "subAgentActivity") {
|
|
23930
|
-
return item.kind === "interrupted" ? this.closingChildSession(item.agentThreadId) : [];
|
|
23934
|
+
return item.kind === "interrupted" ? this.closingChildSession(item.agentThreadId, "cancelled") : [];
|
|
23931
23935
|
}
|
|
23932
23936
|
if (item.type !== "collabAgentToolCall") return [];
|
|
23933
23937
|
const closing = /* @__PURE__ */ new Map();
|
|
23934
23938
|
for (const [threadId, state] of Object.entries(item.agentsStates)) {
|
|
23935
|
-
|
|
23936
|
-
|
|
23939
|
+
const terminalState = state && terminalStateOf(state.status);
|
|
23940
|
+
if (!terminalState) continue;
|
|
23941
|
+
for (const child of this.closingChildSession(threadId, terminalState)) closing.set(threadId, child);
|
|
23937
23942
|
}
|
|
23938
23943
|
return [...closing.values()];
|
|
23939
23944
|
}
|
|
@@ -23965,15 +23970,15 @@ var CodexSubagentEventRouter = class _CodexSubagentEventRouter {
|
|
|
23965
23970
|
const sessionUpdate = this.activeLegacyActivities.delete(item.id) ? "tool_call_update" : "tool_call";
|
|
23966
23971
|
return createSubAgentActivityUpdate(item, "completed", sessionUpdate);
|
|
23967
23972
|
}
|
|
23973
|
+
/** The caller finalizes pending child updates before closing timed-out sessions. */
|
|
23968
23974
|
async wait(signal, timeoutMs = _CodexSubagentEventRouter.DEFAULT_WAIT_TIMEOUT_MS) {
|
|
23969
23975
|
const deadline = Date.now() + timeoutMs;
|
|
23970
23976
|
while (this.hasOutstanding()) {
|
|
23971
|
-
if (signal.aborted) return;
|
|
23977
|
+
if (signal.aborted) return "aborted";
|
|
23972
23978
|
const remainingMs = deadline - Date.now();
|
|
23973
23979
|
if (remainingMs <= 0) {
|
|
23974
23980
|
logger.log(`Timed out waiting for subagents in session ${this.rootSessionId}; marking them failed`);
|
|
23975
|
-
|
|
23976
|
-
return;
|
|
23981
|
+
return "timed_out";
|
|
23977
23982
|
}
|
|
23978
23983
|
const changed = await new Promise((resolve) => {
|
|
23979
23984
|
const timeout = setTimeout(() => {
|
|
@@ -23996,10 +24001,10 @@ var CodexSubagentEventRouter = class _CodexSubagentEventRouter {
|
|
|
23996
24001
|
});
|
|
23997
24002
|
if (!changed) {
|
|
23998
24003
|
logger.log(`Timed out waiting for subagents in session ${this.rootSessionId}; marking them failed`);
|
|
23999
|
-
|
|
24000
|
-
return;
|
|
24004
|
+
return "timed_out";
|
|
24001
24005
|
}
|
|
24002
24006
|
}
|
|
24007
|
+
return "settled";
|
|
24003
24008
|
}
|
|
24004
24009
|
async finishOutstanding(state) {
|
|
24005
24010
|
for (const childSessionId of [...this.pendingSpawns.keys()]) {
|
|
@@ -24012,9 +24017,9 @@ var CodexSubagentEventRouter = class _CodexSubagentEventRouter {
|
|
|
24012
24017
|
isKnownChild(threadId) {
|
|
24013
24018
|
return threadId !== this.rootSessionId && (this.children.has(threadId) || this.pendingSpawns.has(threadId) || this.terminalPendingSpawns.has(threadId));
|
|
24014
24019
|
}
|
|
24015
|
-
closingChildSession(threadId) {
|
|
24020
|
+
closingChildSession(threadId, state) {
|
|
24016
24021
|
const child = this.children.get(threadId);
|
|
24017
|
-
return child && child.terminalState === void 0 ? [{ threadId, sessionId: child.sessionId }] : [];
|
|
24022
|
+
return child && child.terminalState === void 0 ? [{ threadId, sessionId: child.sessionId, state }] : [];
|
|
24018
24023
|
}
|
|
24019
24024
|
async materialize(childSessionId, path9) {
|
|
24020
24025
|
if (this.children.has(childSessionId)) return;
|
|
@@ -24577,6 +24582,25 @@ var STRUCTURED_CODEX_ERROR_CATEGORIES = {
|
|
|
24577
24582
|
activeTurnNotSteerable: "provider_error"
|
|
24578
24583
|
};
|
|
24579
24584
|
var CodexEventHandler = class _CodexEventHandler {
|
|
24585
|
+
constructor(connection, sessionState, supportsPlanUpdates = false, supportsTypedSessionFailures = false, sessionFailureEpoch = randomUUID(), subagents = new CodexSubagentEventRouter(
|
|
24586
|
+
sessionState.sessionId,
|
|
24587
|
+
false,
|
|
24588
|
+
new ACPSessionConnection(connection, sessionState.sessionId)
|
|
24589
|
+
), onAccountUpdated, collectTurnDiffs = false, supportsCompaction = false) {
|
|
24590
|
+
this.supportsCompaction = supportsCompaction;
|
|
24591
|
+
this.onAccountUpdated = onAccountUpdated;
|
|
24592
|
+
this.sessionState = sessionState;
|
|
24593
|
+
this.supportsPlanUpdates = supportsPlanUpdates;
|
|
24594
|
+
this.supportsTypedSessionFailures = supportsTypedSessionFailures;
|
|
24595
|
+
this.sessionFailureEpoch = sessionFailureEpoch;
|
|
24596
|
+
this.session = new ACPSessionConnection(connection, sessionState.sessionId);
|
|
24597
|
+
this.subagents = subagents;
|
|
24598
|
+
this.collectTurnDiffs = collectTurnDiffs;
|
|
24599
|
+
if (sessionState.sessionFailure !== void 0) {
|
|
24600
|
+
this.failuresById.set(sessionState.sessionFailure.id, sessionState.sessionFailure);
|
|
24601
|
+
}
|
|
24602
|
+
}
|
|
24603
|
+
supportsCompaction;
|
|
24580
24604
|
static PLAN_UPDATE_INTERVAL_MS = 150;
|
|
24581
24605
|
sessionState;
|
|
24582
24606
|
supportsPlanUpdates;
|
|
@@ -24612,23 +24636,6 @@ var CodexEventHandler = class _CodexEventHandler {
|
|
|
24612
24636
|
subagents;
|
|
24613
24637
|
/** Connection-level `authStatus` sink; the app-server account push feeds it. */
|
|
24614
24638
|
onAccountUpdated;
|
|
24615
|
-
constructor(connection, sessionState, supportsPlanUpdates = false, supportsTypedSessionFailures = false, sessionFailureEpoch = randomUUID(), subagents = new CodexSubagentEventRouter(
|
|
24616
|
-
sessionState.sessionId,
|
|
24617
|
-
false,
|
|
24618
|
-
new ACPSessionConnection(connection, sessionState.sessionId)
|
|
24619
|
-
), onAccountUpdated, collectTurnDiffs = false) {
|
|
24620
|
-
this.onAccountUpdated = onAccountUpdated;
|
|
24621
|
-
this.sessionState = sessionState;
|
|
24622
|
-
this.supportsPlanUpdates = supportsPlanUpdates;
|
|
24623
|
-
this.supportsTypedSessionFailures = supportsTypedSessionFailures;
|
|
24624
|
-
this.sessionFailureEpoch = sessionFailureEpoch;
|
|
24625
|
-
this.session = new ACPSessionConnection(connection, sessionState.sessionId);
|
|
24626
|
-
this.subagents = subagents;
|
|
24627
|
-
this.collectTurnDiffs = collectTurnDiffs;
|
|
24628
|
-
if (sessionState.sessionFailure !== void 0) {
|
|
24629
|
-
this.failuresById.set(sessionState.sessionFailure.id, sessionState.sessionFailure);
|
|
24630
|
-
}
|
|
24631
|
-
}
|
|
24632
24639
|
getFailure() {
|
|
24633
24640
|
return this.failure;
|
|
24634
24641
|
}
|
|
@@ -24662,6 +24669,7 @@ var CodexEventHandler = class _CodexEventHandler {
|
|
|
24662
24669
|
await this.handleNotification(notification);
|
|
24663
24670
|
return;
|
|
24664
24671
|
}
|
|
24672
|
+
await this.finishCompactionsForNotification(notification);
|
|
24665
24673
|
if (notification.params.willRetry) {
|
|
24666
24674
|
await this.session.update(this.createSessionFailureUpdate(this.recordRetryWarning(notification.params, false)));
|
|
24667
24675
|
return;
|
|
@@ -24733,8 +24741,13 @@ var CodexEventHandler = class _CodexEventHandler {
|
|
|
24733
24741
|
}
|
|
24734
24742
|
async handleNotification(notification) {
|
|
24735
24743
|
await this.flushPendingErrors();
|
|
24744
|
+
await this.finishCompactionsForNotification(notification);
|
|
24736
24745
|
const closingChildren = this.subagents.closingChildSessions(notification);
|
|
24737
24746
|
for (const child of closingChildren) {
|
|
24747
|
+
await this.finishOutstandingCompactions(
|
|
24748
|
+
child.state === "cancelled" ? "cancelled" : "failed",
|
|
24749
|
+
child.sessionId
|
|
24750
|
+
);
|
|
24738
24751
|
await this.sessionState.asyncTasks.reconcile(child.threadId, child.sessionId);
|
|
24739
24752
|
}
|
|
24740
24753
|
const handledBySubagents = await this.subagents.handle(notification);
|
|
@@ -24764,11 +24777,45 @@ var CodexEventHandler = class _CodexEventHandler {
|
|
|
24764
24777
|
return await this.subagents.waitForMaterializedSession(childThreadId);
|
|
24765
24778
|
}
|
|
24766
24779
|
async waitForNativeSubagents(signal) {
|
|
24767
|
-
await this.subagents.wait(signal)
|
|
24780
|
+
if (await this.subagents.wait(signal) === "timed_out") {
|
|
24781
|
+
await this.finishOutstandingNativeSubagents("failed");
|
|
24782
|
+
}
|
|
24768
24783
|
}
|
|
24769
24784
|
async finishOutstandingNativeSubagents(state) {
|
|
24785
|
+
await this.finishOutstandingCompactions(state === "cancelled" ? "cancelled" : "failed");
|
|
24770
24786
|
await this.subagents.finishOutstanding(state);
|
|
24771
24787
|
}
|
|
24788
|
+
async finishOutstandingCompactions(status, sessionId) {
|
|
24789
|
+
if (!this.supportsCompaction) return;
|
|
24790
|
+
for (const { sessionId: targetSessionId, update } of this.sessionState.compactions.finishOutstanding(status, sessionId)) {
|
|
24791
|
+
await this.session.update(update, targetSessionId);
|
|
24792
|
+
}
|
|
24793
|
+
}
|
|
24794
|
+
async finishCompactionsForNotification(notification) {
|
|
24795
|
+
if (!this.supportsCompaction) return;
|
|
24796
|
+
let updates;
|
|
24797
|
+
const sessionId = this.subagents.notificationSessionId(notification);
|
|
24798
|
+
if (notification.method === "turn/completed") {
|
|
24799
|
+
const turn = notification.params.turn;
|
|
24800
|
+
if (turn.status === "inProgress") return;
|
|
24801
|
+
updates = this.sessionState.compactions.finishTurn(
|
|
24802
|
+
sessionId,
|
|
24803
|
+
turn.id,
|
|
24804
|
+
turn.status === "interrupted" ? "cancelled" : "failed",
|
|
24805
|
+
turn.error?.message ?? "Codex ended the turn before compaction completed."
|
|
24806
|
+
);
|
|
24807
|
+
} else if (notification.method === "error" && !notification.params.willRetry) {
|
|
24808
|
+
updates = this.sessionState.compactions.finishTurn(
|
|
24809
|
+
sessionId,
|
|
24810
|
+
notification.params.turnId,
|
|
24811
|
+
"failed",
|
|
24812
|
+
notification.params.error.message
|
|
24813
|
+
);
|
|
24814
|
+
} else {
|
|
24815
|
+
return;
|
|
24816
|
+
}
|
|
24817
|
+
for (const update of updates) await this.session.update(update, sessionId);
|
|
24818
|
+
}
|
|
24772
24819
|
async flushPendingPlanUpdates() {
|
|
24773
24820
|
this.cancelPlanUpdateTimer();
|
|
24774
24821
|
do {
|
|
@@ -24892,7 +24939,10 @@ var CodexEventHandler = class _CodexEventHandler {
|
|
|
24892
24939
|
case "item/autoApprovalReview/completed":
|
|
24893
24940
|
return this.handleGuardianApprovalReviewCompleted(notification.params);
|
|
24894
24941
|
case "thread/compacted":
|
|
24895
|
-
return this.
|
|
24942
|
+
return this.supportsCompaction ? this.sessionState.compactions.completeLegacy(
|
|
24943
|
+
this.subagents.notificationSessionId(notification),
|
|
24944
|
+
notification.params.turnId
|
|
24945
|
+
) : this.createContextCompactedEvent();
|
|
24896
24946
|
case "item/reasoning/summaryTextDelta":
|
|
24897
24947
|
this.completeRetryIncidentOnTurnProgress();
|
|
24898
24948
|
return this.createReasoningDeltaEvent(notification.params);
|
|
@@ -25091,7 +25141,11 @@ ${event.details}` : event.summary;
|
|
|
25091
25141
|
this.rememberAgentMessagePhase(event.item);
|
|
25092
25142
|
return null;
|
|
25093
25143
|
case "contextCompaction":
|
|
25094
|
-
return
|
|
25144
|
+
return this.supportsCompaction ? this.sessionState.compactions.start(
|
|
25145
|
+
this.subagents.notificationSessionId({ method: "item/started", params: event }),
|
|
25146
|
+
event.turnId,
|
|
25147
|
+
event.item.id
|
|
25148
|
+
) : createContextCompactionStartUpdate(event.item);
|
|
25095
25149
|
case "subAgentActivity":
|
|
25096
25150
|
return this.subagents.legacyActivityStarted(event.item);
|
|
25097
25151
|
case "sleep":
|
|
@@ -25159,7 +25213,11 @@ ${event.details}` : event.summary;
|
|
|
25159
25213
|
case "exitedReviewMode":
|
|
25160
25214
|
return this.createExitedReviewModeEvent(event.item);
|
|
25161
25215
|
case "contextCompaction":
|
|
25162
|
-
return
|
|
25216
|
+
return this.supportsCompaction ? this.sessionState.compactions.complete(
|
|
25217
|
+
this.subagents.notificationSessionId({ method: "item/completed", params: event }),
|
|
25218
|
+
event.turnId,
|
|
25219
|
+
event.item.id
|
|
25220
|
+
) : createContextCompactionCompleteUpdate(event.item);
|
|
25163
25221
|
//ignored types
|
|
25164
25222
|
case "subAgentActivity":
|
|
25165
25223
|
return this.subagents.legacyActivityCompleted(event.item);
|
|
@@ -27808,7 +27866,7 @@ var package_default = {
|
|
|
27808
27866
|
publishConfig: {
|
|
27809
27867
|
access: "public"
|
|
27810
27868
|
},
|
|
27811
|
-
version: "1.
|
|
27869
|
+
version: "1.12.1-preview.1",
|
|
27812
27870
|
description: "",
|
|
27813
27871
|
main: "dist/index.js",
|
|
27814
27872
|
bin: {
|
|
@@ -28637,8 +28695,9 @@ var CodexAcpClient = class {
|
|
|
28637
28695
|
delivery: "inline"
|
|
28638
28696
|
}, onTurnStarted);
|
|
28639
28697
|
}
|
|
28640
|
-
async runCompact(sessionId) {
|
|
28641
|
-
await this.codexClient.runCompact({ threadId: sessionId });
|
|
28698
|
+
async runCompact(sessionId, onTurnStarted) {
|
|
28699
|
+
const completed = await this.codexClient.runCompact({ threadId: sessionId }, onTurnStarted);
|
|
28700
|
+
return completed.method === "turn/completed" ? completed.params : void 0;
|
|
28642
28701
|
}
|
|
28643
28702
|
async getGoal(sessionId) {
|
|
28644
28703
|
const response = await this.codexClient.threadGoalGet({ threadId: sessionId });
|
|
@@ -29242,7 +29301,7 @@ var CodexAppServerClient = class {
|
|
|
29242
29301
|
if (this.handleStaleTurnNotification(serverNotification, routing)) {
|
|
29243
29302
|
return;
|
|
29244
29303
|
}
|
|
29245
|
-
this.recordTurnRouting(routing);
|
|
29304
|
+
this.recordTurnRouting(routing, serverNotification);
|
|
29246
29305
|
if (this.handleStaleTurnNotification(serverNotification, routing)) {
|
|
29247
29306
|
return;
|
|
29248
29307
|
}
|
|
@@ -29524,10 +29583,45 @@ var CodexAppServerClient = class {
|
|
|
29524
29583
|
threadStatusChanged: handleThreadStatusChanged
|
|
29525
29584
|
};
|
|
29526
29585
|
}
|
|
29527
|
-
async runCompact(params) {
|
|
29528
|
-
|
|
29529
|
-
|
|
29530
|
-
|
|
29586
|
+
async runCompact(params, onTurnStarted) {
|
|
29587
|
+
let compactTurnId = null;
|
|
29588
|
+
let resolveCompleted = () => {
|
|
29589
|
+
};
|
|
29590
|
+
let rejectCompleted = () => {
|
|
29591
|
+
};
|
|
29592
|
+
const completed = new Promise((resolve, reject) => {
|
|
29593
|
+
resolveCompleted = resolve;
|
|
29594
|
+
rejectCompleted = reject;
|
|
29595
|
+
});
|
|
29596
|
+
void completed.catch(() => {
|
|
29597
|
+
});
|
|
29598
|
+
const closed = this.connection.onClose?.(() => rejectCompleted(new Error("Codex connection closed during compaction.")));
|
|
29599
|
+
const completeCompaction = (event) => {
|
|
29600
|
+
if (compactTurnId !== null && event.params.turnId !== compactTurnId) return;
|
|
29601
|
+
resolveCompleted(event);
|
|
29602
|
+
};
|
|
29603
|
+
const releaseCompactionCapture = this.captureCompactionCompletions(params.threadId, completeCompaction);
|
|
29604
|
+
const releaseTurnCapture = this.captureTurnCompletions(params.threadId, (event) => {
|
|
29605
|
+
if (compactTurnId === null || event.turn.id !== compactTurnId) return;
|
|
29606
|
+
if (event.turn.status !== "inProgress") {
|
|
29607
|
+
resolveCompleted({ method: "turn/completed", params: event });
|
|
29608
|
+
}
|
|
29609
|
+
});
|
|
29610
|
+
const releaseRoutingCapture = this.captureTurnRoutings(params.threadId, (turnId, notification) => {
|
|
29611
|
+
if (compactTurnId !== null) return;
|
|
29612
|
+
if (notification.method !== "turn/started" && !(notification.method === "item/started" && notification.params.item.type === "contextCompaction")) return;
|
|
29613
|
+
compactTurnId = turnId;
|
|
29614
|
+
onTurnStarted?.(turnId);
|
|
29615
|
+
});
|
|
29616
|
+
try {
|
|
29617
|
+
await this.threadCompactStart(params);
|
|
29618
|
+
return await completed;
|
|
29619
|
+
} finally {
|
|
29620
|
+
releaseTurnCapture();
|
|
29621
|
+
releaseRoutingCapture();
|
|
29622
|
+
releaseCompactionCapture();
|
|
29623
|
+
closed?.dispose();
|
|
29624
|
+
}
|
|
29531
29625
|
}
|
|
29532
29626
|
async turnInterrupt(params) {
|
|
29533
29627
|
return await this.sendRequest({ method: "turn/interrupt", params });
|
|
@@ -29697,9 +29791,10 @@ var CodexAppServerClient = class {
|
|
|
29697
29791
|
}
|
|
29698
29792
|
async awaitCompactionCompleted(threadId) {
|
|
29699
29793
|
return await new Promise((resolve) => {
|
|
29700
|
-
const
|
|
29701
|
-
|
|
29702
|
-
|
|
29794
|
+
const releaseCapture = this.captureCompactionCompletions(threadId, (event) => {
|
|
29795
|
+
releaseCapture();
|
|
29796
|
+
resolve(event);
|
|
29797
|
+
});
|
|
29703
29798
|
});
|
|
29704
29799
|
}
|
|
29705
29800
|
resolveTurnInterrupted(threadId, turnId) {
|
|
@@ -29779,11 +29874,24 @@ var CodexAppServerClient = class {
|
|
|
29779
29874
|
if (!resolvers) {
|
|
29780
29875
|
return;
|
|
29781
29876
|
}
|
|
29782
|
-
this.pendingCompactionCompletionResolvers.delete(threadId);
|
|
29783
29877
|
for (const resolve of resolvers) {
|
|
29784
29878
|
resolve(event);
|
|
29785
29879
|
}
|
|
29786
29880
|
}
|
|
29881
|
+
captureCompactionCompletions(threadId, capture) {
|
|
29882
|
+
const captures = this.pendingCompactionCompletionResolvers.get(threadId) ?? /* @__PURE__ */ new Set();
|
|
29883
|
+
captures.add(capture);
|
|
29884
|
+
this.pendingCompactionCompletionResolvers.set(threadId, captures);
|
|
29885
|
+
let released = false;
|
|
29886
|
+
return () => {
|
|
29887
|
+
if (released) return;
|
|
29888
|
+
released = true;
|
|
29889
|
+
captures.delete(capture);
|
|
29890
|
+
if (captures.size === 0) {
|
|
29891
|
+
this.pendingCompactionCompletionResolvers.delete(threadId);
|
|
29892
|
+
}
|
|
29893
|
+
};
|
|
29894
|
+
}
|
|
29787
29895
|
recordThreadStatusChanged(event) {
|
|
29788
29896
|
const captures = this.threadStatusCaptures.get(event.threadId);
|
|
29789
29897
|
if (!captures) {
|
|
@@ -29811,7 +29919,7 @@ var CodexAppServerClient = class {
|
|
|
29811
29919
|
capture();
|
|
29812
29920
|
}
|
|
29813
29921
|
}
|
|
29814
|
-
recordTurnRouting(routing) {
|
|
29922
|
+
recordTurnRouting(routing, notification) {
|
|
29815
29923
|
if (routing.threadId === null || routing.turnId === null) {
|
|
29816
29924
|
return;
|
|
29817
29925
|
}
|
|
@@ -29820,7 +29928,7 @@ var CodexAppServerClient = class {
|
|
|
29820
29928
|
return;
|
|
29821
29929
|
}
|
|
29822
29930
|
for (const capture of captures) {
|
|
29823
|
-
capture(routing.turnId);
|
|
29931
|
+
capture(routing.turnId, notification);
|
|
29824
29932
|
}
|
|
29825
29933
|
}
|
|
29826
29934
|
handleStaleTurnNotification(notification, routing) {
|
|
@@ -30267,8 +30375,12 @@ var CodexCommands = class {
|
|
|
30267
30375
|
return { handled: options.setConfigOption !== void 0 };
|
|
30268
30376
|
}
|
|
30269
30377
|
case "compact": {
|
|
30270
|
-
|
|
30271
|
-
|
|
30378
|
+
options.onTurnStartPending?.();
|
|
30379
|
+
const turnCompleted = await this.runWithProcessCheck(() => this.codexAcpClient.runCompact(
|
|
30380
|
+
sessionId,
|
|
30381
|
+
(turnId) => options.onTurnStarted?.(turnId, sessionId)
|
|
30382
|
+
));
|
|
30383
|
+
return { handled: true, ...turnCompleted === void 0 ? {} : { turnCompleted } };
|
|
30272
30384
|
}
|
|
30273
30385
|
case "goal": {
|
|
30274
30386
|
return await this.runGoalCommand(sessionState, command.rest, options);
|
|
@@ -32233,6 +32345,72 @@ function notificationThreadId(notification) {
|
|
|
32233
32345
|
return typeof threadId === "string" ? threadId : null;
|
|
32234
32346
|
}
|
|
32235
32347
|
|
|
32348
|
+
// src/CodexSessionCompactions.ts
|
|
32349
|
+
function clientSupportsCompaction(capabilities) {
|
|
32350
|
+
return capabilities?.session?.compaction != null;
|
|
32351
|
+
}
|
|
32352
|
+
function createCompactionUpdate(compactionId, status, error51) {
|
|
32353
|
+
return {
|
|
32354
|
+
sessionUpdate: "compaction_update",
|
|
32355
|
+
compactionId,
|
|
32356
|
+
status,
|
|
32357
|
+
...status === "failed" && error51 !== void 0 ? { error: error51 } : {}
|
|
32358
|
+
};
|
|
32359
|
+
}
|
|
32360
|
+
var CodexSessionCompactions = class {
|
|
32361
|
+
items = /* @__PURE__ */ new Map();
|
|
32362
|
+
latestByTurn = /* @__PURE__ */ new Map();
|
|
32363
|
+
start(sessionId, turnId, itemId) {
|
|
32364
|
+
const key = JSON.stringify([sessionId, itemId]);
|
|
32365
|
+
if (this.items.has(key)) return null;
|
|
32366
|
+
const compaction = this.remember(sessionId, turnId, itemId);
|
|
32367
|
+
return createCompactionUpdate(compaction.id, "in_progress");
|
|
32368
|
+
}
|
|
32369
|
+
complete(sessionId, turnId, itemId) {
|
|
32370
|
+
const latest = this.latestByTurn.get(JSON.stringify([sessionId, turnId]));
|
|
32371
|
+
if (!this.items.has(JSON.stringify([sessionId, itemId])) && latest?.legacyOnly) {
|
|
32372
|
+
this.items.delete(JSON.stringify([sessionId, latest.id]));
|
|
32373
|
+
this.items.set(JSON.stringify([sessionId, itemId]), latest);
|
|
32374
|
+
latest.legacyOnly = false;
|
|
32375
|
+
}
|
|
32376
|
+
const compaction = this.items.get(JSON.stringify([sessionId, itemId])) ?? this.remember(sessionId, turnId, itemId);
|
|
32377
|
+
return this.finish(compaction, "completed");
|
|
32378
|
+
}
|
|
32379
|
+
completeLegacy(sessionId, turnId) {
|
|
32380
|
+
const compaction = this.latestByTurn.get(JSON.stringify([sessionId, turnId])) ?? this.remember(sessionId, turnId, `compaction:${turnId}`, true);
|
|
32381
|
+
return this.finish(compaction, "completed");
|
|
32382
|
+
}
|
|
32383
|
+
finishTurn(sessionId, turnId, status, error51) {
|
|
32384
|
+
const updates = [];
|
|
32385
|
+
for (const compaction of this.items.values()) {
|
|
32386
|
+
if (compaction.sessionId !== sessionId || compaction.turnId !== turnId) continue;
|
|
32387
|
+
const update = this.finish(compaction, status, error51);
|
|
32388
|
+
if (update) updates.push(update);
|
|
32389
|
+
}
|
|
32390
|
+
return updates;
|
|
32391
|
+
}
|
|
32392
|
+
finishOutstanding(status, sessionId) {
|
|
32393
|
+
const updates = [];
|
|
32394
|
+
for (const compaction of this.items.values()) {
|
|
32395
|
+
if (sessionId !== void 0 && compaction.sessionId !== sessionId) continue;
|
|
32396
|
+
const update = this.finish(compaction, status);
|
|
32397
|
+
if (update) updates.push({ sessionId: compaction.sessionId, update });
|
|
32398
|
+
}
|
|
32399
|
+
return updates;
|
|
32400
|
+
}
|
|
32401
|
+
remember(sessionId, turnId, id, legacyOnly = false) {
|
|
32402
|
+
const compaction = { sessionId, turnId, id, terminal: false, legacyOnly };
|
|
32403
|
+
this.items.set(JSON.stringify([sessionId, id]), compaction);
|
|
32404
|
+
this.latestByTurn.set(JSON.stringify([sessionId, turnId]), compaction);
|
|
32405
|
+
return compaction;
|
|
32406
|
+
}
|
|
32407
|
+
finish(compaction, status, error51) {
|
|
32408
|
+
if (compaction.terminal) return null;
|
|
32409
|
+
compaction.terminal = true;
|
|
32410
|
+
return createCompactionUpdate(compaction.id, status, error51);
|
|
32411
|
+
}
|
|
32412
|
+
};
|
|
32413
|
+
|
|
32236
32414
|
// src/CodexAcpServer.ts
|
|
32237
32415
|
var CODEX_PROCESS_EXITED_ERROR_CODE = 1001;
|
|
32238
32416
|
function clientSupportsTypedSessionFailures(capabilities) {
|
|
@@ -32646,7 +32824,8 @@ Check ${configPath} and project .codex directories, especially their config.toml
|
|
|
32646
32824
|
clientSupportsSubagents(this.clientCapabilities),
|
|
32647
32825
|
new ACPSessionConnection(this.connection, sessionId)
|
|
32648
32826
|
),
|
|
32649
|
-
asyncTasks: this.createAsyncTasks(sessionId)
|
|
32827
|
+
asyncTasks: this.createAsyncTasks(sessionId),
|
|
32828
|
+
compactions: new CodexSessionCompactions()
|
|
32650
32829
|
};
|
|
32651
32830
|
sessionState.titleGen = new TitleGenerator(
|
|
32652
32831
|
this.codexAcpClient.appServerClient,
|
|
@@ -33706,7 +33885,8 @@ Check ${configPath} and project .codex directories, especially their config.toml
|
|
|
33706
33885
|
clientSupportsSubagents(this.clientCapabilities),
|
|
33707
33886
|
new ACPSessionConnection(this.connection, sessionId)
|
|
33708
33887
|
),
|
|
33709
|
-
asyncTasks: this.createAsyncTasks(sessionId)
|
|
33888
|
+
asyncTasks: this.createAsyncTasks(sessionId),
|
|
33889
|
+
compactions: new CodexSessionCompactions()
|
|
33710
33890
|
};
|
|
33711
33891
|
sessionState.titleGen = new TitleGenerator(
|
|
33712
33892
|
this.codexAcpClient.appServerClient,
|
|
@@ -33981,7 +34161,7 @@ Check ${configPath} and project .codex directories, especially their config.toml
|
|
|
33981
34161
|
case "exitedReviewMode":
|
|
33982
34162
|
return [this.createReviewModeUpdate(item, false)];
|
|
33983
34163
|
case "contextCompaction":
|
|
33984
|
-
return [createCompletedContextCompactionUpdate(item)];
|
|
34164
|
+
return [clientSupportsCompaction(this.clientCapabilities) ? createCompactionUpdate(item.id, "completed") : createCompletedContextCompactionUpdate(item)];
|
|
33985
34165
|
case "plan":
|
|
33986
34166
|
return item.text.length > 0 ? [this.createPlanHistoryUpdate(item)] : [];
|
|
33987
34167
|
}
|
|
@@ -34417,7 +34597,8 @@ Check ${configPath} and project .codex directories, especially their config.toml
|
|
|
34417
34597
|
this.sessionFailureEpoch,
|
|
34418
34598
|
sessionState.subagents,
|
|
34419
34599
|
(accountUpdated) => this.handleAccountUpdated(accountUpdated),
|
|
34420
|
-
agentFileChangeReportRequest !== null
|
|
34600
|
+
agentFileChangeReportRequest !== null,
|
|
34601
|
+
clientSupportsCompaction(this.clientCapabilities)
|
|
34421
34602
|
);
|
|
34422
34603
|
eventHandler = promptEventHandler;
|
|
34423
34604
|
const permissionLifecycle = this.permissionLifecycleContext(sessionState);
|
|
@@ -34767,7 +34948,7 @@ Check ${configPath} and project .codex directories, especially their config.toml
|
|
|
34767
34948
|
promptWasCancelled || activePrompt.signal.aborted || this.sessionIsClosing(params.sessionId) ? "cancelled" : "failed"
|
|
34768
34949
|
);
|
|
34769
34950
|
} catch (error51) {
|
|
34770
|
-
logger.error("Failed to publish terminal subagent state during prompt cleanup", error51);
|
|
34951
|
+
logger.error("Failed to publish terminal compaction or subagent state during prompt cleanup", error51);
|
|
34771
34952
|
}
|
|
34772
34953
|
if (agentFileChangeReportRequest !== null && agentFileChangeWorkspace !== null) {
|
|
34773
34954
|
if (promptWasCancelled || activePrompt.signal.aborted || this.sessionIsClosing(params.sessionId)) {
|