@bitkyc08/opencodex 2.100.6 → 2.100.7-preview.20261120.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.
Files changed (103) hide show
  1. package/gui/dist/assets/App-Te21Q-Fv.js +65 -0
  2. package/gui/dist/assets/App-hklyKJR5.css +1 -0
  3. package/gui/dist/assets/{Tray-CVqm4S4W.js → Tray-Bto-DJ6b.js} +1 -1
  4. package/gui/dist/assets/brand-mark-CCRs3Ywg.js +1 -0
  5. package/gui/dist/assets/index-B85uU8rK.css +2 -0
  6. package/gui/dist/assets/index-Befqr0m8.js +138 -0
  7. package/gui/dist/assets/{segment-thumb-features-COdzmORE.js → segment-thumb-features-CKFf9DaQ.js} +1 -1
  8. package/gui/dist/classic/assets/App-BPkhxI3i.js +64 -0
  9. package/gui/dist/classic/assets/App-DSivR528.css +1 -0
  10. package/gui/dist/classic/assets/{Tray-BDlcOLDK.js → Tray-CSRN8p3a.js} +1 -1
  11. package/gui/dist/classic/assets/index-BHM1aTF8.js +138 -0
  12. package/gui/dist/classic/assets/usage-companion-chart-DC8ve7g8.js +1 -0
  13. package/gui/dist/classic/index.html +1 -1
  14. package/gui/dist/index.html +2 -2
  15. package/package.json +2 -2
  16. package/src/adapters/coding-agent/process-tree.ts +30 -0
  17. package/src/adapters/coding-agent/profile.ts +1 -1
  18. package/src/adapters/coding-agent/turn.ts +2 -9
  19. package/src/adapters/command-code-decision-guard.ts +25 -0
  20. package/src/adapters/cursor/catalog.ts +14 -0
  21. package/src/adapters/cursor/effort-map.ts +3 -0
  22. package/src/adapters/google-usage.ts +28 -0
  23. package/src/adapters/google.ts +9 -26
  24. package/src/adapters/qoder/adapter.ts +197 -13
  25. package/src/adapters/registry.ts +13 -0
  26. package/src/adapters/step-cli/adapter.ts +401 -0
  27. package/src/adapters/step-cli/constants.ts +11 -0
  28. package/src/adapters/step-cli/conversation.ts +159 -0
  29. package/src/adapters/step-cli/env.ts +49 -0
  30. package/src/adapters/step-cli/errors.ts +76 -0
  31. package/src/adapters/step-cli/events.ts +227 -0
  32. package/src/adapters/step-cli/profiles.ts +134 -0
  33. package/src/adapters/step-cli/projection.ts +242 -0
  34. package/src/adapters/step-cli/registry.ts +181 -0
  35. package/src/adapters/step-cli/session-pool.ts +225 -0
  36. package/src/adapters/step-cli/session.ts +842 -0
  37. package/src/adapters/step-cli/stdio-frames.ts +330 -0
  38. package/src/adapters/step-cli/tool-bridge.ts +92 -0
  39. package/src/cli/claude.ts +5 -2
  40. package/src/client/link-management-relay.ts +11 -0
  41. package/src/client/machine-listener.ts +6 -2
  42. package/src/codex/account-label.ts +1 -1
  43. package/src/codex/catalog/gather-capture.ts +2 -1
  44. package/src/codex/catalog/metadata.ts +48 -2
  45. package/src/codex/catalog/model-hints.ts +19 -5
  46. package/src/codex/catalog/model-visibility.ts +4 -7
  47. package/src/codex/catalog/native-ultrafast.ts +8 -6
  48. package/src/generated/compatibility-version.json +137 -61
  49. package/src/generated/model-metadata.ts +1 -1
  50. package/src/lib/client-error-body.ts +2 -0
  51. package/src/lib/messages-error-body.ts +3 -1
  52. package/src/lib/optional-shutdown-hooks.ts +55 -5
  53. package/src/lib/process-control.ts +3 -2
  54. package/src/lib/shutdown-budget.ts +5 -0
  55. package/src/link/remote-platform.ts +24 -9
  56. package/src/link/ssh-argv.ts +8 -2
  57. package/src/link/ssh-runner.ts +15 -2
  58. package/src/oauth/m365-copilot-web-session.ts +28 -4
  59. package/src/protocols/dto.ts +24 -12
  60. package/src/protocols/settings.ts +20 -16
  61. package/src/protocols/shadow.ts +2 -3
  62. package/src/protocols/trace.ts +24 -2
  63. package/src/providers/command-code-decision-models.ts +65 -0
  64. package/src/providers/quota.ts +4 -4
  65. package/src/providers/registry/entries-core.ts +18 -7
  66. package/src/providers/registry/entries-extended.ts +41 -0
  67. package/src/providers/registry/model-seeds.ts +42 -0
  68. package/src/providers/resolved-model-policy-merge.ts +8 -0
  69. package/src/providers/resolved-model-policy.ts +185 -165
  70. package/src/providers/slug-codec.ts +5 -0
  71. package/src/server/chat-native-eligibility.ts +5 -0
  72. package/src/server/credential-recovery-attempt.ts +2 -2
  73. package/src/server/gemini-inbound.ts +15 -11
  74. package/src/server/gemini-native-catalog.ts +27 -2
  75. package/src/server/gemini-native-wire.ts +71 -6
  76. package/src/server/gemini-native.ts +129 -34
  77. package/src/server/index/gemini-routes.ts +6 -1
  78. package/src/server/lifecycle.ts +2 -1
  79. package/src/server/management/agent-settings-routes.ts +26 -28
  80. package/src/server/management/api-access.ts +5 -3
  81. package/src/server/management/protocol-routes.ts +3 -1
  82. package/src/server/management/protocol-settings-patch.ts +25 -10
  83. package/src/server/management/shared.ts +20 -5
  84. package/src/server/messages-native-eligibility.ts +4 -0
  85. package/src/server/messages-native-tool-guard.ts +18 -5
  86. package/src/server/request-log-generation-window.ts +7 -2
  87. package/src/server/responses/command-code-decision-refusal.ts +24 -0
  88. package/src/server/responses/compact.ts +2 -2
  89. package/src/server/responses/core-combo.ts +18 -3
  90. package/src/server/responses/core-pipeline.ts +6 -0
  91. package/src/server/responses/sidecar-execution.ts +10 -7
  92. package/src/types/config.ts +2 -0
  93. package/src/usage/expected-prices.ts +17 -0
  94. package/src/usage/telemetry-contract.ts +3 -0
  95. package/gui/dist/assets/App-BI8LQ7Qk.css +0 -1
  96. package/gui/dist/assets/App-CsZ1Gr7S.js +0 -60
  97. package/gui/dist/assets/brand-mark-BebhnAtV.js +0 -1
  98. package/gui/dist/assets/index-BtwVlpeQ.css +0 -2
  99. package/gui/dist/assets/index-CEeMegqE.js +0 -138
  100. package/gui/dist/classic/assets/App-BJgUWNJ8.js +0 -59
  101. package/gui/dist/classic/assets/App-CoiVLRW3.css +0 -1
  102. package/gui/dist/classic/assets/index-B9Jgli_W.js +0 -138
  103. package/gui/dist/classic/assets/usage-companion-chart-vbzDcND0.js +0 -1
