@aexol/spectral 0.8.2 → 0.8.5

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 (523) hide show
  1. package/CHANGELOG.md +82 -55
  2. package/README.md +80 -82
  3. package/dist/agent/agents.d.ts +37 -0
  4. package/dist/agent/agents.d.ts.map +1 -0
  5. package/dist/agent/index.d.ts +29 -0
  6. package/dist/agent/index.d.ts.map +1 -0
  7. package/dist/cli.d.ts +17 -0
  8. package/dist/cli.d.ts.map +1 -0
  9. package/dist/commands/bind.d.ts +12 -0
  10. package/dist/commands/bind.d.ts.map +1 -0
  11. package/dist/commands/login-oauth.d.ts +15 -0
  12. package/dist/commands/login-oauth.d.ts.map +1 -0
  13. package/dist/commands/login.d.ts +37 -0
  14. package/dist/commands/login.d.ts.map +1 -0
  15. package/dist/commands/logout.d.ts +8 -0
  16. package/dist/commands/logout.d.ts.map +1 -0
  17. package/dist/commands/serve.d.ts +112 -0
  18. package/dist/commands/serve.d.ts.map +1 -0
  19. package/dist/commands/unbind.d.ts +8 -0
  20. package/dist/commands/unbind.d.ts.map +1 -0
  21. package/dist/config.d.ts +49 -0
  22. package/dist/config.d.ts.map +1 -0
  23. package/dist/designer/guidelines.d.ts +23 -0
  24. package/dist/designer/guidelines.d.ts.map +1 -0
  25. package/dist/designer/index.d.ts +26 -0
  26. package/dist/designer/index.d.ts.map +1 -0
  27. package/dist/designer/philosophies.d.ts +33 -0
  28. package/dist/designer/philosophies.d.ts.map +1 -0
  29. package/dist/designer/skills.d.ts +27 -0
  30. package/dist/designer/skills.d.ts.map +1 -0
  31. package/dist/designer/systems.d.ts +36 -0
  32. package/dist/designer/systems.d.ts.map +1 -0
  33. package/dist/extensions/aexol-mcp.d.ts +25 -0
  34. package/dist/extensions/aexol-mcp.d.ts.map +1 -0
  35. package/dist/extensions/kanban-bridge.d.ts +24 -0
  36. package/dist/extensions/kanban-bridge.d.ts.map +1 -0
  37. package/dist/extensions/openrouter-attribution.d.ts +12 -0
  38. package/dist/extensions/openrouter-attribution.d.ts.map +1 -0
  39. package/dist/extensions/spectral-vision-fallback.d.ts +23 -0
  40. package/dist/extensions/spectral-vision-fallback.d.ts.map +1 -0
  41. package/dist/extensions/spectral-vision-fallback.js +29 -20
  42. package/dist/index.d.ts +46 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +44 -0
  45. package/dist/mcp/agent-dir.d.ts +3 -0
  46. package/dist/mcp/agent-dir.d.ts.map +1 -0
  47. package/dist/mcp/commands.d.ts +9 -0
  48. package/dist/mcp/commands.d.ts.map +1 -0
  49. package/dist/mcp/config.d.ts +78 -0
  50. package/dist/mcp/config.d.ts.map +1 -0
  51. package/dist/mcp/consent-manager.d.ts +14 -0
  52. package/dist/mcp/consent-manager.d.ts.map +1 -0
  53. package/dist/mcp/direct-tools.d.ts +11 -0
  54. package/dist/mcp/direct-tools.d.ts.map +1 -0
  55. package/dist/mcp/errors.d.ts +100 -0
  56. package/dist/mcp/errors.d.ts.map +1 -0
  57. package/dist/mcp/glimpse-ui.d.ts +10 -0
  58. package/dist/mcp/glimpse-ui.d.ts.map +1 -0
  59. package/dist/mcp/host-html-template.d.ts +17 -0
  60. package/dist/mcp/host-html-template.d.ts.map +1 -0
  61. package/dist/mcp/index.d.ts +3 -0
  62. package/dist/mcp/index.d.ts.map +1 -0
  63. package/dist/mcp/init.d.ts +10 -0
  64. package/dist/mcp/init.d.ts.map +1 -0
  65. package/dist/mcp/lifecycle.d.ts +30 -0
  66. package/dist/mcp/lifecycle.d.ts.map +1 -0
  67. package/dist/mcp/logger.d.ts +52 -0
  68. package/dist/mcp/logger.d.ts.map +1 -0
  69. package/dist/mcp/mcp-auth-flow.d.ts +69 -0
  70. package/dist/mcp/mcp-auth-flow.d.ts.map +1 -0
  71. package/dist/mcp/mcp-auth.d.ts +100 -0
  72. package/dist/mcp/mcp-auth.d.ts.map +1 -0
  73. package/dist/mcp/mcp-callback-server.d.ts +40 -0
  74. package/dist/mcp/mcp-callback-server.d.ts.map +1 -0
  75. package/dist/mcp/mcp-oauth-provider.d.ts +101 -0
  76. package/dist/mcp/mcp-oauth-provider.d.ts.map +1 -0
  77. package/dist/mcp/metadata-cache.d.ts +32 -0
  78. package/dist/mcp/metadata-cache.d.ts.map +1 -0
  79. package/dist/mcp/npx-resolver.d.ts +7 -0
  80. package/dist/mcp/npx-resolver.d.ts.map +1 -0
  81. package/dist/mcp/oauth-handler.d.ts +19 -0
  82. package/dist/mcp/oauth-handler.d.ts.map +1 -0
  83. package/dist/mcp/onboarding-state.d.ts +13 -0
  84. package/dist/mcp/onboarding-state.d.ts.map +1 -0
  85. package/dist/mcp/proxy-modes.d.ts +12 -0
  86. package/dist/mcp/proxy-modes.d.ts.map +1 -0
  87. package/dist/mcp/resource-tools.d.ts +2 -0
  88. package/dist/mcp/resource-tools.d.ts.map +1 -0
  89. package/dist/mcp/sampling-handler.d.ts +16 -0
  90. package/dist/mcp/sampling-handler.d.ts.map +1 -0
  91. package/dist/mcp/server-manager.d.ts +42 -0
  92. package/dist/mcp/server-manager.d.ts.map +1 -0
  93. package/dist/mcp/state.d.ts +41 -0
  94. package/dist/mcp/state.d.ts.map +1 -0
  95. package/dist/mcp/tool-metadata.d.ts +11 -0
  96. package/dist/mcp/tool-metadata.d.ts.map +1 -0
  97. package/dist/mcp/tool-registrar.d.ts +9 -0
  98. package/dist/mcp/tool-registrar.d.ts.map +1 -0
  99. package/dist/mcp/types.d.ts +263 -0
  100. package/dist/mcp/types.d.ts.map +1 -0
  101. package/dist/mcp/ui-resource-handler.d.ts +10 -0
  102. package/dist/mcp/ui-resource-handler.d.ts.map +1 -0
  103. package/dist/mcp/ui-server.d.ts +37 -0
  104. package/dist/mcp/ui-server.d.ts.map +1 -0
  105. package/dist/mcp/ui-session.d.ts +27 -0
  106. package/dist/mcp/ui-session.d.ts.map +1 -0
  107. package/dist/mcp/ui-stream-types.d.ts +197 -0
  108. package/dist/mcp/ui-stream-types.d.ts.map +1 -0
  109. package/dist/mcp/utils.d.ts +17 -0
  110. package/dist/mcp/utils.d.ts.map +1 -0
  111. package/dist/mcp/vitest.config.d.ts +3 -0
  112. package/dist/mcp/vitest.config.d.ts.map +1 -0
  113. package/dist/mcp-client.d.ts +58 -0
  114. package/dist/mcp-client.d.ts.map +1 -0
  115. package/dist/mcp-client.js +2 -1
  116. package/dist/memory/branch.d.ts +124 -0
  117. package/dist/memory/branch.d.ts.map +1 -0
  118. package/dist/memory/commands/status.d.ts +4 -0
  119. package/dist/memory/commands/status.d.ts.map +1 -0
  120. package/dist/memory/commands/view.d.ts +4 -0
  121. package/dist/memory/commands/view.d.ts.map +1 -0
  122. package/dist/memory/compaction.d.ts +113 -0
  123. package/dist/memory/compaction.d.ts.map +1 -0
  124. package/dist/memory/config.d.ts +27 -0
  125. package/dist/memory/config.d.ts.map +1 -0
  126. package/dist/memory/debug-log.d.ts +12 -0
  127. package/dist/memory/debug-log.d.ts.map +1 -0
  128. package/dist/memory/hooks/compaction-hook.d.ts +4 -0
  129. package/dist/memory/hooks/compaction-hook.d.ts.map +1 -0
  130. package/dist/memory/hooks/compaction-trigger.d.ts +4 -0
  131. package/dist/memory/hooks/compaction-trigger.d.ts.map +1 -0
  132. package/dist/memory/hooks/observer-trigger.d.ts +4 -0
  133. package/dist/memory/hooks/observer-trigger.d.ts.map +1 -0
  134. package/dist/memory/ids.d.ts +2 -0
  135. package/dist/memory/ids.d.ts.map +1 -0
  136. package/dist/memory/index.d.ts +3 -0
  137. package/dist/memory/index.d.ts.map +1 -0
  138. package/dist/memory/model-budget.d.ts +4 -0
  139. package/dist/memory/model-budget.d.ts.map +1 -0
  140. package/dist/memory/observer.d.ts +21 -0
  141. package/dist/memory/observer.d.ts.map +1 -0
  142. package/dist/memory/project-observations-store.d.ts +24 -0
  143. package/dist/memory/project-observations-store.d.ts.map +1 -0
  144. package/dist/memory/prompts.d.ts +11 -0
  145. package/dist/memory/prompts.d.ts.map +1 -0
  146. package/dist/memory/relevance.d.ts +4 -0
  147. package/dist/memory/relevance.d.ts.map +1 -0
  148. package/dist/memory/runtime.d.ts +40 -0
  149. package/dist/memory/runtime.d.ts.map +1 -0
  150. package/dist/memory/serialize.d.ts +26 -0
  151. package/dist/memory/serialize.d.ts.map +1 -0
  152. package/dist/memory/tokens.d.ts +8 -0
  153. package/dist/memory/tokens.d.ts.map +1 -0
  154. package/dist/memory/tools/read-project-observations.d.ts +8 -0
  155. package/dist/memory/tools/read-project-observations.d.ts.map +1 -0
  156. package/dist/memory/tools/recall-observation.d.ts +63 -0
  157. package/dist/memory/tools/recall-observation.d.ts.map +1 -0
  158. package/dist/memory/tools/write-project-observation.d.ts +9 -0
  159. package/dist/memory/tools/write-project-observation.d.ts.map +1 -0
  160. package/dist/memory/types.d.ts +65 -0
  161. package/dist/memory/types.d.ts.map +1 -0
  162. package/dist/preflight.d.ts +27 -0
  163. package/dist/preflight.d.ts.map +1 -0
  164. package/dist/preflight.js +3 -1
  165. package/dist/relay/auto-research.d.ts +64 -0
  166. package/dist/relay/auto-research.d.ts.map +1 -0
  167. package/dist/relay/auto-research.js +174 -69
  168. package/dist/relay/client.d.ts +126 -0
  169. package/dist/relay/client.d.ts.map +1 -0
  170. package/dist/relay/dispatcher.d.ts +207 -0
  171. package/dist/relay/dispatcher.d.ts.map +1 -0
  172. package/dist/relay/machine-store.d.ts +68 -0
  173. package/dist/relay/machine-store.d.ts.map +1 -0
  174. package/dist/relay/models-fetch.d.ts +75 -0
  175. package/dist/relay/models-fetch.d.ts.map +1 -0
  176. package/dist/relay/registration.d.ts +81 -0
  177. package/dist/relay/registration.d.ts.map +1 -0
  178. package/dist/sdk/agent-core/agent-loop.d.ts +24 -0
  179. package/dist/sdk/agent-core/agent-loop.d.ts.map +1 -0
  180. package/dist/sdk/agent-core/agent.d.ts +125 -0
  181. package/dist/sdk/agent-core/agent.d.ts.map +1 -0
  182. package/dist/sdk/agent-core/harness/agent-harness.d.ts +92 -0
  183. package/dist/sdk/agent-core/harness/agent-harness.d.ts.map +1 -0
  184. package/dist/sdk/agent-core/harness/compaction/branch-summarization.d.ts +53 -0
  185. package/dist/sdk/agent-core/harness/compaction/branch-summarization.d.ts.map +1 -0
  186. package/dist/sdk/agent-core/harness/compaction/compaction.d.ts +95 -0
  187. package/dist/sdk/agent-core/harness/compaction/compaction.d.ts.map +1 -0
  188. package/dist/sdk/agent-core/harness/compaction/utils.d.ts +25 -0
  189. package/dist/sdk/agent-core/harness/compaction/utils.d.ts.map +1 -0
  190. package/dist/sdk/agent-core/harness/env/nodejs.d.ts +51 -0
  191. package/dist/sdk/agent-core/harness/env/nodejs.d.ts.map +1 -0
  192. package/dist/sdk/agent-core/harness/messages.d.ts +51 -0
  193. package/dist/sdk/agent-core/harness/messages.d.ts.map +1 -0
  194. package/dist/sdk/agent-core/harness/prompt-templates.d.ts +48 -0
  195. package/dist/sdk/agent-core/harness/prompt-templates.d.ts.map +1 -0
  196. package/dist/sdk/agent-core/harness/session/jsonl-repo.d.ts +26 -0
  197. package/dist/sdk/agent-core/harness/session/jsonl-repo.d.ts.map +1 -0
  198. package/dist/sdk/agent-core/harness/session/jsonl-storage.d.ts +33 -0
  199. package/dist/sdk/agent-core/harness/session/jsonl-storage.d.ts.map +1 -0
  200. package/dist/sdk/agent-core/harness/session/memory-repo.d.ts +18 -0
  201. package/dist/sdk/agent-core/harness/session/memory-repo.d.ts.map +1 -0
  202. package/dist/sdk/agent-core/harness/session/memory-storage.d.ts +25 -0
  203. package/dist/sdk/agent-core/harness/session/memory-storage.d.ts.map +1 -0
  204. package/dist/sdk/agent-core/harness/session/repo-utils.d.ts +11 -0
  205. package/dist/sdk/agent-core/harness/session/repo-utils.d.ts.map +1 -0
  206. package/dist/sdk/agent-core/harness/session/session.d.ts +32 -0
  207. package/dist/sdk/agent-core/harness/session/session.d.ts.map +1 -0
  208. package/dist/sdk/agent-core/harness/session/uuid.d.ts +2 -0
  209. package/dist/sdk/agent-core/harness/session/uuid.d.ts.map +1 -0
  210. package/dist/sdk/agent-core/harness/skills.d.ts +44 -0
  211. package/dist/sdk/agent-core/harness/skills.d.ts.map +1 -0
  212. package/dist/sdk/agent-core/harness/system-prompt.d.ts +3 -0
  213. package/dist/sdk/agent-core/harness/system-prompt.d.ts.map +1 -0
  214. package/dist/sdk/agent-core/harness/types.d.ts +601 -0
  215. package/dist/sdk/agent-core/harness/types.d.ts.map +1 -0
  216. package/dist/sdk/agent-core/harness/utils/shell-output.d.ts +14 -0
  217. package/dist/sdk/agent-core/harness/utils/shell-output.d.ts.map +1 -0
  218. package/dist/sdk/agent-core/harness/utils/truncate.d.ts +70 -0
  219. package/dist/sdk/agent-core/harness/utils/truncate.d.ts.map +1 -0
  220. package/dist/sdk/agent-core/index.d.ts +20 -0
  221. package/dist/sdk/agent-core/index.d.ts.map +1 -0
  222. package/dist/sdk/agent-core/node.d.ts +3 -0
  223. package/dist/sdk/agent-core/node.d.ts.map +1 -0
  224. package/dist/sdk/agent-core/proxy.d.ts +69 -0
  225. package/dist/sdk/agent-core/proxy.d.ts.map +1 -0
  226. package/dist/sdk/agent-core/types.d.ts +393 -0
  227. package/dist/sdk/agent-core/types.d.ts.map +1 -0
  228. package/dist/sdk/ai/api-registry.d.ts +20 -0
  229. package/dist/sdk/ai/api-registry.d.ts.map +1 -0
  230. package/dist/sdk/ai/cli.d.ts +3 -0
  231. package/dist/sdk/ai/cli.d.ts.map +1 -0
  232. package/dist/sdk/ai/env-api-keys.d.ts +18 -0
  233. package/dist/sdk/ai/env-api-keys.d.ts.map +1 -0
  234. package/dist/sdk/ai/image-models.d.ts +10 -0
  235. package/dist/sdk/ai/image-models.d.ts.map +1 -0
  236. package/dist/sdk/ai/image-models.generated.d.ts +440 -0
  237. package/dist/sdk/ai/image-models.generated.d.ts.map +1 -0
  238. package/dist/sdk/ai/images-api-registry.d.ts +14 -0
  239. package/dist/sdk/ai/images-api-registry.d.ts.map +1 -0
  240. package/dist/sdk/ai/images.d.ts +4 -0
  241. package/dist/sdk/ai/images.d.ts.map +1 -0
  242. package/dist/sdk/ai/index.d.ts +21 -0
  243. package/dist/sdk/ai/index.d.ts.map +1 -0
  244. package/dist/sdk/ai/models.d.ts +18 -0
  245. package/dist/sdk/ai/models.d.ts.map +1 -0
  246. package/dist/sdk/ai/models.generated.d.ts +17349 -0
  247. package/dist/sdk/ai/models.generated.d.ts.map +1 -0
  248. package/dist/sdk/ai/oauth.d.ts +2 -0
  249. package/dist/sdk/ai/oauth.d.ts.map +1 -0
  250. package/dist/sdk/ai/providers/anthropic.d.ts +54 -0
  251. package/dist/sdk/ai/providers/anthropic.d.ts.map +1 -0
  252. package/dist/sdk/ai/providers/faux.d.ts +56 -0
  253. package/dist/sdk/ai/providers/faux.d.ts.map +1 -0
  254. package/dist/sdk/ai/providers/github-copilot-headers.d.ts +8 -0
  255. package/dist/sdk/ai/providers/github-copilot-headers.d.ts.map +1 -0
  256. package/dist/sdk/ai/providers/openai-completions.d.ts +19 -0
  257. package/dist/sdk/ai/providers/openai-completions.d.ts.map +1 -0
  258. package/dist/sdk/ai/providers/openai-prompt-cache.d.ts +3 -0
  259. package/dist/sdk/ai/providers/openai-prompt-cache.d.ts.map +1 -0
  260. package/dist/sdk/ai/providers/register-builtins.d.ts +15 -0
  261. package/dist/sdk/ai/providers/register-builtins.d.ts.map +1 -0
  262. package/dist/sdk/ai/providers/simple-options.d.ts +8 -0
  263. package/dist/sdk/ai/providers/simple-options.d.ts.map +1 -0
  264. package/dist/sdk/ai/providers/transform-messages.d.ts +8 -0
  265. package/dist/sdk/ai/providers/transform-messages.d.ts.map +1 -0
  266. package/dist/sdk/ai/session-resources.d.ts +4 -0
  267. package/dist/sdk/ai/session-resources.d.ts.map +1 -0
  268. package/dist/sdk/ai/stream.d.ts +8 -0
  269. package/dist/sdk/ai/stream.d.ts.map +1 -0
  270. package/dist/sdk/ai/types.d.ts +488 -0
  271. package/dist/sdk/ai/types.d.ts.map +1 -0
  272. package/dist/sdk/ai/utils/diagnostics.d.ts +19 -0
  273. package/dist/sdk/ai/utils/diagnostics.d.ts.map +1 -0
  274. package/dist/sdk/ai/utils/event-stream.d.ts +21 -0
  275. package/dist/sdk/ai/utils/event-stream.d.ts.map +1 -0
  276. package/dist/sdk/ai/utils/hash.d.ts +3 -0
  277. package/dist/sdk/ai/utils/hash.d.ts.map +1 -0
  278. package/dist/sdk/ai/utils/headers.d.ts +2 -0
  279. package/dist/sdk/ai/utils/headers.d.ts.map +1 -0
  280. package/dist/sdk/ai/utils/json-parse.d.ts +16 -0
  281. package/dist/sdk/ai/utils/json-parse.d.ts.map +1 -0
  282. package/dist/sdk/ai/utils/node-http-proxy.d.ts +10 -0
  283. package/dist/sdk/ai/utils/node-http-proxy.d.ts.map +1 -0
  284. package/dist/sdk/ai/utils/oauth/anthropic.d.ts +25 -0
  285. package/dist/sdk/ai/utils/oauth/anthropic.d.ts.map +1 -0
  286. package/dist/sdk/ai/utils/oauth/device-code.d.ts +19 -0
  287. package/dist/sdk/ai/utils/oauth/device-code.d.ts.map +1 -0
  288. package/dist/sdk/ai/utils/oauth/github-copilot.d.ts +30 -0
  289. package/dist/sdk/ai/utils/oauth/github-copilot.d.ts.map +1 -0
  290. package/dist/sdk/ai/utils/oauth/index.d.ts +58 -0
  291. package/dist/sdk/ai/utils/oauth/index.d.ts.map +1 -0
  292. package/dist/sdk/ai/utils/oauth/oauth-page.d.ts +3 -0
  293. package/dist/sdk/ai/utils/oauth/oauth-page.d.ts.map +1 -0
  294. package/dist/sdk/ai/utils/oauth/openai-codex.d.ts +34 -0
  295. package/dist/sdk/ai/utils/oauth/openai-codex.d.ts.map +1 -0
  296. package/dist/sdk/ai/utils/oauth/pkce.d.ts +13 -0
  297. package/dist/sdk/ai/utils/oauth/pkce.d.ts.map +1 -0
  298. package/dist/sdk/ai/utils/oauth/types.d.ts +64 -0
  299. package/dist/sdk/ai/utils/oauth/types.d.ts.map +1 -0
  300. package/dist/sdk/ai/utils/overflow.d.ts +56 -0
  301. package/dist/sdk/ai/utils/overflow.d.ts.map +1 -0
  302. package/dist/sdk/ai/utils/sanitize-unicode.d.ts +22 -0
  303. package/dist/sdk/ai/utils/sanitize-unicode.d.ts.map +1 -0
  304. package/dist/sdk/ai/utils/typebox-helpers.d.ts +17 -0
  305. package/dist/sdk/ai/utils/typebox-helpers.d.ts.map +1 -0
  306. package/dist/sdk/ai/utils/validation.d.ts +18 -0
  307. package/dist/sdk/ai/utils/validation.d.ts.map +1 -0
  308. package/dist/sdk/coding-agent/cli.d.ts +3 -0
  309. package/dist/sdk/coding-agent/cli.d.ts.map +1 -0
  310. package/dist/sdk/coding-agent/config.d.ts +71 -0
  311. package/dist/sdk/coding-agent/config.d.ts.map +1 -0
  312. package/dist/sdk/coding-agent/core/agent-session-runtime.d.ts +117 -0
  313. package/dist/sdk/coding-agent/core/agent-session-runtime.d.ts.map +1 -0
  314. package/dist/sdk/coding-agent/core/agent-session-services.d.ts +86 -0
  315. package/dist/sdk/coding-agent/core/agent-session-services.d.ts.map +1 -0
  316. package/dist/sdk/coding-agent/core/agent-session.d.ts +626 -0
  317. package/dist/sdk/coding-agent/core/agent-session.d.ts.map +1 -0
  318. package/dist/sdk/coding-agent/core/auth-guidance.d.ts +5 -0
  319. package/dist/sdk/coding-agent/core/auth-guidance.d.ts.map +1 -0
  320. package/dist/sdk/coding-agent/core/auth-storage.d.ts +145 -0
  321. package/dist/sdk/coding-agent/core/auth-storage.d.ts.map +1 -0
  322. package/dist/sdk/coding-agent/core/bash-executor.d.ts +32 -0
  323. package/dist/sdk/coding-agent/core/bash-executor.d.ts.map +1 -0
  324. package/dist/sdk/coding-agent/core/compaction/branch-summarization.d.ts +88 -0
  325. package/dist/sdk/coding-agent/core/compaction/branch-summarization.d.ts.map +1 -0
  326. package/dist/sdk/coding-agent/core/compaction/compaction.d.ts +142 -0
  327. package/dist/sdk/coding-agent/core/compaction/compaction.d.ts.map +1 -0
  328. package/dist/sdk/coding-agent/core/compaction/index.d.ts +7 -0
  329. package/dist/sdk/coding-agent/core/compaction/index.d.ts.map +1 -0
  330. package/dist/sdk/coding-agent/core/compaction/utils.d.ts +38 -0
  331. package/dist/sdk/coding-agent/core/compaction/utils.d.ts.map +1 -0
  332. package/dist/sdk/coding-agent/core/defaults.d.ts +3 -0
  333. package/dist/sdk/coding-agent/core/defaults.d.ts.map +1 -0
  334. package/dist/sdk/coding-agent/core/diagnostics.d.ts +15 -0
  335. package/dist/sdk/coding-agent/core/diagnostics.d.ts.map +1 -0
  336. package/dist/sdk/coding-agent/core/event-bus.d.ts +9 -0
  337. package/dist/sdk/coding-agent/core/event-bus.d.ts.map +1 -0
  338. package/dist/sdk/coding-agent/core/exec.d.ts +29 -0
  339. package/dist/sdk/coding-agent/core/exec.d.ts.map +1 -0
  340. package/dist/sdk/coding-agent/core/extensions/index.d.ts +12 -0
  341. package/dist/sdk/coding-agent/core/extensions/index.d.ts.map +1 -0
  342. package/dist/sdk/coding-agent/core/extensions/loader.d.ts +24 -0
  343. package/dist/sdk/coding-agent/core/extensions/loader.d.ts.map +1 -0
  344. package/dist/sdk/coding-agent/core/extensions/loader.js +1 -0
  345. package/dist/sdk/coding-agent/core/extensions/runner.d.ts +161 -0
  346. package/dist/sdk/coding-agent/core/extensions/runner.d.ts.map +1 -0
  347. package/dist/sdk/coding-agent/core/extensions/types.d.ts +1181 -0
  348. package/dist/sdk/coding-agent/core/extensions/types.d.ts.map +1 -0
  349. package/dist/sdk/coding-agent/core/extensions/wrapper.d.ts +20 -0
  350. package/dist/sdk/coding-agent/core/extensions/wrapper.d.ts.map +1 -0
  351. package/dist/sdk/coding-agent/core/http-dispatcher.d.ts +21 -0
  352. package/dist/sdk/coding-agent/core/http-dispatcher.d.ts.map +1 -0
  353. package/dist/sdk/coding-agent/core/index.d.ts +12 -0
  354. package/dist/sdk/coding-agent/core/index.d.ts.map +1 -0
  355. package/dist/sdk/coding-agent/core/keybindings.d.ts +371 -0
  356. package/dist/sdk/coding-agent/core/keybindings.d.ts.map +1 -0
  357. package/dist/sdk/coding-agent/core/messages.d.ts +77 -0
  358. package/dist/sdk/coding-agent/core/messages.d.ts.map +1 -0
  359. package/dist/sdk/coding-agent/core/model-registry.d.ts +150 -0
  360. package/dist/sdk/coding-agent/core/model-registry.d.ts.map +1 -0
  361. package/dist/sdk/coding-agent/core/model-resolver-utils.d.ts +7 -0
  362. package/dist/sdk/coding-agent/core/model-resolver-utils.d.ts.map +1 -0
  363. package/dist/sdk/coding-agent/core/model-resolver.d.ts +110 -0
  364. package/dist/sdk/coding-agent/core/model-resolver.d.ts.map +1 -0
  365. package/dist/sdk/coding-agent/core/output-guard.d.ts +6 -0
  366. package/dist/sdk/coding-agent/core/output-guard.d.ts.map +1 -0
  367. package/dist/sdk/coding-agent/core/package-manager.d.ts +204 -0
  368. package/dist/sdk/coding-agent/core/package-manager.d.ts.map +1 -0
  369. package/dist/sdk/coding-agent/core/prompt-templates.d.ts +52 -0
  370. package/dist/sdk/coding-agent/core/prompt-templates.d.ts.map +1 -0
  371. package/dist/sdk/coding-agent/core/provider-display-names.d.ts +2 -0
  372. package/dist/sdk/coding-agent/core/provider-display-names.d.ts.map +1 -0
  373. package/dist/sdk/coding-agent/core/resolve-config-value.d.ts +23 -0
  374. package/dist/sdk/coding-agent/core/resolve-config-value.d.ts.map +1 -0
  375. package/dist/sdk/coding-agent/core/resource-loader.d.ts +194 -0
  376. package/dist/sdk/coding-agent/core/resource-loader.d.ts.map +1 -0
  377. package/dist/sdk/coding-agent/core/sdk.d.ts +107 -0
  378. package/dist/sdk/coding-agent/core/sdk.d.ts.map +1 -0
  379. package/dist/sdk/coding-agent/core/session-cwd.d.ts +19 -0
  380. package/dist/sdk/coding-agent/core/session-cwd.d.ts.map +1 -0
  381. package/dist/sdk/coding-agent/core/session-manager.d.ts +333 -0
  382. package/dist/sdk/coding-agent/core/session-manager.d.ts.map +1 -0
  383. package/dist/sdk/coding-agent/core/settings-manager.d.ts +209 -0
  384. package/dist/sdk/coding-agent/core/settings-manager.d.ts.map +1 -0
  385. package/dist/sdk/coding-agent/core/skills.d.ts +60 -0
  386. package/dist/sdk/coding-agent/core/skills.d.ts.map +1 -0
  387. package/dist/sdk/coding-agent/core/slash-commands.d.ts +14 -0
  388. package/dist/sdk/coding-agent/core/slash-commands.d.ts.map +1 -0
  389. package/dist/sdk/coding-agent/core/source-info.d.ts +18 -0
  390. package/dist/sdk/coding-agent/core/source-info.d.ts.map +1 -0
  391. package/dist/sdk/coding-agent/core/system-prompt.d.ts +28 -0
  392. package/dist/sdk/coding-agent/core/system-prompt.d.ts.map +1 -0
  393. package/dist/sdk/coding-agent/core/telemetry.d.ts +3 -0
  394. package/dist/sdk/coding-agent/core/telemetry.d.ts.map +1 -0
  395. package/dist/sdk/coding-agent/core/theme.d.ts +28 -0
  396. package/dist/sdk/coding-agent/core/theme.d.ts.map +1 -0
  397. package/dist/sdk/coding-agent/core/timings.d.ts +8 -0
  398. package/dist/sdk/coding-agent/core/timings.d.ts.map +1 -0
  399. package/dist/sdk/coding-agent/core/tools/bash.d.ts +63 -0
  400. package/dist/sdk/coding-agent/core/tools/bash.d.ts.map +1 -0
  401. package/dist/sdk/coding-agent/core/tools/edit-diff.d.ts +87 -0
  402. package/dist/sdk/coding-agent/core/tools/edit-diff.d.ts.map +1 -0
  403. package/dist/sdk/coding-agent/core/tools/edit.d.ts +39 -0
  404. package/dist/sdk/coding-agent/core/tools/edit.d.ts.map +1 -0
  405. package/dist/sdk/coding-agent/core/tools/file-mutation-queue.d.ts +6 -0
  406. package/dist/sdk/coding-agent/core/tools/file-mutation-queue.d.ts.map +1 -0
  407. package/dist/sdk/coding-agent/core/tools/find.d.ts +35 -0
  408. package/dist/sdk/coding-agent/core/tools/find.d.ts.map +1 -0
  409. package/dist/sdk/coding-agent/core/tools/grep.d.ts +37 -0
  410. package/dist/sdk/coding-agent/core/tools/grep.d.ts.map +1 -0
  411. package/dist/sdk/coding-agent/core/tools/index.d.ts +40 -0
  412. package/dist/sdk/coding-agent/core/tools/index.d.ts.map +1 -0
  413. package/dist/sdk/coding-agent/core/tools/ls.d.ts +37 -0
  414. package/dist/sdk/coding-agent/core/tools/ls.d.ts.map +1 -0
  415. package/dist/sdk/coding-agent/core/tools/output-accumulator.d.ts +52 -0
  416. package/dist/sdk/coding-agent/core/tools/output-accumulator.d.ts.map +1 -0
  417. package/dist/sdk/coding-agent/core/tools/path-utils.d.ts +8 -0
  418. package/dist/sdk/coding-agent/core/tools/path-utils.d.ts.map +1 -0
  419. package/dist/sdk/coding-agent/core/tools/read.d.ts +35 -0
  420. package/dist/sdk/coding-agent/core/tools/read.d.ts.map +1 -0
  421. package/dist/sdk/coding-agent/core/tools/read.js +18 -10
  422. package/dist/sdk/coding-agent/core/tools/render-diff.d.ts +17 -0
  423. package/dist/sdk/coding-agent/core/tools/render-diff.d.ts.map +1 -0
  424. package/dist/sdk/coding-agent/core/tools/render-utils.d.ts +21 -0
  425. package/dist/sdk/coding-agent/core/tools/render-utils.d.ts.map +1 -0
  426. package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.d.ts +14 -0
  427. package/dist/sdk/coding-agent/core/tools/tool-definition-wrapper.d.ts.map +1 -0
  428. package/dist/sdk/coding-agent/core/tools/truncate.d.ts +70 -0
  429. package/dist/sdk/coding-agent/core/tools/truncate.d.ts.map +1 -0
  430. package/dist/sdk/coding-agent/core/tools/write.d.ts +26 -0
  431. package/dist/sdk/coding-agent/core/tools/write.d.ts.map +1 -0
  432. package/dist/sdk/coding-agent/index.d.ts +29 -0
  433. package/dist/sdk/coding-agent/index.d.ts.map +1 -0
  434. package/dist/sdk/coding-agent/main.d.ts +2 -0
  435. package/dist/sdk/coding-agent/main.d.ts.map +1 -0
  436. package/dist/sdk/coding-agent/migrations.d.ts +33 -0
  437. package/dist/sdk/coding-agent/migrations.d.ts.map +1 -0
  438. package/dist/sdk/coding-agent/modes/index.d.ts +8 -0
  439. package/dist/sdk/coding-agent/modes/index.d.ts.map +1 -0
  440. package/dist/sdk/coding-agent/modes/print-mode.d.ts +28 -0
  441. package/dist/sdk/coding-agent/modes/print-mode.d.ts.map +1 -0
  442. package/dist/sdk/coding-agent/modes/rpc/jsonl.d.ts +17 -0
  443. package/dist/sdk/coding-agent/modes/rpc/jsonl.d.ts.map +1 -0
  444. package/dist/sdk/coding-agent/modes/rpc/rpc-client.d.ts +224 -0
  445. package/dist/sdk/coding-agent/modes/rpc/rpc-client.d.ts.map +1 -0
  446. package/dist/sdk/coding-agent/modes/rpc/rpc-mode.d.ts +20 -0
  447. package/dist/sdk/coding-agent/modes/rpc/rpc-mode.d.ts.map +1 -0
  448. package/dist/sdk/coding-agent/modes/rpc/rpc-types.d.ts +419 -0
  449. package/dist/sdk/coding-agent/modes/rpc/rpc-types.d.ts.map +1 -0
  450. package/dist/sdk/coding-agent/utils/ansi.d.ts +2 -0
  451. package/dist/sdk/coding-agent/utils/ansi.d.ts.map +1 -0
  452. package/dist/sdk/coding-agent/utils/changelog.d.ts +21 -0
  453. package/dist/sdk/coding-agent/utils/changelog.d.ts.map +1 -0
  454. package/dist/sdk/coding-agent/utils/child-process.d.ts +15 -0
  455. package/dist/sdk/coding-agent/utils/child-process.d.ts.map +1 -0
  456. package/dist/sdk/coding-agent/utils/clipboard-image.d.ts +11 -0
  457. package/dist/sdk/coding-agent/utils/clipboard-image.d.ts.map +1 -0
  458. package/dist/sdk/coding-agent/utils/clipboard-native.d.ts +8 -0
  459. package/dist/sdk/coding-agent/utils/clipboard-native.d.ts.map +1 -0
  460. package/dist/sdk/coding-agent/utils/clipboard.d.ts +2 -0
  461. package/dist/sdk/coding-agent/utils/clipboard.d.ts.map +1 -0
  462. package/dist/sdk/coding-agent/utils/exif-orientation.d.ts +5 -0
  463. package/dist/sdk/coding-agent/utils/exif-orientation.d.ts.map +1 -0
  464. package/dist/sdk/coding-agent/utils/frontmatter.d.ts +8 -0
  465. package/dist/sdk/coding-agent/utils/frontmatter.d.ts.map +1 -0
  466. package/dist/sdk/coding-agent/utils/fs-watch.d.ts +5 -0
  467. package/dist/sdk/coding-agent/utils/fs-watch.d.ts.map +1 -0
  468. package/dist/sdk/coding-agent/utils/git.d.ts +26 -0
  469. package/dist/sdk/coding-agent/utils/git.d.ts.map +1 -0
  470. package/dist/sdk/coding-agent/utils/html.d.ts +7 -0
  471. package/dist/sdk/coding-agent/utils/html.d.ts.map +1 -0
  472. package/dist/sdk/coding-agent/utils/image-convert.d.ts +9 -0
  473. package/dist/sdk/coding-agent/utils/image-convert.d.ts.map +1 -0
  474. package/dist/sdk/coding-agent/utils/image-resize.d.ts +36 -0
  475. package/dist/sdk/coding-agent/utils/image-resize.d.ts.map +1 -0
  476. package/dist/sdk/coding-agent/utils/mime.d.ts +3 -0
  477. package/dist/sdk/coding-agent/utils/mime.d.ts.map +1 -0
  478. package/dist/sdk/coding-agent/utils/paths.d.ts +31 -0
  479. package/dist/sdk/coding-agent/utils/paths.d.ts.map +1 -0
  480. package/dist/sdk/coding-agent/utils/photon.d.ts +13 -0
  481. package/dist/sdk/coding-agent/utils/photon.d.ts.map +1 -0
  482. package/dist/sdk/coding-agent/utils/pi-user-agent.d.ts +2 -0
  483. package/dist/sdk/coding-agent/utils/pi-user-agent.d.ts.map +1 -0
  484. package/dist/sdk/coding-agent/utils/shell.d.ts +30 -0
  485. package/dist/sdk/coding-agent/utils/shell.d.ts.map +1 -0
  486. package/dist/sdk/coding-agent/utils/sleep.d.ts +5 -0
  487. package/dist/sdk/coding-agent/utils/sleep.d.ts.map +1 -0
  488. package/dist/sdk/coding-agent/utils/syntax-highlight.d.ts +12 -0
  489. package/dist/sdk/coding-agent/utils/syntax-highlight.d.ts.map +1 -0
  490. package/dist/sdk/coding-agent/utils/tools-manager.d.ts +3 -0
  491. package/dist/sdk/coding-agent/utils/tools-manager.d.ts.map +1 -0
  492. package/dist/sdk/coding-agent/utils/version-check.d.ts +15 -0
  493. package/dist/sdk/coding-agent/utils/version-check.d.ts.map +1 -0
  494. package/dist/sdk/coding-agent/utils/windows-self-update.d.ts +3 -0
  495. package/dist/sdk/coding-agent/utils/windows-self-update.d.ts.map +1 -0
  496. package/dist/server/agent-bridge.d.ts +308 -0
  497. package/dist/server/agent-bridge.d.ts.map +1 -0
  498. package/dist/server/handlers/errors.d.ts +26 -0
  499. package/dist/server/handlers/errors.d.ts.map +1 -0
  500. package/dist/server/handlers/paths-autocomplete.d.ts +45 -0
  501. package/dist/server/handlers/paths-autocomplete.d.ts.map +1 -0
  502. package/dist/server/handlers/projects.d.ts +58 -0
  503. package/dist/server/handlers/projects.d.ts.map +1 -0
  504. package/dist/server/handlers/queue.d.ts +27 -0
  505. package/dist/server/handlers/queue.d.ts.map +1 -0
  506. package/dist/server/handlers/sessions.d.ts +50 -0
  507. package/dist/server/handlers/sessions.d.ts.map +1 -0
  508. package/dist/server/paths.d.ts +51 -0
  509. package/dist/server/paths.d.ts.map +1 -0
  510. package/dist/server/session-stream.d.ts +379 -0
  511. package/dist/server/session-stream.d.ts.map +1 -0
  512. package/dist/server/shutdown.d.ts +102 -0
  513. package/dist/server/shutdown.d.ts.map +1 -0
  514. package/dist/server/storage.d.ts +287 -0
  515. package/dist/server/storage.d.ts.map +1 -0
  516. package/dist/server/title-generator.d.ts +25 -0
  517. package/dist/server/title-generator.d.ts.map +1 -0
  518. package/dist/server/wire.d.ts +448 -0
  519. package/dist/server/wire.d.ts.map +1 -0
  520. package/dist/studio-binding.d.ts +44 -0
  521. package/dist/studio-binding.d.ts.map +1 -0
  522. package/dist/studio-binding.js +1 -1
  523. package/package.json +11 -1
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Pure REST handlers for `/api/sessions/:sessionId/queue/*`.
3
+ *
4
+ * Same contract as sessions/projects handlers — pure functions that take
5
+ * `store` + `manager` dependencies, throw `BadRequestError`/`NotFoundError`
6
+ * on invalid input, and return typed responses.
7
+ *
8
+ * After mutating the queue, each handler calls `manager.pushQueueState()`
9
+ * to broadcast the updated queue to all subscribers via `queue_changed`.
10
+ */
11
+ import type { SessionStreamManager } from "../session-stream.js";
12
+ import type { SessionStore } from "../storage.js";
13
+ export interface EnqueuePromptInputRaw {
14
+ content?: unknown;
15
+ }
16
+ /** Wire shape for a single queue item returned to the frontend. */
17
+ export interface WireQueueItem {
18
+ id: string;
19
+ content: string;
20
+ position: number;
21
+ createdAt: string;
22
+ }
23
+ export declare function handleEnqueuePrompt(store: SessionStore, manager: SessionStreamManager, sessionId: string, body: EnqueuePromptInputRaw): WireQueueItem;
24
+ export declare function handleGetPromptQueue(store: SessionStore, sessionId: string): WireQueueItem[];
25
+ export declare function handleRemovePrompt(store: SessionStore, manager: SessionStreamManager, sessionId: string, itemId: string): void;
26
+ export declare function handleClearPromptQueue(store: SessionStore, manager: SessionStreamManager, sessionId: string): void;
27
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGlD,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,oBAAoB,EAC7B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,qBAAqB,GAC1B,aAAa,CAgBf;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,MAAM,GAChB,aAAa,EAAE,CAUjB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,oBAAoB,EAC7B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,IAAI,CAMN;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,oBAAoB,EAC7B,SAAS,EAAE,MAAM,GAChB,IAAI,CAMN"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Pure REST handlers for `/api/sessions/*`.
3
+ *
4
+ * Same shape as projects handlers — see that file's header for the contract.
5
+ *
6
+ * Note: session deletion does not tear down the in-flight pi stream itself.
7
+ * The Batch 3 dispatcher must call `manager.disposeSessionStream(id)` BEFORE
8
+ * invoking `handleDeleteSession` so the FK cascade doesn't leave a zombie
9
+ * bridge driving events at a row that no longer exists. This matches the
10
+ * ordering the old Hono route used.
11
+ */
12
+ import type { SessionStreamManager } from "../session-stream.js";
13
+ import type { SessionStore } from "../storage.js";
14
+ import type { WireSessionDetail, WireSessionMemoryDetails, WireSessionMemoryStatus, WireSessionSummary } from "../wire.js";
15
+ export interface CreateSessionInputRaw {
16
+ projectId?: unknown;
17
+ title?: unknown;
18
+ }
19
+ export interface UpdateSessionInputRaw {
20
+ title?: unknown;
21
+ }
22
+ export declare function handleCreateSession(store: SessionStore, body: CreateSessionInputRaw): WireSessionSummary;
23
+ export declare function handleGetSessionDetail(store: SessionStore, id: string): WireSessionDetail;
24
+ export declare function handleUpdateSession(store: SessionStore, id: string, body: UpdateSessionInputRaw): WireSessionSummary;
25
+ export declare function handleDeleteSession(store: SessionStore, id: string): void;
26
+ export declare function handleGetSessionMemoryStatus(store: SessionStore, manager: SessionStreamManager, id: string): WireSessionMemoryStatus;
27
+ export declare function handleGetSessionMemoryDetails(store: SessionStore, manager: SessionStreamManager, id: string): WireSessionMemoryDetails;
28
+ export declare function handleCompactSession(store: SessionStore, manager: SessionStreamManager, id: string): Promise<{
29
+ ok: true;
30
+ }>;
31
+ /**
32
+ * Remember & delete: compact the session (which persists observations as
33
+ * project memory via the compaction hook), then delete the session.
34
+ *
35
+ * This gives the user a way to keep a session's reflections as durable
36
+ * cross-session memory even for short sessions that never hit the compaction
37
+ * threshold naturally.
38
+ */
39
+ export declare function handleRememberAndDeleteSession(store: SessionStore, manager: SessionStreamManager, id: string): Promise<{
40
+ ok: true;
41
+ }>;
42
+ /**
43
+ * Fork a session: create a new session copying all messages from the
44
+ * source, with the `fork_compact_source_id` flag set so the
45
+ * SessionStreamManager compacts after the first assistant turn.
46
+ */
47
+ export declare function handleForkSession(store: SessionStore, id: string, body: {
48
+ title?: unknown;
49
+ }): WireSessionSummary;
50
+ //# sourceMappingURL=sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAG3H,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EACnB,IAAI,EAAE,qBAAqB,GAC1B,kBAAkB,CAQpB;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,YAAY,EACnB,EAAE,EAAE,MAAM,GACT,iBAAiB,CAInB;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,YAAY,EACnB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,qBAAqB,GAC1B,kBAAkB,CAOpB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAGzE;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,MAAM,GACT,uBAAuB,CAIzB;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,MAAM,GACT,wBAAwB,CAI1B;AAED,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,MAAM,GACT,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,CAUvB;AAED;;;;;;;GAOG;AACH,wBAAsB,8BAA8B,CAClD,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,oBAAoB,EAC7B,EAAE,EAAE,MAAM,GACT,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,CAUvB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,YAAY,EACnB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACxB,kBAAkB,CAKpB"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Filesystem path helpers for project management.
3
+ *
4
+ * Projects in `spectral serve` are user-owned directories on disk. We accept
5
+ * paths typed by the user from the browser, so two small concerns:
6
+ *
7
+ * - Tilde expansion: `~/foo/bar` is the natural way to refer to a path
8
+ * inside `$HOME`. Node's `path` module does not expand tildes; we do it
9
+ * ourselves with a leading-segment check (NOT a global string replace —
10
+ * `~user/...` and embedded `~` are intentionally left alone).
11
+ * - Validation: the path must exist, must be a directory, and must be
12
+ * readable. We do NOT attempt to verify writability — pi may want to
13
+ * create files inside it, but failure modes there surface naturally
14
+ * through pi's tools, and a write probe here would create stray files.
15
+ *
16
+ * Both helpers are synchronous because they're called on hot HTTP paths
17
+ * (POST /api/projects) where blocking is acceptable: the operation is rare
18
+ * and the user is waiting on the response anyway. `node:fs` sync calls in
19
+ * this regime are simpler than juggling promises through validation.
20
+ */
21
+ /**
22
+ * Expand a leading `~` or `~/` to the user's home directory and return an
23
+ * absolute, normalized path.
24
+ *
25
+ * Behavior:
26
+ * - `~` → `$HOME`
27
+ * - `~/foo` → `$HOME/foo`
28
+ * - `/abs/path` → `/abs/path` (unchanged, normalized)
29
+ * - `relative` → resolved against `$HOME` (NOT process.cwd, since the
30
+ * server runs from `$HOME` and "relative to home" matches the user's
31
+ * mental model when typing into a form)
32
+ * - `~user/...` → returned as-is and resolved against `$HOME`. We do NOT
33
+ * attempt to look up other users' home directories — out of scope.
34
+ */
35
+ export declare function expandPath(input: string): string;
36
+ export interface ProjectPathValidation {
37
+ ok: boolean;
38
+ /** Absolute, normalized path (set when ok=true and also for some errors). */
39
+ path: string;
40
+ /** Human-friendly error message (set when ok=false). */
41
+ error?: string;
42
+ }
43
+ /**
44
+ * Validate a user-supplied project path.
45
+ *
46
+ * Returns `{ok:true, path}` for a real, accessible directory. On failure,
47
+ * `error` carries a message suitable for surfacing to the user. The expanded
48
+ * path is included in both cases so callers can echo it back in errors.
49
+ */
50
+ export declare function validateProjectPath(input: string): ProjectPathValidation;
51
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/server/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAehD;AAED,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,OAAO,CAAC;IACZ,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,qBAAqB,CAmBxE"}
@@ -0,0 +1,379 @@
1
+ /**
2
+ * Session-scoped streaming layer for `spectral serve`.
3
+ *
4
+ * Background: prior to this module each WebSocket owned its own `AgentBridge`
5
+ * instance and the routes layer enforced single-writer-wins (4001 eviction)
6
+ * to keep that bridge unique per session. That model lost data on browser
7
+ * refresh — the WS close torn down the pi process mid-stream, and a re-open
8
+ * couldn't recover what hadn't yet hit `agent_end` (and thus SQLite).
9
+ *
10
+ * New model:
11
+ * - Pi lifecycle is per **Spectral session**, not per WS.
12
+ * - 0..N WebSockets may attach to the same session simultaneously. Each
13
+ * gets the same broadcast stream of events.
14
+ * - When a WS detaches (close, error, refresh), the pi process keeps
15
+ * running. Closing every tab does NOT cancel the in-flight turn —
16
+ * it runs to completion and persists on `agent_end` as before.
17
+ * - On `attach`, the manager hands back a replay payload: full DB history
18
+ * plus a snapshot of the currently in-flight turn (if any). The client
19
+ * replays the snapshot through the same reducer it uses for live events
20
+ * and continues streaming naturally.
21
+ * - Persistence shape is unchanged: only the final assistant message is
22
+ * written to SQLite on `agent_end`. In-flight events live in memory only.
23
+ * A server crash mid-turn discards the in-flight state — acceptable
24
+ * for MVP.
25
+ *
26
+ * Failure modes:
27
+ * - Pi throws synchronously in `prompt()` → bridge surfaces as `error`
28
+ * event; manager broadcasts and clears `currentTurn`.
29
+ * - One subscriber's `ws.send` throws → caught, logged, removed from the
30
+ * subscriber set; broadcast continues to the rest.
31
+ * - `agent_end` arrives without a current turn (defensive) → broadcast
32
+ * anyway so any late attachers don't get stuck.
33
+ *
34
+ * TODO (future): idle GC. A `SessionStream` with `subscribers.size === 0`
35
+ * and no current turn could be disposed after some grace window (e.g. 5
36
+ * minutes) to release pi resources for chronically-idle sessions. Skipped
37
+ * for now — streams accumulate for the lifetime of the server process.
38
+ */
39
+ import { type AgentBridgeOptions } from "./agent-bridge.js";
40
+ import type { SessionStore } from "./storage.js";
41
+ import type { ImageAttachment, InProgressTurnSnapshot, ServerEvent, WireMessage, WireSessionMemoryDetails } from "./wire.js";
42
+ /**
43
+ * Anything we can `send` and `close` on. The `ws` library's WebSocket fits;
44
+ * tests can pass a stub. Kept minimal so we don't drag the `ws` types in.
45
+ */
46
+ export interface Subscriber {
47
+ /** Send a JSON-serialized event. Implementations should be best-effort. */
48
+ send(event: ServerEvent): void;
49
+ /** True when the subscriber is no longer reachable (closed/closing). */
50
+ isOpen(): boolean;
51
+ }
52
+ /**
53
+ * Bridge-shaped object — `AgentBridge` is the only real impl; tests duck-type
54
+ * via this interface. Identical contract to `BridgeLike` in `routes.ts` but
55
+ * defined here too so `session-stream.ts` doesn't depend on `routes.ts`.
56
+ */
57
+ export interface BridgeLike {
58
+ start(): Promise<void>;
59
+ prompt(text: string, images?: ImageAttachment[]): Promise<void>;
60
+ dispose(): void;
61
+ /**
62
+ * Manually compact the session context via pi's built-in compaction.
63
+ * Fires compaction_start / compaction_end events through the bridge's
64
+ * emit callback. Used by the Fork & Compact flow after the first
65
+ * assistant turn of a forked session completes.
66
+ */
67
+ compact?(customInstructions?: string): Promise<void>;
68
+ /**
69
+ * Optional sticky reasoning effort. Maps frontend effort strings
70
+ * (xhigh|high|medium|low|minimal|none) to pi ThinkingLevel.
71
+ */
72
+ setReasoningEffort?(effort: string | undefined): void;
73
+ /**
74
+ * Optional sticky model selection. Phase 3 (Available Models whitelist).
75
+ * Real AgentBridge implements this; test stubs may omit it (the manager
76
+ * skips the call when undefined, which is exactly what tests want).
77
+ * Returns true when the model is in effect; false when the bridge
78
+ * surfaced an error (the manager will then drop the prompt).
79
+ */
80
+ setModel?(modelId: string | null | undefined): Promise<boolean>;
81
+ /**
82
+ * Return the modelId of the first available model from the backend
83
+ * whitelist (preserving backend sortOrder). Used as defense-in-depth
84
+ * default when neither the envelope nor SQLite supply a modelId.
85
+ * Returns `undefined` when no models are available.
86
+ */
87
+ getFirstAvailableModelId?(): string | undefined;
88
+ /**
89
+ * Return current session context usage from pi's built-in estimator.
90
+ * Returns `undefined` when the bridge hasn't started yet or the model
91
+ * has no context window configured.
92
+ */
93
+ getContextUsage?(): {
94
+ tokens: number | null;
95
+ contextWindow: number;
96
+ percent: number | null;
97
+ } | undefined;
98
+ getSessionBranch?(): Array<{
99
+ type: string;
100
+ id: string;
101
+ timestamp?: string;
102
+ message?: unknown;
103
+ content?: unknown;
104
+ customType?: string;
105
+ summary?: unknown;
106
+ fromId?: string;
107
+ data?: unknown;
108
+ details?: unknown;
109
+ firstKeptEntryId?: string;
110
+ }>;
111
+ getMemoryActivity?(): {
112
+ phase: "idle" | "observing" | "compacting" | "reflecting" | "pruning";
113
+ inFlight: {
114
+ observer: boolean;
115
+ compaction: boolean;
116
+ reflection: boolean;
117
+ pruner: boolean;
118
+ };
119
+ };
120
+ }
121
+ /** Factory signature shared with `routes.ts`. */
122
+ export type BridgeFactory = (args: AgentBridgeOptions) => BridgeLike;
123
+ export interface SessionMemoryStatus {
124
+ mode: "active" | "passive";
125
+ phase: "idle" | "observing" | "compacting" | "reflecting" | "pruning";
126
+ inFlight: {
127
+ observer: boolean;
128
+ compaction: boolean;
129
+ reflection: boolean;
130
+ pruner: boolean;
131
+ };
132
+ reflections: {
133
+ count: number;
134
+ tokens: number;
135
+ };
136
+ observations: {
137
+ committedCount: number;
138
+ committedTokens: number;
139
+ pendingCount: number;
140
+ pendingTokens: number;
141
+ };
142
+ thresholds: {
143
+ observation: number;
144
+ compaction: number;
145
+ reflection: number;
146
+ };
147
+ progress: {
148
+ sinceObservationBoundTokens: number;
149
+ sinceLastCompactionTokens: number;
150
+ observationPoolTokens: number;
151
+ };
152
+ }
153
+ export interface AttachResult {
154
+ history: WireMessage[];
155
+ currentTurn: InProgressTurnSnapshot | null;
156
+ /** Resolves when the underlying pi session is ready (or rejects on start failure). */
157
+ ready: Promise<void>;
158
+ /** True when this session was created via "Fork & Compact" and has not yet
159
+ * triggered its first compaction. The dispatcher includes this in
160
+ * `session_ready` so the frontend can adapt the send button. */
161
+ forkCompactPending: boolean;
162
+ /** Cumulative context tokens used across the session (null initially, updated on first token_usage). */
163
+ contextWindowUsed: number | null;
164
+ /** Model's total context window in tokens (null if model metadata not yet available). */
165
+ contextWindowMax: number | null;
166
+ }
167
+ export interface SessionStreamManagerOptions {
168
+ store: SessionStore;
169
+ /**
170
+ * Fallback cwd used ONLY when a session has no resolvable project (which
171
+ * shouldn't happen in normal operation since FK enforces it). Sessions
172
+ * with a valid project always run pi against `project.path`.
173
+ */
174
+ cwd: string;
175
+ /**
176
+ * Backend base URL — threaded into every AgentBridge so pi proxies all
177
+ * inference through `${backendUrl}/v1` instead of reading
178
+ * `~/.spectral/agent/auth.json`. Required in production; tests that supply a
179
+ * `bridgeFactory` may pass any non-empty placeholder.
180
+ */
181
+ backendUrl: string;
182
+ /**
183
+ * Machine JWT — used as the Bearer credential pi sends to the backend
184
+ * proxy on every inference call. See `backendUrl` for context.
185
+ */
186
+ machineJwt: string;
187
+ bridgeFactory?: BridgeFactory;
188
+ agentDir?: string;
189
+ }
190
+ export declare class SessionStreamManager {
191
+ private readonly store;
192
+ private readonly cwd;
193
+ private readonly backendUrl;
194
+ private readonly machineJwt;
195
+ private readonly bridgeFactory;
196
+ private readonly agentDir;
197
+ private readonly streams;
198
+ private disposed;
199
+ constructor(opts: SessionStreamManagerOptions);
200
+ /**
201
+ * Attach a subscriber to a session. Lazily creates the underlying pi
202
+ * session on first attach. The caller is responsible for sending the
203
+ * initial `session_ready` frame using the returned replay payload (this
204
+ * keeps wire-protocol concerns in the routes layer).
205
+ *
206
+ * Throws if the session id is unknown in SQLite (caller should turn this
207
+ * into a wire-level error frame + close).
208
+ */
209
+ attach(sessionId: string, subscriber: Subscriber): AttachResult;
210
+ /**
211
+ * Detach a subscriber. Idempotent. Does NOT dispose the underlying pi
212
+ * session — even when subscribers reach zero, the in-flight turn must
213
+ * complete and persist.
214
+ */
215
+ detach(sessionId: string, subscriber: Subscriber): void;
216
+ /** True if the session has an in-flight turn (manager-side; not WS-side). */
217
+ hasActiveTurn(sessionId: string): boolean;
218
+ /**
219
+ * Return the set of session IDs that currently have an in-flight turn.
220
+ * Cheap O(streams) scan used by the list-project / list-sessions endpoints
221
+ * to enrich responses with `hasActiveTurn` markers so the frontend can
222
+ * render a yellow pulsating dot next to active sessions/projects.
223
+ */
224
+ getActiveTurnSessionIds(): Set<string>;
225
+ getSessionMemoryStatus(sessionId: string): SessionMemoryStatus;
226
+ getSessionMemoryDetails(sessionId: string): WireSessionMemoryDetails;
227
+ compactSession(sessionId: string): Promise<void>;
228
+ /**
229
+ * Persist a user message and forward it to pi. Resolves after the user
230
+ * message is persisted + pi is invoked (NOT after the turn completes —
231
+ * the turn lifetime is observed via the broadcast stream).
232
+ *
233
+ * Broadcast ordering:
234
+ * 1. user message persisted to SQLite
235
+ * 2. `user_message_appended` broadcast to all subscribers (including
236
+ * the originating tab)
237
+ * 3. new `currentTurn` opened
238
+ * 4. `bridge.prompt()` invoked (events arrive asynchronously and are
239
+ * buffered + broadcast as they come)
240
+ *
241
+ * Sticky model selection (Phase 3 — Available Models whitelist):
242
+ * - When `modelId` is provided, we apply it via `bridge.setModel()` and
243
+ * persist to SQLite for cross-restart recovery, BEFORE invoking
244
+ * `bridge.prompt()`. If `setModel` fails (unknown model, registry
245
+ * unavailable, pi-side error) the bridge has already emitted an
246
+ * `error` wire event and we drop the prompt to avoid running it
247
+ * against the wrong model.
248
+ * - When `modelId` is omitted, we look up SQLite. If a previous turn
249
+ * persisted a value, we reapply it on this turn (this is the
250
+ * cross-restart recovery path: a fresh server process has lost pi's
251
+ * in-memory model state, so we re-pin from durable storage).
252
+ * - When neither envelope nor SQLite have a value, we leave model
253
+ * selection to pi's own settings file (pre-Phase-3 behaviour).
254
+ */
255
+ prompt(sessionId: string, content: string, modelId?: string, images?: ImageAttachment[], reasoningEffort?: string): Promise<void>;
256
+ /**
257
+ * Tear down everything. Best-effort: disposes every bridge, drops all
258
+ * subscribers. After this the manager is unusable.
259
+ */
260
+ dispose(): void;
261
+ /** Test/inspection helper: how many streams are currently tracked. */
262
+ streamCount(): number;
263
+ /**
264
+ * Count of sessions with an in-flight turn (i.e. a `currentTurn` set).
265
+ * Used by `gracefulShutdown` to decide whether to keep waiting before
266
+ * tearing down — a non-zero count means at least one assistant response
267
+ * is mid-stream and we'd rather let it finish (within the grace window)
268
+ * than orphan a half-streamed message in the UI.
269
+ *
270
+ * Cheap O(streams) scan; we only call it ~50× during a 5 s graceful
271
+ * shutdown so the linear walk is fine.
272
+ */
273
+ activeTurnCount(): number;
274
+ /**
275
+ * Cancel the in-flight turn for a session (user pressed Stop in the UI).
276
+ * Disposes the pi bridge and broadcasts `agent_end` so all subscribers
277
+ * see the turn close. The stream itself is kept alive — the next user
278
+ * message (via `prompt()`) will lazily create a fresh bridge.
279
+ *
280
+ * Idempotent: if no stream exists for the session, or no turn is in
281
+ * flight, this is a no-op.
282
+ */
283
+ cancelTurn(sessionId: string): void;
284
+ /**
285
+ * Tear down a single session's stream — disposes the pi bridge and clears
286
+ * subscribers. Idempotent. Called by the routes layer right before
287
+ * `DELETE /api/sessions/:id` so the SQL cascade doesn't leave a zombie
288
+ * pi process driving events at a session that no longer exists.
289
+ *
290
+ * Does NOT remove the session from the store — that's the caller's job.
291
+ */
292
+ disposeSessionStream(sessionId: string): void;
293
+ /**
294
+ * Tear down every stream whose session belongs to the given list of ids.
295
+ * Used by the project-delete path: the route layer reads the project's
296
+ * session ids from `deleteProject()` and passes them here BEFORE the SQL
297
+ * cascade fires, so no pi process ever observes the FK cascade.
298
+ */
299
+ disposeProjectStreams(sessionIds: readonly string[]): void;
300
+ /**
301
+ * Set the autonomous iterative loop state for a session.
302
+ *
303
+ * When `active` is true, the manager replays `originalPrompt` after each
304
+ * `agent_end` event — the agent sees its own file changes from prior
305
+ * iterations and iteratively improves its solution (Ralph Wiggum pattern).
306
+ * The loop stops when the agent emits `<LOOP_DONE>` in its response or the
307
+ * safety iteration limit is reached.
308
+ */
309
+ setLoopActive(sessionId: string, active: boolean, originalPrompt?: string, maxIterations?: number, goal?: string): void;
310
+ /**
311
+ * Fork & Compact: trigger compaction after the first assistant turn of a
312
+ * forked session. Uses pi's built-in `compact()` which generates a summary
313
+ * of older context, retaining the most recent ~20K tokens (including the
314
+ * user's new message + the assistant's response).
315
+ *
316
+ * Custom instructions reference the most recent user message so the LLM
317
+ * summary prioritizes information relevant to the current task.
318
+ */
319
+ private triggerForkCompact;
320
+ /**
321
+ * Send the next prompt for an autonomous loop iteration, waiting for any
322
+ * in-flight observational-memory compaction to finish first so the LLM
323
+ * sees the compacted context.
324
+ *
325
+ * The compaction-trigger extension fires on agent_end (via setTimeout),
326
+ * so we poll stream.compacting briefly. If compaction hasn't started after
327
+ * a short grace period, we check whether the context window exceeds the
328
+ * threshold and proactively trigger compaction via the bridge (which
329
+ * invokes pi's full pipeline, including the session_before_compact hook
330
+ * where the observational memory extension provides its summary).
331
+ *
332
+ * A duplicate call from the extension's delayed compaction trigger is
333
+ * harmless — pi throws "Already compacted" which the extension catches.
334
+ */
335
+ /**
336
+ * Send the next prompt for an autonomous loop iteration, compacting first
337
+ * if the context window exceeds the threshold.
338
+ *
339
+ * Instead of polling for the extension's delayed compaction-trigger (which
340
+ * fires via setTimeout), we proactively call bridge.compact() directly.
341
+ * bridge.compact() → session.compact() → fires session_before_compact
342
+ * (where the extension's compaction-hook provides the observational-memory
343
+ * summary), then appends the compaction entry, reloads the compacted
344
+ * context into agent.state.messages, and emits compaction_start/end.
345
+ *
346
+ * The extension's trigger still fires (via setTimeout), but by the time
347
+ * its callback runs, bridge.compact() has already appended the compaction
348
+ * entry → prepareCompaction() returns undefined → "Already compacted"
349
+ * → the trigger's onError handler catches it harmlessly.
350
+ */
351
+ private buildLoopPrompt;
352
+ private sendNextLoopIteration;
353
+ private createStream;
354
+ private handleBridgeEvent;
355
+ /**
356
+ * Flush the current in-flight turn's events to SQLite for crash recovery.
357
+ * Only the events accumulated since the last flush are written — we append
358
+ * them to the already-stored JSONL via INSERT OR REPLACE. Called every
359
+ * `BATCH_FLUSH_INTERVAL` events from `handleBridgeEvent`.
360
+ *
361
+ * Errors are caught, logged, and swallowed: batch persistence is a
362
+ * best-effort hardening, never a failure path that should block the stream.
363
+ */
364
+ private flushInFlightTurn;
365
+ private broadcast;
366
+ /**
367
+ * Push the current prompt queue state to all subscribers of a session.
368
+ * Called after every queue mutation (enqueue, remove, clear, dequeue).
369
+ * Safe to call when no stream exists or no subscribers — silently no-ops.
370
+ */
371
+ pushQueueState(sessionId: string): void;
372
+ /**
373
+ * Auto-dequeue the next prompt from the persistent queue and start a
374
+ * new turn. Called from the `agent_end` handler when no loop is active.
375
+ * Returns true if a prompt was dequeued and a turn started.
376
+ */
377
+ private maybeAutoDequeue;
378
+ }
379
+ //# sourceMappingURL=session-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-stream.d.ts","sourceRoot":"","sources":["../../src/server/session-stream.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Graceful shutdown helper for `spectral serve`.
3
+ *
4
+ * Why a separate module:
5
+ * - The shutdown flag (`shutdownState.isShuttingDown`) is read by the relay
6
+ * dispatcher to reject new `client_message` envelopes. Putting it on
7
+ * `serve.ts` would create a circular import (dispatcher → serve → relay
8
+ * client → …); pulling it out keeps the dependency graph linear.
9
+ * - The orchestration is small but has enough edge cases (idempotent on a
10
+ * second SIGTERM, bounded wait for in-flight streams, best-effort store
11
+ * close) that it's worth one focused unit test.
12
+ *
13
+ * Behaviour summary (matches the contract in the Batch 6 brief):
14
+ * 1. First SIGINT/SIGTERM:
15
+ * - Log "Shutting down…" to stderr.
16
+ * - Flip `shutdownState.isShuttingDown = true`. From this point on the
17
+ * dispatcher refuses new `client_message` frames with an error
18
+ * wrapped as a `ws_event` (so the browser sees the rejection on the
19
+ * same stream it was using).
20
+ * - Wait up to `gracePeriodMs` (default 5_000 ms) for the in-flight
21
+ * stream count reported by `inFlightCount()` to drain to 0. Polled
22
+ * every 100 ms — any non-zero value indicates an active turn.
23
+ * - Close the relay (code 1000, reason "shutdown") and dispose the
24
+ * manager. The dispose order matters: relay first so the backend
25
+ * sees a clean close before our local state goes; manager second so
26
+ * any pi processes get torn down deterministically.
27
+ * - Close the SQLite store (best-effort — a failure here just gets
28
+ * logged; the process is exiting anyway).
29
+ * - Exit with the supplied code (default 0).
30
+ * 2. Second SIGINT/SIGTERM during the grace period: skip the wait, force
31
+ * immediate exit with code 1. We don't want a hung pi process to
32
+ * prevent operators from killing the server with a second Ctrl-C.
33
+ *
34
+ * The function is intentionally framework-free — it takes plain callbacks
35
+ * for everything I/O-shaped so the unit test can exercise the orchestration
36
+ * without spawning a real relay or sqlite handle.
37
+ */
38
+ /**
39
+ * Process-wide shutdown flag. Read by the dispatcher to gate new
40
+ * `client_message` envelopes; written by `gracefulShutdown` (and by tests
41
+ * via `resetShutdownState`).
42
+ *
43
+ * Module-level singleton because there is exactly one server process per
44
+ * `spectral serve` invocation; co-locating with serve.ts would require
45
+ * threading the flag through the dispatcher's deps (already a small
46
+ * object) and risks dispatcher tests carrying serve.ts state.
47
+ */
48
+ export declare const shutdownState: {
49
+ isShuttingDown: boolean;
50
+ };
51
+ /**
52
+ * Reset the singleton flag. Tests use this in `beforeEach` so a previous
53
+ * test's shutdown doesn't bleed into the next. Production code must NOT
54
+ * call this — once the process is shutting down, it's shutting down.
55
+ */
56
+ export declare function resetShutdownState(): void;
57
+ export interface GracefulShutdownOptions {
58
+ /** Logger; defaults to `console`. Tests inject a noop or a recorder. */
59
+ logger?: Pick<Console, "log" | "warn" | "error">;
60
+ /**
61
+ * Reports in-flight stream count (e.g. `() => manager.activeTurnCount()`).
62
+ * Polled every 100 ms until it returns 0 or `gracePeriodMs` elapses.
63
+ * If omitted we skip the wait entirely (treated as "nothing in flight").
64
+ */
65
+ inFlightCount?: () => number;
66
+ /** Close the relay with code 1000 / reason "shutdown". */
67
+ closeRelay?: () => void | Promise<void>;
68
+ /** Dispose the SessionStreamManager (kills pi processes). */
69
+ disposeManager?: () => void | Promise<void>;
70
+ /** Close the SQLite store. Failures are logged, not rethrown. */
71
+ closeStore?: () => void;
72
+ /** Bound on how long to wait for in-flight streams. Default 5_000 ms. */
73
+ gracePeriodMs?: number;
74
+ /** Polling interval for the in-flight wait. Default 100 ms. */
75
+ pollIntervalMs?: number;
76
+ /** Exit code on a clean first-signal shutdown. Default 0. */
77
+ exitCode?: number;
78
+ /**
79
+ * Override `process.exit` for tests. Not called as a function reference
80
+ * directly so the test can assert on what was requested without actually
81
+ * killing vitest.
82
+ */
83
+ exitFn?: (code: number) => void;
84
+ /**
85
+ * Sleep helper. Tests inject a mock clock; production uses real
86
+ * `setTimeout`. Resolves after `ms` milliseconds.
87
+ */
88
+ sleep?: (ms: number) => Promise<void>;
89
+ }
90
+ /** Test-only: reset the entry counter alongside `shutdownState`. */
91
+ export declare function resetShutdownEntryCount(): void;
92
+ /**
93
+ * Run the graceful shutdown sequence. Idempotent on the entry-count
94
+ * dimension: the second concurrent call resolves immediately after
95
+ * triggering an immediate exit.
96
+ *
97
+ * Returns once the supplied `exitFn` has been invoked (or would have been
98
+ * invoked in production where `process.exit` does not return). Tests can
99
+ * await it to assert ordering.
100
+ */
101
+ export declare function gracefulShutdown(opts?: GracefulShutdownOptions): Promise<void>;
102
+ //# sourceMappingURL=shutdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shutdown.d.ts","sourceRoot":"","sources":["../../src/server/shutdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE;IAAE,cAAc,EAAE,OAAO,CAAA;CAEpD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,MAAM,WAAW,uBAAuB;IACtC,wEAAwE;IACxE,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACjD;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,MAAM,CAAC;IAC7B,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,+DAA+D;IAC/D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC;;;OAGG;IACH,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAaD,oEAAoE;AACpE,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,GAAE,uBAA4B,GACjC,OAAO,CAAC,IAAI,CAAC,CAmGf"}