@gajae-code/coding-agent 0.15.5 → 0.16.0

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 (272) hide show
  1. package/CHANGELOG.md +85 -1
  2. package/dist/types/async/job-manager.d.ts +83 -0
  3. package/dist/types/cli/args.d.ts +2 -0
  4. package/dist/types/cli/auth-gateway-cli.d.ts +17 -0
  5. package/dist/types/cli/model-presets-cli.d.ts +9 -0
  6. package/dist/types/cli/root-flags.d.ts +14 -0
  7. package/dist/types/cli/update-cli.d.ts +15 -0
  8. package/dist/types/cli.d.ts +7 -0
  9. package/dist/types/commands/auth-gateway.d.ts +3 -0
  10. package/dist/types/commands/gc.d.ts +13 -0
  11. package/dist/types/commands/launch.d.ts +10 -0
  12. package/dist/types/commands/model-presets.d.ts +21 -0
  13. package/dist/types/config/autorouting-tier-map.d.ts +120 -0
  14. package/dist/types/config/file-lock.d.ts +54 -2
  15. package/dist/types/config/internal/model-preset-registry-test-state.d.ts +4 -0
  16. package/dist/types/config/internal/model-preset-registry-test-support.d.ts +3 -0
  17. package/dist/types/config/keybindings.d.ts +3 -2
  18. package/dist/types/config/model-preset-registry.d.ts +368 -0
  19. package/dist/types/config/model-profile-activation.d.ts +39 -0
  20. package/dist/types/config/model-profiles.d.ts +5 -3
  21. package/dist/types/config/model-registry.d.ts +17 -5
  22. package/dist/types/config/settings-schema.d.ts +19 -1
  23. package/dist/types/config/settings.d.ts +2 -0
  24. package/dist/types/coordinator-mcp/model-preset.d.ts +7 -5
  25. package/dist/types/coordinator-mcp/projection-scan.d.ts +54 -0
  26. package/dist/types/crash/record-loader.d.ts +15 -0
  27. package/dist/types/extensibility/extensions/types.d.ts +2 -5
  28. package/dist/types/gjc-runtime/empty-delete-gc.d.ts +58 -0
  29. package/dist/types/gjc-runtime/gc-runtime.d.ts +2 -0
  30. package/dist/types/gjc-runtime/launch-worktree-reservation.d.ts +21 -0
  31. package/dist/types/gjc-runtime/managed-owner-supervisor.d.ts +2 -0
  32. package/dist/types/gjc-runtime/session-state-lock.d.ts +35 -6
  33. package/dist/types/gjc-runtime/session-state-sidecar.d.ts +72 -1
  34. package/dist/types/gjc-runtime/tmux-owner-isolation.d.ts +1 -0
  35. package/dist/types/gjc-runtime/tmux-sessions.d.ts +27 -0
  36. package/dist/types/index.d.ts +1 -0
  37. package/dist/types/main.d.ts +3 -1
  38. package/dist/types/master-mode/context.d.ts +21 -0
  39. package/dist/types/master-mode/first-request.d.ts +34 -0
  40. package/dist/types/master-mode/snapshot.d.ts +32 -0
  41. package/dist/types/modes/components/frictionless-onboarding-selector.d.ts +10 -0
  42. package/dist/types/modes/components/jobs-overlay-model.d.ts +4 -2
  43. package/dist/types/modes/components/oauth-selector.d.ts +1 -0
  44. package/dist/types/modes/components/status-line/model-name.d.ts +18 -0
  45. package/dist/types/modes/components/status-line/priority-row.d.ts +34 -0
  46. package/dist/types/modes/components/status-line/segments.d.ts +10 -0
  47. package/dist/types/modes/jobs-observer.d.ts +36 -0
  48. package/dist/types/modes/print-mode.d.ts +17 -0
  49. package/dist/types/modes/ui-language.d.ts +7 -1
  50. package/dist/types/sdk/broker/broker.d.ts +80 -1
  51. package/dist/types/sdk/broker/endpoint-authority.d.ts +24 -0
  52. package/dist/types/sdk/broker/index.d.ts +3 -0
  53. package/dist/types/sdk/broker/lifecycle.d.ts +26 -0
  54. package/dist/types/sdk/broker/master-capability.d.ts +10 -0
  55. package/dist/types/sdk/broker/session-index.d.ts +40 -11
  56. package/dist/types/sdk/broker/session-scope.d.ts +72 -0
  57. package/dist/types/sdk/broker/spawn-authority.d.ts +201 -0
  58. package/dist/types/sdk/broker/spawn-substrate.d.ts +30 -0
  59. package/dist/types/sdk/broker/state-version.d.ts +4 -1
  60. package/dist/types/sdk/broker/worktree-occupancy.d.ts +28 -0
  61. package/dist/types/sdk/bus/chat-daemon-control.d.ts +3 -0
  62. package/dist/types/sdk/bus/index.d.ts +6 -0
  63. package/dist/types/sdk/bus/kind-aware-reconciliation.d.ts +3 -0
  64. package/dist/types/sdk/bus/prompt-reconciliation.d.ts +4 -0
  65. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +1 -1
  66. package/dist/types/sdk/cli/index.d.ts +1 -0
  67. package/dist/types/sdk/cli/master-cli.d.ts +63 -0
  68. package/dist/types/sdk/cli/rows.d.ts +4 -3
  69. package/dist/types/sdk/cli/session-cli.d.ts +18 -2
  70. package/dist/types/sdk/client/client.d.ts +3 -2
  71. package/dist/types/sdk/client/discovery.d.ts +1 -0
  72. package/dist/types/sdk/host/control/dispatch.d.ts +10 -0
  73. package/dist/types/sdk/host/control/index.d.ts +1 -1
  74. package/dist/types/sdk/host/control/operations.d.ts +2 -0
  75. package/dist/types/sdk/host/control/runtime-gate.d.ts +21 -7
  76. package/dist/types/sdk/host/host.d.ts +10 -0
  77. package/dist/types/sdk/host/model-pin.d.ts +7 -2
  78. package/dist/types/sdk/host/sdk-run-capability.d.ts +1 -0
  79. package/dist/types/sdk/host/session-runtime.d.ts +67 -1
  80. package/dist/types/sdk/lifecycle/broker-client.d.ts +6 -0
  81. package/dist/types/sdk/lifecycle/service.d.ts +15 -3
  82. package/dist/types/sdk/lifecycle-session.d.ts +2 -0
  83. package/dist/types/sdk/prompt-deadline-manager.d.ts +11 -1
  84. package/dist/types/sdk/protocol/adapter-validation.d.ts +2 -0
  85. package/dist/types/sdk/router/session-router.d.ts +11 -0
  86. package/dist/types/sdk/session.d.ts +16 -0
  87. package/dist/types/sdk/startup-capability.d.ts +2 -1
  88. package/dist/types/session/account-inventory.d.ts +1 -0
  89. package/dist/types/session/agent-session.d.ts +24 -7
  90. package/dist/types/session/credential-store-errors.d.ts +1 -0
  91. package/dist/types/session/fold-coordinator.d.ts +201 -0
  92. package/dist/types/session/sdk-run-capability-internal.d.ts +7 -0
  93. package/dist/types/session/sdk-run-capability.d.ts +2 -0
  94. package/dist/types/session/session-manager.d.ts +65 -0
  95. package/dist/types/session/yield-queue.d.ts +5 -4
  96. package/dist/types/setup/frictionless-onboarding.d.ts +1 -0
  97. package/dist/types/telemetry/control.d.ts +11 -0
  98. package/dist/types/telemetry/events.d.ts +20 -0
  99. package/dist/types/telemetry/index.d.ts +3 -0
  100. package/dist/types/telemetry/transport.d.ts +22 -0
  101. package/dist/types/tools/bash-interactive.d.ts +23 -0
  102. package/dist/types/tools/bash.d.ts +4 -0
  103. package/dist/types/tools/gh.d.ts +8 -0
  104. package/dist/types/tools/index.d.ts +10 -5
  105. package/dist/types/web/search/providers/base.d.ts +9 -4
  106. package/dist/types/web/search/providers/xai.d.ts +2 -1
  107. package/dist/types/web/search/types.d.ts +14 -0
  108. package/package.json +10 -7
  109. package/scripts/generate-hotkeys-docs.ts +4 -0
  110. package/scripts/generate-sdk-operation-inventory.ts +9 -3
  111. package/scripts/verify-gjc-sdk-canonicalization.ts +35 -1
  112. package/src/async/job-manager.ts +671 -39
  113. package/src/cli/accounts-cli.ts +9 -5
  114. package/src/cli/args.ts +17 -0
  115. package/src/cli/auth-broker-cli.ts +40 -12
  116. package/src/cli/auth-gateway-cli.ts +273 -97
  117. package/src/cli/config-cli.ts +2 -2
  118. package/src/cli/fast-help.ts +4 -0
  119. package/src/cli/model-presets-cli.ts +100 -0
  120. package/src/cli/root-flags.ts +5 -0
  121. package/src/cli/update-cli.ts +117 -16
  122. package/src/cli.ts +6 -2
  123. package/src/commands/auth-gateway.ts +12 -8
  124. package/src/commands/gc.ts +19 -0
  125. package/src/commands/launch.ts +86 -18
  126. package/src/commands/model-presets.ts +24 -0
  127. package/src/commands/sdk.ts +113 -21
  128. package/src/config/autorouting-tier-map.ts +44 -0
  129. package/src/config/file-lock-gc.ts +9 -4
  130. package/src/config/file-lock.ts +890 -99
  131. package/src/config/internal/model-preset-registry-test-state.ts +28 -0
  132. package/src/config/internal/model-preset-registry-test-support.ts +11 -0
  133. package/src/config/keybindings.ts +6 -2
  134. package/src/config/model-preset-registry.ts +2795 -0
  135. package/src/config/model-profile-activation.ts +115 -28
  136. package/src/config/model-profile-contract.ts +4 -1
  137. package/src/config/model-profiles.ts +56 -14
  138. package/src/config/model-registry.ts +1044 -122
  139. package/src/config/model-resolver.ts +5 -0
  140. package/src/config/settings-schema.ts +19 -1
  141. package/src/config/settings.ts +11 -1
  142. package/src/coordinator-mcp/model-preset.ts +32 -17
  143. package/src/coordinator-mcp/projection-scan.ts +592 -0
  144. package/src/coordinator-mcp/question-state.ts +9 -11
  145. package/src/coordinator-mcp/server.ts +111 -42
  146. package/src/coordinator-mcp/session-reaper.ts +9 -3
  147. package/src/crash/index-store.ts +2 -0
  148. package/src/crash/record-loader.ts +10 -0
  149. package/src/extensibility/extensions/loader.ts +0 -1
  150. package/src/extensibility/extensions/types.ts +2 -3
  151. package/src/extensibility/gjc-plugins/runtime-adapters.ts +1 -0
  152. package/src/gjc-runtime/empty-delete-gc.ts +301 -0
  153. package/src/gjc-runtime/gc-render.ts +29 -0
  154. package/src/gjc-runtime/gc-runtime.ts +174 -11
  155. package/src/gjc-runtime/launch-worktree-reservation.ts +242 -0
  156. package/src/gjc-runtime/managed-owner-supervisor.ts +63 -51
  157. package/src/gjc-runtime/session-state-lock.ts +1321 -147
  158. package/src/gjc-runtime/session-state-sidecar.ts +1004 -25
  159. package/src/gjc-runtime/tmux-owner-isolation-cli.ts +4 -7
  160. package/src/gjc-runtime/tmux-owner-isolation.ts +2 -2
  161. package/src/gjc-runtime/tmux-sessions.ts +252 -13
  162. package/src/hooks/skill-state.ts +6 -0
  163. package/src/index.ts +1 -0
  164. package/src/internal-urls/docs-index.generated.ts +14 -13
  165. package/src/internal-urls/issue-pr-protocol.ts +4 -2
  166. package/src/lsp/config.ts +4 -3
  167. package/src/lsp/path-trust.ts +12 -6
  168. package/src/main.ts +66 -4
  169. package/src/master-mode/context.ts +50 -0
  170. package/src/master-mode/first-request.ts +65 -0
  171. package/src/master-mode/snapshot.ts +205 -0
  172. package/src/modes/acp/acp-agent.ts +616 -161
  173. package/src/modes/components/footer.ts +4 -2
  174. package/src/modes/components/frictionless-onboarding-selector.ts +48 -2
  175. package/src/modes/components/jobs-overlay-model.ts +99 -16
  176. package/src/modes/components/model-selector.ts +158 -18
  177. package/src/modes/components/oauth-selector.ts +6 -1
  178. package/src/modes/components/settings-selector.ts +1 -0
  179. package/src/modes/components/status-line/model-name.ts +53 -0
  180. package/src/modes/components/status-line/priority-row.ts +107 -0
  181. package/src/modes/components/status-line/segments.ts +29 -10
  182. package/src/modes/components/tool-status-header.ts +151 -15
  183. package/src/modes/controllers/extension-ui-controller.ts +1 -1
  184. package/src/modes/controllers/input-controller.ts +51 -6
  185. package/src/modes/controllers/selector-controller.ts +191 -96
  186. package/src/modes/interactive-mode.ts +14 -1
  187. package/src/modes/jobs-observer.ts +149 -16
  188. package/src/modes/print-mode.ts +64 -0
  189. package/src/modes/runtime-init.ts +1 -1
  190. package/src/modes/ui-language.ts +49 -2
  191. package/src/modes/utils/injected-user-submission.ts +15 -1
  192. package/src/prompts/system/master-mode.md +28 -0
  193. package/src/prompts/tools/bash.md +2 -2
  194. package/src/prompts/tools/fold-receipt.md +3 -0
  195. package/src/prompts/tools/job.md +1 -1
  196. package/src/sdk/acp/adapter.ts +17 -2
  197. package/src/sdk/broker/broker.ts +1671 -34
  198. package/src/sdk/broker/endpoint-authority.ts +86 -0
  199. package/src/sdk/broker/ensure.ts +5 -0
  200. package/src/sdk/broker/index.ts +3 -0
  201. package/src/sdk/broker/lifecycle.ts +217 -46
  202. package/src/sdk/broker/master-capability.ts +232 -0
  203. package/src/sdk/broker/session-index.ts +121 -17
  204. package/src/sdk/broker/session-scope.ts +272 -0
  205. package/src/sdk/broker/spawn-authority.ts +1031 -0
  206. package/src/sdk/broker/spawn-substrate.ts +548 -0
  207. package/src/sdk/broker/state-version.ts +26 -14
  208. package/src/sdk/broker/transport.ts +1 -0
  209. package/src/sdk/broker/worktree-occupancy.ts +90 -0
  210. package/src/sdk/bus/chat-daemon-control.ts +5 -2
  211. package/src/sdk/bus/chat-daemon-runtime.ts +46 -5
  212. package/src/sdk/bus/index.ts +51 -4
  213. package/src/sdk/bus/kind-aware-reconciliation.ts +36 -6
  214. package/src/sdk/bus/prompt-reconciliation.ts +28 -4
  215. package/src/sdk/bus/slack-conversation.ts +5 -1
  216. package/src/sdk/bus/telegram-daemon-contract.ts +1 -1
  217. package/src/sdk/cli/index.ts +1 -0
  218. package/src/sdk/cli/master-cli.ts +259 -0
  219. package/src/sdk/cli/rows.ts +11 -8
  220. package/src/sdk/cli/session-cli.ts +276 -6
  221. package/src/sdk/client/client.ts +14 -8
  222. package/src/sdk/client/discovery.ts +3 -1
  223. package/src/sdk/host/control/dispatch.ts +101 -37
  224. package/src/sdk/host/control/index.ts +2 -0
  225. package/src/sdk/host/control/operations.ts +2 -0
  226. package/src/sdk/host/control/runtime-gate.ts +203 -11
  227. package/src/sdk/host/host.ts +27 -2
  228. package/src/sdk/host/model-pin.ts +185 -25
  229. package/src/sdk/host/sdk-run-capability.ts +1 -0
  230. package/src/sdk/host/session-runtime.test.ts +581 -43
  231. package/src/sdk/host/session-runtime.ts +655 -101
  232. package/src/sdk/lifecycle/broker-client.ts +28 -0
  233. package/src/sdk/lifecycle/service.ts +279 -20
  234. package/src/sdk/lifecycle-session.ts +10 -2
  235. package/src/sdk/prompt-deadline-manager.ts +16 -1
  236. package/src/sdk/protocol/adapter-validation.ts +27 -0
  237. package/src/sdk/protocol/operation-inventory.generated.json +53 -2
  238. package/src/sdk/protocol/operation-registry.ts +17 -4
  239. package/src/sdk/router/session-router.ts +294 -154
  240. package/src/sdk/session.ts +440 -167
  241. package/src/sdk/startup-capability.ts +1 -0
  242. package/src/session/account-inventory.ts +27 -11
  243. package/src/session/agent-session.ts +1292 -180
  244. package/src/session/blob-store.ts +15 -5
  245. package/src/session/credential-store-errors.ts +2 -0
  246. package/src/session/fold-coordinator.ts +433 -0
  247. package/src/session/internal/managed-session-storage.ts +153 -78
  248. package/src/session/sdk-run-capability-internal.ts +15 -0
  249. package/src/session/sdk-run-capability.ts +2 -0
  250. package/src/session/session-manager.ts +342 -28
  251. package/src/session/yield-queue.ts +24 -10
  252. package/src/setup/frictionless-onboarding.ts +2 -0
  253. package/src/setup/provider-presets.json +1 -1
  254. package/src/slash-commands/helpers/credential-switch.ts +6 -1
  255. package/src/task/executor.ts +19 -3
  256. package/src/telemetry/control.ts +26 -0
  257. package/src/telemetry/events.ts +1268 -0
  258. package/src/telemetry/index.ts +3 -0
  259. package/src/telemetry/transport.ts +87 -0
  260. package/src/tools/bash-interactive.ts +182 -85
  261. package/src/tools/bash.ts +1028 -109
  262. package/src/tools/gh.ts +104 -48
  263. package/src/tools/github-cache.ts +2 -2
  264. package/src/tools/index.ts +11 -5
  265. package/src/tools/tool-catalog.generated.ts +1 -1
  266. package/src/web/search/provider.ts +120 -11
  267. package/src/web/search/providers/anthropic.ts +89 -17
  268. package/src/web/search/providers/base.ts +9 -4
  269. package/src/web/search/providers/gemini.ts +87 -15
  270. package/src/web/search/providers/openai-compatible.ts +23 -8
  271. package/src/web/search/providers/xai.ts +98 -12
  272. package/src/web/search/types.ts +16 -0
