gsd-pi 2.76.0 → 2.77.0-dev.538325aea

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 (1182) hide show
  1. package/README.md +32 -30
  2. package/dist/claude-cli-check.js +32 -3
  3. package/dist/cli.js +13 -21
  4. package/dist/extension-registry.js +1 -1
  5. package/dist/headless-ui.d.ts +1 -1
  6. package/dist/headless.js +2 -4
  7. package/dist/loader.js +0 -1
  8. package/dist/mcp-server.d.ts +7 -0
  9. package/dist/mcp-server.js +35 -1
  10. package/dist/onboarding.js +50 -5
  11. package/dist/provider-migrations.d.ts +2 -2
  12. package/dist/provider-migrations.js +2 -1
  13. package/dist/remote-questions-config.js +1 -1
  14. package/dist/resource-loader.d.ts +1 -1
  15. package/dist/resource-loader.js +2 -8
  16. package/dist/resources/agents/researcher.md +1 -1
  17. package/dist/resources/extensions/async-jobs/async-bash-tool.js +1 -1
  18. package/dist/resources/extensions/aws-auth/index.js +2 -1
  19. package/dist/resources/extensions/bg-shell/bg-shell-lifecycle.js +6 -9
  20. package/dist/resources/extensions/bg-shell/process-manager.js +2 -1
  21. package/dist/resources/extensions/browser-tools/index.js +0 -1
  22. package/dist/resources/extensions/claude-code-cli/index.js +1 -1
  23. package/dist/resources/extensions/claude-code-cli/partial-builder.js +106 -17
  24. package/dist/resources/extensions/claude-code-cli/readiness.js +31 -8
  25. package/dist/resources/extensions/claude-code-cli/stream-adapter.js +94 -27
  26. package/dist/resources/extensions/gsd/auto/loop.js +9 -0
  27. package/dist/resources/extensions/gsd/auto/phases.js +104 -11
  28. package/dist/resources/extensions/gsd/auto/run-unit.js +38 -2
  29. package/dist/resources/extensions/gsd/auto/session.js +22 -1
  30. package/dist/resources/extensions/gsd/auto-dispatch.js +56 -17
  31. package/dist/resources/extensions/gsd/auto-model-selection.js +53 -16
  32. package/dist/resources/extensions/gsd/auto-post-unit.js +59 -2
  33. package/dist/resources/extensions/gsd/auto-prompts.js +14 -0
  34. package/dist/resources/extensions/gsd/auto-recovery.js +69 -1
  35. package/dist/resources/extensions/gsd/auto-start.js +74 -59
  36. package/dist/resources/extensions/gsd/auto-verification.js +33 -0
  37. package/dist/resources/extensions/gsd/auto-worktree.js +51 -53
  38. package/dist/resources/extensions/gsd/auto.js +70 -28
  39. package/dist/resources/extensions/gsd/blocked-models.js +68 -0
  40. package/dist/resources/extensions/gsd/bootstrap/agent-end-recovery.js +93 -1
  41. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +39 -9
  42. package/dist/resources/extensions/gsd/bootstrap/exec-tools.js +93 -0
  43. package/dist/resources/extensions/gsd/bootstrap/memory-tools.js +3 -0
  44. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +12 -0
  45. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +52 -6
  46. package/dist/resources/extensions/gsd/bootstrap/system-context.js +84 -23
  47. package/dist/resources/extensions/gsd/bootstrap/write-gate.js +34 -2
  48. package/dist/resources/extensions/gsd/clean-root-preflight.js +93 -0
  49. package/dist/resources/extensions/gsd/commands-extract-learnings.js +54 -89
  50. package/dist/resources/extensions/gsd/commands-prefs-wizard.js +968 -23
  51. package/dist/resources/extensions/gsd/compaction-snapshot.js +121 -0
  52. package/dist/resources/extensions/gsd/complexity-classifier.js +5 -3
  53. package/dist/resources/extensions/gsd/db-writer.js +88 -16
  54. package/dist/resources/extensions/gsd/dispatch-guard.js +44 -3
  55. package/dist/resources/extensions/gsd/doctor-git-checks.js +23 -29
  56. package/dist/resources/extensions/gsd/doctor-providers.js +51 -5
  57. package/dist/resources/extensions/gsd/ecosystem/gsd-extension-api.js +1 -0
  58. package/dist/resources/extensions/gsd/error-classifier.js +31 -3
  59. package/dist/resources/extensions/gsd/exec-history.js +120 -0
  60. package/dist/resources/extensions/gsd/exec-sandbox.js +258 -0
  61. package/dist/resources/extensions/gsd/gitignore.js +1 -0
  62. package/dist/resources/extensions/gsd/gsd-db.js +168 -23
  63. package/dist/resources/extensions/gsd/guided-flow.js +191 -2
  64. package/dist/resources/extensions/gsd/health-widget.js +4 -1
  65. package/dist/resources/extensions/gsd/hook-emitter.js +108 -0
  66. package/dist/resources/extensions/gsd/init-wizard.js +15 -1
  67. package/dist/resources/extensions/gsd/key-manager.js +28 -0
  68. package/dist/resources/extensions/gsd/memory-backfill.js +126 -0
  69. package/dist/resources/extensions/gsd/memory-store.js +19 -0
  70. package/dist/resources/extensions/gsd/model-router.js +36 -3
  71. package/dist/resources/extensions/gsd/pre-execution-checks.js +44 -9
  72. package/dist/resources/extensions/gsd/preferences-types.js +9 -0
  73. package/dist/resources/extensions/gsd/preferences-validation.js +83 -0
  74. package/dist/resources/extensions/gsd/preferences.js +17 -17
  75. package/dist/resources/extensions/gsd/prompt-loader.js +22 -7
  76. package/dist/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  77. package/dist/resources/extensions/gsd/prompts/complete-slice.md +2 -2
  78. package/dist/resources/extensions/gsd/prompts/debug-diagnose.md +2 -0
  79. package/dist/resources/extensions/gsd/prompts/discuss-headless.md +8 -0
  80. package/dist/resources/extensions/gsd/prompts/discuss.md +29 -2
  81. package/dist/resources/extensions/gsd/prompts/execute-task.md +3 -2
  82. package/dist/resources/extensions/gsd/prompts/parallel-research-slices.md +5 -2
  83. package/dist/resources/extensions/gsd/prompts/plan-slice.md +1 -0
  84. package/dist/resources/extensions/gsd/prompts/research-slice.md +1 -0
  85. package/dist/resources/extensions/gsd/prompts/system.md +1 -0
  86. package/dist/resources/extensions/gsd/safety/evidence-collector.js +96 -0
  87. package/dist/resources/extensions/gsd/safety/file-change-validator.js +13 -5
  88. package/dist/resources/extensions/gsd/safety/safety-harness.js +5 -1
  89. package/dist/resources/extensions/gsd/state.js +43 -4
  90. package/dist/resources/extensions/gsd/token-counter.js +22 -5
  91. package/dist/resources/extensions/gsd/tools/complete-milestone.js +16 -10
  92. package/dist/resources/extensions/gsd/tools/exec-search-tool.js +59 -0
  93. package/dist/resources/extensions/gsd/tools/exec-tool.js +126 -0
  94. package/dist/resources/extensions/gsd/tools/memory-tools.js +26 -1
  95. package/dist/resources/extensions/gsd/tools/resume-tool.js +23 -0
  96. package/dist/resources/extensions/gsd/uok/plan-v2.js +20 -3
  97. package/dist/resources/extensions/gsd/workflow-mcp.js +3 -0
  98. package/dist/resources/extensions/gsd/workflow-templates/spike.md +6 -0
  99. package/dist/resources/extensions/gsd/worktree-resolver.js +50 -10
  100. package/dist/resources/extensions/mcp-client/index.js +1 -1
  101. package/dist/resources/extensions/ollama/index.js +1 -2
  102. package/dist/resources/extensions/ollama/ollama-chat-provider.js +5 -15
  103. package/dist/resources/extensions/remote-questions/config.js +12 -1
  104. package/dist/resources/extensions/search-the-web/command-search-provider.js +5 -4
  105. package/dist/resources/extensions/search-the-web/native-search.js +45 -13
  106. package/dist/resources/extensions/universal-config/index.js +1 -1
  107. package/dist/resources/skills/api-design/SKILL.md +190 -0
  108. package/dist/resources/skills/create-mcp-server/SKILL.md +121 -0
  109. package/dist/resources/skills/decompose-into-slices/SKILL.md +139 -0
  110. package/dist/resources/skills/dependency-upgrade/SKILL.md +158 -0
  111. package/dist/resources/skills/design-an-interface/SKILL.md +102 -0
  112. package/dist/resources/skills/forensics/SKILL.md +153 -0
  113. package/dist/resources/skills/grill-me/SKILL.md +93 -0
  114. package/dist/resources/skills/handoff/SKILL.md +121 -0
  115. package/dist/resources/skills/observability/SKILL.md +174 -0
  116. package/dist/resources/skills/security-review/SKILL.md +181 -0
  117. package/dist/resources/skills/spike-wrap-up/SKILL.md +138 -0
  118. package/dist/resources/skills/tdd/SKILL.md +112 -0
  119. package/dist/resources/skills/verify-before-complete/SKILL.md +98 -0
  120. package/dist/resources/skills/write-docs/SKILL.md +82 -0
  121. package/dist/resources/skills/write-milestone-brief/SKILL.md +135 -0
  122. package/dist/security-overrides.d.ts +4 -1
  123. package/dist/security-overrides.js +16 -3
  124. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  125. package/dist/web/standalone/.next/BUILD_ID +1 -1
  126. package/dist/web/standalone/.next/app-path-routes-manifest.json +11 -11
  127. package/dist/web/standalone/.next/build-manifest.json +4 -4
  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 +4 -4
  131. package/dist/web/standalone/.next/server/app/_global-error/page.js +3 -3
  132. package/dist/web/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  133. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  134. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  135. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  136. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  137. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  138. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  139. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  140. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  141. package/dist/web/standalone/.next/server/app/_not-found/page.js +2 -2
  142. package/dist/web/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  143. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  144. package/dist/web/standalone/.next/server/app/_not-found.rsc +3 -3
  145. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  146. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  147. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
  148. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  149. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  150. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  151. package/dist/web/standalone/.next/server/app/api/boot/route.js +1 -1
  152. package/dist/web/standalone/.next/server/app/api/boot/route_client-reference-manifest.js +1 -1
  153. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route.js +1 -1
  154. package/dist/web/standalone/.next/server/app/api/bridge-terminal/input/route_client-reference-manifest.js +1 -1
  155. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route.js +1 -1
  156. package/dist/web/standalone/.next/server/app/api/bridge-terminal/resize/route_client-reference-manifest.js +1 -1
  157. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route.js +2 -2
  158. package/dist/web/standalone/.next/server/app/api/bridge-terminal/stream/route_client-reference-manifest.js +1 -1
  159. package/dist/web/standalone/.next/server/app/api/browse-directories/route.js +1 -1
  160. package/dist/web/standalone/.next/server/app/api/browse-directories/route_client-reference-manifest.js +1 -1
  161. package/dist/web/standalone/.next/server/app/api/captures/route.js +1 -1
  162. package/dist/web/standalone/.next/server/app/api/captures/route_client-reference-manifest.js +1 -1
  163. package/dist/web/standalone/.next/server/app/api/cleanup/route.js +1 -1
  164. package/dist/web/standalone/.next/server/app/api/cleanup/route_client-reference-manifest.js +1 -1
  165. package/dist/web/standalone/.next/server/app/api/dev-mode/route.js +1 -1
  166. package/dist/web/standalone/.next/server/app/api/dev-mode/route_client-reference-manifest.js +1 -1
  167. package/dist/web/standalone/.next/server/app/api/doctor/route.js +1 -1
  168. package/dist/web/standalone/.next/server/app/api/doctor/route_client-reference-manifest.js +1 -1
  169. package/dist/web/standalone/.next/server/app/api/experimental/route.js +2 -2
  170. package/dist/web/standalone/.next/server/app/api/experimental/route_client-reference-manifest.js +1 -1
  171. package/dist/web/standalone/.next/server/app/api/export-data/route.js +1 -1
  172. package/dist/web/standalone/.next/server/app/api/export-data/route_client-reference-manifest.js +1 -1
  173. package/dist/web/standalone/.next/server/app/api/files/route.js +1 -1
  174. package/dist/web/standalone/.next/server/app/api/files/route_client-reference-manifest.js +1 -1
  175. package/dist/web/standalone/.next/server/app/api/forensics/route.js +1 -1
  176. package/dist/web/standalone/.next/server/app/api/forensics/route_client-reference-manifest.js +1 -1
  177. package/dist/web/standalone/.next/server/app/api/git/route.js +1 -1
  178. package/dist/web/standalone/.next/server/app/api/git/route_client-reference-manifest.js +1 -1
  179. package/dist/web/standalone/.next/server/app/api/history/route.js +1 -1
  180. package/dist/web/standalone/.next/server/app/api/history/route_client-reference-manifest.js +1 -1
  181. package/dist/web/standalone/.next/server/app/api/hooks/route.js +1 -1
  182. package/dist/web/standalone/.next/server/app/api/hooks/route_client-reference-manifest.js +1 -1
  183. package/dist/web/standalone/.next/server/app/api/inspect/route.js +1 -1
  184. package/dist/web/standalone/.next/server/app/api/inspect/route_client-reference-manifest.js +1 -1
  185. package/dist/web/standalone/.next/server/app/api/knowledge/route.js +1 -1
  186. package/dist/web/standalone/.next/server/app/api/knowledge/route_client-reference-manifest.js +1 -1
  187. package/dist/web/standalone/.next/server/app/api/live-state/route.js +1 -1
  188. package/dist/web/standalone/.next/server/app/api/live-state/route_client-reference-manifest.js +1 -1
  189. package/dist/web/standalone/.next/server/app/api/notifications/route.js +2 -2
  190. package/dist/web/standalone/.next/server/app/api/notifications/route_client-reference-manifest.js +1 -1
  191. package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
  192. package/dist/web/standalone/.next/server/app/api/onboarding/route_client-reference-manifest.js +1 -1
  193. package/dist/web/standalone/.next/server/app/api/preferences/route.js +1 -1
  194. package/dist/web/standalone/.next/server/app/api/preferences/route_client-reference-manifest.js +1 -1
  195. package/dist/web/standalone/.next/server/app/api/projects/route.js +1 -1
  196. package/dist/web/standalone/.next/server/app/api/projects/route_client-reference-manifest.js +1 -1
  197. package/dist/web/standalone/.next/server/app/api/recovery/route.js +1 -1
  198. package/dist/web/standalone/.next/server/app/api/recovery/route_client-reference-manifest.js +1 -1
  199. package/dist/web/standalone/.next/server/app/api/remote-questions/route.js +2 -2
  200. package/dist/web/standalone/.next/server/app/api/remote-questions/route_client-reference-manifest.js +1 -1
  201. package/dist/web/standalone/.next/server/app/api/session/browser/route.js +1 -1
  202. package/dist/web/standalone/.next/server/app/api/session/browser/route_client-reference-manifest.js +1 -1
  203. package/dist/web/standalone/.next/server/app/api/session/command/route.js +1 -1
  204. package/dist/web/standalone/.next/server/app/api/session/command/route_client-reference-manifest.js +1 -1
  205. package/dist/web/standalone/.next/server/app/api/session/events/route.js +2 -2
  206. package/dist/web/standalone/.next/server/app/api/session/events/route_client-reference-manifest.js +1 -1
  207. package/dist/web/standalone/.next/server/app/api/session/manage/route.js +1 -1
  208. package/dist/web/standalone/.next/server/app/api/session/manage/route_client-reference-manifest.js +1 -1
  209. package/dist/web/standalone/.next/server/app/api/settings-data/route.js +1 -1
  210. package/dist/web/standalone/.next/server/app/api/settings-data/route_client-reference-manifest.js +1 -1
  211. package/dist/web/standalone/.next/server/app/api/shutdown/route.js +1 -1
  212. package/dist/web/standalone/.next/server/app/api/shutdown/route_client-reference-manifest.js +1 -1
  213. package/dist/web/standalone/.next/server/app/api/skill-health/route.js +1 -1
  214. package/dist/web/standalone/.next/server/app/api/skill-health/route_client-reference-manifest.js +1 -1
  215. package/dist/web/standalone/.next/server/app/api/steer/route.js +1 -1
  216. package/dist/web/standalone/.next/server/app/api/steer/route_client-reference-manifest.js +1 -1
  217. package/dist/web/standalone/.next/server/app/api/switch-root/route.js +1 -1
  218. package/dist/web/standalone/.next/server/app/api/switch-root/route_client-reference-manifest.js +1 -1
  219. package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +2 -2
  220. package/dist/web/standalone/.next/server/app/api/terminal/input/route_client-reference-manifest.js +1 -1
  221. package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +2 -2
  222. package/dist/web/standalone/.next/server/app/api/terminal/resize/route_client-reference-manifest.js +1 -1
  223. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +2 -2
  224. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route_client-reference-manifest.js +1 -1
  225. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +4 -4
  226. package/dist/web/standalone/.next/server/app/api/terminal/stream/route_client-reference-manifest.js +1 -1
  227. package/dist/web/standalone/.next/server/app/api/terminal/upload/route.js +1 -1
  228. package/dist/web/standalone/.next/server/app/api/terminal/upload/route_client-reference-manifest.js +1 -1
  229. package/dist/web/standalone/.next/server/app/api/undo/route.js +1 -1
  230. package/dist/web/standalone/.next/server/app/api/undo/route_client-reference-manifest.js +1 -1
  231. package/dist/web/standalone/.next/server/app/api/update/route.js +1 -1
  232. package/dist/web/standalone/.next/server/app/api/update/route_client-reference-manifest.js +1 -1
  233. package/dist/web/standalone/.next/server/app/api/visualizer/route.js +1 -1
  234. package/dist/web/standalone/.next/server/app/api/visualizer/route_client-reference-manifest.js +1 -1
  235. package/dist/web/standalone/.next/server/app/index.html +1 -1
  236. package/dist/web/standalone/.next/server/app/index.rsc +4 -4
  237. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  238. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
  239. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  240. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +3 -3
  241. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  242. package/dist/web/standalone/.next/server/app/page.js +2 -2
  243. package/dist/web/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  244. package/dist/web/standalone/.next/server/app-paths-manifest.json +11 -11
  245. package/dist/web/standalone/.next/server/chunks/63.js +3 -3
  246. package/dist/web/standalone/.next/server/chunks/6897.js +3 -3
  247. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  248. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  249. package/dist/web/standalone/.next/server/middleware-react-loadable-manifest.js +1 -1
  250. package/dist/web/standalone/.next/server/middleware.js +2 -2
  251. package/dist/web/standalone/.next/server/next-font-manifest.js +1 -1
  252. package/dist/web/standalone/.next/server/next-font-manifest.json +1 -1
  253. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  254. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  255. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  256. package/dist/web/standalone/.next/static/chunks/2826.d445fb428ef41fa1.js +9 -0
  257. package/dist/web/standalone/.next/static/chunks/app/_not-found/{page-2f24283c162b6ab3.js → page-f2a7482d42a5614b.js} +1 -1
  258. package/dist/web/standalone/.next/static/chunks/app/{layout-9ecfd95f343793f0.js → layout-a16c7a7ecdf0c2cf.js} +1 -1
  259. package/dist/web/standalone/.next/static/chunks/app/page-5b113fd32bc2a1c3.js +1 -0
  260. package/dist/web/standalone/.next/static/chunks/main-app-fdab67f7802d7832.js +1 -0
  261. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-459824ffb8c323dd.js +1 -0
  262. package/dist/web/standalone/.next/static/chunks/{webpack-5fc74f13a25fa1bb.js → webpack-1832629448831fdc.js} +1 -1
  263. package/dist/web/standalone/node_modules/node-pty/build/Makefile +2 -2
  264. package/dist/web/standalone/node_modules/node-pty/build/Release/pty.node +0 -0
  265. package/dist/web/standalone/node_modules/node-pty/build/pty.target.mk +14 -14
  266. package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api.target.mk +14 -14
  267. package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api_except.target.mk +14 -14
  268. package/dist/web/standalone/node_modules/node-pty/node-addon-api/node_addon_api_maybe.target.mk +14 -14
  269. package/dist/web/standalone/server.js +1 -1
  270. package/dist/web-mode.js +1 -1
  271. package/dist/welcome-screen.js +19 -15
  272. package/dist/wizard.js +4 -5
  273. package/package.json +25 -7
  274. package/packages/daemon/package.json +2 -2
  275. package/packages/gsd-agent-core/dist/agent-session.d.ts +716 -0
  276. package/packages/gsd-agent-core/dist/agent-session.d.ts.map +1 -0
  277. package/packages/gsd-agent-core/dist/agent-session.js +2595 -0
  278. package/packages/gsd-agent-core/dist/agent-session.js.map +1 -0
  279. package/packages/gsd-agent-core/dist/artifact-manager.d.ts +52 -0
  280. package/packages/gsd-agent-core/dist/artifact-manager.d.ts.map +1 -0
  281. package/packages/gsd-agent-core/dist/artifact-manager.js +118 -0
  282. package/packages/gsd-agent-core/dist/artifact-manager.js.map +1 -0
  283. package/packages/gsd-agent-core/dist/bash-executor.d.ts +57 -0
  284. package/packages/gsd-agent-core/dist/bash-executor.d.ts.map +1 -0
  285. package/packages/gsd-agent-core/dist/bash-executor.js +282 -0
  286. package/packages/gsd-agent-core/dist/bash-executor.js.map +1 -0
  287. package/packages/gsd-agent-core/dist/blob-store.d.ts +39 -0
  288. package/packages/gsd-agent-core/dist/blob-store.d.ts.map +1 -0
  289. package/packages/gsd-agent-core/dist/blob-store.js +151 -0
  290. package/packages/gsd-agent-core/dist/blob-store.js.map +1 -0
  291. package/packages/gsd-agent-core/dist/compaction/branch-summarization.d.ts +90 -0
  292. package/packages/gsd-agent-core/dist/compaction/branch-summarization.d.ts.map +1 -0
  293. package/packages/gsd-agent-core/dist/compaction/branch-summarization.js +207 -0
  294. package/packages/gsd-agent-core/dist/compaction/branch-summarization.js.map +1 -0
  295. package/packages/gsd-agent-core/dist/compaction/compaction.d.ts +137 -0
  296. package/packages/gsd-agent-core/dist/compaction/compaction.d.ts.map +1 -0
  297. package/packages/gsd-agent-core/dist/compaction/compaction.js +621 -0
  298. package/packages/gsd-agent-core/dist/compaction/compaction.js.map +1 -0
  299. package/packages/gsd-agent-core/dist/compaction/index.d.ts +7 -0
  300. package/packages/gsd-agent-core/dist/compaction/index.d.ts.map +1 -0
  301. package/packages/gsd-agent-core/dist/compaction/index.js +7 -0
  302. package/packages/gsd-agent-core/dist/compaction/index.js.map +1 -0
  303. package/packages/gsd-agent-core/dist/compaction/utils.d.ts +78 -0
  304. package/packages/gsd-agent-core/dist/compaction/utils.d.ts.map +1 -0
  305. package/packages/gsd-agent-core/dist/compaction/utils.js +263 -0
  306. package/packages/gsd-agent-core/dist/compaction/utils.js.map +1 -0
  307. package/packages/gsd-agent-core/dist/compaction-orchestrator.d.ts +90 -0
  308. package/packages/gsd-agent-core/dist/compaction-orchestrator.d.ts.map +1 -0
  309. package/packages/gsd-agent-core/dist/compaction-orchestrator.js +338 -0
  310. package/packages/gsd-agent-core/dist/compaction-orchestrator.js.map +1 -0
  311. package/packages/gsd-agent-core/dist/contextual-tips.d.ts +43 -0
  312. package/packages/gsd-agent-core/dist/contextual-tips.d.ts.map +1 -0
  313. package/packages/gsd-agent-core/dist/contextual-tips.js +208 -0
  314. package/packages/gsd-agent-core/dist/contextual-tips.js.map +1 -0
  315. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.d.ts +18 -0
  316. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.d.ts.map +1 -0
  317. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.js +250 -0
  318. package/packages/gsd-agent-core/dist/export-html/ansi-to-html.js.map +1 -0
  319. package/packages/gsd-agent-core/dist/export-html/index.d.ts +37 -0
  320. package/packages/gsd-agent-core/dist/export-html/index.d.ts.map +1 -0
  321. package/packages/gsd-agent-core/dist/export-html/index.js +257 -0
  322. package/packages/gsd-agent-core/dist/export-html/index.js.map +1 -0
  323. package/packages/gsd-agent-core/dist/export-html/template.css +971 -0
  324. package/packages/gsd-agent-core/dist/export-html/template.html +54 -0
  325. package/packages/gsd-agent-core/dist/export-html/template.js +1583 -0
  326. package/packages/gsd-agent-core/dist/export-html/tool-renderer.d.ts +38 -0
  327. package/packages/gsd-agent-core/dist/export-html/tool-renderer.d.ts.map +1 -0
  328. package/packages/gsd-agent-core/dist/export-html/tool-renderer.js +70 -0
  329. package/packages/gsd-agent-core/dist/export-html/tool-renderer.js.map +1 -0
  330. package/packages/gsd-agent-core/dist/export-html/vendor/highlight.min.js +1213 -0
  331. package/packages/gsd-agent-core/dist/export-html/vendor/marked.min.js +6 -0
  332. package/packages/gsd-agent-core/dist/fallback-resolver.d.ts +75 -0
  333. package/packages/gsd-agent-core/dist/fallback-resolver.d.ts.map +1 -0
  334. package/packages/gsd-agent-core/dist/fallback-resolver.js +118 -0
  335. package/packages/gsd-agent-core/dist/fallback-resolver.js.map +1 -0
  336. package/packages/gsd-agent-core/dist/image-overflow-recovery.d.ts +44 -0
  337. package/packages/gsd-agent-core/dist/image-overflow-recovery.d.ts.map +1 -0
  338. package/packages/gsd-agent-core/dist/image-overflow-recovery.js +99 -0
  339. package/packages/gsd-agent-core/dist/image-overflow-recovery.js.map +1 -0
  340. package/packages/gsd-agent-core/dist/index.d.ts +14 -0
  341. package/packages/gsd-agent-core/dist/index.d.ts.map +1 -0
  342. package/packages/gsd-agent-core/dist/index.js +19 -0
  343. package/packages/gsd-agent-core/dist/index.js.map +1 -0
  344. package/packages/gsd-agent-core/dist/keybindings.d.ts +47 -0
  345. package/packages/gsd-agent-core/dist/keybindings.d.ts.map +1 -0
  346. package/packages/gsd-agent-core/dist/keybindings.js +156 -0
  347. package/packages/gsd-agent-core/dist/keybindings.js.map +1 -0
  348. package/packages/gsd-agent-core/dist/lifecycle-hooks.d.ts +42 -0
  349. package/packages/gsd-agent-core/dist/lifecycle-hooks.d.ts.map +1 -0
  350. package/packages/gsd-agent-core/dist/lifecycle-hooks.js +204 -0
  351. package/packages/gsd-agent-core/dist/lifecycle-hooks.js.map +1 -0
  352. package/packages/gsd-agent-core/dist/retry-handler.d.ts +128 -0
  353. package/packages/gsd-agent-core/dist/retry-handler.d.ts.map +1 -0
  354. package/packages/gsd-agent-core/dist/retry-handler.js +518 -0
  355. package/packages/gsd-agent-core/dist/retry-handler.js.map +1 -0
  356. package/packages/gsd-agent-core/dist/sdk.d.ts +159 -0
  357. package/packages/gsd-agent-core/dist/sdk.d.ts.map +1 -0
  358. package/packages/gsd-agent-core/dist/sdk.js +375 -0
  359. package/packages/gsd-agent-core/dist/sdk.js.map +1 -0
  360. package/packages/gsd-agent-core/dist/system-prompt.d.ts +28 -0
  361. package/packages/gsd-agent-core/dist/system-prompt.d.ts.map +1 -0
  362. package/packages/gsd-agent-core/dist/system-prompt.js +201 -0
  363. package/packages/gsd-agent-core/dist/system-prompt.js.map +1 -0
  364. package/packages/gsd-agent-core/package.json +25 -0
  365. package/packages/gsd-agent-core/scripts/copy-assets.cjs +43 -0
  366. package/packages/gsd-agent-core/src/agent-session.test.ts +169 -0
  367. package/packages/gsd-agent-core/src/agent-session.ts +3358 -0
  368. package/packages/gsd-agent-core/src/artifact-manager.ts +126 -0
  369. package/packages/gsd-agent-core/src/bash-executor.ts +352 -0
  370. package/packages/gsd-agent-core/src/blob-store.ts +154 -0
  371. package/packages/gsd-agent-core/src/compaction/branch-summarization.ts +317 -0
  372. package/packages/gsd-agent-core/src/compaction/compaction.ts +855 -0
  373. package/packages/gsd-agent-core/src/compaction/index.ts +7 -0
  374. package/packages/gsd-agent-core/src/compaction/utils.ts +312 -0
  375. package/packages/gsd-agent-core/src/compaction-orchestrator.ts +449 -0
  376. package/packages/gsd-agent-core/src/contextual-tips.ts +232 -0
  377. package/packages/gsd-agent-core/src/export-html/ansi-to-html.ts +259 -0
  378. package/packages/gsd-agent-core/src/export-html/index.ts +345 -0
  379. package/packages/gsd-agent-core/src/export-html/template.css +971 -0
  380. package/packages/gsd-agent-core/src/export-html/template.html +54 -0
  381. package/packages/gsd-agent-core/src/export-html/template.js +1583 -0
  382. package/packages/gsd-agent-core/src/export-html/tool-renderer.ts +114 -0
  383. package/packages/gsd-agent-core/src/export-html/vendor/highlight.min.js +1213 -0
  384. package/packages/gsd-agent-core/src/export-html/vendor/marked.min.js +6 -0
  385. package/packages/gsd-agent-core/src/fallback-resolver.ts +193 -0
  386. package/packages/gsd-agent-core/src/image-overflow-recovery.ts +120 -0
  387. package/packages/gsd-agent-core/src/index.ts +68 -0
  388. package/packages/gsd-agent-core/src/keybindings.ts +220 -0
  389. package/packages/gsd-agent-core/src/lifecycle-hooks.ts +284 -0
  390. package/packages/gsd-agent-core/src/retry-handler.ts +620 -0
  391. package/packages/gsd-agent-core/src/sdk.ts +550 -0
  392. package/packages/gsd-agent-core/src/system-prompt.ts +270 -0
  393. package/packages/gsd-agent-core/tsconfig.json +28 -0
  394. package/packages/gsd-agent-core/tsconfig.tsbuildinfo +1 -0
  395. package/packages/gsd-agent-modes/dist/cli/args.d.ts +58 -0
  396. package/packages/gsd-agent-modes/dist/cli/args.d.ts.map +1 -0
  397. package/packages/gsd-agent-modes/dist/cli/args.js +324 -0
  398. package/packages/gsd-agent-modes/dist/cli/args.js.map +1 -0
  399. package/packages/gsd-agent-modes/dist/cli/config-selector.d.ts +13 -0
  400. package/packages/gsd-agent-modes/dist/cli/config-selector.d.ts.map +1 -0
  401. package/packages/gsd-agent-modes/dist/cli/config-selector.js +32 -0
  402. package/packages/gsd-agent-modes/dist/cli/config-selector.js.map +1 -0
  403. package/packages/gsd-agent-modes/dist/cli/file-processor.d.ts +15 -0
  404. package/packages/gsd-agent-modes/dist/cli/file-processor.d.ts.map +1 -0
  405. package/packages/gsd-agent-modes/dist/cli/file-processor.js +86 -0
  406. package/packages/gsd-agent-modes/dist/cli/file-processor.js.map +1 -0
  407. package/packages/gsd-agent-modes/dist/cli/list-models.d.ts +21 -0
  408. package/packages/gsd-agent-modes/dist/cli/list-models.d.ts.map +1 -0
  409. package/packages/gsd-agent-modes/dist/cli/list-models.js +114 -0
  410. package/packages/gsd-agent-modes/dist/cli/list-models.js.map +1 -0
  411. package/packages/gsd-agent-modes/dist/cli/session-picker.d.ts +10 -0
  412. package/packages/gsd-agent-modes/dist/cli/session-picker.d.ts.map +1 -0
  413. package/packages/gsd-agent-modes/dist/cli/session-picker.js +37 -0
  414. package/packages/gsd-agent-modes/dist/cli/session-picker.js.map +1 -0
  415. package/packages/gsd-agent-modes/dist/index.d.ts +7 -0
  416. package/packages/gsd-agent-modes/dist/index.d.ts.map +1 -0
  417. package/packages/gsd-agent-modes/dist/index.js +7 -0
  418. package/packages/gsd-agent-modes/dist/index.js.map +1 -0
  419. package/packages/gsd-agent-modes/dist/main.d.ts +8 -0
  420. package/packages/gsd-agent-modes/dist/main.d.ts.map +1 -0
  421. package/packages/gsd-agent-modes/dist/main.js +491 -0
  422. package/packages/gsd-agent-modes/dist/main.js.map +1 -0
  423. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.d.ts +34 -0
  424. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.d.ts.map +1 -0
  425. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.js +330 -0
  426. package/packages/gsd-agent-modes/dist/modes/interactive/components/armin.js.map +1 -0
  427. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.d.ts +29 -0
  428. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  429. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js +141 -0
  430. package/packages/gsd-agent-modes/dist/modes/interactive/components/assistant-message.js.map +1 -0
  431. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.d.ts +36 -0
  432. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  433. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.js +157 -0
  434. package/packages/gsd-agent-modes/dist/modes/interactive/components/bash-execution.js.map +1 -0
  435. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.d.ts +16 -0
  436. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  437. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.js +48 -0
  438. package/packages/gsd-agent-modes/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  439. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.d.ts +16 -0
  440. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  441. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.js +43 -0
  442. package/packages/gsd-agent-modes/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  443. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.d.ts +11 -0
  444. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.d.ts.map +1 -0
  445. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.js +47 -0
  446. package/packages/gsd-agent-modes/dist/modes/interactive/components/chat-frame.js.map +1 -0
  447. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.d.ts +16 -0
  448. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  449. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.js +44 -0
  450. package/packages/gsd-agent-modes/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  451. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.d.ts +71 -0
  452. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  453. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.js +474 -0
  454. package/packages/gsd-agent-modes/dist/modes/interactive/components/config-selector.js.map +1 -0
  455. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.d.ts +15 -0
  456. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  457. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.js +32 -0
  458. package/packages/gsd-agent-modes/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  459. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.d.ts +22 -0
  460. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  461. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.js +70 -0
  462. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-editor.js.map +1 -0
  463. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.d.ts +20 -0
  464. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  465. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.js +75 -0
  466. package/packages/gsd-agent-modes/dist/modes/interactive/components/custom-message.js.map +1 -0
  467. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.d.ts +23 -0
  468. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
  469. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.js +140 -0
  470. package/packages/gsd-agent-modes/dist/modes/interactive/components/daxnuts.js.map +1 -0
  471. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.d.ts +12 -0
  472. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.d.ts.map +1 -0
  473. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.js +133 -0
  474. package/packages/gsd-agent-modes/dist/modes/interactive/components/diff.js.map +1 -0
  475. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.d.ts +33 -0
  476. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  477. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.js +82 -0
  478. package/packages/gsd-agent-modes/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  479. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.d.ts +20 -0
  480. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  481. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.js +111 -0
  482. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-editor.js.map +1 -0
  483. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.d.ts +24 -0
  484. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  485. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.js +63 -0
  486. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-input.js.map +1 -0
  487. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.d.ts +33 -0
  488. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  489. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.js +118 -0
  490. package/packages/gsd-agent-modes/dist/modes/interactive/components/extension-selector.js.map +1 -0
  491. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.d.ts +32 -0
  492. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.d.ts.map +1 -0
  493. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.js +230 -0
  494. package/packages/gsd-agent-modes/dist/modes/interactive/components/footer.js.map +1 -0
  495. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.d.ts +34 -0
  496. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.d.ts.map +1 -0
  497. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.js +36 -0
  498. package/packages/gsd-agent-modes/dist/modes/interactive/components/index.js.map +1 -0
  499. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.d.ts +48 -0
  500. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
  501. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.js +72 -0
  502. package/packages/gsd-agent-modes/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
  503. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.d.ts +63 -0
  504. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.d.ts.map +1 -0
  505. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.js +213 -0
  506. package/packages/gsd-agent-modes/dist/modes/interactive/components/login-dialog.js.map +1 -0
  507. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.d.ts +86 -0
  508. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.d.ts.map +1 -0
  509. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.js +536 -0
  510. package/packages/gsd-agent-modes/dist/modes/interactive/components/model-selector.js.map +1 -0
  511. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.d.ts +19 -0
  512. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -0
  513. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.js +93 -0
  514. package/packages/gsd-agent-modes/dist/modes/interactive/components/oauth-selector.js.map +1 -0
  515. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.d.ts +30 -0
  516. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.d.ts.map +1 -0
  517. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.js +169 -0
  518. package/packages/gsd-agent-modes/dist/modes/interactive/components/provider-manager.js.map +1 -0
  519. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.d.ts +49 -0
  520. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -0
  521. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.js +267 -0
  522. package/packages/gsd-agent-modes/dist/modes/interactive/components/scoped-models-selector.js.map +1 -0
  523. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.d.ts +21 -0
  524. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  525. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.js +155 -0
  526. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  527. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.d.ts +97 -0
  528. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  529. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.js +810 -0
  530. package/packages/gsd-agent-modes/dist/modes/interactive/components/session-selector.js.map +1 -0
  531. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts +71 -0
  532. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  533. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js +320 -0
  534. package/packages/gsd-agent-modes/dist/modes/interactive/components/settings-selector.js.map +1 -0
  535. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.d.ts +10 -0
  536. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  537. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.js +34 -0
  538. package/packages/gsd-agent-modes/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  539. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
  540. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  541. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.js +46 -0
  542. package/packages/gsd-agent-modes/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  543. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.d.ts +11 -0
  544. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  545. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.js +45 -0
  546. package/packages/gsd-agent-modes/dist/modes/interactive/components/theme-selector.js.map +1 -0
  547. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.d.ts +11 -0
  548. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  549. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.js +46 -0
  550. package/packages/gsd-agent-modes/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  551. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.d.ts +15 -0
  552. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.d.ts.map +1 -0
  553. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.js +40 -0
  554. package/packages/gsd-agent-modes/dist/modes/interactive/components/timestamp.js.map +1 -0
  555. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts +111 -0
  556. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  557. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js +984 -0
  558. package/packages/gsd-agent-modes/dist/modes/interactive/components/tool-execution.js.map +1 -0
  559. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.d.ts +44 -0
  560. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.d.ts.map +1 -0
  561. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.js +61 -0
  562. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-render-utils.js.map +1 -0
  563. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.d.ts +109 -0
  564. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  565. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.js +1035 -0
  566. package/packages/gsd-agent-modes/dist/modes/interactive/components/tree-selector.js.map +1 -0
  567. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.d.ts +30 -0
  568. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  569. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.js +112 -0
  570. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  571. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.d.ts +12 -0
  572. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  573. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.js +38 -0
  574. package/packages/gsd-agent-modes/dist/modes/interactive/components/user-message.js.map +1 -0
  575. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.d.ts +24 -0
  576. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  577. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.js +33 -0
  578. package/packages/gsd-agent-modes/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  579. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts +27 -0
  580. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -0
  581. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js +793 -0
  582. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/chat-controller.js.map +1 -0
  583. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.d.ts +4 -0
  584. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.d.ts.map +1 -0
  585. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.js +62 -0
  586. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/extension-ui-controller.js.map +1 -0
  587. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.d.ts +22 -0
  588. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.d.ts.map +1 -0
  589. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js +118 -0
  590. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/input-controller.js.map +1 -0
  591. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.d.ts +7 -0
  592. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.d.ts.map +1 -0
  593. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.js +68 -0
  594. package/packages/gsd-agent-modes/dist/modes/interactive/controllers/model-controller.js.map +1 -0
  595. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts +50 -0
  596. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.d.ts.map +1 -0
  597. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js +2 -0
  598. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode-state.js.map +1 -0
  599. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts +358 -0
  600. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  601. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js +3409 -0
  602. package/packages/gsd-agent-modes/dist/modes/interactive/interactive-mode.js.map +1 -0
  603. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.d.ts +77 -0
  604. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.d.ts.map +1 -0
  605. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.js +529 -0
  606. package/packages/gsd-agent-modes/dist/modes/interactive/slash-command-handlers.js.map +1 -0
  607. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.d.ts +6 -0
  608. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.d.ts.map +1 -0
  609. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.js +15 -0
  610. package/packages/gsd-agent-modes/dist/modes/interactive/utils/shorten-path.js.map +1 -0
  611. package/packages/gsd-agent-modes/dist/modes/print-mode.d.ts +28 -0
  612. package/packages/gsd-agent-modes/dist/modes/print-mode.d.ts.map +1 -0
  613. package/packages/gsd-agent-modes/dist/modes/print-mode.js +84 -0
  614. package/packages/gsd-agent-modes/dist/modes/print-mode.js.map +1 -0
  615. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.d.ts +17 -0
  616. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.d.ts.map +1 -0
  617. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.js +49 -0
  618. package/packages/gsd-agent-modes/dist/modes/rpc/jsonl.js.map +1 -0
  619. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.d.ts +37 -0
  620. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.d.ts.map +1 -0
  621. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.js +84 -0
  622. package/packages/gsd-agent-modes/dist/modes/rpc/remote-terminal.js.map +1 -0
  623. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts +243 -0
  624. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  625. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js +464 -0
  626. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-client.js.map +1 -0
  627. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts +25 -0
  628. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  629. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js +750 -0
  630. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-mode.js.map +1 -0
  631. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.d.ts +511 -0
  632. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  633. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.js +8 -0
  634. package/packages/gsd-agent-modes/dist/modes/rpc/rpc-types.js.map +1 -0
  635. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.d.ts +19 -0
  636. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.d.ts.map +1 -0
  637. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.js +45 -0
  638. package/packages/gsd-agent-modes/dist/modes/shared/command-context-actions.js.map +1 -0
  639. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.d.ts +22 -0
  640. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.d.ts.map +1 -0
  641. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.js +21 -0
  642. package/packages/gsd-agent-modes/dist/pi-coding-agent-compat.js.map +1 -0
  643. package/packages/gsd-agent-modes/dist/pi-tui-compat.d.ts +4 -0
  644. package/packages/gsd-agent-modes/dist/pi-tui-compat.d.ts.map +1 -0
  645. package/packages/gsd-agent-modes/dist/pi-tui-compat.js +3 -0
  646. package/packages/gsd-agent-modes/dist/pi-tui-compat.js.map +1 -0
  647. package/packages/gsd-agent-modes/dist/theme.d.ts +15 -0
  648. package/packages/gsd-agent-modes/dist/theme.d.ts.map +1 -0
  649. package/packages/gsd-agent-modes/dist/theme.js +23 -0
  650. package/packages/gsd-agent-modes/dist/theme.js.map +1 -0
  651. package/packages/gsd-agent-modes/dist/utils/theme.d.ts +16 -0
  652. package/packages/gsd-agent-modes/dist/utils/theme.d.ts.map +1 -0
  653. package/packages/gsd-agent-modes/dist/utils/theme.js +11 -0
  654. package/packages/gsd-agent-modes/dist/utils/theme.js.map +1 -0
  655. package/packages/gsd-agent-modes/package.json +23 -0
  656. package/packages/gsd-agent-modes/src/cli/args.ts +350 -0
  657. package/packages/gsd-agent-modes/src/cli/config-selector.ts +54 -0
  658. package/packages/gsd-agent-modes/src/cli/file-processor.ts +107 -0
  659. package/packages/gsd-agent-modes/src/cli/list-models.ts +141 -0
  660. package/packages/gsd-agent-modes/src/cli/session-picker.ts +59 -0
  661. package/packages/gsd-agent-modes/src/index.ts +6 -0
  662. package/packages/gsd-agent-modes/src/main.ts +614 -0
  663. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/login-dialog.test.ts +24 -0
  664. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/provider-display-name.test.ts +18 -0
  665. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/timestamp.test.ts +38 -0
  666. package/packages/gsd-agent-modes/src/modes/interactive/components/__tests__/tool-execution.test.ts +171 -0
  667. package/packages/gsd-agent-modes/src/modes/interactive/components/armin.ts +382 -0
  668. package/packages/gsd-agent-modes/src/modes/interactive/components/assistant-message.ts +178 -0
  669. package/packages/gsd-agent-modes/src/modes/interactive/components/bash-execution.ts +212 -0
  670. package/packages/gsd-agent-modes/src/modes/interactive/components/bordered-loader.ts +66 -0
  671. package/packages/gsd-agent-modes/src/modes/interactive/components/branch-summary-message.ts +59 -0
  672. package/packages/gsd-agent-modes/src/modes/interactive/components/chat-frame.ts +67 -0
  673. package/packages/gsd-agent-modes/src/modes/interactive/components/compaction-summary-message.ts +60 -0
  674. package/packages/gsd-agent-modes/src/modes/interactive/components/config-selector.ts +597 -0
  675. package/packages/gsd-agent-modes/src/modes/interactive/components/countdown-timer.ts +41 -0
  676. package/packages/gsd-agent-modes/src/modes/interactive/components/custom-editor.ts +88 -0
  677. package/packages/gsd-agent-modes/src/modes/interactive/components/custom-message.ts +100 -0
  678. package/packages/gsd-agent-modes/src/modes/interactive/components/daxnuts.ts +165 -0
  679. package/packages/gsd-agent-modes/src/modes/interactive/components/diff.ts +147 -0
  680. package/packages/gsd-agent-modes/src/modes/interactive/components/dynamic-border.test.ts +73 -0
  681. package/packages/gsd-agent-modes/src/modes/interactive/components/dynamic-border.ts +89 -0
  682. package/packages/gsd-agent-modes/src/modes/interactive/components/extension-editor.ts +151 -0
  683. package/packages/gsd-agent-modes/src/modes/interactive/components/extension-input.ts +100 -0
  684. package/packages/gsd-agent-modes/src/modes/interactive/components/extension-selector.ts +156 -0
  685. package/packages/gsd-agent-modes/src/modes/interactive/components/footer.ts +257 -0
  686. package/packages/gsd-agent-modes/src/modes/interactive/components/index.ts +35 -0
  687. package/packages/gsd-agent-modes/src/modes/interactive/components/keybinding-hints.ts +84 -0
  688. package/packages/gsd-agent-modes/src/modes/interactive/components/login-dialog.ts +257 -0
  689. package/packages/gsd-agent-modes/src/modes/interactive/components/model-selector.ts +656 -0
  690. package/packages/gsd-agent-modes/src/modes/interactive/components/oauth-selector.ts +122 -0
  691. package/packages/gsd-agent-modes/src/modes/interactive/components/provider-manager.ts +210 -0
  692. package/packages/gsd-agent-modes/src/modes/interactive/components/scoped-models-selector.ts +342 -0
  693. package/packages/gsd-agent-modes/src/modes/interactive/components/session-selector-search.ts +194 -0
  694. package/packages/gsd-agent-modes/src/modes/interactive/components/session-selector.ts +1011 -0
  695. package/packages/gsd-agent-modes/src/modes/interactive/components/settings-selector.ts +452 -0
  696. package/packages/gsd-agent-modes/src/modes/interactive/components/show-images-selector.ts +45 -0
  697. package/packages/gsd-agent-modes/src/modes/interactive/components/skill-invocation-message.ts +56 -0
  698. package/packages/gsd-agent-modes/src/modes/interactive/components/theme-selector.ts +63 -0
  699. package/packages/gsd-agent-modes/src/modes/interactive/components/thinking-selector.ts +64 -0
  700. package/packages/gsd-agent-modes/src/modes/interactive/components/timestamp.ts +48 -0
  701. package/packages/gsd-agent-modes/src/modes/interactive/components/tool-execution.ts +1157 -0
  702. package/packages/gsd-agent-modes/src/modes/interactive/components/tree-render-utils.ts +81 -0
  703. package/packages/gsd-agent-modes/src/modes/interactive/components/tree-selector.ts +1208 -0
  704. package/packages/gsd-agent-modes/src/modes/interactive/components/user-message-selector.ts +145 -0
  705. package/packages/gsd-agent-modes/src/modes/interactive/components/user-message.ts +44 -0
  706. package/packages/gsd-agent-modes/src/modes/interactive/components/visual-truncate.ts +50 -0
  707. package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller-ordering.test.ts +1430 -0
  708. package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller.test.ts +71 -0
  709. package/packages/gsd-agent-modes/src/modes/interactive/controllers/chat-controller.ts +957 -0
  710. package/packages/gsd-agent-modes/src/modes/interactive/controllers/extension-ui-controller.ts +63 -0
  711. package/packages/gsd-agent-modes/src/modes/interactive/controllers/input-controller.test.ts +183 -0
  712. package/packages/gsd-agent-modes/src/modes/interactive/controllers/input-controller.ts +140 -0
  713. package/packages/gsd-agent-modes/src/modes/interactive/controllers/model-controller.ts +77 -0
  714. package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode-ordering.test.ts +44 -0
  715. package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode-state.ts +49 -0
  716. package/packages/gsd-agent-modes/src/modes/interactive/interactive-mode.ts +4195 -0
  717. package/packages/gsd-agent-modes/src/modes/interactive/slash-command-handlers.ts +670 -0
  718. package/packages/gsd-agent-modes/src/modes/interactive/utils/shorten-path.ts +14 -0
  719. package/packages/gsd-agent-modes/src/modes/print-mode.ts +106 -0
  720. package/packages/gsd-agent-modes/src/modes/rpc/jsonl.ts +58 -0
  721. package/packages/gsd-agent-modes/src/modes/rpc/remote-terminal.ts +109 -0
  722. package/packages/gsd-agent-modes/src/modes/rpc/rpc-client.ts +572 -0
  723. package/packages/gsd-agent-modes/src/modes/rpc/rpc-mode.ts +902 -0
  724. package/packages/gsd-agent-modes/src/modes/rpc/rpc-protocol-v2.test.ts +971 -0
  725. package/packages/gsd-agent-modes/src/modes/rpc/rpc-types.ts +335 -0
  726. package/packages/gsd-agent-modes/src/modes/shared/command-context-actions.ts +53 -0
  727. package/packages/gsd-agent-modes/src/pi-coding-agent-compat.ts +42 -0
  728. package/packages/gsd-agent-modes/src/pi-tui-compat.ts +4 -0
  729. package/packages/gsd-agent-modes/src/theme.ts +25 -0
  730. package/packages/gsd-agent-modes/src/utils/theme.ts +24 -0
  731. package/packages/gsd-agent-modes/tsconfig.json +28 -0
  732. package/packages/gsd-agent-modes/tsconfig.tsbuildinfo +1 -0
  733. package/packages/gsd-agent-types/dist/index.d.ts +176 -0
  734. package/packages/gsd-agent-types/dist/index.d.ts.map +1 -0
  735. package/packages/gsd-agent-types/dist/index.js +24 -0
  736. package/packages/gsd-agent-types/dist/index.js.map +1 -0
  737. package/packages/gsd-agent-types/package.json +24 -0
  738. package/packages/gsd-agent-types/src/index.ts +206 -0
  739. package/packages/gsd-agent-types/tsconfig.json +25 -0
  740. package/packages/gsd-agent-types/tsconfig.tsbuildinfo +1 -0
  741. package/packages/mcp-server/dist/remote-questions.d.ts +45 -0
  742. package/packages/mcp-server/dist/remote-questions.d.ts.map +1 -0
  743. package/packages/mcp-server/dist/remote-questions.js +732 -0
  744. package/packages/mcp-server/dist/remote-questions.js.map +1 -0
  745. package/packages/mcp-server/dist/server.d.ts +7 -0
  746. package/packages/mcp-server/dist/server.d.ts.map +1 -1
  747. package/packages/mcp-server/dist/server.js +77 -11
  748. package/packages/mcp-server/dist/server.js.map +1 -1
  749. package/packages/mcp-server/dist/session-manager.d.ts +14 -0
  750. package/packages/mcp-server/dist/session-manager.d.ts.map +1 -1
  751. package/packages/mcp-server/dist/session-manager.js +49 -1
  752. package/packages/mcp-server/dist/session-manager.js.map +1 -1
  753. package/packages/mcp-server/dist/workflow-tools.d.ts +1 -1
  754. package/packages/mcp-server/dist/workflow-tools.d.ts.map +1 -1
  755. package/packages/mcp-server/dist/workflow-tools.js +163 -25
  756. package/packages/mcp-server/dist/workflow-tools.js.map +1 -1
  757. package/packages/mcp-server/package.json +4 -3
  758. package/packages/mcp-server/src/mcp-server.test.ts +67 -0
  759. package/packages/mcp-server/src/remote-questions.test.ts +294 -0
  760. package/packages/mcp-server/src/remote-questions.ts +916 -0
  761. package/packages/mcp-server/src/server.ts +94 -18
  762. package/packages/mcp-server/src/session-manager.ts +43 -1
  763. package/packages/mcp-server/src/workflow-tools.test.ts +146 -1
  764. package/packages/mcp-server/src/workflow-tools.ts +215 -43
  765. package/packages/mcp-server/tsconfig.test.json +19 -0
  766. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  767. package/packages/native/dist/tsconfig.tsbuildinfo +1 -0
  768. package/packages/native/package.json +1 -1
  769. package/packages/native/tsconfig.json +2 -1
  770. package/packages/pi-agent-core/dist/agent-loop.js +12 -0
  771. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  772. package/packages/pi-agent-core/dist/types.d.ts +30 -0
  773. package/packages/pi-agent-core/dist/types.d.ts.map +1 -1
  774. package/packages/pi-agent-core/dist/types.js.map +1 -1
  775. package/packages/pi-agent-core/package.json +1 -1
  776. package/packages/pi-agent-core/src/agent-loop.ts +14 -0
  777. package/packages/pi-agent-core/src/types.ts +34 -0
  778. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
  779. package/packages/pi-ai/dist/models/custom.d.ts +38 -0
  780. package/packages/pi-ai/dist/models/custom.d.ts.map +1 -1
  781. package/packages/pi-ai/dist/models/custom.js +41 -0
  782. package/packages/pi-ai/dist/models/custom.js.map +1 -1
  783. package/packages/pi-ai/dist/providers/anthropic-auth.test.js +1 -1
  784. package/packages/pi-ai/dist/providers/anthropic-auth.test.js.map +1 -1
  785. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.d.ts +2 -0
  786. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.d.ts.map +1 -0
  787. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.js +13 -0
  788. package/packages/pi-ai/dist/providers/anthropic-bearer-auth.test.js.map +1 -0
  789. package/packages/pi-ai/dist/providers/anthropic-shared.d.ts.map +1 -1
  790. package/packages/pi-ai/dist/providers/anthropic-shared.js +27 -4
  791. package/packages/pi-ai/dist/providers/anthropic-shared.js.map +1 -1
  792. package/packages/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  793. package/packages/pi-ai/dist/providers/anthropic.js +13 -4
  794. package/packages/pi-ai/dist/providers/anthropic.js.map +1 -1
  795. package/packages/pi-ai/dist/providers/minimax-tool-name.test.d.ts +2 -0
  796. package/packages/pi-ai/dist/providers/minimax-tool-name.test.d.ts.map +1 -0
  797. package/packages/pi-ai/dist/providers/minimax-tool-name.test.js +80 -0
  798. package/packages/pi-ai/dist/providers/minimax-tool-name.test.js.map +1 -0
  799. package/packages/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
  800. package/packages/pi-ai/dist/providers/openai-completions.js +60 -15
  801. package/packages/pi-ai/dist/providers/openai-completions.js.map +1 -1
  802. package/packages/pi-ai/dist/providers/simple-options.d.ts +10 -0
  803. package/packages/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  804. package/packages/pi-ai/dist/providers/simple-options.js +16 -1
  805. package/packages/pi-ai/dist/providers/simple-options.js.map +1 -1
  806. package/packages/pi-ai/dist/providers/think-tag-parser.d.ts +17 -0
  807. package/packages/pi-ai/dist/providers/think-tag-parser.d.ts.map +1 -0
  808. package/packages/pi-ai/dist/providers/think-tag-parser.js +75 -0
  809. package/packages/pi-ai/dist/providers/think-tag-parser.js.map +1 -0
  810. package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts +2 -0
  811. package/packages/pi-ai/dist/providers/think-tag-parser.test.d.ts.map +1 -0
  812. package/packages/pi-ai/dist/providers/think-tag-parser.test.js +41 -0
  813. package/packages/pi-ai/dist/providers/think-tag-parser.test.js.map +1 -0
  814. package/packages/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +1 -1
  815. package/packages/pi-ai/dist/utils/oauth/github-copilot.js +12 -2
  816. package/packages/pi-ai/dist/utils/oauth/github-copilot.js.map +1 -1
  817. package/packages/pi-ai/dist/utils/oauth/github-copilot.test.js +164 -14
  818. package/packages/pi-ai/dist/utils/oauth/github-copilot.test.js.map +1 -1
  819. package/packages/pi-ai/dist/utils/oauth/google-antigravity.d.ts.map +1 -1
  820. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js +15 -3
  821. package/packages/pi-ai/dist/utils/oauth/google-antigravity.js.map +1 -1
  822. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.d.ts +2 -0
  823. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.d.ts.map +1 -0
  824. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.js +67 -0
  825. package/packages/pi-ai/dist/utils/oauth/google-antigravity.test.js.map +1 -0
  826. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.d.ts.map +1 -1
  827. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js +16 -3
  828. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.js.map +1 -1
  829. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.d.ts +2 -0
  830. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.d.ts.map +1 -0
  831. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.js +67 -0
  832. package/packages/pi-ai/dist/utils/oauth/google-gemini-cli.test.js.map +1 -0
  833. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.d.ts +2 -0
  834. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.d.ts.map +1 -0
  835. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.js +289 -0
  836. package/packages/pi-ai/dist/utils/oauth/oauth-providers.test.js.map +1 -0
  837. package/packages/pi-ai/package.json +1 -1
  838. package/packages/pi-ai/src/models/custom.ts +42 -0
  839. package/packages/pi-ai/src/providers/anthropic-auth.test.ts +1 -1
  840. package/packages/pi-ai/src/providers/anthropic-bearer-auth.test.ts +26 -0
  841. package/packages/pi-ai/src/providers/anthropic-shared.ts +26 -5
  842. package/packages/pi-ai/src/providers/anthropic.ts +15 -4
  843. package/packages/pi-ai/src/providers/minimax-tool-name.test.ts +98 -0
  844. package/packages/pi-ai/src/providers/openai-completions.ts +57 -16
  845. package/packages/pi-ai/src/providers/simple-options.ts +17 -1
  846. package/packages/pi-ai/src/providers/think-tag-parser.test.ts +44 -0
  847. package/packages/pi-ai/src/providers/think-tag-parser.ts +94 -0
  848. package/packages/pi-ai/src/utils/oauth/github-copilot.test.ts +200 -23
  849. package/packages/pi-ai/src/utils/oauth/github-copilot.ts +12 -2
  850. package/packages/pi-ai/src/utils/oauth/google-antigravity.test.ts +84 -0
  851. package/packages/pi-ai/src/utils/oauth/google-antigravity.ts +15 -5
  852. package/packages/pi-ai/src/utils/oauth/google-gemini-cli.test.ts +84 -0
  853. package/packages/pi-ai/src/utils/oauth/google-gemini-cli.ts +16 -5
  854. package/packages/pi-ai/src/utils/oauth/oauth-providers.test.ts +363 -0
  855. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  856. package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js +3 -2
  857. package/packages/pi-coding-agent/dist/core/agent-session-abort-order.test.js.map +1 -1
  858. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +2 -0
  859. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  860. package/packages/pi-coding-agent/dist/core/agent-session.js +32 -2
  861. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  862. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts +1 -1
  863. package/packages/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
  864. package/packages/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
  865. package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  866. package/packages/pi-coding-agent/dist/core/extensions/loader.js +4 -0
  867. package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  868. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts +35 -2
  869. package/packages/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
  870. package/packages/pi-coding-agent/dist/core/extensions/runner.js +233 -0
  871. package/packages/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
  872. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts +205 -2
  873. package/packages/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  874. package/packages/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  875. package/packages/pi-coding-agent/dist/core/hooks-runner.d.ts +53 -0
  876. package/packages/pi-coding-agent/dist/core/hooks-runner.d.ts.map +1 -0
  877. package/packages/pi-coding-agent/dist/core/hooks-runner.js +337 -0
  878. package/packages/pi-coding-agent/dist/core/hooks-runner.js.map +1 -0
  879. package/packages/pi-coding-agent/dist/core/hooks-runner.test.d.ts +2 -0
  880. package/packages/pi-coding-agent/dist/core/hooks-runner.test.d.ts.map +1 -0
  881. package/packages/pi-coding-agent/dist/core/hooks-runner.test.js +234 -0
  882. package/packages/pi-coding-agent/dist/core/hooks-runner.test.js.map +1 -0
  883. package/packages/pi-coding-agent/dist/core/index.d.ts +1 -0
  884. package/packages/pi-coding-agent/dist/core/index.d.ts.map +1 -1
  885. package/packages/pi-coding-agent/dist/core/index.js +1 -0
  886. package/packages/pi-coding-agent/dist/core/index.js.map +1 -1
  887. package/packages/pi-coding-agent/dist/core/model-discovery.d.ts +3 -1
  888. package/packages/pi-coding-agent/dist/core/model-discovery.d.ts.map +1 -1
  889. package/packages/pi-coding-agent/dist/core/model-discovery.js +92 -12
  890. package/packages/pi-coding-agent/dist/core/model-discovery.js.map +1 -1
  891. package/packages/pi-coding-agent/dist/core/model-discovery.test.js +16 -1
  892. package/packages/pi-coding-agent/dist/core/model-discovery.test.js.map +1 -1
  893. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.d.ts +2 -0
  894. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.d.ts.map +1 -0
  895. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.js +40 -0
  896. package/packages/pi-coding-agent/dist/core/model-registry-auth-header.test.js.map +1 -0
  897. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.d.ts +2 -0
  898. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.d.ts.map +1 -0
  899. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.js +203 -0
  900. package/packages/pi-coding-agent/dist/core/model-registry-custom-caps.test.js.map +1 -0
  901. package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js +61 -1
  902. package/packages/pi-coding-agent/dist/core/model-registry-discovery.test.js.map +1 -1
  903. package/packages/pi-coding-agent/dist/core/model-registry.d.ts +5 -0
  904. package/packages/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  905. package/packages/pi-coding-agent/dist/core/model-registry.js +90 -10
  906. package/packages/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  907. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts +2 -0
  908. package/packages/pi-coding-agent/dist/core/redact-secrets.d.ts.map +1 -0
  909. package/packages/pi-coding-agent/dist/core/redact-secrets.js +49 -0
  910. package/packages/pi-coding-agent/dist/core/redact-secrets.js.map +1 -0
  911. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts +2 -0
  912. package/packages/pi-coding-agent/dist/core/redact-secrets.test.d.ts.map +1 -0
  913. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js +67 -0
  914. package/packages/pi-coding-agent/dist/core/redact-secrets.test.js.map +1 -0
  915. package/packages/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  916. package/packages/pi-coding-agent/dist/core/session-manager.js +10 -6
  917. package/packages/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  918. package/packages/pi-coding-agent/dist/core/session-manager.test.js +45 -1
  919. package/packages/pi-coding-agent/dist/core/session-manager.test.js.map +1 -1
  920. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts +55 -0
  921. package/packages/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  922. package/packages/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  923. package/packages/pi-coding-agent/dist/index.d.ts +1 -1
  924. package/packages/pi-coding-agent/dist/index.d.ts.map +1 -1
  925. package/packages/pi-coding-agent/dist/index.js.map +1 -1
  926. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts +1 -1
  927. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -1
  928. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +5 -4
  929. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -1
  930. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.d.ts.map +1 -1
  931. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js +13 -7
  932. package/packages/pi-coding-agent/dist/modes/interactive/components/provider-manager.js.map +1 -1
  933. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts +7 -6
  934. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  935. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +29 -21
  936. package/packages/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  937. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  938. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +13 -1
  939. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  940. package/packages/pi-coding-agent/package.json +1 -1
  941. package/packages/pi-coding-agent/src/core/agent-session-abort-order.test.ts +3 -2
  942. package/packages/pi-coding-agent/src/core/agent-session.ts +38 -2
  943. package/packages/pi-coding-agent/src/core/extensions/index.ts +16 -0
  944. package/packages/pi-coding-agent/src/core/extensions/loader.ts +5 -0
  945. package/packages/pi-coding-agent/src/core/extensions/runner.ts +351 -0
  946. package/packages/pi-coding-agent/src/core/extensions/types.ts +258 -0
  947. package/packages/pi-coding-agent/src/core/hooks-runner.test.ts +269 -0
  948. package/packages/pi-coding-agent/src/core/hooks-runner.ts +460 -0
  949. package/packages/pi-coding-agent/src/core/index.ts +10 -0
  950. package/packages/pi-coding-agent/src/core/model-discovery.test.ts +19 -0
  951. package/packages/pi-coding-agent/src/core/model-discovery.ts +99 -12
  952. package/packages/pi-coding-agent/src/core/model-registry-auth-header.test.ts +44 -0
  953. package/packages/pi-coding-agent/src/core/model-registry-custom-caps.test.ts +245 -0
  954. package/packages/pi-coding-agent/src/core/model-registry-discovery.test.ts +75 -0
  955. package/packages/pi-coding-agent/src/core/model-registry.ts +102 -10
  956. package/packages/pi-coding-agent/src/core/redact-secrets.test.ts +86 -0
  957. package/packages/pi-coding-agent/src/core/redact-secrets.ts +58 -0
  958. package/packages/pi-coding-agent/src/core/session-manager.test.ts +65 -1
  959. package/packages/pi-coding-agent/src/core/session-manager.ts +10 -6
  960. package/packages/pi-coding-agent/src/core/settings-manager.ts +57 -0
  961. package/packages/pi-coding-agent/src/index.ts +16 -0
  962. package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +6 -6
  963. package/packages/pi-coding-agent/src/modes/interactive/components/provider-manager.ts +16 -7
  964. package/packages/pi-coding-agent/src/modes/interactive/components/skill-invocation-message.ts +36 -22
  965. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +13 -1
  966. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  967. package/packages/pi-tui/package.json +1 -1
  968. package/packages/rpc-client/package.json +1 -1
  969. package/pkg/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  970. package/pkg/dist/core/export-html/ansi-to-html.js +1 -0
  971. package/pkg/dist/core/export-html/ansi-to-html.js.map +1 -1
  972. package/pkg/dist/core/export-html/index.d.ts +1 -1
  973. package/pkg/dist/core/export-html/index.d.ts.map +1 -1
  974. package/pkg/dist/core/export-html/index.js +39 -5
  975. package/pkg/dist/core/export-html/index.js.map +1 -1
  976. package/pkg/dist/core/export-html/tool-renderer.d.ts +2 -2
  977. package/pkg/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  978. package/pkg/dist/core/export-html/tool-renderer.js.map +1 -1
  979. package/pkg/package.json +1 -1
  980. package/scripts/ensure-workspace-builds.cjs +2 -0
  981. package/scripts/install.js +512 -0
  982. package/scripts/link-workspace-packages.cjs +3 -0
  983. package/scripts/postinstall.js +9 -178
  984. package/src/resources/agents/researcher.md +1 -1
  985. package/src/resources/extensions/async-jobs/async-bash-tool.ts +1 -1
  986. package/src/resources/extensions/aws-auth/index.ts +2 -1
  987. package/src/resources/extensions/bg-shell/bg-shell-lifecycle.ts +4 -7
  988. package/src/resources/extensions/bg-shell/index.ts +2 -1
  989. package/src/resources/extensions/bg-shell/process-manager.ts +2 -1
  990. package/src/resources/extensions/browser-tools/index.ts +2 -1
  991. package/src/resources/extensions/claude-code-cli/index.ts +1 -1
  992. package/src/resources/extensions/claude-code-cli/partial-builder.ts +115 -23
  993. package/src/resources/extensions/claude-code-cli/readiness.ts +32 -8
  994. package/src/resources/extensions/claude-code-cli/stream-adapter.ts +97 -26
  995. package/src/resources/extensions/claude-code-cli/tests/provider-registration.test.ts +27 -0
  996. package/src/resources/extensions/claude-code-cli/tests/stream-adapter.test.ts +176 -8
  997. package/src/resources/extensions/gsd/auto/loop-deps.ts +14 -0
  998. package/src/resources/extensions/gsd/auto/loop.ts +9 -0
  999. package/src/resources/extensions/gsd/auto/phases.ts +131 -10
  1000. package/src/resources/extensions/gsd/auto/run-unit.ts +40 -2
  1001. package/src/resources/extensions/gsd/auto/session.ts +35 -2
  1002. package/src/resources/extensions/gsd/auto-dispatch.ts +59 -16
  1003. package/src/resources/extensions/gsd/auto-model-selection.ts +71 -15
  1004. package/src/resources/extensions/gsd/auto-post-unit.ts +62 -3
  1005. package/src/resources/extensions/gsd/auto-prompts.ts +28 -1
  1006. package/src/resources/extensions/gsd/auto-recovery.ts +62 -1
  1007. package/src/resources/extensions/gsd/auto-start.ts +80 -74
  1008. package/src/resources/extensions/gsd/auto-verification.ts +33 -0
  1009. package/src/resources/extensions/gsd/auto-worktree.ts +62 -63
  1010. package/src/resources/extensions/gsd/auto.ts +73 -28
  1011. package/src/resources/extensions/gsd/blocked-models.ts +98 -0
  1012. package/src/resources/extensions/gsd/bootstrap/agent-end-recovery.ts +120 -1
  1013. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +40 -9
  1014. package/src/resources/extensions/gsd/bootstrap/exec-tools.ts +109 -0
  1015. package/src/resources/extensions/gsd/bootstrap/memory-tools.ts +5 -0
  1016. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +15 -0
  1017. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +54 -6
  1018. package/src/resources/extensions/gsd/bootstrap/system-context.ts +89 -26
  1019. package/src/resources/extensions/gsd/bootstrap/write-gate.ts +35 -2
  1020. package/src/resources/extensions/gsd/clean-root-preflight.ts +111 -0
  1021. package/src/resources/extensions/gsd/commands-extract-learnings.ts +55 -90
  1022. package/src/resources/extensions/gsd/commands-prefs-wizard.ts +898 -32
  1023. package/src/resources/extensions/gsd/compaction-snapshot.ts +165 -0
  1024. package/src/resources/extensions/gsd/complexity-classifier.ts +5 -3
  1025. package/src/resources/extensions/gsd/db-writer.ts +88 -17
  1026. package/src/resources/extensions/gsd/dispatch-guard.ts +44 -2
  1027. package/src/resources/extensions/gsd/doctor-git-checks.ts +23 -27
  1028. package/src/resources/extensions/gsd/doctor-providers.ts +59 -6
  1029. package/src/resources/extensions/gsd/ecosystem/gsd-extension-api.ts +2 -0
  1030. package/src/resources/extensions/gsd/error-classifier.ts +36 -3
  1031. package/src/resources/extensions/gsd/exec-history.ts +153 -0
  1032. package/src/resources/extensions/gsd/exec-sandbox.ts +326 -0
  1033. package/src/resources/extensions/gsd/gitignore.ts +1 -1
  1034. package/src/resources/extensions/gsd/gsd-db.ts +186 -23
  1035. package/src/resources/extensions/gsd/guided-flow.ts +223 -2
  1036. package/src/resources/extensions/gsd/health-widget.ts +3 -1
  1037. package/src/resources/extensions/gsd/hook-emitter.ts +188 -0
  1038. package/src/resources/extensions/gsd/init-wizard.ts +15 -1
  1039. package/src/resources/extensions/gsd/journal.ts +2 -1
  1040. package/src/resources/extensions/gsd/key-manager.ts +28 -0
  1041. package/src/resources/extensions/gsd/memory-backfill.ts +140 -0
  1042. package/src/resources/extensions/gsd/memory-store.ts +26 -0
  1043. package/src/resources/extensions/gsd/model-router.ts +42 -1
  1044. package/src/resources/extensions/gsd/pre-execution-checks.ts +46 -10
  1045. package/src/resources/extensions/gsd/preferences-types.ts +46 -0
  1046. package/src/resources/extensions/gsd/preferences-validation.ts +79 -0
  1047. package/src/resources/extensions/gsd/preferences.ts +17 -17
  1048. package/src/resources/extensions/gsd/prompt-loader.ts +30 -7
  1049. package/src/resources/extensions/gsd/prompts/complete-milestone.md +1 -1
  1050. package/src/resources/extensions/gsd/prompts/complete-slice.md +2 -2
  1051. package/src/resources/extensions/gsd/prompts/debug-diagnose.md +2 -0
  1052. package/src/resources/extensions/gsd/prompts/discuss-headless.md +8 -0
  1053. package/src/resources/extensions/gsd/prompts/discuss.md +29 -2
  1054. package/src/resources/extensions/gsd/prompts/execute-task.md +3 -2
  1055. package/src/resources/extensions/gsd/prompts/parallel-research-slices.md +5 -2
  1056. package/src/resources/extensions/gsd/prompts/plan-slice.md +1 -0
  1057. package/src/resources/extensions/gsd/prompts/research-slice.md +1 -0
  1058. package/src/resources/extensions/gsd/prompts/system.md +1 -0
  1059. package/src/resources/extensions/gsd/safety/evidence-collector.ts +119 -0
  1060. package/src/resources/extensions/gsd/safety/file-change-validator.ts +17 -4
  1061. package/src/resources/extensions/gsd/safety/safety-harness.ts +9 -0
  1062. package/src/resources/extensions/gsd/state.ts +45 -4
  1063. package/src/resources/extensions/gsd/tests/auto-loop.test.ts +188 -2
  1064. package/src/resources/extensions/gsd/tests/auto-model-selection.test.ts +95 -1
  1065. package/src/resources/extensions/gsd/tests/auto-paused-session-validation.test.ts +12 -0
  1066. package/src/resources/extensions/gsd/tests/auto-recovery.test.ts +122 -0
  1067. package/src/resources/extensions/gsd/tests/auto-start-bootstrap-await-3420.test.ts +141 -0
  1068. package/src/resources/extensions/gsd/tests/auto-start-clean-runtime-db-gated.test.ts +63 -0
  1069. package/src/resources/extensions/gsd/tests/auto-start-model-capture.test.ts +33 -3
  1070. package/src/resources/extensions/gsd/tests/auto-thinking-restore.test.ts +38 -0
  1071. package/src/resources/extensions/gsd/tests/auto-wrapup-inflight-guard.test.ts +23 -0
  1072. package/src/resources/extensions/gsd/tests/blocked-models.test.ts +98 -0
  1073. package/src/resources/extensions/gsd/tests/bundled-skill-triggers.test.ts +54 -0
  1074. package/src/resources/extensions/gsd/tests/clean-root-preflight.test.ts +186 -0
  1075. package/src/resources/extensions/gsd/tests/commands-extract-learnings.test.ts +68 -66
  1076. package/src/resources/extensions/gsd/tests/compaction-snapshot.test.ts +123 -0
  1077. package/src/resources/extensions/gsd/tests/complete-milestone-false-merge.test.ts +15 -0
  1078. package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +61 -1
  1079. package/src/resources/extensions/gsd/tests/complete-slice.test.ts +2 -2
  1080. package/src/resources/extensions/gsd/tests/complete-task.test.ts +2 -2
  1081. package/src/resources/extensions/gsd/tests/complexity-classifier.test.ts +3 -3
  1082. package/src/resources/extensions/gsd/tests/custom-engine-loop-integration.test.ts +2 -0
  1083. package/src/resources/extensions/gsd/tests/derive-state-db.test.ts +42 -0
  1084. package/src/resources/extensions/gsd/tests/derive-state-helpers.test.ts +8 -4
  1085. package/src/resources/extensions/gsd/tests/dispatch-complete-milestone-guard.test.ts +9 -9
  1086. package/src/resources/extensions/gsd/tests/dispatch-guard-summary-db-mismatch.test.ts +77 -0
  1087. package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +148 -3
  1088. package/src/resources/extensions/gsd/tests/double-merge-guard.test.ts +1 -1
  1089. package/src/resources/extensions/gsd/tests/ensure-db-open.test.ts +306 -1
  1090. package/src/resources/extensions/gsd/tests/escalation.test.ts +1 -1
  1091. package/src/resources/extensions/gsd/tests/exec-history.test.ts +237 -0
  1092. package/src/resources/extensions/gsd/tests/exec-sandbox.test.ts +210 -0
  1093. package/src/resources/extensions/gsd/tests/file-change-validator.test.ts +58 -0
  1094. package/src/resources/extensions/gsd/tests/flat-rate-routing-guard.test.ts +40 -9
  1095. package/src/resources/extensions/gsd/tests/freeform-decisions.test.ts +62 -0
  1096. package/src/resources/extensions/gsd/tests/gsd-db.test.ts +447 -1
  1097. package/src/resources/extensions/gsd/tests/init-wizard.test.ts +27 -0
  1098. package/src/resources/extensions/gsd/tests/integration/doctor-git-symlink-cwd.test.ts +11 -0
  1099. package/src/resources/extensions/gsd/tests/integration/doctor-git.test.ts +78 -0
  1100. package/src/resources/extensions/gsd/tests/integration/git-service.test.ts +1 -0
  1101. package/src/resources/extensions/gsd/tests/integration/gitignore-tracked-gsd.test.ts +1 -0
  1102. package/src/resources/extensions/gsd/tests/integration/idle-recovery.test.ts +30 -0
  1103. package/src/resources/extensions/gsd/tests/integration/worktree-e2e.test.ts +11 -0
  1104. package/src/resources/extensions/gsd/tests/interactive-routing-bypass.test.ts +1 -1
  1105. package/src/resources/extensions/gsd/tests/isolation-none-branch-guard.test.ts +1 -1
  1106. package/src/resources/extensions/gsd/tests/issue-4540-regressions.test.ts +288 -0
  1107. package/src/resources/extensions/gsd/tests/journal-integration.test.ts +37 -0
  1108. package/src/resources/extensions/gsd/tests/key-manager.test.ts +9 -0
  1109. package/src/resources/extensions/gsd/tests/load-memory-block.test.ts +36 -0
  1110. package/src/resources/extensions/gsd/tests/md-importer.test.ts +1 -1
  1111. package/src/resources/extensions/gsd/tests/memory-pressure-stuck-state.test.ts +12 -0
  1112. package/src/resources/extensions/gsd/tests/memory-store.test.ts +2 -2
  1113. package/src/resources/extensions/gsd/tests/milestone-status-authoritative.test.ts +3 -3
  1114. package/src/resources/extensions/gsd/tests/parallel-research-dispatch.test.ts +19 -0
  1115. package/src/resources/extensions/gsd/tests/plan-gate-failed-doctor-heal-hint.test.ts +37 -0
  1116. package/src/resources/extensions/gsd/tests/pre-exec-backtick-strip.test.ts +14 -0
  1117. package/src/resources/extensions/gsd/tests/pre-exec-gate-loop.test.ts +272 -0
  1118. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +356 -0
  1119. package/src/resources/extensions/gsd/tests/preferences.test.ts +110 -0
  1120. package/src/resources/extensions/gsd/tests/prefs-wizard-coverage.test.ts +44 -0
  1121. package/src/resources/extensions/gsd/tests/prompt-loader-extension-dir.test.ts +49 -0
  1122. package/src/resources/extensions/gsd/tests/provider-errors.test.ts +103 -4
  1123. package/src/resources/extensions/gsd/tests/ready-phrase-no-files-4573.test.ts +388 -0
  1124. package/src/resources/extensions/gsd/tests/restore-tools-after-discuss.test.ts +9 -3
  1125. package/src/resources/extensions/gsd/tests/resume-dispatch-worktree.test.ts +230 -0
  1126. package/src/resources/extensions/gsd/tests/safety-harness-false-positives.test.ts +205 -0
  1127. package/src/resources/extensions/gsd/tests/save-gate-result-render.test.ts +95 -0
  1128. package/src/resources/extensions/gsd/tests/schema-v21-sequence.test.ts +413 -0
  1129. package/src/resources/extensions/gsd/tests/session-start-footer.test.ts +32 -40
  1130. package/src/resources/extensions/gsd/tests/stash-queued-context-files.test.ts +56 -0
  1131. package/src/resources/extensions/gsd/tests/token-counter.test.ts +105 -1
  1132. package/src/resources/extensions/gsd/tests/tool-compatibility.test.ts +107 -0
  1133. package/src/resources/extensions/gsd/tests/uok-plan-v2-wiring.test.ts +23 -0
  1134. package/src/resources/extensions/gsd/tests/validate-milestone.test.ts +136 -8
  1135. package/src/resources/extensions/gsd/tests/workflow-tool-executors.test.ts +65 -2
  1136. package/src/resources/extensions/gsd/tests/worktree-db.test.ts +35 -0
  1137. package/src/resources/extensions/gsd/tests/worktree-journal-events.test.ts +6 -1
  1138. package/src/resources/extensions/gsd/tests/worktree-resolver.test.ts +78 -5
  1139. package/src/resources/extensions/gsd/tests/write-gate.test.ts +64 -0
  1140. package/src/resources/extensions/gsd/tests/zombie-gsd-state.test.ts +3 -1
  1141. package/src/resources/extensions/gsd/token-counter.ts +22 -5
  1142. package/src/resources/extensions/gsd/tools/complete-milestone.ts +15 -9
  1143. package/src/resources/extensions/gsd/tools/exec-search-tool.ts +81 -0
  1144. package/src/resources/extensions/gsd/tools/exec-tool.ts +183 -0
  1145. package/src/resources/extensions/gsd/tools/memory-tools.ts +31 -1
  1146. package/src/resources/extensions/gsd/tools/resume-tool.ts +40 -0
  1147. package/src/resources/extensions/gsd/uok/plan-v2.ts +26 -3
  1148. package/src/resources/extensions/gsd/workflow-logger.ts +4 -1
  1149. package/src/resources/extensions/gsd/workflow-mcp.ts +3 -0
  1150. package/src/resources/extensions/gsd/workflow-templates/spike.md +6 -0
  1151. package/src/resources/extensions/gsd/worktree-resolver.ts +54 -9
  1152. package/src/resources/extensions/mcp-client/index.ts +1 -1
  1153. package/src/resources/extensions/ollama/index.ts +3 -3
  1154. package/src/resources/extensions/ollama/ollama-chat-provider.ts +6 -18
  1155. package/src/resources/extensions/remote-questions/config.ts +15 -4
  1156. package/src/resources/extensions/search-the-web/command-search-provider.ts +5 -4
  1157. package/src/resources/extensions/search-the-web/index.ts +2 -1
  1158. package/src/resources/extensions/search-the-web/native-search.ts +48 -12
  1159. package/src/resources/extensions/shared/tests/format-utils.test.ts +5 -3
  1160. package/src/resources/extensions/universal-config/index.ts +1 -1
  1161. package/src/resources/skills/api-design/SKILL.md +190 -0
  1162. package/src/resources/skills/create-mcp-server/SKILL.md +121 -0
  1163. package/src/resources/skills/decompose-into-slices/SKILL.md +139 -0
  1164. package/src/resources/skills/dependency-upgrade/SKILL.md +158 -0
  1165. package/src/resources/skills/design-an-interface/SKILL.md +102 -0
  1166. package/src/resources/skills/forensics/SKILL.md +153 -0
  1167. package/src/resources/skills/grill-me/SKILL.md +93 -0
  1168. package/src/resources/skills/handoff/SKILL.md +121 -0
  1169. package/src/resources/skills/observability/SKILL.md +174 -0
  1170. package/src/resources/skills/security-review/SKILL.md +181 -0
  1171. package/src/resources/skills/spike-wrap-up/SKILL.md +138 -0
  1172. package/src/resources/skills/tdd/SKILL.md +112 -0
  1173. package/src/resources/skills/verify-before-complete/SKILL.md +98 -0
  1174. package/src/resources/skills/write-docs/SKILL.md +82 -0
  1175. package/src/resources/skills/write-milestone-brief/SKILL.md +135 -0
  1176. package/dist/web/standalone/.next/static/chunks/2826.e59e8578e2e28639.js +0 -9
  1177. package/dist/web/standalone/.next/static/chunks/app/page-151349214571e2b6.js +0 -1
  1178. package/dist/web/standalone/.next/static/chunks/main-app-d3d4c336195465f9.js +0 -1
  1179. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/global-error-ab5a8926e07ec673.js +0 -1
  1180. package/packages/native/tsconfig.tsbuildinfo +0 -1
  1181. /package/dist/web/standalone/.next/static/{ssX7BLv3Dw9Fb4CtrCGeR → gy6_foLMsEzdGBT19c3hr}/_buildManifest.js +0 -0
  1182. /package/dist/web/standalone/.next/static/{ssX7BLv3Dw9Fb4CtrCGeR → gy6_foLMsEzdGBT19c3hr}/_ssgManifest.js +0 -0
