@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,54 @@
|
|
|
1
|
+
export interface ProfileEntry {
|
|
2
|
+
model: string;
|
|
3
|
+
backend?: string;
|
|
4
|
+
mode?: string;
|
|
5
|
+
extraEnv?: Record<string, string>;
|
|
6
|
+
extraOption?: Record<string, string>;
|
|
7
|
+
/** DR-0012: opt into TUI-mode Claude (interactive tmux + jsonl tail). Default 'print' for backward
|
|
8
|
+
* compatibility. Only meaningful when backend='claude'. Other backends ignore the field. */
|
|
9
|
+
claudeBackend?: 'print' | 'tui';
|
|
10
|
+
fallback?: ProfileEntry[];
|
|
11
|
+
}
|
|
12
|
+
export interface ProfilesFile {
|
|
13
|
+
defaultProfile: string;
|
|
14
|
+
profiles: Record<string, ProfileEntry>;
|
|
15
|
+
}
|
|
16
|
+
export interface ResolvedProfile extends ProfileEntry {
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ResolvedProfileConfig {
|
|
20
|
+
name: string;
|
|
21
|
+
model: string;
|
|
22
|
+
backend: string;
|
|
23
|
+
mode: string | null;
|
|
24
|
+
extraEnv: Record<string, string>;
|
|
25
|
+
extraOption: Record<string, string>;
|
|
26
|
+
/** DR-0012: resolved claude adapter mode. 'print' (default, uses -p + stream-json) or 'tui'
|
|
27
|
+
* (interactive Claude under tmux + jsonl tail). Ignored for non-claude backends. */
|
|
28
|
+
claudeBackend: 'print' | 'tui';
|
|
29
|
+
fallback: Array<{
|
|
30
|
+
model: string;
|
|
31
|
+
backend: string;
|
|
32
|
+
mode: string | null;
|
|
33
|
+
extraEnv: Record<string, string>;
|
|
34
|
+
extraOption: Record<string, string>;
|
|
35
|
+
claudeBackend: 'print' | 'tui';
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
declare function loadProfilesFile(): ProfilesFile;
|
|
39
|
+
/**
|
|
40
|
+
* Pure resolver: maps a ProfileEntry's claudeBackend field to one of the two valid modes.
|
|
41
|
+
* Defaults to 'print' for any non-'tui' value (including missing field). Used at adapter dispatch
|
|
42
|
+
* time so unknown/legacy values silently fall back to the safe 'print' path.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resolveClaudeBackend(p: {
|
|
45
|
+
claudeBackend?: unknown;
|
|
46
|
+
}): 'print' | 'tui';
|
|
47
|
+
declare function validateProfilesFile(data: unknown): void;
|
|
48
|
+
declare function listProfiles(): ResolvedProfile[];
|
|
49
|
+
declare function getDefaultProfileName(): string;
|
|
50
|
+
declare function getProfile(name: string | null): ResolvedProfile | null;
|
|
51
|
+
declare function resolveProfile(name?: string | null): ResolvedProfile;
|
|
52
|
+
declare function getProfileModel(name?: string | null): string;
|
|
53
|
+
declare function resolveProfileConfig(name?: string | null): ResolvedProfileConfig;
|
|
54
|
+
export { loadProfilesFile, listProfiles, getDefaultProfileName, getProfile, resolveProfile, getProfileModel, resolveProfileConfig, validateProfilesFile, };
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// input: profiles.json config file (I/O delegated to store/profile-repo.ts)
|
|
2
|
+
// output: load/list/get/resolveProfile + validate helpers
|
|
3
|
+
// pos: named agent profile resolution and fallback config chain. Business validation (validateProfilesFile) stays in this file,
|
|
4
|
+
// JSON I/O goes through profileRepo (Pattern A, DR-s12-gate). Public API maintains sync semantics.
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import { profileRepo } from '../../store/profile-repo.js';
|
|
7
|
+
const PROFILE_NAME_RE = /^[a-zA-Z0-9_-]+$/;
|
|
8
|
+
const MODE_NAME_RE = /^[a-zA-Z0-9_-]+$/;
|
|
9
|
+
const ENV_KEY_RE = /^[A-Z_][A-Z0-9_]*$/;
|
|
10
|
+
const VALID_BACKENDS = new Set(['claude', 'codex', 'pi']);
|
|
11
|
+
function loadProfilesFile() {
|
|
12
|
+
try {
|
|
13
|
+
const data = profileRepo.readSync();
|
|
14
|
+
validateProfilesFile(data);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
throw new Error(`Failed to load profiles.json: ${error.message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function validateProfileEntry(profile, label) {
|
|
22
|
+
const p = profile;
|
|
23
|
+
if (!p || typeof p !== 'object' || Array.isArray(p)) {
|
|
24
|
+
throw new Error(`${label} must be an object`);
|
|
25
|
+
}
|
|
26
|
+
if (!p.model || typeof p.model !== 'string') {
|
|
27
|
+
throw new Error(`${label} must define a non-empty string model`);
|
|
28
|
+
}
|
|
29
|
+
if (p.backend !== undefined && !VALID_BACKENDS.has(p.backend)) {
|
|
30
|
+
throw new Error(`${label} has invalid backend: ${p.backend}`);
|
|
31
|
+
}
|
|
32
|
+
if (p.mode !== undefined) {
|
|
33
|
+
if (typeof p.mode !== 'string' || !MODE_NAME_RE.test(p.mode)) {
|
|
34
|
+
throw new Error(`${label} has invalid mode: ${p.mode}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (p.extraEnv !== undefined) {
|
|
38
|
+
if (!p.extraEnv || typeof p.extraEnv !== 'object' || Array.isArray(p.extraEnv)) {
|
|
39
|
+
throw new Error(`${label} extraEnv must be a plain object`);
|
|
40
|
+
}
|
|
41
|
+
for (const [k, v] of Object.entries(p.extraEnv)) {
|
|
42
|
+
if (!ENV_KEY_RE.test(k)) {
|
|
43
|
+
throw new Error(`${label} extraEnv has invalid key: ${k}`);
|
|
44
|
+
}
|
|
45
|
+
if (typeof v !== 'string') {
|
|
46
|
+
throw new Error(`${label} extraEnv["${k}"] must be a string`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (p.extraOption !== undefined) {
|
|
51
|
+
if (!p.extraOption || typeof p.extraOption !== 'object' || Array.isArray(p.extraOption)) {
|
|
52
|
+
throw new Error(`${label} extraOption must be a plain object`);
|
|
53
|
+
}
|
|
54
|
+
for (const [k, v] of Object.entries(p.extraOption)) {
|
|
55
|
+
if (typeof k !== 'string' || !k.startsWith('--')) {
|
|
56
|
+
throw new Error(`${label} extraOption key must start with --: ${k}`);
|
|
57
|
+
}
|
|
58
|
+
if (typeof v !== 'string') {
|
|
59
|
+
throw new Error(`${label} extraOption["${k}"] must be a string`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (p.claudeBackend !== undefined) {
|
|
64
|
+
if (p.claudeBackend !== 'print' && p.claudeBackend !== 'tui') {
|
|
65
|
+
throw new Error(`${label} has invalid claudeBackend: ${String(p.claudeBackend)} (expected 'print' or 'tui')`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Pure resolver: maps a ProfileEntry's claudeBackend field to one of the two valid modes.
|
|
71
|
+
* Defaults to 'print' for any non-'tui' value (including missing field). Used at adapter dispatch
|
|
72
|
+
* time so unknown/legacy values silently fall back to the safe 'print' path.
|
|
73
|
+
*/
|
|
74
|
+
export function resolveClaudeBackend(p) {
|
|
75
|
+
return p.claudeBackend === 'tui' ? 'tui' : 'print';
|
|
76
|
+
}
|
|
77
|
+
function validateProfilesFile(data) {
|
|
78
|
+
const d = data;
|
|
79
|
+
if (!d || typeof d !== 'object' || Array.isArray(d)) {
|
|
80
|
+
throw new Error('top-level value must be an object');
|
|
81
|
+
}
|
|
82
|
+
const { defaultProfile, profiles } = d;
|
|
83
|
+
if (!defaultProfile || typeof defaultProfile !== 'string') {
|
|
84
|
+
throw new Error('defaultProfile must be a non-empty string');
|
|
85
|
+
}
|
|
86
|
+
if (!profiles || typeof profiles !== 'object' || Array.isArray(profiles)) {
|
|
87
|
+
throw new Error('profiles must be an object');
|
|
88
|
+
}
|
|
89
|
+
const profs = profiles;
|
|
90
|
+
if (!profs[defaultProfile]) {
|
|
91
|
+
throw new Error(`defaultProfile "${defaultProfile}" is missing from profiles`);
|
|
92
|
+
}
|
|
93
|
+
for (const [name, profile] of Object.entries(profs)) {
|
|
94
|
+
if (!PROFILE_NAME_RE.test(name)) {
|
|
95
|
+
throw new Error(`invalid profile name: ${name}`);
|
|
96
|
+
}
|
|
97
|
+
validateProfileEntry(profile, `profile "${name}"`);
|
|
98
|
+
const pe = profile;
|
|
99
|
+
if (pe.fallback !== undefined) {
|
|
100
|
+
if (!Array.isArray(pe.fallback)) {
|
|
101
|
+
throw new Error(`profile "${name}" fallback must be an array`);
|
|
102
|
+
}
|
|
103
|
+
pe.fallback.forEach((fb, i) => {
|
|
104
|
+
validateProfileEntry(fb, `profile "${name}" fallback[${i}]`);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function listProfiles() {
|
|
110
|
+
const data = loadProfilesFile();
|
|
111
|
+
return Object.entries(data.profiles).map(([name, profile]) => ({ name, ...profile }));
|
|
112
|
+
}
|
|
113
|
+
function getDefaultProfileName() {
|
|
114
|
+
return loadProfilesFile().defaultProfile;
|
|
115
|
+
}
|
|
116
|
+
function getProfile(name) {
|
|
117
|
+
if (!name)
|
|
118
|
+
return null;
|
|
119
|
+
const data = loadProfilesFile();
|
|
120
|
+
const profile = data.profiles[name];
|
|
121
|
+
return profile ? { name, ...profile } : null;
|
|
122
|
+
}
|
|
123
|
+
function resolveProfile(name = null) {
|
|
124
|
+
const data = loadProfilesFile();
|
|
125
|
+
const resolvedName = name || data.defaultProfile;
|
|
126
|
+
const profile = data.profiles[resolvedName];
|
|
127
|
+
if (!profile) {
|
|
128
|
+
throw new Error(`Unknown profile: ${resolvedName}`);
|
|
129
|
+
}
|
|
130
|
+
return { name: resolvedName, ...profile };
|
|
131
|
+
}
|
|
132
|
+
function getProfileModel(name = null) {
|
|
133
|
+
return resolveProfile(name).model;
|
|
134
|
+
}
|
|
135
|
+
function resolveProfileConfig(name = null) {
|
|
136
|
+
const data = loadProfilesFile();
|
|
137
|
+
const resolvedName = name || data.defaultProfile;
|
|
138
|
+
const profile = data.profiles[resolvedName];
|
|
139
|
+
if (!profile) {
|
|
140
|
+
throw new Error(`Unknown profile: ${resolvedName}`);
|
|
141
|
+
}
|
|
142
|
+
const primary = {
|
|
143
|
+
model: profile.model,
|
|
144
|
+
backend: profile.backend || 'claude',
|
|
145
|
+
mode: profile.mode || null,
|
|
146
|
+
extraEnv: { ...(profile.extraEnv || {}) },
|
|
147
|
+
extraOption: { ...(profile.extraOption || {}) },
|
|
148
|
+
claudeBackend: resolveClaudeBackend(profile),
|
|
149
|
+
};
|
|
150
|
+
const fallback = (profile.fallback || []).map(fb => ({
|
|
151
|
+
model: fb.model,
|
|
152
|
+
backend: fb.backend || primary.backend,
|
|
153
|
+
mode: fb.mode || primary.mode,
|
|
154
|
+
extraEnv: { ...(fb.extraEnv || {}) },
|
|
155
|
+
extraOption: { ...(fb.extraOption || {}) },
|
|
156
|
+
claudeBackend: fb.claudeBackend !== undefined ? resolveClaudeBackend(fb) : primary.claudeBackend,
|
|
157
|
+
}));
|
|
158
|
+
return { name: resolvedName, ...primary, fallback };
|
|
159
|
+
}
|
|
160
|
+
export { loadProfilesFile, listProfiles, getDefaultProfileName, getProfile, resolveProfile, getProfileModel, resolveProfileConfig, validateProfilesFile, };
|
|
161
|
+
// resolveClaudeBackend is already an `export function` above; named here for discoverability of the public surface.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// input: codex JSON-RPC event method/params
|
|
2
|
+
// output: CODEX_LOG_MODE / shouldLogCodexEvent / formatCodexEvent
|
|
3
|
+
// pos: Codex event log filtering and human-readable rendering
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
const RAW_CODEX_LOG_MODE = String(process.env.CODEX_LOG_MODE || 'summary').toLowerCase();
|
|
6
|
+
export const CODEX_LOG_MODE = new Set(['full', 'summary', 'off']).has(RAW_CODEX_LOG_MODE)
|
|
7
|
+
? RAW_CODEX_LOG_MODE
|
|
8
|
+
: 'summary';
|
|
9
|
+
function isNoisyCodexLogEvent(method) {
|
|
10
|
+
const normalized = String(method || '');
|
|
11
|
+
const lower = normalized.toLowerCase();
|
|
12
|
+
if (normalized.startsWith('codex/event/'))
|
|
13
|
+
return true;
|
|
14
|
+
if (lower.includes('delta'))
|
|
15
|
+
return true;
|
|
16
|
+
if (normalized === 'thread/tokenUsage/updated')
|
|
17
|
+
return true;
|
|
18
|
+
if (normalized === 'account/rateLimits/updated')
|
|
19
|
+
return true;
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
export function shouldLogCodexEvent(method) {
|
|
23
|
+
if (CODEX_LOG_MODE === 'off')
|
|
24
|
+
return false;
|
|
25
|
+
if (CODEX_LOG_MODE === 'full')
|
|
26
|
+
return true;
|
|
27
|
+
return !isNoisyCodexLogEvent(method);
|
|
28
|
+
}
|
|
29
|
+
function formatExecCompleted(item) {
|
|
30
|
+
const cmd = (item?.command || '').replace(/\s+/g, ' ').trim();
|
|
31
|
+
const out = (item?.aggregatedOutput || '').replace(/\s+/g, ' ').trim();
|
|
32
|
+
const cmdPreview = cmd.length > 120 ? `${cmd.substring(0, 120)}...` : cmd;
|
|
33
|
+
const outPreview = out ? (out.length > 180 ? `${out.substring(0, 180)}...` : out) : '';
|
|
34
|
+
const meta = `exit=${item?.exitCode ?? 'n/a'}, durMs=${item?.durationMs ?? 'n/a'}`;
|
|
35
|
+
return outPreview
|
|
36
|
+
? `[exec/completed] ${meta}, cmd=${cmdPreview}, out=${outPreview}`
|
|
37
|
+
: `[exec/completed] ${meta}, cmd=${cmdPreview}`;
|
|
38
|
+
}
|
|
39
|
+
function formatItemCompleted(params) {
|
|
40
|
+
const item = params?.item;
|
|
41
|
+
if (item?.type === 'agentMessage') {
|
|
42
|
+
const text = (item?.text || '').replace(/\s+/g, ' ').trim();
|
|
43
|
+
if (text)
|
|
44
|
+
return text.length > 240 ? `[agent/final] ${text.substring(0, 240)}...` : `[agent/final] ${text}`;
|
|
45
|
+
}
|
|
46
|
+
if (item?.type === 'commandExecution')
|
|
47
|
+
return formatExecCompleted(item);
|
|
48
|
+
return `[item/completed] type=${item?.type}, status=${item?.status}`;
|
|
49
|
+
}
|
|
50
|
+
const CODEX_EVENT_FORMATTERS = {
|
|
51
|
+
'turn/started': (p) => `[turn/started] id=${p?.turn?.id}`,
|
|
52
|
+
'turn/completed': (p) => { const s = p?.turn?.status; const e = p?.turn?.error?.message; return `[turn/completed] status=${s}${e ? ' error=' + e : ''}`; },
|
|
53
|
+
'turn/plan/updated': (p) => { const steps = (p?.plan || []).map((s) => ` ${s.status === 'completed' ? 'v' : s.status === 'inProgress' ? '>' : 'o'} ${s.step}`).join('\n'); return `[plan]\n${steps}`; },
|
|
54
|
+
'item/started': (p) => `[item/started] type=${p?.item?.type}, id=${p?.item?.id}`,
|
|
55
|
+
'item/completed': formatItemCompleted,
|
|
56
|
+
'thread/tokenUsage/updated': (p) => { const u = p?.tokenUsage?.total; return `[tokens] input=${u?.inputTokens}, output=${u?.outputTokens}, total=${u?.totalTokens}`; },
|
|
57
|
+
'thread/status/changed': (p) => `[thread/status] ${p?.status?.type}`,
|
|
58
|
+
};
|
|
59
|
+
export function formatCodexEvent(method, params) {
|
|
60
|
+
if (!shouldLogCodexEvent(method))
|
|
61
|
+
return null;
|
|
62
|
+
const formatter = CODEX_EVENT_FORMATTERS[method];
|
|
63
|
+
if (formatter)
|
|
64
|
+
return formatter(params);
|
|
65
|
+
return `[${method}] ${JSON.stringify(params).substring(0, 150)}`;
|
|
66
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// input: Codex rate limit data from runCodex result
|
|
2
|
+
// output: { maybeNotifyCodexLowUsage } — Codex low usage alert
|
|
3
|
+
// pos: Codex usage monitoring module, alerts via PlatformAdapter when usage is below threshold
|
|
4
|
+
// >>> If I am updated, update my header comment and CORTEX.md <<<
|
|
5
|
+
import { createLogger } from '../../core/log.js';
|
|
6
|
+
const log = createLogger('codex-usage');
|
|
7
|
+
const rawThreshold = Number(process.env.CODEX_LOW_USAGE_THRESHOLD_PERCENT || 10);
|
|
8
|
+
const THRESHOLD_PERCENT = Number.isFinite(rawThreshold)
|
|
9
|
+
? Math.min(100, Math.max(0, rawThreshold))
|
|
10
|
+
: 10;
|
|
11
|
+
const alertedWindows = new Set();
|
|
12
|
+
function formatResetAt(unixSeconds) {
|
|
13
|
+
if (!Number.isFinite(unixSeconds))
|
|
14
|
+
return 'unknown';
|
|
15
|
+
return new Date(unixSeconds * 1000).toLocaleString('en-US', {
|
|
16
|
+
month: 'short', day: 'numeric',
|
|
17
|
+
hour: '2-digit', minute: '2-digit', hour12: false,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function collectLowEntries(result) {
|
|
21
|
+
const limits = result?.codexRateLimits?.limits;
|
|
22
|
+
if (!Array.isArray(limits))
|
|
23
|
+
return [];
|
|
24
|
+
const entries = [];
|
|
25
|
+
for (const limit of limits) {
|
|
26
|
+
for (const scopeName of ['primary', 'secondary']) {
|
|
27
|
+
const scope = limit?.[scopeName];
|
|
28
|
+
if (!scope || !Number.isFinite(scope.remainingPercent))
|
|
29
|
+
continue;
|
|
30
|
+
if (scope.remainingPercent >= THRESHOLD_PERCENT)
|
|
31
|
+
continue;
|
|
32
|
+
entries.push({
|
|
33
|
+
limitId: limit.limitId || 'unknown',
|
|
34
|
+
limitName: limit.limitName || null,
|
|
35
|
+
scopeName,
|
|
36
|
+
usedPercent: scope.usedPercent,
|
|
37
|
+
remainingPercent: scope.remainingPercent,
|
|
38
|
+
resetsAt: scope.resetsAt,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return entries.sort((a, b) => a.remainingPercent - b.remainingPercent);
|
|
43
|
+
}
|
|
44
|
+
async function maybeNotifyCodexLowUsage({ adapter, channel, result }) {
|
|
45
|
+
const lowEntries = collectLowEntries(result);
|
|
46
|
+
if (!lowEntries.length)
|
|
47
|
+
return;
|
|
48
|
+
const newEntries = lowEntries.filter((entry) => {
|
|
49
|
+
const key = `${entry.limitId}:${entry.scopeName}:${entry.resetsAt || 'na'}`;
|
|
50
|
+
if (alertedWindows.has(key))
|
|
51
|
+
return false;
|
|
52
|
+
alertedWindows.add(key);
|
|
53
|
+
return true;
|
|
54
|
+
});
|
|
55
|
+
if (!newEntries.length)
|
|
56
|
+
return;
|
|
57
|
+
const lines = newEntries.map((e) => {
|
|
58
|
+
const label = e.limitName ? `${e.limitName} (${e.limitId})` : e.limitId;
|
|
59
|
+
const used = Number.isFinite(e.usedPercent) ? `${e.usedPercent.toFixed(1)}%` : 'unknown';
|
|
60
|
+
const remaining = Number.isFinite(e.remainingPercent) ? `${e.remainingPercent.toFixed(1)}%` : 'unknown';
|
|
61
|
+
return `• ${label} ${e.scopeName}: remaining ${remaining} (used ${used}), reset ${formatResetAt(e.resetsAt)}`;
|
|
62
|
+
});
|
|
63
|
+
const logHint = result?.codexRawLogPath ? `\nlog: \`${result.codexRawLogPath}\`` : '';
|
|
64
|
+
const text = [`:warning: Codex usage low (threshold: ${THRESHOLD_PERCENT}%)`, ...lines].join('\n') + logHint;
|
|
65
|
+
try {
|
|
66
|
+
await adapter.postMessage(channel, { text });
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
log.error('Failed to send low-usage alert:', error.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export { maybeNotifyCodexLowUsage };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { costRepo } from '../../store/cost-repo.js';
|
|
2
|
+
export type { CostsData, BudgetConfig } from '../../store/cost-repo.js';
|
|
3
|
+
export interface CostEntry {
|
|
4
|
+
timestamp: string;
|
|
5
|
+
project: string;
|
|
6
|
+
trigger: string;
|
|
7
|
+
cost_usd: number;
|
|
8
|
+
num_turns: number | null;
|
|
9
|
+
duration_s: number | null;
|
|
10
|
+
backend: string;
|
|
11
|
+
mode: string;
|
|
12
|
+
source: string;
|
|
13
|
+
input_tokens?: number;
|
|
14
|
+
output_tokens?: number;
|
|
15
|
+
provider?: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
}
|
|
18
|
+
interface PeriodBucket {
|
|
19
|
+
today: number;
|
|
20
|
+
week: number;
|
|
21
|
+
month: number;
|
|
22
|
+
total: number;
|
|
23
|
+
}
|
|
24
|
+
interface ModeBuckets {
|
|
25
|
+
total: number;
|
|
26
|
+
api: number;
|
|
27
|
+
plan: number;
|
|
28
|
+
[key: string]: number;
|
|
29
|
+
}
|
|
30
|
+
interface TokenBucket {
|
|
31
|
+
input: number;
|
|
32
|
+
output: number;
|
|
33
|
+
}
|
|
34
|
+
export interface CostSummary {
|
|
35
|
+
today: number;
|
|
36
|
+
week: number;
|
|
37
|
+
month: number;
|
|
38
|
+
total: number;
|
|
39
|
+
byMode: Record<string, ModeBuckets>;
|
|
40
|
+
byProject: Record<string, PeriodBucket>;
|
|
41
|
+
byTrigger: Record<string, PeriodBucket>;
|
|
42
|
+
bySource: Record<string, PeriodBucket>;
|
|
43
|
+
byBackend: Record<string, PeriodBucket>;
|
|
44
|
+
tokens: {
|
|
45
|
+
today: TokenBucket;
|
|
46
|
+
month: TokenBucket;
|
|
47
|
+
total: TokenBucket;
|
|
48
|
+
};
|
|
49
|
+
entryCount: number;
|
|
50
|
+
}
|
|
51
|
+
export interface BudgetStatus {
|
|
52
|
+
withinBudget: boolean;
|
|
53
|
+
dailyBudget: number;
|
|
54
|
+
dailySpent: number;
|
|
55
|
+
dailyRemaining: number;
|
|
56
|
+
monthlyBudget: number;
|
|
57
|
+
monthlySpent: number;
|
|
58
|
+
monthlyRemaining: number;
|
|
59
|
+
byMode: Record<string, ModeBuckets>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Record a cost entry after a Claude invocation.
|
|
63
|
+
* source: 'estimate' (default, from Claude CLI) or 'gateway' (from aistatus gateway usage data)
|
|
64
|
+
* Gateway entries may have cost_usd=0 (e.g. plan mode) but still track tokens.
|
|
65
|
+
*/
|
|
66
|
+
declare function recordCost({ project, trigger, cost_usd, num_turns, duration_s, backend, mode, source, input_tokens, output_tokens, provider, model }: {
|
|
67
|
+
project?: string;
|
|
68
|
+
trigger?: string;
|
|
69
|
+
cost_usd?: number | null;
|
|
70
|
+
num_turns?: number | null;
|
|
71
|
+
duration_s?: number | null;
|
|
72
|
+
backend?: string;
|
|
73
|
+
mode?: string;
|
|
74
|
+
source?: string;
|
|
75
|
+
input_tokens?: number;
|
|
76
|
+
output_tokens?: number;
|
|
77
|
+
provider?: string;
|
|
78
|
+
model?: string;
|
|
79
|
+
}): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Detect project from a message string.
|
|
82
|
+
*
|
|
83
|
+
* Priority:
|
|
84
|
+
* 1. [project:xxx] explicit tag — always wins
|
|
85
|
+
* 2. Case-insensitive substring match against context/projects/ directory names
|
|
86
|
+
* (longest match wins when multiple project names appear in the message)
|
|
87
|
+
* 3. 'general' fallback
|
|
88
|
+
*/
|
|
89
|
+
declare function detectProject(message: string | null | undefined): string;
|
|
90
|
+
/**
|
|
91
|
+
* Get cost summary (global, optionally filtered by project).
|
|
92
|
+
*/
|
|
93
|
+
declare function getCostSummary(project?: string | null): Promise<CostSummary>;
|
|
94
|
+
/**
|
|
95
|
+
* Check global budget (not per-project).
|
|
96
|
+
* Returns budget status and whether we're within limits.
|
|
97
|
+
*/
|
|
98
|
+
declare function checkBudget(): Promise<BudgetStatus>;
|
|
99
|
+
/**
|
|
100
|
+
* Update global budget limits.
|
|
101
|
+
*/
|
|
102
|
+
declare function setBudget({ daily_usd, monthly_usd }: {
|
|
103
|
+
daily_usd?: number;
|
|
104
|
+
monthly_usd?: number;
|
|
105
|
+
}): Promise<{
|
|
106
|
+
daily_usd: number;
|
|
107
|
+
monthly_usd: number;
|
|
108
|
+
}>;
|
|
109
|
+
/**
|
|
110
|
+
* Format cost summary as a readable string for Slack.
|
|
111
|
+
*/
|
|
112
|
+
declare function formatCostReport(project?: string | null): Promise<string>;
|
|
113
|
+
/** Reset the project name cache. Pass an array to pre-seed the cache (for tests). */
|
|
114
|
+
declare function _resetProjectCache(names?: string[] | null): void;
|
|
115
|
+
export { costRepo, recordCost, detectProject, getCostSummary, checkBudget, setBudget, formatCostReport, _resetProjectCache };
|