@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,120 @@
|
|
|
1
|
+
// input: ./types.js (RichBlock/ModalDefinition/ActionElement)
|
|
2
|
+
// output: Question types + buildQuestion*/buildPlan* builders
|
|
3
|
+
// pos: Platform-independent interactive component builder
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
// --- AskUserQuestion builders ---
|
|
6
|
+
export function buildQuestionGroupBlocks(group) {
|
|
7
|
+
const blocks = [];
|
|
8
|
+
const allAnswered = group.answers.size === group.questions.length;
|
|
9
|
+
for (const [qIdx, q] of group.questions.entries()) {
|
|
10
|
+
if (qIdx > 0)
|
|
11
|
+
blocks.push({ type: 'divider' });
|
|
12
|
+
blocks.push({ type: 'section', text: `*${q.header}*\n${q.question}` });
|
|
13
|
+
const answer = group.answers.get(q.pendingId);
|
|
14
|
+
if (answer) {
|
|
15
|
+
const formatted = Array.isArray(answer.value) ? `[${answer.value.join(', ')}]` : answer.value;
|
|
16
|
+
blocks.push({ type: 'context', text: `:white_check_mark: ${formatted}` });
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const optionsList = q.options.map(o => o.label).join(' · ');
|
|
20
|
+
blocks.push({ type: 'context', text: `_${optionsList}_` });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!allAnswered) {
|
|
24
|
+
blocks.push({
|
|
25
|
+
type: 'actions',
|
|
26
|
+
elements: [{
|
|
27
|
+
type: 'button',
|
|
28
|
+
text: `Answer (${group.answers.size}/${group.questions.length})`,
|
|
29
|
+
actionId: 'ask_user_question_open_modal',
|
|
30
|
+
value: group.groupId,
|
|
31
|
+
style: 'primary',
|
|
32
|
+
}],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return blocks;
|
|
36
|
+
}
|
|
37
|
+
export function buildQuestionModalDefinition(group) {
|
|
38
|
+
const fields = [];
|
|
39
|
+
for (const [qIdx, q] of group.questions.entries()) {
|
|
40
|
+
let questionText = `*${q.header}*\n${q.question}`;
|
|
41
|
+
if (q.options.some(o => o.description)) {
|
|
42
|
+
for (const option of q.options) {
|
|
43
|
+
if (option.description)
|
|
44
|
+
questionText += `\n• *${option.label}*: ${option.description}`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
fields.push({ type: 'section', text: questionText });
|
|
48
|
+
// Only add select field when there are options — Slack rejects empty option lists.
|
|
49
|
+
if (q.options.length > 0) {
|
|
50
|
+
fields.push({
|
|
51
|
+
type: q.multiSelect ? 'multi_select' : 'select',
|
|
52
|
+
blockId: `q_${qIdx}`,
|
|
53
|
+
label: q.multiSelect ? 'Select one or more' : 'Select one',
|
|
54
|
+
actionId: 'selection',
|
|
55
|
+
placeholder: q.multiSelect ? 'Select one or more' : 'Select one',
|
|
56
|
+
options: q.options.map((option, optIdx) => ({
|
|
57
|
+
label: option.label,
|
|
58
|
+
value: String(optIdx),
|
|
59
|
+
})),
|
|
60
|
+
optional: true,
|
|
61
|
+
});
|
|
62
|
+
fields.push({
|
|
63
|
+
type: 'text_input',
|
|
64
|
+
blockId: `q_${qIdx}_other`,
|
|
65
|
+
label: 'Or type your answer',
|
|
66
|
+
actionId: 'other_text',
|
|
67
|
+
placeholder: 'Custom answer (overrides selection above)',
|
|
68
|
+
optional: true,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Free-form text only — no select, text_input is required.
|
|
73
|
+
fields.push({
|
|
74
|
+
type: 'text_input',
|
|
75
|
+
blockId: `q_${qIdx}_other`,
|
|
76
|
+
label: 'Your answer',
|
|
77
|
+
actionId: 'other_text',
|
|
78
|
+
placeholder: 'Type your answer',
|
|
79
|
+
optional: false,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
callbackId: 'ask_user_question_modal_submit',
|
|
85
|
+
title: 'Questions',
|
|
86
|
+
submitLabel: 'Submit',
|
|
87
|
+
closeLabel: 'Cancel',
|
|
88
|
+
privateMetadata: JSON.stringify({ groupId: group.groupId }),
|
|
89
|
+
fields,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// --- Plan approval builders ---
|
|
93
|
+
export function buildPlanApprovalContent(requestId) {
|
|
94
|
+
return {
|
|
95
|
+
richBlocks: [
|
|
96
|
+
{ type: 'section', text: ':memo: *Plan ready for review.* Approve to proceed or provide feedback.' },
|
|
97
|
+
],
|
|
98
|
+
actions: [
|
|
99
|
+
{ type: 'button', text: 'Approve', actionId: 'hook_plan_approve', value: requestId, style: 'primary' },
|
|
100
|
+
{ type: 'button', text: 'Provide Feedback', actionId: 'hook_plan_feedback', value: requestId },
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function buildPlanFeedbackModal(requestId) {
|
|
105
|
+
return {
|
|
106
|
+
callbackId: 'hook_plan_feedback_submit',
|
|
107
|
+
title: 'Plan Feedback',
|
|
108
|
+
submitLabel: 'Submit',
|
|
109
|
+
closeLabel: 'Cancel',
|
|
110
|
+
privateMetadata: JSON.stringify({ requestId }),
|
|
111
|
+
fields: [{
|
|
112
|
+
type: 'text_input',
|
|
113
|
+
blockId: 'feedback',
|
|
114
|
+
label: 'Your feedback (Cortex will revise the plan)',
|
|
115
|
+
actionId: 'text',
|
|
116
|
+
multiline: true,
|
|
117
|
+
placeholder: 'What should be changed?',
|
|
118
|
+
}],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { PlatformAdapter } from './adapter.js';
|
|
2
|
+
import type { MessageRef, MessageContent, MessageContext, MessageEditContext, ActionContext, ModalSubmitContext, ModalDefinition, ModalFieldValue, PlatformCapabilities, PlatformFileRef, DownloadedFile, PostMessageOpts, FileUploadOpts, ActionElement } from './types.js';
|
|
3
|
+
export interface PostedMessage {
|
|
4
|
+
channel: string;
|
|
5
|
+
content: MessageContent;
|
|
6
|
+
threadId?: string;
|
|
7
|
+
actions?: ActionElement[];
|
|
8
|
+
}
|
|
9
|
+
export interface UpdatedMessage {
|
|
10
|
+
ref: MessageRef;
|
|
11
|
+
content: MessageContent;
|
|
12
|
+
}
|
|
13
|
+
export interface DeletedMessage {
|
|
14
|
+
ref: MessageRef;
|
|
15
|
+
}
|
|
16
|
+
export interface AddedReaction {
|
|
17
|
+
ref: MessageRef;
|
|
18
|
+
emoji: string;
|
|
19
|
+
}
|
|
20
|
+
export interface UploadedFile {
|
|
21
|
+
channel: string;
|
|
22
|
+
filePath: string;
|
|
23
|
+
opts?: FileUploadOpts;
|
|
24
|
+
}
|
|
25
|
+
export interface OpenedModal {
|
|
26
|
+
triggerId: string;
|
|
27
|
+
modal: ModalDefinition;
|
|
28
|
+
}
|
|
29
|
+
export interface EphemeralMessage {
|
|
30
|
+
channel: string;
|
|
31
|
+
userId: string;
|
|
32
|
+
text: string;
|
|
33
|
+
}
|
|
34
|
+
export declare class MockAdapter implements PlatformAdapter {
|
|
35
|
+
readonly name = "mock";
|
|
36
|
+
readonly capabilities: PlatformCapabilities;
|
|
37
|
+
posted: PostedMessage[];
|
|
38
|
+
updated: UpdatedMessage[];
|
|
39
|
+
deleted: DeletedMessage[];
|
|
40
|
+
reactions: AddedReaction[];
|
|
41
|
+
uploads: UploadedFile[];
|
|
42
|
+
modals: OpenedModal[];
|
|
43
|
+
ephemeralMessages: EphemeralMessage[];
|
|
44
|
+
/** Optional fault injection for tests: count of remaining failures, then succeed. */
|
|
45
|
+
failPostMessageCount: number;
|
|
46
|
+
failUpdateMessageCount: number;
|
|
47
|
+
failPostInteractiveCount: number;
|
|
48
|
+
private nextId;
|
|
49
|
+
private _adminChannel;
|
|
50
|
+
private messageHandlers;
|
|
51
|
+
private editHandlers;
|
|
52
|
+
private actionHandlers;
|
|
53
|
+
private modalHandlers;
|
|
54
|
+
constructor(opts?: Partial<PlatformCapabilities> | {
|
|
55
|
+
adminChannel?: string;
|
|
56
|
+
capabilities?: Partial<PlatformCapabilities>;
|
|
57
|
+
});
|
|
58
|
+
start(): Promise<void>;
|
|
59
|
+
stop(): Promise<void>;
|
|
60
|
+
onMessage(handler: (ctx: MessageContext) => Promise<void>): void;
|
|
61
|
+
onMessageEdit(handler: (ctx: MessageEditContext) => Promise<void>): void;
|
|
62
|
+
onAction(actionId: string, handler: (ctx: ActionContext) => Promise<void>): void;
|
|
63
|
+
onModalSubmit(callbackId: string, handler: (ctx: ModalSubmitContext) => Promise<void>): void;
|
|
64
|
+
postMessage(channel: string, content: MessageContent, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
65
|
+
updateMessage(ref: MessageRef, content: MessageContent): Promise<void>;
|
|
66
|
+
deleteMessage(ref: MessageRef): Promise<void>;
|
|
67
|
+
postInteractive(channel: string, content: MessageContent & {
|
|
68
|
+
actions: ActionElement[];
|
|
69
|
+
}, opts?: PostMessageOpts): Promise<MessageRef>;
|
|
70
|
+
openModal(triggerId: string, modal: ModalDefinition): Promise<void>;
|
|
71
|
+
addReaction(ref: MessageRef, emoji: string): Promise<void>;
|
|
72
|
+
uploadFile(channel: string, filePath: string, opts?: FileUploadOpts): Promise<void>;
|
|
73
|
+
downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
|
|
74
|
+
getPermalink(ref: MessageRef): Promise<string | null>;
|
|
75
|
+
postEphemeral(channel: string, userId: string, text: string): Promise<void>;
|
|
76
|
+
getAdminChannel(): string | null;
|
|
77
|
+
getRawClient(): null;
|
|
78
|
+
/** Simulate an inbound message for testing event handlers. */
|
|
79
|
+
simulateMessage(channel: string, text: string, opts?: {
|
|
80
|
+
senderId?: string;
|
|
81
|
+
threadId?: string;
|
|
82
|
+
isBot?: boolean;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
/** Simulate a message edit for testing edit handlers. */
|
|
85
|
+
simulateMessageEdit(channel: string, messageId: string, newText: string): Promise<void>;
|
|
86
|
+
/** Simulate a button/action click for testing action handlers. */
|
|
87
|
+
simulateAction(actionId: string, value: string, opts?: {
|
|
88
|
+
channelId?: string;
|
|
89
|
+
userId?: string;
|
|
90
|
+
triggerId?: string;
|
|
91
|
+
messageRef?: MessageRef;
|
|
92
|
+
}): Promise<void>;
|
|
93
|
+
/** Simulate a modal submission for testing modal handlers. */
|
|
94
|
+
simulateModalSubmit(callbackId: string, values: Record<string, Record<string, ModalFieldValue>>, opts?: {
|
|
95
|
+
privateMetadata?: string;
|
|
96
|
+
userId?: string;
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
/** Reset all recorded state. */
|
|
99
|
+
reset(): void;
|
|
100
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// input: ./adapter.js + ./types.js
|
|
2
|
+
// output: MockAdapter + recorded message/modal types
|
|
3
|
+
// pos: In-memory mock adapter for unit tests
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
export class MockAdapter {
|
|
6
|
+
name = 'mock';
|
|
7
|
+
capabilities;
|
|
8
|
+
posted = [];
|
|
9
|
+
updated = [];
|
|
10
|
+
deleted = [];
|
|
11
|
+
reactions = [];
|
|
12
|
+
uploads = [];
|
|
13
|
+
modals = [];
|
|
14
|
+
ephemeralMessages = [];
|
|
15
|
+
/** Optional fault injection for tests: count of remaining failures, then succeed. */
|
|
16
|
+
failPostMessageCount = 0;
|
|
17
|
+
failUpdateMessageCount = 0;
|
|
18
|
+
failPostInteractiveCount = 0;
|
|
19
|
+
nextId = 1000;
|
|
20
|
+
_adminChannel;
|
|
21
|
+
messageHandlers = [];
|
|
22
|
+
editHandlers = [];
|
|
23
|
+
actionHandlers = new Map();
|
|
24
|
+
modalHandlers = new Map();
|
|
25
|
+
constructor(opts) {
|
|
26
|
+
const isLegacy = opts && !('adminChannel' in opts) && !('capabilities' in opts);
|
|
27
|
+
const capabilities = isLegacy ? opts : opts?.capabilities;
|
|
28
|
+
this._adminChannel = isLegacy ? 'mock-admin' : (opts?.adminChannel ?? null);
|
|
29
|
+
this.capabilities = {
|
|
30
|
+
threads: true,
|
|
31
|
+
messageEdit: true,
|
|
32
|
+
modals: true,
|
|
33
|
+
reactions: true,
|
|
34
|
+
ephemeral: true,
|
|
35
|
+
fileUpload: true,
|
|
36
|
+
richFormatting: true,
|
|
37
|
+
maxMessageLength: 3000,
|
|
38
|
+
maxThreadDepth: 1,
|
|
39
|
+
...capabilities,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async start() { }
|
|
43
|
+
async stop() { }
|
|
44
|
+
onMessage(handler) {
|
|
45
|
+
this.messageHandlers.push(handler);
|
|
46
|
+
}
|
|
47
|
+
onMessageEdit(handler) {
|
|
48
|
+
this.editHandlers.push(handler);
|
|
49
|
+
}
|
|
50
|
+
onAction(actionId, handler) {
|
|
51
|
+
this.actionHandlers.set(actionId, handler);
|
|
52
|
+
}
|
|
53
|
+
onModalSubmit(callbackId, handler) {
|
|
54
|
+
this.modalHandlers.set(callbackId, handler);
|
|
55
|
+
}
|
|
56
|
+
async postMessage(channel, content, opts) {
|
|
57
|
+
if (this.failPostMessageCount > 0) {
|
|
58
|
+
this.failPostMessageCount--;
|
|
59
|
+
throw new Error('mock: postMessage transient failure');
|
|
60
|
+
}
|
|
61
|
+
const messageId = String(this.nextId++);
|
|
62
|
+
this.posted.push({ channel, content, threadId: opts?.threadId });
|
|
63
|
+
return { channel, messageId, threadId: opts?.threadId };
|
|
64
|
+
}
|
|
65
|
+
async updateMessage(ref, content) {
|
|
66
|
+
if (this.failUpdateMessageCount > 0) {
|
|
67
|
+
this.failUpdateMessageCount--;
|
|
68
|
+
throw new Error('mock: updateMessage transient failure');
|
|
69
|
+
}
|
|
70
|
+
this.updated.push({ ref, content });
|
|
71
|
+
}
|
|
72
|
+
async deleteMessage(ref) {
|
|
73
|
+
this.deleted.push({ ref });
|
|
74
|
+
}
|
|
75
|
+
async postInteractive(channel, content, opts) {
|
|
76
|
+
if (this.failPostInteractiveCount > 0) {
|
|
77
|
+
this.failPostInteractiveCount--;
|
|
78
|
+
throw new Error('mock: postInteractive transient failure');
|
|
79
|
+
}
|
|
80
|
+
const messageId = String(this.nextId++);
|
|
81
|
+
this.posted.push({ channel, content, threadId: opts?.threadId, actions: content.actions });
|
|
82
|
+
return { channel, messageId, threadId: opts?.threadId };
|
|
83
|
+
}
|
|
84
|
+
async openModal(triggerId, modal) {
|
|
85
|
+
this.modals.push({ triggerId, modal });
|
|
86
|
+
}
|
|
87
|
+
async addReaction(ref, emoji) {
|
|
88
|
+
this.reactions.push({ ref, emoji });
|
|
89
|
+
}
|
|
90
|
+
async uploadFile(channel, filePath, opts) {
|
|
91
|
+
this.uploads.push({ channel, filePath, opts });
|
|
92
|
+
}
|
|
93
|
+
async downloadFile(fileRef, destDir) {
|
|
94
|
+
return { localPath: `${destDir}/${fileRef.id}`, mimetype: fileRef.mimetype, name: fileRef.name };
|
|
95
|
+
}
|
|
96
|
+
async getPermalink(ref) {
|
|
97
|
+
return `https://mock.test/permalink/${ref.channel}/${ref.messageId}`;
|
|
98
|
+
}
|
|
99
|
+
async postEphemeral(channel, userId, text) {
|
|
100
|
+
this.ephemeralMessages.push({ channel, userId, text });
|
|
101
|
+
}
|
|
102
|
+
getAdminChannel() {
|
|
103
|
+
return this._adminChannel;
|
|
104
|
+
}
|
|
105
|
+
getRawClient() {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
// --- Test helpers ---
|
|
109
|
+
/** Simulate an inbound message for testing event handlers. */
|
|
110
|
+
async simulateMessage(channel, text, opts) {
|
|
111
|
+
const ref = {
|
|
112
|
+
channel,
|
|
113
|
+
messageId: String(this.nextId++),
|
|
114
|
+
threadId: opts?.threadId,
|
|
115
|
+
};
|
|
116
|
+
const adapter = this;
|
|
117
|
+
const ctx = {
|
|
118
|
+
message: {
|
|
119
|
+
ref,
|
|
120
|
+
text,
|
|
121
|
+
senderId: opts?.senderId || 'user-1',
|
|
122
|
+
isBot: opts?.isBot ?? false,
|
|
123
|
+
raw: {},
|
|
124
|
+
},
|
|
125
|
+
async reply(content, replyOpts) {
|
|
126
|
+
return adapter.postMessage(channel, content, {
|
|
127
|
+
threadId: replyOpts?.threadId || ref.threadId,
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
for (const handler of this.messageHandlers) {
|
|
132
|
+
await handler(ctx);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/** Simulate a message edit for testing edit handlers. */
|
|
136
|
+
async simulateMessageEdit(channel, messageId, newText) {
|
|
137
|
+
const ctx = {
|
|
138
|
+
originalRef: { channel, messageId },
|
|
139
|
+
newText,
|
|
140
|
+
raw: {},
|
|
141
|
+
};
|
|
142
|
+
for (const handler of this.editHandlers) {
|
|
143
|
+
await handler(ctx);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** Simulate a button/action click for testing action handlers. */
|
|
147
|
+
async simulateAction(actionId, value, opts) {
|
|
148
|
+
const handler = this.actionHandlers.get(actionId);
|
|
149
|
+
if (!handler)
|
|
150
|
+
return;
|
|
151
|
+
await handler({
|
|
152
|
+
actionId,
|
|
153
|
+
value,
|
|
154
|
+
triggerId: opts?.triggerId || 'trigger-1',
|
|
155
|
+
channelId: opts?.channelId || 'C123',
|
|
156
|
+
userId: opts?.userId || 'user-1',
|
|
157
|
+
messageRef: opts?.messageRef,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/** Simulate a modal submission for testing modal handlers. */
|
|
161
|
+
async simulateModalSubmit(callbackId, values, opts) {
|
|
162
|
+
const handler = this.modalHandlers.get(callbackId);
|
|
163
|
+
if (!handler)
|
|
164
|
+
return;
|
|
165
|
+
let acked = false;
|
|
166
|
+
await handler({
|
|
167
|
+
callbackId,
|
|
168
|
+
privateMetadata: opts?.privateMetadata || '',
|
|
169
|
+
values,
|
|
170
|
+
userId: opts?.userId || 'user-1',
|
|
171
|
+
async ack(response) {
|
|
172
|
+
acked = true;
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/** Reset all recorded state. */
|
|
177
|
+
reset() {
|
|
178
|
+
this.posted = [];
|
|
179
|
+
this.updated = [];
|
|
180
|
+
this.deleted = [];
|
|
181
|
+
this.reactions = [];
|
|
182
|
+
this.uploads = [];
|
|
183
|
+
this.modals = [];
|
|
184
|
+
this.ephemeralMessages = [];
|
|
185
|
+
this.nextId = 1000;
|
|
186
|
+
this.failPostMessageCount = 0;
|
|
187
|
+
this.failUpdateMessageCount = 0;
|
|
188
|
+
this.failPostInteractiveCount = 0;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { VirtualMessage } from './index.js';
|
|
2
|
+
export declare function isToolTraceEnabled(): boolean;
|
|
3
|
+
/** One-line summary of a single tool invocation's params — short enough to chain. */
|
|
4
|
+
declare function summarizeToolInput(name: string, input: any): string;
|
|
5
|
+
/** Compose the Slack line. Truncates from the tail when total exceeds MAX_LINE_LEN. */
|
|
6
|
+
declare function renderToolLine(toolName: string, summaries: string[], opts?: {
|
|
7
|
+
prefix?: string | null;
|
|
8
|
+
}): string;
|
|
9
|
+
export interface ToolTraceOptions {
|
|
10
|
+
/** Prefix prepended to the line; used by multi-agent threads (e.g. `*[writer]*`). */
|
|
11
|
+
slotPrefix?: string | null;
|
|
12
|
+
}
|
|
13
|
+
export declare class ToolTrace {
|
|
14
|
+
private vm;
|
|
15
|
+
private prefix;
|
|
16
|
+
/** Name of the currently-open group (null if no open group). */
|
|
17
|
+
private groupName;
|
|
18
|
+
/** Accumulated summaries for the open group; rendered on every update. */
|
|
19
|
+
private groupSummaries;
|
|
20
|
+
constructor(vm: VirtualMessage, opts?: ToolTraceOptions);
|
|
21
|
+
onToolUse(name: string, input: any): void;
|
|
22
|
+
/** Seal the current group on the tool-trace side. VM's tail is not touched
|
|
23
|
+
* here — the next `vm.append(text)` or `vm.appendMutableTail(...)` will
|
|
24
|
+
* seal it naturally. */
|
|
25
|
+
flush(): void;
|
|
26
|
+
}
|
|
27
|
+
/** Factory: returns a ToolTrace wired to the given VM, or null if the feature is disabled or VM is missing. */
|
|
28
|
+
export declare function createToolTrace(vm: VirtualMessage | null | undefined, opts?: ToolTraceOptions): ToolTrace | null;
|
|
29
|
+
export declare const _test: {
|
|
30
|
+
summarizeToolInput: typeof summarizeToolInput;
|
|
31
|
+
renderToolLine: typeof renderToolLine;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// input: platform/VirtualMessage, CORTEX_SHOW_TOOL_CALLS env
|
|
2
|
+
// output: ToolTrace class + createToolTrace factory + isToolTraceEnabled
|
|
3
|
+
// pos: Compact tool_use trace merged into the main VM message mutable tail
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
const MAX_LINE_LEN = 120;
|
|
6
|
+
const ELLIPSIS = '…';
|
|
7
|
+
function isEnvTruthy(v) {
|
|
8
|
+
if (!v)
|
|
9
|
+
return false;
|
|
10
|
+
const s = v.trim().toLowerCase();
|
|
11
|
+
return s === '1' || s === 'true' || s === 'yes' || s === 'on';
|
|
12
|
+
}
|
|
13
|
+
export function isToolTraceEnabled() {
|
|
14
|
+
return isEnvTruthy(process.env.CORTEX_SHOW_TOOL_CALLS);
|
|
15
|
+
}
|
|
16
|
+
function firstLine(s) {
|
|
17
|
+
const i = s.indexOf('\n');
|
|
18
|
+
return i === -1 ? s : s.slice(0, i);
|
|
19
|
+
}
|
|
20
|
+
function shortenPath(p) {
|
|
21
|
+
const parts = p.replace(/\\/g, '/').split('/').filter(Boolean);
|
|
22
|
+
if (parts.length <= 2)
|
|
23
|
+
return p;
|
|
24
|
+
return `.../${parts.slice(-2).join('/')}`;
|
|
25
|
+
}
|
|
26
|
+
function stripMcpPrefix(name) {
|
|
27
|
+
const m = name.match(/^mcp__[^_]+__(.+)$/);
|
|
28
|
+
return m ? m[1] : name;
|
|
29
|
+
}
|
|
30
|
+
/** One-line summary of a single tool invocation's params — short enough to chain. */
|
|
31
|
+
function summarizeToolInput(name, input) {
|
|
32
|
+
if (!input || typeof input !== 'object')
|
|
33
|
+
return '';
|
|
34
|
+
const raw = stripMcpPrefix(name);
|
|
35
|
+
switch (raw) {
|
|
36
|
+
case 'Bash':
|
|
37
|
+
return firstLine(String(input.command ?? '')).slice(0, 80);
|
|
38
|
+
case 'Read':
|
|
39
|
+
case 'Write':
|
|
40
|
+
case 'Edit':
|
|
41
|
+
case 'NotebookEdit':
|
|
42
|
+
return shortenPath(String(input.file_path ?? ''));
|
|
43
|
+
case 'remote_read':
|
|
44
|
+
case 'remote_write':
|
|
45
|
+
case 'remote_edit': {
|
|
46
|
+
const dev = input.device ? `${input.device}:` : '';
|
|
47
|
+
return `${dev}${shortenPath(String(input.file_path ?? ''))}`;
|
|
48
|
+
}
|
|
49
|
+
case 'remote_bash':
|
|
50
|
+
return `${input.device || '?'}$ ${firstLine(String(input.command ?? '')).slice(0, 60)}`;
|
|
51
|
+
case 'Grep':
|
|
52
|
+
return firstLine(String(input.pattern ?? '')).slice(0, 60);
|
|
53
|
+
case 'Glob':
|
|
54
|
+
return firstLine(String(input.pattern ?? '')).slice(0, 60);
|
|
55
|
+
case 'WebFetch':
|
|
56
|
+
return String(input.url ?? '').slice(0, 80);
|
|
57
|
+
case 'WebSearch':
|
|
58
|
+
return firstLine(String(input.query ?? '')).slice(0, 60);
|
|
59
|
+
case 'Skill':
|
|
60
|
+
return String(input.skill ?? '');
|
|
61
|
+
case 'Agent':
|
|
62
|
+
return firstLine(String(input.description ?? input.subagent_type ?? '')).slice(0, 60);
|
|
63
|
+
case 'TodoWrite':
|
|
64
|
+
return `${(input.todos || []).length} todos`;
|
|
65
|
+
case 'Task':
|
|
66
|
+
return firstLine(String(input.description ?? '')).slice(0, 60);
|
|
67
|
+
case 'slack_send_file':
|
|
68
|
+
return String(input.file_path ?? '');
|
|
69
|
+
case 'AskUserQuestion':
|
|
70
|
+
case 'ExitPlanMode':
|
|
71
|
+
case 'EnterPlanMode':
|
|
72
|
+
case 'TaskStop':
|
|
73
|
+
return '';
|
|
74
|
+
default: {
|
|
75
|
+
// Fallback: first meaningful string field
|
|
76
|
+
for (const k of ['file_path', 'path', 'command', 'pattern', 'query', 'description', 'name']) {
|
|
77
|
+
const v = input[k];
|
|
78
|
+
if (typeof v === 'string' && v)
|
|
79
|
+
return firstLine(v).slice(0, 80);
|
|
80
|
+
}
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Compose the Slack line. Truncates from the tail when total exceeds MAX_LINE_LEN. */
|
|
86
|
+
function renderToolLine(toolName, summaries, opts) {
|
|
87
|
+
const prefix = opts?.prefix ? `${opts.prefix} ` : '';
|
|
88
|
+
const display = stripMcpPrefix(toolName) || '?';
|
|
89
|
+
const count = summaries.length;
|
|
90
|
+
const head = `${prefix}:wrench: ${display} \u00d7${count}`;
|
|
91
|
+
const nonEmpty = summaries.filter(s => s && s.trim().length > 0);
|
|
92
|
+
if (nonEmpty.length === 0)
|
|
93
|
+
return head;
|
|
94
|
+
// Greedy fit: keep as many summaries as fit under MAX_LINE_LEN.
|
|
95
|
+
const sep = ' \u00b7 ';
|
|
96
|
+
let line = head;
|
|
97
|
+
const kept = [];
|
|
98
|
+
for (const s of nonEmpty) {
|
|
99
|
+
const next = kept.length === 0 ? `${head}${sep}${s}` : `${line}${sep}${s}`;
|
|
100
|
+
if (next.length <= MAX_LINE_LEN) {
|
|
101
|
+
kept.push(s);
|
|
102
|
+
line = next;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (kept.length < nonEmpty.length) {
|
|
109
|
+
const missing = nonEmpty.length - kept.length;
|
|
110
|
+
const withTail = `${line}${sep}+${missing}${ELLIPSIS}`;
|
|
111
|
+
if (withTail.length <= MAX_LINE_LEN + 4)
|
|
112
|
+
line = withTail;
|
|
113
|
+
}
|
|
114
|
+
// Final hard-cap (if even the head+first summary exceeded — rare).
|
|
115
|
+
if (line.length > MAX_LINE_LEN + 4) {
|
|
116
|
+
line = line.slice(0, MAX_LINE_LEN) + ELLIPSIS;
|
|
117
|
+
}
|
|
118
|
+
return line;
|
|
119
|
+
}
|
|
120
|
+
export class ToolTrace {
|
|
121
|
+
vm;
|
|
122
|
+
prefix;
|
|
123
|
+
/** Name of the currently-open group (null if no open group). */
|
|
124
|
+
groupName = null;
|
|
125
|
+
/** Accumulated summaries for the open group; rendered on every update. */
|
|
126
|
+
groupSummaries = [];
|
|
127
|
+
constructor(vm, opts) {
|
|
128
|
+
this.vm = vm;
|
|
129
|
+
this.prefix = opts?.slotPrefix || null;
|
|
130
|
+
}
|
|
131
|
+
onToolUse(name, input) {
|
|
132
|
+
if (!name)
|
|
133
|
+
return;
|
|
134
|
+
const summary = summarizeToolInput(name, input || {});
|
|
135
|
+
if (this.groupName === name) {
|
|
136
|
+
// Same group — append summary and edit the tail in place.
|
|
137
|
+
this.groupSummaries.push(summary);
|
|
138
|
+
const text = renderToolLine(name, this.groupSummaries, { prefix: this.prefix });
|
|
139
|
+
this.vm.editMutableTail(text);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// New group — open a fresh mutable tail. VM seals the previous tail (if any)
|
|
143
|
+
// into committed content as part of appendMutableTail().
|
|
144
|
+
this.groupName = name;
|
|
145
|
+
this.groupSummaries = [summary];
|
|
146
|
+
const text = renderToolLine(name, this.groupSummaries, { prefix: this.prefix });
|
|
147
|
+
this.vm.appendMutableTail(text);
|
|
148
|
+
}
|
|
149
|
+
/** Seal the current group on the tool-trace side. VM's tail is not touched
|
|
150
|
+
* here — the next `vm.append(text)` or `vm.appendMutableTail(...)` will
|
|
151
|
+
* seal it naturally. */
|
|
152
|
+
flush() {
|
|
153
|
+
this.groupName = null;
|
|
154
|
+
this.groupSummaries = [];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** Factory: returns a ToolTrace wired to the given VM, or null if the feature is disabled or VM is missing. */
|
|
158
|
+
export function createToolTrace(vm, opts) {
|
|
159
|
+
if (!isToolTraceEnabled())
|
|
160
|
+
return null;
|
|
161
|
+
if (!vm)
|
|
162
|
+
return null;
|
|
163
|
+
return new ToolTrace(vm, opts);
|
|
164
|
+
}
|
|
165
|
+
export const _test = { summarizeToolInput, renderToolLine };
|