gsd-pi 2.71.0-dev.06b86c6 → 2.71.0-dev.246c32d

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 (289) hide show
  1. package/README.md +34 -1
  2. package/dist/cli.js +17 -0
  3. package/dist/headless-events.d.ts +2 -0
  4. package/dist/headless-events.js +7 -0
  5. package/dist/headless.js +16 -3
  6. package/dist/mcp-server.js +37 -14
  7. package/dist/resource-loader.js +6 -3
  8. package/dist/resources/agents/debugger.md +58 -0
  9. package/dist/resources/agents/doc-writer.md +43 -0
  10. package/dist/resources/agents/git-ops.md +56 -0
  11. package/dist/resources/agents/javascript-pro.md +46 -271
  12. package/dist/resources/agents/planner.md +55 -0
  13. package/dist/resources/agents/refactorer.md +47 -0
  14. package/dist/resources/agents/reviewer.md +48 -0
  15. package/dist/resources/agents/security.md +59 -0
  16. package/dist/resources/agents/tester.md +50 -0
  17. package/dist/resources/agents/typescript-pro.md +41 -235
  18. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +113 -10
  19. package/dist/resources/extensions/gsd/auto/infra-errors.js +34 -0
  20. package/dist/resources/extensions/gsd/auto/loop.js +32 -1
  21. package/dist/resources/extensions/gsd/auto/phases.js +5 -1
  22. package/dist/resources/extensions/gsd/auto/session.js +11 -0
  23. package/dist/resources/extensions/gsd/auto-dashboard.js +22 -16
  24. package/dist/resources/extensions/gsd/auto-model-selection.js +10 -2
  25. package/dist/resources/extensions/gsd/auto-prompts.js +88 -33
  26. package/dist/resources/extensions/gsd/auto-start.js +33 -6
  27. package/dist/resources/extensions/gsd/auto-worktree.js +1 -1
  28. package/dist/resources/extensions/gsd/auto.js +56 -0
  29. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +3 -3
  30. package/dist/resources/extensions/gsd/bootstrap/register-shortcuts.js +63 -51
  31. package/dist/resources/extensions/gsd/commands/handlers/auto.js +10 -33
  32. package/dist/resources/extensions/gsd/commands/handlers/core.js +56 -11
  33. package/dist/resources/extensions/gsd/commands/handlers/notifications-handler.js +15 -6
  34. package/dist/resources/extensions/gsd/commands/handlers/workflow.js +4 -10
  35. package/dist/resources/extensions/gsd/dashboard-overlay.js +8 -3
  36. package/dist/resources/extensions/gsd/doctor-providers.js +23 -0
  37. package/dist/resources/extensions/gsd/error-classifier.js +4 -1
  38. package/dist/resources/extensions/gsd/forensics.js +19 -6
  39. package/dist/resources/extensions/gsd/gate-registry.js +208 -0
  40. package/dist/resources/extensions/gsd/gsd-db.js +41 -0
  41. package/dist/resources/extensions/gsd/guided-flow.js +5 -10
  42. package/dist/resources/extensions/gsd/metrics.js +1 -0
  43. package/dist/resources/extensions/gsd/milestone-actions.js +10 -4
  44. package/dist/resources/extensions/gsd/milestone-validation-gates.js +11 -12
  45. package/dist/resources/extensions/gsd/notification-overlay.js +42 -13
  46. package/dist/resources/extensions/gsd/notification-store.js +35 -4
  47. package/dist/resources/extensions/gsd/notification-widget.js +5 -13
  48. package/dist/resources/extensions/gsd/parallel-monitor-overlay.js +8 -3
  49. package/dist/resources/extensions/gsd/prompt-validation.js +126 -0
  50. package/dist/resources/extensions/gsd/prompts/complete-slice.md +3 -1
  51. package/dist/resources/extensions/gsd/prompts/execute-task.md +2 -0
  52. package/dist/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  53. package/dist/resources/extensions/gsd/session-model-override.js +25 -0
  54. package/dist/resources/extensions/gsd/shortcut-defs.js +40 -0
  55. package/dist/resources/extensions/gsd/state.js +9 -2
  56. package/dist/resources/extensions/gsd/tools/complete-slice.js +52 -1
  57. package/dist/resources/extensions/gsd/tools/complete-task.js +51 -1
  58. package/dist/resources/extensions/gsd/tools/workflow-tool-executors.js +4 -1
  59. package/dist/resources/extensions/ollama/index.js +13 -5
  60. package/dist/resources/extensions/shared/gsd-phase-state.js +35 -0
  61. package/dist/resources/extensions/subagent/agents.js +8 -0
  62. package/dist/resources/extensions/subagent/index.js +17 -0
  63. package/dist/startup-model-validation.d.ts +0 -1
  64. package/dist/startup-model-validation.js +6 -2
  65. package/dist/web/standalone/.next/BUILD_ID +1 -1
  66. package/dist/web/standalone/.next/app-path-routes-manifest.json +17 -17
  67. package/dist/web/standalone/.next/build-manifest.json +2 -2
  68. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  69. package/dist/web/standalone/.next/required-server-files.json +1 -1
  70. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  71. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  72. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  73. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  74. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  75. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  76. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  77. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  78. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  79. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  80. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  81. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  82. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  83. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  84. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  85. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  86. package/dist/web/standalone/.next/server/app/index.html +1 -1
  87. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  88. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  89. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  90. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  91. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  92. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  93. package/dist/web/standalone/.next/server/app-paths-manifest.json +17 -17
  94. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  95. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  96. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  97. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  98. package/dist/web/standalone/server.js +1 -1
  99. package/package.json +1 -1
  100. package/packages/mcp-server/dist/server.d.ts +12 -1
  101. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  102. package/packages/mcp-server/dist/server.js +90 -42
  103. package/packages/mcp-server/dist/server.js.map +1 -1
  104. package/packages/mcp-server/dist/workflow-tools.js +1 -1
  105. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  106. package/packages/mcp-server/src/server.ts +110 -38
  107. package/packages/mcp-server/src/workflow-tools.ts +1 -1
  108. package/packages/pi-ai/dist/providers/anthropic-auth.test.d.ts +2 -0
  109. package/packages/pi-ai/dist/providers/anthropic-auth.test.d.ts.map +1 -0
  110. package/packages/pi-ai/dist/providers/anthropic-auth.test.js +20 -0
  111. package/packages/pi-ai/dist/providers/anthropic-auth.test.js.map +1 -0
  112. package/packages/pi-ai/dist/providers/anthropic.d.ts +2 -1
  113. package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  114. package/packages/pi-ai/dist/providers/anthropic.js +7 -4
  115. package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
  116. package/packages/pi-ai/src/providers/anthropic-auth.test.ts +32 -0
  117. package/packages/pi-ai/src/providers/anthropic.ts +8 -4
  118. package/packages/pi-coding-agent/dist/core/agent-session-renderable-tools.test.d.ts +2 -0
  119. package/packages/pi-coding-agent/dist/core/agent-session-renderable-tools.test.d.ts.map +1 -0
  120. package/packages/pi-coding-agent/dist/core/agent-session-renderable-tools.test.js +61 -0
  121. package/packages/pi-coding-agent/dist/core/agent-session-renderable-tools.test.js.map +1 -0
  122. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  123. package/packages/pi-coding-agent/dist/core/agent-session.js +2 -1
  124. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  125. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts +10 -0
  126. package/packages/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  127. package/packages/pi-coding-agent/dist/core/auth-storage.js +27 -0
  128. package/packages/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  129. package/packages/pi-coding-agent/dist/core/auth-storage.test.js +85 -0
  130. package/packages/pi-coding-agent/dist/core/auth-storage.test.js.map +1 -1
  131. package/packages/pi-coding-agent/dist/core/model-resolver-initial-model-auth.test.d.ts +2 -0
  132. package/packages/pi-coding-agent/dist/core/model-resolver-initial-model-auth.test.d.ts.map +1 -0
  133. package/packages/pi-coding-agent/dist/core/model-resolver-initial-model-auth.test.js +64 -0
  134. package/packages/pi-coding-agent/dist/core/model-resolver-initial-model-auth.test.js.map +1 -0
  135. package/packages/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
  136. package/packages/pi-coding-agent/dist/core/model-resolver.js +22 -18
  137. package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
  138. package/packages/pi-coding-agent/dist/core/model-resolver.test.d.ts +8 -0
  139. package/packages/pi-coding-agent/dist/core/model-resolver.test.d.ts.map +1 -0
  140. package/packages/pi-coding-agent/dist/core/model-resolver.test.js +75 -0
  141. package/packages/pi-coding-agent/dist/core/model-resolver.test.js.map +1 -0
  142. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +5 -0
  143. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -1
  144. package/packages/pi-coding-agent/dist/core/retry-handler.js +55 -1
  145. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -1
  146. package/packages/pi-coding-agent/dist/core/retry-handler.test.js +57 -0
  147. package/packages/pi-coding-agent/dist/core/retry-handler.test.js.map +1 -1
  148. package/packages/pi-coding-agent/dist/core/sdk.d.ts +11 -0
  149. package/packages/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
  150. package/packages/pi-coding-agent/dist/core/sdk.js +38 -5
  151. package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
  152. package/packages/pi-coding-agent/dist/core/sdk.test.d.ts +2 -0
  153. package/packages/pi-coding-agent/dist/core/sdk.test.d.ts.map +1 -0
  154. package/packages/pi-coding-agent/dist/core/sdk.test.js +71 -0
  155. package/packages/pi-coding-agent/dist/core/sdk.test.js.map +1 -0
  156. package/packages/pi-coding-agent/dist/index.d.ts +1 -1
  157. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  158. package/packages/pi-coding-agent/dist/index.js +1 -1
  159. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  160. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/login-dialog.test.d.ts +2 -0
  161. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/login-dialog.test.d.ts.map +1 -0
  162. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/login-dialog.test.js +13 -0
  163. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/login-dialog.test.js.map +1 -0
  164. package/packages/pi-coding-agent/dist/modes/interactive/components/login-dialog.d.ts +4 -0
  165. package/packages/pi-coding-agent/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  166. package/packages/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +24 -2
  167. package/packages/pi-coding-agent/dist/modes/interactive/components/login-dialog.js.map +1 -1
  168. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  169. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js +9 -2
  170. package/packages/pi-coding-agent/dist/modes/interactive/components/model-selector.js.map +1 -1
  171. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +4 -0
  172. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  173. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +43 -0
  174. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  175. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  176. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +7 -2
  177. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  178. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.d.ts.map +1 -1
  179. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.js +6 -1
  180. package/packages/pi-coding-agent/dist/modes/interactive/controllers/model-controller.js.map +1 -1
  181. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  182. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +4 -3
  183. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  184. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js +4 -2
  185. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js.map +1 -1
  186. package/packages/pi-coding-agent/src/core/agent-session-renderable-tools.test.ts +70 -0
  187. package/packages/pi-coding-agent/src/core/agent-session.ts +2 -1
  188. package/packages/pi-coding-agent/src/core/auth-storage.test.ts +108 -0
  189. package/packages/pi-coding-agent/src/core/auth-storage.ts +30 -0
  190. package/packages/pi-coding-agent/src/core/model-resolver-initial-model-auth.test.ts +78 -0
  191. package/packages/pi-coding-agent/src/core/model-resolver.test.ts +85 -0
  192. package/packages/pi-coding-agent/src/core/model-resolver.ts +22 -18
  193. package/packages/pi-coding-agent/src/core/retry-handler.test.ts +83 -0
  194. package/packages/pi-coding-agent/src/core/retry-handler.ts +60 -1
  195. package/packages/pi-coding-agent/src/core/sdk.test.ts +89 -0
  196. package/packages/pi-coding-agent/src/core/sdk.ts +45 -9
  197. package/packages/pi-coding-agent/src/index.ts +1 -0
  198. package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/login-dialog.test.ts +24 -0
  199. package/packages/pi-coding-agent/src/modes/interactive/components/login-dialog.ts +30 -2
  200. package/packages/pi-coding-agent/src/modes/interactive/components/model-selector.ts +15 -6
  201. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +47 -0
  202. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +7 -2
  203. package/packages/pi-coding-agent/src/modes/interactive/controllers/model-controller.ts +6 -1
  204. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +4 -3
  205. package/packages/pi-coding-agent/src/modes/interactive/slash-command-handlers.ts +4 -2
  206. package/src/resources/agents/debugger.md +58 -0
  207. package/src/resources/agents/doc-writer.md +43 -0
  208. package/src/resources/agents/git-ops.md +56 -0
  209. package/src/resources/agents/javascript-pro.md +46 -271
  210. package/src/resources/agents/planner.md +55 -0
  211. package/src/resources/agents/refactorer.md +47 -0
  212. package/src/resources/agents/reviewer.md +48 -0
  213. package/src/resources/agents/security.md +59 -0
  214. package/src/resources/agents/tester.md +50 -0
  215. package/src/resources/agents/typescript-pro.md +41 -235
  216. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +122 -8
  217. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +189 -6
  218. package/src/resources/extensions/gsd/auto/infra-errors.ts +38 -0
  219. package/src/resources/extensions/gsd/auto/loop-deps.ts +2 -0
  220. package/src/resources/extensions/gsd/auto/loop.ts +45 -1
  221. package/src/resources/extensions/gsd/auto/phases.ts +6 -0
  222. package/src/resources/extensions/gsd/auto/session.ts +11 -0
  223. package/src/resources/extensions/gsd/auto-dashboard.ts +29 -18
  224. package/src/resources/extensions/gsd/auto-model-selection.ts +9 -1
  225. package/src/resources/extensions/gsd/auto-prompts.ts +111 -33
  226. package/src/resources/extensions/gsd/auto-start.ts +40 -6
  227. package/src/resources/extensions/gsd/auto-worktree.ts +1 -1
  228. package/src/resources/extensions/gsd/auto.ts +72 -0
  229. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +3 -3
  230. package/src/resources/extensions/gsd/bootstrap/register-shortcuts.ts +79 -60
  231. package/src/resources/extensions/gsd/commands/handlers/auto.ts +10 -36
  232. package/src/resources/extensions/gsd/commands/handlers/core.ts +58 -11
  233. package/src/resources/extensions/gsd/commands/handlers/notifications-handler.ts +17 -7
  234. package/src/resources/extensions/gsd/commands/handlers/workflow.ts +4 -10
  235. package/src/resources/extensions/gsd/dashboard-overlay.ts +10 -3
  236. package/src/resources/extensions/gsd/doctor-providers.ts +24 -0
  237. package/src/resources/extensions/gsd/error-classifier.ts +4 -1
  238. package/src/resources/extensions/gsd/forensics.ts +23 -7
  239. package/src/resources/extensions/gsd/gate-registry.ts +251 -0
  240. package/src/resources/extensions/gsd/gsd-db.ts +51 -0
  241. package/src/resources/extensions/gsd/guided-flow.ts +5 -10
  242. package/src/resources/extensions/gsd/interrupted-session.ts +1 -0
  243. package/src/resources/extensions/gsd/metrics.ts +12 -1
  244. package/src/resources/extensions/gsd/milestone-actions.ts +10 -3
  245. package/src/resources/extensions/gsd/milestone-validation-gates.ts +11 -13
  246. package/src/resources/extensions/gsd/notification-overlay.ts +47 -14
  247. package/src/resources/extensions/gsd/notification-store.ts +35 -4
  248. package/src/resources/extensions/gsd/notification-widget.ts +5 -14
  249. package/src/resources/extensions/gsd/parallel-monitor-overlay.ts +10 -3
  250. package/src/resources/extensions/gsd/prompt-validation.ts +157 -0
  251. package/src/resources/extensions/gsd/prompts/complete-slice.md +3 -1
  252. package/src/resources/extensions/gsd/prompts/execute-task.md +2 -0
  253. package/src/resources/extensions/gsd/prompts/validate-milestone.md +2 -0
  254. package/src/resources/extensions/gsd/session-model-override.ts +36 -0
  255. package/src/resources/extensions/gsd/shortcut-defs.ts +56 -0
  256. package/src/resources/extensions/gsd/state.ts +13 -2
  257. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +25 -9
  258. package/src/resources/extensions/gsd/tests/complete-slice-gate-closure.test.ts +167 -0
  259. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +36 -0
  260. package/src/resources/extensions/gsd/tests/forensics-stuck-loops.test.ts +62 -0
  261. package/src/resources/extensions/gsd/tests/format-shortcut.test.ts +31 -0
  262. package/src/resources/extensions/gsd/tests/gate-dispatch.test.ts +27 -0
  263. package/src/resources/extensions/gsd/tests/gate-registry.test.ts +140 -0
  264. package/src/resources/extensions/gsd/tests/infra-errors-cooldown.test.ts +180 -0
  265. package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +66 -1
  266. package/src/resources/extensions/gsd/tests/model-isolation.test.ts +36 -51
  267. package/src/resources/extensions/gsd/tests/notification-store.test.ts +18 -0
  268. package/src/resources/extensions/gsd/tests/notification-widget.test.ts +3 -2
  269. package/src/resources/extensions/gsd/tests/notifications-handler.test.ts +90 -0
  270. package/src/resources/extensions/gsd/tests/parallel-monitor-overlay.test.ts +1 -0
  271. package/src/resources/extensions/gsd/tests/park-db-sync.test.ts +18 -0
  272. package/src/resources/extensions/gsd/tests/prompt-system-gate-coverage.test.ts +208 -0
  273. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +9 -0
  274. package/src/resources/extensions/gsd/tests/register-shortcuts.test.ts +63 -5
  275. package/src/resources/extensions/gsd/tests/session-model-override.test.ts +35 -0
  276. package/src/resources/extensions/gsd/tests/start-auto-detached.test.ts +90 -0
  277. package/src/resources/extensions/gsd/tools/complete-slice.ts +63 -0
  278. package/src/resources/extensions/gsd/tools/complete-task.ts +63 -0
  279. package/src/resources/extensions/gsd/tools/workflow-tool-executors.ts +4 -1
  280. package/src/resources/extensions/gsd/types.ts +26 -0
  281. package/src/resources/extensions/ollama/index.ts +13 -3
  282. package/src/resources/extensions/ollama/ollama-status-indicator.test.ts +28 -0
  283. package/src/resources/extensions/shared/gsd-phase-state.ts +42 -0
  284. package/src/resources/extensions/shared/tests/gsd-phase-state.test.ts +48 -0
  285. package/src/resources/extensions/subagent/agents.ts +10 -0
  286. package/src/resources/extensions/subagent/index.ts +18 -0
  287. package/src/resources/extensions/subagent/tests/agents-conflicts.test.ts +33 -0
  288. /package/dist/web/standalone/.next/static/{dYVdRaunb2ZSEA8fjkT-V → hnGGkVMxIGGpxSJkf5jIV}/_buildManifest.js +0 -0
  289. /package/dist/web/standalone/.next/static/{dYVdRaunb2ZSEA8fjkT-V → hnGGkVMxIGGpxSJkf5jIV}/_ssgManifest.js +0 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * complete-slice gate closure integration test.