@@ -1,9 +1,27 @@
1
1
  import { type Settings } from "../../config/settings";
2
2
  import type { ExtensionAPI, ExtensionContext } from "../../extensibility/extensions";
3
+ import { type MasterRoleAttestationV2, SessionIndex, type SessionLocatorV2 } from "../broker/session-index";
4
+ import { type TurnResultContent } from "../turn-result";
3
5
  import { SessionSdkHost, type SessionSdkHostOptions } from "./host";
4
6
  import { type SessionSurface } from "./query";
5
7
  import { type SdkCapabilities, type SdkSurfacePolicy } from "./surface-policy";
6
8
  import type { BrokerIndexWriter, SdkFrame } from "./types";
9
+ export type MasterCapabilityReplayState = Map<string, number>;
10
+ export declare function verifyMasterCapabilityFrame(input: {
11
+ frame: {
12
+ nonce: unknown;
13
+ attestationEpoch: unknown;
14
+ capability: unknown;
15
+ };
16
+ expectedCapability: string | undefined;
17
+ expectedEpoch: string | undefined;
18
+ replay: MasterCapabilityReplayState;
19
+ now?: number;
20
+ }): {
21
+ ok: boolean;
22
+ nonce: string;
23
+ attestationEpoch: string;
24
+ };
7
25
  /** Transport-neutral endpoint contract consumed by the SDK session runtime. */
