@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,67 @@
|
|
|
1
|
+
export interface RecommendationSection {
|
|
2
|
+
header: string;
|
|
3
|
+
body: string;
|
|
4
|
+
source_file: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Recommendation {
|
|
7
|
+
source_id: string;
|
|
8
|
+
section_header: string;
|
|
9
|
+
text: string;
|
|
10
|
+
source_file: string;
|
|
11
|
+
}
|
|
12
|
+
export interface TaskCandidate {
|
|
13
|
+
text: string;
|
|
14
|
+
why: string;
|
|
15
|
+
done_when: string;
|
|
16
|
+
source_id?: string;
|
|
17
|
+
source_type: string;
|
|
18
|
+
pattern?: string;
|
|
19
|
+
is_duplicate: boolean;
|
|
20
|
+
duplicate_of?: string;
|
|
21
|
+
source_file: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ReflectionField {
|
|
24
|
+
experiment_id: string;
|
|
25
|
+
field_name: string;
|
|
26
|
+
content: string;
|
|
27
|
+
experiment_date: string;
|
|
28
|
+
source_file: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ImpliedTaskPattern {
|
|
31
|
+
pattern: string;
|
|
32
|
+
signals: RegExp[];
|
|
33
|
+
suggested_task_type: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ImpliedTaskMatch {
|
|
36
|
+
pattern: string;
|
|
37
|
+
finding_text: string;
|
|
38
|
+
source_id: string;
|
|
39
|
+
suggested_task_type: string;
|
|
40
|
+
source_file: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ScanSummary {
|
|
43
|
+
files_scanned: number;
|
|
44
|
+
recommendations_found: number;
|
|
45
|
+
implied_tasks_found: number;
|
|
46
|
+
reflection_fields_found: number;
|
|
47
|
+
total_candidates: number;
|
|
48
|
+
actionable: number;
|
|
49
|
+
duplicates: number;
|
|
50
|
+
new_candidates: number;
|
|
51
|
+
}
|
|
52
|
+
export interface ScanResult {
|
|
53
|
+
candidates: TaskCandidate[];
|
|
54
|
+
reflection_fields: ReflectionField[];
|
|
55
|
+
scan_summary: ScanSummary;
|
|
56
|
+
}
|
|
57
|
+
export interface CliOptions {
|
|
58
|
+
baseDir: string;
|
|
59
|
+
project: string | null;
|
|
60
|
+
days: number;
|
|
61
|
+
json: boolean;
|
|
62
|
+
}
|
|
63
|
+
export interface CliResult {
|
|
64
|
+
exitCode: number;
|
|
65
|
+
stdout: string;
|
|
66
|
+
stderr: string;
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { taskStore, withGitLock, TaskRepo } from '../../store/task-repo.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
interface CortexRunArgs {
|
|
3
|
+
name?: string;
|
|
4
|
+
device: string;
|
|
5
|
+
command?: string[];
|
|
6
|
+
project: string | null;
|
|
7
|
+
taskId: string | null;
|
|
8
|
+
envPassthrough: string[];
|
|
9
|
+
logTailBytes: number;
|
|
10
|
+
cancel: string | null;
|
|
11
|
+
signal: string;
|
|
12
|
+
stall: string;
|
|
13
|
+
gpu: string;
|
|
14
|
+
force: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare function getCortexRunHelp(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Returns true if the user is asking for help at the top level.
|
|
19
|
+
* `--help` / `-h` that appear AFTER the `--` separator belong to the user
|
|
20
|
+
* command and must not be treated as cortex-run help requests.
|
|
21
|
+
*/
|
|
22
|
+
declare function isHelpRequest(rawArgs: string[]): boolean;
|
|
23
|
+
declare function parseCliArgs(): CortexRunArgs;
|
|
24
|
+
export { parseCliArgs, getCortexRunHelp, isHelpRequest };
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// cortex-run — CLI dispatch via sendCommand (DR-0011 §4.8 + §4.9).
|
|
3
|
+
//
|
|
4
|
+
// Launch:
|
|
5
|
+
// cortex-run [--device <name>] --name <name> [--stall 10m] [--gpu auto]
|
|
6
|
+
// [--task-project P --task-id ABCD] [--force]
|
|
7
|
+
// [--env-passthrough VAR1,VAR2,...]
|
|
8
|
+
// [--log-tail-bytes 5000]
|
|
9
|
+
// -- COMMAND [ARGS...]
|
|
10
|
+
//
|
|
11
|
+
// Cancel:
|
|
12
|
+
// cortex-run --cancel <name> [--device <name>] [--signal SIGTERM]
|
|
13
|
+
//
|
|
14
|
+
// No local spawn — all execution forwarded via sendCommand to cortex-client.
|
|
15
|
+
import { getLocalMachine } from '../../tasks/dispatch-utils.js';
|
|
16
|
+
import { pendingTask } from './task-state.js';
|
|
17
|
+
import { parseArgs } from 'node:util';
|
|
18
|
+
import { isMainModule } from '../../../core/utils.js';
|
|
19
|
+
// --- Daemon webhook bridge (HTTP to agent-server daemon) ---
|
|
20
|
+
// The daemon's webhook server runs at 127.0.0.1:3001 (env WEBHOOK_PORT).
|
|
21
|
+
// When cortex-run runs standalone, the client-manager's devices Map lives in
|
|
22
|
+
// the daemon process, so we proxy sendCommand/isDeviceOnline through HTTP.
|
|
23
|
+
const WEBHOOK_PORT = parseInt(process.env.WEBHOOK_PORT || '3001', 10);
|
|
24
|
+
const WEBHOOK_BASE = `http://127.0.0.1:${WEBHOOK_PORT}`;
|
|
25
|
+
async function httpIsDeviceOnline(device) {
|
|
26
|
+
try {
|
|
27
|
+
const res = await fetch(`${WEBHOOK_BASE}/webhook/devices`);
|
|
28
|
+
if (!res.ok)
|
|
29
|
+
return false;
|
|
30
|
+
const data = (await res.json());
|
|
31
|
+
return data.devices?.includes(device) ?? false;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function isConnectionRefused(err) {
|
|
38
|
+
if (err && typeof err === 'object') {
|
|
39
|
+
const e = err;
|
|
40
|
+
if (e.cause?.code === 'ECONNREFUSED' || e.code === 'ECONNREFUSED')
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
async function httpSendCommand(device, command) {
|
|
46
|
+
const httpTimeout = (command.timeout || 60_000) + 15_000;
|
|
47
|
+
const controller = new AbortController();
|
|
48
|
+
const timer = setTimeout(() => controller.abort(), httpTimeout);
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch(`${WEBHOOK_BASE}/webhook/remote-command`, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: { 'Content-Type': 'application/json' },
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
device,
|
|
55
|
+
action: command.action,
|
|
56
|
+
params: command.params,
|
|
57
|
+
timeout: command.timeout,
|
|
58
|
+
}),
|
|
59
|
+
signal: controller.signal,
|
|
60
|
+
});
|
|
61
|
+
const data = (await res.json());
|
|
62
|
+
if (!data.success) {
|
|
63
|
+
const suffix = data.onlineDevices?.length
|
|
64
|
+
? ` Online devices: ${data.onlineDevices.join(', ')}`
|
|
65
|
+
: '';
|
|
66
|
+
throw new Error(`${data.error || 'Unknown error from daemon'}${suffix}`);
|
|
67
|
+
}
|
|
68
|
+
return data.data;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (isConnectionRefused(e)) {
|
|
72
|
+
throw new Error(`Cannot connect to cortex daemon at ${WEBHOOK_BASE}. Is the agent server running?`);
|
|
73
|
+
}
|
|
74
|
+
throw e;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
clearTimeout(timer);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// --- CLI parsing ---
|
|
81
|
+
function getCortexRunHelp() {
|
|
82
|
+
return [
|
|
83
|
+
'cortex-run — dispatch a command on a remote device via the Cortex daemon',
|
|
84
|
+
'',
|
|
85
|
+
'Launch:',
|
|
86
|
+
' cortex-run [--device <name>] --name <name> [--stall 10m] [--gpu auto]',
|
|
87
|
+
' [--task-project P --task-id ABCD] [--force]',
|
|
88
|
+
' [--env-passthrough VAR1,VAR2,...]',
|
|
89
|
+
' [--log-tail-bytes 5000]',
|
|
90
|
+
' -- COMMAND [ARGS...]',
|
|
91
|
+
'',
|
|
92
|
+
'Cancel:',
|
|
93
|
+
' cortex-run --cancel <name> [--device <name>] [--signal SIGTERM]',
|
|
94
|
+
'',
|
|
95
|
+
'Options:',
|
|
96
|
+
' --name <name> Required for launch — unique run name (also used as result dir)',
|
|
97
|
+
' --device <name> Target device (default: local machine name from machines.json)',
|
|
98
|
+
' --stall <duration> Stall timeout, e.g. 10m / 1h (default: 10m)',
|
|
99
|
+
' --gpu <slot> GPU slot: auto | none | <index> (default: auto)',
|
|
100
|
+
' --force Allow launch even if a same-name run state dir exists',
|
|
101
|
+
' --task-project <name> Link this run to a TASKS.yaml task — marks pending on launch',
|
|
102
|
+
' --task-id <hash> 4-char hex task id (used with --task-project)',
|
|
103
|
+
' --env-passthrough <list> Comma-separated env var names to forward to the remote',
|
|
104
|
+
' --log-tail-bytes <n> Bytes of log tail returned in callback (default: 5000)',
|
|
105
|
+
' --cancel <name> Cancel a previously launched run by name',
|
|
106
|
+
' --signal <sig> Signal to send when cancelling (default: SIGTERM)',
|
|
107
|
+
' --help, -h Show this help',
|
|
108
|
+
'',
|
|
109
|
+
'Notes:',
|
|
110
|
+
' • All execution is forwarded via the daemon webhook (default 127.0.0.1:3001).',
|
|
111
|
+
' • Without --task-id, exit/termination is still reported but no task lifecycle is touched.',
|
|
112
|
+
' • --task-id must be 4-char hex; invalid IDs cause a non-zero exit before dispatch.',
|
|
113
|
+
].join('\n');
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns true if the user is asking for help at the top level.
|
|
117
|
+
* `--help` / `-h` that appear AFTER the `--` separator belong to the user
|
|
118
|
+
* command and must not be treated as cortex-run help requests.
|
|
119
|
+
*/
|
|
120
|
+
function isHelpRequest(rawArgs) {
|
|
121
|
+
if (rawArgs.length === 0)
|
|
122
|
+
return true;
|
|
123
|
+
const sepIdx = rawArgs.indexOf('--');
|
|
124
|
+
const helpIdx = rawArgs.indexOf('--help');
|
|
125
|
+
const shortIdx = rawArgs.indexOf('-h');
|
|
126
|
+
const firstHelp = [helpIdx, shortIdx].filter((i) => i !== -1).sort((a, b) => a - b)[0];
|
|
127
|
+
if (firstHelp == null)
|
|
128
|
+
return false;
|
|
129
|
+
return sepIdx === -1 || firstHelp < sepIdx;
|
|
130
|
+
}
|
|
131
|
+
function parseCliArgs() {
|
|
132
|
+
const rawArgs = process.argv.slice(2);
|
|
133
|
+
// Detect --cancel mode: only if no -- separator present, or --cancel is before --
|
|
134
|
+
const sepIdx = rawArgs.indexOf('--');
|
|
135
|
+
const cancelIdx = rawArgs.indexOf('--cancel');
|
|
136
|
+
const isCancelMode = cancelIdx !== -1 && (sepIdx === -1 || cancelIdx < sepIdx);
|
|
137
|
+
if (isCancelMode) {
|
|
138
|
+
const cancelArgs = rawArgs.slice(0);
|
|
139
|
+
const { values } = parseArgs({
|
|
140
|
+
args: cancelArgs,
|
|
141
|
+
options: {
|
|
142
|
+
cancel: { type: 'string' },
|
|
143
|
+
device: { type: 'string' },
|
|
144
|
+
signal: { type: 'string', default: 'SIGTERM' },
|
|
145
|
+
},
|
|
146
|
+
strict: true,
|
|
147
|
+
allowPositionals: true,
|
|
148
|
+
});
|
|
149
|
+
if (!values.cancel) {
|
|
150
|
+
console.error('Error: --cancel requires a run name.');
|
|
151
|
+
process.exit(2);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
cancel: values.cancel,
|
|
155
|
+
device: values.device || getLocalMachine(),
|
|
156
|
+
signal: values.signal || 'SIGTERM',
|
|
157
|
+
name: undefined,
|
|
158
|
+
command: undefined,
|
|
159
|
+
project: null,
|
|
160
|
+
taskId: null,
|
|
161
|
+
envPassthrough: [],
|
|
162
|
+
logTailBytes: 5000,
|
|
163
|
+
stall: '10m',
|
|
164
|
+
gpu: 'auto',
|
|
165
|
+
force: false,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
// Launch mode: -- separator required
|
|
169
|
+
if (sepIdx === -1) {
|
|
170
|
+
console.error('Error: No command specified. Use -- to separate cortex-run args from command.');
|
|
171
|
+
process.exit(2);
|
|
172
|
+
}
|
|
173
|
+
const cortexArgs = rawArgs.slice(0, sepIdx);
|
|
174
|
+
const command = rawArgs.slice(sepIdx + 1);
|
|
175
|
+
if (command.length === 0) {
|
|
176
|
+
console.error('Error: No command specified after --.');
|
|
177
|
+
process.exit(2);
|
|
178
|
+
}
|
|
179
|
+
// --cancel inside launch mode (after --) is not cancel mode; but if --cancel
|
|
180
|
+
// appears in cortexArgs, parseArgs will reject it since it's not in the
|
|
181
|
+
// launch option list. That's a usage error.
|
|
182
|
+
const { values } = parseArgs({
|
|
183
|
+
args: cortexArgs,
|
|
184
|
+
options: {
|
|
185
|
+
name: { type: 'string' },
|
|
186
|
+
device: { type: 'string' },
|
|
187
|
+
stall: { type: 'string', default: '10m' },
|
|
188
|
+
gpu: { type: 'string', default: 'auto' },
|
|
189
|
+
force: { type: 'boolean', default: false },
|
|
190
|
+
'task-project': { type: 'string' },
|
|
191
|
+
'task-id': { type: 'string' },
|
|
192
|
+
'env-passthrough': { type: 'string' },
|
|
193
|
+
'log-tail-bytes': { type: 'string' },
|
|
194
|
+
},
|
|
195
|
+
strict: true,
|
|
196
|
+
});
|
|
197
|
+
if (!values.name) {
|
|
198
|
+
console.error('Error: --name is required.');
|
|
199
|
+
process.exit(2);
|
|
200
|
+
}
|
|
201
|
+
const rawTaskId = values['task-id'] || null;
|
|
202
|
+
if (rawTaskId && !/^[0-9a-fA-F]{4}$/.test(rawTaskId)) {
|
|
203
|
+
console.error(`[cortex-run] FATAL: --task-id='${rawTaskId}' is not a valid 4-char hex hash. ` +
|
|
204
|
+
`Refusing to start — fix the launch command.`);
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
// Parse env-passthrough (comma-separated key list)
|
|
208
|
+
const envPassthrough = [];
|
|
209
|
+
if (values['env-passthrough']) {
|
|
210
|
+
for (const key of values['env-passthrough'].split(',').map(s => s.trim()).filter(Boolean)) {
|
|
211
|
+
envPassthrough.push(key);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Parse log-tail-bytes
|
|
215
|
+
let logTailBytes = 5000;
|
|
216
|
+
if (values['log-tail-bytes']) {
|
|
217
|
+
logTailBytes = parseInt(values['log-tail-bytes'], 10);
|
|
218
|
+
if (isNaN(logTailBytes) || logTailBytes < 0) {
|
|
219
|
+
console.error(`Error: invalid --log-tail-bytes '${values['log-tail-bytes']}'.`);
|
|
220
|
+
process.exit(2);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
name: values.name,
|
|
225
|
+
device: values.device || getLocalMachine(),
|
|
226
|
+
command,
|
|
227
|
+
project: values['task-project'] || null,
|
|
228
|
+
taskId: rawTaskId,
|
|
229
|
+
envPassthrough,
|
|
230
|
+
logTailBytes,
|
|
231
|
+
cancel: null,
|
|
232
|
+
signal: 'SIGTERM',
|
|
233
|
+
stall: values.stall,
|
|
234
|
+
gpu: values.gpu,
|
|
235
|
+
force: values.force,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
// --- Launch (DR-0011 §4.8) ---
|
|
239
|
+
async function cmdLaunch(args) {
|
|
240
|
+
const device = args.device;
|
|
241
|
+
if (!(await httpIsDeviceOnline(device))) {
|
|
242
|
+
console.error(`[cortex-run] Error: device "${device}" is not online (cortex-client not connected)`);
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
// --env-passthrough: extract values from server process.env
|
|
246
|
+
const passthroughEnv = {};
|
|
247
|
+
for (const key of args.envPassthrough) {
|
|
248
|
+
if (process.env[key] !== undefined) {
|
|
249
|
+
passthroughEnv[key] = process.env[key];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// Task linkage: mark pending (belt-and-suspenders, non-blocking)
|
|
253
|
+
if (args.project && args.taskId) {
|
|
254
|
+
try {
|
|
255
|
+
const result = pendingTask(null, args.project, args.taskId);
|
|
256
|
+
if (!result.success) {
|
|
257
|
+
console.error(`[cortex-run] Warning: pendingTask failed: ${result.message}`);
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
console.log(`[cortex-run] Task ${args.taskId} marked pending`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
catch (e) {
|
|
264
|
+
console.error(`[cortex-run] Warning: pendingTask error: ${e.message}`);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// Single pathway: all launch via sendCommand
|
|
268
|
+
let result;
|
|
269
|
+
try {
|
|
270
|
+
result = await httpSendCommand(device, {
|
|
271
|
+
action: 'cortex-run.launch',
|
|
272
|
+
params: {
|
|
273
|
+
name: args.name,
|
|
274
|
+
command: args.command,
|
|
275
|
+
stall: args.stall,
|
|
276
|
+
gpu: args.gpu,
|
|
277
|
+
force: args.force,
|
|
278
|
+
cwd: process.cwd(),
|
|
279
|
+
env: passthroughEnv,
|
|
280
|
+
logTailBytes: args.logTailBytes,
|
|
281
|
+
taskProject: args.project,
|
|
282
|
+
taskId: args.taskId,
|
|
283
|
+
},
|
|
284
|
+
timeout: 30_000,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
catch (e) {
|
|
288
|
+
console.error(`[cortex-run] Error: launch failed: ${e.message}`);
|
|
289
|
+
process.exit(1);
|
|
290
|
+
}
|
|
291
|
+
console.log(`[cortex-run] launched on ${device}`);
|
|
292
|
+
console.log(`[cortex-run] pid=${result.pid}`);
|
|
293
|
+
console.log(`[cortex-run] callbackId=${result.callbackId}`);
|
|
294
|
+
console.log(`[cortex-run] resultDir=${result.resultDir}`);
|
|
295
|
+
console.log(`[cortex-run] task lifecycle will be reported back via task-callback`);
|
|
296
|
+
process.exit(0);
|
|
297
|
+
}
|
|
298
|
+
// --- Cancel (DR-0011 §4.9) ---
|
|
299
|
+
async function cmdCancel(args) {
|
|
300
|
+
const device = args.device;
|
|
301
|
+
if (!(await httpIsDeviceOnline(device))) {
|
|
302
|
+
console.error(`[cortex-run] Error: device "${device}" is not online (cortex-client not connected)`);
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
let result;
|
|
306
|
+
try {
|
|
307
|
+
result = await httpSendCommand(device, {
|
|
308
|
+
action: 'cortex-run.cancel',
|
|
309
|
+
params: {
|
|
310
|
+
name: args.cancel,
|
|
311
|
+
signal: args.signal,
|
|
312
|
+
},
|
|
313
|
+
timeout: 30_000,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
catch (e) {
|
|
317
|
+
console.error(`[cortex-run] Error: cancel failed: ${e.message}`);
|
|
318
|
+
process.exit(1);
|
|
319
|
+
}
|
|
320
|
+
console.log(`[cortex-run] cancel signal sent to ${device}: ${args.cancel}`);
|
|
321
|
+
console.log(`[cortex-run] killed=${result.killed} (pid=${result.pid})`);
|
|
322
|
+
process.exit(0);
|
|
323
|
+
}
|
|
324
|
+
// --- Main entry ---
|
|
325
|
+
export { parseCliArgs, getCortexRunHelp, isHelpRequest };
|
|
326
|
+
// Use the shared isMainModule helper so symlink invocations (e.g. via the
|
|
327
|
+
// global `cortex-run` bin) follow through to realpath comparison. The
|
|
328
|
+
// hand-rolled `path.resolve` variant previously here did not follow symlinks
|
|
329
|
+
// and silently skipped main() when invoked via the npm global bin link.
|
|
330
|
+
if (isMainModule(import.meta.url)) {
|
|
331
|
+
if (isHelpRequest(process.argv.slice(2))) {
|
|
332
|
+
process.stdout.write(`${getCortexRunHelp()}\n`);
|
|
333
|
+
process.exit(0);
|
|
334
|
+
}
|
|
335
|
+
const args = parseCliArgs();
|
|
336
|
+
if (args.cancel) {
|
|
337
|
+
await cmdCancel(args);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
await cmdLaunch(args);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
interface ParsedValues {
|
|
2
|
+
project: string | null;
|
|
3
|
+
task: string | null;
|
|
4
|
+
taskId: string | null;
|
|
5
|
+
agent: string;
|
|
6
|
+
reason: string | null;
|
|
7
|
+
note: string;
|
|
8
|
+
text: string | null;
|
|
9
|
+
why: string | null;
|
|
10
|
+
doneWhen: string | null;
|
|
11
|
+
plan: string | null;
|
|
12
|
+
priority: string | null;
|
|
13
|
+
template: string | null;
|
|
14
|
+
dependsOn: string[];
|
|
15
|
+
addDependsOn: string[];
|
|
16
|
+
removeDependsOn: string[];
|
|
17
|
+
clearDependsOn: boolean;
|
|
18
|
+
taskIds: string[];
|
|
19
|
+
subtasksFile: string | null;
|
|
20
|
+
status: string | null;
|
|
21
|
+
hasDeps: boolean;
|
|
22
|
+
noDeps: boolean;
|
|
23
|
+
json: boolean;
|
|
24
|
+
dryRun: boolean;
|
|
25
|
+
skipVerify: boolean;
|
|
26
|
+
skipVerifyReason: string | null;
|
|
27
|
+
force: boolean;
|
|
28
|
+
}
|
|
29
|
+
declare function getCliHelp(): string;
|
|
30
|
+
declare function splitCommand(argv: string[]): {
|
|
31
|
+
command: string;
|
|
32
|
+
args: string[];
|
|
33
|
+
};
|
|
34
|
+
declare function collectMultiValues(argv: string[], index: number): {
|
|
35
|
+
values: string[];
|
|
36
|
+
nextIndex: number;
|
|
37
|
+
};
|
|
38
|
+
declare function parseArgs(argv: string[]): {
|
|
39
|
+
command: string;
|
|
40
|
+
values: ParsedValues;
|
|
41
|
+
};
|
|
42
|
+
interface CliResult {
|
|
43
|
+
exitCode: number;
|
|
44
|
+
stdout: string;
|
|
45
|
+
stderr: string;
|
|
46
|
+
}
|
|
47
|
+
declare function runCli(argv: string[]): CliResult;
|
|
48
|
+
declare function main(): void;
|
|
49
|
+
export { getCliHelp, main, parseArgs, runCli, splitCommand, collectMultiValues };
|