@cortex-agent/server 2026.5.19-1
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/defaults/.claude/settings.json +13 -0
- package/defaults/CORTEX.md +15 -0
- package/defaults/config/budget.json +4 -0
- package/defaults/config/session-hooks.json +7 -0
- package/defaults/config/thread-templates.json +528 -0
- package/defaults/context/CORTEX.md +40 -0
- package/defaults/context/decisions/DR-0012.md +54 -0
- package/defaults/context/ideas/CORTEX.md +10 -0
- package/defaults/context/projects/CORTEX.md +25 -0
- package/defaults/context/scans/CORTEX.md +13 -0
- package/defaults/context/user/CORTEX.md +21 -0
- package/defaults/data/schedules.json +52 -0
- package/defaults/gitignore +44 -0
- package/defaults/hooks/ask-user-question-hook.mjs +66 -0
- package/defaults/hooks/cortex-md-injector.mjs +237 -0
- package/defaults/hooks/exit-plan-mode-hook.mjs +84 -0
- package/defaults/hooks/memory-ref-tracker.mjs +154 -0
- package/defaults/hooks/new-session-hook.mjs +83 -0
- package/defaults/hooks/post-task-hook.mjs +63 -0
- package/defaults/hooks/rules-loader.mjs +212 -0
- package/defaults/hooks/sensitive-file-edit.mjs +84 -0
- package/defaults/hooks/session-activity-tracker.mjs +254 -0
- package/defaults/hooks/task-status-check.mjs +218 -0
- package/defaults/hooks/tasks-yaml-guard.mjs +230 -0
- package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +5 -0
- package/defaults/plugins/cortex-coder/skills/cli-standards/SKILL.md +208 -0
- package/defaults/plugins/cortex-coder/skills/code-standards/SKILL.md +146 -0
- package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +164 -0
- package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +5 -0
- package/defaults/plugins/cortex-common/skills/compound/SKILL.md +349 -0
- package/defaults/plugins/cortex-common/skills/compound-simple/SKILL.md +104 -0
- package/defaults/plugins/cortex-common/skills/critique/SKILL.md +88 -0
- package/defaults/plugins/cortex-common/skills/debug-campaign/SKILL.md +508 -0
- package/defaults/plugins/cortex-common/skills/diagnose/SKILL.md +169 -0
- package/defaults/plugins/cortex-common/skills/postmortem/SKILL.md +135 -0
- package/defaults/plugins/cortex-common/skills/solution-design/SKILL.md +183 -0
- package/defaults/plugins/cortex-common/skills/synthesize/SKILL.md +120 -0
- package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +5 -0
- package/defaults/plugins/cortex-stage-gate/skills/need-approval/SKILL.md +89 -0
- package/defaults/plugins/cortex-stage-gate/skills/reorient/SKILL.md +163 -0
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +425 -0
- package/defaults/plugins/cortex-system/.claude-plugin/plugin.json +5 -0
- package/defaults/plugins/cortex-system/skills/approval/SKILL.md +84 -0
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +199 -0
- package/defaults/plugins/cortex-system/skills/deep-retrospective/CORTEX.md +8 -0
- package/defaults/plugins/cortex-system/skills/deep-retrospective/SKILL.md +201 -0
- package/defaults/plugins/cortex-system/skills/deep-retrospective/scripts/CORTEX.md +8 -0
- package/defaults/plugins/cortex-system/skills/deep-retrospective/scripts/extract_session.py +165 -0
- package/defaults/plugins/cortex-system/skills/deep-retrospective/scripts/scan_logs.py +402 -0
- package/defaults/plugins/cortex-system/skills/evolve/SKILL.md +115 -0
- package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +262 -0
- package/defaults/plugins/cortex-system/skills/gravity/SKILL.md +125 -0
- package/defaults/plugins/cortex-system/skills/orient/SKILL.md +310 -0
- package/defaults/plugins/cortex-system/skills/orient-project/SKILL.md +85 -0
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +167 -0
- package/defaults/plugins/cortex-system/skills/refresh-skills/SKILL.md +153 -0
- package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +209 -0
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +478 -0
- package/defaults/plugins/cortex-system/skills/user-learn/SKILL.md +95 -0
- package/defaults/prompts/directives/coder-reviewer.md +106 -0
- package/defaults/prompts/directives/coder.md +90 -0
- package/defaults/prompts/directives/director.md +97 -0
- package/defaults/prompts/directives/doc-reviewer.md +93 -0
- package/defaults/prompts/directives/doc-writer.md +85 -0
- package/defaults/prompts/directives/executor-reviewer.md +96 -0
- package/defaults/prompts/directives/executor.md +85 -0
- package/defaults/prompts/directives/milestone-executor.md +119 -0
- package/defaults/prompts/directives/milestone-reviewer.md +108 -0
- package/defaults/prompts/directives/plan-executor.md +121 -0
- package/defaults/prompts/directives/plan-reviewer.md +99 -0
- package/defaults/prompts/systemPrompts/coder.md +64 -0
- package/defaults/prompts/systemPrompts/direct.md +92 -0
- package/defaults/prompts/systemPrompts/web-opus-4-6.md +68 -0
- package/defaults/prompts/systemPrompts/web-sonnet-4-6.md +76 -0
- package/defaults/prompts/systemPrompts/web.md +50 -0
- package/defaults/prompts/systemPrompts/worker.md +67 -0
- package/defaults/rules/correction-propagation.md +31 -0
- package/defaults/rules/decision-records.md +49 -0
- package/defaults/rules/experiment-format.md +165 -0
- package/defaults/rules/issues-md.md +37 -0
- package/defaults/rules/meta-conventions.md +45 -0
- package/defaults/rules/mission-md.md +47 -0
- package/defaults/rules/overview-md.md +41 -0
- package/defaults/rules/roadmap-md.md +55 -0
- package/defaults/rules/status-md.md +49 -0
- package/defaults/rules/task-system.md +53 -0
- package/dist/agent-adapter/capabilities.d.ts +12 -0
- package/dist/agent-adapter/capabilities.js +52 -0
- package/dist/agent-adapter/claude/adapter-tui.d.ts +140 -0
- package/dist/agent-adapter/claude/adapter-tui.js +422 -0
- package/dist/agent-adapter/claude/adapter.d.ts +85 -0
- package/dist/agent-adapter/claude/adapter.js +771 -0
- package/dist/agent-adapter/claude/cost-from-usage.d.ts +62 -0
- package/dist/agent-adapter/claude/cost-from-usage.js +97 -0
- package/dist/agent-adapter/claude/defaults.d.ts +30 -0
- package/dist/agent-adapter/claude/defaults.js +49 -0
- package/dist/agent-adapter/claude/event-parser.d.ts +28 -0
- package/dist/agent-adapter/claude/event-parser.js +173 -0
- package/dist/agent-adapter/claude/hooks-builder.d.ts +36 -0
- package/dist/agent-adapter/claude/hooks-builder.js +57 -0
- package/dist/agent-adapter/claude/jsonl-tail.d.ts +68 -0
- package/dist/agent-adapter/claude/jsonl-tail.js +344 -0
- package/dist/agent-adapter/claude/spawn-args.d.ts +38 -0
- package/dist/agent-adapter/claude/spawn-args.js +83 -0
- package/dist/agent-adapter/claude/tmux-control.d.ts +69 -0
- package/dist/agent-adapter/claude/tmux-control.js +127 -0
- package/dist/agent-adapter/claude/tool-summarizers.d.ts +2 -0
- package/dist/agent-adapter/claude/tool-summarizers.js +24 -0
- package/dist/agent-adapter/codex/adapter.d.ts +42 -0
- package/dist/agent-adapter/codex/adapter.js +916 -0
- package/dist/agent-adapter/codex/event-parser.d.ts +17 -0
- package/dist/agent-adapter/codex/event-parser.js +41 -0
- package/dist/agent-adapter/codex/spawn-args.d.ts +6 -0
- package/dist/agent-adapter/codex/spawn-args.js +30 -0
- package/dist/agent-adapter/index.d.ts +8 -0
- package/dist/agent-adapter/index.js +33 -0
- package/dist/agent-adapter/normalize/event-stream.d.ts +6 -0
- package/dist/agent-adapter/normalize/event-stream.js +47 -0
- package/dist/agent-adapter/normalize/event-types.d.ts +58 -0
- package/dist/agent-adapter/normalize/event-types.js +5 -0
- package/dist/agent-adapter/normalize/hooks.d.ts +26 -0
- package/dist/agent-adapter/normalize/hooks.js +5 -0
- package/dist/agent-adapter/normalize/prompt-builder.d.ts +6 -0
- package/dist/agent-adapter/normalize/prompt-builder.js +23 -0
- package/dist/agent-adapter/normalize/tool-names.d.ts +6 -0
- package/dist/agent-adapter/normalize/tool-names.js +73 -0
- package/dist/agent-adapter/pi/adapter.d.ts +60 -0
- package/dist/agent-adapter/pi/adapter.js +626 -0
- package/dist/agent-adapter/pi/agent-dir.d.ts +11 -0
- package/dist/agent-adapter/pi/agent-dir.js +34 -0
- package/dist/agent-adapter/pi/event-parser.d.ts +26 -0
- package/dist/agent-adapter/pi/event-parser.js +313 -0
- package/dist/agent-adapter/pi/framing.d.ts +6 -0
- package/dist/agent-adapter/pi/framing.js +35 -0
- package/dist/agent-adapter/pi/hook-bridge.d.ts +59 -0
- package/dist/agent-adapter/pi/hook-bridge.js +233 -0
- package/dist/agent-adapter/pi/mcp-bridge.d.ts +26 -0
- package/dist/agent-adapter/pi/mcp-bridge.js +140 -0
- package/dist/agent-adapter/pi/pi-ext-types.d.ts +90 -0
- package/dist/agent-adapter/pi/pi-ext-types.js +5 -0
- package/dist/agent-adapter/pi/spawn-args.d.ts +20 -0
- package/dist/agent-adapter/pi/spawn-args.js +54 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +2 -0
- package/dist/agent-adapter/pi/tool-shims.js +181 -0
- package/dist/agent-adapter/types.d.ts +94 -0
- package/dist/agent-adapter/types.js +5 -0
- package/dist/core/async-mutex.d.ts +6 -0
- package/dist/core/async-mutex.js +36 -0
- package/dist/core/cli-utils.d.ts +37 -0
- package/dist/core/cli-utils.js +69 -0
- package/dist/core/config-generator.d.ts +9 -0
- package/dist/core/config-generator.js +58 -0
- package/dist/core/gateway-generator.d.ts +46 -0
- package/dist/core/gateway-generator.js +336 -0
- package/dist/core/log.d.ts +7 -0
- package/dist/core/log.js +103 -0
- package/dist/core/paths.d.ts +32 -0
- package/dist/core/paths.js +49 -0
- package/dist/core/profile-generator.d.ts +65 -0
- package/dist/core/profile-generator.js +310 -0
- package/dist/core/running-executions.d.ts +88 -0
- package/dist/core/running-executions.js +186 -0
- package/dist/core/status-format.d.ts +18 -0
- package/dist/core/status-format.js +31 -0
- package/dist/core/task-parser.d.ts +69 -0
- package/dist/core/task-parser.js +423 -0
- package/dist/core/types/agent-types.d.ts +31 -0
- package/dist/core/types/agent-types.js +5 -0
- package/dist/core/types/thread-types.d.ts +261 -0
- package/dist/core/types/thread-types.js +5 -0
- package/dist/core/utils.d.ts +29 -0
- package/dist/core/utils.js +98 -0
- package/dist/core/version.d.ts +3 -0
- package/dist/core/version.js +12 -0
- package/dist/domain/agents/config.d.ts +58 -0
- package/dist/domain/agents/config.js +313 -0
- package/dist/domain/agents/facade.d.ts +52 -0
- package/dist/domain/agents/facade.js +264 -0
- package/dist/domain/agents/index.d.ts +2 -0
- package/dist/domain/agents/index.js +4 -0
- package/dist/domain/agents/profile-manager.d.ts +54 -0
- package/dist/domain/agents/profile-manager.js +161 -0
- package/dist/domain/costs/codex-event-format.d.ts +4 -0
- package/dist/domain/costs/codex-event-format.js +66 -0
- package/dist/domain/costs/codex-usage-monitor.d.ts +7 -0
- package/dist/domain/costs/codex-usage-monitor.js +72 -0
- package/dist/domain/costs/cost-tracker.d.ts +115 -0
- package/dist/domain/costs/cost-tracker.js +327 -0
- package/dist/domain/costs/gateway-manager.d.ts +6 -0
- package/dist/domain/costs/gateway-manager.js +228 -0
- package/dist/domain/costs/rate-limit-parser.d.ts +11 -0
- package/dist/domain/costs/rate-limit-parser.js +87 -0
- package/dist/domain/costs/rate-limit-throttle.d.ts +32 -0
- package/dist/domain/costs/rate-limit-throttle.js +129 -0
- package/dist/domain/executions/registry.d.ts +20 -0
- package/dist/domain/executions/registry.js +124 -0
- package/dist/domain/mcp/core-server.d.ts +2 -0
- package/dist/domain/mcp/core-server.js +34 -0
- package/dist/domain/mcp/server.d.ts +3 -0
- package/dist/domain/mcp/server.js +78 -0
- package/dist/domain/mcp/tools/context.d.ts +23 -0
- package/dist/domain/mcp/tools/context.js +51 -0
- package/dist/domain/mcp/tools/cortex-md.d.ts +17 -0
- package/dist/domain/mcp/tools/cortex-md.js +36 -0
- package/dist/domain/mcp/tools/cost.d.ts +2 -0
- package/dist/domain/mcp/tools/cost.js +54 -0
- package/dist/domain/mcp/tools/executions.d.ts +2 -0
- package/dist/domain/mcp/tools/executions.js +94 -0
- package/dist/domain/mcp/tools/schedule.d.ts +23 -0
- package/dist/domain/mcp/tools/schedule.js +245 -0
- package/dist/domain/mcp/tools/slack.d.ts +21 -0
- package/dist/domain/mcp/tools/slack.js +124 -0
- package/dist/domain/mcp/tools/task-ops.d.ts +2 -0
- package/dist/domain/mcp/tools/task-ops.js +509 -0
- package/dist/domain/mcp/tools/tui-ask.d.ts +31 -0
- package/dist/domain/mcp/tools/tui-ask.js +108 -0
- package/dist/domain/mcp/tools/tui-plan.d.ts +28 -0
- package/dist/domain/mcp/tools/tui-plan.js +118 -0
- package/dist/domain/mcp/tui-server.d.ts +2 -0
- package/dist/domain/mcp/tui-server.js +69 -0
- package/dist/domain/memory/consolidate.d.ts +55 -0
- package/dist/domain/memory/consolidate.js +471 -0
- package/dist/domain/memory/cortex-md-injector.d.ts +30 -0
- package/dist/domain/memory/cortex-md-injector.js +123 -0
- package/dist/domain/memory/cortex-md-scanner.d.ts +9 -0
- package/dist/domain/memory/cortex-md-scanner.js +67 -0
- package/dist/domain/memory/index-regen.d.ts +19 -0
- package/dist/domain/memory/index-regen.js +398 -0
- package/dist/domain/memory/rules-loader.d.ts +27 -0
- package/dist/domain/memory/rules-loader.js +97 -0
- package/dist/domain/memory/skill-scanner.d.ts +5 -0
- package/dist/domain/memory/skill-scanner.js +132 -0
- package/dist/domain/memory/user-context.d.ts +5 -0
- package/dist/domain/memory/user-context.js +34 -0
- package/dist/domain/memory/watcher.d.ts +2 -0
- package/dist/domain/memory/watcher.js +81 -0
- package/dist/domain/monitor/disk-monitor.d.ts +20 -0
- package/dist/domain/monitor/disk-monitor.js +97 -0
- package/dist/domain/monitor/gpu-monitor.d.ts +26 -0
- package/dist/domain/monitor/gpu-monitor.js +135 -0
- package/dist/domain/remote/client-bootstrap.d.ts +1 -0
- package/dist/domain/remote/client-bootstrap.js +139 -0
- package/dist/domain/remote/client-hot-reload.d.ts +18 -0
- package/dist/domain/remote/client-hot-reload.js +142 -0
- package/dist/domain/remote/client-manager.d.ts +50 -0
- package/dist/domain/remote/client-manager.js +452 -0
- package/dist/domain/remote/cortex-client.d.ts +1 -0
- package/dist/domain/remote/cortex-client.js +704 -0
- package/dist/domain/scheduling/job-registry.d.ts +31 -0
- package/dist/domain/scheduling/job-registry.js +34 -0
- package/dist/domain/scheduling/jobs/_shared.d.ts +14 -0
- package/dist/domain/scheduling/jobs/_shared.js +45 -0
- package/dist/domain/scheduling/jobs/memory-index-regen.d.ts +1 -0
- package/dist/domain/scheduling/jobs/memory-index-regen.js +16 -0
- package/dist/domain/scheduling/jobs/scheduled-task.d.ts +11 -0
- package/dist/domain/scheduling/jobs/scheduled-task.js +186 -0
- package/dist/domain/scheduling/jobs/target-dispatch.d.ts +41 -0
- package/dist/domain/scheduling/jobs/target-dispatch.js +48 -0
- package/dist/domain/scheduling/jobs/task-archive.d.ts +1 -0
- package/dist/domain/scheduling/jobs/task-archive.js +19 -0
- package/dist/domain/scheduling/jobs/task-dispatch.d.ts +12 -0
- package/dist/domain/scheduling/jobs/task-dispatch.js +214 -0
- package/dist/domain/scheduling/runner.d.ts +13 -0
- package/dist/domain/scheduling/runner.js +24 -0
- package/dist/domain/scheduling/schedule-cli.d.ts +16 -0
- package/dist/domain/scheduling/schedule-cli.js +268 -0
- package/dist/domain/scheduling/schedule-command.d.ts +4 -0
- package/dist/domain/scheduling/schedule-command.js +274 -0
- package/dist/domain/scheduling/scheduler.d.ts +86 -0
- package/dist/domain/scheduling/scheduler.js +544 -0
- package/dist/domain/sessions/session-backup.d.ts +49 -0
- package/dist/domain/sessions/session-backup.js +217 -0
- package/dist/domain/sessions/session-hooks.d.ts +103 -0
- package/dist/domain/sessions/session-hooks.js +311 -0
- package/dist/domain/sessions/session-registry.d.ts +21 -0
- package/dist/domain/sessions/session-registry.js +31 -0
- package/dist/domain/sessions/session.d.ts +3 -0
- package/dist/domain/sessions/session.js +14 -0
- package/dist/domain/tasks/archiver.d.ts +9 -0
- package/dist/domain/tasks/archiver.js +123 -0
- package/dist/domain/tasks/dispatch-utils.d.ts +37 -0
- package/dist/domain/tasks/dispatch-utils.js +143 -0
- package/dist/domain/tasks/dispatcher.d.ts +48 -0
- package/dist/domain/tasks/dispatcher.js +285 -0
- package/dist/domain/tasks/lint.d.ts +12 -0
- package/dist/domain/tasks/lint.js +102 -0
- package/dist/domain/tasks/mutator.d.ts +21 -0
- package/dist/domain/tasks/mutator.js +208 -0
- package/dist/domain/tasks/parser.d.ts +1 -0
- package/dist/domain/tasks/parser.js +6 -0
- package/dist/domain/tasks/pending-tracker.d.ts +67 -0
- package/dist/domain/tasks/pending-tracker.js +163 -0
- package/dist/domain/tasks/recommendation/extractor.d.ts +12 -0
- package/dist/domain/tasks/recommendation/extractor.js +563 -0
- package/dist/domain/tasks/recommendation/patterns.d.ts +11 -0
- package/dist/domain/tasks/recommendation/patterns.js +99 -0
- package/dist/domain/tasks/recommendation/types.d.ts +67 -0
- package/dist/domain/tasks/recommendation/types.js +5 -0
- package/dist/domain/tasks/store.d.ts +1 -0
- package/dist/domain/tasks/store.js +3 -0
- package/dist/domain/tasks/system/cortex-run.d.ts +24 -0
- package/dist/domain/tasks/system/cortex-run.js +342 -0
- package/dist/domain/tasks/system/task-cli.d.ts +49 -0
- package/dist/domain/tasks/system/task-cli.js +664 -0
- package/dist/domain/tasks/system/task-completion.d.ts +22 -0
- package/dist/domain/tasks/system/task-completion.js +89 -0
- package/dist/domain/tasks/system/task-id-utils.d.ts +24 -0
- package/dist/domain/tasks/system/task-id-utils.js +84 -0
- package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +34 -0
- package/dist/domain/tasks/system/task-lifecycle-edit.js +208 -0
- package/dist/domain/tasks/system/task-lock.d.ts +25 -0
- package/dist/domain/tasks/system/task-lock.js +139 -0
- package/dist/domain/tasks/system/task-mutations.d.ts +31 -0
- package/dist/domain/tasks/system/task-mutations.js +110 -0
- package/dist/domain/tasks/system/task-process.d.ts +37 -0
- package/dist/domain/tasks/system/task-process.js +119 -0
- package/dist/domain/tasks/system/task-state.d.ts +70 -0
- package/dist/domain/tasks/system/task-state.js +176 -0
- package/dist/domain/threads/artifact-io.d.ts +18 -0
- package/dist/domain/threads/artifact-io.js +182 -0
- package/dist/domain/threads/auto-thread.d.ts +3 -0
- package/dist/domain/threads/auto-thread.js +19 -0
- package/dist/domain/threads/hook-runner.d.ts +4 -0
- package/dist/domain/threads/hook-runner.js +250 -0
- package/dist/domain/threads/index.d.ts +5 -0
- package/dist/domain/threads/index.js +7 -0
- package/dist/domain/threads/prompt-builder.d.ts +25 -0
- package/dist/domain/threads/prompt-builder.js +176 -0
- package/dist/domain/threads/runner.d.ts +83 -0
- package/dist/domain/threads/runner.js +434 -0
- package/dist/domain/threads/state-machine.d.ts +61 -0
- package/dist/domain/threads/state-machine.js +440 -0
- package/dist/domain/threads/template-loader.d.ts +20 -0
- package/dist/domain/threads/template-loader.js +189 -0
- package/dist/domain/threads/template-resolver.d.ts +1 -0
- package/dist/domain/threads/template-resolver.js +95 -0
- package/dist/domain/threads/utils.d.ts +19 -0
- package/dist/domain/threads/utils.js +49 -0
- package/dist/entry/app.d.ts +1 -0
- package/dist/entry/app.js +234 -0
- package/dist/entry/cli.d.ts +12 -0
- package/dist/entry/cli.js +254 -0
- package/dist/entry/daemon.d.ts +11 -0
- package/dist/entry/daemon.js +521 -0
- package/dist/entry/init.d.ts +93 -0
- package/dist/entry/init.js +1299 -0
- package/dist/entry/startup-helpers.d.ts +2 -0
- package/dist/entry/startup-helpers.js +56 -0
- package/dist/entry/startup-notify.d.ts +10 -0
- package/dist/entry/startup-notify.js +20 -0
- package/dist/events/event-bus.d.ts +42 -0
- package/dist/events/event-bus.js +84 -0
- package/dist/events/event-logger.d.ts +12 -0
- package/dist/events/event-logger.js +135 -0
- package/dist/events/event-replay.d.ts +1 -0
- package/dist/events/event-replay.js +51 -0
- package/dist/events/event-types.d.ts +145 -0
- package/dist/events/event-types.js +5 -0
- package/dist/events/index.d.ts +5 -0
- package/dist/events/index.js +6 -0
- package/dist/hooks/ask-user-question-hook.mjs +66 -0
- package/dist/hooks/cortex-md-injector.mjs +237 -0
- package/dist/hooks/exit-plan-mode-hook.mjs +84 -0
- package/dist/hooks/memory-ref-tracker.mjs +154 -0
- package/dist/hooks/new-session-hook.mjs +83 -0
- package/dist/hooks/post-task-hook.mjs +63 -0
- package/dist/hooks/rules-loader.mjs +212 -0
- package/dist/hooks/sensitive-file-edit.mjs +84 -0
- package/dist/hooks/session-activity-tracker.mjs +254 -0
- package/dist/hooks/task-status-check.mjs +218 -0
- package/dist/hooks/tasks-yaml-guard.mjs +230 -0
- package/dist/orchestration/agent-runner.d.ts +72 -0
- package/dist/orchestration/agent-runner.js +289 -0
- package/dist/orchestration/busy-tracker.d.ts +12 -0
- package/dist/orchestration/busy-tracker.js +35 -0
- package/dist/orchestration/channel-queue.d.ts +18 -0
- package/dist/orchestration/channel-queue.js +32 -0
- package/dist/orchestration/dispatch-reconciler.d.ts +1 -0
- package/dist/orchestration/dispatch-reconciler.js +16 -0
- package/dist/orchestration/durable-helpers.d.ts +4 -0
- package/dist/orchestration/durable-helpers.js +42 -0
- package/dist/orchestration/interactions/ask-user-question.d.ts +32 -0
- package/dist/orchestration/interactions/ask-user-question.js +182 -0
- package/dist/orchestration/interactions/command-action-router.d.ts +47 -0
- package/dist/orchestration/interactions/command-action-router.js +91 -0
- package/dist/orchestration/interactions/interaction-handlers.d.ts +5 -0
- package/dist/orchestration/interactions/interaction-handlers.js +279 -0
- package/dist/orchestration/interactions/plan-approvals.d.ts +47 -0
- package/dist/orchestration/interactions/plan-approvals.js +77 -0
- package/dist/orchestration/interactions/plan-handler.d.ts +6 -0
- package/dist/orchestration/interactions/plan-handler.js +12 -0
- package/dist/orchestration/lifecycle.d.ts +50 -0
- package/dist/orchestration/lifecycle.js +308 -0
- package/dist/orchestration/orchestrator.d.ts +29 -0
- package/dist/orchestration/orchestrator.js +25 -0
- package/dist/orchestration/routing/commands/cancel.d.ts +10 -0
- package/dist/orchestration/routing/commands/cancel.js +136 -0
- package/dist/orchestration/routing/commands/channel.d.ts +11 -0
- package/dist/orchestration/routing/commands/channel.js +219 -0
- package/dist/orchestration/routing/commands/command-context.d.ts +29 -0
- package/dist/orchestration/routing/commands/command-context.js +4 -0
- package/dist/orchestration/routing/commands/cost.d.ts +3 -0
- package/dist/orchestration/routing/commands/cost.js +22 -0
- package/dist/orchestration/routing/commands/device.d.ts +6 -0
- package/dist/orchestration/routing/commands/device.js +83 -0
- package/dist/orchestration/routing/commands/dispatch.d.ts +2 -0
- package/dist/orchestration/routing/commands/dispatch.js +49 -0
- package/dist/orchestration/routing/commands/index.d.ts +15 -0
- package/dist/orchestration/routing/commands/index.js +130 -0
- package/dist/orchestration/routing/commands/mode.d.ts +13 -0
- package/dist/orchestration/routing/commands/mode.js +290 -0
- package/dist/orchestration/routing/commands/nvtop.d.ts +3 -0
- package/dist/orchestration/routing/commands/nvtop.js +103 -0
- package/dist/orchestration/routing/commands/orient.d.ts +2 -0
- package/dist/orchestration/routing/commands/orient.js +3 -0
- package/dist/orchestration/routing/commands/schedule.d.ts +4 -0
- package/dist/orchestration/routing/commands/schedule.js +132 -0
- package/dist/orchestration/routing/commands/sendfile.d.ts +2 -0
- package/dist/orchestration/routing/commands/sendfile.js +92 -0
- package/dist/orchestration/routing/commands/session.d.ts +9 -0
- package/dist/orchestration/routing/commands/session.js +153 -0
- package/dist/orchestration/routing/commands/status.d.ts +7 -0
- package/dist/orchestration/routing/commands/status.js +180 -0
- package/dist/orchestration/routing/commands/tail.d.ts +2 -0
- package/dist/orchestration/routing/commands/tail.js +73 -0
- package/dist/orchestration/routing/commands/task.d.ts +6 -0
- package/dist/orchestration/routing/commands/task.js +142 -0
- package/dist/orchestration/routing/commands/thread-handlers.d.ts +2 -0
- package/dist/orchestration/routing/commands/thread-handlers.js +138 -0
- package/dist/orchestration/routing/commands/thread.d.ts +2 -0
- package/dist/orchestration/routing/commands/thread.js +2 -0
- package/dist/orchestration/routing/edit-handler.d.ts +24 -0
- package/dist/orchestration/routing/edit-handler.js +161 -0
- package/dist/orchestration/routing/file-handler.d.ts +6 -0
- package/dist/orchestration/routing/file-handler.js +23 -0
- package/dist/orchestration/routing/hook-bridge-subscribers.d.ts +4 -0
- package/dist/orchestration/routing/hook-bridge-subscribers.js +79 -0
- package/dist/orchestration/routing/hook-bridge.d.ts +30 -0
- package/dist/orchestration/routing/hook-bridge.js +112 -0
- package/dist/orchestration/routing/message-router.d.ts +6 -0
- package/dist/orchestration/routing/message-router.js +70 -0
- package/dist/orchestration/routing/webhook.d.ts +10 -0
- package/dist/orchestration/routing/webhook.js +239 -0
- package/dist/orchestration/status-helpers.d.ts +66 -0
- package/dist/orchestration/status-helpers.js +222 -0
- package/dist/orchestration/superseded-edits.d.ts +22 -0
- package/dist/orchestration/superseded-edits.js +31 -0
- package/dist/orchestration/thread-executor.d.ts +31 -0
- package/dist/orchestration/thread-executor.js +234 -0
- package/dist/platform/adapter.d.ts +28 -0
- package/dist/platform/adapter.js +5 -0
- package/dist/platform/adapters/feishu.d.ts +66 -0
- package/dist/platform/adapters/feishu.js +558 -0
- package/dist/platform/adapters/index.d.ts +16 -0
- package/dist/platform/adapters/index.js +65 -0
- package/dist/platform/adapters/slack.d.ts +90 -0
- package/dist/platform/adapters/slack.js +630 -0
- package/dist/platform/index.d.ts +12 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/interactive-builder.d.ts +27 -0
- package/dist/platform/interactive-builder.js +120 -0
- package/dist/platform/testing.d.ts +100 -0
- package/dist/platform/testing.js +190 -0
- package/dist/platform/tool-trace.d.ts +33 -0
- package/dist/platform/tool-trace.js +165 -0
- package/dist/platform/types.d.ts +176 -0
- package/dist/platform/types.js +5 -0
- package/dist/platform/utils/rate-limiter.d.ts +92 -0
- package/dist/platform/utils/rate-limiter.js +213 -0
- package/dist/platform/virtual-message.d.ts +68 -0
- package/dist/platform/virtual-message.js +464 -0
- package/dist/store/atomic-write.d.ts +6 -0
- package/dist/store/atomic-write.js +18 -0
- package/dist/store/channel-repo.d.ts +21 -0
- package/dist/store/channel-repo.js +55 -0
- package/dist/store/conversation-ledger-repo.d.ts +86 -0
- package/dist/store/conversation-ledger-repo.js +220 -0
- package/dist/store/cost-repo.d.ts +57 -0
- package/dist/store/cost-repo.js +135 -0
- package/dist/store/execution-repo.d.ts +172 -0
- package/dist/store/execution-repo.js +343 -0
- package/dist/store/in-memory-repository.d.ts +14 -0
- package/dist/store/in-memory-repository.js +31 -0
- package/dist/store/json-repository.d.ts +51 -0
- package/dist/store/json-repository.js +118 -0
- package/dist/store/outbound-queue.d.ts +65 -0
- package/dist/store/outbound-queue.js +269 -0
- package/dist/store/profile-repo.d.ts +36 -0
- package/dist/store/profile-repo.js +144 -0
- package/dist/store/project-dir-repo.d.ts +22 -0
- package/dist/store/project-dir-repo.js +60 -0
- package/dist/store/schedule-repo.d.ts +92 -0
- package/dist/store/schedule-repo.js +88 -0
- package/dist/store/session-registry-repo.d.ts +38 -0
- package/dist/store/session-registry-repo.js +96 -0
- package/dist/store/session-repo.d.ts +14 -0
- package/dist/store/session-repo.js +56 -0
- package/dist/store/task-repo.d.ts +41 -0
- package/dist/store/task-repo.js +137 -0
- package/dist/store/thread-repo.d.ts +50 -0
- package/dist/store/thread-repo.js +190 -0
- package/package.json +58 -0
- package/scripts/postinstall-restart-trigger.mjs +39 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// input: rate_limit_event + persistence + slack client
|
|
2
|
+
// output: init/handleRateLimitEvent/isThrottled/isModeRateLimited/getThrottleState
|
|
3
|
+
// pos: Pure state tracker — no scheduler coupling. Mode-level rate limit tracking.
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { createLogger } from '../../core/log.js';
|
|
6
|
+
const log = createLogger('rate-limit-throttle');
|
|
7
|
+
const UTILIZATION_THRESHOLD = 0.90;
|
|
8
|
+
const RESUME_BUFFER_MS = 5_000;
|
|
9
|
+
// --- Module state ---
|
|
10
|
+
let _adapter = null;
|
|
11
|
+
let _persistence = null;
|
|
12
|
+
let _isThrottled = false;
|
|
13
|
+
let _resetsAt = null; // Unix seconds
|
|
14
|
+
let _resumeTimer = null;
|
|
15
|
+
const _rateLimitedModes = new Set();
|
|
16
|
+
// --- Logging (handled by createLogger) ---
|
|
17
|
+
// --- Admin DM (fire-and-forget) ---
|
|
18
|
+
function sendDM(text) {
|
|
19
|
+
if (!_adapter)
|
|
20
|
+
return;
|
|
21
|
+
const adminChannel = _adapter.getAdminChannel();
|
|
22
|
+
if (!adminChannel)
|
|
23
|
+
return;
|
|
24
|
+
_adapter.postMessage(adminChannel, { text }).catch(e => {
|
|
25
|
+
log.error(`DM failed: ${e.message}`);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function formatResetTime(epochSec) {
|
|
29
|
+
return new Date(epochSec * 1000).toLocaleString('en-GB', {
|
|
30
|
+
month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: false,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// --- Timer ---
|
|
34
|
+
function clearThrottle() {
|
|
35
|
+
_isThrottled = false;
|
|
36
|
+
_resetsAt = null;
|
|
37
|
+
_rateLimitedModes.clear();
|
|
38
|
+
_resumeTimer = null;
|
|
39
|
+
sendDM(':white_check_mark: Rate limit throttle cleared.');
|
|
40
|
+
_persistence?.save(null).catch(e => {
|
|
41
|
+
log.error(`Failed to persist cleared throttle: ${e.message}`);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function scheduleResumeTimer() {
|
|
45
|
+
if (_resumeTimer)
|
|
46
|
+
clearTimeout(_resumeTimer);
|
|
47
|
+
const delayMs = Math.max(0, (_resetsAt * 1000) - Date.now()) + RESUME_BUFFER_MS;
|
|
48
|
+
log.info(`Resume scheduled in ${(delayMs / 1000 / 60).toFixed(1)} min`);
|
|
49
|
+
_resumeTimer = setTimeout(() => {
|
|
50
|
+
clearThrottle();
|
|
51
|
+
}, delayMs);
|
|
52
|
+
}
|
|
53
|
+
// --- Public API ---
|
|
54
|
+
async function initRateLimitThrottle(adapter, persistence) {
|
|
55
|
+
_adapter = adapter;
|
|
56
|
+
_persistence = persistence;
|
|
57
|
+
// Recover throttle state from disk (survives restart)
|
|
58
|
+
const persisted = await persistence.load();
|
|
59
|
+
if (persisted) {
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
if (persisted.resetsAt * 1000 + RESUME_BUFFER_MS > now) {
|
|
62
|
+
_isThrottled = true;
|
|
63
|
+
_resetsAt = persisted.resetsAt;
|
|
64
|
+
if (persisted.modes) {
|
|
65
|
+
for (const m of persisted.modes)
|
|
66
|
+
_rateLimitedModes.add(m);
|
|
67
|
+
}
|
|
68
|
+
log.info(`Restored throttle from disk: ${persisted.modes?.length ?? 0} mode(s) rate-limited, resetsAt=${new Date(_resetsAt * 1000).toISOString()}`);
|
|
69
|
+
scheduleResumeTimer();
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
log.info(`Throttle expired during downtime (resetsAt was ${new Date(persisted.resetsAt * 1000).toISOString()}). Clearing.`);
|
|
73
|
+
await persistence.save(null);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
log.info('Initialized');
|
|
77
|
+
}
|
|
78
|
+
async function handleRateLimitEvent(info, mode) {
|
|
79
|
+
if (!info || !_persistence)
|
|
80
|
+
return;
|
|
81
|
+
if (info.rateLimitType !== 'five_hour')
|
|
82
|
+
return;
|
|
83
|
+
if (typeof info.utilization !== 'number' || info.utilization < UTILIZATION_THRESHOLD)
|
|
84
|
+
return;
|
|
85
|
+
if (!info.resetsAt)
|
|
86
|
+
return;
|
|
87
|
+
if (_isThrottled) {
|
|
88
|
+
if (info.resetsAt > (_resetsAt || 0)) {
|
|
89
|
+
log.info(`Extending throttle: resetsAt ${_resetsAt} → ${info.resetsAt}`);
|
|
90
|
+
_resetsAt = info.resetsAt;
|
|
91
|
+
if (mode)
|
|
92
|
+
_rateLimitedModes.add(mode);
|
|
93
|
+
await _persistence.save({ resetsAt: _resetsAt, activatedAt: Date.now(), modes: [..._rateLimitedModes] });
|
|
94
|
+
scheduleResumeTimer();
|
|
95
|
+
}
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
_isThrottled = true;
|
|
99
|
+
_resetsAt = info.resetsAt;
|
|
100
|
+
if (mode)
|
|
101
|
+
_rateLimitedModes.add(mode);
|
|
102
|
+
log.info(`Throttle activated: utilization=${info.utilization}, resetsAt=${new Date(_resetsAt * 1000).toISOString()}, mode=${mode ?? '(none)'}`);
|
|
103
|
+
scheduleResumeTimer();
|
|
104
|
+
await _persistence.save({ resetsAt: _resetsAt, activatedAt: Date.now(), modes: [..._rateLimitedModes] });
|
|
105
|
+
const resetStr = formatResetTime(_resetsAt);
|
|
106
|
+
const modeNote = mode ? ` (mode: ${mode})` : '';
|
|
107
|
+
sendDM(`:warning: Rate limit throttle activated — utilization ${(info.utilization * 100).toFixed(0)}%${modeNote}.\nAuto-resume at ${resetStr}.`);
|
|
108
|
+
}
|
|
109
|
+
function isThrottled() {
|
|
110
|
+
return _isThrottled;
|
|
111
|
+
}
|
|
112
|
+
function isModeRateLimited(mode) {
|
|
113
|
+
return _isThrottled && _rateLimitedModes.has(mode);
|
|
114
|
+
}
|
|
115
|
+
function getThrottleState() {
|
|
116
|
+
return { isThrottled: _isThrottled, resetsAt: _resetsAt, rateLimitedModes: [..._rateLimitedModes] };
|
|
117
|
+
}
|
|
118
|
+
// --- Test helpers ---
|
|
119
|
+
function _testReset() {
|
|
120
|
+
if (_resumeTimer)
|
|
121
|
+
clearTimeout(_resumeTimer);
|
|
122
|
+
_isThrottled = false;
|
|
123
|
+
_resetsAt = null;
|
|
124
|
+
_resumeTimer = null;
|
|
125
|
+
_rateLimitedModes.clear();
|
|
126
|
+
_adapter = null;
|
|
127
|
+
_persistence = null;
|
|
128
|
+
}
|
|
129
|
+
export { initRateLimitThrottle, handleRateLimitEvent, isThrottled, isModeRateLimited, getThrottleState, _testReset };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { executionRepo, TERMINAL_STATUSES } from '../../store/execution-repo.js';
|
|
2
|
+
export type { ExecutionRecord, DispatchInfo } from '../../store/execution-repo.js';
|
|
3
|
+
export { TERMINAL_STATUSES };
|
|
4
|
+
export declare function getExecution(id: string): import("../../store/execution-repo.js").ExecutionRecord;
|
|
5
|
+
export declare function getExecutionByTaskId(taskId: string | null | undefined): import("../../store/execution-repo.js").ExecutionRecord;
|
|
6
|
+
export declare function getRunningExecutions(): import("../../store/execution-repo.js").ExecutionRecord[];
|
|
7
|
+
export declare function findRunningDispatchMatch(opts: Parameters<typeof executionRepo.findRunningDispatchMatch>[0]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
8
|
+
export declare function startLocalExecution(opts: Parameters<typeof executionRepo.startLocalExecution>[0]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
9
|
+
export declare function registerDispatchExecution(opts: Parameters<typeof executionRepo.registerDispatchExecution>[0]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
10
|
+
export declare function touchExecution(id: string, patch?: Parameters<typeof executionRepo.touchExecution>[1]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
11
|
+
export declare function completeExecution(id: string, metrics?: Parameters<typeof executionRepo.completeExecution>[1]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
12
|
+
export declare function completeExecutionByTaskId(taskId: string, metrics?: Parameters<typeof executionRepo.completeExecutionByTaskId>[1]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
13
|
+
export declare function failExecution(id: string, metrics?: Parameters<typeof executionRepo.failExecution>[1]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
14
|
+
export declare function failExecutionByTaskId(taskId: string, metrics?: Parameters<typeof executionRepo.failExecutionByTaskId>[1]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
15
|
+
export declare function cancelExecution(id: string, metrics?: Parameters<typeof executionRepo.cancelExecution>[1]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
16
|
+
export declare function cancelExecutionByTaskId(taskId: string, metrics?: Parameters<typeof executionRepo.cancelExecutionByTaskId>[1]): import("../../store/execution-repo.js").ExecutionRecord;
|
|
17
|
+
export declare function markMissingRunningExecutionsStale(keepRunning?: Parameters<typeof executionRepo.markMissingRunningExecutionsStale>[0]): Promise<string[]>;
|
|
18
|
+
export declare function reconcileStaleDispatches(opts: Parameters<typeof executionRepo.reconcileStaleDispatches>[0]): Promise<number>;
|
|
19
|
+
/** @deprecated ExecutionRepo uses in-memory Map; cache clearing is a no-op. */
|
|
20
|
+
export declare function clearExecutionCache(): void;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// input: ExecutionRepo singleton (store/execution-repo.ts)
|
|
2
|
+
// output: named function exports matching the pre-migration API surface, with lock-release side effect on terminal transitions
|
|
3
|
+
// pos: thin re-export layer — delegates to ExecutionRepo. Maintains backward compat for all import sites.
|
|
4
|
+
// Lock-release: every terminal transition (complete/fail/cancel/stale) auto-releases any task lock held by the executionId.
|
|
5
|
+
// >>> If I am updated, update my header comment and CORTEX.md <<<
|
|
6
|
+
import * as fs from 'node:fs';
|
|
7
|
+
import { executionRepo, TERMINAL_STATUSES } from '../../store/execution-repo.js';
|
|
8
|
+
import { PROJECTS_DIR } from '../../core/utils.js';
|
|
9
|
+
import { readLock, releaseLock } from '../tasks/system/task-lock.js';
|
|
10
|
+
import { createLogger } from '../../core/log.js';
|
|
11
|
+
export { TERMINAL_STATUSES };
|
|
12
|
+
const lockLog = createLogger('execution-lock-release');
|
|
13
|
+
/** Release any task locks still owned by `executionId` after its agent finished.
|
|
14
|
+
* Idempotent — `releaseLock` returns success on absent or non-matching locks. */
|
|
15
|
+
function releaseLocksOwnedBy(executionId) {
|
|
16
|
+
if (!executionId)
|
|
17
|
+
return;
|
|
18
|
+
let projects;
|
|
19
|
+
try {
|
|
20
|
+
projects = fs.readdirSync(PROJECTS_DIR, { withFileTypes: true })
|
|
21
|
+
.filter(d => d.isDirectory()).map(d => d.name);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
for (const project of projects) {
|
|
27
|
+
let lock;
|
|
28
|
+
try {
|
|
29
|
+
lock = readLock(project);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (!lock || lock.owner !== executionId)
|
|
35
|
+
continue;
|
|
36
|
+
try {
|
|
37
|
+
const r = releaseLock(project, executionId);
|
|
38
|
+
if (r.released) {
|
|
39
|
+
lockLog.warn(`auto-released stale lock on '${project}' held by execution ${executionId} ` +
|
|
40
|
+
`(agent finished without calling cortex-task lock-release)`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
lockLog.warn(`release attempt failed for ${project} / ${executionId}: ${err?.message || err}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// --- Sync reads ---
|
|
49
|
+
export function getExecution(id) {
|
|
50
|
+
return executionRepo.getExecution(id);
|
|
51
|
+
}
|
|
52
|
+
export function getExecutionByTaskId(taskId) {
|
|
53
|
+
return executionRepo.getExecutionByTaskId(taskId);
|
|
54
|
+
}
|
|
55
|
+
export function getRunningExecutions() {
|
|
56
|
+
return executionRepo.getRunningExecutions();
|
|
57
|
+
}
|
|
58
|
+
export function findRunningDispatchMatch(opts) {
|
|
59
|
+
return executionRepo.findRunningDispatchMatch(opts);
|
|
60
|
+
}
|
|
61
|
+
// --- Sync create/mutate + fire-and-forget persist ---
|
|
62
|
+
export function startLocalExecution(opts) {
|
|
63
|
+
return executionRepo.startLocalExecution(opts);
|
|
64
|
+
}
|
|
65
|
+
export function registerDispatchExecution(opts) {
|
|
66
|
+
return executionRepo.registerDispatchExecution(opts);
|
|
67
|
+
}
|
|
68
|
+
export function touchExecution(id, patch) {
|
|
69
|
+
return executionRepo.touchExecution(id, patch);
|
|
70
|
+
}
|
|
71
|
+
export function completeExecution(id, metrics) {
|
|
72
|
+
const r = executionRepo.completeExecution(id, metrics);
|
|
73
|
+
if (r && TERMINAL_STATUSES.has(r.status))
|
|
74
|
+
releaseLocksOwnedBy(id);
|
|
75
|
+
return r;
|
|
76
|
+
}
|
|
77
|
+
export function completeExecutionByTaskId(taskId, metrics) {
|
|
78
|
+
const record = executionRepo.getExecutionByTaskId(taskId);
|
|
79
|
+
if (!record)
|
|
80
|
+
return null;
|
|
81
|
+
return completeExecution(record.id, metrics);
|
|
82
|
+
}
|
|
83
|
+
export function failExecution(id, metrics) {
|
|
84
|
+
const r = executionRepo.failExecution(id, metrics);
|
|
85
|
+
if (r && TERMINAL_STATUSES.has(r.status))
|
|
86
|
+
releaseLocksOwnedBy(id);
|
|
87
|
+
return r;
|
|
88
|
+
}
|
|
89
|
+
export function failExecutionByTaskId(taskId, metrics) {
|
|
90
|
+
const record = executionRepo.getExecutionByTaskId(taskId);
|
|
91
|
+
if (!record)
|
|
92
|
+
return null;
|
|
93
|
+
return failExecution(record.id, metrics);
|
|
94
|
+
}
|
|
95
|
+
export function cancelExecution(id, metrics) {
|
|
96
|
+
const r = executionRepo.cancelExecution(id, metrics);
|
|
97
|
+
if (r && TERMINAL_STATUSES.has(r.status))
|
|
98
|
+
releaseLocksOwnedBy(id);
|
|
99
|
+
return r;
|
|
100
|
+
}
|
|
101
|
+
export function cancelExecutionByTaskId(taskId, metrics) {
|
|
102
|
+
const record = executionRepo.getExecutionByTaskId(taskId);
|
|
103
|
+
if (!record)
|
|
104
|
+
return null;
|
|
105
|
+
return cancelExecution(record.id, metrics);
|
|
106
|
+
}
|
|
107
|
+
// --- Async operations ---
|
|
108
|
+
export async function markMissingRunningExecutionsStale(keepRunning) {
|
|
109
|
+
const staled = await executionRepo.markMissingRunningExecutionsStale(keepRunning);
|
|
110
|
+
for (const id of staled)
|
|
111
|
+
releaseLocksOwnedBy(id);
|
|
112
|
+
return staled;
|
|
113
|
+
}
|
|
114
|
+
export async function reconcileStaleDispatches(opts) {
|
|
115
|
+
const { count, staled } = await executionRepo.reconcileStaleDispatches(opts);
|
|
116
|
+
for (const id of staled)
|
|
117
|
+
releaseLocksOwnedBy(id);
|
|
118
|
+
return count;
|
|
119
|
+
}
|
|
120
|
+
// --- Deprecated ---
|
|
121
|
+
/** @deprecated ExecutionRepo uses in-memory Map; cache clearing is a no-op. */
|
|
122
|
+
export function clearExecutionCache() {
|
|
123
|
+
// no-op: ExecutionRepo does not use module-level cache
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// input: MCP SDK, task-ops tool module
|
|
2
|
+
// output: MCP stdio service, exposing remote_* tools only
|
|
3
|
+
// pos: Core MCP server — thread agents load only this one (no Slack/cost/schedule tools)
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
7
|
+
import { registerTaskOpsTools } from './tools/task-ops.js';
|
|
8
|
+
import { isMainModule } from '../../core/utils.js';
|
|
9
|
+
import { createLogger } from '../../core/log.js';
|
|
10
|
+
import { CORTEX_VERSION } from '../../core/version.js';
|
|
11
|
+
const log = createLogger('mcp-core');
|
|
12
|
+
// --- McpServer + tool registration ---
|
|
13
|
+
const server = new McpServer({ name: 'cortex-core', version: CORTEX_VERSION });
|
|
14
|
+
registerTaskOpsTools(server);
|
|
15
|
+
// --- Exported tool name list (for verification) ---
|
|
16
|
+
export const TOOL_NAMES = [
|
|
17
|
+
'remote_bash',
|
|
18
|
+
'remote_read',
|
|
19
|
+
'remote_write',
|
|
20
|
+
'remote_edit',
|
|
21
|
+
'remote_glob',
|
|
22
|
+
'remote_grep',
|
|
23
|
+
];
|
|
24
|
+
// --- Start (called by barrel when run as standalone) ---
|
|
25
|
+
export async function startServer() {
|
|
26
|
+
const transport = new StdioServerTransport();
|
|
27
|
+
await server.connect(transport);
|
|
28
|
+
}
|
|
29
|
+
if (isMainModule(import.meta.url)) {
|
|
30
|
+
startServer().catch((e) => {
|
|
31
|
+
log.error(e);
|
|
32
|
+
process.exit(1);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// input: MCP SDK, Slack WebClient, 4 tool-family modules (no remote_* — those live in core-server.ts)
|
|
2
|
+
// output: MCP stdio service, exposing slack/cost/query/context/schedule tools
|
|
3
|
+
// pos: Ext MCP server — direct-agent-only tools (Slack, cost, executions, context, schedule)
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
6
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
7
|
+
import { WebClient } from '@slack/web-api';
|
|
8
|
+
import { registerSlackTools } from './tools/slack.js';
|
|
9
|
+
import { registerCostTools } from './tools/cost.js';
|
|
10
|
+
import { registerExecutionTools } from './tools/executions.js';
|
|
11
|
+
import { registerContextTools } from './tools/context.js';
|
|
12
|
+
import { registerScheduleTools } from './tools/schedule.js';
|
|
13
|
+
import { isMainModule } from '../../core/utils.js';
|
|
14
|
+
import { createLogger } from '../../core/log.js';
|
|
15
|
+
import { CORTEX_VERSION } from '../../core/version.js';
|
|
16
|
+
const log = createLogger('mcp-server');
|
|
17
|
+
// --- Config from env / CLI args ---
|
|
18
|
+
const token = process.env.SLACK_BOT_TOKEN;
|
|
19
|
+
const fallbackChannel = process.env.SLACK_CHANNEL;
|
|
20
|
+
const branchMachine = process.env.CORTEX_BRANCH_MACHINE;
|
|
21
|
+
const fallbackCallbackSource = process.env.CORTEX_CALLBACK_SOURCE;
|
|
22
|
+
function getCliArg(name) {
|
|
23
|
+
const idx = process.argv.indexOf(name);
|
|
24
|
+
if (idx !== -1 && idx + 1 < process.argv.length)
|
|
25
|
+
return process.argv[idx + 1];
|
|
26
|
+
const prefixed = process.argv.find(a => a.startsWith(`${name}=`));
|
|
27
|
+
if (prefixed)
|
|
28
|
+
return prefixed.slice(name.length + 1);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const routeContextFile = getCliArg('--route-context-file') ||
|
|
32
|
+
process.env.CORTEX_ROUTE_CONTEXT_FILE ||
|
|
33
|
+
null;
|
|
34
|
+
// --- Slack client ---
|
|
35
|
+
const slack = token ? new WebClient(token) : null;
|
|
36
|
+
// --- McpServer + tool registration ---
|
|
37
|
+
const server = new McpServer({ name: 'cortex', version: CORTEX_VERSION });
|
|
38
|
+
const slackDeps = {
|
|
39
|
+
slack,
|
|
40
|
+
fallbackChannel,
|
|
41
|
+
routeContextFile,
|
|
42
|
+
branchMachine,
|
|
43
|
+
callbackSource: fallbackCallbackSource,
|
|
44
|
+
};
|
|
45
|
+
const contextDeps = { routeContextFile };
|
|
46
|
+
registerSlackTools(server, slackDeps);
|
|
47
|
+
registerCostTools(server);
|
|
48
|
+
registerExecutionTools(server);
|
|
49
|
+
registerContextTools(server, contextDeps);
|
|
50
|
+
registerScheduleTools(server, contextDeps);
|
|
51
|
+
// --- Exported tool name list (for verification) ---
|
|
52
|
+
export const TOOL_NAMES = [
|
|
53
|
+
'slack_send_file',
|
|
54
|
+
'cost_query',
|
|
55
|
+
'query_executions',
|
|
56
|
+
'cortex_context',
|
|
57
|
+
'cortex_schedule_add',
|
|
58
|
+
'cortex_schedule_list',
|
|
59
|
+
'cortex_schedule_get',
|
|
60
|
+
'cortex_schedule_remove',
|
|
61
|
+
'cortex_schedule_pause',
|
|
62
|
+
'cortex_schedule_resume',
|
|
63
|
+
];
|
|
64
|
+
// --- Start (called by barrel when run as standalone) ---
|
|
65
|
+
export async function startServer() {
|
|
66
|
+
if (!token || !fallbackChannel) {
|
|
67
|
+
log.warn('SLACK_BOT_TOKEN or SLACK_CHANNEL not set — slack_send_file will be unavailable');
|
|
68
|
+
}
|
|
69
|
+
const transport = new StdioServerTransport();
|
|
70
|
+
await server.connect(transport);
|
|
71
|
+
}
|
|
72
|
+
export { uploadFileToSlack } from './tools/slack.js';
|
|
73
|
+
if (isMainModule(import.meta.url)) {
|
|
74
|
+
startServer().catch((e) => {
|
|
75
|
+
log.error(e);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
export interface ContextToolDeps {
|
|
3
|
+
/** Path to the per-route context.json written by Codex's writeRouteContext (codex backend only). Null on Claude. */
|
|
4
|
+
routeContextFile: string | null;
|
|
5
|
+
}
|
|
6
|
+
interface CortexContextResponse {
|
|
7
|
+
channel: string | null;
|
|
8
|
+
sessionId: string | null;
|
|
9
|
+
sessionName: string | null;
|
|
10
|
+
threadId: string | null;
|
|
11
|
+
profile: string | null;
|
|
12
|
+
project: string | null;
|
|
13
|
+
backend: string | null;
|
|
14
|
+
scheduleTaskId: string | null;
|
|
15
|
+
callbackSource: string | null;
|
|
16
|
+
}
|
|
17
|
+
/** Resolve the Cortex execution context from route-context.json (preferred — refreshed
|
|
18
|
+
* per turn for Codex) and falling back to the env vars set at MCP server spawn time
|
|
19
|
+
* (Claude path; sticky for the session lifetime). When sessionId is known but sessionName
|
|
20
|
+
* is not, look up the session-registry to get the cortex-XXXX short name. */
|
|
21
|
+
export declare function resolveCortexContext(deps: ContextToolDeps): Promise<CortexContextResponse>;
|
|
22
|
+
export declare function registerContextTools(server: McpServer, deps: ContextToolDeps): void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// input: McpServer + route-context-file + CORTEX_* env + thread/session stores
|
|
2
|
+
// output: cortex_context tool registration
|
|
3
|
+
// pos: MCP tool letting the running LLM self-discover its channel/thread/session/profile,
|
|
4
|
+
// so cortex_schedule_add can target the current scope without guessing IDs.
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import { sessionRegistryRepo } from '../../../store/session-registry-repo.js';
|
|
8
|
+
function readRouteContext(routeContextFile) {
|
|
9
|
+
if (!routeContextFile)
|
|
10
|
+
return null;
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(fs.readFileSync(routeContextFile, 'utf8'));
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Resolve the Cortex execution context from route-context.json (preferred — refreshed
|
|
19
|
+
* per turn for Codex) and falling back to the env vars set at MCP server spawn time
|
|
20
|
+
* (Claude path; sticky for the session lifetime). When sessionId is known but sessionName
|
|
21
|
+
* is not, look up the session-registry to get the cortex-XXXX short name. */
|
|
22
|
+
export async function resolveCortexContext(deps) {
|
|
23
|
+
const route = readRouteContext(deps.routeContextFile);
|
|
24
|
+
const sessionId = route?.sessionId ?? process.env.CORTEX_SESSION_ID ?? null;
|
|
25
|
+
let sessionName = route?.sessionName ?? process.env.CORTEX_SESSION_NAME ?? null;
|
|
26
|
+
if (!sessionName && sessionId) {
|
|
27
|
+
sessionName = await sessionRegistryRepo.lookupBySessionId(sessionId);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
channel: route?.channel ?? process.env.SLACK_CHANNEL ?? null,
|
|
31
|
+
sessionId,
|
|
32
|
+
sessionName,
|
|
33
|
+
threadId: route?.threadId ?? process.env.CORTEX_THREAD_ID ?? null,
|
|
34
|
+
profile: route?.profile ?? process.env.CORTEX_PROFILE ?? null,
|
|
35
|
+
project: route?.project ?? process.env.CORTEX_PROJECT ?? null,
|
|
36
|
+
backend: process.env.CORTEX_BACKEND ?? null,
|
|
37
|
+
scheduleTaskId: process.env.CORTEX_SCHEDULE_TASK_ID ?? null,
|
|
38
|
+
callbackSource: route?.callbackSource ?? process.env.CORTEX_CALLBACK_SOURCE ?? null,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function registerContextTools(server, deps) {
|
|
42
|
+
server.tool('cortex_context', 'Return the current Cortex execution context: channel, sessionId, sessionName (cortex-XXXX), threadId, profile, project, backend. Use this to discover the current scope before calling cortex_schedule_add with target=current-channel/current-session/current-thread.', {}, { readOnlyHint: true }, async () => {
|
|
43
|
+
try {
|
|
44
|
+
const ctxResponse = await resolveCortexContext(deps);
|
|
45
|
+
return { content: [{ type: 'text', text: JSON.stringify(ctxResponse, null, 2) }] };
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
return { content: [{ type: 'text', text: `Failed to resolve context: ${e.message}` }], isError: true };
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type CortexMDEntry } from '../../memory/cortex-md-injector.js';
|
|
2
|
+
export { type CortexMDEntry };
|
|
3
|
+
/** Build text content blocks for the CORTEX.md chain returned by cortex-client.
|
|
4
|
+
* Dedup by (device:path) mtime via CortexMDInjector — each CORTEX.md is injected
|
|
5
|
+
* at most once per MCP process, and the cache is disk-backed so restarts
|
|
6
|
+
* don't re-flood the agent with the same instructions.
|
|
7
|
+
*
|
|
8
|
+
* If `targetFilePath` is supplied and equals one of the chain entries (i.e. the
|
|
9
|
+
* tool is reading/writing/editing a CORTEX.md itself), that entry is marked as
|
|
10
|
+
* seen in the cache but its block is suppressed — the agent already receives
|
|
11
|
+
* the content as the primary tool response, so re-injecting would just double
|
|
12
|
+
* it. Subsequent reads of sibling files in the same dir will then hit the
|
|
13
|
+
* cache and also skip, matching the normal dedup behavior. */
|
|
14
|
+
export declare function cortexMDContentBlocks(device: string, entries: CortexMDEntry[] | undefined, targetFilePath?: string): Array<{
|
|
15
|
+
type: 'text';
|
|
16
|
+
text: string;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// helper: CORTEX.md injection blocks for remote_* tool responses
|
|
2
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
3
|
+
import { getDefaultCortexInjector } from '../../memory/cortex-md-injector.js';
|
|
4
|
+
/** Build text content blocks for the CORTEX.md chain returned by cortex-client.
|
|
5
|
+
* Dedup by (device:path) mtime via CortexMDInjector — each CORTEX.md is injected
|
|
6
|
+
* at most once per MCP process, and the cache is disk-backed so restarts
|
|
7
|
+
* don't re-flood the agent with the same instructions.
|
|
8
|
+
*
|
|
9
|
+
* If `targetFilePath` is supplied and equals one of the chain entries (i.e. the
|
|
10
|
+
* tool is reading/writing/editing a CORTEX.md itself), that entry is marked as
|
|
11
|
+
* seen in the cache but its block is suppressed — the agent already receives
|
|
12
|
+
* the content as the primary tool response, so re-injecting would just double
|
|
13
|
+
* it. Subsequent reads of sibling files in the same dir will then hit the
|
|
14
|
+
* cache and also skip, matching the normal dedup behavior. */
|
|
15
|
+
export function cortexMDContentBlocks(device, entries, targetFilePath) {
|
|
16
|
+
if (!entries || entries.length === 0)
|
|
17
|
+
return [];
|
|
18
|
+
let markOnly;
|
|
19
|
+
if (targetFilePath) {
|
|
20
|
+
const matched = entries.filter(e => pathsEqualForMarking(e.path, targetFilePath));
|
|
21
|
+
if (matched.length > 0)
|
|
22
|
+
markOnly = new Set(matched.map(e => e.path));
|
|
23
|
+
}
|
|
24
|
+
return getDefaultCortexInjector().buildBlocks(device, entries, markOnly);
|
|
25
|
+
}
|
|
26
|
+
/** Tolerant path equality for matching tool `file_path` against scanner-produced
|
|
27
|
+
* entry paths. The scanner runs on the remote device (Linux or Windows), so
|
|
28
|
+
* separators may differ. We compare directly and with both separators
|
|
29
|
+
* normalized to forward slashes. Case-sensitive — Windows remotes reading
|
|
30
|
+
* through differently-cased paths will just not mark (graceful degrade to the
|
|
31
|
+
* pre-existing duplicate-on-first-read behavior). */
|
|
32
|
+
function pathsEqualForMarking(a, b) {
|
|
33
|
+
if (a === b)
|
|
34
|
+
return true;
|
|
35
|
+
return a.replace(/\\/g, '/') === b.replace(/\\/g, '/');
|
|
36
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// input: McpServer, cost-repo, cost-tracker
|
|
2
|
+
// output: cost_query tool registration
|
|
3
|
+
// pos: MCP tool for querying current cost and budget status
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { getCostSummary } from '../../costs/cost-tracker.js';
|
|
6
|
+
import { costRepo } from '../../../store/cost-repo.js';
|
|
7
|
+
export function registerCostTools(server) {
|
|
8
|
+
server.tool('cost_query', 'Query current cost and budget status. Returns today/month spending, budget limits, remaining budget, api/plan cost split, source breakdown (gateway vs estimate), and token usage.', {}, { readOnlyHint: true }, async () => {
|
|
9
|
+
try {
|
|
10
|
+
const budget = await costRepo.readBudget();
|
|
11
|
+
const summaryData = await getCostSummary();
|
|
12
|
+
const now = new Date();
|
|
13
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
14
|
+
const todayStr = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
15
|
+
const monthStr = `${now.getFullYear()}-${pad(now.getMonth() + 1)}`;
|
|
16
|
+
const todayTotal = summaryData.byMode.today.total;
|
|
17
|
+
const monthTotal = summaryData.byMode.month.total;
|
|
18
|
+
const todayApi = summaryData.byMode.today.api;
|
|
19
|
+
const todayPlan = summaryData.byMode.today.plan;
|
|
20
|
+
const monthApi = summaryData.byMode.month.api;
|
|
21
|
+
const monthPlan = summaryData.byMode.month.plan;
|
|
22
|
+
const dailyPct = ((todayTotal / budget.daily_usd) * 100).toFixed(1);
|
|
23
|
+
const monthlyPct = ((monthTotal / budget.monthly_usd) * 100).toFixed(1);
|
|
24
|
+
const lines = [
|
|
25
|
+
`Today (${todayStr}): $${todayTotal.toFixed(2)} / $${budget.daily_usd} (${dailyPct}%, ${summaryData.entryCount} sessions in window)`,
|
|
26
|
+
` API: $${todayApi.toFixed(2)} | Plan: $${todayPlan.toFixed(2)}`,
|
|
27
|
+
`Month (${monthStr}): $${monthTotal.toFixed(2)} / $${budget.monthly_usd} (${monthlyPct}%)`,
|
|
28
|
+
` API: $${monthApi.toFixed(2)} | Plan: $${monthPlan.toFixed(2)}`,
|
|
29
|
+
`Remaining today: $${(budget.daily_usd - todayTotal).toFixed(2)}`,
|
|
30
|
+
`Remaining month: $${(budget.monthly_usd - monthTotal).toFixed(2)}`,
|
|
31
|
+
];
|
|
32
|
+
// Source breakdown
|
|
33
|
+
if (summaryData.bySource && Object.keys(summaryData.bySource).length > 0) {
|
|
34
|
+
lines.push('');
|
|
35
|
+
lines.push('By source:');
|
|
36
|
+
for (const [src, stats] of Object.entries(summaryData.bySource)) {
|
|
37
|
+
lines.push(` ${src}: today $${stats.today.toFixed(2)} | month $${stats.month.toFixed(2)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Token usage
|
|
41
|
+
const tok = summaryData.tokens;
|
|
42
|
+
if (tok && (tok.total.input > 0 || tok.total.output > 0)) {
|
|
43
|
+
const fmtTok = (n) => n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1e3 ? `${(n / 1e3).toFixed(1)}k` : String(n);
|
|
44
|
+
lines.push('');
|
|
45
|
+
lines.push(`Tokens today: ${fmtTok(tok.today.input)} in / ${fmtTok(tok.today.output)} out`);
|
|
46
|
+
lines.push(`Tokens month: ${fmtTok(tok.month.input)} in / ${fmtTok(tok.month.output)} out`);
|
|
47
|
+
}
|
|
48
|
+
return { content: [{ type: 'text', text: lines.join('\n') }] };
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
return { content: [{ type: 'text', text: `Failed to query cost: ${e.message}` }], isError: true };
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|