gsd-pi 2.74.0-dev.6e23363 → 2.74.0-dev.703eabc

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 (271) hide show
  1. package/dist/resources/extensions/gsd/auto-post-unit.js +7 -3
  2. package/dist/resources/extensions/gsd/bootstrap/register-extension.js +10 -1
  3. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +45 -4
  4. package/dist/resources/extensions/gsd/commands/handlers/ops.js +5 -0
  5. package/dist/resources/extensions/gsd/commands-extract-learnings.js +225 -0
  6. package/dist/resources/extensions/gsd/ecosystem/gsd-extension-api.js +144 -0
  7. package/dist/resources/extensions/gsd/ecosystem/loader.js +145 -0
  8. package/dist/tsconfig.extensions.tsbuildinfo +1 -1
  9. package/dist/web/standalone/.next/BUILD_ID +1 -1
  10. package/dist/web/standalone/.next/app-path-routes-manifest.json +16 -16
  11. package/dist/web/standalone/.next/build-manifest.json +2 -2
  12. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  13. package/dist/web/standalone/.next/server/app/_global-error.html +1 -1
  14. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  15. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  16. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  17. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  18. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  19. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  20. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  21. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  22. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  23. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  24. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  25. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  26. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  27. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  28. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  29. package/dist/web/standalone/.next/server/app/api/onboarding/route.js +1 -1
  30. package/dist/web/standalone/.next/server/app/api/terminal/input/route.js +1 -1
  31. package/dist/web/standalone/.next/server/app/api/terminal/resize/route.js +1 -1
  32. package/dist/web/standalone/.next/server/app/api/terminal/sessions/route.js +1 -1
  33. package/dist/web/standalone/.next/server/app/api/terminal/stream/route.js +1 -1
  34. package/dist/web/standalone/.next/server/app/index.html +1 -1
  35. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app-paths-manifest.json +16 -16
  42. package/dist/web/standalone/.next/server/chunks/6897.js +3 -3
  43. package/dist/web/standalone/.next/server/middleware-build-manifest.js +1 -1
  44. package/dist/web/standalone/.next/server/middleware-manifest.json +5 -5
  45. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  46. package/dist/web/standalone/.next/server/pages/500.html +1 -1
  47. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  48. package/package.json +1 -1
  49. package/packages/mcp-server/dist/readers/graph.d.ts +1 -1
  50. package/packages/mcp-server/dist/readers/graph.d.ts.map +1 -1
  51. package/packages/mcp-server/dist/readers/graph.js +107 -0
  52. package/packages/mcp-server/dist/readers/graph.js.map +1 -1
  53. package/packages/mcp-server/src/readers/graph.test.ts +178 -0
  54. package/packages/mcp-server/src/readers/graph.ts +148 -1
  55. package/packages/mcp-server/tsconfig.tsbuildinfo +1 -1
  56. package/packages/pi-agent-core/tsconfig.tsbuildinfo +1 -1
  57. package/packages/pi-ai/dist/index.d.ts +1 -9
  58. package/packages/pi-ai/dist/index.d.ts.map +1 -1
  59. package/packages/pi-ai/dist/index.js +1 -9
  60. package/packages/pi-ai/dist/index.js.map +1 -1
  61. package/packages/pi-ai/dist/models/capability-patches.d.ts +19 -0
  62. package/packages/pi-ai/dist/models/capability-patches.d.ts.map +1 -0
  63. package/packages/pi-ai/dist/models/capability-patches.js +36 -0
  64. package/packages/pi-ai/dist/models/capability-patches.js.map +1 -0
  65. package/packages/pi-ai/dist/{models.custom.d.ts → models/custom.d.ts} +1 -1
  66. package/packages/pi-ai/dist/models/custom.d.ts.map +1 -0
  67. package/packages/pi-ai/dist/{models.custom.js → models/custom.js} +4 -4
  68. package/packages/pi-ai/dist/models/custom.js.map +1 -0
  69. package/packages/pi-ai/dist/models/generated/amazon-bedrock.d.ts +1482 -0
  70. package/packages/pi-ai/dist/models/generated/amazon-bedrock.d.ts.map +1 -0
  71. package/packages/pi-ai/dist/models/generated/amazon-bedrock.js +1484 -0
  72. package/packages/pi-ai/dist/models/generated/amazon-bedrock.js.map +1 -0
  73. package/packages/pi-ai/dist/models/generated/anthropic.d.ts +377 -0
  74. package/packages/pi-ai/dist/models/generated/anthropic.d.ts.map +1 -0
  75. package/packages/pi-ai/dist/models/generated/anthropic.js +379 -0
  76. package/packages/pi-ai/dist/models/generated/anthropic.js.map +1 -0
  77. package/packages/pi-ai/dist/models/generated/azure-openai-responses.d.ts +700 -0
  78. package/packages/pi-ai/dist/models/generated/azure-openai-responses.d.ts.map +1 -0
  79. package/packages/pi-ai/dist/models/generated/azure-openai-responses.js +702 -0
  80. package/packages/pi-ai/dist/models/generated/azure-openai-responses.js.map +1 -0
  81. package/packages/pi-ai/dist/models/generated/cerebras.d.ts +71 -0
  82. package/packages/pi-ai/dist/models/generated/cerebras.d.ts.map +1 -0
  83. package/packages/pi-ai/dist/models/generated/cerebras.js +73 -0
  84. package/packages/pi-ai/dist/models/generated/cerebras.js.map +1 -0
  85. package/packages/pi-ai/dist/models/generated/github-copilot.d.ts +590 -0
  86. package/packages/pi-ai/dist/models/generated/github-copilot.d.ts.map +1 -0
  87. package/packages/pi-ai/dist/models/generated/github-copilot.js +444 -0
  88. package/packages/pi-ai/dist/models/generated/github-copilot.js.map +1 -0
  89. package/packages/pi-ai/dist/models/generated/google-antigravity.d.ts +156 -0
  90. package/packages/pi-ai/dist/models/generated/google-antigravity.d.ts.map +1 -0
  91. package/packages/pi-ai/dist/models/generated/google-antigravity.js +158 -0
  92. package/packages/pi-ai/dist/models/generated/google-antigravity.js.map +1 -0
  93. package/packages/pi-ai/dist/models/generated/google-gemini-cli.d.ts +105 -0
  94. package/packages/pi-ai/dist/models/generated/google-gemini-cli.d.ts.map +1 -0
  95. package/packages/pi-ai/dist/models/generated/google-gemini-cli.js +107 -0
  96. package/packages/pi-ai/dist/models/generated/google-gemini-cli.js.map +1 -0
  97. package/packages/pi-ai/dist/models/generated/google-vertex.d.ts +207 -0
  98. package/packages/pi-ai/dist/models/generated/google-vertex.d.ts.map +1 -0
  99. package/packages/pi-ai/dist/models/generated/google-vertex.js +209 -0
  100. package/packages/pi-ai/dist/models/generated/google-vertex.js.map +1 -0
  101. package/packages/pi-ai/dist/models/generated/google.d.ts +462 -0
  102. package/packages/pi-ai/dist/models/generated/google.d.ts.map +1 -0
  103. package/packages/pi-ai/dist/models/generated/google.js +464 -0
  104. package/packages/pi-ai/dist/models/generated/google.js.map +1 -0
  105. package/packages/pi-ai/dist/models/generated/groq.d.ts +309 -0
  106. package/packages/pi-ai/dist/models/generated/groq.d.ts.map +1 -0
  107. package/packages/pi-ai/dist/models/generated/groq.js +311 -0
  108. package/packages/pi-ai/dist/models/generated/groq.js.map +1 -0
  109. package/packages/pi-ai/dist/models/generated/huggingface.d.ts +383 -0
  110. package/packages/pi-ai/dist/models/generated/huggingface.d.ts.map +1 -0
  111. package/packages/pi-ai/dist/models/generated/huggingface.js +347 -0
  112. package/packages/pi-ai/dist/models/generated/huggingface.js.map +1 -0
  113. package/packages/pi-ai/dist/{models.generated.d.ts → models/generated/index.d.ts} +1 -1
  114. package/packages/pi-ai/dist/{models.generated.d.ts.map → models/generated/index.d.ts.map} +1 -1
  115. package/packages/pi-ai/dist/models/generated/index.js +51 -0
  116. package/packages/pi-ai/dist/models/generated/index.js.map +1 -0
  117. package/packages/pi-ai/dist/models/generated/kimi-coding.d.ts +37 -0
  118. package/packages/pi-ai/dist/models/generated/kimi-coding.d.ts.map +1 -0
  119. package/packages/pi-ai/dist/models/generated/kimi-coding.js +39 -0
  120. package/packages/pi-ai/dist/models/generated/kimi-coding.js.map +1 -0
  121. package/packages/pi-ai/dist/models/generated/minimax-cn.d.ts +105 -0
  122. package/packages/pi-ai/dist/models/generated/minimax-cn.d.ts.map +1 -0
  123. package/packages/pi-ai/dist/models/generated/minimax-cn.js +107 -0
  124. package/packages/pi-ai/dist/models/generated/minimax-cn.js.map +1 -0
  125. package/packages/pi-ai/dist/models/generated/minimax.d.ts +105 -0
  126. package/packages/pi-ai/dist/models/generated/minimax.d.ts.map +1 -0
  127. package/packages/pi-ai/dist/models/generated/minimax.js +107 -0
  128. package/packages/pi-ai/dist/models/generated/minimax.js.map +1 -0
  129. package/packages/pi-ai/dist/models/generated/mistral.d.ts +445 -0
  130. package/packages/pi-ai/dist/models/generated/mistral.d.ts.map +1 -0
  131. package/packages/pi-ai/dist/models/generated/mistral.js +447 -0
  132. package/packages/pi-ai/dist/models/generated/mistral.js.map +1 -0
  133. package/packages/pi-ai/dist/models/generated/openai-codex.d.ts +139 -0
  134. package/packages/pi-ai/dist/models/generated/openai-codex.d.ts.map +1 -0
  135. package/packages/pi-ai/dist/models/generated/openai-codex.js +141 -0
  136. package/packages/pi-ai/dist/models/generated/openai-codex.js.map +1 -0
  137. package/packages/pi-ai/dist/models/generated/openai.d.ts +700 -0
  138. package/packages/pi-ai/dist/models/generated/openai.d.ts.map +1 -0
  139. package/packages/pi-ai/dist/models/generated/openai.js +702 -0
  140. package/packages/pi-ai/dist/models/generated/openai.js.map +1 -0
  141. package/packages/pi-ai/dist/models/generated/opencode-go.d.ts +122 -0
  142. package/packages/pi-ai/dist/models/generated/opencode-go.d.ts.map +1 -0
  143. package/packages/pi-ai/dist/models/generated/opencode-go.js +124 -0
  144. package/packages/pi-ai/dist/models/generated/opencode-go.js.map +1 -0
  145. package/packages/pi-ai/dist/models/generated/opencode.d.ts +530 -0
  146. package/packages/pi-ai/dist/models/generated/opencode.d.ts.map +1 -0
  147. package/packages/pi-ai/dist/models/generated/opencode.js +532 -0
  148. package/packages/pi-ai/dist/models/generated/opencode.js.map +1 -0
  149. package/packages/pi-ai/dist/models/generated/openrouter.d.ts +4270 -0
  150. package/packages/pi-ai/dist/models/generated/openrouter.d.ts.map +1 -0
  151. package/packages/pi-ai/dist/models/generated/openrouter.js +4272 -0
  152. package/packages/pi-ai/dist/models/generated/openrouter.js.map +1 -0
  153. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.d.ts +2604 -0
  154. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.d.ts.map +1 -0
  155. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.js +2606 -0
  156. package/packages/pi-ai/dist/models/generated/vercel-ai-gateway.js.map +1 -0
  157. package/packages/pi-ai/dist/models/generated/xai.d.ts +411 -0
  158. package/packages/pi-ai/dist/models/generated/xai.d.ts.map +1 -0
  159. package/packages/pi-ai/dist/models/generated/xai.js +413 -0
  160. package/packages/pi-ai/dist/models/generated/xai.js.map +1 -0
  161. package/packages/pi-ai/dist/models/generated/zai.d.ts +276 -0
  162. package/packages/pi-ai/dist/models/generated/zai.d.ts.map +1 -0
  163. package/packages/pi-ai/dist/models/generated/zai.js +239 -0
  164. package/packages/pi-ai/dist/models/generated/zai.js.map +1 -0
  165. package/packages/pi-ai/dist/models/index.d.ts +27 -0
  166. package/packages/pi-ai/dist/models/index.d.ts.map +1 -0
  167. package/packages/pi-ai/dist/models/index.js +80 -0
  168. package/packages/pi-ai/dist/models/index.js.map +1 -0
  169. package/packages/pi-ai/dist/models.d.ts +1 -36
  170. package/packages/pi-ai/dist/models.d.ts.map +1 -1
  171. package/packages/pi-ai/dist/models.generated.test.js +1 -2
  172. package/packages/pi-ai/dist/models.generated.test.js.map +1 -1
  173. package/packages/pi-ai/dist/models.js +3 -112
  174. package/packages/pi-ai/dist/models.js.map +1 -1
  175. package/packages/pi-ai/dist/models.test.js +6 -5
  176. package/packages/pi-ai/dist/models.test.js.map +1 -1
  177. package/packages/pi-ai/scripts/generate-models.ts +74 -40
  178. package/packages/pi-ai/src/index.ts +1 -9
  179. package/packages/pi-ai/src/models/capability-patches.ts +40 -0
  180. package/packages/pi-ai/src/{models.custom.ts → models/custom.ts} +4 -4
  181. package/packages/pi-ai/src/models/generated/amazon-bedrock.ts +1486 -0
  182. package/packages/pi-ai/src/models/generated/anthropic.ts +381 -0
  183. package/packages/pi-ai/src/models/generated/azure-openai-responses.ts +704 -0
  184. package/packages/pi-ai/src/models/generated/cerebras.ts +75 -0
  185. package/packages/pi-ai/src/models/generated/github-copilot.ts +446 -0
  186. package/packages/pi-ai/src/models/generated/google-antigravity.ts +160 -0
  187. package/packages/pi-ai/src/models/generated/google-gemini-cli.ts +109 -0
  188. package/packages/pi-ai/src/models/generated/google-vertex.ts +211 -0
  189. package/packages/pi-ai/src/models/generated/google.ts +466 -0
  190. package/packages/pi-ai/src/models/generated/groq.ts +313 -0
  191. package/packages/pi-ai/src/models/generated/huggingface.ts +349 -0
  192. package/packages/pi-ai/src/models/generated/index.ts +52 -0
  193. package/packages/pi-ai/src/models/generated/kimi-coding.ts +41 -0
  194. package/packages/pi-ai/src/models/generated/minimax-cn.ts +109 -0
  195. package/packages/pi-ai/src/models/generated/minimax.ts +109 -0
  196. package/packages/pi-ai/src/models/generated/mistral.ts +449 -0
  197. package/packages/pi-ai/src/models/generated/openai-codex.ts +143 -0
  198. package/packages/pi-ai/src/models/generated/openai.ts +704 -0
  199. package/packages/pi-ai/src/models/generated/opencode-go.ts +126 -0
  200. package/packages/pi-ai/src/models/generated/opencode.ts +534 -0
  201. package/packages/pi-ai/src/models/generated/openrouter.ts +4274 -0
  202. package/packages/pi-ai/src/models/generated/vercel-ai-gateway.ts +2608 -0
  203. package/packages/pi-ai/src/models/generated/xai.ts +415 -0
  204. package/packages/pi-ai/src/models/generated/zai.ts +241 -0
  205. package/packages/pi-ai/src/models/index.ts +106 -0
  206. package/packages/pi-ai/src/models.generated.test.ts +1 -2
  207. package/packages/pi-ai/src/models.test.ts +6 -5
  208. package/packages/pi-ai/src/models.ts +3 -153
  209. package/packages/pi-ai/tsconfig.tsbuildinfo +1 -1
  210. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  211. package/packages/pi-coding-agent/dist/core/agent-session.js +8 -2
  212. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  213. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js +359 -7
  214. package/packages/pi-coding-agent/dist/core/chat-controller-ordering.test.js.map +1 -1
  215. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js +11 -0
  216. package/packages/pi-coding-agent/dist/modes/interactive/components/__tests__/tool-execution.test.js.map +1 -1
  217. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts +1 -0
  218. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  219. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js +23 -9
  220. package/packages/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
  221. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts +11 -0
  222. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.d.ts.map +1 -0
  223. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js +47 -0
  224. package/packages/pi-coding-agent/dist/modes/interactive/components/chat-frame.js.map +1 -0
  225. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  226. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +51 -8
  227. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  228. package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  229. package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.js +22 -22
  230. package/packages/pi-coding-agent/dist/modes/interactive/components/user-message.js.map +1 -1
  231. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.d.ts.map +1 -1
  232. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js +192 -22
  233. package/packages/pi-coding-agent/dist/modes/interactive/controllers/chat-controller.js.map +1 -1
  234. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.d.ts +2 -0
  235. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.d.ts.map +1 -0
  236. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.js +38 -0
  237. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode-ordering.test.js.map +1 -0
  238. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +13 -0
  239. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  240. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +53 -6
  241. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  242. package/packages/pi-coding-agent/src/core/agent-session.ts +12 -6
  243. package/packages/pi-coding-agent/src/core/chat-controller-ordering.test.ts +453 -7
  244. package/packages/pi-coding-agent/src/modes/interactive/components/__tests__/tool-execution.test.ts +19 -0
  245. package/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +25 -10
  246. package/packages/pi-coding-agent/src/modes/interactive/components/chat-frame.ts +67 -0
  247. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +66 -7
  248. package/packages/pi-coding-agent/src/modes/interactive/components/user-message.ts +23 -26
  249. package/packages/pi-coding-agent/src/modes/interactive/controllers/chat-controller.ts +253 -45
  250. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode-ordering.test.ts +44 -0
  251. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +73 -6
  252. package/packages/pi-coding-agent/tsconfig.tsbuildinfo +1 -1
  253. package/src/resources/extensions/gsd/auto-post-unit.ts +7 -3
  254. package/src/resources/extensions/gsd/bootstrap/register-extension.ts +15 -1
  255. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +56 -3
  256. package/src/resources/extensions/gsd/commands/handlers/ops.ts +5 -0
  257. package/src/resources/extensions/gsd/commands-extract-learnings.ts +304 -0
  258. package/src/resources/extensions/gsd/ecosystem/gsd-extension-api.ts +228 -0
  259. package/src/resources/extensions/gsd/ecosystem/loader.ts +201 -0
  260. package/src/resources/extensions/gsd/tests/commands-extract-learnings.test.ts +340 -0
  261. package/src/resources/extensions/gsd/tests/health-widget.test.ts +1 -1
  262. package/src/resources/extensions/gsd/tests/register-hooks-depth-verification.test.ts +1 -1
  263. package/src/resources/extensions/gsd/types.ts +13 -0
  264. package/src/resources/extensions/gsd/workflow-logger.ts +2 -1
  265. package/packages/pi-ai/dist/models.custom.d.ts.map +0 -1
  266. package/packages/pi-ai/dist/models.custom.js.map +0 -1
  267. package/packages/pi-ai/dist/models.generated.js +0 -14343
  268. package/packages/pi-ai/dist/models.generated.js.map +0 -1
  269. package/packages/pi-ai/src/models.generated.ts +0 -14345
  270. /package/dist/web/standalone/.next/static/{bc2gRVFTgD7j--BsJE7vP → 3U-oZ5FT59BM7sm2GInic}/_buildManifest.js +0 -0
  271. /package/dist/web/standalone/.next/static/{bc2gRVFTgD7j--BsJE7vP → 3U-oZ5FT59BM7sm2GInic}/_ssgManifest.js +0 -0
