@cortex-agent/server 2026.6.22 → 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/context/user/CORTEX.md +2 -2
- package/defaults/gitignore +3 -0
- package/defaults/hooks/CORTEX.md +18 -0
- package/defaults/hooks/ask-user-question-hook.mjs +1 -0
- package/defaults/hooks/cortex-hook-api.mjs +84 -0
- package/defaults/hooks/cortex-md-injector.mjs +99 -49
- package/defaults/hooks/exit-plan-mode-hook.mjs +1 -0
- package/defaults/hooks/memory-ref-tracker.mjs +1 -0
- package/defaults/hooks/new-session-hook.mjs +1 -0
- package/defaults/hooks/post-task-hook.mjs +1 -0
- package/defaults/hooks/rules-loader.mjs +1 -0
- package/defaults/hooks/sensitive-file-edit.mjs +1 -0
- package/defaults/hooks/session-activity-tracker.mjs +8 -100
- package/defaults/hooks/task-status-check.mjs +10 -10
- package/defaults/hooks/tasks-yaml-guard.mjs +1 -0
- 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-feishu/.claude-plugin/plugin.json +5 -0
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +163 -0
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/scripts/ensure-lark-cli.sh +53 -0
- 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-reviewer.md +6 -6
- package/defaults/prompts/directives/coder.md +4 -29
- 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 +14 -0
- package/dist/agent-adapter/claude/adapter-tui.js +16 -0
- package/dist/agent-adapter/claude/adapter.d.ts +89 -5
- package/dist/agent-adapter/claude/adapter.js +410 -40
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +23 -8
- package/dist/agent-adapter/claude/bg-task-tracker.js +48 -19
- 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 +15 -11
- 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 +30 -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/interactions.d.ts +6 -0
- package/dist/core/locales/slices/interactions.js +14 -0
- 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/status-format.d.ts +14 -0
- package/dist/core/status-format.js +23 -1
- 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 +90 -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 +74 -10
- package/dist/domain/agents/facade.js +333 -62
- 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 +5 -56
- package/dist/domain/mcp/feishu-server.d.ts +0 -1
- package/dist/domain/mcp/feishu-server.js +5 -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/memory/user-context.d.ts +6 -5
- package/dist/domain/memory/user-context.js +12 -7
- 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.d.ts +9 -2
- package/dist/domain/remote/client-hot-reload.js +81 -9
- 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 +40 -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 +38 -15
- package/dist/domain/sessions/session-hooks.js +128 -122
- 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.d.ts +63 -0
- package/dist/domain/system/doctor.js +359 -0
- 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 +37 -7
- package/dist/domain/tasks/system/task-completion.js +148 -42
- package/dist/domain/tasks/system/task-lifecycle-edit.js +3 -0
- package/dist/domain/tasks/system/task-state.d.ts +10 -1
- package/dist/domain/tasks/system/task-state.js +31 -1
- 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 +14 -4
- package/dist/domain/threads/prompt-builder.js +38 -20
- package/dist/domain/threads/runner.d.ts +19 -5
- package/dist/domain/threads/runner.js +238 -82
- 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 +307 -36
- package/dist/entry/cli.js +10 -0
- 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/doctor-cli.d.ts +12 -0
- package/dist/entry/doctor-cli.js +76 -0
- 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/ask-user-question-hook.mjs +1 -0
- package/dist/hooks/cortex-hook-api.mjs +84 -0
- package/dist/hooks/cortex-md-injector.mjs +99 -49
- package/dist/hooks/exit-plan-mode-hook.mjs +1 -0
- package/dist/hooks/memory-ref-tracker.mjs +1 -0
- package/dist/hooks/new-session-hook.mjs +1 -0
- package/dist/hooks/post-task-hook.mjs +1 -0
- package/dist/hooks/rules-loader.mjs +1 -0
- package/dist/hooks/sensitive-file-edit.mjs +1 -0
- package/dist/hooks/session-activity-tracker.mjs +8 -100
- package/dist/hooks/task-status-check.mjs +10 -10
- package/dist/hooks/tasks-yaml-guard.mjs +1 -0
- 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 +368 -55
- 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 +71 -13
- 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 +10 -4
- package/dist/orchestration/lifecycle.js +155 -60
- package/dist/orchestration/manager-qa.d.ts +15 -4
- package/dist/orchestration/manager-qa.js +43 -37
- 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 +26 -4
- package/dist/orchestration/resume-dispatcher.js +89 -43
- 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 -3
- package/dist/orchestration/thread-callback.js +329 -74
- 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/plugin-sync.d.ts +21 -0
- package/dist/store/plugin-sync.js +119 -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 +11 -0
- package/dist/store/version-migrations.js +286 -9
- package/dist/tui/App.js +219 -27
- package/dist/tui/components/Dashboard.d.ts +3 -1
- package/dist/tui/components/Dashboard.js +31 -12
- 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 +263 -8
- 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 -594
- 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/bitable.d.ts +0 -3
- package/dist/domain/mcp/feishu/bitable.js +0 -168
- package/dist/domain/mcp/feishu/block-types.d.ts +0 -44
- package/dist/domain/mcp/feishu/block-types.js +0 -127
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +0 -19
- package/dist/domain/mcp/feishu/blocks-to-text.js +0 -43
- package/dist/domain/mcp/feishu/docx.d.ts +0 -3
- package/dist/domain/mcp/feishu/docx.js +0 -163
- package/dist/domain/mcp/feishu/drive.d.ts +0 -23
- package/dist/domain/mcp/feishu/drive.js +0 -66
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +0 -40
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +0 -191
- package/dist/domain/mcp/feishu/sheets.d.ts +0 -3
- package/dist/domain/mcp/feishu/sheets.js +0 -119
- package/dist/domain/mcp/feishu/wiki.d.ts +0 -3
- package/dist/domain/mcp/feishu/wiki.js +0 -77
- 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
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: hook registry/templates, CLI helpers, hook process runner
|
|
3
|
+
// output: runHookCli and cortex-hook executable entry point
|
|
4
|
+
// pos: Operator CLI for hook observability and blocking user asks
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
import * as http from 'node:http';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import { cliError, formatError, formatHelp, readStdinSync, } from '../core/cli-utils.js';
|
|
10
|
+
import { runHookProcess } from '../core/hook-exec.js';
|
|
11
|
+
import { CONFIG_DIR, HOOKS_DIR } from '../core/paths.js';
|
|
12
|
+
import { isMainModule } from '../core/utils.js';
|
|
13
|
+
import { normalizeAskLevel } from '../platform/interactive-builder.js';
|
|
14
|
+
import { MANAGED_RESYNC_WARNING, setHookEnabled } from '../store/hook-writer.js';
|
|
15
|
+
import { loadMountedHooks, summarizeMountedHook, } from '../store/hook-registry.js';
|
|
16
|
+
const COMMANDS = ['list', 'show', 'enable', 'disable', 'test', 'ask'];
|
|
17
|
+
const ROOT_HELP = {
|
|
18
|
+
name: 'cortex-hook',
|
|
19
|
+
description: 'Inspect, manage, and execute Cortex hook declarations',
|
|
20
|
+
usage: 'cortex-hook <command> [options]',
|
|
21
|
+
commands: [
|
|
22
|
+
{ name: 'list', description: 'List registry and template-scoped hooks' },
|
|
23
|
+
{ name: 'show --id <id>', description: 'Show one complete hook declaration' },
|
|
24
|
+
{ name: 'enable --id <id>', description: 'Enable a registry hook' },
|
|
25
|
+
{ name: 'disable --id <id>', description: 'Disable a registry hook' },
|
|
26
|
+
{ name: 'test --id <id>', description: 'Execute one hook with a payload' },
|
|
27
|
+
{ name: 'ask --question <text>', description: 'Ask the user a card question and block for the answer' },
|
|
28
|
+
],
|
|
29
|
+
options: [{ flag: '--help, -h', description: 'Show this help' }],
|
|
30
|
+
examples: [
|
|
31
|
+
{ description: 'List mounted declarations', command: 'cortex-hook list' },
|
|
32
|
+
{ description: 'Inspect one declaration', command: 'cortex-hook show --id sensitive-file-edit' },
|
|
33
|
+
{ description: 'Execute with a payload file', command: 'cortex-hook test --id sensitive-file-edit --payload payload.json' },
|
|
34
|
+
{ description: 'Ask the user from a hook', command: 'cortex-hook ask --question "Clean old checkpoints?" --options "Clean|Keep" --level warning' },
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
const COMMAND_HELP = {
|
|
38
|
+
list: {
|
|
39
|
+
name: 'cortex-hook list',
|
|
40
|
+
description: 'List every registry and template-scoped hook declaration',
|
|
41
|
+
usage: 'cortex-hook list',
|
|
42
|
+
options: [{ flag: '--help, -h', description: 'Show this help' }],
|
|
43
|
+
examples: [{ description: 'List hooks as JSON', command: 'cortex-hook list' }],
|
|
44
|
+
},
|
|
45
|
+
show: {
|
|
46
|
+
name: 'cortex-hook show',
|
|
47
|
+
description: 'Show one complete hook declaration',
|
|
48
|
+
usage: 'cortex-hook show --id <id>',
|
|
49
|
+
options: [
|
|
50
|
+
{ flag: '--id <id>', description: 'Hook id from cortex-hook list' },
|
|
51
|
+
{ flag: '--help, -h', description: 'Show this help' },
|
|
52
|
+
],
|
|
53
|
+
examples: [{ description: 'Show a hook', command: 'cortex-hook show --id sensitive-file-edit' }],
|
|
54
|
+
},
|
|
55
|
+
enable: {
|
|
56
|
+
name: 'cortex-hook enable',
|
|
57
|
+
description: 'Enable one registry hook idempotently',
|
|
58
|
+
usage: 'cortex-hook enable --id <id> [--dry-run]',
|
|
59
|
+
options: [
|
|
60
|
+
{ flag: '--id <id>', description: 'Registry hook id' },
|
|
61
|
+
{ flag: '--dry-run', description: 'Validate and preview without writing', default: 'false' },
|
|
62
|
+
{ flag: '--help, -h', description: 'Show this help' },
|
|
63
|
+
],
|
|
64
|
+
examples: [
|
|
65
|
+
{ description: 'Preview enabling a hook', command: 'cortex-hook enable --id sensitive-file-edit --dry-run' },
|
|
66
|
+
{ description: 'Enable a hook', command: 'cortex-hook enable --id sensitive-file-edit' },
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
disable: {
|
|
70
|
+
name: 'cortex-hook disable',
|
|
71
|
+
description: 'Disable one registry hook idempotently',
|
|
72
|
+
usage: 'cortex-hook disable --id <id> [--dry-run]',
|
|
73
|
+
options: [
|
|
74
|
+
{ flag: '--id <id>', description: 'Registry hook id' },
|
|
75
|
+
{ flag: '--dry-run', description: 'Validate and preview without writing', default: 'false' },
|
|
76
|
+
{ flag: '--help, -h', description: 'Show this help' },
|
|
77
|
+
],
|
|
78
|
+
examples: [
|
|
79
|
+
{ description: 'Preview disabling a hook', command: 'cortex-hook disable --id sensitive-file-edit --dry-run' },
|
|
80
|
+
{ description: 'Disable a hook', command: 'cortex-hook disable --id sensitive-file-edit' },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
test: {
|
|
84
|
+
name: 'cortex-hook test',
|
|
85
|
+
description: 'Execute one hook once with payload bytes delivered on stdin',
|
|
86
|
+
usage: 'cortex-hook test --id <id> --payload <file|->',
|
|
87
|
+
options: [
|
|
88
|
+
{ flag: '--id <id>', description: 'Hook id from cortex-hook list' },
|
|
89
|
+
{ flag: '--payload <file|->', description: 'Payload file, or - to read stdin' },
|
|
90
|
+
{ flag: '--help, -h', description: 'Show this help' },
|
|
91
|
+
],
|
|
92
|
+
examples: [
|
|
93
|
+
{ description: 'Execute with a file', command: 'cortex-hook test --id sensitive-file-edit --payload payload.json' },
|
|
94
|
+
{ description: 'Execute from stdin', command: 'cat payload.json | cortex-hook test --id sensitive-file-edit --payload -' },
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
ask: {
|
|
98
|
+
name: 'cortex-hook ask',
|
|
99
|
+
description: 'Post an ask-user card on the session message platform and block until answered',
|
|
100
|
+
usage: 'cortex-hook ask --question <text> [--options "a|b"] [--level <level>] [--channel <id> | --session-id <id>]',
|
|
101
|
+
options: [
|
|
102
|
+
{ flag: '--question <text>', description: 'Single question text (or use --payload)' },
|
|
103
|
+
{ flag: '--header <text>', description: 'Short card label (default: question prefix)' },
|
|
104
|
+
{ flag: '--options "a|b|c"', description: 'Pipe-separated choice labels' },
|
|
105
|
+
{ flag: '--multi', description: 'Allow selecting multiple options', default: 'false' },
|
|
106
|
+
{ flag: '--level <level>', description: 'Card severity: info, warn, warning, error' },
|
|
107
|
+
{ flag: '--channel <id>', description: 'Target conduit (default: CORTEX_HOOK_CHANNEL / SLACK_CHANNEL)' },
|
|
108
|
+
{ flag: '--session-id <id>', description: 'Resolve channel from a session (default: CORTEX_HOOK_SESSION_ID)' },
|
|
109
|
+
{ flag: '--payload <file|->', description: 'JSON array of question objects, or - for stdin' },
|
|
110
|
+
{ flag: '--dry-run', description: 'Smoke-test: journal only, resolve synthetically', default: 'false' },
|
|
111
|
+
{ flag: '--help, -h', description: 'Show this help' },
|
|
112
|
+
],
|
|
113
|
+
examples: [
|
|
114
|
+
{ description: 'Warning card with choices', command: 'cortex-hook ask --question "Disk almost full - clean old checkpoints?" --options "Clean|Keep" --level warning' },
|
|
115
|
+
{ description: 'Multi-question payload from stdin', command: 'cat questions.json | cortex-hook ask --payload - --session-id abc123' },
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
const FLAG_ALLOWLIST = {
|
|
120
|
+
list: ['--help', '-h'],
|
|
121
|
+
show: ['--id', '--help', '-h'],
|
|
122
|
+
enable: ['--id', '--dry-run', '--help', '-h'],
|
|
123
|
+
disable: ['--id', '--dry-run', '--help', '-h'],
|
|
124
|
+
test: ['--id', '--payload', '--help', '-h'],
|
|
125
|
+
ask: ['--question', '--header', '--options', '--multi', '--level', '--channel', '--session-id', '--payload', '--dry-run', '--help', '-h'],
|
|
126
|
+
};
|
|
127
|
+
const VALUE_FIELDS = {
|
|
128
|
+
'--id': 'id',
|
|
129
|
+
'--payload': 'payload',
|
|
130
|
+
'--question': 'question',
|
|
131
|
+
'--header': 'header',
|
|
132
|
+
'--options': 'options',
|
|
133
|
+
'--level': 'level',
|
|
134
|
+
'--channel': 'channel',
|
|
135
|
+
'--session-id': 'sessionId',
|
|
136
|
+
};
|
|
137
|
+
const BOOLEAN_FIELDS = {
|
|
138
|
+
'--dry-run': 'dryRun',
|
|
139
|
+
'--multi': 'multi',
|
|
140
|
+
'--help': 'help',
|
|
141
|
+
'-h': 'help',
|
|
142
|
+
};
|
|
143
|
+
function success(payload, exitCode = 0) {
|
|
144
|
+
return { exitCode, stdout: JSON.stringify(payload, null, 2), stderr: '' };
|
|
145
|
+
}
|
|
146
|
+
function failure(message) {
|
|
147
|
+
return { exitCode: 1, stdout: '', stderr: message };
|
|
148
|
+
}
|
|
149
|
+
function cliFailure(message, validValues, hint) {
|
|
150
|
+
return cliError(formatError(message, { validValues, hint }));
|
|
151
|
+
}
|
|
152
|
+
function defaults(options) {
|
|
153
|
+
return {
|
|
154
|
+
registryDir: options.registryDir ?? path.join(CONFIG_DIR, 'hooks'),
|
|
155
|
+
templateDir: options.templateDir ?? path.join(CONFIG_DIR, 'thread-templates', 'templates'),
|
|
156
|
+
hooksDir: options.hooksDir ?? HOOKS_DIR,
|
|
157
|
+
readStdin: options.readStdin ?? readStdinSync,
|
|
158
|
+
askPost: options.askPost ?? defaultAskPost,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function emptyParsed(command, help = false) {
|
|
162
|
+
return {
|
|
163
|
+
command, id: null, payload: null, question: null, header: null, options: null,
|
|
164
|
+
level: null, channel: null, sessionId: null, multi: false, dryRun: false, help,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function parseRoot(argv) {
|
|
168
|
+
if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
|
|
169
|
+
return emptyParsed(null, true);
|
|
170
|
+
}
|
|
171
|
+
if (!COMMANDS.includes(argv[0])) {
|
|
172
|
+
throw cliFailure(`Unknown command: '${argv[0]}'`, [...COMMANDS]);
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
function parseFlags(command, args) {
|
|
177
|
+
const parsed = emptyParsed(command);
|
|
178
|
+
const allowed = FLAG_ALLOWLIST[command];
|
|
179
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
180
|
+
const token = args[index];
|
|
181
|
+
if (!allowed.includes(token))
|
|
182
|
+
throw cliFailure(`Unknown argument: '${token}'`, allowed);
|
|
183
|
+
if (Object.hasOwn(VALUE_FIELDS, token)) {
|
|
184
|
+
const value = args[index + 1];
|
|
185
|
+
if (!value || value.startsWith('--'))
|
|
186
|
+
throw cliFailure(`${token} requires a value`);
|
|
187
|
+
parsed[VALUE_FIELDS[token]] = value;
|
|
188
|
+
index += 1;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
parsed[BOOLEAN_FIELDS[token]] = true;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return parsed;
|
|
195
|
+
}
|
|
196
|
+
function validateRequired(parsed) {
|
|
197
|
+
if (parsed.help || parsed.command === 'list' || parsed.command === null)
|
|
198
|
+
return;
|
|
199
|
+
if (parsed.command === 'ask') {
|
|
200
|
+
if (!parsed.question && !parsed.payload) {
|
|
201
|
+
throw cliFailure('ask requires --question or --payload', ['--question <text>', '--payload <file|->']);
|
|
202
|
+
}
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (!parsed.id)
|
|
206
|
+
throw cliFailure('--id is required', ['--id <id>']);
|
|
207
|
+
if (parsed.command === 'test' && !parsed.payload) {
|
|
208
|
+
throw cliFailure('--payload is required for test', ['--payload <file>', '--payload -']);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function parseArgs(argv) {
|
|
212
|
+
const root = parseRoot(argv);
|
|
213
|
+
if (root)
|
|
214
|
+
return root;
|
|
215
|
+
const parsed = parseFlags(argv[0], argv.slice(1));
|
|
216
|
+
validateRequired(parsed);
|
|
217
|
+
return parsed;
|
|
218
|
+
}
|
|
219
|
+
function uniqueHookIds(hooks) {
|
|
220
|
+
const counts = new Map();
|
|
221
|
+
for (const hook of hooks)
|
|
222
|
+
counts.set(hook.id, (counts.get(hook.id) ?? 0) + 1);
|
|
223
|
+
return hooks.filter((hook) => counts.get(hook.id) === 1).map((hook) => hook.id);
|
|
224
|
+
}
|
|
225
|
+
function findHook(id, hooks) {
|
|
226
|
+
const matches = hooks.filter((candidate) => candidate.id === id);
|
|
227
|
+
if (matches.length === 1)
|
|
228
|
+
return matches[0];
|
|
229
|
+
const valid = uniqueHookIds(hooks);
|
|
230
|
+
if (matches.length === 0)
|
|
231
|
+
throw cliFailure(`Unknown hook id: '${id}'`, valid);
|
|
232
|
+
const sources = matches.map((hook) => hook.source).join(', ');
|
|
233
|
+
throw cliFailure(`Ambiguous hook id: '${id}' from sources ${sources}`, valid, 'Rename one declaration so every mounted hook id is unique');
|
|
234
|
+
}
|
|
235
|
+
function showHook(hook) {
|
|
236
|
+
if (hook.kind === 'registry') {
|
|
237
|
+
return { ...hook.entry, enabled: hook.enabled, source: hook.source };
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
id: hook.id,
|
|
241
|
+
event: hook.event,
|
|
242
|
+
run: hook.run,
|
|
243
|
+
enabled: hook.enabled,
|
|
244
|
+
source: hook.source,
|
|
245
|
+
template: hook.template,
|
|
246
|
+
phase: hook.phase,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function registryForMutation(id, hooks) {
|
|
250
|
+
const hook = findHook(id, hooks);
|
|
251
|
+
if (hook.kind === 'registry')
|
|
252
|
+
return hook;
|
|
253
|
+
const valid = hooks.filter((item) => item.kind === 'registry').map((item) => item.id);
|
|
254
|
+
throw cliFailure(`Hook '${id}' is template-scoped; template-scoped hooks are read-only`, valid);
|
|
255
|
+
}
|
|
256
|
+
function managedWarnings(hook, enabled) {
|
|
257
|
+
if (hook.source !== 'managed' || enabled)
|
|
258
|
+
return undefined;
|
|
259
|
+
return [MANAGED_RESYNC_WARNING];
|
|
260
|
+
}
|
|
261
|
+
function statePayload(hook, enabled, changed, dryRun) {
|
|
262
|
+
const payload = {
|
|
263
|
+
ok: true,
|
|
264
|
+
id: hook.id,
|
|
265
|
+
enabled,
|
|
266
|
+
changed,
|
|
267
|
+
dry_run: dryRun,
|
|
268
|
+
source: hook.source,
|
|
269
|
+
timestamp: new Date().toISOString(),
|
|
270
|
+
};
|
|
271
|
+
if (dryRun)
|
|
272
|
+
payload.would_set = { enabled };
|
|
273
|
+
const warnings = managedWarnings(hook, enabled);
|
|
274
|
+
if (warnings)
|
|
275
|
+
payload.warnings = warnings;
|
|
276
|
+
return payload;
|
|
277
|
+
}
|
|
278
|
+
// The write itself is delegated to the shared registry writer, so the CLI and the Web UI cannot
|
|
279
|
+
// drift into two different on-disk representations of the same toggle. The CLI keeps ownership of
|
|
280
|
+
// what the writer has no opinion about: --dry-run, and the richer template-scoped error message.
|
|
281
|
+
function handleState(context, enabled) {
|
|
282
|
+
const hook = registryForMutation(context.parsed.id, context.hooks);
|
|
283
|
+
if (context.parsed.dryRun) {
|
|
284
|
+
return success(statePayload(hook, enabled, hook.enabled !== enabled, true));
|
|
285
|
+
}
|
|
286
|
+
const { changed } = setHookEnabled(context.options.registryDir, hook.id, enabled);
|
|
287
|
+
return success(statePayload(hook, enabled, changed, false));
|
|
288
|
+
}
|
|
289
|
+
function shellQuote(value) {
|
|
290
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
291
|
+
}
|
|
292
|
+
function processOptions(hook, hooksDir, stdinPayload) {
|
|
293
|
+
if (hook.kind === 'template') {
|
|
294
|
+
return {
|
|
295
|
+
command: hook.run.command,
|
|
296
|
+
args: hook.run.args,
|
|
297
|
+
timeoutMs: hook.run.timeout ?? 30_000,
|
|
298
|
+
stdinPayload,
|
|
299
|
+
label: hook.id,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
const command = hook.entry.run.script === undefined
|
|
303
|
+
? hook.entry.run.command
|
|
304
|
+
: `node ${shellQuote(path.join(hooksDir, hook.entry.run.script))}`;
|
|
305
|
+
return {
|
|
306
|
+
command,
|
|
307
|
+
timeoutMs: (hook.entry.run.timeout ?? 30) * 1_000,
|
|
308
|
+
stdinPayload,
|
|
309
|
+
label: hook.id,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function readPayload(payload, options) {
|
|
313
|
+
if (payload === '-')
|
|
314
|
+
return options.readStdin();
|
|
315
|
+
try {
|
|
316
|
+
return fs.readFileSync(payload, 'utf8');
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
320
|
+
throw cliFailure(`Cannot read --payload file '${payload}': ${message}`, ['existing file path', '-']);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async function handleTest(context) {
|
|
324
|
+
const hook = findHook(context.parsed.id, context.hooks);
|
|
325
|
+
const payload = readPayload(context.parsed.payload, context.options);
|
|
326
|
+
const result = await runHookProcess(processOptions(hook, context.options.hooksDir, payload));
|
|
327
|
+
const output = {
|
|
328
|
+
ok: result.exitCode === 0 && !result.error,
|
|
329
|
+
id: hook.id,
|
|
330
|
+
exit_code: result.exitCode,
|
|
331
|
+
stdout: result.stdout,
|
|
332
|
+
stderr: result.stderr,
|
|
333
|
+
};
|
|
334
|
+
if (result.error)
|
|
335
|
+
output.error = result.error;
|
|
336
|
+
return success(output, result.exitCode ?? (result.error ? 1 : 0));
|
|
337
|
+
}
|
|
338
|
+
// --- ask: hook-facing blocking ask-user card ---
|
|
339
|
+
function defaultAskPost(url, body, headers) {
|
|
340
|
+
const payload = JSON.stringify(body);
|
|
341
|
+
return new Promise((resolve, reject) => {
|
|
342
|
+
const req = http.request(url, {
|
|
343
|
+
method: 'POST',
|
|
344
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload), ...headers },
|
|
345
|
+
timeout: 60 * 60 * 1000, // user may take time; the server bridge TTL (30 min) fires first
|
|
346
|
+
}, (res) => {
|
|
347
|
+
let data = '';
|
|
348
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
349
|
+
res.on('end', () => {
|
|
350
|
+
try {
|
|
351
|
+
resolve({ status: res.statusCode ?? 0, body: JSON.parse(data) });
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
reject(new Error(`invalid webhook response: ${data}`));
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
req.on('error', reject);
|
|
359
|
+
req.on('timeout', () => { req.destroy(); reject(new Error('webhook request timed out')); });
|
|
360
|
+
req.write(payload);
|
|
361
|
+
req.end();
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
function parseAskQuestions(parsed, options) {
|
|
365
|
+
if (parsed.payload) {
|
|
366
|
+
const raw = readPayload(parsed.payload, options);
|
|
367
|
+
let questions;
|
|
368
|
+
try {
|
|
369
|
+
questions = JSON.parse(raw);
|
|
370
|
+
}
|
|
371
|
+
catch (e) {
|
|
372
|
+
throw cliFailure(`--payload is not valid JSON: ${e.message}`, ['JSON array of question objects']);
|
|
373
|
+
}
|
|
374
|
+
if (!Array.isArray(questions) || questions.length === 0) {
|
|
375
|
+
throw cliFailure('--payload must be a non-empty JSON array of question objects');
|
|
376
|
+
}
|
|
377
|
+
return questions;
|
|
378
|
+
}
|
|
379
|
+
const question = parsed.question;
|
|
380
|
+
return [{
|
|
381
|
+
question,
|
|
382
|
+
header: parsed.header ?? question.slice(0, 12),
|
|
383
|
+
multiSelect: parsed.multi,
|
|
384
|
+
options: parsed.options ? parsed.options.split('|').map((label) => ({ label: label.trim() })) : [],
|
|
385
|
+
}];
|
|
386
|
+
}
|
|
387
|
+
function buildAskBody(parsed, questions) {
|
|
388
|
+
const channel = parsed.channel ?? process.env.CORTEX_HOOK_CHANNEL ?? process.env.SLACK_CHANNEL ?? null;
|
|
389
|
+
const sessionId = parsed.sessionId ?? process.env.CORTEX_HOOK_SESSION_ID ?? null;
|
|
390
|
+
if (!channel && !sessionId) {
|
|
391
|
+
throw cliFailure('No target: no channel or session in flags or hook env', ['--channel <id>', '--session-id <id>'], 'Hook environments set CORTEX_HOOK_CHANNEL / SLACK_CHANNEL / CORTEX_HOOK_SESSION_ID automatically');
|
|
392
|
+
}
|
|
393
|
+
const level = parsed.level === null ? null : normalizeAskLevel(parsed.level);
|
|
394
|
+
if (parsed.level !== null && !level) {
|
|
395
|
+
throw cliFailure(`Invalid --level: '${parsed.level}'`, ['info', 'warn', 'warning', 'error']);
|
|
396
|
+
}
|
|
397
|
+
return {
|
|
398
|
+
...(channel ? { channel } : {}),
|
|
399
|
+
...(sessionId ? { sessionId } : {}),
|
|
400
|
+
threadId: process.env.CORTEX_THREAD_ID ?? null,
|
|
401
|
+
questions,
|
|
402
|
+
...(level ? { level } : {}),
|
|
403
|
+
...(parsed.dryRun ? { dryRun: true } : {}),
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/** Map the webhook response to CLI output — timeout exits 2, other bridge errors exit 1. */
|
|
407
|
+
function mapAskResponse(resp) {
|
|
408
|
+
if (resp.status !== 200) {
|
|
409
|
+
return failure(formatError(`Webhook returned status ${resp.status}: ${resp.body?.error ?? JSON.stringify(resp.body ?? {})}`));
|
|
410
|
+
}
|
|
411
|
+
if (resp.body?.error) {
|
|
412
|
+
const timeout = resp.body.error === 'timeout';
|
|
413
|
+
return success({ ok: false, error: resp.body.error, ...(timeout ? { answers: {} } : {}) }, timeout ? 2 : 1);
|
|
414
|
+
}
|
|
415
|
+
if (resp.body?.dryRun)
|
|
416
|
+
return success({ ok: true, dry_run: true, answers: {} });
|
|
417
|
+
return success({ ok: true, answers: resp.body?.answers ?? {} });
|
|
418
|
+
}
|
|
419
|
+
async function handleAsk(context) {
|
|
420
|
+
const questions = parseAskQuestions(context.parsed, context.options);
|
|
421
|
+
const body = buildAskBody(context.parsed, questions);
|
|
422
|
+
const port = parseInt(process.env.WEBHOOK_PORT || '3001', 10);
|
|
423
|
+
const url = `http://127.0.0.1:${port}/hook/ask-user-question`;
|
|
424
|
+
const headers = { 'x-cortex-token': process.env.CORTEX_WEBHOOK_TOKEN || '' };
|
|
425
|
+
return mapAskResponse(await context.options.askPost(url, body, headers));
|
|
426
|
+
}
|
|
427
|
+
async function dispatch(context) {
|
|
428
|
+
const command = context.parsed.command;
|
|
429
|
+
if (command === 'list') {
|
|
430
|
+
return success({ ok: true, hooks: context.hooks.map(summarizeMountedHook) });
|
|
431
|
+
}
|
|
432
|
+
if (command === 'show') {
|
|
433
|
+
return success({ ok: true, hook: showHook(findHook(context.parsed.id, context.hooks)) });
|
|
434
|
+
}
|
|
435
|
+
if (command === 'enable' || command === 'disable') {
|
|
436
|
+
return handleState(context, command === 'enable');
|
|
437
|
+
}
|
|
438
|
+
if (command === 'ask') {
|
|
439
|
+
return handleAsk(context);
|
|
440
|
+
}
|
|
441
|
+
return handleTest(context);
|
|
442
|
+
}
|
|
443
|
+
export async function runHookCli(argv, cliOptions = {}) {
|
|
444
|
+
try {
|
|
445
|
+
const parsed = parseArgs(argv);
|
|
446
|
+
if (parsed.help) {
|
|
447
|
+
const spec = parsed.command === null ? ROOT_HELP : COMMAND_HELP[parsed.command];
|
|
448
|
+
return { exitCode: 0, stdout: formatHelp(spec), stderr: '' };
|
|
449
|
+
}
|
|
450
|
+
const options = defaults(cliOptions);
|
|
451
|
+
const hooks = loadMountedHooks(options.registryDir, options.templateDir);
|
|
452
|
+
return await dispatch({ parsed, hooks, options });
|
|
453
|
+
}
|
|
454
|
+
catch (error) {
|
|
455
|
+
return failure(error instanceof Error ? error.message : String(error));
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
459
|
+
const result = await runHookCli(argv);
|
|
460
|
+
if (result.stdout)
|
|
461
|
+
process.stdout.write(`${result.stdout}\n`);
|
|
462
|
+
if (result.stderr)
|
|
463
|
+
process.stderr.write(`${result.stderr}\n`);
|
|
464
|
+
process.exitCode = result.exitCode;
|
|
465
|
+
}
|
|
466
|
+
if (isMainModule(import.meta.url)) {
|
|
467
|
+
void main();
|
|
468
|
+
}
|
package/dist/entry/init.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
// input:
|
|
2
|
-
// output: runInit
|
|
3
|
-
// pos:
|
|
4
|
-
//
|
|
5
|
-
// creates directory structure, generates .env (CORTEX_PLATFORM as a comma list),
|
|
6
|
-
// copies default configs, auto-generates mcp-config.json and mode.json
|
|
7
|
-
//
|
|
8
|
-
// INSTALL_ROOT is computed from import.meta.url (agent-server dir, 2 levels up from dist/entry/).
|
|
9
|
-
// DATA_DIR is resolved via the --home arg, $CORTEX_HOME env, or ~/.cortex/ default.
|
|
10
|
-
// Run with: node dist/entry/cli.js init [--home <path>] [--force]
|
|
1
|
+
// input: defaults, filesystem, MCP builders, platform setup
|
|
2
|
+
// output: runInit and initialization helpers
|
|
3
|
+
// pos: Initializes Cortex home and runtime configuration
|
|
4
|
+
// >>> 一旦我被更新,务必更新我的开头注释与所属文件夹 CORTEX.md <<<
|
|
11
5
|
import { mkdirSync, writeFileSync, copyFileSync, existsSync, readFileSync, readdirSync } from 'fs';
|
|
12
6
|
import { randomBytes } from 'crypto';
|
|
13
7
|
import { execSync } from 'child_process';
|
|
@@ -18,7 +12,7 @@ import { createInterface } from 'readline/promises';
|
|
|
18
12
|
import { stdin as processStdin } from 'process';
|
|
19
13
|
import * as clack from '@clack/prompts';
|
|
20
14
|
import * as yaml from 'yaml';
|
|
21
|
-
import { buildFullConfig,
|
|
15
|
+
import { buildCoreConfig, buildFullConfig, buildManagerQaConfig, buildTasksConfig, buildThreadConfig, buildTuiConfig, } from '../core/config-generator.js';
|
|
22
16
|
import { discoverEndpoints, writeMergedGatewayYaml, validateProfilesAgainstGateway } from '../core/gateway-generator.js';
|
|
23
17
|
import { generateProfiles, writeProfilesJson, listChoices } from '../core/profile-generator.js';
|
|
24
18
|
import { mergeThreadTemplates } from '../domain/threads/index.js';
|
|
@@ -1085,11 +1079,10 @@ function copyDefaults(paths, force) {
|
|
|
1085
1079
|
safeCopy(path.join(DEFAULTS_DIR, 'context', 'scans', 'CORTEX.md'), path.join(paths.CONTEXT_DIR, 'scans', 'CORTEX.md'), false, 'context/scans/CORTEX.md');
|
|
1086
1080
|
safeCopy(path.join(DEFAULTS_DIR, 'context', 'ideas', 'CORTEX.md'), path.join(paths.CONTEXT_DIR, 'ideas', 'CORTEX.md'), false, 'context/ideas/CORTEX.md');
|
|
1087
1081
|
safeCopy(path.join(DEFAULTS_DIR, 'context', 'user', 'CORTEX.md'), path.join(paths.CONTEXT_DIR, 'user', 'CORTEX.md'), false, 'context/user/CORTEX.md');
|
|
1088
|
-
// Config defaults — budget
|
|
1089
|
-
// thread-templates are merged (new agents/templates added, existing preserved)
|
|
1082
|
+
// Config defaults — budget overwrites only with --force;
|
|
1083
|
+
// thread-templates are merged per-file (new agents/templates/shells added, existing preserved)
|
|
1090
1084
|
safeCopy(path.join(DEFAULTS_DIR, 'config', 'budget.json'), path.join(paths.CONFIG_DIR, 'budget.json'), force, 'budget.json');
|
|
1091
|
-
mergeThreadTemplates(path.join(DEFAULTS_DIR, 'config', 'thread-templates
|
|
1092
|
-
safeCopy(path.join(DEFAULTS_DIR, 'config', 'session-hooks.json'), path.join(paths.CONFIG_DIR, 'session-hooks.json'), force, 'session-hooks.json');
|
|
1085
|
+
mergeThreadTemplates(path.join(DEFAULTS_DIR, 'config', 'thread-templates'), path.join(paths.CONFIG_DIR, 'thread-templates'));
|
|
1093
1086
|
// Seed asset trees — per-file safeCopy semantics: new files always added, existing files
|
|
1094
1087
|
// preserved unless force=true. These directories are referenced at runtime; without them
|
|
1095
1088
|
// thread-manager / skill-scanner / rules-loader can't find their inputs.
|
|
@@ -1117,11 +1110,22 @@ function deployHooks(paths, force) {
|
|
|
1117
1110
|
safeCopy(src, dst, force, `hooks/${file}`);
|
|
1118
1111
|
}
|
|
1119
1112
|
}
|
|
1113
|
+
function writeMcpConfigs(configDir) {
|
|
1114
|
+
const configs = [
|
|
1115
|
+
['mcp-config.json', buildFullConfig(INSTALL_ROOT)],
|
|
1116
|
+
['mcp-config-core.json', buildCoreConfig(INSTALL_ROOT)],
|
|
1117
|
+
['mcp-config-tasks.json', buildTasksConfig(INSTALL_ROOT)],
|
|
1118
|
+
['mcp-config-manager-qa.json', buildManagerQaConfig(INSTALL_ROOT)],
|
|
1119
|
+
['mcp-config-thread.json', buildThreadConfig(INSTALL_ROOT)],
|
|
1120
|
+
['mcp-config-tui.json', buildTuiConfig(INSTALL_ROOT)],
|
|
1121
|
+
];
|
|
1122
|
+
for (const [fileName, config] of configs) {
|
|
1123
|
+
writeFileSync(path.join(configDir, fileName), JSON.stringify(config, null, 2));
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1120
1126
|
export function generateConfigs(paths, answers, force) {
|
|
1121
1127
|
// MCP configs — always regenerate (machine-specific, in .gitignore)
|
|
1122
|
-
|
|
1123
|
-
writeFileSync(path.join(paths.CONFIG_DIR, 'mcp-config-core.json'), JSON.stringify(buildCoreConfig(INSTALL_ROOT), null, 2));
|
|
1124
|
-
writeFileSync(path.join(paths.CONFIG_DIR, 'mcp-config-tui.json'), JSON.stringify(buildTuiConfig(INSTALL_ROOT), null, 2));
|
|
1128
|
+
writeMcpConfigs(paths.CONFIG_DIR);
|
|
1125
1129
|
// mode.json — skip if exists (user may have customized)
|
|
1126
1130
|
const modeJsonPath = path.join(paths.STORE_DIR, 'mode.json');
|
|
1127
1131
|
if (!existsSync(modeJsonPath) || force) {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { UiHttpServer } from '../platform/ui-http/ui-http-server.js';
|
|
2
|
+
import type { AccessJwtVerifier } from '../platform/ui-http/access-jwt.js';
|
|
3
|
+
import type { UiService } from '../domain/ui-service/types.js';
|
|
4
|
+
export interface StartUiHttpOptions {
|
|
5
|
+
/** The composed UiService (real domain-backed instance in production; a fake in tests). */
|
|
6
|
+
uiService: UiService;
|
|
7
|
+
/** Token accessor the server accepts. Defaults to getClientToken (the shared secret clients carry). */
|
|
8
|
+
getToken?: () => string;
|
|
9
|
+
/** Env to read the gate/port from. Defaults to process.env (injectable for tests). */
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
/**
|
|
12
|
+
* Directory of the built SPA to serve for non-tRPC paths. When omitted, resolved from
|
|
13
|
+
* CORTEX_UI_SPA_DIR else the monorepo web/dist. Absent/missing on disk → 404 stub.
|
|
14
|
+
*/
|
|
15
|
+
spaDir?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Explicit CORS allow-list forwarded to the transport-host. When omitted, the list is parsed
|
|
18
|
+
* from the CORTEX_UI_CORS_ORIGINS env var (comma-separated; entries trimmed, empties dropped).
|
|
19
|
+
* Env-driven so the running-server path (agent-server) can enable CORS for the Tauri desktop
|
|
20
|
+
* webview (e.g. tauri://localhost) with no code change — just the env var. Absent/empty → no
|
|
21
|
+
* CORS headers.
|
|
22
|
+
*/
|
|
23
|
+
corsOrigins?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Explicit Cloudflare Access JWT verifier forwarded to the transport-host (the browser auth path).
|
|
26
|
+
* When omitted, it is built from env via accessVerifierFromEnv (CORTEX_ACCESS_TEAM_DOMAIN +
|
|
27
|
+
* CORTEX_ACCESS_AUD, optional CORTEX_ACCESS_CERTS_URL). When those are unset the verifier is
|
|
28
|
+
* undefined and the gate degrades to token-only. Injectable for tests.
|
|
29
|
+
*/
|
|
30
|
+
verifyAccessJwt?: AccessJwtVerifier;
|
|
31
|
+
}
|
|
32
|
+
/** Resolve a UI-relative `workspace/…` path to an absolute path strictly inside WORKSPACE_DIR.
|
|
33
|
+
* Thin wrapper over the shared `resolveWorkspaceRelPath` (core/paths) so the download route and the
|
|
34
|
+
* agent-runner attachment mapping resolve the `workspace/` alias identically. Returns null when the
|
|
35
|
+
* prefix is wrong or the resolved target escapes the workspace root. Exported for the traversal-guard
|
|
36
|
+
* unit test. */
|
|
37
|
+
export declare function resolveWorkspacePath(rel: string): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Build the AppRouter from the injected UiService and start the Web UI HTTP+SSE transport-host
|
|
40
|
+
* on CORTEX_UI_PORT (default 3004), bound 127.0.0.1, behind the x-cortex-token gate, serving the
|
|
41
|
+
* built SPA same-origin. Returns the running server handle, or null when the CORTEX_UI_HTTP env
|
|
42
|
+
* gate is off (clean skip). The caller owns the handle and must call close() on shutdown.
|
|
43
|
+
*/
|
|
44
|
+
export declare function startUiHttpServer(opts: StartUiHttpOptions): UiHttpServer | null;
|