@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,274 @@
|
|
|
1
|
+
// input: !schedule text, PlatformAdapter, Scheduler, profile
|
|
2
|
+
// output: handleScheduleCommand dispatcher
|
|
3
|
+
// pos: !schedule subcommand routing and profile pinning
|
|
4
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
+
import { formatDuration, formatTimeUntil, parseDuration } from './scheduler.js';
|
|
6
|
+
import { listProfiles, resolveProfile, getDefaultProfileName } from '../agents/profile-manager.js';
|
|
7
|
+
function scheduleHelp() {
|
|
8
|
+
const profileNames = listProfiles().map(p => `\`${p.name}\``).join(', ');
|
|
9
|
+
return [
|
|
10
|
+
'*Schedule commands:*',
|
|
11
|
+
'`!schedule add interval <duration> [--profile <name>] <message>` — repeat every duration (e.g. `30m`, `2h`, `1d`)',
|
|
12
|
+
'`!schedule add daily <HH:MM> [--profile <name>] <message>` — run every day at a fixed time (24-hour)',
|
|
13
|
+
'`!schedule add weekly <day> <HH:MM> [--profile <name>] <message>` — run every week (day: mon,tue,wed,thu,fri,sat,sun)',
|
|
14
|
+
'`!schedule add once <duration> [--profile <name>] <message>` — run once after a delay',
|
|
15
|
+
'`!schedule list` — show all scheduled tasks',
|
|
16
|
+
'`!schedule pause <id>` — pause a recurring task',
|
|
17
|
+
'`!schedule resume <id>` — resume a paused recurring task',
|
|
18
|
+
'`!schedule remove <id>` — remove a task by id',
|
|
19
|
+
`Available profiles: ${profileNames}`,
|
|
20
|
+
].join('\n');
|
|
21
|
+
}
|
|
22
|
+
const DAY_MAP = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 };
|
|
23
|
+
const FMT_OPTS = { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hour12: false };
|
|
24
|
+
const fmtTime = (ts) => new Date(ts).toLocaleString('en-US', FMT_OPTS);
|
|
25
|
+
async function handleList(parts, channel, adapter, scheduler) {
|
|
26
|
+
const tasks = await scheduler.list();
|
|
27
|
+
if (tasks.length === 0) {
|
|
28
|
+
await adapter.postMessage(channel, { text: 'No scheduled tasks.' });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const lines = tasks.map((t) => formatTaskLine(t, now));
|
|
33
|
+
await adapter.postMessage(channel, { text: `*Scheduled tasks (${tasks.length}):*\n${lines.join('\n')}` });
|
|
34
|
+
}
|
|
35
|
+
function formatTaskLine(t, now) {
|
|
36
|
+
const id = `\`${t.id}\``;
|
|
37
|
+
const profile = ` | profile: *${t.profile || 'plan'}*`;
|
|
38
|
+
const paused = t.isPaused ? ` | status: *paused*${t.pausedBy === 'rate-limit' ? ' (rate-limit)' : ''}` : '';
|
|
39
|
+
if (t.type === 'interval') {
|
|
40
|
+
const nextAt = t.nextRun ? ` (${fmtTime(t.nextRun)})` : '';
|
|
41
|
+
const nextText = t.isPaused ? 'paused' : `${formatTimeUntil((t.nextRun || 0) - now)}${nextAt}`;
|
|
42
|
+
return `• ${id} every *${formatDuration(t.intervalMs)}*${profile}${paused} | next: ${nextText} | "${t.message}"`;
|
|
43
|
+
}
|
|
44
|
+
if (t.type === 'daily') {
|
|
45
|
+
const nextAt = t.nextRun ? ` (${fmtTime(t.nextRun)})` : '';
|
|
46
|
+
const nextText = t.isPaused ? 'paused' : `${formatTimeUntil((t.nextRun || 0) - now)}${nextAt}`;
|
|
47
|
+
return `• ${id} daily *${t.time}*${profile}${paused} | next: ${nextText} | "${t.message}"`;
|
|
48
|
+
}
|
|
49
|
+
if (t.type === 'weekly') {
|
|
50
|
+
const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
51
|
+
const nextAt = t.nextRun ? ` (${fmtTime(t.nextRun)})` : '';
|
|
52
|
+
const nextText = t.isPaused ? 'paused' : `${formatTimeUntil((t.nextRun || 0) - now)}${nextAt}`;
|
|
53
|
+
return `• ${id} weekly *${dayNames[t.dayOfWeek]} ${t.time}*${profile}${paused} | next: ${nextText} | "${t.message}"`;
|
|
54
|
+
}
|
|
55
|
+
if (t.type === 'once') {
|
|
56
|
+
const nextAt = t.runAt ? ` (${fmtTime(t.runAt)})` : '';
|
|
57
|
+
return `• ${id} once${profile} | runs: ${formatTimeUntil(t.runAt - now)}${nextAt} | "${t.message}"`;
|
|
58
|
+
}
|
|
59
|
+
return `• ${id} ${t.type}${profile}${paused} | "${t.message}"`;
|
|
60
|
+
}
|
|
61
|
+
function normalizeTaskId(id) {
|
|
62
|
+
if (!id)
|
|
63
|
+
return id;
|
|
64
|
+
const trimmed = id.trim();
|
|
65
|
+
const wrapped = trimmed.match(/^`([^`]+)`$/);
|
|
66
|
+
return wrapped ? wrapped[1] : trimmed;
|
|
67
|
+
}
|
|
68
|
+
async function handleRemove(parts, channel, adapter, scheduler) {
|
|
69
|
+
const rawId = parts[2];
|
|
70
|
+
const id = normalizeTaskId(rawId);
|
|
71
|
+
if (!id) {
|
|
72
|
+
await adapter.postMessage(channel, { text: 'Usage: `!schedule remove <id>`' });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const removed = await scheduler.remove(id);
|
|
76
|
+
await adapter.postMessage(channel, {
|
|
77
|
+
text: removed ? `:white_check_mark: Removed task \`${id}\`.` : `:x: Task not found: \`${id}\``,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function handlePause(parts, channel, adapter, scheduler) {
|
|
81
|
+
const rawId = parts[2];
|
|
82
|
+
const id = normalizeTaskId(rawId);
|
|
83
|
+
if (!id) {
|
|
84
|
+
await adapter.postMessage(channel, { text: 'Usage: `!schedule pause <id>`' });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
const task = await scheduler.pause(id);
|
|
89
|
+
if (!task) {
|
|
90
|
+
await adapter.postMessage(channel, { text: `:x: Task not found: \`${id}\`` });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
await adapter.postMessage(channel, { text: `:double_vertical_bar: Paused task \`${id}\`.` });
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function handleResume(parts, channel, adapter, scheduler) {
|
|
100
|
+
const rawId = parts[2];
|
|
101
|
+
const id = normalizeTaskId(rawId);
|
|
102
|
+
if (!id) {
|
|
103
|
+
await adapter.postMessage(channel, { text: 'Usage: `!schedule resume <id>`' });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const task = await scheduler.resume(id);
|
|
108
|
+
if (!task) {
|
|
109
|
+
await adapter.postMessage(channel, { text: `:x: Task not found: \`${id}\`` });
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const nextAt = task.nextRun ? ` Next run: ${fmtTime(task.nextRun)}.` : '';
|
|
113
|
+
await adapter.postMessage(channel, { text: `:arrow_forward: Resumed task \`${id}\`.${nextAt}` });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function parseProfileArgs(args, usage) {
|
|
120
|
+
if (args.length >= 1 && args[0] !== '--profile') {
|
|
121
|
+
return { profileName: getDefaultProfileName(), rest: args };
|
|
122
|
+
}
|
|
123
|
+
if (args[0] !== '--profile') {
|
|
124
|
+
return { profileName: getDefaultProfileName(), rest: args };
|
|
125
|
+
}
|
|
126
|
+
const profileName = args[1];
|
|
127
|
+
if (!profileName)
|
|
128
|
+
throw new Error(`Usage: ${usage}`);
|
|
129
|
+
try {
|
|
130
|
+
resolveProfile(profileName);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw new Error(error.message);
|
|
134
|
+
}
|
|
135
|
+
return { profileName, rest: args.slice(2) };
|
|
136
|
+
}
|
|
137
|
+
function buildScheduledConfirmation(prefix, task, timestampLabel) {
|
|
138
|
+
const profileText = task.profile ? `\nprofile: *${task.profile}*` : '';
|
|
139
|
+
return `${prefix}\nid: \`${task.id}\`${profileText}${timestampLabel}`;
|
|
140
|
+
}
|
|
141
|
+
async function handleAddInterval(parts, channel, adapter, scheduler) {
|
|
142
|
+
const durationStr = parts[3];
|
|
143
|
+
let parsed;
|
|
144
|
+
try {
|
|
145
|
+
parsed = parseProfileArgs(parts.slice(4), '`!schedule add interval <duration> [--profile <name>] <message>`');
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const msg = parsed.rest.join(' ');
|
|
152
|
+
const ms = parseDuration(durationStr);
|
|
153
|
+
if (!ms) {
|
|
154
|
+
await adapter.postMessage(channel, { text: `Invalid duration: \`${durationStr}\`. Use e.g. \`30s\`, \`5m\`, \`2h\`, \`1d\`` });
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!msg) {
|
|
158
|
+
await adapter.postMessage(channel, { text: 'Usage: `!schedule add interval <duration> [--profile <name>] <message>`' });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
const task = await scheduler.add('interval', { intervalMs: ms, message: msg, channel, profile: parsed.profileName });
|
|
162
|
+
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
163
|
+
await adapter.postMessage(channel, { text: buildScheduledConfirmation(`:white_check_mark: Scheduled every *${formatDuration(ms)}*: "${msg}"`, task, nextAt) });
|
|
164
|
+
}
|
|
165
|
+
async function handleAddDaily(parts, channel, adapter, scheduler) {
|
|
166
|
+
const time = parts[3];
|
|
167
|
+
let parsed;
|
|
168
|
+
try {
|
|
169
|
+
parsed = parseProfileArgs(parts.slice(4), '`!schedule add daily <HH:MM> [--profile <name>] <message>`');
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const msg = parsed.rest.join(' ');
|
|
176
|
+
if (!/^\d{2}:\d{2}$/.test(time)) {
|
|
177
|
+
await adapter.postMessage(channel, { text: `Invalid time: \`${time}\`. Use 24-hour HH:MM, e.g. \`09:00\`` });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!msg) {
|
|
181
|
+
await adapter.postMessage(channel, { text: 'Usage: `!schedule add daily <HH:MM> [--profile <name>] <message>`' });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const task = await scheduler.add('daily', { time, message: msg, channel, profile: parsed.profileName });
|
|
185
|
+
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
186
|
+
await adapter.postMessage(channel, { text: buildScheduledConfirmation(`:white_check_mark: Scheduled daily at *${time}*: "${msg}"`, task, nextAt) });
|
|
187
|
+
}
|
|
188
|
+
async function handleAddWeekly(parts, channel, adapter, scheduler) {
|
|
189
|
+
const dayStr = (parts[3] || '').toLowerCase();
|
|
190
|
+
const time = parts[4];
|
|
191
|
+
let parsed;
|
|
192
|
+
try {
|
|
193
|
+
parsed = parseProfileArgs(parts.slice(5), '`!schedule add weekly <day> <HH:MM> [--profile <name>] <message>`');
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const msg = parsed.rest.join(' ');
|
|
200
|
+
const dayOfWeek = DAY_MAP[dayStr];
|
|
201
|
+
if (dayOfWeek == null) {
|
|
202
|
+
await adapter.postMessage(channel, { text: `Invalid day: \`${parts[3]}\`. Use: mon, tue, wed, thu, fri, sat, sun` });
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (!/^\d{2}:\d{2}$/.test(time)) {
|
|
206
|
+
await adapter.postMessage(channel, { text: `Invalid time: \`${time}\`. Use 24-hour HH:MM, e.g. \`21:00\`` });
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (!msg) {
|
|
210
|
+
await adapter.postMessage(channel, { text: 'Usage: `!schedule add weekly <day> <HH:MM> [--profile <name>] <message>`' });
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
214
|
+
const task = await scheduler.add('weekly', { dayOfWeek, time, message: msg, channel, profile: parsed.profileName });
|
|
215
|
+
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
216
|
+
await adapter.postMessage(channel, { text: buildScheduledConfirmation(`:white_check_mark: Scheduled weekly *${dayNames[dayOfWeek]} ${time}*: "${msg}"`, task, nextAt) });
|
|
217
|
+
}
|
|
218
|
+
async function handleAddOnce(parts, channel, adapter, scheduler) {
|
|
219
|
+
const durationStr = parts[3];
|
|
220
|
+
let parsed;
|
|
221
|
+
try {
|
|
222
|
+
parsed = parseProfileArgs(parts.slice(4), '`!schedule add once <duration> [--profile <name>] <message>`');
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
await adapter.postMessage(channel, { text: `:x: ${error.message}` });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const msg = parsed.rest.join(' ');
|
|
229
|
+
const ms = parseDuration(durationStr);
|
|
230
|
+
if (!ms) {
|
|
231
|
+
await adapter.postMessage(channel, { text: `Invalid duration: \`${durationStr}\`. Use e.g. \`30s\`, \`5m\`, \`2h\`, \`1d\`` });
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (!msg) {
|
|
235
|
+
await adapter.postMessage(channel, { text: 'Usage: `!schedule add once <duration> [--profile <name>] <message>`' });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const task = await scheduler.add('once', { delay: ms, message: msg, channel, profile: parsed.profileName });
|
|
239
|
+
const runAt = task.runAt ? ` | runs at: ${fmtTime(task.runAt)}` : '';
|
|
240
|
+
await adapter.postMessage(channel, { text: buildScheduledConfirmation(`:white_check_mark: Scheduled once in *${formatDuration(ms)}*: "${msg}"`, task, runAt) });
|
|
241
|
+
}
|
|
242
|
+
const ADD_TYPE_HANDLERS = {
|
|
243
|
+
interval: handleAddInterval,
|
|
244
|
+
daily: handleAddDaily,
|
|
245
|
+
weekly: handleAddWeekly,
|
|
246
|
+
once: handleAddOnce,
|
|
247
|
+
};
|
|
248
|
+
async function handleAdd(parts, channel, adapter, scheduler) {
|
|
249
|
+
const type = parts[2];
|
|
250
|
+
const handler = ADD_TYPE_HANDLERS[type];
|
|
251
|
+
if (handler)
|
|
252
|
+
return handler(parts, channel, adapter, scheduler);
|
|
253
|
+
if (type) {
|
|
254
|
+
await adapter.postMessage(channel, { text: `Unknown type: \`${type}\`. Use \`interval\`, \`daily\`, \`weekly\`, or \`once\`` });
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
await adapter.postMessage(channel, { text: scheduleHelp() });
|
|
258
|
+
}
|
|
259
|
+
const SUB_HANDLERS = {
|
|
260
|
+
list: handleList,
|
|
261
|
+
pause: handlePause,
|
|
262
|
+
resume: handleResume,
|
|
263
|
+
remove: handleRemove,
|
|
264
|
+
add: handleAdd,
|
|
265
|
+
};
|
|
266
|
+
async function handleScheduleCommand(text, channel, adapter, scheduler) {
|
|
267
|
+
const parts = text.split(/\s+/);
|
|
268
|
+
const sub = parts[1];
|
|
269
|
+
const handler = SUB_HANDLERS[sub];
|
|
270
|
+
if (handler)
|
|
271
|
+
return handler(parts, channel, adapter, scheduler);
|
|
272
|
+
await adapter.postMessage(channel, { text: scheduleHelp() });
|
|
273
|
+
}
|
|
274
|
+
export { handleScheduleCommand };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { FSWatcher } from 'fs';
|
|
2
|
+
import { ScheduleRepo, SCHEDULES_FILE, type ScheduleTask } from '../../store/schedule-repo.js';
|
|
3
|
+
export type { ScheduleTask } from '../../store/schedule-repo.js';
|
|
4
|
+
declare function parseDuration(str: string | null | undefined): number | null;
|
|
5
|
+
declare function formatDuration(ms: number): string;
|
|
6
|
+
declare function formatTimeUntil(ms: number): string;
|
|
7
|
+
interface RunnerParams {
|
|
8
|
+
message: string;
|
|
9
|
+
channel: string;
|
|
10
|
+
scheduleTaskId: string;
|
|
11
|
+
profileName: string;
|
|
12
|
+
/** Where the fired task should land — passed through so scheduled-task.ts can pick its dispatch branch. */
|
|
13
|
+
target?: ScheduleTask['target'];
|
|
14
|
+
/** What to do if the chosen target's session/thread no longer exists at fire time. */
|
|
15
|
+
fallback?: ScheduleTask['fallback'];
|
|
16
|
+
}
|
|
17
|
+
interface TaskDispatchParams {
|
|
18
|
+
channel: string;
|
|
19
|
+
scheduleTaskId: string;
|
|
20
|
+
profileName: string;
|
|
21
|
+
}
|
|
22
|
+
interface ProgrammaticHandlerParams {
|
|
23
|
+
channel: string;
|
|
24
|
+
scheduleTaskId: string;
|
|
25
|
+
}
|
|
26
|
+
type RunnerFn = (params: RunnerParams) => Promise<void>;
|
|
27
|
+
type TaskDispatchRunnerFn = (params: TaskDispatchParams) => Promise<void>;
|
|
28
|
+
type ProgrammaticHandler = (params: ProgrammaticHandlerParams) => Promise<void>;
|
|
29
|
+
interface SchedulerOptions {
|
|
30
|
+
schedulesFile?: string;
|
|
31
|
+
watchFile?: boolean;
|
|
32
|
+
/** Override the default scheduleRepo (for tests with custom schedulesFile). */
|
|
33
|
+
repo?: ScheduleRepo;
|
|
34
|
+
}
|
|
35
|
+
declare class Scheduler {
|
|
36
|
+
runner: RunnerFn;
|
|
37
|
+
taskDispatchRunner: TaskDispatchRunnerFn | null;
|
|
38
|
+
programmaticHandlers: Record<string, ProgrammaticHandler>;
|
|
39
|
+
schedulesFile: string;
|
|
40
|
+
watchFile: boolean;
|
|
41
|
+
timers: Map<string, ReturnType<typeof setTimeout>>;
|
|
42
|
+
_repo: ScheduleRepo;
|
|
43
|
+
_inFlight: Set<string>;
|
|
44
|
+
_taskConfigs: Map<string, string>;
|
|
45
|
+
_watcher: FSWatcher | null;
|
|
46
|
+
_reloadTimer: ReturnType<typeof setTimeout> | null;
|
|
47
|
+
_selfWriting: boolean;
|
|
48
|
+
_beforeRunGuard: ((task: ScheduleTask) => boolean) | null;
|
|
49
|
+
/** Async callback invoked after _beforeRunGuard blocks a task. Used for async bookkeeping (e.g. persisting pause). */
|
|
50
|
+
_onGuardBlocked: ((task: ScheduleTask) => Promise<void>) | null;
|
|
51
|
+
/** Admin notification callback for hot-reload → Slack messages. Set by app.ts after adapter creation. */
|
|
52
|
+
_adminNotifier: ((text: string) => void) | null;
|
|
53
|
+
/** Set _selfWriting=true before a disk write, clear after 100ms to avoid triggering fs.watch hot-reload. */
|
|
54
|
+
_withWriteGuard<T>(fn: () => Promise<T>): Promise<T>;
|
|
55
|
+
constructor(runner: RunnerFn, taskDispatchRunner: TaskDispatchRunnerFn | null, programmaticHandlers?: Record<string, ProgrammaticHandler>, options?: SchedulerOptions);
|
|
56
|
+
/** Set a callback for admin notifications (hot-reload → Slack). Called by app.ts after adapter creation. */
|
|
57
|
+
setAdminNotifier(fn: (text: string) => void): void;
|
|
58
|
+
start(): Promise<void>;
|
|
59
|
+
stop(): void;
|
|
60
|
+
_startWatching(): void;
|
|
61
|
+
_hotReload(): Promise<void>;
|
|
62
|
+
add(type: string, options: Record<string, any>): Promise<ScheduleTask>;
|
|
63
|
+
remove(id: string): Promise<boolean>;
|
|
64
|
+
list(): Promise<ScheduleTask[]>;
|
|
65
|
+
get(id: string): Promise<ScheduleTask | null>;
|
|
66
|
+
update(id: string, patch: Record<string, any>): Promise<ScheduleTask | null>;
|
|
67
|
+
pause(id: string, pausedBy?: 'user' | 'rate-limit'): Promise<ScheduleTask | null>;
|
|
68
|
+
resume(id: string): Promise<ScheduleTask | null>;
|
|
69
|
+
setBeforeRunGuard(fn: ((task: ScheduleTask) => boolean) | null): void;
|
|
70
|
+
setOnGuardBlocked(fn: ((task: ScheduleTask) => Promise<void>) | null): void;
|
|
71
|
+
getRateLimitThrottle(): Promise<{
|
|
72
|
+
resetsAt: number;
|
|
73
|
+
activatedAt: number;
|
|
74
|
+
modes?: string[];
|
|
75
|
+
} | null>;
|
|
76
|
+
setRateLimitThrottle(meta: {
|
|
77
|
+
resetsAt: number;
|
|
78
|
+
activatedAt: number;
|
|
79
|
+
modes?: string[];
|
|
80
|
+
} | null): Promise<void>;
|
|
81
|
+
setInterval(id: string, intervalMs: number): Promise<ScheduleTask | null>;
|
|
82
|
+
_rescheduleTask(task: ScheduleTask): void;
|
|
83
|
+
_scheduleTask(task: ScheduleTask): void;
|
|
84
|
+
_runTask(task: ScheduleTask): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
export { Scheduler, parseDuration, formatDuration, formatTimeUntil, SCHEDULES_FILE };
|