@gajae-code/coding-agent 0.15.6 → 0.16.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 (270) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/dist/types/async/job-manager.d.ts +32 -1
  3. package/dist/types/browser-backend.d.ts +12 -0
  4. package/dist/types/cli/args.d.ts +2 -0
  5. package/dist/types/cli/root-flags.d.ts +14 -0
  6. package/dist/types/cli/update-cli.d.ts +14 -0
  7. package/dist/types/cli.d.ts +7 -0
  8. package/dist/types/commands/launch.d.ts +10 -0
  9. package/dist/types/commands/sdk.d.ts +2 -0
  10. package/dist/types/config/autorouting-tier-map.d.ts +24 -0
  11. package/dist/types/config/billing-path.d.ts +25 -0
  12. package/dist/types/config/config-schema-version.d.ts +13 -1
  13. package/dist/types/config/file-lock.d.ts +5 -0
  14. package/dist/types/config/model-registry.d.ts +22 -0
  15. package/dist/types/config/settings-schema.d.ts +27 -8
  16. package/dist/types/config/settings.d.ts +2 -0
  17. package/dist/types/coordinator-mcp/projection-scan.d.ts +8 -0
  18. package/dist/types/crash/record-loader.d.ts +15 -0
  19. package/dist/types/extensibility/extensions/types.d.ts +8 -3
  20. package/dist/types/gjc-runtime/launch-worktree-reservation.d.ts +21 -0
  21. package/dist/types/gjc-runtime/launch-worktree.d.ts +25 -1
  22. package/dist/types/gjc-runtime/managed-owner-supervisor.d.ts +2 -0
  23. package/dist/types/gjc-runtime/session-state-lock.d.ts +22 -0
  24. package/dist/types/gjc-runtime/session-state-sidecar.d.ts +66 -1
  25. package/dist/types/gjc-runtime/tmux-owner-isolation.d.ts +1 -0
  26. package/dist/types/gjc-runtime/tmux-sessions.d.ts +27 -0
  27. package/dist/types/main.d.ts +1 -0
  28. package/dist/types/master-mode/context.d.ts +21 -0
  29. package/dist/types/master-mode/first-request.d.ts +34 -0
  30. package/dist/types/master-mode/snapshot.d.ts +32 -0
  31. package/dist/types/modes/acp/acp-agent.d.ts +21 -21
  32. package/dist/types/modes/components/frictionless-onboarding-selector.d.ts +10 -0
  33. package/dist/types/modes/components/model-selector.d.ts +4 -0
  34. package/dist/types/modes/components/oauth-selector.d.ts +1 -0
  35. package/dist/types/modes/components/session-selector.d.ts +1 -1
  36. package/dist/types/modes/components/sessions-dashboard.d.ts +2 -1
  37. package/dist/types/modes/components/status-line/model-name.d.ts +18 -0
  38. package/dist/types/modes/components/status-line/priority-row.d.ts +34 -0
  39. package/dist/types/modes/components/status-line/segments.d.ts +10 -0
  40. package/dist/types/modes/interactive-mode.d.ts +16 -2
  41. package/dist/types/modes/print-mode.d.ts +17 -0
  42. package/dist/types/modes/theme/theme.d.ts +2 -1
  43. package/dist/types/modes/types.d.ts +2 -0
  44. package/dist/types/modes/ui-language.d.ts +7 -1
  45. package/dist/types/sdk/broker/broker.d.ts +79 -2
  46. package/dist/types/sdk/broker/endpoint-authority.d.ts +24 -0
  47. package/dist/types/sdk/broker/ensure.d.ts +3 -0
  48. package/dist/types/sdk/broker/index.d.ts +3 -0
  49. package/dist/types/sdk/broker/lifecycle-ledger.d.ts +6 -0
  50. package/dist/types/sdk/broker/lifecycle.d.ts +40 -0
  51. package/dist/types/sdk/broker/master-capability.d.ts +10 -0
  52. package/dist/types/sdk/broker/session-index.d.ts +40 -11
  53. package/dist/types/sdk/broker/session-scope.d.ts +72 -0
  54. package/dist/types/sdk/broker/spawn-authority.d.ts +201 -0
  55. package/dist/types/sdk/broker/spawn-substrate.d.ts +30 -0
  56. package/dist/types/sdk/broker/startup-budget.d.ts +52 -0
  57. package/dist/types/sdk/broker/state-version.d.ts +21 -1
  58. package/dist/types/sdk/broker/worktree-occupancy.d.ts +28 -0
  59. package/dist/types/sdk/bus/chat-daemon-control.d.ts +3 -0
  60. package/dist/types/sdk/bus/discord-daemon.d.ts +1 -1
  61. package/dist/types/sdk/bus/index.d.ts +9 -1
  62. package/dist/types/sdk/bus/kind-aware-reconciliation.d.ts +1 -1
  63. package/dist/types/sdk/bus/prompt-reconciliation.d.ts +1 -1
  64. package/dist/types/sdk/bus/slack-conversation.d.ts +1 -1
  65. package/dist/types/sdk/bus/slack-daemon.d.ts +1 -1
  66. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +1 -1
  67. package/dist/types/sdk/cli/index.d.ts +1 -0
  68. package/dist/types/sdk/cli/master-cli.d.ts +63 -0
  69. package/dist/types/sdk/cli/rows.d.ts +12 -5
  70. package/dist/types/sdk/cli/session-cli.d.ts +20 -3
  71. package/dist/types/sdk/client/client.d.ts +3 -2
  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/events.d.ts +1 -0
  77. package/dist/types/sdk/host/host.d.ts +10 -0
  78. package/dist/types/sdk/host/query/cursor.d.ts +4 -2
  79. package/dist/types/sdk/host/query/handlers.d.ts +1 -0
  80. package/dist/types/sdk/host/query/revision-store.d.ts +1 -0
  81. package/dist/types/sdk/host/session-runtime.d.ts +70 -17
  82. package/dist/types/sdk/lifecycle/broker-client.d.ts +6 -0
  83. package/dist/types/sdk/lifecycle/service.d.ts +15 -3
  84. package/dist/types/sdk/lifecycle-session.d.ts +3 -1
  85. package/dist/types/sdk/prompt-deadline-manager.d.ts +2 -5
  86. package/dist/types/sdk/receipt-state.d.ts +2 -0
  87. package/dist/types/sdk/router/session-router.d.ts +6 -0
  88. package/dist/types/sdk/session.d.ts +16 -0
  89. package/dist/types/sdk/startup-capability.d.ts +2 -1
  90. package/dist/types/sdk/turn-result.d.ts +6 -0
  91. package/dist/types/session/agent-session.d.ts +52 -7
  92. package/dist/types/session/credential-store-errors.d.ts +1 -0
  93. package/dist/types/session/fold-coordinator.d.ts +29 -2
  94. package/dist/types/session/session-manager.d.ts +79 -2
  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/tools/ask.d.ts +1 -0
  98. package/dist/types/tools/bash.d.ts +16 -0
  99. package/dist/types/tools/browser/launch.d.ts +10 -0
  100. package/dist/types/tools/browser/registry.d.ts +8 -0
  101. package/dist/types/tools/gh.d.ts +8 -0
  102. package/dist/types/tools/index.d.ts +10 -10
  103. package/dist/types/tools/job.d.ts +3 -1
  104. package/dist/types/utils/external-editor.d.ts +7 -0
  105. package/examples/extensions/README.md +1 -1
  106. package/examples/extensions/pirate.ts +7 -4
  107. package/package.json +7 -7
  108. package/scripts/generate-sdk-operation-inventory.ts +13 -1
  109. package/scripts/verify-gjc-sdk-canonicalization.ts +35 -1
  110. package/src/async/job-manager.ts +107 -9
  111. package/src/browser-backend.ts +29 -0
  112. package/src/cli/accounts-cli.ts +9 -5
  113. package/src/cli/args.ts +17 -0
  114. package/src/cli/fast-help.ts +1 -0
  115. package/src/cli/plugin-cli.ts +29 -0
  116. package/src/cli/root-flags.ts +5 -0
  117. package/src/cli/update-cli.ts +140 -23
  118. package/src/commands/launch.ts +86 -18
  119. package/src/commands/sdk.ts +135 -28
  120. package/src/config/autorouting-tier-map.ts +12 -0
  121. package/src/config/billing-path.ts +42 -0
  122. package/src/config/config-schema-version.ts +18 -1
  123. package/src/config/file-lock.ts +158 -83
  124. package/src/config/model-preset-registry.ts +178 -23
  125. package/src/config/model-profiles.ts +5 -5
  126. package/src/config/model-registry.ts +291 -42
  127. package/src/config/model-resolver.ts +5 -0
  128. package/src/config/settings-schema.ts +27 -8
  129. package/src/config/settings.ts +51 -15
  130. package/src/coordinator-mcp/projection-scan.ts +27 -6
  131. package/src/coordinator-mcp/question-state.ts +9 -11
  132. package/src/coordinator-mcp/server.ts +115 -21
  133. package/src/crash/index-store.ts +2 -0
  134. package/src/crash/record-loader.ts +10 -0
  135. package/src/defaults/gjc/skills/deep-interview/SKILL.md +1 -1
  136. package/src/extensibility/extensions/runner.ts +27 -0
  137. package/src/extensibility/extensions/types.ts +8 -3
  138. package/src/extensibility/gjc-plugins/installer.ts +51 -11
  139. package/src/extensibility/runtime-skill-discovery.ts +110 -3
  140. package/src/extensibility/skills.ts +22 -12
  141. package/src/gjc-runtime/launch-worktree-reservation.ts +242 -0
  142. package/src/gjc-runtime/launch-worktree.ts +285 -4
  143. package/src/gjc-runtime/managed-owner-supervisor.ts +63 -51
  144. package/src/gjc-runtime/session-state-lock.ts +213 -14
  145. package/src/gjc-runtime/session-state-sidecar.ts +938 -39
  146. package/src/gjc-runtime/tmux-owner-isolation-cli.ts +4 -7
  147. package/src/gjc-runtime/tmux-owner-isolation.ts +18 -3
  148. package/src/gjc-runtime/tmux-sessions.ts +252 -13
  149. package/src/hooks/skill-state.ts +6 -0
  150. package/src/internal-urls/docs-index.generated.ts +15 -15
  151. package/src/internal-urls/issue-pr-protocol.ts +4 -2
  152. package/src/main.ts +61 -3
  153. package/src/master-mode/context.ts +50 -0
  154. package/src/master-mode/first-request.ts +65 -0
  155. package/src/master-mode/snapshot.ts +205 -0
  156. package/src/modes/acp/acp-agent.ts +610 -161
  157. package/src/modes/components/footer.ts +4 -2
  158. package/src/modes/components/frictionless-onboarding-selector.ts +48 -2
  159. package/src/modes/components/model-selector.ts +76 -8
  160. package/src/modes/components/oauth-selector.ts +6 -1
  161. package/src/modes/components/session-selector.ts +23 -15
  162. package/src/modes/components/sessions-dashboard.ts +8 -5
  163. package/src/modes/components/settings-selector.ts +1 -0
  164. package/src/modes/components/status-line/model-name.ts +53 -0
  165. package/src/modes/components/status-line/priority-row.ts +107 -0
  166. package/src/modes/components/status-line/segments.ts +23 -9
  167. package/src/modes/components/tool-status-header.ts +151 -15
  168. package/src/modes/controllers/command-controller.ts +1 -1
  169. package/src/modes/controllers/event-controller.ts +30 -4
  170. package/src/modes/controllers/extension-ui-controller.ts +13 -13
  171. package/src/modes/controllers/input-controller.ts +30 -2
  172. package/src/modes/controllers/selector-controller.ts +200 -98
  173. package/src/modes/interactive-mode.ts +36 -12
  174. package/src/modes/print-mode.ts +64 -0
  175. package/src/modes/prompt-action-autocomplete.ts +30 -4
  176. package/src/modes/runtime-init.ts +12 -9
  177. package/src/modes/theme/theme.ts +5 -0
  178. package/src/modes/types.ts +2 -0
  179. package/src/modes/ui-language.ts +49 -2
  180. package/src/modes/utils/ui-helpers.ts +22 -3
  181. package/src/prompts/agent-fragments/browser-aside.md +22 -0
  182. package/src/prompts/system/master-mode.md +28 -0
  183. package/src/prompts/tools/ask.md +1 -1
  184. package/src/prompts/tools/bash.md +1 -0
  185. package/src/prompts/tools/job.md +1 -1
  186. package/src/sdk/acp/adapter.ts +5 -0
  187. package/src/sdk/broker/broker.ts +1646 -27
  188. package/src/sdk/broker/endpoint-authority.ts +86 -0
  189. package/src/sdk/broker/ensure.ts +81 -3
  190. package/src/sdk/broker/index.ts +3 -0
  191. package/src/sdk/broker/lifecycle-ledger.ts +6 -0
  192. package/src/sdk/broker/lifecycle.ts +440 -75
  193. package/src/sdk/broker/master-capability.ts +232 -0
  194. package/src/sdk/broker/session-index.ts +121 -17
  195. package/src/sdk/broker/session-scope.ts +272 -0
  196. package/src/sdk/broker/spawn-authority.ts +1031 -0
  197. package/src/sdk/broker/spawn-substrate.ts +591 -0
  198. package/src/sdk/broker/startup-budget.ts +144 -2
  199. package/src/sdk/broker/state-version.ts +43 -14
  200. package/src/sdk/broker/transport.ts +1 -0
  201. package/src/sdk/broker/worktree-occupancy.ts +90 -0
  202. package/src/sdk/bus/chat-daemon-control.ts +5 -2
  203. package/src/sdk/bus/chat-daemon-runtime.ts +136 -18
  204. package/src/sdk/bus/discord-daemon.ts +50 -10
  205. package/src/sdk/bus/index.ts +84 -7
  206. package/src/sdk/bus/kind-aware-reconciliation.ts +296 -48
  207. package/src/sdk/bus/lifecycle-commands.ts +4 -0
  208. package/src/sdk/bus/notification-service.ts +22 -5
  209. package/src/sdk/bus/prompt-reconciliation.ts +7 -2
  210. package/src/sdk/bus/reconciliation-store.ts +55 -31
  211. package/src/sdk/bus/slack-conversation.ts +1 -1
  212. package/src/sdk/bus/slack-daemon.ts +72 -38
  213. package/src/sdk/bus/telegram-daemon-contract.ts +1 -1
  214. package/src/sdk/cli/index.ts +1 -0
  215. package/src/sdk/cli/master-cli.ts +259 -0
  216. package/src/sdk/cli/rows.ts +41 -15
  217. package/src/sdk/cli/session-cli.ts +297 -26
  218. package/src/sdk/client/client.ts +14 -8
  219. package/src/sdk/host/control/dispatch.ts +101 -40
  220. package/src/sdk/host/control/index.ts +2 -0
  221. package/src/sdk/host/control/operations.ts +2 -0
  222. package/src/sdk/host/control/runtime-gate.ts +203 -11
  223. package/src/sdk/host/events.ts +1 -0
  224. package/src/sdk/host/host.ts +29 -2
  225. package/src/sdk/host/query/cursor.ts +52 -7
  226. package/src/sdk/host/query/handlers.ts +33 -12
  227. package/src/sdk/host/query/revision-store.ts +12 -0
  228. package/src/sdk/host/session-runtime.test.ts +673 -14
  229. package/src/sdk/host/session-runtime.ts +674 -103
  230. package/src/sdk/host/surface-policy.ts +3 -3
  231. package/src/sdk/lifecycle/broker-client.ts +28 -0
  232. package/src/sdk/lifecycle/service.ts +279 -20
  233. package/src/sdk/lifecycle-session.ts +17 -4
  234. package/src/sdk/prompt-deadline-manager.ts +2 -1
  235. package/src/sdk/protocol/operation-inventory.generated.json +105 -3
  236. package/src/sdk/protocol/operation-registry.ts +14 -4
  237. package/src/sdk/receipt-state.ts +10 -0
  238. package/src/sdk/router/session-router.ts +219 -118
  239. package/src/sdk/session.ts +416 -195
  240. package/src/sdk/startup-capability.ts +1 -0
  241. package/src/sdk/turn-result.ts +22 -0
  242. package/src/session/agent-session.ts +1628 -318
  243. package/src/session/blob-store.ts +15 -5
  244. package/src/session/credential-store-errors.ts +2 -0
  245. package/src/session/fold-coordinator.ts +40 -3
  246. package/src/session/internal/managed-session-storage.ts +153 -78
  247. package/src/session/session-manager.ts +850 -97
  248. package/src/session/yield-queue.ts +24 -10
  249. package/src/setup/frictionless-onboarding.ts +2 -0
  250. package/src/slash-commands/builtin-registry.ts +41 -0
  251. package/src/task/executor.ts +9 -4
  252. package/src/telemetry/events.ts +1138 -12
  253. package/src/tools/ask-contract.test.ts +64 -0
  254. package/src/tools/ask-contract.ts +36 -1
  255. package/src/tools/ask.ts +10 -8
  256. package/src/tools/bash-interactive.ts +11 -2
  257. package/src/tools/bash.ts +412 -75
  258. package/src/tools/browser/launch.ts +37 -0
  259. package/src/tools/browser/registry.ts +99 -9
  260. package/src/tools/cron.ts +6 -4
  261. package/src/tools/descriptors.test.ts +15 -0
  262. package/src/tools/descriptors.ts +5 -1
  263. package/src/tools/gh.ts +104 -48
  264. package/src/tools/github-cache.ts +2 -2
  265. package/src/tools/index.ts +10 -6
  266. package/src/tools/job.ts +4 -1
  267. package/src/tools/monitor.ts +12 -9
  268. package/src/tools/resolve.ts +30 -10
  269. package/src/tools/tool-catalog.generated.ts +2 -2
  270. package/src/utils/external-editor.ts +72 -1
