@gajae-code/coding-agent 0.16.7 → 0.17.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 (321) hide show
  1. package/CHANGELOG.md +180 -1
  2. package/dist/types/capability/fs.d.ts +37 -4
  3. package/dist/types/capability/index.d.ts +19 -0
  4. package/dist/types/capability/types.d.ts +9 -0
  5. package/dist/types/cli/doctor/args.d.ts +36 -0
  6. package/dist/types/cli/doctor/checks.d.ts +18 -0
  7. package/dist/types/cli/doctor/config-repairs.d.ts +38 -0
  8. package/dist/types/cli/doctor/context.d.ts +89 -0
  9. package/dist/types/cli/doctor/files.d.ts +27 -0
  10. package/dist/types/cli/doctor/ids.d.ts +20 -0
  11. package/dist/types/cli/doctor/install-repairs.d.ts +94 -0
  12. package/dist/types/cli/doctor/journal.d.ts +43 -0
  13. package/dist/types/cli/doctor/managed-link.d.ts +39 -0
  14. package/dist/types/cli/doctor/native-probe.d.ts +2 -0
  15. package/dist/types/cli/doctor/permission-repairs.d.ts +25 -0
  16. package/dist/types/cli/doctor/plugin-quarantine.d.ts +77 -0
  17. package/dist/types/cli/doctor/plugin-restore.d.ts +40 -0
  18. package/dist/types/cli/doctor/plugin-targets.d.ts +11 -0
  19. package/dist/types/cli/doctor/probe-client.d.ts +9 -0
  20. package/dist/types/cli/doctor/probe-types.d.ts +18 -0
  21. package/dist/types/cli/doctor/probe.d.ts +3 -0
  22. package/dist/types/cli/doctor/projection-probe.d.ts +2 -0
  23. package/dist/types/cli/doctor/repairs.d.ts +28 -0
  24. package/dist/types/cli/doctor/report.d.ts +27 -0
  25. package/dist/types/cli/doctor/runner.d.ts +4 -0
  26. package/dist/types/cli/doctor/safety.d.ts +10 -0
  27. package/dist/types/cli/doctor/service-repairs.d.ts +8 -0
  28. package/dist/types/cli/doctor/service-targets.d.ts +41 -0
  29. package/dist/types/cli/doctor/types.d.ts +145 -0
  30. package/dist/types/cli/doctor-cli.d.ts +7 -0
  31. package/dist/types/cli/doctor-supervisor.d.ts +121 -0
  32. package/dist/types/cli/doctor-worker.d.ts +29 -0
  33. package/dist/types/cli/install-activation.d.ts +158 -0
  34. package/dist/types/cli/macos-community-app.d.ts +41 -0
  35. package/dist/types/cli/mcp-cli.d.ts +0 -11
  36. package/dist/types/cli/update-cli.d.ts +41 -4
  37. package/dist/types/cli-main.d.ts +174 -0
  38. package/dist/types/cli.d.ts +1 -171
  39. package/dist/types/commands/doctor.d.ts +7 -0
  40. package/dist/types/commands/sdk.d.ts +17 -8
  41. package/dist/types/config/autorouting-tier-map.d.ts +19 -0
  42. package/dist/types/config/file-lock.d.ts +27 -3
  43. package/dist/types/config/model-preset-registry.d.ts +1 -0
  44. package/dist/types/config/model-registry.d.ts +12 -5
  45. package/dist/types/config/model-resolver.d.ts +16 -3
  46. package/dist/types/config/models-config-schema.d.ts +2 -0
  47. package/dist/types/config/settings-schema.d.ts +1 -1
  48. package/dist/types/coordinator-mcp/question-gate-codec.d.ts +1 -1
  49. package/dist/types/coordinator-mcp/session-reaper.d.ts +15 -5
  50. package/dist/types/cursor.d.ts +9 -9
  51. package/dist/types/discovery/agents-md.d.ts +6 -1
  52. package/dist/types/discovery/helpers.d.ts +36 -7
  53. package/dist/types/discovery/index.d.ts +1 -1
  54. package/dist/types/discovery/mcp-json.d.ts +2 -0
  55. package/dist/types/extensibility/extensions/loader.d.ts +22 -1
  56. package/dist/types/extensibility/gjc-plugins/lifecycle.d.ts +14 -1
  57. package/dist/types/extensibility/gjc-plugins/paths.d.ts +2 -1
  58. package/dist/types/extensibility/gjc-plugins/types.d.ts +25 -0
  59. package/dist/types/extensibility/plugins/manager.d.ts +33 -4
  60. package/dist/types/extensibility/plugins/marketplace/cache.d.ts +6 -0
  61. package/dist/types/extensibility/plugins/marketplace/manager.d.ts +186 -0
  62. package/dist/types/extensibility/plugins/marketplace/registry.d.ts +27 -0
  63. package/dist/types/extensibility/plugins/marketplace/source-resolver.d.ts +16 -1
  64. package/dist/types/extensibility/runtime-skill-discovery.d.ts +16 -3
  65. package/dist/types/gjc-runtime/autoresearch-runtime.d.ts +6 -0
  66. package/dist/types/gjc-runtime/launch-worktree.d.ts +53 -0
  67. package/dist/types/gjc-runtime/session-layout.d.ts +8 -0
  68. package/dist/types/gjc-runtime/session-state-lock.d.ts +15 -0
  69. package/dist/types/gjc-runtime/session-state-sidecar.d.ts +13 -0
  70. package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +6 -0
  71. package/dist/types/main.d.ts +19 -1
  72. package/dist/types/modes/acp/acp-agent.d.ts +40 -0
  73. package/dist/types/modes/components/agent-dashboard.d.ts +1 -0
  74. package/dist/types/modes/components/model-selector.d.ts +2 -0
  75. package/dist/types/modes/interactive-mode.d.ts +1 -1
  76. package/dist/types/runtime-mcp/config-writer.d.ts +47 -0
  77. package/dist/types/runtime-mcp/policy-json-edit.d.ts +60 -0
  78. package/dist/types/runtime-mcp/startup-policy.d.ts +4 -0
  79. package/dist/types/runtime-mcp/types.d.ts +2 -2
  80. package/dist/types/sdk/acp/adapter.d.ts +5 -1
  81. package/dist/types/sdk/broker/broker.d.ts +51 -0
  82. package/dist/types/sdk/broker/daemon-entry.d.ts +39 -0
  83. package/dist/types/sdk/broker/discovery.d.ts +38 -0
  84. package/dist/types/sdk/broker/doctor-restart.d.ts +79 -0
  85. package/dist/types/sdk/broker/endpoint-authority.d.ts +7 -0
  86. package/dist/types/sdk/broker/ensure.d.ts +14 -0
  87. package/dist/types/sdk/broker/lifecycle.d.ts +2 -0
  88. package/dist/types/sdk/broker/process-incarnation.d.ts +50 -0
  89. package/dist/types/sdk/broker/runtime.d.ts +26 -0
  90. package/dist/types/sdk/broker/session-index.d.ts +13 -4
  91. package/dist/types/sdk/broker/worktree-occupancy.d.ts +14 -0
  92. package/dist/types/sdk/bus/chat-daemon-cli.d.ts +16 -0
  93. package/dist/types/sdk/bus/chat-daemon-control.d.ts +101 -6
  94. package/dist/types/sdk/bus/chat-daemon-runtime.d.ts +16 -0
  95. package/dist/types/sdk/bus/daemon-startup-exclusion.d.ts +43 -0
  96. package/dist/types/sdk/bus/doctor-daemon-restart-client.d.ts +51 -0
  97. package/dist/types/sdk/bus/doctor-daemon-restart.d.ts +39 -0
  98. package/dist/types/sdk/bus/index.d.ts +2 -0
  99. package/dist/types/sdk/bus/notification-service.d.ts +3 -0
  100. package/dist/types/sdk/bus/telegram-daemon-cli.d.ts +11 -0
  101. package/dist/types/sdk/bus/telegram-daemon-contract.d.ts +1 -1
  102. package/dist/types/sdk/bus/telegram-daemon-control.d.ts +5 -0
  103. package/dist/types/sdk/bus/telegram-daemon-owner-registry.d.ts +1 -0
  104. package/dist/types/sdk/bus/telegram-daemon.d.ts +36 -5
  105. package/dist/types/sdk/cli/session-cli.d.ts +1 -0
  106. package/dist/types/sdk/host/session-runtime.d.ts +4 -0
  107. package/dist/types/sdk/host/surface-policy.d.ts +3 -1
  108. package/dist/types/sdk/lifecycle/service.d.ts +44 -10
  109. package/dist/types/sdk/prompt-deadline-lease.d.ts +6 -3
  110. package/dist/types/sdk/prompt-deadline-manager.d.ts +2 -2
  111. package/dist/types/sdk/prompt-failure.d.ts +47 -0
  112. package/dist/types/sdk/prompt-status.d.ts +19 -0
  113. package/dist/types/sdk/router/session-router.d.ts +3 -4
  114. package/dist/types/sdk/service-artifact-paths.d.ts +16 -0
  115. package/dist/types/sdk/session-authority.d.ts +9 -0
  116. package/dist/types/sdk/session.d.ts +3 -1
  117. package/dist/types/session/agent-session.d.ts +1 -1
  118. package/dist/types/session/blob-store.d.ts +1 -1
  119. package/dist/types/session/fallback-chain-controller.d.ts +3 -6
  120. package/dist/types/session/internal/managed-session-scope.d.ts +44 -0
  121. package/dist/types/session/primary-control-surface.d.ts +4 -0
  122. package/dist/types/session/session-manager.d.ts +6 -0
  123. package/dist/types/system-prompt.d.ts +6 -0
  124. package/dist/types/tools/ask.d.ts +25 -0
  125. package/dist/types/tools/image-gen.d.ts +0 -4
  126. package/dist/types/tools/skill-discovery.d.ts +7 -5
  127. package/dist/types/tools/ultragoal-ask-guard.d.ts +7 -4
  128. package/dist/types/utils/changelog.d.ts +0 -9
  129. package/dist/types/utils/mupdf-wasm.d.ts +1 -0
  130. package/package.json +9 -8
  131. package/scripts/compile-args.ts +8 -4
  132. package/src/capability/fs.ts +395 -17
  133. package/src/capability/index.ts +273 -10
  134. package/src/capability/types.ts +9 -0
  135. package/src/cli/customize-doctor.ts +18 -12
  136. package/src/cli/doctor/args.ts +236 -0
  137. package/src/cli/doctor/checks.ts +431 -0
  138. package/src/cli/doctor/config-repairs.ts +517 -0
  139. package/src/cli/doctor/context.ts +149 -0
  140. package/src/cli/doctor/files.ts +149 -0
  141. package/src/cli/doctor/ids.ts +115 -0
  142. package/src/cli/doctor/install-repairs.ts +335 -0
  143. package/src/cli/doctor/journal.ts +423 -0
  144. package/src/cli/doctor/managed-link.ts +514 -0
  145. package/src/cli/doctor/native-probe.ts +13 -0
  146. package/src/cli/doctor/permission-repairs.ts +242 -0
  147. package/src/cli/doctor/plugin-quarantine.ts +377 -0
  148. package/src/cli/doctor/plugin-restore.ts +59 -0
  149. package/src/cli/doctor/plugin-targets.ts +373 -0
  150. package/src/cli/doctor/probe-client.ts +195 -0
  151. package/src/cli/doctor/probe-types.ts +21 -0
  152. package/src/cli/doctor/probe.ts +42 -0
  153. package/src/cli/doctor/projection-probe.ts +249 -0
  154. package/src/cli/doctor/repairs.ts +1157 -0
  155. package/src/cli/doctor/report.ts +176 -0
  156. package/src/cli/doctor/runner.ts +342 -0
  157. package/src/cli/doctor/safety.ts +40 -0
  158. package/src/cli/doctor/service-repairs.ts +452 -0
  159. package/src/cli/doctor/service-targets.ts +274 -0
  160. package/src/cli/doctor/types.ts +164 -0
  161. package/src/cli/doctor-cli.ts +62 -0
  162. package/src/cli/doctor-supervisor.ts +571 -0
  163. package/src/cli/doctor-worker.ts +181 -0
  164. package/src/cli/install-activation.ts +666 -0
  165. package/src/cli/macos-community-app.ts +1449 -0
  166. package/src/cli/mcp-cli.ts +11 -21
  167. package/src/cli/nofile-limit.ts +5 -1
  168. package/src/cli/plugin-cli.ts +6 -1
  169. package/src/cli/update-cli.ts +362 -264
  170. package/src/cli-main.ts +517 -0
  171. package/src/cli.ts +64 -433
  172. package/src/commands/autoresearch.ts +11 -5
  173. package/src/commands/completion.ts +1 -1
  174. package/src/commands/doctor.ts +13 -0
  175. package/src/commands/sdk.ts +58 -10
  176. package/src/commands/ultragoal.ts +11 -5
  177. package/src/config/autorouting-tier-map.ts +7 -0
  178. package/src/config/file-lock.ts +736 -71
  179. package/src/config/mcp-schema.json +3 -3
  180. package/src/config/model-preset-registry.ts +1 -0
  181. package/src/config/model-registry.ts +80 -27
  182. package/src/config/model-resolver.ts +33 -4
  183. package/src/config/models-config-schema.ts +2 -0
  184. package/src/config/settings-schema.ts +6 -2
  185. package/src/coordinator-mcp/question-gate-codec.ts +1 -0
  186. package/src/coordinator-mcp/server.ts +534 -51
  187. package/src/coordinator-mcp/session-reaper.ts +64 -8
  188. package/src/cursor.ts +223 -53
  189. package/src/discovery/agents-md.ts +74 -8
  190. package/src/discovery/agents.ts +32 -7
  191. package/src/discovery/builtin.ts +184 -75
  192. package/src/discovery/claude-plugins.ts +85 -17
  193. package/src/discovery/cline.ts +38 -10
  194. package/src/discovery/cursor.ts +19 -6
  195. package/src/discovery/gemini.ts +62 -22
  196. package/src/discovery/github.ts +13 -3
  197. package/src/discovery/helpers.ts +483 -89
  198. package/src/discovery/index.ts +1 -0
  199. package/src/discovery/mcp-json.ts +36 -10
  200. package/src/discovery/opencode.ts +36 -19
  201. package/src/discovery/ssh.ts +11 -8
  202. package/src/discovery/windsurf.ts +12 -3
  203. package/src/exec/bash-executor.ts +10 -3
  204. package/src/exec/isolated-shell.ts +15 -2
  205. package/src/extensibility/extensions/loader.ts +88 -26
  206. package/src/extensibility/gjc-plugins/lifecycle.ts +189 -0
  207. package/src/extensibility/gjc-plugins/paths.ts +4 -1
  208. package/src/extensibility/gjc-plugins/types.ts +27 -0
  209. package/src/extensibility/plugins/manager.ts +200 -22
  210. package/src/extensibility/plugins/marketplace/cache.ts +55 -2
  211. package/src/extensibility/plugins/marketplace/manager.ts +1262 -162
  212. package/src/extensibility/plugins/marketplace/registry.ts +153 -0
  213. package/src/extensibility/plugins/marketplace/source-resolver.ts +116 -10
  214. package/src/extensibility/runtime-skill-discovery.ts +61 -9
  215. package/src/extensibility/skill-management.ts +7 -1
  216. package/src/gjc-runtime/autoresearch-runtime.ts +10 -1
  217. package/src/gjc-runtime/launch-worktree.test.ts +248 -0
  218. package/src/gjc-runtime/launch-worktree.ts +275 -38
  219. package/src/gjc-runtime/repository-binding.ts +26 -1
  220. package/src/gjc-runtime/session-layout.ts +10 -0
  221. package/src/gjc-runtime/session-state-lock.ts +330 -23
  222. package/src/gjc-runtime/session-state-sidecar.ts +328 -80
  223. package/src/gjc-runtime/ultragoal-runtime.ts +10 -1
  224. package/src/harness-control-plane/session-lease.ts +2 -2
  225. package/src/internal-urls/docs-index.generated.ts +28 -26
  226. package/src/main.ts +150 -29
  227. package/src/memories/index.ts +24 -2
  228. package/src/modes/acp/acp-agent.ts +522 -68
  229. package/src/modes/components/agent-dashboard.ts +3 -1
  230. package/src/modes/components/model-selector.ts +28 -19
  231. package/src/modes/components/plugin-settings.ts +2 -1
  232. package/src/modes/controllers/selector-controller.ts +15 -9
  233. package/src/modes/interactive-mode.ts +21 -3
  234. package/src/prompts/system/system-prompt.md +5 -1
  235. package/src/prompts/tools/browser.md +1 -1
  236. package/src/prompts/tools/move-session.md +4 -0
  237. package/src/prompts/tools/read.md +2 -1
  238. package/src/prompts/tools/skill-discovery.md +6 -5
  239. package/src/prompts/tools/task.md +1 -0
  240. package/src/runtime-mcp/config-writer.ts +228 -0
  241. package/src/runtime-mcp/oauth-discovery.ts +114 -14
  242. package/src/runtime-mcp/policy-json-edit.ts +129 -0
  243. package/src/runtime-mcp/startup-policy.ts +14 -0
  244. package/src/runtime-mcp/types.ts +2 -2
  245. package/src/sdk/acp/adapter.ts +27 -12
  246. package/src/sdk/broker/broker.ts +273 -44
  247. package/src/sdk/broker/daemon-entry.ts +119 -0
  248. package/src/sdk/broker/discovery.ts +173 -20
  249. package/src/sdk/broker/doctor-restart.ts +206 -0
  250. package/src/sdk/broker/endpoint-authority.ts +36 -0
  251. package/src/sdk/broker/ensure.ts +49 -14
  252. package/src/sdk/broker/lifecycle.ts +174 -42
  253. package/src/sdk/broker/process-incarnation.ts +86 -2
  254. package/src/sdk/broker/runtime.ts +145 -21
  255. package/src/sdk/broker/session-index.ts +136 -22
  256. package/src/sdk/broker/spawn-substrate.ts +4 -1
  257. package/src/sdk/broker/transport.ts +5 -0
  258. package/src/sdk/broker/worktree-occupancy.ts +21 -1
  259. package/src/sdk/bus/chat-daemon-cli.ts +63 -0
  260. package/src/sdk/bus/chat-daemon-control.ts +260 -64
  261. package/src/sdk/bus/chat-daemon-runtime.ts +141 -25
  262. package/src/sdk/bus/daemon-startup-exclusion.ts +119 -0
  263. package/src/sdk/bus/doctor-daemon-restart-client.ts +291 -0
  264. package/src/sdk/bus/doctor-daemon-restart.ts +92 -0
  265. package/src/sdk/bus/index.ts +252 -51
  266. package/src/sdk/bus/kind-aware-reconciliation.ts +76 -41
  267. package/src/sdk/bus/notification-service.ts +21 -3
  268. package/src/sdk/bus/reconciliation-store.ts +17 -11
  269. package/src/sdk/bus/telegram-daemon-cli.ts +91 -5
  270. package/src/sdk/bus/telegram-daemon-contract.ts +1 -1
  271. package/src/sdk/bus/telegram-daemon-control.ts +47 -0
  272. package/src/sdk/bus/telegram-daemon-owner-registry.ts +1 -1
  273. package/src/sdk/bus/telegram-daemon.ts +178 -13
  274. package/src/sdk/cli/session-cli.ts +100 -12
  275. package/src/sdk/host/host.ts +2 -7
  276. package/src/sdk/host/session-runtime.test.ts +329 -8
  277. package/src/sdk/host/session-runtime.ts +202 -50
  278. package/src/sdk/host/surface-policy.ts +8 -1
  279. package/src/sdk/lifecycle/service.ts +199 -22
  280. package/src/sdk/mcp/server.ts +1 -1
  281. package/src/sdk/prompt-deadline-lease.ts +12 -4
  282. package/src/sdk/prompt-deadline-manager.ts +5 -7
  283. package/src/sdk/prompt-failure.ts +148 -0
  284. package/src/sdk/prompt-status.ts +30 -1
  285. package/src/sdk/prompt-watchdog.ts +11 -3
  286. package/src/sdk/protocol/operation-inventory.generated.json +18 -0
  287. package/src/sdk/protocol/operation-registry.ts +20 -8
  288. package/src/sdk/router/session-router.ts +8 -3
  289. package/src/sdk/service-artifact-paths.ts +26 -0
  290. package/src/sdk/session-authority.ts +10 -0
  291. package/src/sdk/session.ts +361 -194
  292. package/src/session/agent-session.ts +398 -93
  293. package/src/session/blob-store.ts +9 -9
  294. package/src/session/fallback-chain-controller.ts +3 -7
  295. package/src/session/internal/managed-session-scope.ts +445 -29
  296. package/src/session/internal/managed-session-storage.ts +38 -6
  297. package/src/session/primary-control-surface.ts +12 -0
  298. package/src/session/session-manager.ts +11 -3
  299. package/src/session/session-storage.ts +1 -1
  300. package/src/session-import/codex.ts +6 -1
  301. package/src/session-import/redact.ts +7 -0
  302. package/src/skill-state/workflow-mutation-guard.ts +645 -39
  303. package/src/slash-commands/builtin-registry.ts +7 -3
  304. package/src/system-prompt.ts +8 -0
  305. package/src/task/executor.ts +36 -3
  306. package/src/task/types.ts +27 -5
  307. package/src/tools/ask.ts +114 -34
  308. package/src/tools/browser/actions.ts +2 -2
  309. package/src/tools/browser/tab-worker.ts +11 -8
  310. package/src/tools/descriptors.ts +6 -1
  311. package/src/tools/fetch.ts +7 -2
  312. package/src/tools/image-gen.ts +33 -34
  313. package/src/tools/read.ts +78 -32
  314. package/src/tools/skill-discovery.ts +17 -7
  315. package/src/tools/tool-catalog.generated.ts +8 -8
  316. package/src/tools/ultragoal-ask-guard.ts +16 -26
  317. package/src/utils/changelog.ts +7 -1
  318. package/src/utils/git.ts +3 -1
  319. package/src/utils/markit.ts +24 -2
  320. package/src/utils/mupdf-wasm.ts +26 -0
  321. package/src/web/search/providers/openai-compatible.ts +191 -14
