gsd-pi 2.64.0 → 2.65.0

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 (255) hide show
  1. package/dist/headless.js +3 -1
  2. package/dist/resources/extensions/bg-shell/bg-shell-lifecycle.js +22 -7
  3. package/dist/resources/extensions/bg-shell/process-manager.js +6 -1
  4. package/dist/resources/extensions/gsd/auto-dashboard.js +5 -5
  5. package/dist/resources/extensions/gsd/auto-post-unit.js +98 -1
  6. package/dist/resources/extensions/gsd/auto-verification.js +138 -1
  7. package/dist/resources/extensions/gsd/auto.js +5 -0
  8. package/dist/resources/extensions/gsd/bootstrap/db-tools.js +24 -13
  9. package/dist/resources/extensions/gsd/bootstrap/notify-interceptor.js +28 -0
  10. package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +8 -0
  11. package/dist/resources/extensions/gsd/bootstrap/register-shortcuts.js +16 -0
  12. package/dist/resources/extensions/gsd/bootstrap/system-context.js +20 -0
  13. package/dist/resources/extensions/gsd/commands/catalog.js +7 -1
  14. package/dist/resources/extensions/gsd/commands/handlers/core.js +1 -0
  15. package/dist/resources/extensions/gsd/commands/handlers/notifications-handler.js +104 -0
  16. package/dist/resources/extensions/gsd/commands/handlers/ops.js +5 -0
  17. package/dist/resources/extensions/gsd/notification-overlay.js +256 -0
  18. package/dist/resources/extensions/gsd/notification-store.js +273 -0
  19. package/dist/resources/extensions/gsd/notification-widget.js +56 -0
  20. package/dist/resources/extensions/gsd/post-execution-checks.js +407 -0
  21. package/dist/resources/extensions/gsd/pre-execution-checks.js +464 -0
  22. package/dist/resources/extensions/gsd/preferences-types.js +4 -0
  23. package/dist/resources/extensions/gsd/preferences-validation.js +33 -0
  24. package/dist/resources/extensions/gsd/preferences.js +4 -0
  25. package/dist/resources/extensions/gsd/verification-evidence.js +18 -0
  26. package/dist/resources/extensions/gsd/workflow-logger.js +8 -0
  27. package/dist/web/standalone/.next/BUILD_ID +1 -1
  28. package/dist/web/standalone/.next/app-path-routes-manifest.json +7 -6
  29. package/dist/web/standalone/.next/build-manifest.json +2 -2
  30. package/dist/web/standalone/.next/prerender-manifest.json +3 -3
  31. package/dist/web/standalone/.next/required-server-files.json +1 -1
  32. package/dist/web/standalone/.next/routes-manifest.json +6 -0
  33. package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
  34. package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
  35. package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  36. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  37. package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  38. package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  39. package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  40. package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  41. package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
  42. package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
  43. package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  44. package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  45. package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  46. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  47. package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  48. package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  49. package/dist/web/standalone/.next/server/app/api/notifications/route.js +3 -0
  50. package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -0
  51. package/dist/web/standalone/.next/server/app/api/notifications/route_client-reference-manifest.js +1 -0
  52. package/dist/web/standalone/.next/server/app/index.html +1 -1
  53. package/dist/web/standalone/.next/server/app/index.rsc +1 -1
  54. package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  55. package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
  56. package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  57. package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  58. package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  59. package/dist/web/standalone/.next/server/app-paths-manifest.json +7 -6
  60. package/dist/web/standalone/.next/server/functions-config-manifest.json +1 -0
  61. package/dist/web/standalone/.next/server/pages/404.html +1 -1
  62. package/dist/web/standalone/.next/server/pages/500.html +2 -2
  63. package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
  64. package/dist/web/standalone/.next/static/MRM3OSYIAa4HMDqVGQ9nt/_buildManifest.js +1 -0
  65. package/dist/web/standalone/.next/static/chunks/app/_global-error/page-8805a20e15762c3c.js +1 -0
  66. package/dist/web/standalone/.next/static/chunks/app/api/boot/route-8805a20e15762c3c.js +1 -0
  67. package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/input/route-8805a20e15762c3c.js +1 -0
  68. package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/resize/route-8805a20e15762c3c.js +1 -0
  69. package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/stream/route-8805a20e15762c3c.js +1 -0
  70. package/dist/web/standalone/.next/static/chunks/app/api/browse-directories/route-8805a20e15762c3c.js +1 -0
  71. package/dist/web/standalone/.next/static/chunks/app/api/captures/route-8805a20e15762c3c.js +1 -0
  72. package/dist/web/standalone/.next/static/chunks/app/api/cleanup/route-8805a20e15762c3c.js +1 -0
  73. package/dist/web/standalone/.next/static/chunks/app/api/dev-mode/route-8805a20e15762c3c.js +1 -0
  74. package/dist/web/standalone/.next/static/chunks/app/api/doctor/route-8805a20e15762c3c.js +1 -0
  75. package/dist/web/standalone/.next/static/chunks/app/api/experimental/route-8805a20e15762c3c.js +1 -0
  76. package/dist/web/standalone/.next/static/chunks/app/api/export-data/route-8805a20e15762c3c.js +1 -0
  77. package/dist/web/standalone/.next/static/chunks/app/api/files/route-8805a20e15762c3c.js +1 -0
  78. package/dist/web/standalone/.next/static/chunks/app/api/forensics/route-8805a20e15762c3c.js +1 -0
  79. package/dist/web/standalone/.next/static/chunks/app/api/git/route-8805a20e15762c3c.js +1 -0
  80. package/dist/web/standalone/.next/static/chunks/app/api/history/route-8805a20e15762c3c.js +1 -0
  81. package/dist/web/standalone/.next/static/chunks/app/api/hooks/route-8805a20e15762c3c.js +1 -0
  82. package/dist/web/standalone/.next/static/chunks/app/api/inspect/route-8805a20e15762c3c.js +1 -0
  83. package/dist/web/standalone/.next/static/chunks/app/api/knowledge/route-8805a20e15762c3c.js +1 -0
  84. package/dist/web/standalone/.next/static/chunks/app/api/live-state/route-8805a20e15762c3c.js +1 -0
  85. package/dist/web/standalone/.next/static/chunks/app/api/notifications/route-8805a20e15762c3c.js +1 -0
  86. package/dist/web/standalone/.next/static/chunks/app/api/onboarding/route-8805a20e15762c3c.js +1 -0
  87. package/dist/web/standalone/.next/static/chunks/app/api/preferences/route-8805a20e15762c3c.js +1 -0
  88. package/dist/web/standalone/.next/static/chunks/app/api/projects/route-8805a20e15762c3c.js +1 -0
  89. package/dist/web/standalone/.next/static/chunks/app/api/recovery/route-8805a20e15762c3c.js +1 -0
  90. package/dist/web/standalone/.next/static/chunks/app/api/remote-questions/route-8805a20e15762c3c.js +1 -0
  91. package/dist/web/standalone/.next/static/chunks/app/api/session/browser/route-8805a20e15762c3c.js +1 -0
  92. package/dist/web/standalone/.next/static/chunks/app/api/session/command/route-8805a20e15762c3c.js +1 -0
  93. package/dist/web/standalone/.next/static/chunks/app/api/session/events/route-8805a20e15762c3c.js +1 -0
  94. package/dist/web/standalone/.next/static/chunks/app/api/session/manage/route-8805a20e15762c3c.js +1 -0
  95. package/dist/web/standalone/.next/static/chunks/app/api/settings-data/route-8805a20e15762c3c.js +1 -0
  96. package/dist/web/standalone/.next/static/chunks/app/api/shutdown/route-8805a20e15762c3c.js +1 -0
  97. package/dist/web/standalone/.next/static/chunks/app/api/skill-health/route-8805a20e15762c3c.js +1 -0
  98. package/dist/web/standalone/.next/static/chunks/app/api/steer/route-8805a20e15762c3c.js +1 -0
  99. package/dist/web/standalone/.next/static/chunks/app/api/switch-root/route-8805a20e15762c3c.js +1 -0
  100. package/dist/web/standalone/.next/static/chunks/app/api/terminal/input/route-8805a20e15762c3c.js +1 -0
  101. package/dist/web/standalone/.next/static/chunks/app/api/terminal/resize/route-8805a20e15762c3c.js +1 -0
  102. package/dist/web/standalone/.next/static/chunks/app/api/terminal/sessions/route-8805a20e15762c3c.js +1 -0
  103. package/dist/web/standalone/.next/static/chunks/app/api/terminal/stream/route-8805a20e15762c3c.js +1 -0
  104. package/dist/web/standalone/.next/static/chunks/app/api/terminal/upload/route-8805a20e15762c3c.js +1 -0
  105. package/dist/web/standalone/.next/static/chunks/app/api/undo/route-8805a20e15762c3c.js +1 -0
  106. package/dist/web/standalone/.next/static/chunks/app/api/update/route-8805a20e15762c3c.js +1 -0
  107. package/dist/web/standalone/.next/static/chunks/app/api/visualizer/route-8805a20e15762c3c.js +1 -0
  108. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-8805a20e15762c3c.js +1 -0
  109. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-8805a20e15762c3c.js +1 -0
  110. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-8805a20e15762c3c.js +1 -0
  111. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-8805a20e15762c3c.js +1 -0
  112. package/dist/web/standalone/server.js +1 -1
  113. package/package.json +1 -1
  114. package/packages/pi-agent-core/dist/agent-loop.js +26 -9
  115. package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
  116. package/packages/pi-agent-core/src/agent-loop.test.ts +100 -4
  117. package/packages/pi-agent-core/src/agent-loop.ts +43 -12
  118. package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.d.ts +2 -0
  119. package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.d.ts.map +1 -0
  120. package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js +38 -0
  121. package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js.map +1 -0
  122. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  123. package/packages/pi-coding-agent/dist/core/agent-session.js +11 -0
  124. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  125. package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.d.ts +2 -0
  126. package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.d.ts.map +1 -0
  127. package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.js +24 -0
  128. package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.js.map +1 -0
  129. package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
  130. package/packages/pi-coding-agent/dist/core/resource-loader.js +4 -1
  131. package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
  132. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +1 -0
  133. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  134. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +8 -0
  135. package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  136. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +6 -0
  137. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  138. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +36 -0
  139. package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  140. package/packages/pi-coding-agent/package.json +1 -1
  141. package/packages/pi-coding-agent/src/core/agent-session-tool-refresh.test.ts +64 -0
  142. package/packages/pi-coding-agent/src/core/agent-session.ts +10 -0
  143. package/packages/pi-coding-agent/src/core/resource-loader-cache-reset.test.ts +42 -0
  144. package/packages/pi-coding-agent/src/core/resource-loader.ts +5 -1
  145. package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +9 -0
  146. package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +33 -0
  147. package/packages/pi-tui/dist/__tests__/overlay-layout.test.d.ts +2 -0
  148. package/packages/pi-tui/dist/__tests__/overlay-layout.test.d.ts.map +1 -0
  149. package/packages/pi-tui/dist/__tests__/overlay-layout.test.js +66 -0
  150. package/packages/pi-tui/dist/__tests__/overlay-layout.test.js.map +1 -0
  151. package/packages/pi-tui/dist/components/loader.d.ts +4 -2
  152. package/packages/pi-tui/dist/components/loader.d.ts.map +1 -1
  153. package/packages/pi-tui/dist/components/loader.js +27 -9
  154. package/packages/pi-tui/dist/components/loader.js.map +1 -1
  155. package/packages/pi-tui/dist/components/text.d.ts.map +1 -1
  156. package/packages/pi-tui/dist/components/text.js +2 -0
  157. package/packages/pi-tui/dist/components/text.js.map +1 -1
  158. package/packages/pi-tui/dist/overlay-layout.d.ts.map +1 -1
  159. package/packages/pi-tui/dist/overlay-layout.js +12 -1
  160. package/packages/pi-tui/dist/overlay-layout.js.map +1 -1
  161. package/packages/pi-tui/dist/tui.d.ts +4 -0
  162. package/packages/pi-tui/dist/tui.d.ts.map +1 -1
  163. package/packages/pi-tui/dist/tui.js +35 -0
  164. package/packages/pi-tui/dist/tui.js.map +1 -1
  165. package/packages/pi-tui/src/__tests__/overlay-layout.test.ts +82 -0
  166. package/packages/pi-tui/src/components/loader.ts +27 -10
  167. package/packages/pi-tui/src/components/text.ts +1 -0
  168. package/packages/pi-tui/src/overlay-layout.ts +13 -1
  169. package/packages/pi-tui/src/tui.ts +34 -0
  170. package/pkg/package.json +1 -1
  171. package/src/resources/extensions/bg-shell/bg-shell-lifecycle.ts +19 -7
  172. package/src/resources/extensions/bg-shell/process-manager.ts +8 -2
  173. package/src/resources/extensions/gsd/auto-dashboard.ts +5 -4
  174. package/src/resources/extensions/gsd/auto-post-unit.ts +122 -0
  175. package/src/resources/extensions/gsd/auto-verification.ts +190 -2
  176. package/src/resources/extensions/gsd/auto.ts +4 -0
  177. package/src/resources/extensions/gsd/bootstrap/db-tools.ts +25 -13
  178. package/src/resources/extensions/gsd/bootstrap/notify-interceptor.ts +34 -0
  179. package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +8 -0
  180. package/src/resources/extensions/gsd/bootstrap/register-shortcuts.ts +20 -0
  181. package/src/resources/extensions/gsd/bootstrap/system-context.ts +28 -0
  182. package/src/resources/extensions/gsd/commands/catalog.ts +7 -1
  183. package/src/resources/extensions/gsd/commands/handlers/core.ts +1 -0
  184. package/src/resources/extensions/gsd/commands/handlers/notifications-handler.ts +140 -0
  185. package/src/resources/extensions/gsd/commands/handlers/ops.ts +5 -0
  186. package/src/resources/extensions/gsd/notification-overlay.ts +295 -0
  187. package/src/resources/extensions/gsd/notification-store.ts +293 -0
  188. package/src/resources/extensions/gsd/notification-widget.ts +68 -0
  189. package/src/resources/extensions/gsd/post-execution-checks.ts +539 -0
  190. package/src/resources/extensions/gsd/pre-execution-checks.ts +573 -0
  191. package/src/resources/extensions/gsd/preferences-types.ts +28 -0
  192. package/src/resources/extensions/gsd/preferences-validation.ts +33 -0
  193. package/src/resources/extensions/gsd/preferences.ts +4 -0
  194. package/src/resources/extensions/gsd/tests/auto-start-time-persistence.test.ts +50 -0
  195. package/src/resources/extensions/gsd/tests/complete-slice-string-coercion.test.ts +36 -0
  196. package/src/resources/extensions/gsd/tests/discuss-tool-scope-leak.test.ts +76 -0
  197. package/src/resources/extensions/gsd/tests/enhanced-verification-integration.test.ts +526 -0
  198. package/src/resources/extensions/gsd/tests/notification-overlay.test.ts +73 -0
  199. package/src/resources/extensions/gsd/tests/notification-store.test.ts +282 -0
  200. package/src/resources/extensions/gsd/tests/post-exec-retry-bypass.test.ts +312 -0
  201. package/src/resources/extensions/gsd/tests/post-execution-checks.test.ts +813 -0
  202. package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +999 -0
  203. package/src/resources/extensions/gsd/tests/pre-execution-fail-closed.test.ts +266 -0
  204. package/src/resources/extensions/gsd/tests/pre-execution-pause-wiring.test.ts +457 -0
  205. package/src/resources/extensions/gsd/tests/unstructured-continue-context-injection.test.ts +163 -0
  206. package/src/resources/extensions/gsd/verification-evidence.ts +68 -0
  207. package/src/resources/extensions/gsd/workflow-logger.ts +13 -0
  208. package/dist/web/standalone/.next/static/chunks/app/_global-error/page-c4cc189e7b117ea2.js +0 -1
  209. package/dist/web/standalone/.next/static/chunks/app/api/boot/route-c4cc189e7b117ea2.js +0 -1
  210. package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/input/route-c4cc189e7b117ea2.js +0 -1
  211. package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/resize/route-c4cc189e7b117ea2.js +0 -1
  212. package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/stream/route-c4cc189e7b117ea2.js +0 -1
  213. package/dist/web/standalone/.next/static/chunks/app/api/browse-directories/route-c4cc189e7b117ea2.js +0 -1
  214. package/dist/web/standalone/.next/static/chunks/app/api/captures/route-c4cc189e7b117ea2.js +0 -1
  215. package/dist/web/standalone/.next/static/chunks/app/api/cleanup/route-c4cc189e7b117ea2.js +0 -1
  216. package/dist/web/standalone/.next/static/chunks/app/api/dev-mode/route-c4cc189e7b117ea2.js +0 -1
  217. package/dist/web/standalone/.next/static/chunks/app/api/doctor/route-c4cc189e7b117ea2.js +0 -1
  218. package/dist/web/standalone/.next/static/chunks/app/api/experimental/route-c4cc189e7b117ea2.js +0 -1
  219. package/dist/web/standalone/.next/static/chunks/app/api/export-data/route-c4cc189e7b117ea2.js +0 -1
  220. package/dist/web/standalone/.next/static/chunks/app/api/files/route-c4cc189e7b117ea2.js +0 -1
  221. package/dist/web/standalone/.next/static/chunks/app/api/forensics/route-c4cc189e7b117ea2.js +0 -1
  222. package/dist/web/standalone/.next/static/chunks/app/api/git/route-c4cc189e7b117ea2.js +0 -1
  223. package/dist/web/standalone/.next/static/chunks/app/api/history/route-c4cc189e7b117ea2.js +0 -1
  224. package/dist/web/standalone/.next/static/chunks/app/api/hooks/route-c4cc189e7b117ea2.js +0 -1
  225. package/dist/web/standalone/.next/static/chunks/app/api/inspect/route-c4cc189e7b117ea2.js +0 -1
  226. package/dist/web/standalone/.next/static/chunks/app/api/knowledge/route-c4cc189e7b117ea2.js +0 -1
  227. package/dist/web/standalone/.next/static/chunks/app/api/live-state/route-c4cc189e7b117ea2.js +0 -1
  228. package/dist/web/standalone/.next/static/chunks/app/api/onboarding/route-c4cc189e7b117ea2.js +0 -1
  229. package/dist/web/standalone/.next/static/chunks/app/api/preferences/route-c4cc189e7b117ea2.js +0 -1
  230. package/dist/web/standalone/.next/static/chunks/app/api/projects/route-c4cc189e7b117ea2.js +0 -1
  231. package/dist/web/standalone/.next/static/chunks/app/api/recovery/route-c4cc189e7b117ea2.js +0 -1
  232. package/dist/web/standalone/.next/static/chunks/app/api/remote-questions/route-c4cc189e7b117ea2.js +0 -1
  233. package/dist/web/standalone/.next/static/chunks/app/api/session/browser/route-c4cc189e7b117ea2.js +0 -1
  234. package/dist/web/standalone/.next/static/chunks/app/api/session/command/route-c4cc189e7b117ea2.js +0 -1
  235. package/dist/web/standalone/.next/static/chunks/app/api/session/events/route-c4cc189e7b117ea2.js +0 -1
  236. package/dist/web/standalone/.next/static/chunks/app/api/session/manage/route-c4cc189e7b117ea2.js +0 -1
  237. package/dist/web/standalone/.next/static/chunks/app/api/settings-data/route-c4cc189e7b117ea2.js +0 -1
  238. package/dist/web/standalone/.next/static/chunks/app/api/shutdown/route-c4cc189e7b117ea2.js +0 -1
  239. package/dist/web/standalone/.next/static/chunks/app/api/skill-health/route-c4cc189e7b117ea2.js +0 -1
  240. package/dist/web/standalone/.next/static/chunks/app/api/steer/route-c4cc189e7b117ea2.js +0 -1
  241. package/dist/web/standalone/.next/static/chunks/app/api/switch-root/route-c4cc189e7b117ea2.js +0 -1
  242. package/dist/web/standalone/.next/static/chunks/app/api/terminal/input/route-c4cc189e7b117ea2.js +0 -1
  243. package/dist/web/standalone/.next/static/chunks/app/api/terminal/resize/route-c4cc189e7b117ea2.js +0 -1
  244. package/dist/web/standalone/.next/static/chunks/app/api/terminal/sessions/route-c4cc189e7b117ea2.js +0 -1
  245. package/dist/web/standalone/.next/static/chunks/app/api/terminal/stream/route-c4cc189e7b117ea2.js +0 -1
  246. package/dist/web/standalone/.next/static/chunks/app/api/terminal/upload/route-c4cc189e7b117ea2.js +0 -1
  247. package/dist/web/standalone/.next/static/chunks/app/api/undo/route-c4cc189e7b117ea2.js +0 -1
  248. package/dist/web/standalone/.next/static/chunks/app/api/update/route-c4cc189e7b117ea2.js +0 -1
  249. package/dist/web/standalone/.next/static/chunks/app/api/visualizer/route-c4cc189e7b117ea2.js +0 -1
  250. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-c4cc189e7b117ea2.js +0 -1
  251. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-c4cc189e7b117ea2.js +0 -1
  252. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-c4cc189e7b117ea2.js +0 -1
  253. package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-c4cc189e7b117ea2.js +0 -1
  254. package/dist/web/standalone/.next/static/eebXKteM9EaWyseHKTjqp/_buildManifest.js +0 -1
  255. /package/dist/web/standalone/.next/static/{eebXKteM9EaWyseHKTjqp → MRM3OSYIAa4HMDqVGQ9nt}/_ssgManifest.js +0 -0
