@cortex-agent/server 2026.6.24 → 2026.7.30
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/README.md +25 -13
- package/defaults/.claude/settings.json +4 -0
- package/defaults/config/CORTEX.md +9 -0
- package/defaults/config/hooks/01-sensitive-file-edit.json +11 -0
- package/defaults/config/hooks/02-tasks-yaml-guard.json +11 -0
- package/defaults/config/hooks/03-ask-user-question-hook.json +19 -0
- package/defaults/config/hooks/04-exit-plan-mode-hook.json +19 -0
- package/defaults/config/hooks/05-memory-ref-tracker.json +10 -0
- package/defaults/config/hooks/06-rules-loader.json +10 -0
- package/defaults/config/hooks/07-session-activity-tracker.json +10 -0
- package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +10 -0
- package/defaults/config/hooks/09-permission-request-auto-allow.json +11 -0
- package/defaults/config/hooks/10-cortex-md-injector-session-start.json +10 -0
- package/defaults/config/hooks/11-task-status-check.json +14 -0
- package/defaults/config/hooks/12-session-new-hook.json +11 -0
- package/defaults/config/hooks/CORTEX.md +18 -0
- package/defaults/config/thread-templates/agents/coder-reviewer.json +25 -0
- package/defaults/config/thread-templates/agents/coder.json +30 -0
- package/defaults/config/thread-templates/agents/direct-review.json +17 -0
- package/defaults/config/thread-templates/agents/direct-web.json +16 -0
- package/defaults/config/thread-templates/agents/direct.json +16 -0
- package/defaults/config/thread-templates/agents/director.json +14 -0
- package/defaults/config/thread-templates/agents/doc-reviewer.json +14 -0
- package/defaults/config/thread-templates/agents/doc-writer.json +25 -0
- package/defaults/config/thread-templates/agents/executor-reviewer.json +14 -0
- package/defaults/config/thread-templates/agents/executor.json +25 -0
- package/defaults/config/thread-templates/agents/main.json +16 -0
- package/defaults/config/thread-templates/agents/manager.json +17 -0
- package/defaults/config/thread-templates/agents/scheduler-main.json +16 -0
- package/defaults/config/thread-templates/shells/worker-review.json +19 -0
- package/defaults/config/thread-templates/templates/coder-review.json +53 -0
- package/defaults/config/thread-templates/templates/default.json +10 -0
- package/defaults/config/thread-templates/templates/doc-review.json +6 -0
- package/defaults/config/thread-templates/templates/execute-review.json +6 -0
- package/defaults/config/thread-templates/templates/manager.json +11 -0
- package/defaults/config/thread-templates/templates/scheduler.json +19 -0
- package/defaults/context/decisions/DR-0012.md +1 -1
- package/defaults/gitignore +3 -0
- package/defaults/hooks/CORTEX.md +18 -0
- package/defaults/hooks/cortex-hook-api.mjs +84 -0
- package/defaults/hooks/cortex-md-injector.mjs +99 -49
- package/defaults/hooks/session-activity-tracker.mjs +8 -101
- package/defaults/hooks/task-status-check.mjs +10 -11
- package/defaults/mcp-config-web.json +11 -0
- package/defaults/pi/agents/explore.md +9 -0
- package/defaults/pi/agents/general-purpose.md +6 -0
- package/defaults/pi/agents/plan.md +9 -0
- package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +1 -1
- package/defaults/plugins/cortex-coder/skills/cli-standards/SKILL.md +2 -2
- package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +33 -0
- package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-common/skills/debug-campaign/SKILL.md +16 -16
- package/defaults/plugins/cortex-common/skills/execute-method/SKILL.md +53 -0
- package/defaults/plugins/cortex-common/skills/execute-review-rubric/SKILL.md +102 -0
- package/defaults/plugins/cortex-common/skills/manager-method/SKILL.md +67 -0
- package/defaults/plugins/cortex-common/skills/solution-design/SKILL.md +3 -3
- package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +2 -2
- package/defaults/plugins/cortex-stage-gate/skills/director-method/SKILL.md +54 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +132 -112
- package/defaults/plugins/cortex-system/.claude-plugin/plugin.json +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +17 -10
- package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/orient/SKILL.md +1 -1
- package/defaults/plugins/cortex-system/skills/orient-project/SKILL.md +2 -2
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +66 -17
- package/defaults/prompts/directives/coder.md +7 -31
- package/defaults/prompts/directives/director.md +4 -17
- package/defaults/prompts/directives/doc-reviewer.md +2 -35
- package/defaults/prompts/directives/doc-writer.md +2 -7
- package/defaults/prompts/directives/executor-reviewer.md +2 -39
- package/defaults/prompts/directives/executor.md +2 -7
- package/defaults/prompts/directives/manager.md +12 -27
- package/defaults/prompts/systemPrompts/coder.md +1 -1
- package/defaults/prompts/systemPrompts/direct.md +1 -1
- package/defaults/prompts/systemPrompts/web.md +5 -0
- package/defaults/prompts/systemPrompts/worker.md +1 -1
- package/dist/agent-adapter/bg-wait.d.ts +44 -0
- package/dist/agent-adapter/bg-wait.js +197 -0
- package/dist/agent-adapter/capabilities.d.ts +7 -1
- package/dist/agent-adapter/capabilities.js +18 -9
- package/dist/agent-adapter/claude/adapter-tui.d.ts +2 -0
- package/dist/agent-adapter/claude/adapter-tui.js +1 -0
- package/dist/agent-adapter/claude/adapter.d.ts +89 -5
- package/dist/agent-adapter/claude/adapter.js +404 -38
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +22 -15
- package/dist/agent-adapter/claude/bg-task-tracker.js +48 -32
- package/dist/agent-adapter/claude/compact-window.d.ts +9 -0
- package/dist/agent-adapter/claude/compact-window.js +46 -0
- package/dist/agent-adapter/claude/context-usage.d.ts +28 -0
- package/dist/agent-adapter/claude/context-usage.js +177 -0
- package/dist/agent-adapter/claude/defaults.d.ts +17 -3
- package/dist/agent-adapter/claude/defaults.js +25 -9
- package/dist/agent-adapter/claude/event-parser.d.ts +30 -0
- package/dist/agent-adapter/claude/event-parser.js +68 -4
- package/dist/agent-adapter/claude/hooks-builder.d.ts +23 -23
- package/dist/agent-adapter/claude/hooks-builder.js +63 -7
- package/dist/agent-adapter/claude/spawn-args.d.ts +25 -6
- package/dist/agent-adapter/claude/spawn-args.js +62 -22
- package/dist/agent-adapter/index.js +2 -4
- package/dist/agent-adapter/normalize/event-types.d.ts +8 -1
- package/dist/agent-adapter/normalize/event-types.js +1 -1
- package/dist/agent-adapter/normalize/tool-names.js +0 -9
- package/dist/agent-adapter/pi/adapter.d.ts +3 -33
- package/dist/agent-adapter/pi/adapter.js +461 -229
- package/dist/agent-adapter/pi/agent-dir.d.ts +6 -0
- package/dist/agent-adapter/pi/agent-dir.js +24 -14
- package/dist/agent-adapter/pi/defaults.d.ts +4 -0
- package/dist/agent-adapter/pi/defaults.js +11 -0
- package/dist/agent-adapter/pi/discovery.d.ts +4 -0
- package/dist/agent-adapter/pi/discovery.js +63 -0
- package/dist/agent-adapter/pi/event-parser.d.ts +13 -2
- package/dist/agent-adapter/pi/event-parser.js +139 -69
- package/dist/agent-adapter/pi/hook-bridge.d.ts +13 -28
- package/dist/agent-adapter/pi/hook-bridge.js +272 -167
- package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +24 -0
- package/dist/agent-adapter/pi/mcp-bridge-logic.js +39 -0
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +13 -35
- package/dist/agent-adapter/pi/mcp-bridge.js +147 -137
- package/dist/agent-adapter/pi/pi-ext-types.d.ts +30 -0
- package/dist/agent-adapter/pi/pi-ext-types.js +2 -2
- package/dist/agent-adapter/pi/session-support.d.ts +96 -0
- package/dist/agent-adapter/pi/session-support.js +213 -0
- package/dist/agent-adapter/pi/spawn-args.d.ts +15 -0
- package/dist/agent-adapter/pi/spawn-args.js +46 -3
- package/dist/agent-adapter/pi/subagent.d.ts +68 -0
- package/dist/agent-adapter/pi/subagent.js +521 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +1 -13
- package/dist/agent-adapter/pi/tool-shims.js +182 -198
- package/dist/agent-adapter/pi/web-fetch.d.ts +13 -0
- package/dist/agent-adapter/pi/web-fetch.js +201 -0
- package/dist/agent-adapter/pi/web-search.d.ts +9 -0
- package/dist/agent-adapter/pi/web-search.js +513 -0
- package/dist/agent-adapter/types.d.ts +61 -10
- package/dist/agent-adapter/types.js +4 -4
- package/dist/core/atomic-write.d.ts +3 -5
- package/dist/core/atomic-write.js +26 -12
- package/dist/core/bg-held-sessions.d.ts +35 -0
- package/dist/core/bg-held-sessions.js +79 -0
- package/dist/core/calver.d.ts +1 -0
- package/dist/core/calver.js +29 -0
- package/dist/core/config-generator.d.ts +13 -2
- package/dist/core/config-generator.js +55 -5
- package/dist/core/debug-mode.d.ts +14 -0
- package/dist/core/debug-mode.js +32 -0
- package/dist/core/gateway-generator.js +5 -10
- package/dist/core/hook-bus.d.ts +23 -0
- package/dist/core/hook-bus.js +111 -0
- package/dist/core/hook-exec.d.ts +15 -0
- package/dist/core/hook-exec.js +90 -0
- package/dist/core/icons.d.ts +2 -0
- package/dist/core/icons.js +2 -0
- package/dist/core/locales/en.d.ts +24 -7
- package/dist/core/locales/en.js +4 -1
- package/dist/core/locales/slices/commands.d.ts +12 -2
- package/dist/core/locales/slices/commands.js +31 -7
- package/dist/core/locales/slices/init.d.ts +1 -1
- package/dist/core/locales/slices/init.js +2 -2
- package/dist/core/locales/slices/status.d.ts +7 -3
- package/dist/core/locales/slices/status.js +16 -8
- package/dist/core/log.js +4 -3
- package/dist/core/paths.d.ts +9 -0
- package/dist/core/paths.js +20 -1
- package/dist/core/profile-generator.d.ts +2 -2
- package/dist/core/profile-generator.js +6 -9
- package/dist/core/running-executions.d.ts +10 -1
- package/dist/core/running-executions.js +10 -0
- package/dist/core/task-node.d.ts +7 -0
- package/dist/core/task-node.js +29 -0
- package/dist/core/types/agent-types.d.ts +23 -2
- package/dist/core/types/agent-types.js +2 -2
- package/dist/core/types/thread-types.d.ts +87 -15
- package/dist/core/types/thread-types.js +3 -3
- package/dist/core/utils.d.ts +2 -2
- package/dist/core/utils.js +3 -3
- package/dist/domain/agents/config.d.ts +6 -5
- package/dist/domain/agents/config.js +17 -5
- package/dist/domain/agents/facade.d.ts +61 -10
- package/dist/domain/agents/facade.js +309 -61
- package/dist/domain/agents/index.d.ts +1 -0
- package/dist/domain/agents/index.js +1 -0
- package/dist/domain/agents/profile-manager.d.ts +14 -7
- package/dist/domain/agents/profile-manager.js +23 -7
- package/dist/domain/agents/profile-switch.d.ts +53 -0
- package/dist/domain/agents/profile-switch.js +79 -0
- package/dist/domain/costs/cost-tracker.d.ts +21 -1
- package/dist/domain/costs/cost-tracker.js +54 -26
- package/dist/domain/costs/gateway-manager.js +5 -3
- package/dist/domain/costs/rate-limit-throttle.d.ts +44 -19
- package/dist/domain/costs/rate-limit-throttle.js +331 -103
- package/dist/domain/costs/resume-registry.d.ts +17 -9
- package/dist/domain/costs/resume-registry.js +63 -8
- package/dist/domain/executions/log-tailer.d.ts +71 -0
- package/dist/domain/executions/log-tailer.js +195 -0
- package/dist/domain/executions/registry.d.ts +10 -1
- package/dist/domain/executions/registry.js +14 -0
- package/dist/domain/hooks/hook-view.d.ts +22 -0
- package/dist/domain/hooks/hook-view.js +38 -0
- package/dist/domain/mcp/core-server.d.ts +0 -1
- package/dist/domain/mcp/core-server.js +8 -40
- package/dist/domain/mcp/feishu/file.js +1 -11
- package/dist/domain/mcp/feishu/index.d.ts +0 -2
- package/dist/domain/mcp/feishu/index.js +3 -8
- package/dist/domain/mcp/feishu-server.d.ts +0 -1
- package/dist/domain/mcp/feishu-server.js +4 -6
- package/dist/domain/mcp/manager-qa-server.d.ts +1 -0
- package/dist/domain/mcp/manager-qa-server.js +23 -0
- package/dist/domain/mcp/server.d.ts +0 -1
- package/dist/domain/mcp/server.js +5 -31
- package/dist/domain/mcp/slack-server.d.ts +0 -1
- package/dist/domain/mcp/slack-server.js +3 -5
- package/dist/domain/mcp/tasks-server.d.ts +1 -0
- package/dist/domain/mcp/tasks-server.js +23 -0
- package/dist/domain/mcp/thread-server.d.ts +1 -0
- package/dist/domain/mcp/thread-server.js +25 -0
- package/dist/domain/mcp/tools/context.d.ts +3 -10
- package/dist/domain/mcp/tools/context.js +13 -29
- package/dist/domain/mcp/tools/manager-qa.d.ts +2 -1
- package/dist/domain/mcp/tools/manager-qa.js +49 -53
- package/dist/domain/mcp/tools/schedule.d.ts +1 -2
- package/dist/domain/mcp/tools/schedule.js +7 -10
- package/dist/domain/mcp/tools/slack.d.ts +0 -1
- package/dist/domain/mcp/tools/slack.js +2 -13
- package/dist/domain/mcp/tools/task-ops.js +10 -137
- package/dist/domain/mcp/tools/thread-ops.js +6 -11
- package/dist/domain/mcp/tools/tui-ask.d.ts +2 -0
- package/dist/domain/mcp/tools/tui-ask.js +8 -0
- package/dist/domain/mcp/tools/ui-file.d.ts +2 -0
- package/dist/domain/mcp/tools/ui-file.js +49 -0
- package/dist/domain/mcp/tui-server.d.ts +0 -1
- package/dist/domain/mcp/tui-server.js +39 -24
- package/dist/domain/mcp/web-server.d.ts +1 -0
- package/dist/domain/mcp/web-server.js +25 -0
- package/dist/domain/memory/cortex-md-injector.d.ts +4 -10
- package/dist/domain/memory/cortex-md-injector.js +113 -77
- package/dist/domain/memory/cortex-md-scanner.d.ts +1 -0
- package/dist/domain/memory/cortex-md-scanner.js +5 -2
- package/dist/domain/memory/skill-scanner.d.ts +3 -1
- package/dist/domain/memory/skill-scanner.js +8 -12
- package/dist/domain/monitor/disk-monitor.js +2 -3
- package/dist/domain/projects/index.d.ts +1 -0
- package/dist/domain/projects/project-store.d.ts +18 -0
- package/dist/domain/projects/project-store.js +39 -3
- package/dist/domain/remote/client-hot-reload.js +4 -3
- package/dist/domain/remote/client-manager.d.ts +15 -1
- package/dist/domain/remote/client-manager.js +75 -11
- package/dist/domain/remote/cortex-client.js +6 -48
- package/dist/domain/scheduling/job-registry.d.ts +0 -2
- package/dist/domain/scheduling/job-registry.js +2 -6
- package/dist/domain/scheduling/jobs/_shared.d.ts +5 -1
- package/dist/domain/scheduling/jobs/_shared.js +2 -1
- package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.d.ts +1 -0
- package/dist/domain/scheduling/jobs/failed-dispatch-reconciliation.js +78 -0
- package/dist/domain/scheduling/jobs/scheduled-task.js +1 -3
- package/dist/domain/scheduling/jobs/task-dispatch.js +39 -31
- package/dist/domain/scheduling/scheduler.d.ts +0 -10
- package/dist/domain/scheduling/scheduler.js +9 -9
- package/dist/domain/sessions/session-hooks.d.ts +7 -14
- package/dist/domain/sessions/session-hooks.js +66 -112
- package/dist/domain/sessions/session-lifecycle.d.ts +38 -1
- package/dist/domain/sessions/session-lifecycle.js +41 -4
- package/dist/domain/sessions/session-registry.d.ts +3 -1
- package/dist/domain/system/doctor.js +4 -7
- package/dist/domain/system/server-update-check.d.ts +2 -1
- package/dist/domain/system/server-update-check.js +7 -26
- package/dist/domain/system/system-notice.d.ts +18 -0
- package/dist/domain/system/system-notice.js +34 -0
- package/dist/domain/tasks/acceptance-ledger.d.ts +31 -0
- package/dist/domain/tasks/acceptance-ledger.js +83 -0
- package/dist/domain/tasks/claim-recovery.d.ts +10 -0
- package/dist/domain/tasks/claim-recovery.js +64 -0
- package/dist/domain/tasks/dispatch-utils.d.ts +19 -0
- package/dist/domain/tasks/dispatcher.js +1 -3
- package/dist/domain/tasks/mutator.d.ts +7 -1
- package/dist/domain/tasks/mutator.js +55 -3
- package/dist/domain/tasks/recommendation/extractor.js +3 -3
- package/dist/domain/tasks/system/cortex-run.js +0 -0
- package/dist/domain/tasks/system/task-cli.d.ts +2 -0
- package/dist/domain/tasks/system/task-cli.js +30 -3
- package/dist/domain/tasks/system/task-completion.js +148 -42
- package/dist/domain/tasks/system/task-lifecycle-edit.js +3 -0
- package/dist/domain/threads/artifact-io.d.ts +3 -15
- package/dist/domain/threads/artifact-io.js +13 -119
- package/dist/domain/threads/hook-runner.d.ts +7 -2
- package/dist/domain/threads/hook-runner.js +68 -85
- package/dist/domain/threads/index.js +6 -1
- package/dist/domain/threads/prompt-builder.d.ts +7 -0
- package/dist/domain/threads/prompt-builder.js +30 -13
- package/dist/domain/threads/runner.d.ts +19 -5
- package/dist/domain/threads/runner.js +211 -78
- package/dist/domain/threads/shell-templates.d.ts +9 -0
- package/dist/domain/threads/shell-templates.js +117 -0
- package/dist/domain/threads/state-machine.d.ts +35 -7
- package/dist/domain/threads/state-machine.js +170 -29
- package/dist/domain/threads/template-loader.d.ts +15 -7
- package/dist/domain/threads/template-loader.js +204 -87
- package/dist/domain/threads/thread-transcript.d.ts +47 -0
- package/dist/domain/threads/thread-transcript.js +64 -0
- package/dist/domain/threads/utils.d.ts +8 -1
- package/dist/domain/threads/utils.js +17 -1
- package/dist/domain/tui-session/tui-session-service.js +9 -16
- package/dist/domain/tui-session/types.d.ts +12 -0
- package/dist/domain/ui-service/app-router.d.ts +670 -0
- package/dist/domain/ui-service/app-router.js +195 -0
- package/dist/domain/ui-service/index.d.ts +1 -1
- package/dist/domain/ui-service/input-schemas.d.ts +644 -0
- package/dist/domain/ui-service/input-schemas.js +385 -0
- package/dist/domain/ui-service/mutate/approvals.d.ts +31 -0
- package/dist/domain/ui-service/mutate/approvals.js +140 -0
- package/dist/domain/ui-service/mutate/config.d.ts +16 -0
- package/dist/domain/ui-service/mutate/config.js +72 -0
- package/dist/domain/ui-service/mutate/hooks.d.ts +16 -0
- package/dist/domain/ui-service/mutate/hooks.js +138 -0
- package/dist/domain/ui-service/mutate/issues.d.ts +18 -0
- package/dist/domain/ui-service/mutate/issues.js +111 -0
- package/dist/domain/ui-service/mutate/notes.d.ts +6 -0
- package/dist/domain/ui-service/mutate/notes.js +36 -0
- package/dist/domain/ui-service/mutate/projects.d.ts +4 -0
- package/dist/domain/ui-service/mutate/projects.js +10 -0
- package/dist/domain/ui-service/mutate/schedules.d.ts +2 -1
- package/dist/domain/ui-service/mutate/schedules.js +57 -3
- package/dist/domain/ui-service/mutate/sessions.d.ts +11 -0
- package/dist/domain/ui-service/mutate/sessions.js +198 -0
- package/dist/domain/ui-service/mutate/system.d.ts +2 -0
- package/dist/domain/ui-service/mutate/system.js +97 -0
- package/dist/domain/ui-service/query/approvals.d.ts +10 -0
- package/dist/domain/ui-service/query/approvals.js +109 -0
- package/dist/domain/ui-service/query/config.d.ts +8 -0
- package/dist/domain/ui-service/query/config.js +138 -0
- package/dist/domain/ui-service/query/executions.d.ts +2 -1
- package/dist/domain/ui-service/query/executions.js +47 -3
- package/dist/domain/ui-service/query/hooks.d.ts +7 -0
- package/dist/domain/ui-service/query/hooks.js +110 -0
- package/dist/domain/ui-service/query/issues.d.ts +14 -0
- package/dist/domain/ui-service/query/issues.js +85 -0
- package/dist/domain/ui-service/query/machines.d.ts +2 -0
- package/dist/domain/ui-service/query/machines.js +39 -0
- package/dist/domain/ui-service/query/memory.d.ts +5 -0
- package/dist/domain/ui-service/query/memory.js +199 -0
- package/dist/domain/ui-service/query/notes.d.ts +3 -0
- package/dist/domain/ui-service/query/notes.js +18 -0
- package/dist/domain/ui-service/query/schedules.js +1 -0
- package/dist/domain/ui-service/query/sessions.d.ts +3 -1
- package/dist/domain/ui-service/query/sessions.js +227 -15
- package/dist/domain/ui-service/query/skills.d.ts +2 -0
- package/dist/domain/ui-service/query/skills.js +14 -0
- package/dist/domain/ui-service/query/system.d.ts +3 -0
- package/dist/domain/ui-service/query/system.js +132 -0
- package/dist/domain/ui-service/query/task-verification.d.ts +2 -0
- package/dist/domain/ui-service/query/task-verification.js +60 -0
- package/dist/domain/ui-service/query/tasks.d.ts +1 -0
- package/dist/domain/ui-service/query/tasks.js +24 -16
- package/dist/domain/ui-service/query/thread-templates.d.ts +8 -0
- package/dist/domain/ui-service/query/thread-templates.js +54 -0
- package/dist/domain/ui-service/query/threads.d.ts +2 -1
- package/dist/domain/ui-service/query/threads.js +213 -4
- package/dist/domain/ui-service/subscribe.js +27 -1
- package/dist/domain/ui-service/trpc.d.ts +13 -0
- package/dist/domain/ui-service/trpc.js +12 -0
- package/dist/domain/ui-service/types.d.ts +1266 -4
- package/dist/domain/ui-service/types.js +4 -4
- package/dist/domain/ui-service/ui-service.d.ts +2 -1
- package/dist/domain/ui-service/ui-service.js +112 -10
- package/dist/entry/app.js +281 -34
- package/dist/entry/daemon-notice.d.ts +17 -0
- package/dist/entry/daemon-notice.js +26 -0
- package/dist/entry/daemon.d.ts +23 -1
- package/dist/entry/daemon.js +126 -41
- package/dist/entry/hook-cli.d.ts +18 -0
- package/dist/entry/hook-cli.js +468 -0
- package/dist/entry/init.js +22 -18
- package/dist/entry/start-ui-http.d.ts +44 -0
- package/dist/entry/start-ui-http.js +289 -0
- package/dist/entry/startup-notify.js +5 -9
- package/dist/entry/ui-http-gate.d.ts +11 -0
- package/dist/entry/ui-http-gate.js +29 -0
- package/dist/events/event-bus.d.ts +7 -2
- package/dist/events/event-bus.js +5 -2
- package/dist/events/event-logger.js +14 -0
- package/dist/events/event-types.d.ts +110 -0
- package/dist/events/event-types.js +3 -3
- package/dist/hooks/cortex-hook-api.mjs +84 -0
- package/dist/hooks/cortex-md-injector.mjs +99 -49
- package/dist/hooks/session-activity-tracker.mjs +8 -101
- package/dist/hooks/task-status-check.mjs +10 -11
- package/dist/orchestration/agent-file-send.d.ts +54 -0
- package/dist/orchestration/agent-file-send.js +110 -0
- package/dist/orchestration/agent-runner.d.ts +49 -0
- package/dist/orchestration/agent-runner.js +365 -53
- package/dist/orchestration/bg-continuation.d.ts +51 -9
- package/dist/orchestration/bg-continuation.js +53 -15
- package/dist/orchestration/bg-wait-guard.d.ts +28 -0
- package/dist/orchestration/bg-wait-guard.js +73 -0
- package/dist/orchestration/conduit-queue.d.ts +2 -0
- package/dist/orchestration/conduit-queue.js +14 -1
- package/dist/orchestration/conversation-runner.d.ts +37 -5
- package/dist/orchestration/conversation-runner.js +70 -15
- package/dist/orchestration/delta-coalescer.d.ts +69 -0
- package/dist/orchestration/delta-coalescer.js +128 -0
- package/dist/orchestration/interactions/ask-user-question.d.ts +11 -3
- package/dist/orchestration/interactions/ask-user-question.js +27 -3
- package/dist/orchestration/interactions/interaction-handlers.js +11 -36
- package/dist/orchestration/interactions/interaction-records.d.ts +59 -0
- package/dist/orchestration/interactions/interaction-records.js +156 -0
- package/dist/orchestration/interactions/plan-approvals.d.ts +5 -0
- package/dist/orchestration/interactions/plan-approvals.js +8 -0
- package/dist/orchestration/interactions/plan-response.d.ts +8 -0
- package/dist/orchestration/interactions/plan-response.js +37 -0
- package/dist/orchestration/lifecycle.d.ts +8 -3
- package/dist/orchestration/lifecycle.js +143 -62
- package/dist/orchestration/manager-qa.d.ts +12 -2
- package/dist/orchestration/manager-qa.js +34 -33
- package/dist/orchestration/mid-turn-inject.d.ts +105 -0
- package/dist/orchestration/mid-turn-inject.js +298 -0
- package/dist/orchestration/pending-injection-recovery.d.ts +35 -0
- package/dist/orchestration/pending-injection-recovery.js +92 -0
- package/dist/orchestration/resume-dispatcher.d.ts +21 -4
- package/dist/orchestration/resume-dispatcher.js +67 -37
- package/dist/orchestration/routing/commands/cancel.d.ts +26 -0
- package/dist/orchestration/routing/commands/cancel.js +64 -18
- package/dist/orchestration/routing/commands/compact.d.ts +10 -0
- package/dist/orchestration/routing/commands/compact.js +26 -0
- package/dist/orchestration/routing/commands/index.d.ts +2 -0
- package/dist/orchestration/routing/commands/index.js +9 -0
- package/dist/orchestration/routing/commands/mode.js +24 -11
- package/dist/orchestration/routing/commands/restart.d.ts +22 -0
- package/dist/orchestration/routing/commands/restart.js +49 -0
- package/dist/orchestration/routing/commands/session.js +4 -0
- package/dist/orchestration/routing/commands/status.js +5 -0
- package/dist/orchestration/routing/edit-handler.js +1 -1
- package/dist/orchestration/routing/hook-bridge-subscribers.d.ts +2 -1
- package/dist/orchestration/routing/hook-bridge-subscribers.js +45 -4
- package/dist/orchestration/routing/hook-bridge.d.ts +10 -3
- package/dist/orchestration/routing/hook-bridge.js +26 -14
- package/dist/orchestration/routing/webhook.js +110 -19
- package/dist/orchestration/session-compact.d.ts +58 -0
- package/dist/orchestration/session-compact.js +82 -0
- package/dist/orchestration/session-events.d.ts +111 -0
- package/dist/orchestration/session-events.js +113 -0
- package/dist/orchestration/session-rewind.d.ts +72 -0
- package/dist/orchestration/session-rewind.js +104 -0
- package/dist/orchestration/session-send.d.ts +19 -0
- package/dist/orchestration/session-send.js +39 -0
- package/dist/orchestration/status-helpers.d.ts +4 -0
- package/dist/orchestration/status-helpers.js +18 -0
- package/dist/orchestration/thread-callback.d.ts +75 -7
- package/dist/orchestration/thread-callback.js +300 -49
- package/dist/orchestration/thread-executor.d.ts +1 -0
- package/dist/orchestration/thread-executor.js +23 -31
- package/dist/orchestration/web-bg-hold.d.ts +52 -0
- package/dist/orchestration/web-bg-hold.js +105 -0
- package/dist/platform/adapter.d.ts +3 -0
- package/dist/platform/adapter.js +2 -2
- package/dist/platform/adapters/composite-adapter.d.ts +6 -1
- package/dist/platform/adapters/composite-adapter.js +64 -4
- package/dist/platform/adapters/feishu.d.ts +6 -1
- package/dist/platform/adapters/feishu.js +52 -12
- package/dist/platform/adapters/slack.d.ts +2 -1
- package/dist/platform/adapters/slack.js +41 -9
- package/dist/platform/adapters/tui/index.d.ts +1 -1
- package/dist/platform/adapters/tui/ports.d.ts +8 -7
- package/dist/platform/adapters/tui/tui-gateway.d.ts +7 -0
- package/dist/platform/adapters/tui/tui-gateway.js +48 -5
- package/dist/platform/adapters/tui/tui-transcript.js +17 -29
- package/dist/platform/index.d.ts +1 -1
- package/dist/platform/index.js +1 -1
- package/dist/platform/interactive-builder.d.ts +7 -0
- package/dist/platform/interactive-builder.js +22 -2
- package/dist/platform/testing.d.ts +5 -0
- package/dist/platform/testing.js +7 -2
- package/dist/platform/tui/protocol.d.ts +0 -2
- package/dist/platform/tui/protocol.js +4 -53
- package/dist/platform/types.d.ts +12 -0
- package/dist/platform/types.js +5 -0
- package/dist/platform/ui-http/access-jwt.d.ts +28 -0
- package/dist/platform/ui-http/access-jwt.js +67 -0
- package/dist/platform/ui-http/app-update.d.ts +58 -0
- package/dist/platform/ui-http/app-update.js +155 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +56 -0
- package/dist/platform/ui-http/ui-http-server.js +231 -0
- package/dist/platform/ui-http/ui-ota.d.ts +20 -0
- package/dist/platform/ui-http/ui-ota.js +128 -0
- package/dist/platform/ui-http/zip-writer.d.ts +13 -0
- package/dist/platform/ui-http/zip-writer.js +102 -0
- package/dist/platform/utils/reaction-diagnostics.d.ts +4 -0
- package/dist/platform/utils/reaction-diagnostics.js +23 -0
- package/dist/store/conversation-history-repo.d.ts +243 -0
- package/dist/store/conversation-history-repo.js +399 -0
- package/dist/store/execution-repo.d.ts +19 -1
- package/dist/store/execution-repo.js +18 -1
- package/dist/store/hook-registry.d.ts +83 -0
- package/dist/store/hook-registry.js +318 -0
- package/dist/store/hook-sync.d.ts +12 -16
- package/dist/store/hook-sync.js +169 -70
- package/dist/store/hook-writer.d.ts +49 -0
- package/dist/store/hook-writer.js +132 -0
- package/dist/store/outbound-queue.d.ts +8 -0
- package/dist/store/outbound-queue.js +24 -3
- package/dist/store/pending-injection-repo.d.ts +30 -0
- package/dist/store/pending-injection-repo.js +51 -0
- package/dist/store/profile-repo.d.ts +2 -1
- package/dist/store/profile-repo.js +6 -11
- package/dist/store/project-notes-repo.d.ts +27 -0
- package/dist/store/project-notes-repo.js +214 -0
- package/dist/store/provider-state-repo.d.ts +18 -0
- package/dist/store/provider-state-repo.js +107 -0
- package/dist/store/schedule-repo.d.ts +0 -21
- package/dist/store/schedule-repo.js +4 -25
- package/dist/store/session-registry-repo.d.ts +47 -1
- package/dist/store/session-registry-repo.js +71 -3
- package/dist/store/version-migrations.d.ts +2 -0
- package/dist/store/version-migrations.js +186 -9
- package/dist/tui/App.js +208 -20
- package/dist/tui/components/Dashboard.d.ts +3 -1
- package/dist/tui/components/Dashboard.js +5 -1
- package/dist/tui/components/DashboardCostTab.js +17 -2
- package/dist/tui/components/DashboardExecutionsTab.js +21 -1
- package/dist/tui/components/DashboardSchedulesTab.js +8 -3
- package/dist/tui/components/DashboardTasksTab.js +11 -6
- package/dist/tui/components/DashboardThreadsTab.js +20 -2
- package/dist/tui/components/InputBox.d.ts +17 -1
- package/dist/tui/components/InputBox.js +237 -21
- package/dist/tui/components/Notifications.js +7 -2
- package/dist/tui/components/ProjectSwitcher.js +7 -2
- package/dist/tui/components/SessionPicker.js +10 -1
- package/dist/tui/components/SidePanel.d.ts +3 -1
- package/dist/tui/components/SidePanel.js +4 -2
- package/dist/tui/components/SlashMenu.d.ts +8 -0
- package/dist/tui/components/SlashMenu.js +14 -0
- package/dist/tui/components/StatusLine.d.ts +12 -3
- package/dist/tui/components/StatusLine.js +29 -10
- package/dist/tui/components/Transcript.d.ts +9 -0
- package/dist/tui/components/Transcript.js +131 -26
- package/dist/tui/components/dashboard-constants.d.ts +1 -0
- package/dist/tui/components/dashboard-constants.js +7 -0
- package/dist/tui/hooks/useKeybindings.d.ts +1 -0
- package/dist/tui/hooks/useKeybindings.js +9 -14
- package/dist/tui/hooks/useMouseHandler.d.ts +17 -0
- package/dist/tui/hooks/useMouseHandler.js +103 -0
- package/dist/tui/hooks/useTranscript.d.ts +7 -2
- package/dist/tui/hooks/useTranscript.js +76 -57
- package/dist/tui/index.js +106 -10
- package/dist/tui/logic.d.ts +146 -2
- package/dist/tui/logic.js +411 -6
- package/dist/tui/raf-batch.d.ts +33 -0
- package/dist/tui/raf-batch.js +103 -0
- package/dist/tui/render/inline-markdown.d.ts +22 -0
- package/dist/tui/render/inline-markdown.js +99 -0
- package/dist/tui/render/rich-blocks.js +10 -8
- package/dist/tui/render-output.d.ts +46 -0
- package/dist/tui/render-output.js +86 -0
- package/dist/tui/slash-commands.d.ts +21 -0
- package/dist/tui/slash-commands.js +73 -0
- package/dist/tui/turn-status.d.ts +10 -0
- package/dist/tui/turn-status.js +53 -0
- package/package.json +17 -7
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/index-B19jLgji.js +138 -0
- package/web/dist/assets/index-BuFyPyRW.css +1 -0
- package/web/dist/assets/index-DCgngTJG.js +1 -0
- package/web/dist/assets/pdf-worker-DIEXcFxP.js +55 -0
- package/web/dist/assets/pdf.worker.min-DqNZU1-t.js +53 -0
- package/web/dist/favicon-32.png +0 -0
- package/web/dist/favicon.svg +7 -0
- package/web/dist/index.html +37 -0
- package/defaults/config/session-hooks.json +0 -7
- package/defaults/config/thread-templates.json +0 -600
- package/defaults/prompts/directives/milestone-executor.md +0 -119
- package/defaults/prompts/directives/milestone-reviewer.md +0 -108
- package/defaults/prompts/directives/plan-executor.md +0 -121
- package/defaults/prompts/directives/plan-reviewer.md +0 -99
- package/dist/agent-adapter/codex/adapter.d.ts +0 -42
- package/dist/agent-adapter/codex/adapter.js +0 -916
- package/dist/agent-adapter/codex/event-parser.d.ts +0 -17
- package/dist/agent-adapter/codex/event-parser.js +0 -41
- package/dist/agent-adapter/codex/spawn-args.d.ts +0 -6
- package/dist/agent-adapter/codex/spawn-args.js +0 -30
- package/dist/domain/costs/codex-event-format.d.ts +0 -4
- package/dist/domain/costs/codex-event-format.js +0 -66
- package/dist/domain/costs/codex-usage-monitor.d.ts +0 -6
- package/dist/domain/costs/codex-usage-monitor.js +0 -73
- package/dist/domain/costs/rate-limit-parser.d.ts +0 -11
- package/dist/domain/costs/rate-limit-parser.js +0 -87
- package/dist/domain/mcp/feishu/block-types.d.ts +0 -44
- package/dist/domain/mcp/feishu/block-types.js +0 -127
- package/dist/tui/components/Header.d.ts +0 -11
- package/dist/tui/components/Header.js +0 -5
- package/dist/tui/components/MessageRow.d.ts +0 -7
- package/dist/tui/components/MessageRow.js +0 -10
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output:
|
|
3
|
-
// pos:
|
|
4
|
-
//
|
|
5
|
-
// runs pending migrations in version order. Supports JSON (parse/serialize) and text
|
|
6
|
-
// (raw string, e.g. markdown system prompts) migrations. Idempotent and crash-safe
|
|
7
|
-
// via atomicWrite.
|
|
8
|
-
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
1
|
+
// input: versions, user config, provider state, defaults
|
|
2
|
+
// output: Versioned and collision-safe startup migrations
|
|
3
|
+
// pos: Migrates user-owned files during server startup
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
9
5
|
import * as path from 'node:path';
|
|
10
6
|
import * as fs from 'node:fs/promises';
|
|
11
7
|
import * as os from 'node:os';
|
|
@@ -13,6 +9,8 @@ import { CORTEX_VERSION, CORTEX_DOCS_URL } from '../core/version.js';
|
|
|
13
9
|
import { DATA_DIR, DEFAULTS_DIR } from '../core/paths.js';
|
|
14
10
|
import { atomicWrite } from '../core/atomic-write.js';
|
|
15
11
|
import { createLogger } from '../core/log.js';
|
|
12
|
+
import { validateHookEntry } from './hook-registry.js';
|
|
13
|
+
import { migrateProviderStateFromSchedules } from './provider-state-repo.js';
|
|
16
14
|
const log = createLogger('version-migrations');
|
|
17
15
|
// ── CalVer comparison ──────────────────────────────────────────
|
|
18
16
|
// CalVer format: YYYY.M.D (no zero-padding, e.g. 2026.5.23).
|
|
@@ -133,6 +131,9 @@ const CODER_REVIEWER_DIRECTIVE_REPLACEMENTS = [
|
|
|
133
131
|
'- **Test run omission**: signing off on an implementation without running the project\'s test suite yourself when one exists. Coder\'s claim that tests pass is not evidence. Run the suite and check every stage. A lint/architecture error or a test regression that Coder missed is as much your failure as theirs.',
|
|
134
132
|
],
|
|
135
133
|
];
|
|
134
|
+
const PI_SUBAGENT_ROLE_REPLACEMENTS = [
|
|
135
|
+
['subagent_type=Explore', 'subagent_type=explore'],
|
|
136
|
+
];
|
|
136
137
|
// ── Registry ───────────────────────────────────────────────────
|
|
137
138
|
// Add new migrations here. The runner groups them by filePath and applies
|
|
138
139
|
// pending ones in version-ascending order.
|
|
@@ -320,6 +321,21 @@ const migrations = [
|
|
|
320
321
|
return applyReplacements(data, CODER_REVIEWER_DIRECTIVE_REPLACEMENTS);
|
|
321
322
|
},
|
|
322
323
|
},
|
|
324
|
+
// M6: Match existing prompt copies to PI's lowercase default role name.
|
|
325
|
+
...[
|
|
326
|
+
'prompts/systemPrompts/direct.md',
|
|
327
|
+
'prompts/systemPrompts/worker.md',
|
|
328
|
+
'prompts/systemPrompts/coder.md',
|
|
329
|
+
].map((filePath) => ({
|
|
330
|
+
filePath,
|
|
331
|
+
version: '2026.6.24',
|
|
332
|
+
format: 'text',
|
|
333
|
+
migrate(data) {
|
|
334
|
+
if (typeof data !== 'string')
|
|
335
|
+
return data;
|
|
336
|
+
return applyReplacements(data, PI_SUBAGENT_ROLE_REPLACEMENTS);
|
|
337
|
+
},
|
|
338
|
+
})),
|
|
323
339
|
];
|
|
324
340
|
// ── Versions file I/O ──────────────────────────────────────────
|
|
325
341
|
async function loadVersionsFrom(filePath) {
|
|
@@ -383,6 +399,10 @@ export async function runMigrations(opts = {}) {
|
|
|
383
399
|
const dataDir = opts.dataDir ?? DATA_DIR;
|
|
384
400
|
const defaultsDir = opts.defaultsDir ?? DEFAULTS_DIR;
|
|
385
401
|
const storeDir = opts.storeDir ?? path.join(dataDir, 'data');
|
|
402
|
+
await migrateProviderStateFromSchedules(dataDir).catch((error) => {
|
|
403
|
+
log.warn(`Could not migrate legacy provider state: ${error.message}`);
|
|
404
|
+
});
|
|
405
|
+
await migrateSessionHooksToRegistry(dataDir);
|
|
386
406
|
const versionsFile = path.join(storeDir, 'versions.json');
|
|
387
407
|
const versions = await loadVersionsFrom(versionsFile);
|
|
388
408
|
// Group migrations by filePath
|
|
@@ -457,7 +477,164 @@ export async function runMigrations(opts = {}) {
|
|
|
457
477
|
}
|
|
458
478
|
await saveVersionsTo(versionsFile, versions);
|
|
459
479
|
}
|
|
460
|
-
|
|
480
|
+
const SESSION_HOOK_DESTINATIONS = {
|
|
481
|
+
onNew: {
|
|
482
|
+
file: '12-session-new-hook.json',
|
|
483
|
+
id: 'session-new-hook',
|
|
484
|
+
event: 'cortex:session.new',
|
|
485
|
+
},
|
|
486
|
+
onMessageEnd: {
|
|
487
|
+
file: '13-session-message-end-hook.json',
|
|
488
|
+
id: 'session-message-end-hook',
|
|
489
|
+
event: 'cortex:session.messageEnd',
|
|
490
|
+
},
|
|
491
|
+
};
|
|
492
|
+
function parseLegacyArgs(value) {
|
|
493
|
+
if (value === undefined)
|
|
494
|
+
return [];
|
|
495
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === 'string')) {
|
|
496
|
+
throw new Error('legacy session hook args must be strings');
|
|
497
|
+
}
|
|
498
|
+
return value;
|
|
499
|
+
}
|
|
500
|
+
function parseLegacyTimeout(value) {
|
|
501
|
+
if (value === undefined)
|
|
502
|
+
return 60_000;
|
|
503
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) {
|
|
504
|
+
throw new Error('legacy session hook timeout must be positive');
|
|
505
|
+
}
|
|
506
|
+
return value;
|
|
507
|
+
}
|
|
508
|
+
function parseLegacyHook(value) {
|
|
509
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
510
|
+
throw new Error('legacy session hook must be an object');
|
|
511
|
+
}
|
|
512
|
+
const raw = value;
|
|
513
|
+
const command = typeof raw.command === 'string' && raw.command.trim() ? raw.command : undefined;
|
|
514
|
+
const script = typeof raw.script === 'string' && raw.script.trim() ? raw.script : undefined;
|
|
515
|
+
if ((command === undefined) === (script === undefined)) {
|
|
516
|
+
throw new Error('legacy session hook needs exactly one command or script');
|
|
517
|
+
}
|
|
518
|
+
return {
|
|
519
|
+
command,
|
|
520
|
+
script,
|
|
521
|
+
args: parseLegacyArgs(raw.args),
|
|
522
|
+
timeout: parseLegacyTimeout(raw.timeout),
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
function shellQuote(value) {
|
|
526
|
+
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
527
|
+
}
|
|
528
|
+
function normalizedScript(script) {
|
|
529
|
+
return script.trim().replace(/^(?:\.\/)?hooks[\\/]/, '');
|
|
530
|
+
}
|
|
531
|
+
function scriptFromCommand(command, args) {
|
|
532
|
+
if (args.length > 0)
|
|
533
|
+
return null;
|
|
534
|
+
const match = command.trim().match(/^node\s+(?:\.\/)?hooks[\\/]([^\s'"]+)$/);
|
|
535
|
+
return match?.[1] ?? null;
|
|
536
|
+
}
|
|
537
|
+
function commandWithArgs(command, args) {
|
|
538
|
+
if (args.length === 0)
|
|
539
|
+
return command;
|
|
540
|
+
return `${command} ${args.map(shellQuote).join(' ')}`;
|
|
541
|
+
}
|
|
542
|
+
function normalizeLegacyRun(config) {
|
|
543
|
+
const timeout = config.timeout / 1_000;
|
|
544
|
+
if (config.script) {
|
|
545
|
+
const script = normalizedScript(config.script);
|
|
546
|
+
if (config.args.length === 0)
|
|
547
|
+
return { script, timeout };
|
|
548
|
+
const command = commandWithArgs(`node ${shellQuote(`hooks/${script}`)}`, config.args);
|
|
549
|
+
return { command, timeout };
|
|
550
|
+
}
|
|
551
|
+
const command = config.command;
|
|
552
|
+
const script = scriptFromCommand(command, config.args);
|
|
553
|
+
return script ? { script, timeout } : { command: commandWithArgs(command, config.args), timeout };
|
|
554
|
+
}
|
|
555
|
+
function migratedSessionHook(name, value) {
|
|
556
|
+
const target = SESSION_HOOK_DESTINATIONS[name];
|
|
557
|
+
return validateHookEntry({
|
|
558
|
+
id: target.id,
|
|
559
|
+
event: target.event,
|
|
560
|
+
run: normalizeLegacyRun(parseLegacyHook(value)),
|
|
561
|
+
result: 'stdout-as-prompt',
|
|
562
|
+
enabled: true,
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
function disabledOnNewHook() {
|
|
566
|
+
return validateHookEntry({
|
|
567
|
+
id: 'session-new-hook',
|
|
568
|
+
event: 'cortex:session.new',
|
|
569
|
+
run: { script: 'new-session-hook.mjs', timeout: 60 },
|
|
570
|
+
result: 'stdout-as-prompt',
|
|
571
|
+
enabled: false,
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function sessionHookMigrationEntries(config) {
|
|
575
|
+
const entries = [];
|
|
576
|
+
const onNew = Object.hasOwn(config, 'onNew')
|
|
577
|
+
? migratedSessionHook('onNew', config.onNew)
|
|
578
|
+
: disabledOnNewHook();
|
|
579
|
+
entries.push([SESSION_HOOK_DESTINATIONS.onNew.file, onNew]);
|
|
580
|
+
if (Object.hasOwn(config, 'onMessageEnd')) {
|
|
581
|
+
entries.push([
|
|
582
|
+
SESSION_HOOK_DESTINATIONS.onMessageEnd.file,
|
|
583
|
+
migratedSessionHook('onMessageEnd', config.onMessageEnd),
|
|
584
|
+
]);
|
|
585
|
+
}
|
|
586
|
+
return entries;
|
|
587
|
+
}
|
|
588
|
+
async function hasCompatibleSessionHookEntry(filePath, expectedEvent) {
|
|
589
|
+
try {
|
|
590
|
+
const raw = await fs.readFile(filePath, 'utf8');
|
|
591
|
+
const existing = validateHookEntry(JSON.parse(raw));
|
|
592
|
+
if (existing.event !== expectedEvent) {
|
|
593
|
+
throw new Error(`registry destination belongs to ${existing.event}`);
|
|
594
|
+
}
|
|
595
|
+
return true;
|
|
596
|
+
}
|
|
597
|
+
catch (error) {
|
|
598
|
+
if (error.code === 'ENOENT')
|
|
599
|
+
return false;
|
|
600
|
+
throw error;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
async function writeSessionHookEntry(filePath, entry) {
|
|
604
|
+
if (await hasCompatibleSessionHookEntry(filePath, entry.event))
|
|
605
|
+
return;
|
|
606
|
+
await atomicWrite(filePath, `${JSON.stringify(entry, null, 2)}\n`);
|
|
607
|
+
}
|
|
608
|
+
/** Move the retired singular session hook config into declarative registry files. */
|
|
609
|
+
export async function migrateSessionHooksToRegistry(dataDir) {
|
|
610
|
+
const source = path.join(dataDir, 'config', 'session-hooks.json');
|
|
611
|
+
let raw;
|
|
612
|
+
try {
|
|
613
|
+
raw = await fs.readFile(source, 'utf8');
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
if (error.code === 'ENOENT')
|
|
617
|
+
return;
|
|
618
|
+
log.warn(`Could not read legacy session hooks: ${error.message}`);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
try {
|
|
622
|
+
const parsed = JSON.parse(raw);
|
|
623
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
624
|
+
throw new Error('legacy session hook config must be an object');
|
|
625
|
+
}
|
|
626
|
+
const registryDir = path.join(dataDir, 'config', 'hooks');
|
|
627
|
+
await fs.mkdir(registryDir, { recursive: true });
|
|
628
|
+
for (const [file, entry] of sessionHookMigrationEntries(parsed)) {
|
|
629
|
+
await writeSessionHookEntry(path.join(registryDir, file), entry);
|
|
630
|
+
}
|
|
631
|
+
await fs.unlink(source);
|
|
632
|
+
log.info('Migrated legacy session hooks into the hook registry');
|
|
633
|
+
}
|
|
634
|
+
catch (error) {
|
|
635
|
+
log.warn(`Could not migrate legacy session hooks: ${error.message}`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
461
638
|
/**
|
|
462
639
|
* Migrate config.yaml from CORTEX_HOME/config/ (wrong location before 2026.6.11)
|
|
463
640
|
* to ~/.aistatus/config.yaml (correct location read by aistatus).
|
package/dist/tui/App.js
CHANGED
|
@@ -3,24 +3,31 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
// output: Top-level layout + global key handler for M5 Ink client
|
|
4
4
|
// pos: Main App component wiring all pieces together
|
|
5
5
|
import { useCallback, useRef, useState, useEffect } from 'react';
|
|
6
|
-
import { Box } from 'ink';
|
|
7
|
-
import { Header } from './components/Header.js';
|
|
6
|
+
import { Box, useStdout } from 'ink';
|
|
8
7
|
import { Transcript } from './components/Transcript.js';
|
|
9
8
|
import { InputBox } from './components/InputBox.js';
|
|
10
9
|
import { StatusLine } from './components/StatusLine.js';
|
|
11
10
|
import { SidePanel } from './components/SidePanel.js';
|
|
12
|
-
import {
|
|
11
|
+
import { NotificationsModal } from './components/Notifications.js';
|
|
13
12
|
import { ProjectSwitcher } from './components/ProjectSwitcher.js';
|
|
14
13
|
import { useMutate } from './hooks/useMutate.js';
|
|
15
14
|
import { useTranscript } from './hooks/useTranscript.js';
|
|
16
15
|
import { useKeybindings } from './hooks/useKeybindings.js';
|
|
16
|
+
import { useMouseHandler } from './hooks/useMouseHandler.js';
|
|
17
|
+
import { osc52Copy } from './logic.js';
|
|
17
18
|
import { useNotifications } from './hooks/useNotifications.js';
|
|
18
19
|
import { useDashboardData } from './hooks/useDashboardData.js';
|
|
19
20
|
import { SessionPicker } from './components/SessionPicker.js';
|
|
21
|
+
import { SLASH_COMMANDS } from './slash-commands.js';
|
|
20
22
|
import { AskUserModal } from './components/AskUserModal.js';
|
|
21
23
|
import { PlanFeedbackModal } from './components/PlanFeedbackModal.js';
|
|
22
|
-
import { isNotification, isUiQueryResult, isUiEvent, isErrorFrame } from '../platform/tui/protocol.js';
|
|
23
|
-
import { computeFocusZone, isAgentResponseFrame } from './logic.js';
|
|
24
|
+
import { isNotification, isUiQueryResult, isUiEvent, isErrorFrame, isChatPost, isChatUpdate } from '../platform/tui/protocol.js';
|
|
25
|
+
import { computeFocusZone, isAgentResponseFrame, matchResumeTarget } from './logic.js';
|
|
26
|
+
import { parseTurnStatus, formatTurnStatus } from './turn-status.js';
|
|
27
|
+
/** A status message is the only TUI chat content that carries an `actions` rich-block. */
|
|
28
|
+
function hasActionsBlock(content) {
|
|
29
|
+
return !!content?.richBlocks?.some(b => b?.type === 'actions');
|
|
30
|
+
}
|
|
24
31
|
export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect, onSendCancel, serverVersion, projectId, sessionName, errorMessage, onSetDispatch, resumableSessions, resumePending, onResumeSelect, onResumeCancel, }) {
|
|
25
32
|
// ── Hooks ──
|
|
26
33
|
const [activeModal, setActiveModal] = useState(null);
|
|
@@ -50,16 +57,52 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
50
57
|
const [sidePanelVisible, setSidePanelVisible] = useState(false);
|
|
51
58
|
const [notificationsOpen, setNotificationsOpen] = useState(false);
|
|
52
59
|
const [projectSwitcherOpen, setProjectSwitcherOpen] = useState(false);
|
|
60
|
+
// Bottom-line shortcuts overlay — '?' on an empty input shows it; any key dismisses it.
|
|
61
|
+
const [showShortcuts, setShowShortcuts] = useState(false);
|
|
62
|
+
// Stable callbacks so the memoized InputBox isn't re-rendered by unrelated App state changes.
|
|
63
|
+
const handleToggleShortcuts = useCallback(() => setShowShortcuts(s => !s), []);
|
|
64
|
+
const handleDismissShortcuts = useCallback(() => setShowShortcuts(false), []);
|
|
65
|
+
// Mouse capture (SGR tracking) state. Default ON so the wheel scrolls the transcript (enabled at
|
|
66
|
+
// startup in index.tsx). Ctrl+T / `/mouse` toggles it OFF — writing the SGR disable sequence —
|
|
67
|
+
// to free the mouse for native click-drag text selection + right-click paste (the wheel stops).
|
|
68
|
+
const [mouseCapture, setMouseCapture] = useState(true);
|
|
69
|
+
// Toast message (e.g. "Copied to clipboard!") — auto-clears after 3 seconds.
|
|
70
|
+
const [toast, setToast] = useState(null);
|
|
71
|
+
const toastTimerRef = useRef(null);
|
|
72
|
+
const showToast = useCallback((msg) => {
|
|
73
|
+
if (toastTimerRef.current)
|
|
74
|
+
clearTimeout(toastTimerRef.current);
|
|
75
|
+
setToast(msg);
|
|
76
|
+
toastTimerRef.current = setTimeout(() => { setToast(null); toastTimerRef.current = null; }, 3000);
|
|
77
|
+
}, []);
|
|
53
78
|
// Project switcher state
|
|
54
79
|
const [projects, setProjects] = useState([]);
|
|
55
80
|
const [projectsLoading, setProjectsLoading] = useState(false);
|
|
56
81
|
const [projectsError, setProjectsError] = useState(null);
|
|
82
|
+
// `/resume` session picker (client-side, replaces the inert Resume button).
|
|
83
|
+
const [slashResumeSessions, setSlashResumeSessions] = useState(null);
|
|
84
|
+
// `/resume <id>` direct-jump target (session id / name / suffix). Resolved against the
|
|
85
|
+
// sessions.list result; null means "show the picker".
|
|
86
|
+
const resumeTargetRef = useRef(null);
|
|
87
|
+
// Dedicated turn-status line shown above the input (state/time/turns/cost). Status
|
|
88
|
+
// frames (identified by their `actions` rich-block) are routed here, NOT the transcript.
|
|
89
|
+
const [turnStatus, setTurnStatus] = useState(null);
|
|
57
90
|
const transcriptRef = useRef(null);
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
:
|
|
91
|
+
// Terminal size — drives the full-screen root box and updates on resize so the layout
|
|
92
|
+
// always fills the alternate-screen buffer (see enterFullscreen in index.tsx).
|
|
93
|
+
const { stdout } = useStdout();
|
|
94
|
+
const [termSize, setTermSize] = useState(() => ({
|
|
95
|
+
rows: stdout?.rows ?? 24,
|
|
96
|
+
columns: stdout?.columns ?? 80,
|
|
97
|
+
}));
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (!stdout)
|
|
100
|
+
return;
|
|
101
|
+
const onResize = () => setTermSize({ rows: stdout.rows, columns: stdout.columns });
|
|
102
|
+
onResize();
|
|
103
|
+
stdout.on('resize', onResize);
|
|
104
|
+
return () => { stdout.off('resize', onResize); };
|
|
105
|
+
}, [stdout]);
|
|
63
106
|
// Active tab for dashboard
|
|
64
107
|
const [activeTab, setActiveTab] = useState('threads');
|
|
65
108
|
// Route non-mutate frames to the appropriate handler
|
|
@@ -76,6 +119,37 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
76
119
|
return;
|
|
77
120
|
}
|
|
78
121
|
if (isUiQueryResult(frame) || isUiEvent(frame)) {
|
|
122
|
+
// Handle the `/resume` session list
|
|
123
|
+
if (isUiQueryResult(frame) && frame.id === 'slash-resume-list') {
|
|
124
|
+
const list = (frame.ok && Array.isArray(frame.data))
|
|
125
|
+
? frame.data.map((s) => ({
|
|
126
|
+
sessionId: s.sessionId ?? s.id,
|
|
127
|
+
name: s.name,
|
|
128
|
+
projectId: s.projectId,
|
|
129
|
+
label: s.label ?? null,
|
|
130
|
+
}))
|
|
131
|
+
: [];
|
|
132
|
+
// `/resume <id>`: resolve the target and jump straight in, skipping the picker.
|
|
133
|
+
const target = resumeTargetRef.current;
|
|
134
|
+
resumeTargetRef.current = null;
|
|
135
|
+
if (target) {
|
|
136
|
+
const matchedId = matchResumeTarget(list, target);
|
|
137
|
+
if (matchedId) {
|
|
138
|
+
const matched = list.find(s => s.sessionId === matchedId);
|
|
139
|
+
sendFrame({
|
|
140
|
+
type: 'session.switch',
|
|
141
|
+
id: 'slash-resume-direct',
|
|
142
|
+
projectId: matched?.projectId ?? projectId ?? 'general',
|
|
143
|
+
sessionId: matchedId,
|
|
144
|
+
});
|
|
145
|
+
setSlashResumeSessions(null);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
// No match — fall through to the picker so the user can choose.
|
|
149
|
+
}
|
|
150
|
+
setSlashResumeSessions(list);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
79
153
|
// Handle project switcher responses
|
|
80
154
|
if (isUiQueryResult(frame) && frame.id === 'proj-switcher-list') {
|
|
81
155
|
if (frame.ok) {
|
|
@@ -93,8 +167,16 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
93
167
|
dashboard.dispatch(frame);
|
|
94
168
|
return;
|
|
95
169
|
}
|
|
170
|
+
// Status messages (the "⏳ Processing…/✅ Done…" line) carry an `actions` rich-block.
|
|
171
|
+
// Route them to the dedicated turn-status line above the input instead of the
|
|
172
|
+
// transcript, so the chat history holds only real user/assistant messages.
|
|
173
|
+
if ((isChatPost(frame) || isChatUpdate(frame)) && hasActionsBlock(frame.content)) {
|
|
174
|
+
const text = String(frame.content?.text ?? '');
|
|
175
|
+
setTurnStatus(text ? formatTurnStatus(parseTurnStatus(text)) : null);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
96
178
|
transcript.dispatch(frame);
|
|
97
|
-
}, [transcript.dispatch, dashboard.dispatch, notif.add]);
|
|
179
|
+
}, [transcript.dispatch, dashboard.dispatch, notif.add, sendFrame, projectId]);
|
|
98
180
|
// Mutate hook: sends ui.mutate frames, correlates results by id, 10s timeout
|
|
99
181
|
const { mutate, handleFrame } = useMutate({ sendFrame, onFrame: routeFrame });
|
|
100
182
|
// Combined dispatch: mutate intercepts mutateResult; rest routes normally
|
|
@@ -105,11 +187,21 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
105
187
|
useEffect(() => {
|
|
106
188
|
sendFrame({ type: 'ui.query', id: 'dash-cost', scope: 'cost.summary', params: {} });
|
|
107
189
|
}, []);
|
|
108
|
-
// Switching project/session (session.switched is handled in index.tsx and never
|
|
109
|
-
//
|
|
190
|
+
// Switching project/session (session.switched is handled in index.tsx and never reaches
|
|
191
|
+
// routeFrame) must release any pending send-lock from the OLD session. With lazy session
|
|
192
|
+
// creation the first message transitions sessionName null→name — that is NOT a switch and
|
|
193
|
+
// must NOT clear the in-flight `awaitingResponse`/queued state, so we only reset when a real
|
|
194
|
+
// prior session existed and actually changed.
|
|
195
|
+
const prevSessionRef = useRef({ projectId, sessionName });
|
|
110
196
|
useEffect(() => {
|
|
111
|
-
|
|
112
|
-
|
|
197
|
+
const prev = prevSessionRef.current;
|
|
198
|
+
const isRealSwitch = (prev.sessionName !== null && prev.sessionName !== sessionName)
|
|
199
|
+
|| (prev.projectId !== null && prev.projectId !== projectId);
|
|
200
|
+
prevSessionRef.current = { projectId, sessionName };
|
|
201
|
+
if (isRealSwitch) {
|
|
202
|
+
setAwaitingResponse(false);
|
|
203
|
+
setQueuedCount(0);
|
|
204
|
+
}
|
|
113
205
|
}, [projectId, sessionName]);
|
|
114
206
|
// Submit message
|
|
115
207
|
const handleSubmit = useCallback((text) => {
|
|
@@ -119,9 +211,14 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
119
211
|
id,
|
|
120
212
|
text,
|
|
121
213
|
});
|
|
214
|
+
// Optimistically echo genuine user messages into the transcript (the server doesn't echo
|
|
215
|
+
// them back). Skip `!`-prefixed control commands (!new/!cancel/!restart…) — they aren't chat.
|
|
216
|
+
if (text && !text.startsWith('!')) {
|
|
217
|
+
transcript.addUserMessage(text);
|
|
218
|
+
}
|
|
122
219
|
setQueuedCount(prev => prev + 1);
|
|
123
220
|
setAwaitingResponse(true);
|
|
124
|
-
}, [sendFrame]);
|
|
221
|
+
}, [sendFrame, transcript]);
|
|
125
222
|
// Cancel (sends !cancel)
|
|
126
223
|
const handleCancel = useCallback(() => {
|
|
127
224
|
onSendCancel();
|
|
@@ -137,6 +234,10 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
137
234
|
const handleScrollDown = useCallback((page) => {
|
|
138
235
|
transcriptRef.current?.scrollDown(page);
|
|
139
236
|
}, []);
|
|
237
|
+
// Coalesced wheel scroll: a batched net delta from useMouseHandler applied in one update.
|
|
238
|
+
const handleScrollByLines = useCallback((delta) => {
|
|
239
|
+
transcriptRef.current?.scrollByLines(delta);
|
|
240
|
+
}, []);
|
|
140
241
|
// Side panel toggle
|
|
141
242
|
const handleToggleSidePanel = useCallback(() => {
|
|
142
243
|
setSidePanelVisible(prev => !prev);
|
|
@@ -149,6 +250,21 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
149
250
|
const handleToggleProjectSwitcher = useCallback(() => {
|
|
150
251
|
setProjectSwitcherOpen(prev => !prev);
|
|
151
252
|
}, []);
|
|
253
|
+
// Toggle mouse capture. Writes the SGR mouse enable/disable sequences straight to the TTY so
|
|
254
|
+
// the change takes effect immediately: OFF frees the mouse for native text selection, ON
|
|
255
|
+
// restores wheel-scroll + in-TUI drag-select capture. ?1002h = button-event tracking (motion
|
|
256
|
+
// only while a button is held), ?1006h = SGR encoding. index.tsx's leaveFullscreen disables
|
|
257
|
+
// tracking on exit anyway.
|
|
258
|
+
const handleToggleMouse = useCallback(() => {
|
|
259
|
+
setMouseCapture(prev => {
|
|
260
|
+
const next = !prev;
|
|
261
|
+
try {
|
|
262
|
+
process.stdout.write(next ? '\x1b[?1002h\x1b[?1006h' : '\x1b[?1002l\x1b[?1006l');
|
|
263
|
+
}
|
|
264
|
+
catch { /* best effort */ }
|
|
265
|
+
return next;
|
|
266
|
+
});
|
|
267
|
+
}, []);
|
|
152
268
|
// Project switcher select
|
|
153
269
|
const handleProjectSelect = useCallback((selectedProjectId) => {
|
|
154
270
|
sendFrame({
|
|
@@ -179,8 +295,57 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
179
295
|
params: {},
|
|
180
296
|
});
|
|
181
297
|
}, [sendFrame]);
|
|
298
|
+
// Slash-command dispatch from the input palette.
|
|
299
|
+
const handleCommand = useCallback((name, args) => {
|
|
300
|
+
switch (name) {
|
|
301
|
+
case 'new':
|
|
302
|
+
// Clear the view, then start a new conversation (server runs the pre-close hook).
|
|
303
|
+
handleClearView();
|
|
304
|
+
handleSubmit('!new');
|
|
305
|
+
break;
|
|
306
|
+
case 'newx':
|
|
307
|
+
// Same, but skip the pre-close hook (no save).
|
|
308
|
+
handleClearView();
|
|
309
|
+
handleSubmit('!newq');
|
|
310
|
+
break;
|
|
311
|
+
case 'cancel':
|
|
312
|
+
handleCancel();
|
|
313
|
+
break;
|
|
314
|
+
case 'restart':
|
|
315
|
+
// Send the server-restart command. The WS connection drops during the respawn
|
|
316
|
+
// and the client reconnects automatically (no need to keep the input locked).
|
|
317
|
+
handleSubmit('!restart');
|
|
318
|
+
break;
|
|
319
|
+
case 'resume':
|
|
320
|
+
// `/resume` opens the picker; `/resume <id>` jumps straight to that session.
|
|
321
|
+
resumeTargetRef.current = args.trim() || null;
|
|
322
|
+
sendFrame({ type: 'ui.query', id: 'slash-resume-list', scope: 'sessions.list', params: { resumable: true } });
|
|
323
|
+
break;
|
|
324
|
+
case 'mouse':
|
|
325
|
+
// Client-side only (the server has no !mouse): toggle mouse capture for text selection.
|
|
326
|
+
handleToggleMouse();
|
|
327
|
+
break;
|
|
328
|
+
case 'help':
|
|
329
|
+
// The palette itself lists the commands — nothing else to do.
|
|
330
|
+
break;
|
|
331
|
+
default:
|
|
332
|
+
// Every other registered slash command mirrors a server `!` command (same name). Forward
|
|
333
|
+
// it as `!<name> <args>` so the server's command dispatcher handles it and replies into
|
|
334
|
+
// the transcript. `!`-prefixed text is not echoed as a chat message (see handleSubmit).
|
|
335
|
+
handleSubmit(`!${name}${args ? ` ${args}` : ''}`);
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}, [handleClearView, handleSubmit, handleCancel, handleToggleMouse, sendFrame]);
|
|
339
|
+
// `/resume` picker selection → switch to the chosen session; Esc/cancel closes it.
|
|
340
|
+
const handleSlashResumeSelect = useCallback((sessionId, pickedProjectId) => {
|
|
341
|
+
sendFrame({ type: 'session.switch', id: 'slash-resume', projectId: pickedProjectId, sessionId });
|
|
342
|
+
setSlashResumeSessions(null);
|
|
343
|
+
}, [sendFrame]);
|
|
344
|
+
const handleSlashResumeCancel = useCallback(() => {
|
|
345
|
+
setSlashResumeSessions(null);
|
|
346
|
+
}, []);
|
|
182
347
|
// Modals pre-empt input; an open dashboard takes keyboard focus from the input.
|
|
183
|
-
const modalOpen = activeModal !== null || notificationsOpen || projectSwitcherOpen;
|
|
348
|
+
const modalOpen = activeModal !== null || notificationsOpen || projectSwitcherOpen || slashResumeSessions !== null;
|
|
184
349
|
const focusZone = computeFocusZone({ modalOpen, sidePanelVisible });
|
|
185
350
|
// Keyboard bindings — toggles/cancel always active outside modals; scroll only
|
|
186
351
|
// when the chat input owns focus; reconnect only when not connected.
|
|
@@ -194,11 +359,30 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
194
359
|
onToggleSidePanel: handleToggleSidePanel,
|
|
195
360
|
onToggleNotifications: handleToggleNotifications,
|
|
196
361
|
onToggleProjectSwitcher: handleToggleProjectSwitcher,
|
|
362
|
+
onToggleMouse: handleToggleMouse,
|
|
197
363
|
onReconnect,
|
|
198
364
|
}, focusZone !== 'modal', {
|
|
199
365
|
allowScroll: focusZone === 'input',
|
|
200
366
|
allowReconnect: connectionState !== 'connected',
|
|
201
367
|
});
|
|
368
|
+
// Mouse handler: wheel scroll, text selection (left-drag → OSC 52 copy), right-click hint.
|
|
369
|
+
const handleSelectionComplete = useCallback((range) => {
|
|
370
|
+
const text = transcriptRef.current?.getSelectedText(range);
|
|
371
|
+
if (text && text.length > 0) {
|
|
372
|
+
osc52Copy(text);
|
|
373
|
+
showToast(`Copied ${text.length} chars to clipboard (OSC 52)`);
|
|
374
|
+
}
|
|
375
|
+
}, [showToast]);
|
|
376
|
+
const handleRightClick = useCallback(() => {
|
|
377
|
+
showToast('Use Ctrl+Shift+V to paste');
|
|
378
|
+
}, [showToast]);
|
|
379
|
+
const { selection } = useMouseHandler({
|
|
380
|
+
onScrollUp: handleScrollUp,
|
|
381
|
+
onScrollDown: handleScrollDown,
|
|
382
|
+
onScrollByLines: handleScrollByLines,
|
|
383
|
+
onSelectionComplete: handleSelectionComplete,
|
|
384
|
+
onRightClick: handleRightClick,
|
|
385
|
+
});
|
|
202
386
|
// Dashboard subscription management callbacks. Depend on the stable inner
|
|
203
387
|
// functions (each a useCallback in useDashboardData), NOT the whole `dashboard`
|
|
204
388
|
// object — that object is recreated every render, which previously made these
|
|
@@ -213,11 +397,15 @@ export function App({ sendFrame, connectionState, ack, onReconnect, onDisconnect
|
|
|
213
397
|
const handleUnregisterSubscription = useCallback((queryId) => {
|
|
214
398
|
unregisterSubscription(queryId);
|
|
215
399
|
}, [unregisterSubscription]);
|
|
400
|
+
// Compute the actual reserved rows for the bottom UI so Transcript sizes its viewport exactly.
|
|
401
|
+
// Base = marginTop(1) + border(3) + StatusLine(1) = 5, plus the optional line above the input
|
|
402
|
+
// (toast OR turn-status — InputBox renders one or the other) and the awaiting-response hint.
|
|
403
|
+
const reservedBottomRows = 5 + ((toast || turnStatus) ? 1 : 0) + (awaitingResponse && focusZone === 'input' ? 1 : 0);
|
|
216
404
|
// If resume mode with sessions to pick, show picker instead of main layout
|
|
217
405
|
if (resumableSessions && resumableSessions.length > 0 && onResumeSelect && onResumeCancel) {
|
|
218
|
-
return (_jsx(Box, { flexDirection: "column", height:
|
|
406
|
+
return (_jsx(Box, { flexDirection: "column", height: termSize.rows, width: termSize.columns, justifyContent: "center", alignItems: "center", children: _jsx(SessionPicker, { sessions: resumableSessions, onSelect: onResumeSelect, onCancel: onResumeCancel }) }));
|
|
219
407
|
}
|
|
220
|
-
return (_jsxs(Box, { flexDirection: "column", height:
|
|
408
|
+
return (_jsxs(Box, { flexDirection: "column", height: termSize.rows, width: termSize.columns, children: [_jsx(Box, { flexDirection: "row", flexGrow: 1, justifyContent: "center", children: sidePanelVisible ? (_jsx(SidePanel, { visible: sidePanelVisible, active: focusZone === 'dashboard', sendFrame: sendFrame, projectId: projectId, dashState: dashboard.state, onMarkPending: handleMarkPending, onRegisterSubscription: handleRegisterSubscription, onUnregisterSubscription: handleUnregisterSubscription, activeTab: activeTab, onSetActiveTab: setActiveTab, onMutate: mutate, onClose: handleToggleSidePanel })) : (_jsx(Box, { flexDirection: "column", flexGrow: 1, children: _jsx(Transcript, { ref: transcriptRef, messages: transcript.messages, ids: transcript.ids, reservedRows: reservedBottomRows, selection: selection }) })) }), activeModal ? (activeModal.modal.callbackId.startsWith('plan')
|
|
221
409
|
? _jsx(PlanFeedbackModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })
|
|
222
|
-
: _jsx(AskUserModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })) : modalOpen ? (_jsxs(Box, { borderStyle: "single", borderDimColor: true, paddingX: 1, marginTop: 1, children: [notificationsOpen ? (_jsx(NotificationsModal, { open: notificationsOpen, notifications: notif.notifications, ids: notif.ids, onMarkRead: notif.markRead, onClose: () => setNotificationsOpen(false), onSelect: handleNotificationSelect })) : null, projectSwitcherOpen ? (_jsx(ProjectSwitcher, { open: projectSwitcherOpen, projects: projects, loading: projectsLoading, error: projectsError, onSelect: handleProjectSelect, onClose: () => setProjectSwitcherOpen(false), onRequestRefresh: handleProjectsRefresh })) : null] })) : (_jsx(InputBox, { onSubmit: handleSubmit, awaitingResponse: awaitingResponse, focus: focusZone === 'input' })), _jsx(StatusLine, { connectionState: connectionState, queuedCount: queuedCount, notificationCount: notif.unreadCount,
|
|
410
|
+
: _jsx(AskUserModal, { modal: activeModal.modal, triggerId: activeModal.triggerId, sendFrame: sendFrame, ackErrors: modalAckErrors, onClose: () => { setActiveModal(null); setModalAckErrors({}); } })) : modalOpen ? (_jsxs(Box, { borderStyle: "single", borderDimColor: true, paddingX: 1, marginTop: 1, children: [notificationsOpen ? (_jsx(NotificationsModal, { open: notificationsOpen, notifications: notif.notifications, ids: notif.ids, onMarkRead: notif.markRead, onClose: () => setNotificationsOpen(false), onSelect: handleNotificationSelect })) : null, projectSwitcherOpen ? (_jsx(ProjectSwitcher, { open: projectSwitcherOpen, projects: projects, loading: projectsLoading, error: projectsError, onSelect: handleProjectSelect, onClose: () => setProjectSwitcherOpen(false), onRequestRefresh: handleProjectsRefresh })) : null, slashResumeSessions !== null ? (_jsx(SessionPicker, { sessions: slashResumeSessions, onSelect: handleSlashResumeSelect, onCancel: handleSlashResumeCancel })) : null] })) : (_jsx(InputBox, { onSubmit: handleSubmit, onCommand: handleCommand, commands: SLASH_COMMANDS, awaitingResponse: awaitingResponse, focus: focusZone === 'input', showShortcuts: showShortcuts, onToggleShortcuts: handleToggleShortcuts, onDismissShortcuts: handleDismissShortcuts, statusLine: turnStatus, toast: toast })), _jsx(StatusLine, { connectionState: connectionState, errorMessage: errorMessage, projectId: projectId, queuedCount: queuedCount, notificationCount: notif.unreadCount, showShortcuts: showShortcuts && focusZone === 'input', dashboardActive: focusZone === 'dashboard', mouseCapture: mouseCapture })] }));
|
|
223
411
|
}
|
|
@@ -18,6 +18,8 @@ interface DashboardProps {
|
|
|
18
18
|
onUnregisterSubscription: (queryId: string) => void;
|
|
19
19
|
activeTab: string;
|
|
20
20
|
onSetActiveTab: (tab: string) => void;
|
|
21
|
+
/** Close the panel (Esc while the dashboard owns the keyboard, mirrors the Ctrl+D toggle). */
|
|
22
|
+
onClose?: () => void;
|
|
21
23
|
}
|
|
22
|
-
export declare function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, }: DashboardProps): React.JSX.Element;
|
|
24
|
+
export declare function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, onClose, }: DashboardProps): React.JSX.Element;
|
|
23
25
|
export {};
|
|
@@ -83,8 +83,12 @@ function TabContent({ tab, active, sendFrame, mutate, projectId, dashState, onMa
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
// ── Component ──
|
|
86
|
-
export function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, }) {
|
|
86
|
+
export function Dashboard({ active, sendFrame, mutate, projectId, dashState, onMarkPending, onRegisterSubscription, onUnregisterSubscription, activeTab, onSetActiveTab, onClose, }) {
|
|
87
87
|
useInput((_input, key) => {
|
|
88
|
+
if (key.escape) {
|
|
89
|
+
onClose?.();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
88
92
|
if (key.tab) {
|
|
89
93
|
const currentIdx = DASHBOARD_TABS.findIndex(t => t.key === activeTab);
|
|
90
94
|
const nextIdx = (currentIdx + 1) % DASHBOARD_TABS.length;
|
|
@@ -10,7 +10,22 @@ export function DashboardCostTab({ data }) {
|
|
|
10
10
|
if (!data.data || (Array.isArray(data.data) && data.data.length === 0)) {
|
|
11
11
|
return _jsx(Text, { dimColor: true, children: "No cost data" });
|
|
12
12
|
}
|
|
13
|
-
//
|
|
13
|
+
// The server returns a CostSummary object (domain/costs/cost-tracker.ts): top-level
|
|
14
|
+
// today/week/month/total are USD numbers; byMode maps mode → { today, week, month, total }.
|
|
15
|
+
// useDashboardData wraps a non-array response in a single-element array.
|
|
14
16
|
const costData = Array.isArray(data.data) ? data.data[0] : data.data;
|
|
15
|
-
|
|
17
|
+
const usd = (v) => `$${typeof v === 'number' ? v.toFixed(4) : String(v)}`;
|
|
18
|
+
// byMode is keyed by PERIOD (today/week/month/total); each value is a ModeBuckets
|
|
19
|
+
// { total, api, plan, ... } breaking that period down by cost type. The all-time
|
|
20
|
+
// bucket (byMode.total) gives the api/plan split; skip the 'total' meta key.
|
|
21
|
+
const allTime = costData?.byMode?.total && typeof costData.byMode.total === 'object' ? costData.byMode.total : {};
|
|
22
|
+
const modeEntries = Object.entries(allTime)
|
|
23
|
+
.filter(([k, v]) => k !== 'total' && typeof v === 'number' && v > 0);
|
|
24
|
+
const hasAnyTotal = costData?.total != null || costData?.month != null || costData?.today != null;
|
|
25
|
+
if (!hasAnyTotal && modeEntries.length === 0) {
|
|
26
|
+
return _jsx(Text, { dimColor: true, children: "No cost summary available" });
|
|
27
|
+
}
|
|
28
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: "Cost Summary" }) }), costData?.total != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Total: " }), _jsx(Text, { children: usd(costData.total) })] })) : null, costData?.month != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "This month: " }), _jsx(Text, { children: usd(costData.month) })] })) : null, costData?.week != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "This week: " }), _jsx(Text, { children: usd(costData.week) })] })) : null, costData?.today != null ? (_jsxs(Box, { children: [_jsx(Text, { children: "Today: " }), _jsx(Text, { children: usd(costData.today) })] })) : null, modeEntries.length > 0 ? (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsx(Text, { dimColor: true, children: "By cost type (all-time):" }), modeEntries
|
|
29
|
+
.sort(([, a], [, b]) => b - a)
|
|
30
|
+
.map(([mode, v]) => (_jsxs(Box, { marginLeft: 1, children: [_jsxs(Text, { dimColor: true, children: [mode, ": "] }), _jsx(Text, { children: usd(v) })] }, mode)))] })) : null] }));
|
|
16
31
|
}
|