@@ -0,0 +1,201 @@
1
+ export type SpawnClaimV2 = {
2
+ version: 2;
3
+ claimId: string;
4
+ lifecycleIdentity: string;
5
+ /** Opaque binding of the raw selector request, retained for catalog-independent replay. */
6
+ requestBindingMac?: string;
7
+ bindingMac: string;
8
+ state: "prepared" | "substrate_starting" | "authority_active" | "seed_prepared" | "dispatching" | "accepted" | "pre_send_rejected" | "uncertain" | "closed";
9
+ failure?: SpawnSubstrateFailure;
10
+ preSendLease?: {
11
+ epoch: string;
12
+ status: "owned" | "consumed";
13
+ };
14
+ childId?: string;
15
+ seed?: SeedDeliveryV2;
16
+ authorityRef?: string;
17
+ createdAt: number;
18
+ updatedAt: number;
19
+ };
20
+ export type SpawnSubstrateFailure = {
21
+ substrateKind: "tmux" | "psmux" | "headless";
22
+ code: string;
23
+ message: string;
24
+ };
25
+ export type SeedDeliveryV2 = {
26
+ version: 2;
27
+ phase: "prepared" | "dispatching" | "accepted" | "pre_send_rejected" | "uncertain";
28
+ clientRef: string;
29
+ commandId?: string;
30
+ turnId?: string;
31
+ acceptedAt?: number;
32
+ lastQ26Status?: "accepted" | "in_flight" | "terminal_ok" | "failed" | "unknown";
33
+ observedAt?: number;
34
+ };
35
+ /** Live-only capability check. Implementations must not retain either argument. */
36
+ export interface MasterCapabilityVerifier {
37
+ verifyMasterCapability(ownerSessionId: string, rawCapability: string, attestationEpoch: string): Promise<{
38
+ allowed: boolean;
39
+ }>;
40
+ }
41
+ /** Structured, shell-free child launch contract owned by the Broker. */
42
+ export interface SpawnSubstrateLaunchSpec {
43
+ childSessionId: string;
44
+ cwd: string;
45
+ argv: readonly string[];
46
+ /** Broker-inherited values are filtered to the portable launch subset. */
47
+ inheritedEnv?: Readonly<Record<string, string>>;
48
+ /** Child-specific values are part of this spec and must be shell-safe. */
49
+ env?: Readonly<Record<string, string>>;
50
+ }
51
+ /** Durable facts required to re-prove one spawned substrate without task material. */
52
+ export type SpawnSubstrateProof = {
53
+ substrateKind: "tmux" | "psmux" | "headless";
54
+ providerIdentity: string;
55
+ nativeSessionId?: string;
56
+ pid?: number;
57
+ processIncarnation?: string;
58
+ ownerGeneration?: number;
59
+ stateFileProof?: Readonly<Record<string, string | number>>;
60
+ };
61
+ export interface SpawnSubstrateProvider {
62
+ launch(spec: SpawnSubstrateLaunchSpec): Promise<{
63
+ ok: true;
64
+ proof: SpawnSubstrateProof;
65
+ } | {
66
+ ok: false;
67
+ code: "substrate_unavailable" | "substrate_proof_failed";
68
+ message: string;
69
+ }>;
70
+ verify(proof: SpawnSubstrateProof): Promise<"verified" | "mismatch" | "gone">;
71
+ close(proof: SpawnSubstrateProof): Promise<{
72
+ ok: boolean;
73
+ code?: string;
74
+ }>;
75
+ }
76
+ export type SpawnAuthorityCloseState = "active" | "close_requested" | "closed" | "uncertain";
77
+ /**
78
+ * Exact, durable ownership evidence for a child substrate. It is deliberately
79
+ * structural: request text, capability material, and their derivatives never
80
+ * belong in this record.
81
+ */
82
+ export type SpawnAuthorityV1 = {
83
+ version: 1;
84
+ authorityId: string;
85
+ claimId: string;
86
+ childId: string;
87
+ ownerSessionId: string;
88
+ lifecycleIdentity: string;
89
+ substrateKind: SpawnSubstrateProof["substrateKind"];
90
+ providerIdentity: string;
91
+ nativeSessionId?: string;
92
+ pid?: number;
93
+ processIncarnation?: string;
94
+ ownerGeneration?: number;
95
+ stateFileProof?: Readonly<Record<string, string | number>>;
96
+ /**
97
+ * Identity of the child HOST endpoint proven at registration. Distinct from
98
+ * the substrate `pid`/`processIncarnation` above: proving the multiplexer
99
+ * substrate is intact says nothing about which host answers on that session
100
+ * id. Optional so pre-pin v1 rows still reopen; recovery treats an absent
101
+ * pin as missing authority and fails closed rather than matching by id.
102
+ */
103
+ endpointGeneration?: number;
104
+ endpointPid?: number;
105
+ endpointIncarnation?: string;
106
+ /** Launch locator, so a colliding generation/pid in another workspace cannot pass. */
107
+ endpointCwd?: string;
108
+ endpointStateRoot?: string;
109
+ closeState: SpawnAuthorityCloseState;
110
+ orphanedAt?: number;
111
+ orphanRecoveredAt?: number;
112
+ closeRequestedAt?: number;
113
+ closedAt?: number;
114
+ createdAt: number;
115
+ updatedAt: number;
116
+ };
117
+ export type SpawnClaimTransition = {
118
+ claimId: string;
119
+ from: SpawnClaimV2["state"];
120
+ to: SpawnClaimV2["state"];
121
+ /** Required when the transition consumes the one pre-send lease. */
122
+ leaseEpoch?: string;
123
+ /** The fresh child ID is committed before substrate launch. */
124
+ childId?: string;
125
+ /** Required for seed and terminal state transitions that carry Q26 facts. */
126
+ seed?: SeedDeliveryV2;
127
+ failure?: SpawnSubstrateFailure;
128
+ /** Required when exact substrate authority becomes active or closes. */
129
+ authority?: SpawnAuthorityV1;
130
+ /** Required to downgrade dispatching only when no frame was handed off. */
131
+ provenNoHandoff?: true;
132
+ };
133
+ export type SpawnAuthorityTransitionResult = {
134
+ claim: SpawnClaimV2;
135
+ authority?: SpawnAuthorityV1;
136
+ };
137
+ export declare class SpawnAuthorityTransitionError extends Error {
138
+ readonly code: "claim_not_found" | "stale_transition" | "illegal_transition" | "invalid_transition";
139
+ constructor(code: "claim_not_found" | "stale_transition" | "illegal_transition" | "invalid_transition");
140
+ }
141
+ export type SpawnClaimDecision = {
142
+ kind: "owner";
143
+ claim: SpawnClaimV2;
144
+ recovery: boolean;
145
+ } | {
146
+ kind: "in_progress";
147
+ claim: SpawnClaimV2;
148
+ } | {
149
+ kind: "replay";
150
+ claim: SpawnClaimV2;
151
+ } | {
152
+ kind: "terminal";
153
+ claim: SpawnClaimV2;
154
+ } | {
155
+ kind: "terminal_uncertain";
156
+ claim: SpawnClaimV2;
157
+ } | {
158
+ kind: "idempotency_conflict";
159
+ claim: SpawnClaimV2;
160
+ };
161
+ type SpawnAuthorityDurableWrite = {
162
+ claim: SpawnClaimV2;
163
+ authority?: SpawnAuthorityV1;
164
+ };
165
+ export interface SpawnAuthorityStoreOptions {
166
+ /** Test-only hook that runs before the journal record becomes durable. */
167
+ beforeSyncForTest?: (write: SpawnAuthorityDurableWrite) => Promise<void> | void;
168
+ /** Test-only hook after both file and parent-directory fsync complete. */
169
+ afterSyncForTest?: (write: SpawnAuthorityDurableWrite) => Promise<void> | void;
170
+ /** Test-only hook between the file barrier and the parent-directory barrier. */
171
+ beforeDirectorySyncForTest?: (write: SpawnAuthorityDurableWrite) => Promise<void> | void;
172
+ }
173
+ export declare function isSpawnSubstrateProof(value: unknown): value is SpawnSubstrateProof;
174
+ export declare function isSpawnAuthorityV1(value: unknown): value is SpawnAuthorityV1;
175
+ export declare function isSpawnClaimV2(value: unknown): value is SpawnClaimV2;
176
+ /**
177
+ * Append-only source of spawn-effect authority. It deliberately records no request
178
+ * input: the opaque identity and raw/canonical structural binding MACs are its
179
+ * only correlators.
180
+ */
181
+ export declare class SpawnAuthorityStore {
182
+ #private;
183
+ constructor(agentDir: string, brokerIdentityKey: string, options?: SpawnAuthorityStoreOptions);
184
+ get file(): string;
185
+ claims(): readonly SpawnClaimV2[];
186
+ claim(lifecycleIdentity: string): SpawnClaimV2 | undefined;
187
+ authority(lifecycleIdentity: string): SpawnAuthorityV1 | undefined;
188
+ open(): Promise<void>;
189
+ claimOrJoin(lifecycleIdentity: string, bindingMac: string | undefined, requestBindingMac?: string | undefined): Promise<SpawnClaimDecision>;
190
+ /**
191
+ * Fsyncs one allowlisted state edge. Callers cannot patch claims in place,
192
+ * which prevents a retry from downgrading a handoff-capable state.
193
+ */
194
+ persistTransition(lifecycleIdentity: string, transition: SpawnClaimTransition): Promise<SpawnAuthorityTransitionResult>;
195
+ /** Persists only an exact authority lifecycle update, never a proof replacement. */
196
+ persistAuthority(lifecycleIdentity: string, authority: SpawnAuthorityV1): Promise<SpawnAuthorityTransitionResult>;
197
+ /** Records an observed Q26 status without reopening or changing a state edge. */
198
+ persistSeedObservation(lifecycleIdentity: string, seed: SeedDeliveryV2): Promise<SpawnAuthorityTransitionResult>;
199
+ releaseOwner(lifecycleIdentity: string): Promise<void>;
200
+ }
201
+ export {};
@@ -0,0 +1,30 @@
1
+ import { type ManagedTmuxLaunchProof } from "../../gjc-runtime/tmux-sessions";
2
+ import type { SpawnSubstrateLaunchSpec, SpawnSubstrateProvider } from "./spawn-authority";
3
+ export type SpawnMultiplexerSelection = "none" | "tmux" | "psmux" | "proof_failed";
4
+ export interface SpawnHeadlessProcess {
5
+ pid: number;
6
+ terminate(): void;
7
+ }
8
+ export interface SpawnSubstrateProviderDependencies {
9
+ platform?: NodeJS.Platform;
10
+ env?: NodeJS.ProcessEnv;
11
+ /** @internal Test seam for deterministic provider selection. */
12
+ selectMultiplexer?: () => SpawnMultiplexerSelection;
13
+ /** @internal Test seam for the managed multiplexer command layer. */
14
+ launchManaged?: (spec: SpawnSubstrateLaunchSpec, env: NodeJS.ProcessEnv, platform: NodeJS.Platform) => ManagedTmuxLaunchProof;
15
+ verifyManaged?: (proof: ManagedTmuxLaunchProof, env: NodeJS.ProcessEnv) => "verified" | "mismatch" | "gone";
16
+ closeManaged?: (proof: ManagedTmuxLaunchProof, env: NodeJS.ProcessEnv) => Promise<void>;
17
+ processIncarnation?: (pid: number) => string | undefined;
18
+ startHeadless?: (spec: SpawnSubstrateLaunchSpec, env: NodeJS.ProcessEnv) => SpawnHeadlessProcess;
19
+ signalHeadless?: (pid: number, incarnation: string, platform: NodeJS.Platform, signal: "SIGTERM" | "SIGKILL") => boolean;
20
+ isProcessGone?: (pid: number) => boolean;
21
+ /** @internal Test seam for bounded close polling. */
22
+ sleep?: (milliseconds: number) => Promise<void>;
23
+ /** @internal Test seam for non-secret inherited-environment launch diagnostics. */
24
+ onInheritedEnvironmentDrop?: (names: readonly string[]) => void;
25
+ }
26
+ /**
27
+ * Provides the Broker's only substrate authority. Every close and replay starts
28
+ * from its durable opaque proof; no PID/name-only operation is exposed.
29
+ */
30
+ export declare function createSpawnSubstrateProvider(dependencies?: SpawnSubstrateProviderDependencies): SpawnSubstrateProvider;
@@ -2,8 +2,16 @@
2
2
  export declare const DEFAULT_READINESS_TIMEOUT_MS = 10000;
