gsd-pi 2.58.0-dev.d63175c → 2.58.0-dev.e002a57

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 (777) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +60 -35
  3. package/dist/headless-ui.d.ts +17 -0
  4. package/dist/headless-ui.js +97 -3
  5. package/dist/headless.js +67 -6
  6. package/dist/help-text.js +1 -0
  7. package/dist/onboarding.js +44 -0
  8. package/dist/resource-loader.js +16 -1
  9. package/dist/resources/agents/researcher.md +1 -1
  10. package/dist/resources/extensions/ask-user-questions.js +16 -3
  11. package/dist/resources/extensions/async-jobs/extension-manifest.json +1 -1
  12. package/dist/resources/extensions/bg-shell/extension-manifest.json +1 -1
  13. package/dist/resources/extensions/browser-tools/extension-manifest.json +1 -1
  14. package/dist/resources/extensions/claude-code-cli/partial-builder.js +14 -6
  15. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +59 -36
  16. package/dist/resources/extensions/context7/extension-manifest.json +1 -1
  17. package/dist/resources/extensions/get-secrets-from-user.js +8 -5
  18. package/dist/resources/extensions/google-search/extension-manifest.json +1 -1
  19. package/dist/resources/extensions/google-search/index.js +2 -1
  20. package/dist/resources/extensions/gsd/auto/phases.js +25 -21
  21. package/dist/resources/extensions/gsd/auto-artifact-paths.js +2 -2
  22. package/dist/resources/extensions/gsd/auto-dashboard.js +37 -20
  23. package/dist/resources/extensions/gsd/auto-dispatch.js +17 -2
  24. package/dist/resources/extensions/gsd/auto-model-selection.js +26 -3
  25. package/dist/resources/extensions/gsd/auto-post-unit.js +16 -4
  26. package/dist/resources/extensions/gsd/auto-prompts.js +1 -1
  27. package/dist/resources/extensions/gsd/auto-recovery.js +13 -5
  28. package/dist/resources/extensions/gsd/auto-start.js +35 -22
  29. package/dist/resources/extensions/gsd/auto-worktree.js +199 -12
  30. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +32 -0
  31. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +80 -8
  32. package/dist/resources/extensions/gsd/bootstrap/dynamic-tools.js +32 -1
  33. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +42 -34
  34. package/dist/resources/extensions/gsd/bootstrap/system-context.js +66 -12
  35. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +67 -0
  36. package/dist/resources/extensions/gsd/captures.js +56 -4
  37. package/dist/resources/extensions/gsd/codebase-generator.js +279 -0
  38. package/dist/resources/extensions/gsd/commands/catalog.js +10 -1
  39. package/dist/resources/extensions/gsd/commands/handlers/ops.js +5 -0
  40. package/dist/resources/extensions/gsd/commands-codebase.js +115 -0
  41. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +41 -4
  42. package/dist/resources/extensions/gsd/complexity-classifier.js +8 -6
  43. package/dist/resources/extensions/gsd/db-writer.js +116 -8
  44. package/dist/resources/extensions/gsd/doctor-git-checks.js +76 -1
  45. package/dist/resources/extensions/gsd/doctor-proactive.js +34 -1
  46. package/dist/resources/extensions/gsd/doctor-providers.js +2 -1
  47. package/dist/resources/extensions/gsd/doctor-runtime-checks.js +5 -4
  48. package/dist/resources/extensions/gsd/doctor.js +3 -1
  49. package/dist/resources/extensions/gsd/error-classifier.js +12 -10
  50. package/dist/resources/extensions/gsd/extension-manifest.json +16 -1
  51. package/dist/resources/extensions/gsd/forensics.js +123 -20
  52. package/dist/resources/extensions/gsd/git-service.js +105 -2
  53. package/dist/resources/extensions/gsd/gitignore.js +33 -0
  54. package/dist/resources/extensions/gsd/gsd-db.js +36 -9
  55. package/dist/resources/extensions/gsd/guided-flow.js +106 -44
  56. package/dist/resources/extensions/gsd/health-widget-core.js +31 -0
  57. package/dist/resources/extensions/gsd/health-widget.js +17 -0
  58. package/dist/resources/extensions/gsd/index.js +1 -1
  59. package/dist/resources/extensions/gsd/memory-extractor.js +7 -0
  60. package/dist/resources/extensions/gsd/migrate-external.js +8 -1
  61. package/dist/resources/extensions/gsd/milestone-validation-gates.js +45 -0
  62. package/dist/resources/extensions/gsd/model-cost-table.js +18 -0
  63. package/dist/resources/extensions/gsd/model-router.js +35 -1
  64. package/dist/resources/extensions/gsd/native-git-bridge.js +39 -0
  65. package/dist/resources/extensions/gsd/notifications.js +16 -1
  66. package/dist/resources/extensions/gsd/parallel-eligibility.js +13 -2
  67. package/dist/resources/extensions/gsd/parallel-merge.js +78 -5
  68. package/dist/resources/extensions/gsd/parsers-legacy.js +20 -3
  69. package/dist/resources/extensions/gsd/paths.js +45 -0
  70. package/dist/resources/extensions/gsd/preferences-models.js +14 -1
  71. package/dist/resources/extensions/gsd/preferences-types.js +3 -1
  72. package/dist/resources/extensions/gsd/preferences.js +13 -16
  73. package/dist/resources/extensions/gsd/prompt-loader.js +4 -1
  74. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  75. package/dist/resources/extensions/gsd/prompts/complete-slice.md +4 -2
  76. package/dist/resources/extensions/gsd/prompts/discuss-headless.md +1 -1
  77. package/dist/resources/extensions/gsd/prompts/discuss.md +1 -1
  78. package/dist/resources/extensions/gsd/prompts/execute-task.md +3 -1
  79. package/dist/resources/extensions/gsd/prompts/forensics.md +2 -2
  80. package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
  81. package/dist/resources/extensions/gsd/prompts/guided-discuss-slice.md +1 -1
  82. package/dist/resources/extensions/gsd/prompts/plan-slice.md +2 -0
  83. package/dist/resources/extensions/gsd/prompts/rethink.md +1 -1
  84. package/dist/resources/extensions/gsd/prompts/triage-captures.md +1 -0
  85. package/dist/resources/extensions/gsd/repo-identity.js +205 -11
  86. package/dist/resources/extensions/gsd/rethink.js +5 -0
  87. package/dist/resources/extensions/gsd/roadmap-slices.js +5 -4
  88. package/dist/resources/extensions/gsd/state.js +85 -27
  89. package/dist/resources/extensions/gsd/tests/dist-redirect.mjs +20 -1
  90. package/dist/resources/extensions/gsd/tools/complete-task.js +34 -71
  91. package/dist/resources/extensions/gsd/tools/plan-milestone.js +12 -2
  92. package/dist/resources/extensions/gsd/tools/reassess-roadmap.js +29 -1
  93. package/dist/resources/extensions/gsd/tools/validate-milestone.js +14 -3
  94. package/dist/resources/extensions/gsd/triage-resolution.js +22 -7
  95. package/dist/resources/extensions/gsd/undo.js +2 -2
  96. package/dist/resources/extensions/gsd/unit-ownership.js +164 -33
  97. package/dist/resources/extensions/gsd/verdict-parser.js +20 -8
  98. package/dist/resources/extensions/gsd/watch/header-renderer.js +241 -0
  99. package/dist/resources/extensions/gsd/workflow-manifest.js +24 -5
  100. package/dist/resources/extensions/gsd/workflow-projections.js +95 -63
  101. package/dist/resources/extensions/gsd/workflow-reconcile.js +35 -5
  102. package/dist/resources/extensions/gsd/workspace-index.js +24 -0
  103. package/dist/resources/extensions/gsd/worktree-manager.js +105 -1
  104. package/dist/resources/extensions/gsd/worktree-resolver.js +20 -3
  105. package/dist/resources/extensions/mcp-client/index.js +11 -7
  106. package/dist/resources/extensions/ollama/index.js +112 -0
  107. package/dist/resources/extensions/ollama/model-capabilities.js +115 -0
  108. package/dist/resources/extensions/ollama/ollama-client.js +168 -0
  109. package/dist/resources/extensions/ollama/ollama-commands.js +194 -0
  110. package/dist/resources/extensions/ollama/ollama-discovery.js +69 -0
  111. package/dist/resources/extensions/ollama/ollama-tool.js +184 -0
  112. package/dist/resources/extensions/ollama/types.js +2 -0
  113. package/dist/resources/extensions/search-the-web/extension-manifest.json +1 -1
  114. package/dist/resources/extensions/search-the-web/url-utils.js +17 -0
  115. package/dist/resources/extensions/shared/interview-ui.js +11 -1
  116. package/dist/resources/skills/create-gsd-extension/SKILL.md +5 -3
  117. package/dist/resources/skills/create-gsd-extension/references/key-rules-gotchas.md +5 -4
  118. package/dist/resources/skills/create-gsd-extension/workflows/add-capability.md +2 -2
  119. package/dist/resources/skills/create-gsd-extension/workflows/create-extension.md +4 -4
  120. package/dist/resources/skills/create-gsd-extension/workflows/debug-extension.md +5 -3
  121. package/dist/security-overrides.d.ts +11 -0
  122. package/dist/security-overrides.js +41 -0
  123. package/dist/startup-model-validation.d.ts +39 -0
  124. package/dist/startup-model-validation.js +50 -0
  125. package/dist/web/standalone/.next/BUILD_ID +1 -1
  126. package/dist/web/standalone/.next/app-path-routes-manifest.json +17 -17
  127. package/dist/web/standalone/.next/build-manifest.json +3 -3
  128. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  129. package/dist/web/standalone/.next/react-loadable-manifest.json +1 -1
  130. package/dist/web/standalone/.next/required-server-files.json +1 -1
  131. package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  132. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  133. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  134. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  135. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  136. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  137. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  138. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  139. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  140. package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  141. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  142. package/dist/web/standalone/.next/server/app/_not-found.rsc +2 -2
  143. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +2 -2
  144. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  145. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +2 -2
  146. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  147. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  148. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  149. package/dist/web/standalone/.next/server/app/api/boot/route_client-reference-manifest.js +1 -1
  150. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route_client-reference-manifest.js +1 -1
  151. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route_client-reference-manifest.js +1 -1
  152. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route_client-reference-manifest.js +1 -1
  153. package/dist/web/standalone/.next/server/app/api/browse-directories/route_client-reference-manifest.js +1 -1
  154. package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
  155. package/dist/web/standalone/.next/server/app/api/captures/route_client-reference-manifest.js +1 -1
  156. package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
  157. package/dist/web/standalone/.next/server/app/api/cleanup/route_client-reference-manifest.js +1 -1
  158. package/dist/web/standalone/.next/server/app/api/dev-mode/route_client-reference-manifest.js +1 -1
  159. package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
  160. package/dist/web/standalone/.next/server/app/api/doctor/route_client-reference-manifest.js +1 -1
  161. package/dist/web/standalone/.next/server/app/api/experimental/route_client-reference-manifest.js +1 -1
  162. package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
  163. package/dist/web/standalone/.next/server/app/api/export-data/route_client-reference-manifest.js +1 -1
  164. package/dist/web/standalone/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
  165. package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
  166. package/dist/web/standalone/.next/server/app/api/forensics/route_client-reference-manifest.js +1 -1
  167. package/dist/web/standalone/.next/server/app/api/git/route_client-reference-manifest.js +1 -1
  168. package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
  169. package/dist/web/standalone/.next/server/app/api/history/route_client-reference-manifest.js +1 -1
  170. package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
  171. package/dist/web/standalone/.next/server/app/api/hooks/route_client-reference-manifest.js +1 -1
  172. package/dist/web/standalone/.next/server/app/api/inspect/route_client-reference-manifest.js +1 -1
  173. package/dist/web/standalone/.next/server/app/api/knowledge/route_client-reference-manifest.js +1 -1
  174. package/dist/web/standalone/.next/server/app/api/live-state/route_client-reference-manifest.js +1 -1
  175. package/dist/web/standalone/.next/server/app/api/onboarding/route_client-reference-manifest.js +1 -1
  176. package/dist/web/standalone/.next/server/app/api/preferences/route_client-reference-manifest.js +1 -1
  177. package/dist/web/standalone/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
  178. package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
  179. package/dist/web/standalone/.next/server/app/api/recovery/route_client-reference-manifest.js +1 -1
  180. package/dist/web/standalone/.next/server/app/api/remote-questions/route_client-reference-manifest.js +1 -1
  181. package/dist/web/standalone/.next/server/app/api/session/browser/route_client-reference-manifest.js +1 -1
  182. package/dist/web/standalone/.next/server/app/api/session/command/route_client-reference-manifest.js +1 -1
  183. package/dist/web/standalone/.next/server/app/api/session/events/route_client-reference-manifest.js +1 -1
  184. package/dist/web/standalone/.next/server/app/api/session/manage/route_client-reference-manifest.js +1 -1
  185. package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
  186. package/dist/web/standalone/.next/server/app/api/settings-data/route_client-reference-manifest.js +1 -1
  187. package/dist/web/standalone/.next/server/app/api/shutdown/route_client-reference-manifest.js +1 -1
  188. package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
  189. package/dist/web/standalone/.next/server/app/api/skill-health/route_client-reference-manifest.js +1 -1
  190. package/dist/web/standalone/.next/server/app/api/steer/route_client-reference-manifest.js +1 -1
  191. package/dist/web/standalone/.next/server/app/api/switch-root/route_client-reference-manifest.js +1 -1
  192. package/dist/web/standalone/.next/server/app/api/terminal/input/route_client-reference-manifest.js +1 -1
  193. package/dist/web/standalone/.next/server/app/api/terminal/resize/route_client-reference-manifest.js +1 -1
  194. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route_client-reference-manifest.js +1 -1
  195. package/dist/web/standalone/.next/server/app/api/terminal/stream/route_client-reference-manifest.js +1 -1
  196. package/dist/web/standalone/.next/server/app/api/terminal/upload/route_client-reference-manifest.js +1 -1
  197. package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
  198. package/dist/web/standalone/.next/server/app/api/undo/route_client-reference-manifest.js +1 -1
  199. package/dist/web/standalone/.next/server/app/api/update/route.js +1 -1
  200. package/dist/web/standalone/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
  201. package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
  202. package/dist/web/standalone/.next/server/app/api/visualizer/route_client-reference-manifest.js +1 -1
  203. package/dist/web/standalone/.next/server/app/index.html +1 -1
  204. package/dist/web/standalone/.next/server/app/index.rsc +2 -2
  205. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  206. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
  207. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  208. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +2 -2
  209. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  210. package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  211. package/dist/web/standalone/.next/server/app-paths-manifest.json +17 -17
  212. package/dist/web/standalone/.next/server/chunks/2229.js +2 -2
  213. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  214. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  215. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  216. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  217. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  218. package/dist/web/standalone/.next/static/chunks/6502.7593d7797a4b3999.js +9 -0
  219. package/dist/web/standalone/.next/static/chunks/{webpack-61d3afac6d0f0ce7.js → webpack-a1c1e452c6b32d04.js} +1 -1
  220. package/dist/web/standalone/.next/static/css/f6e8833d46e738d8.css +1 -0
  221. package/dist/web/standalone/server.js +1 -1
  222. package/dist/web-mode.js +2 -1
  223. package/dist/welcome-screen.d.ts +1 -0
  224. package/dist/welcome-screen.js +32 -6
  225. package/package.json +2 -2
  226. package/packages/native/dist/ast/index.js +9 -5
  227. package/packages/native/dist/ast/types.js +2 -1
  228. package/packages/native/dist/clipboard/index.js +12 -7
  229. package/packages/native/dist/clipboard/types.js +2 -1
  230. package/packages/native/dist/diff/index.js +12 -7
  231. package/packages/native/dist/diff/types.js +2 -1
  232. package/packages/native/dist/fd/index.js +6 -3
  233. package/packages/native/dist/fd/types.js +2 -1
  234. package/packages/native/dist/glob/index.js +9 -5
  235. package/packages/native/dist/glob/types.js +2 -1
  236. package/packages/native/dist/grep/index.js +9 -5
  237. package/packages/native/dist/grep/types.js +2 -1
  238. package/packages/native/dist/gsd-parser/index.js +18 -11
  239. package/packages/native/dist/gsd-parser/types.js +2 -1
  240. package/packages/native/dist/highlight/index.js +12 -7
  241. package/packages/native/dist/highlight/types.js +2 -1
  242. package/packages/native/dist/html/index.js +6 -3
  243. package/packages/native/dist/html/types.js +2 -1
  244. package/packages/native/dist/image/index.js +10 -5
  245. package/packages/native/dist/image/types.js +7 -4
  246. package/packages/native/dist/index.js +70 -17
  247. package/packages/native/dist/json-parse/index.js +13 -8
  248. package/packages/native/dist/native.js +47 -10
  249. package/packages/native/dist/ps/index.js +15 -9
  250. package/packages/native/dist/ps/types.js +2 -1
  251. package/packages/native/dist/stream-process/index.js +12 -7
  252. package/packages/native/dist/text/index.js +24 -14
  253. package/packages/native/dist/text/types.js +5 -2
  254. package/packages/native/dist/truncate/index.js +12 -7
  255. package/packages/native/dist/ttsr/index.js +12 -7
  256. package/packages/native/dist/ttsr/types.js +2 -1
  257. package/packages/native/dist/xxhash/index.js +9 -5
  258. package/packages/native/package.json +19 -19
  259. package/packages/native/src/__tests__/module-compat.test.mjs +91 -0
  260. package/packages/native/src/native.ts +9 -8
  261. package/packages/pi-agent-core/dist/agent-loop.js +3 -2
  262. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  263. package/packages/pi-agent-core/dist/proxy.d.ts +1 -1
  264. package/packages/pi-agent-core/dist/proxy.d.ts.map +1 -1
  265. package/packages/pi-agent-core/dist/proxy.js.map +1 -1
  266. package/packages/pi-agent-core/src/agent-loop.test.ts +45 -0
  267. package/packages/pi-agent-core/src/agent-loop.ts +3 -2
  268. package/packages/pi-agent-core/src/proxy.ts +1 -1
  269. package/packages/pi-ai/dist/env-api-keys.js +1 -0
  270. package/packages/pi-ai/dist/env-api-keys.js.map +1 -1
  271. package/packages/pi-ai/dist/index.d.ts +1 -0
  272. package/packages/pi-ai/dist/index.d.ts.map +1 -1
  273. package/packages/pi-ai/dist/index.js +1 -0
  274. package/packages/pi-ai/dist/index.js.map +1 -1
  275. package/packages/pi-ai/dist/providers/anthropic-shared.d.ts.map +1 -1
  276. package/packages/pi-ai/dist/providers/anthropic-shared.js +19 -2
  277. package/packages/pi-ai/dist/providers/anthropic-shared.js.map +1 -1
  278. package/packages/pi-ai/dist/providers/anthropic-shared.test.d.ts +2 -0
  279. package/packages/pi-ai/dist/providers/anthropic-shared.test.d.ts.map +1 -0
  280. package/packages/pi-ai/dist/providers/anthropic-shared.test.js +25 -0
  281. package/packages/pi-ai/dist/providers/anthropic-shared.test.js.map +1 -0
  282. package/packages/pi-ai/dist/types.d.ts +3 -3
  283. package/packages/pi-ai/dist/types.d.ts.map +1 -1
  284. package/packages/pi-ai/dist/types.js.map +1 -1
  285. package/packages/pi-ai/dist/utils/json-parse.d.ts +3 -0
  286. package/packages/pi-ai/dist/utils/json-parse.d.ts.map +1 -1
  287. package/packages/pi-ai/dist/utils/json-parse.js +24 -1
  288. package/packages/pi-ai/dist/utils/json-parse.js.map +1 -1
  289. package/packages/pi-ai/dist/utils/repair-tool-json.d.ts +37 -0
  290. package/packages/pi-ai/dist/utils/repair-tool-json.d.ts.map +1 -0
  291. package/packages/pi-ai/dist/utils/repair-tool-json.js +75 -0
  292. package/packages/pi-ai/dist/utils/repair-tool-json.js.map +1 -0
  293. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.d.ts +2 -0
  294. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.d.ts.map +1 -0
  295. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.js +73 -0
  296. package/packages/pi-ai/dist/utils/tests/repair-tool-json.test.js.map +1 -0
  297. package/packages/pi-ai/src/env-api-keys.ts +1 -0
  298. package/packages/pi-ai/src/index.ts +1 -0
  299. package/packages/pi-ai/src/providers/anthropic-shared.test.ts +29 -0
  300. package/packages/pi-ai/src/providers/anthropic-shared.ts +17 -2
  301. package/packages/pi-ai/src/types.ts +3 -2
  302. package/packages/pi-ai/src/utils/json-parse.ts +28 -1
  303. package/packages/pi-ai/src/utils/repair-tool-json.ts +88 -0
  304. package/packages/pi-ai/src/utils/tests/repair-tool-json.test.ts +102 -0
  305. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +4 -0
  306. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  307. package/packages/pi-coding-agent/dist/core/agent-session.js +31 -0
  308. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  309. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts +17 -1
  310. package/packages/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
  311. package/packages/pi-coding-agent/dist/core/compaction/compaction.js +62 -2
  312. package/packages/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
  313. package/packages/pi-coding-agent/dist/core/compaction/compaction.test.d.ts +6 -0
  314. package/packages/pi-coding-agent/dist/core/compaction/compaction.test.d.ts.map +1 -0
  315. package/packages/pi-coding-agent/dist/core/compaction/compaction.test.js +176 -0
  316. package/packages/pi-coding-agent/dist/core/compaction/compaction.test.js.map +1 -0
  317. package/packages/pi-coding-agent/dist/core/exec.d.ts.map +1 -1
  318. package/packages/pi-coding-agent/dist/core/exec.js +3 -1
  319. package/packages/pi-coding-agent/dist/core/exec.js.map +1 -1
  320. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.d.ts +28 -0
  321. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.d.ts.map +1 -0
  322. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.js +37 -0
  323. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.js.map +1 -0
  324. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.test.d.ts +2 -0
  325. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.test.d.ts.map +1 -0
  326. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.test.js +63 -0
  327. package/packages/pi-coding-agent/dist/core/extensions/extension-manifest.test.js.map +1 -0
  328. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.d.ts +19 -0
  329. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.d.ts.map +1 -0
  330. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.js +115 -0
  331. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.js.map +1 -0
  332. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.test.d.ts +2 -0
  333. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.test.d.ts.map +1 -0
  334. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.test.js +109 -0
  335. package/packages/pi-coding-agent/dist/core/extensions/extension-sort.test.js.map +1 -0
  336. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +4 -0
  337. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
  338. package/packages/pi-coding-agent/dist/core/extensions/index.js +2 -0
  339. package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
  340. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts +5 -0
  341. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  342. package/packages/pi-coding-agent/dist/core/extensions/loader.js +5 -0
  343. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  344. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.d.ts +44 -0
  345. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.d.ts.map +1 -0
  346. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.js +97 -0
  347. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.js.map +1 -0
  348. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.test.d.ts +2 -0
  349. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.test.d.ts.map +1 -0
  350. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.test.js +181 -0
  351. package/packages/pi-coding-agent/dist/core/image-overflow-recovery.test.js.map +1 -0
  352. package/packages/pi-coding-agent/dist/core/index.d.ts +1 -1
  353. package/packages/pi-coding-agent/dist/core/index.d.ts.map +1 -1
  354. package/packages/pi-coding-agent/dist/core/index.js +1 -1
  355. package/packages/pi-coding-agent/dist/core/index.js.map +1 -1
  356. package/packages/pi-coding-agent/dist/core/lsp/index.d.ts.map +1 -1
  357. package/packages/pi-coding-agent/dist/core/lsp/index.js +3 -0
  358. package/packages/pi-coding-agent/dist/core/lsp/index.js.map +1 -1
  359. package/packages/pi-coding-agent/dist/core/lsp/lspmux.d.ts.map +1 -1
  360. package/packages/pi-coding-agent/dist/core/lsp/lspmux.js +3 -0
  361. package/packages/pi-coding-agent/dist/core/lsp/lspmux.js.map +1 -1
  362. package/packages/pi-coding-agent/dist/core/messages.d.ts.map +1 -1
  363. package/packages/pi-coding-agent/dist/core/messages.js +31 -2
  364. package/packages/pi-coding-agent/dist/core/messages.js.map +1 -1
  365. package/packages/pi-coding-agent/dist/core/messages.test.d.ts +9 -0
  366. package/packages/pi-coding-agent/dist/core/messages.test.d.ts.map +1 -0
  367. package/packages/pi-coding-agent/dist/core/messages.test.js +86 -0
  368. package/packages/pi-coding-agent/dist/core/messages.test.js.map +1 -0
  369. package/packages/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
  370. package/packages/pi-coding-agent/dist/core/model-resolver.js +1 -0
  371. package/packages/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
  372. package/packages/pi-coding-agent/dist/core/resolve-config-value.d.ts +8 -0
  373. package/packages/pi-coding-agent/dist/core/resolve-config-value.d.ts.map +1 -1
  374. package/packages/pi-coding-agent/dist/core/resolve-config-value.js +23 -2
  375. package/packages/pi-coding-agent/dist/core/resolve-config-value.js.map +1 -1
  376. package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js +89 -2
  377. package/packages/pi-coding-agent/dist/core/resolve-config-value.test.js.map +1 -1
  378. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts +10 -0
  379. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
  380. package/packages/pi-coding-agent/dist/core/resource-loader.js +12 -1
  381. package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
  382. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts +6 -0
  383. package/packages/pi-coding-agent/dist/core/retry-handler.d.ts.map +1 -1
  384. package/packages/pi-coding-agent/dist/core/retry-handler.js +48 -1
  385. package/packages/pi-coding-agent/dist/core/retry-handler.js.map +1 -1
  386. package/packages/pi-coding-agent/dist/core/retry-handler.test.d.ts +9 -0
  387. package/packages/pi-coding-agent/dist/core/retry-handler.test.d.ts.map +1 -0
  388. package/packages/pi-coding-agent/dist/core/retry-handler.test.js +193 -0
  389. package/packages/pi-coding-agent/dist/core/retry-handler.test.js.map +1 -0
  390. package/packages/pi-coding-agent/dist/core/settings-manager-security.test.d.ts +2 -0
  391. package/packages/pi-coding-agent/dist/core/settings-manager-security.test.d.ts.map +1 -0
  392. package/packages/pi-coding-agent/dist/core/settings-manager-security.test.js +83 -0
  393. package/packages/pi-coding-agent/dist/core/settings-manager-security.test.js.map +1 -0
  394. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +14 -0
  395. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  396. package/packages/pi-coding-agent/dist/core/settings-manager.js +36 -3
  397. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  398. package/packages/pi-coding-agent/dist/core/tools/hashline-read.d.ts.map +1 -1
  399. package/packages/pi-coding-agent/dist/core/tools/hashline-read.js +10 -3
  400. package/packages/pi-coding-agent/dist/core/tools/hashline-read.js.map +1 -1
  401. package/packages/pi-coding-agent/dist/core/tools/read.d.ts.map +1 -1
  402. package/packages/pi-coding-agent/dist/core/tools/read.js +13 -4
  403. package/packages/pi-coding-agent/dist/core/tools/read.js.map +1 -1
  404. package/packages/pi-coding-agent/dist/core/tools/spawn-shell-windows.test.d.ts +16 -0
  405. package/packages/pi-coding-agent/dist/core/tools/spawn-shell-windows.test.d.ts.map +1 -0
  406. package/packages/pi-coding-agent/dist/core/tools/spawn-shell-windows.test.js +80 -0
  407. package/packages/pi-coding-agent/dist/core/tools/spawn-shell-windows.test.js.map +1 -0
  408. package/packages/pi-coding-agent/dist/index.d.ts +3 -2
  409. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  410. package/packages/pi-coding-agent/dist/index.js +2 -1
  411. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  412. package/packages/pi-coding-agent/dist/modes/interactive/components/armin.d.ts +1 -1
  413. package/packages/pi-coding-agent/dist/modes/interactive/components/armin.d.ts.map +1 -1
  414. package/packages/pi-coding-agent/dist/modes/interactive/components/armin.js +9 -8
  415. package/packages/pi-coding-agent/dist/modes/interactive/components/armin.js.map +1 -1
  416. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  417. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +0 -3
  418. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
  419. package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts +1 -0
  420. package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  421. package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.js +2 -1
  422. package/packages/pi-coding-agent/dist/modes/interactive/components/bash-execution.js.map +1 -1
  423. package/packages/pi-coding-agent/dist/modes/interactive/components/bordered-loader.js +1 -1
  424. package/packages/pi-coding-agent/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  425. package/packages/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js +1 -1
  426. package/packages/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  427. package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js +1 -1
  428. package/packages/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  429. package/packages/pi-coding-agent/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  430. package/packages/pi-coding-agent/dist/modes/interactive/components/config-selector.js +5 -2
  431. package/packages/pi-coding-agent/dist/modes/interactive/components/config-selector.js.map +1 -1
  432. package/packages/pi-coding-agent/dist/modes/interactive/components/countdown-timer.d.ts +1 -0
  433. package/packages/pi-coding-agent/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  434. package/packages/pi-coding-agent/dist/modes/interactive/components/countdown-timer.js +4 -0
  435. package/packages/pi-coding-agent/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  436. package/packages/pi-coding-agent/dist/modes/interactive/components/custom-message.js +1 -1
  437. package/packages/pi-coding-agent/dist/modes/interactive/components/custom-message.js.map +1 -1
  438. package/packages/pi-coding-agent/dist/modes/interactive/components/daxnuts.d.ts +1 -1
  439. package/packages/pi-coding-agent/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  440. package/packages/pi-coding-agent/dist/modes/interactive/components/daxnuts.js +4 -2
  441. package/packages/pi-coding-agent/dist/modes/interactive/components/daxnuts.js.map +1 -1
  442. package/packages/pi-coding-agent/dist/modes/interactive/components/diff.js +2 -2
  443. package/packages/pi-coding-agent/dist/modes/interactive/components/diff.js.map +1 -1
  444. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  445. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js +8 -1
  446. package/packages/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  447. package/packages/pi-coding-agent/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  448. package/packages/pi-coding-agent/dist/modes/interactive/components/extension-input.js +2 -0
  449. package/packages/pi-coding-agent/dist/modes/interactive/components/extension-input.js.map +1 -1
  450. package/packages/pi-coding-agent/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  451. package/packages/pi-coding-agent/dist/modes/interactive/components/extension-selector.js +4 -0
  452. package/packages/pi-coding-agent/dist/modes/interactive/components/extension-selector.js.map +1 -1
  453. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
  454. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js +26 -12
  455. package/packages/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
  456. package/packages/pi-coding-agent/dist/modes/interactive/components/oauth-selector.js +4 -4
  457. package/packages/pi-coding-agent/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  458. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.d.ts +3 -0
  459. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.d.ts.map +1 -1
  460. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js +46 -14
  461. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js.map +1 -1
  462. package/packages/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  463. package/packages/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.js +2 -8
  464. package/packages/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  465. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js +4 -4
  466. package/packages/pi-coding-agent/dist/modes/interactive/components/session-selector.js.map +1 -1
  467. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +2 -2
  468. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  469. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  470. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +8 -3
  471. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  472. package/packages/pi-coding-agent/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  473. package/packages/pi-coding-agent/dist/modes/interactive/components/user-message-selector.js +3 -2
  474. package/packages/pi-coding-agent/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  475. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  476. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +19 -1
  477. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  478. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.d.ts.map +1 -1
  479. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js +16 -1
  480. package/packages/pi-coding-agent/dist/modes/interactive/controllers/input-controller.js.map +1 -1
  481. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +1 -0
  482. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  483. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +27 -4
  484. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  485. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.d.ts.map +1 -1
  486. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js +6 -0
  487. package/packages/pi-coding-agent/dist/modes/interactive/slash-command-handlers.js.map +1 -1
  488. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js +1 -1
  489. package/packages/pi-coding-agent/dist/modes/interactive/theme/themes.js.map +1 -1
  490. package/packages/pi-coding-agent/dist/modes/rpc/remote-terminal.d.ts +1 -0
  491. package/packages/pi-coding-agent/dist/modes/rpc/remote-terminal.d.ts.map +1 -1
  492. package/packages/pi-coding-agent/dist/modes/rpc/remote-terminal.js +5 -0
  493. package/packages/pi-coding-agent/dist/modes/rpc/remote-terminal.js.map +1 -1
  494. package/packages/pi-coding-agent/src/core/agent-session.ts +38 -1
  495. package/packages/pi-coding-agent/src/core/compaction/compaction.test.ts +236 -0
  496. package/packages/pi-coding-agent/src/core/compaction/compaction.ts +94 -1
  497. package/packages/pi-coding-agent/src/core/exec.ts +3 -1
  498. package/packages/pi-coding-agent/src/core/extensions/extension-manifest.test.ts +77 -0
  499. package/packages/pi-coding-agent/src/core/extensions/extension-manifest.ts +62 -0
  500. package/packages/pi-coding-agent/src/core/extensions/extension-sort.test.ts +134 -0
  501. package/packages/pi-coding-agent/src/core/extensions/extension-sort.ts +137 -0
  502. package/packages/pi-coding-agent/src/core/extensions/index.ts +4 -0
  503. package/packages/pi-coding-agent/src/core/extensions/loader.ts +5 -0
  504. package/packages/pi-coding-agent/src/core/image-overflow-recovery.test.ts +228 -0
  505. package/packages/pi-coding-agent/src/core/image-overflow-recovery.ts +118 -0
  506. package/packages/pi-coding-agent/src/core/index.ts +6 -0
  507. package/packages/pi-coding-agent/src/core/lsp/index.ts +3 -0
  508. package/packages/pi-coding-agent/src/core/lsp/lspmux.ts +3 -0
  509. package/packages/pi-coding-agent/src/core/messages.test.ts +114 -0
  510. package/packages/pi-coding-agent/src/core/messages.ts +29 -2
  511. package/packages/pi-coding-agent/src/core/model-resolver.ts +1 -0
  512. package/packages/pi-coding-agent/src/core/resolve-config-value.test.ts +111 -1
  513. package/packages/pi-coding-agent/src/core/resolve-config-value.ts +26 -2
  514. package/packages/pi-coding-agent/src/core/resource-loader.ts +20 -1
  515. package/packages/pi-coding-agent/src/core/retry-handler.test.ts +255 -0
  516. package/packages/pi-coding-agent/src/core/retry-handler.ts +52 -1
  517. package/packages/pi-coding-agent/src/core/settings-manager-security.test.ts +102 -0
  518. package/packages/pi-coding-agent/src/core/settings-manager.ts +44 -3
  519. package/packages/pi-coding-agent/src/core/tools/hashline-read.ts +11 -3
  520. package/packages/pi-coding-agent/src/core/tools/read.ts +14 -4
  521. package/packages/pi-coding-agent/src/core/tools/spawn-shell-windows.test.ts +92 -0
  522. package/packages/pi-coding-agent/src/index.ts +11 -0
  523. package/packages/pi-coding-agent/src/modes/interactive/components/armin.ts +9 -9
  524. package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +0 -2
  525. package/packages/pi-coding-agent/src/modes/interactive/components/bash-execution.ts +3 -1
  526. package/packages/pi-coding-agent/src/modes/interactive/components/bordered-loader.ts +1 -1
  527. package/packages/pi-coding-agent/src/modes/interactive/components/branch-summary-message.ts +1 -1
  528. package/packages/pi-coding-agent/src/modes/interactive/components/compaction-summary-message.ts +1 -1
  529. package/packages/pi-coding-agent/src/modes/interactive/components/config-selector.ts +7 -2
  530. package/packages/pi-coding-agent/src/modes/interactive/components/countdown-timer.ts +3 -0
  531. package/packages/pi-coding-agent/src/modes/interactive/components/custom-message.ts +1 -1
  532. package/packages/pi-coding-agent/src/modes/interactive/components/daxnuts.ts +4 -3
  533. package/packages/pi-coding-agent/src/modes/interactive/components/diff.ts +2 -2
  534. package/packages/pi-coding-agent/src/modes/interactive/components/dynamic-border.ts +3 -1
  535. package/packages/pi-coding-agent/src/modes/interactive/components/extension-input.ts +1 -0
  536. package/packages/pi-coding-agent/src/modes/interactive/components/extension-selector.ts +4 -0
  537. package/packages/pi-coding-agent/src/modes/interactive/components/footer.ts +27 -13
  538. package/packages/pi-coding-agent/src/modes/interactive/components/oauth-selector.ts +4 -4
  539. package/packages/pi-coding-agent/src/modes/interactive/components/provider-manager.ts +45 -14
  540. package/packages/pi-coding-agent/src/modes/interactive/components/scoped-models-selector.ts +2 -7
  541. package/packages/pi-coding-agent/src/modes/interactive/components/session-selector.ts +4 -4
  542. package/packages/pi-coding-agent/src/modes/interactive/components/skill-invocation-message.ts +2 -2
  543. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +8 -3
  544. package/packages/pi-coding-agent/src/modes/interactive/components/user-message-selector.ts +3 -2
  545. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +24 -1
  546. package/packages/pi-coding-agent/src/modes/interactive/controllers/input-controller.ts +14 -1
  547. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +35 -3
  548. package/packages/pi-coding-agent/src/modes/interactive/slash-command-handlers.ts +7 -0
  549. package/packages/pi-coding-agent/src/modes/interactive/theme/themes.ts +1 -1
  550. package/packages/pi-coding-agent/src/modes/rpc/remote-terminal.ts +6 -0
  551. package/packages/pi-tui/dist/terminal.d.ts +2 -0
  552. package/packages/pi-tui/dist/terminal.d.ts.map +1 -1
  553. package/packages/pi-tui/dist/terminal.js +9 -0
  554. package/packages/pi-tui/dist/terminal.js.map +1 -1
  555. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  556. package/packages/pi-tui/dist/tui.js +9 -0
  557. package/packages/pi-tui/dist/tui.js.map +1 -1
  558. package/packages/pi-tui/src/terminal.ts +14 -0
  559. package/packages/pi-tui/src/tui.ts +8 -0
  560. package/pkg/dist/modes/interactive/theme/themes.js +1 -1
  561. package/pkg/dist/modes/interactive/theme/themes.js.map +1 -1
  562. package/scripts/ensure-workspace-builds.cjs +45 -14
  563. package/src/resources/agents/researcher.md +1 -1
  564. package/src/resources/extensions/ask-user-questions.ts +21 -3
  565. package/src/resources/extensions/async-jobs/extension-manifest.json +1 -1
  566. package/src/resources/extensions/bg-shell/extension-manifest.json +1 -1
  567. package/src/resources/extensions/browser-tools/extension-manifest.json +1 -1
  568. package/src/resources/extensions/claude-code-cli/partial-builder.ts +13 -6
  569. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +63 -35
  570. package/src/resources/extensions/claude-code-cli/tests/partial-builder.test.ts +28 -0
  571. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +108 -1
  572. package/src/resources/extensions/context7/extension-manifest.json +1 -1
  573. package/src/resources/extensions/get-secrets-from-user.ts +8 -5
  574. package/src/resources/extensions/google-search/extension-manifest.json +1 -1
  575. package/src/resources/extensions/google-search/index.ts +2 -1
  576. package/src/resources/extensions/gsd/auto/loop-deps.ts +1 -0
  577. package/src/resources/extensions/gsd/auto/phases.ts +43 -34
  578. package/src/resources/extensions/gsd/auto-artifact-paths.ts +2 -2
  579. package/src/resources/extensions/gsd/auto-dashboard.ts +37 -19
  580. package/src/resources/extensions/gsd/auto-dispatch.ts +18 -2
  581. package/src/resources/extensions/gsd/auto-model-selection.ts +26 -5
  582. package/src/resources/extensions/gsd/auto-post-unit.ts +18 -4
  583. package/src/resources/extensions/gsd/auto-prompts.ts +1 -1
  584. package/src/resources/extensions/gsd/auto-recovery.ts +12 -5
  585. package/src/resources/extensions/gsd/auto-start.ts +35 -26
  586. package/src/resources/extensions/gsd/auto-worktree.ts +193 -9
  587. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +31 -0
  588. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +85 -8
  589. package/src/resources/extensions/gsd/bootstrap/dynamic-tools.ts +38 -1
  590. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +41 -35
  591. package/src/resources/extensions/gsd/bootstrap/system-context.ts +72 -12
  592. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +75 -0
  593. package/src/resources/extensions/gsd/captures.ts +63 -3
  594. package/src/resources/extensions/gsd/codebase-generator.ts +351 -0
  595. package/src/resources/extensions/gsd/commands/catalog.ts +10 -1
  596. package/src/resources/extensions/gsd/commands/handlers/ops.ts +5 -0
  597. package/src/resources/extensions/gsd/commands-codebase.ts +164 -0
  598. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +46 -4
  599. package/src/resources/extensions/gsd/complexity-classifier.ts +8 -6
  600. package/src/resources/extensions/gsd/db-writer.ts +140 -7
  601. package/src/resources/extensions/gsd/doctor-git-checks.ts +75 -1
  602. package/src/resources/extensions/gsd/doctor-proactive.ts +35 -1
  603. package/src/resources/extensions/gsd/doctor-providers.ts +2 -1
  604. package/src/resources/extensions/gsd/doctor-runtime-checks.ts +5 -4
  605. package/src/resources/extensions/gsd/doctor-types.ts +2 -0
  606. package/src/resources/extensions/gsd/doctor.ts +3 -1
  607. package/src/resources/extensions/gsd/error-classifier.ts +13 -11
  608. package/src/resources/extensions/gsd/extension-manifest.json +16 -1
  609. package/src/resources/extensions/gsd/forensics.ts +144 -20
  610. package/src/resources/extensions/gsd/git-service.ts +119 -3
  611. package/src/resources/extensions/gsd/gitignore.ts +33 -0
  612. package/src/resources/extensions/gsd/gsd-db.ts +43 -7
  613. package/src/resources/extensions/gsd/guided-flow.ts +114 -45
  614. package/src/resources/extensions/gsd/health-widget-core.ts +34 -0
  615. package/src/resources/extensions/gsd/health-widget.ts +17 -0
  616. package/src/resources/extensions/gsd/index.ts +1 -0
  617. package/src/resources/extensions/gsd/memory-extractor.ts +8 -0
  618. package/src/resources/extensions/gsd/migrate-external.ts +9 -1
  619. package/src/resources/extensions/gsd/milestone-validation-gates.ts +56 -0
  620. package/src/resources/extensions/gsd/model-cost-table.ts +19 -0
  621. package/src/resources/extensions/gsd/model-router.ts +35 -1
  622. package/src/resources/extensions/gsd/native-git-bridge.ts +41 -0
  623. package/src/resources/extensions/gsd/notifications.ts +16 -0
  624. package/src/resources/extensions/gsd/parallel-eligibility.ts +15 -2
  625. package/src/resources/extensions/gsd/parallel-merge.ts +87 -4
  626. package/src/resources/extensions/gsd/parsers-legacy.ts +22 -3
  627. package/src/resources/extensions/gsd/paths.ts +44 -0
  628. package/src/resources/extensions/gsd/preferences-models.ts +14 -1
  629. package/src/resources/extensions/gsd/preferences-types.ts +10 -1
  630. package/src/resources/extensions/gsd/preferences.ts +13 -15
  631. package/src/resources/extensions/gsd/prompt-loader.ts +4 -1
  632. package/src/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  633. package/src/resources/extensions/gsd/prompts/complete-slice.md +4 -2
  634. package/src/resources/extensions/gsd/prompts/discuss-headless.md +1 -1
  635. package/src/resources/extensions/gsd/prompts/discuss.md +1 -1
  636. package/src/resources/extensions/gsd/prompts/execute-task.md +3 -1
  637. package/src/resources/extensions/gsd/prompts/forensics.md +2 -2
  638. package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +1 -1
  639. package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +1 -1
  640. package/src/resources/extensions/gsd/prompts/plan-slice.md +2 -0
  641. package/src/resources/extensions/gsd/prompts/rethink.md +1 -1
  642. package/src/resources/extensions/gsd/prompts/triage-captures.md +1 -0
  643. package/src/resources/extensions/gsd/repo-identity.ts +186 -11
  644. package/src/resources/extensions/gsd/rethink.ts +6 -0
  645. package/src/resources/extensions/gsd/roadmap-slices.ts +5 -4
  646. package/src/resources/extensions/gsd/state.ts +84 -32
  647. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +29 -0
  648. package/src/resources/extensions/gsd/tests/auto-mode-interactive-guard.test.ts +71 -0
  649. package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +71 -1
  650. package/src/resources/extensions/gsd/tests/captures.test.ts +103 -0
  651. package/src/resources/extensions/gsd/tests/cli-provider-rate-limit.test.ts +47 -0
  652. package/src/resources/extensions/gsd/tests/codebase-generator.test.ts +488 -0
  653. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +27 -0
  654. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +21 -0
  655. package/src/resources/extensions/gsd/tests/completion-hierarchy-guards.test.ts +192 -0
  656. package/src/resources/extensions/gsd/tests/complexity-classifier.test.ts +4 -4
  657. package/src/resources/extensions/gsd/tests/db-path-worktree-symlink.test.ts +131 -0
  658. package/src/resources/extensions/gsd/tests/db-writer.test.ts +7 -12
  659. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +78 -5
  660. package/src/resources/extensions/gsd/tests/derive-state.test.ts +29 -0
  661. package/src/resources/extensions/gsd/tests/discord-invite-links.test.ts +47 -0
  662. package/src/resources/extensions/gsd/tests/discuss-empty-db-fallback.test.ts +127 -0
  663. package/src/resources/extensions/gsd/tests/discuss-queued-milestones.test.ts +40 -0
  664. package/src/resources/extensions/gsd/tests/dist-redirect.mjs +20 -1
  665. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +117 -0
  666. package/src/resources/extensions/gsd/tests/dynamic-routing-default.test.ts +20 -0
  667. package/src/resources/extensions/gsd/tests/empty-content-abort-loop.test.ts +74 -0
  668. package/src/resources/extensions/gsd/tests/event-replay-idempotency.test.ts +140 -0
  669. package/src/resources/extensions/gsd/tests/forensics-context-persist.test.ts +129 -0
  670. package/src/resources/extensions/gsd/tests/forensics-db-completion.test.ts +96 -0
  671. package/src/resources/extensions/gsd/tests/forensics-dedup.test.ts +31 -0
  672. package/src/resources/extensions/gsd/tests/gsd-tools.test.ts +125 -12
  673. package/src/resources/extensions/gsd/tests/gsdroot-worktree-detection.test.ts +164 -0
  674. package/src/resources/extensions/gsd/tests/guided-flow-dynamic-routing.test.ts +135 -0
  675. package/src/resources/extensions/gsd/tests/guided-flow-session-isolation.test.ts +97 -0
  676. package/src/resources/extensions/gsd/tests/health-widget.test.ts +67 -0
  677. package/src/resources/extensions/gsd/tests/hook-key-parsing.test.ts +107 -0
  678. package/src/resources/extensions/gsd/tests/integration/auto-recovery.test.ts +111 -1
  679. package/src/resources/extensions/gsd/tests/integration/auto-worktree-milestone-merge.test.ts +134 -0
  680. package/src/resources/extensions/gsd/tests/integration/auto-worktree.test.ts +59 -0
  681. package/src/resources/extensions/gsd/tests/integration/doctor-false-positives.test.ts +243 -0
  682. package/src/resources/extensions/gsd/tests/integration/doctor-git.test.ts +72 -0
  683. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +68 -0
  684. package/src/resources/extensions/gsd/tests/integration/gitignore-staging-2570.test.ts +150 -0
  685. package/src/resources/extensions/gsd/tests/integration/parallel-merge.test.ts +110 -0
  686. package/src/resources/extensions/gsd/tests/integration/run-uat.test.ts +1 -1
  687. package/src/resources/extensions/gsd/tests/integration/state-machine-live-validation.test.ts +959 -0
  688. package/src/resources/extensions/gsd/tests/memory-extractor.test.ts +85 -2
  689. package/src/resources/extensions/gsd/tests/migrate-external-worktree.test.ts +105 -0
  690. package/src/resources/extensions/gsd/tests/milestone-status-authoritative.test.ts +116 -0
  691. package/src/resources/extensions/gsd/tests/model-cost-table.test.ts +34 -0
  692. package/src/resources/extensions/gsd/tests/model-router.test.ts +68 -3
  693. package/src/resources/extensions/gsd/tests/model-unittype-mapping.test.ts +28 -0
  694. package/src/resources/extensions/gsd/tests/notifications.test.ts +45 -0
  695. package/src/resources/extensions/gsd/tests/parallel-commit-scope.test.ts +159 -0
  696. package/src/resources/extensions/gsd/tests/parallel-eligibility-ghost.test.ts +150 -0
  697. package/src/resources/extensions/gsd/tests/plan-milestone-title.test.ts +70 -0
  698. package/src/resources/extensions/gsd/tests/plan-milestone.test.ts +33 -1
  699. package/src/resources/extensions/gsd/tests/project-relocation-recovery.test.ts +297 -0
  700. package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +29 -0
  701. package/src/resources/extensions/gsd/tests/prompt-loader-replacement.test.ts +178 -0
  702. package/src/resources/extensions/gsd/tests/prompt-tool-names.test.ts +69 -0
  703. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +38 -0
  704. package/src/resources/extensions/gsd/tests/queue-execution-guard.test.ts +157 -0
  705. package/src/resources/extensions/gsd/tests/quick-turn-end-cleanup.test.ts +90 -0
  706. package/src/resources/extensions/gsd/tests/reassess-handler.test.ts +117 -0
  707. package/src/resources/extensions/gsd/tests/reconciliation-edge-cases.test.ts +162 -0
  708. package/src/resources/extensions/gsd/tests/roadmap-slices.test.ts +97 -0
  709. package/src/resources/extensions/gsd/tests/secure-env-collect.test.ts +134 -0
  710. package/src/resources/extensions/gsd/tests/slice-disk-reconcile.test.ts +233 -0
  711. package/src/resources/extensions/gsd/tests/stash-queued-context-files.test.ts +305 -0
  712. package/src/resources/extensions/gsd/tests/state-corruption-2945.test.ts +405 -0
  713. package/src/resources/extensions/gsd/tests/state-derivation-parity.test.ts +257 -0
  714. package/src/resources/extensions/gsd/tests/state-machine-full-walkthrough.test.ts +1628 -0
  715. package/src/resources/extensions/gsd/tests/stop-auto-race-null-unit.test.ts +106 -0
  716. package/src/resources/extensions/gsd/tests/stuck-detection-coverage.test.ts +174 -0
  717. package/src/resources/extensions/gsd/tests/summary-render-parity.test.ts +221 -0
  718. package/src/resources/extensions/gsd/tests/terminated-transient.test.ts +44 -0
  719. package/src/resources/extensions/gsd/tests/tool-naming.test.ts +2 -1
  720. package/src/resources/extensions/gsd/tests/triage-resolution.test.ts +8 -0
  721. package/src/resources/extensions/gsd/tests/uat-stuck-loop-orphaned-worktree.test.ts +289 -0
  722. package/src/resources/extensions/gsd/tests/unit-ownership.test.ts +100 -17
  723. package/src/resources/extensions/gsd/tests/vacuum-recovery.test.ts +154 -0
  724. package/src/resources/extensions/gsd/tests/validate-milestone-write-order.test.ts +4 -1
  725. package/src/resources/extensions/gsd/tests/verdict-parser.test.ts +156 -0
  726. package/src/resources/extensions/gsd/tests/verification-operational-gate.test.ts +82 -0
  727. package/src/resources/extensions/gsd/tests/workflow-logger.test.ts +48 -0
  728. package/src/resources/extensions/gsd/tests/workflow-manifest.test.ts +92 -0
  729. package/src/resources/extensions/gsd/tests/workflow-projections.test.ts +4 -2
  730. package/src/resources/extensions/gsd/tests/worktree-db-respawn-truncation.test.ts +140 -0
  731. package/src/resources/extensions/gsd/tests/worktree-nested-git-safety.test.ts +101 -0
  732. package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +48 -1
  733. package/src/resources/extensions/gsd/tests/worktree-sync-milestones.test.ts +29 -5
  734. package/src/resources/extensions/gsd/tests/zombie-gsd-state.test.ts +95 -0
  735. package/src/resources/extensions/gsd/tools/complete-task.ts +36 -74
  736. package/src/resources/extensions/gsd/tools/plan-milestone.ts +13 -1
  737. package/src/resources/extensions/gsd/tools/reassess-roadmap.ts +36 -0
  738. package/src/resources/extensions/gsd/tools/validate-milestone.ts +20 -2
  739. package/src/resources/extensions/gsd/triage-resolution.ts +23 -6
  740. package/src/resources/extensions/gsd/types.ts +4 -2
  741. package/src/resources/extensions/gsd/undo.ts +2 -2
  742. package/src/resources/extensions/gsd/unit-ownership.ts +206 -35
  743. package/src/resources/extensions/gsd/verdict-parser.ts +21 -6
  744. package/src/resources/extensions/gsd/watch/header-renderer.ts +275 -0
  745. package/src/resources/extensions/gsd/workflow-logger.ts +3 -1
  746. package/src/resources/extensions/gsd/workflow-manifest.ts +22 -5
  747. package/src/resources/extensions/gsd/workflow-projections.ts +97 -64
  748. package/src/resources/extensions/gsd/workflow-reconcile.ts +39 -10
  749. package/src/resources/extensions/gsd/workspace-index.ts +30 -0
  750. package/src/resources/extensions/gsd/worktree-manager.ts +120 -1
  751. package/src/resources/extensions/gsd/worktree-resolver.ts +22 -3
  752. package/src/resources/extensions/mcp-client/index.ts +13 -7
  753. package/src/resources/extensions/mcp-client/tests/server-name-spaces.test.ts +55 -0
  754. package/src/resources/extensions/ollama/index.ts +130 -0
  755. package/src/resources/extensions/ollama/model-capabilities.ts +145 -0
  756. package/src/resources/extensions/ollama/ollama-client.ts +196 -0
  757. package/src/resources/extensions/ollama/ollama-commands.ts +248 -0
  758. package/src/resources/extensions/ollama/ollama-discovery.ts +106 -0
  759. package/src/resources/extensions/ollama/ollama-tool.ts +218 -0
  760. package/src/resources/extensions/ollama/tests/model-capabilities.test.ts +162 -0
  761. package/src/resources/extensions/ollama/tests/ollama-client.test.ts +38 -0
  762. package/src/resources/extensions/ollama/tests/ollama-discovery.test.ts +28 -0
  763. package/src/resources/extensions/ollama/types.ts +130 -0
  764. package/src/resources/extensions/search-the-web/extension-manifest.json +1 -1
  765. package/src/resources/extensions/search-the-web/url-utils.ts +19 -0
  766. package/src/resources/extensions/shared/interview-ui.ts +12 -1
  767. package/src/resources/extensions/shared/tests/ask-user-freetext.test.ts +156 -0
  768. package/src/resources/skills/create-gsd-extension/SKILL.md +5 -3
  769. package/src/resources/skills/create-gsd-extension/references/key-rules-gotchas.md +5 -4
  770. package/src/resources/skills/create-gsd-extension/workflows/add-capability.md +2 -2
  771. package/src/resources/skills/create-gsd-extension/workflows/create-extension.md +4 -4
  772. package/src/resources/skills/create-gsd-extension/workflows/debug-extension.md +5 -3
  773. package/dist/web/standalone/.next/static/chunks/6502.8b732f67a11b11b4.js +0 -9
  774. package/dist/web/standalone/.next/static/css/a58ef8a151aa0493.css +0 -1
  775. package/src/resources/extensions/gsd/tests/empty-db-reconciliation.test.ts +0 -79
  776. /package/dist/web/standalone/.next/static/{5DLsjFHdSB6_a1EDQVjr7 → nUA6d2OJrDSVq9RNb-c8b}/_buildManifest.js +0 -0
  777. /package/dist/web/standalone/.next/static/{5DLsjFHdSB6_a1EDQVjr7 → nUA6d2OJrDSVq9RNb-c8b}/_ssgManifest.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AssistantMessageEventStream } from \"./utils/event-stream.js\";\n\nexport type { AssistantMessageEventStream } from \"./utils/event-stream.js\";\n\nexport type KnownApi =\n\t| \"openai-completions\"\n\t| \"mistral-conversations\"\n\t| \"openai-responses\"\n\t| \"azure-openai-responses\"\n\t| \"openai-codex-responses\"\n\t| \"anthropic-messages\"\n\t| \"anthropic-vertex\"\n\t| \"bedrock-converse-stream\"\n\t| \"google-generative-ai\"\n\t| \"google-gemini-cli\"\n\t| \"google-vertex\";\n\nexport type Api = KnownApi | (string & {});\n\nexport type KnownProvider =\n\t| \"amazon-bedrock\"\n\t| \"anthropic\"\n\t| \"anthropic-vertex\"\n\t| \"google\"\n\t| \"google-gemini-cli\"\n\t| \"google-antigravity\"\n\t| \"google-vertex\"\n\t| \"openai\"\n\t| \"azure-openai-responses\"\n\t| \"openai-codex\"\n\t| \"github-copilot\"\n\t| \"xai\"\n\t| \"groq\"\n\t| \"cerebras\"\n\t| \"openrouter\"\n\t| \"vercel-ai-gateway\"\n\t| \"zai\"\n\t| \"mistral\"\n\t| \"minimax\"\n\t| \"minimax-cn\"\n\t| \"huggingface\"\n\t| \"opencode\"\n\t| \"opencode-go\"\n\t| \"kimi-coding\"\n\t| \"alibaba-coding-plan\"\n\t| \"ollama-cloud\";\nexport type Provider = KnownProvider | string;\n\nexport type ThinkingLevel = \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\n/** Token budgets for each thinking level (token-based providers only) */\nexport interface ThinkingBudgets {\n\tminimal?: number;\n\tlow?: number;\n\tmedium?: number;\n\thigh?: number;\n}\n\n// Base options all providers share\nexport type CacheRetention = \"none\" | \"short\" | \"long\";\n\nexport type Transport = \"sse\" | \"websocket\" | \"auto\";\n\nexport interface StreamOptions {\n\ttemperature?: number;\n\tmaxTokens?: number;\n\tsignal?: AbortSignal;\n\tapiKey?: string;\n\t/**\n\t * Preferred transport for providers that support multiple transports.\n\t * Providers that do not support this option ignore it.\n\t */\n\ttransport?: Transport;\n\t/**\n\t * Prompt cache retention preference. Providers map this to their supported values.\n\t * Default: \"short\".\n\t */\n\tcacheRetention?: CacheRetention;\n\t/**\n\t * Optional session identifier for providers that support session-based caching.\n\t * Providers can use this to enable prompt caching, request routing, or other\n\t * session-aware features. Ignored by providers that don't support it.\n\t */\n\tsessionId?: string;\n\t/**\n\t * Optional callback for inspecting or replacing provider payloads before sending.\n\t * Return undefined to keep the payload unchanged.\n\t */\n\tonPayload?: (payload: unknown, model: Model<Api>) => unknown | undefined | Promise<unknown | undefined>;\n\t/**\n\t * Optional custom HTTP headers to include in API requests.\n\t * Merged with provider defaults; can override default headers.\n\t * Not supported by all providers (e.g., AWS Bedrock uses SDK auth).\n\t */\n\theaders?: Record<string, string>;\n\t/**\n\t * Maximum delay in milliseconds to wait for a retry when the server requests a long wait.\n\t * If the server's requested delay exceeds this value, the request fails immediately\n\t * with an error containing the requested delay, allowing higher-level retry logic\n\t * to handle it with user visibility.\n\t * Default: 60000 (60 seconds). Set to 0 to disable the cap.\n\t */\n\tmaxRetryDelayMs?: number;\n\t/**\n\t * Optional metadata to include in API requests.\n\t * Providers extract the fields they understand and ignore the rest.\n\t * For example, Anthropic uses `user_id` for abuse tracking and rate limiting.\n\t */\n\tmetadata?: Record<string, unknown>;\n}\n\nexport type ProviderStreamOptions = StreamOptions & Record<string, unknown>;\n\n// Unified options with reasoning passed to streamSimple() and completeSimple()\nexport interface SimpleStreamOptions extends StreamOptions {\n\treasoning?: ThinkingLevel;\n\t/** Custom token budgets for thinking levels (token-based providers only) */\n\tthinkingBudgets?: ThinkingBudgets;\n}\n\n// Generic StreamFunction with typed options\nexport type StreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = StreamOptions> = (\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: TOptions,\n) => AssistantMessageEventStream;\n\nexport interface TextSignatureV1 {\n\tv: 1;\n\tid: string;\n\tphase?: \"commentary\" | \"final_answer\";\n}\n\nexport interface TextContent {\n\ttype: \"text\";\n\ttext: string;\n\ttextSignature?: string; // e.g., for OpenAI responses, message metadata (legacy id string or TextSignatureV1 JSON)\n}\n\nexport interface ThinkingContent {\n\ttype: \"thinking\";\n\tthinking: string;\n\tthinkingSignature?: string; // e.g., for OpenAI responses, the reasoning item ID\n\t/** When true, the thinking content was redacted by safety filters. The opaque\n\t * encrypted payload is stored in `thinkingSignature` so it can be passed back\n\t * to the API for multi-turn continuity. */\n\tredacted?: boolean;\n}\n\nexport interface ImageContent {\n\ttype: \"image\";\n\tdata: string; // base64 encoded image data\n\tmimeType: string; // e.g., \"image/jpeg\", \"image/png\"\n}\n\nexport interface ToolCall {\n\ttype: \"toolCall\";\n\tid: string;\n\tname: string;\n\targuments: Record<string, any>;\n\tthoughtSignature?: string; // Google-specific: opaque signature for reusing thought context\n}\n\n/** Server-side tool use (e.g., Anthropic native web search). Executed by the API, not the client. */\nexport interface ServerToolUseContent {\n\ttype: \"serverToolUse\";\n\tid: string;\n\tname: string; // e.g., \"web_search\"\n\tinput: unknown;\n}\n\n/** Result of a server-side tool execution, paired with a ServerToolUseContent by toolUseId. */\nexport interface WebSearchResultContent {\n\ttype: \"webSearchResult\";\n\ttoolUseId: string;\n\t/** Search results or error from the server. Opaque — stored for API replay. */\n\tcontent: unknown;\n}\n\nexport interface Usage {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\ttotalTokens: number;\n\tcost: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\ttotal: number;\n\t};\n}\n\nexport type StopReason = \"stop\" | \"length\" | \"toolUse\" | \"error\" | \"aborted\";\n\nexport interface UserMessage {\n\trole: \"user\";\n\tcontent: string | (TextContent | ImageContent)[];\n\ttimestamp: number; // Unix timestamp in milliseconds\n}\n\nexport interface AssistantMessage {\n\trole: \"assistant\";\n\tcontent: (TextContent | ThinkingContent | ToolCall | ServerToolUseContent | WebSearchResultContent)[];\n\tapi: Api;\n\tprovider: Provider;\n\tmodel: string;\n\tusage: Usage;\n\tstopReason: StopReason;\n\terrorMessage?: string;\n\t/** Server-requested retry delay in milliseconds (from Retry-After or rate limit headers). */\n\tretryAfterMs?: number;\n\ttimestamp: number; // Unix timestamp in milliseconds\n}\n\nexport interface ToolResultMessage<TDetails = any> {\n\trole: \"toolResult\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tcontent: (TextContent | ImageContent)[]; // Supports text and images\n\tdetails?: TDetails;\n\tisError: boolean;\n\ttimestamp: number; // Unix timestamp in milliseconds\n}\n\nexport type Message = UserMessage | AssistantMessage | ToolResultMessage;\n\nimport type { TSchema } from \"@sinclair/typebox\";\n\nexport interface Tool<TParameters extends TSchema = TSchema> {\n\tname: string;\n\tdescription: string;\n\tparameters: TParameters;\n}\n\nexport interface Context {\n\tsystemPrompt?: string;\n\tmessages: Message[];\n\ttools?: Tool[];\n}\n\nexport type AssistantMessageEvent =\n\t| { type: \"start\"; partial: AssistantMessage }\n\t| { type: \"text_start\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"text_delta\"; contentIndex: number; delta: string; partial: AssistantMessage }\n\t| { type: \"text_end\"; contentIndex: number; content: string; partial: AssistantMessage }\n\t| { type: \"thinking_start\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"thinking_delta\"; contentIndex: number; delta: string; partial: AssistantMessage }\n\t| { type: \"thinking_end\"; contentIndex: number; content: string; partial: AssistantMessage }\n\t| { type: \"toolcall_start\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"toolcall_delta\"; contentIndex: number; delta: string; partial: AssistantMessage }\n\t| { type: \"toolcall_end\"; contentIndex: number; toolCall: ToolCall; partial: AssistantMessage; malformedArguments?: boolean }\n\t| { type: \"server_tool_use\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"web_search_result\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"done\"; reason: Extract<StopReason, \"stop\" | \"length\" | \"toolUse\">; message: AssistantMessage }\n\t| { type: \"error\"; reason: Extract<StopReason, \"aborted\" | \"error\">; error: AssistantMessage };\n\n/**\n * Compatibility settings for OpenAI-compatible completions APIs.\n * Use this to override URL-based auto-detection for custom providers.\n */\nexport interface OpenAICompletionsCompat {\n\t/** Whether the provider supports the `store` field. Default: auto-detected from URL. */\n\tsupportsStore?: boolean;\n\t/** Whether the provider supports the `developer` role (vs `system`). Default: auto-detected from URL. */\n\tsupportsDeveloperRole?: boolean;\n\t/** Whether the provider supports `reasoning_effort`. Default: auto-detected from URL. */\n\tsupportsReasoningEffort?: boolean;\n\t/** Optional mapping from pi-ai reasoning levels to provider/model-specific `reasoning_effort` values. */\n\treasoningEffortMap?: Partial<Record<ThinkingLevel, string>>;\n\t/** Whether the provider supports `stream_options: { include_usage: true }` for token usage in streaming responses. Default: true. */\n\tsupportsUsageInStreaming?: boolean;\n\t/** Which field to use for max tokens. Default: auto-detected from URL. */\n\tmaxTokensField?: \"max_completion_tokens\" | \"max_tokens\";\n\t/** Whether tool results require the `name` field. Default: auto-detected from URL. */\n\trequiresToolResultName?: boolean;\n\t/** Whether a user message after tool results requires an assistant message in between. Default: auto-detected from URL. */\n\trequiresAssistantAfterToolResult?: boolean;\n\t/** Whether thinking blocks must be converted to text blocks with <thinking> delimiters. Default: auto-detected from URL. */\n\trequiresThinkingAsText?: boolean;\n\t/** Format for reasoning/thinking parameter. \"openai\" uses reasoning_effort, \"zai\" uses thinking: { type: \"enabled\" }, \"qwen\" uses enable_thinking: boolean. Default: \"openai\". */\n\tthinkingFormat?: \"openai\" | \"zai\" | \"qwen\";\n\t/** OpenRouter-specific routing preferences. Only used when baseUrl points to OpenRouter. */\n\topenRouterRouting?: OpenRouterRouting;\n\t/** Vercel AI Gateway routing preferences. Only used when baseUrl points to Vercel AI Gateway. */\n\tvercelGatewayRouting?: VercelGatewayRouting;\n\t/** Whether the provider supports the `strict` field in tool definitions. Default: true. */\n\tsupportsStrictMode?: boolean;\n}\n\n/** Compatibility settings for OpenAI Responses APIs. */\nexport interface OpenAIResponsesCompat {\n\t// Reserved for future use\n}\n\n/**\n * OpenRouter provider routing preferences.\n * Controls which upstream providers OpenRouter routes requests to.\n * @see https://openrouter.ai/docs/provider-routing\n */\nexport interface OpenRouterRouting {\n\t/** List of provider slugs to exclusively use for this request (e.g., [\"amazon-bedrock\", \"anthropic\"]). */\n\tonly?: string[];\n\t/** List of provider slugs to try in order (e.g., [\"anthropic\", \"openai\"]). */\n\torder?: string[];\n}\n\n/**\n * Vercel AI Gateway routing preferences.\n * Controls which upstream providers the gateway routes requests to.\n * @see https://vercel.com/docs/ai-gateway/models-and-providers/provider-options\n */\nexport interface VercelGatewayRouting {\n\t/** List of provider slugs to exclusively use for this request (e.g., [\"bedrock\", \"anthropic\"]). */\n\tonly?: string[];\n\t/** List of provider slugs to try in order (e.g., [\"anthropic\", \"openai\"]). */\n\torder?: string[];\n}\n\n/**\n * Provider-agnostic capability declarations for a model.\n *\n * These fields allow models to self-declare supported features so that call\n * sites can read from metadata rather than pattern-matching on model IDs or\n * provider names. Add fields here as new cross-provider capabilities emerge.\n */\nexport interface ModelCapabilities {\n\t/** Whether the model supports xhigh thinking level. */\n\tsupportsXhigh?: boolean;\n\t/**\n\t * Whether tool call IDs must be included and normalised in tool results for\n\t * this model. Relevant for models deployed cross-provider (e.g. Claude or\n\t * GPT variants via Google APIs) where the host API imposes stricter ID rules.\n\t */\n\trequiresToolCallId?: boolean;\n\t/** Whether OpenAI-style service tiers (priority/flex) apply to this model. */\n\tsupportsServiceTier?: boolean;\n\t/**\n\t * Approximate characters per token for this model.\n\t * Used as a fallback when an accurate tokenizer is unavailable.\n\t * If omitted, the provider-level default is used.\n\t */\n\tcharsPerToken?: number;\n}\n\n// Model interface for the unified model system\nexport interface Model<TApi extends Api> {\n\tid: string;\n\tname: string;\n\tapi: TApi;\n\tprovider: Provider;\n\tbaseUrl: string;\n\treasoning: boolean;\n\tinput: (\"text\" | \"image\")[];\n\tcost: {\n\t\tinput: number; // $/million tokens\n\t\toutput: number; // $/million tokens\n\t\tcacheRead: number; // $/million tokens\n\t\tcacheWrite: number; // $/million tokens\n\t};\n\tcontextWindow: number;\n\tmaxTokens: number;\n\theaders?: Record<string, string>;\n\t/** Compatibility overrides for OpenAI-compatible APIs. If not set, auto-detected from baseUrl. */\n\tcompat?: TApi extends \"openai-completions\"\n\t\t? OpenAICompletionsCompat\n\t\t: TApi extends \"openai-responses\"\n\t\t\t? OpenAIResponsesCompat\n\t\t\t: never;\n\t/**\n\t * Provider-agnostic capability declarations for this model.\n\t * Read these fields instead of pattern-matching on model IDs or provider names.\n\t */\n\tcapabilities?: ModelCapabilities;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AssistantMessageEventStream } from \"./utils/event-stream.js\";\n\nexport type { AssistantMessageEventStream } from \"./utils/event-stream.js\";\n\nexport type KnownApi =\n\t| \"openai-completions\"\n\t| \"mistral-conversations\"\n\t| \"openai-responses\"\n\t| \"azure-openai-responses\"\n\t| \"openai-codex-responses\"\n\t| \"anthropic-messages\"\n\t| \"anthropic-vertex\"\n\t| \"bedrock-converse-stream\"\n\t| \"google-generative-ai\"\n\t| \"google-gemini-cli\"\n\t| \"google-vertex\";\n\nexport type Api = KnownApi | (string & {});\n\nexport type KnownProvider =\n\t| \"amazon-bedrock\"\n\t| \"anthropic\"\n\t| \"anthropic-vertex\"\n\t| \"google\"\n\t| \"google-gemini-cli\"\n\t| \"google-antigravity\"\n\t| \"google-vertex\"\n\t| \"openai\"\n\t| \"azure-openai-responses\"\n\t| \"openai-codex\"\n\t| \"github-copilot\"\n\t| \"xai\"\n\t| \"groq\"\n\t| \"cerebras\"\n\t| \"openrouter\"\n\t| \"vercel-ai-gateway\"\n\t| \"zai\"\n\t| \"mistral\"\n\t| \"minimax\"\n\t| \"minimax-cn\"\n\t| \"huggingface\"\n\t| \"opencode\"\n\t| \"opencode-go\"\n\t| \"kimi-coding\"\n\t| \"alibaba-coding-plan\"\n\t| \"ollama\"\n\t| \"ollama-cloud\";\nexport type Provider = KnownProvider | string;\n\nexport type ThinkingLevel = \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\n/** Token budgets for each thinking level (token-based providers only) */\nexport interface ThinkingBudgets {\n\tminimal?: number;\n\tlow?: number;\n\tmedium?: number;\n\thigh?: number;\n}\n\n// Base options all providers share\nexport type CacheRetention = \"none\" | \"short\" | \"long\";\n\nexport type Transport = \"sse\" | \"websocket\" | \"auto\";\n\nexport interface StreamOptions {\n\ttemperature?: number;\n\tmaxTokens?: number;\n\tsignal?: AbortSignal;\n\tapiKey?: string;\n\t/**\n\t * Preferred transport for providers that support multiple transports.\n\t * Providers that do not support this option ignore it.\n\t */\n\ttransport?: Transport;\n\t/**\n\t * Prompt cache retention preference. Providers map this to their supported values.\n\t * Default: \"short\".\n\t */\n\tcacheRetention?: CacheRetention;\n\t/**\n\t * Optional session identifier for providers that support session-based caching.\n\t * Providers can use this to enable prompt caching, request routing, or other\n\t * session-aware features. Ignored by providers that don't support it.\n\t */\n\tsessionId?: string;\n\t/**\n\t * Optional callback for inspecting or replacing provider payloads before sending.\n\t * Return undefined to keep the payload unchanged.\n\t */\n\tonPayload?: (payload: unknown, model: Model<Api>) => unknown | undefined | Promise<unknown | undefined>;\n\t/**\n\t * Optional custom HTTP headers to include in API requests.\n\t * Merged with provider defaults; can override default headers.\n\t * Not supported by all providers (e.g., AWS Bedrock uses SDK auth).\n\t */\n\theaders?: Record<string, string>;\n\t/**\n\t * Maximum delay in milliseconds to wait for a retry when the server requests a long wait.\n\t * If the server's requested delay exceeds this value, the request fails immediately\n\t * with an error containing the requested delay, allowing higher-level retry logic\n\t * to handle it with user visibility.\n\t * Default: 60000 (60 seconds). Set to 0 to disable the cap.\n\t */\n\tmaxRetryDelayMs?: number;\n\t/**\n\t * Optional metadata to include in API requests.\n\t * Providers extract the fields they understand and ignore the rest.\n\t * For example, Anthropic uses `user_id` for abuse tracking and rate limiting.\n\t */\n\tmetadata?: Record<string, unknown>;\n}\n\nexport type ProviderStreamOptions = StreamOptions & Record<string, unknown>;\n\n// Unified options with reasoning passed to streamSimple() and completeSimple()\nexport interface SimpleStreamOptions extends StreamOptions {\n\treasoning?: ThinkingLevel;\n\t/** Custom token budgets for thinking levels (token-based providers only) */\n\tthinkingBudgets?: ThinkingBudgets;\n}\n\n// Generic StreamFunction with typed options\nexport type StreamFunction<TApi extends Api = Api, TOptions extends StreamOptions = StreamOptions> = (\n\tmodel: Model<TApi>,\n\tcontext: Context,\n\toptions?: TOptions,\n) => AssistantMessageEventStream;\n\nexport interface TextSignatureV1 {\n\tv: 1;\n\tid: string;\n\tphase?: \"commentary\" | \"final_answer\";\n}\n\nexport interface TextContent {\n\ttype: \"text\";\n\ttext: string;\n\ttextSignature?: string; // e.g., for OpenAI responses, message metadata (legacy id string or TextSignatureV1 JSON)\n}\n\nexport interface ThinkingContent {\n\ttype: \"thinking\";\n\tthinking: string;\n\tthinkingSignature?: string; // e.g., for OpenAI responses, the reasoning item ID\n\t/** When true, the thinking content was redacted by safety filters. The opaque\n\t * encrypted payload is stored in `thinkingSignature` so it can be passed back\n\t * to the API for multi-turn continuity. */\n\tredacted?: boolean;\n}\n\nexport interface ImageContent {\n\ttype: \"image\";\n\tdata: string; // base64 encoded image data\n\tmimeType: string; // e.g., \"image/jpeg\", \"image/png\"\n}\n\nexport interface ToolCall {\n\ttype: \"toolCall\";\n\tid: string;\n\tname: string;\n\targuments: Record<string, any>;\n\tthoughtSignature?: string; // Google-specific: opaque signature for reusing thought context\n}\n\n/** Server-side tool use (e.g., Anthropic native web search). Executed by the API, not the client. */\nexport interface ServerToolUseContent {\n\ttype: \"serverToolUse\";\n\tid: string;\n\tname: string; // e.g., \"web_search\"\n\tinput: unknown;\n}\n\n/** Result of a server-side tool execution, paired with a ServerToolUseContent by toolUseId. */\nexport interface WebSearchResultContent {\n\ttype: \"webSearchResult\";\n\ttoolUseId: string;\n\t/** Search results or error from the server. Opaque — stored for API replay. */\n\tcontent: unknown;\n}\n\nexport interface Usage {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\ttotalTokens: number;\n\tcost: {\n\t\tinput: number;\n\t\toutput: number;\n\t\tcacheRead: number;\n\t\tcacheWrite: number;\n\t\ttotal: number;\n\t};\n}\n\nexport type StopReason = \"stop\" | \"length\" | \"toolUse\" | \"pauseTurn\" | \"error\" | \"aborted\";\n\nexport interface UserMessage {\n\trole: \"user\";\n\tcontent: string | (TextContent | ImageContent)[];\n\ttimestamp: number; // Unix timestamp in milliseconds\n}\n\nexport interface AssistantMessage {\n\trole: \"assistant\";\n\tcontent: (TextContent | ThinkingContent | ToolCall | ServerToolUseContent | WebSearchResultContent)[];\n\tapi: Api;\n\tprovider: Provider;\n\tmodel: string;\n\tusage: Usage;\n\tstopReason: StopReason;\n\terrorMessage?: string;\n\t/** Server-requested retry delay in milliseconds (from Retry-After or rate limit headers). */\n\tretryAfterMs?: number;\n\ttimestamp: number; // Unix timestamp in milliseconds\n}\n\nexport interface ToolResultMessage<TDetails = any> {\n\trole: \"toolResult\";\n\ttoolCallId: string;\n\ttoolName: string;\n\tcontent: (TextContent | ImageContent)[]; // Supports text and images\n\tdetails?: TDetails;\n\tisError: boolean;\n\ttimestamp: number; // Unix timestamp in milliseconds\n}\n\nexport type Message = UserMessage | AssistantMessage | ToolResultMessage;\n\nimport type { TSchema } from \"@sinclair/typebox\";\n\nexport interface Tool<TParameters extends TSchema = TSchema> {\n\tname: string;\n\tdescription: string;\n\tparameters: TParameters;\n}\n\nexport interface Context {\n\tsystemPrompt?: string;\n\tmessages: Message[];\n\ttools?: Tool[];\n}\n\nexport type AssistantMessageEvent =\n\t| { type: \"start\"; partial: AssistantMessage }\n\t| { type: \"text_start\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"text_delta\"; contentIndex: number; delta: string; partial: AssistantMessage }\n\t| { type: \"text_end\"; contentIndex: number; content: string; partial: AssistantMessage }\n\t| { type: \"thinking_start\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"thinking_delta\"; contentIndex: number; delta: string; partial: AssistantMessage }\n\t| { type: \"thinking_end\"; contentIndex: number; content: string; partial: AssistantMessage }\n\t| { type: \"toolcall_start\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"toolcall_delta\"; contentIndex: number; delta: string; partial: AssistantMessage }\n\t| { type: \"toolcall_end\"; contentIndex: number; toolCall: ToolCall; partial: AssistantMessage; malformedArguments?: boolean }\n\t| { type: \"server_tool_use\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"web_search_result\"; contentIndex: number; partial: AssistantMessage }\n\t| { type: \"done\"; reason: Extract<StopReason, \"stop\" | \"length\" | \"toolUse\" | \"pauseTurn\">; message: AssistantMessage }\n\t| { type: \"error\"; reason: Extract<StopReason, \"aborted\" | \"error\">; error: AssistantMessage };\n\n/**\n * Compatibility settings for OpenAI-compatible completions APIs.\n * Use this to override URL-based auto-detection for custom providers.\n */\nexport interface OpenAICompletionsCompat {\n\t/** Whether the provider supports the `store` field. Default: auto-detected from URL. */\n\tsupportsStore?: boolean;\n\t/** Whether the provider supports the `developer` role (vs `system`). Default: auto-detected from URL. */\n\tsupportsDeveloperRole?: boolean;\n\t/** Whether the provider supports `reasoning_effort`. Default: auto-detected from URL. */\n\tsupportsReasoningEffort?: boolean;\n\t/** Optional mapping from pi-ai reasoning levels to provider/model-specific `reasoning_effort` values. */\n\treasoningEffortMap?: Partial<Record<ThinkingLevel, string>>;\n\t/** Whether the provider supports `stream_options: { include_usage: true }` for token usage in streaming responses. Default: true. */\n\tsupportsUsageInStreaming?: boolean;\n\t/** Which field to use for max tokens. Default: auto-detected from URL. */\n\tmaxTokensField?: \"max_completion_tokens\" | \"max_tokens\";\n\t/** Whether tool results require the `name` field. Default: auto-detected from URL. */\n\trequiresToolResultName?: boolean;\n\t/** Whether a user message after tool results requires an assistant message in between. Default: auto-detected from URL. */\n\trequiresAssistantAfterToolResult?: boolean;\n\t/** Whether thinking blocks must be converted to text blocks with <thinking> delimiters. Default: auto-detected from URL. */\n\trequiresThinkingAsText?: boolean;\n\t/** Format for reasoning/thinking parameter. \"openai\" uses reasoning_effort, \"zai\" uses thinking: { type: \"enabled\" }, \"qwen\" uses enable_thinking: boolean. Default: \"openai\". */\n\tthinkingFormat?: \"openai\" | \"zai\" | \"qwen\";\n\t/** OpenRouter-specific routing preferences. Only used when baseUrl points to OpenRouter. */\n\topenRouterRouting?: OpenRouterRouting;\n\t/** Vercel AI Gateway routing preferences. Only used when baseUrl points to Vercel AI Gateway. */\n\tvercelGatewayRouting?: VercelGatewayRouting;\n\t/** Whether the provider supports the `strict` field in tool definitions. Default: true. */\n\tsupportsStrictMode?: boolean;\n}\n\n/** Compatibility settings for OpenAI Responses APIs. */\nexport interface OpenAIResponsesCompat {\n\t// Reserved for future use\n}\n\n/**\n * OpenRouter provider routing preferences.\n * Controls which upstream providers OpenRouter routes requests to.\n * @see https://openrouter.ai/docs/provider-routing\n */\nexport interface OpenRouterRouting {\n\t/** List of provider slugs to exclusively use for this request (e.g., [\"amazon-bedrock\", \"anthropic\"]). */\n\tonly?: string[];\n\t/** List of provider slugs to try in order (e.g., [\"anthropic\", \"openai\"]). */\n\torder?: string[];\n}\n\n/**\n * Vercel AI Gateway routing preferences.\n * Controls which upstream providers the gateway routes requests to.\n * @see https://vercel.com/docs/ai-gateway/models-and-providers/provider-options\n */\nexport interface VercelGatewayRouting {\n\t/** List of provider slugs to exclusively use for this request (e.g., [\"bedrock\", \"anthropic\"]). */\n\tonly?: string[];\n\t/** List of provider slugs to try in order (e.g., [\"anthropic\", \"openai\"]). */\n\torder?: string[];\n}\n\n/**\n * Provider-agnostic capability declarations for a model.\n *\n * These fields allow models to self-declare supported features so that call\n * sites can read from metadata rather than pattern-matching on model IDs or\n * provider names. Add fields here as new cross-provider capabilities emerge.\n */\nexport interface ModelCapabilities {\n\t/** Whether the model supports xhigh thinking level. */\n\tsupportsXhigh?: boolean;\n\t/**\n\t * Whether tool call IDs must be included and normalised in tool results for\n\t * this model. Relevant for models deployed cross-provider (e.g. Claude or\n\t * GPT variants via Google APIs) where the host API imposes stricter ID rules.\n\t */\n\trequiresToolCallId?: boolean;\n\t/** Whether OpenAI-style service tiers (priority/flex) apply to this model. */\n\tsupportsServiceTier?: boolean;\n\t/**\n\t * Approximate characters per token for this model.\n\t * Used as a fallback when an accurate tokenizer is unavailable.\n\t * If omitted, the provider-level default is used.\n\t */\n\tcharsPerToken?: number;\n}\n\n// Model interface for the unified model system\nexport interface Model<TApi extends Api> {\n\tid: string;\n\tname: string;\n\tapi: TApi;\n\tprovider: Provider;\n\tbaseUrl: string;\n\treasoning: boolean;\n\tinput: (\"text\" | \"image\")[];\n\tcost: {\n\t\tinput: number; // $/million tokens\n\t\toutput: number; // $/million tokens\n\t\tcacheRead: number; // $/million tokens\n\t\tcacheWrite: number; // $/million tokens\n\t};\n\tcontextWindow: number;\n\tmaxTokens: number;\n\theaders?: Record<string, string>;\n\t/** Compatibility overrides for OpenAI-compatible APIs. If not set, auto-detected from baseUrl. */\n\tcompat?: TApi extends \"openai-completions\"\n\t\t? OpenAICompletionsCompat\n\t\t: TApi extends \"openai-responses\"\n\t\t\t? OpenAIResponsesCompat\n\t\t\t: never;\n\t/**\n\t * Provider-agnostic capability declarations for this model.\n\t * Read these fields instead of pattern-matching on model IDs or provider names.\n\t */\n\tcapabilities?: ModelCapabilities;\n}\n"]}