3
+ *
4
+ * Pins the fix for the Q8-stall bug: complete-slice must close every gate
5
+ * owned by the complete-slice turn based on the content of the matching
6
+ * CompleteSliceParams field. Without this, Q8 stays pending forever and
7
+ * blocks state derivation on subsequent loops.
8
+ */
9
+
10
+ import { describe, test, beforeEach, afterEach } from "node:test";
11
+ import assert from "node:assert/strict";
12
+ import * as fs from "node:fs";
13
+ import * as path from "node:path";
14
+ import * as os from "node:os";
15
+
16
+ import {
17
+ openDatabase,
18
+ closeDatabase,
19
+ insertMilestone,
20
+ insertSlice,
21
+ insertTask,
22
+ insertGateRow,
23
+ getGateResults,
24
+ } from "../gsd-db.ts";
25
+ import { handleCompleteSlice } from "../tools/complete-slice.ts";
26
+ import type { CompleteSliceParams } from "../types.ts";
27
+
28
+ function makeValidSliceParams(overrides: Partial<CompleteSliceParams> = {}): CompleteSliceParams {
29
+ return {
30
+ sliceId: "S01",
31
+ milestoneId: "M001",
32
+ sliceTitle: "Test Slice",
33
+ oneLiner: "Implemented test slice",
34
+ narrative: "Built and tested.",
35
+ verification: "All tests pass.",
36
+ deviations: "None.",
37
+ knownLimitations: "None.",
38
+ followUps: "None.",
39
+ keyFiles: ["src/foo.ts"],
40
+ keyDecisions: [],
41
+ patternsEstablished: [],
42
+ observabilitySurfaces: [],
43
+ provides: [],
44
+ requirementsSurfaced: [],
45
+ drillDownPaths: [],
46
+ affects: [],
47
+ requirementsAdvanced: [],
48
+ requirementsValidated: [],
49
+ requirementsInvalidated: [],
50
+ filesModified: [],
51
+ requires: [],
52
+ uatContent: "## Smoke Test\n\nVerify happy path.",
53
+ ...overrides,
54
+ };
55
+ }
56
+
57
+ describe("complete-slice closes complete-slice-owned gates", () => {
58
+ let dbPath: string;
59
+ let basePath: string;
60
+
61
+ beforeEach(() => {
62
+ dbPath = path.join(
63
+ fs.mkdtempSync(path.join(os.tmpdir(), "gsd-slice-gate-")),
64
+ "test.db",
65
+ );
66
+ openDatabase(dbPath);
67
+
68
+ basePath = fs.mkdtempSync(path.join(os.tmpdir(), "gsd-slice-gate-handler-"));
69
+ const sliceDir = path.join(
70
+ basePath, ".gsd", "milestones", "M001", "slices", "S01", "tasks",
71
+ );
72
+ fs.mkdirSync(sliceDir, { recursive: true });
73
+ fs.writeFileSync(
74
+ path.join(basePath, ".gsd", "milestones", "M001", "M001-ROADMAP.md"),
75
+ [
76
+ "# M001: Test Milestone",
77
+ "",
78
+ "## Slices",
79
+ "",
80
+ '- [ ] **S01: Test Slice** `risk:medium` `depends:[]`',
81
+ " - After this: basic functionality works",
82
+ ].join("\n"),
83
+ );
84
+
85
+ insertMilestone({ id: "M001" });
86
+ insertSlice({ id: "S01", milestoneId: "M001" });
87
+ insertTask({
88
+ id: "T01", sliceId: "S01", milestoneId: "M001",
89
+ status: "complete", title: "Task 1",
90
+ });
91
+
92
+ // Seed Q8 as pending — this is what plan-slice does today.
93
+ insertGateRow({
94
+ milestoneId: "M001", sliceId: "S01",
95
+ gateId: "Q8", scope: "slice",
96
+ });
97
+ });
98
+
99
+ afterEach(() => {
100
+ closeDatabase();
101
+ fs.rmSync(path.dirname(dbPath), { recursive: true, force: true });
102
+ fs.rmSync(basePath, { recursive: true, force: true });
103
+ });
104
+
105
+ test("Q8 closes as 'pass' when operationalReadiness is populated", async () => {
106
+ const params = makeValidSliceParams({
107
+ operationalReadiness: [
108
+ "- Health signal: /health endpoint returns 200",
109
+ "- Failure signal: error rate alert in observability dashboard",
110
+ "- Recovery: systemd auto-restart",
111
+ ].join("\n"),
112
+ });
113
+
114
+ const result = await handleCompleteSlice(params, basePath);
115
+ assert.ok(!("error" in result), `handler failed: ${(result as any).error}`);
116
+
117
+ const gates = getGateResults("M001", "S01", "slice");
118
+ const q8 = gates.find((g) => g.gate_id === "Q8");
119
+ assert.ok(q8, "Q8 row must exist after complete-slice");
120
+ assert.equal(q8.status, "complete");
121
+ assert.equal(q8.verdict, "pass");
122
+ assert.ok(
123
+ q8.findings.includes("Health signal"),
124
+ "Q8 findings must capture the operationalReadiness content",
125
+ );
126
+ });
127
+
128
+ test("Q8 closes as 'omitted' when operationalReadiness is empty", async () => {
129
+ const params = makeValidSliceParams({ operationalReadiness: "" });
130
+
131
+ const result = await handleCompleteSlice(params, basePath);
132
+ assert.ok(!("error" in result), `handler failed: ${(result as any).error}`);
133
+
134
+ const gates = getGateResults("M001", "S01", "slice");
135
+ const q8 = gates.find((g) => g.gate_id === "Q8");
136
+ assert.ok(q8, "Q8 row must exist after complete-slice");
137
+ assert.equal(q8.status, "complete");
138
+ assert.equal(q8.verdict, "omitted");
139
+ });
140
+
141
+ test("Q8 also closes when operationalReadiness is omitted entirely", async () => {
142
+ // A model that doesn't pass operationalReadiness at all must still
143
+ // move Q8 out of 'pending' — leaving it pending produces the stall.
144
+ const params = makeValidSliceParams();
145
+ const result = await handleCompleteSlice(params, basePath);
146
+ assert.ok(!("error" in result), `handler failed: ${(result as any).error}`);
147
+
148
+ const gates = getGateResults("M001", "S01", "slice");
149
+ const q8 = gates.find((g) => g.gate_id === "Q8");
150
+ assert.ok(q8);
151
+ assert.notEqual(q8.status, "pending", "Q8 must never remain pending after complete-slice");
152
+ assert.equal(q8.verdict, "omitted");
153
+ });
154
+
155
+ test("summary markdown contains Operational Readiness section", async () => {
156
+ const params = makeValidSliceParams({
157
+ operationalReadiness: "- Health signal: /health\n- Failure signal: alert",
158
+ });
159
+ const result = await handleCompleteSlice(params, basePath);
160
+ assert.ok(!("error" in result));
161
+ if (!("error" in result)) {
162
+ const summary = fs.readFileSync(result.summaryPath, "utf-8");
163
+ assert.match(summary, /^## Operational Readiness/m);
164
+ assert.match(summary, /Health signal: \/health/);
165
+ }
166
+ });
167
+ });
@@ -574,6 +574,42 @@ test("runProviderChecks reports ok for OpenAI via openai-codex auth.json (#2922)
574
574
  rmSync(tmpHome, { recursive: true, force: true });
575
575
  });
