@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,509 @@
|
|
|
1
|
+
// input: McpServer, webhook proxy, image processing, diff sideband
|
|
2
|
+
// output: remote_bash/read/write/edit/glob/grep tool registrations
|
|
3
|
+
// pos: MCP tools for remote device operations via cortex-client
|
|
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 * as crypto from 'crypto';
|
|
9
|
+
import { pathToFileURL } from 'url';
|
|
10
|
+
import * as Diff from 'diff';
|
|
11
|
+
import { WORKSPACE_DIR } from '../../../core/utils.js';
|
|
12
|
+
import { cortexMDContentBlocks } from './cortex-md.js';
|
|
13
|
+
// Remote device commands proxied through app.ts webhook (separate process, no shared memory with client-manager)
|
|
14
|
+
const WEBHOOK_BASE = `http://127.0.0.1:${process.env.WEBHOOK_PORT || '3001'}`;
|
|
15
|
+
async function proxyGetOnlineDevices() {
|
|
16
|
+
const res = await fetch(`${WEBHOOK_BASE}/webhook/devices`);
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
return data.devices || [];
|
|
19
|
+
}
|
|
20
|
+
async function proxySendCommand(device, action, params, timeout) {
|
|
21
|
+
const res = await fetch(`${WEBHOOK_BASE}/webhook/remote-command`, {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: { 'Content-Type': 'application/json' },
|
|
24
|
+
body: JSON.stringify({ device, action, params, timeout }),
|
|
25
|
+
});
|
|
26
|
+
const data = await res.json();
|
|
27
|
+
if (!data.success)
|
|
28
|
+
throw new Error(data.error || 'Command failed');
|
|
29
|
+
return data.data;
|
|
30
|
+
}
|
|
31
|
+
async function deviceListDescription() {
|
|
32
|
+
const devices = await proxyGetOnlineDevices();
|
|
33
|
+
if (devices.length === 0)
|
|
34
|
+
return 'No devices currently online.';
|
|
35
|
+
return `Online devices: ${devices.join(', ')}`;
|
|
36
|
+
}
|
|
37
|
+
/** Cross-platform absolute-path check (server runs on Linux but validates paths for Windows clients). */
|
|
38
|
+
function isAbsoluteFilePath(p) {
|
|
39
|
+
if (path.isAbsolute(p))
|
|
40
|
+
return true;
|
|
41
|
+
// Windows absolute: D:\, D:/, etc.
|
|
42
|
+
if (/^[A-Za-z]:[/\\]/.test(p))
|
|
43
|
+
return true;
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
// --- Tool result persistence ---
|
|
47
|
+
// When tool output exceeds a character threshold, save full output to a local
|
|
48
|
+
// file and return a pointer + preview. Prevents context window explosion while
|
|
49
|
+
// keeping full results accessible via Read tool.
|
|
50
|
+
// remote_read excluded (Infinity) — self-bounds via word-count error on client.
|
|
51
|
+
const TOOL_RESULT_DIR = path.join(WORKSPACE_DIR, 'tool-results');
|
|
52
|
+
const RESULT_SIZE_THRESHOLDS = {
|
|
53
|
+
remote_bash: 30_000,
|
|
54
|
+
remote_grep: 20_000,
|
|
55
|
+
remote_glob: 100_000,
|
|
56
|
+
remote_edit: 100_000,
|
|
57
|
+
remote_write: 100_000,
|
|
58
|
+
remote_read: Infinity,
|
|
59
|
+
};
|
|
60
|
+
function persistLargeResult(toolName, text) {
|
|
61
|
+
const threshold = RESULT_SIZE_THRESHOLDS[toolName] ?? 30_000;
|
|
62
|
+
if (text.length <= threshold)
|
|
63
|
+
return text;
|
|
64
|
+
fs.mkdirSync(TOOL_RESULT_DIR, { recursive: true });
|
|
65
|
+
const id = `${toolName}-${Date.now()}-${crypto.randomBytes(4).toString('hex')}`;
|
|
66
|
+
const filePath = path.join(TOOL_RESULT_DIR, `${id}.txt`);
|
|
67
|
+
fs.writeFileSync(filePath, text, 'utf8');
|
|
68
|
+
const sizeKB = (text.length / 1024).toFixed(2);
|
|
69
|
+
const preview = text.slice(0, 2000);
|
|
70
|
+
return [
|
|
71
|
+
'<persisted-output>',
|
|
72
|
+
`Output too large (${sizeKB} KB). Full output saved to local file:`,
|
|
73
|
+
` ${filePath}`,
|
|
74
|
+
'',
|
|
75
|
+
'Preview (first 2 KB):',
|
|
76
|
+
preview,
|
|
77
|
+
'...',
|
|
78
|
+
'</persisted-output>',
|
|
79
|
+
].join('\n');
|
|
80
|
+
}
|
|
81
|
+
// --- Image processing pipeline ---
|
|
82
|
+
// sharp — optional image processing (resize/compress for token budget)
|
|
83
|
+
let sharpModule = null;
|
|
84
|
+
try {
|
|
85
|
+
sharpModule = (await import('sharp')).default;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// sharp not installed — image reads will pass through raw base64
|
|
89
|
+
}
|
|
90
|
+
const IMAGE_TOKEN_BUDGET = 25_000;
|
|
91
|
+
const IMAGE_MAX_LONG_SIDE = 1568;
|
|
92
|
+
function estimateTokens(base64Length) {
|
|
93
|
+
return Math.ceil(base64Length * 0.125);
|
|
94
|
+
}
|
|
95
|
+
async function processImage(rawBase64, mimeType, origWidth, origHeight) {
|
|
96
|
+
if (!sharpModule) {
|
|
97
|
+
return { data: rawBase64, mimeType, width: origWidth || 0, height: origHeight || 0 };
|
|
98
|
+
}
|
|
99
|
+
const inputBuf = Buffer.from(rawBase64, 'base64');
|
|
100
|
+
const meta = await sharpModule(inputBuf).metadata();
|
|
101
|
+
let w = meta.width || origWidth || 0;
|
|
102
|
+
let h = meta.height || origHeight || 0;
|
|
103
|
+
let currentMime = mimeType;
|
|
104
|
+
// Step 1: Standard resize — long side > 1568px → scale down
|
|
105
|
+
const longSide = Math.max(w, h);
|
|
106
|
+
let resizedBuf = inputBuf;
|
|
107
|
+
if (longSide > IMAGE_MAX_LONG_SIDE) {
|
|
108
|
+
const scale = IMAGE_MAX_LONG_SIDE / longSide;
|
|
109
|
+
w = Math.round(w * scale);
|
|
110
|
+
h = Math.round(h * scale);
|
|
111
|
+
resizedBuf = await sharpModule(inputBuf).resize(w, h, { fit: 'inside', withoutEnlargement: true }).toBuffer();
|
|
112
|
+
}
|
|
113
|
+
// Step 2: Initial encode
|
|
114
|
+
let outputBuf;
|
|
115
|
+
if (currentMime === 'image/png') {
|
|
116
|
+
outputBuf = await sharpModule(resizedBuf).png({ compressionLevel: 6 }).toBuffer();
|
|
117
|
+
}
|
|
118
|
+
else if (currentMime === 'image/webp') {
|
|
119
|
+
outputBuf = await sharpModule(resizedBuf).webp({ quality: 85 }).toBuffer();
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
outputBuf = await sharpModule(resizedBuf).jpeg({ quality: 85 }).toBuffer();
|
|
123
|
+
currentMime = 'image/jpeg';
|
|
124
|
+
}
|
|
125
|
+
let base64 = outputBuf.toString('base64');
|
|
126
|
+
let tokens = estimateTokens(base64.length);
|
|
127
|
+
// Step 3: Aggressive compression if over budget
|
|
128
|
+
if (tokens > IMAGE_TOKEN_BUDGET) {
|
|
129
|
+
// PNG → JPEG conversion first
|
|
130
|
+
if (currentMime === 'image/png' || currentMime === 'image/webp') {
|
|
131
|
+
outputBuf = await sharpModule(outputBuf).jpeg({ quality: 80 }).toBuffer();
|
|
132
|
+
currentMime = 'image/jpeg';
|
|
133
|
+
base64 = outputBuf.toString('base64');
|
|
134
|
+
tokens = estimateTokens(base64.length);
|
|
135
|
+
}
|
|
136
|
+
// Reduce quality iteratively
|
|
137
|
+
const qualitySteps = [70, 55, 40, 30];
|
|
138
|
+
for (const q of qualitySteps) {
|
|
139
|
+
if (tokens <= IMAGE_TOKEN_BUDGET)
|
|
140
|
+
break;
|
|
141
|
+
outputBuf = await sharpModule(resizedBuf)
|
|
142
|
+
.resize(w, h, { fit: 'inside', withoutEnlargement: true })
|
|
143
|
+
.jpeg({ quality: q })
|
|
144
|
+
.toBuffer();
|
|
145
|
+
currentMime = 'image/jpeg';
|
|
146
|
+
base64 = outputBuf.toString('base64');
|
|
147
|
+
tokens = estimateTokens(base64.length);
|
|
148
|
+
}
|
|
149
|
+
// Reduce dimensions if still over budget
|
|
150
|
+
const dimScaleSteps = [0.75, 0.5, 0.35];
|
|
151
|
+
for (const s of dimScaleSteps) {
|
|
152
|
+
if (tokens <= IMAGE_TOKEN_BUDGET)
|
|
153
|
+
break;
|
|
154
|
+
const newW = Math.round(w * s);
|
|
155
|
+
const newH = Math.round(h * s);
|
|
156
|
+
outputBuf = await sharpModule(inputBuf)
|
|
157
|
+
.resize(newW, newH, { fit: 'inside', withoutEnlargement: true })
|
|
158
|
+
.jpeg({ quality: 30 })
|
|
159
|
+
.toBuffer();
|
|
160
|
+
base64 = outputBuf.toString('base64');
|
|
161
|
+
tokens = estimateTokens(base64.length);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Final dimensions
|
|
165
|
+
const finalMeta = await sharpModule(outputBuf).metadata();
|
|
166
|
+
return {
|
|
167
|
+
data: base64,
|
|
168
|
+
mimeType: currentMime,
|
|
169
|
+
width: finalMeta.width || w,
|
|
170
|
+
height: finalMeta.height || h,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
// --- Diff marker sideband ---
|
|
174
|
+
//
|
|
175
|
+
// remote_write/remote_edit produce a diff payload (originalFile/structuredPatch/writtenContent)
|
|
176
|
+
// that the session-activity-tracker hook needs, but it's wasteful/harmful to put into the
|
|
177
|
+
// agent-visible tool_result content (can reach ~140 KB on large files, blowing the Claude Code
|
|
178
|
+
// 25k-token tool response limit). We persist it to a sideband file keyed by the Claude Code
|
|
179
|
+
// tool_use_id (available in the MCP request _meta as 'claudecode/toolUseId'), and the hook
|
|
180
|
+
// reads + unlinks by the same key. If toolUseId is absent (non-Claude-Code client), we fall
|
|
181
|
+
// back to the legacy inline text-block marker so functionality degrades gracefully.
|
|
182
|
+
const DIFF_MARKERS_DIR = path.join(WORKSPACE_DIR, 'diff-markers');
|
|
183
|
+
const DIFF_MARKERS_TTL_MS = 10 * 60 * 1000;
|
|
184
|
+
/** Build the diff payload (shared between sideband-file and legacy inline-block paths).
|
|
185
|
+
* Returns null when there is nothing to record (e.g. cortex-client returned nothing). */
|
|
186
|
+
function buildDiffPayload(device, filePath, tool, result) {
|
|
187
|
+
if (!result)
|
|
188
|
+
return null;
|
|
189
|
+
const degraded = !!(result.originalFileTruncated || result.newContentTruncated);
|
|
190
|
+
const originalFile = result.originalFile ?? null;
|
|
191
|
+
const newContent = result.newContent;
|
|
192
|
+
let structuredPatch = null;
|
|
193
|
+
let writtenContent = null;
|
|
194
|
+
if (!degraded && typeof newContent === 'string') {
|
|
195
|
+
if (tool === 'write')
|
|
196
|
+
writtenContent = newContent;
|
|
197
|
+
if (typeof originalFile === 'string') {
|
|
198
|
+
try {
|
|
199
|
+
// Cast required because @types/diff exposes both sync (ParsedDiff) and callback (void) overloads,
|
|
200
|
+
// and TS picks the latter when no options are provided.
|
|
201
|
+
const sp = Diff.structuredPatch(filePath, filePath, originalFile, newContent, '', '');
|
|
202
|
+
structuredPatch = sp.hunks;
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// structuredPatch failure leaves patch null; consumer treats as raw write
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (originalFile === null && tool === 'write') {
|
|
209
|
+
// Create-from-nothing: emit empty hunks; tracker uses writtenContent as full state.
|
|
210
|
+
structuredPatch = [];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return {
|
|
214
|
+
device,
|
|
215
|
+
file_path: filePath,
|
|
216
|
+
tool,
|
|
217
|
+
originalFile,
|
|
218
|
+
structuredPatch,
|
|
219
|
+
writtenContent,
|
|
220
|
+
degraded,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
/** Sanitize a toolUseId so it can't escape the sideband dir (defence in depth — Claude Code
|
|
224
|
+
* tool_use_ids are `toolu_<base64url>` but this makes the write safe even if that changes). */
|
|
225
|
+
function isSafeToolUseId(id) {
|
|
226
|
+
return typeof id === 'string' && id.length > 0 && id.length <= 128 && /^[A-Za-z0-9_-]+$/.test(id);
|
|
227
|
+
}
|
|
228
|
+
function sidebandPathFor(toolUseId) {
|
|
229
|
+
return path.join(DIFF_MARKERS_DIR, `${toolUseId}.json`);
|
|
230
|
+
}
|
|
231
|
+
/** Persist the diff payload to the sideband file keyed by toolUseId. Returns true on success
|
|
232
|
+
* (caller should skip emitting the legacy inline block). Silently returns false on any failure
|
|
233
|
+
* so the tool call itself is never broken by tracking bookkeeping. */
|
|
234
|
+
function persistDiffPayload(toolUseId, device, filePath, tool, result) {
|
|
235
|
+
const payload = buildDiffPayload(device, filePath, tool, result);
|
|
236
|
+
if (!payload)
|
|
237
|
+
return false;
|
|
238
|
+
try {
|
|
239
|
+
fs.mkdirSync(DIFF_MARKERS_DIR, { recursive: true });
|
|
240
|
+
const target = sidebandPathFor(toolUseId);
|
|
241
|
+
const tmp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
242
|
+
fs.writeFileSync(tmp, JSON.stringify(payload), 'utf8');
|
|
243
|
+
fs.renameSync(tmp, target);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** Legacy inline marker — retained as a fallback when toolUseId is unavailable. */
|
|
251
|
+
function inlineDiffMarkerBlock(device, filePath, tool, result) {
|
|
252
|
+
const payload = buildDiffPayload(device, filePath, tool, result);
|
|
253
|
+
if (!payload)
|
|
254
|
+
return null;
|
|
255
|
+
return { type: 'text', text: `<!--cortex-diff-data\n${JSON.stringify(payload)}\n-->` };
|
|
256
|
+
}
|
|
257
|
+
/** Remove stale sideband files (orphans from hook failures). Best-effort, swallows errors. */
|
|
258
|
+
function sweepStaleDiffMarkers() {
|
|
259
|
+
try {
|
|
260
|
+
if (!fs.existsSync(DIFF_MARKERS_DIR))
|
|
261
|
+
return;
|
|
262
|
+
const now = Date.now();
|
|
263
|
+
for (const name of fs.readdirSync(DIFF_MARKERS_DIR)) {
|
|
264
|
+
const p = path.join(DIFF_MARKERS_DIR, name);
|
|
265
|
+
try {
|
|
266
|
+
const st = fs.statSync(p);
|
|
267
|
+
if (!st.isFile())
|
|
268
|
+
continue;
|
|
269
|
+
if (now - st.mtimeMs > DIFF_MARKERS_TTL_MS)
|
|
270
|
+
fs.rmSync(p, { force: true });
|
|
271
|
+
}
|
|
272
|
+
catch { /* ignore */ }
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch { /* ignore */ }
|
|
276
|
+
}
|
|
277
|
+
sweepStaleDiffMarkers();
|
|
278
|
+
export function registerTaskOpsTools(server) {
|
|
279
|
+
// --- remote_bash ---
|
|
280
|
+
server.tool('remote_bash', 'Execute a shell command on a remote device via cortex-client. On Windows devices, commands run through git-bash.', {
|
|
281
|
+
device: z.string().describe('Target device name (e.g. "server", "workstation", "local")'),
|
|
282
|
+
command: z.string().describe('Shell command to execute'),
|
|
283
|
+
timeout: z.number().max(600000).optional().describe('Timeout in milliseconds (default: 120000, max: 600000)'),
|
|
284
|
+
description: z.string().optional().describe('Description of what the command does (for logging)'),
|
|
285
|
+
run_in_background: z.boolean().optional().describe('Run command in background, return PID immediately'),
|
|
286
|
+
}, async ({ device, command, timeout, description, run_in_background }) => {
|
|
287
|
+
try {
|
|
288
|
+
const effectiveTimeout = timeout || 120000;
|
|
289
|
+
const result = await proxySendCommand(device, 'bash', {
|
|
290
|
+
command, timeout: effectiveTimeout, run_in_background: run_in_background || false,
|
|
291
|
+
}, effectiveTimeout + 5000);
|
|
292
|
+
const parts = [];
|
|
293
|
+
if (result.stdout)
|
|
294
|
+
parts.push(result.stdout);
|
|
295
|
+
if (result.stderr)
|
|
296
|
+
parts.push(`[stderr]\n${result.stderr}`);
|
|
297
|
+
if (result.exitCode !== 0)
|
|
298
|
+
parts.push(`[exit code: ${result.exitCode}]`);
|
|
299
|
+
const rawText = parts.join('\n') || '(no output)';
|
|
300
|
+
const text = persistLargeResult('remote_bash', rawText);
|
|
301
|
+
const hasError = result.exitCode !== undefined && result.exitCode !== 0;
|
|
302
|
+
return { content: [{ type: 'text', text }], ...(hasError ? { isError: true } : {}) };
|
|
303
|
+
}
|
|
304
|
+
catch (e) {
|
|
305
|
+
return { content: [{ type: 'text', text: `remote_bash error: ${e.message}` }], isError: true };
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
// --- remote_read ---
|
|
309
|
+
server.tool('remote_read', 'Read a file from a remote device. Returns file contents with line numbers. Supports image files (PNG, JPEG, GIF, WebP, BMP) which are returned as inline images. Supports PDF files (.pdf) which are returned as inline documents. File path must be absolute.', {
|
|
310
|
+
device: z.string().describe('Target device name'),
|
|
311
|
+
file_path: z.string().describe('Absolute path to the file to read'),
|
|
312
|
+
offset: z.number().optional().describe('Line number to start reading from (0-based)'),
|
|
313
|
+
limit: z.number().optional().describe('Number of lines to read'),
|
|
314
|
+
}, { readOnlyHint: true }, async ({ device, file_path, offset, limit }) => {
|
|
315
|
+
try {
|
|
316
|
+
if (!isAbsoluteFilePath(file_path)) {
|
|
317
|
+
return { content: [{ type: 'text', text: 'file_path must be absolute' }], isError: true };
|
|
318
|
+
}
|
|
319
|
+
const result = await proxySendCommand(device, 'read', { file_path, offset, limit });
|
|
320
|
+
const cmdBlocks = cortexMDContentBlocks(device, result.cortexMDs, file_path);
|
|
321
|
+
// Image response path
|
|
322
|
+
if (result.image) {
|
|
323
|
+
const { data, mimeType, width, height, originalSize } = result.image;
|
|
324
|
+
try {
|
|
325
|
+
const processed = await processImage(data, mimeType, width, height);
|
|
326
|
+
const tokens = estimateTokens(processed.data.length);
|
|
327
|
+
const metaParts = [
|
|
328
|
+
`Image: ${file_path}`,
|
|
329
|
+
`Original: ${width || '?'}x${height || '?'} ${mimeType} (${(originalSize / 1024).toFixed(1)} KB)`,
|
|
330
|
+
];
|
|
331
|
+
if (processed.width !== width || processed.height !== height || processed.mimeType !== mimeType) {
|
|
332
|
+
metaParts.push(`Processed: ${processed.width}x${processed.height} ${processed.mimeType} (~${tokens} tokens)`);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
metaParts.push(`~${tokens} tokens`);
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
content: [
|
|
339
|
+
{ type: 'text', text: metaParts.join('\n') },
|
|
340
|
+
{ type: 'image', data: processed.data, mimeType: processed.mimeType },
|
|
341
|
+
...cmdBlocks,
|
|
342
|
+
],
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
catch (imgErr) {
|
|
346
|
+
return {
|
|
347
|
+
content: [
|
|
348
|
+
{
|
|
349
|
+
type: 'text',
|
|
350
|
+
text: `Image detected (${mimeType}, ${width || '?'}x${height || '?'}, ${(originalSize / 1024).toFixed(1)} KB) but processing failed: ${imgErr.message}`,
|
|
351
|
+
},
|
|
352
|
+
...cmdBlocks,
|
|
353
|
+
],
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// PDF response path — return as EmbeddedResource blob
|
|
358
|
+
if (result.pdf) {
|
|
359
|
+
const { data, originalSize } = result.pdf;
|
|
360
|
+
return {
|
|
361
|
+
content: [
|
|
362
|
+
{ type: 'text', text: `PDF: ${file_path} (${(originalSize / 1024).toFixed(1)} KB)` },
|
|
363
|
+
{
|
|
364
|
+
type: 'resource',
|
|
365
|
+
resource: {
|
|
366
|
+
uri: pathToFileURL(file_path).href,
|
|
367
|
+
mimeType: 'application/pdf',
|
|
368
|
+
blob: data,
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
...cmdBlocks,
|
|
372
|
+
],
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
// Text response path
|
|
376
|
+
return { content: [{ type: 'text', text: result.content || '(empty file)' }, ...cmdBlocks] };
|
|
377
|
+
}
|
|
378
|
+
catch (e) {
|
|
379
|
+
return { content: [{ type: 'text', text: `remote_read error: ${e.message}` }], isError: true };
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
// --- remote_write ---
|
|
383
|
+
server.tool('remote_write', 'Write content to a file on a remote device. Creates parent directories if needed. File path must be absolute.', {
|
|
384
|
+
device: z.string().describe('Target device name'),
|
|
385
|
+
file_path: z.string().describe('Absolute path to the file to write'),
|
|
386
|
+
content: z.string().describe('Content to write to the file'),
|
|
387
|
+
}, async ({ device, file_path, content }, extra) => {
|
|
388
|
+
try {
|
|
389
|
+
if (!isAbsoluteFilePath(file_path)) {
|
|
390
|
+
return { content: [{ type: 'text', text: 'file_path must be absolute' }], isError: true };
|
|
391
|
+
}
|
|
392
|
+
const result = await proxySendCommand(device, 'write', { file_path, content });
|
|
393
|
+
const cmdBlocks = cortexMDContentBlocks(device, result?.cortexMDs, file_path);
|
|
394
|
+
const blocks = [{ type: 'text', text: `File written: ${file_path}` }];
|
|
395
|
+
const toolUseId = extra?._meta?.['claudecode/toolUseId'];
|
|
396
|
+
const persisted = isSafeToolUseId(toolUseId)
|
|
397
|
+
? persistDiffPayload(toolUseId, device, file_path, 'write', result)
|
|
398
|
+
: false;
|
|
399
|
+
if (!persisted) {
|
|
400
|
+
// Legacy fallback: inline text marker for non-Claude-Code clients (or if persistence failed).
|
|
401
|
+
const diffBlock = inlineDiffMarkerBlock(device, file_path, 'write', result);
|
|
402
|
+
if (diffBlock)
|
|
403
|
+
blocks.push(diffBlock);
|
|
404
|
+
}
|
|
405
|
+
blocks.push(...cmdBlocks);
|
|
406
|
+
return { content: blocks };
|
|
407
|
+
}
|
|
408
|
+
catch (e) {
|
|
409
|
+
return { content: [{ type: 'text', text: `remote_write error: ${e.message}` }], isError: true };
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
// --- remote_edit ---
|
|
413
|
+
server.tool('remote_edit', 'Edit a file on a remote device by replacing a string. The old_string must be unique in the file (unless replace_all is true). File path must be absolute.', {
|
|
414
|
+
device: z.string().describe('Target device name'),
|
|
415
|
+
file_path: z.string().describe('Absolute path to the file to edit'),
|
|
416
|
+
old_string: z.string().describe('The text to replace'),
|
|
417
|
+
new_string: z.string().describe('The replacement text'),
|
|
418
|
+
replace_all: z.boolean().optional().describe('Replace all occurrences (default: false)'),
|
|
419
|
+
}, async ({ device, file_path, old_string, new_string, replace_all }, extra) => {
|
|
420
|
+
try {
|
|
421
|
+
if (!isAbsoluteFilePath(file_path)) {
|
|
422
|
+
return { content: [{ type: 'text', text: 'file_path must be absolute' }], isError: true };
|
|
423
|
+
}
|
|
424
|
+
const result = await proxySendCommand(device, 'edit', { file_path, old_string, new_string, replace_all: replace_all || false });
|
|
425
|
+
const cmdBlocks = cortexMDContentBlocks(device, result?.cortexMDs, file_path);
|
|
426
|
+
const blocks = [{ type: 'text', text: `File edited: ${file_path}` }];
|
|
427
|
+
const toolUseId = extra?._meta?.['claudecode/toolUseId'];
|
|
428
|
+
const persisted = isSafeToolUseId(toolUseId)
|
|
429
|
+
? persistDiffPayload(toolUseId, device, file_path, 'edit', result)
|
|
430
|
+
: false;
|
|
431
|
+
if (!persisted) {
|
|
432
|
+
const diffBlock = inlineDiffMarkerBlock(device, file_path, 'edit', result);
|
|
433
|
+
if (diffBlock)
|
|
434
|
+
blocks.push(diffBlock);
|
|
435
|
+
}
|
|
436
|
+
blocks.push(...cmdBlocks);
|
|
437
|
+
return { content: blocks };
|
|
438
|
+
}
|
|
439
|
+
catch (e) {
|
|
440
|
+
return { content: [{ type: 'text', text: `remote_edit error: ${e.message}` }], isError: true };
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
// --- remote_glob ---
|
|
444
|
+
server.tool('remote_glob', 'Find files matching a glob pattern on a remote device. Returns a list of matching file paths.', {
|
|
445
|
+
device: z.string().describe('Target device name'),
|
|
446
|
+
pattern: z.string().describe('Glob pattern to match files against'),
|
|
447
|
+
path: z.string().optional().describe('Directory to search in (absolute path)'),
|
|
448
|
+
}, { readOnlyHint: true }, async ({ device, pattern, path: searchPath }) => {
|
|
449
|
+
try {
|
|
450
|
+
const result = await proxySendCommand(device, 'glob', { pattern, path: searchPath });
|
|
451
|
+
const files = result.files || [];
|
|
452
|
+
if (files.length === 0) {
|
|
453
|
+
return { content: [{ type: 'text', text: 'No files matched the pattern.' }] };
|
|
454
|
+
}
|
|
455
|
+
let output = files.join('\n');
|
|
456
|
+
if (result.truncated) {
|
|
457
|
+
output += `\n[... truncated at ${files.length} results]`;
|
|
458
|
+
}
|
|
459
|
+
const text = persistLargeResult('remote_glob', output);
|
|
460
|
+
return { content: [{ type: 'text', text }] };
|
|
461
|
+
}
|
|
462
|
+
catch (e) {
|
|
463
|
+
return { content: [{ type: 'text', text: `remote_glob error: ${e.message}` }], isError: true };
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
// --- remote_grep ---
|
|
467
|
+
server.tool('remote_grep', 'Search file contents on a remote device using ripgrep. Returns matching lines or file paths.', {
|
|
468
|
+
device: z.string().describe('Target device name'),
|
|
469
|
+
pattern: z.string().describe('Regex pattern to search for'),
|
|
470
|
+
path: z.string().optional().describe('File or directory to search in'),
|
|
471
|
+
glob: z.string().optional().describe('Glob pattern to filter files (e.g. "*.ts", "*.{ts,tsx}")'),
|
|
472
|
+
type: z.string().optional().describe('File type to search (e.g. "js", "py", "rust")'),
|
|
473
|
+
output_mode: z.enum(['content', 'files_with_matches', 'count']).optional().describe('Output mode (default: files_with_matches)'),
|
|
474
|
+
'-A': z.number().optional().describe('Lines to show after each match'),
|
|
475
|
+
'-B': z.number().optional().describe('Lines to show before each match'),
|
|
476
|
+
'-C': z.number().optional().describe('Context lines before and after each match'),
|
|
477
|
+
context: z.number().optional().describe('Alias for -C'),
|
|
478
|
+
'-i': z.boolean().optional().describe('Case insensitive search'),
|
|
479
|
+
'-n': z.boolean().optional().describe('Show line numbers (default: true for content mode)'),
|
|
480
|
+
head_limit: z.number().optional().describe('Limit output entries (default: 250, 0 for unlimited)'),
|
|
481
|
+
offset: z.number().optional().describe('Skip first N entries before applying head_limit'),
|
|
482
|
+
multiline: z.boolean().optional().describe('Enable multiline matching (pattern can span lines)'),
|
|
483
|
+
}, { readOnlyHint: true }, async ({ device, pattern, path: searchPath, glob: globFilter, type, output_mode, context: ctxLines, head_limit, offset, multiline, ...flags }) => {
|
|
484
|
+
try {
|
|
485
|
+
const result = await proxySendCommand(device, 'grep', {
|
|
486
|
+
pattern,
|
|
487
|
+
path: searchPath,
|
|
488
|
+
glob: globFilter,
|
|
489
|
+
type,
|
|
490
|
+
output_mode,
|
|
491
|
+
'-A': flags['-A'],
|
|
492
|
+
'-B': flags['-B'],
|
|
493
|
+
'-C': flags['-C'],
|
|
494
|
+
context: ctxLines,
|
|
495
|
+
'-i': flags['-i'],
|
|
496
|
+
'-n': flags['-n'],
|
|
497
|
+
head_limit,
|
|
498
|
+
offset,
|
|
499
|
+
multiline,
|
|
500
|
+
});
|
|
501
|
+
const rawText = result.output || '(no matches)';
|
|
502
|
+
const text = persistLargeResult('remote_grep', rawText);
|
|
503
|
+
return { content: [{ type: 'text', text }] };
|
|
504
|
+
}
|
|
505
|
+
catch (e) {
|
|
506
|
+
return { content: [{ type: 'text', text: `remote_grep error: ${e.message}` }], isError: true };
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import type { TuiToolDeps, CallToolResultShape } from './tui-plan.js';
|
|
3
|
+
/**
|
|
4
|
+
* Schema mirrors the native AskUserQuestion / PI ask_user_question shape (see
|
|
5
|
+
* agent-adapter/pi/tool-shims.ts:26-45) so the LLM produces identical output regardless of
|
|
6
|
+
* backend: a list of 1-4 questions, each with header / question / options[{label,description}] /
|
|
7
|
+
* multiSelect. This shape is also what /hook/ask-user-question consumes and what
|
|
8
|
+
* jsonl-tail.ts's normalizer expects — keeping all three aligned removes per-backend branches.
|
|
9
|
+
*/
|
|
10
|
+
interface AskUserOption {
|
|
11
|
+
label: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
14
|
+
interface AskUserQuestion {
|
|
15
|
+
question: string;
|
|
16
|
+
header?: string;
|
|
17
|
+
options?: AskUserOption[];
|
|
18
|
+
multiSelect?: boolean;
|
|
19
|
+
}
|
|
20
|
+
interface AskUserArgs {
|
|
21
|
+
questions: AskUserQuestion[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Webhook response contract (see orch/interactions/ask-user-question.ts:117-148):
|
|
25
|
+
* - Success: { answers: { [questionText]: <stringified value> } }
|
|
26
|
+
* (multi-select values are pre-joined with ", " by the platform)
|
|
27
|
+
* - Error: { error: <code>, answers: {} } (codes: 'timeout' | 'post_failed' | 'bus_not_initialized')
|
|
28
|
+
*/
|
|
29
|
+
export declare function runAskUser(args: AskUserArgs, deps: TuiToolDeps): Promise<CallToolResultShape>;
|
|
30
|
+
export declare function registerTuiAskTools(server: McpServer, deps: TuiToolDeps): void;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// input: McpServer + TuiToolDeps (channel/sessionId/threadId/webhookBaseUrl/httpPost)
|
|
2
|
+
// output: registerTuiAskTools + pure runAskUser business-logic function
|
|
3
|
+
// pos: DR-0012 Phase 3 — cortex-tui-bridge MCP tool replacing AskUserQuestion for TUI mode
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
/**
|
|
7
|
+
* Webhook response contract (see orch/interactions/ask-user-question.ts:117-148):
|
|
8
|
+
* - Success: { answers: { [questionText]: <stringified value> } }
|
|
9
|
+
* (multi-select values are pre-joined with ", " by the platform)
|
|
10
|
+
* - Error: { error: <code>, answers: {} } (codes: 'timeout' | 'post_failed' | 'bus_not_initialized')
|
|
11
|
+
*/
|
|
12
|
+
export async function runAskUser(args, deps) {
|
|
13
|
+
if (!deps.channel) {
|
|
14
|
+
return { content: [{ type: 'text', text: 'cortex_ask_user error: no channel configured in MCP env (SLACK_CHANNEL missing)' }], isError: true };
|
|
15
|
+
}
|
|
16
|
+
const questions = Array.isArray(args.questions) ? args.questions : [];
|
|
17
|
+
if (questions.length === 0) {
|
|
18
|
+
return { content: [{ type: 'text', text: 'cortex_ask_user error: at least one question is required' }], isError: true };
|
|
19
|
+
}
|
|
20
|
+
for (const q of questions) {
|
|
21
|
+
if (!q || typeof q.question !== 'string' || !q.question.trim()) {
|
|
22
|
+
return { content: [{ type: 'text', text: 'cortex_ask_user error: every question must have a non-empty `question` field' }], isError: true };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Normalize each question to the shape /hook/ask-user-question consumes
|
|
26
|
+
// (createHookGroup at orch/interactions/ask-user-question.ts:88-94 reads
|
|
27
|
+
// header / question / options[{label, description}] / multiSelect).
|
|
28
|
+
const normalizedQuestions = questions.map((q) => {
|
|
29
|
+
const entry = {
|
|
30
|
+
question: q.question,
|
|
31
|
+
header: q.header ?? q.question.slice(0, 12),
|
|
32
|
+
multiSelect: !!q.multiSelect,
|
|
33
|
+
};
|
|
34
|
+
if (Array.isArray(q.options) && q.options.length > 0) {
|
|
35
|
+
entry.options = q.options.map((o) => ({
|
|
36
|
+
label: typeof o === 'string' ? o : o.label,
|
|
37
|
+
description: typeof o === 'string' ? undefined : o.description,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
entry.options = [];
|
|
42
|
+
}
|
|
43
|
+
return entry;
|
|
44
|
+
});
|
|
45
|
+
const body = {
|
|
46
|
+
sessionId: deps.sessionId,
|
|
47
|
+
channel: deps.channel,
|
|
48
|
+
questions: normalizedQuestions,
|
|
49
|
+
threadId: deps.threadId,
|
|
50
|
+
};
|
|
51
|
+
let resp;
|
|
52
|
+
try {
|
|
53
|
+
resp = await deps.httpPost(`${deps.webhookBaseUrl}/hook/ask-user-question`, body);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
return { content: [{ type: 'text', text: `cortex_ask_user error: webhook call failed: ${e.message}` }], isError: true };
|
|
57
|
+
}
|
|
58
|
+
if (resp.status !== 200) {
|
|
59
|
+
const detail = resp.body?.error ?? JSON.stringify(resp.body ?? {});
|
|
60
|
+
return { content: [{ type: 'text', text: `cortex_ask_user error: webhook returned status ${resp.status}: ${detail}` }], isError: true };
|
|
61
|
+
}
|
|
62
|
+
// Explicit error/timeout from the bridge — surface to the assistant so it can decide what to do.
|
|
63
|
+
const errorCode = typeof resp.body?.error === 'string' ? resp.body.error : null;
|
|
64
|
+
if (errorCode === 'timeout') {
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: 'text', text: 'cortex_ask_user: user did not respond within the approval window. Proceed with reasonable defaults or restate the question.' }],
|
|
67
|
+
isError: true,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (errorCode) {
|
|
71
|
+
return {
|
|
72
|
+
content: [{ type: 'text', text: `cortex_ask_user error: ${errorCode}` }],
|
|
73
|
+
isError: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// answers is a dict keyed by question text — { [questionText]: <stringified value> }.
|
|
77
|
+
const answersDict = resp.body?.answers;
|
|
78
|
+
if (!answersDict || typeof answersDict !== 'object' || Array.isArray(answersDict)) {
|
|
79
|
+
return { content: [{ type: 'text', text: 'cortex_ask_user: empty or malformed answers payload from approval bridge' }], isError: true };
|
|
80
|
+
}
|
|
81
|
+
const collected = [];
|
|
82
|
+
for (const q of questions) {
|
|
83
|
+
const v = answersDict[q.question];
|
|
84
|
+
if (v === undefined || v === null || v === '') {
|
|
85
|
+
collected.push(`Q: ${q.question}\nA: (no answer)`);
|
|
86
|
+
}
|
|
87
|
+
else if (Array.isArray(v)) {
|
|
88
|
+
collected.push(`Q: ${q.question}\nA: ${v.join(', ')}`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
collected.push(`Q: ${q.question}\nA: ${String(v)}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { content: [{ type: 'text', text: collected.join('\n\n') }] };
|
|
95
|
+
}
|
|
96
|
+
export function registerTuiAskTools(server, deps) {
|
|
97
|
+
server.tool('cortex_ask_user', 'Ask the human one or more clarifying questions and BLOCK until they answer (replaces native AskUserQuestion). Posts each question via a Slack modal with optional multiple-choice options. Use this when you need clarification, a decision, or a choice from the user. Supply 1-4 questions per call. Set `multiSelect=true` on a question to allow multi-pick. The answers are returned in the tool_result.', {
|
|
98
|
+
questions: z.array(z.object({
|
|
99
|
+
question: z.string().describe('The complete question to ask the user.'),
|
|
100
|
+
header: z.string().optional().describe('Very short label (max 12 chars), e.g. "Auth method", "Library". Falls back to a trimmed question prefix.'),
|
|
101
|
+
options: z.array(z.object({
|
|
102
|
+
label: z.string().describe('Display text for this option.'),
|
|
103
|
+
description: z.string().optional().describe('Optional explanation of what this option means.'),
|
|
104
|
+
})).optional().describe('Optional multiple-choice options. Omit for free-text answer.'),
|
|
105
|
+
multiSelect: z.boolean().optional().describe('If true, the user may select multiple options (default false).'),
|
|
106
|
+
})).min(1).max(4).describe('Questions to ask (1-4 questions).'),
|
|
107
|
+
}, {}, async (args) => (await runAskUser(args, deps)));
|
|
108
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
/** Per-process injection point for tests. Production binds httpPost to global fetch. */
|
|
3
|
+
export interface TuiToolDeps {
|
|
4
|
+
channel: string | null;
|
|
5
|
+
sessionId: string | null;
|
|
6
|
+
threadId: string | null;
|
|
7
|
+
webhookBaseUrl: string;
|
|
8
|
+
httpPost: (url: string, body: any) => Promise<{
|
|
9
|
+
status: number;
|
|
10
|
+
body: any;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
/** Shape of an MCP CallToolResult — kept structural to avoid importing SDK types into test files. */
|
|
14
|
+
export interface CallToolResultShape {
|
|
15
|
+
content: Array<{
|
|
16
|
+
type: 'text';
|
|
17
|
+
text: string;
|
|
18
|
+
}>;
|
|
19
|
+
isError?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function runPlanEnter(args: {
|
|
22
|
+
reasoning?: string;
|
|
23
|
+
}): CallToolResultShape;
|
|
24
|
+
export declare function runPlanExit(args: {
|
|
25
|
+
plan_file_path: string;
|
|
26
|
+
summary?: string;
|
|
27
|
+
}, deps: TuiToolDeps): Promise<CallToolResultShape>;
|
|
28
|
+
export declare function registerTuiPlanTools(server: McpServer, deps: TuiToolDeps): void;
|