@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,88 @@
|
|
|
1
|
+
// input: schedules.json + JsonRepository
|
|
2
|
+
// output: ScheduleRepo (read / addTask / removeTask / updateTask / rateLimitThrottle)
|
|
3
|
+
// pos: Schedule persistence layer. Based on JsonRepository abstraction (Pattern A), AsyncMutex serializes reads/writes of schedules.json.
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { JsonRepository } from './json-repository.js';
|
|
7
|
+
import { STORE_DIR } from '../core/paths.js';
|
|
8
|
+
export const SCHEDULES_FILE = path.join(STORE_DIR, 'schedules.json');
|
|
9
|
+
function defaultData() {
|
|
10
|
+
return { tasks: [] };
|
|
11
|
+
}
|
|
12
|
+
function migrate(raw) {
|
|
13
|
+
if (typeof raw !== 'object' || raw === null || !('tasks' in raw)) {
|
|
14
|
+
return defaultData();
|
|
15
|
+
}
|
|
16
|
+
const data = raw;
|
|
17
|
+
// Backfill target=fresh on records persisted before the multi-target dispatch landed,
|
|
18
|
+
// so the scheduler can dispatch them through the unified branch table without null-checks.
|
|
19
|
+
for (const task of data.tasks) {
|
|
20
|
+
if (!task.target)
|
|
21
|
+
task.target = { kind: 'fresh' };
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
export class ScheduleRepo {
|
|
26
|
+
_repo;
|
|
27
|
+
constructor(filePath = SCHEDULES_FILE) {
|
|
28
|
+
this._repo = new JsonRepository({
|
|
29
|
+
filePath,
|
|
30
|
+
defaultValue: defaultData,
|
|
31
|
+
migrate,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
async read() {
|
|
35
|
+
return this._repo.read();
|
|
36
|
+
}
|
|
37
|
+
async addTask(task) {
|
|
38
|
+
await this._repo.mutate((data) => {
|
|
39
|
+
data.tasks.push(task);
|
|
40
|
+
return { next: data, result: undefined };
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async removeTask(id) {
|
|
44
|
+
return this._repo.mutate((data) => {
|
|
45
|
+
const idx = data.tasks.findIndex(t => t.id === id);
|
|
46
|
+
if (idx === -1)
|
|
47
|
+
return { next: data, result: false };
|
|
48
|
+
data.tasks.splice(idx, 1);
|
|
49
|
+
return { next: data, result: true };
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async updateTask(id, fn) {
|
|
53
|
+
return this._repo.mutate((data) => {
|
|
54
|
+
const task = data.tasks.find(t => t.id === id);
|
|
55
|
+
if (!task)
|
|
56
|
+
return { next: data, result: null };
|
|
57
|
+
fn(task);
|
|
58
|
+
return { next: data, result: task };
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async findTask(id) {
|
|
62
|
+
const data = await this._repo.read();
|
|
63
|
+
return data.tasks.find(t => t.id === id) || null;
|
|
64
|
+
}
|
|
65
|
+
async setRateLimitThrottle(meta) {
|
|
66
|
+
await this._repo.mutate((data) => {
|
|
67
|
+
data.rateLimitThrottle = meta;
|
|
68
|
+
return { next: data, result: undefined };
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async getRateLimitThrottle() {
|
|
72
|
+
const data = await this._repo.read();
|
|
73
|
+
return data.rateLimitThrottle || null;
|
|
74
|
+
}
|
|
75
|
+
/** Generic mutate passthrough for composite operations. */
|
|
76
|
+
async mutate(fn) {
|
|
77
|
+
return this._repo.mutate(fn);
|
|
78
|
+
}
|
|
79
|
+
/** Drop the in-memory cache so the next read() fetches from disk. Test hook. */
|
|
80
|
+
invalidate() {
|
|
81
|
+
this._repo.invalidate();
|
|
82
|
+
}
|
|
83
|
+
/** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */
|
|
84
|
+
flush() {
|
|
85
|
+
return this._repo.flush();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export const scheduleRepo = new ScheduleRepo(); // default singleton for production use
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const REGISTRY_FILE: string;
|
|
2
|
+
export interface SessionRecord {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
channel: string;
|
|
5
|
+
backend: string;
|
|
6
|
+
kind: 'local' | 'scheduled';
|
|
7
|
+
createdAt: string;
|
|
8
|
+
lastUsedAt: string;
|
|
9
|
+
label: string | null;
|
|
10
|
+
/** Profile name active when the session was created. Restored on !resume. */
|
|
11
|
+
profileName: string | null;
|
|
12
|
+
}
|
|
13
|
+
export type SessionRegistryData = Record<string, SessionRecord>;
|
|
14
|
+
export declare class SessionRegistryRepo {
|
|
15
|
+
private readonly _repo;
|
|
16
|
+
constructor(filePath?: string);
|
|
17
|
+
generateSessionName(): Promise<string>;
|
|
18
|
+
registerSession(name: string, opts: {
|
|
19
|
+
sessionId: string;
|
|
20
|
+
channel: string;
|
|
21
|
+
backend: string;
|
|
22
|
+
kind: 'local' | 'scheduled';
|
|
23
|
+
label?: string | null;
|
|
24
|
+
profileName?: string | null;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
updateSession(name: string, updates: Partial<Pick<SessionRecord, 'sessionId' | 'lastUsedAt' | 'label' | 'profileName'>>): Promise<void>;
|
|
27
|
+
lookupSession(name: string): Promise<SessionRecord | null>;
|
|
28
|
+
lookupBySessionId(sessionId: string): Promise<string | null>;
|
|
29
|
+
listRecentSessions(limit?: number): Promise<Array<{
|
|
30
|
+
name: string;
|
|
31
|
+
} & SessionRecord>>;
|
|
32
|
+
getActiveSessionName(channel: string, backend: string): Promise<string | null>;
|
|
33
|
+
/** Drop the in-memory cache so the next read() fetches from disk. Test hook. */
|
|
34
|
+
invalidate(): void;
|
|
35
|
+
/** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */
|
|
36
|
+
flush(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare const sessionRegistryRepo: SessionRegistryRepo;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// input: session-registry.json + JsonRepository
|
|
2
|
+
// output: SessionRegistryRepo (async generateSessionName / registerSession / updateSession / lookupSession / lookupBySessionId / listRecentSessions / getActiveSessionName)
|
|
3
|
+
// pos: cortex-XXXX short name ↔ session UUID registry persistence layer (Pattern A, JsonRepository)
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import * as crypto from 'crypto';
|
|
7
|
+
import { JsonRepository } from './json-repository.js';
|
|
8
|
+
import { STORE_DIR } from '../core/paths.js';
|
|
9
|
+
import { sessionRepo } from './session-repo.js';
|
|
10
|
+
export const REGISTRY_FILE = path.join(STORE_DIR, 'session-registry.json');
|
|
11
|
+
export class SessionRegistryRepo {
|
|
12
|
+
_repo;
|
|
13
|
+
constructor(filePath = REGISTRY_FILE) {
|
|
14
|
+
this._repo = new JsonRepository({
|
|
15
|
+
filePath,
|
|
16
|
+
defaultValue: () => ({}),
|
|
17
|
+
migrate: (raw) => (typeof raw === 'object' && raw !== null ? raw : ({})),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async generateSessionName() {
|
|
21
|
+
const registry = await this._repo.read();
|
|
22
|
+
for (let i = 0; i < 100; i++) {
|
|
23
|
+
const hex = crypto.randomBytes(3).toString('hex');
|
|
24
|
+
const name = `cortex-${hex}`;
|
|
25
|
+
if (!registry[name])
|
|
26
|
+
return name;
|
|
27
|
+
}
|
|
28
|
+
return `cortex-${crypto.randomBytes(4).toString('hex')}`;
|
|
29
|
+
}
|
|
30
|
+
async registerSession(name, opts) {
|
|
31
|
+
const now = new Date().toISOString();
|
|
32
|
+
await this._repo.mutate((registry) => {
|
|
33
|
+
registry[name] = {
|
|
34
|
+
sessionId: opts.sessionId,
|
|
35
|
+
channel: opts.channel,
|
|
36
|
+
backend: opts.backend,
|
|
37
|
+
kind: opts.kind,
|
|
38
|
+
createdAt: now,
|
|
39
|
+
lastUsedAt: now,
|
|
40
|
+
label: opts.label?.substring(0, 60) || null,
|
|
41
|
+
profileName: opts.profileName ?? null,
|
|
42
|
+
};
|
|
43
|
+
return { next: registry, result: undefined };
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async updateSession(name, updates) {
|
|
47
|
+
await this._repo.mutate((registry) => {
|
|
48
|
+
const record = registry[name];
|
|
49
|
+
if (!record)
|
|
50
|
+
return { next: registry, result: undefined };
|
|
51
|
+
if (updates.sessionId !== undefined)
|
|
52
|
+
record.sessionId = updates.sessionId;
|
|
53
|
+
if (updates.lastUsedAt !== undefined)
|
|
54
|
+
record.lastUsedAt = updates.lastUsedAt;
|
|
55
|
+
if (updates.label !== undefined)
|
|
56
|
+
record.label = updates.label?.substring(0, 60) || null;
|
|
57
|
+
if (updates.profileName !== undefined)
|
|
58
|
+
record.profileName = updates.profileName;
|
|
59
|
+
return { next: registry, result: undefined };
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async lookupSession(name) {
|
|
63
|
+
const registry = await this._repo.read();
|
|
64
|
+
return registry[name] || null;
|
|
65
|
+
}
|
|
66
|
+
async lookupBySessionId(sessionId) {
|
|
67
|
+
const registry = await this._repo.read();
|
|
68
|
+
for (const [name, record] of Object.entries(registry)) {
|
|
69
|
+
if (record.sessionId === sessionId)
|
|
70
|
+
return name;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
async listRecentSessions(limit = 10) {
|
|
75
|
+
const registry = await this._repo.read();
|
|
76
|
+
return Object.entries(registry)
|
|
77
|
+
.map(([name, record]) => ({ name, ...record }))
|
|
78
|
+
.sort((a, b) => b.lastUsedAt.localeCompare(a.lastUsedAt))
|
|
79
|
+
.slice(0, limit);
|
|
80
|
+
}
|
|
81
|
+
async getActiveSessionName(channel, backend) {
|
|
82
|
+
const sessionId = await sessionRepo.getSessionAsync(channel, backend);
|
|
83
|
+
if (!sessionId)
|
|
84
|
+
return null;
|
|
85
|
+
return this.lookupBySessionId(sessionId);
|
|
86
|
+
}
|
|
87
|
+
/** Drop the in-memory cache so the next read() fetches from disk. Test hook. */
|
|
88
|
+
invalidate() {
|
|
89
|
+
this._repo.invalidate();
|
|
90
|
+
}
|
|
91
|
+
/** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */
|
|
92
|
+
flush() {
|
|
93
|
+
return this._repo.flush();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export const sessionRegistryRepo = new SessionRegistryRepo();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Shape of sessions.json: `{"backend:channel": sessionId, "legacyChannel": sessionId, ...}` */
|
|
2
|
+
export type SessionsData = Record<string, string>;
|
|
3
|
+
declare class SessionRepo {
|
|
4
|
+
private _repo;
|
|
5
|
+
getSessionAsync(channel: string, backend: string): Promise<string | undefined>;
|
|
6
|
+
setSessionAsync(channel: string, sessionId: string, backend: string): Promise<void>;
|
|
7
|
+
deleteSessionAsync(channel: string, backend: string): Promise<void>;
|
|
8
|
+
/** Drop the in-memory cache so the next read() fetches from disk. Test hook. */
|
|
9
|
+
invalidate(): void;
|
|
10
|
+
/** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */
|
|
11
|
+
flush(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare const sessionRepo: SessionRepo;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// input: sessions.json + JsonRepository
|
|
2
|
+
// output: SessionRepo (async getSessionAsync / setSessionAsync / deleteSessionAsync)
|
|
3
|
+
// pos: Session persistence layer. Based on JsonRepository abstraction, AsyncMutex serializes reads/writes of sessions.json.
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { JsonRepository } from './json-repository.js';
|
|
7
|
+
import { STORE_DIR } from '../core/paths.js';
|
|
8
|
+
const SESSIONS_FILE = path.join(STORE_DIR, 'sessions.json');
|
|
9
|
+
/** Key format: `backend:channel`. */
|
|
10
|
+
function sessionKey(backend, channel) {
|
|
11
|
+
return `${backend}:${channel}`;
|
|
12
|
+
}
|
|
13
|
+
/** Whether a channel name should be treated as "bare" (eligible for legacy-key cleanup). */
|
|
14
|
+
function isBareChannel(channel) {
|
|
15
|
+
return !channel.includes(':');
|
|
16
|
+
}
|
|
17
|
+
/** Remove a legacy bare-channel key if the channel qualifies. */
|
|
18
|
+
function removeLegacyKey(sessions, channel) {
|
|
19
|
+
if (isBareChannel(channel) && channel in sessions) {
|
|
20
|
+
delete sessions[channel];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class SessionRepo {
|
|
24
|
+
_repo = new JsonRepository({
|
|
25
|
+
filePath: SESSIONS_FILE,
|
|
26
|
+
defaultValue: () => ({}),
|
|
27
|
+
migrate: (raw) => (typeof raw === 'object' && raw !== null ? raw : ({})),
|
|
28
|
+
});
|
|
29
|
+
async getSessionAsync(channel, backend) {
|
|
30
|
+
const sessions = await this._repo.read();
|
|
31
|
+
return sessions[sessionKey(backend, channel)] ?? sessions[channel] ?? undefined;
|
|
32
|
+
}
|
|
33
|
+
async setSessionAsync(channel, sessionId, backend) {
|
|
34
|
+
await this._repo.mutate((sessions) => {
|
|
35
|
+
sessions[sessionKey(backend, channel)] = sessionId;
|
|
36
|
+
removeLegacyKey(sessions, channel);
|
|
37
|
+
return { next: sessions, result: undefined };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async deleteSessionAsync(channel, backend) {
|
|
41
|
+
await this._repo.mutate((sessions) => {
|
|
42
|
+
delete sessions[sessionKey(backend, channel)];
|
|
43
|
+
removeLegacyKey(sessions, channel);
|
|
44
|
+
return { next: sessions, result: undefined };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** Drop the in-memory cache so the next read() fetches from disk. Test hook. */
|
|
48
|
+
invalidate() {
|
|
49
|
+
this._repo.invalidate();
|
|
50
|
+
}
|
|
51
|
+
/** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */
|
|
52
|
+
flush() {
|
|
53
|
+
return this._repo.flush();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export const sessionRepo = new SessionRepo();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare function withGitLock<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
2
|
+
export interface TaskRepoOptions {
|
|
3
|
+
/** Skip git-add/commit/push after mutations — for tests. Defaults to false. */
|
|
4
|
+
skipGit?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class TaskRepo {
|
|
7
|
+
private tasks;
|
|
8
|
+
private taskMutex;
|
|
9
|
+
private initialized;
|
|
10
|
+
private readonly skipGit;
|
|
11
|
+
constructor(opts?: TaskRepoOptions);
|
|
12
|
+
/** Load all tasks from TASKS.yaml files into memory */
|
|
13
|
+
load(): void;
|
|
14
|
+
/** Reload tasks from files (e.g. after external edit or git pull) */
|
|
15
|
+
refresh(): void;
|
|
16
|
+
/**
|
|
17
|
+
* WARNING: this refreshes from disk on every call — `load()` walks every TASKS.yaml.
|
|
18
|
+
* task-dispatcher invokes this on every dispatch tick, so this is a
|
|
19
|
+
* hot path. If you observe dispatcher latency regression, this is the first
|
|
20
|
+
* suspect — consider caching or splitting into a `getActionableCached()` fast-path.
|
|
21
|
+
*/
|
|
22
|
+
getActionable(): any[];
|
|
23
|
+
getAll(project?: string): any[];
|
|
24
|
+
getById(taskId: string): any | null;
|
|
25
|
+
getStats(): any;
|
|
26
|
+
getGpuBusyMachines(): Map<string, number>;
|
|
27
|
+
runExclusive<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Wait for any in-flight `runExclusive` / mutation to drain.
|
|
30
|
+
* Acquire-release the mutex; FIFO ordering guarantees all preceding
|
|
31
|
+
* operations have completed when this resolves.
|
|
32
|
+
* Git sync is synchronous so it's always done by the time mutex releases.
|
|
33
|
+
* Known limitation: asyncPush errors may be lost during SIGTERM drain —
|
|
34
|
+
* matching current task-store.ts behavior.
|
|
35
|
+
*/
|
|
36
|
+
flush(): Promise<void>;
|
|
37
|
+
/** Commit TASKS.yaml changes and push to origin/main */
|
|
38
|
+
commitAndPush(message: string): void;
|
|
39
|
+
private asyncPush;
|
|
40
|
+
}
|
|
41
|
+
export declare const taskStore: TaskRepo;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// input: TASKS.yaml files per project, core/task-parser
|
|
2
|
+
// output: { taskStore, withGitLock } — TaskRepo singleton + git lock helper
|
|
3
|
+
// pos: Serialized coordination center for TASKS.yaml changes. Based on core/AsyncMutex + atomicWrite (Pattern B)
|
|
4
|
+
// S4: mutation shim methods removed, now lives in domain/tasks/mutator.ts
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { execSync, execFileSync, spawn } from 'child_process';
|
|
8
|
+
import { PROJECTS_DIR, DATA_DIR } from '../core/utils.js';
|
|
9
|
+
import { scanAllTasks, scanAvailableTasks, getTaskStatsFromTasks, } from '../core/task-parser.js';
|
|
10
|
+
import { createLogger } from '../core/log.js';
|
|
11
|
+
import { AsyncMutex } from '../core/async-mutex.js';
|
|
12
|
+
const log = createLogger('task-store');
|
|
13
|
+
// --- Git mutex (shared across TaskRepo) ---
|
|
14
|
+
const gitMutex = new AsyncMutex();
|
|
15
|
+
export function withGitLock(fn) {
|
|
16
|
+
return gitMutex.run(fn);
|
|
17
|
+
}
|
|
18
|
+
export class TaskRepo {
|
|
19
|
+
tasks = [];
|
|
20
|
+
taskMutex = new AsyncMutex();
|
|
21
|
+
initialized = false;
|
|
22
|
+
skipGit;
|
|
23
|
+
constructor(opts = {}) {
|
|
24
|
+
this.skipGit = opts.skipGit ?? false;
|
|
25
|
+
}
|
|
26
|
+
/** Load all tasks from TASKS.yaml files into memory */
|
|
27
|
+
load() {
|
|
28
|
+
try {
|
|
29
|
+
this.tasks = scanAllTasks();
|
|
30
|
+
this.initialized = true;
|
|
31
|
+
log.info(`Loaded ${this.tasks.length} tasks from ${new Set(this.tasks.map(t => t.project)).size} projects`);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
log.error(`Failed to load tasks: ${e.message}`);
|
|
35
|
+
this.tasks = [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Reload tasks from files (e.g. after external edit or git pull) */
|
|
39
|
+
refresh() {
|
|
40
|
+
this.load();
|
|
41
|
+
}
|
|
42
|
+
// --- Read operations (from memory, no lock needed) ---
|
|
43
|
+
/**
|
|
44
|
+
* WARNING: this refreshes from disk on every call — `load()` walks every TASKS.yaml.
|
|
45
|
+
* task-dispatcher invokes this on every dispatch tick, so this is a
|
|
46
|
+
* hot path. If you observe dispatcher latency regression, this is the first
|
|
47
|
+
* suspect — consider caching or splitting into a `getActionableCached()` fast-path.
|
|
48
|
+
*/
|
|
49
|
+
getActionable() {
|
|
50
|
+
// Always refresh from disk so this.tasks stays in sync with what we return
|
|
51
|
+
this.load();
|
|
52
|
+
return scanAvailableTasks();
|
|
53
|
+
}
|
|
54
|
+
getAll(project) {
|
|
55
|
+
if (!this.initialized)
|
|
56
|
+
this.load();
|
|
57
|
+
return project ? this.tasks.filter(t => t.project === project) : [...this.tasks];
|
|
58
|
+
}
|
|
59
|
+
getById(taskId) {
|
|
60
|
+
if (!this.initialized)
|
|
61
|
+
this.load();
|
|
62
|
+
return this.tasks.find(t => t.id === taskId) || null;
|
|
63
|
+
}
|
|
64
|
+
getStats() {
|
|
65
|
+
if (!this.initialized)
|
|
66
|
+
this.load();
|
|
67
|
+
return getTaskStatsFromTasks(this.tasks);
|
|
68
|
+
}
|
|
69
|
+
getGpuBusyMachines() {
|
|
70
|
+
if (!this.initialized)
|
|
71
|
+
this.load();
|
|
72
|
+
const counts = new Map();
|
|
73
|
+
for (const t of this.tasks) {
|
|
74
|
+
if (t.gpu && t.claimed_by && t.status !== 'done') {
|
|
75
|
+
const machine = t.gpu.toLowerCase();
|
|
76
|
+
const gpuCount = t.gpu_count || 1;
|
|
77
|
+
counts.set(machine, (counts.get(machine) || 0) + gpuCount);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return counts;
|
|
81
|
+
}
|
|
82
|
+
// --- External exclusive access (for callers like task-archiver) ---
|
|
83
|
+
async runExclusive(fn) {
|
|
84
|
+
return this.taskMutex.run(fn);
|
|
85
|
+
}
|
|
86
|
+
// --- Graceful shutdown ---
|
|
87
|
+
/**
|
|
88
|
+
* Wait for any in-flight `runExclusive` / mutation to drain.
|
|
89
|
+
* Acquire-release the mutex; FIFO ordering guarantees all preceding
|
|
90
|
+
* operations have completed when this resolves.
|
|
91
|
+
* Git sync is synchronous so it's always done by the time mutex releases.
|
|
92
|
+
* Known limitation: asyncPush errors may be lost during SIGTERM drain —
|
|
93
|
+
* matching current task-store.ts behavior.
|
|
94
|
+
*/
|
|
95
|
+
async flush() {
|
|
96
|
+
await this.taskMutex.run(async () => { });
|
|
97
|
+
}
|
|
98
|
+
// --- Git sync ---
|
|
99
|
+
/** Commit TASKS.yaml changes and push to origin/main */
|
|
100
|
+
commitAndPush(message) {
|
|
101
|
+
if (this.skipGit)
|
|
102
|
+
return;
|
|
103
|
+
try {
|
|
104
|
+
const rel = path.relative(DATA_DIR, PROJECTS_DIR);
|
|
105
|
+
const glob = `${rel}/*/TASKS.yaml`;
|
|
106
|
+
execSync(`git add "${glob}"`, { cwd: DATA_DIR, timeout: 10000 });
|
|
107
|
+
const status = execSync(`git status --porcelain -- "${glob}"`, {
|
|
108
|
+
cwd: DATA_DIR, encoding: 'utf8', timeout: 5000,
|
|
109
|
+
}).trim();
|
|
110
|
+
if (status) {
|
|
111
|
+
execFileSync('git', ['commit', '-m', message], { cwd: DATA_DIR, timeout: 10000 });
|
|
112
|
+
log.info(`Committed: ${message}`);
|
|
113
|
+
this.asyncPush();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
log.error(`Git sync failed: ${e.message}`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
asyncPush() {
|
|
121
|
+
const child = spawn('git', ['push', 'origin', 'main'], {
|
|
122
|
+
cwd: DATA_DIR,
|
|
123
|
+
stdio: ['ignore', 'ignore', 'pipe'],
|
|
124
|
+
detached: true,
|
|
125
|
+
});
|
|
126
|
+
let stderr = '';
|
|
127
|
+
child.stderr.on('data', (d) => { stderr += d; });
|
|
128
|
+
child.on('close', (code) => {
|
|
129
|
+
if (code !== 0) {
|
|
130
|
+
log.error(`Async push failed (exit ${code}): ${stderr.trim()}`);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
child.unref();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// --- Singleton ---
|
|
137
|
+
export const taskStore = new TaskRepo();
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ThreadRecord, ThreadId } from '../core/types/thread-types.js';
|
|
2
|
+
declare class ThreadRepo {
|
|
3
|
+
/** In-memory source of truth for all thread records. All sync reads come from here. */
|
|
4
|
+
private map;
|
|
5
|
+
private repo;
|
|
6
|
+
/** Serializes all persist operations (set, delete, mutate, lifecycle). */
|
|
7
|
+
private mutex;
|
|
8
|
+
/** Promise chain for `set()`/`delete()`-initiated persists, guarded by this.mutex. */
|
|
9
|
+
private _pendingPersist;
|
|
10
|
+
/** Load threads from disk into memory. Populates the Map from threads.json. */
|
|
11
|
+
load(): void;
|
|
12
|
+
generateId(): ThreadId;
|
|
13
|
+
get(id: ThreadId): ThreadRecord | null;
|
|
14
|
+
/**
|
|
15
|
+
* Insert or replace a thread record. Updates `updatedAt` and queues a persist.
|
|
16
|
+
* Map update is synchronous; disk write is queued through the mutex.
|
|
17
|
+
* Returns the persist promise for callers that need to await it.
|
|
18
|
+
*/
|
|
19
|
+
set(record: ThreadRecord): Promise<void>;
|
|
20
|
+
/** Remove a thread and queue a persist. */
|
|
21
|
+
delete(id: ThreadId): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Mutate a single thread's record in-place, updating `updatedAt` and persisting.
|
|
24
|
+
* Awaits any pending `set()`/`delete()` persists, then acquires the mutex for
|
|
25
|
+
* a serialized read-modify-write.
|
|
26
|
+
*/
|
|
27
|
+
mutate(id: ThreadId, fn: (t: ThreadRecord) => void): Promise<void>;
|
|
28
|
+
/** Await all pending `set()`/`delete()` disk writes AND any in-flight `mutate()`.
|
|
29
|
+
* For graceful SIGTERM drain and test cleanup.
|
|
30
|
+
* Two awaits because set/delete queue through _pendingPersist while mutate/cleanup/
|
|
31
|
+
* markRunningAsFailedOnStartup acquire this.mutex directly after awaiting the chain. */
|
|
32
|
+
flush(): Promise<void>;
|
|
33
|
+
findByChannel(channel: string): ThreadRecord[];
|
|
34
|
+
findByPlatformThread(channel: string, platformThreadId: string): ThreadRecord | null;
|
|
35
|
+
findActive(channel: string): ThreadRecord | null;
|
|
36
|
+
getAll(): ThreadRecord[];
|
|
37
|
+
markRunningAsFailedOnStartup(): Promise<number>;
|
|
38
|
+
/** Remove threads older than maxAge (default 7 days), including workspace directories.
|
|
39
|
+
* Auto-records (no workspace) use a shorter 24h TTL since they only need to
|
|
40
|
+
* survive long enough for !thread add chaining. */
|
|
41
|
+
cleanup(maxAgeMs?: number): Promise<number>;
|
|
42
|
+
/** Queue a persist through the mutex, chaining off any prior persist. Returns the promise.
|
|
43
|
+
* Errors are caught at the chain level so a single I/O failure does not poison all subsequent
|
|
44
|
+
* writes (returning a rejected chain would short-circuit every follow-up `.then`). */
|
|
45
|
+
queuePersist(): Promise<void>;
|
|
46
|
+
/** Atomically persist the entire Map to disk. Uses `repo.write()` (no read-modify-write needed). */
|
|
47
|
+
private persist;
|
|
48
|
+
}
|
|
49
|
+
export declare const threadStore: ThreadRepo;
|
|
50
|
+
export {};
|