gsd-pi 2.63.0-dev.d04bbc5 → 2.64.0-dev.05b8a94
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.
- package/dist/headless.js +3 -1
- package/dist/resources/extensions/bg-shell/bg-shell-lifecycle.js +22 -7
- package/dist/resources/extensions/bg-shell/process-manager.js +6 -1
- package/dist/resources/extensions/gsd/auto-dashboard.js +5 -5
- package/dist/resources/extensions/gsd/auto-post-unit.js +98 -1
- package/dist/resources/extensions/gsd/auto-verification.js +138 -1
- package/dist/resources/extensions/gsd/auto.js +5 -0
- package/dist/resources/extensions/gsd/bootstrap/db-tools.js +24 -13
- package/dist/resources/extensions/gsd/bootstrap/notify-interceptor.js +28 -0
- package/dist/resources/extensions/gsd/bootstrap/register-hooks.js +8 -0
- package/dist/resources/extensions/gsd/bootstrap/register-shortcuts.js +15 -0
- package/dist/resources/extensions/gsd/bootstrap/system-context.js +20 -0
- package/dist/resources/extensions/gsd/commands/catalog.js +7 -1
- package/dist/resources/extensions/gsd/commands/handlers/core.js +1 -0
- package/dist/resources/extensions/gsd/commands/handlers/notifications-handler.js +103 -0
- package/dist/resources/extensions/gsd/commands/handlers/ops.js +5 -0
- package/dist/resources/extensions/gsd/notification-overlay.js +224 -0
- package/dist/resources/extensions/gsd/notification-store.js +268 -0
- package/dist/resources/extensions/gsd/notification-widget.js +56 -0
- package/dist/resources/extensions/gsd/post-execution-checks.js +407 -0
- package/dist/resources/extensions/gsd/pre-execution-checks.js +464 -0
- package/dist/resources/extensions/gsd/preferences-types.js +4 -0
- package/dist/resources/extensions/gsd/preferences-validation.js +33 -0
- package/dist/resources/extensions/gsd/preferences.js +4 -0
- package/dist/resources/extensions/gsd/verification-evidence.js +18 -0
- package/dist/resources/extensions/gsd/workflow-logger.js +8 -0
- package/dist/web/standalone/.next/BUILD_ID +1 -1
- package/dist/web/standalone/.next/app-path-routes-manifest.json +20 -19
- package/dist/web/standalone/.next/build-manifest.json +2 -2
- package/dist/web/standalone/.next/prerender-manifest.json +3 -3
- package/dist/web/standalone/.next/required-server-files.json +1 -1
- package/dist/web/standalone/.next/routes-manifest.json +6 -0
- package/dist/web/standalone/.next/server/app/_global-error.html +2 -2
- package/dist/web/standalone/.next/server/app/_global-error.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.html +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/api/notifications/route.js +3 -0
- package/dist/web/standalone/.next/server/app/api/notifications/route.js.nft.json +1 -0
- package/dist/web/standalone/.next/server/app/api/notifications/route_client-reference-manifest.js +1 -0
- package/dist/web/standalone/.next/server/app/index.html +1 -1
- package/dist/web/standalone/.next/server/app/index.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_full.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/dist/web/standalone/.next/server/app-paths-manifest.json +20 -19
- package/dist/web/standalone/.next/server/functions-config-manifest.json +1 -0
- package/dist/web/standalone/.next/server/pages/404.html +1 -1
- package/dist/web/standalone/.next/server/pages/500.html +2 -2
- package/dist/web/standalone/.next/server/server-reference-manifest.json +1 -1
- package/dist/web/standalone/.next/static/Vbx2-SrSBOgta6576xj9m/_buildManifest.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/_global-error/page-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/boot/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/input/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/resize/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/stream/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/browse-directories/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/captures/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/cleanup/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/dev-mode/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/doctor/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/experimental/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/export-data/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/files/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/forensics/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/git/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/history/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/hooks/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/inspect/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/knowledge/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/live-state/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/notifications/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/onboarding/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/preferences/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/projects/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/recovery/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/remote-questions/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/session/browser/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/session/command/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/session/events/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/session/manage/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/settings-data/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/shutdown/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/skill-health/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/steer/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/switch-root/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/input/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/resize/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/sessions/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/stream/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/upload/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/undo/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/update/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/app/api/visualizer/route-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-8805a20e15762c3c.js +1 -0
- package/dist/web/standalone/server.js +1 -1
- package/package.json +1 -1
- package/packages/pi-agent-core/dist/agent-loop.js +26 -9
- package/packages/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/packages/pi-agent-core/src/agent-loop.test.ts +100 -4
- package/packages/pi-agent-core/src/agent-loop.ts +43 -12
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js +38 -0
- package/packages/pi-coding-agent/dist/core/agent-session-tool-refresh.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/agent-session.js +11 -0
- package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.d.ts +2 -0
- package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.d.ts.map +1 -0
- package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.js +24 -0
- package/packages/pi-coding-agent/dist/core/resource-loader-cache-reset.test.js.map +1 -0
- package/packages/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js +4 -1
- package/packages/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +1 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js +8 -0
- package/packages/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +6 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js +36 -0
- package/packages/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/agent-session-tool-refresh.test.ts +64 -0
- package/packages/pi-coding-agent/src/core/agent-session.ts +10 -0
- package/packages/pi-coding-agent/src/core/resource-loader-cache-reset.test.ts +42 -0
- package/packages/pi-coding-agent/src/core/resource-loader.ts +5 -1
- package/packages/pi-coding-agent/src/modes/interactive/components/tool-execution.ts +9 -0
- package/packages/pi-coding-agent/src/modes/interactive/interactive-mode.ts +33 -0
- package/packages/pi-tui/dist/components/loader.d.ts +4 -2
- package/packages/pi-tui/dist/components/loader.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/loader.js +27 -9
- package/packages/pi-tui/dist/components/loader.js.map +1 -1
- package/packages/pi-tui/dist/components/text.d.ts.map +1 -1
- package/packages/pi-tui/dist/components/text.js +2 -0
- package/packages/pi-tui/dist/components/text.js.map +1 -1
- package/packages/pi-tui/dist/tui.d.ts +2 -0
- package/packages/pi-tui/dist/tui.d.ts.map +1 -1
- package/packages/pi-tui/dist/tui.js +35 -0
- package/packages/pi-tui/dist/tui.js.map +1 -1
- package/packages/pi-tui/src/components/loader.ts +27 -10
- package/packages/pi-tui/src/components/text.ts +1 -0
- package/packages/pi-tui/src/tui.ts +32 -0
- package/pkg/package.json +1 -1
- package/src/resources/extensions/bg-shell/bg-shell-lifecycle.ts +19 -7
- package/src/resources/extensions/bg-shell/process-manager.ts +8 -2
- package/src/resources/extensions/gsd/auto-dashboard.ts +5 -4
- package/src/resources/extensions/gsd/auto-post-unit.ts +122 -0
- package/src/resources/extensions/gsd/auto-verification.ts +190 -2
- package/src/resources/extensions/gsd/auto.ts +4 -0
- package/src/resources/extensions/gsd/bootstrap/db-tools.ts +25 -13
- package/src/resources/extensions/gsd/bootstrap/notify-interceptor.ts +34 -0
- package/src/resources/extensions/gsd/bootstrap/register-hooks.ts +8 -0
- package/src/resources/extensions/gsd/bootstrap/register-shortcuts.ts +19 -0
- package/src/resources/extensions/gsd/bootstrap/system-context.ts +28 -0
- package/src/resources/extensions/gsd/commands/catalog.ts +7 -1
- package/src/resources/extensions/gsd/commands/handlers/core.ts +1 -0
- package/src/resources/extensions/gsd/commands/handlers/notifications-handler.ts +139 -0
- package/src/resources/extensions/gsd/commands/handlers/ops.ts +5 -0
- package/src/resources/extensions/gsd/notification-overlay.ts +267 -0
- package/src/resources/extensions/gsd/notification-store.ts +288 -0
- package/src/resources/extensions/gsd/notification-widget.ts +68 -0
- package/src/resources/extensions/gsd/post-execution-checks.ts +539 -0
- package/src/resources/extensions/gsd/pre-execution-checks.ts +573 -0
- package/src/resources/extensions/gsd/preferences-types.ts +28 -0
- package/src/resources/extensions/gsd/preferences-validation.ts +33 -0
- package/src/resources/extensions/gsd/preferences.ts +4 -0
- package/src/resources/extensions/gsd/tests/auto-start-time-persistence.test.ts +50 -0
- package/src/resources/extensions/gsd/tests/complete-slice-string-coercion.test.ts +36 -0
- package/src/resources/extensions/gsd/tests/discuss-tool-scope-leak.test.ts +76 -0
- package/src/resources/extensions/gsd/tests/enhanced-verification-integration.test.ts +526 -0
- package/src/resources/extensions/gsd/tests/notification-store.test.ts +249 -0
- package/src/resources/extensions/gsd/tests/post-exec-retry-bypass.test.ts +312 -0
- package/src/resources/extensions/gsd/tests/post-execution-checks.test.ts +813 -0
- package/src/resources/extensions/gsd/tests/pre-execution-checks.test.ts +999 -0
- package/src/resources/extensions/gsd/tests/pre-execution-fail-closed.test.ts +266 -0
- package/src/resources/extensions/gsd/tests/pre-execution-pause-wiring.test.ts +457 -0
- package/src/resources/extensions/gsd/tests/unstructured-continue-context-injection.test.ts +163 -0
- package/src/resources/extensions/gsd/verification-evidence.ts +68 -0
- package/src/resources/extensions/gsd/workflow-logger.ts +13 -0
- package/dist/web/standalone/.next/static/chunks/app/_global-error/page-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/boot/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/input/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/resize/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/bridge-terminal/stream/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/browse-directories/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/captures/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/cleanup/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/dev-mode/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/doctor/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/experimental/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/export-data/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/files/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/forensics/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/git/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/history/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/hooks/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/inspect/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/knowledge/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/live-state/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/onboarding/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/preferences/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/projects/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/recovery/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/remote-questions/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/session/browser/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/session/command/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/session/events/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/session/manage/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/settings-data/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/shutdown/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/skill-health/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/steer/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/switch-root/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/input/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/resize/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/sessions/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/stream/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/terminal/upload/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/undo/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/update/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/app/api/visualizer/route-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/app-error-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/forbidden-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/not-found-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/chunks/next/dist/client/components/builtin/unauthorized-c4cc189e7b117ea2.js +0 -1
- package/dist/web/standalone/.next/static/vIq9fmvRUaFOpguoX5j4W/_buildManifest.js +0 -1
- /package/dist/web/standalone/.next/static/{vIq9fmvRUaFOpguoX5j4W → Vbx2-SrSBOgta6576xj9m}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// GSD Extension — /gsd notifications Command Handler
|
|
2
|
+
// View, filter, and clear the persistent notification history.
|
|
3
|
+
|
|
4
|
+
import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
readNotifications,
|
|
8
|
+
clearNotifications,
|
|
9
|
+
getUnreadCount,
|
|
10
|
+
suppressPersistence,
|
|
11
|
+
unsuppressPersistence,
|
|
12
|
+
type NotifySeverity,
|
|
13
|
+
} from "../../notification-store.js";
|
|
14
|
+
import { GSDNotificationOverlay } from "../../notification-overlay.js";
|
|
15
|
+
|
|
16
|
+
function severityIcon(severity: NotifySeverity): string {
|
|
17
|
+
switch (severity) {
|
|
18
|
+
case "error": return "✗";
|
|
19
|
+
case "warning": return "⚠";
|
|
20
|
+
case "success": return "✓";
|
|
21
|
+
case "info":
|
|
22
|
+
default: return "●";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function formatTimestamp(ts: string): string {
|
|
27
|
+
try {
|
|
28
|
+
const d = new Date(ts);
|
|
29
|
+
return d.toLocaleString("en-US", { hour12: false, month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" });
|
|
30
|
+
} catch {
|
|
31
|
+
return ts.slice(0, 19);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function handleNotificationsCommand(
|
|
36
|
+
args: string,
|
|
37
|
+
ctx: ExtensionCommandContext,
|
|
38
|
+
pi: ExtensionAPI,
|
|
39
|
+
): Promise<boolean> {
|
|
40
|
+
// /gsd notifications clear
|
|
41
|
+
if (args === "clear") {
|
|
42
|
+
clearNotifications();
|
|
43
|
+
// Suppress persistence so the confirmation toast doesn't re-populate the store
|
|
44
|
+
suppressPersistence();
|
|
45
|
+
try {
|
|
46
|
+
ctx.ui.notify("All notifications cleared.", "success");
|
|
47
|
+
} finally {
|
|
48
|
+
unsuppressPersistence();
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// /gsd notifications tail [N]
|
|
54
|
+
if (args === "tail" || args.startsWith("tail ")) {
|
|
55
|
+
const countStr = args.replace(/^tail\s*/, "").trim();
|
|
56
|
+
const count = countStr ? parseInt(countStr, 10) : 20;
|
|
57
|
+
const n = isNaN(count) || count < 1 ? 20 : Math.min(count, 100);
|
|
58
|
+
const entries = readNotifications().slice(0, n);
|
|
59
|
+
|
|
60
|
+
if (entries.length === 0) {
|
|
61
|
+
ctx.ui.notify("No notifications.", "info");
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const lines = entries.map((e) =>
|
|
66
|
+
`${severityIcon(e.severity)} [${formatTimestamp(e.ts)}] ${e.message}`,
|
|
67
|
+
);
|
|
68
|
+
ctx.ui.notify(`Last ${entries.length} notification(s):\n${lines.join("\n")}`, "info");
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// /gsd notifications filter <severity>
|
|
73
|
+
if (args.startsWith("filter ")) {
|
|
74
|
+
const severity = args.replace(/^filter\s+/, "").trim().toLowerCase();
|
|
75
|
+
if (!["error", "warning", "info", "success"].includes(severity)) {
|
|
76
|
+
ctx.ui.notify("Usage: /gsd notifications filter <error|warning|info|success>", "warning");
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
const entries = readNotifications().filter((e) => e.severity === severity);
|
|
80
|
+
|
|
81
|
+
if (entries.length === 0) {
|
|
82
|
+
ctx.ui.notify(`No ${severity} notifications.`, "info");
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const lines = entries.slice(0, 20).map((e) =>
|
|
87
|
+
`${severityIcon(e.severity)} [${formatTimestamp(e.ts)}] ${e.message}`,
|
|
88
|
+
);
|
|
89
|
+
const suffix = entries.length > 20 ? `\n... and ${entries.length - 20} more` : "";
|
|
90
|
+
ctx.ui.notify(`${severity} notifications (${entries.length}):\n${lines.join("\n")}${suffix}`, "info");
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// /gsd notifications (no args) — open overlay in TUI, or print summary
|
|
95
|
+
if (args === "" || args === "status") {
|
|
96
|
+
// Try overlay first (TUI mode)
|
|
97
|
+
if (ctx.hasUI) {
|
|
98
|
+
try {
|
|
99
|
+
await ctx.ui.custom<void>(
|
|
100
|
+
(tui, theme, _kb, done) => new GSDNotificationOverlay(tui, theme, () => done()),
|
|
101
|
+
{
|
|
102
|
+
overlay: true,
|
|
103
|
+
overlayOptions: {
|
|
104
|
+
width: "80%",
|
|
105
|
+
minWidth: 60,
|
|
106
|
+
maxHeight: "88%",
|
|
107
|
+
anchor: "center",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
);
|
|
111
|
+
return true;
|
|
112
|
+
} catch {
|
|
113
|
+
// Fall through to text output if overlay fails
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Text fallback (RPC/headless mode)
|
|
118
|
+
const unread = getUnreadCount();
|
|
119
|
+
const entries = readNotifications().slice(0, 10);
|
|
120
|
+
if (entries.length === 0) {
|
|
121
|
+
ctx.ui.notify("No notifications.", "info");
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const lines = entries.map((e) =>
|
|
126
|
+
`${severityIcon(e.severity)} [${formatTimestamp(e.ts)}] ${e.message}`,
|
|
127
|
+
);
|
|
128
|
+
const header = unread > 0 ? `${unread} unread — ` : "";
|
|
129
|
+
ctx.ui.notify(`${header}Recent notifications:\n${lines.join("\n")}`, "info");
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Unknown subcommand
|
|
134
|
+
ctx.ui.notify(
|
|
135
|
+
"Usage: /gsd notifications [clear|tail [N]|filter <severity>]",
|
|
136
|
+
"warning",
|
|
137
|
+
);
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
@@ -178,6 +178,11 @@ Examples:
|
|
|
178
178
|
await dispatchDirectPhase(ctx, pi, phase, projectRoot());
|
|
179
179
|
return true;
|
|
180
180
|
}
|
|
181
|
+
if (trimmed === "notifications" || trimmed.startsWith("notifications ")) {
|
|
182
|
+
const { handleNotificationsCommand } = await import("./notifications-handler.js");
|
|
183
|
+
await handleNotificationsCommand(trimmed.replace(/^notifications\s*/, "").trim(), ctx, pi);
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
181
186
|
if (trimmed === "inspect") {
|
|
182
187
|
await handleInspect(ctx);
|
|
183
188
|
return true;
|
|
@@ -0,0 +1,267 @@
|
|
|
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
|
+
function formatTimestamp(ts: string): string {
|
|
32
|
+
try {
|
|
33
|
+
const d = new Date(ts);
|
|
34
|
+
const now = Date.now();
|
|
35
|
+
const diffMs = now - d.getTime();
|
|
36
|
+
if (diffMs < 60_000) return "just now";
|
|
37
|
+
if (diffMs < 3600_000) return `${Math.floor(diffMs / 60_000)}m ago`;
|
|
38
|
+
if (diffMs < 86400_000) return `${Math.floor(diffMs / 3600_000)}h ago`;
|
|
39
|
+
return `${Math.floor(diffMs / 86400_000)}d ago`;
|
|
40
|
+
} catch {
|
|
41
|
+
return ts.slice(11, 19); // fallback: HH:MM:SS
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class GSDNotificationOverlay {
|
|
46
|
+
private tui: { requestRender: () => void };
|
|
47
|
+
private theme: Theme;
|
|
48
|
+
private onClose: () => void;
|
|
49
|
+
private cachedWidth?: number;
|
|
50
|
+
private cachedLines?: string[];
|
|
51
|
+
private scrollOffset = 0;
|
|
52
|
+
private filterIndex = 0;
|
|
53
|
+
private entries: NotificationEntry[] = [];
|
|
54
|
+
private refreshTimer: ReturnType<typeof setInterval>;
|
|
55
|
+
private disposed = false;
|
|
56
|
+
private resizeHandler: (() => void) | null = null;
|
|
57
|
+
|
|
58
|
+
constructor(
|
|
59
|
+
tui: { requestRender: () => void },
|
|
60
|
+
theme: Theme,
|
|
61
|
+
onClose: () => void,
|
|
62
|
+
) {
|
|
63
|
+
this.tui = tui;
|
|
64
|
+
this.theme = theme;
|
|
65
|
+
this.onClose = onClose;
|
|
66
|
+
|
|
67
|
+
// Mark all as read on open
|
|
68
|
+
markAllRead();
|
|
69
|
+
this.entries = readNotifications();
|
|
70
|
+
|
|
71
|
+
// Resize handler
|
|
72
|
+
this.resizeHandler = () => {
|
|
73
|
+
if (this.disposed) return;
|
|
74
|
+
this.invalidate();
|
|
75
|
+
this.tui.requestRender();
|
|
76
|
+
};
|
|
77
|
+
process.stdout.on("resize", this.resizeHandler);
|
|
78
|
+
|
|
79
|
+
// Refresh every 3s for new notifications
|
|
80
|
+
this.refreshTimer = setInterval(() => {
|
|
81
|
+
if (this.disposed) return;
|
|
82
|
+
const fresh = readNotifications();
|
|
83
|
+
if (fresh.length !== this.entries.length) {
|
|
84
|
+
this.entries = fresh;
|
|
85
|
+
markAllRead();
|
|
86
|
+
this.invalidate();
|
|
87
|
+
this.tui.requestRender();
|
|
88
|
+
}
|
|
89
|
+
}, 3000);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private get filter(): FilterMode {
|
|
93
|
+
return FILTER_CYCLE[this.filterIndex]!;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private get filteredEntries(): NotificationEntry[] {
|
|
97
|
+
if (this.filter === "all") return this.entries;
|
|
98
|
+
return this.entries.filter((e) => e.severity === this.filter);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
handleInput(data: string): void {
|
|
102
|
+
if (matchesKey(data, Key.escape) || matchesKey(data, Key.ctrl("c")) || matchesKey(data, Key.ctrlAlt("n"))) {
|
|
103
|
+
this.dispose();
|
|
104
|
+
this.onClose();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Scroll
|
|
109
|
+
if (matchesKey(data, Key.down) || matchesKey(data, "j")) {
|
|
110
|
+
this.scrollOffset++;
|
|
111
|
+
this.invalidate();
|
|
112
|
+
this.tui.requestRender();
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (matchesKey(data, Key.up) || matchesKey(data, "k")) {
|
|
116
|
+
this.scrollOffset = Math.max(0, this.scrollOffset - 1);
|
|
117
|
+
this.invalidate();
|
|
118
|
+
this.tui.requestRender();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (data === "g") {
|
|
122
|
+
this.scrollOffset = 0;
|
|
123
|
+
this.invalidate();
|
|
124
|
+
this.tui.requestRender();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (data === "G") {
|
|
128
|
+
this.scrollOffset = 999;
|
|
129
|
+
this.invalidate();
|
|
130
|
+
this.tui.requestRender();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Filter cycle
|
|
135
|
+
if (data === "f") {
|
|
136
|
+
this.filterIndex = (this.filterIndex + 1) % FILTER_CYCLE.length;
|
|
137
|
+
this.scrollOffset = 0;
|
|
138
|
+
this.invalidate();
|
|
139
|
+
this.tui.requestRender();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Clear all
|
|
144
|
+
if (data === "c") {
|
|
145
|
+
clearNotifications();
|
|
146
|
+
this.entries = [];
|
|
147
|
+
this.scrollOffset = 0;
|
|
148
|
+
this.invalidate();
|
|
149
|
+
this.tui.requestRender();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
render(width: number): string[] {
|
|
155
|
+
if (this.cachedLines && this.cachedWidth === width) {
|
|
156
|
+
return this.cachedLines;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const content = this.buildContentLines(width);
|
|
160
|
+
const viewportHeight = Math.max(5, process.stdout.rows ? process.stdout.rows - 8 : 24);
|
|
161
|
+
const chromeHeight = 2; // top + bottom border
|
|
162
|
+
const visibleContentRows = Math.max(1, viewportHeight - chromeHeight);
|
|
163
|
+
const maxScroll = Math.max(0, content.length - visibleContentRows);
|
|
164
|
+
this.scrollOffset = Math.min(this.scrollOffset, maxScroll);
|
|
165
|
+
const visibleContent = content.slice(this.scrollOffset, this.scrollOffset + visibleContentRows);
|
|
166
|
+
|
|
167
|
+
const lines = this.wrapInBox(visibleContent, width);
|
|
168
|
+
|
|
169
|
+
this.cachedWidth = width;
|
|
170
|
+
this.cachedLines = lines;
|
|
171
|
+
return lines;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
invalidate(): void {
|
|
175
|
+
this.cachedLines = undefined;
|
|
176
|
+
this.cachedWidth = undefined;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
dispose(): void {
|
|
180
|
+
this.disposed = true;
|
|
181
|
+
clearInterval(this.refreshTimer);
|
|
182
|
+
if (this.resizeHandler) {
|
|
183
|
+
process.stdout.removeListener("resize", this.resizeHandler);
|
|
184
|
+
this.resizeHandler = null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private wrapInBox(inner: string[], width: number): string[] {
|
|
189
|
+
const th = this.theme;
|
|
190
|
+
const border = (s: string) => th.fg("borderAccent", s);
|
|
191
|
+
const innerWidth = width - 4;
|
|
192
|
+
const lines: string[] = [];
|
|
193
|
+
|
|
194
|
+
lines.push(border("╭" + "─".repeat(width - 2) + "╮"));
|
|
195
|
+
for (const line of inner) {
|
|
196
|
+
const truncated = truncateToWidth(line, innerWidth);
|
|
197
|
+
const padWidth = Math.max(0, innerWidth - visibleWidth(truncated));
|
|
198
|
+
lines.push(border("│") + " " + truncated + " ".repeat(padWidth) + " " + border("│"));
|
|
199
|
+
}
|
|
200
|
+
lines.push(border("╰" + "─".repeat(width - 2) + "╯"));
|
|
201
|
+
return lines;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private buildContentLines(width: number): string[] {
|
|
205
|
+
const th = this.theme;
|
|
206
|
+
const shellWidth = width - 4;
|
|
207
|
+
const contentWidth = Math.min(shellWidth, 128);
|
|
208
|
+
const sidePad = Math.max(0, Math.floor((shellWidth - contentWidth) / 2));
|
|
209
|
+
const leftMargin = " ".repeat(sidePad);
|
|
210
|
+
const lines: string[] = [];
|
|
211
|
+
|
|
212
|
+
const row = (content = ""): string => {
|
|
213
|
+
const truncated = truncateToWidth(content, contentWidth);
|
|
214
|
+
return leftMargin + padRight(truncated, contentWidth);
|
|
215
|
+
};
|
|
216
|
+
const blank = () => row("");
|
|
217
|
+
const hr = () => row(th.fg("dim", "─".repeat(contentWidth)));
|
|
218
|
+
|
|
219
|
+
// Header
|
|
220
|
+
const title = th.fg("accent", th.bold("Notifications"));
|
|
221
|
+
const filterLabel = this.filter === "all"
|
|
222
|
+
? th.fg("dim", "all")
|
|
223
|
+
: th.fg(this.filter === "error" ? "error" : this.filter === "warning" ? "warning" : "dim", this.filter);
|
|
224
|
+
const count = `${this.filteredEntries.length} entries`;
|
|
225
|
+
lines.push(row(joinColumns(
|
|
226
|
+
`${title} ${th.fg("dim", "filter:")} ${filterLabel}`,
|
|
227
|
+
th.fg("dim", count),
|
|
228
|
+
contentWidth,
|
|
229
|
+
)));
|
|
230
|
+
lines.push(hr());
|
|
231
|
+
|
|
232
|
+
// Controls
|
|
233
|
+
lines.push(row(th.fg("dim", "↑/↓ scroll f filter c clear Esc close")));
|
|
234
|
+
lines.push(blank());
|
|
235
|
+
|
|
236
|
+
// Entries
|
|
237
|
+
const filtered = this.filteredEntries;
|
|
238
|
+
if (filtered.length === 0) {
|
|
239
|
+
lines.push(blank());
|
|
240
|
+
lines.push(row(th.fg("dim", this.entries.length === 0
|
|
241
|
+
? "No notifications yet."
|
|
242
|
+
: `No ${this.filter} notifications.`)));
|
|
243
|
+
lines.push(blank());
|
|
244
|
+
return lines;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
for (const entry of filtered) {
|
|
248
|
+
const icon = severityIcon(entry.severity);
|
|
249
|
+
const coloredIcon = entry.severity === "error" ? th.fg("error", icon)
|
|
250
|
+
: entry.severity === "warning" ? th.fg("warning", icon)
|
|
251
|
+
: entry.severity === "success" ? th.fg("success", icon)
|
|
252
|
+
: th.fg("dim", icon);
|
|
253
|
+
const time = th.fg("dim", formatTimestamp(entry.ts));
|
|
254
|
+
const source = entry.source === "workflow-logger" ? th.fg("dim", " [engine]") : "";
|
|
255
|
+
|
|
256
|
+
// First line: icon + timestamp + source
|
|
257
|
+
const msgMaxWidth = contentWidth - 20;
|
|
258
|
+
const msg = entry.message.length > msgMaxWidth
|
|
259
|
+
? entry.message.slice(0, msgMaxWidth - 1) + "…"
|
|
260
|
+
: entry.message;
|
|
261
|
+
|
|
262
|
+
lines.push(row(`${coloredIcon} ${time}${source} ${msg}`));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return lines;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
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
|
+
try {
|
|
279
|
+
// Write our PID timestamp into the lock for stale detection
|
|
280
|
+
if (fd !== null) {
|
|
281
|
+
writeFileSync(lockPath, String(Date.now()), "utf-8");
|
|
282
|
+
closeSync(fd);
|
|
283
|
+
}
|
|
284
|
+
return fn();
|
|
285
|
+
} finally {
|
|
286
|
+
try { unlinkSync(lockPath); } catch { /* best-effort cleanup */ }
|
|
287
|
+
}
|
|
288
|
+
}
|