576
576
 
577
+ test("runProviderChecks reports ok for claude-code without any API key", () => {
578
+ const repo = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-cc-repo-")));
579
+ mkdirSync(join(repo, ".gsd"), { recursive: true });
580
+ writeFileSync(
581
+ join(repo, ".gsd", "PREFERENCES.md"),
582
+ [
583
+ "---",
584
+ "models:",
585
+ " execution:",
586
+ " model: claude-sonnet-4-6",
587
+ " provider: claude-code",
588
+ "---",
589
+ "",
590
+ ].join("\n"),
591
+ );
592
+
593
+ const tmpHome = realpathSync(mkdtempSync(join(tmpdir(), "gsd-providers-cc-home-")));
594
+
595
+ withEnv({
596
+ HOME: tmpHome,
597
+ ANTHROPIC_API_KEY: undefined,
598
+ ANTHROPIC_OAUTH_TOKEN: undefined,
599
+ }, () => {
600
+ withCwd(repo, () => {
601
+ const results = runProviderChecks();
602
+ const cc = results.find(r => r.name === "claude-code");
603
+ assert.ok(cc, "claude-code result should exist");
604
+ assert.equal(cc!.status, "ok", "claude-code uses CLI auth — must be ok without API keys");
605
+ assert.ok(cc!.message.includes("CLI auth"), "should indicate CLI auth");
606
+ });
607
+ });
608
+
609
+ rmSync(repo, { recursive: true, force: true });
610
+ rmSync(tmpHome, { recursive: true, force: true });
611
+ });
612
+
577
613
  test("PROVIDER_ROUTES includes google-gemini-cli as route for google (#2922)", async () => {
578
614
  const { readFileSync: readFS } = await import("node:fs");
579
615
  const { dirname: dirn, join: joinPath } = await import("node:path");
@@ -101,3 +101,65 @@ test("#1943 detectStuckLoops ignores watchdog duplicates but flags real re-dispa
101
101
  assert.equal(anomalies.length, 1, `expected 1 anomaly (for the 3x dispatched task), got ${anomalies.length}`);
102
102
  assert.ok(anomalies[0].summary.includes("3 times"));
103
103
  });
104
+
105
+ test("#3760 detectStuckLoops ignores cross-session recovery re-dispatches", () => {
106
+ const anomalies: ForensicAnomaly[] = [];
107
+
108
+ const units: UnitMetrics[] = [
109
+ makeUnit({
110
+ type: "plan-slice",
111
+ id: "M001/S02",
112
+ startedAt: 1000,
113
+ finishedAt: 2000,
114
+ autoSessionKey: "session-a",
115
+ }),
116
+ makeUnit({
117
+ type: "plan-slice",
118
+ id: "M001/S02",
119
+ startedAt: 5000,
120
+ finishedAt: 6000,
121
+ autoSessionKey: "session-b",
122
+ }),
123
+ ];
124
+
125
+ detectStuckLoops(units, anomalies);
126
+
127
+ assert.equal(anomalies.length, 0, "cross-session recovery should not be flagged as a stuck loop");
128
+ });
129
+
130
+ test("#3760 detectStuckLoops still flags repeated dispatches within one auto session", () => {
131
+ const anomalies: ForensicAnomaly[] = [];
132
+
133
+ const units: UnitMetrics[] = [
134
+ makeUnit({
135
+ type: "complete-slice",
136
+ id: "M011/S02",
137
+ startedAt: 1000,
138
+ finishedAt: 2000,
139
+ autoSessionKey: "session-a",
140
+ }),
141
+ makeUnit({
142
+ type: "complete-slice",
143
+ id: "M011/S02",
144
+ startedAt: 5000,
145
+ finishedAt: 6000,
146
+ autoSessionKey: "session-a",
147
+ }),
148
+ makeUnit({
149
+ type: "complete-slice",
150
+ id: "M011/S02",
151
+ startedAt: 9000,
152
+ finishedAt: 10000,
153
+ autoSessionKey: "session-b",
154
+ }),
155
+ ];
156
+
157
+ detectStuckLoops(units, anomalies);
158
+
159
+ assert.equal(anomalies.length, 1, "within-session retries should still be flagged");
160
+ assert.ok(anomalies[0].summary.includes("2 times"), `summary should reflect the worst same-session loop: ${anomalies[0].summary}`);
161
+ assert.ok(
162
+ anomalies[0].details.includes("Cross-session recovery runs are ignored"),
163
+ `details should explain the session-aware rule: ${anomalies[0].details}`,
164
+ );
165
+ });
@@ -4,6 +4,7 @@
4
4
  import test from 'node:test';
5
5
  import assert from 'node:assert/strict';
6
6
  import { formatShortcut } from '../files.ts';
7
+ import { formattedShortcutPair, primaryShortcutCombo, fallbackShortcutCombo } from '../shortcut-defs.ts';
7
8
 
8
9
  // ─── formatShortcut renders per-platform shortcuts ──────────────────────
9
10
 
@@ -67,3 +68,33 @@ test('formatShortcut: passes through plain key names', () => {
67
68
  assert.strictEqual(formatShortcut('Escape'), 'Escape');
68
69
  assert.strictEqual(formatShortcut('Enter'), 'Enter');
69
70
  });
71
+
72
+ test("shortcut-defs: exposes canonical dashboard combos", () => {
73
+ assert.equal(primaryShortcutCombo("dashboard"), "Ctrl+Alt+G");
74
+ assert.equal(fallbackShortcutCombo("dashboard"), "Ctrl+Shift+G");
75
+ });
76
+
77
+ test("shortcut-defs: formats shortcut pair using platform symbols", () => {
78
+ const pair = formattedShortcutPair("notifications");
79
+ if (process.platform === "darwin") {
80
+ assert.equal(pair, "⌃⌥N / ⌃⇧N");
81
+ } else {
82
+ assert.equal(pair, "Ctrl+Alt+N / Ctrl+Shift+N");
83
+ }
84
+ });
85
+
86
+ test("shortcut-defs: parallel shortcut omits fallback (hasFallback: false)", () => {
87
+ const pair = formattedShortcutPair("parallel");
88
+ if (process.platform === "darwin") {
89
+ assert.equal(pair, "⌃⌥P", "parallel should only show primary combo");
90
+ } else {
91
+ assert.equal(pair, "Ctrl+Alt+P", "parallel should only show primary combo");
92
+ }
93
+ // Verify it does NOT contain the fallback separator
94
+ assert.ok(!pair.includes("/"), "parallel pair should not contain fallback separator");
95
+ });
96
+
97
+ test("shortcut-defs: dashboard shortcut includes fallback (hasFallback: true)", () => {
98
+ const pair = formattedShortcutPair("dashboard");
99
+ assert.ok(pair.includes("/"), "dashboard pair should contain fallback separator");
100
+ });
@@ -186,4 +186,31 @@ describe("evaluating-gates phase", () => {
186
186
  insertGateRow({ milestoneId: "M001", sliceId: "S01", gateId: "Q5", scope: "task", taskId: "T01" });
187
187
  assert.equal(getPendingSliceGateCount("M001", "S01"), 1);
188
188
  });
189
+
190
+ test("Q8 (owned by complete-slice) does not block evaluating-gates phase", async () => {
191
+ // Regression: Q8 is stored with scope:"slice" but owned by the
192
+ // complete-slice turn. Before the gate registry landed, deriveState
193
+ // counted Q8 as a blocker for evaluating-gates while the gate-evaluate
194
+ // prompt silently dropped Q8 — an unrecoverable stall. After the
195
+ // registry change, deriveState filters by owner turn, so Q8 never
196
+ // blocks evaluating-gates.
197
+ planSlice(tmpDir);
198
+ await renderPlanFromDb(tmpDir, "M001", "S01");
199
+
200
+ insertGateRow({ milestoneId: "M001", sliceId: "S01", gateId: "Q3", scope: "slice" });
201
+ insertGateRow({ milestoneId: "M001", sliceId: "S01", gateId: "Q4", scope: "slice" });
202
+ insertGateRow({ milestoneId: "M001", sliceId: "S01", gateId: "Q8", scope: "slice" });
203
+
204
+ saveGateResult({ milestoneId: "M001", sliceId: "S01", gateId: "Q3", verdict: "pass", rationale: "OK", findings: "" });
205
+ saveGateResult({ milestoneId: "M001", sliceId: "S01", gateId: "Q4", verdict: "omitted", rationale: "N/A", findings: "" });
206
+ // Q8 deliberately left pending — it's complete-slice's problem.
207
+
208
+ invalidateStateCache();
209
+ const state = await deriveState(tmpDir);
210
+ assert.equal(
211
+ state.phase,
212
+ "executing",
213
+ `pending Q8 must not stall evaluating-gates — got phase=${state.phase}`,
214
+ );
215
+ });
189
216
  });
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Gate registry tests — enforce that every declared GateId has a registry
3
+ * entry, that every owner-turn bucket is non-empty, and that coverage
4
+ * assertions fail loudly instead of silently skipping unknown gates.
5
+ */
6
+
7
+ import { describe, test } from "node:test";
8
+ import assert from "node:assert/strict";
9
+
10
+ import {
11
+ GATE_REGISTRY,
12
+ assertGateCoverage,
13
+ getGateDefinition,
14
+ getGateIdsForTurn,
15
+ getGatesForTurn,
16
+ getOwnerTurn,
17
+ type OwnerTurn,
18
+ } from "../gate-registry.ts";
19
+ import type { GateId } from "../types.ts";
20
+
21
+ /** Authoritative list of GateIds as declared in types.ts. */
22
+ const ALL_GATE_IDS: readonly GateId[] = [
23
+ "Q3", "Q4", "Q5", "Q6", "Q7", "Q8",
24
+ "MV01", "MV02", "MV03", "MV04",
25
+ ];
26
+
27
+ const ALL_OWNER_TURNS: readonly OwnerTurn[] = [
28
+ "gate-evaluate",
29
+ "execute-task",
30
+ "complete-slice",
31
+ "validate-milestone",
32
+ ];
33
+
34
+ describe("gate-registry", () => {
35
+ test("every declared GateId has a registry entry", () => {
36
+ for (const id of ALL_GATE_IDS) {
37
+ const def = GATE_REGISTRY[id];
38
+ assert.ok(def, `missing registry entry for gate ${id}`);
39
+ assert.equal(def.id, id);
40
+ assert.ok(def.question.length > 0, `${id} missing question`);
41
+ assert.ok(def.guidance.length > 0, `${id} missing guidance`);
42
+ assert.ok(def.promptSection.length > 0, `${id} missing promptSection`);
43
+ }
44
+ });
45
+
46
+ test("registry contains no extra gate entries", () => {
47
+ const registryIds = new Set(Object.keys(GATE_REGISTRY));
48
+ const declaredIds = new Set<string>(ALL_GATE_IDS);
49
+ for (const id of registryIds) {
50
+ assert.ok(declaredIds.has(id), `registry has unknown gate ${id}`);
51
+ }
52
+ });
53
+
54
+ test("every owner turn owns at least one gate", () => {
55
+ for (const turn of ALL_OWNER_TURNS) {
56
+ const gates = getGatesForTurn(turn);
57
+ assert.ok(
58
+ gates.length > 0,
59
+ `owner turn "${turn}" has no gates — likely a registry mistake`,
60
+ );
61
+ }
62
+ });
63
+
64
+ test("owner turn buckets are disjoint", () => {
65
+ const seen = new Set<string>();
66
+ for (const turn of ALL_OWNER_TURNS) {
67
+ for (const def of getGatesForTurn(turn)) {
68
+ assert.ok(!seen.has(def.id), `gate ${def.id} claimed by two turns`);
69
+ seen.add(def.id);
70
+ }
71
+ }
72
+ // Every gate should appear in exactly one bucket.
73
+ assert.equal(seen.size, ALL_GATE_IDS.length);
74
+ });
75
+
76
+ test("getOwnerTurn round-trips against GATE_REGISTRY", () => {
77
+ for (const id of ALL_GATE_IDS) {
78
+ const turn = getOwnerTurn(id);
79
+ const idsForTurn = getGateIdsForTurn(turn);
80
+ assert.ok(idsForTurn.has(id), `${id} not in ${turn} bucket`);
81
+ }
82
+ });
83
+
84
+ test("getGateDefinition returns undefined for unknown ids", () => {
85
+ assert.equal(getGateDefinition("Q99"), undefined);
86
+ assert.equal(getGateDefinition("not-a-gate"), undefined);
87
+ });
88
+ });
89
+
90
+ describe("assertGateCoverage", () => {
91
+ test("throws when a row is owned by a different turn", () => {
92
+ // Q8 is owned by complete-slice, not gate-evaluate — this used to be
93
+ // silently dropped by the old `if (!meta) continue;` filter, causing
94
+ // the evaluating-gates phase to stall.
95
+ assert.throws(
96
+ () => assertGateCoverage([{ gate_id: "Q8" }], "gate-evaluate"),
97
+ (err: Error) =>
98
+ err.message.includes("Q8") && err.message.includes("gate-evaluate"),
99
+ );
100
+ });
101
+
102
+ test("throws when a row has an unknown gate id", () => {
103
+ assert.throws(
104
+ () => assertGateCoverage([{ gate_id: "Q999" as GateId }], "gate-evaluate", { requireAll: false }),
105
+ (err: Error) => err.message.includes("Q999"),
106
+ );
107
+ });
108
+
109
+ test("throws when requireAll is true and an owned gate is missing", () => {
110
+ // gate-evaluate owns Q3 and Q4. Passing only Q3 should fail.
111
+ assert.throws(
112
+ () => assertGateCoverage([{ gate_id: "Q3" }], "gate-evaluate", { requireAll: true }),
113
+ (err: Error) => err.message.includes("Q4"),
114
+ );
115
+ });
116
+
117
+ test("passes when requireAll is false and only a subset is pending", () => {
118
+ // execute-task owns Q5/Q6/Q7, but a task with no external dependencies
119
+ // may only have Q7 seeded. That's still valid coverage.
120
+ assert.doesNotThrow(() =>
121
+ assertGateCoverage([{ gate_id: "Q7" }], "execute-task", { requireAll: false }),
122
+ );
123
+ });
124
+
125
+ test("passes when requireAll is true and every owned gate is pending", () => {
126
+ assert.doesNotThrow(() =>
127
+ assertGateCoverage(
128
+ [{ gate_id: "Q3" }, { gate_id: "Q4" }],
129
+ "gate-evaluate",
130
+ { requireAll: true },
131
+ ),
132
+ );
133
+ });
134
+
135
+ test("empty pending list passes when requireAll is false", () => {
136
+ assert.doesNotThrow(() =>
137
+ assertGateCoverage([], "complete-slice", { requireAll: false }),
138
+ );
139
+ });
140
+ });
@@ -0,0 +1,180 @@
1
+ // gsd / infra-errors cooldown detection tests
2
+ // Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
3
+
4
+ import test, { describe } from "node:test";
5
+ import assert from "node:assert/strict";
6
+
7
+ import {
8
+ isTransientCooldownError,
9
+ getCooldownRetryAfterMs,
10
+ MAX_COOLDOWN_RETRIES,
11
+ COOLDOWN_FALLBACK_WAIT_MS,
12
+ } from "../auto/infra-errors.js";
13
+
14
+ // ─── Constants ────────────────────────────────────────────────────────────────
15
+
16
+ describe("infra-errors cooldown constants", () => {
17
+ test("COOLDOWN_FALLBACK_WAIT_MS is a positive number greater than the 30s rate-limit backoff", () => {
18
+ assert.ok(typeof COOLDOWN_FALLBACK_WAIT_MS === "number");
19
+ assert.ok(COOLDOWN_FALLBACK_WAIT_MS > 30_000, "should exceed the 30s rate-limit window");
20
+ });
21
+
22
+ test("MAX_COOLDOWN_RETRIES is a positive integer", () => {
23
+ assert.ok(typeof MAX_COOLDOWN_RETRIES === "number");
24
+ assert.ok(Number.isInteger(MAX_COOLDOWN_RETRIES));
25
+ assert.ok(MAX_COOLDOWN_RETRIES > 0);
26
+ });
27
+
28
+ test("COOLDOWN_FALLBACK_WAIT_MS is 35_000", () => {
29
+ assert.equal(COOLDOWN_FALLBACK_WAIT_MS, 35_000);
30
+ });
31
+
32
+ test("MAX_COOLDOWN_RETRIES is 5", () => {
33
+ assert.equal(MAX_COOLDOWN_RETRIES, 5);
34
+ });
35
+ });
36
+
37
+ // ─── isTransientCooldownError: structured detection ──────────────────────────
38
+
39
+ describe("isTransientCooldownError — structured code detection", () => {
40
+ test("returns true for an object with code === AUTH_COOLDOWN", () => {
41
+ const err = { code: "AUTH_COOLDOWN", message: "credentials in cooldown" };
42
+ assert.equal(isTransientCooldownError(err), true);
43
+ });
44
+
45
+ test("returns true for a real CredentialCooldownError-shaped error", () => {
46
+ // Simulate CredentialCooldownError without importing sdk.ts (leaf-module rule)
47
+ const err = Object.assign(new Error('All credentials for "anthropic" are in a cooldown window.'), {
48
+ code: "AUTH_COOLDOWN",
49
+ retryAfterMs: 30_000,
50
+ name: "CredentialCooldownError",
51
+ });
52
+ assert.equal(isTransientCooldownError(err), true);
53
+ });
54
+
55
+ test("returns false for an object with a different code", () => {
56
+ const err = { code: "ENOSPC", message: "disk full" };
57
+ assert.equal(isTransientCooldownError(err), false);
58
+ });
59
+
60
+ test("returns false for an object with no code property", () => {
61
+ const err = { message: "some random error" };
62
+ assert.equal(isTransientCooldownError(err), false);
63
+ });
64
+ });
65
+
66
+ // ─── isTransientCooldownError: message fallback ───────────────────────────────
67
+
68
+ describe("isTransientCooldownError — message fallback (cross-process)", () => {
69
+ test("returns true when message contains 'in a cooldown window'", () => {
70
+ const err = new Error('All credentials for "openai" are in a cooldown window. Please wait.');
71
+ assert.equal(isTransientCooldownError(err), true);
72
+ });
73
+
74
+ test("returns true when message matches case-insensitively", () => {
75
+ const err = new Error("credentials IN A COOLDOWN WINDOW");
76
+ assert.equal(isTransientCooldownError(err), true);
77
+ });
78
+
79
+ test("returns true for a plain string containing cooldown window phrase", () => {
80
+ assert.equal(isTransientCooldownError("all keys in a cooldown window"), true);
81
+ });
82
+
83
+ test("returns false for a generic error message", () => {
84
+ const err = new Error("rate limit exceeded");
85
+ assert.equal(isTransientCooldownError(err), false);
86
+ });
87
+
88
+ test("returns false for an error message about auth failure without cooldown phrase", () => {
89
+ const err = new Error("Authentication failed: invalid API key");
90
+ assert.equal(isTransientCooldownError(err), false);
91
+ });
92
+ });
93
+
94
+ // ─── isTransientCooldownError: edge cases ────────────────────────────────────
95
+
96
+ describe("isTransientCooldownError — edge cases", () => {
97
+ test("returns false for null", () => {
98
+ assert.equal(isTransientCooldownError(null), false);
99
+ });
100
+
101
+ test("returns false for undefined", () => {
102
+ assert.equal(isTransientCooldownError(undefined), false);
103
+ });
104
+
105
+ test("returns false for a number", () => {
106
+ assert.equal(isTransientCooldownError(42), false);
107
+ });
108
+
109
+ test("returns false for an empty object", () => {
110
+ assert.equal(isTransientCooldownError({}), false);
111
+ });
112
+
113
+ test("returns false for an object with code === AUTH_COOLDOWN as a non-string", () => {
114
+ // code must be a string matching "AUTH_COOLDOWN" exactly
115
+ const err = { code: 42 };
116
+ assert.equal(isTransientCooldownError(err), false);
117
+ });
118
+ });
119
+
120
+ // ─── getCooldownRetryAfterMs: structured extraction ──────────────────────────
121
+
122
+ describe("getCooldownRetryAfterMs — structured extraction", () => {
123
+ test("returns retryAfterMs when code is AUTH_COOLDOWN and retryAfterMs is set", () => {
124
+ const err = { code: "AUTH_COOLDOWN", retryAfterMs: 30_000 };
125
+ assert.equal(getCooldownRetryAfterMs(err), 30_000);
126
+ });
127
+
128
+ test("returns undefined when code is AUTH_COOLDOWN but retryAfterMs is absent", () => {
129
+ const err = { code: "AUTH_COOLDOWN" };
130
+ assert.equal(getCooldownRetryAfterMs(err), undefined);
131
+ });
132
+
133
+ test("returns 0 when retryAfterMs is explicitly 0", () => {
134
+ const err = { code: "AUTH_COOLDOWN", retryAfterMs: 0 };
135
+ assert.equal(getCooldownRetryAfterMs(err), 0);
136
+ });
137
+
138
+ test("returns undefined for an error with a different code even if retryAfterMs is set", () => {
139
+ const err = { code: "ENOSPC", retryAfterMs: 5_000 };
140
+ assert.equal(getCooldownRetryAfterMs(err), undefined);
141
+ });
142
+
143
+ test("returns undefined for a plain Error with no code property", () => {
144
+ const err = new Error("something went wrong");
145
+ assert.equal(getCooldownRetryAfterMs(err), undefined);
146
+ });
147
+
148
+ test("returns retryAfterMs from a full CredentialCooldownError-shaped object", () => {
149
+ const err = Object.assign(new Error('All credentials for "anthropic" are in a cooldown window.'), {
150
+ code: "AUTH_COOLDOWN",
151
+ retryAfterMs: 15_000,
152
+ name: "CredentialCooldownError",
153
+ });
154
+ assert.equal(getCooldownRetryAfterMs(err), 15_000);
155
+ });
156
+ });
157
+
158
+ // ─── getCooldownRetryAfterMs: edge cases ─────────────────────────────────────
159
+
160
+ describe("getCooldownRetryAfterMs — edge cases", () => {
161
+ test("returns undefined for null", () => {
162
+ assert.equal(getCooldownRetryAfterMs(null), undefined);
163
+ });
164
+
165
+ test("returns undefined for undefined", () => {
166
+ assert.equal(getCooldownRetryAfterMs(undefined), undefined);
167
+ });
168
+
169
+ test("returns undefined for a plain string", () => {
170
+ assert.equal(getCooldownRetryAfterMs("AUTH_COOLDOWN"), undefined);
171
+ });
172
+
173
+ test("returns undefined for an empty object", () => {
174
+ assert.equal(getCooldownRetryAfterMs({}), undefined);
175
+ });
176
+
177
+ test("returns undefined for a number", () => {
178
+ assert.equal(getCooldownRetryAfterMs(42), undefined);
179
+ });
180
+ });