@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,22 @@
|
|
|
1
|
+
declare function completeTask(taskText: string | null, project: string, completionNote?: string, taskId?: string | null, skipVerify?: boolean, skipVerifyReason?: string | null): {
|
|
2
|
+
success: boolean;
|
|
3
|
+
message: string;
|
|
4
|
+
task_id?: undefined;
|
|
5
|
+
unblocked?: undefined;
|
|
6
|
+
verify_warning?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
success: boolean;
|
|
9
|
+
message: string;
|
|
10
|
+
task_id: string;
|
|
11
|
+
unblocked: {
|
|
12
|
+
taskId: string | null;
|
|
13
|
+
project: string;
|
|
14
|
+
preview: string;
|
|
15
|
+
}[];
|
|
16
|
+
verify_warning: string;
|
|
17
|
+
};
|
|
18
|
+
declare function uncompleteTask(taskText: string | null, project: string, taskId?: string | null): {
|
|
19
|
+
success: boolean;
|
|
20
|
+
message: string;
|
|
21
|
+
};
|
|
22
|
+
export { completeTask, uncompleteTask };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { execSync } from 'node:child_process';
|
|
4
|
+
import { DATA_DIR, todayISO } from '../../../core/utils.js';
|
|
5
|
+
import { clearDependsOnAll, findTask, getTasksPath, readTasks, writeTasks } from './task-lifecycle-edit.js';
|
|
6
|
+
function verifyCompletionEvidence(taskId, doneWhen) {
|
|
7
|
+
let gitFound = false;
|
|
8
|
+
let grepFound = false;
|
|
9
|
+
if (taskId) {
|
|
10
|
+
try {
|
|
11
|
+
const out = execSync(`git -C ${JSON.stringify(DATA_DIR)} log --oneline --grep=${JSON.stringify(taskId)}`, { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 5000 });
|
|
12
|
+
const logLines = out.trim().split('\n').filter(Boolean);
|
|
13
|
+
gitFound = logLines.some((l) => !/task-store:\s+(claim|unclaim)/i.test(l));
|
|
14
|
+
}
|
|
15
|
+
catch { }
|
|
16
|
+
}
|
|
17
|
+
if (!gitFound && doneWhen) {
|
|
18
|
+
const tokens = doneWhen.match(/[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_/.-]+/g) ?? [];
|
|
19
|
+
for (const token of tokens) {
|
|
20
|
+
if (fs.existsSync(path.join(DATA_DIR, token))) {
|
|
21
|
+
grepFound = true;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { hasEvidence: gitFound || grepFound, gitFound, grepFound };
|
|
27
|
+
}
|
|
28
|
+
function completeTask(taskText, project, completionNote = '', taskId = null, skipVerify = false, skipVerifyReason = null) {
|
|
29
|
+
const tasks = readTasks(project);
|
|
30
|
+
if (tasks.length === 0 && !fs.existsSync(getTasksPath(project))) {
|
|
31
|
+
return { success: false, message: `TASKS.yaml not found for project ${project}` };
|
|
32
|
+
}
|
|
33
|
+
const found = findTask(tasks, taskText, taskId);
|
|
34
|
+
if ('error' in found)
|
|
35
|
+
return { success: false, message: found.error };
|
|
36
|
+
const task = found.task;
|
|
37
|
+
if (task.status === 'done')
|
|
38
|
+
return { success: false, message: 'Task is already completed' };
|
|
39
|
+
if (task.paused)
|
|
40
|
+
return { success: false, message: 'Cannot complete a paused task — resume it first' };
|
|
41
|
+
if (task.blocked_by)
|
|
42
|
+
return { success: false, message: 'Cannot complete a blocked task — unblock it first' };
|
|
43
|
+
let verifyWarning = null;
|
|
44
|
+
if (skipVerify) {
|
|
45
|
+
verifyWarning = `verify skipped: ${skipVerifyReason ?? 'no reason given'}`;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const { hasEvidence } = verifyCompletionEvidence(task.id, task.done_when);
|
|
49
|
+
if (!hasEvidence) {
|
|
50
|
+
verifyWarning = 'no evidence of work: no matching git commit and no Done-when artifact found in repo. Re-run with --skip-verify to bypass.';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const today = todayISO();
|
|
54
|
+
task.status = 'done';
|
|
55
|
+
task.claimed_by = null;
|
|
56
|
+
task.claimed_at = null;
|
|
57
|
+
task.blocked_by = null;
|
|
58
|
+
task.approval_needed = false;
|
|
59
|
+
task.paused = false;
|
|
60
|
+
task.pending_at = null;
|
|
61
|
+
task.completed_at = today;
|
|
62
|
+
task.completed_note = completionNote || null;
|
|
63
|
+
writeTasks(project, tasks);
|
|
64
|
+
const unblockResult = task.id ? clearDependsOnAll(task.id) : { count: 0, tasks: [] };
|
|
65
|
+
let message = `Task completed on ${today}`;
|
|
66
|
+
if (unblockResult.count > 0) {
|
|
67
|
+
const details = unblockResult.tasks.map((t) => ` ${t.taskId ? `[${t.taskId}]` : '(?)'} ${t.project}: ${t.preview}`).join('\n');
|
|
68
|
+
message += ` (unblocked ${unblockResult.count} dependent task(s)):\n${details}`;
|
|
69
|
+
}
|
|
70
|
+
return { success: true, message, task_id: task.id, unblocked: unblockResult.tasks, verify_warning: verifyWarning };
|
|
71
|
+
}
|
|
72
|
+
function uncompleteTask(taskText, project, taskId = null) {
|
|
73
|
+
const tasks = readTasks(project);
|
|
74
|
+
if (tasks.length === 0 && !fs.existsSync(getTasksPath(project))) {
|
|
75
|
+
return { success: false, message: `TASKS.yaml not found for project ${project}` };
|
|
76
|
+
}
|
|
77
|
+
const found = findTask(tasks, taskText, taskId);
|
|
78
|
+
if ('error' in found)
|
|
79
|
+
return { success: false, message: found.error };
|
|
80
|
+
const task = found.task;
|
|
81
|
+
if (task.status !== 'done')
|
|
82
|
+
return { success: false, message: 'Task is not completed' };
|
|
83
|
+
task.status = 'open';
|
|
84
|
+
task.completed_at = null;
|
|
85
|
+
task.completed_note = null;
|
|
86
|
+
writeTasks(project, tasks);
|
|
87
|
+
return { success: true, message: 'Task marked as incomplete' };
|
|
88
|
+
}
|
|
89
|
+
export { completeTask, uncompleteTask };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
declare function generateHash(existingHashes?: Set<string>): string;
|
|
2
|
+
declare function collectAllExistingHashes(): Set<string>;
|
|
3
|
+
declare function assignIds(project?: string | null): {
|
|
4
|
+
success: boolean;
|
|
5
|
+
message: string;
|
|
6
|
+
assigned?: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
success: boolean;
|
|
9
|
+
message: string;
|
|
10
|
+
assigned: number;
|
|
11
|
+
};
|
|
12
|
+
declare function validateIds(): {
|
|
13
|
+
success: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
collisions?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
success: boolean;
|
|
18
|
+
message: string;
|
|
19
|
+
collisions: {
|
|
20
|
+
id: string;
|
|
21
|
+
projects: string[];
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
export { assignIds, collectAllExistingHashes, generateHash, validateIds };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { PROJECTS_DIR, listProjectDirs } from '../../../core/utils.js';
|
|
4
|
+
import { parseTasksFile, serializeTasksFile } from '../../../core/task-parser.js';
|
|
5
|
+
function generateHash(existingHashes = new Set()) {
|
|
6
|
+
while (true) {
|
|
7
|
+
const hash = Math.floor(Math.random() * 0x10000).toString(16).padStart(4, '0');
|
|
8
|
+
if (!existingHashes.has(hash))
|
|
9
|
+
return hash;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function collectAllExistingHashes() {
|
|
13
|
+
const allHashes = new Set();
|
|
14
|
+
if (!fs.existsSync(PROJECTS_DIR))
|
|
15
|
+
return allHashes;
|
|
16
|
+
for (const projectName of listProjectDirs()) {
|
|
17
|
+
const tasksPath = path.join(PROJECTS_DIR, projectName, 'TASKS.yaml');
|
|
18
|
+
if (!fs.existsSync(tasksPath))
|
|
19
|
+
continue;
|
|
20
|
+
const tasks = parseTasksFile(fs.readFileSync(tasksPath, 'utf8'), projectName);
|
|
21
|
+
for (const t of tasks) {
|
|
22
|
+
if (t.id)
|
|
23
|
+
allHashes.add(t.id);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return allHashes;
|
|
27
|
+
}
|
|
28
|
+
function assignIds(project = null) {
|
|
29
|
+
if (!fs.existsSync(PROJECTS_DIR)) {
|
|
30
|
+
return { success: false, message: 'Projects directory not found' };
|
|
31
|
+
}
|
|
32
|
+
let totalAssigned = 0;
|
|
33
|
+
const allHashes = collectAllExistingHashes();
|
|
34
|
+
const projects = project ? [project] : listProjectDirs();
|
|
35
|
+
for (const projectName of projects) {
|
|
36
|
+
const tasksPath = path.join(PROJECTS_DIR, projectName, 'TASKS.yaml');
|
|
37
|
+
if (!fs.existsSync(tasksPath))
|
|
38
|
+
continue;
|
|
39
|
+
const tasks = parseTasksFile(fs.readFileSync(tasksPath, 'utf8'), projectName);
|
|
40
|
+
let modified = false;
|
|
41
|
+
for (const task of tasks) {
|
|
42
|
+
if (!task.id || task.id === '') {
|
|
43
|
+
const hash = generateHash(allHashes);
|
|
44
|
+
allHashes.add(hash);
|
|
45
|
+
task.id = hash;
|
|
46
|
+
modified = true;
|
|
47
|
+
totalAssigned += 1;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (modified) {
|
|
51
|
+
fs.writeFileSync(tasksPath, serializeTasksFile(tasks), 'utf8');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { success: true, message: `Assigned ${totalAssigned} task ID(s)`, assigned: totalAssigned };
|
|
55
|
+
}
|
|
56
|
+
function validateIds() {
|
|
57
|
+
if (!fs.existsSync(PROJECTS_DIR)) {
|
|
58
|
+
return { success: false, message: 'Projects directory not found' };
|
|
59
|
+
}
|
|
60
|
+
const idToProjects = new Map();
|
|
61
|
+
for (const projectName of listProjectDirs()) {
|
|
62
|
+
const tasksPath = path.join(PROJECTS_DIR, projectName, 'TASKS.yaml');
|
|
63
|
+
if (!fs.existsSync(tasksPath))
|
|
64
|
+
continue;
|
|
65
|
+
const tasks = parseTasksFile(fs.readFileSync(tasksPath, 'utf8'), projectName);
|
|
66
|
+
for (const task of tasks) {
|
|
67
|
+
if (!task.id)
|
|
68
|
+
continue;
|
|
69
|
+
const existing = idToProjects.get(task.id) || [];
|
|
70
|
+
existing.push(projectName);
|
|
71
|
+
idToProjects.set(task.id, existing);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const collisions = [];
|
|
75
|
+
for (const [hash, projects] of idToProjects) {
|
|
76
|
+
if (projects.length > 1)
|
|
77
|
+
collisions.push({ id: hash, projects });
|
|
78
|
+
}
|
|
79
|
+
if (collisions.length === 0) {
|
|
80
|
+
return { success: true, message: `No collisions found (${idToProjects.size} unique IDs across all projects)`, collisions: [] };
|
|
81
|
+
}
|
|
82
|
+
return { success: false, message: `Found ${collisions.length} cross-project ID collision(s)`, collisions };
|
|
83
|
+
}
|
|
84
|
+
export { assignIds, collectAllExistingHashes, generateHash, validateIds };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Task } from '../../../core/task-parser.js';
|
|
2
|
+
declare function sweepTaskOrphans(tasksPath: string): void;
|
|
3
|
+
declare const VALID_PRIORITIES: Set<string>;
|
|
4
|
+
declare function _resetTemplateNameCacheForTests(): void;
|
|
5
|
+
declare function validateTemplateName(name: string): string | null;
|
|
6
|
+
declare function getTasksPath(project: string): string;
|
|
7
|
+
declare function readTasks(project: string): Task[];
|
|
8
|
+
declare function writeTasks(project: string, tasks: Task[]): void;
|
|
9
|
+
declare function findTaskById(tasks: Task[], taskId: string): Task | undefined;
|
|
10
|
+
declare function findTask(tasks: Task[], taskText: string | null, taskId: string | null): {
|
|
11
|
+
task: Task;
|
|
12
|
+
index: number;
|
|
13
|
+
} | {
|
|
14
|
+
error: string;
|
|
15
|
+
};
|
|
16
|
+
declare function clearDependsOnAll(completedHash: string): {
|
|
17
|
+
count: number;
|
|
18
|
+
tasks: {
|
|
19
|
+
taskId: string | null;
|
|
20
|
+
project: string;
|
|
21
|
+
preview: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
type TaskLineTransformResult = {
|
|
25
|
+
success: true;
|
|
26
|
+
message?: string;
|
|
27
|
+
[k: string]: any;
|
|
28
|
+
} | {
|
|
29
|
+
success: false;
|
|
30
|
+
message: string;
|
|
31
|
+
};
|
|
32
|
+
declare function editTask(project: string, options?: any): TaskLineTransformResult;
|
|
33
|
+
export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, validateTemplateName, writeTasks, };
|
|
34
|
+
export type { TaskLineTransformResult };
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { PROJECTS_DIR, listProjectDirs } from '../../../core/utils.js';
|
|
4
|
+
import { createLogger } from '../../../core/log.js';
|
|
5
|
+
import { loadConfig, listTemplateNames } from '../../threads/template-loader.js';
|
|
6
|
+
import { parseTasksFile, parseTasksFileWithLock, serializeTasksFile, serializeTasksFileWithLock } from '../../../core/task-parser.js';
|
|
7
|
+
const log = createLogger('task-lifecycle');
|
|
8
|
+
// ── Atomic write ──
|
|
9
|
+
function atomicWriteSync(filePath, data) {
|
|
10
|
+
const tmp = `${filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
11
|
+
try {
|
|
12
|
+
fs.writeFileSync(tmp, data, 'utf8');
|
|
13
|
+
fs.renameSync(tmp, filePath);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
try {
|
|
17
|
+
fs.unlinkSync(tmp);
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const sweptPaths = new Set();
|
|
24
|
+
function sweepTaskOrphans(tasksPath) {
|
|
25
|
+
try {
|
|
26
|
+
const dir = path.dirname(tasksPath);
|
|
27
|
+
const base = path.basename(tasksPath);
|
|
28
|
+
const prefix = `${base}.tmp.`;
|
|
29
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
30
|
+
if (entry.startsWith(prefix)) {
|
|
31
|
+
try {
|
|
32
|
+
fs.unlinkSync(path.join(dir, entry));
|
|
33
|
+
}
|
|
34
|
+
catch { }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch { }
|
|
39
|
+
}
|
|
40
|
+
function ensureSwept(tasksPath) {
|
|
41
|
+
if (sweptPaths.has(tasksPath))
|
|
42
|
+
return;
|
|
43
|
+
sweptPaths.add(tasksPath);
|
|
44
|
+
sweepTaskOrphans(tasksPath);
|
|
45
|
+
}
|
|
46
|
+
// ── Template validation ──
|
|
47
|
+
const VALID_PRIORITIES = new Set(['high', 'medium', 'low']);
|
|
48
|
+
let cachedTemplateNames = null;
|
|
49
|
+
function getValidTemplateNames() {
|
|
50
|
+
if (cachedTemplateNames !== null)
|
|
51
|
+
return cachedTemplateNames;
|
|
52
|
+
try {
|
|
53
|
+
loadConfig();
|
|
54
|
+
}
|
|
55
|
+
catch { /* suppress loadConfig output */ }
|
|
56
|
+
cachedTemplateNames = new Set(listTemplateNames());
|
|
57
|
+
return cachedTemplateNames;
|
|
58
|
+
}
|
|
59
|
+
function _resetTemplateNameCacheForTests() {
|
|
60
|
+
cachedTemplateNames = null;
|
|
61
|
+
}
|
|
62
|
+
function validateTemplateName(name) {
|
|
63
|
+
const valid = getValidTemplateNames();
|
|
64
|
+
if (valid.size === 0)
|
|
65
|
+
return null;
|
|
66
|
+
if (!valid.has(name)) {
|
|
67
|
+
return `Unknown template: '${name}'. Valid templates: ${[...valid].sort().join(', ')}`;
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
// ── YAML file I/O ──
|
|
72
|
+
function getTasksPath(project) {
|
|
73
|
+
return path.join(PROJECTS_DIR, project, 'TASKS.yaml');
|
|
74
|
+
}
|
|
75
|
+
function readTasks(project) {
|
|
76
|
+
const tasksPath = getTasksPath(project);
|
|
77
|
+
if (!fs.existsSync(tasksPath))
|
|
78
|
+
return [];
|
|
79
|
+
return parseTasksFile(fs.readFileSync(tasksPath, 'utf8'), project);
|
|
80
|
+
}
|
|
81
|
+
function writeTasks(project, tasks) {
|
|
82
|
+
const tasksPath = getTasksPath(project);
|
|
83
|
+
ensureSwept(tasksPath);
|
|
84
|
+
let lock = null;
|
|
85
|
+
if (fs.existsSync(tasksPath)) {
|
|
86
|
+
const parsed = parseTasksFileWithLock(fs.readFileSync(tasksPath, 'utf8'), project);
|
|
87
|
+
lock = parsed.lock;
|
|
88
|
+
}
|
|
89
|
+
atomicWriteSync(tasksPath, serializeTasksFileWithLock({ tasks, lock }));
|
|
90
|
+
}
|
|
91
|
+
function findTaskById(tasks, taskId) {
|
|
92
|
+
return tasks.find((t) => t.id === taskId);
|
|
93
|
+
}
|
|
94
|
+
function findTask(tasks, taskText, taskId) {
|
|
95
|
+
if (taskId) {
|
|
96
|
+
const index = tasks.findIndex((t) => t.id === taskId);
|
|
97
|
+
if (index >= 0)
|
|
98
|
+
return { task: tasks[index], index };
|
|
99
|
+
}
|
|
100
|
+
if (taskText) {
|
|
101
|
+
const needle = taskText.toLowerCase().trim();
|
|
102
|
+
const matches = [];
|
|
103
|
+
for (const [index, t] of tasks.entries()) {
|
|
104
|
+
const text = t.text.toLowerCase();
|
|
105
|
+
if (needle.includes(text) || text.includes(needle)) {
|
|
106
|
+
matches.push({ task: t, index });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (matches.length === 1)
|
|
110
|
+
return matches[0];
|
|
111
|
+
if (matches.length > 1) {
|
|
112
|
+
const previews = matches.map((m) => ` [${m.task.id}] ${m.task.text.substring(0, 80)}`).join('\n');
|
|
113
|
+
return { error: `Ambiguous match: "${taskText}" matches ${matches.length} tasks. Use --task-id instead.\n${previews}` };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { error: `Task not found: ${taskId || taskText}` };
|
|
117
|
+
}
|
|
118
|
+
// ── Cross-project dependency clearing ──
|
|
119
|
+
function clearDependsOnAll(completedHash) {
|
|
120
|
+
if (!fs.existsSync(PROJECTS_DIR))
|
|
121
|
+
return { count: 0, tasks: [] };
|
|
122
|
+
const unblockedTasks = [];
|
|
123
|
+
for (const projectName of listProjectDirs()) {
|
|
124
|
+
const tasksPath = path.join(PROJECTS_DIR, projectName, 'TASKS.yaml');
|
|
125
|
+
if (!fs.existsSync(tasksPath))
|
|
126
|
+
continue;
|
|
127
|
+
const tasks = parseTasksFile(fs.readFileSync(tasksPath, 'utf8'), projectName);
|
|
128
|
+
let modified = false;
|
|
129
|
+
for (const task of tasks) {
|
|
130
|
+
const idx = task.depends_on.indexOf(completedHash);
|
|
131
|
+
if (idx >= 0) {
|
|
132
|
+
task.depends_on.splice(idx, 1);
|
|
133
|
+
unblockedTasks.push({ taskId: task.id || null, project: projectName, preview: task.text.substring(0, 60) });
|
|
134
|
+
modified = true;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (modified) {
|
|
138
|
+
ensureSwept(tasksPath);
|
|
139
|
+
atomicWriteSync(tasksPath, serializeTasksFile(tasks));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { count: unblockedTasks.length, tasks: unblockedTasks };
|
|
143
|
+
}
|
|
144
|
+
function editTask(project, options = {}) {
|
|
145
|
+
const { taskText = null, taskId = null, text = null, why = null, doneWhen = null, plan = null, priority = null, setDependsOn = null, addDependsOn = [], removeDependsOn = [], clearDependsOn = false, } = options;
|
|
146
|
+
if (priority && !VALID_PRIORITIES.has(priority)) {
|
|
147
|
+
return { success: false, message: `Invalid priority: ${priority}` };
|
|
148
|
+
}
|
|
149
|
+
const expandIdList = (list) => {
|
|
150
|
+
if (!list)
|
|
151
|
+
return null;
|
|
152
|
+
return list.flatMap((d) => d.includes(',') ? d.split(',').map((s) => s.trim()).filter(Boolean) : [d]);
|
|
153
|
+
};
|
|
154
|
+
const expandedSetDependsOn = expandIdList(setDependsOn);
|
|
155
|
+
const expandedAddDependsOn = expandIdList(addDependsOn) ?? [];
|
|
156
|
+
const expandedRemoveDependsOn = expandIdList(removeDependsOn) ?? [];
|
|
157
|
+
for (const dep of [...(expandedSetDependsOn ?? []), ...expandedAddDependsOn, ...expandedRemoveDependsOn]) {
|
|
158
|
+
if (!(/^[0-9a-fA-F]{4}$/).test(dep)) {
|
|
159
|
+
return { success: false, message: `Invalid depends-on id: ${dep}` };
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const tasks = readTasks(project);
|
|
163
|
+
if (tasks.length === 0) {
|
|
164
|
+
const tasksPath = getTasksPath(project);
|
|
165
|
+
if (!fs.existsSync(tasksPath))
|
|
166
|
+
return { success: false, message: `TASKS.yaml not found for project ${project}` };
|
|
167
|
+
}
|
|
168
|
+
const found = findTask(tasks, taskText, taskId);
|
|
169
|
+
if ('error' in found)
|
|
170
|
+
return { success: false, message: found.error };
|
|
171
|
+
const task = found.task;
|
|
172
|
+
const updatedFields = [];
|
|
173
|
+
if (text != null) {
|
|
174
|
+
task.text = text;
|
|
175
|
+
updatedFields.push('text');
|
|
176
|
+
}
|
|
177
|
+
if (why != null) {
|
|
178
|
+
task.why = why;
|
|
179
|
+
updatedFields.push('why');
|
|
180
|
+
}
|
|
181
|
+
if (doneWhen != null) {
|
|
182
|
+
task.done_when = doneWhen;
|
|
183
|
+
updatedFields.push('done_when');
|
|
184
|
+
}
|
|
185
|
+
if (plan != null) {
|
|
186
|
+
task.plan = plan.trim();
|
|
187
|
+
updatedFields.push('plan');
|
|
188
|
+
}
|
|
189
|
+
if (priority != null) {
|
|
190
|
+
task.priority = priority;
|
|
191
|
+
updatedFields.push('priority');
|
|
192
|
+
}
|
|
193
|
+
if (clearDependsOn || expandedSetDependsOn != null) {
|
|
194
|
+
task.depends_on = expandedSetDependsOn ?? [];
|
|
195
|
+
updatedFields.push('depends_on');
|
|
196
|
+
}
|
|
197
|
+
else if (expandedAddDependsOn.length > 0 || expandedRemoveDependsOn.length > 0) {
|
|
198
|
+
task.depends_on = task.depends_on.filter((id) => !expandedRemoveDependsOn.includes(id));
|
|
199
|
+
for (const id of expandedAddDependsOn) {
|
|
200
|
+
if (!task.depends_on.includes(id))
|
|
201
|
+
task.depends_on.push(id);
|
|
202
|
+
}
|
|
203
|
+
updatedFields.push('depends_on');
|
|
204
|
+
}
|
|
205
|
+
writeTasks(project, tasks);
|
|
206
|
+
return { success: true, message: 'Task updated', task_id: taskId, updated_fields: updatedFields };
|
|
207
|
+
}
|
|
208
|
+
export { VALID_PRIORITIES, _resetTemplateNameCacheForTests, clearDependsOnAll, editTask, findTask, findTaskById, getTasksPath, readTasks, sweepTaskOrphans, validateTemplateName, writeTasks, };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { LockState } from '../../../core/task-parser.js';
|
|
2
|
+
export declare function getOwnerIdentity(): string;
|
|
3
|
+
export declare function readLock(project: string): LockState | null;
|
|
4
|
+
export declare function writeLock(project: string, lock: LockState | null): void;
|
|
5
|
+
export declare function acquireLock(project: string, opts: {
|
|
6
|
+
owner: string;
|
|
7
|
+
force?: boolean;
|
|
8
|
+
note?: string;
|
|
9
|
+
}): {
|
|
10
|
+
acquired: boolean;
|
|
11
|
+
lock?: LockState;
|
|
12
|
+
message?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function releaseLock(project: string, owner: string, opts?: {
|
|
15
|
+
force?: boolean;
|
|
16
|
+
}): {
|
|
17
|
+
released: boolean;
|
|
18
|
+
message?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function assertLockHeld(project: string, owner: string): string | null;
|
|
21
|
+
export declare function isProjectLocked(project: string, now?: string): {
|
|
22
|
+
locked: boolean;
|
|
23
|
+
owner?: string;
|
|
24
|
+
expiresAt?: string;
|
|
25
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as os from 'node:os';
|
|
4
|
+
import { PROJECTS_DIR } from '../../../core/utils.js';
|
|
5
|
+
import { createLogger } from '../../../core/log.js';
|
|
6
|
+
import { parseTasksFileWithLock, serializeTasksFileWithLock } from '../../../core/task-parser.js';
|
|
7
|
+
const log = createLogger('task-lock');
|
|
8
|
+
// ── Atomic write ──
|
|
9
|
+
function atomicWriteSync(filePath, data) {
|
|
10
|
+
const tmp = `${filePath}.tmp.${process.pid}.${Date.now()}`;
|
|
11
|
+
try {
|
|
12
|
+
fs.writeFileSync(tmp, data, 'utf8');
|
|
13
|
+
fs.renameSync(tmp, filePath);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
try {
|
|
17
|
+
fs.unlinkSync(tmp);
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// ── Path helpers ──
|
|
24
|
+
function tasksYamlPath(project) {
|
|
25
|
+
return path.join(PROJECTS_DIR, project, 'TASKS.yaml');
|
|
26
|
+
}
|
|
27
|
+
// ── Exports ──
|
|
28
|
+
export function getOwnerIdentity() {
|
|
29
|
+
if (process.env.CORTEX_EXECUTION_ID)
|
|
30
|
+
return process.env.CORTEX_EXECUTION_ID;
|
|
31
|
+
let user;
|
|
32
|
+
try {
|
|
33
|
+
user = os.userInfo().username;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
user = process.env.USER || 'unknown';
|
|
37
|
+
}
|
|
38
|
+
return `manual:${user}:${process.pid}`;
|
|
39
|
+
}
|
|
40
|
+
export function readLock(project) {
|
|
41
|
+
const filePath = tasksYamlPath(project);
|
|
42
|
+
if (!fs.existsSync(filePath))
|
|
43
|
+
return null;
|
|
44
|
+
try {
|
|
45
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
46
|
+
const { lock } = parseTasksFileWithLock(content, project);
|
|
47
|
+
return lock;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
log.warn('Failed to read lock for %s: %s', project, err);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function writeLock(project, lock) {
|
|
55
|
+
const filePath = tasksYamlPath(project);
|
|
56
|
+
let tasks;
|
|
57
|
+
if (fs.existsSync(filePath)) {
|
|
58
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
59
|
+
const parsed = parseTasksFileWithLock(content, project);
|
|
60
|
+
tasks = parsed.tasks;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
tasks = [];
|
|
64
|
+
}
|
|
65
|
+
const yaml = serializeTasksFileWithLock({ tasks, lock });
|
|
66
|
+
atomicWriteSync(filePath, yaml);
|
|
67
|
+
}
|
|
68
|
+
export function acquireLock(project, opts) {
|
|
69
|
+
const { owner, force = false, note } = opts;
|
|
70
|
+
const ttlMs = 1_200_000; // fixed 20 min — TTL is a safety net, LLM is expected to release
|
|
71
|
+
const now = new Date();
|
|
72
|
+
const nowISO = now.toISOString();
|
|
73
|
+
const current = readLock(project);
|
|
74
|
+
if (current && !force) {
|
|
75
|
+
const expiresAt = new Date(current.expires_at);
|
|
76
|
+
if (expiresAt > now) {
|
|
77
|
+
return {
|
|
78
|
+
acquired: false,
|
|
79
|
+
lock: current,
|
|
80
|
+
message: `Lock held by ${current.owner} (expires ${current.expires_at})`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const expiresAt = new Date(now.getTime() + ttlMs).toISOString();
|
|
85
|
+
const newLock = {
|
|
86
|
+
owner,
|
|
87
|
+
acquired_at: nowISO,
|
|
88
|
+
expires_at: expiresAt,
|
|
89
|
+
...(note ? { note } : {}),
|
|
90
|
+
};
|
|
91
|
+
writeLock(project, newLock);
|
|
92
|
+
log.info('Lock acquired for %s by %s (expires %s)', project, owner, expiresAt);
|
|
93
|
+
return { acquired: true, lock: newLock };
|
|
94
|
+
}
|
|
95
|
+
export function releaseLock(project, owner, opts) {
|
|
96
|
+
const current = readLock(project);
|
|
97
|
+
if (!current) {
|
|
98
|
+
return { released: true, message: 'No lock held' };
|
|
99
|
+
}
|
|
100
|
+
if (!opts?.force && current.owner !== owner) {
|
|
101
|
+
return {
|
|
102
|
+
released: false,
|
|
103
|
+
message: `Lock held by different owner: ${current.owner}`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
writeLock(project, null);
|
|
107
|
+
log.info('Lock released for %s by %s', project, owner);
|
|
108
|
+
return { released: true, message: 'Lock released' };
|
|
109
|
+
}
|
|
110
|
+
export function assertLockHeld(project, owner) {
|
|
111
|
+
const current = readLock(project);
|
|
112
|
+
if (!current) {
|
|
113
|
+
return 'No lock held';
|
|
114
|
+
}
|
|
115
|
+
if (current.owner !== owner) {
|
|
116
|
+
return `Lock held by different owner: ${current.owner}`;
|
|
117
|
+
}
|
|
118
|
+
const expiresAt = new Date(current.expires_at);
|
|
119
|
+
if (expiresAt <= new Date()) {
|
|
120
|
+
return `Lock expired at ${current.expires_at}`;
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
export function isProjectLocked(project, now) {
|
|
125
|
+
const current = readLock(project);
|
|
126
|
+
if (!current) {
|
|
127
|
+
return { locked: false };
|
|
128
|
+
}
|
|
129
|
+
const refTime = now ? new Date(now) : new Date();
|
|
130
|
+
const expiresAt = new Date(current.expires_at);
|
|
131
|
+
if (expiresAt <= refTime) {
|
|
132
|
+
return { locked: false };
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
locked: true,
|
|
136
|
+
owner: current.owner,
|
|
137
|
+
expiresAt: current.expires_at,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare function addTask(project: string, text: string | null, why: string | null, doneWhen: string | null, priority?: string, template?: string | null, dependsOn?: string[] | null, plan?: string | null): {
|
|
2
|
+
success: boolean;
|
|
3
|
+
message: string;
|
|
4
|
+
task_id?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
success: boolean;
|
|
7
|
+
message: string;
|
|
8
|
+
task_id: string;
|
|
9
|
+
};
|
|
10
|
+
declare function batchEdit(project: string, taskIds: string[], options?: any): {
|
|
11
|
+
success: boolean;
|
|
12
|
+
message: string;
|
|
13
|
+
results: {
|
|
14
|
+
taskId: string;
|
|
15
|
+
success: boolean;
|
|
16
|
+
message: string;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
declare function decomposeTask(project: string, originalText: string | null, subtasks: Array<{
|
|
20
|
+
text: string;
|
|
21
|
+
template?: string;
|
|
22
|
+
why?: string;
|
|
23
|
+
done_when?: string;
|
|
24
|
+
priority?: string;
|
|
25
|
+
plan?: string;
|
|
26
|
+
depends_on?: string[];
|
|
27
|
+
}>, taskId?: string | null): {
|
|
28
|
+
success: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
};
|
|
31
|
+
export { addTask, batchEdit, decomposeTask };
|