@@ -0,0 +1,295 @@
1
+ // GSD Extension — Notification History Overlay
2
+ // Scrollable panel showing all persisted notifications with severity filtering.
3
+ // Toggled with Ctrl+Alt+N or opened from /gsd notifications.
4
+
5
+ import type { Theme } from "@gsd/pi-coding-agent";
6
+ import { truncateToWidth, visibleWidth, matchesKey, Key } from "@gsd/pi-tui";
7
+
8
+ import {
9
+ readNotifications,
10
+ markAllRead,
11
+ clearNotifications,
12
+ getUnreadCount,
13
+ type NotificationEntry,
14
+ type NotifySeverity,
15
+ } from "./notification-store.js";
16
+ import { padRight, centerLine, joinColumns, formatDuration } from "../shared/mod.js";
17
+
18
+ type FilterMode = "all" | "error" | "warning" | "info";
19
+ const FILTER_CYCLE: FilterMode[] = ["all", "error", "warning", "info"];
20
+
21
+ function severityIcon(severity: NotifySeverity): string {
22
+ switch (severity) {
23
+ case "error": return "✗";
24
+ case "warning": return "⚠";
25
+ case "success": return "✓";
26
+ case "info":
27
+ default: return "●";
28
+ }
29
+ }
30
+
31
+ /** Word-wrap plain text to fit within maxWidth columns. */
32
+ function wrapText(text: string, maxWidth: number): string[] {
33
+ if (text.length <= maxWidth) return [text];
34
+ const words = text.split(/\s+/);
35
+ const lines: string[] = [];
36
+ let current = "";
37
+ for (const word of words) {
38
+ if (current.length === 0) {
39
+ current = word;
40
+ } else if (current.length + 1 + word.length <= maxWidth) {
41
+ current += " " + word;
42
+ } else {
43
+ lines.push(current);
44
+ current = word;
45
+ }
46
+ }
47
+ if (current.length > 0) lines.push(current);
48
+ // If a single word exceeds maxWidth, truncate it
49
+ return lines.map((l) => l.length > maxWidth ? l.slice(0, maxWidth - 1) + "…" : l);
50
+ }
51
+
52
+ function formatTimestamp(ts: string): string {
53
+ try {
54
+ const d = new Date(ts);
55
+ const now = Date.now();
56
+ const diffMs = now - d.getTime();
57
+ if (diffMs < 60_000) return "just now";
58
+ if (diffMs < 3600_000) return `${Math.floor(diffMs / 60_000)}m ago`;
59
+ if (diffMs < 86400_000) return `${Math.floor(diffMs / 3600_000)}h ago`;
60
+ return `${Math.floor(diffMs / 86400_000)}d ago`;
61
+ } catch {
62
+ return ts.slice(11, 19); // fallback: HH:MM:SS
63
+ }
64
+ }
65
+
66
+ export class GSDNotificationOverlay {
67
+ private tui: { requestRender: () => void };
68
+ private theme: Theme;
69
+ private onClose: () => void;
70
+ private cachedWidth?: number;
71
+ private cachedLines?: string[];
72
+ private scrollOffset = 0;
73
+ private filterIndex = 0;
74
+ private entries: NotificationEntry[] = [];
75
+ private refreshTimer: ReturnType<typeof setInterval>;
76
+ private disposed = false;
77
+ private resizeHandler: (() => void) | null = null;
78
+
79
+ constructor(
80
+ tui: { requestRender: () => void },
81
+ theme: Theme,
82
+ onClose: () => void,
83
+ ) {
84
+ this.tui = tui;
85
+ this.theme = theme;
86
+ this.onClose = onClose;
87
+
88
+ // Mark all as read on open
89
+ markAllRead();
90
+ this.entries = readNotifications();
91
+
92
+ // Resize handler
93
+ this.resizeHandler = () => {
94
+ if (this.disposed) return;
95
+ this.invalidate();
96
+ this.tui.requestRender();
97
+ };
98
+ process.stdout.on("resize", this.resizeHandler);
99
+
100
+ // Refresh every 3s for new notifications
101
+ this.refreshTimer = setInterval(() => {
102
+ if (this.disposed) return;
103
+ const fresh = readNotifications();
104
+ if (fresh.length !== this.entries.length) {
105
+ this.entries = fresh;
106
+ markAllRead();
107
+ this.invalidate();
108
+ this.tui.requestRender();
109
+ }
110
+ }, 3000);
111
+ }
112
+
113
+ private get filter(): FilterMode {
114
+ return FILTER_CYCLE[this.filterIndex]!;
115
+ }
116
+
117
+ private get filteredEntries(): NotificationEntry[] {
118
+ if (this.filter === "all") return this.entries;
119
+ return this.entries.filter((e) => e.severity === this.filter);
120
+ }
121
+
122
+ handleInput(data: string): void {
123
+ if (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c")) || matchesKey(data, Key.ctrlAlt("n"))) {
124
+ this.dispose();
125
+ this.onClose();
126
+ return;
127
+ }
128
+
129
+ // Scroll
130
+ if (matchesKey(data, Key.down) || matchesKey(data, "j")) {
131
+ this.scrollOffset++;
132
+ this.invalidate();
133
+ this.tui.requestRender();
134
+ return;
135
+ }
136
+ if (matchesKey(data, Key.up) || matchesKey(data, "k")) {
137
+ this.scrollOffset = Math.max(0, this.scrollOffset - 1);
138
+ this.invalidate();
139
+ this.tui.requestRender();
140
+ return;
141
+ }
142
+ if (data === "g") {
143
+ this.scrollOffset = 0;
144
+ this.invalidate();
145
+ this.tui.requestRender();
146
+ return;
147
+ }
148
+ if (data === "G") {
149
+ this.scrollOffset = 999;
150
+ this.invalidate();
151
+ this.tui.requestRender();
152
+ return;
153
+ }
154
+
155
+ // Filter cycle
156
+ if (data === "f") {
157
+ this.filterIndex = (this.filterIndex + 1) % FILTER_CYCLE.length;
158
+ this.scrollOffset = 0;
159
+ this.invalidate();
160
+ this.tui.requestRender();
161
+ return;
162
+ }
163
+
164
+ // Clear all
165
+ if (data === "c") {
166
+ clearNotifications();
167
+ this.entries = [];
168
+ this.scrollOffset = 0;
169
+ this.invalidate();
170
+ this.tui.requestRender();
171
+ return;
172
+ }
173
+ }
174
+
175
+ render(width: number): string[] {
176
+ if (this.cachedLines && this.cachedWidth === width) {
177
+ return this.cachedLines;
178
+ }
179
+
180
+ const content = this.buildContentLines(width);
181
+ const maxVisibleRows = Math.max(5, process.stdout.rows ? process.stdout.rows - 8 : 24) - 2;
182
+ const visibleContentRows = Math.min(content.length, maxVisibleRows);
183
+ const maxScroll = Math.max(0, content.length - visibleContentRows);
184
+ this.scrollOffset = Math.min(this.scrollOffset, maxScroll);
185
+ const visibleContent = content.slice(this.scrollOffset, this.scrollOffset + visibleContentRows);
186
+
187
+ const lines = this.wrapInBox(visibleContent, width);
188
+
189
+ this.cachedWidth = width;
190
+ this.cachedLines = lines;
191
+ return lines;
192
+ }
193
+
194
+ invalidate(): void {
195
+ this.cachedLines = undefined;
196
+ this.cachedWidth = undefined;
197
+ }
198
+
199
+ dispose(): void {
200
+ this.disposed = true;
201
+ clearInterval(this.refreshTimer);
202
+ if (this.resizeHandler) {
203
+ process.stdout.removeListener("resize", this.resizeHandler);
204
+ this.resizeHandler = null;
205
+ }
206
+ }
207
+
208
+ private wrapInBox(inner: string[], width: number): string[] {
209
+ const th = this.theme;
210
+ const border = (s: string) => th.fg("borderAccent", s);
211
+ const innerWidth = width - 4;
212
+ const lines: string[] = [];
213
+
214
+ lines.push(border("╭" + "─".repeat(width - 2) + "╮"));
215
+ for (const line of inner) {
216
+ const truncated = truncateToWidth(line, innerWidth);
217
+ const padWidth = Math.max(0, innerWidth - visibleWidth(truncated));
218
+ lines.push(border("│") + " " + truncated + " ".repeat(padWidth) + " " + border("│"));
219
+ }
220
+ lines.push(border("╰" + "─".repeat(width - 2) + "╯"));
221
+ return lines;
222
+ }
223
+
224
+ private buildContentLines(width: number): string[] {
225
+ const th = this.theme;
226
+ const shellWidth = width - 4;
227
+ const contentWidth = Math.min(shellWidth, 128);
228
+ const sidePad = Math.max(0, Math.floor((shellWidth - contentWidth) / 2));
229
+ const leftMargin = " ".repeat(sidePad);
230
+ const lines: string[] = [];
231
+
232
+ const row = (content = ""): string => {
233
+ const truncated = truncateToWidth(content, contentWidth);
234
+ return leftMargin + padRight(truncated, contentWidth);
235
+ };
236
+ const blank = () => row("");
237
+ const hr = () => row(th.fg("dim", "─".repeat(contentWidth)));
238
+
239
+ // Header
240
+ const title = th.fg("accent", th.bold("Notifications"));
241
+ const filterLabel = this.filter === "all"
242
+ ? th.fg("dim", "all")
243
+ : th.fg(this.filter === "error" ? "error" : this.filter === "warning" ? "warning" : "dim", this.filter);
244
+ const count = `${this.filteredEntries.length} entries`;
245
+ lines.push(row(joinColumns(
246
+ `${title} ${th.fg("dim", "filter:")} ${filterLabel}`,
247
+ th.fg("dim", count),
248
+ contentWidth,
249
+ )));
250
+ lines.push(hr());
251
+
252
+ // Controls
253
+ lines.push(row(th.fg("dim", "↑/↓ scroll f filter c clear Esc close")));
254
+ lines.push(blank());
255
+
256
+ // Entries
257
+ const filtered = this.filteredEntries;
258
+ if (filtered.length === 0) {
259
+ lines.push(blank());
260
+ lines.push(row(th.fg("dim", this.entries.length === 0
261
+ ? "No notifications yet."
262
+ : `No ${this.filter} notifications.`)));
263
+ lines.push(blank());
264
+ return lines;
265
+ }
266
+
267
+ for (const entry of filtered) {
268
+ const icon = severityIcon(entry.severity);
269
+ const coloredIcon = entry.severity === "error" ? th.fg("error", icon)
270
+ : entry.severity === "warning" ? th.fg("warning", icon)
271
+ : entry.severity === "success" ? th.fg("success", icon)
272
+ : th.fg("dim", icon);
273
+ const time = th.fg("dim", formatTimestamp(entry.ts));
274
+ const source = entry.source === "workflow-logger" ? th.fg("dim", " [engine]") : "";
275
+
276
+ // Measure actual prefix width for wrapping
277
+ const prefix = `${coloredIcon} ${time}${source} `;
278
+ const prefixWidth = visibleWidth(prefix);
279
+ const msgMaxWidth = Math.max(10, contentWidth - prefixWidth);
280
+
281
+ // Wrap long messages onto continuation lines indented to align with message start
282
+ const msgLines = wrapText(entry.message, msgMaxWidth);
283
+ const indent = " ".repeat(prefixWidth);
284
+ for (let i = 0; i < msgLines.length; i++) {
285
+ if (i === 0) {
286
+ lines.push(row(`${prefix}${msgLines[i]}`));
287
+ } else {
288
+ lines.push(row(`${indent}${msgLines[i]}`));
289
+ }
290
+ }
291
+ }
292
+
293
+ return lines;
294
+ }
295
+ }
@@ -0,0 +1,293 @@
1
+ // GSD Extension — Persistent Notification Store
2
+ // Captures all ctx.ui.notify() calls and workflow-logger warnings to
3
+ // .gsd/notifications.jsonl so they survive context resets and session restarts.
4
+ // Rotates at MAX_ENTRIES to prevent unbounded growth.
5
+
6
+ import { appendFileSync, existsSync, mkdirSync, openSync, closeSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { randomUUID } from "node:crypto";
9
+
10
+ // ─── Types ──────────────────────────────────────────────────────────────
11
+
12
+ export type NotifySeverity = "info" | "success" | "warning" | "error";
13
+ export type NotificationSource = "notify" | "workflow-logger";
14
+
15
+ export interface NotificationEntry {
16
+ id: string;
17
+ ts: string;
18
+ severity: NotifySeverity;
19
+ message: string;
20
+ source: NotificationSource;
21
+ read: boolean;
22
+ }
23
+
24
+ // ─── Constants ──────────────────────────────────────────────────────────
25
+
26
+ const MAX_ENTRIES = 500;
27
+ const FILENAME = "notifications.jsonl";
28
+ const LOCKFILE = "notifications.lock";
29
+
30
+ // ─── Module State ───────────────────────────────────────────────────────
31
+
32
+ let _basePath: string | null = null;
33
+ let _lineCount = 0; // Hint for rotation — not authoritative for public API
34
+ let _suppressCount = 0;
35
+
36
+ // ─── Public API ─────────────────────────────────────────────────────────
37
+
38
+ /**
39
+ * Initialize the notification store. Call once at session start with the
40
+ * project root. Seeds in-memory counters from the existing file on disk.
41
+ */
42
+ export function initNotificationStore(basePath: string): void {
43
+ _basePath = basePath;
44
+ // Seed line count hint for rotation — public counters read from disk
45
+ _lineCount = _readEntriesFromDisk(basePath).length;
46
+ }
47
+
48
+ /**
49
+ * Append a notification entry to the store. Synchronous — safe to call
50
+ * from the notify() shim which is declared void (not async).
51
+ */
52
+ export function appendNotification(
53
+ message: string,
54
+ severity: NotifySeverity,
55
+ source: NotificationSource = "notify",
56
+ ): void {
57
+ if (!_basePath) return;
58
+ if (_suppressCount > 0) return;
59
+
60
+ const entry: NotificationEntry = {
61
+ id: randomUUID(),
62
+ ts: new Date().toISOString(),
63
+ severity,
64
+ message: message.length > 500 ? message.slice(0, 500) + "…" : message,
65
+ source,
66
+ read: false,
67
+ };
68
+
69
+ try {
70
+ const dir = join(_basePath, ".gsd");
71
+ mkdirSync(dir, { recursive: true });
72
+ appendFileSync(join(dir, FILENAME), JSON.stringify(entry) + "\n", "utf-8");
73
+ _lineCount++;
74
+
75
+ // Rotate if hint suggests we're over limit
76
+ if (_lineCount > MAX_ENTRIES) {
77
+ _rotate();
78
+ }
79
+ } catch {
80
+ // Non-fatal — never let persistence break the caller
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Read all notification entries from disk. Returns newest-first.
86
+ */
87
+ export function readNotifications(basePath?: string): NotificationEntry[] {
88
+ const bp = basePath ?? _basePath;
89
+ if (!bp) return [];
90
+ return _readEntriesFromDisk(bp).reverse();
91
+ }
92
+
93
+ /**
94
+ * Mark all notifications as read. Atomic rewrite via temp-file + rename.
95
+ * Resyncs in-memory counters from disk after mutation.
96
+ */
97
+ export function markAllRead(basePath?: string): void {
98
+ const bp = basePath ?? _basePath;
99
+ if (!bp) return;
100
+
101
+ const entries = _readEntriesFromDisk(bp);
102
+ if (entries.length === 0) return;
103
+
104
+ const hasUnread = entries.some((e) => !e.read);
105
+ if (!hasUnread) return;
106
+
107
+ try {
108
+ _withLock(bp, () => {
109
+ // Re-read inside lock to get freshest state
110
+ const fresh = _readEntriesFromDisk(bp);
111
+ if (fresh.length === 0 || !fresh.some((e) => !e.read)) return;
112
+ const lines = fresh.map((e) => JSON.stringify({ ...e, read: true }));
113
+ _atomicWrite(bp, lines.join("\n") + "\n");
114
+ });
115
+ } catch {
116
+ // Non-fatal
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Clear all notifications. Atomic write of empty content under lock.
122
+ */
123
+ export function clearNotifications(basePath?: string): void {
124
+ const bp = basePath ?? _basePath;
125
+ if (!bp) return;
126
+
127
+ try {
128
+ _withLock(bp, () => {
129
+ _atomicWrite(bp, "");
130
+ });
131
+ } catch {
132
+ // Non-fatal
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Get the current unread count. Reads from disk to stay accurate across
138
+ * processes (web subprocess can clear/modify the file independently).
139
+ */
140
+ export function getUnreadCount(): number {
141
+ if (!_basePath) return 0;
142
+ try {
143
+ const entries = _readEntriesFromDisk(_basePath);
144
+ return entries.filter((e) => !e.read).length;
145
+ } catch {
146
+ return 0;
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Get the total notification count. Reads from disk for cross-process accuracy.
152
+ */
153
+ export function getLineCount(): number {
154
+ if (!_basePath) return 0;
155
+ try {
156
+ return _readEntriesFromDisk(_basePath).length;
157
+ } catch {
158
+ return 0;
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Temporarily suppress persistence. Use around ctx.ui.notify calls that
164
+ * should NOT be persisted (e.g., confirmation toasts after clear).
165
+ * Calls are ref-counted — nest safely.
166
+ */
167
+ export function suppressPersistence(): void {
168
+ _suppressCount++;
169
+ }
170
+
171
+ export function unsuppressPersistence(): void {
172
+ _suppressCount = Math.max(0, _suppressCount - 1);
173
+ }
174
+
175
+ // ─── Test Helpers ───────────────────────────────────────────────────────
176
+
177
+ /**
178
+ * Reset module state. Only for use in tests.
179
+ */
180
+ export function _resetNotificationStore(): void {
181
+ _basePath = null;
182
+ _lineCount = 0;
183
+ _suppressCount = 0;
184
+ }
185
+
186
+ // ─── Internal ───────────────────────────────────────────────────────────
187
+
188
+ function _readEntriesFromDisk(basePath: string): NotificationEntry[] {
189
+ const filePath = join(basePath, ".gsd", FILENAME);
190
+ if (!existsSync(filePath)) return [];
191
+ try {
192
+ const content = readFileSync(filePath, "utf-8");
193
+ return content
194
+ .split("\n")
195
+ .filter((l) => l.length > 0)
196
+ .map((l) => {
197
+ try {
198
+ return JSON.parse(l) as NotificationEntry;
199
+ } catch {
200
+ return null;
201
+ }
202
+ })
203
+ .filter((e): e is NotificationEntry => e !== null);
204
+ } catch {
205
+ return [];
206
+ }
207
+ }
208
+
209
+ function _rotate(): void {
210
+ if (!_basePath) return;
211
+ try {
212
+ _withLock(_basePath, () => {
213
+ // Re-read inside lock to get freshest state
214
+ const entries = _readEntriesFromDisk(_basePath!);
215
+ if (entries.length <= MAX_ENTRIES) return;
216
+ const trimmed = entries.slice(entries.length - MAX_ENTRIES);
217
+ const lines = trimmed.map((e) => JSON.stringify(e));
218
+ _atomicWrite(_basePath!, lines.join("\n") + "\n");
219
+ });
220
+ } catch {
221
+ // Non-fatal
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Atomic file rewrite via temp-file + rename. Prevents partial reads
227
+ * by other processes (web API subprocess, parallel workers).
228
+ * Must be called inside _withLock for cross-process safety.
229
+ */
230
+ function _atomicWrite(basePath: string, content: string): void {
231
+ const dir = join(basePath, ".gsd");
232
+ mkdirSync(dir, { recursive: true });
233
+ const target = join(dir, FILENAME);
234
+ const tmp = target + ".tmp." + process.pid;
235
+ writeFileSync(tmp, content, "utf-8");
236
+ renameSync(tmp, target);
237
+ }
238
+
239
+ /**
240
+ * Acquire an exclusive lockfile for rewrite operations.
241
+ * Uses O_CREAT|O_EXCL for atomic creation — if the file exists, another
242
+ * process holds the lock. Retries briefly, then proceeds anyway (best-effort)
243
+ * to avoid deadlocking the UI on a stale lock.
244
+ */
245
+ function _withLock<T>(basePath: string, fn: () => T): T {
246
+ const lockPath = join(basePath, ".gsd", LOCKFILE);
247
+ let fd: number | null = null;
248
+ const maxAttempts = 5;
249
+ const retryMs = 20;
250
+
251
+ for (let i = 0; i < maxAttempts; i++) {
252
+ try {
253
+ mkdirSync(join(basePath, ".gsd"), { recursive: true });
254
+ fd = openSync(lockPath, "wx");
255
+ break;
256
+ } catch (err: any) {
257
+ if (err?.code === "EEXIST") {
258
+ // Check if lock is stale (older than 5s)
259
+ try {
260
+ const stat = readFileSync(lockPath, "utf-8");
261
+ const lockTime = parseInt(stat, 10);
262
+ if (Date.now() - lockTime > 5000) {
263
+ try { unlinkSync(lockPath); } catch { /* race ok */ }
264
+ continue;
265
+ }
266
+ } catch { /* can't read lock, retry */ }
267
+
268
+ // Wait and retry
269
+ const start = Date.now();
270
+ while (Date.now() - start < retryMs) { /* spin */ }
271
+ continue;
272
+ }
273
+ // Other error — proceed without lock
274
+ break;
275
+ }
276
+ }
277
+
278
+ // Only run the mutation if we actually own the lock
279
+ const ownsLock = fd !== null;
280
+ try {
281
+ if (ownsLock && fd !== null) {
282
+ // Write our PID timestamp into the lock for stale detection
283
+ writeFileSync(lockPath, String(Date.now()), "utf-8");
284
+ closeSync(fd);
285
+ }
286
+ return fn();
287
+ } finally {
288
+ // Only delete the lock if we created it — never remove another process's lock
289
+ if (ownsLock) {
290
+ try { unlinkSync(lockPath); } catch { /* best-effort cleanup */ }
291
+ }
292
+ }
293
+ }
@@ -0,0 +1,68 @@
1
+ // GSD Extension — Notification Widget
2
+ // Always-on ambient widget rendered belowEditor showing unread count and
3
+ // the most recent notification message. Refreshes every 5 seconds.
4
+ // Widget key: "gsd-notifications", placement: "belowEditor"
5
+
6
+ import type { ExtensionContext } from "@gsd/pi-coding-agent";
7
+
8
+ import { getUnreadCount, readNotifications } from "./notification-store.js";
9
+
10
+ // ─── Pure rendering ──���────────────────────────���─────────────────────────
11
+
12
+ export function buildNotificationWidgetLines(): string[] {
13
+ const unread = getUnreadCount();
14
+ if (unread === 0) return [];
15
+
16
+ const entries = readNotifications();
17
+ const latest = entries[0]; // newest-first
18
+ if (!latest) return [];
19
+
20
+ const icon = latest.severity === "error" ? "✗" : latest.severity === "warning" ? "⚠" : "●";
21
+ const badge = `${unread} unread`;
22
+ const msgMax = 80;
23
+ const truncated = latest.message.length > msgMax
24
+ ? latest.message.slice(0, msgMax - 1) + "…"
25
+ : latest.message;
26
+
27
+ return [` ${icon} [${badge}] ${truncated} (Ctrl+Alt+N to view)`];
28
+ }
29
+
30
+ // ─── Widget init ────────────────────────────────────────────────────────
31
+
32
+ const REFRESH_INTERVAL_MS = 5_000;
33
+
34
+ /**
35
+ * Initialize the always-on notification widget (belowEditor).
36
+ * Call once from session_start after the notification store is initialized.
37
+ */
38
+ export function initNotificationWidget(ctx: ExtensionContext): void {
39
+ if (!ctx.hasUI) return;
40
+
41
+ // String-array fallback for RPC mode
42
+ ctx.ui.setWidget("gsd-notifications", buildNotificationWidgetLines(), { placement: "belowEditor" });
43
+
44
+ // Factory-based widget for TUI mode
45
+ ctx.ui.setWidget("gsd-notifications", (_tui, _theme) => {
46
+ let cachedLines: string[] | undefined;
47
+
48
+ const refresh = () => {
49
+ cachedLines = undefined;
50
+ _tui.requestRender();
51
+ };
52
+
53
+ const refreshTimer = setInterval(refresh, REFRESH_INTERVAL_MS);
54
+
55
+ return {
56
+ render(_width: number): string[] {
57
+ if (!cachedLines) cachedLines = buildNotificationWidgetLines();
58
+ return cachedLines;
59
+ },
60
+ invalidate(): void {
61
+ cachedLines = undefined;
62
+ },
63
+ dispose(): void {
64
+ clearInterval(refreshTimer);
65
+ },
66
+ };
67
+ }, { placement: "belowEditor" });
68
+ }