@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,11 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
|
+
import type { CommandResult } from './command-context.js';
|
|
3
|
+
import type { CommandActionRouter } from '../../interactions/command-action-router.js';
|
|
4
|
+
export declare function handleProjectsCmd(channel: string, adapter: PlatformAdapter): Promise<void>;
|
|
5
|
+
export declare function createRegisterHandler(router?: CommandActionRouter): (channel: string, adapter: PlatformAdapter, trimmedMessage: string) => Promise<CommandResult | void>;
|
|
6
|
+
/** @deprecated Use createRegisterHandler() instead. */
|
|
7
|
+
export declare function handleRegisterCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
8
|
+
export declare function handleUnregisterCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
9
|
+
export declare function createProjectDirHandler(router?: CommandActionRouter): (channel: string, adapter: PlatformAdapter, trimmedMessage: string) => Promise<CommandResult | void>;
|
|
10
|
+
/** @deprecated Use createProjectDirHandler() instead. */
|
|
11
|
+
export declare function handleProjectDirCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { channelRepo } from '../../../store/channel-repo.js';
|
|
2
|
+
import { projectDirRepo } from '../../../store/project-dir-repo.js';
|
|
3
|
+
import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
|
|
4
|
+
export async function handleProjectsCmd(channel, adapter) {
|
|
5
|
+
const projects = await channelRepo.listProjects();
|
|
6
|
+
if (projects.length === 0) {
|
|
7
|
+
await adapter.postMessage(channel, { text: 'No projects found.' });
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const registrations = await channelRepo.getAllRegistrations();
|
|
11
|
+
const lines = projects.map(p => {
|
|
12
|
+
const ch = registrations[p];
|
|
13
|
+
const status = ch ? ` → <#${ch}>` : '';
|
|
14
|
+
return `• \`${p}\`${status}`;
|
|
15
|
+
});
|
|
16
|
+
await adapter.postMessage(channel, { text: `*Projects*\n${lines.join('\n')}` });
|
|
17
|
+
}
|
|
18
|
+
const MAX_PROJECT_BUTTONS = 10;
|
|
19
|
+
export function createRegisterHandler(router) {
|
|
20
|
+
if (router) {
|
|
21
|
+
const registerHandler = async (ctx) => {
|
|
22
|
+
const adapter = router.getAdapter();
|
|
23
|
+
if (!adapter)
|
|
24
|
+
return;
|
|
25
|
+
const project = ctx.value;
|
|
26
|
+
try {
|
|
27
|
+
await channelRepo.setProjectChannel(project, ctx.channelId);
|
|
28
|
+
if (ctx.messageRef) {
|
|
29
|
+
await adapter.updateMessage(ctx.messageRef, {
|
|
30
|
+
text: `:white_check_mark: Registered for \`${project}\` task notifications.`,
|
|
31
|
+
}).catch(() => { });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch { /* ignore */ }
|
|
35
|
+
};
|
|
36
|
+
router.registerCommand('register', {
|
|
37
|
+
actions: Array.from({ length: MAX_PROJECT_BUTTONS }, (_, i) => ({
|
|
38
|
+
actionId: `project-${i}`,
|
|
39
|
+
handler: registerHandler,
|
|
40
|
+
})),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return async function handleRegisterCmdInteractive(channel, adapter, trimmedMessage) {
|
|
44
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
45
|
+
if (args.length > 0) {
|
|
46
|
+
const project = args[0];
|
|
47
|
+
const projects = await channelRepo.listProjects();
|
|
48
|
+
if (!projects.includes(project)) {
|
|
49
|
+
await adapter.postMessage(channel, { text: `:x: Unknown project: \`${project}\`\nAvailable: ${projects.map(p => `\`${p}\``).join(', ')}` });
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
await channelRepo.setProjectChannel(project, channel);
|
|
53
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: This channel is now registered for project \`${project}\` task notifications.` });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const registrations = await channelRepo.getAllRegistrations();
|
|
57
|
+
const bound = Object.entries(registrations).filter(([, ch]) => ch === channel).map(([p]) => p);
|
|
58
|
+
const projects = await channelRepo.listProjects();
|
|
59
|
+
const unbound = projects.filter(p => !bound.includes(p));
|
|
60
|
+
const lines = [];
|
|
61
|
+
if (bound.length > 0) {
|
|
62
|
+
lines.push(`Registered: ${bound.map(p => `\`${p}\``).join(', ')}`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
lines.push('This channel is not registered to any project.');
|
|
66
|
+
}
|
|
67
|
+
if (unbound.length > 0) {
|
|
68
|
+
lines.push(`Available: ${unbound.map(p => `\`${p}\``).join(', ')}`);
|
|
69
|
+
}
|
|
70
|
+
const text = lines.join('\n');
|
|
71
|
+
if (!router || unbound.length === 0) {
|
|
72
|
+
await adapter.postMessage(channel, { text });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
text,
|
|
77
|
+
richBlocks: [{ type: 'section', text }],
|
|
78
|
+
actions: unbound.slice(0, MAX_PROJECT_BUTTONS).map((p, i) => ({
|
|
79
|
+
type: 'button',
|
|
80
|
+
text: p.length > 20 ? p.slice(0, 17) + '...' : p,
|
|
81
|
+
actionId: `cmd:register:project-${i}`,
|
|
82
|
+
value: p,
|
|
83
|
+
style: 'primary',
|
|
84
|
+
})),
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** @deprecated Use createRegisterHandler() instead. */
|
|
89
|
+
export async function handleRegisterCmd(channel, adapter, trimmedMessage) {
|
|
90
|
+
const handler = createRegisterHandler();
|
|
91
|
+
await handler(channel, adapter, trimmedMessage);
|
|
92
|
+
}
|
|
93
|
+
export async function handleUnregisterCmd(channel, adapter, trimmedMessage) {
|
|
94
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
95
|
+
if (args.length === 0) {
|
|
96
|
+
await adapter.postMessage(channel, { text: 'Usage: `!unregister <project>`' });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const project = args[0];
|
|
100
|
+
const current = await channelRepo.getProjectChannel(project);
|
|
101
|
+
if (!current || current !== channel) {
|
|
102
|
+
await adapter.postMessage(channel, { text: `:x: This channel is not registered for project \`${project}\`.` });
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
await channelRepo.removeProjectChannel(project);
|
|
106
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Unregistered this channel from project \`${project}\`.` });
|
|
107
|
+
}
|
|
108
|
+
function buildProjectDirModal(channel) {
|
|
109
|
+
const machines = Object.keys(getMachineRegistry());
|
|
110
|
+
return {
|
|
111
|
+
callbackId: 'cmd_project_dir_add',
|
|
112
|
+
title: 'Add Project Directory',
|
|
113
|
+
submitLabel: 'Save',
|
|
114
|
+
privateMetadata: JSON.stringify({ channel }),
|
|
115
|
+
fields: [
|
|
116
|
+
{ type: 'text_input', blockId: 'pd_project', label: 'Project name', actionId: 'text', placeholder: 'e.g. example-project-dataset' },
|
|
117
|
+
{
|
|
118
|
+
type: 'select', blockId: 'pd_machine', label: 'Machine', actionId: 'selection',
|
|
119
|
+
options: machines.map(m => ({ label: m, value: m })),
|
|
120
|
+
},
|
|
121
|
+
{ type: 'text_input', blockId: 'pd_path', label: 'Directory path', actionId: 'text', placeholder: 'e.g. /home/user/project' },
|
|
122
|
+
],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export function createProjectDirHandler(router) {
|
|
126
|
+
if (router) {
|
|
127
|
+
router.registerCommand('project-dir', {
|
|
128
|
+
actions: [{
|
|
129
|
+
actionId: 'open-add',
|
|
130
|
+
handler: async (ctx) => {
|
|
131
|
+
const adapter = router.getAdapter();
|
|
132
|
+
if (!adapter)
|
|
133
|
+
return;
|
|
134
|
+
await adapter.openModal(ctx.triggerId, buildProjectDirModal(ctx.channelId));
|
|
135
|
+
},
|
|
136
|
+
}],
|
|
137
|
+
modals: [{
|
|
138
|
+
callbackId: 'cmd_project_dir_add',
|
|
139
|
+
handler: async (ctx) => {
|
|
140
|
+
await ctx.ack();
|
|
141
|
+
const adapter = router.getAdapter();
|
|
142
|
+
if (!adapter)
|
|
143
|
+
return;
|
|
144
|
+
const { channel } = JSON.parse(ctx.privateMetadata);
|
|
145
|
+
const project = ctx.values?.pd_project?.text?.value;
|
|
146
|
+
const machine = ctx.values?.pd_machine?.selection?.selectedOption?.value;
|
|
147
|
+
const dirPath = ctx.values?.pd_path?.text?.value;
|
|
148
|
+
if (!project || !machine || !dirPath)
|
|
149
|
+
return;
|
|
150
|
+
await projectDirRepo.setProjectDir(project, machine, dirPath);
|
|
151
|
+
await adapter.postMessage(channel, {
|
|
152
|
+
text: `:white_check_mark: \`${project}\` on \`${machine}\` → \`${dirPath}\``,
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
}],
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
return async function handleProjectDirCmdInteractive(channel, adapter, trimmedMessage) {
|
|
159
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
160
|
+
if (args.length > 0) {
|
|
161
|
+
if (args.length < 2) {
|
|
162
|
+
await adapter.postMessage(channel, { text: ':x: Usage: `!project-dir <project> <machine> <path>` or `!project-dir <project> <machine> --remove`' });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const [project, machine] = args;
|
|
166
|
+
const validMachines = Object.keys(getMachineRegistry());
|
|
167
|
+
if (!validMachines.includes(machine)) {
|
|
168
|
+
await adapter.postMessage(channel, { text: `:x: Unknown machine: \`${machine}\`\nValid: ${validMachines.map(m => `\`${m}\``).join(', ')}` });
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (args.length === 2 || args[2] === '--remove') {
|
|
172
|
+
if (args[2] === '--remove') {
|
|
173
|
+
await projectDirRepo.removeProjectDir(project, machine);
|
|
174
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Removed \`${project}\` directory on \`${machine}\`.` });
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
const dir = await projectDirRepo.getProjectDir(project, machine);
|
|
178
|
+
if (dir) {
|
|
179
|
+
await adapter.postMessage(channel, { text: `\`${project}\` on \`${machine}\` → \`${dir}\`` });
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
await adapter.postMessage(channel, { text: `No directory registered for \`${project}\` on \`${machine}\`.` });
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
const dirPath = args.slice(2).join(' ');
|
|
188
|
+
await projectDirRepo.setProjectDir(project, machine, dirPath);
|
|
189
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: \`${project}\` on \`${machine}\` → \`${dirPath}\`` });
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const allDirs = await projectDirRepo.getAllProjectDirs();
|
|
193
|
+
const entries = Object.entries(allDirs);
|
|
194
|
+
const lines = entries.length > 0
|
|
195
|
+
? entries.flatMap(([project, machines]) => Object.entries(machines).map(([machine, dir]) => `• \`${project}\` on \`${machine}\` → \`${dir}\``))
|
|
196
|
+
: ['No project directories registered.'];
|
|
197
|
+
const text = `*Project Directories*\n${lines.join('\n')}`;
|
|
198
|
+
if (!router) {
|
|
199
|
+
await adapter.postMessage(channel, { text });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
text,
|
|
204
|
+
richBlocks: [{ type: 'section', text }],
|
|
205
|
+
actions: [{
|
|
206
|
+
type: 'button',
|
|
207
|
+
text: 'Add',
|
|
208
|
+
actionId: 'cmd:project-dir:open-add',
|
|
209
|
+
value: 'add',
|
|
210
|
+
style: 'primary',
|
|
211
|
+
}],
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/** @deprecated Use createProjectDirHandler() instead. */
|
|
216
|
+
export async function handleProjectDirCmd(channel, adapter, trimmedMessage) {
|
|
217
|
+
const handler = createProjectDirHandler();
|
|
218
|
+
await handler(channel, adapter, trimmedMessage);
|
|
219
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
|
+
import type { RichBlock, ActionElement } from '../../../platform/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Context object passed to interactive command handlers.
|
|
5
|
+
* Replaces the positional (channel, adapter, trimmedMessage) triple.
|
|
6
|
+
*/
|
|
7
|
+
export interface CommandContext {
|
|
8
|
+
/** The channel/source where the command was issued. */
|
|
9
|
+
channel: string;
|
|
10
|
+
/** Platform adapter for outbound messaging. */
|
|
11
|
+
adapter: PlatformAdapter;
|
|
12
|
+
/** The full trimmed message text, e.g. "!cancel --all". */
|
|
13
|
+
message: string;
|
|
14
|
+
/** The command name without "!", e.g. "cancel". */
|
|
15
|
+
commandName: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Return value for a handler that wants the dispatch layer to deliver its response.
|
|
19
|
+
* When `actions` is present, dispatchLayer uses `postInteractive()` instead of `postMessage()`.
|
|
20
|
+
* A `void` return (Promise<void>) means the handler already posted its own messages (backward compat).
|
|
21
|
+
*/
|
|
22
|
+
export interface CommandResult {
|
|
23
|
+
/** Plain text body (used as fallback on platforms without rich formatting). */
|
|
24
|
+
text: string;
|
|
25
|
+
/** Optional rich blocks for formatted content. */
|
|
26
|
+
richBlocks?: RichBlock[];
|
|
27
|
+
/** Optional interactive actions (buttons, selects). If present, dispatch uses postInteractive. */
|
|
28
|
+
actions?: ActionElement[];
|
|
29
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
|
+
export declare function handleCostCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
3
|
+
export declare function handleBudgetCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { formatCostReport, checkBudget, setBudget } from '../../../domain/costs/cost-tracker.js';
|
|
2
|
+
export async function handleCostCmd(channel, adapter, trimmedMessage) {
|
|
3
|
+
const project = trimmedMessage.split(/\s+/).slice(1).join(' ').trim() || null;
|
|
4
|
+
await adapter.postMessage(channel, { text: await formatCostReport(project) });
|
|
5
|
+
}
|
|
6
|
+
export async function handleBudgetCmd(channel, adapter, trimmedMessage) {
|
|
7
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
8
|
+
if (args.length === 0) {
|
|
9
|
+
const b = await checkBudget();
|
|
10
|
+
await adapter.postMessage(channel, {
|
|
11
|
+
text: `*Budget*\n• Daily: $${b.dailyBudget} (spent: $${b.dailySpent.toFixed(2)}, remaining: $${b.dailyRemaining.toFixed(2)})\n• Monthly: $${b.monthlyBudget} (spent: $${b.monthlySpent.toFixed(2)}, remaining: $${b.monthlyRemaining.toFixed(2)})`,
|
|
12
|
+
});
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const daily = args.find(a => a.includes('/d'))?.replace(/[^\d.]/g, '');
|
|
16
|
+
const monthly = args.find(a => a.includes('/m'))?.replace(/[^\d.]/g, '');
|
|
17
|
+
const result = await setBudget({
|
|
18
|
+
daily_usd: daily ? parseFloat(daily) : undefined,
|
|
19
|
+
monthly_usd: monthly ? parseFloat(monthly) : undefined,
|
|
20
|
+
});
|
|
21
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Budget updated: $${result.daily_usd}/day, $${result.monthly_usd}/month` });
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
|
+
import type { CommandResult } from './command-context.js';
|
|
3
|
+
import type { CommandActionRouter } from '../../interactions/command-action-router.js';
|
|
4
|
+
export declare function createDevicesHandler(router?: CommandActionRouter): (channel: string, adapter: PlatformAdapter) => Promise<CommandResult | void>;
|
|
5
|
+
/** @deprecated Use createDevicesHandler() instead. */
|
|
6
|
+
export declare function handleDevicesCmd(channel: string, adapter: PlatformAdapter): Promise<void>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { getOnlineDevices } from '../../../domain/remote/client-manager.js';
|
|
2
|
+
import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
|
|
3
|
+
function formatTimeAgo(ms) {
|
|
4
|
+
const seconds = Math.floor(ms / 1000);
|
|
5
|
+
if (seconds < 60)
|
|
6
|
+
return `${seconds}s ago`;
|
|
7
|
+
const minutes = Math.floor(seconds / 60);
|
|
8
|
+
if (minutes < 60)
|
|
9
|
+
return `${minutes}m ago`;
|
|
10
|
+
const hours = Math.floor(minutes / 60);
|
|
11
|
+
if (hours < 24)
|
|
12
|
+
return `${hours}h ago`;
|
|
13
|
+
const days = Math.floor(hours / 24);
|
|
14
|
+
return `${days}d ago`;
|
|
15
|
+
}
|
|
16
|
+
function buildDevicesText() {
|
|
17
|
+
const onlineDevices = getOnlineDevices();
|
|
18
|
+
const knownNames = new Set(Object.keys(getMachineRegistry()));
|
|
19
|
+
for (const d of onlineDevices)
|
|
20
|
+
knownNames.add(d.device);
|
|
21
|
+
const now = Date.now();
|
|
22
|
+
const lines = ['*Devices*'];
|
|
23
|
+
for (const name of [...knownNames].sort()) {
|
|
24
|
+
const online = onlineDevices.find(d => d.device === name);
|
|
25
|
+
if (online) {
|
|
26
|
+
const connAgo = formatTimeAgo(now - online.connectedAt.getTime());
|
|
27
|
+
const hbAgo = formatTimeAgo(now - online.lastHeartbeat.getTime());
|
|
28
|
+
lines.push(`:white_check_mark: \`${name}\` ${online.platform} connected ${connAgo} heartbeat ${hbAgo}`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
lines.push(`:x: \`${name}\` offline`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (knownNames.size === 0) {
|
|
35
|
+
lines.push('No devices registered or online.');
|
|
36
|
+
}
|
|
37
|
+
return lines.join('\n');
|
|
38
|
+
}
|
|
39
|
+
const REFRESH_BUTTON = {
|
|
40
|
+
type: 'button',
|
|
41
|
+
text: 'Refresh',
|
|
42
|
+
actionId: 'cmd:devices:refresh',
|
|
43
|
+
value: 'refresh',
|
|
44
|
+
};
|
|
45
|
+
export function createDevicesHandler(router) {
|
|
46
|
+
if (router) {
|
|
47
|
+
router.registerCommand('devices', {
|
|
48
|
+
actions: [{
|
|
49
|
+
actionId: 'refresh',
|
|
50
|
+
handler: async (ctx) => {
|
|
51
|
+
const adapter = router.getAdapter();
|
|
52
|
+
if (!adapter || !ctx.messageRef)
|
|
53
|
+
return;
|
|
54
|
+
const text = buildDevicesText();
|
|
55
|
+
await adapter.updateMessage(ctx.messageRef, {
|
|
56
|
+
text,
|
|
57
|
+
richBlocks: [
|
|
58
|
+
{ type: 'section', text },
|
|
59
|
+
{ type: 'actions', elements: [REFRESH_BUTTON] },
|
|
60
|
+
],
|
|
61
|
+
}).catch(() => { });
|
|
62
|
+
},
|
|
63
|
+
}],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return async function handleDevicesCmd(channel, adapter) {
|
|
67
|
+
const text = buildDevicesText();
|
|
68
|
+
if (!router) {
|
|
69
|
+
await adapter.postMessage(channel, { text });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
text,
|
|
74
|
+
richBlocks: [{ type: 'section', text }],
|
|
75
|
+
actions: [REFRESH_BUTTON],
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** @deprecated Use createDevicesHandler() instead. */
|
|
80
|
+
export async function handleDevicesCmd(channel, adapter) {
|
|
81
|
+
const handler = createDevicesHandler();
|
|
82
|
+
await handler(channel, adapter);
|
|
83
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// input: thread-store, profile-manager, core/types/thread-types
|
|
2
|
+
// output: handleDispatchCmd — set profileOverride on running dispatch threads
|
|
3
|
+
// pos: !dispatch <threadId> [--profile <name>]
|
|
4
|
+
import { threadStore } from '../../../store/thread-repo.js';
|
|
5
|
+
import { resolveProfile } from '../../../domain/agents/profile-manager.js';
|
|
6
|
+
const USAGE = 'Usage: `!dispatch <threadId> [--profile <name>]`';
|
|
7
|
+
export async function handleDispatchCmd(channel, adapter, trimmedMessage) {
|
|
8
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
9
|
+
if (args.length === 0) {
|
|
10
|
+
await adapter.postMessage(channel, { text: USAGE });
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const threadId = args[0];
|
|
14
|
+
const thread = threadStore.get(threadId);
|
|
15
|
+
if (!thread) {
|
|
16
|
+
await adapter.postMessage(channel, { text: `:x: Thread not found: \`${threadId}\`` });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (thread.metadata?.trigger !== 'task-dispatch') {
|
|
20
|
+
await adapter.postMessage(channel, { text: `:x: Thread \`${threadId}\` is not a dispatch thread.` });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (thread.status === 'completed' || thread.status === 'failed' || thread.status === 'cancelled' || thread.status === 'aborted') {
|
|
24
|
+
await adapter.postMessage(channel, {
|
|
25
|
+
text: `:warning: Dispatch \`${threadId.substring(0, 12)}\` is \`${thread.status}\`. Profile override will only apply if the thread is continued via \`!thread add\`.${thread.status === 'completed' ? '' : ''}`,
|
|
26
|
+
});
|
|
27
|
+
// Allow the change to go through even for completed threads — it takes effect if continued.
|
|
28
|
+
}
|
|
29
|
+
const profileIdx = args.indexOf('--profile');
|
|
30
|
+
if (profileIdx === -1 || profileIdx + 1 >= args.length) {
|
|
31
|
+
const current = thread.metadata?.profileOverride || '(not set)';
|
|
32
|
+
await adapter.postMessage(channel, { text: `Dispatch \`${threadId.substring(0, 12)}\`: current \`profileOverride\` = \`${current}\`\n${USAGE}` });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const profileName = args[profileIdx + 1];
|
|
36
|
+
try {
|
|
37
|
+
resolveProfile(profileName);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
await adapter.postMessage(channel, { text: `:x: Unknown profile: \`${profileName}\`. Use \`!profile\` to see available profiles.` });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await threadStore.mutate(threadId, (t) => {
|
|
44
|
+
t.metadata = { ...t.metadata, profileOverride: profileName };
|
|
45
|
+
});
|
|
46
|
+
await adapter.postMessage(channel, {
|
|
47
|
+
text: `:white_check_mark: Dispatch \`${threadId.substring(0, 12)}\`: \`profileOverride\` set to \`${profileName}\`. Next step will use this profile.`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
|
+
import type { CommandActionRouter } from '../../interactions/command-action-router.js';
|
|
3
|
+
export interface CommandDeps {
|
|
4
|
+
scheduler: any;
|
|
5
|
+
cancelDispatchedTask?: ((opts: {
|
|
6
|
+
taskId: string;
|
|
7
|
+
channel: string;
|
|
8
|
+
}) => Promise<{
|
|
9
|
+
ok: boolean;
|
|
10
|
+
message: string;
|
|
11
|
+
}>) | null;
|
|
12
|
+
getExecutionStatusReport?: (() => string) | null;
|
|
13
|
+
commandRouter?: CommandActionRouter;
|
|
14
|
+
}
|
|
15
|
+
export declare function registerCommands(deps: CommandDeps): (trimmedMessage: string | undefined, channel: string, adapter: PlatformAdapter, threadTs?: string | null) => boolean;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createLogger } from '../../../core/log.js';
|
|
2
|
+
import { handleOrientCmd } from './orient.js';
|
|
3
|
+
import { handleThreadCmd } from './thread.js';
|
|
4
|
+
import { createScheduleHandler } from './schedule.js';
|
|
5
|
+
import { handleCostCmd, handleBudgetCmd } from './cost.js';
|
|
6
|
+
import { createTasksHandler } from './task.js';
|
|
7
|
+
import { handleModeCmd, handleBackendCmd, handleModelCmd, createProfileHandler, handleSkillsCmd, createAgentHandler } from './mode.js';
|
|
8
|
+
import { createStatusHandler, createHelpHandler } from './status.js';
|
|
9
|
+
import { createCancelHandler } from './cancel.js';
|
|
10
|
+
import { handleNvidiaSmiCmd, handleNvtopCmd } from './nvtop.js';
|
|
11
|
+
import { handleNewCmd, createResumeHandler } from './session.js';
|
|
12
|
+
import { handleProjectsCmd, createRegisterHandler, createProjectDirHandler, handleUnregisterCmd } from './channel.js';
|
|
13
|
+
import { createDevicesHandler } from './device.js';
|
|
14
|
+
import { handleTailCmd } from './tail.js';
|
|
15
|
+
import { handleSendFileCmd } from './sendfile.js';
|
|
16
|
+
import { handleDispatchCmd } from './dispatch.js';
|
|
17
|
+
const log = createLogger('command-handler');
|
|
18
|
+
/**
|
|
19
|
+
* Execute a command handler and handle its return.
|
|
20
|
+
* - If handler returns CommandResult (with `text`), dispatch layer delivers the message.
|
|
21
|
+
* - If handler returns void, it already posted its own response (backward compat).
|
|
22
|
+
*/
|
|
23
|
+
async function executeCommand(handler, channel, adapter, trimmedMessage, _commandName, threadTs) {
|
|
24
|
+
const result = await handler(channel, adapter, trimmedMessage, threadTs);
|
|
25
|
+
if (result && typeof result === 'object' && 'text' in result) {
|
|
26
|
+
if (result.actions && result.actions.length > 0) {
|
|
27
|
+
// Merge actions into richBlocks as a trailing actions block,
|
|
28
|
+
// then use postMessage (not postInteractive) to avoid Slack API
|
|
29
|
+
// restrictions on standalone actions blocks.
|
|
30
|
+
const blocks = [
|
|
31
|
+
...(result.richBlocks || []),
|
|
32
|
+
{ type: 'actions', elements: result.actions },
|
|
33
|
+
];
|
|
34
|
+
await adapter.postMessage(channel, {
|
|
35
|
+
text: result.text,
|
|
36
|
+
richBlocks: blocks,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
await adapter.postMessage(channel, {
|
|
41
|
+
text: result.text,
|
|
42
|
+
richBlocks: result.richBlocks,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const catchHandlerError = (promise, cmd, channel, adapter, threadTs) => {
|
|
48
|
+
Promise.resolve(promise).catch(err => {
|
|
49
|
+
log.error(`Error in ${cmd}:`, err?.message || err);
|
|
50
|
+
if (err?.data)
|
|
51
|
+
log.error(`Slack error data:`, JSON.stringify(err.data));
|
|
52
|
+
adapter.postMessage(channel, { text: `:x: Command error: ${err?.message || 'unknown error'}` }).catch(() => { });
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export function registerCommands(deps) {
|
|
56
|
+
const router = deps.commandRouter;
|
|
57
|
+
const handleCancelCmd = createCancelHandler(deps.cancelDispatchedTask ?? null, router);
|
|
58
|
+
const handleStatusCmd = createStatusHandler(deps.getExecutionStatusReport ?? null, router);
|
|
59
|
+
const handleHelpCmd = createHelpHandler(router);
|
|
60
|
+
const handleDevicesCmdInteractive = createDevicesHandler(router);
|
|
61
|
+
const handleTasksCmdInteractive = createTasksHandler(router);
|
|
62
|
+
const handleResumeCmdInteractive = createResumeHandler(router);
|
|
63
|
+
const handleProfileCmdInteractive = createProfileHandler(router);
|
|
64
|
+
const handleAgentCmdInteractive = createAgentHandler(router);
|
|
65
|
+
const handleRegisterCmdInteractive = createRegisterHandler(router);
|
|
66
|
+
const handleProjectDirCmdInteractive = createProjectDirHandler(router);
|
|
67
|
+
const handleScheduleCmd = createScheduleHandler(deps.scheduler, router);
|
|
68
|
+
const EXACT_COMMANDS = {
|
|
69
|
+
'!help': (ch, ad, _msg) => handleHelpCmd(ch, ad),
|
|
70
|
+
'!new': (ch, ad, _msg, threadTs) => handleNewCmd(ch, ad, {}, threadTs),
|
|
71
|
+
'!newq': (ch, ad, _msg, threadTs) => handleNewCmd(ch, ad, { skipHook: true }, threadTs),
|
|
72
|
+
'!cancel': (ch, ad, msg) => handleCancelCmd(ch, ad, msg),
|
|
73
|
+
'!mode': (ch, ad, _msg) => handleModeCmd(ch, ad),
|
|
74
|
+
'!skills': (ch, ad, _msg) => handleSkillsCmd(ch, ad),
|
|
75
|
+
'!status': (ch, ad, _msg) => handleStatusCmd(ch, ad),
|
|
76
|
+
'!projects': (ch, ad, _msg) => handleProjectsCmd(ch, ad),
|
|
77
|
+
'!resume': (ch, ad, msg) => handleResumeCmdInteractive(ch, ad, msg),
|
|
78
|
+
'!tail': (ch, ad, msg) => handleTailCmd(ch, ad, msg),
|
|
79
|
+
'!devices': (ch, ad, _msg) => handleDevicesCmdInteractive(ch, ad),
|
|
80
|
+
'!clients': (ch, ad, _msg) => handleDevicesCmdInteractive(ch, ad),
|
|
81
|
+
'!thread': (ch, ad, msg) => handleThreadCmd(ch, ad, msg),
|
|
82
|
+
'!agent': (ch, ad, msg) => handleAgentCmdInteractive(ch, ad, msg),
|
|
83
|
+
'!orient': (ch, ad, _msg) => handleOrientCmd(ch, ad),
|
|
84
|
+
};
|
|
85
|
+
const PREFIX_COMMANDS = [
|
|
86
|
+
{ prefix: '!cancel', handler: handleCancelCmd },
|
|
87
|
+
{ prefix: '!backend', handler: handleBackendCmd },
|
|
88
|
+
{ prefix: '!model', handler: handleModelCmd },
|
|
89
|
+
{ prefix: '!profile', handler: handleProfileCmdInteractive },
|
|
90
|
+
{ prefix: '!cost', handler: handleCostCmd },
|
|
91
|
+
{ prefix: '!budget', handler: handleBudgetCmd },
|
|
92
|
+
{ prefix: '!schedule', handler: handleScheduleCmd },
|
|
93
|
+
{ prefix: '!resume', handler: handleResumeCmdInteractive },
|
|
94
|
+
{ prefix: '!tail', handler: handleTailCmd },
|
|
95
|
+
{ prefix: '!tasks', handler: handleTasksCmdInteractive },
|
|
96
|
+
{ prefix: '!nvidia-smi', handler: handleNvidiaSmiCmd },
|
|
97
|
+
{ prefix: '!nvtop', handler: handleNvtopCmd },
|
|
98
|
+
{ prefix: '!project-dir', handler: handleProjectDirCmdInteractive },
|
|
99
|
+
{ prefix: '!register', handler: handleRegisterCmdInteractive },
|
|
100
|
+
{ prefix: '!unregister', handler: handleUnregisterCmd },
|
|
101
|
+
{ prefix: '!thread', handler: handleThreadCmd },
|
|
102
|
+
{ prefix: '!agent', handler: handleAgentCmdInteractive },
|
|
103
|
+
{ prefix: '!sendFile', handler: handleSendFileCmd },
|
|
104
|
+
{ prefix: '!dispatch', handler: handleDispatchCmd },
|
|
105
|
+
];
|
|
106
|
+
const dispatchFn = function dispatchCommand(trimmedMessage, channel, adapter, threadTs) {
|
|
107
|
+
if (!trimmedMessage)
|
|
108
|
+
return false;
|
|
109
|
+
const exact = EXACT_COMMANDS[trimmedMessage];
|
|
110
|
+
if (exact) {
|
|
111
|
+
catchHandlerError(executeCommand(exact, channel, adapter, trimmedMessage, trimmedMessage, threadTs), trimmedMessage, channel, adapter, threadTs);
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
for (const { prefix, handler } of PREFIX_COMMANDS) {
|
|
115
|
+
if (trimmedMessage.startsWith(prefix)) {
|
|
116
|
+
catchHandlerError(executeCommand(handler, channel, adapter, trimmedMessage, prefix, threadTs), prefix, channel, adapter, threadTs);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (trimmedMessage.startsWith('!')) {
|
|
121
|
+
const cmd = trimmedMessage.split(/\s+/)[0];
|
|
122
|
+
adapter.postMessage(channel, { text: `:x: Unknown command: \`${cmd}\`. Run \`!help\` for available commands.` });
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
};
|
|
127
|
+
// Attach router as a property for callers that need it (app.ts)
|
|
128
|
+
dispatchFn.router = router;
|
|
129
|
+
return dispatchFn;
|
|
130
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
|
+
import type { CommandResult } from './command-context.js';
|
|
3
|
+
import type { CommandActionRouter } from '../../interactions/command-action-router.js';
|
|
4
|
+
export declare function handleModeCmd(channel: string, adapter: PlatformAdapter): Promise<void>;
|
|
5
|
+
export declare function handleBackendCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
6
|
+
export declare function handleModelCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
7
|
+
export declare function createProfileHandler(router?: CommandActionRouter): (channel: string, adapter: PlatformAdapter, trimmedMessage: string) => Promise<CommandResult | void>;
|
|
8
|
+
/** @deprecated Use createProfileHandler() instead. */
|
|
9
|
+
export declare function handleProfileCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
10
|
+
export declare function handleSkillsCmd(channel: string, adapter: PlatformAdapter): Promise<void>;
|
|
11
|
+
export declare function createAgentHandler(router?: CommandActionRouter): (channel: string, adapter: PlatformAdapter, trimmedMessage: string) => Promise<CommandResult | void>;
|
|
12
|
+
/** @deprecated Use createAgentHandler() instead. */
|
|
13
|
+
export declare function handleAgentCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|