@@ -1121,11 +1121,15 @@ export async function postUnitPostVerification(pctx: PostUnitContext): Promise<"
1121
1121
  });
1122
1122
  }
1123
1123
 
1124
- // Notify UI
1124
+ // Notify UI — surface actionable details (#4259)
1125
1125
  if (result.status === "fail") {
1126
- const blockingCount = result.checks.filter(c => !c.passed && c.blocking).length;
1126
+ const blockingChecks = result.checks.filter(c => !c.passed && c.blocking);
1127
+ const blockingCount = blockingChecks.length;
1128
+ const details = blockingChecks.slice(0, 3).map(c => ` \u2022 ${c.message}`).join("\n");
1129
+ const suffix = blockingChecks.length > 3 ? `\n \u2022 ...and ${blockingChecks.length - 3} more` : "";
1130
+ const evidenceNote = `\nSee ${sid}-PRE-EXEC-VERIFY.json for full details.`;
1127
1131
  ctx.ui.notify(
1128
- `Pre-execution checks failed: ${blockingCount} blocking issue${blockingCount === 1 ? "" : "s"} found`,
1132
+ `Pre-execution checks failed: ${blockingCount} blocking issue${blockingCount === 1 ? "" : "s"} found\n${details}${suffix}${evidenceNote}`,
1129
1133
  "error",
1130
1134
  );
1131
1135
  preExecPauseNeeded = true;
@@ -4,6 +4,8 @@ import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent
4
4
 
5
5
  import { registerExitCommand } from "../exit-command.js";
6
6
  import { registerWorktreeCommand } from "../worktree-command.js";
7
+ import type { GSDEcosystemBeforeAgentStartHandler } from "../ecosystem/gsd-extension-api.js";
8
+ import { loadEcosystemExtensions } from "../ecosystem/loader.js";
7
9
  import { registerDbTools } from "./db-tools.js";
8
10
  import { registerDynamicTools } from "./dynamic-tools.js";
9
11
  import { registerJournalTools } from "./journal-tools.js";
@@ -65,6 +67,10 @@ export function registerGsdExtension(pi: ExtensionAPI): void {
65
67
 
66
68
  installEpipeGuard();
67
69
 
70
+ // Ecosystem handlers captured by the GSDExtensionAPI wrapper for the
71
+ // GSD-owned `before_agent_start` dispatch step (#3338).
72
+ const ecosystemHandlers: GSDEcosystemBeforeAgentStartHandler[] = [];
73
+
68
74
  pi.registerCommand("kill", {
69
75
  description: "Exit GSD immediately (no cleanup)",
70
76
  handler: async (_args: string, _ctx: ExtensionCommandContext) => {
@@ -80,7 +86,15 @@ export function registerGsdExtension(pi: ExtensionAPI): void {
80
86
  ["journal-tools", () => registerJournalTools(pi)],
81
87
  ["query-tools", () => registerQueryTools(pi)],
82
88
  ["shortcuts", () => registerShortcuts(pi)],
83
- ["hooks", () => registerHooks(pi)],
89
+ ["hooks", () => registerHooks(pi, ecosystemHandlers)],
90
+ ["ecosystem", () => {
91
+ void loadEcosystemExtensions(pi, ecosystemHandlers).catch((err) => {
92
+ logWarning(
93
+ "ecosystem",
94
+ `loader failed: ${err instanceof Error ? err.message : String(err)}`,
95
+ );
96
+ });
97
+ }],
84
98
  ];
85
99
 
86
100
  for (const [name, register] of nonCriticalRegistrations) {
@@ -3,6 +3,10 @@ import { join } from "node:path";
3
3
  import type { ExtensionAPI, ExtensionContext } from "@gsd/pi-coding-agent";
4
4
  import { isToolCallEventType } from "@gsd/pi-coding-agent";
5
5
 
6
+ import type { GSDEcosystemBeforeAgentStartHandler } from "../ecosystem/gsd-extension-api.js";
7
+ import { updateSnapshot } from "../ecosystem/gsd-extension-api.js";
8
+ import { getEcosystemReadyPromise } from "../ecosystem/loader.js";
9
+
6
10
  import { buildMilestoneFileName, resolveMilestonePath, resolveSliceFile, resolveSlicePath } from "../paths.js";
7
11
  import { buildBeforeAgentStartResult } from "./system-context.js";
8
12
  import { handleAgentEnd } from "./agent-end-recovery.js";
@@ -35,7 +39,10 @@ async function syncServiceTierStatus(ctx: ExtensionContext): Promise<void> {
35
39
  ctx.ui.setStatus("gsd-fast", formatServiceTierFooterStatus(getEffectiveServiceTier(), ctx.model?.id));
36
40
  }
37
41
 
38
- export function registerHooks(pi: ExtensionAPI): void {
42
+ export function registerHooks(
43
+ pi: ExtensionAPI,
44
+ ecosystemHandlers: GSDEcosystemBeforeAgentStartHandler[],
45
+ ): void {
39
46
  pi.on("session_start", async (_event, ctx) => {
40
47
  initNotificationStore(process.cwd());
41
48
  installNotifyInterceptor(ctx);
@@ -93,7 +100,50 @@ export function registerHooks(pi: ExtensionAPI): void {
93
100
  });
94
101
 
95
102
  pi.on("before_agent_start", async (event, ctx: ExtensionContext) => {
96
- return buildBeforeAgentStartResult(event, ctx);
103
+ // Wait for ecosystem loader to finish (no-op after first turn).
104
+ await getEcosystemReadyPromise();
105
+
106
+ // GSD's own context injection (existing behavior — unchanged).
107
+ const gsdResult = await buildBeforeAgentStartResult(event, ctx);
108
+
109
+ // Refresh the snapshot used by ecosystem getPhase()/getActiveUnit().
110
+ // deriveState has its own ~100ms cache so this is cheap on repeat calls.
111
+ try {
112
+ const state = await deriveState(process.cwd());
113
+ updateSnapshot(state);
114
+ } catch {
115
+ updateSnapshot(null);
116
+ }
117
+
118
+ // Chain ecosystem handlers using pi's runner.ts chaining protocol:
119
+ // each handler sees the systemPrompt mutated by prior handlers.
120
+ let currentSystemPrompt = gsdResult?.systemPrompt ?? event.systemPrompt;
121
+ // `any` because pi's BeforeAgentStartEventResult.message uses an internal
122
+ // CustomMessage type that's not re-exported (see ecosystem/gsd-extension-api.ts).
123
+ let lastMessage: any = gsdResult?.message;
124
+
125
+ for (const handler of ecosystemHandlers) {
126
+ try {
127
+ const r = await handler(
128
+ { ...event, systemPrompt: currentSystemPrompt },
129
+ ctx,
130
+ );
131
+ if (r?.systemPrompt !== undefined) currentSystemPrompt = r.systemPrompt;
132
+ if (r?.message) lastMessage = r.message;
133
+ } catch (err) {
134
+ safetyLogWarning(
135
+ "ecosystem",
136
+ `before_agent_start handler failed: ${err instanceof Error ? err.message : String(err)}`,
137
+ );
138
+ }
139
+ }
140
+
141
+ // Compose result. Return undefined if nothing changed (preserves runner contract).
142
+ if (currentSystemPrompt === event.systemPrompt && !lastMessage) return undefined;
143
+ return {
144
+ systemPrompt: currentSystemPrompt !== event.systemPrompt ? currentSystemPrompt : undefined,
145
+ message: lastMessage,
146
+ };
97
147
  });
98
148
 
99
149
  pi.on("agent_end", async (event, ctx: ExtensionContext) => {
@@ -125,7 +175,10 @@ export function registerHooks(pi: ExtensionAPI): void {
125
175
  await ensureDbOpen();
126
176
  const state = await deriveState(basePath);
127
177
  if (!state.activeMilestone || !state.activeSlice || !state.activeTask) return;
128
- if (state.phase !== "executing") return;
178
+ // Write checkpoint for ALL phases, not just "executing" — discuss, research,
179
+ // and planning also carry in-memory state (user answers, gate verification)
180
+ // that would be lost on compaction (#4258).
181
+ // if (state.phase !== "executing") return;
129
182
 
130
183
  const sliceDir = resolveSlicePath(basePath, state.activeMilestone.id, state.activeSlice.id);
131
184
  if (!sliceDir) return;
@@ -236,5 +236,10 @@ Examples:
236
236
  await handleAddTests(trimmed.replace(/^add-tests\s*/, "").trim(), ctx, pi);
237
237
  return true;
238
238
  }
239
+ if (trimmed === "extract-learnings" || trimmed.startsWith("extract-learnings ")) {
240
+ const { handleExtractLearnings } = await import("../../commands-extract-learnings.js");
241
+ await handleExtractLearnings(trimmed.replace(/^extract-learnings\s*/, "").trim(), ctx, pi);
242
+ return true;
243
+ }
239
244
  return false;
240
245
  }
@@ -0,0 +1,304 @@
1
+ /**
2
+ * GSD Command — /gsd extract-learnings
3
+ *
4
+ * Analyses completed milestone artefacts and dispatches an LLM turn that
5
+ * extracts structured knowledge into 4 categories:
6
+ * Decisions · Lessons · Patterns · Surprises
7
+ */
8
+
9
+ import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent";
10
+
11
+ import { existsSync, readFileSync } from "node:fs";
12
+ import { join, basename } from "node:path";
13
+
14
+ import { gsdRoot, resolveMilestonePath } from "./paths.js";
15
+ import { projectRoot } from "./commands/context.js";
16
+
17
+ // ─── Types ────────────────────────────────────────────────────────────────────
18
+
19
+ export interface PhaseArtifacts {
20
+ plan: string | null;
21
+ summary: string | null;
22
+ verification: string | null;
23
+ uat: string | null;
24
+ missingRequired: string[];
25
+ }
26
+
27
+ export interface ExtractLearningsPromptContext {
28
+ milestoneId: string;
29
+ milestoneName: string;
30
+ outputPath: string;
31
+ relativeOutputPath: string;
32
+ planContent: string;
33
+ summaryContent: string;
34
+ verificationContent: string | null;
35
+ uatContent: string | null;
36
+ missingArtifacts: string[];
37
+ projectName: string;
38
+ }
39
+
40
+ export interface FrontmatterContext {
41
+ milestoneId: string;
42
+ milestoneName: string;
43
+ projectName: string;
44
+ generatedAt: string;
45
+ counts: {
46
+ decisions: number;
47
+ lessons: number;
48
+ patterns: number;
49
+ surprises: number;
50
+ };
51
+ missingArtifacts: string[];
52
+ }
53
+
54
+ // ─── Pure functions ───────────────────────────────────────────────────────────
55
+
56
+ export function parseExtractLearningsArgs(args: string): { milestoneId: string | null } {
57
+ const trimmed = args.trim();
58
+ return { milestoneId: trimmed || null };
59
+ }
60
+
61
+ export function buildLearningsOutputPath(milestoneDir: string, milestoneId: string): string {
62
+ return join(milestoneDir, `${milestoneId}-LEARNINGS.md`);
63
+ }
64
+
65
+ export function resolvePhaseArtifacts(milestoneDir: string, milestoneId: string): PhaseArtifacts {
66
+ const missingRequired: string[] = [];
67
+
68
+ const planFile = `${milestoneId}-PLAN.md`;
69
+ const summaryFile = `${milestoneId}-SUMMARY.md`;
70
+ const verificationFile = `${milestoneId}-VERIFICATION.md`;
71
+ const uatFile = `${milestoneId}-UAT.md`;
72
+
73
+ const planPath = join(milestoneDir, planFile);
74
+ const summaryPath = join(milestoneDir, summaryFile);
75
+ const verificationPath = join(milestoneDir, verificationFile);
76
+ const uatPath = join(milestoneDir, uatFile);
77
+
78
+ const plan = existsSync(planPath) ? planPath : null;
79
+ const summary = existsSync(summaryPath) ? summaryPath : null;
80
+ const verification = existsSync(verificationPath) ? verificationPath : null;
81
+ const uat = existsSync(uatPath) ? uatPath : null;
82
+
83
+ if (!plan) missingRequired.push(planFile);
84
+ if (!summary) missingRequired.push(summaryFile);
85
+
86
+ return { plan, summary, verification, uat, missingRequired };
87
+ }
88
+
89
+ export function buildExtractLearningsPrompt(ctx: ExtractLearningsPromptContext): string {
90
+ const optionalSections: string[] = [];
91
+
92
+ if (ctx.verificationContent) {
93
+ optionalSections.push(`## Verification Report\n\n${ctx.verificationContent}`);
94
+ }
95
+ if (ctx.uatContent) {
96
+ optionalSections.push(`## UAT Report\n\n${ctx.uatContent}`);
97
+ }
98
+
99
+ const missingNote = ctx.missingArtifacts.length > 0
100
+ ? `\nNote: The following optional artefacts were not available: ${ctx.missingArtifacts.join(", ")}\n`
101
+ : "";
102
+
103
+ return `# Extract Learnings — ${ctx.milestoneId}: ${ctx.milestoneName}
104
+
105
+ **Project:** ${ctx.projectName}
106
+ **Output file:** ${ctx.outputPath}
107
+
108
+ ## Your Task
109
+
110
+ Analyse the artefacts below and extract structured knowledge from milestone **${ctx.milestoneId}**.
111
+
112
+ Write a LEARNINGS document to \`${ctx.outputPath}\` with the following 4 sections:
113
+
114
+ ### Decisions
115
+ Key architectural and design decisions made during this milestone, including the rationale and alternatives considered.
116
+
117
+ ### Lessons
118
+ What the team learned — technical discoveries, process insights, and knowledge gaps that were filled.
119
+
120
+ ### Patterns
121
+ Reusable patterns, approaches, or solutions that emerged and should be applied in future work.
122
+
123
+ ### Surprises
124
+ Unexpected challenges, discoveries, or outcomes — things that deviated from assumptions.
125
+
126
+ ### Source Attribution (REQUIRED)
127
+
128
+ Every extracted item MUST include a \`Source:\` line immediately after the item text.
129
+ Format: \`Source: {artifact-filename}/{section}\`
130
+ Example: \`Source: M001-PLAN.md/Architecture Decisions\`
131
+
132
+ Items without a Source attribution are invalid and must not be included in the output.
133
+
134
+ ---
135
+
136
+ ## Artefacts
137
+
138
+ ### Plan
139
+
140
+ ${ctx.planContent}
141
+
142
+ ---
143
+
144
+ ### Summary
145
+
146
+ ${ctx.summaryContent}
147
+
148
+ ${optionalSections.join("\n\n---\n\n")}
149
+ ${missingNote}
150
+ ---
151
+
152
+ ## Output Format
153
+
154
+ Write the LEARNINGS file to \`${ctx.relativeOutputPath}\` with YAML frontmatter followed by the 4 sections above.
155
+ Each section should contain concise, actionable bullet points.
156
+ Every bullet point MUST be followed by a source line, for example:
157
+
158
+ \`\`\`
159
+ ### Decisions
160
+ - Chose PostgreSQL over SQLite for concurrent write support.
161
+ Source: M001-PLAN.md/Architecture Decisions
162
+ \`\`\`
163
+
164
+ Items without a \`Source:\` line are invalid.
165
+
166
+ ---
167
+
168
+ ## Optional: Capture Individual Learnings
169
+
170
+ If the \`capture_thought\` tool is available, call it once for each extracted item with:
171
+ - category: "decision" | "lesson" | "pattern" | "surprise"
172
+ - phase: "${ctx.milestoneId}"
173
+ - content: {the learning text}
174
+ - source: {artifact filename}
175
+
176
+ If \`capture_thought\` is not available, skip this step silently — do not report an error.
177
+
178
+ ---
179
+
180
+ ## Rebuild Knowledge Graph
181
+
182
+ After writing LEARNINGS.md, call the \`gsd_graph\` tool with \`{ "mode": "build" }\` to rebuild the knowledge graph so the new learnings are immediately queryable by future milestone prompts.
183
+
184
+ If the \`gsd_graph\` tool is not available, skip this step silently.
185
+ `;
186
+ }
187
+
188
+ export function buildFrontmatter(ctx: FrontmatterContext): string {
189
+ const missingList = ctx.missingArtifacts.length > 0
190
+ ? ctx.missingArtifacts.map((a) => ` - ${a}`).join("\n")
191
+ : " []";
192
+
193
+ const missingValue = ctx.missingArtifacts.length > 0
194
+ ? `\n${missingList}`
195
+ : " []";
196
+
197
+ return `---
198
+ phase: ${ctx.milestoneId}
199
+ phase_name: ${ctx.milestoneName}
200
+ project: ${ctx.projectName}
201
+ generated: ${ctx.generatedAt}
202
+ counts:
203
+ decisions: ${ctx.counts.decisions}
204
+ lessons: ${ctx.counts.lessons}
205
+ patterns: ${ctx.counts.patterns}
206
+ surprises: ${ctx.counts.surprises}
207
+ missing_artifacts:${missingValue}
208
+ ---`;
209
+ }
210
+
211
+ export function extractProjectName(basePath: string): string {
212
+ const projectMdPath = join(gsdRoot(basePath), "PROJECT.md");
213
+
214
+ if (existsSync(projectMdPath)) {
215
+ try {
216
+ const content = readFileSync(projectMdPath, "utf-8");
217
+ const match = content.match(/^name:\s*(.+)$/m);
218
+ if (match) return match[1].trim();
219
+ } catch {
220
+ // non-fatal
221
+ }
222
+ }
223
+
224
+ return basename(basePath);
225
+ }
226
+
227
+ // ─── Handler ──────────────────────────────────────────────────────────────────
228
+
229
+ export async function handleExtractLearnings(
230
+ args: string,
231
+ ctx: ExtensionCommandContext,
232
+ pi: ExtensionAPI,
233
+ ): Promise<void> {
234
+ const { milestoneId } = parseExtractLearningsArgs(args);
235
+
236
+ if (!milestoneId) {
237
+ ctx.ui.notify("Usage: /gsd extract-learnings <milestoneId> (e.g. M001)", "warning");
238
+ return;
239
+ }
240
+
241
+ // projectRoot() throws GSDNoProjectError if no project found — intentional, handled by dispatcher
242
+ const basePath = projectRoot();
243
+ const milestoneDir = resolveMilestonePath(basePath, milestoneId);
244
+
245
+ if (!milestoneDir) {
246
+ ctx.ui.notify(`Milestone not found: ${milestoneId}`, "error");
247
+ return;
248
+ }
249
+
250
+ const artifacts = resolvePhaseArtifacts(milestoneDir, milestoneId);
251
+
252
+ if (artifacts.missingRequired.length > 0) {
253
+ ctx.ui.notify(
254
+ `Cannot extract learnings — required artefacts missing: ${artifacts.missingRequired.join(", ")}`,
255
+ "error",
256
+ );
257
+ return;
258
+ }
259
+
260
+ // Read required artefacts
261
+ const planContent = readFileSync(artifacts.plan!, "utf-8");
262
+ const summaryContent = readFileSync(artifacts.summary!, "utf-8");
263
+
264
+ // Read optional artefacts
265
+ const verificationContent = artifacts.verification
266
+ ? readFileSync(artifacts.verification, "utf-8")
267
+ : null;
268
+ const uatContent = artifacts.uat
269
+ ? readFileSync(artifacts.uat, "utf-8")
270
+ : null;
271
+
272
+ // Determine missing optional artefacts for context
273
+ const missingArtifacts: string[] = [];
274
+ if (!artifacts.verification) missingArtifacts.push(`${milestoneId}-VERIFICATION.md`);
275
+ if (!artifacts.uat) missingArtifacts.push(`${milestoneId}-UAT.md`);
276
+
277
+ // Extract milestone name from Plan H1 or fall back to milestoneId
278
+ const h1Match = planContent.match(/^#\s+(.+)$/m);
279
+ const milestoneName = h1Match?.[1]?.trim() ?? milestoneId;
280
+
281
+ const projectName = extractProjectName(basePath);
282
+ const outputPath = buildLearningsOutputPath(milestoneDir, milestoneId);
283
+ const relativeOutputPath = outputPath.replace(basePath + "/", "");
284
+
285
+ const prompt = buildExtractLearningsPrompt({
286
+ milestoneId,
287
+ milestoneName,
288
+ outputPath,
289
+ relativeOutputPath,
290
+ planContent,
291
+ summaryContent,
292
+ verificationContent,
293
+ uatContent,
294
+ missingArtifacts,
295
+ projectName,
296
+ });
297
+
298
+ ctx.ui.notify(`Extracting learnings for ${milestoneId}: "${milestoneName}"...`, "info");
299
+
300
+ pi.sendMessage(
301
+ { customType: "gsd-extract-learnings", content: prompt, display: false },
302
+ { triggerTurn: true },
303
+ );
304
+ }
@@ -0,0 +1,228 @@
1
+ // GSD2 — Ecosystem Extension API wrapper
2
+ // Wraps pi's ExtensionAPI to expose typed GSD context (phase + active unit)
3
+ // to extensions loaded from `./.gsd/extensions/`. The wrapper intercepts only
4
+ // `on("before_agent_start", ...)` so GSD can dispatch ecosystem handlers AFTER
5
+ // refreshing state — fixing the load-order race where third-party
6
+ // `.pi/extensions/` handlers see a stale module-level snapshot (#3338).
7
+ //
8
+ // SINGLE-SESSION INVARIANT: the module-level `_snapshot` is per-process.
9
+ // Worktree or project switches do NOT reload extensions, matching pi's
10
+ // `.pi/extensions/` behavior. Only re-launching the CLI rebinds the snapshot.
11
+
12
+ import type {
13
+ BeforeAgentStartEvent,
14
+ ExtensionAPI,
15
+ ExtensionHandler,
16
+ } from "@gsd/pi-coding-agent";
17
+
18
+ // Structural mirror of pi's internal BeforeAgentStartEventResult. The internal
19
+ // type is not re-exported from the package root, and constraint #3 forbids
20
+ // changes to packages/pi-coding-agent/, so we mirror the public shape here.
21
+ // `any` on inner fields keeps assignability bidirectional with pi's stricter
22
+ // `Pick<CustomMessage, ...>` shape (CustomMessage is also not re-exported).
23
+ // Source of truth: packages/pi-coding-agent/src/core/extensions/types.ts
24
+ export interface BeforeAgentStartEventResult {
25
+ message?: {
26
+ customType: string;
27
+ content?: any;
28
+ display?: any;
29
+ details?: any;
30
+ };
31
+ systemPrompt?: string;
32
+ }
33
+
34
+ import type { GSDActiveUnit, GSDState, Phase } from "../types.js";
35
+ import { isGSDActive, getCurrentPhase } from "../../shared/gsd-phase-state.js";
36
+ import { logWarning } from "../workflow-logger.js";
37
+
38
+ // ─── Public Interface ───────────────────────────────────────────────────
39
+
40
+ export interface GSDExtensionAPI extends ExtensionAPI {
41
+ /** Current GSD workflow phase, or null if no project state. */
42
+ getPhase(): Phase | null;
43
+ /** Currently active milestone/slice/task triple, or null if none. */
44
+ getActiveUnit(): GSDActiveUnit | null;
45
+ }
46
+
47
+ export type GSDEcosystemBeforeAgentStartHandler = ExtensionHandler<
48
+ BeforeAgentStartEvent,
49
+ BeforeAgentStartEventResult
50
+ >;
51
+
52
+ // ─── Auto-loop phase mapping ────────────────────────────────────────────
53
+
54
+ const AUTO_LOOP_PHASE_MAP: Record<string, Phase> = {
55
+ "plan-milestone": "planning",
56
+ "plan-slice": "planning",
57
+ "research": "researching",
58
+ "discuss": "discussing",
59
+ "execute-task": "executing",
60
+ "verify": "verifying",
61
+ "summarize-task": "summarizing",
62
+ "summarize-slice": "summarizing",
63
+ "advance": "advancing",
64
+ "validate-milestone": "validating-milestone",
65
+ "complete-milestone": "completing-milestone",
66
+ "replan-slice": "replanning-slice",
67
+ };
68
+
69
+ /** Exposed for unit tests. Returns null for unknown keys (does NOT default). */
70
+ export function mapAutoLoopPhase(raw: string): Phase | null {
71
+ return AUTO_LOOP_PHASE_MAP[raw] ?? null;
72
+ }
73
+
74
+ function resolvePhase(state: GSDState | null): Phase | null {
75
+ if (!state) return null;
76
+ if (isGSDActive()) {
77
+ const raw = getCurrentPhase();
78
+ if (raw != null) {
79
+ const mapped = AUTO_LOOP_PHASE_MAP[raw];
80
+ if (mapped) return mapped;
81
+ logWarning("ecosystem", `unknown auto-loop phase: ${raw}`);
82
+ // FALL THROUGH to state.phase rather than defaulting to "executing".
83
+ }
84
+ }
85
+ return state.phase;
86
+ }
87
+
88
+ function resolveActiveUnit(state: GSDState | null): GSDActiveUnit | null {
89
+ if (!state) return null;
90
+ const m = state.activeMilestone;
91
+ const s = state.activeSlice;
92
+ const t = state.activeTask;
93
+ if (!m || !s || !t) return null;
94
+ return {
95
+ milestoneId: m.id,
96
+ milestoneTitle: m.title,
97
+ sliceId: s.id,
98
+ sliceTitle: s.title,
99
+ taskId: t.id,
100
+ taskTitle: t.title,
101
+ };
102
+ }
103
+
104
+ // ─── Module-level snapshot ──────────────────────────────────────────────
105
+
106
+ interface Snapshot {
107
+ phase: Phase | null;
108
+ activeUnit: GSDActiveUnit | null;
109
+ }
110
+
111
+ let _snapshot: Snapshot = { phase: null, activeUnit: null };
112
+
113
+ /** Refresh the snapshot from a freshly derived GSDState (or null on failure). */
114
+ export function updateSnapshot(state: GSDState | null): void {
115
+ _snapshot = {
116
+ phase: resolvePhase(state),
117
+ activeUnit: resolveActiveUnit(state),
118
+ };
119
+ }
120
+
121
+ export function getSnapshotPhase(): Phase | null {
122
+ return _snapshot.phase;
123
+ }
124
+
125
+ export function getSnapshotActiveUnit(): GSDActiveUnit | null {
126
+ return _snapshot.activeUnit;
127
+ }
128
+
129
+ /** Test-only: reset the snapshot to its initial empty state. */
130
+ export function _resetSnapshot(): void {
131
+ _snapshot = { phase: null, activeUnit: null };
132
+ }
133
+
134
+ // ─── Wrapper factory ────────────────────────────────────────────────────
135
+
136
+ /**
137
+ * Build a GSDExtensionAPI by manually delegating every ExtensionAPI method
138
+ * to the underlying pi instance, except `on("before_agent_start", ...)`
139
+ * which is captured into `sharedHandlers` for GSD-owned dispatch.
140
+ *
141
+ * Uses `satisfies GSDExtensionAPI` (NOT `as`) so TypeScript catches drift
142
+ * when pi adds new ExtensionAPI methods.
143
+ */
144
+ export function createGSDExtensionAPI(
145
+ pi: ExtensionAPI,
146
+ sharedHandlers: GSDEcosystemBeforeAgentStartHandler[],
147
+ ): GSDExtensionAPI {
148
+ const wrapper = {
149
+ // ── Event subscription (single intercept point) ────────────────────
150
+ on(event: any, handler: any): void {
151
+ if (event === "before_agent_start") {
152
+ sharedHandlers.push(handler as GSDEcosystemBeforeAgentStartHandler);
153
+ return;
154
+ }
155
+ (pi.on as (e: any, h: any) => void)(event, handler);
156
+ },
157
+
158
+ // ── Event emission ─────────────────────────────────────────────────
159
+ emitBeforeModelSelect: (...args: Parameters<ExtensionAPI["emitBeforeModelSelect"]>) =>
160
+ pi.emitBeforeModelSelect(...args),
161
+ emitAdjustToolSet: (...args: Parameters<ExtensionAPI["emitAdjustToolSet"]>) =>
162
+ pi.emitAdjustToolSet(...args),
163
+
164
+ // ── Tool / command / shortcut / flag registration ──────────────────
165
+ registerTool: ((tool: any) => pi.registerTool(tool)) as ExtensionAPI["registerTool"],
166
+ registerCommand: (...args: Parameters<ExtensionAPI["registerCommand"]>) =>
167
+ pi.registerCommand(...args),
168
+ registerBeforeInstall: (...args: Parameters<ExtensionAPI["registerBeforeInstall"]>) =>
169
+ pi.registerBeforeInstall(...args),
170
+ registerAfterInstall: (...args: Parameters<ExtensionAPI["registerAfterInstall"]>) =>
171
+ pi.registerAfterInstall(...args),
172
+ registerBeforeRemove: (...args: Parameters<ExtensionAPI["registerBeforeRemove"]>) =>
173
+ pi.registerBeforeRemove(...args),
174
+ registerAfterRemove: (...args: Parameters<ExtensionAPI["registerAfterRemove"]>) =>
175
+ pi.registerAfterRemove(...args),
176
+ registerShortcut: (...args: Parameters<ExtensionAPI["registerShortcut"]>) =>
177
+ pi.registerShortcut(...args),
178
+ registerFlag: (...args: Parameters<ExtensionAPI["registerFlag"]>) =>
179
+ pi.registerFlag(...args),
180
+ getFlag: (...args: Parameters<ExtensionAPI["getFlag"]>) => pi.getFlag(...args),
181
+
182
+ // ── Message rendering ──────────────────────────────────────────────
183
+ registerMessageRenderer: ((customType: string, renderer: any) =>
184
+ pi.registerMessageRenderer(customType, renderer)) as ExtensionAPI["registerMessageRenderer"],
185
+
186
+ // ── Actions ────────────────────────────────────────────────────────
187
+ sendMessage: ((message: any, options?: any) =>
188
+ pi.sendMessage(message, options)) as ExtensionAPI["sendMessage"],
189
+ sendUserMessage: (...args: Parameters<ExtensionAPI["sendUserMessage"]>) =>
190
+ pi.sendUserMessage(...args),
191
+ retryLastTurn: () => pi.retryLastTurn(),
192
+ appendEntry: ((customType: string, data?: any) =>
193
+ pi.appendEntry(customType, data)) as ExtensionAPI["appendEntry"],
194
+
195
+ // ── Session metadata ───────────────────────────────────────────────
196
+ setSessionName: (...args: Parameters<ExtensionAPI["setSessionName"]>) =>
197
+ pi.setSessionName(...args),
198
+ getSessionName: () => pi.getSessionName(),
199
+ setLabel: (...args: Parameters<ExtensionAPI["setLabel"]>) => pi.setLabel(...args),
200
+ exec: (...args: Parameters<ExtensionAPI["exec"]>) => pi.exec(...args),
201
+ getActiveTools: () => pi.getActiveTools(),
202
+ getAllTools: () => pi.getAllTools(),
203
+ setActiveTools: (...args: Parameters<ExtensionAPI["setActiveTools"]>) =>
204
+ pi.setActiveTools(...args),
205
+ getCommands: () => pi.getCommands(),
206
+
207
+ // ── Model & thinking ───────────────────────────────────────────────
208
+ setModel: (...args: Parameters<ExtensionAPI["setModel"]>) => pi.setModel(...args),
209
+ getThinkingLevel: () => pi.getThinkingLevel(),
210
+ setThinkingLevel: (...args: Parameters<ExtensionAPI["setThinkingLevel"]>) =>
211
+ pi.setThinkingLevel(...args),
212
+
213
+ // ── Provider registration ──────────────────────────────────────────
214
+ registerProvider: (...args: Parameters<ExtensionAPI["registerProvider"]>) =>
215
+ pi.registerProvider(...args),
216
+ unregisterProvider: (...args: Parameters<ExtensionAPI["unregisterProvider"]>) =>
217
+ pi.unregisterProvider(...args),
218
+
219
+ // ── Shared event bus (passthrough property) ────────────────────────
220
+ events: pi.events,
221
+
222
+ // ── GSD-specific additions ─────────────────────────────────────────
223
+ getPhase: (): Phase | null => _snapshot.phase,
224
+ getActiveUnit: (): GSDActiveUnit | null => _snapshot.activeUnit,
225
+ } satisfies GSDExtensionAPI;
226
+
227
+ return wrapper;
228
+ }