@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,261 @@
|
|
|
1
|
+
export type ThreadId = string;
|
|
2
|
+
export type AgentSlotId = string;
|
|
3
|
+
export type ThreadStatus = 'running' | 'waiting' | 'completed' | 'failed' | 'cancelled' | 'aborted';
|
|
4
|
+
/** A named stage of an agent. When an agent declares `stages`, each transition target
|
|
5
|
+
* may select one stage (syntax `"agent:stage"`). Stages that set `continuesSession: true`
|
|
6
|
+
* send only an incremental prompt when the persistent session is being resumed — the
|
|
7
|
+
* directive, protocol preamble and auto `previousOutput` injection are all skipped.
|
|
8
|
+
* Stage prompts MUST reference `{{artifactPath}}` so the agent can self-recover when
|
|
9
|
+
* the Claude session is lost and the full-bootstrap fallback kicks in. */
|
|
10
|
+
export interface StageDefinition {
|
|
11
|
+
promptTemplate: string;
|
|
12
|
+
continuesSession?: boolean;
|
|
13
|
+
description?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface AgentDefinition {
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
profile: string;
|
|
19
|
+
persistSession: boolean;
|
|
20
|
+
directive?: string;
|
|
21
|
+
systemPrompt?: string;
|
|
22
|
+
promptTemplate?: string;
|
|
23
|
+
claudeAgent?: string;
|
|
24
|
+
outputStyle?: string;
|
|
25
|
+
tools?: string;
|
|
26
|
+
pluginDirs?: string[];
|
|
27
|
+
/** Optional per-stage prompt map. When set, `promptTemplate` is ignored and the engine
|
|
28
|
+
* selects one stage per step based on the transition target (`"agent:stage"` syntax). */
|
|
29
|
+
stages?: Record<string, StageDefinition>;
|
|
30
|
+
/** Default stage for transitions that target this agent without an explicit stage
|
|
31
|
+
* (`"agent"` rather than `"agent:stage"`). Required when `stages` has >1 entry; defaults to
|
|
32
|
+
* the first declared stage otherwise. */
|
|
33
|
+
entryStage?: string;
|
|
34
|
+
}
|
|
35
|
+
/** Template can reference an agent by name (string) or with per-template overrides (object) */
|
|
36
|
+
export type TemplateAgentRef = string | {
|
|
37
|
+
ref: string;
|
|
38
|
+
promptTemplate?: string;
|
|
39
|
+
directive?: string;
|
|
40
|
+
systemPrompt?: string;
|
|
41
|
+
persistSession?: boolean;
|
|
42
|
+
claudeAgent?: string;
|
|
43
|
+
outputStyle?: string;
|
|
44
|
+
tools?: string;
|
|
45
|
+
pluginDirs?: string[];
|
|
46
|
+
};
|
|
47
|
+
export interface AgentSlotConfig {
|
|
48
|
+
slotId: AgentSlotId;
|
|
49
|
+
profile: string;
|
|
50
|
+
persistSession: boolean;
|
|
51
|
+
directive?: string;
|
|
52
|
+
systemPrompt?: string;
|
|
53
|
+
promptTemplate?: string;
|
|
54
|
+
claudeAgent?: string;
|
|
55
|
+
outputStyle?: string;
|
|
56
|
+
tools?: string;
|
|
57
|
+
pluginDirs?: string[];
|
|
58
|
+
/** Per-stage prompts (merged from AgentDefinition; templates currently don't override per stage). */
|
|
59
|
+
stages?: Record<string, StageDefinition>;
|
|
60
|
+
/** Default stage when a transition target omits the `:stage` suffix. */
|
|
61
|
+
entryStage?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface TransitionCondition {
|
|
64
|
+
type: 'always' | 'convergence' | 'output_contains' | 'output_not_contains';
|
|
65
|
+
marker?: string;
|
|
66
|
+
pattern?: string;
|
|
67
|
+
maxIterations?: number;
|
|
68
|
+
}
|
|
69
|
+
/** Transition endpoint. Accepts either `"agent"` (selects agent's entryStage) or `"agent:stage"`.
|
|
70
|
+
* Parsed at transition-evaluation time by `parseTarget`. */
|
|
71
|
+
export type TransitionEndpoint = string;
|
|
72
|
+
export interface TransitionRule {
|
|
73
|
+
from: TransitionEndpoint;
|
|
74
|
+
to: TransitionEndpoint;
|
|
75
|
+
condition: TransitionCondition;
|
|
76
|
+
}
|
|
77
|
+
/** Hook configuration: execute external script at a specific point in the thread lifecycle;
|
|
78
|
+
* the script can decide whether to insert a temporary agent.
|
|
79
|
+
*
|
|
80
|
+
* `command` is the full shell invocation string; callers write the interpreter directly
|
|
81
|
+
* (e.g. "node ~/.cortex/hooks/xxx.mjs", "bash /path/to/handler.sh", etc.).
|
|
82
|
+
* Aligns with Claude Code settings.json hooks `{ type: "command", command: "..." }` —
|
|
83
|
+
* no longer depends on the script's +x bit.
|
|
84
|
+
*
|
|
85
|
+
* `args` are runtime positional arguments appended via the `sh -c 'cmd "$@"'` spawn mechanism,
|
|
86
|
+
* passed as `$1..$N`. Dynamic parameters (e.g. task_id, project name) go here instead of
|
|
87
|
+
* being concatenated into the command string.
|
|
88
|
+
*
|
|
89
|
+
* spawn cwd = REPO_ROOT; relative paths are resolved from the repo root.
|
|
90
|
+
*/
|
|
91
|
+
export interface ThreadHookConfig {
|
|
92
|
+
command: string;
|
|
93
|
+
args?: string[];
|
|
94
|
+
timeout?: number;
|
|
95
|
+
}
|
|
96
|
+
/** Result returned by hook script (stdout JSON)
|
|
97
|
+
* Two modes:
|
|
98
|
+
* 1. insertAgent: true → create a new temporary agent to execute the prompt
|
|
99
|
+
* 2. targetAgent: "slotId" → send prompt to an existing agent's persistent session (stdin if alive, --resume if dead)
|
|
100
|
+
*/
|
|
101
|
+
export interface HookResult {
|
|
102
|
+
insertAgent: boolean;
|
|
103
|
+
targetAgent?: AgentSlotId;
|
|
104
|
+
prompt?: string;
|
|
105
|
+
profile?: string;
|
|
106
|
+
directive?: string;
|
|
107
|
+
}
|
|
108
|
+
/** Context received by hook script (stdin JSON) */
|
|
109
|
+
export interface HookContext {
|
|
110
|
+
threadId: string;
|
|
111
|
+
templateName: string;
|
|
112
|
+
phase: 'start' | 'transition' | 'end';
|
|
113
|
+
currentStepIndex: number;
|
|
114
|
+
steps: AgentStep[];
|
|
115
|
+
activeAgent: string;
|
|
116
|
+
previousAgent?: string;
|
|
117
|
+
artifactContent: string;
|
|
118
|
+
userMessage: string;
|
|
119
|
+
totalCostUsd: number;
|
|
120
|
+
}
|
|
121
|
+
/** Lifecycle hooks for thread templates */
|
|
122
|
+
export interface ThreadHooks {
|
|
123
|
+
onStart?: ThreadHookConfig;
|
|
124
|
+
onTransition?: ThreadHookConfig;
|
|
125
|
+
onEnd?: ThreadHookConfig;
|
|
126
|
+
}
|
|
127
|
+
export interface ThreadTemplate {
|
|
128
|
+
name: string;
|
|
129
|
+
description: string;
|
|
130
|
+
agents: TemplateAgentRef[];
|
|
131
|
+
transitions: TransitionRule[];
|
|
132
|
+
entryAgent: AgentSlotId;
|
|
133
|
+
/** Stage to enter on the first step. Defaults to the agent's own `entryStage` (or its
|
|
134
|
+
* single `promptTemplate` pseudo-stage) when omitted. */
|
|
135
|
+
entryStage?: string;
|
|
136
|
+
maxTotalSteps: number;
|
|
137
|
+
maxTotalCostUsd?: number;
|
|
138
|
+
hooks?: ThreadHooks;
|
|
139
|
+
}
|
|
140
|
+
export interface ThreadConfigFile {
|
|
141
|
+
agents: Record<string, AgentDefinition>;
|
|
142
|
+
templates: Record<string, ThreadTemplate>;
|
|
143
|
+
}
|
|
144
|
+
/** @deprecated Use ThreadConfigFile */
|
|
145
|
+
export interface ThreadTemplatesFile {
|
|
146
|
+
templates: Record<string, ThreadTemplate>;
|
|
147
|
+
}
|
|
148
|
+
export interface AgentStep {
|
|
149
|
+
stepIndex: number;
|
|
150
|
+
agentSlotId: AgentSlotId;
|
|
151
|
+
/** Stage name this step ran. Null for single-stage agents (no `stages` map declared). */
|
|
152
|
+
stage: string | null;
|
|
153
|
+
executionId: string | null;
|
|
154
|
+
sessionId: string | null;
|
|
155
|
+
sessionName: string | null;
|
|
156
|
+
input: string;
|
|
157
|
+
output: string | null;
|
|
158
|
+
costUsd: number | null;
|
|
159
|
+
numTurns: number | null;
|
|
160
|
+
durationS: number | null;
|
|
161
|
+
startedAt: string | null;
|
|
162
|
+
endedAt: string | null;
|
|
163
|
+
}
|
|
164
|
+
export interface AgentSlot {
|
|
165
|
+
slotId: AgentSlotId;
|
|
166
|
+
profile: string;
|
|
167
|
+
sessionId: string | null;
|
|
168
|
+
sessionName: string | null;
|
|
169
|
+
status: 'idle' | 'running' | 'completed';
|
|
170
|
+
lastOutput: string | null;
|
|
171
|
+
persistSession: boolean;
|
|
172
|
+
}
|
|
173
|
+
export interface ThreadRecord {
|
|
174
|
+
id: ThreadId;
|
|
175
|
+
templateName: string | null;
|
|
176
|
+
status: ThreadStatus;
|
|
177
|
+
channel: string;
|
|
178
|
+
platformThreadId: string | null;
|
|
179
|
+
userMessage: string;
|
|
180
|
+
userMessageTs: string;
|
|
181
|
+
workspacePath: string;
|
|
182
|
+
artifactPath: string;
|
|
183
|
+
agents: Record<AgentSlotId, AgentSlot>;
|
|
184
|
+
activeAgent: AgentSlotId;
|
|
185
|
+
/** Stage to run in the next step. Null for single-stage agents or pre-stage threads. */
|
|
186
|
+
activeStage: string | null;
|
|
187
|
+
currentStepIndex: number;
|
|
188
|
+
steps: AgentStep[];
|
|
189
|
+
iterationCounts: Record<string, number>;
|
|
190
|
+
totalCostUsd: number;
|
|
191
|
+
createdAt: string;
|
|
192
|
+
updatedAt: string;
|
|
193
|
+
endedAt: string | null;
|
|
194
|
+
error: string | null;
|
|
195
|
+
/** Agent-self-reported abort reason (set when status='aborted'); null otherwise. */
|
|
196
|
+
abortReason: string | null;
|
|
197
|
+
metadata?: ThreadMetadata | null;
|
|
198
|
+
}
|
|
199
|
+
/** Caller-provided metadata stored on ThreadRecord, used by thread-runner for execution registry etc. */
|
|
200
|
+
export interface ThreadMetadata {
|
|
201
|
+
scheduleTaskId?: string | null;
|
|
202
|
+
trigger?: string | null;
|
|
203
|
+
project?: string | null;
|
|
204
|
+
profileOverride?: string | null;
|
|
205
|
+
/** Messages buffered while a step was executing, to be included in the next step's prompt. */
|
|
206
|
+
pendingMessages?: string[];
|
|
207
|
+
}
|
|
208
|
+
export interface StepResult {
|
|
209
|
+
done: boolean;
|
|
210
|
+
reason?: 'converged' | 'max_iterations' | 'max_steps' | 'no_transition' | 'cost_limit' | 'error' | 'cancelled' | 'aborted';
|
|
211
|
+
step?: AgentStep;
|
|
212
|
+
}
|
|
213
|
+
export interface TransitionResult {
|
|
214
|
+
shouldTransition: boolean;
|
|
215
|
+
nextAgent?: AgentSlotId;
|
|
216
|
+
/** Stage name to run on the next agent. Null for single-stage agents. */
|
|
217
|
+
nextStage?: string | null;
|
|
218
|
+
reason: 'transition' | 'converged' | 'max_iterations' | 'cost_limit' | 'no_matching_transition';
|
|
219
|
+
}
|
|
220
|
+
import type { PlatformAdapter, MessageRef } from '../../platform/index.js';
|
|
221
|
+
export interface RunThreadOptions {
|
|
222
|
+
adapter: PlatformAdapter;
|
|
223
|
+
channel: string;
|
|
224
|
+
threadTs: string | null;
|
|
225
|
+
statusMsg: MessageRef | null;
|
|
226
|
+
startTime: number;
|
|
227
|
+
existingSessionId: string | null;
|
|
228
|
+
/** Pre-resolved session name from the caller (e.g. agent-runner).
|
|
229
|
+
* buildStepConfig reuses it for default threads instead of generating a new name. */
|
|
230
|
+
sessionName?: string | null;
|
|
231
|
+
onAssistantMessage?: ((text: string) => void) | null;
|
|
232
|
+
onProgress?: ((progress: any) => void) | null;
|
|
233
|
+
onFallback?: any;
|
|
234
|
+
onToolUse?: ((name: string, input: any) => void) | null;
|
|
235
|
+
isUserInitiated?: boolean;
|
|
236
|
+
files?: any[];
|
|
237
|
+
/** Called by the facade event loop when a plan_written NormalizedEvent fires (PI backend: during turn, not after). */
|
|
238
|
+
onPlanWritten?: ((event: {
|
|
239
|
+
path: string;
|
|
240
|
+
content: string;
|
|
241
|
+
toolUseId: string;
|
|
242
|
+
}) => void) | null;
|
|
243
|
+
/** Called by the facade event loop when an ask_user_question NormalizedEvent fires (PI backend: during turn). */
|
|
244
|
+
onAskUserQuestion?: ((event: {
|
|
245
|
+
toolUseId: string;
|
|
246
|
+
questions: Array<{
|
|
247
|
+
question: string;
|
|
248
|
+
options?: string[];
|
|
249
|
+
multi?: boolean;
|
|
250
|
+
}>;
|
|
251
|
+
}) => void) | null;
|
|
252
|
+
/** Per-call lifecycle hooks injected by the caller (task-dispatcher / scheduled-runner / etc.).
|
|
253
|
+
* Executed AFTER the template's hook at the same phase (template first, extra second) and share
|
|
254
|
+
* the same execution semantics (HookContext via stdin, insertAgent / targetAgent result).
|
|
255
|
+
* Not persisted to ThreadRecord — valid only for this runThread() invocation. */
|
|
256
|
+
extraHooks?: {
|
|
257
|
+
onStart?: ThreadHookConfig;
|
|
258
|
+
onTransition?: ThreadHookConfig;
|
|
259
|
+
onEnd?: ThreadHookConfig;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// input: thread-templates.json, runtime thread state
|
|
2
|
+
// output: TypeScript types and schema for Thread/Agent/Template/Hook/Stage
|
|
3
|
+
// pos: shared type definitions for the Thread system
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR } from './paths.js';
|
|
2
|
+
/** Directories to skip during recursive filesystem scans */
|
|
3
|
+
declare const SKIP_DIRS: Set<string>;
|
|
4
|
+
declare function moduleDir(importMetaUrl: any): string;
|
|
5
|
+
declare function isMainModule(importMetaUrl: any): boolean;
|
|
6
|
+
declare function readableTimestamp(): string;
|
|
7
|
+
/** Split text into chunks of maxChunk chars, breaking at line boundaries.
|
|
8
|
+
* When hrSplitEvery > 0, also force a new chunk before the Nth horizontal
|
|
9
|
+
* rule (---) to avoid Slack's "Show full message" truncation. */
|
|
10
|
+
declare function chunkText(text: any, maxChunk?: number, hrSplitEvery?: number): any[];
|
|
11
|
+
/** Format seconds as compact human-readable duration (e.g. "5s", "2m 30s", "1m") */
|
|
12
|
+
declare function formatDurationCompact(seconds: any): string;
|
|
13
|
+
/** Today's date as ISO string (YYYY-MM-DD) */
|
|
14
|
+
declare function todayISO(): string;
|
|
15
|
+
/**
|
|
16
|
+
* List subdirectories of PROJECTS_DIR that look like project folders.
|
|
17
|
+
*
|
|
18
|
+
* Filters out:
|
|
19
|
+
* - non-directories (e.g. top-level files like CORTEX.md, AGENTS.md that
|
|
20
|
+
* some users keep next to their projects/ tree)
|
|
21
|
+
* - dotfiles (.git, .obsidian, etc.)
|
|
22
|
+
*
|
|
23
|
+
* Returns [] if the directory does not exist or is unreadable.
|
|
24
|
+
* Use this everywhere instead of `fs.readdirSync(PROJECTS_DIR)` to avoid
|
|
25
|
+
* treating stray files as projects (would surface as ghost projects in
|
|
26
|
+
* `cortex-task lock-status`, `stats`, id-assignment, etc.).
|
|
27
|
+
*/
|
|
28
|
+
declare function listProjectDirs(projectsDir?: string): string[];
|
|
29
|
+
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// input: nothing (leaf module)
|
|
2
|
+
// output: INSTALL_ROOT / DEFAULTS_DIR / DATA_DIR / CONFIG_DIR / STORE_DIR / CONTEXT_DIR / PROJECTS_DIR / WORKSPACE_DIR / PLUGINS_DIR / PROMPTS_DIR / HOOKS_DIR
|
|
3
|
+
// (deprecated re-exports: PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT) + moduleDir + utility helpers
|
|
4
|
+
// pos: cross-module shared constants and ESM/time/path utilities
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
9
|
+
import { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, } from './paths.js';
|
|
10
|
+
/** Directories to skip during recursive filesystem scans */
|
|
11
|
+
const SKIP_DIRS = new Set(['.git', 'node_modules', 'tmp', 'logs', '__pycache__']);
|
|
12
|
+
function moduleDir(importMetaUrl) {
|
|
13
|
+
return path.dirname(fileURLToPath(importMetaUrl));
|
|
14
|
+
}
|
|
15
|
+
function isMainModule(importMetaUrl) {
|
|
16
|
+
if (!process.argv[1])
|
|
17
|
+
return false;
|
|
18
|
+
const thisFile = fileURLToPath(importMetaUrl);
|
|
19
|
+
const invoked = path.resolve(process.argv[1]);
|
|
20
|
+
if (invoked === thisFile)
|
|
21
|
+
return true;
|
|
22
|
+
try {
|
|
23
|
+
return fs.realpathSync(invoked) === thisFile;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function readableTimestamp() {
|
|
30
|
+
const now = new Date();
|
|
31
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
32
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}_${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}`;
|
|
33
|
+
}
|
|
34
|
+
/** Split text into chunks of maxChunk chars, breaking at line boundaries.
|
|
35
|
+
* When hrSplitEvery > 0, also force a new chunk before the Nth horizontal
|
|
36
|
+
* rule (---) to avoid Slack's "Show full message" truncation. */
|
|
37
|
+
function chunkText(text, maxChunk = 3000, hrSplitEvery = 3) {
|
|
38
|
+
const lines = text.split('\n');
|
|
39
|
+
const chunks = [];
|
|
40
|
+
let current = '';
|
|
41
|
+
let hrCount = 0;
|
|
42
|
+
for (const line of lines) {
|
|
43
|
+
const isHr = hrSplitEvery > 0 && /^-{3,}\s*$/.test(line.trim());
|
|
44
|
+
const wouldExceedChars = current.length + line.length + 1 > maxChunk && current.length > 0;
|
|
45
|
+
const wouldExceedHrs = isHr && hrCount + 1 >= hrSplitEvery && current.length > 0;
|
|
46
|
+
if (wouldExceedChars || wouldExceedHrs) {
|
|
47
|
+
chunks.push(current);
|
|
48
|
+
current = line;
|
|
49
|
+
hrCount = isHr ? 1 : 0;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
current = current ? current + '\n' + line : line;
|
|
53
|
+
if (isHr)
|
|
54
|
+
hrCount++;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (current)
|
|
58
|
+
chunks.push(current);
|
|
59
|
+
return chunks;
|
|
60
|
+
}
|
|
61
|
+
/** Format seconds as compact human-readable duration (e.g. "5s", "2m 30s", "1m") */
|
|
62
|
+
function formatDurationCompact(seconds) {
|
|
63
|
+
if (seconds < 60)
|
|
64
|
+
return `${Math.round(seconds)}s`;
|
|
65
|
+
const m = Math.floor(seconds / 60);
|
|
66
|
+
const s = Math.round(seconds % 60);
|
|
67
|
+
return s > 0 ? `${m}m ${s}s` : `${m}m`;
|
|
68
|
+
}
|
|
69
|
+
/** Today's date as ISO string (YYYY-MM-DD) */
|
|
70
|
+
function todayISO() {
|
|
71
|
+
return new Date().toISOString().slice(0, 10);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* List subdirectories of PROJECTS_DIR that look like project folders.
|
|
75
|
+
*
|
|
76
|
+
* Filters out:
|
|
77
|
+
* - non-directories (e.g. top-level files like CORTEX.md, AGENTS.md that
|
|
78
|
+
* some users keep next to their projects/ tree)
|
|
79
|
+
* - dotfiles (.git, .obsidian, etc.)
|
|
80
|
+
*
|
|
81
|
+
* Returns [] if the directory does not exist or is unreadable.
|
|
82
|
+
* Use this everywhere instead of `fs.readdirSync(PROJECTS_DIR)` to avoid
|
|
83
|
+
* treating stray files as projects (would surface as ghost projects in
|
|
84
|
+
* `cortex-task lock-status`, `stats`, id-assignment, etc.).
|
|
85
|
+
*/
|
|
86
|
+
function listProjectDirs(projectsDir = PROJECTS_DIR) {
|
|
87
|
+
if (!fs.existsSync(projectsDir))
|
|
88
|
+
return [];
|
|
89
|
+
try {
|
|
90
|
+
return fs.readdirSync(projectsDir, { withFileTypes: true })
|
|
91
|
+
.filter((d) => d.isDirectory() && !d.name.startsWith('.'))
|
|
92
|
+
.map((d) => d.name);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
export { INSTALL_ROOT, DEFAULTS_DIR, PACKAGE_ROOT, SERVER_ROOT, REPO_ROOT, DATA_DIR, CONFIG_DIR, STORE_DIR, CONTEXT_DIR, PROJECTS_DIR, WORKSPACE_DIR, PLUGINS_DIR, PROMPTS_DIR, HOOKS_DIR, SKIP_DIRS, moduleDir, isMainModule, readableTimestamp, chunkText, formatDurationCompact, todayISO, listProjectDirs };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// input: package.json (read at module load)
|
|
2
|
+
// output: CORTEX_VERSION string (CalVer: YYYY.M.D, no zero-padding)
|
|
3
|
+
// pos: single source of truth for Cortex version — imported by MCP servers and anywhere else
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { INSTALL_ROOT } from './paths.js';
|
|
8
|
+
const pkgPath = join(INSTALL_ROOT, 'package.json');
|
|
9
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
|
|
10
|
+
/** Cortex version — reads from package.json at module load time.
|
|
11
|
+
* Format: CalVer `YYYY.M.D` (no zero-padding), e.g. `2026.5.19`. */
|
|
12
|
+
export const CORTEX_VERSION = pkg.version;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export interface ModeFileData {
|
|
2
|
+
mode?: string;
|
|
3
|
+
claudeMode?: string;
|
|
4
|
+
backend?: string;
|
|
5
|
+
claudeModel?: string;
|
|
6
|
+
activeProfile?: string | null;
|
|
7
|
+
defaultAgent?: string | null;
|
|
8
|
+
channelProfiles?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export interface ApiEnv {
|
|
11
|
+
ANTHROPIC_API_KEY: string | undefined;
|
|
12
|
+
ANTHROPIC_BASE_URL: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
declare const GATEWAY_ANTHROPIC_URL = "http://127.0.0.1:9880/anthropic";
|
|
15
|
+
export declare function gatewayModeUrl(mode: string, metadata?: Record<string, string>): string;
|
|
16
|
+
declare function loadModeFile(): ModeFileData;
|
|
17
|
+
export declare function loadMode(): string;
|
|
18
|
+
export declare function loadBackend(): string;
|
|
19
|
+
declare function saveModeFile(mode: string, backend: string, model?: string, profile?: string | null, agent?: string | null): void;
|
|
20
|
+
export declare function saveMode(mode: string): void;
|
|
21
|
+
export declare function getClaudeMode(): string;
|
|
22
|
+
export declare function getActiveBackend(): string;
|
|
23
|
+
export declare function getClaudeModel(): string;
|
|
24
|
+
export declare function setActiveBackend(backend: string): void;
|
|
25
|
+
export declare function setClaudeModel(model: string): void;
|
|
26
|
+
export declare function getActiveProfile(channel?: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the effective backend for a channel. Channel profile overrides global activeBackend
|
|
29
|
+
* — without this, conversations on channels using a non-default profile (e.g. profile `execute`
|
|
30
|
+
* with `backend: pi`) end up storing the wrong backend in the conversation ledger and routing
|
|
31
|
+
* rollback / session lookup to the wrong adapter.
|
|
32
|
+
*
|
|
33
|
+
* Falls back to global activeBackend when the channel has no profile or the profile lookup
|
|
34
|
+
* fails (e.g. profile was renamed/removed since channelProfiles was last persisted).
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveBackendForChannel(channel?: string): string;
|
|
37
|
+
export declare function setActiveProfile(profileName: string | null, channel?: string): void;
|
|
38
|
+
export declare function clearChannelProfile(channel: string): void;
|
|
39
|
+
export declare function getChannelProfiles(): Record<string, string>;
|
|
40
|
+
export declare function getDefaultAgent(): string | null;
|
|
41
|
+
export declare function setDefaultAgent(name: string | null): void;
|
|
42
|
+
export declare function switchMode(): {
|
|
43
|
+
oldMode: string;
|
|
44
|
+
newMode: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function isApiRateLimitError(errorMessage: string | null | undefined): boolean;
|
|
47
|
+
export declare function isRetryableResult(result: {
|
|
48
|
+
rateLimited?: boolean;
|
|
49
|
+
} | null): boolean;
|
|
50
|
+
export declare function isRetryableError(error: Error | null | undefined): boolean;
|
|
51
|
+
export declare function configureEnvForMode(mode: string, metadata?: Record<string, string>): string | undefined;
|
|
52
|
+
export declare function setGatewayMode(mode: string): Promise<string>;
|
|
53
|
+
export declare function resolveAgentModel({ profileName, modelOverride }?: {
|
|
54
|
+
profileName?: string | null;
|
|
55
|
+
modelOverride?: string | null;
|
|
56
|
+
}): string;
|
|
57
|
+
export declare function detectBillingMode(): string;
|
|
58
|
+
export { GATEWAY_ANTHROPIC_URL, saveModeFile, loadModeFile, };
|