@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,237 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: stdin JSON — Claude Code hook event or PI hook-bridge payload
|
|
3
|
+
// output: { hookSpecificOutput: { hookEventName, additionalContext, matched } }
|
|
4
|
+
// pos: Inject CORTEX.md / CORTEX.local.md ancestor chain into agent context
|
|
5
|
+
// 2-event dispatch:
|
|
6
|
+
// PostToolUse (Read) — from tool_input.file_path/path
|
|
7
|
+
// SessionStart (startup|resume|clear|compact) — from payload.cwd
|
|
8
|
+
// Per-session disk-backed dedup cache (~/.cortex/tmp/cortexmd-cache/<sessionId>.json)
|
|
9
|
+
// markOnlyPaths: tool operating on a CORTEX.md itself → cache update only, no inject
|
|
10
|
+
// Total length guard at 9,500 chars with truncated annotation
|
|
11
|
+
// >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
|
|
12
|
+
|
|
13
|
+
import { readFileSync, statSync, existsSync, mkdirSync, renameSync, writeFileSync } from 'fs';
|
|
14
|
+
import { join, resolve, dirname, basename } from 'path';
|
|
15
|
+
import { homedir, hostname } from 'os';
|
|
16
|
+
|
|
17
|
+
const HOSTNAME = hostname();
|
|
18
|
+
const CORTEX_MD_NAMES = ['CORTEX.md', 'CORTEX.local.md'];
|
|
19
|
+
const CORTEX_HOME = process.env.CORTEX_HOME
|
|
20
|
+
? resolve(process.env.CORTEX_HOME)
|
|
21
|
+
: join(homedir(), '.cortex');
|
|
22
|
+
const HOME_FALLBACK = join(CORTEX_HOME, 'CORTEX.md');
|
|
23
|
+
const MAX_FILE_SIZE = 200 * 1024;
|
|
24
|
+
const MAX_DEPTH = 20;
|
|
25
|
+
const CACHE_DIR = join(CORTEX_HOME, 'tmp', 'cortexmd-cache');
|
|
26
|
+
const MAX_CONTEXT_CHARS = 9500;
|
|
27
|
+
const SESSION_ID_RE = /^[A-Za-z0-9._-]+$/;
|
|
28
|
+
|
|
29
|
+
// ── scan helpers ──
|
|
30
|
+
|
|
31
|
+
function tryReadEntry(filePath) {
|
|
32
|
+
try {
|
|
33
|
+
const st = statSync(filePath, { throwIfNoEntry: false });
|
|
34
|
+
if (!st || !st.isFile()) return null;
|
|
35
|
+
if (st.size > MAX_FILE_SIZE) return null;
|
|
36
|
+
const content = readFileSync(filePath, 'utf8');
|
|
37
|
+
return { path: filePath, content, mtimeMs: st.mtimeMs };
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Walk from the directory containing `targetFilePath` up to the filesystem root,
|
|
44
|
+
* collecting CORTEX.md and CORTEX.local.md at each level. Also appends the
|
|
45
|
+
* home fallback at ~/.cortex/CORTEX.md if present. Returns leaf→root order.
|
|
46
|
+
* If targetFilePath is a directory, scan that directory and its ancestors.
|
|
47
|
+
* If it is a file (or does not exist), scan its parent directory and ancestors. */
|
|
48
|
+
function scanChain(targetFilePath) {
|
|
49
|
+
const entries = [];
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
|
|
52
|
+
let resolved;
|
|
53
|
+
try {
|
|
54
|
+
resolved = resolve(targetFilePath);
|
|
55
|
+
} catch {
|
|
56
|
+
return entries;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let dir;
|
|
60
|
+
try {
|
|
61
|
+
const st = statSync(resolved, { throwIfNoEntry: false });
|
|
62
|
+
dir = (st && st.isDirectory()) ? resolved : dirname(resolved);
|
|
63
|
+
} catch {
|
|
64
|
+
dir = dirname(resolved);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (let depth = 0; depth < MAX_DEPTH; depth++) {
|
|
68
|
+
for (const name of CORTEX_MD_NAMES) {
|
|
69
|
+
const p = join(dir, name);
|
|
70
|
+
if (seen.has(p)) continue;
|
|
71
|
+
seen.add(p);
|
|
72
|
+
const entry = tryReadEntry(p);
|
|
73
|
+
if (entry) entries.push(entry);
|
|
74
|
+
}
|
|
75
|
+
const parent = dirname(dir);
|
|
76
|
+
if (parent === dir) break;
|
|
77
|
+
dir = parent;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Home fallback
|
|
81
|
+
if (!seen.has(HOME_FALLBACK)) {
|
|
82
|
+
seen.add(HOME_FALLBACK);
|
|
83
|
+
const entry = tryReadEntry(HOME_FALLBACK);
|
|
84
|
+
if (entry) entries.push(entry);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return entries;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ── cache helpers ──
|
|
91
|
+
|
|
92
|
+
function loadCache(sessionId) {
|
|
93
|
+
const cache = new Map();
|
|
94
|
+
if (!sessionId || !SESSION_ID_RE.test(sessionId)) return cache;
|
|
95
|
+
const cacheFile = join(CACHE_DIR, `${sessionId}.json`);
|
|
96
|
+
try {
|
|
97
|
+
if (!existsSync(cacheFile)) return cache;
|
|
98
|
+
const raw = readFileSync(cacheFile, 'utf8');
|
|
99
|
+
const data = JSON.parse(raw);
|
|
100
|
+
if (data && typeof data === 'object') {
|
|
101
|
+
for (const [k, v] of Object.entries(data)) {
|
|
102
|
+
if (typeof k === 'string' && typeof v === 'number') {
|
|
103
|
+
cache.set(k, v);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} catch { /* corrupt/unreadable — start fresh */ }
|
|
108
|
+
return cache;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function saveCache(sessionId, cache) {
|
|
112
|
+
if (!sessionId || !SESSION_ID_RE.test(sessionId)) return;
|
|
113
|
+
try {
|
|
114
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
115
|
+
const cacheFile = join(CACHE_DIR, `${sessionId}.json`);
|
|
116
|
+
const obj = Object.fromEntries(cache);
|
|
117
|
+
const tmp = `${cacheFile}.${process.pid}.tmp`;
|
|
118
|
+
writeFileSync(tmp, JSON.stringify(obj), 'utf8');
|
|
119
|
+
renameSync(tmp, cacheFile);
|
|
120
|
+
} catch { /* disk full etc. — degrade gracefully */ }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ── context builder ──
|
|
124
|
+
|
|
125
|
+
function buildContext(entries) {
|
|
126
|
+
if (entries.length === 0) return '';
|
|
127
|
+
|
|
128
|
+
// Build blocks in original order (leaf→root)
|
|
129
|
+
const blocks = entries.map(e =>
|
|
130
|
+
`<system-reminder>\nAuto-loaded CORTEX.md from ${HOSTNAME}:${e.path} (ancestor of accessed path). These instructions apply to files under this directory.\n\n${e.content}\n</system-reminder>`
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const included = [];
|
|
134
|
+
let totalLen = 0;
|
|
135
|
+
|
|
136
|
+
for (const block of blocks) {
|
|
137
|
+
if (totalLen + block.length > MAX_CONTEXT_CHARS) break;
|
|
138
|
+
included.push(block);
|
|
139
|
+
totalLen += block.length;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const remaining = entries.length - included.length;
|
|
143
|
+
|
|
144
|
+
// No block fit within the limit — return empty rather than
|
|
145
|
+
// emitting a bare "[truncated, N more files at root]" message.
|
|
146
|
+
if (included.length === 0) return '';
|
|
147
|
+
|
|
148
|
+
let context = included.join('\n\n');
|
|
149
|
+
|
|
150
|
+
if (remaining > 0) {
|
|
151
|
+
context += `\n\n[truncated, ${remaining} more files at root]`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return context;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── main ──
|
|
158
|
+
|
|
159
|
+
function main() {
|
|
160
|
+
let input = '';
|
|
161
|
+
try {
|
|
162
|
+
input = readFileSync(0, 'utf8');
|
|
163
|
+
} catch {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!input.trim()) return;
|
|
168
|
+
|
|
169
|
+
let payload;
|
|
170
|
+
try {
|
|
171
|
+
payload = JSON.parse(input);
|
|
172
|
+
} catch {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const hookEventName = payload.hook_event_name;
|
|
177
|
+
const sessionId = payload.session_id;
|
|
178
|
+
|
|
179
|
+
// Determine scan root path based on hook event type
|
|
180
|
+
let scanRoot = null;
|
|
181
|
+
|
|
182
|
+
if (hookEventName === 'PostToolUse') {
|
|
183
|
+
const toolName = payload.tool_name;
|
|
184
|
+
if (!toolName || toolName !== 'Read') return;
|
|
185
|
+
scanRoot = payload.tool_input?.file_path || payload.tool_input?.path;
|
|
186
|
+
} else if (hookEventName === 'SessionStart') {
|
|
187
|
+
scanRoot = payload.cwd;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (!scanRoot) return;
|
|
191
|
+
|
|
192
|
+
// Scan CORTEX.md chain
|
|
193
|
+
const entries = scanChain(scanRoot);
|
|
194
|
+
if (entries.length === 0) return;
|
|
195
|
+
|
|
196
|
+
// markOnlyPaths: if PostToolUse and tool target is itself a CORTEX.md,
|
|
197
|
+
// update cache only, don't inject
|
|
198
|
+
if (hookEventName === 'PostToolUse') {
|
|
199
|
+
const targetPath = resolve(payload.tool_input?.file_path || payload.tool_input?.path || '');
|
|
200
|
+
const targetName = basename(targetPath);
|
|
201
|
+
if (CORTEX_MD_NAMES.includes(targetName)) {
|
|
202
|
+
// Update cache with all entries (mark as seen) but don't inject
|
|
203
|
+
const cache = loadCache(sessionId);
|
|
204
|
+
for (const entry of entries) {
|
|
205
|
+
cache.set(entry.path, entry.mtimeMs);
|
|
206
|
+
}
|
|
207
|
+
saveCache(sessionId, cache);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Session dedup
|
|
213
|
+
const cache = loadCache(sessionId);
|
|
214
|
+
const newEntries = entries.filter(e => cache.get(e.path) !== e.mtimeMs);
|
|
215
|
+
|
|
216
|
+
// Update cache with all scanned entries
|
|
217
|
+
for (const entry of entries) {
|
|
218
|
+
cache.set(entry.path, entry.mtimeMs);
|
|
219
|
+
}
|
|
220
|
+
saveCache(sessionId, cache);
|
|
221
|
+
|
|
222
|
+
if (newEntries.length === 0) return;
|
|
223
|
+
|
|
224
|
+
// Build context with truncation guard
|
|
225
|
+
const additionalContext = buildContext(newEntries);
|
|
226
|
+
if (!additionalContext) return;
|
|
227
|
+
|
|
228
|
+
process.stdout.write(JSON.stringify({
|
|
229
|
+
hookSpecificOutput: {
|
|
230
|
+
hookEventName,
|
|
231
|
+
additionalContext,
|
|
232
|
+
matched: newEntries.map(e => e.path),
|
|
233
|
+
},
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
main();
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: stdin Claude Code PreToolUse event, node:http
|
|
3
|
+
// output: stdout permissionDecision (plan injected back after Slack approval)
|
|
4
|
+
// pos: PreToolUse hook: intercept ExitPlanMode and forward plan to Slack for approval
|
|
5
|
+
// >>> If I am updated, be sure to update my header comment and the CLAUDE.md in the same folder <<<
|
|
6
|
+
|
|
7
|
+
import http from 'node:http';
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
let input = '';
|
|
11
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
12
|
+
|
|
13
|
+
const hookInput = JSON.parse(input);
|
|
14
|
+
const channel = process.env.SLACK_CHANNEL;
|
|
15
|
+
const port = parseInt(process.env.WEBHOOK_PORT || '3001', 10);
|
|
16
|
+
const sessionId = hookInput.session_id;
|
|
17
|
+
|
|
18
|
+
if (!channel) {
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const toolInput = hookInput.tool_input || {};
|
|
23
|
+
const planContent = typeof toolInput.plan === 'string' ? toolInput.plan : '';
|
|
24
|
+
const threadId = process.env.CORTEX_THREAD_ID || null;
|
|
25
|
+
const body = JSON.stringify({
|
|
26
|
+
sessionId,
|
|
27
|
+
channel,
|
|
28
|
+
threadId,
|
|
29
|
+
planContent,
|
|
30
|
+
toolInput,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const response = await new Promise((resolve, reject) => {
|
|
34
|
+
const req = http.request({
|
|
35
|
+
hostname: '127.0.0.1',
|
|
36
|
+
port,
|
|
37
|
+
path: '/hook/exit-plan-mode',
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) },
|
|
40
|
+
timeout: 60 * 60 * 1000, // 60 minutes — user may take time to respond
|
|
41
|
+
}, (res) => {
|
|
42
|
+
let data = '';
|
|
43
|
+
res.on('data', (chunk) => { data += chunk; });
|
|
44
|
+
res.on('end', () => {
|
|
45
|
+
try { resolve(JSON.parse(data)); }
|
|
46
|
+
catch { reject(new Error(`Invalid response: ${data}`)); }
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
req.on('error', reject);
|
|
50
|
+
req.on('timeout', () => { req.destroy(); reject(new Error('timeout')); });
|
|
51
|
+
req.write(body);
|
|
52
|
+
req.end();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
if (response.error) {
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (response.approved) {
|
|
60
|
+
process.stdout.write(JSON.stringify({
|
|
61
|
+
hookSpecificOutput: {
|
|
62
|
+
hookEventName: 'PreToolUse',
|
|
63
|
+
permissionDecision: 'allow',
|
|
64
|
+
updatedInput: {
|
|
65
|
+
...hookInput.tool_input,
|
|
66
|
+
notice: 'User approved the plan via Slack. '
|
|
67
|
+
+ 'Note: Claude Code may still show "Exit plan mode?" and fail — '
|
|
68
|
+
+ 'this is a known limitation in non-interactive mode. '
|
|
69
|
+
+ 'If you see this message as a tool error, ignore it and proceed with implementation.',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
73
|
+
} else {
|
|
74
|
+
process.stdout.write(JSON.stringify({
|
|
75
|
+
hookSpecificOutput: {
|
|
76
|
+
hookEventName: 'PreToolUse',
|
|
77
|
+
permissionDecision: 'deny',
|
|
78
|
+
permissionDecisionReason: response.reason || 'User rejected the plan.',
|
|
79
|
+
},
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
main().catch(() => process.exit(1));
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: stdin JSON from Claude PostToolUse hook
|
|
3
|
+
// output: appends to _meta/access-log.jsonl per project
|
|
4
|
+
// pos: Read/Grep memory access tracking hook
|
|
5
|
+
|
|
6
|
+
import { readFileSync, existsSync, mkdirSync, appendFileSync } from 'fs';
|
|
7
|
+
import { execSync } from 'child_process';
|
|
8
|
+
import { join, resolve } from 'path';
|
|
9
|
+
import { homedir } from 'os';
|
|
10
|
+
|
|
11
|
+
const DATA_DIR = process.env.CORTEX_HOME
|
|
12
|
+
? resolve(process.env.CORTEX_HOME)
|
|
13
|
+
: join(homedir(), '.cortex');
|
|
14
|
+
const PROJECTS_DIR = process.env.CORTEX_PROJECTS_DIR
|
|
15
|
+
? resolve(process.env.CORTEX_PROJECTS_DIR)
|
|
16
|
+
: join(DATA_DIR, 'context', 'projects');
|
|
17
|
+
|
|
18
|
+
const MEMORY_FILE_RE = /\/(experiments|knowledge|patterns)\/(EXP-\d+[a-z]?|K-\d+|PAT-\d+)\.md$/;
|
|
19
|
+
const PROJECT_PATH_RE = /\/context\/projects\/([^/]+)\//;
|
|
20
|
+
|
|
21
|
+
function extractProjectName(filePath) {
|
|
22
|
+
const m = filePath.match(PROJECT_PATH_RE);
|
|
23
|
+
return m ? m[1] : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function extractMemoryFiles(filePath) {
|
|
27
|
+
const m = filePath.match(MEMORY_FILE_RE);
|
|
28
|
+
if (!m) return null;
|
|
29
|
+
return `${m[2]}.md`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function appendAccessLog(project, filename, toolName) {
|
|
33
|
+
const metaDir = join(PROJECTS_DIR, project, '_meta');
|
|
34
|
+
if (!existsSync(metaDir)) {
|
|
35
|
+
mkdirSync(metaDir, { recursive: true });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const logPath = join(metaDir, 'access-log.jsonl');
|
|
39
|
+
const record = {
|
|
40
|
+
file: filename,
|
|
41
|
+
tool: toolName,
|
|
42
|
+
ts: new Date().toISOString(),
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
appendFileSync(logPath, JSON.stringify(record) + '\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function processReadTool(payload) {
|
|
49
|
+
const filePath = payload.tool_input?.file_path;
|
|
50
|
+
if (!filePath) return;
|
|
51
|
+
|
|
52
|
+
const filename = extractMemoryFiles(filePath);
|
|
53
|
+
if (!filename) return;
|
|
54
|
+
|
|
55
|
+
const project = extractProjectName(filePath);
|
|
56
|
+
if (!project) return;
|
|
57
|
+
|
|
58
|
+
appendAccessLog(project, filename, 'Read');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function processGrepTool(payload) {
|
|
62
|
+
const searchPath = payload.tool_input?.path;
|
|
63
|
+
if (!searchPath) return;
|
|
64
|
+
|
|
65
|
+
const projectMatch = searchPath.match(PROJECT_PATH_RE);
|
|
66
|
+
if (!projectMatch) return;
|
|
67
|
+
|
|
68
|
+
const project = projectMatch[1];
|
|
69
|
+
|
|
70
|
+
if (!/\/(experiments|knowledge|patterns)(\/|$)/.test(searchPath)) return;
|
|
71
|
+
|
|
72
|
+
const output = payload.tool_output || '';
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
|
|
75
|
+
const fileMatches = output.matchAll(/(?:^|\n)\s*([^\n]*\/(EXP-\d+[a-z]?|K-\d+|PAT-\d+)\.md)/g);
|
|
76
|
+
for (const match of fileMatches) {
|
|
77
|
+
const filename = `${match[2]}.md`;
|
|
78
|
+
if (!seen.has(filename)) {
|
|
79
|
+
seen.add(filename);
|
|
80
|
+
appendAccessLog(project, filename, 'Grep');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (seen.size === 0) {
|
|
85
|
+
appendAccessLog(project, '_directory_search', 'Grep');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function autoCommitAccessLog() {
|
|
90
|
+
try {
|
|
91
|
+
let hasStaged = false;
|
|
92
|
+
try {
|
|
93
|
+
execSync('git diff --cached --quiet', { cwd: DATA_DIR, timeout: 5_000 });
|
|
94
|
+
} catch {
|
|
95
|
+
hasStaged = true;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let dirty;
|
|
99
|
+
try {
|
|
100
|
+
dirty = execSync(
|
|
101
|
+
"git diff --name-only -- '**/access-log.jsonl'",
|
|
102
|
+
{ cwd: DATA_DIR, encoding: 'utf8', timeout: 5_000 },
|
|
103
|
+
).trim();
|
|
104
|
+
} catch {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!dirty) return;
|
|
108
|
+
|
|
109
|
+
const files = dirty.split('\n').filter(Boolean);
|
|
110
|
+
for (const f of files) {
|
|
111
|
+
execSync(`git add -- ${JSON.stringify(f)}`, { cwd: DATA_DIR, timeout: 5_000 });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!hasStaged) {
|
|
115
|
+
execSync('git commit -m "chore: update access log" --no-gpg-sign', {
|
|
116
|
+
cwd: DATA_DIR, timeout: 10_000, stdio: 'pipe',
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
} catch {
|
|
120
|
+
// Silently ignore — committing is best-effort
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function main() {
|
|
125
|
+
let input = '';
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
input = readFileSync(0, 'utf8');
|
|
129
|
+
} catch {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!input.trim()) return;
|
|
134
|
+
|
|
135
|
+
let payload;
|
|
136
|
+
try {
|
|
137
|
+
payload = JSON.parse(input);
|
|
138
|
+
} catch {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const toolName = payload.tool_name;
|
|
143
|
+
if (!toolName) return;
|
|
144
|
+
|
|
145
|
+
if (toolName === 'Read') {
|
|
146
|
+
processReadTool(payload);
|
|
147
|
+
} else if (toolName === 'Grep') {
|
|
148
|
+
processGrepTool(payload);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
autoCommitAccessLog();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
main();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: stdin { channel, sessionId, sessionName, trigger, timestampIso } + env CORTEX_HOOK_*
|
|
3
|
+
// output: stdout — prompt to inject into the closing session (empty stdout = skip)
|
|
4
|
+
// pos: !new pre-close memory flush hook — recall valuable user and project info from the session, write to corresponding context files
|
|
5
|
+
// >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
|
|
6
|
+
|
|
7
|
+
import { execSync } from 'child_process';
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
let raw = '';
|
|
11
|
+
for await (const chunk of process.stdin) raw += chunk;
|
|
12
|
+
let ctx = {};
|
|
13
|
+
try { ctx = JSON.parse(raw || '{}'); } catch {}
|
|
14
|
+
|
|
15
|
+
let hasChanges = false;
|
|
16
|
+
try {
|
|
17
|
+
const out = execSync('git status --porcelain', { encoding: 'utf8', timeout: 10_000 }).trim();
|
|
18
|
+
hasChanges = out.length > 0;
|
|
19
|
+
} catch {}
|
|
20
|
+
|
|
21
|
+
const prompt = `Before this session closes, do a memory flush. Think back through everything that happened in this session and persist anything a fresh session would need to know.
|
|
22
|
+
|
|
23
|
+
## User memory — USER.md (context/user/USER.md)
|
|
24
|
+
|
|
25
|
+
Is there anything new you learned about the user *personally*? USER.md is for the individual's preferences, identity, communication style, and working habits — NOT lab environment, project deadlines, or technical infrastructure (those belong in project context below).
|
|
26
|
+
|
|
27
|
+
Examples of what to record:
|
|
28
|
+
- "Prefers Chinese for discussion, English for code/paper"
|
|
29
|
+
- "Likes to review all changes before they're committed"
|
|
30
|
+
- "Dislikes long docstrings — prefers single-line comments at call sites"
|
|
31
|
+
- "Uses two-space indentation in all projects"
|
|
32
|
+
- "Prefers to be addressed as 'Alex' rather than 'Taylor'"
|
|
33
|
+
|
|
34
|
+
Non-examples (do NOT record — these are project/lab context, not personal):
|
|
35
|
+
- Deadlines ("Conference 2026 submission due [date]") → goes to project context
|
|
36
|
+
- Lab setup ("uses ROS 2 Humble on Ubuntu 22.04") → goes to project context
|
|
37
|
+
- Technical tools ("uses Weights & Biases") → goes to project context
|
|
38
|
+
- Transient facts ("asked me to run ls in /tmp")
|
|
39
|
+
- One-off requests unlikely to recur
|
|
40
|
+
- Information already present in USER.md
|
|
41
|
+
|
|
42
|
+
If you find something, use the /user-learn skill or directly edit USER.md. Respect the 3KB hard limit — compress rather than grow if near the limit. The file has YAML frontmatter (last-updated, updated-by, size-limit) — update those fields.
|
|
43
|
+
|
|
44
|
+
## Project context — STATUS.md, knowledge/K-NNN.md, ISSUES.md
|
|
45
|
+
|
|
46
|
+
Did this session produce findings, decisions, or changes that future sessions need to know? Did you discover the location of external resources?
|
|
47
|
+
|
|
48
|
+
Examples of what to record:
|
|
49
|
+
- A new experiment was launched → update STATUS.md with what's running
|
|
50
|
+
- A non-obvious fact was discovered ("the dataset is on gpu-server at /data/xxx") → create a K-NNN.md entry so it's indexed
|
|
51
|
+
- External resource locations → "The paper source is at ~/papers/conference2026/", "Training data lives on gpu-server:/datasets/dataset-v3/", "Reference implementation at https://github.com/xxx/yyy" — record in STATUS.md or as a knowledge entry
|
|
52
|
+
- A recurring friction was encountered ("the GPU on local always OOMs with batch_size > 32") → append to ISSUES.md
|
|
53
|
+
- A design decision was made → add to decisions/ directory
|
|
54
|
+
- A new project dependency or constraint was discovered → update STATUS.md
|
|
55
|
+
|
|
56
|
+
File update rules you MUST respect:
|
|
57
|
+
- **STATUS.md** — overwrite mode: replace with latest state, do not append
|
|
58
|
+
- **ISSUES.md** — append mode: add new entries at the end, keep history
|
|
59
|
+
- **knowledge/K-NNN.md** — atomic: one file per knowledge entry, with YAML frontmatter
|
|
60
|
+
- **knowledge/index.md, experiments/index.md, patterns/index.md** — AUTO-GENERATED, do NOT edit manually
|
|
61
|
+
- **mission.md** — requires user approval to modify
|
|
62
|
+
- **roadmap.md** — stable, only update checklist items that were verified this session
|
|
63
|
+
- **TASKS.yaml** — use cortex-task CLI, do not hand-edit
|
|
64
|
+
|
|
65
|
+
Do NOT create files for trivial observations. Only persist what a fresh session would genuinely need.
|
|
66
|
+
|
|
67
|
+
## After recording
|
|
68
|
+
|
|
69
|
+
- Run \`git status\` to review all changes
|
|
70
|
+
- Commit context file changes with a clear, specific message (e.g. "context: record gpu-server dataset path and Conference deadline")
|
|
71
|
+
- Do NOT commit changes you did not make`;
|
|
72
|
+
|
|
73
|
+
if (hasChanges) {
|
|
74
|
+
process.stdout.write(prompt + '\n\nNote: there are already uncommitted changes in the repo from earlier work — only commit your own changes, leave the rest alone.');
|
|
75
|
+
} else {
|
|
76
|
+
process.stdout.write(prompt);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main().catch((err) => {
|
|
81
|
+
process.stderr.write(`[new-session-hook] ${err?.message || err}\n`);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// input: stdin HookContext, argv [targetAgent]
|
|
3
|
+
// output: HookResult — compound + git commit prompt to targetAgent
|
|
4
|
+
// pos: scheduler and *-review template onEnd compound/commit hook
|
|
5
|
+
// >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
|
|
6
|
+
|
|
7
|
+
import { execSync } from 'child_process';
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
// Read context from stdin
|
|
11
|
+
let input = '';
|
|
12
|
+
for await (const chunk of process.stdin) input += chunk;
|
|
13
|
+
|
|
14
|
+
const context = JSON.parse(input);
|
|
15
|
+
const targetAgent = process.argv[2];
|
|
16
|
+
|
|
17
|
+
if (!targetAgent) {
|
|
18
|
+
console.error('[post-task-hook] Missing targetAgent argument (argv[2])');
|
|
19
|
+
console.log(JSON.stringify({ insertAgent: false }));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Check if compound is needed
|
|
24
|
+
const lastStep = context.steps[context.steps.length - 1];
|
|
25
|
+
const lastOutput = lastStep?.output || '';
|
|
26
|
+
const needCompound = typeof lastOutput !== 'string' || !lastOutput.includes('/cortex-common:compound-simple');
|
|
27
|
+
|
|
28
|
+
// Check git status for uncommitted changes
|
|
29
|
+
let hasChanges = false;
|
|
30
|
+
try {
|
|
31
|
+
const gitStatus = execSync('git status --porcelain', { encoding: 'utf8', timeout: 10000 }).trim();
|
|
32
|
+
hasChanges = gitStatus.length > 0;
|
|
33
|
+
} catch {
|
|
34
|
+
// git not available or error — skip git check
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!needCompound && !hasChanges) {
|
|
38
|
+
console.log(JSON.stringify({ insertAgent: false }));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Compose prompt
|
|
43
|
+
const parts = [];
|
|
44
|
+
|
|
45
|
+
if (needCompound) {
|
|
46
|
+
parts.push('/cortex-common:compound-simple Reflect on the task you just completed');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (hasChanges) {
|
|
50
|
+
parts.push('After completing the task, run `git status` to check for your uncommitted changes. If there are changes, commit them with an appropriate commit message. Do not commit changes that are not made by you.');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
console.log(JSON.stringify({
|
|
54
|
+
insertAgent: false,
|
|
55
|
+
targetAgent,
|
|
56
|
+
prompt: parts.join('\n\n'),
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
main().catch((err) => {
|
|
61
|
+
console.error(`[post-task-hook] Fatal: ${err.message}`);
|
|
62
|
+
console.log(JSON.stringify({ insertAgent: false }));
|
|
63
|
+
});
|