3
3
  export declare const MIN_READINESS_TIMEOUT_MS = 4000;
4
4
  export declare const MAX_READINESS_TIMEOUT_MS = 60000;
5
+ /** Bounded git worktree add/reuse window; independent of child semantic readiness. */
6
+ export declare const DEFAULT_WORKTREE_PREPARATION_TIMEOUT_MS = 30000;
7
+ export declare const MIN_PREPARATION_TIMEOUT_MS = 1000;
8
+ export declare const MAX_PREPARATION_TIMEOUT_MS = 120000;
9
+ /** Bounded workspace install window; independent of child semantic readiness. */
10
+ export declare const DEFAULT_DEPENDENCY_PREPARATION_TIMEOUT_MS = 30000;
5
11
  export declare function isValidReadinessTimeoutMs(value: unknown): value is number;
12
+ export declare function isValidPreparationTimeoutMs(value: unknown): value is number;
6
13
  export declare const READINESS_TIMEOUT_INVALID_MESSAGE = "readinessTimeoutMs must be an integer between 4000 and 60000.";
14
+ export declare const PREPARATION_TIMEOUT_INVALID_MESSAGE = "worktreePreparationTimeoutMs and dependencyPreparationTimeoutMs must be integers between 1000 and 120000.";
7
15
  /**
8
16
  * Sleep until the duration elapses or the caller cancels the wait. Queue admission
9
17
  * uses this so a granted or refused waiter does not retain its cutoff timer for the
@@ -40,5 +48,49 @@ export declare function lifecycleStartupBudgetMs(requestedReadinessTimeoutMs: nu
40
48
  * rather than left unextended: the broker queues it for exactly as long as one that
41
49
  * asked, so the common path would otherwise fail client-side while the broker runs
42
50
  * the startup to a durably persisted terminal result.
51
+ *
52
+ * Worktree launches add independent preparation budgets so git add / install cannot
53
+ * cut the caller while the broker still owns the request. One-arg
54
+ * {@link lifecycleStartupBudgetMs} stays queue+readiness for no-worktree callers.
43
55
  */
