@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,290 @@
|
|
|
1
|
+
import { switchMode, getActiveBackend, setActiveBackend, getClaudeModel, setClaudeModel, getActiveProfile, setActiveProfile, clearChannelProfile, getDefaultAgent, setDefaultAgent } from '../../../domain/agents/index.js';
|
|
2
|
+
import { getDefaultProfileName, listProfiles, resolveProfile } from '../../../domain/agents/profile-manager.js';
|
|
3
|
+
import { getDisplaySkillGroups } from '../../../domain/memory/skill-scanner.js';
|
|
4
|
+
import { getAgent, listAgents } from '../../../domain/threads/index.js';
|
|
5
|
+
import { handleNewCmd } from './session.js';
|
|
6
|
+
function formatProfileList(channel) {
|
|
7
|
+
const globalActive = getActiveProfile();
|
|
8
|
+
const channelActive = channel ? getActiveProfile(channel) : globalActive;
|
|
9
|
+
const defaultName = getDefaultProfileName();
|
|
10
|
+
return listProfiles().map(profile => {
|
|
11
|
+
const markers = [];
|
|
12
|
+
if (profile.name === defaultName)
|
|
13
|
+
markers.push('default');
|
|
14
|
+
if (profile.name === (globalActive || defaultName))
|
|
15
|
+
markers.push('global');
|
|
16
|
+
if (channel && channelActive !== globalActive && profile.name === channelActive)
|
|
17
|
+
markers.push('channel');
|
|
18
|
+
const suffix = markers.length ? ` (${markers.join(', ')})` : '';
|
|
19
|
+
const backend = profile.backend || 'claude';
|
|
20
|
+
const mode = profile.mode || '-';
|
|
21
|
+
return `• *${profile.name}* → \`${profile.model}\` · ${backend} · ${mode}${suffix}`;
|
|
22
|
+
}).join('\n');
|
|
23
|
+
}
|
|
24
|
+
export async function handleModeCmd(channel, adapter) {
|
|
25
|
+
const { newMode } = switchMode();
|
|
26
|
+
await adapter.postMessage(channel, { text: `:arrows_counterclockwise: Switched to *${newMode === 'api' ? 'API' : 'Plan'}* mode` });
|
|
27
|
+
}
|
|
28
|
+
export async function handleBackendCmd(channel, adapter, trimmedMessage) {
|
|
29
|
+
const arg = trimmedMessage.split(/\s+/)[1];
|
|
30
|
+
const newBackend = (arg === 'claude' || arg === 'codex') ? arg : (getActiveBackend() === 'claude' ? 'codex' : 'claude');
|
|
31
|
+
setActiveBackend(newBackend);
|
|
32
|
+
await adapter.postMessage(channel, {
|
|
33
|
+
text: `:arrows_counterclockwise: Backend: *${newBackend === 'claude' ? 'Claude Code' : 'Codex'}*`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export async function handleModelCmd(channel, adapter, trimmedMessage) {
|
|
37
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
38
|
+
if (args.length === 0) {
|
|
39
|
+
await adapter.postMessage(channel, { text: `Current Claude model: *${getClaudeModel()}*` });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const model = args.join(' ').trim();
|
|
43
|
+
if (!model) {
|
|
44
|
+
await adapter.postMessage(channel, { text: ':x: Usage: `!model <model-name>`' });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setClaudeModel(model);
|
|
48
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Claude model set to *${getClaudeModel()}*` });
|
|
49
|
+
}
|
|
50
|
+
const MAX_PROFILE_BUTTONS = 10;
|
|
51
|
+
function buildProfileText(channel) {
|
|
52
|
+
const effective = getActiveProfile(channel) || getDefaultProfileName();
|
|
53
|
+
const globalProfile = getActiveProfile() || getDefaultProfileName();
|
|
54
|
+
const isOverridden = channel && effective !== globalProfile;
|
|
55
|
+
const header = isOverridden
|
|
56
|
+
? `Channel profile: *${effective}* (global: ${globalProfile})`
|
|
57
|
+
: `Active profile: *${effective}*`;
|
|
58
|
+
return `${header}\n${formatProfileList(channel)}`;
|
|
59
|
+
}
|
|
60
|
+
function buildProfileButtons(channel) {
|
|
61
|
+
const profiles = listProfiles();
|
|
62
|
+
return profiles.slice(0, MAX_PROFILE_BUTTONS).map((p, i) => ({
|
|
63
|
+
type: 'button',
|
|
64
|
+
text: p.name,
|
|
65
|
+
actionId: `cmd:profile:set-${i}`,
|
|
66
|
+
value: JSON.stringify({ name: p.name, channel }),
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
export function createProfileHandler(router) {
|
|
70
|
+
if (router) {
|
|
71
|
+
const setHandler = async (ctx) => {
|
|
72
|
+
const adapter = router.getAdapter();
|
|
73
|
+
if (!adapter)
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
const { name, channel } = JSON.parse(ctx.value);
|
|
77
|
+
resolveProfile(name);
|
|
78
|
+
setActiveProfile(name, channel);
|
|
79
|
+
const text = `:white_check_mark: Channel profile set to *${name}*\n${formatProfileList(channel)}`;
|
|
80
|
+
if (ctx.messageRef) {
|
|
81
|
+
await adapter.updateMessage(ctx.messageRef, {
|
|
82
|
+
text,
|
|
83
|
+
richBlocks: [
|
|
84
|
+
{ type: 'section', text },
|
|
85
|
+
{ type: 'actions', elements: buildProfileButtons(channel) },
|
|
86
|
+
],
|
|
87
|
+
}).catch(() => { });
|
|
88
|
+
}
|
|
89
|
+
await handleNewCmd(channel, adapter, { skipHook: true });
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
if (ctx.messageRef) {
|
|
93
|
+
await adapter.updateMessage(ctx.messageRef, {
|
|
94
|
+
text: `:x: ${error.message}`,
|
|
95
|
+
}).catch(() => { });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
router.registerCommand('profile', {
|
|
100
|
+
actions: Array.from({ length: MAX_PROFILE_BUTTONS }, (_, i) => ({
|
|
101
|
+
actionId: `set-${i}`,
|
|
102
|
+
handler: setHandler,
|
|
103
|
+
})),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return async function handleProfileCmdInteractive(channel, adapter, trimmedMessage) {
|
|
107
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
108
|
+
if (args.length > 0) {
|
|
109
|
+
if (args[0] === 'reset') {
|
|
110
|
+
clearChannelProfile(channel);
|
|
111
|
+
const fallback = getActiveProfile() || getDefaultProfileName();
|
|
112
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Channel profile cleared, using global: *${fallback}*` });
|
|
113
|
+
await handleNewCmd(channel, adapter, { skipHook: true });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (args[0] === 'global') {
|
|
117
|
+
if (args.length < 2) {
|
|
118
|
+
await adapter.postMessage(channel, { text: ':x: Usage: `!profile global <name>`' });
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const profileName = args[1];
|
|
122
|
+
try {
|
|
123
|
+
resolveProfile(profileName);
|
|
124
|
+
setActiveProfile(profileName);
|
|
125
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Global profile set to *${profileName}*\n${formatProfileList(channel)}` });
|
|
126
|
+
await handleNewCmd(channel, adapter, { skipHook: true });
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const profileName = args[0];
|
|
134
|
+
try {
|
|
135
|
+
resolveProfile(profileName);
|
|
136
|
+
setActiveProfile(profileName, channel);
|
|
137
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Channel profile set to *${profileName}*\n${formatProfileList(channel)}` });
|
|
138
|
+
await handleNewCmd(channel, adapter, { skipHook: true });
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const text = buildProfileText(channel);
|
|
146
|
+
if (!router) {
|
|
147
|
+
await adapter.postMessage(channel, { text });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
text,
|
|
152
|
+
richBlocks: [{ type: 'section', text }],
|
|
153
|
+
actions: buildProfileButtons(channel),
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** @deprecated Use createProfileHandler() instead. */
|
|
158
|
+
export async function handleProfileCmd(channel, adapter, trimmedMessage) {
|
|
159
|
+
const handler = createProfileHandler();
|
|
160
|
+
await handler(channel, adapter, trimmedMessage);
|
|
161
|
+
}
|
|
162
|
+
export async function handleSkillsCmd(channel, adapter) {
|
|
163
|
+
const groups = getDisplaySkillGroups();
|
|
164
|
+
if (groups.length === 0) {
|
|
165
|
+
await adapter.postMessage(channel, { text: 'No skills found.' });
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const lines = ['*Available skills*'];
|
|
169
|
+
for (const { plugin, skills } of groups) {
|
|
170
|
+
lines.push(plugin ? `_${plugin}_` : '_.claude/skills_');
|
|
171
|
+
for (const skill of skills) {
|
|
172
|
+
lines.push(`• \`${skill}\``);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
await adapter.postMessage(channel, { text: lines.join('\n') });
|
|
176
|
+
}
|
|
177
|
+
const MAX_AGENT_BUTTONS = 10;
|
|
178
|
+
function buildAgentText() {
|
|
179
|
+
const current = getDefaultAgent();
|
|
180
|
+
const agents = listAgents();
|
|
181
|
+
if (current) {
|
|
182
|
+
const agentDef = getAgent(current);
|
|
183
|
+
const profile = agentDef?.profile || '?';
|
|
184
|
+
const claudeAgentStr = agentDef?.claudeAgent ? ` · agent:${agentDef.claudeAgent}` : '';
|
|
185
|
+
return `Default agent: *${current}* (${profile}${claudeAgentStr})`;
|
|
186
|
+
}
|
|
187
|
+
return 'No default agent set.\nAvailable: ' + agents.map(a => `\`${a.name}\``).join(', ');
|
|
188
|
+
}
|
|
189
|
+
function buildAgentButtons() {
|
|
190
|
+
const agents = listAgents();
|
|
191
|
+
const buttons = agents.slice(0, MAX_AGENT_BUTTONS - 1).map((a, i) => ({
|
|
192
|
+
type: 'button',
|
|
193
|
+
text: a.name,
|
|
194
|
+
actionId: `cmd:agent:set-${i}`,
|
|
195
|
+
value: a.name,
|
|
196
|
+
}));
|
|
197
|
+
buttons.push({
|
|
198
|
+
type: 'button',
|
|
199
|
+
text: 'Disable',
|
|
200
|
+
actionId: 'cmd:agent:disable',
|
|
201
|
+
value: 'off',
|
|
202
|
+
style: 'danger',
|
|
203
|
+
});
|
|
204
|
+
return buttons;
|
|
205
|
+
}
|
|
206
|
+
export function createAgentHandler(router) {
|
|
207
|
+
if (router) {
|
|
208
|
+
const setHandler = async (ctx) => {
|
|
209
|
+
const adapter = router.getAdapter();
|
|
210
|
+
if (!adapter)
|
|
211
|
+
return;
|
|
212
|
+
const name = ctx.value;
|
|
213
|
+
const agentDef = getAgent(name);
|
|
214
|
+
if (!agentDef)
|
|
215
|
+
return;
|
|
216
|
+
setDefaultAgent(name);
|
|
217
|
+
const claudeAgentStr = agentDef.claudeAgent ? ` · agent:${agentDef.claudeAgent}` : '';
|
|
218
|
+
const text = `:white_check_mark: Default agent set to *${name}* (${agentDef.profile}${claudeAgentStr})`;
|
|
219
|
+
if (ctx.messageRef) {
|
|
220
|
+
await adapter.updateMessage(ctx.messageRef, {
|
|
221
|
+
text,
|
|
222
|
+
richBlocks: [
|
|
223
|
+
{ type: 'section', text },
|
|
224
|
+
{ type: 'actions', elements: buildAgentButtons() },
|
|
225
|
+
],
|
|
226
|
+
}).catch(() => { });
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
const disableHandler = async (ctx) => {
|
|
230
|
+
const adapter = router.getAdapter();
|
|
231
|
+
if (!adapter)
|
|
232
|
+
return;
|
|
233
|
+
setDefaultAgent(null);
|
|
234
|
+
if (ctx.messageRef) {
|
|
235
|
+
await adapter.updateMessage(ctx.messageRef, {
|
|
236
|
+
text: ':white_check_mark: Default agent disabled.',
|
|
237
|
+
richBlocks: [
|
|
238
|
+
{ type: 'section', text: ':white_check_mark: Default agent disabled.' },
|
|
239
|
+
{ type: 'actions', elements: buildAgentButtons() },
|
|
240
|
+
],
|
|
241
|
+
}).catch(() => { });
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
router.registerCommand('agent', {
|
|
245
|
+
actions: [
|
|
246
|
+
...Array.from({ length: MAX_AGENT_BUTTONS - 1 }, (_, i) => ({
|
|
247
|
+
actionId: `set-${i}`,
|
|
248
|
+
handler: setHandler,
|
|
249
|
+
})),
|
|
250
|
+
{ actionId: 'disable', handler: disableHandler },
|
|
251
|
+
],
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
return async function handleAgentCmdInteractive(channel, adapter, trimmedMessage) {
|
|
255
|
+
const args = trimmedMessage.replace(/^!agent\s*/, '').trim();
|
|
256
|
+
if (args) {
|
|
257
|
+
const name = args.split(/\s+/)[0];
|
|
258
|
+
if (name === 'off' || name === 'none' || name === 'disable') {
|
|
259
|
+
setDefaultAgent(null);
|
|
260
|
+
await adapter.postMessage(channel, { text: ':white_check_mark: Default agent disabled.' });
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const agentDef = getAgent(name);
|
|
264
|
+
if (!agentDef) {
|
|
265
|
+
const available = listAgents().map(a => `\`${a.name}\``).join(', ');
|
|
266
|
+
await adapter.postMessage(channel, { text: `:x: Unknown agent: \`${name}\`\nAvailable: ${available}` });
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
setDefaultAgent(name);
|
|
270
|
+
const claudeAgentStr = agentDef.claudeAgent ? ` · agent:${agentDef.claudeAgent}` : '';
|
|
271
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Default agent set to *${name}* (${agentDef.profile}${claudeAgentStr})` });
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const text = buildAgentText();
|
|
275
|
+
if (!router) {
|
|
276
|
+
await adapter.postMessage(channel, { text });
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
text,
|
|
281
|
+
richBlocks: [{ type: 'section', text }],
|
|
282
|
+
actions: buildAgentButtons(),
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/** @deprecated Use createAgentHandler() instead. */
|
|
287
|
+
export async function handleAgentCmd(channel, adapter, trimmedMessage) {
|
|
288
|
+
const handler = createAgentHandler();
|
|
289
|
+
await handler(channel, adapter, trimmedMessage);
|
|
290
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PlatformAdapter } from '../../../platform/index.js';
|
|
2
|
+
export declare function handleNvidiaSmiCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
3
|
+
export declare function handleNvtopCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { queryGpuSnapshot, renderGpuSnapshot } from '../../../domain/monitor/gpu-monitor.js';
|
|
2
|
+
import { getMachineRegistry, getLocalMachine } from '../../../domain/tasks/dispatch-utils.js';
|
|
3
|
+
import { sendCommand, isDeviceOnline } from '../../../domain/remote/client-manager.js';
|
|
4
|
+
const NVTOP_REFRESH_MS = 1000;
|
|
5
|
+
const NVTOP_HISTORY_LIMIT = 12;
|
|
6
|
+
const activeNvtopMonitors = new Map();
|
|
7
|
+
function rememberGpuHistory(historyByGpu, snapshot) {
|
|
8
|
+
for (const gpu of snapshot.gpus) {
|
|
9
|
+
const history = historyByGpu.get(gpu.uuid) || [];
|
|
10
|
+
history.push(gpu.utilPercent);
|
|
11
|
+
if (history.length > NVTOP_HISTORY_LIMIT)
|
|
12
|
+
history.shift();
|
|
13
|
+
historyByGpu.set(gpu.uuid, history);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async function updateNvtopMessage(channel, adapter) {
|
|
17
|
+
const active = activeNvtopMonitors.get(channel);
|
|
18
|
+
if (!active)
|
|
19
|
+
return;
|
|
20
|
+
const snapshot = await queryGpuSnapshot(active.machine);
|
|
21
|
+
rememberGpuHistory(active.historyByGpu, snapshot);
|
|
22
|
+
const text = renderGpuSnapshot(snapshot, active.historyByGpu, NVTOP_REFRESH_MS / 1000);
|
|
23
|
+
await adapter.updateMessage({ channel, messageId: active.trackingTs }, { text });
|
|
24
|
+
}
|
|
25
|
+
export async function handleNvidiaSmiCmd(channel, adapter, trimmedMessage) {
|
|
26
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
27
|
+
const machine = args[0] || getLocalMachine();
|
|
28
|
+
const reg = getMachineRegistry()[machine];
|
|
29
|
+
if (!reg) {
|
|
30
|
+
const valid = Object.keys(getMachineRegistry()).filter(m => getMachineRegistry()[m].gpuCount > 0).map(m => `\`${m}\``).join(', ');
|
|
31
|
+
await adapter.postMessage(channel, { text: `:x: Unknown machine: \`${machine}\`\nGPU machines: ${valid}` });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (reg.gpuCount === 0) {
|
|
35
|
+
await adapter.postMessage(channel, { text: `:x: \`${machine}\` has no GPU.` });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!isDeviceOnline(machine)) {
|
|
39
|
+
await adapter.postMessage(channel, { text: `:x: Device \`${machine}\` is not online.` });
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const result = await sendCommand(machine, { action: 'bash', params: { command: 'nvidia-smi' }, timeout: 15000 });
|
|
44
|
+
const output = result.stdout || result.stderr || '(no output)';
|
|
45
|
+
await adapter.postMessage(channel, { text: `*nvidia-smi* on \`${machine}\`\n\`\`\`\n${output}\n\`\`\`` });
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
await adapter.postMessage(channel, { text: `:x: nvidia-smi failed on \`${machine}\`: ${err.message}` });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export async function handleNvtopCmd(channel, adapter, trimmedMessage) {
|
|
52
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
53
|
+
if (args[0] === 'stop') {
|
|
54
|
+
const active = activeNvtopMonitors.get(channel);
|
|
55
|
+
if (!active) {
|
|
56
|
+
await adapter.postMessage(channel, { text: 'No active nvtop monitor in this channel.' });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
clearInterval(active.interval);
|
|
60
|
+
activeNvtopMonitors.delete(channel);
|
|
61
|
+
await adapter.postMessage(channel, { text: `:octagonal_sign: nvtop stopped on \`${active.machine}\`.` });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (activeNvtopMonitors.has(channel)) {
|
|
65
|
+
await adapter.postMessage(channel, { text: 'nvtop already running. Use `!nvtop stop` first.' });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const machine = args[0] || getLocalMachine();
|
|
69
|
+
const reg = getMachineRegistry()[machine];
|
|
70
|
+
if (!reg) {
|
|
71
|
+
const valid = Object.keys(getMachineRegistry()).filter(m => getMachineRegistry()[m].gpuCount > 0).map(m => `\`${m}\``).join(', ');
|
|
72
|
+
await adapter.postMessage(channel, { text: `:x: Unknown machine: \`${machine}\`\nGPU machines: ${valid}` });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (reg.gpuCount === 0) {
|
|
76
|
+
await adapter.postMessage(channel, { text: `:x: nvtop monitoring is not supported on \`${machine}\` yet.` });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const historyByGpu = new Map();
|
|
81
|
+
const snapshot = await queryGpuSnapshot(machine);
|
|
82
|
+
rememberGpuHistory(historyByGpu, snapshot);
|
|
83
|
+
const text = renderGpuSnapshot(snapshot, historyByGpu, NVTOP_REFRESH_MS / 1000);
|
|
84
|
+
const result = await adapter.postMessage(channel, { text });
|
|
85
|
+
const interval = setInterval(async () => {
|
|
86
|
+
try {
|
|
87
|
+
await updateNvtopMessage(channel, adapter);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
// Keep monitor alive; next refresh may recover.
|
|
91
|
+
}
|
|
92
|
+
}, NVTOP_REFRESH_MS);
|
|
93
|
+
activeNvtopMonitors.set(channel, {
|
|
94
|
+
interval,
|
|
95
|
+
machine,
|
|
96
|
+
trackingTs: result.messageId,
|
|
97
|
+
historyByGpu,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
await adapter.postMessage(channel, { text: `:x: nvtop failed on \`${machine}\`: ${err.message}` });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
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 createScheduleHandler(scheduler: any, router?: CommandActionRouter): (channel: string, adapter: PlatformAdapter, trimmedMessage: string) => Promise<CommandResult | void>;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { handleScheduleCommand } from '../../../domain/scheduling/schedule-command.js';
|
|
2
|
+
const MAX_SCHEDULE_BUTTONS = 10;
|
|
3
|
+
const FMT_OPTS = { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: false };
|
|
4
|
+
const fmtTime = (ts) => new Date(ts).toLocaleString('en-US', FMT_OPTS);
|
|
5
|
+
function formatTimeUntilCompact(ms) {
|
|
6
|
+
if (ms <= 0)
|
|
7
|
+
return 'now';
|
|
8
|
+
const seconds = Math.floor(ms / 1000);
|
|
9
|
+
if (seconds < 60)
|
|
10
|
+
return `${seconds}s`;
|
|
11
|
+
const minutes = Math.floor(seconds / 60);
|
|
12
|
+
if (minutes < 60)
|
|
13
|
+
return `${minutes}m`;
|
|
14
|
+
const hours = Math.floor(minutes / 60);
|
|
15
|
+
if (hours < 24)
|
|
16
|
+
return `${hours}h`;
|
|
17
|
+
return `${Math.floor(hours / 24)}d`;
|
|
18
|
+
}
|
|
19
|
+
function formatTaskLine(t, now) {
|
|
20
|
+
const id = `\`${t.id}\``;
|
|
21
|
+
const profile = t.profile ? ` · ${t.profile}` : '';
|
|
22
|
+
const paused = t.isPaused ? ' · *paused*' : '';
|
|
23
|
+
const nextMs = (t.nextRun || t.runAt || 0) - now;
|
|
24
|
+
const next = t.isPaused ? '' : ` · next: ${formatTimeUntilCompact(nextMs)}`;
|
|
25
|
+
const msg = t.message.length > 40 ? t.message.slice(0, 37) + '...' : t.message;
|
|
26
|
+
return `${id} ${t.type}${profile}${paused}${next} · "${msg}"`;
|
|
27
|
+
}
|
|
28
|
+
function buildScheduleTaskButtons(tasks) {
|
|
29
|
+
const buttons = [];
|
|
30
|
+
for (let i = 0; i < Math.min(tasks.length, MAX_SCHEDULE_BUTTONS); i++) {
|
|
31
|
+
const t = tasks[i];
|
|
32
|
+
if (t.type === 'once') {
|
|
33
|
+
buttons.push({
|
|
34
|
+
type: 'button', text: `Remove ${t.id}`,
|
|
35
|
+
actionId: `cmd:schedule:remove-${i}`, value: t.id, style: 'danger',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
else if (t.isPaused) {
|
|
39
|
+
buttons.push({
|
|
40
|
+
type: 'button', text: `Resume ${t.id}`,
|
|
41
|
+
actionId: `cmd:schedule:resume-${i}`, value: t.id,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
buttons.push({
|
|
46
|
+
type: 'button', text: `Pause ${t.id}`,
|
|
47
|
+
actionId: `cmd:schedule:pause-${i}`, value: t.id,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return buttons;
|
|
52
|
+
}
|
|
53
|
+
export function createScheduleHandler(scheduler, router) {
|
|
54
|
+
if (router && scheduler) {
|
|
55
|
+
const refreshList = async (adapter, messageRef) => {
|
|
56
|
+
const tasks = await scheduler.list();
|
|
57
|
+
const now = Date.now();
|
|
58
|
+
const text = tasks.length === 0
|
|
59
|
+
? 'No scheduled tasks.'
|
|
60
|
+
: `*Scheduled tasks (${tasks.length}):*\n${tasks.map(t => `• ${formatTaskLine(t, now)}`).join('\n')}`;
|
|
61
|
+
await adapter.updateMessage(messageRef, {
|
|
62
|
+
text,
|
|
63
|
+
richBlocks: [
|
|
64
|
+
{ type: 'section', text },
|
|
65
|
+
...(tasks.length > 0 ? [{ type: 'actions', elements: buildScheduleTaskButtons(tasks) }] : []),
|
|
66
|
+
],
|
|
67
|
+
}).catch(() => { });
|
|
68
|
+
};
|
|
69
|
+
const pauseHandler = async (ctx) => {
|
|
70
|
+
const adapter = router.getAdapter();
|
|
71
|
+
if (!adapter || !ctx.messageRef)
|
|
72
|
+
return;
|
|
73
|
+
try {
|
|
74
|
+
await scheduler.pause(ctx.value);
|
|
75
|
+
}
|
|
76
|
+
catch { /* ignore */ }
|
|
77
|
+
await refreshList(adapter, ctx.messageRef);
|
|
78
|
+
};
|
|
79
|
+
const resumeHandler = async (ctx) => {
|
|
80
|
+
const adapter = router.getAdapter();
|
|
81
|
+
if (!adapter || !ctx.messageRef)
|
|
82
|
+
return;
|
|
83
|
+
try {
|
|
84
|
+
await scheduler.resume(ctx.value);
|
|
85
|
+
}
|
|
86
|
+
catch { /* ignore */ }
|
|
87
|
+
await refreshList(adapter, ctx.messageRef);
|
|
88
|
+
};
|
|
89
|
+
const removeHandler = async (ctx) => {
|
|
90
|
+
const adapter = router.getAdapter();
|
|
91
|
+
if (!adapter || !ctx.messageRef)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
await scheduler.remove(ctx.value);
|
|
95
|
+
}
|
|
96
|
+
catch { /* ignore */ }
|
|
97
|
+
await refreshList(adapter, ctx.messageRef);
|
|
98
|
+
};
|
|
99
|
+
router.registerCommand('schedule', {
|
|
100
|
+
actions: [
|
|
101
|
+
...Array.from({ length: MAX_SCHEDULE_BUTTONS }, (_, i) => ({
|
|
102
|
+
actionId: `pause-${i}`, handler: pauseHandler,
|
|
103
|
+
})),
|
|
104
|
+
...Array.from({ length: MAX_SCHEDULE_BUTTONS }, (_, i) => ({
|
|
105
|
+
actionId: `resume-${i}`, handler: resumeHandler,
|
|
106
|
+
})),
|
|
107
|
+
...Array.from({ length: MAX_SCHEDULE_BUTTONS }, (_, i) => ({
|
|
108
|
+
actionId: `remove-${i}`, handler: removeHandler,
|
|
109
|
+
})),
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return async function handleScheduleCmd(channel, adapter, trimmedMessage) {
|
|
114
|
+
const parts = trimmedMessage.split(/\s+/);
|
|
115
|
+
const sub = parts[1];
|
|
116
|
+
if (router && scheduler && (!sub || sub === 'list')) {
|
|
117
|
+
const tasks = await scheduler.list();
|
|
118
|
+
if (tasks.length === 0) {
|
|
119
|
+
await adapter.postMessage(channel, { text: 'No scheduled tasks.' });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const now = Date.now();
|
|
123
|
+
const text = `*Scheduled tasks (${tasks.length}):*\n${tasks.map(t => `• ${formatTaskLine(t, now)}`).join('\n')}`;
|
|
124
|
+
return {
|
|
125
|
+
text,
|
|
126
|
+
richBlocks: [{ type: 'section', text }],
|
|
127
|
+
actions: buildScheduleTaskButtons(tasks),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return handleScheduleCommand(trimmedMessage, channel, adapter, scheduler);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
|
|
2
|
+
import { statSync, existsSync, mkdirSync, unlinkSync } from 'fs';
|
|
3
|
+
import { execFile } from 'child_process';
|
|
4
|
+
import * as os from 'os';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { WORKSPACE_DIR } from '../../../core/utils.js';
|
|
7
|
+
async function sendLocalFile(channel, adapter, reg, filePath, machine) {
|
|
8
|
+
let resolved;
|
|
9
|
+
if (filePath.startsWith('~/') || filePath === '~') {
|
|
10
|
+
resolved = filePath.replace(/^~/, process.env.HOME || os.homedir());
|
|
11
|
+
}
|
|
12
|
+
else if (path.isAbsolute(filePath)) {
|
|
13
|
+
resolved = filePath;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
resolved = path.resolve(reg.cortexPath, filePath);
|
|
17
|
+
}
|
|
18
|
+
if (!existsSync(resolved)) {
|
|
19
|
+
await adapter.postMessage(channel, { text: `:x: File not found: \`${resolved}\`` });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const stat = statSync(resolved);
|
|
23
|
+
if (!stat.isFile()) {
|
|
24
|
+
await adapter.postMessage(channel, { text: `:x: Not a file: \`${resolved}\`` });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
await adapter.uploadFile(channel, resolved, { filename: path.basename(resolved) });
|
|
28
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Sent \`${path.basename(resolved)}\` (${(stat.size / 1024).toFixed(1)} KB) from ${machine}` });
|
|
29
|
+
}
|
|
30
|
+
async function sendRemoteFile(channel, adapter, reg, filePath, machine) {
|
|
31
|
+
let remotePath;
|
|
32
|
+
if (filePath.startsWith('~/') || filePath === '~') {
|
|
33
|
+
remotePath = filePath;
|
|
34
|
+
}
|
|
35
|
+
else if (path.isAbsolute(filePath) || (reg.win && /^[A-Z]:\\/i.test(filePath))) {
|
|
36
|
+
remotePath = filePath;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
remotePath = reg.win ? `${reg.cortexPath}\\${filePath}` : `${reg.cortexPath}/${filePath}`;
|
|
40
|
+
}
|
|
41
|
+
const tmpDir = path.join(WORKSPACE_DIR, 'sendfile');
|
|
42
|
+
mkdirSync(tmpDir, { recursive: true });
|
|
43
|
+
const fileName = path.basename(remotePath);
|
|
44
|
+
const localTmp = path.join(tmpDir, `${Date.now()}-${fileName}`);
|
|
45
|
+
try {
|
|
46
|
+
await new Promise((resolve, reject) => {
|
|
47
|
+
execFile('scp', [
|
|
48
|
+
'-o', 'ConnectTimeout=10',
|
|
49
|
+
'-o', 'StrictHostKeyChecking=no',
|
|
50
|
+
`${reg.ssh}:${remotePath}`,
|
|
51
|
+
localTmp,
|
|
52
|
+
], { timeout: 60000 }, (err) => {
|
|
53
|
+
if (err)
|
|
54
|
+
reject(new Error(`SCP failed: ${err.message}`));
|
|
55
|
+
else
|
|
56
|
+
resolve();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
await adapter.postMessage(channel, { text: `:x: Failed to fetch from ${machine}: ${err.message}` });
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const tmpStat = statSync(localTmp);
|
|
66
|
+
await adapter.uploadFile(channel, localTmp, { filename: fileName });
|
|
67
|
+
await adapter.postMessage(channel, { text: `:white_check_mark: Sent \`${fileName}\` (${(tmpStat.size / 1024).toFixed(1)} KB) from ${machine}` });
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
unlinkSync(localTmp);
|
|
72
|
+
}
|
|
73
|
+
catch { }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export async function handleSendFileCmd(channel, adapter, trimmedMessage) {
|
|
77
|
+
const args = trimmedMessage.split(/\s+/).slice(1);
|
|
78
|
+
if (args.length < 2) {
|
|
79
|
+
await adapter.postMessage(channel, { text: 'Usage: `!sendFile <machine> <path>`\nPath can be absolute, relative to Cortex root, or start with `~`' });
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const machine = args[0];
|
|
83
|
+
const filePath = args.slice(1).join(' ');
|
|
84
|
+
const reg = getMachineRegistry()[machine];
|
|
85
|
+
if (!reg) {
|
|
86
|
+
await adapter.postMessage(channel, { text: `:x: Unknown machine: \`${machine}\`. Known: ${Object.keys(getMachineRegistry()).join(', ')}` });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!reg.ssh)
|
|
90
|
+
return sendLocalFile(channel, adapter, reg, filePath, machine);
|
|
91
|
+
return sendRemoteFile(channel, adapter, reg, filePath, machine);
|
|
92
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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 handleNewCmd(channel: string, adapter: PlatformAdapter, opts?: {
|
|
5
|
+
skipHook?: boolean;
|
|
6
|
+
}, threadTs?: string | null): Promise<void>;
|
|
7
|
+
export declare function createResumeHandler(router?: CommandActionRouter): (channel: string, adapter: PlatformAdapter, trimmedMessage: string) => Promise<CommandResult | void>;
|
|
8
|
+
/** @deprecated Use createResumeHandler() instead. */
|
|
9
|
+
export declare function handleResumeCmd(channel: string, adapter: PlatformAdapter, trimmedMessage: string): Promise<void>;
|