@@ -0,0 +1,181 @@
1
+ import { getConfigDir } from "../../config/paths";
2
+ import { didRunDrainStartHooks, didRunOptionalShutdownHooks, registerAsyncOptionalShutdownHook } from "../../lib/optional-shutdown-hooks";
3
+ import type { AdapterEvent, OcxUsage } from "../../types";
4
+ import { buildStepCliArgs } from "./profiles";
5
+
6
+ /**
7
+ * How long a conversation's process survives without traffic.
8
+ *
9
+ * Long enough that a Codex thread's pauses between turns do not tear the conversation down, short
10
+ * enough that an abandoned thread does not leave a StepCode process running.
11
+ */
12
+ export const STEP_CLI_IDLE_TIMEOUT_MS = 10 * 60_000;
13
+ import {
14
+ resolveStepCliBinaryPath,
15
+ stepCliProcessEnvironment,
16
+ StepSessionError,
17
+ type StepSessionDeps,
18
+ type StepSessionEvent,
19
+ } from "./session";
20
+ import {
21
+ StepSessionPool,
22
+ type StepConversationHost,
23
+ type StepConversationRef,
24
+ type StepConversationSession,
25
+ } from "./session-pool";
26
+
27
+ /**
28
+ * Process- and turn-lifetime state that outlives a request.
29
+ *
30
+ * `createStepCliAdapter` runs once per request, so anything that must survive a request boundary
31
+ * cannot live in its closure: a reverse request arriving during request N+1 would be routed to an
32
+ * instance that no longer exists and the conversation would silently restart. `devin/trajectory.ts`
33
+ * keeps its conversation map at module scope for the same reason.
34
+ */
35
+
36
+ /**
37
+ * Per-request turn state, keyed by the process that owns it.
38
+ *
39
+ * `createStepCliAdapter` runs once per request, so nothing that has to survive a request boundary can
40
+ * live in its closure: a reverse request arriving during request N+1 would be routed to an instance
41
+ * that no longer exists, and the conversation would silently restart. `devin/trajectory.ts` keeps its
42
+ * conversation map at module scope for the same reason.
43
+ */
44
+ export interface StepTurnRuntime {
45
+ ref: StepConversationRef;
46
+ pool: StepConversationHost;
47
+ emit: (event: AdapterEvent) => void;
48
+ settle: () => void;
49
+ emittedNames: Map<string, string>;
50
+ catalogKey: string;
51
+ queryId?: string;
52
+ }
53
+
54
+ export const turnRuntimes = new WeakMap<StepConversationSession, StepTurnRuntime>();
55
+
56
+ export const lastAssistantUsage = new WeakMap<StepConversationSession, OcxUsage>();
57
+
58
+ /** Query currently owned by each session, so an abandoned turn can interrupt exactly that one. */
59
+ export const lastQueryId = new WeakMap<StepConversationSession, string>();
60
+
61
+ /* ------------------------------------------------------------------------- *
62
+ * Turn runtime accessors.
63
+ *
64
+ * `events` and `adapter` go through these instead of touching the maps, so the storage shape can
65
+ * change without every caller changing with it — and so "who owns this session's turn" is answered in
66
+ * one place rather than by whoever happens to remember the variable name.
67
+ * ------------------------------------------------------------------------- */
68
+
69
+ /** Attach a turn to the session that owns it, replacing any turn left behind. */
70
+ export function beginTurn(session: StepConversationSession, turn: StepTurnRuntime): void {
71
+ lastAssistantUsage.delete(session);
72
+ turnRuntimes.set(session, turn);
73
+ }
74
+
75
+ /** The turn currently owning this session, if any. */
76
+ export function currentTurn(session: StepConversationSession): StepTurnRuntime | undefined {
77
+ return turnRuntimes.get(session);
78
+ }
79
+
80
+ /** Detach a session's turn. Returns true when one was actually attached. */
81
+ export function endTurn(session: StepConversationSession): boolean {
82
+ return turnRuntimes.delete(session);
83
+ }
84
+
85
+ /** Record the usage the CLI reported for this session's assistant turn. */
86
+ export function recordAssistantUsage(session: StepConversationSession, usage: OcxUsage): void {
87
+ lastAssistantUsage.set(session, usage);
88
+ }
89
+
90
+ /** The usage recorded for this session's assistant turn, if any. */
91
+ export function assistantUsage(session: StepConversationSession): OcxUsage | undefined {
92
+ return lastAssistantUsage.get(session);
93
+ }
94
+
95
+ /** Remember which query this session is running, so an abandoned turn interrupts exactly that one. */
96
+ export function rememberQuery(session: StepConversationSession, queryId: string): void {
97
+ lastQueryId.set(session, queryId);
98
+ const turn = currentTurn(session);
99
+ if (turn) turn.queryId = queryId;
100
+ }
101
+
102
+ /** The query this session is running, if any. */
103
+ export function currentQuery(session: StepConversationSession): string | undefined {
104
+ return lastQueryId.get(session);
105
+ }
106
+
107
+ /** Forget the session's query, e.g. once its input stream has been closed. */
108
+ export function forgetQuery(session: StepConversationSession): void {
109
+ lastQueryId.delete(session);
110
+ }
111
+
112
+ /** One pool per OpenCodex home, so two homes in one process never share a StepCode session. */
113
+ export const pools = new Map<string, StepSessionPool>();
114
+
115
+ const STEP_CLI_SHUTDOWN_KEY = "step-cli-sessions";
116
+ /** Close every owned process during proxy shutdown or an explicit registry clear. */
117
+ export async function clearStepCliSessions(deadlineMs?: number): Promise<void> {
118
+ const closed = await Promise.allSettled([...pools].map(async ([home, pool]) => {
119
+ await pool.closeAll(deadlineMs);
120
+ if (pools.get(home) === pool) pools.delete(home);
121
+ }));
122
+ const failure = closed.find(result => result.status === "rejected");
123
+ if (failure?.status === "rejected") throw failure.reason;
124
+ }
125
+
126
+ function forceStepCliShutdown(): void {
127
+ let failed = false;
128
+ for (const pool of pools.values()) {
129
+ try { pool.forceShutdown(); }
130
+ catch { failed = true; }
131
+ }
132
+ if (failed) throw new StepSessionError("StepCode emergency process cleanup failed.", "step_cli_cleanup_failed");
133
+ }
134
+
135
+ export function poolFor(
136
+ home: string,
137
+ deps: StepSessionDeps,
138
+ handlers: { onEvent(event: StepSessionEvent): void },
139
+ ): StepSessionPool {
140
+ if (didRunDrainStartHooks() || didRunOptionalShutdownHooks()) throw new StepSessionError("StepCode cannot open sessions while the proxy is shutting down.");
141
+ const existing = pools.get(home);
142
+ if (existing) return existing;
143
+ registerAsyncOptionalShutdownHook(STEP_CLI_SHUTDOWN_KEY, clearStepCliSessions, forceStepCliShutdown);
144
+ const { env, cwd } = stepCliProcessEnvironment(home);
145
+ const pool = new StepSessionPool(
146
+ {
147
+ openCodexHome: home,
148
+ idleTimeoutMs: STEP_CLI_IDLE_TIMEOUT_MS,
149
+ buildOptions: () => ({
150
+ binary: resolveStepCliBinaryPath(deps.which),
151
+ args: buildStepCliArgs(undefined, undefined),
152
+ env,
153
+ cwd,
154
+ handshakeTimeoutMs: 30_000,
155
+ requestTimeoutMs: 120_000,
156
+ // StepCode's own tool window is 120s and answering later produces a `permission_denied`
157
+ // message inside the model's context, so the hold is bounded shorter and fails the turn.
158
+ reverseRequestHoldMs: 110_000,
159
+ idleTimeoutMs: STEP_CLI_IDLE_TIMEOUT_MS,
160
+ killGraceMs: 2_000,
161
+ }),
162
+ },
163
+ handlers,
164
+ deps,
165
+ );
166
+ pools.set(home, pool);
167
+ return pool;
168
+ }
169
+
170
+ /**
171
+ * A reverse request the CLI is waiting on this peer to answer.
172
+ *
173
+ * `permission.request` is allowed immediately because the approval already happened upstream of this
174
+ * adapter. A `sdk_tool.invoke` is deliberately NOT answered here: its result only exists once the
175
+ * client has executed the tool and sent its next request, and answering it is how that result reaches
176
+ * the model inside the query the model is already running.
177
+ */
178
+ /**
179
+ * Exported for its regression tests: every reverse request must be ANSWERED, and the tests drive this
180
+ * exact function rather than a mirror of it.
181
+ */
@@ -0,0 +1,225 @@
1
+ import { StepCliSession, StepSessionError, type StepSessionDeps, type StepSessionEvent, type StepSessionHandlers, type StepSessionOptions } from "./session";
2
+
3
+ /** Conversation identity the client echoes back through `providerState`. */
4
+ export interface StepConversationRef {
5
+ sessionId: string;
6
+ /** Process-local key; never a credential, only a proxy-internal handle. */
7
+ handle: string;
8
+ }
9
+
10
+ /**
11
+ * The reverse request this conversation is holding, and the call it belongs to.
12
+ *
13
+ * The call id is kept beside the frame id because the client's next request may carry results for
14
+ * several calls; delivering the newest result by POSITION would answer the wrong call.
15
+ */
16
+ export interface StepHeldTool {
17
+ readonly frameId: string;
18
+ readonly callId: string;
19
+ readonly queryId: string;
20
+ readonly catalogKey: string;
21
+ }
22
+
23
+ export interface StepSessionPoolOptions {
24
+ openCodexHome: string;
25
+ buildOptions: () => StepSessionOptions;
26
+ idleTimeoutMs: number;
27
+ }
28
+
29
+ interface PoolEntry {
30
+ readonly ref: StepConversationRef;
31
+ readonly session: StepCliSession;
32
+ /** Reverse request the pool is currently holding for the next client request. */
33
+ heldTool: StepHeldTool | undefined;
34
+ }
35
+
36
+ /**
37
+ * Conversation-keyed StepCode sessions.
38
+ *
39
+ * The pool exists because StepCode's only durable conversation state is process memory: one process
40
+ * serves one query at a time (`maxConcurrentQueries: 1`) and `query.input` carries text and images
41
+ * only, so a client conversation maps onto exactly one live process. Entries are reclaimed by idle
42
+ * timeout and on process exit, and a conversation whose process died is reported as such rather than
43
+ * silently restarted — a restart would lose the model's view of earlier tool results, and a tool
44
+ * result the client already delivered is not recoverable from the transcript.
45
+ */
46
+ /**
47
+ * The conversation bookkeeping the adapter depends on.
48
+ *
49
+ * Narrower than the pool itself so a test can supply a fake process and still exercise the real
50
+ * `runTurn` path — the path that decides whether a captured call is answered, refused or abandoned.
51
+ */
52
+ export interface StepConversationHost {
53
+ get(ref: StepConversationRef | undefined): StepConversationSession | undefined;
54
+ open(ref: StepConversationRef): Promise<StepConversationSession>;
55
+ nextRef(): StepConversationRef;
56
+ rememberHeldTool(ref: StepConversationRef, held: StepHeldTool): void;
57
+ takeHeldTool(ref: StepConversationRef): StepHeldTool | undefined;
58
+ closeAll(): Promise<void>;
59
+ }
60
+
61
+ /** The session surface `runTurn` uses. */
62
+ export type StepConversationSession = Pick<
63
+ StepCliSession,
64
+ "sessionId" | "closed" | "handshake" | "startQuery" | "sendInput" | "endInput" | "interrupt" | "close" | "resolveHeldToolResult" | "allowPermission" | "denyPermission" | "refuseToolCall"
65
+ >;
66
+
67
+ export class StepSessionPool implements StepConversationHost {
68
+ readonly #entries = new Map<string, PoolEntry>();
69
+ /**
70
+ * In-flight opens, keyed by handle.
71
+ *
72
+ * `open` is async, so two requests for one conversation (a Codex retry, or two clients sharing a
73
+ * handle) both miss the map and both spawn a process; the second `#entries.set` then orphans the
74
+ * first session with a held tool call nobody can release. Coalescing on the promise makes one
75
+ * conversation exactly one process.
76
+ */
77
+ readonly #opening = new Map<string, Promise<StepCliSession>>();
78
+ /** Track ownership from construction through confirmed cleanup, even for an in-flight open. */
79
+ readonly #sessions = new Set<StepCliSession>();
80
+ readonly #options: StepSessionPoolOptions;
81
+ readonly #deps: StepSessionDeps;
82
+ readonly #handlers: StepSessionHandlers;
83
+ readonly #sweepMs: number;
84
+ #sweep: ReturnType<typeof setInterval> | undefined;
85
+ #handleSeq = 0;
86
+ #closing = false;
87
+ #closePromise: Promise<void> | undefined;
88
+
89
+ constructor(
90
+ options: StepSessionPoolOptions,
91
+ handlers: StepSessionHandlers,
92
+ deps: StepSessionDeps = {},
93
+ ) {
94
+ this.#options = options;
95
+ this.#handlers = handlers;
96
+ this.#deps = deps;
97
+ this.#sweepMs = Math.max(1_000, Math.min(options.idleTimeoutMs, 60_000));
98
+ }
99
+
100
+ /** Look up a live session for a conversation, if one is still open. */
101
+ get(ref: StepConversationRef | undefined): StepCliSession | undefined {
102
+ if (!ref) return undefined;
103
+ const entry = this.#entries.get(ref.handle);
104
+ return entry && !entry.session.closed ? entry.session : undefined;
105
+ }
106
+
107
+ /** Open a session for a conversation, coalescing concurrent opens of the same handle. */
108
+ async open(ref: StepConversationRef): Promise<StepCliSession> {
109
+ if (this.#closing) throw new StepSessionError("StepCode session pool is closing.");
110
+ const existing = this.get(ref);
111
+ if (existing) return existing;
112
+ if (this.#entries.has(ref.handle)) {
113
+ throw new StepSessionError("StepCode conversation cleanup is pending or quarantined.", "step_cli_cleanup_failed");
114
+ }
115
+ const inFlight = this.#opening.get(ref.handle);
116
+ if (inFlight) return inFlight;
117
+ const opening = (async () => {
118
+ const session = await StepCliSession.open(this.#options.buildOptions(), this.#handlers, this.#deps, owned => {
119
+ this.#sessions.add(owned);
120
+ owned.onExit(() => this.#sessions.delete(owned));
121
+ });
122
+ if (this.#closing) {
123
+ await session.close();
124
+ return session;
125
+ }
126
+ const entry: PoolEntry = { ref, session, heldTool: undefined };
127
+ this.#entries.set(ref.handle, entry);
128
+ session.onExit(() => {
129
+ if (this.#entries.get(ref.handle) === entry) this.#entries.delete(ref.handle);
130
+ });
131
+ this.#ensureSweep();
132
+ return session;
133
+ })();
134
+ this.#opening.set(ref.handle, opening);
135
+ try {
136
+ return await opening;
137
+ } finally {
138
+ if (this.#opening.get(ref.handle) === opening) this.#opening.delete(ref.handle);
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Remember which reverse request the next client request must answer.
144
+ *
145
+ * The result arrives in a later HTTP request, so the frame has to outlive the turn that produced
146
+ * it. Storing only its id keeps the session's own hold timer authoritative.
147
+ */
148
+ rememberHeldTool(ref: StepConversationRef, held: StepHeldTool): void {
149
+ const entry = this.#entries.get(ref.handle);
150
+ if (entry) entry.heldTool = held;
151
+ }
152
+
153
+ /** Consume the remembered hold, so one tool result can never be delivered twice. */
154
+ takeHeldTool(ref: StepConversationRef): StepHeldTool | undefined {
155
+ const entry = this.#entries.get(ref.handle);
156
+ if (!entry) return undefined;
157
+ const held = entry.heldTool;
158
+ entry.heldTool = undefined;
159
+ return held;
160
+ }
161
+
162
+ /** Mint the identity a new conversation is addressed by. */
163
+ nextRef(): StepConversationRef {
164
+ this.#handleSeq += 1;
165
+ return { handle: `step_${this.#handleSeq}`, sessionId: "" };
166
+ }
167
+
168
+ #ensureSweep(): void {
169
+ if (this.#sweep) return;
170
+ this.#sweep = setInterval(() => {
171
+ for (const entry of [...this.#entries.values()]) {
172
+ if (entry.session.closed || entry.session.idleMs() >= this.#options.idleTimeoutMs) {
173
+ // The exit listener releases the handle only after cleanup succeeds. Failed sessions
174
+ // stay owned and the entry remains quarantined; never retry from every sweep.
175
+ void entry.session.close().catch(() => {});
176
+ }
177
+ }
178
+ if (this.#entries.size === 0) this.#stopSweep();
179
+ }, this.#sweepMs);
180
+ this.#sweep.unref?.();
181
+ }
182
+
183
+ #stopSweep(): void {
184
+ if (!this.#sweep) return;
185
+ clearInterval(this.#sweep);
186
+ this.#sweep = undefined;
187
+ }
188
+
189
+ get size(): number {
190
+ return this.#entries.size;
191
+ }
192
+
193
+ closeAll(deadlineMs?: number): Promise<void> {
194
+ this.#closing = true;
195
+ if (deadlineMs !== undefined) {
196
+ for (const session of this.#sessions) session.closeBy(deadlineMs);
197
+ }
198
+ if (this.#closePromise) return this.#closePromise;
199
+ this.#stopSweep();
200
+ const opening = [...this.#opening.values()];
201
+ const entries = [...this.#entries.values()];
202
+ this.#closePromise = (async () => {
203
+ const closed = await Promise.allSettled(entries.map(entry => entry.session.close()));
204
+ // An open owns its child until it returns. Its closing branch reaps that child before
205
+ // resolving, so shutdown cannot finish while a late open can still publish a session.
206
+ const opened = await Promise.allSettled(opening);
207
+ const cleanup = await Promise.allSettled([...this.#sessions].map(session => session.close()));
208
+ const failure = [...closed, ...opened, ...cleanup].find(result => result.status === "rejected");
209
+ if (failure?.status === "rejected") throw failure.reason;
210
+ })();
211
+ return this.#closePromise;
212
+ }
213
+
214
+ forceShutdown(): void {
215
+ let failed = false;
216
+ for (const session of this.#sessions) {
217
+ try { session.forceShutdown(); }
218
+ catch { failed = true; }
219
+ }
220
+ if (failed) throw new StepSessionError("StepCode emergency process cleanup failed.", "step_cli_cleanup_failed");
221
+ }
222
+ }
223
+
224
+ export { StepSessionError };
225
+ export type { StepSessionEvent, StepSessionHandlers };