44
56
  export declare function lifecycleRequestTimeoutMs(operation: string, input: Record<string, unknown>): number | undefined;
57
+ /**
58
+ * True when this request will run named or detached worktree preparation.
59
+ * Coordinator nests the selector at `target.worktree`; Direct/lifecycle service
60
+ * put `worktree` on the mutation target itself; broker serialization also
61
+ * accepts `{ worktree: { name } }` without `enabled`.
62
+ */
63
+ export declare function lifecycleRequestHasWorktree(input: Record<string, unknown>): boolean;
64
+ /**
65
+ * Sum of worktree and dependency preparation budgets, or 0 when the request
66
+ * has no worktree. Returns `undefined` when an explicit prep field is present
67
+ * but invalid so callers fail closed instead of silently dropping prep time.
68
+ */
69
+ export declare function preparationBudgetMs(input: Record<string, unknown>): number | undefined;
70
+ export interface LifecycleOuterDeadlines {
71
+ admittedAt: number;
72
+ worktreePrepTimeoutMs: number;
73
+ dependencyPrepTimeoutMs: number;
74
+ requestedReadinessTimeoutMs: number;
75
+ worktreePreparationDeadlineAt: number;
76
+ lifecycleCleanupDeadlineAt: number;
77
+ }
78
+ /**
79
+ * Whole-request outer deadlines for a worktree launch. Child semantic readiness
80
+ * is still derived later at prepSucceededAt. Dependency start is sequential:
81
+ * callers clip remaining dep budget against `lifecycleCleanupDeadlineAt`
82
+ * after worktreeDoneAt.
83
+ */
84
+ export declare function deriveLifecycleOuterDeadlines(input: {
85
+ admittedAt: number;
86
+ worktreePrepTimeoutMs: number;
87
+ dependencyPrepTimeoutMs: number;
88
+ requestedReadinessTimeoutMs: number;
89
+ }): LifecycleOuterDeadlines;
90
+ export declare function readPreparationTimeouts(input: Record<string, unknown>): {
91
+ ok: true;
92
+ worktreePrepTimeoutMs: number;
93
+ dependencyPrepTimeoutMs: number;
94
+ } | {
95
+ ok: false;
96
+ };
@@ -1,5 +1,16 @@
1
1
  export declare const SDK_STATE_VERSION = 1;