@@ -3,6 +3,9 @@
3
3
  * Always returns a valid object, even if the JSON is incomplete.
4
4
  *
5
5
  * Uses the native Rust streaming JSON parser for performance.
6
+ * Falls back to YAML bullet-list repair when the native parser
7
+ * returns an empty object from input that contains YAML-style
8
+ * bullet lists copied from template formatting (#2660).
6
9
  *
7
10
  * @param partialJson The partial JSON string from streaming
8
11
  * @returns Parsed object or empty object if parsing fails
@@ -1 +1 @@
1
- {"version":3,"file":"json-parse.d.ts","sourceRoot":"","sources":["../../src/utils/json-parse.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC,CAE9E"}
1
+ {"version":3,"file":"json-parse.d.ts","sourceRoot":"","sources":["../../src/utils/json-parse.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,GAAG,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,CAAC,CAyB9E"}
@@ -1,14 +1,37 @@
1
1
  import { parseStreamingJson as nativeParseStreamingJson } from "@gsd/native";
2
+ import { hasYamlBulletLists, repairToolJson } from "./repair-tool-json.js";
2
3
  /**
3
4
  * Attempts to parse potentially incomplete JSON during streaming.
4
5
  * Always returns a valid object, even if the JSON is incomplete.
5
6
  *
6
7
  * Uses the native Rust streaming JSON parser for performance.
8
+ * Falls back to YAML bullet-list repair when the native parser
9
+ * returns an empty object from input that contains YAML-style
10
+ * bullet lists copied from template formatting (#2660).
7
11
  *
8
12
  * @param partialJson The partial JSON string from streaming
9
13
  * @returns Parsed object or empty object if parsing fails
10
14
  */
11
15
  export function parseStreamingJson(partialJson) {
12
- return nativeParseStreamingJson(partialJson);
16
+ if (!partialJson || partialJson.trim() === "") {
17
+ return {};
18
+ }
19
+ // Fast path: try native streaming parser first
20
+ const result = nativeParseStreamingJson(partialJson);
21
+ // If the native parser returned a non-empty result, use it.
22
+ // Only attempt repair when the result is empty AND the input
23
+ // contains YAML bullet patterns (avoids unnecessary work).
24
+ if (result &&
25
+ typeof result === "object" &&
26
+ Object.keys(result).length === 0 &&
27
+ hasYamlBulletLists(partialJson)) {
28
+ try {
29
+ return JSON.parse(repairToolJson(partialJson));
30
+ }
31
+ catch {
32
+ // Repair failed — return the empty object from native parser
33
+ }
34
+ }
35
+ return result;
13
36
  }
14
37
  //# sourceMappingURL=json-parse.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"json-parse.js","sourceRoot":"","sources":["../../src/utils/json-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,IAAI,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAE7E;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAU,WAA+B;IAC1E,OAAO,wBAAwB,CAAI,WAAW,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import { parseStreamingJson as nativeParseStreamingJson } from \"@gsd/native\";\n\n/**\n * Attempts to parse potentially incomplete JSON during streaming.\n * Always returns a valid object, even if the JSON is incomplete.\n *\n * Uses the native Rust streaming JSON parser for performance.\n *\n * @param partialJson The partial JSON string from streaming\n * @returns Parsed object or empty object if parsing fails\n */\nexport function parseStreamingJson<T = any>(partialJson: string | undefined): T {\n\treturn nativeParseStreamingJson<T>(partialJson);\n}\n"]}
1
+ {"version":3,"file":"json-parse.js","sourceRoot":"","sources":["../../src/utils/json-parse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,IAAI,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE3E;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAAU,WAA+B;IAC1E,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC/C,OAAO,EAAO,CAAC;IAChB,CAAC;IAED,+CAA+C;IAC/C,MAAM,MAAM,GAAG,wBAAwB,CAAI,WAAW,CAAC,CAAC;IAExD,4DAA4D;IAC5D,6DAA6D;IAC7D,2DAA2D;IAC3D,IACC,MAAM;QACN,OAAO,MAAM,KAAK,QAAQ;QAC1B,MAAM,CAAC,IAAI,CAAC,MAAgB,CAAC,CAAC,MAAM,KAAK,CAAC;QAC1C,kBAAkB,CAAC,WAAW,CAAC,EAC9B,CAAC;QACF,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAM,CAAC;QACrD,CAAC;QAAC,MAAM,CAAC;YACR,6DAA6D;QAC9D,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import { parseStreamingJson as nativeParseStreamingJson } from \"@gsd/native\";\nimport { hasYamlBulletLists, repairToolJson } from \"./repair-tool-json.js\";\n\n/**\n * Attempts to parse potentially incomplete JSON during streaming.\n * Always returns a valid object, even if the JSON is incomplete.\n *\n * Uses the native Rust streaming JSON parser for performance.\n * Falls back to YAML bullet-list repair when the native parser\n * returns an empty object from input that contains YAML-style\n * bullet lists copied from template formatting (#2660).\n *\n * @param partialJson The partial JSON string from streaming\n * @returns Parsed object or empty object if parsing fails\n */\nexport function parseStreamingJson<T = any>(partialJson: string | undefined): T {\n\tif (!partialJson || partialJson.trim() === \"\") {\n\t\treturn {} as T;\n\t}\n\n\t// Fast path: try native streaming parser first\n\tconst result = nativeParseStreamingJson<T>(partialJson);\n\n\t// If the native parser returned a non-empty result, use it.\n\t// Only attempt repair when the result is empty AND the input\n\t// contains YAML bullet patterns (avoids unnecessary work).\n\tif (\n\t\tresult &&\n\t\ttypeof result === \"object\" &&\n\t\tObject.keys(result as object).length === 0 &&\n\t\thasYamlBulletLists(partialJson)\n\t) {\n\t\ttry {\n\t\t\treturn JSON.parse(repairToolJson(partialJson)) as T;\n\t\t} catch {\n\t\t\t// Repair failed — return the empty object from native parser\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Repair malformed JSON in LLM tool-call arguments.
3
+ *
4
+ * LLMs sometimes copy YAML template formatting into JSON tool arguments,
5
+ * producing patterns like:
6
+ *
7
+ * "keyDecisions": - Used Web Notification API...,
8
+ * "keyFiles": - src-tauri/src/lib.rs — Extended...
9
+ *
10
+ * instead of valid JSON arrays:
11
+ *
12
+ * "keyDecisions": ["Used Web Notification API..."],
13
+ * "keyFiles": ["src-tauri/src/lib.rs — Extended..."]
14
+ *
15
+ * This module detects and repairs such patterns before JSON.parse is called.
16
+ *
17
+ * @see https://github.com/gsd-build/gsd-2/issues/2660
18
+ */
19
+ /**
20
+ * Detect whether a JSON string contains YAML-style bullet-list values
21
+ * (i.e. `"key": - item` instead of `"key": ["item"]`).
22
+ */
23
+ export declare function hasYamlBulletLists(json: string): boolean;
24
+ /**
25
+ * Attempt to repair YAML-style bullet lists embedded in a JSON string.
26
+ *
27
+ * Converts patterns like:
28
+ * "keyDecisions": - Used Web Notification API..., "keyFiles": - file1
29
+ *
30
+ * Into:
31
+ * "keyDecisions": ["Used Web Notification API..."], "keyFiles": ["file1"]
32
+ *
33
+ * Returns the original string unchanged if no YAML patterns are detected
34
+ * or if the repair itself would produce invalid JSON.
35
+ */
36
+ export declare function repairToolJson(json: string): string;
37
+ //# sourceMappingURL=repair-tool-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repair-tool-json.d.ts","sourceRoot":"","sources":["../../src/utils/repair-tool-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAIxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA8CnD"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Repair malformed JSON in LLM tool-call arguments.
3
+ *
4
+ * LLMs sometimes copy YAML template formatting into JSON tool arguments,
5
+ * producing patterns like:
6
+ *
7
+ * "keyDecisions": - Used Web Notification API...,
8
+ * "keyFiles": - src-tauri/src/lib.rs — Extended...
9
+ *
10
+ * instead of valid JSON arrays:
11
+ *
12
+ * "keyDecisions": ["Used Web Notification API..."],
13
+ * "keyFiles": ["src-tauri/src/lib.rs — Extended..."]
14
+ *
15
+ * This module detects and repairs such patterns before JSON.parse is called.
16
+ *
17
+ * @see https://github.com/gsd-build/gsd-2/issues/2660
18
+ */
19
+ /**
20
+ * Detect whether a JSON string contains YAML-style bullet-list values
21
+ * (i.e. `"key": - item` instead of `"key": ["item"]`).
22
+ */
23
+ export function hasYamlBulletLists(json) {
24
+ // Match: "key": followed by whitespace then a dash-space pattern (YAML bullet)
25
+ // The negative lookahead excludes negative numbers (e.g. "key": -1)
26
+ return /"\s*:\s*-\s+(?!\d)/.test(json);
27
+ }
28
+ /**
29
+ * Attempt to repair YAML-style bullet lists embedded in a JSON string.
30
+ *
31
+ * Converts patterns like:
32
+ * "keyDecisions": - Used Web Notification API..., "keyFiles": - file1
33
+ *
34
+ * Into:
35
+ * "keyDecisions": ["Used Web Notification API..."], "keyFiles": ["file1"]
36
+ *
37
+ * Returns the original string unchanged if no YAML patterns are detected
38
+ * or if the repair itself would produce invalid JSON.
39
+ */
40
+ export function repairToolJson(json) {
41
+ if (!hasYamlBulletLists(json)) {
42
+ return json;
43
+ }
44
+ // Strategy: find each `"key": - item1\n - item2\n - item3` region and
45
+ // wrap items in a JSON array.
46
+ //
47
+ // We work on the raw string because the JSON is not parseable yet.
48
+ // The pattern we target:
49
+ // "someKey":\s*- item text (possibly multiline)
50
+ // optionally followed by more `- item` lines
51
+ // terminated by the next `"key":` or `}` or end of string.
52
+ let repaired = json;
53
+ // Match a key followed by YAML-style bullet list.
54
+ // Capture: (1) the key portion including colon, (2) the bullet-list body,
55
+ // (3) the separator (comma or empty) before the next key/bracket.
56
+ // The bullet list body ends at the next `"key":` or `}` or `]` or end of string.
57
+ const keyBulletPattern = /("(?:[^"\\]|\\.)*"\s*:\s*)(- .+?)(,?\s*)(?="(?:[^"\\]|\\.)*"\s*:|[}\]]|$)/gs;
58
+ repaired = repaired.replace(keyBulletPattern, (_match, keyPart, bulletBody, separator) => {
59
+ // Split the bullet body into individual items on `- ` boundaries.
60
+ // Items may contain embedded newlines for multi-line values.
61
+ const items = bulletBody
62
+ .split(/\n?\s*- /)
63
+ .filter((s) => s.trim().length > 0)
64
+ .map((s) => s.replace(/,\s*$/, "").trim());
65
+ // JSON-encode each item as a string, then wrap in an array.
66
+ const jsonArray = "[" + items.map((item) => JSON.stringify(item)).join(", ") + "]";
67
+ // Re-emit the separator (comma) so the next key is properly delimited
68
+ const sep = separator.trim() ? separator : (/^\s*"/.test(separator + "x") ? ", " : "");
69
+ return keyPart + jsonArray + sep;
70
+ });
71
+ // Strip trailing commas before } or ] (common in repaired JSON)
72
+ repaired = repaired.replace(/,(\s*[}\]])/g, "$1");
73
+ return repaired;
74
+ }
75
+ //# sourceMappingURL=repair-tool-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repair-tool-json.js","sourceRoot":"","sources":["../../src/utils/repair-tool-json.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC9C,+EAA+E;IAC/E,oEAAoE;IACpE,OAAO,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IAC1C,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,wEAAwE;IACxE,8BAA8B;IAC9B,EAAE;IACF,mEAAmE;IACnE,yBAAyB;IACzB,kDAAkD;IAClD,+CAA+C;IAC/C,6DAA6D;IAE7D,IAAI,QAAQ,GAAG,IAAI,CAAC;IAEpB,kDAAkD;IAClD,0EAA0E;IAC1E,kEAAkE;IAClE,iFAAiF;IACjF,MAAM,gBAAgB,GACrB,6EAA6E,CAAC;IAE/E,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAC1B,gBAAgB,EAChB,CAAC,MAAM,EAAE,OAAe,EAAE,UAAkB,EAAE,SAAiB,EAAE,EAAE;QAClE,kEAAkE;QAClE,6DAA6D;QAC7D,MAAM,KAAK,GAAG,UAAU;aACtB,KAAK,CAAC,UAAU,CAAC;aACjB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;aAClC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAE5C,4DAA4D;QAC5D,MAAM,SAAS,GAAG,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QAEnF,sEAAsE;QACtE,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvF,OAAO,OAAO,GAAG,SAAS,GAAG,GAAG,CAAC;IAClC,CAAC,CACD,CAAC;IAEF,gEAAgE;IAChE,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAElD,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["/**\n * Repair malformed JSON in LLM tool-call arguments.\n *\n * LLMs sometimes copy YAML template formatting into JSON tool arguments,\n * producing patterns like:\n *\n * \"keyDecisions\": - Used Web Notification API...,\n * \"keyFiles\": - src-tauri/src/lib.rs — Extended...\n *\n * instead of valid JSON arrays:\n *\n * \"keyDecisions\": [\"Used Web Notification API...\"],\n * \"keyFiles\": [\"src-tauri/src/lib.rs — Extended...\"]\n *\n * This module detects and repairs such patterns before JSON.parse is called.\n *\n * @see https://github.com/gsd-build/gsd-2/issues/2660\n */\n\n/**\n * Detect whether a JSON string contains YAML-style bullet-list values\n * (i.e. `\"key\": - item` instead of `\"key\": [\"item\"]`).\n */\nexport function hasYamlBulletLists(json: string): boolean {\n\t// Match: \"key\": followed by whitespace then a dash-space pattern (YAML bullet)\n\t// The negative lookahead excludes negative numbers (e.g. \"key\": -1)\n\treturn /\"\\s*:\\s*-\\s+(?!\\d)/.test(json);\n}\n\n/**\n * Attempt to repair YAML-style bullet lists embedded in a JSON string.\n *\n * Converts patterns like:\n * \"keyDecisions\": - Used Web Notification API..., \"keyFiles\": - file1\n *\n * Into:\n * \"keyDecisions\": [\"Used Web Notification API...\"], \"keyFiles\": [\"file1\"]\n *\n * Returns the original string unchanged if no YAML patterns are detected\n * or if the repair itself would produce invalid JSON.\n */\nexport function repairToolJson(json: string): string {\n\tif (!hasYamlBulletLists(json)) {\n\t\treturn json;\n\t}\n\n\t// Strategy: find each `\"key\": - item1\\n - item2\\n - item3` region and\n\t// wrap items in a JSON array.\n\t//\n\t// We work on the raw string because the JSON is not parseable yet.\n\t// The pattern we target:\n\t// \"someKey\":\\s*- item text (possibly multiline)\n\t// optionally followed by more `- item` lines\n\t// terminated by the next `\"key\":` or `}` or end of string.\n\n\tlet repaired = json;\n\n\t// Match a key followed by YAML-style bullet list.\n\t// Capture: (1) the key portion including colon, (2) the bullet-list body,\n\t// (3) the separator (comma or empty) before the next key/bracket.\n\t// The bullet list body ends at the next `\"key\":` or `}` or `]` or end of string.\n\tconst keyBulletPattern =\n\t\t/(\"(?:[^\"\\\\]|\\\\.)*\"\\s*:\\s*)(- .+?)(,?\\s*)(?=\"(?:[^\"\\\\]|\\\\.)*\"\\s*:|[}\\]]|$)/gs;\n\n\trepaired = repaired.replace(\n\t\tkeyBulletPattern,\n\t\t(_match, keyPart: string, bulletBody: string, separator: string) => {\n\t\t\t// Split the bullet body into individual items on `- ` boundaries.\n\t\t\t// Items may contain embedded newlines for multi-line values.\n\t\t\tconst items = bulletBody\n\t\t\t\t.split(/\\n?\\s*- /)\n\t\t\t\t.filter((s) => s.trim().length > 0)\n\t\t\t\t.map((s) => s.replace(/,\\s*$/, \"\").trim());\n\n\t\t\t// JSON-encode each item as a string, then wrap in an array.\n\t\t\tconst jsonArray = \"[\" + items.map((item) => JSON.stringify(item)).join(\", \") + \"]\";\n\n\t\t\t// Re-emit the separator (comma) so the next key is properly delimited\n\t\t\tconst sep = separator.trim() ? separator : (/^\\s*\"/.test(separator + \"x\") ? \", \" : \"\");\n\t\t\treturn keyPart + jsonArray + sep;\n\t\t},\n\t);\n\n\t// Strip trailing commas before } or ] (common in repaired JSON)\n\trepaired = repaired.replace(/,(\\s*[}\\]])/g, \"$1\");\n\n\treturn repaired;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=repair-tool-json.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repair-tool-json.test.d.ts","sourceRoot":"","sources":["../../../src/utils/tests/repair-tool-json.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,73 @@
1
+ import { describe, test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { repairToolJson, hasYamlBulletLists } from "../repair-tool-json.js";
4
+ describe("repairToolJson — YAML bullet list repair (#2660)", () => {
5
+ // ── Detection ──────────────────────────────────────────────────────────
6
+ test("hasYamlBulletLists detects YAML-style bullets", () => {
7
+ assert.equal(hasYamlBulletLists('"keyDecisions": - Used Web Notification API'), true);
8
+ });
9
+ test("hasYamlBulletLists ignores negative numbers", () => {
10
+ assert.equal(hasYamlBulletLists('"offset": -1'), false, "negative number should not be detected as YAML bullet");
11
+ });
12
+ test("hasYamlBulletLists returns false for valid JSON", () => {
13
+ assert.equal(hasYamlBulletLists('{"keyDecisions": ["item1", "item2"]}'), false);
14
+ });
15
+ // ── Single bullet item ────────────────────────────────────────────────
16
+ test("repairs single YAML bullet to JSON array", () => {
17
+ const malformed = '{"keyDecisions": - Used Web Notification API}';
18
+ const repaired = repairToolJson(malformed);
19
+ const parsed = JSON.parse(repaired);
20
+ assert.deepEqual(parsed.keyDecisions, ["Used Web Notification API"]);
21
+ });
22
+ // ── Multiple bullet items (newline-separated) ─────────────────────────
23
+ test("repairs multiple YAML bullets separated by newlines", () => {
24
+ const malformed = '{"keyDecisions": - Used Web Notification API\n - Chose Tauri over Electron\n - Adopted SQLite for storage, "title": "M005"}';
25
+ const repaired = repairToolJson(malformed);
26
+ const parsed = JSON.parse(repaired);
27
+ assert.deepEqual(parsed.keyDecisions, [
28
+ "Used Web Notification API",
29
+ "Chose Tauri over Electron",
30
+ "Adopted SQLite for storage",
31
+ ]);
32
+ assert.equal(parsed.title, "M005");
33
+ });
34
+ // ── Multiple fields with YAML bullets ─────────────────────────────────
35
+ test("repairs multiple fields each with YAML bullet lists", () => {
36
+ const malformed = '{"keyDecisions": - decision one\n - decision two, "keyFiles": - src/lib.rs — Extended menu\n - src/main.ts — Entry point, "title": "done"}';
37
+ const repaired = repairToolJson(malformed);
38
+ const parsed = JSON.parse(repaired);
39
+ assert.deepEqual(parsed.keyDecisions, ["decision one", "decision two"]);
40
+ assert.deepEqual(parsed.keyFiles, [
41
+ "src/lib.rs \u2014 Extended menu",
42
+ "src/main.ts \u2014 Entry point",
43
+ ]);
44
+ assert.equal(parsed.title, "done");
45
+ });
46
+ // ── Exact reproduction from issue #2660 ───────────────────────────────
47
+ test("repairs the exact malformed JSON from issue #2660", () => {
48
+ const malformed = `{"milestoneId": "M005", "title": "Native Desktop Polish", "oneLiner": "summary", "narrative": "details", "successCriteriaResults": "all pass", "definitionOfDoneResults": "all done", "requirementOutcomes": "met", "keyDecisions": - Used Web Notification API (new window.Notification()) instead of Tauri sendNotification wrapper, "keyFiles": - src-tauri/src/lib.rs \u2014 Extended menu builder with notification toggle, "lessonsLearned": - Always test notification permissions before sending, "followUps": "none", "deviations": "none", "verificationPassed": true}`;
49
+ const repaired = repairToolJson(malformed);
50
+ const parsed = JSON.parse(repaired);
51
+ assert.equal(parsed.milestoneId, "M005");
52
+ assert.equal(parsed.title, "Native Desktop Polish");
53
+ assert.ok(Array.isArray(parsed.keyDecisions), "keyDecisions should be an array");
54
+ assert.ok(parsed.keyDecisions[0].includes("Web Notification API"));
55
+ assert.ok(Array.isArray(parsed.keyFiles), "keyFiles should be an array");
56
+ assert.ok(parsed.keyFiles[0].includes("src-tauri/src/lib.rs"));
57
+ assert.ok(Array.isArray(parsed.lessonsLearned), "lessonsLearned should be an array");
58
+ assert.equal(parsed.verificationPassed, true);
59
+ });
60
+ // ── Passthrough for valid JSON ────────────────────────────────────────
61
+ test("returns valid JSON unchanged", () => {
62
+ const valid = '{"keyDecisions": ["item1", "item2"], "count": -5}';
63
+ const result = repairToolJson(valid);
64
+ assert.equal(result, valid, "valid JSON should be returned unchanged");
65
+ });
66
+ // ── Negative numbers are preserved ────────────────────────────────────
67
+ test("does not mangle negative numbers", () => {
68
+ const valid = '{"offset": -1, "limit": -100}';
69
+ const result = repairToolJson(valid);
70
+ assert.equal(result, valid);
71
+ });
72
+ });
73
+ //# sourceMappingURL=repair-tool-json.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repair-tool-json.test.js","sourceRoot":"","sources":["../../../src/utils/tests/repair-tool-json.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5E,QAAQ,CAAC,kDAAkD,EAAE,GAAG,EAAE;IACjE,0EAA0E;IAE1E,IAAI,CAAC,+CAA+C,EAAE,GAAG,EAAE;QAC1D,MAAM,CAAC,KAAK,CACX,kBAAkB,CAAC,6CAA6C,CAAC,EACjE,IAAI,CACJ,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,KAAK,CACX,kBAAkB,CAAC,cAAc,CAAC,EAClC,KAAK,EACL,uDAAuD,CACvD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE;QAC5D,MAAM,CAAC,KAAK,CACX,kBAAkB,CAAC,sCAAsC,CAAC,EAC1D,KAAK,CACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,yEAAyE;IAEzE,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACrD,MAAM,SAAS,GAAG,+CAA+C,CAAC;QAClE,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,2BAA2B,CAAC,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,yEAAyE;IAEzE,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAChE,MAAM,SAAS,GACd,+HAA+H,CAAC;QACjI,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE;YACrC,2BAA2B;YAC3B,2BAA2B;YAC3B,4BAA4B;SAC5B,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,yEAAyE;IAEzE,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAChE,MAAM,SAAS,GACd,8IAA8I,CAAC;QAChJ,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACpC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;QACxE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,EAAE;YACjC,iCAAiC;YACjC,gCAAgC;SAChC,CAAC,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,yEAAyE;IAEzE,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC9D,MAAM,SAAS,GAAG,kjBAAkjB,CAAC;QAErkB,MAAM,QAAQ,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAEpC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACzC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;QACpD,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,iCAAiC,CAAC,CAAC;QACjF,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC;QACnE,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,6BAA6B,CAAC,CAAC;QACzE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC/D,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,mCAAmC,CAAC,CAAC;QACrF,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,yEAAyE;IAEzE,IAAI,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACzC,MAAM,KAAK,GAAG,mDAAmD,CAAC;QAClE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,yCAAyC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,yEAAyE;IAEzE,IAAI,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC7C,MAAM,KAAK,GAAG,+BAA+B,CAAC;QAC9C,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { describe, test } from \"node:test\";\nimport assert from \"node:assert/strict\";\nimport { repairToolJson, hasYamlBulletLists } from \"../repair-tool-json.js\";\n\ndescribe(\"repairToolJson — YAML bullet list repair (#2660)\", () => {\n\t// ── Detection ──────────────────────────────────────────────────────────\n\n\ttest(\"hasYamlBulletLists detects YAML-style bullets\", () => {\n\t\tassert.equal(\n\t\t\thasYamlBulletLists('\"keyDecisions\": - Used Web Notification API'),\n\t\t\ttrue,\n\t\t);\n\t});\n\n\ttest(\"hasYamlBulletLists ignores negative numbers\", () => {\n\t\tassert.equal(\n\t\t\thasYamlBulletLists('\"offset\": -1'),\n\t\t\tfalse,\n\t\t\t\"negative number should not be detected as YAML bullet\",\n\t\t);\n\t});\n\n\ttest(\"hasYamlBulletLists returns false for valid JSON\", () => {\n\t\tassert.equal(\n\t\t\thasYamlBulletLists('{\"keyDecisions\": [\"item1\", \"item2\"]}'),\n\t\t\tfalse,\n\t\t);\n\t});\n\n\t// ── Single bullet item ────────────────────────────────────────────────\n\n\ttest(\"repairs single YAML bullet to JSON array\", () => {\n\t\tconst malformed = '{\"keyDecisions\": - Used Web Notification API}';\n\t\tconst repaired = repairToolJson(malformed);\n\t\tconst parsed = JSON.parse(repaired);\n\t\tassert.deepEqual(parsed.keyDecisions, [\"Used Web Notification API\"]);\n\t});\n\n\t// ── Multiple bullet items (newline-separated) ─────────────────────────\n\n\ttest(\"repairs multiple YAML bullets separated by newlines\", () => {\n\t\tconst malformed =\n\t\t\t'{\"keyDecisions\": - Used Web Notification API\\n - Chose Tauri over Electron\\n - Adopted SQLite for storage, \"title\": \"M005\"}';\n\t\tconst repaired = repairToolJson(malformed);\n\t\tconst parsed = JSON.parse(repaired);\n\t\tassert.deepEqual(parsed.keyDecisions, [\n\t\t\t\"Used Web Notification API\",\n\t\t\t\"Chose Tauri over Electron\",\n\t\t\t\"Adopted SQLite for storage\",\n\t\t]);\n\t\tassert.equal(parsed.title, \"M005\");\n\t});\n\n\t// ── Multiple fields with YAML bullets ─────────────────────────────────\n\n\ttest(\"repairs multiple fields each with YAML bullet lists\", () => {\n\t\tconst malformed =\n\t\t\t'{\"keyDecisions\": - decision one\\n - decision two, \"keyFiles\": - src/lib.rs — Extended menu\\n - src/main.ts — Entry point, \"title\": \"done\"}';\n\t\tconst repaired = repairToolJson(malformed);\n\t\tconst parsed = JSON.parse(repaired);\n\t\tassert.deepEqual(parsed.keyDecisions, [\"decision one\", \"decision two\"]);\n\t\tassert.deepEqual(parsed.keyFiles, [\n\t\t\t\"src/lib.rs \\u2014 Extended menu\",\n\t\t\t\"src/main.ts \\u2014 Entry point\",\n\t\t]);\n\t\tassert.equal(parsed.title, \"done\");\n\t});\n\n\t// ── Exact reproduction from issue #2660 ───────────────────────────────\n\n\ttest(\"repairs the exact malformed JSON from issue #2660\", () => {\n\t\tconst malformed = `{\"milestoneId\": \"M005\", \"title\": \"Native Desktop Polish\", \"oneLiner\": \"summary\", \"narrative\": \"details\", \"successCriteriaResults\": \"all pass\", \"definitionOfDoneResults\": \"all done\", \"requirementOutcomes\": \"met\", \"keyDecisions\": - Used Web Notification API (new window.Notification()) instead of Tauri sendNotification wrapper, \"keyFiles\": - src-tauri/src/lib.rs \\u2014 Extended menu builder with notification toggle, \"lessonsLearned\": - Always test notification permissions before sending, \"followUps\": \"none\", \"deviations\": \"none\", \"verificationPassed\": true}`;\n\n\t\tconst repaired = repairToolJson(malformed);\n\t\tconst parsed = JSON.parse(repaired);\n\n\t\tassert.equal(parsed.milestoneId, \"M005\");\n\t\tassert.equal(parsed.title, \"Native Desktop Polish\");\n\t\tassert.ok(Array.isArray(parsed.keyDecisions), \"keyDecisions should be an array\");\n\t\tassert.ok(parsed.keyDecisions[0].includes(\"Web Notification API\"));\n\t\tassert.ok(Array.isArray(parsed.keyFiles), \"keyFiles should be an array\");\n\t\tassert.ok(parsed.keyFiles[0].includes(\"src-tauri/src/lib.rs\"));\n\t\tassert.ok(Array.isArray(parsed.lessonsLearned), \"lessonsLearned should be an array\");\n\t\tassert.equal(parsed.verificationPassed, true);\n\t});\n\n\t// ── Passthrough for valid JSON ────────────────────────────────────────\n\n\ttest(\"returns valid JSON unchanged\", () => {\n\t\tconst valid = '{\"keyDecisions\": [\"item1\", \"item2\"], \"count\": -5}';\n\t\tconst result = repairToolJson(valid);\n\t\tassert.equal(result, valid, \"valid JSON should be returned unchanged\");\n\t});\n\n\t// ── Negative numbers are preserved ────────────────────────────────────\n\n\ttest(\"does not mangle negative numbers\", () => {\n\t\tconst valid = '{\"offset\": -1, \"limit\": -100}';\n\t\tconst result = repairToolJson(valid);\n\t\tassert.equal(result, valid);\n\t});\n});\n"]}
@@ -137,6 +137,7 @@ export function getEnvApiKey(provider: any): string | undefined {
137
137
  "opencode-go": "OPENCODE_API_KEY",
138
138
  "kimi-coding": "KIMI_API_KEY",
139
139
  "alibaba-coding-plan": "ALIBABA_API_KEY",
140
+ ollama: "OLLAMA_API_KEY",
140
141
  "ollama-cloud": "OLLAMA_API_KEY",
141
142
  "custom-openai": "CUSTOM_OPENAI_API_KEY",
142
143
  };
@@ -27,4 +27,5 @@ export type {
27
27
  } from "./utils/oauth/types.js";
28
28
  export * from "./utils/overflow.js";
29
29
  export * from "./utils/typebox-helpers.js";
30
+ export * from "./utils/repair-tool-json.js";
30
31
  export * from "./utils/validation.js";
@@ -0,0 +1,29 @@
1
+ import { describe, it } from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { mapStopReason } from "./anthropic-shared.js";
4
+
5
+ describe("mapStopReason", () => {
6
+ it("maps end_turn to stop", () => {
7
+ assert.equal(mapStopReason("end_turn"), "stop");
8
+ });
9
+
10
+ it("maps max_tokens to length", () => {
11
+ assert.equal(mapStopReason("max_tokens"), "length");
12
+ });
13
+
14
+ it("maps tool_use to toolUse", () => {
15
+ assert.equal(mapStopReason("tool_use"), "toolUse");
16
+ });
17
+
18
+ it("maps pause_turn to pauseTurn (not stop)", () => {
19
+ // pause_turn means the server paused a long-running turn (e.g. native
20
+ // web search hit its iteration limit). Mapping it to "stop" causes the
21
+ // agent loop to exit, leaving an incomplete server_tool_use block in
22
+ // history which triggers a 400 on the next request.
23
+ assert.equal(mapStopReason("pause_turn"), "pauseTurn");
24
+ });
25
+
26
+ it("throws on unknown stop reason", () => {
27
+ assert.throws(() => mapStopReason("bogus"), /Unhandled stop reason/);
28
+ });
29
+ });
@@ -31,6 +31,7 @@ import type {
31
31
  export type AnthropicApi = "anthropic-messages" | "anthropic-vertex";
32
32
  import type { AssistantMessageEventStream } from "../utils/event-stream.js";
33
33
  import { parseStreamingJson } from "../utils/json-parse.js";
34
+ import { repairToolJson } from "../utils/repair-tool-json.js";
34
35
  import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
35
36
  import { transformMessages } from "./transform-messages.js";
36
37
 
@@ -502,7 +503,7 @@ export function mapStopReason(reason: string): StopReason {
502
503
  case "refusal":
503
504
  return "error";
504
505
  case "pause_turn":
505
- return "stop";
506
+ return "pauseTurn";
506
507
  case "stop_sequence":
507
508
  return "stop";
508
509
  case "sensitive":
@@ -696,7 +697,21 @@ export function processAnthropicStream(
696
697
  partial: output,
697
698
  });
698
699
  } else if (block.type === "toolCall") {
699
- block.arguments = parseStreamingJson(block.partialJson);
700
+ // Try strict parse first; if it fails, attempt YAML bullet
701
+ // repair (#2660) before falling back to the lenient streaming
702
+ // parser which silently swallows errors.
703
+ const raw = block.partialJson ?? "";
704
+ let parsed: Record<string, any> | undefined;
705
+ try {
706
+ parsed = JSON.parse(raw);
707
+ } catch {
708
+ try {
709
+ parsed = JSON.parse(repairToolJson(raw));
710
+ } catch {
711
+ // Fall through to streaming parser
712
+ }
713
+ }
714
+ block.arguments = parsed ?? parseStreamingJson(block.partialJson);
700
715
  delete (block as any).partialJson;
701
716
  stream.push({
702
717
  type: "toolcall_end",
@@ -43,6 +43,7 @@ export type KnownProvider =
43
43
  | "opencode-go"
44
44
  | "kimi-coding"
45
45
  | "alibaba-coding-plan"
46
+ | "ollama"
46
47
  | "ollama-cloud";
47
48
  export type Provider = KnownProvider | string;
48
49
 
@@ -192,7 +193,7 @@ export interface Usage {
192
193
  };
193
194
  }
194
195
 
195
- export type StopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
196
+ export type StopReason = "stop" | "length" | "toolUse" | "pauseTurn" | "error" | "aborted";
196
197
 
197
198
  export interface UserMessage {
198
199
  role: "user";
@@ -253,7 +254,7 @@ export type AssistantMessageEvent =
253
254
  | { type: "toolcall_end"; contentIndex: number; toolCall: ToolCall; partial: AssistantMessage; malformedArguments?: boolean }
254
255
  | { type: "server_tool_use"; contentIndex: number; partial: AssistantMessage }
255
256
  | { type: "web_search_result"; contentIndex: number; partial: AssistantMessage }
256
- | { type: "done"; reason: Extract<StopReason, "stop" | "length" | "toolUse">; message: AssistantMessage }
257
+ | { type: "done"; reason: Extract<StopReason, "stop" | "length" | "toolUse" | "pauseTurn">; message: AssistantMessage }
257
258
  | { type: "error"; reason: Extract<StopReason, "aborted" | "error">; error: AssistantMessage };
258
259
 
259
260
  /**
@@ -1,14 +1,41 @@
1
1
  import { parseStreamingJson as nativeParseStreamingJson } from "@gsd/native";
2
+ import { hasYamlBulletLists, repairToolJson } from "./repair-tool-json.js";
2
3
 
3
4
  /**
4
5
  * Attempts to parse potentially incomplete JSON during streaming.
5
6
  * Always returns a valid object, even if the JSON is incomplete.
6
7
  *
7
8
  * Uses the native Rust streaming JSON parser for performance.
9
+ * Falls back to YAML bullet-list repair when the native parser
10
+ * returns an empty object from input that contains YAML-style
11
+ * bullet lists copied from template formatting (#2660).
8
12
  *
9
13
  * @param partialJson The partial JSON string from streaming
10
14
  * @returns Parsed object or empty object if parsing fails
11
15
  */
12
16
  export function parseStreamingJson<T = any>(partialJson: string | undefined): T {
13
- return nativeParseStreamingJson<T>(partialJson);
17
+ if (!partialJson || partialJson.trim() === "") {
18
+ return {} as T;
19
+ }
20
+
21
+ // Fast path: try native streaming parser first
22
+ const result = nativeParseStreamingJson<T>(partialJson);
23
+
24
+ // If the native parser returned a non-empty result, use it.
25
+ // Only attempt repair when the result is empty AND the input
26
+ // contains YAML bullet patterns (avoids unnecessary work).
27
+ if (
28
+ result &&
29
+ typeof result === "object" &&
30
+ Object.keys(result as object).length === 0 &&
31
+ hasYamlBulletLists(partialJson)
32
+ ) {
33
+ try {
34
+ return JSON.parse(repairToolJson(partialJson)) as T;
35
+ } catch {
36
+ // Repair failed — return the empty object from native parser
37
+ }
38
+ }
39
+
40
+ return result;
14
41
  }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Repair malformed JSON in LLM tool-call arguments.
3
+ *
4
+ * LLMs sometimes copy YAML template formatting into JSON tool arguments,
5
+ * producing patterns like:
6
+ *
7
+ * "keyDecisions": - Used Web Notification API...,
8
+ * "keyFiles": - src-tauri/src/lib.rs — Extended...
9
+ *
10
+ * instead of valid JSON arrays:
11
+ *
12
+ * "keyDecisions": ["Used Web Notification API..."],
13
+ * "keyFiles": ["src-tauri/src/lib.rs — Extended..."]
14
+ *
15
+ * This module detects and repairs such patterns before JSON.parse is called.
16
+ *
17
+ * @see https://github.com/gsd-build/gsd-2/issues/2660
18
+ */
19
+
20
+ /**
21
+ * Detect whether a JSON string contains YAML-style bullet-list values
22
+ * (i.e. `"key": - item` instead of `"key": ["item"]`).
23
+ */
24
+ export function hasYamlBulletLists(json: string): boolean {
25
+ // Match: "key": followed by whitespace then a dash-space pattern (YAML bullet)
26
+ // The negative lookahead excludes negative numbers (e.g. "key": -1)
27
+ return /"\s*:\s*-\s+(?!\d)/.test(json);
28
+ }
29
+
30
+ /**
31
+ * Attempt to repair YAML-style bullet lists embedded in a JSON string.
32
+ *
33
+ * Converts patterns like:
34
+ * "keyDecisions": - Used Web Notification API..., "keyFiles": - file1
35
+ *
36
+ * Into:
37
+ * "keyDecisions": ["Used Web Notification API..."], "keyFiles": ["file1"]
38
+ *
39
+ * Returns the original string unchanged if no YAML patterns are detected
40
+ * or if the repair itself would produce invalid JSON.
41
+ */
42
+ export function repairToolJson(json: string): string {
43
+ if (!hasYamlBulletLists(json)) {
44
+ return json;
45
+ }
46
+
47
+ // Strategy: find each `"key": - item1\n - item2\n - item3` region and
48
+ // wrap items in a JSON array.
49
+ //
50
+ // We work on the raw string because the JSON is not parseable yet.
51
+ // The pattern we target:
52
+ // "someKey":\s*- item text (possibly multiline)
53
+ // optionally followed by more `- item` lines
54
+ // terminated by the next `"key":` or `}` or end of string.
55
+
56
+ let repaired = json;
57
+
58
+ // Match a key followed by YAML-style bullet list.
59
+ // Capture: (1) the key portion including colon, (2) the bullet-list body,
60
+ // (3) the separator (comma or empty) before the next key/bracket.
61
+ // The bullet list body ends at the next `"key":` or `}` or `]` or end of string.
62
+ const keyBulletPattern =
63
+ /("(?:[^"\\]|\\.)*"\s*:\s*)(- .+?)(,?\s*)(?="(?:[^"\\]|\\.)*"\s*:|[}\]]|$)/gs;
64
+
65
+ repaired = repaired.replace(
66
+ keyBulletPattern,
67
+ (_match, keyPart: string, bulletBody: string, separator: string) => {
68
+ // Split the bullet body into individual items on `- ` boundaries.
69
+ // Items may contain embedded newlines for multi-line values.
70
+ const items = bulletBody
71
+ .split(/\n?\s*- /)
72
+ .filter((s) => s.trim().length > 0)
73
+ .map((s) => s.replace(/,\s*$/, "").trim());
74
+
75
+ // JSON-encode each item as a string, then wrap in an array.
76
+ const jsonArray = "[" + items.map((item) => JSON.stringify(item)).join(", ") + "]";
77
+
78
+ // Re-emit the separator (comma) so the next key is properly delimited
79
+ const sep = separator.trim() ? separator : (/^\s*"/.test(separator + "x") ? ", " : "");
80
+ return keyPart + jsonArray + sep;
81
+ },
82
+ );
83
+
84
+ // Strip trailing commas before } or ] (common in repaired JSON)
85
+ repaired = repaired.replace(/,(\s*[}\]])/g, "$1");
86
+
87
+ return repaired;
88
+ }