@@ -0,0 +1,1583 @@
1
+ (function() {
2
+ 'use strict';
3
+
4
+ // ============================================================
5
+ // DATA LOADING
6
+ // ============================================================
7
+
8
+ const base64 = document.getElementById('session-data').textContent;
9
+ const binary = atob(base64);
10
+ const bytes = new Uint8Array(binary.length);
11
+ for (let i = 0; i < binary.length; i++) {
12
+ bytes[i] = binary.charCodeAt(i);
13
+ }
14
+ const data = JSON.parse(new TextDecoder('utf-8').decode(bytes));
15
+ const { header, entries, leafId: defaultLeafId, systemPrompt, tools, renderedTools } = data;
16
+
17
+ // ============================================================
18
+ // URL PARAMETER HANDLING
19
+ // ============================================================
20
+
21
+ // Parse URL parameters for deep linking: leafId and targetId
22
+ // Check for injected params (when loaded in iframe via srcdoc) or use window.location
23
+ const injectedParams = document.querySelector('meta[name="pi-url-params"]');
24
+ const searchString = injectedParams ? injectedParams.content : window.location.search.substring(1);
25
+ const urlParams = new URLSearchParams(searchString);
26
+ const urlLeafId = urlParams.get('leafId');
27
+ const urlTargetId = urlParams.get('targetId');
28
+ // Use URL leafId if provided, otherwise fall back to session default
29
+ const leafId = urlLeafId || defaultLeafId;
30
+
31
+ // ============================================================
32
+ // DATA STRUCTURES
33
+ // ============================================================
34
+
35
+ // Entry lookup by ID
36
+ const byId = new Map();
37
+ for (const entry of entries) {
38
+ byId.set(entry.id, entry);
39
+ }
40
+
41
+ // Tool call lookup (toolCallId -> {name, arguments})
42
+ const toolCallMap = new Map();
43
+ for (const entry of entries) {
44
+ if (entry.type === 'message' && entry.message.role === 'assistant') {
45
+ const content = entry.message.content;
46
+ if (Array.isArray(content)) {
47
+ for (const block of content) {
48
+ if (block.type === 'toolCall') {
49
+ toolCallMap.set(block.id, { name: block.name, arguments: block.arguments });
50
+ }
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ // Label lookup (entryId -> label string)
57
+ // Labels are stored in 'label' entries that reference their target via targetId
58
+ const labelMap = new Map();
59
+ for (const entry of entries) {
60
+ if (entry.type === 'label' && entry.targetId && entry.label) {
61
+ labelMap.set(entry.targetId, entry.label);
62
+ }
63
+ }
64
+
65
+ // ============================================================
66
+ // TREE DATA PREPARATION (no DOM, pure data)
67
+ // ============================================================
68
+
69
+ /**
70
+ * Build tree structure from flat entries.
71
+ * Returns array of root nodes, each with { entry, children, label }.
72
+ */
73
+ function buildTree() {
74
+ const nodeMap = new Map();
75
+ const roots = [];
76
+
77
+ // Create nodes
78
+ for (const entry of entries) {
79
+ nodeMap.set(entry.id, {
80
+ entry,
81
+ children: [],
82
+ label: labelMap.get(entry.id)
83
+ });
84
+ }
85
+
86
+ // Build parent-child relationships
87
+ for (const entry of entries) {
88
+ const node = nodeMap.get(entry.id);
89
+ if (entry.parentId === null || entry.parentId === undefined || entry.parentId === entry.id) {
90
+ roots.push(node);
91
+ } else {
92
+ const parent = nodeMap.get(entry.parentId);
93
+ if (parent) {
94
+ parent.children.push(node);
95
+ } else {
96
+ roots.push(node);
97
+ }
98
+ }
99
+ }
100
+
101
+ // Sort children by timestamp
102
+ function sortChildren(node) {
103
+ node.children.sort((a, b) =>
104
+ new Date(a.entry.timestamp).getTime() - new Date(b.entry.timestamp).getTime()
105
+ );
106
+ node.children.forEach(sortChildren);
107
+ }
108
+ roots.forEach(sortChildren);
109
+
110
+ return roots;
111
+ }
112
+
113
+ /**
114
+ * Build set of entry IDs on path from root to target.
115
+ */
116
+ function buildActivePathIds(targetId) {
117
+ const ids = new Set();
118
+ let current = byId.get(targetId);
119
+ while (current) {
120
+ ids.add(current.id);
121
+ // Stop if no parent or self-referencing (root)
122
+ if (!current.parentId || current.parentId === current.id) {
123
+ break;
124
+ }
125
+ current = byId.get(current.parentId);
126
+ }
127
+ return ids;
128
+ }
129
+
130
+ /**
131
+ * Get array of entries from root to target (the conversation path).
132
+ */
133
+ function getPath(targetId) {
134
+ const path = [];
135
+ let current = byId.get(targetId);
136
+ while (current) {
137
+ path.unshift(current);
138
+ // Stop if no parent or self-referencing (root)
139
+ if (!current.parentId || current.parentId === current.id) {
140
+ break;
141
+ }
142
+ current = byId.get(current.parentId);
143
+ }
144
+ return path;
145
+ }
146
+
147
+ // Tree node lookup for finding leaves
148
+ let treeNodeMap = null;
149
+
150
+ /**
151
+ * Find the newest leaf node reachable from a given node.
152
+ * This allows clicking any node in a branch to show the full branch.
153
+ * Children are sorted by timestamp, so the newest is always last.
154
+ */
155
+ function findNewestLeaf(nodeId) {
156
+ // Build tree node map lazily
157
+ if (!treeNodeMap) {
158
+ treeNodeMap = new Map();
159
+ const tree = buildTree();
160
+ function mapNodes(node) {
161
+ treeNodeMap.set(node.entry.id, node);
162
+ node.children.forEach(mapNodes);
163
+ }
164
+ tree.forEach(mapNodes);
165
+ }
166
+
167
+ const node = treeNodeMap.get(nodeId);
168
+ if (!node) return nodeId;
169
+
170
+ // Follow the newest (last) child at each level
171
+ let current = node;
172
+ while (current.children.length > 0) {
173
+ current = current.children[current.children.length - 1];
174
+ }
175
+ return current.entry.id;
176
+ }
177
+
178
+ /**
179
+ * Flatten tree into list with indentation and connector info.
180
+ * Returns array of { node, indent, showConnector, isLast, gutters, isVirtualRootChild, multipleRoots }.
181
+ * Matches tree-selector.ts logic exactly.
182
+ */
183
+ function flattenTree(roots, activePathIds) {
184
+ const result = [];
185
+ const multipleRoots = roots.length > 1;
186
+
187
+ // Mark which subtrees contain the active leaf
188
+ const containsActive = new Map();
189
+ function markActive(node) {
190
+ let has = activePathIds.has(node.entry.id);
191
+ for (const child of node.children) {
192
+ if (markActive(child)) has = true;
193
+ }
194
+ containsActive.set(node, has);
195
+ return has;
196
+ }
197
+ roots.forEach(markActive);
198
+
199
+ // Stack: [node, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild]
200
+ const stack = [];
201
+
202
+ // Add roots (prioritize branch containing active leaf)
203
+ const orderedRoots = [...roots].sort((a, b) =>
204
+ Number(containsActive.get(b)) - Number(containsActive.get(a))
205
+ );
206
+ for (let i = orderedRoots.length - 1; i >= 0; i--) {
207
+ const isLast = i === orderedRoots.length - 1;
208
+ stack.push([orderedRoots[i], multipleRoots ? 1 : 0, multipleRoots, multipleRoots, isLast, [], multipleRoots]);
209
+ }
210
+
211
+ while (stack.length > 0) {
212
+ const [node, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild] = stack.pop();
213
+
214
+ result.push({ node, indent, showConnector, isLast, gutters, isVirtualRootChild, multipleRoots });
215
+
216
+ const children = node.children;
217
+ const multipleChildren = children.length > 1;
218
+
219
+ // Order children (active branch first)
220
+ const orderedChildren = [...children].sort((a, b) =>
221
+ Number(containsActive.get(b)) - Number(containsActive.get(a))
222
+ );
223
+
224
+ // Calculate child indent (matches tree-selector.ts)
225
+ let childIndent;
226
+ if (multipleChildren) {
227
+ // Parent branches: children get +1
228
+ childIndent = indent + 1;
229
+ } else if (justBranched && indent > 0) {
230
+ // First generation after a branch: +1 for visual grouping
231
+ childIndent = indent + 1;
232
+ } else {
233
+ // Single-child chain: stay flat
234
+ childIndent = indent;
235
+ }
236
+
237
+ // Build gutters for children
238
+ const connectorDisplayed = showConnector && !isVirtualRootChild;
239
+ const currentDisplayIndent = multipleRoots ? Math.max(0, indent - 1) : indent;
240
+ const connectorPosition = Math.max(0, currentDisplayIndent - 1);
241
+ const childGutters = connectorDisplayed
242
+ ? [...gutters, { position: connectorPosition, show: !isLast }]
243
+ : gutters;
244
+
245
+ // Add children in reverse order for stack
246
+ for (let i = orderedChildren.length - 1; i >= 0; i--) {
247
+ const childIsLast = i === orderedChildren.length - 1;
248
+ stack.push([orderedChildren[i], childIndent, multipleChildren, multipleChildren, childIsLast, childGutters, false]);
249
+ }
250
+ }
251
+
252
+ return result;
253
+ }
254
+
255
+ /**
256
+ * Build ASCII prefix string for tree node.
257
+ */
258
+ function buildTreePrefix(flatNode) {
259
+ const { indent, showConnector, isLast, gutters, isVirtualRootChild, multipleRoots } = flatNode;
260
+ const displayIndent = multipleRoots ? Math.max(0, indent - 1) : indent;
261
+ const connector = showConnector && !isVirtualRootChild ? (isLast ? '└─ ' : '├─ ') : '';
262
+ const connectorPosition = connector ? displayIndent - 1 : -1;
263
+
264
+ const totalChars = displayIndent * 3;
265
+ const prefixChars = [];
266
+ for (let i = 0; i < totalChars; i++) {
267
+ const level = Math.floor(i / 3);
268
+ const posInLevel = i % 3;
269
+
270
+ const gutter = gutters.find(g => g.position === level);
271
+ if (gutter) {
272
+ prefixChars.push(posInLevel === 0 ? (gutter.show ? '│' : ' ') : ' ');
273
+ } else if (connector && level === connectorPosition) {
274
+ if (posInLevel === 0) {
275
+ prefixChars.push(isLast ? '└' : '├');
276
+ } else if (posInLevel === 1) {
277
+ prefixChars.push('─');
278
+ } else {
279
+ prefixChars.push(' ');
280
+ }
281
+ } else {
282
+ prefixChars.push(' ');
283
+ }
284
+ }
285
+ return prefixChars.join('');
286
+ }
287
+
288
+ // ============================================================
289
+ // FILTERING (pure data)
290
+ // ============================================================
291
+
292
+ let filterMode = 'default';
293
+ let searchQuery = '';
294
+
295
+ function hasTextContent(content) {
296
+ if (typeof content === 'string') return content.trim().length > 0;
297
+ if (Array.isArray(content)) {
298
+ for (const c of content) {
299
+ if (c.type === 'text' && c.text && c.text.trim().length > 0) return true;
300
+ }
301
+ }
302
+ return false;
303
+ }
304
+
305
+ function extractContent(content) {
306
+ if (typeof content === 'string') return content;
307
+ if (Array.isArray(content)) {
308
+ return content
309
+ .filter(c => c.type === 'text' && c.text)
310
+ .map(c => c.text)
311
+ .join('');
312
+ }
313
+ return '';
314
+ }
315
+
316
+ function getSearchableText(entry, label) {
317
+ const parts = [];
318
+ if (label) parts.push(label);
319
+
320
+ switch (entry.type) {
321
+ case 'message': {
322
+ const msg = entry.message;
323
+ parts.push(msg.role);
324
+ if (msg.content) parts.push(extractContent(msg.content));
325
+ if (msg.role === 'bashExecution' && msg.command) parts.push(msg.command);
326
+ break;
327
+ }
328
+ case 'custom_message':
329
+ parts.push(entry.customType);
330
+ parts.push(typeof entry.content === 'string' ? entry.content : extractContent(entry.content));
331
+ break;
332
+ case 'compaction':
333
+ parts.push('compaction');
334
+ break;
335
+ case 'branch_summary':
336
+ parts.push('branch summary', entry.summary);
337
+ break;
338
+ case 'model_change':
339
+ parts.push('model', entry.modelId);
340
+ break;
341
+ case 'thinking_level_change':
342
+ parts.push('thinking', entry.thinkingLevel);
343
+ break;
344
+ }
345
+
346
+ return parts.join(' ').toLowerCase();
347
+ }
348
+
349
+ /**
350
+ * Filter flat nodes based on current filterMode and searchQuery.
351
+ */
352
+ function filterNodes(flatNodes, currentLeafId) {
353
+ const searchTokens = searchQuery.toLowerCase().split(/\s+/).filter(Boolean);
354
+
355
+ const filtered = flatNodes.filter(flatNode => {
356
+ const entry = flatNode.node.entry;
357
+ const label = flatNode.node.label;
358
+ const isCurrentLeaf = entry.id === currentLeafId;
359
+
360
+ // Always show current leaf
361
+ if (isCurrentLeaf) return true;
362
+
363
+ // Hide assistant messages with only tool calls (no text) unless error/aborted
364
+ if (entry.type === 'message' && entry.message.role === 'assistant') {
365
+ const msg = entry.message;
366
+ const hasText = hasTextContent(msg.content);
367
+ const isErrorOrAborted = msg.stopReason && msg.stopReason !== 'stop' && msg.stopReason !== 'toolUse';
368
+ if (!hasText && !isErrorOrAborted) return false;
369
+ }
370
+
371
+ // Apply filter mode
372
+ const isSettingsEntry = ['label', 'custom', 'model_change', 'thinking_level_change'].includes(entry.type);
373
+ let passesFilter = true;
374
+
375
+ switch (filterMode) {
376
+ case 'user-only':
377
+ passesFilter = entry.type === 'message' && entry.message.role === 'user';
378
+ break;
379
+ case 'no-tools':
380
+ passesFilter = !isSettingsEntry && !(entry.type === 'message' && entry.message.role === 'toolResult');
381
+ break;
382
+ case 'labeled-only':
383
+ passesFilter = label !== undefined;
384
+ break;
385
+ case 'all':
386
+ passesFilter = true;
387
+ break;
388
+ default: // 'default'
389
+ passesFilter = !isSettingsEntry;
390
+ break;
391
+ }
392
+
393
+ if (!passesFilter) return false;
394
+
395
+ // Apply search filter
396
+ if (searchTokens.length > 0) {
397
+ const nodeText = getSearchableText(entry, label);
398
+ if (!searchTokens.every(t => nodeText.includes(t))) return false;
399
+ }
400
+
401
+ return true;
402
+ });
403
+
404
+ // Recalculate visual structure based on visible tree
405
+ recalculateVisualStructure(filtered, flatNodes);
406
+
407
+ return filtered;
408
+ }
409
+
410
+ /**
411
+ * Recompute indentation/connectors for the filtered view
412
+ *
413
+ * Filtering can hide intermediate entries; descendants attach to the nearest visible ancestor.
414
+ * Keep indentation semantics aligned with flattenTree() so single-child chains don't drift right.
415
+ */
416
+ function recalculateVisualStructure(filteredNodes, allFlatNodes) {
417
+ if (filteredNodes.length === 0) return;
418
+
419
+ const visibleIds = new Set(filteredNodes.map(n => n.node.entry.id));
420
+
421
+ // Build entry map for parent lookup (using full tree)
422
+ const entryMap = new Map();
423
+ for (const flatNode of allFlatNodes) {
424
+ entryMap.set(flatNode.node.entry.id, flatNode);
425
+ }
426
+
427
+ // Find nearest visible ancestor for a node
428
+ function findVisibleAncestor(nodeId) {
429
+ let currentId = entryMap.get(nodeId)?.node.entry.parentId;
430
+ while (currentId != null) {
431
+ if (visibleIds.has(currentId)) {
432
+ return currentId;
433
+ }
434
+ currentId = entryMap.get(currentId)?.node.entry.parentId;
435
+ }
436
+ return null;
437
+ }
438
+
439
+ // Build visible tree structure
440
+ const visibleParent = new Map();
441
+ const visibleChildren = new Map();
442
+ visibleChildren.set(null, []); // root-level nodes
443
+
444
+ for (const flatNode of filteredNodes) {
445
+ const nodeId = flatNode.node.entry.id;
446
+ const ancestorId = findVisibleAncestor(nodeId);
447
+ visibleParent.set(nodeId, ancestorId);
448
+
449
+ if (!visibleChildren.has(ancestorId)) {
450
+ visibleChildren.set(ancestorId, []);
451
+ }
452
+ visibleChildren.get(ancestorId).push(nodeId);
453
+ }
454
+
455
+ // Update multipleRoots based on visible roots
456
+ const visibleRootIds = visibleChildren.get(null);
457
+ const multipleRoots = visibleRootIds.length > 1;
458
+
459
+ // Build a map for quick lookup: nodeId → FlatNode
460
+ const filteredNodeMap = new Map();
461
+ for (const flatNode of filteredNodes) {
462
+ filteredNodeMap.set(flatNode.node.entry.id, flatNode);
463
+ }
464
+
465
+ // DFS traversal of visible tree, applying same indentation rules as flattenTree()
466
+ // Stack items: [nodeId, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild]
467
+ const stack = [];
468
+
469
+ // Add visible roots in reverse order (to process in forward order via stack)
470
+ for (let i = visibleRootIds.length - 1; i >= 0; i--) {
471
+ const isLast = i === visibleRootIds.length - 1;
472
+ stack.push([
473
+ visibleRootIds[i],
474
+ multipleRoots ? 1 : 0,
475
+ multipleRoots,
476
+ multipleRoots,
477
+ isLast,
478
+ [],
479
+ multipleRoots
480
+ ]);
481
+ }
482
+
483
+ while (stack.length > 0) {
484
+ const [nodeId, indent, justBranched, showConnector, isLast, gutters, isVirtualRootChild] = stack.pop();
485
+
486
+ const flatNode = filteredNodeMap.get(nodeId);
487
+ if (!flatNode) continue;
488
+
489
+ // Update this node's visual properties
490
+ flatNode.indent = indent;
491
+ flatNode.showConnector = showConnector;
492
+ flatNode.isLast = isLast;
493
+ flatNode.gutters = gutters;
494
+ flatNode.isVirtualRootChild = isVirtualRootChild;
495
+ flatNode.multipleRoots = multipleRoots;
496
+
497
+ // Get visible children of this node
498
+ const children = visibleChildren.get(nodeId) || [];
499
+ const multipleChildren = children.length > 1;
500
+
501
+ // Calculate child indent using same rules as flattenTree():
502
+ // - Parent branches (multiple children): children get +1
503
+ // - Just branched and indent > 0: children get +1 for visual grouping
504
+ // - Single-child chain: stay flat
505
+ let childIndent;
506
+ if (multipleChildren) {
507
+ childIndent = indent + 1;
508
+ } else if (justBranched && indent > 0) {
509
+ childIndent = indent + 1;
510
+ } else {
511
+ childIndent = indent;
512
+ }
513
+
514
+ // Build gutters for children (same logic as flattenTree)
515
+ const connectorDisplayed = showConnector && !isVirtualRootChild;
516
+ const currentDisplayIndent = multipleRoots ? Math.max(0, indent - 1) : indent;
517
+ const connectorPosition = Math.max(0, currentDisplayIndent - 1);
518
+ const childGutters = connectorDisplayed
519
+ ? [...gutters, { position: connectorPosition, show: !isLast }]
520
+ : gutters;
521
+
522
+ // Add children in reverse order (to process in forward order via stack)
523
+ for (let i = children.length - 1; i >= 0; i--) {
524
+ const childIsLast = i === children.length - 1;
525
+ stack.push([
526
+ children[i],
527
+ childIndent,
528
+ multipleChildren,
529
+ multipleChildren,
530
+ childIsLast,
531
+ childGutters,
532
+ false
533
+ ]);
534
+ }
535
+ }
536
+ }
537
+
538
+ // ============================================================
539
+ // TREE DISPLAY TEXT (pure data -> string)
540
+ // ============================================================
541
+
542
+ function shortenPath(p) {
543
+ if (typeof p !== 'string') return '';
544
+ if (p.startsWith('/Users/')) {
545
+ const parts = p.split('/');
546
+ if (parts.length > 2) return '~' + p.slice(('/Users/' + parts[2]).length);
547
+ }
548
+ if (p.startsWith('/home/')) {
549
+ const parts = p.split('/');
550
+ if (parts.length > 2) return '~' + p.slice(('/home/' + parts[2]).length);
551
+ }
552
+ return p;
553
+ }
554
+
555
+ function formatToolCall(name, args) {
556
+ switch (name) {
557
+ case 'read': {
558
+ const path = shortenPath(String(args.path || args.file_path || ''));
559
+ const offset = args.offset;
560
+ const limit = args.limit;
561
+ let display = path;
562
+ if (offset !== undefined || limit !== undefined) {
563
+ const start = offset ?? 1;
564
+ const end = limit !== undefined ? start + limit - 1 : '';
565
+ display += `:${start}${end ? `-${end}` : ''}`;
566
+ }
567
+ return `[read: ${display}]`;
568
+ }
569
+ case 'write':
570
+ return `[write: ${shortenPath(String(args.path || args.file_path || ''))}]`;
571
+ case 'edit':
572
+ return `[edit: ${shortenPath(String(args.path || args.file_path || ''))}]`;
573
+ case 'bash': {
574
+ const rawCmd = String(args.command || '');
575
+ const cmd = rawCmd.replace(/[\n\t]/g, ' ').trim().slice(0, 50);
576
+ return `[bash: ${cmd}${rawCmd.length > 50 ? '...' : ''}]`;
577
+ }
578
+ case 'grep':
579
+ return `[grep: /${args.pattern || ''}/ in ${shortenPath(String(args.path || '.'))}]`;
580
+ case 'find':
581
+ return `[find: ${args.pattern || ''} in ${shortenPath(String(args.path || '.'))}]`;
582
+ case 'ls':
583
+ return `[ls: ${shortenPath(String(args.path || '.'))}]`;
584
+ default: {
585
+ const argsStr = JSON.stringify(args).slice(0, 40);
586
+ return `[${name}: ${argsStr}${JSON.stringify(args).length > 40 ? '...' : ''}]`;
587
+ }
588
+ }
589
+ }
590
+
591
+ function escapeHtml(text) {
592
+ const div = document.createElement('div');
593
+ div.textContent = text;
594
+ return div.innerHTML;
595
+ }
596
+
597
+ /**
598
+ * Truncate string to maxLen chars, append "..." if truncated.
599
+ */
600
+ function truncate(s, maxLen = 100) {
601
+ if (s.length <= maxLen) return s;
602
+ return s.slice(0, maxLen) + '...';
603
+ }
604
+
605
+ /**
606
+ * Get display text for tree node (returns HTML string).
607
+ */
608
+ function getTreeNodeDisplayHtml(entry, label) {
609
+ const normalize = s => s.replace(/[\n\t]/g, ' ').trim();
610
+ const labelHtml = label ? `<span class="tree-label">[${escapeHtml(label)}]</span> ` : '';
611
+
612
+ switch (entry.type) {
613
+ case 'message': {
614
+ const msg = entry.message;
615
+ if (msg.role === 'user') {
616
+ const content = truncate(normalize(extractContent(msg.content)));
617
+ return labelHtml + `<span class="tree-role-user">user:</span> ${escapeHtml(content)}`;
618
+ }
619
+ if (msg.role === 'assistant') {
620
+ const textContent = truncate(normalize(extractContent(msg.content)));
621
+ if (textContent) {
622
+ return labelHtml + `<span class="tree-role-assistant">assistant:</span> ${escapeHtml(textContent)}`;
623
+ }
624
+ if (msg.stopReason === 'aborted') {
625
+ return labelHtml + `<span class="tree-role-assistant">assistant:</span> <span class="tree-muted">(aborted)</span>`;
626
+ }
627
+ if (msg.errorMessage) {
628
+ return labelHtml + `<span class="tree-role-assistant">assistant:</span> <span class="tree-error">${escapeHtml(truncate(msg.errorMessage))}</span>`;
629
+ }
630
+ return labelHtml + `<span class="tree-role-assistant">assistant:</span> <span class="tree-muted">(no text)</span>`;
631
+ }
632
+ if (msg.role === 'toolResult') {
633
+ const toolCall = msg.toolCallId ? toolCallMap.get(msg.toolCallId) : null;
634
+ if (toolCall) {
635
+ return labelHtml + `<span class="tree-role-tool">${escapeHtml(formatToolCall(toolCall.name, toolCall.arguments))}</span>`;
636
+ }
637
+ return labelHtml + `<span class="tree-role-tool">[${msg.toolName || 'tool'}]</span>`;
638
+ }
639
+ if (msg.role === 'bashExecution') {
640
+ const cmd = truncate(normalize(msg.command || ''));
641
+ return labelHtml + `<span class="tree-role-tool">[bash]:</span> ${escapeHtml(cmd)}`;
642
+ }
643
+ return labelHtml + `<span class="tree-muted">[${msg.role}]</span>`;
644
+ }
645
+ case 'compaction':
646
+ return labelHtml + `<span class="tree-compaction">[compaction: ${Math.round(entry.tokensBefore/1000)}k tokens]</span>`;
647
+ case 'branch_summary': {
648
+ const summary = truncate(normalize(entry.summary || ''));
649
+ return labelHtml + `<span class="tree-branch-summary">[branch summary]:</span> ${escapeHtml(summary)}`;
650
+ }
651
+ case 'custom_message': {
652
+ const content = typeof entry.content === 'string' ? entry.content : extractContent(entry.content);
653
+ return labelHtml + `<span class="tree-custom">[${escapeHtml(entry.customType)}]:</span> ${escapeHtml(truncate(normalize(content)))}`;
654
+ }
655
+ case 'model_change':
656
+ return labelHtml + `<span class="tree-muted">[model: ${entry.modelId}]</span>`;
657
+ case 'thinking_level_change':
658
+ return labelHtml + `<span class="tree-muted">[thinking: ${entry.thinkingLevel}]</span>`;
659
+ default:
660
+ return labelHtml + `<span class="tree-muted">[${entry.type}]</span>`;
661
+ }
662
+ }
663
+
664
+ // ============================================================
665
+ // TREE RENDERING (DOM manipulation)
666
+ // ============================================================
667
+
668
+ let currentLeafId = leafId;
669
+ let currentTargetId = urlTargetId || leafId;
670
+ let treeRendered = false;
671
+
672
+ function renderTree() {
673
+ const tree = buildTree();
674
+ const activePathIds = buildActivePathIds(currentLeafId);
675
+ const flatNodes = flattenTree(tree, activePathIds);
676
+ const filtered = filterNodes(flatNodes, currentLeafId);
677
+ const container = document.getElementById('tree-container');
678
+
679
+ // Full render only on first call or when filter/search changes
680
+ if (!treeRendered) {
681
+ container.innerHTML = '';
682
+
683
+ for (const flatNode of filtered) {
684
+ const entry = flatNode.node.entry;
685
+ const isOnPath = activePathIds.has(entry.id);
686
+ const isTarget = entry.id === currentTargetId;
687
+
688
+ const div = document.createElement('div');
689
+ div.className = 'tree-node';
690
+ if (isOnPath) div.classList.add('in-path');
691
+ if (isTarget) div.classList.add('active');
692
+ div.dataset.id = entry.id;
693
+
694
+ const prefix = buildTreePrefix(flatNode);
695
+ const prefixSpan = document.createElement('span');
696
+ prefixSpan.className = 'tree-prefix';
697
+ prefixSpan.textContent = prefix;
698
+
699
+ const marker = document.createElement('span');
700
+ marker.className = 'tree-marker';
701
+ marker.textContent = isOnPath ? '•' : ' ';
702
+
703
+ const content = document.createElement('span');
704
+ content.className = 'tree-content';
705
+ content.innerHTML = getTreeNodeDisplayHtml(entry, flatNode.node.label);
706
+
707
+ div.appendChild(prefixSpan);
708
+ div.appendChild(marker);
709
+ div.appendChild(content);
710
+ // Navigate to the newest leaf through this node, but scroll to the clicked node
711
+ div.addEventListener('click', () => {
712
+ const leafId = findNewestLeaf(entry.id);
713
+ navigateTo(leafId, 'target', entry.id);
714
+ });
715
+
716
+ container.appendChild(div);
717
+ }
718
+
719
+ treeRendered = true;
720
+ } else {
721
+ // Just update markers and classes
722
+ const nodes = container.querySelectorAll('.tree-node');
723
+ for (const node of nodes) {
724
+ const id = node.dataset.id;
725
+ const isOnPath = activePathIds.has(id);
726
+ const isTarget = id === currentTargetId;
727
+
728
+ node.classList.toggle('in-path', isOnPath);
729
+ node.classList.toggle('active', isTarget);
730
+
731
+ const marker = node.querySelector('.tree-marker');
732
+ if (marker) {
733
+ marker.textContent = isOnPath ? '•' : ' ';
734
+ }
735
+ }
736
+ }
737
+
738
+ document.getElementById('tree-status').textContent = `${filtered.length} / ${flatNodes.length} entries`;
739
+
740
+ // Scroll active node into view after layout
741
+ setTimeout(() => {
742
+ const activeNode = container.querySelector('.tree-node.active');
743
+ if (activeNode) {
744
+ activeNode.scrollIntoView({ block: 'nearest' });
745
+ }
746
+ }, 0);
747
+ }
748
+
749
+ function forceTreeRerender() {
750
+ treeRendered = false;
751
+ renderTree();
752
+ }
753
+
754
+ // ============================================================
755
+ // MESSAGE RENDERING
756
+ // ============================================================
757
+
758
+ function formatTokens(count) {
759
+ if (count < 1000) return count.toString();
760
+ if (count < 10000) return (count / 1000).toFixed(1) + 'k';
761
+ if (count < 1000000) return Math.round(count / 1000) + 'k';
762
+ return (count / 1000000).toFixed(1) + 'M';
763
+ }
764
+
765
+ function formatTimestamp(ts) {
766
+ if (!ts) return '';
767
+ const date = new Date(ts);
768
+ return date.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit' });
769
+ }
770
+
771
+ function replaceTabs(text) {
772
+ return text.replace(/\t/g, ' ');
773
+ }
774
+
775
+ /** Safely coerce value to string for display. Returns null if invalid type. */
776
+ function str(value) {
777
+ if (typeof value === 'string') return value;
778
+ if (value == null) return '';
779
+ return null;
780
+ }
781
+
782
+ function getLanguageFromPath(filePath) {
783
+ const ext = filePath.split('.').pop()?.toLowerCase();
784
+ const extToLang = {
785
+ ts: 'typescript', tsx: 'typescript', js: 'javascript', jsx: 'javascript',
786
+ py: 'python', rb: 'ruby', rs: 'rust', go: 'go', java: 'java',
787
+ c: 'c', cpp: 'cpp', h: 'c', hpp: 'cpp', cs: 'csharp',
788
+ php: 'php', sh: 'bash', bash: 'bash', zsh: 'bash',
789
+ sql: 'sql', html: 'html', css: 'css', scss: 'scss',
790
+ json: 'json', yaml: 'yaml', yml: 'yaml', xml: 'xml',
791
+ md: 'markdown', dockerfile: 'dockerfile'
792
+ };
793
+ return extToLang[ext];
794
+ }
795
+
796
+ function findToolResult(toolCallId) {
797
+ for (const entry of entries) {
798
+ if (entry.type === 'message' && entry.message.role === 'toolResult') {
799
+ if (entry.message.toolCallId === toolCallId) {
800
+ return entry.message;
801
+ }
802
+ }
803
+ }
804
+ return null;
805
+ }
806
+
807
+ function formatExpandableOutput(text, maxLines, lang) {
808
+ text = replaceTabs(text);
809
+ const lines = text.split('\n');
810
+ const displayLines = lines.slice(0, maxLines);
811
+ const remaining = lines.length - maxLines;
812
+
813
+ if (lang) {
814
+ let highlighted;
815
+ try {
816
+ highlighted = hljs.highlight(text, { language: lang }).value;
817
+ } catch {
818
+ highlighted = escapeHtml(text);
819
+ }
820
+
821
+ if (remaining > 0) {
822
+ const previewCode = displayLines.join('\n');
823
+ let previewHighlighted;
824
+ try {
825
+ previewHighlighted = hljs.highlight(previewCode, { language: lang }).value;
826
+ } catch {
827
+ previewHighlighted = escapeHtml(previewCode);
828
+ }
829
+
830
+ return `<div class="tool-output expandable" onclick="this.classList.toggle('expanded')">
831
+ <div class="output-preview"><pre><code class="hljs">${previewHighlighted}</code></pre>
832
+ <div class="expand-hint">... (${remaining} more lines)</div></div>
833
+ <div class="output-full"><pre><code class="hljs">${highlighted}</code></pre></div></div>`;
834
+ }
835
+
836
+ return `<div class="tool-output"><pre><code class="hljs">${highlighted}</code></pre></div>`;
837
+ }
838
+
839
+ // Plain text output
840
+ if (remaining > 0) {
841
+ let out = '<div class="tool-output expandable" onclick="this.classList.toggle(\'expanded\')">';
842
+ out += '<div class="output-preview">';
843
+ for (const line of displayLines) {
844
+ out += `<div>${escapeHtml(replaceTabs(line))}</div>`;
845
+ }
846
+ out += `<div class="expand-hint">... (${remaining} more lines)</div></div>`;
847
+ out += '<div class="output-full">';
848
+ for (const line of lines) {
849
+ out += `<div>${escapeHtml(replaceTabs(line))}</div>`;
850
+ }
851
+ out += '</div></div>';
852
+ return out;
853
+ }
854
+
855
+ let out = '<div class="tool-output">';
856
+ for (const line of displayLines) {
857
+ out += `<div>${escapeHtml(replaceTabs(line))}</div>`;
858
+ }
859
+ out += '</div>';
860
+ return out;
861
+ }
862
+
863
+ function renderToolCall(call) {
864
+ const result = findToolResult(call.id);
865
+ const isError = result?.isError || false;
866
+ const statusClass = result ? (isError ? 'error' : 'success') : 'pending';
867
+
868
+ const getResultText = () => {
869
+ if (!result) return '';
870
+ const textBlocks = result.content.filter(c => c.type === 'text');
871
+ return textBlocks.map(c => c.text).join('\n');
872
+ };
873
+
874
+ const getResultImages = () => {
875
+ if (!result) return [];
876
+ return result.content.filter(c => c.type === 'image');
877
+ };
878
+
879
+ const renderResultImages = () => {
880
+ const images = getResultImages();
881
+ if (images.length === 0) return '';
882
+ return '<div class="tool-images">' +
883
+ images.map(img => `<img src="data:${img.mimeType};base64,${img.data}" class="tool-image" />`).join('') +
884
+ '</div>';
885
+ };
886
+
887
+ let html = `<div class="tool-execution ${statusClass}">`;
888
+ const args = call.arguments || {};
889
+ const name = call.name;
890
+
891
+ const invalidArg = '<span class="tool-error">[invalid arg]</span>';
892
+
893
+ switch (name) {
894
+ case 'bash': {
895
+ const command = str(args.command);
896
+ const cmdDisplay = command === null ? invalidArg : escapeHtml(command || '...');
897
+ html += `<div class="tool-command">$ ${cmdDisplay}</div>`;
898
+ if (result) {
899
+ const output = getResultText().trim();
900
+ if (output) html += formatExpandableOutput(output, 5);
901
+ }
902
+ break;
903
+ }
904
+ case 'read': {
905
+ const filePath = str(args.file_path ?? args.path);
906
+ const offset = args.offset;
907
+ const limit = args.limit;
908
+
909
+ let pathHtml = filePath === null ? invalidArg : escapeHtml(shortenPath(filePath || ''));
910
+ if (filePath !== null && (offset !== undefined || limit !== undefined)) {
911
+ const startLine = offset ?? 1;
912
+ const endLine = limit !== undefined ? startLine + limit - 1 : '';
913
+ pathHtml += `<span class="line-numbers">:${startLine}${endLine ? '-' + endLine : ''}</span>`;
914
+ }
915
+
916
+ html += `<div class="tool-header"><span class="tool-name">read</span> <span class="tool-path">${pathHtml}</span></div>`;
917
+ if (result) {
918
+ html += renderResultImages();
919
+ const output = getResultText();
920
+ const lang = filePath ? getLanguageFromPath(filePath) : null;
921
+ if (output) html += formatExpandableOutput(output, 10, lang);
922
+ }
923
+ break;
924
+ }
925
+ case 'write': {
926
+ const filePath = str(args.file_path ?? args.path);
927
+ const content = str(args.content);
928
+
929
+ html += `<div class="tool-header"><span class="tool-name">write</span> <span class="tool-path">${filePath === null ? invalidArg : escapeHtml(shortenPath(filePath || ''))}</span>`;
930
+ if (content !== null && content) {
931
+ const lines = content.split('\n');
932
+ if (lines.length > 10) html += ` <span class="line-count">(${lines.length} lines)</span>`;
933
+ }
934
+ html += '</div>';
935
+
936
+ if (content === null) {
937
+ html += `<div class="tool-error">[invalid content arg - expected string]</div>`;
938
+ } else if (content) {
939
+ const lang = filePath ? getLanguageFromPath(filePath) : null;
940
+ html += formatExpandableOutput(content, 10, lang);
941
+ }
942
+ if (result) {
943
+ const output = getResultText().trim();
944
+ if (output) html += `<div class="tool-output"><div>${escapeHtml(output)}</div></div>`;
945
+ }
946
+ break;
947
+ }
948
+ case 'edit': {
949
+ const filePath = str(args.file_path ?? args.path);
950
+ html += `<div class="tool-header"><span class="tool-name">edit</span> <span class="tool-path">${filePath === null ? invalidArg : escapeHtml(shortenPath(filePath || ''))}</span></div>`;
951
+
952
+ if (result?.details?.diff) {
953
+ const diffLines = result.details.diff.split('\n');
954
+ html += '<div class="tool-diff">';
955
+ for (const line of diffLines) {
956
+ const cls = line.match(/^\+/) ? 'diff-added' : line.match(/^-/) ? 'diff-removed' : 'diff-context';
957
+ html += `<div class="${cls}">${escapeHtml(replaceTabs(line))}</div>`;
958
+ }
959
+ html += '</div>';
960
+ } else if (result) {
961
+ const output = getResultText().trim();
962
+ if (output) html += `<div class="tool-output"><pre>${escapeHtml(output)}</pre></div>`;
963
+ }
964
+ break;
965
+ }
966
+ default: {
967
+ // Check for pre-rendered custom tool HTML
968
+ const rendered = renderedTools?.[call.id];
969
+ if (rendered?.callHtml || rendered?.resultHtmlCollapsed || rendered?.resultHtmlExpanded) {
970
+ // Custom tool with pre-rendered HTML from TUI renderer
971
+ if (rendered.callHtml) {
972
+ html += `<div class="tool-header ansi-rendered">${rendered.callHtml}</div>`;
973
+ } else {
974
+ html += `<div class="tool-header"><span class="tool-name">${escapeHtml(name)}</span></div>`;
975
+ }
976
+
977
+ if (rendered.resultHtmlCollapsed && rendered.resultHtmlExpanded && rendered.resultHtmlCollapsed !== rendered.resultHtmlExpanded) {
978
+ // Both collapsed and expanded differ - render expandable section
979
+ html += `<div class="tool-output expandable ansi-rendered" onclick="this.classList.toggle('expanded')">
980
+ <div class="output-preview">${rendered.resultHtmlCollapsed}</div>
981
+ <div class="output-full">${rendered.resultHtmlExpanded}</div>
982
+ </div>`;
983
+ } else if (rendered.resultHtmlExpanded) {
984
+ // Only expanded exists (or collapsed is identical) - show directly
985
+ html += `<div class="tool-output ansi-rendered">${rendered.resultHtmlExpanded}</div>`;
986
+ } else if (result) {
987
+ // No pre-rendered result HTML - fallback to JSON
988
+ const output = getResultText();
989
+ if (output) html += formatExpandableOutput(output, 10);
990
+ }
991
+ } else {
992
+ // Fallback to JSON display (existing behavior)
993
+ html += `<div class="tool-header"><span class="tool-name">${escapeHtml(name)}</span></div>`;
994
+ html += `<div class="tool-output"><pre>${escapeHtml(JSON.stringify(args, null, 2))}</pre></div>`;
995
+ if (result) {
996
+ const output = getResultText();
997
+ if (output) html += formatExpandableOutput(output, 10);
998
+ }
999
+ }
1000
+ }
1001
+ }
1002
+
1003
+ html += '</div>';
1004
+ return html;
1005
+ }
1006
+
1007
+ /**
1008
+ * Download the session data as a JSONL file.
1009
+ * Reconstructs the original format: header line + entry lines.
1010
+ */
1011
+ window.downloadSessionJson = function() {
1012
+ // Build JSONL content: header first, then all entries
1013
+ const lines = [];
1014
+ if (header) {
1015
+ lines.push(JSON.stringify({ type: 'header', ...header }));
1016
+ }
1017
+ for (const entry of entries) {
1018
+ lines.push(JSON.stringify(entry));
1019
+ }
1020
+ const jsonlContent = lines.join('\n');
1021
+
1022
+ // Create download
1023
+ const blob = new Blob([jsonlContent], { type: 'application/x-ndjson' });
1024
+ const url = URL.createObjectURL(blob);
1025
+ const a = document.createElement('a');
1026
+ a.href = url;
1027
+ a.download = `${header?.id || 'session'}.jsonl`;
1028
+ document.body.appendChild(a);
1029
+ a.click();
1030
+ document.body.removeChild(a);
1031
+ URL.revokeObjectURL(url);
1032
+ }
1033
+
1034
+ /**
1035
+ * Build a shareable URL for a specific message.
1036
+ * URL format: base?gistId&leafId=<leafId>&targetId=<entryId>
1037
+ */
1038
+ function buildShareUrl(entryId) {
1039
+ // Check for injected base URL (used when loaded in iframe via srcdoc)
1040
+ const baseUrlMeta = document.querySelector('meta[name="pi-share-base-url"]');
1041
+ const baseUrl = baseUrlMeta ? baseUrlMeta.content : window.location.href.split('?')[0];
1042
+
1043
+ const url = new URL(window.location.href);
1044
+ // Find the gist ID (first query param without value, e.g., ?abc123)
1045
+ const gistId = Array.from(url.searchParams.keys()).find(k => !url.searchParams.get(k));
1046
+
1047
+ // Build the share URL
1048
+ const params = new URLSearchParams();
1049
+ params.set('leafId', currentLeafId);
1050
+ params.set('targetId', entryId);
1051
+
1052
+ // If we have an injected base URL (iframe context), use it directly
1053
+ if (baseUrlMeta) {
1054
+ return `${baseUrl}&${params.toString()}`;
1055
+ }
1056
+
1057
+ // Otherwise build from current location (direct file access)
1058
+ url.search = gistId ? `?${gistId}&${params.toString()}` : `?${params.toString()}`;
1059
+ return url.toString();
1060
+ }
1061
+
1062
+ /**
1063
+ * Copy text to clipboard with visual feedback.
1064
+ * Uses navigator.clipboard with fallback to execCommand for HTTP contexts.
1065
+ */
1066
+ async function copyToClipboard(text, button) {
1067
+ let success = false;
1068
+ try {
1069
+ if (navigator.clipboard && navigator.clipboard.writeText) {
1070
+ await navigator.clipboard.writeText(text);
1071
+ success = true;
1072
+ }
1073
+ } catch (err) {
1074
+ // Clipboard API failed, try fallback
1075
+ }
1076
+
1077
+ // Fallback for HTTP or when Clipboard API is unavailable
1078
+ if (!success) {
1079
+ try {
1080
+ const textarea = document.createElement('textarea');
1081
+ textarea.value = text;
1082
+ textarea.style.position = 'fixed';
1083
+ textarea.style.opacity = '0';
1084
+ document.body.appendChild(textarea);
1085
+ textarea.select();
1086
+ success = document.execCommand('copy');
1087
+ document.body.removeChild(textarea);
1088
+ } catch (err) {
1089
+ console.error('Failed to copy:', err);
1090
+ }
1091
+ }
1092
+
1093
+ if (success && button) {
1094
+ const originalHtml = button.innerHTML;
1095
+ button.innerHTML = '✓';
1096
+ button.classList.add('copied');
1097
+ setTimeout(() => {
1098
+ button.innerHTML = originalHtml;
1099
+ button.classList.remove('copied');
1100
+ }, 1500);
1101
+ }
1102
+ }
1103
+
1104
+ /**
1105
+ * Render the copy-link button HTML for a message.
1106
+ */
1107
+ function renderCopyLinkButton(entryId) {
1108
+ return `<button class="copy-link-btn" data-entry-id="${entryId}" title="Copy link to this message">
1109
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
1110
+ <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/>
1111
+ <path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>
1112
+ </svg>
1113
+ </button>`;
1114
+ }
1115
+
1116
+ function renderEntry(entry) {
1117
+ const ts = formatTimestamp(entry.timestamp);
1118
+ const tsHtml = ts ? `<div class="message-timestamp">${ts}</div>` : '';
1119
+ const entryId = `entry-${entry.id}`;
1120
+ const copyBtnHtml = renderCopyLinkButton(entry.id);
1121
+
1122
+ if (entry.type === 'message') {
1123
+ const msg = entry.message;
1124
+
1125
+ if (msg.role === 'user') {
1126
+ let html = `<div class="user-message" id="${entryId}">${copyBtnHtml}${tsHtml}`;
1127
+ const content = msg.content;
1128
+
1129
+ if (Array.isArray(content)) {
1130
+ const images = content.filter(c => c.type === 'image');
1131
+ if (images.length > 0) {
1132
+ html += '<div class="message-images">';
1133
+ for (const img of images) {
1134
+ html += `<img src="data:${img.mimeType};base64,${img.data}" class="message-image" />`;
1135
+ }
1136
+ html += '</div>';
1137
+ }
1138
+ }
1139
+
1140
+ const text = typeof content === 'string' ? content :
1141
+ content.filter(c => c.type === 'text').map(c => c.text).join('\n');
1142
+ if (text.trim()) {
1143
+ html += `<div class="markdown-content">${safeMarkedParse(text)}</div>`;
1144
+ }
1145
+ html += '</div>';
1146
+ return html;
1147
+ }
1148
+
1149
+ if (msg.role === 'assistant') {
1150
+ let html = `<div class="assistant-message" id="${entryId}">${copyBtnHtml}${tsHtml}`;
1151
+
1152
+ for (const block of msg.content) {
1153
+ if (block.type === 'text' && block.text.trim()) {
1154
+ html += `<div class="assistant-text markdown-content">${safeMarkedParse(block.text)}</div>`;
1155
+ } else if (block.type === 'thinking' && block.thinking.trim()) {
1156
+ html += `<div class="thinking-block">
1157
+ <div class="thinking-text">${escapeHtml(block.thinking)}</div>
1158
+ <div class="thinking-collapsed">Thinking ...</div>
1159
+ </div>`;
1160
+ }
1161
+ }
1162
+
1163
+ for (const block of msg.content) {
1164
+ if (block.type === 'toolCall') {
1165
+ html += renderToolCall(block);
1166
+ }
1167
+ }
1168
+
1169
+ if (msg.stopReason === 'aborted') {
1170
+ html += '<div class="error-text">Aborted</div>';
1171
+ } else if (msg.stopReason === 'error') {
1172
+ html += `<div class="error-text">Error: ${escapeHtml(msg.errorMessage || 'Unknown error')}</div>`;
1173
+ }
1174
+
1175
+ html += '</div>';
1176
+ return html;
1177
+ }
1178
+
1179
+ if (msg.role === 'bashExecution') {
1180
+ const isError = msg.cancelled || (msg.exitCode !== 0 && msg.exitCode !== null);
1181
+ let html = `<div class="tool-execution ${isError ? 'error' : 'success'}" id="${entryId}">${tsHtml}`;
1182
+ html += `<div class="tool-command">$ ${escapeHtml(msg.command)}</div>`;
1183
+ if (msg.output) html += formatExpandableOutput(msg.output, 10);
1184
+ if (msg.cancelled) {
1185
+ html += '<div style="color: var(--warning)">(cancelled)</div>';
1186
+ } else if (msg.exitCode !== 0 && msg.exitCode !== null) {
1187
+ html += `<div style="color: var(--error)">(exit ${msg.exitCode})</div>`;
1188
+ }
1189
+ html += '</div>';
1190
+ return html;
1191
+ }
1192
+
1193
+ if (msg.role === 'toolResult') return '';
1194
+ }
1195
+
1196
+ if (entry.type === 'model_change') {
1197
+ return `<div class="model-change" id="${entryId}">${tsHtml}Switched to model: <span class="model-name">${escapeHtml(entry.provider)}/${escapeHtml(entry.modelId)}</span></div>`;
1198
+ }
1199
+
1200
+ if (entry.type === 'compaction') {
1201
+ return `<div class="compaction" id="${entryId}" onclick="this.classList.toggle('expanded')">
1202
+ <div class="compaction-label">[compaction]</div>
1203
+ <div class="compaction-collapsed">Compacted from ${entry.tokensBefore.toLocaleString()} tokens</div>
1204
+ <div class="compaction-content"><strong>Compacted from ${entry.tokensBefore.toLocaleString()} tokens</strong>\n\n${escapeHtml(entry.summary)}</div>
1205
+ </div>`;
1206
+ }
1207
+
1208
+ if (entry.type === 'branch_summary') {
1209
+ return `<div class="branch-summary" id="${entryId}">${tsHtml}
1210
+ <div class="branch-summary-header">Branch Summary</div>
1211
+ <div class="markdown-content">${safeMarkedParse(entry.summary)}</div>
1212
+ </div>`;
1213
+ }
1214
+
1215
+ if (entry.type === 'custom_message' && entry.display) {
1216
+ return `<div class="hook-message" id="${entryId}">${tsHtml}
1217
+ <div class="hook-type">[${escapeHtml(entry.customType)}]</div>
1218
+ <div class="markdown-content">${safeMarkedParse(typeof entry.content === 'string' ? entry.content : JSON.stringify(entry.content))}</div>
1219
+ </div>`;
1220
+ }
1221
+
1222
+ return '';
1223
+ }
1224
+
1225
+ // ============================================================
1226
+ // HEADER / STATS
1227
+ // ============================================================
1228
+
1229
+ function computeStats(entryList) {
1230
+ let userMessages = 0, assistantMessages = 0, toolResults = 0;
1231
+ let customMessages = 0, compactions = 0, branchSummaries = 0, toolCalls = 0;
1232
+ const tokens = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
1233
+ const cost = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
1234
+ const models = new Set();
1235
+
1236
+ for (const entry of entryList) {
1237
+ if (entry.type === 'message') {
1238
+ const msg = entry.message;
1239
+ if (msg.role === 'user') userMessages++;
1240
+ if (msg.role === 'assistant') {
1241
+ assistantMessages++;
1242
+ if (msg.model) models.add(msg.provider ? `${msg.provider}/${msg.model}` : msg.model);
1243
+ if (msg.usage) {
1244
+ tokens.input += msg.usage.input || 0;
1245
+ tokens.output += msg.usage.output || 0;
1246
+ tokens.cacheRead += msg.usage.cacheRead || 0;
1247
+ tokens.cacheWrite += msg.usage.cacheWrite || 0;
1248
+ if (msg.usage.cost) {
1249
+ cost.input += msg.usage.cost.input || 0;
1250
+ cost.output += msg.usage.cost.output || 0;
1251
+ cost.cacheRead += msg.usage.cost.cacheRead || 0;
1252
+ cost.cacheWrite += msg.usage.cost.cacheWrite || 0;
1253
+ }
1254
+ }
1255
+ toolCalls += msg.content.filter(c => c.type === 'toolCall').length;
1256
+ }
1257
+ if (msg.role === 'toolResult') toolResults++;
1258
+ } else if (entry.type === 'compaction') {
1259
+ compactions++;
1260
+ } else if (entry.type === 'branch_summary') {
1261
+ branchSummaries++;
1262
+ } else if (entry.type === 'custom_message') {
1263
+ customMessages++;
1264
+ }
1265
+ }
1266
+
1267
+ return { userMessages, assistantMessages, toolResults, customMessages, compactions, branchSummaries, toolCalls, tokens, cost, models: Array.from(models) };
1268
+ }
1269
+
1270
+ const globalStats = computeStats(entries);
1271
+
1272
+ function renderHeader() {
1273
+ const totalCost = globalStats.cost.input + globalStats.cost.output + globalStats.cost.cacheRead + globalStats.cost.cacheWrite;
1274
+
1275
+ const tokenParts = [];
1276
+ if (globalStats.tokens.input) tokenParts.push(`↑${formatTokens(globalStats.tokens.input)}`);
1277
+ if (globalStats.tokens.output) tokenParts.push(`↓${formatTokens(globalStats.tokens.output)}`);
1278
+ if (globalStats.tokens.cacheRead) tokenParts.push(`R${formatTokens(globalStats.tokens.cacheRead)}`);
1279
+ if (globalStats.tokens.cacheWrite) tokenParts.push(`W${formatTokens(globalStats.tokens.cacheWrite)}`);
1280
+
1281
+ const msgParts = [];
1282
+ if (globalStats.userMessages) msgParts.push(`${globalStats.userMessages} user`);
1283
+ if (globalStats.assistantMessages) msgParts.push(`${globalStats.assistantMessages} assistant`);
1284
+ if (globalStats.toolResults) msgParts.push(`${globalStats.toolResults} tool results`);
1285
+ if (globalStats.customMessages) msgParts.push(`${globalStats.customMessages} custom`);
1286
+ if (globalStats.compactions) msgParts.push(`${globalStats.compactions} compactions`);
1287
+ if (globalStats.branchSummaries) msgParts.push(`${globalStats.branchSummaries} branch summaries`);
1288
+
1289
+ let html = `
1290
+ <div class="header">
1291
+ <h1>Session: ${escapeHtml(header?.id || 'unknown')}</h1>
1292
+ <div class="help-bar">
1293
+ <span>Ctrl+T toggle thinking · Ctrl+O toggle tools</span>
1294
+ <button class="download-json-btn" onclick="downloadSessionJson()" title="Download session as JSONL">↓ JSONL</button>
1295
+ </div>
1296
+ <div class="header-info">
1297
+ <div class="info-item"><span class="info-label">Date:</span><span class="info-value">${header?.timestamp ? new Date(header.timestamp).toLocaleString() : 'unknown'}</span></div>
1298
+ <div class="info-item"><span class="info-label">Models:</span><span class="info-value">${globalStats.models.join(', ') || 'unknown'}</span></div>
1299
+ <div class="info-item"><span class="info-label">Messages:</span><span class="info-value">${msgParts.join(', ') || '0'}</span></div>
1300
+ <div class="info-item"><span class="info-label">Tool Calls:</span><span class="info-value">${globalStats.toolCalls}</span></div>
1301
+ <div class="info-item"><span class="info-label">Tokens:</span><span class="info-value">${tokenParts.join(' ') || '0'}</span></div>
1302
+ <div class="info-item"><span class="info-label">Cost:</span><span class="info-value">$${totalCost.toFixed(3)}</span></div>
1303
+ </div>
1304
+ </div>`;
1305
+
1306
+ // Render system prompt (user's base prompt, applies to all providers)
1307
+ if (systemPrompt) {
1308
+ const lines = systemPrompt.split('\n');
1309
+ const previewLines = 10;
1310
+ if (lines.length > previewLines) {
1311
+ const preview = lines.slice(0, previewLines).join('\n');
1312
+ const remaining = lines.length - previewLines;
1313
+ html += `<div class="system-prompt expandable" onclick="this.classList.toggle('expanded')">
1314
+ <div class="system-prompt-header">System Prompt</div>
1315
+ <div class="system-prompt-preview">${escapeHtml(preview)}</div>
1316
+ <div class="system-prompt-expand-hint">... (${remaining} more lines, click to expand)</div>
1317
+ <div class="system-prompt-full">${escapeHtml(systemPrompt)}</div>
1318
+ </div>`;
1319
+ } else {
1320
+ html += `<div class="system-prompt">
1321
+ <div class="system-prompt-header">System Prompt</div>
1322
+ <div class="system-prompt-full" style="display: block">${escapeHtml(systemPrompt)}</div>
1323
+ </div>`;
1324
+ }
1325
+ }
1326
+
1327
+ if (tools && tools.length > 0) {
1328
+ html += `<div class="tools-list">
1329
+ <div class="tools-header">Available Tools</div>
1330
+ <div class="tools-content">
1331
+ ${tools.map(t => {
1332
+ const hasParams = t.parameters && typeof t.parameters === 'object' && t.parameters.properties && Object.keys(t.parameters.properties).length > 0;
1333
+ if (!hasParams) {
1334
+ return `<div class="tool-item"><span class="tool-item-name">${escapeHtml(t.name)}</span> - <span class="tool-item-desc">${escapeHtml(t.description)}</span></div>`;
1335
+ }
1336
+ const params = t.parameters;
1337
+ const properties = params.properties;
1338
+ const required = params.required || [];
1339
+ let paramsHtml = '';
1340
+ for (const [name, prop] of Object.entries(properties)) {
1341
+ const isRequired = required.includes(name);
1342
+ const typeStr = prop.type || 'any';
1343
+ const reqLabel = isRequired ? '<span class="tool-param-required">required</span>' : '<span class="tool-param-optional">optional</span>';
1344
+ paramsHtml += `<div class="tool-param"><span class="tool-param-name">${escapeHtml(name)}</span> <span class="tool-param-type">${escapeHtml(typeStr)}</span> ${reqLabel}`;
1345
+ if (prop.description) {
1346
+ paramsHtml += `<div class="tool-param-desc">${escapeHtml(prop.description)}</div>`;
1347
+ }
1348
+ paramsHtml += `</div>`;
1349
+ }
1350
+ return `<div class="tool-item" onclick="this.classList.toggle('params-expanded')"><span class="tool-item-name">${escapeHtml(t.name)}</span> - <span class="tool-item-desc">${escapeHtml(t.description)}</span> <span class="tool-params-hint"></span><div class="tool-params-content">${paramsHtml}</div></div>`;
1351
+ }).join('')}
1352
+ </div>
1353
+ </div>`;
1354
+ }
1355
+
1356
+ return html;
1357
+ }
1358
+
1359
+ // ============================================================
1360
+ // NAVIGATION
1361
+ // ============================================================
1362
+
1363
+ // Cache for rendered entry DOM nodes
1364
+ const entryCache = new Map();
1365
+
1366
+ function renderEntryToNode(entry) {
1367
+ // Check cache first
1368
+ if (entryCache.has(entry.id)) {
1369
+ return entryCache.get(entry.id).cloneNode(true);
1370
+ }
1371
+
1372
+ // Render to HTML string, then parse to node
1373
+ const html = renderEntry(entry);
1374
+ if (!html) return null;
1375
+
1376
+ const template = document.createElement('template');
1377
+ template.innerHTML = html;
1378
+ const node = template.content.firstElementChild;
1379
+
1380
+ // Cache the node
1381
+ if (node) {
1382
+ entryCache.set(entry.id, node.cloneNode(true));
1383
+ }
1384
+ return node;
1385
+ }
1386
+
1387
+ function navigateTo(targetId, scrollMode = 'target', scrollToEntryId = null) {
1388
+ currentLeafId = targetId;
1389
+ currentTargetId = scrollToEntryId || targetId;
1390
+ const path = getPath(targetId);
1391
+
1392
+ renderTree();
1393
+
1394
+ document.getElementById('header-container').innerHTML = renderHeader();
1395
+
1396
+ // Build messages using cached DOM nodes
1397
+ const messagesEl = document.getElementById('messages');
1398
+ const fragment = document.createDocumentFragment();
1399
+
1400
+ for (const entry of path) {
1401
+ const node = renderEntryToNode(entry);
1402
+ if (node) {
1403
+ fragment.appendChild(node);
1404
+ }
1405
+ }
1406
+
1407
+ messagesEl.innerHTML = '';
1408
+ messagesEl.appendChild(fragment);
1409
+
1410
+ // Attach click handlers for copy-link buttons
1411
+ messagesEl.querySelectorAll('.copy-link-btn').forEach(btn => {
1412
+ btn.addEventListener('click', (e) => {
1413
+ e.stopPropagation();
1414
+ const entryId = btn.dataset.entryId;
1415
+ const shareUrl = buildShareUrl(entryId);
1416
+ copyToClipboard(shareUrl, btn);
1417
+ });
1418
+ });
1419
+
1420
+ // Use setTimeout(0) to ensure DOM is fully laid out before scrolling
1421
+ setTimeout(() => {
1422
+ const content = document.getElementById('content');
1423
+ if (scrollMode === 'bottom') {
1424
+ content.scrollTop = content.scrollHeight;
1425
+ } else if (scrollMode === 'target') {
1426
+ // If scrollToEntryId is provided, scroll to that specific entry
1427
+ const scrollTargetId = scrollToEntryId || targetId;
1428
+ const targetEl = document.getElementById(`entry-${scrollTargetId}`);
1429
+ if (targetEl) {
1430
+ targetEl.scrollIntoView({ block: 'center' });
1431
+ // Briefly highlight the target message
1432
+ if (scrollToEntryId) {
1433
+ targetEl.classList.add('highlight');
1434
+ setTimeout(() => targetEl.classList.remove('highlight'), 2000);
1435
+ }
1436
+ }
1437
+ }
1438
+ }, 0);
1439
+ }
1440
+
1441
+ // ============================================================
1442
+ // INITIALIZATION
1443
+ // ============================================================
1444
+
1445
+ // Escape HTML tags in text (but not code blocks)
1446
+ function escapeHtmlTags(text) {
1447
+ return text.replace(/<(?=[a-zA-Z\/])/g, '&lt;');
1448
+ }
1449
+
1450
+ // Configure marked with syntax highlighting and HTML escaping for text
1451
+ marked.use({
1452
+ breaks: true,
1453
+ gfm: true,
1454
+ renderer: {
1455
+ // Code blocks: syntax highlight, no HTML escaping
1456
+ code(token) {
1457
+ const code = token.text;
1458
+ const lang = token.lang;
1459
+ let highlighted;
1460
+ if (lang && hljs.getLanguage(lang)) {
1461
+ try {
1462
+ highlighted = hljs.highlight(code, { language: lang }).value;
1463
+ } catch {
1464
+ highlighted = escapeHtml(code);
1465
+ }
1466
+ } else {
1467
+ // Auto-detect language if not specified
1468
+ try {
1469
+ highlighted = hljs.highlightAuto(code).value;
1470
+ } catch {
1471
+ highlighted = escapeHtml(code);
1472
+ }
1473
+ }
1474
+ return `<pre><code class="hljs">${highlighted}</code></pre>`;
1475
+ },
1476
+ // Text content: escape HTML tags
1477
+ text(token) {
1478
+ return escapeHtmlTags(escapeHtml(token.text));
1479
+ },
1480
+ // Inline code: escape HTML
1481
+ codespan(token) {
1482
+ return `<code>${escapeHtml(token.text)}</code>`;
1483
+ }
1484
+ }
1485
+ });
1486
+
1487
+ // Simple marked parse (escaping handled in renderers)
1488
+ function safeMarkedParse(text) {
1489
+ return marked.parse(text);
1490
+ }
1491
+
1492
+ // Search input
1493
+ const searchInput = document.getElementById('tree-search');
1494
+ searchInput.addEventListener('input', (e) => {
1495
+ searchQuery = e.target.value;
1496
+ forceTreeRerender();
1497
+ });
1498
+
1499
+ // Filter buttons
1500
+ document.querySelectorAll('.filter-btn').forEach(btn => {
1501
+ btn.addEventListener('click', () => {
1502
+ document.querySelectorAll('.filter-btn').forEach(b => b.classList.remove('active'));
1503
+ btn.classList.add('active');
1504
+ filterMode = btn.dataset.filter;
1505
+ forceTreeRerender();
1506
+ });
1507
+ });
1508
+
1509
+ // Sidebar toggle
1510
+ const sidebar = document.getElementById('sidebar');
1511
+ const overlay = document.getElementById('sidebar-overlay');
1512
+ const hamburger = document.getElementById('hamburger');
1513
+
1514
+ hamburger.addEventListener('click', () => {
1515
+ sidebar.classList.add('open');
1516
+ overlay.classList.add('open');
1517
+ hamburger.style.display = 'none';
1518
+ });
1519
+
1520
+ const closeSidebar = () => {
1521
+ sidebar.classList.remove('open');
1522
+ overlay.classList.remove('open');
1523
+ hamburger.style.display = '';
1524
+ };
1525
+
1526
+ overlay.addEventListener('click', closeSidebar);
1527
+ document.getElementById('sidebar-close').addEventListener('click', closeSidebar);
1528
+
1529
+ // Toggle states
1530
+ let thinkingExpanded = true;
1531
+ let toolOutputsExpanded = false;
1532
+
1533
+ const toggleThinking = () => {
1534
+ thinkingExpanded = !thinkingExpanded;
1535
+ document.querySelectorAll('.thinking-text').forEach(el => {
1536
+ el.style.display = thinkingExpanded ? '' : 'none';
1537
+ });
1538
+ document.querySelectorAll('.thinking-collapsed').forEach(el => {
1539
+ el.style.display = thinkingExpanded ? 'none' : 'block';
1540
+ });
1541
+ };
1542
+
1543
+ const toggleToolOutputs = () => {
1544
+ toolOutputsExpanded = !toolOutputsExpanded;
1545
+ document.querySelectorAll('.tool-output.expandable').forEach(el => {
1546
+ el.classList.toggle('expanded', toolOutputsExpanded);
1547
+ });
1548
+ document.querySelectorAll('.compaction').forEach(el => {
1549
+ el.classList.toggle('expanded', toolOutputsExpanded);
1550
+ });
1551
+ };
1552
+
1553
+ // Keyboard shortcuts
1554
+ document.addEventListener('keydown', (e) => {
1555
+ if (e.key === 'Escape') {
1556
+ searchInput.value = '';
1557
+ searchQuery = '';
1558
+ navigateTo(leafId, 'bottom');
1559
+ }
1560
+ if (e.ctrlKey && e.key === 't') {
1561
+ e.preventDefault();
1562
+ toggleThinking();
1563
+ }
1564
+ if (e.ctrlKey && e.key === 'o') {
1565
+ e.preventDefault();
1566
+ toggleToolOutputs();
1567
+ }
1568
+ });
1569
+
1570
+ // Initial render
1571
+ // If URL has targetId, scroll to that specific message; otherwise stay at top
1572
+ if (leafId) {
1573
+ if (urlTargetId && byId.has(urlTargetId)) {
1574
+ // Deep link: navigate to leaf and scroll to target message
1575
+ navigateTo(leafId, 'target', urlTargetId);
1576
+ } else {
1577
+ navigateTo(leafId, 'none');
1578
+ }
1579
+ } else if (entries.length > 0) {
1580
+ // Fallback: use last entry if no leafId
1581
+ navigateTo(entries[entries.length - 1].id, 'none');
1582
+ }
1583
+ })();