@@ -0,0 +1,51 @@
1
+ import type { Settings } from "../../config/settings";
2
+ import type { DoctorDaemonIdentity, DoctorDaemonOwner } from "./doctor-daemon-restart";
3
+ export interface DoctorDaemonRestartOptions {
4
+ readonly agentDir: string;
5
+ readonly owner: DoctorDaemonOwner;
6
+ readonly settings: Settings;
7
+ readonly requestId?: string;
8
+ readonly deadlineMs?: number;
9
+ /** Bounded natural-completion wait; idle attached sessions still count as workload. */
10
+ readonly drainSeconds?: number;
11
+ }
12
+ /**
13
+ * Typed before/after-effect outcome. Every refusal names the exact stage it
14
+ * stopped at, so a caller never has to infer whether an effect began.
15
+ */
16
+ export type DoctorDaemonRestartOutcome = {
17
+ kind: "restarted";
18
+ requestId: string;
19
+ oldOwner: DoctorDaemonIdentity;
20
+ successor: DoctorDaemonIdentity;
21
+ adopted: boolean;
22
+ } | {
23
+ kind: "owner_unavailable";
24
+ reason: "no_state" | "owner_not_confirmed_live" | "unsupported_incumbent_protocol";
25
+ } | {
26
+ kind: "prepare_refused";
27
+ reason: "control_write_failed" | "not_acknowledged";
28
+ } | {
29
+ kind: "commit_refused";
30
+ reason: "control_write_failed";
31
+ } | {
32
+ kind: "old_owner_exit_timeout";
33
+ requestId: string;
34
+ oldOwner: DoctorDaemonIdentity;
35
+ } | {
36
+ kind: "successor_refused";
37
+ requestId: string;
38
+ oldOwner: DoctorDaemonIdentity;
39
+ reason: "start_refused" | "publication_timeout";
40
+ };
41
+ /**
42
+ * Owner-side prepare/commit, positive-exit-confirmed cleanup, then exactly one
43
+ * successor started through the product's own ensure path.
44
+ *
45
+ * Ordering is fixed: prepare (owner closes admission) → occupancy settles →
46
+ * commit → owner exits under its own gate → positive absence proof → successor
47
+ * start or adoption. A commit is never issued before the owner acknowledged the
48
+ * prepare, and a successor is never started before the predecessor is proven
49
+ * gone.
50
+ */
51
+ export declare function restartDaemonForDoctor(options: DoctorDaemonRestartOptions): Promise<DoctorDaemonRestartOutcome>;
@@ -0,0 +1,39 @@
1
+ export type DoctorDaemonOwner = "telegram" | "discord" | "slack";
2
+ export interface DoctorDaemonIdentity {
3
+ owner: DoctorDaemonOwner;
4
+ ownerId: string;
5
+ generation: number;
6
+ incarnation: string;
7
+ }
8
+ export interface DoctorDaemonOccupancy {
9
+ attached: number;
10
+ inflight: number;
11
+ inbound: number;
12
+ outbound: number;
13
+ cleanup: number;
14
+ }
15
+ export interface DoctorDaemonStatus extends DoctorDaemonIdentity {
16
+ requestId: string;
17
+ phase: "idle" | "prepared" | "committed" | "cancelled" | "expired";
18
+ admitting: boolean;
19
+ occupancy: DoctorDaemonOccupancy;
20
+ leaseExpiresAt: number;
21
+ }
22
+ export interface DoctorDaemonControlRequest extends DoctorDaemonIdentity {
23
+ version: 1;
24
+ requestId: string;
25
+ action: "prepare" | "commit" | "cancel" | "status";
26
+ createdAt: number;
27
+ leaseExpiresAt?: number;
28
+ }
29
+ export declare function doctorDaemonOccupancyEmpty(): DoctorDaemonOccupancy;
30
+ /**
31
+ * True only when every named occupancy category is an explicit, valid,
32
+ * zero-valued integer. An empty object, a partial object, or an object with
33
+ * extra/malformed keys is never vacuously "settled" — `Object.values({}).
34
+ * every(...)` was previously `true` for `{}` because there is nothing to
35
+ * iterate; this checks the exact required key set instead.
36
+ */
37
+ export declare function doctorDaemonOccupancySettled(occupancy: DoctorDaemonOccupancy | undefined): boolean;
38
+ export declare function doctorDaemonIdentityMatches(left: DoctorDaemonIdentity | undefined, right: DoctorDaemonIdentity): boolean;
39
+ export declare function isDoctorDaemonControlRequest(value: unknown): value is DoctorDaemonControlRequest;
@@ -601,6 +601,8 @@ export declare function createNotificationsExtension(api: ExtensionAPI, options?
601
601
  controller?: NotificationSessionController;
602
602
  /** Whether this host mode can own the root SDK endpoint. Default: true. */
603
603
  sdkHostModeSupported?: boolean;
604
+ /** Startup surface that owns host-level permission and lifecycle authority. */
605
+ primaryControlSurface?: "cli" | "sdk";
604
606
  /** In-memory master capability for private broker verification only. */
605
607
  masterCapability?: string;
606
608
  /** Opaque direct-role epoch this effective host may adopt. */
@@ -3,6 +3,7 @@ import type { Settings } from "../../config/settings";
3
3
  import { type NotificationProvider, type NotificationRuntime, type ProviderResolution } from "./config";
4
4
  import type { DiscordDiagnosticProvider } from "./discord-provider";
5
5
  import type { SlackDiagnosticProvider } from "./slack-provider";
6
+ import { type TelegramDaemonStopCause } from "./telegram-daemon";
6
7
  /**
7
8
  * Strip secrets from a human-facing diagnostic string. Redacts the configured
8
9
  * bot token (exact match) and any token-shaped substring so health/test details
@@ -162,6 +163,8 @@ export interface DaemonHealth {
162
163
  stopped: boolean;
163
164
  heartbeatAt: number | undefined;
164
165
  heartbeatAgeMs: number | undefined;
166
+ /** Bounded persisted stop cause; absent means this record predates diagnostics or is unknown. */
167
+ stopCause?: TelegramDaemonStopCause;
165
168
  /**
166
169
  * Session endpoints the live owner reported an OPEN socket to in its latest
167
170
  * matching heartbeat sidecar. `undefined` means the owner never published the
@@ -5,6 +5,16 @@ import { type DaemonState, type TelegramDaemonOptions } from "./telegram-daemon"
5
5
  type TelegramDaemonRunner = {
6
6
  run(): Promise<void>;
7
7
  requestStop(reason?: "reload" | "signal" | "stop"): void;
8
+ prepareDoctorRestart?(): void;
9
+ cancelDoctorRestart?(): void;
10
+ doctorOccupancy?(): {
11
+ attached: number;
12
+ inflight: number;
13
+ inbound: number;
14
+ outbound: number;
15
+ cleanup: number;
16
+ };
17
+ doctorRestartReady?(): boolean;
8
18
  };
9
19
  type TelegramDaemonConstructor = new (opts: TelegramDaemonOptions) => TelegramDaemonRunner;
10
20
  export type LightweightDaemonSettings = Pick<Settings, "get" | "getAgentDir" | "set" | "flush"> & NotificationSettingsReader;
@@ -47,6 +57,7 @@ export declare function ownerPidFromOwnerId(ownerId: string): number | undefined
47
57
  /** Creates owner-fenced daemon control hooks for the CLI lifecycle boundary. */
48
58
  export declare function createDaemonControlHooks(settings: Settings): {
49
59
  shouldStop: (owner: string) => Promise<boolean>;
60
+ requestedAction: (owner: string) => Promise<"reload" | "stop" | undefined>;
50
61
  clear: (owner: string) => Promise<void>;
51
62
  };
52
63
  export declare function runDaemonSmoke(opts?: {
@@ -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 = 181;
289
+ export declare const DAEMON_GENERATION = 187;
290
290
  /**
291
291
  * Serving-compatibility boundary for daemon lifecycle requests. Epoch 7
292
292
  * requires durable publication receipts and acknowledged attachment dispatch,
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import type { Settings } from "../../config/settings";
11
11
  import type { BuiltInDaemonController, DaemonOperationOptions, DaemonOperationResult, DaemonStatus } from "../../daemon/control-types";
12
+ import { type DoctorDaemonControlRequest } from "./doctor-daemon-restart";
12
13
  import { type TelegramDaemonDeps, type TelegramDaemonFs } from "./telegram-daemon";
13
14
  export interface TelegramDaemonControlRequest {
14
15
  version: 1;
@@ -19,6 +20,10 @@ export interface TelegramDaemonControlRequest {
19
20
  createdAt: number;
20
21
  }
21
22
  export declare function telegramControlRequestPath(agentDir: string): string;
23
+ export declare function telegramDoctorControlRequestPath(agentDir: string): string;
24
+ export declare function readTelegramDoctorControlRequest(settings: Settings, fsImpl?: TelegramDaemonFs): Promise<DoctorDaemonControlRequest | undefined>;
25
+ export declare function writeTelegramDoctorControlRequest(settings: Settings, request: DoctorDaemonControlRequest, fsImpl?: TelegramDaemonFs): Promise<void>;
26
+ export declare function clearTelegramDoctorControlRequest(settings: Settings, requestId?: string, fsImpl?: TelegramDaemonFs): Promise<void>;
22
27
  export declare function readTelegramControlRequest(settings: Settings, fsImpl?: TelegramDaemonFs): Promise<TelegramDaemonControlRequest | undefined>;
23
28
  export declare function writeTelegramControlRequest(settings: Settings, request: TelegramDaemonControlRequest, fsImpl?: TelegramDaemonFs): Promise<void>;
24
29
  export declare function clearTelegramControlRequest(settings: Settings, requestId?: string, fsImpl?: TelegramDaemonFs): Promise<void>;
@@ -10,6 +10,7 @@ export interface TelegramOwnerMarker {
10
10
  createdAt: number;
11
11
  startedAt: number;
12
12
  }
13
+ export declare function validMarker(value: unknown): value is TelegramOwnerMarker;
13
14
  export declare function writeTelegramOwnerMarker(fsImpl: TelegramDaemonFs, agentDir: string, marker: TelegramOwnerMarker): Promise<void>;
14
15
  export declare function removeTelegramOwnerMarker(fsImpl: TelegramDaemonFs, agentDir: string, acquisitionId: string): Promise<void>;
15
16
  export declare function readTelegramOwnerMarker(fsImpl: TelegramDaemonFs, agentDir: string, acquisitionId: string): Promise<TelegramOwnerMarker | undefined>;
@@ -3,6 +3,7 @@ import { type NativeExactFileIdentity, type NativeExactUnlinkResult } from "@gaj
3
3
  import type { Settings } from "../../config/settings";
4
4
  import type { DaemonRuntimeInfo } from "../../daemon/control-types";
5
5
  import { HEARTBEAT_TTL_MS } from "./daemon-paths";
6
+ import { type DoctorDaemonOccupancy } from "./doctor-daemon-restart";
6
7
  import { type DaemonTransitionLock, type NotificationEndpointFile, type NotificationEndpointFileIdentity, type NotificationExactUnlinkResult } from "./notification-service";
7
8
  import { type DaemonProcessReference } from "./telegram-daemon-control";
8
9
  import { type TelegramSetupPreflight } from "./telegram-setup";
@@ -17,6 +18,9 @@ export type EnsureDaemonResult = "owner_spawned" | "attached" | "disabled" | "bl
17
18
  /** Detailed result for orchestration that must distinguish a #2028 handoff from a fresh spawn. */
18
19
  export type EnsureTelegramDaemonDetailedResult = "spawned" | "reloaded" | "attached" | "disabled" | "blocked_identity";
19
20
  export type TelegramDaemonOwnershipPhase = "provisional" | "ready" | "retired";
21
+ /** Closed vocabulary for the durable reason an owner stopped serving. */
22
+ export type TelegramDaemonStopCause = "stop" | "reload" | "signal" | "idle_timeout" | "ownership_loss" | "startup_failed" | "unexpected_exception" | "postmortem";
23
+ export declare function isTelegramDaemonStopCause(value: unknown): value is TelegramDaemonStopCause;
20
24
  export interface DaemonState {
21
25
  pid: number;
22
26
  /** OS process-start provenance; mandatory for PID-authorized ownership actions. */
@@ -45,6 +49,8 @@ export interface DaemonState {
45
49
  /** Lifecycle-serving compatibility epoch; absent pre-epoch records are epoch 1. */
46
50
  servingEpoch?: number;
47
51
  stoppedAt?: number;
52
+ /** Bounded, secret-free explanation for a stopped owner; absent on legacy/unknown records. */
53
+ stopCause?: TelegramDaemonStopCause;
48
54
  }
49
55
  interface ExactFileStat {
50
56
  dev: bigint;
@@ -476,6 +482,7 @@ export declare function releaseDaemonOwnership(input: {
476
482
  pidIncarnation?: (pid: number) => string | undefined;
477
483
  fs?: TelegramDaemonFs;
478
484
  now?: () => number;
485
+ stopCause?: TelegramDaemonStopCause;
479
486
  }): Promise<void>;
480
487
  /**
481
488
  * Record that this owner's process is gone, without claiming a clean handoff.
@@ -487,9 +494,9 @@ export declare function releaseDaemonOwnership(input: {
487
494
  * `ownershipPhase: "ready"` and a fresh-looking lock behind forever, so later
488
495
  * readers attached to an owner that had not existed for hours.
489
496
  *
490
- * This writes `stoppedAt` and nothing else. The lock is left in place for the
491
- * existing reclaim path to adjudicate, because a process on its way out is the
492
- * least qualified party to decide who owns what next.
497
+ * This writes `stoppedAt` and a closed-vocabulary `stopCause`. The lock is left
498
+ * in place for the existing reclaim path to adjudicate, because a process on
499
+ * its way out is the least qualified party to decide who owns what next.
493
500
  *
494
501
  * Fenced on full owner identity: if the state no longer names this exact
495
502
  * owner, acquisition, pid and incarnation, a successor already took over and
@@ -686,6 +693,12 @@ export declare class TelegramEventDispatchState {
686
693
  export interface DaemonControlHooks {
687
694
  /** Returns true when a stop/reload has been requested for this owner. */
688
695
  shouldStop(ownerId: string): Promise<boolean>;
696
+ /**
697
+ * Returns the owner-fenced action behind `shouldStop`, when the control
698
+ * plane can provide one. This is a diagnostic projection, not an alternate
699
+ * stop authority: callers must still gate it behind `shouldStop`.
700
+ */
701
+ requestedAction?(ownerId: string): Promise<"reload" | "stop" | undefined>;
689
702
  /** Clear a consumed control request (best-effort). */
690
703
  clear?(ownerId: string): Promise<void>;
691
704
  }
@@ -900,9 +913,27 @@ export declare class TelegramNotificationDaemon {
900
913
  /**
901
914
  * Cooperatively stop the daemon: set the stop flag and abort the in-flight
902
915
  * long poll so the run loop wakes immediately instead of waiting out the
903
- * ~25s getUpdates timeout. Safe to call from a signal handler.
916
+ * ~25s getUpdates timeout. Safe to call from a signal handler. The
917
+ * no-argument form is the generic finally fallback and never overwrites a
918
+ * previously observed specific cause.
919
+ */
920
+ requestStop(reason?: TelegramDaemonStopCause): void;
921
+ /** Doctor reservation hook: stop admitting new provider work without killing the owner. Synchronous fence; returns a real acknowledgement. */
922
+ prepareDoctorRestart(): boolean;
923
+ /**
924
+ * Real occupancy read from the live runtime structures the daemon actually
925
+ * uses, not synthetic zeros. `inflight` is turns currently executing;
926
+ * `inbound` is inbound work accepted but not yet resolved (pending /btw
927
+ * turns, topic-adoption session_create dispatches in flight, and inbound
928
+ * reaction acks not yet terminal); `outbound` is the real rate-limit pool
929
+ * backlog plus terminal /btw deliveries still in flight; `cleanup` counts
930
+ * only genuinely outstanding cleanup — non-completed cleanup receipts plus
931
+ * live archive/compensation fences — never a completed receipt or an
932
+ * unrelated rejected-topic notice timer.
904
933
  */
905
- requestStop(_reason?: "reload" | "stop" | "signal"): void;
934
+ doctorOccupancy(): DoctorDaemonOccupancy;
935
+ doctorRestartReady(): boolean;
936
+ cancelDoctorRestart(): void;
906
937
  /** Handle a paired-chat /session_* command through the SDK lifecycle service. */
907
938
  private handleLifecycleCommand;
908
939
  private refreshBotIdentity;
@@ -24,6 +24,7 @@ export interface SdkSessionCliArgs {
24
24
  strict?: boolean;
25
25
  untilIdle?: boolean;
26
26
  allEvents?: boolean;
27
+ page?: boolean;
27
28
  repo?: string;
28
29
  scope?: string;
29
30
  limit?: number;
@@ -211,6 +211,8 @@ export interface CreateSdkSessionRuntimeOptions {
211
211
  brokerRegistrationRequired?: boolean;
212
212
  /** Trusted broker-issued lifecycle marker bound to lifecycle host index events. */
213
213
  lifecycleRequestId?: string;
214
+ /** Startup surface that owns host-level permission and lifecycle authority. */
215
+ primaryControlSurface?: "cli" | "sdk";
214
216
  createTransport(input: {
215
217
  sessionId: string;
216
218
  stateRoot: string;
@@ -306,6 +308,8 @@ export interface SdkSurfaceFactoryOptions {
306
308
  ctx: ExtensionContext;
307
309
  id: string;
308
310
  api: ExtensionAPI;
311
+ /** Startup surface that owns host-level permission and lifecycle authority. */
312
+ primaryControlSurface?: "cli" | "sdk";
309
313
  policy?: SdkSurfacePolicy;
310
314
  getInstalledDefinitions?: (capability: string) => unknown | undefined;
311
315
  getLiveState?: () => {
@@ -15,7 +15,9 @@ export interface SdkCapabilities {
15
15
  operations: string[];
16
16
  hostTools: boolean;
17
17
  promptTerminalOutcomeVersion: 1;
18
+ /** Startup surface that owns host-level permission and lifecycle authority. */
19
+ primaryControlSurface: "cli" | "sdk";
18
20
  }
19
- export declare function createSdkCapabilities(policy: SdkSurfacePolicy, hostTools?: boolean): SdkCapabilities;
21
+ export declare function createSdkCapabilities(policy: SdkSurfacePolicy, hostTools?: boolean, primaryControlSurface?: SdkCapabilities["primaryControlSurface"]): SdkCapabilities;
20
22
  /** Derive the shared policy from an extension context without importing adapters. */
21
23
  export declare function createSdkSurfacePolicyForContext(ctx: ExtensionContext, workflowGateAvailable?: boolean): SdkSurfacePolicy;
@@ -1,5 +1,9 @@
1
1
  import { type ScopeRequestV1, type SdkSearchResultV1 } from "../broker/session-scope";
2
- export type SessionLifecycleOperation = "session.create" | "session.fork" | "session.resume" | "session.close" | "session.delete" | "session.reconcile_uncertain" | "session.list";
2
+ import type { SessionBindingAuthority } from "../session-authority";
3
+ export type { SessionBindingAuthority, SessionEndpointAuthority } from "../session-authority";
4
+ export type SessionLifecycleOperation = "session.create" | "session.fork" | "session.resume" | "session.close" | "session.delete" | "session.reconcile_uncertain" | "session.lookup" | "session.list";
5
+ export type SessionLifecycleMutationOperation = Exclude<SessionLifecycleOperation, "session.lookup" | "session.list">;
6
+ export type SessionLifecycleLookupOperation = "session.create";
3
7
  export interface SessionLifecycleActor {
4
8
  readonly id: string;
5
9
  readonly namespace: string;
@@ -80,11 +84,11 @@ export type SessionResumeTarget = SessionLifecycleCoordinatorTarget & {
80
84
  readonly worktree?: SessionLifecycleWorktreeTarget;
81
85
  readonly readinessTimeoutMs?: number;
82
86
  };
83
- export interface SessionCloseTarget {
87
+ export type SessionCloseTarget = {
84
88
  readonly sessionId: string;
85
- readonly endpointGeneration?: number;
86
- readonly endpointIncarnation?: string;
87
- }
89
+ readonly endpointGeneration?: never;
90
+ readonly endpointIncarnation?: never;
91
+ } | SessionBindingAuthority;
88
92
  export interface SessionReconcileUncertainTarget {
89
93
  readonly sessionId: string;
90
94
  readonly cwd: string;
@@ -109,7 +113,7 @@ export interface SessionListTarget {
109
113
  readonly limit?: number;
110
114
  readonly cursor?: string;
111
115
  }
112
- interface SessionLifecycleMutationRequestBase<TOperation extends Exclude<SessionLifecycleOperation, "session.list">, TTarget> {
116
+ interface SessionLifecycleMutationRequestBase<TOperation extends SessionLifecycleMutationOperation, TTarget> {
113
117
  readonly operation: TOperation;
114
118
  readonly actor: SessionLifecycleActor;
115
119
  readonly capability: TOperation;
@@ -130,7 +134,15 @@ export interface SessionListRequest {
130
134
  readonly target?: SessionListTarget;
131
135
  readonly timeoutMs?: number;
132
136
  }
133
- export type SessionLifecycleRequest = SessionLifecycleMutationRequest | SessionListRequest;
137
+ export interface SessionLifecycleLookupRequest {
138
+ readonly operation: SessionLifecycleLookupOperation;
139
+ readonly actor: SessionLifecycleActor;
140
+ readonly capability: "session.lookup";
141
+ readonly requestKey: string;
142
+ readonly target: Readonly<Record<string, unknown>>;
143
+ readonly timeoutMs?: number;
144
+ }
145
+ export type SessionLifecycleRequest = SessionLifecycleMutationRequest | SessionListRequest | SessionLifecycleLookupRequest;
134
146
  export type SessionLifecycleMutationRequest = SessionCreateRequest | SessionForkRequest | SessionResumeRequest | SessionCloseRequest | SessionDeleteRequest | SessionReconcileUncertainRequest;
135
147
  export type SessionLifecycleCertainty = "terminal" | "retryable" | "cleanup_pending" | "uncertain";
136
148
  export interface SessionLifecycleSessionResult {
@@ -145,6 +157,7 @@ export interface SessionLifecycleListEntry {
145
157
  readonly sessionId: string;
146
158
  readonly live?: boolean;
147
159
  readonly endpointGeneration?: number;
160
+ readonly endpointIncarnation?: string;
148
161
  readonly terminalUncertain?: boolean;
149
162
  readonly cwd?: string;
150
163
  readonly locator?: {
@@ -195,6 +208,26 @@ export interface SessionListSuccessResult {
195
208
  readonly operation: "session.list";
196
209
  readonly result: SessionLifecycleListResult | SessionScopedListResult;
197
210
  }
211
+ export interface SessionLifecycleLookupIdentity {
212
+ readonly operation: SessionLifecycleLookupOperation;
213
+ readonly requestKey: string;
214
+ }
215
+ export type SessionLifecycleLookupStatus = "found" | "pending" | "not_found" | "conflict" | "uncertain" | "terminal";
216
+ export interface SessionLifecycleLookupSuccessResult {
217
+ readonly ok: true;
218
+ readonly operation: "session.lookup";
219
+ readonly status: "found";
220
+ readonly request: SessionLifecycleLookupIdentity;
221
+ readonly result: SessionLifecycleSessionResult;
222
+ }
223
+ export interface SessionLifecycleLookupFailure {
224
+ readonly ok: false;
225
+ readonly operation: "session.lookup";
226
+ readonly status: Exclude<SessionLifecycleLookupStatus, "found"> | "unavailable";
227
+ readonly request: SessionLifecycleLookupIdentity;
228
+ readonly certainty: SessionLifecycleCertainty;
229
+ readonly error: SessionLifecycleError;
230
+ }
198
231
  export interface SessionLifecycleError {
199
232
  readonly code: string;
200
233
  readonly message: string;
@@ -249,11 +282,12 @@ export type SessionCloseOutcome = SessionCloseResult | SessionCloseFailure;
249
282
  export type SessionDeleteOutcome = SessionDeleteResult | SessionDeleteFailure;
250
283
  export type SessionReconcileUncertainOutcome = SessionReconcileUncertainResult | SessionReconcileUncertainFailure;
251
284
  export type SessionListOutcome = SessionListSuccessResult | SessionListFailure;
252
- export type SessionLifecycleResult = SessionCreateOutcome | SessionForkOutcome | SessionResumeOutcome | SessionCloseOutcome | SessionDeleteOutcome | SessionReconcileUncertainOutcome | SessionListOutcome;
285
+ export type SessionLifecycleLookupOutcome = SessionLifecycleLookupSuccessResult | SessionLifecycleLookupFailure;
286
+ export type SessionLifecycleResult = SessionCreateOutcome | SessionForkOutcome | SessionResumeOutcome | SessionCloseOutcome | SessionDeleteOutcome | SessionReconcileUncertainOutcome | SessionListOutcome | SessionLifecycleLookupOutcome;
253
287
  /** Shared, side-effect-free validation for lifecycle mutation requests. */
254
288
  export type SessionLifecycleMutationValidation = {
255
289
  readonly ok: true;
256
- readonly operation: Exclude<SessionLifecycleOperation, "session.list">;
290
+ readonly operation: SessionLifecycleMutationOperation;
257
291
  readonly actor: SessionLifecycleActor;
258
292
  readonly requestKey: string;
259
293
  readonly target: Readonly<Record<string, unknown>>;
@@ -266,6 +300,7 @@ export declare function validateSessionLifecycleMutationRequest(request: unknown
266
300
  export declare class SessionLifecycleService {
267
301
  #private;
268
302
  constructor(client: SessionLifecycleClient);
303
+ lookup(request: SessionLifecycleLookupRequest): Promise<SessionLifecycleLookupOutcome>;
269
304
  scopedList(scope: ScopeRequestV1, limit?: number, cursor?: string): Promise<SessionListOutcome>;
270
305
  execute(request: SessionLifecycleMutationRequest, idempotencyKeyOverride?: string): Promise<SessionCreateOutcome | SessionForkOutcome | SessionResumeOutcome | SessionCloseOutcome | SessionDeleteOutcome | SessionReconcileUncertainOutcome>;
271
306
  executeWithIdempotencyKey(request: SessionLifecycleMutationRequest, idempotencyKey: string): Promise<SessionCreateOutcome | SessionForkOutcome | SessionResumeOutcome | SessionCloseOutcome | SessionDeleteOutcome | SessionReconcileUncertainOutcome>;
@@ -277,4 +312,3 @@ export declare class SessionLifecycleService {
277
312
  reconcileUncertain(request: Omit<SessionReconcileUncertainRequest, "operation">): Promise<SessionReconcileUncertainOutcome>;
278
313
  list(request: Omit<SessionListRequest, "operation">): Promise<SessionListOutcome>;
279
314
  }
280
- export {};
@@ -38,8 +38,11 @@ export declare function promptDeadlineAt(lease: PromptDeadlineLease): number;
38
38
  export declare function recordAttributableProgress(lease: PromptDeadlineLease, now: number): void;
39
39
  /**
40
40
  * Whether an agent session event at the prompt/agent runtime boundary is
41
- * attributable progress for the accepted prompt. Only tool execution
42
- * boundaries qualify: skills do their work through tools, so skill progress is
43
- * covered; streaming text/thinking deltas, retries, and bookkeeping are not.
41
+ * attributable progress for the accepted prompt. Tool execution boundaries and
42
+ * streaming updates qualify: skills do their work through tools, so skill
43
+ * progress is covered; `tool_execution_update` keeps long-running tools (e.g.
44
+ * a multi-minute Gradle compile that streams stdout) from tripping the
45
+ * inactivity deadline mid-run. Streaming text/thinking deltas, retries, and
46
+ * bookkeeping are not attributable.
44
47
  */
45
48
  export declare function isAttributableProgressEventType(type: string): boolean;
@@ -3,10 +3,10 @@ import type { InvocationCorrelation, InvocationReconciliation } from "./host/ses
3
3
  import type { SdkPromptTerminalOutcome } from "./prompt-status";
4
4
  import type { TurnResultContent } from "./turn-result";
5
5
  type DeadlineReconciliation = InvocationReconciliation | KindAwareReconciliation;
6
- export type PromptDeadlineOutcome = {
6
+ export type PromptDeadlineOutcome = Extract<SdkPromptTerminalOutcome, {
7
7
  kind: "failed";
8
+ }> & {
8
9
  code: "prompt_deadline_exceeded";
9
- message: string;
10
10
  provenance: "deadline";
11
11
  };
12
12
  export interface PromptTerminalTransitionEvidence {
@@ -3,7 +3,54 @@
3
3
  * Provider error text is retained only in the local diagnostic log; wire and
4
4
  * persisted reconciliation details expose a fixed redacted message.
5
5
  */
6
+ import type { SdkPromptFailureCategory, SdkPromptFailurePhase, SdkPromptTerminalOutcome } from "./prompt-status";
6
7
  export declare const PROMPT_FAILURE_CODE_MAX = 64;
8
+ export declare const PROMPT_FAILURE_MESSAGE_SUBMISSION = "Prompt submission failed.";
9
+ export declare const PROMPT_FAILURE_MESSAGE_POST_START_PROVIDER = "Provider failure after execution started.";
10
+ export declare const PROMPT_FAILURE_MESSAGE_POST_START_AGENT = "Agent run failed after execution started.";
11
+ export declare const PROMPT_FAILURE_MESSAGE_DEADLINE = "Prompt deadline exceeded.";
12
+ /** Evidence that decides whether a failure happened before or after the run started. */
13
+ export interface PromptFailureEvidence {
14
+ startedAt?: number;
15
+ hasActivity?: boolean;
16
+ }
17
+ /** Start/activity evidence for phase derivation from a reconciliation record. */
18
+ export declare function failureEvidence(record: {
19
+ startedAt?: number;
20
+ }, hasActivity?: boolean): PromptFailureEvidence;
21
+ /** Whether the run had already started when the failure was recorded. */
22
+ export declare function promptFailurePhase(evidence: PromptFailureEvidence): SdkPromptFailurePhase;
23
+ export declare function isSdkPromptFailurePhase(value: unknown): value is SdkPromptFailurePhase;
24
+ /** Allowlisted origin category for a bounded safe classifier + provenance. */
25
+ export declare function promptFailureCategory(code: string | undefined, provenance: "agent_failed" | "deadline"): SdkPromptFailureCategory;
26
+ /**
27
+ * Phase- and category-aware safe wording. A post-start failure is never
28
+ * described as a submission rejection; the wording says only what the bounded
29
+ * category actually proves.
30
+ */
31
+ export declare function promptFailureMessage(phase: SdkPromptFailurePhase, category: SdkPromptFailureCategory): string;
32
+ /**
33
+ * Recompute `phase`, `category` and `message` for a failed outcome from the
34
+ * bounded classifier plus the record's start/activity evidence. Non-failed
35
+ * outcomes pass through untouched. Idempotent.
36
+ */
37
+ export declare function rephaseFailedOutcome(outcome: SdkPromptTerminalOutcome, evidence: PromptFailureEvidence): SdkPromptTerminalOutcome;
38
+ /** Build a complete failed outcome from a bounded classifier and evidence. */
39
+ export declare function failedPromptOutcome(input: {
40
+ code: "prompt_failed" | "prompt_deadline_exceeded";
41
+ provenance: "agent_failed" | "deadline";
42
+ providerCode?: string;
43
+ phase?: SdkPromptFailurePhase;
44
+ evidence: PromptFailureEvidence;
45
+ }): Extract<SdkPromptTerminalOutcome, {
46
+ kind: "failed";
47
+ }>;
48
+ /**
49
+ * Bounded safe classifier read off a terminal assistant message: the provider's
50
+ * own `errorCode`, else the typed transport fact's `providerCode`. Only a safe
51
+ * token is accepted; anything else is dropped rather than forwarded.
52
+ */
53
+ export declare function assistantFailureCode(assistant: unknown): string | undefined;
7
54
  /** Safe-token code capped at 64; arbitrary failure text is never retained. */
8
55
  export declare function sanitizePromptFailure(error: unknown): {
9
56
  code: string;
@@ -52,6 +52,19 @@ import type { ReceiptState } from "./receipt-state";
52
52
  export type PromptReconciliationStatus = "accepted" | "in_flight" | "terminal_ok" | "failed";
53
53
  export type SdkPromptStopReason = "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled";
54
54
  export type SdkPromptFailureCode = "prompt_failed" | "prompt_deadline_exceeded";
55
+ /**
56
+ * Stable, safe execution phase of a failed prompt. `submission` means the
57
+ * failure happened before the run started (a genuine submission rejection);
58
+ * `post_start` means the run had already started, so it must never be described
59
+ * as a submission rejection.
60
+ */
61
+ export type SdkPromptFailurePhase = "submission" | "post_start";
62
+ /**
63
+ * Allowlisted, bounded origin category for a failed prompt. It is derived only
64
+ * from safe classifiers (never raw provider text) and preserves `unknown` when
65
+ * attribution is uncertain instead of guessing.
66
+ */
67
+ export type SdkPromptFailureCategory = "provider_transport" | "provider_rejected" | "agent_runtime" | "deadline" | "unknown";
55
68
  export type SdkPromptTerminalOutcome = {
56
69
  kind: "stopped";
57
70
  reason: SdkPromptStopReason;
@@ -61,6 +74,12 @@ export type SdkPromptTerminalOutcome = {
61
74
  code: SdkPromptFailureCode;
62
75
  message: string;
63
76
  provenance: "agent_failed" | "deadline";
77
+ /** Execution phase at failure time; never a submission rejection when post_start. */
78
+ phase: SdkPromptFailurePhase;
79
+ /** Bounded failure-origin category; `unknown` when attribution is uncertain. */
80
+ category: SdkPromptFailureCategory;
81
+ /** Bounded safe provider/transport classifier when the provider supplied one. */
82
+ providerCode?: string;
64
83
  };
65
84
  /** Exactly one selector per lookup. */
66
85
  export type TurnPromptStatusSelector = {
@@ -1,6 +1,8 @@
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
+ import type { SessionBindingAuthority } from "../session-authority";
5
+ export type { SessionBindingAuthority, SessionEndpointAuthority } from "../session-authority";
4
6
  export interface SessionEndpointIdentity {
5
7
  readonly dev: bigint;
6
8
  readonly mtimeMs: number;
@@ -216,10 +218,7 @@ export declare class SessionRouter {
216
218
  dispatchFence?: (dispatch: () => Promise<Record<string, unknown>>) => Promise<Record<string, unknown>>;
217
219
  }): Promise<Record<string, unknown>>;
218
220
  /** Resolves the exact provider-neutral binding authority for operator adoption. */
219
- bindingAuthority(sessionId: string): Promise<{
220
- sessionId: string;
221
- endpointGeneration: number;
222
- } | undefined>;
221
+ bindingAuthority(sessionId: string): Promise<SessionBindingAuthority | undefined>;
223
222
  /**
224
223
  * Reconciles one exact endpoint generation without exposing endpoint or process
225
224
  * credentials. Retirement is returned only from a retained positive terminal
@@ -0,0 +1,16 @@
1
+ /** Shared path names; importing this module never initializes a service. */
2
+ export declare const BROKER_ARTIFACT_PATHS: {
3
+ readonly discovery: "sdk/broker.json";
4
+ readonly ownerLock: "sdk/broker.lock";
5
+ readonly ownerRecord: "sdk/broker.lock/owner.json";
6
+ readonly restartIntent: "sdk/broker.restart.json";
7
+ };
8
+ /** Existing-root identity only; never creates a directory or identity file. */
9
+ export declare function canonicalServiceRootDigest(agentDir: string): Promise<string>;
10
+ export declare const DOCTOR_RESTART_CONTROL_FILE = "doctor-restart.control.json";
11
+ export declare const CHAT_DAEMON_DIRECTORY = "sdk/daemons";
12
+ export declare const CHAT_DAEMON_FILES: {
13
+ readonly ownerLock: "owner.lock";
14
+ readonly state: "state.json";
15
+ readonly control: "control.json";
16
+ };
@@ -0,0 +1,9 @@
1
+ /** Exact endpoint authority captured from a verified SDK session binding. */
2
+ export interface SessionEndpointAuthority {
3
+ readonly endpointGeneration: number;
4
+ readonly endpointIncarnation: string;
5
+ }
6
+ /** Session identity plus the endpoint authority bound to that exact session. */
7
+ export interface SessionBindingAuthority extends SessionEndpointAuthority {
8
+ readonly sessionId: string;
9
+ }
@@ -137,7 +137,9 @@ export interface CreateAgentSessionOptions {
137
137
  /** Disable extension discovery (explicit paths still load). */
138
138
  disableExtensionDiscovery?: boolean;
139
139
  /**
140
- * Pre-loaded extensions (skips file discovery).
140
+ * Pre-loaded extensions (skips file discovery). A COMPLETE result is required:
141
+ * the session reuses its live `runtime`, so a partial result dereferences a
142
+ * missing runtime instead of degrading.
141
143
  * @internal Used by CLI when extensions are loaded early to parse custom flags.
142
144
  */
143
145
  preloadedExtensions?: LoadExtensionsResult;
@@ -300,7 +300,7 @@ export interface AgentSessionConfig {
300
300
  discoveryMode?: "off" | "mcp-only" | "all";
301
301
  /** MCP tool names to activate for the current session when discovery mode is enabled. */
302
302
  initialSelectedMCPToolNames?: string[];
303
- /** Keep persisted MCP names until a deferred exact catalog becomes available. */
303
+ /** Keep persisted MCP names until a deferred (exact or conventional) catalog becomes available. */
304
304
  preserveUnavailableInitialMCPToolSelection?: boolean;
305
305
  /** Built-in discoverable tool names restored for the current all-discovery session. */
306
306
  initialSelectedDiscoveredBuiltinToolNames?: string[];
@@ -124,7 +124,7 @@ export declare class MemoryBlobStore extends BlobStore {
124
124
  #private;
125
125
  constructor(options?: MemoryBlobStoreOptions);
126
126
  put(data: Buffer): Promise<BlobPutResult>;
127
- putSync(data: Buffer): BlobPutResult;
127
+ putSync(data: Buffer, ownership?: typeof TAKE_BLOB_BUFFER_OWNERSHIP): BlobPutResult;
128
128
  putImmutableSync(data: Buffer): CheckedBlobPutResult;
129
129
  get(hash: string): Promise<Buffer | null>;
130
130
  getSync(hash: string): Buffer | null;