2
- export declare const SESSION_INDEX_SNAPSHOT_VERSION = 3;
2
+ export declare const SESSION_INDEX_SNAPSHOT_VERSION = 4;
3
+ export declare const SESSION_INDEX_EVENT_VERSION = 4;
4
+ /**
5
+ * Thrown when a persisted SDK state file carries a version this build does not
6
+ * support. `assertSupportedStateVersion` fences only generic SDK state (broker
7
+ * discovery, lifecycle-ledger rows, guide cache meta) whose current format is
8
+ * exactly `SDK_STATE_VERSION`. Session-index files carry their own versions
9
+ * (see `assertSupportedSessionIndexEventVersion` and
10
+ * `assertSupportedSnapshotVersion`) and MUST NOT be validated with the generic
11
+ * guard — a supported v4 index row would crash with "maximum supported version
12
+ * is 1" (#5181).
13
+ */
3
14
  export declare class UnsupportedStateVersionError extends Error {
4
15
  readonly file: string;
5
16
  readonly version: number;
@@ -7,5 +18,14 @@ export declare class UnsupportedStateVersionError extends Error {
7
18
  readonly code = "unsupported_state_version";
8
19
  constructor(file: string, version: number, maximumSupportedVersion?: number);
9
20
  }
21
+ /**
22
+ * Generic SDK-state fence: rejects any version above `SDK_STATE_VERSION`.
23
+ * ONLY for generic state whose current format is exactly `SDK_STATE_VERSION`
24
+ * (broker discovery `broker.json`, lifecycle-ledger rows, guide cache meta).
25
+ * Never validate session-index rows or snapshots with this guard — they have
26
+ * dedicated version fences and currently accept v4 (#5181).
27
+ */
10
28
  export declare function assertSupportedStateVersion(file: string, value: unknown): void;
29
+ /** Rejects session-index events outside the known legacy and current formats. */
30
+ export declare function assertSupportedSessionIndexEventVersion(file: string, value: unknown): void;
11
31
  export declare function assertSupportedSnapshotVersion(file: string, value: unknown): void;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Which session currently holds a GJC-managed worktree.
3
+ *
4
+ * Both launch paths need this answer and must not disagree about it: the broker
5
+ * refuses a lifecycle launch into an occupied worktree, and the interactive
6
+ * `gjc --worktree` launch refuses for the same reason. Keeping one predicate —
7
+ * and one definition of "still running" — here prevents the two from drifting
8
+ * into different notions of liveness.
9
+ */
10
+ import type { IndexedSession } from "./session-index";
11
+ export type ProcessObservation = "alive" | "exited" | "uncertain";
12
+ /** Only ESRCH or a changed, readable incarnation proves the owned process exited. */
13
+ export declare function observeProcess(pid: number, expectedIncarnation: string | undefined, readIncarnation?: (pid: number) => string | undefined): ProcessObservation;
14
+ /**
15
+ * The id of a session still occupying `worktreePath`, or null when it is free.
16
+ *
17
+ * `ensureLaunchWorktree` reuses an existing worktree without asking whether
18
+ * anyone is in it, and an unnamed launch derives its directory deterministically
19
+ * from the repository's current branch. Two concurrent sessions in one
20
+ * repository therefore land in the same checkout and overwrite each other's
21
+ * files with no error.
22
+ *
23
+ * Only a process observed as definitively exited releases the worktree.
24
+ * `uncertain` counts as occupied: refusing a launch is recoverable by picking
25
+ * another worktree name, whereas two live sessions sharing a checkout corrupts
26
+ * work already done.
27
+ */
28
+ export declare function worktreeOccupant(sessions: readonly IndexedSession[], worktreePath: string, observe?: (pid: number, expectedIncarnation: string | undefined) => ProcessObservation): string | null;
@@ -102,6 +102,9 @@ export type ChatDaemonAction = "stop" | "reload";
102
102
  * session-index lock every 2s; staleness retirement moved to a 30s sweep and
103
103
  * lease heartbeats no longer force an authority reconcile. A pre-upgrade owner
104
104
  * would retain the old hot polling loop, so replacement is required.
105
+ * Discord generation 72 / Slack generation 75 serialize same-generation
106
+ * successor attachment admission behind predecessor provider retirement, so a
107
+ * pre-upgrade owner cannot retain the queue race fixed by #5120.
105
108
  */
106
109
  export declare const CHAT_DAEMON_GENERATIONS: Readonly<Record<ChatDaemonKind, number>>;
107
110
  export declare function chatDaemonGeneration(kind: ChatDaemonKind): number;
@@ -47,7 +47,7 @@ export declare class DiscordNotificationDaemon {
47
47
  /** Posts a safe command outcome to the active mapped conversation. */
48
48
  postCommandResult(sessionId: string, content: string): Promise<boolean>;
49
49
  close(sessionId: string, endpointGeneration?: number): Promise<void>;
50
- recoverCleanup(sessionId: string, endpointGeneration: number): Promise<void>;
50
+ recoverCleanup(sessionId: string, endpointGeneration: number, authorityId?: string): Promise<boolean>;
51
51
  retireAttachment(sessionId: string, endpointGeneration: number): Promise<void>;
52
52
  archive(sessionId: string): Promise<void>;
53
53
  resume(sessionId: string, endpointGeneration: number, attachmentAuthorityId?: string): Promise<DiscordConversation | undefined>;
@@ -116,7 +116,7 @@ export interface SessionResumeResponseFrame {
116
116
  sessionId: string;
117
117
  mode: ResumeMode;
118
118
  }
119
- export type LifecycleErrorReason = "unauthorized" | "rate_limited" | "duplicate_conflict" | "invalid_target" | "ambiguous_target" | "spawn_failed" | "discovery_timeout" | "readiness_timeout" | "close_refused" | "not_found" | "terminal_uncertain" | "unsupported_platform";
119
+ export type LifecycleErrorReason = "unauthorized" | "rate_limited" | "duplicate_conflict" | "invalid_target" | "ambiguous_target" | "spawn_failed" | "discovery_timeout" | "readiness_timeout" | "worktree_preparation_timeout" | "dependency_preparation_timeout" | "close_refused" | "not_found" | "terminal_uncertain" | "unsupported_platform";
120
120
  export interface ResumeCandidate {
121
121
  sessionId: string;
122
122
  path?: string;
@@ -310,6 +310,8 @@ interface SessionRuntime {
310
310
  disposeGateTerminalController: () => void;
311
311
  disposeAckRecoveryParticipant: () => void;
312
312
  disposeGateEmitterListener: () => void;
313
+ /** Deregisters this session's job-fold listener (`bash_folded`). */
314
+ disposeFoldListener: () => void;
313
315
  /** Aborts and fences side turns while notification delivery is disabled. */
314
316
  disableEphemeralTurns: () => void;
315
317
  waitForGateResolutionQuiescence: () => Promise<void>;
@@ -599,6 +601,12 @@ export declare function createNotificationsExtension(api: ExtensionAPI, options?
599
601
  controller?: NotificationSessionController;
600
602
  /** Whether this host mode can own the root SDK endpoint. Default: true. */
601
603
  sdkHostModeSupported?: boolean;
604
+ /** In-memory master capability for private broker verification only. */
605
+ masterCapability?: string;
606
+ /** Opaque direct-role epoch this effective host may adopt. */
607
+ masterAttestationEpoch?: string;
608
+ /** Stable master lineage identity retained across session switches/branches. */
609
+ masterOwnerSessionId?: string;
602
610
  onSdkRequest?: (kind: "control" | "query", connectionId: string, frame: Record<string, unknown>) => void;
603
611
  runBtwTurn?: (question: string, signal: AbortSignal) => Promise<{
604
612
  replyText: string;
@@ -1,5 +1,5 @@
1
1
  import type { PromptReconciliationStatus, SdkPromptTerminalOutcome, TurnPromptReconciliation } from "../prompt-status";
2
- import type { ReceiptState } from "../receipt-state";
2
+ import { type ReceiptState } from "../receipt-state";
3
3
  import { type TurnResultContent, type TurnResultPage } from "../turn-result";
4
4
  import { type PromptCorrelation } from "./prompt-reconciliation";
5
5
  import type { DurableReconciliationRecord, ReconciliationKind, ReconciliationStore } from "./reconciliation-store";
@@ -23,7 +23,7 @@
23
23
  */
24
24
  import { PROMPT_FAILURE_CODE_MAX, sanitizePromptFailure } from "../prompt-failure";
25
25
  import type { SdkPromptTerminalOutcome } from "../prompt-status";
26
- import type { ReceiptState } from "../receipt-state";
26
+ import { type ReceiptState } from "../receipt-state";
27
27
  export { PROMPT_FAILURE_CODE_MAX, sanitizePromptFailure };
28
28
  export declare const PROMPT_RECONCILIATION_ACTIVE_CAPACITY = 128;
29
29
  export declare const PROMPT_RECONCILIATION_TERMINAL_CAPACITY = 256;
@@ -5,7 +5,7 @@ export interface SlackInboundDispatchReceipt {
5
5
  interactionId: string;
6
6
  retryKey: string;
7
7
  eventContext?: string;
8
- kind: "action" | "command";
8
+ kind: "action" | "command" | "message";
9
9
  actionId?: string;
10
10
  /** The endpoint generation and SDK effect captured before Socket Mode ACK. */
11
11
  endpointGeneration: number;
@@ -69,7 +69,7 @@ export declare class SlackNotificationDaemon {
69
69
  postCommandResult(sessionId: string, content: string): Promise<boolean>;
70
70
  resolveAction(sessionId: string, actionId: string): Promise<void>;
71
71
  close(sessionId: string, marker?: string, endpointGeneration?: number): Promise<boolean>;
72
- recoverCleanup(sessionId: string, endpointGeneration: number): Promise<void>;
72
+ recoverCleanup(sessionId: string, endpointGeneration: number, authorityId?: string): Promise<boolean>;
73
73
  retireAttachment(sessionId: string, endpointGeneration: number): Promise<void>;
74
74
  resume(sessionId: string, body: string, endpointGeneration?: number, publicationId?: string): Promise<SlackConversation>;
75
75
  findSession(sessionId: string, includeInactive: boolean): Promise<{
@@ -286,7 +286,7 @@ export declare const SDK_LIFECYCLE_ROUTER_PROTOCOL_VERSION = 1;
286
286
  * killing a session's mirroring after one transient rejection and must be
287
287
  * replaced across this upgrade.
288
288
  */
289
- export declare const DAEMON_GENERATION = 179;
289
+ export declare const DAEMON_GENERATION = 181;
290
290
  /**
291
291
  * Serving-compatibility boundary for daemon lifecycle requests. Epoch 7
292
292
  * requires durable publication receipts and acknowledged attachment dispatch,
@@ -1 +1,2 @@
1
+ export * from "./master-cli";
1
2
  export * from "./session-cli";
@@ -0,0 +1,63 @@
1
+ import { type IndexedSession } from "../broker/session-index";
2
+ export declare class SdkMasterCliError extends Error {
3
+ readonly code: string;
4
+ readonly exitCode: 1 | 2;
5
+ constructor(code: string, message: string, exitCode?: 1 | 2);
6
+ }
7
+ export interface SdkSpawnArgs {
8
+ cwd?: string;
9
+ prompt?: string;
10
+ model?: string;
11
+ profile?: string;
12
+ agentDir?: string;
13
+ idempotencyKey?: string;
14
+ json?: boolean;
15
+ }
16
+ /** The allowlisted spawn result projection rendered to the operator. */
17
+ export interface SdkSpawnRendered {
18
+ code: string;
19
+ claimId?: string;
20
+ sessionId?: string;
21
+ substrateKind?: string;
22
+ seed?: {
23
+ phase?: string;
24
+ clientRef?: string;
25
+ commandId?: string;
26
+ turnId?: string;
27
+ status?: string;
28
+ };
29
+ idempotencyKey?: string;
30
+ error?: {
31
+ code: string;
32
+ message: string;
33
+ };
34
+ }
35
+ export interface SdkSpawnDependencies {
36
+ env: Record<string, string | undefined>;
37
+ dispatch: (agentDir: string, input: Record<string, unknown>, idempotencyKey: string) => Promise<unknown>;
38
+ resolveAttestationEpoch: (agentDir: string, ownerSessionId: string) => Promise<string | undefined>;
39
+ }
40
+ /**
41
+ * Select the newest retained master attestation for an owner session.
42
+ *
43
+ * `listSessionIdentities()` can retain both the direct-role row and one or
44
+ * more endpoint generations. Its iteration order is a projection detail, not
45
+ * authority ordering, so selecting the first matching row can resurrect an
46
+ * older epoch after a master relaunch. The broker's monotonically increasing
47
+ * `indexSeq` is the authoritative retained ordering.
48
+ */
49
+ export declare function selectNewestMasterAttestationEpoch(rows: readonly IndexedSession[], ownerSessionId: string): string | undefined;
50
+ /** Projects an arbitrary Broker response onto the allowlisted render shape. */
51
+ export declare function safeSpawnRender(response: unknown): {
52
+ rendered: SdkSpawnRendered;
53
+ exitCode: 0 | 1;
54
+ };
55
+ export declare function renderSpawnTable(rendered: SdkSpawnRendered): string;
56
+ /**
57
+ * Runs one local master spawn. A caller-provided idempotency key replays the
58
+ * matching durable claim; otherwise each invocation receives a fresh key.
59
+ */
60
+ export declare function runSdkSpawn(args: SdkSpawnArgs, dependencies?: Partial<SdkSpawnDependencies>): Promise<{
61
+ rendered: SdkSpawnRendered;
62
+ exitCode: 0 | 1;
63
+ }>;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Versioned DTO rows for `gjc sdk session` semantic verbs (row DTO v1, DR-12).
2
+ * Versioned DTO rows for `gjc sdk session` semantic verbs (row DTO v2, DR-12).
3
3
  *
4
4
  * Every semantic verb renders its output through these rows so machine
5
5
  * consumers get one deterministic, versioned envelope per verb. Credentials
@@ -7,7 +7,7 @@
7
7
  * credentials, and pass-through host payloads are redacted recursively before
8
8
  * rendering.
9
9
  */
10
- export declare const SESSION_ROWS_VERSION = 1;
10
+ export declare const SESSION_ROWS_VERSION = 2;
11
11
  export type SdkSessionActivityState = "active" | "idle";
12
12
  export interface SdkSessionActivityV1 {
13
13
  state: SdkSessionActivityState;
@@ -16,7 +16,8 @@ export interface SdkSessionActivityV1 {
16
16
  export interface SdkSessionRowV1 {
17
17
  sessionId: string;
18
18
  locator: {
19
- repo: string;
19
+ cwd: string;
20
+ worktreeRoot: string | null;
20
21
  stateRoot: string;
21
22
  };
22
23
  endpointGeneration: number;
@@ -39,24 +40,29 @@ export interface SdkSessionRowV1 {
39
40
  /** True when the same sessionId maps to more than one stateRoot (cross-repo duplicate). */
40
41
  ambiguous?: boolean;
41
42
  }
42
- export interface SdkCheckpointRecordV1 {
43
+ export interface SdkRingPositionV1 {
43
44
  revision: number;
44
45
  generation: number;
45
46
  seq: number;
46
47
  }
48
+ export interface SdkCheckpointRecordV1 extends SdkRingPositionV1 {
49
+ idle: boolean;
50
+ }
47
51
  export interface SdkRetentionGapV1 {
48
52
  code: "retention_gap";
49
53
  missing?: {
50
54
  from: number;
51
55
  to: number;
52
56
  };
53
- resync?: SdkCheckpointRecordV1;
57
+ resync?: SdkRingPositionV1;
54
58
  }
55
59
  /** One tail item: a retained transcript entry or a live event-ring event. */
56
60
  export interface SdkTailItemV1 {
57
61
  /** "transcript" for retained transcript entries, otherwise the event-ring kind. */
58
62
  kind: string;
59
63
  id?: string;
64
+ /** Durable revision at emission; (revision,generation,seq) is unique per session. generation:seq alone is revision-local. */
65
+ revision?: number;
60
66
  generation?: number;
61
67
  seq?: number;
62
68
  payload: unknown;
@@ -84,6 +90,7 @@ export declare function toRetentionGapV1(value: unknown): SdkRetentionGapV1 | un
84
90
  /** Projects a transcript entry or ring event into a tail item with dedupe keys. */
85
91
  export declare function toTailItemV1(value: unknown, fallback: {
86
92
  kind: string;
93
+ revision?: number;
87
94
  generation?: number;
88
95
  seq?: number;
89
96
  }): SdkTailItemV1;
@@ -1,6 +1,8 @@
1
+ import { type SdkSearchResultV1, type SdkSearchRowV1 } from "../broker/session-scope";
2
+ import type { SessionLifecycleService } from "../lifecycle/service";
1
3
  import { SessionRouter } from "../router";
2
4
  import { type SdkSessionRowV1 } from "./rows";
3
- export type SdkSessionCliAction = "list" | "inspect" | "send" | "status" | "tail" | "retire" | "global" | "raw" | "control" | "query" | "global";
5
+ export type SdkSessionCliAction = "list" | "search" | "inspect" | "send" | "status" | "tail" | "retire" | "global" | "raw" | "control" | "query" | "global";
4
6
  export type SdkSessionListScope = "repo" | "cwd" | "worktree" | "all";
5
7
  export type SdkSessionCliRawKind = "control" | "query" | "global";
6
8
  export interface SdkSessionCliArgs {
@@ -15,7 +17,6 @@ export interface SdkSessionCliArgs {
15
17
  jsonInputFile?: string;
16
18
  jsonInputStdin?: boolean;
17
19
  idempotencyKey?: string;
18
- scope?: string;
19
20
  confirm?: boolean;
20
21
  cursor?: string;
21
22
  wait?: boolean;
@@ -24,12 +25,24 @@ export interface SdkSessionCliArgs {
24
25
  untilIdle?: boolean;
25
26
  allEvents?: boolean;
26
27
  repo?: string;
28
+ scope?: string;
29
+ limit?: number;
30
+ json?: boolean;
27
31
  agentDir?: string;
28
32
  }
33
+ type JsonRecord = Record<string, unknown>;
29
34
  export interface RetainedTranscriptTailReader {
30
35
  readonly size: number;
31
36
  readRange(start: number, end: number): Promise<Uint8Array>;
32
37
  }
38
+ export declare function mergeProbedSearchRows(rows: readonly SdkSearchRowV1[], probedRows: readonly SdkSearchRowV1[]): readonly SdkSearchRowV1[];
39
+ /** Resolves, lists, and probes only the exact rows selected by the Broker-scoped search. */
40
+ export declare function runSdkSearch(args: Pick<SdkSessionCliArgs, "agentDir" | "repo" | "scope" | "limit" | "cursor">, createService?: (agentDir: string) => SessionLifecycleService, probe?: (agentDir: string, result: SdkSearchResultV1) => Promise<SdkSearchResultV1>): Promise<{
41
+ result: SdkSearchResultV1;
42
+ exitCode: 0 | 1;
43
+ }>;
44
+ /** Renders a credential-free scope/status preamble and bounded search table. */
45
+ export declare function renderSdkSearchTable(result: SdkSearchResultV1): string;
33
46
  interface WorkspaceIdentity {
34
47
  /** Canonical workspace path (realpath when it exists, lexical resolve otherwise). */
35
48
  canonicalPath: string;
@@ -54,7 +67,8 @@ export declare function parseSessionListScope(value: string | undefined): SdkSes
54
67
  /**
55
68
  * Resolves the list selection from `--repo` (default: process cwd) under the
56
69
  * effective scope. Outside Git, `repo`/`worktree` fail typed and actionable —
57
- * they never broaden to `all`; `cwd` remains an exact canonical match.
70
+ * they never broaden to `all`; `cwd` remains an exact canonical match, and
71
+ * `all` ignores the selection entirely so it works outside any checkout.
58
72
  */
59
73
  export declare function resolveSessionListSelection(scope: SdkSessionListScope, repoArg: string | undefined): Promise<SdkSessionListSelection>;
60
74
  /**
@@ -69,6 +83,9 @@ export declare function filterSessionRowsByScope(rows: readonly SdkSessionRowV1[
69
83
  }>;
70
84
  /** Creates a lowercase ULID operation reference for prompt reconciliation. */
71
85
  export declare function createOperationRef(now?: number): string;
86
+ /** Builds the public CLI control envelope without leaking envelope fields into operation input. */
87
+ export declare function controlRequestFrame(operation: string, input: JsonRecord, args: Pick<SdkSessionCliArgs, "confirm" | "idempotencyKey">): JsonRecord;
88
+ export declare function operatorAbortBrokerRequest(sessionId: string, operation: string, input: JsonRecord, args: Pick<SdkSessionCliArgs, "confirm" | "idempotencyKey">): JsonRecord | undefined;
72
89
  /** Exported for tests: each status poll must stay inside the caller's wait window. */
73
90
  export declare function waitForTerminalStatus(router: SessionRouter, sessionId: string, clientRef: string, timeoutMs: number | undefined): Promise<{
74
91
  terminal: boolean;