8
26
  export interface SessionSdkTransport {
9
27
  readonly sessionId: string;
@@ -26,6 +44,8 @@ export interface SessionSdkRuntimeOptions extends Omit<SessionSdkHostOptions, "s
26
44
  settings?: Settings;
27
45
  /** Mutable shadow of patched config values merged into query readback. */
28
46
  configOverrides?: Map<string, unknown>;
47
+ /** Stable master lineage identity retained across session switches/branches. */
48
+ masterOwnerSessionId?: string;
29
49
  }
30
50
  export interface SdkOnlyInvocationRecord extends InvocationCorrelation {
31
51
  kind: InvocationKind | "terminal" | "steer";
@@ -160,6 +180,8 @@ export interface CreateSdkSessionRuntimeOptions {
160
180
  agentDir: string;
161
181
  /** Lifecycle-owned sessions require broker publication before they become usable. */
162
182
  brokerRegistrationRequired?: boolean;
183
+ /** Trusted broker-issued lifecycle marker bound to lifecycle host index events. */
184
+ lifecycleRequestId?: string;
163
185
  createTransport(input: {
164
186
  sessionId: string;
165
187
  stateRoot: string;
@@ -171,6 +193,12 @@ export interface CreateSdkSessionRuntimeOptions {
171
193
  onSdkRequest?: SessionSdkHostOptions["onRequest"];
172
194
  /** Mutable shadow of patched config values merged into query readback. */
173
195
  configOverrides?: Map<string, unknown>;
196
+ /** In-memory master capability for private broker verification only. */
197
+ masterCapability?: string;
198
+ /** Opaque direct-role epoch this effective host may adopt. */
199
+ masterAttestationEpoch?: string;
200
+ /** Stable master lineage identity retained across session switches/branches. */
201
+ masterOwnerSessionId?: string;
174
202
  /** Private session-owned terminal-abort capabilities; never exposed on ExtensionContext. */
175
203
  terminalAbortSeams?: SdkOnlyTerminalAbortSeams;
176
204
  /** Callback when a frame is admitted to the runtime (test harness). */
@@ -194,9 +222,18 @@ export interface InvocationReconciliation {
194
222
  noteAccepted(kind: InvocationKind, correlation: InvocationCorrelation, clientRef?: string): Promise<void>;
195
223
  noteTransition(kind: InvocationKind, correlation: InvocationCorrelation | undefined, frame: {
196
224
  type: "agent_start" | "agent_end";
225
+ content?: TurnResultContent;
226
+ hasActivity?: boolean;
227
+ outcome?: {
228
+ kind: "stopped";
229
+ reason: "cancelled";
230
+ provenance: "client_cancel";
231
+ };
197
232
  } | {
198
233
  type: "agent_failed";
199
234
  error: unknown;
235
+ content?: TurnResultContent;
236
+ hasActivity?: boolean;
200
237
  }): Promise<void>;
201
238
  lookup(kind: InvocationKind, selector: {
202
239
  commandId?: string;
@@ -228,7 +265,11 @@ export interface InvocationReconciliation {
228
265
  }, arg4?: (() => boolean) | {
229
266
  code: string;
230
267
  message: string;
231
- }, arg5?: unknown): Promise<void>;
268
+ }, arg5?: unknown, arg6?: {
269
+ content?: TurnResultContent;
270
+ hasActivity?: boolean;
271
+ outcomeKind?: string;
272
+ }): Promise<void>;
232
273
  markUncertain(kind: InvocationKind, correlation: InvocationCorrelation, isCurrent?: () => boolean, deadlineMaxAt?: number): Promise<void>;
233
274
  }
234
275
  export declare function createInvocationReconciliation(options?: {
@@ -279,6 +320,31 @@ export declare function createSdkSurfaceFactory(options: SdkSurfaceFactoryOption
279
320
  }): SdkSurfaceFactory;
280
321
  /** Register the default-session notification command without loading notification adapters. */
281
322
  export declare function registerSdkOnlyNotificationCommand(api: ExtensionAPI): void;
323
+ export declare function masterAttestationForEffectiveHost(input: {
324
+ masterCapability: string | undefined;
325
+ attestationEpoch: string | undefined;
326
+ ownerSessionId?: string;
327
+ sessionId: string;
328
+ pid: number;
329
+ processIncarnation: string | undefined;
330
+ direct: MasterRoleAttestationV2 | undefined;
331
+ }): MasterRoleAttestationV2 | undefined;
332
+ /**
333
+ * Establish direct master authority for the session currently hosted by this
334
+ * process. Session identity transitions retain the master capability and epoch
335
+ * but require a new direct attestation before their effective endpoint can
336
+ * adopt that authority.
337
+ */
338
+ export declare function reattestMasterSessionIdentity(input: {
339
+ index: SessionIndex;
340
+ locator: SessionLocatorV2;
341
+ masterCapability: string | undefined;
342
+ attestationEpoch: string | undefined;
343
+ ownerSessionId?: string;
344
+ sessionId: string;
345
+ pid: number;
346
+ processIncarnation: string | undefined;
347
+ }): Promise<MasterRoleAttestationV2 | undefined>;
282
348
  /** Install a complete SDK host for a session when notifications are inactive. */
283
349
  export declare function createSdkSessionRuntimeExtension(api: ExtensionAPI, options: CreateSdkSessionRuntimeOptions): void;
284
350
  export {};
@@ -6,3 +6,9 @@ export declare class AgentDirSessionLifecycleClient implements SessionLifecycleC
6
6
  global(operation: SessionLifecycleOperation, input: Record<string, unknown>, options: SessionLifecycleClientRequestOptions): Promise<unknown>;
7
7
  }
8
8
  export declare function createBrokerSessionLifecycleService(agentDir: string): SessionLifecycleService;
9
+ /**
10
+ * Dedicated dispatch for the local master `session.spawn` surface. It shares
11
+ * the lifecycle client's credential boundary but bypasses the generic mutation
12
+ * outcome types: spawn responses are validated by the caller's allowlist.
13
+ */
14
+ export declare function dispatchSpawnGlobal(agentDir: string, input: Record<string, unknown>, idempotencyKey: string, timeoutMs: number): Promise<unknown>;
@@ -1,3 +1,4 @@
1
+ import { type ScopeRequestV1, type SdkSearchResultV1 } from "../broker/session-scope";
1
2
  export type SessionLifecycleOperation = "session.create" | "session.fork" | "session.resume" | "session.close" | "session.delete" | "session.reconcile_uncertain" | "session.list";
2
3
  export interface SessionLifecycleActor {
3
4
  readonly id: string;
@@ -104,6 +105,9 @@ export interface SessionDeleteTarget {
104
105
  export interface SessionListTarget {
105
106
  readonly cwd?: string;
106
107
  readonly resolveSessionId?: string;
108
+ readonly scope?: ScopeRequestV1;
109
+ readonly limit?: number;
110
+ readonly cursor?: string;
107
111
  }
108
112
  interface SessionLifecycleMutationRequestBase<TOperation extends Exclude<SessionLifecycleOperation, "session.list">, TTarget> {
109
113
  readonly operation: TOperation;
@@ -141,7 +145,12 @@ export interface SessionLifecycleListEntry {
141
145
  readonly live?: boolean;
142
146
  readonly endpointGeneration?: number;
143
147
  readonly terminalUncertain?: boolean;
144
- readonly repo?: string;
148
+ readonly cwd?: string;
149
+ readonly locator?: {
150
+ readonly cwd: string;
151
+ readonly worktreeRoot: string | null;
152
+ readonly stateRoot: string;
153
+ };
145
154
  }
146
155
  export interface SessionLifecycleListResult {
147
156
  readonly indexSeq: number;
@@ -149,6 +158,7 @@ export interface SessionLifecycleListResult {
149
158
  readonly warnings: readonly string[];
150
159
  readonly savedSession?: SessionLifecycleSavedSession;
151
160
  }
161
+ export type SessionScopedListResult = SdkSearchResultV1;
152
162
  export interface SessionCreateResult {
153
163
  readonly ok: true;
154
164
  readonly operation: "session.create";
@@ -182,7 +192,7 @@ export interface SessionReconcileUncertainResult {
182
192
  export interface SessionListSuccessResult {
183
193
  readonly ok: true;
184
194
  readonly operation: "session.list";
185
- readonly result: SessionLifecycleListResult;
195
+ readonly result: SessionLifecycleListResult | SessionScopedListResult;
186
196
  }
187
197
  export interface SessionLifecycleError {
188
198
  readonly code: string;
@@ -229,6 +239,7 @@ export type SessionListFailure = {
229
239
  readonly operation: "session.list";
230
240
  readonly certainty: SessionLifecycleCertainty;
231
241
  readonly error: SessionLifecycleError;
242
+ readonly result?: SessionScopedListResult;
232
243
  };
233
244
  export type SessionCreateOutcome = SessionCreateResult | SessionCreateFailure;
234
245
  export type SessionForkOutcome = SessionForkResult | SessionForkFailure;
@@ -254,7 +265,8 @@ export declare function validateSessionLifecycleMutationRequest(request: unknown
254
265
  export declare class SessionLifecycleService {
255
266
  #private;
256
267
  constructor(client: SessionLifecycleClient);
257
- execute(request: SessionLifecycleMutationRequest): Promise<SessionCreateOutcome | SessionForkOutcome | SessionResumeOutcome | SessionCloseOutcome | SessionDeleteOutcome | SessionReconcileUncertainOutcome>;
268
+ scopedList(scope: ScopeRequestV1, limit?: number, cursor?: string): Promise<SessionListOutcome>;
269
+ execute(request: SessionLifecycleMutationRequest, idempotencyKeyOverride?: string): Promise<SessionCreateOutcome | SessionForkOutcome | SessionResumeOutcome | SessionCloseOutcome | SessionDeleteOutcome | SessionReconcileUncertainOutcome>;
258
270
  executeWithIdempotencyKey(request: SessionLifecycleMutationRequest, idempotencyKey: string): Promise<SessionCreateOutcome | SessionForkOutcome | SessionResumeOutcome | SessionCloseOutcome | SessionDeleteOutcome | SessionReconcileUncertainOutcome>;
259
271
  create(request: Omit<SessionCreateRequest, "operation">): Promise<SessionCreateOutcome>;
260
272
  fork(request: Omit<SessionForkRequest, "operation">): Promise<SessionForkOutcome>;
@@ -48,6 +48,8 @@ export type CreateLifecycleAgentSessionOptions = Omit<CreateAgentSessionOptions,
48
48
  * a prepared signal instead of readiness until it is explicitly activated.
49
49
  */
50
50
  readiness?: "immediate" | "deferred";
51
+ /** Broker-issued lifecycle request identity published with host registration. */
52
+ lifecycleRequestId?: string;
51
53
  };
52
54
  /** Internal lifecycle-only session construction with an owner-bound SDK startup result. */
53
55
  export declare function createLifecycleAgentSession(options?: CreateLifecycleAgentSessionOptions): Promise<CreateLifecycleAgentSessionResult>;
@@ -1,5 +1,6 @@
1
1
  import type { KindAwareReconciliation } from "./bus/kind-aware-reconciliation";
2
2
  import type { InvocationCorrelation, InvocationReconciliation } from "./host/session-runtime";
3
+ import type { TurnResultContent } from "./turn-result";
3
4
  type DeadlineReconciliation = InvocationReconciliation | KindAwareReconciliation;
4
5
  export type PromptDeadlineOutcome = {
5
6
  kind: "failed";
@@ -7,6 +8,15 @@ export type PromptDeadlineOutcome = {
7
8
  message: string;
8
9
  provenance: "deadline";
9
10
  };
11
+ export interface PromptTerminalTransitionEvidence {
12
+ content?: TurnResultContent;
13
+ hasActivity?: boolean;
14
+ outcome?: {
15
+ kind: "stopped";
16
+ reason: "cancelled";
17
+ provenance: "client_cancel";
18
+ };
19
+ }
10
20
  export declare class PromptDeadlineManager {
11
21
  #private;
12
22
  constructor(options: {
@@ -28,7 +38,7 @@ export declare class PromptDeadlineManager {
28
38
  noteTerminalTransition(correlation: InvocationCorrelation, pendingFailure?: {
29
39
  code: string;
30
40
  message: string;
31
- }): void;
41
+ }, evidence?: PromptTerminalTransitionEvidence): void;
32
42
  clear(correlation: InvocationCorrelation): void;
33
43
  clearAll(): void;
34
44
  /** For tests: current deadline or undefined if no lease. */
@@ -9,6 +9,8 @@ export type AdapterValidationError = {
9
9
  code: "invalid_reload_component" | "invalid_input";
10
10
  message: string;
11
11
  };
12
+ /** Rejects instruction-bearing controls before correlation or provider work. */
13
+ export declare function validateRequiredPromptText(operation: string, input: Input): AdapterValidationError | undefined;
12
14
  /** Validates controls that adapters must reject before forwarding them to a host. */
13
15
  export declare function validateAdapterControl(operation: string, input: Input): AdapterValidationError | undefined;
14
16
  export {};
@@ -1,6 +1,13 @@
1
1
  import { type SessionIndex } from "../broker/session-index";
2
2
  import { type SdkDispatchContext, type SdkDispatchHandler } from "../client/client";
3
3
  import { type ActivatedPreparedSession } from "../session-activation";
4
+ export interface SessionEndpointIdentity {
5
+ readonly mtimeMs: number;
6
+ readonly mtimeNs: bigint;
7
+ readonly ctimeNs: bigint;
8
+ readonly size: bigint;
9
+ readonly ino: bigint;
10
+ }
4
11
  /**
5
12
  * Exact identity of one attached SDK session endpoint. Providers persist it next to
6
13
  * their conversation state and re-prove it before every resume, so it must be derived
@@ -14,6 +21,8 @@ export declare function sessionAttachmentAuthorityId(input: {
14
21
  endpointMtimeMs: number | undefined;
15
22
  url: string;
16
23
  token: string;
24
+ /** Proven no-follow endpoint identity, when the caller has one. */
25
+ endpointIdentity?: SessionEndpointIdentity;
17
26
  }): string;
18
27
  /** The only capability a provider may retain for an attached SDK session. */
19
28
  export interface SessionAttachment {
@@ -155,6 +164,8 @@ export interface SessionRouterDeps {
155
164
  export type SessionRouterProviderDeps = Pick<SessionRouterDeps, "createClient" | "createIndex" | "createBrokerClient" | "setInterval" | "clearInterval" | "setTimeout" | "clearTimeout" | "onReconciled">;
156
165
  export interface SessionRouterOptions {
157
166
  agentDir: string;
167
+ /** Limits attachment to exact ids selected by a Broker-scoped operation. */
168
+ sessionIds?: readonly string[];
158
169
  deps?: SessionRouterDeps;
159
170
  /** Runtime-specific identity validation; Router supplies a conservative fallback. */
160
171
  correlateFrame?: SessionRouterFrameCorrelator;
@@ -7,6 +7,7 @@ import { ModelRegistry } from "../config/model-registry";
7
7
  import { type ScopedModelSelection } from "../config/model-resolver";
8
8
  import { type PromptTemplate } from "../config/prompt-templates";
9
9
  import { Settings, type SkillsSettings } from "../config/settings";
10
+ import type { MasterModeContext } from "../master-mode/context";
10
11
  import type { BashRestrictionProfile } from "../tools/bash-allowed-prefixes";
11
12
  import "../discovery";
12
13
  import type { CustomCommandsLoadResult } from "../extensibility/custom-commands";
@@ -176,6 +177,8 @@ export interface CreateAgentSessionOptions {
176
177
  * @internal CLI-only startup optimization; SDK callers retain synchronous loading by default.
177
178
  */
178
179
  deferMcpConfigStartup?: boolean;
180
+ /** Process-local master authority. Never persist or pass to lifecycle children. */
181
+ masterModeContext?: MasterModeContext;
179
182
  /**
180
183
  * Defer memory backend startup until the caller has applied startup model profiles.
181
184
  * @internal CLI-only ordering guard; SDK callers retain immediate startup by default.
@@ -384,4 +387,17 @@ export declare function createPluginHooksExtension(hooks: ConstrainedPluginHook[
384
387
  export declare function resolveIntentTracingEnabled(intentTracingSetting: boolean | undefined, options: {
385
388
  subSession: boolean;
386
389
  }): boolean;
390
+ /**
391
+ * Order candidates so each known provider's curated default model is tried
392
+ * before the rest of the catalog.
393
+ *
394
+ * Provider catalogs are not ranked by fitness — a withdrawn model whose ID
395
+ * carries an older date suffix sorts ahead of its current replacement — so
396
+ * picking the first credentialed entry can start an unconfigured install on a
397
+ * model the provider no longer serves. `DEFAULT_MODEL_PER_PROVIDER` is the
398
+ * curated table `findInitialModel` already sweeps for the same purpose;
399
+ * reusing it keeps both unconfigured paths on one source of truth. Candidates
400
+ * that are not a provider default keep their original relative order.
401
+ */
402
+ export declare function orderByProviderDefaultFirst(candidates: readonly Model[], providerOrder?: readonly string[]): Model[];
387
403
  export declare function createAgentSession(options?: CreateAgentSessionOptions): Promise<CreateAgentSessionResult>;
@@ -49,6 +49,7 @@ export declare class SdkStartupCapability {
49
49
  #private;
50
50
  readonly rollback?: SdkStartupRollbackTracker | undefined;
51
51
  readonly readiness: "immediate" | "deferred";
52
+ readonly lifecycleRequestId?: string | undefined;
52
53
  get cancelled(): boolean;
53
54
  cancel(): void;
54
55
  /**
@@ -57,7 +58,7 @@ export declare class SdkStartupCapability {
57
58
  * environment so bus wiring can never mistake an inherited process-global
58
59
  * flag for a broker-managed preparation.
59
60
  */
60
- constructor(rollback?: SdkStartupRollbackTracker | undefined, readiness?: "immediate" | "deferred");
61
+ constructor(rollback?: SdkStartupRollbackTracker | undefined, readiness?: "immediate" | "deferred", lifecycleRequestId?: string | undefined);
61
62
  normalizeFailure(phase: SdkStartupPhase, reason: SdkStartupReason, error?: unknown): SdkStartupFailure;
62
63
  get result(): SdkStartupResult | undefined;
63
64
  get promise(): Promise<SdkStartupResult>;
@@ -59,6 +59,7 @@ export interface AccountInventoryInput {
59
59
  provider: string;
60
60
  }>;
61
61
  getProviderBaseUrl?: (provider: string) => string | undefined;
62
+ getAuthStorageOwner?: () => object;
62
63
  };
63
64
  sessionId?: string;
64
65
  provider?: string;
@@ -109,6 +109,7 @@ import { type ConfiguredFallbackChain, type FallbackChainRuntimeState } from "./
109
109
  export { DefaultModelSelectionRecoveryError } from "./default-model-selection";
110
110
  import type { ClientBridge, ClientBridgePermissionOption, ClientBridgePermissionOutcome, ClientBridgePermissionToolCall } from "./client-bridge";
111
111
  import { type ContributionPrepOptions, type ContributionPrepResult } from "./contribution-prep";
112
+ import { type FoldAdapter, FoldCoordinator } from "./fold-coordinator";
112
113
  import type { MemoryGuardRestoreResult } from "./memory-guard-checkpoint-participant";
113
114
  import { type CustomMessage } from "./messages";
114
115
  import type { BranchSummaryEntry, CompactionEntry, NewSessionOptions, PreparedNewSession, RecoveryHydrationContext, RecoveryHydrationPromotionFence, SessionContext, SessionManagerCloseOutcome, SessionMemoryStats } from "./session-manager";
@@ -426,8 +427,8 @@ export interface PromptOptions {
426
427
  }) => void;
427
428
  /** Optional invocation-scoped cancellation fence used before an accepted skill starts execution. */
428
429
  preflightSignal?: AbortSignal;
429
- /** Internal SDK lifecycle owner token. */
430
- sdkRunToken?: string;
430
+ /** Internal host capability; ordinary package callers cannot construct the branded value. */
431
+ sdkRunCapability?: unknown;
431
432
  }
432
433
  /** Result from a handoff operation. */
433
434
  export interface HandoffResult {
@@ -553,6 +554,14 @@ export type BeforeAgentStartContributor = (event: {
553
554
  images?: ImageContent[];
554
555
  sessionId: string | undefined;
555
556
  }) => Promise<BeforeAgentStartInternalMessage | undefined>;
557
+ export type WorkerIntegrationOutcome = {
558
+ status: "completed";
559
+ } | {
560
+ status: "failed";
561
+ error: string;
562
+ } | {
563
+ status: "timed_out";
564
+ };
556
565
  export declare class WorkerIntegrationRequestScheduler {
557
566
  #private;
558
567
  readonly request: (signal: AbortSignal) => Promise<void>;
@@ -560,6 +569,7 @@ export declare class WorkerIntegrationRequestScheduler {
560
569
  constructor(request: (signal: AbortSignal) => Promise<void>, timeoutMs?: number);
561
570
  enqueue(): void;
562
571
  flush(): Promise<void>;
572
+ flushWithOutcome(): Promise<WorkerIntegrationOutcome>;
563
573
  }
564
574
  export type StreamingEditParsedToolCall = {
565
575
  toolCall: ToolCall;
@@ -795,6 +805,11 @@ export declare class AgentSession {
795
805
  * proceeds.
796
806
  */
797
807
  awaitSessionSettlement(): Promise<void>;
808
+ queueCoordinatorRuntimeStatePersistForTests(event: AgentSessionEvent, gate: Promise<void>): Promise<void>;
809
+ parkAgentEndForCoordinatorPersistForTests(event: Extract<AgentSessionEvent, {
810
+ type: "agent_end";
811
+ }>): void;
812
+ flushParkedAgentEndForCoordinatorPersistForTests(): void;
798
813
  drainAsyncJobDeliveriesForAcp(options?: {
799
814
  timeoutMs?: number;
800
815
  }): Promise<boolean>;
@@ -837,7 +852,9 @@ export declare class AgentSession {
837
852
  * handler, so Ctrl+B-style folding fails closed instead of aborting or
838
853
  * shell-suspending arbitrary work.
839
854
  */
840
- registerForegroundBashBackgroundRequestHandler(handler: () => void): () => void;
855
+ registerForegroundFoldParticipant(adapter: FoldAdapter): () => void;
856
+ /** The session-owned fold coordinator, for delivery-side receipt lookup. */
857
+ get foldCoordinator(): FoldCoordinator;
841
858
  /**
842
859
  * Returns whether a managed foreground bash call is currently backgroundable.
843
860
  * UI key handlers use this to avoid consuming normal editor shortcuts when
@@ -854,7 +871,7 @@ export declare class AgentSession {
854
871
  * Ask the active managed foreground bash call to return as a background job.
855
872
  * Returns false when no supported foreground tool is currently backgroundable.
856
873
  */
857
- requestForegroundBashBackground(): boolean;
874
+ requestForegroundBashBackground(): Promise<boolean>;
858
875
  /**
859
876
  * Get all configured tool names (built-in via --tools or default, plus custom tools).
860
877
  */
@@ -947,7 +964,7 @@ export declare class AgentSession {
947
964
  /** Live SDK configuration values exposed through the session query surface. */
948
965
  getSdkConfigItems(): Record<string, string>;
949
966
  setPlanModeState(state: PlanModeState | undefined): void;
950
- invokeSkill(name: string, args?: string, options?: Pick<PromptOptions, "onPreflightAccepted" | "onPreflightAcceptCommit" | "onSkillPrepared" | "preflightSignal" | "sdkRunToken">): Promise<{
967
+ invokeSkill(name: string, args?: string, options?: Pick<PromptOptions, "onPreflightAccepted" | "onPreflightAcceptCommit" | "onSkillPrepared" | "preflightSignal" | "sdkRunCapability">): Promise<{
951
968
  name: string;
952
969
  path: string;
953
970
  args?: string;
@@ -1002,7 +1019,7 @@ export declare class AgentSession {
1002
1019
  * @throws Error if no model selected or no API key available (when not streaming)
1003
1020
  */
1004
1021
  prompt(text: string, options?: PromptOptions): Promise<void>;
1005
- promptCustomMessage<T = unknown>(message: Pick<CustomMessage<T>, "customType" | "content" | "display" | "details" | "attribution">, options?: Pick<PromptOptions, "streamingBehavior" | "toolChoice" | "followUpQueuePolicy" | "onPreflightAccepted" | "onPreflightAcceptCommit" | "preflightSignal" | "sdkRunToken">): Promise<void>;
1022
+ promptCustomMessage<T = unknown>(message: Pick<CustomMessage<T>, "customType" | "content" | "display" | "details" | "attribution">, options?: Pick<PromptOptions, "streamingBehavior" | "toolChoice" | "followUpQueuePolicy" | "onPreflightAccepted" | "onPreflightAcceptCommit" | "preflightSignal" | "sdkRunCapability">): Promise<void>;
1006
1023
  /**
1007
1024
  * Queue a steering message to interrupt the agent mid-run.
1008
1025
  */
@@ -1062,7 +1079,7 @@ export declare class AgentSession {
1062
1079
  startsOwnRun: boolean;
1063
1080
  }) => void;
1064
1081
  preflightSignal?: AbortSignal;
1065
- sdkRunToken?: string;
1082
+ sdkRunCapability?: unknown;
1066
1083
  }): Promise<void>;
1067
1084
  /**
1068
1085
  * Clear queued messages and return them.
@@ -0,0 +1 @@
1
+ export declare const CREDENTIAL_STORE_UNREADABLE_MESSAGE = "Credential store is unreadable. Back up the database, then have an operator run PRAGMA integrity_check or REINDEX; no automatic repair was attempted.";
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Session-owned fold/wake coordinator.
3
+ *
4
+ * Folding a running foreground wait is a lifecycle handoff across three
5
+ * independently scheduled domains — the tool observer, the job owner, and
6
+ * agent-turn admission — so it needs ONE linearization point. That is this
7
+ * coordinator: a synchronous prologue claims the fold and arms the steering
8
+ * fence with no `await` in between, and only then does an async tail capture and
9
+ * persist the receipt.
10
+ *
11
+ * Two invariants are load-bearing and easy to get wrong:
12
+ *
13
+ * 1. **Identity is the `AsyncJob` instance, acquired once.** Job ids and
14
+ * generations are manager-local, so two managers can mint the same
15
+ * `bg_1`/`job:1` pair. Slots are therefore keyed by the object itself,
16
+ * obtained exactly once through the registration-bound
17
+ * {@link FoldAdapter.getJob} and retained for the rest of the transaction.
18
+ * Nothing in the fold path may consult an ambient, singleton, or
19
+ * endpoint-resolved manager.
20
+ * 2. **A delivery callback can run more than once.** The async job manager
21
+ * re-pushes the SAME delivery object on retry, so the receipt is attached to
22
+ * a carrier keyed by that object BEFORE the slot is released. A retried
23
+ * delivery therefore still carries its receipt and can never silently
24
+ * degrade into an ordinary receipt-less completion.
25
+ */
26
+ import type { AsyncJob } from "../async/job-manager";
27
+ /**
28
+ * Idle-flush merge window.
29
+ *
30
+ * Completions that land within this window coalesce into ONE wake turn. The
31
+ * previous 1ms debounce meant staggered completions each bought their own full
32
+ * LLM turn. Deliberately a fixed internal constant, not a setting: the contract
33
+ * is one merge window, and a per-user knob would let wake behavior differ
34
+ * between sessions.
35
+ */
36
+ export declare const FOLD_WAKE_MERGE_WINDOW_MS = 800;
37
+ /** The wait kinds that can be folded. `task`/`subagent` awaits are a non-goal. */
38
+ export type FoldWaitKind = "bash-managed" | "client-terminal" | "bash-pty";
39
+ /** Outcome of settling the foreground caller. Exactly one party may settle it. */
40
+ export type ForegroundSettleOutcome = "resolved" | "already-settled";
41
+ /**
42
+ * How a folded job's output is retrieved later. Deliberately a structured
43
+ * handle over already-implemented paths rather than an invented URI scheme:
44
+ * there is no `job://` resolver, and inventing one would make the reference
45
+ * unresolvable in exactly the degraded case it exists for.
46
+ */
47
+ export interface JobOutputRetrieval {
48
+ jobId: string;
49
+ generation: string;
50
+ /** Human/model-facing retrieval instruction naming a real mechanism. */
51
+ instruction: string;
52
+ }
53
+ /** Durable record captured at fold time and replayed into the wake turn. */
54
+ export interface FoldReceipt {
55
+ jobId: string;
56
+ jobGeneration: string;
57
+ kind: FoldWaitKind;
58
+ label: string;
59
+ outputRef: JobOutputRetrieval;
60
+ /** What the interrupted turn still intended to do, so the wake can finish it. */
61
+ remainingIntent: string | undefined;
62
+ foldedAt: number;
63
+ /** Only command kinds can change directory; task-style waits never do. */
64
+ cwdSensitive: boolean;
65
+ }
66
+ /** A terminal completion observed for a folded job. */
67
+ export interface ForegroundTerminalPayload {
68
+ jobId: string;
69
+ generation: string;
70
+ text: string;
71
+ }
72
+ /**
73
+ * Per-wait fold capability. `getJob` is bound at registration over the manager
74
+ * that registered THIS job, which is what makes cross-manager identity safe.
75
+ */
76
+ export interface FoldAdapter {
77
+ readonly kind: FoldWaitKind;
78
+ readonly jobId: string;
79
+ readonly jobGeneration: string;
80
+ readonly label: string;
81
+ readonly cwdSensitive: boolean;
82
+ /** Signal for the foreground wait; aborting capture must roll back the fold. */
83
+ readonly signal?: AbortSignal;
84
+ /** True only when the adapter was created by a model-owned Agent turn. */
85
+ readonly originatingTurn?: boolean;
86
+ readonly outputRef: JobOutputRetrieval;
87
+ /** Registration-bound resolver: the job for this adapter, or undefined once evicted or reused. */
88
+ readonly getJob: () => AsyncJob | undefined;
89
+ /** Settle the foreground caller with the fold result. Idempotent. */
90
+ readonly detachObserver: (receipt: FoldReceipt) => ForegroundSettleOutcome;
91
+ /** Hand a parked completion back to a still-attached observer. Idempotent. */
92
+ readonly resolveForegroundObserver: (payload: ForegroundTerminalPayload) => ForegroundSettleOutcome;
93
+ }
94
+ export type FoldRequestResult = {
95
+ status: "folded";
96
+ receipt: FoldReceipt;
97
+ } | {
98
+ status: "unavailable";
99
+ reason: string;
100
+ } | {
101
+ status: "already-terminal";
102
+ reason: string;
103
+ } | {
104
+ status: "capture-failed";
105
+ reason: string;
106
+ };
107
+ /** What a delivery should carry, decided by the durable slot state (T2). */
108
+ export type FoldDeliveryDisposition = {
109
+ kind: "ordinary";
110
+ } | {
111
+ kind: "parked";
112
+ } | {
113
+ kind: "receipt";
114
+ receipt: FoldReceipt;
115
+ text: string;
116
+ };
117
+ export interface FoldCoordinatorDeps {
118
+ /**
119
+ * Fence old-turn steering admission and return the release handle. Armed
120
+ * synchronously inside the prologue because the agent loop polls steering
121
+ * upstream of its pause checkpoint; fencing there keeps queued steering
122
+ * intact instead of draining it.
123
+ */
124
+ armSteeringFence: () => () => void;
125
+ /** Whether this fold belongs to a currently running Agent turn. */
126
+ hasActiveTurn?: () => boolean;
127
+ /** Arm the cooperative stop so the turn ends after the fold result, never via abort. */
128
+ requestStop: () => void;
129
+ /** Capture what the interrupted turn still intended to accomplish. */
130
+ captureRemainingIntent: () => Promise<string | undefined> | string | undefined;
131
+ /**
132
+ * Push a parked completion into the wake path. The delivery seam parks a
133
+ * completion that arrives before the receipt exists; when the fold later
134
+ * replays it (A6), THIS is what makes the wake happen rather than relying on
135
+ * an unrelated idle rearm to rescue it.
136
+ */
137
+ deliverParked: (job: AsyncJob, disposition: {
138
+ kind: "receipt";
139
+ receipt: FoldReceipt;
140
+ text: string;
141
+ }) => void;
142
+ }
143
+ /** Why a slot is being retired, which decides whether retiring is safe. */
144
+ export type FoldRetireReason = "cancel" | "evict";
145
+ /**
146
+ * Render a fold receipt for the wake turn.
147
+ *
148
+ * Carries the job id, a real retrieval handle, and the captured remaining
149
+ * intent, so the wake turn can finish the ORIGINAL task instead of only
150
+ * reporting that a command ended. The cwd caveat is included only for wait
151
+ * kinds that can actually change directory.
152
+ */
153
+ export declare function describeFoldReceipt(receipt: FoldReceipt): string;
154
+ export declare class FoldCoordinator {
155
+ #private;
156
+ constructor(deps: FoldCoordinatorDeps);
157
+ /** Register a foldable wait. The most recently registered wait is the default target. */
158
+ registerParticipant(adapter: FoldAdapter): () => void;
159
+ /** Whether any wait is currently foldable, for the key-availability gate. */
160
+ hasFoldableParticipant(): boolean;
161
+ /** Deterministic target: newest registration wins, so the chord folds what the user is watching. */
162
+ resolveTarget(): FoldAdapter | undefined;
163
+ /**
164
+ * T1. Synchronous prologue then async durability tail.
165
+ *
166
+ * Nothing awaits before the slot is reserved and the fence is armed, so a
167
+ * completion or a steering submission that races the capture cannot slip
168
+ * past into the old turn.
169
+ */
170
+ requestFold(explicit?: FoldAdapter): Promise<FoldRequestResult>;
171
+ /**
172
+ * T2. Decide what a delivery carries, branching on the DURABLE slot state
173
+ * rather than on transient hand-off state.
174
+ *
175
+ * `present` attaches the receipt to the retry-stable carrier BEFORE clearing
176
+ * the slot, so a retried invocation still finds it.
177
+ */
178
+ onDelivery(job: AsyncJob, text: string): FoldDeliveryDisposition;
179
+ /**
180
+ * Retirement. T-R2: never drop a slot that holds an undelivered payload or
181
+ * that a still-possible delivery could consume.
182
+ *
183
+ * - `cancel` retires freely, because a cancelled job enqueues no delivery at
184
+ * all, so no later consumer can arrive.
185
+ * - `evict` only retires when the job can no longer deliver. An evicted
186
+ * record still delivers with its retained job object, so a completed or
187
+ * failed job keeps its slot.
188
+ */
189
+ retire(job: AsyncJob, reason: FoldRetireReason): boolean;
190
+ /**
191
+ * Claim the single completion notice for a job.
192
+ *
193
+ * Returns true exactly once per job. A delivery can be retried with the same
194
+ * object, so an unguarded notice would repeat for one completion.
195
+ */
196
+ claimCompletionNotice(job: AsyncJob): boolean;
197
+ /** Claim the receipt-bearing queue entry once across manager delivery retries. */
198
+ claimCompletionDelivery(job: AsyncJob): boolean;
199
+ /** Test/diagnostic view of the durable slot state for a job. */
200
+ slotStateFor(job: AsyncJob): "none" | "reserved-empty" | "reserved-parked" | "present" | "carried";
201
+ }
@@ -0,0 +1,7 @@
1
+ declare const sdkRunTokenBrand: unique symbol;
2
+ export interface SdkRunCapability {
3
+ readonly [sdkRunTokenBrand]: string;
4
+ }
5
+ export declare function createSdkRunCapability(token: string): SdkRunCapability;
6
+ export declare function readSdkRunCapability(value: unknown): string | undefined;
7
+ export {};
@@ -0,0 +1,2 @@
1
+ export type { SdkRunCapability } from "./sdk-run-capability-internal";
2
+ export { readSdkRunCapability } from "./sdk-run-capability-internal";