@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,94 @@
|
|
|
1
|
+
// input: McpServer, execution-repo
|
|
2
|
+
// output: query_executions tool registration
|
|
3
|
+
// pos: MCP tool for querying execution status
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { executionRepo } from '../../../store/execution-repo.js';
|
|
7
|
+
function formatDuration(ms) {
|
|
8
|
+
if (ms < 60000)
|
|
9
|
+
return `${(ms / 1000).toFixed(0)}s`;
|
|
10
|
+
if (ms < 3600000)
|
|
11
|
+
return `${(ms / 60000).toFixed(1)}m`;
|
|
12
|
+
return `${(ms / 3600000).toFixed(1)}h`;
|
|
13
|
+
}
|
|
14
|
+
function formatRecord(r, now, detail = false) {
|
|
15
|
+
const startMs = r.runtime?.startedAt ? new Date(r.runtime.startedAt).getTime() : 0;
|
|
16
|
+
const elapsed = r.status === 'running' ? formatDuration(now - startMs) : (r.metrics?.durationS ? formatDuration(r.metrics.durationS * 1000) : '—');
|
|
17
|
+
const cost = r.metrics?.costUsd != null ? `$${r.metrics.costUsd.toFixed(4)}` : '—';
|
|
18
|
+
const turns = r.metrics?.numTurns ?? '—';
|
|
19
|
+
const machine = r.dispatch?.machine || '—';
|
|
20
|
+
const taskId = r.dispatch?.taskId || '—';
|
|
21
|
+
const taskHash = r.dispatch?.taskHash || '—';
|
|
22
|
+
const lines = [
|
|
23
|
+
`[${r.id}] ${r.status} (${r.kind})`,
|
|
24
|
+
` Project: ${r.project || '—'} | Machine: ${machine}`,
|
|
25
|
+
` Task ID: ${taskId} | Hash: ${taskHash}`,
|
|
26
|
+
` Elapsed: ${elapsed} | Cost: ${cost} | Turns: ${turns}`,
|
|
27
|
+
];
|
|
28
|
+
if (r.text?.label)
|
|
29
|
+
lines.push(` Label: ${r.text.label}`);
|
|
30
|
+
if (detail) {
|
|
31
|
+
if (r.runtime?.startedAt)
|
|
32
|
+
lines.push(` Started: ${r.runtime.startedAt}`);
|
|
33
|
+
if (r.runtime?.endedAt)
|
|
34
|
+
lines.push(` Ended: ${r.runtime.endedAt}`);
|
|
35
|
+
if (r.dispatch?.sessionName)
|
|
36
|
+
lines.push(` Session: ${r.dispatch.sessionName}`);
|
|
37
|
+
if (r.dispatch?.tmuxName)
|
|
38
|
+
lines.push(` Tmux: ${r.dispatch.tmuxName}`);
|
|
39
|
+
if (r.text?.error)
|
|
40
|
+
lines.push(` Error: ${r.text.error}`);
|
|
41
|
+
if (r.text?.finalOutput)
|
|
42
|
+
lines.push(` Output: ${r.text.finalOutput.slice(0, 500)}`);
|
|
43
|
+
}
|
|
44
|
+
return lines.join('\n');
|
|
45
|
+
}
|
|
46
|
+
export function registerExecutionTools(server) {
|
|
47
|
+
server.tool('query_executions', 'Query execution status. List filtered executions, or look up a specific one by execution ID or dispatch task ID.', {
|
|
48
|
+
execution_id: z.string().optional().describe('Look up by execution ID (exec_dispatch_xxx)'),
|
|
49
|
+
task_id: z.string().optional().describe('Look up by dispatch task ID or TASKS.yaml hash'),
|
|
50
|
+
status: z.enum(['running', 'completed', 'failed', 'cancelled', 'stale', 'all']).optional().describe('Filter by status (default: running)'),
|
|
51
|
+
project: z.string().optional().describe('Filter by project'),
|
|
52
|
+
limit: z.number().optional().describe('Max results (default: 10)'),
|
|
53
|
+
}, { readOnlyHint: true }, async ({ execution_id, task_id, status, project, limit }) => {
|
|
54
|
+
try {
|
|
55
|
+
const records = executionRepo.getAllExecutions();
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
// Single lookup mode
|
|
58
|
+
if (execution_id) {
|
|
59
|
+
const r = executionRepo.getExecution(execution_id);
|
|
60
|
+
if (!r)
|
|
61
|
+
return { content: [{ type: 'text', text: `No execution found: ${execution_id}` }], isError: true };
|
|
62
|
+
return { content: [{ type: 'text', text: formatRecord(r, now, true) }] };
|
|
63
|
+
}
|
|
64
|
+
if (task_id) {
|
|
65
|
+
const r = executionRepo.getExecutionByTaskId(task_id) || records.find(r => r.dispatch?.taskHash === task_id);
|
|
66
|
+
if (!r)
|
|
67
|
+
return { content: [{ type: 'text', text: `No execution found for task: ${task_id}` }], isError: true };
|
|
68
|
+
return { content: [{ type: 'text', text: formatRecord(r, now, true) }] };
|
|
69
|
+
}
|
|
70
|
+
// List mode
|
|
71
|
+
const filterStatus = status || 'running';
|
|
72
|
+
let filtered = filterStatus === 'all' ? records : records.filter(r => r.status === filterStatus);
|
|
73
|
+
if (project)
|
|
74
|
+
filtered = filtered.filter(r => r.project === project);
|
|
75
|
+
filtered.sort((a, b) => {
|
|
76
|
+
const ta = a.runtime?.startedAt ? new Date(a.runtime.startedAt).getTime() : 0;
|
|
77
|
+
const tb = b.runtime?.startedAt ? new Date(b.runtime.startedAt).getTime() : 0;
|
|
78
|
+
return tb - ta;
|
|
79
|
+
});
|
|
80
|
+
const maxResults = limit || 10;
|
|
81
|
+
const truncated = filtered.length > maxResults;
|
|
82
|
+
filtered = filtered.slice(0, maxResults);
|
|
83
|
+
if (filtered.length === 0) {
|
|
84
|
+
return { content: [{ type: 'text', text: `No ${filterStatus} executions found.` }] };
|
|
85
|
+
}
|
|
86
|
+
const header = `${filterStatus === 'all' ? 'All' : filterStatus} executions: ${filtered.length}${truncated ? ` (showing first ${maxResults})` : ''}`;
|
|
87
|
+
const body = filtered.map(r => formatRecord(r, now)).join('\n\n');
|
|
88
|
+
return { content: [{ type: 'text', text: `${header}\n\n${body}` }] };
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
return { content: [{ type: 'text', text: `Failed to query executions: ${e.message}` }], isError: true };
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { type ScheduleTarget } from '../../../store/schedule-repo.js';
|
|
3
|
+
import { type ContextToolDeps } from './context.js';
|
|
4
|
+
/** Snapshot of the Cortex execution context — what cortex_context returns, sliced
|
|
5
|
+
* down to fields needed by target resolution. Decoupled from the Tool's response
|
|
6
|
+
* shape so the resolver can be unit-tested without spinning up MCP. */
|
|
7
|
+
export interface CortexContextSnapshot {
|
|
8
|
+
channel: string | null;
|
|
9
|
+
sessionId: string | null;
|
|
10
|
+
sessionName: string | null;
|
|
11
|
+
threadId: string | null;
|
|
12
|
+
profile: string | null;
|
|
13
|
+
project: string | null;
|
|
14
|
+
backend: string | null;
|
|
15
|
+
scheduleTaskId: string | null;
|
|
16
|
+
callbackSource: string | null;
|
|
17
|
+
}
|
|
18
|
+
/** Target spec accepted by cortex_schedule_add: shorthand string OR explicit object.
|
|
19
|
+
* Shorthand strings are resolved to concrete ScheduleTarget objects at create time
|
|
20
|
+
* (decision: list/get always shows real IDs). */
|
|
21
|
+
export type TargetSpec = undefined | 'fresh' | 'current-channel' | 'current-session' | 'current-thread' | ScheduleTarget;
|
|
22
|
+
export declare function resolveTargetShorthand(spec: TargetSpec, ctx: CortexContextSnapshot): ScheduleTarget;
|
|
23
|
+
export declare function registerScheduleTools(server: McpServer, deps: ContextToolDeps): void;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// input: McpServer + scheduleRepo + Scheduler (for timing math) + cortex_context resolver
|
|
2
|
+
// output: cortex_schedule_{add,list,get,remove,pause,resume} tool registrations
|
|
3
|
+
// pos: MCP entry that lets the running LLM CRUD scheduled tasks without shelling out
|
|
4
|
+
// to bin/schedule. Resolves __current__ shorthand against the live execution context
|
|
5
|
+
// at create time so the persisted record always shows real channel/session/thread IDs.
|
|
6
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { Scheduler, parseDuration } from '../../scheduling/scheduler.js';
|
|
9
|
+
import { scheduleRepo } from '../../../store/schedule-repo.js';
|
|
10
|
+
import { resolveCortexContext } from './context.js';
|
|
11
|
+
export function resolveTargetShorthand(spec, ctx) {
|
|
12
|
+
if (spec === undefined || spec === 'fresh')
|
|
13
|
+
return { kind: 'fresh' };
|
|
14
|
+
if (spec === 'current-channel') {
|
|
15
|
+
if (!ctx.channel)
|
|
16
|
+
throw new Error('current-channel requested but no channel in current context');
|
|
17
|
+
return { kind: 'channel', channel: ctx.channel };
|
|
18
|
+
}
|
|
19
|
+
if (spec === 'current-session') {
|
|
20
|
+
if (!ctx.sessionName || !ctx.sessionId || !ctx.channel) {
|
|
21
|
+
throw new Error('current-session requested but session context incomplete (need sessionName + sessionId + channel)');
|
|
22
|
+
}
|
|
23
|
+
return { kind: 'session', sessionName: ctx.sessionName, sessionId: ctx.sessionId, channel: ctx.channel };
|
|
24
|
+
}
|
|
25
|
+
if (spec === 'current-thread') {
|
|
26
|
+
if (!ctx.threadId || !ctx.channel) {
|
|
27
|
+
throw new Error('current-thread requested but no threadId or channel in current context');
|
|
28
|
+
}
|
|
29
|
+
return { kind: 'thread', threadId: ctx.threadId, channel: ctx.channel };
|
|
30
|
+
}
|
|
31
|
+
// Object form — light validation per kind so we fail fast at create rather than at fire time.
|
|
32
|
+
if (typeof spec === 'object' && spec !== null && 'kind' in spec) {
|
|
33
|
+
if (spec.kind === 'fresh')
|
|
34
|
+
return { kind: 'fresh' };
|
|
35
|
+
if (spec.kind === 'channel') {
|
|
36
|
+
if (!spec.channel)
|
|
37
|
+
throw new Error('channel target requires { channel }');
|
|
38
|
+
return { kind: 'channel', channel: spec.channel };
|
|
39
|
+
}
|
|
40
|
+
if (spec.kind === 'session') {
|
|
41
|
+
if (!spec.sessionName || !spec.sessionId || !spec.channel) {
|
|
42
|
+
throw new Error('session target requires { sessionName, sessionId, channel }');
|
|
43
|
+
}
|
|
44
|
+
return { kind: 'session', sessionName: spec.sessionName, sessionId: spec.sessionId, channel: spec.channel };
|
|
45
|
+
}
|
|
46
|
+
if (spec.kind === 'thread') {
|
|
47
|
+
if (!spec.threadId || !spec.channel) {
|
|
48
|
+
throw new Error('thread target requires { threadId, channel }');
|
|
49
|
+
}
|
|
50
|
+
return { kind: 'thread', threadId: spec.threadId, channel: spec.channel };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`Unknown target spec: ${JSON.stringify(spec)}`);
|
|
54
|
+
}
|
|
55
|
+
// --- Day-of-week parsing (shared with schedule-cli) ---
|
|
56
|
+
const DAY_MAP = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 };
|
|
57
|
+
function parseDayOfWeek(value) {
|
|
58
|
+
if (typeof value === 'number')
|
|
59
|
+
return value;
|
|
60
|
+
if (/^\d+$/.test(value))
|
|
61
|
+
return Number(value);
|
|
62
|
+
const n = DAY_MAP[value.toLowerCase()];
|
|
63
|
+
if (n === undefined)
|
|
64
|
+
throw new Error(`invalid dayOfWeek: ${value}`);
|
|
65
|
+
return n;
|
|
66
|
+
}
|
|
67
|
+
function parseIntervalSpec(spec) {
|
|
68
|
+
if (typeof spec === 'number')
|
|
69
|
+
return spec;
|
|
70
|
+
const parsed = parseDuration(spec);
|
|
71
|
+
if (parsed)
|
|
72
|
+
return parsed;
|
|
73
|
+
if (/^\d+$/.test(spec))
|
|
74
|
+
return Number(spec);
|
|
75
|
+
throw new Error(`invalid interval: ${spec}`);
|
|
76
|
+
}
|
|
77
|
+
function parseDelaySpec(spec) {
|
|
78
|
+
return parseIntervalSpec(spec);
|
|
79
|
+
}
|
|
80
|
+
// --- Scheduler instance (no-op runners, no fs watcher; daemon will hot-reload) ---
|
|
81
|
+
function makeWriteOnlyScheduler() {
|
|
82
|
+
// Mirrors schedule-cli's pattern: a throwaway Scheduler used purely for its add() timing
|
|
83
|
+
// math + atomic write through the shared scheduleRepo singleton. The daemon's live
|
|
84
|
+
// Scheduler picks the new task up via fs.watch within ~300ms.
|
|
85
|
+
return new Scheduler(async () => { }, null, {}, { watchFile: false });
|
|
86
|
+
}
|
|
87
|
+
// --- Tool implementation: cortex_schedule_add ---
|
|
88
|
+
const targetSchema = z.union([
|
|
89
|
+
z.literal('fresh'),
|
|
90
|
+
z.literal('current-channel'),
|
|
91
|
+
z.literal('current-session'),
|
|
92
|
+
z.literal('current-thread'),
|
|
93
|
+
z.object({ kind: z.literal('fresh') }),
|
|
94
|
+
z.object({ kind: z.literal('channel'), channel: z.string() }),
|
|
95
|
+
z.object({ kind: z.literal('session'), sessionName: z.string(), sessionId: z.string(), channel: z.string() }),
|
|
96
|
+
z.object({ kind: z.literal('thread'), threadId: z.string(), channel: z.string() }),
|
|
97
|
+
]).optional();
|
|
98
|
+
const fallbackSchema = z.enum(['fresh', 'skip', 'wait']).optional();
|
|
99
|
+
const addInputShape = {
|
|
100
|
+
type: z.enum(['interval', 'daily', 'weekly', 'once']).describe('Schedule type'),
|
|
101
|
+
message: z.string().min(1).describe('Prompt to send when the schedule fires (no [Scheduled Task] prefix — added at fire time)'),
|
|
102
|
+
interval: z.union([z.string(), z.number()]).optional().describe('For type=interval: duration like "30s", "5m", "1h", "1d", or raw ms number'),
|
|
103
|
+
time: z.string().optional().describe('For type=daily/weekly: HH:MM 24-hour'),
|
|
104
|
+
dayOfWeek: z.union([z.string(), z.number()]).optional().describe('For type=weekly: 0-6 (0=Sun) or sun/mon/tue/wed/thu/fri/sat'),
|
|
105
|
+
delay: z.union([z.string(), z.number()]).optional().describe('For type=once: delay from now (duration string or ms)'),
|
|
106
|
+
target: targetSchema.describe('Where to land the fired task. Shorthand: "fresh" (default) | "current-channel" | "current-session" | "current-thread", or explicit { kind, ...ids }. __current__ shorthand is resolved to concrete IDs at create time.'),
|
|
107
|
+
fallback: fallbackSchema.describe('What to do if target session/thread is gone at fire time. fresh (default): silently fall back. skip: post one-line note, do not run. wait: not yet implemented (treated as fresh).'),
|
|
108
|
+
profile: z.string().optional().describe('Agent profile name (defaults to active profile)'),
|
|
109
|
+
preCheck: z.string().optional().describe('Optional shell command; non-zero exit → skip this fire. 15s timeout. Receives PRECHECK_LAST_RUN env var.'),
|
|
110
|
+
channel: z.string().optional().describe('Override the channel used for fresh-fallback. Defaults to current-context channel.'),
|
|
111
|
+
};
|
|
112
|
+
async function runScheduleAdd(input, deps) {
|
|
113
|
+
const ctxSnapshot = await resolveCortexContext(deps);
|
|
114
|
+
const target = resolveTargetShorthand(input.target, ctxSnapshot);
|
|
115
|
+
// Resolve channel: explicit > target.channel (when not fresh) > current-context channel.
|
|
116
|
+
let channel = input.channel ?? null;
|
|
117
|
+
if (!channel && target.kind !== 'fresh')
|
|
118
|
+
channel = target.channel;
|
|
119
|
+
if (!channel)
|
|
120
|
+
channel = ctxSnapshot.channel;
|
|
121
|
+
if (!channel)
|
|
122
|
+
throw new Error('No channel: pass --channel or run inside a context with SLACK_CHANNEL set.');
|
|
123
|
+
const scheduler = makeWriteOnlyScheduler();
|
|
124
|
+
let task;
|
|
125
|
+
try {
|
|
126
|
+
if (input.type === 'interval') {
|
|
127
|
+
if (input.interval === undefined)
|
|
128
|
+
throw new Error('interval is required for type=interval');
|
|
129
|
+
task = await scheduler.add('interval', {
|
|
130
|
+
intervalMs: parseIntervalSpec(input.interval),
|
|
131
|
+
message: input.message, channel, profile: input.profile ?? null, preCheck: input.preCheck,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else if (input.type === 'daily') {
|
|
135
|
+
if (!input.time)
|
|
136
|
+
throw new Error('time is required for type=daily');
|
|
137
|
+
task = await scheduler.add('daily', { time: input.time, message: input.message, channel, profile: input.profile ?? null, preCheck: input.preCheck });
|
|
138
|
+
}
|
|
139
|
+
else if (input.type === 'weekly') {
|
|
140
|
+
if (input.dayOfWeek === undefined)
|
|
141
|
+
throw new Error('dayOfWeek is required for type=weekly');
|
|
142
|
+
if (!input.time)
|
|
143
|
+
throw new Error('time is required for type=weekly');
|
|
144
|
+
task = await scheduler.add('weekly', {
|
|
145
|
+
dayOfWeek: parseDayOfWeek(input.dayOfWeek),
|
|
146
|
+
time: input.time, message: input.message, channel, profile: input.profile ?? null, preCheck: input.preCheck,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else { // once
|
|
150
|
+
if (input.delay === undefined)
|
|
151
|
+
throw new Error('delay is required for type=once');
|
|
152
|
+
task = await scheduler.add('once', {
|
|
153
|
+
delay: parseDelaySpec(input.delay),
|
|
154
|
+
message: input.message, channel, profile: input.profile ?? null, preCheck: input.preCheck,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
// Backfill target + fallback fields after add() so timing math (which doesn't know about them) ran first.
|
|
158
|
+
await scheduleRepo.updateTask(task.id, (t) => {
|
|
159
|
+
t.target = target;
|
|
160
|
+
if (input.fallback)
|
|
161
|
+
t.fallback = input.fallback;
|
|
162
|
+
});
|
|
163
|
+
const updated = await scheduleRepo.findTask(task.id);
|
|
164
|
+
return updated ?? task;
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
scheduler.stop();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// --- Tool registrations ---
|
|
171
|
+
export function registerScheduleTools(server, deps) {
|
|
172
|
+
server.tool('cortex_schedule_add', 'Create a scheduled task. Supports interval/daily/weekly/once. target shorthand "current-channel" | "current-session" | "current-thread" | "fresh" auto-resolves to concrete IDs against the running agent context — no need to call cortex_context first unless you need an explicit ID.', addInputShape, async (input) => {
|
|
173
|
+
try {
|
|
174
|
+
const result = await runScheduleAdd(input, deps);
|
|
175
|
+
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
return { content: [{ type: 'text', text: `Failed to add schedule: ${e.message}` }], isError: true };
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
server.tool('cortex_schedule_list', 'List all scheduled tasks. Returns id, type, message, channel, profile, target, nextRun, lastRun, isPaused.', { limit: z.number().int().positive().optional().describe('Max records to return (default 50).') }, { readOnlyHint: true }, async ({ limit }) => {
|
|
182
|
+
try {
|
|
183
|
+
const data = await scheduleRepo.read();
|
|
184
|
+
const max = limit ?? 50;
|
|
185
|
+
return { content: [{ type: 'text', text: JSON.stringify({ tasks: data.tasks.slice(0, max), totalCount: data.tasks.length }, null, 2) }] };
|
|
186
|
+
}
|
|
187
|
+
catch (e) {
|
|
188
|
+
return { content: [{ type: 'text', text: `Failed to list schedules: ${e.message}` }], isError: true };
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
server.tool('cortex_schedule_get', 'Look up a scheduled task by id.', { id: z.string().describe('Schedule task id (8-char hex from cortex_schedule_add).') }, { readOnlyHint: true }, async ({ id }) => {
|
|
192
|
+
try {
|
|
193
|
+
const task = await scheduleRepo.findTask(id);
|
|
194
|
+
if (!task)
|
|
195
|
+
return { content: [{ type: 'text', text: `No such schedule: ${id}` }], isError: true };
|
|
196
|
+
return { content: [{ type: 'text', text: JSON.stringify(task, null, 2) }] };
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
return { content: [{ type: 'text', text: `Failed to get schedule: ${e.message}` }], isError: true };
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
server.tool('cortex_schedule_remove', 'Delete a scheduled task by id. Idempotent — returns { removed: false } if no such id.', { id: z.string().describe('Schedule task id.') }, async ({ id }) => {
|
|
203
|
+
try {
|
|
204
|
+
const removed = await scheduleRepo.removeTask(id);
|
|
205
|
+
return { content: [{ type: 'text', text: JSON.stringify({ id, removed }, null, 2) }] };
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
return { content: [{ type: 'text', text: `Failed to remove schedule: ${e.message}` }], isError: true };
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
server.tool('cortex_schedule_pause', 'Pause a scheduled task (recurring only — once tasks cannot be paused). pausedBy is recorded as "user" so the rate-limit auto-resume path skips it.', { id: z.string().describe('Schedule task id.') }, async ({ id }) => {
|
|
212
|
+
try {
|
|
213
|
+
const scheduler = makeWriteOnlyScheduler();
|
|
214
|
+
try {
|
|
215
|
+
const task = await scheduler.pause(id, 'user');
|
|
216
|
+
if (!task)
|
|
217
|
+
return { content: [{ type: 'text', text: `No such schedule: ${id}` }], isError: true };
|
|
218
|
+
return { content: [{ type: 'text', text: JSON.stringify(task, null, 2) }] };
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
scheduler.stop();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
catch (e) {
|
|
225
|
+
return { content: [{ type: 'text', text: `Failed to pause schedule: ${e.message}` }], isError: true };
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
server.tool('cortex_schedule_resume', 'Resume a paused scheduled task. nextRun is recomputed.', { id: z.string().describe('Schedule task id.') }, async ({ id }) => {
|
|
229
|
+
try {
|
|
230
|
+
const scheduler = makeWriteOnlyScheduler();
|
|
231
|
+
try {
|
|
232
|
+
const task = await scheduler.resume(id);
|
|
233
|
+
if (!task)
|
|
234
|
+
return { content: [{ type: 'text', text: `No such schedule: ${id}` }], isError: true };
|
|
235
|
+
return { content: [{ type: 'text', text: JSON.stringify(task, null, 2) }] };
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
scheduler.stop();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
return { content: [{ type: 'text', text: `Failed to resume schedule: ${e.message}` }], isError: true };
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { WebClient } from '@slack/web-api';
|
|
3
|
+
export interface SlackToolDeps {
|
|
4
|
+
slack: WebClient | null;
|
|
5
|
+
fallbackChannel: string | undefined;
|
|
6
|
+
routeContextFile: string | null;
|
|
7
|
+
branchMachine: string | undefined;
|
|
8
|
+
callbackSource: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function uploadFileToSlack(slack: WebClient, { channel, filePath, fileName, title, initialComment }: {
|
|
11
|
+
channel: string;
|
|
12
|
+
filePath: string;
|
|
13
|
+
fileName?: string;
|
|
14
|
+
title?: string;
|
|
15
|
+
initialComment?: string;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
path: string;
|
|
18
|
+
fileName: string;
|
|
19
|
+
size: number;
|
|
20
|
+
}>;
|
|
21
|
+
export declare function registerSlackTools(server: McpServer, deps: SlackToolDeps): void;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// input: McpServer, Slack WebClient, route-context file path
|
|
2
|
+
// output: slack_send_file tool registration
|
|
3
|
+
// pos: MCP tool for uploading files to Slack
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { TokenBucketRateLimiter } from '../../../platform/utils/rate-limiter.js';
|
|
9
|
+
/** Per-process rate limiter for the MCP server's Slack API calls.
|
|
10
|
+
* The MCP server runs as a separate subprocess, so it maintains its own
|
|
11
|
+
* rate limiter state. Configure via the same CORTEX_SLACK_RL_* env vars. */
|
|
12
|
+
function createRateLimiter() {
|
|
13
|
+
return new TokenBucketRateLimiter({
|
|
14
|
+
globalCapacity: _envNum('CORTEX_SLACK_RL_GLOBAL_CAPACITY', 20),
|
|
15
|
+
globalRefillPerSec: _envNum('CORTEX_SLACK_RL_GLOBAL_REFILL_PER_SEC', 1),
|
|
16
|
+
perChannelCapacity: _envNum('CORTEX_SLACK_RL_CHANNEL_CAPACITY', 1),
|
|
17
|
+
perChannelRefillPerSec: _envNum('CORTEX_SLACK_RL_CHANNEL_REFILL_PER_SEC', 1),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function _envNum(key, def) {
|
|
21
|
+
const v = process.env[key];
|
|
22
|
+
return v ? Number(v) : def;
|
|
23
|
+
}
|
|
24
|
+
function readRouteContext(routeContextFile) {
|
|
25
|
+
if (!routeContextFile)
|
|
26
|
+
return null;
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(fs.readFileSync(routeContextFile, 'utf8'));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function withReplyPrefix(text, { branchMachine, callbackSource }) {
|
|
35
|
+
if (!text)
|
|
36
|
+
return text;
|
|
37
|
+
if (branchMachine)
|
|
38
|
+
return `:satellite: *[branch: ${branchMachine}]* ${text}`;
|
|
39
|
+
if (callbackSource)
|
|
40
|
+
return `:leftwards_arrow_with_hook: *[callback: ${callbackSource}]* ${text}`;
|
|
41
|
+
return text;
|
|
42
|
+
}
|
|
43
|
+
function resolveReadableFilePath(filePathInput) {
|
|
44
|
+
const resolved = path.isAbsolute(filePathInput)
|
|
45
|
+
? filePathInput
|
|
46
|
+
: path.resolve(process.cwd(), filePathInput);
|
|
47
|
+
if (!fs.existsSync(resolved)) {
|
|
48
|
+
throw new Error(`File not found: ${resolved}`);
|
|
49
|
+
}
|
|
50
|
+
const stat = fs.statSync(resolved);
|
|
51
|
+
if (!stat.isFile()) {
|
|
52
|
+
throw new Error(`Not a file: ${resolved}`);
|
|
53
|
+
}
|
|
54
|
+
return { resolved, size: stat.size };
|
|
55
|
+
}
|
|
56
|
+
/** Lazy-initialized per-process rate limiter for Slack API calls in the MCP server. */
|
|
57
|
+
let _rateLimiter = null;
|
|
58
|
+
export async function uploadFileToSlack(slack, { channel, filePath, fileName, title, initialComment }) {
|
|
59
|
+
const rl = _rateLimiter ?? (_rateLimiter = createRateLimiter());
|
|
60
|
+
const { resolved, size } = resolveReadableFilePath(filePath);
|
|
61
|
+
const body = fs.readFileSync(resolved);
|
|
62
|
+
const uploadName = fileName || path.basename(resolved);
|
|
63
|
+
if (initialComment) {
|
|
64
|
+
await rl.acquire('chat.postMessage', channel);
|
|
65
|
+
await slack.chat.postMessage({ channel, text: initialComment });
|
|
66
|
+
}
|
|
67
|
+
await rl.acquire('files.getUploadURLExternal', channel);
|
|
68
|
+
const uploadInit = await slack.files.getUploadURLExternal({
|
|
69
|
+
filename: uploadName,
|
|
70
|
+
length: size,
|
|
71
|
+
});
|
|
72
|
+
if (!uploadInit?.upload_url || !uploadInit?.file_id) {
|
|
73
|
+
throw new Error('Slack upload initialization failed: missing upload_url or file_id');
|
|
74
|
+
}
|
|
75
|
+
const uploadRes = await fetch(uploadInit.upload_url, {
|
|
76
|
+
method: 'POST',
|
|
77
|
+
headers: { 'Content-Type': 'application/octet-stream' },
|
|
78
|
+
body,
|
|
79
|
+
});
|
|
80
|
+
if (!uploadRes.ok) {
|
|
81
|
+
const errBody = await uploadRes.text().catch(() => '');
|
|
82
|
+
const suffix = errBody ? `: ${errBody.slice(0, 300)}` : '';
|
|
83
|
+
throw new Error(`Slack file upload failed (${uploadRes.status} ${uploadRes.statusText})${suffix}`);
|
|
84
|
+
}
|
|
85
|
+
await rl.acquire('files.completeUploadExternal', channel);
|
|
86
|
+
await slack.files.completeUploadExternal({
|
|
87
|
+
files: [{ id: uploadInit.file_id, title: title || uploadName }],
|
|
88
|
+
channel_id: channel,
|
|
89
|
+
});
|
|
90
|
+
return { path: resolved, fileName: uploadName, size };
|
|
91
|
+
}
|
|
92
|
+
export function registerSlackTools(server, deps) {
|
|
93
|
+
server.tool('slack_send_file', 'Upload a local file to Slack. Use this when you need to share a file (image, log, data, etc.) with the user.', {
|
|
94
|
+
file_path: z.string().describe('Local file path to upload'),
|
|
95
|
+
file_name: z.string().optional().describe('Optional filename override shown in Slack'),
|
|
96
|
+
title: z.string().optional().describe('Optional file title shown in Slack'),
|
|
97
|
+
comment: z.string().optional().describe('Optional comment to accompany the file'),
|
|
98
|
+
}, async ({ file_path, file_name, title, comment }) => {
|
|
99
|
+
try {
|
|
100
|
+
const routeCtx = readRouteContext(deps.routeContextFile);
|
|
101
|
+
const channel = routeCtx?.channel || deps.fallbackChannel;
|
|
102
|
+
if (!channel)
|
|
103
|
+
throw new Error('No routing channel available');
|
|
104
|
+
if (!deps.slack)
|
|
105
|
+
throw new Error('Missing SLACK_BOT_TOKEN');
|
|
106
|
+
const uploaded = await uploadFileToSlack(deps.slack, {
|
|
107
|
+
channel,
|
|
108
|
+
filePath: file_path,
|
|
109
|
+
fileName: file_name,
|
|
110
|
+
title,
|
|
111
|
+
initialComment: comment || undefined,
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
content: [{
|
|
115
|
+
type: 'text',
|
|
116
|
+
text: `File uploaded: ${uploaded.fileName} (${uploaded.size} bytes)`,
|
|
117
|
+
}],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
return { content: [{ type: 'text', text: `Failed to upload file: ${e.message}` }], isError: true };
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|