@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,218 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: stdin HookContext, argv [project, taskId]
|
|
3
|
+
// output: HookResult — checks TASKS.yaml task status after thread ends
|
|
4
|
+
// pos: task-dispatch thread onEnd status check hook
|
|
5
|
+
// >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
|
|
6
|
+
|
|
7
|
+
import { readFileSync, existsSync, readdirSync } from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import { homedir } from 'os';
|
|
11
|
+
|
|
12
|
+
const DATA_DIR = process.env.CORTEX_HOME
|
|
13
|
+
? path.resolve(process.env.CORTEX_HOME)
|
|
14
|
+
: path.join(homedir(), '.cortex');
|
|
15
|
+
const PROJECTS_DIR = process.env.CORTEX_PROJECTS_DIR
|
|
16
|
+
? path.resolve(process.env.CORTEX_PROJECTS_DIR)
|
|
17
|
+
: path.join(DATA_DIR, 'context', 'projects');
|
|
18
|
+
|
|
19
|
+
const CORTEX_ROOT = process.env.CORTEX_ROOT
|
|
20
|
+
? path.resolve(process.env.CORTEX_ROOT)
|
|
21
|
+
: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
22
|
+
const CORTEX_RUN_DIR = path.join(CORTEX_ROOT, 'tmp', 'cortex-run');
|
|
23
|
+
|
|
24
|
+
function noop() {
|
|
25
|
+
console.log(JSON.stringify({ insertAgent: false }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parse a single TASKS.yaml task block into an object.
|
|
30
|
+
* A task block starts with " - id:" and spans until the next " - id:" or EOF.
|
|
31
|
+
* We only extract fields we care about: id, status, claimed-by, blocked-by.
|
|
32
|
+
*/
|
|
33
|
+
function findTaskById(content, taskId) {
|
|
34
|
+
const lines = content.split('\n');
|
|
35
|
+
let inBlock = false;
|
|
36
|
+
let blockStart = -1;
|
|
37
|
+
|
|
38
|
+
// Find the task block containing our taskId
|
|
39
|
+
for (let i = 0; i < lines.length; i++) {
|
|
40
|
+
const line = lines[i];
|
|
41
|
+
const idMatch = line.match(/^\s+- id:\s*(.+)$/);
|
|
42
|
+
if (idMatch) {
|
|
43
|
+
// Extract the ID value (handle both quoted and unquoted)
|
|
44
|
+
const thisId = idMatch[1].trim().replace(/^["']|["']$/g, '');
|
|
45
|
+
if (thisId === taskId) {
|
|
46
|
+
inBlock = true;
|
|
47
|
+
blockStart = i;
|
|
48
|
+
} else if (inBlock) {
|
|
49
|
+
// We were in our block but hit the next task — stop
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
} else if (inBlock && /^\s+- id:/.test(line)) {
|
|
53
|
+
// Fallback: next task block starts
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (blockStart === -1) return null;
|
|
59
|
+
|
|
60
|
+
// Parse fields from the task block
|
|
61
|
+
const task = { id: taskId };
|
|
62
|
+
for (let i = blockStart + 1; i < lines.length; i++) {
|
|
63
|
+
const line = lines[i];
|
|
64
|
+
// Stop at next top-level key or next task
|
|
65
|
+
if (/^\S/.test(line) && !/^\s/.test(line)) break;
|
|
66
|
+
if (/^\s+- id:/.test(line)) break;
|
|
67
|
+
|
|
68
|
+
const fieldMatch = line.match(/^\s{4,}([a-zA-Z_-]+):\s*(.*)$/);
|
|
69
|
+
if (fieldMatch) {
|
|
70
|
+
const key = fieldMatch[1];
|
|
71
|
+
let value = fieldMatch[2].trim();
|
|
72
|
+
// Unquote string values
|
|
73
|
+
value = value.replace(/^["']|["']$/g, '');
|
|
74
|
+
// Handle boolean/null
|
|
75
|
+
if (value === 'true') value = true;
|
|
76
|
+
else if (value === 'false') value = false;
|
|
77
|
+
else if (value === 'null' || value === '') value = null;
|
|
78
|
+
task[key] = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return task;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Find a cortex-run state file that references the given task. */
|
|
86
|
+
function findStateFileForTask(project, taskId) {
|
|
87
|
+
try {
|
|
88
|
+
if (!existsSync(CORTEX_RUN_DIR)) return null;
|
|
89
|
+
for (const entry of readdirSync(CORTEX_RUN_DIR, { withFileTypes: true })) {
|
|
90
|
+
if (!entry.isDirectory()) continue;
|
|
91
|
+
const statePath = path.join(CORTEX_RUN_DIR, entry.name, 'state.json');
|
|
92
|
+
if (!existsSync(statePath)) continue;
|
|
93
|
+
try {
|
|
94
|
+
const state = JSON.parse(readFileSync(statePath, 'utf8'));
|
|
95
|
+
if (state.task_project === project && state.task_id === taskId) {
|
|
96
|
+
return { runName: entry.name, ...state };
|
|
97
|
+
}
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
} catch {}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Check if a PID is still alive. */
|
|
105
|
+
function pidAlive(pid) {
|
|
106
|
+
try {
|
|
107
|
+
process.kill(pid, 0);
|
|
108
|
+
return true;
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function main() {
|
|
115
|
+
let input = '';
|
|
116
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
117
|
+
const ctx = input.trim() ? JSON.parse(input) : {};
|
|
118
|
+
const [project, taskId] = process.argv.slice(2);
|
|
119
|
+
|
|
120
|
+
if (!project || !taskId) { noop(); return; }
|
|
121
|
+
|
|
122
|
+
const tasksPath = path.join(PROJECTS_DIR, project, 'TASKS.yaml');
|
|
123
|
+
if (!existsSync(tasksPath)) { noop(); return; }
|
|
124
|
+
|
|
125
|
+
let content;
|
|
126
|
+
try {
|
|
127
|
+
content = readFileSync(tasksPath, 'utf8');
|
|
128
|
+
} catch {
|
|
129
|
+
noop();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const task = findTaskById(content, taskId);
|
|
134
|
+
if (!task) { noop(); return; }
|
|
135
|
+
|
|
136
|
+
// Task is done — nothing to do.
|
|
137
|
+
if (task.status === 'done') { noop(); return; }
|
|
138
|
+
|
|
139
|
+
// Task is pending — cortex-run is handling it. No recovery; just verify.
|
|
140
|
+
if (task.status === 'pending') {
|
|
141
|
+
const stateFile = findStateFileForTask(project, taskId);
|
|
142
|
+
if (!stateFile || stateFile.status === 'failed') {
|
|
143
|
+
// cortex-run state file missing or run failed — but per design, do not auto-recover.
|
|
144
|
+
// Just report so it's visible.
|
|
145
|
+
const targetAgent = ctx.previousAgent;
|
|
146
|
+
if (targetAgent) {
|
|
147
|
+
const note = !stateFile
|
|
148
|
+
? 'no state file found (cortex-run may not have started)'
|
|
149
|
+
: `state file shows status=${stateFile.status} (exit ${stateFile.exit_code})`;
|
|
150
|
+
console.log(JSON.stringify({
|
|
151
|
+
insertAgent: false,
|
|
152
|
+
targetAgent,
|
|
153
|
+
prompt: [
|
|
154
|
+
`FYI: task [id: ${taskId}] in project "${project}" is still [pending] but cortex-run ${note}.`,
|
|
155
|
+
'Per current policy, pending→done recovery is not automatic. Check manually if needed.',
|
|
156
|
+
].join('\n'),
|
|
157
|
+
}));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
noop();
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Task is blocked — nothing to do.
|
|
166
|
+
if (task['blocked-by']) { noop(); return; }
|
|
167
|
+
|
|
168
|
+
// Task is still claimed — thread ended but task not transitioned.
|
|
169
|
+
if (task['claimed-by']) {
|
|
170
|
+
const targetAgent = ctx.previousAgent;
|
|
171
|
+
if (!targetAgent) { noop(); return; }
|
|
172
|
+
|
|
173
|
+
// Check if there's a cortex-run process handling this task
|
|
174
|
+
const stateFile = findStateFileForTask(project, taskId);
|
|
175
|
+
|
|
176
|
+
if (stateFile && stateFile.status === 'running') {
|
|
177
|
+
// cortex-run is running — this is a legitimate pending case.
|
|
178
|
+
// Engineer forgot to call cortex-task pending; auto-transition.
|
|
179
|
+
console.log(JSON.stringify({
|
|
180
|
+
insertAgent: false,
|
|
181
|
+
targetAgent,
|
|
182
|
+
prompt: [
|
|
183
|
+
`Auto-detected: task [id: ${taskId}] in project "${project}" is still claimed,`,
|
|
184
|
+
`but a cortex-run process "(${stateFile.runName})" is running for this task (PID ${stateFile.pid}).`,
|
|
185
|
+
`The engineer likely forgot to mark the task pending. Call:`,
|
|
186
|
+
` cortex-task pending --project ${project} --task-id ${taskId}`,
|
|
187
|
+
].join('\n'),
|
|
188
|
+
}));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// No cortex-run state file — genuine orphan.
|
|
193
|
+
// Unclaim and prompt agent to resolve.
|
|
194
|
+
console.log(JSON.stringify({
|
|
195
|
+
insertAgent: false,
|
|
196
|
+
targetAgent,
|
|
197
|
+
prompt: [
|
|
198
|
+
`Status check: task [id: ${taskId}] in project "${project}" is still marked [claimed] in TASKS.yaml, but the thread has finished. No running cortex-run process found for this task.`,
|
|
199
|
+
'',
|
|
200
|
+
'Resolve the task status now — do not leave it in limbo:',
|
|
201
|
+
`- If done-when conditions are satisfied: cortex-task complete --project ${project} --task-id ${taskId} --note "<what you did>"`,
|
|
202
|
+
`- If blocked by external reasons: cortex-task block --project ${project} --task-id ${taskId} --reason "<reason>"`,
|
|
203
|
+
`- If a cortex-run is still running: cortex-task pending --project ${project} --task-id ${taskId}`,
|
|
204
|
+
`- If none of the above apply: cortex-task unclaim --project ${project} --task-id ${taskId}`,
|
|
205
|
+
'',
|
|
206
|
+
'After updating the task, commit the TASKS.yaml change.',
|
|
207
|
+
].join('\n'),
|
|
208
|
+
}));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
noop();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
main().catch((err) => {
|
|
216
|
+
console.error(`[task-status-check] Fatal: ${err.message}`);
|
|
217
|
+
console.log(JSON.stringify({ insertAgent: false }));
|
|
218
|
+
});
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: stdin JSON — Claude Code PreToolUse event payload
|
|
3
|
+
// output: stdout JSON — { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision, permissionDecisionReason } }
|
|
4
|
+
// pos: PreToolUse hook — intercepts Edit/Write on **/TASKS.yaml, checks project lock
|
|
5
|
+
// allow when current process holds the lock; deny + helpful message otherwise
|
|
6
|
+
// Owner identity: process.env.CORTEX_EXECUTION_ID ?? manual:<user>:<pid>
|
|
7
|
+
// >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
|
|
8
|
+
|
|
9
|
+
import { readFileSync, existsSync } from 'fs';
|
|
10
|
+
import { basename, resolve } from 'path';
|
|
11
|
+
import { userInfo } from 'os';
|
|
12
|
+
|
|
13
|
+
// ── Constants ──
|
|
14
|
+
|
|
15
|
+
const TASKS_YAML = 'TASKS.yaml';
|
|
16
|
+
const TOOLS = new Set(['Edit', 'Write']);
|
|
17
|
+
|
|
18
|
+
// ── Helpers ──
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Get the current owner identity.
|
|
22
|
+
* Priority: CORTEX_EXECUTION_ID env var > manual:<user>:<pid>
|
|
23
|
+
*/
|
|
24
|
+
function getOwnerIdentity() {
|
|
25
|
+
if (process.env.CORTEX_EXECUTION_ID) return process.env.CORTEX_EXECUTION_ID;
|
|
26
|
+
let user;
|
|
27
|
+
try {
|
|
28
|
+
user = userInfo().username;
|
|
29
|
+
} catch {
|
|
30
|
+
user = process.env.USER || 'unknown';
|
|
31
|
+
}
|
|
32
|
+
return `manual:${user}:${process.pid}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Parse the `lock:` top-level field from a TASKS.yaml string.
|
|
37
|
+
* Returns null if no lock section or if YAML is unparseable.
|
|
38
|
+
*
|
|
39
|
+
* Lock format:
|
|
40
|
+
* lock:
|
|
41
|
+
* owner: <string>
|
|
42
|
+
* acquired_at: <ISO string>
|
|
43
|
+
* expires_at: <ISO string>
|
|
44
|
+
* note?: <string>
|
|
45
|
+
*/
|
|
46
|
+
function parseLock(content) {
|
|
47
|
+
const lines = content.split('\n');
|
|
48
|
+
let inLock = false;
|
|
49
|
+
let lockIndent = 0;
|
|
50
|
+
const lock = {};
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < lines.length; i++) {
|
|
53
|
+
const line = lines[i];
|
|
54
|
+
const trimmed = line.trimEnd();
|
|
55
|
+
|
|
56
|
+
// Detect top-level `lock:` key (at column 0)
|
|
57
|
+
if (!inLock) {
|
|
58
|
+
const lockMatch = trimmed.match(/^lock:\s*(.*)$/);
|
|
59
|
+
if (lockMatch) {
|
|
60
|
+
inLock = true;
|
|
61
|
+
lockIndent = line.length - trimmed.length; // leading whitespace
|
|
62
|
+
// If inline value after lock: (e.g. lock: null), skip
|
|
63
|
+
if (lockMatch[1].trim() && lockMatch[1].trim() !== '') {
|
|
64
|
+
// Inline value — not an object, so no lock
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// We're in the lock block. Check if this line is still part of it.
|
|
73
|
+
const leadingSpace = line.length - line.trimStart().length;
|
|
74
|
+
|
|
75
|
+
// Empty line — skip
|
|
76
|
+
if (trimmed === '') continue;
|
|
77
|
+
|
|
78
|
+
// Line at same or lesser indent than the `lock:` key → lock block is done
|
|
79
|
+
if (leadingSpace <= lockIndent && line.trim()) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Parse key: value within lock block
|
|
84
|
+
const kvMatch = trimmed.match(/^(\s*)([a-zA-Z_-]+):\s*(.*)$/);
|
|
85
|
+
if (kvMatch) {
|
|
86
|
+
const key = kvMatch[2];
|
|
87
|
+
let value = kvMatch[3].trim();
|
|
88
|
+
// Unquote strings
|
|
89
|
+
value = value.replace(/^["']|["']$/g, '');
|
|
90
|
+
lock[key] = value;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Validate required fields
|
|
95
|
+
if (lock.owner && lock.acquired_at && lock.expires_at) {
|
|
96
|
+
return { owner: lock.owner, acquired_at: lock.acquired_at, expires_at: lock.expires_at };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Build a friendly deny message with cortex-task usage examples.
|
|
104
|
+
*/
|
|
105
|
+
function buildDenyMessage(lock, owner) {
|
|
106
|
+
const lines = [
|
|
107
|
+
'Direct Edit/Write of TASKS.yaml is not allowed without holding the project lock.',
|
|
108
|
+
'',
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
if (!lock) {
|
|
112
|
+
lines.push('No lock is currently held on this TASKS.yaml.');
|
|
113
|
+
} else {
|
|
114
|
+
const expiresAt = new Date(lock.expires_at);
|
|
115
|
+
if (expiresAt <= new Date()) {
|
|
116
|
+
lines.push(`The lock expired at ${lock.expires_at}. The previous owner was: ${lock.owner}`);
|
|
117
|
+
} else {
|
|
118
|
+
lines.push(`Lock is held by: ${lock.owner} (current identity: ${owner})`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
lines.push(
|
|
123
|
+
'',
|
|
124
|
+
'Use the cortex-task CLI to safely modify tasks:',
|
|
125
|
+
' cortex-task lock-acquire --project <project> Acquire the project lock',
|
|
126
|
+
' cortex-task add --project <project> Add a new task',
|
|
127
|
+
' cortex-task edit --project <project> --task-id <id> Edit an existing task',
|
|
128
|
+
' cortex-task lock-release --project <project> Release the lock when done',
|
|
129
|
+
'',
|
|
130
|
+
'The cortex-task CLI handles lock checking automatically.',
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return lines.join('\n');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Check lock state and return decision.
|
|
138
|
+
*/
|
|
139
|
+
function checkLock(absPath, owner) {
|
|
140
|
+
let content;
|
|
141
|
+
try {
|
|
142
|
+
content = readFileSync(absPath, 'utf8');
|
|
143
|
+
} catch {
|
|
144
|
+
// File doesn't exist or can't be read — not our concern
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const lock = parseLock(content);
|
|
149
|
+
|
|
150
|
+
// No lock → deny (with helpful message to acquire one)
|
|
151
|
+
if (!lock) {
|
|
152
|
+
return {
|
|
153
|
+
permissionDecision: 'deny',
|
|
154
|
+
permissionDecisionReason: buildDenyMessage(null, owner),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Check expiry
|
|
159
|
+
const expiresAt = new Date(lock.expires_at);
|
|
160
|
+
if (isNaN(expiresAt.getTime()) || expiresAt <= new Date()) {
|
|
161
|
+
return {
|
|
162
|
+
permissionDecision: 'deny',
|
|
163
|
+
permissionDecisionReason: buildDenyMessage(lock, owner),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Lock held by different owner
|
|
168
|
+
if (lock.owner !== owner) {
|
|
169
|
+
return {
|
|
170
|
+
permissionDecision: 'deny',
|
|
171
|
+
permissionDecisionReason: buildDenyMessage(lock, owner),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Lock held by current owner
|
|
176
|
+
return {
|
|
177
|
+
permissionDecision: 'allow',
|
|
178
|
+
permissionDecisionReason: `Lock held by ${owner} (acquired ${lock.acquired_at}, expires ${lock.expires_at}) — proceed with edit.`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ── Main ──
|
|
183
|
+
|
|
184
|
+
function main() {
|
|
185
|
+
let input = '';
|
|
186
|
+
try {
|
|
187
|
+
input = readFileSync(0, 'utf8');
|
|
188
|
+
} catch {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!input.trim()) return;
|
|
193
|
+
|
|
194
|
+
let payload;
|
|
195
|
+
try {
|
|
196
|
+
payload = JSON.parse(input);
|
|
197
|
+
} catch {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Only intercept Edit and Write tools
|
|
202
|
+
const toolName = payload.tool_name;
|
|
203
|
+
if (!TOOLS.has(toolName)) return;
|
|
204
|
+
|
|
205
|
+
// Extract file path
|
|
206
|
+
const toolInput = payload.tool_input || {};
|
|
207
|
+
const filePath = toolInput.file_path || '';
|
|
208
|
+
if (!filePath) return;
|
|
209
|
+
|
|
210
|
+
const cwd = payload.cwd || process.cwd();
|
|
211
|
+
const absPath = resolve(cwd, filePath);
|
|
212
|
+
|
|
213
|
+
// Only guard TASKS.yaml files
|
|
214
|
+
if (basename(absPath) !== TASKS_YAML) return;
|
|
215
|
+
|
|
216
|
+
const owner = getOwnerIdentity();
|
|
217
|
+
const decision = checkLock(absPath, owner);
|
|
218
|
+
|
|
219
|
+
if (!decision) return;
|
|
220
|
+
|
|
221
|
+
process.stdout.write(JSON.stringify({
|
|
222
|
+
hookSpecificOutput: {
|
|
223
|
+
hookEventName: 'PreToolUse',
|
|
224
|
+
permissionDecision: decision.permissionDecision,
|
|
225
|
+
permissionDecisionReason: decision.permissionDecisionReason,
|
|
226
|
+
},
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
main();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { PlatformAdapter, IncomingMessage } from '../platform/index.js';
|
|
2
|
+
type Enqueuer = (channel: string, fn: () => Promise<void>) => boolean;
|
|
3
|
+
type Tracker = (delta: number) => void;
|
|
4
|
+
type Executor = (ctx: AgentRunnerCtx) => Promise<void>;
|
|
5
|
+
interface AgentConfig {
|
|
6
|
+
effectiveMessage: string;
|
|
7
|
+
profileForRun: string;
|
|
8
|
+
defaultAgentName: string | null;
|
|
9
|
+
claudeAgent: string | null;
|
|
10
|
+
systemPrompt: string | null;
|
|
11
|
+
outputStyle: string | null;
|
|
12
|
+
tools: string | null;
|
|
13
|
+
pluginDirs: string[] | null;
|
|
14
|
+
}
|
|
15
|
+
export interface AgentRunnerCtx {
|
|
16
|
+
message: IncomingMessage;
|
|
17
|
+
channel: string;
|
|
18
|
+
adapter: PlatformAdapter;
|
|
19
|
+
threadTs: string | null;
|
|
20
|
+
hasFiles: boolean;
|
|
21
|
+
userMessage: string;
|
|
22
|
+
agentMessage: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class AgentRunner {
|
|
25
|
+
readonly _enqueue: Enqueuer;
|
|
26
|
+
readonly _track: Tracker;
|
|
27
|
+
/** Injectable for unit tests — allows verification of track(-1)-in-finally without spawning Claude. */
|
|
28
|
+
readonly _execute: Executor;
|
|
29
|
+
constructor(opts?: {
|
|
30
|
+
enqueue?: Enqueuer;
|
|
31
|
+
track?: Tracker;
|
|
32
|
+
execute?: Executor;
|
|
33
|
+
});
|
|
34
|
+
route(ctx: AgentRunnerCtx): Promise<void>;
|
|
35
|
+
private _executeReal;
|
|
36
|
+
}
|
|
37
|
+
export declare const agentRunner: AgentRunner;
|
|
38
|
+
/** Exposed for unit testing. */
|
|
39
|
+
export declare function resolveDefaultAgent(agentMessage: string, channel?: string): AgentConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Build interactive callbacks for plan_written, ask_user_question, and tool_use events.
|
|
42
|
+
* These fire during the turn (not after) and publish bus events so the existing
|
|
43
|
+
* Slack interaction flow handles them.
|
|
44
|
+
*
|
|
45
|
+
* Exported so that all runThread call sites (thread-executor, scheduled-task,
|
|
46
|
+
* task-dispatch) can wire these callbacks — without them, ask_user_question
|
|
47
|
+
* events are silently dropped and the subprocess blocks forever.
|
|
48
|
+
*
|
|
49
|
+
* ORDERING INVARIANT: onToolUse fires synchronously before onAskUserQuestion
|
|
50
|
+
* within the same event-loop tick (guaranteed by the PI adapter's sequential
|
|
51
|
+
* event processing in event-parser.ts). The closure variables pendingAskInput
|
|
52
|
+
* and pendingExitPlanMode rely on this ordering — onToolUse captures state
|
|
53
|
+
* that onAskUserQuestion consumes. If the adapter ever processes events
|
|
54
|
+
* asynchronously or out of order, this contract breaks silently.
|
|
55
|
+
*/
|
|
56
|
+
export declare function buildInteractiveCallbacks(channel: string, sessionId: string | null, threadId?: string | null): {
|
|
57
|
+
onPlanWritten: (event: {
|
|
58
|
+
path: string;
|
|
59
|
+
content: string;
|
|
60
|
+
toolUseId: string;
|
|
61
|
+
}) => void;
|
|
62
|
+
onAskUserQuestion: (event: {
|
|
63
|
+
toolUseId: string;
|
|
64
|
+
questions: Array<{
|
|
65
|
+
question: string;
|
|
66
|
+
options?: string[];
|
|
67
|
+
multi?: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
}) => void;
|
|
70
|
+
onToolUse: (name: string, input: any) => void;
|
|
71
|
+
};
|
|
72
|
+
export {};
|