@cortex-agent/server 2026.9.15 → 2026.9.25

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.
Files changed (297) hide show
  1. package/README.md +3 -2
  2. package/defaults/config/hooks/08-agents-md-injector-post-tool.json +10 -0
  3. package/defaults/config/hooks/{10-cortex-md-injector-session-start.json → 10-agents-md-injector-session-start.json} +3 -3
  4. package/defaults/config/hooks/{CORTEX.md → AGENTS.md} +2 -2
  5. package/defaults/config/thread-templates/agents/creative.json +17 -0
  6. package/defaults/hooks/{CORTEX.md → AGENTS.md} +1 -1
  7. package/defaults/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
  8. package/defaults/hooks/cortex-hook-api.mjs +2 -2
  9. package/defaults/hooks/new-session-hook.mjs +2 -2
  10. package/defaults/hooks/rules-loader.mjs +2 -2
  11. package/defaults/hooks/status-md-guard.mjs +8 -8
  12. package/defaults/hooks/task-status-check.mjs +18 -76
  13. package/defaults/hooks/tasks-yaml-guard.mjs +2 -2
  14. package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +1 -1
  15. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +2 -2
  16. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
  17. package/defaults/plugins/cortex-system/skills/task/SKILL.md +1 -1
  18. package/defaults/prompts/systemPrompts/creative.md +13 -0
  19. package/defaults/prompts/systemPrompts/direct.md +1 -1
  20. package/defaults/rules/{cortex-md.md → agents-md.md} +4 -4
  21. package/defaults/rules/decision-records.md +1 -1
  22. package/defaults/rules/meta-conventions.md +4 -4
  23. package/defaults/rules/mission-md.md +1 -1
  24. package/dist/agent-adapter/claude/adapter.d.ts +12 -0
  25. package/dist/agent-adapter/claude/adapter.js +19 -1
  26. package/dist/agent-adapter/claude/hooks-builder.js +2 -2
  27. package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
  28. package/dist/agent-adapter/claude/spawn-args.js +14 -0
  29. package/dist/agent-adapter/claude/turn-machine.d.ts +11 -0
  30. package/dist/agent-adapter/claude/turn-machine.js +46 -5
  31. package/dist/agent-adapter/normalize/prompt-builder.d.ts +16 -1
  32. package/dist/agent-adapter/normalize/prompt-builder.js +24 -6
  33. package/dist/agent-adapter/pi/child-runner.d.ts +4 -2
  34. package/dist/agent-adapter/pi/child-runner.js +5 -1
  35. package/dist/agent-adapter/pi/event-parser.d.ts +3 -2
  36. package/dist/agent-adapter/pi/event-parser.js +46 -2
  37. package/dist/agent-adapter/pi/extensions.d.ts +7 -1
  38. package/dist/agent-adapter/pi/extensions.js +10 -3
  39. package/dist/agent-adapter/pi/mcp-bridge.js +8 -8
  40. package/dist/agent-adapter/pi/pi-session.js +5 -0
  41. package/dist/agent-adapter/pi/runtime.js +3 -0
  42. package/dist/agent-adapter/pi/session-options.js +5 -1
  43. package/dist/agent-adapter/pi/subagent.d.ts +15 -3
  44. package/dist/agent-adapter/pi/subagent.js +18 -0
  45. package/dist/agent-adapter/pi/tool-shims.d.ts +6 -1
  46. package/dist/agent-adapter/pi/tool-shims.js +34 -1
  47. package/dist/agent-adapter/types.d.ts +6 -0
  48. package/dist/core/agents/subagent/types.d.ts +3 -0
  49. package/dist/core/config-generator.js +17 -2
  50. package/dist/core/debug-mode.d.ts +11 -10
  51. package/dist/core/debug-mode.js +12 -18
  52. package/dist/core/exec-async.d.ts +26 -0
  53. package/dist/core/exec-async.js +47 -0
  54. package/dist/core/locales/en.d.ts +14 -1
  55. package/dist/core/locales/slices/commands.d.ts +12 -1
  56. package/dist/core/locales/slices/commands.js +24 -2
  57. package/dist/core/locales/slices/startup.d.ts +2 -0
  58. package/dist/core/locales/slices/startup.js +4 -0
  59. package/dist/core/mcp-tool-gate.js +1 -0
  60. package/dist/core/media-types.d.ts +10 -0
  61. package/dist/core/media-types.js +34 -0
  62. package/dist/core/platform-settings-spec.js +1 -1
  63. package/dist/core/rebuild-progress.d.ts +58 -0
  64. package/dist/core/rebuild-progress.js +103 -0
  65. package/dist/core/resilient-watch.js +5 -3
  66. package/dist/core/run-registry.d.ts +7 -0
  67. package/dist/core/run-registry.js +6 -0
  68. package/dist/core/settings-spec.d.ts +21 -0
  69. package/dist/core/settings-spec.js +28 -1
  70. package/dist/core/types/agent-types.d.ts +3 -1
  71. package/dist/core/types/thread-types.d.ts +23 -4
  72. package/dist/core/utils.d.ts +1 -1
  73. package/dist/core/utils.js +1 -1
  74. package/dist/domain/agents/agent-state.d.ts +7 -0
  75. package/dist/domain/agents/agent-state.js +9 -1
  76. package/dist/domain/agents/agent-switch.d.ts +38 -0
  77. package/dist/domain/agents/agent-switch.js +106 -0
  78. package/dist/domain/agents/config.d.ts +20 -2
  79. package/dist/domain/agents/config.js +58 -4
  80. package/dist/domain/agents/index.d.ts +1 -0
  81. package/dist/domain/agents/index.js +1 -0
  82. package/dist/domain/agents/profile-manager.d.ts +6 -0
  83. package/dist/domain/agents/profile-manager.js +14 -1
  84. package/dist/domain/executions/registry.d.ts +3 -2
  85. package/dist/domain/executions/registry.js +84 -10
  86. package/dist/domain/mcp/bundled-server.js +4 -3
  87. package/dist/domain/mcp/feishu/file.js +37 -18
  88. package/dist/domain/mcp/feishu/types.d.ts +3 -0
  89. package/dist/domain/mcp/feishu-server.js +1 -1
  90. package/dist/domain/mcp/tools/{cortex-md.d.ts → agents-md.d.ts} +6 -6
  91. package/dist/domain/mcp/tools/{cortex-md.js → agents-md.js} +6 -6
  92. package/dist/domain/mcp/tools/remote-file.d.ts +20 -0
  93. package/dist/domain/mcp/tools/remote-file.js +44 -0
  94. package/dist/domain/mcp/tools/slack.d.ts +2 -0
  95. package/dist/domain/mcp/tools/slack.js +22 -7
  96. package/dist/domain/mcp/tools/task-ops.js +5 -13
  97. package/dist/domain/mcp/tools/ui-file.js +23 -10
  98. package/dist/domain/mcp/tools/waitpoint.d.ts +3 -0
  99. package/dist/domain/mcp/tools/waitpoint.js +122 -0
  100. package/dist/domain/memory/agents-md-injector.d.ts +24 -0
  101. package/dist/domain/memory/{cortex-md-injector.js → agents-md-injector.js} +10 -7
  102. package/dist/domain/plugins/runtime.js +1 -1
  103. package/dist/domain/plugins/skill-projection.d.ts +8 -2
  104. package/dist/domain/plugins/skill-projection.js +76 -19
  105. package/dist/domain/projects/project-store.d.ts +1 -1
  106. package/dist/domain/projects/project-store.js +3 -3
  107. package/dist/domain/remote/client-bootstrap.js +1 -1
  108. package/dist/domain/remote/client-hot-reload.d.ts +1 -1
  109. package/dist/domain/remote/client-hot-reload.js +30 -24
  110. package/dist/domain/remote/client-manager.js +39 -119
  111. package/dist/domain/remote/cortex-client-config.d.ts +1 -1
  112. package/dist/domain/remote/cortex-client-config.js +1 -1
  113. package/dist/domain/remote/device-file.d.ts +51 -0
  114. package/dist/domain/remote/device-file.js +193 -0
  115. package/dist/domain/remote/device-port.js +3 -0
  116. package/dist/domain/remote/reverse-stream.d.ts +18 -7
  117. package/dist/domain/remote/reverse-stream.js +19 -6
  118. package/dist/domain/runs/engine-spec.js +4 -0
  119. package/dist/domain/runs/request.d.ts +6 -0
  120. package/dist/domain/runs/run.js +1 -0
  121. package/dist/domain/runs/spec-loader.d.ts +4 -3
  122. package/dist/domain/runs/spec-loader.js +4 -3
  123. package/dist/domain/scheduling/jobs/sync-public.js +6 -6
  124. package/dist/domain/scheduling/scheduler.js +14 -12
  125. package/dist/domain/sessions/session-lifecycle.d.ts +5 -0
  126. package/dist/domain/sessions/session-lifecycle.js +13 -1
  127. package/dist/domain/system/rebuild-hold.d.ts +44 -0
  128. package/dist/domain/system/rebuild-hold.js +91 -0
  129. package/dist/domain/system/server-update-check.d.ts +2 -1
  130. package/dist/domain/system/server-update-check.js +15 -13
  131. package/dist/domain/tasks/archiver.js +21 -13
  132. package/dist/domain/tasks/claim-recovery.js +2 -2
  133. package/dist/domain/tasks/dispatch-utils.d.ts +10 -1
  134. package/dist/domain/tasks/dispatch-utils.js +46 -1
  135. package/dist/domain/tasks/dispatcher.js +4 -5
  136. package/dist/domain/tasks/mutator.d.ts +2 -2
  137. package/dist/domain/tasks/mutator.js +62 -61
  138. package/dist/domain/tasks/system/task-cli.js +2 -2
  139. package/dist/domain/tasks/system/task-completion.d.ts +7 -2
  140. package/dist/domain/tasks/system/task-completion.js +69 -6
  141. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -1
  142. package/dist/domain/tasks/system/task-lifecycle-edit.js +21 -2
  143. package/dist/domain/tasks/system/task-lock.d.ts +23 -0
  144. package/dist/domain/tasks/system/task-lock.js +29 -1
  145. package/dist/domain/tasks/system/task-mutations.d.ts +14 -1
  146. package/dist/domain/tasks/system/task-mutations.js +25 -2
  147. package/dist/domain/tasks/system/task-state.d.ts +12 -1
  148. package/dist/domain/tasks/system/task-state.js +20 -3
  149. package/dist/domain/threads/prompt-builder.d.ts +9 -6
  150. package/dist/domain/threads/prompt-builder.js +28 -10
  151. package/dist/domain/threads/runner.js +10 -4
  152. package/dist/domain/threads/state-machine.js +15 -11
  153. package/dist/domain/threads/template-loader.js +6 -4
  154. package/dist/domain/threads/template-validate.d.ts +43 -6
  155. package/dist/domain/threads/template-validate.js +12 -0
  156. package/dist/domain/ui-service/app-router.d.ts +34 -3
  157. package/dist/domain/ui-service/app-router.js +9 -14
  158. package/dist/domain/ui-service/input-schemas.d.ts +28 -5
  159. package/dist/domain/ui-service/input-schemas.js +24 -9
  160. package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
  161. package/dist/domain/ui-service/mutate/sessions.d.ts +6 -1
  162. package/dist/domain/ui-service/mutate/sessions.js +54 -0
  163. package/dist/domain/ui-service/mutate/tasks.js +4 -3
  164. package/dist/domain/ui-service/mutate/waitpoints.d.ts +2 -0
  165. package/dist/domain/ui-service/mutate/waitpoints.js +20 -0
  166. package/dist/domain/ui-service/platform-settings.js +1 -1
  167. package/dist/domain/ui-service/plugins-shared.js +1 -1
  168. package/dist/domain/ui-service/query/config.js +20 -2
  169. package/dist/domain/ui-service/query/executions.js +0 -2
  170. package/dist/domain/ui-service/query/machine-detail.js +3 -8
  171. package/dist/domain/ui-service/query/memory.js +29 -35
  172. package/dist/domain/ui-service/query/sessions.js +96 -12
  173. package/dist/domain/ui-service/query/system.js +19 -0
  174. package/dist/domain/ui-service/query/threads.js +1 -54
  175. package/dist/domain/ui-service/query/waitpoints.d.ts +30 -0
  176. package/dist/domain/ui-service/query/waitpoints.js +117 -0
  177. package/dist/domain/ui-service/query-input-schemas.d.ts +4 -0
  178. package/dist/domain/ui-service/query-input-schemas.js +5 -0
  179. package/dist/domain/ui-service/trpc.js +1 -1
  180. package/dist/domain/ui-service/types.d.ts +229 -51
  181. package/dist/domain/ui-service/types.js +1 -1
  182. package/dist/domain/ui-service/ui-service.js +8 -31
  183. package/dist/domain/waitpoints/notices.d.ts +21 -0
  184. package/dist/domain/waitpoints/notices.js +115 -0
  185. package/dist/domain/waitpoints/service.d.ts +91 -0
  186. package/dist/domain/waitpoints/service.js +243 -0
  187. package/dist/entry/app.js +52 -11
  188. package/dist/entry/auth-login-cli.js +1 -1
  189. package/dist/entry/auth-login-terminal.js +1 -1
  190. package/dist/entry/daemon-notice.d.ts +10 -1
  191. package/dist/entry/daemon-notice.js +16 -1
  192. package/dist/entry/daemon.d.ts +43 -2
  193. package/dist/entry/daemon.js +163 -9
  194. package/dist/entry/init-auth.js +1 -1
  195. package/dist/entry/init.js +6 -6
  196. package/dist/entry/signal-cli.d.ts +30 -0
  197. package/dist/entry/signal-cli.js +207 -0
  198. package/dist/entry/start-ui-http.d.ts +1 -1
  199. package/dist/entry/start-ui-http.js +2 -2
  200. package/dist/events/event-types.d.ts +0 -7
  201. package/dist/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
  202. package/dist/hooks/cortex-hook-api.mjs +2 -2
  203. package/dist/hooks/new-session-hook.mjs +2 -2
  204. package/dist/hooks/rules-loader.mjs +2 -2
  205. package/dist/hooks/status-md-guard.mjs +8 -8
  206. package/dist/hooks/task-status-check.mjs +18 -76
  207. package/dist/hooks/tasks-yaml-guard.mjs +2 -2
  208. package/dist/orchestration/agent-file-send.d.ts +9 -0
  209. package/dist/orchestration/agent-file-send.js +21 -2
  210. package/dist/orchestration/agent-runner.d.ts +3 -2
  211. package/dist/orchestration/agent-runner.js +33 -12
  212. package/dist/orchestration/attachments-store.d.ts +31 -0
  213. package/dist/orchestration/attachments-store.js +184 -0
  214. package/dist/orchestration/conversation-request.d.ts +37 -0
  215. package/dist/orchestration/conversation-request.js +91 -22
  216. package/dist/orchestration/interactions/plan-approvals.js +1 -1
  217. package/dist/orchestration/mid-turn-inject.d.ts +3 -0
  218. package/dist/orchestration/mid-turn-inject.js +9 -4
  219. package/dist/orchestration/outputs-store.d.ts +11 -0
  220. package/dist/orchestration/outputs-store.js +32 -6
  221. package/dist/orchestration/resume-dispatcher.js +4 -2
  222. package/dist/orchestration/routing/commands/mode.js +114 -63
  223. package/dist/orchestration/routing/file-handler.d.ts +23 -2
  224. package/dist/orchestration/routing/file-handler.js +22 -5
  225. package/dist/orchestration/routing/webhook.js +193 -39
  226. package/dist/orchestration/session-gateway.d.ts +1 -1
  227. package/dist/orchestration/session-gateway.js +1 -0
  228. package/dist/orchestration/thread-executor.d.ts +2 -0
  229. package/dist/orchestration/thread-executor.js +24 -1
  230. package/dist/orchestration/thread-input.d.ts +3 -2
  231. package/dist/orchestration/thread-input.js +8 -9
  232. package/dist/orchestration/turn/turn-prep.d.ts +15 -1
  233. package/dist/orchestration/turn/turn-prep.js +19 -8
  234. package/dist/orchestration/turn/turn.js +1 -0
  235. package/dist/orchestration/waitpoint-ingress.d.ts +41 -0
  236. package/dist/orchestration/waitpoint-ingress.js +172 -0
  237. package/dist/orchestration/waitpoint-notifier.d.ts +21 -0
  238. package/dist/orchestration/waitpoint-notifier.js +119 -0
  239. package/dist/orchestration/waitpoint-remote-drain.d.ts +20 -0
  240. package/dist/orchestration/waitpoint-remote-drain.js +147 -0
  241. package/dist/orchestration/waitpoint-sweep.d.ts +42 -0
  242. package/dist/orchestration/waitpoint-sweep.js +87 -0
  243. package/dist/platform/adapters/feishu-image.d.ts +19 -0
  244. package/dist/platform/adapters/feishu-image.js +71 -0
  245. package/dist/platform/adapters/feishu.d.ts +2 -0
  246. package/dist/platform/adapters/feishu.js +26 -16
  247. package/dist/platform/ui-http/listening-ports.d.ts +1 -1
  248. package/dist/platform/ui-http/listening-ports.js +1 -1
  249. package/dist/platform/ui-http/ui-session.js +1 -1
  250. package/dist/store/conversation-display-projection.d.ts +9 -1
  251. package/dist/store/conversation-display-projection.js +13 -6
  252. package/dist/store/conversation-history-reader.d.ts +19 -0
  253. package/dist/store/conversation-history-reader.js +163 -44
  254. package/dist/store/conversation-history-repo.d.ts +37 -10
  255. package/dist/store/conversation-history-repo.js +161 -139
  256. package/dist/store/conversation-ledger-repo.js +1 -1
  257. package/dist/store/execution-repo.d.ts +1 -19
  258. package/dist/store/execution-repo.js +1 -18
  259. package/dist/store/project-notes-repo.js +11 -2
  260. package/dist/store/prompt-migration-replacements.js +1 -1
  261. package/dist/store/session-registry-import.js +1 -1
  262. package/dist/store/session-registry-journal.d.ts +4 -0
  263. package/dist/store/session-registry-journal.js +5 -1
  264. package/dist/store/session-registry-repo.d.ts +2 -1
  265. package/dist/store/session-registry-repo.js +3 -1
  266. package/dist/store/task-repo.d.ts +6 -3
  267. package/dist/store/task-repo.js +26 -10
  268. package/dist/store/version-migrations.d.ts +13 -3
  269. package/dist/store/version-migrations.js +254 -24
  270. package/dist/store/waitpoint-repo.d.ts +108 -0
  271. package/dist/store/waitpoint-repo.js +94 -0
  272. package/package.json +3 -2
  273. package/web/dist/AGENTS.md +10 -0
  274. package/web/dist/assets/index-B1dBi8Za.css +1 -0
  275. package/web/dist/assets/{index-CEZ0DSei.js → index-BAeLybF0.js} +1 -1
  276. package/web/dist/assets/index-BcQI8Fh5.js +445 -0
  277. package/web/dist/index.html +12 -4
  278. package/web/dist/theme.css +211 -40
  279. package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +0 -10
  280. package/dist/domain/executions/log-tailer.d.ts +0 -71
  281. package/dist/domain/executions/log-tailer.js +0 -194
  282. package/dist/domain/memory/cortex-md-injector.d.ts +0 -24
  283. package/dist/domain/memory/cortex-md-scanner.d.ts +0 -10
  284. package/dist/domain/memory/cortex-md-scanner.js +0 -66
  285. package/dist/domain/remote/cortex-client.d.ts +0 -1
  286. package/dist/domain/remote/cortex-client.js +0 -662
  287. package/dist/domain/tasks/system/cortex-run.d.ts +0 -25
  288. package/dist/domain/tasks/system/cortex-run.js +0 -360
  289. package/web/dist/assets/index-CRDJo39X.css +0 -1
  290. package/web/dist/assets/index-DjuPJVZE.js +0 -444
  291. /package/defaults/{CORTEX.md → AGENTS.md} +0 -0
  292. /package/defaults/config/{CORTEX.md → AGENTS.md} +0 -0
  293. /package/defaults/context/{CORTEX.md → AGENTS.md} +0 -0
  294. /package/defaults/context/ideas/{CORTEX.md → AGENTS.md} +0 -0
  295. /package/defaults/context/projects/{CORTEX.md → AGENTS.md} +0 -0
  296. /package/defaults/context/scans/{CORTEX.md → AGENTS.md} +0 -0
  297. /package/defaults/context/user/{CORTEX.md → AGENTS.md} +0 -0
package/README.md CHANGED
@@ -147,16 +147,17 @@ variable reference, file layout, and precedence rules are in
147
147
  | [Browser Access](./docs/browser-access.md) | Web workbench authentication and deployment |
148
148
  | [Slack Setup](./docs/slack-setup.md) | App creation, token collection, Socket Mode, scopes |
149
149
  | [Configuration](./docs/configuration.md) | Full `.env` and `config/settings.json` reference, `profiles.json`, file layout, hot-reload |
150
- | [CLI Reference](./docs/cli-reference.md) | `cortex`, `cortex-task`, `cortex-run` — every subcommand and flag |
150
+ | [CLI Reference](./docs/cli-reference.md) | `cortex`, `cortex-task`, `cortex-signal` — every subcommand and flag |
151
151
  | [Backends](./docs/backends.md) | Claude Code vs PI, feature matrix, fallback, cost reporting |
152
152
  | [Architecture](./docs/architecture.md) | Server layers, WS protocol, event bus |
153
153
  | [Threads](./docs/threads.md) | Multi-agent pipelines, templates, transitions, hooks |
154
- | [Tasks](./docs/tasks.md) | TASKS.yaml format, lifecycle, dispatch, cortex-run watchdog |
154
+ | [Tasks](./docs/tasks.md) | TASKS.yaml format, lifecycle, dispatch, acceptance ledger |
155
155
  | [Memory](./docs/memory.md) | EXP/K/PAT atomized knowledge, project log governance |
156
156
  | [Skills & Plugins](./docs/skills-and-plugins.md) | Skill authoring, plugin layout, third-party plugins |
157
157
  | [Scheduling](./docs/scheduling.md) | Interval/daily/weekly/once schedules, preCheck, fallback |
158
158
  | [Safety & Approvals](./docs/safety-and-approvals.md) | Blast-radius classes, approval workflow, audit trail |
159
159
  | [Hooks](./docs/hooks.md) | Hook lifecycle, hook-bridge, custom hooks in settings.json |
160
+ | [Waitpoints](./docs/waitpoints.md) | Waiting on external jobs without polling: arm, signal, quorum, expiry |
160
161
  | [MCP](./docs/mcp.md) | Privilege-scoped Cortex MCP servers, third-party MCP |
161
162
  | [Cross-machine](./docs/cross-machine.md) | cortex-client deployment, remote tools, network topology |
162
163
 
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "agents-md-injector-post-tool",
3
+ "event": "agent:post-tool",
4
+ "matcher": "Read|Edit",
5
+ "run": {
6
+ "script": "agents-md-injector.mjs"
7
+ },
8
+ "enabled": true,
9
+ "version": "2026.9.15"
10
+ }
@@ -1,10 +1,10 @@
1
1
  {
2
- "id": "cortex-md-injector-session-start",
2
+ "id": "agents-md-injector-session-start",
3
3
  "event": "agent:session-start",
4
4
  "matcher": "startup|resume|clear|compact",
5
5
  "run": {
6
- "script": "cortex-md-injector.mjs"
6
+ "script": "agents-md-injector.mjs"
7
7
  },
8
8
  "enabled": true,
9
- "version": "2026.7.29"
9
+ "version": "2026.9.15"
10
10
  }
@@ -8,8 +8,8 @@ Managed declarative hooks shipped into the user hook registry.
8
8
  | 05-memory-ref-tracker.json | tracker | Tracks memory reference reads |
9
9
  | 06-rules-loader.json | loader | Loads matching rules after reads |
10
10
  | 07-session-activity-tracker.json | tracker | Records session tool activity |
11
- | 08-cortex-md-injector-post-tool.json | context | Injects directory context after tools |
12
- | 10-cortex-md-injector-session-start.json | context | Injects context at session start |
11
+ | 08-agents-md-injector-post-tool.json | context | Injects directory context after tools |
12
+ | 10-agents-md-injector-session-start.json | context | Injects context at session start |
13
13
  | 11-task-status-check.json | thread | Checks task state when dispatch threads end |
14
14
  | 12-session-new-hook.json | session | Flushes memory before starting a new session |
15
15
  | 13-status-md-guard.json | guard | Enforces STATUS.md register size caps |
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "creative",
3
+ "description": "Clean-room creative environment: writing, image prompts, naming, copy. No skills, no project rules, minimal tools.",
4
+ "profile": "__active__",
5
+ "persistSession": true,
6
+ "promptTemplate": "{{input}}",
7
+ "systemPrompt": "file:creative.md",
8
+ "tools": "Read,Write,Edit",
9
+ "pluginDirs": [],
10
+ "skills": false,
11
+ "settingSources": [],
12
+ "mcpComposition": "direct",
13
+ "mcpToolAllowlist": ["send_file", "send_view", "cortex_ask_user"],
14
+ "loadRules": false,
15
+ "disableHooks": true,
16
+ "projectContext": false
17
+ }
@@ -5,7 +5,7 @@ Managed hook scripts deployed into the runtime hook directory.
5
5
  | filename | role | function |
6
6
  |---|---|---|
7
7
  | cortex-hook-api.mjs | library | posts non-empty question arrays for hooks |
8
- | cortex-md-injector.mjs | context | Injects matching directory context; also exports runHook for in-process callers |
8
+ | agents-md-injector.mjs | context | Injects matching directory context; also exports runHook for in-process callers |
9
9
  | memory-ref-tracker.mjs | tracker | Records memory reference reads |
10
10
  | new-session-hook.mjs | session | Builds the new-session flush prompt |
11
11
  | rules-loader.mjs | loader | Loads matching rules after file reads |
@@ -1,33 +1,45 @@
1
1
  #!/usr/bin/env node
2
- // @cortex-hook-version 2026.8.7 ← set to the current release version (agent-server/package.json) whenever you change this hook; syncManagedHooks then refreshes deployed installs
2
+ // @cortex-hook-version 2026.9.15 ← set to the current release version (agent-server/package.json) whenever you change this hook; syncManagedHooks then refreshes deployed installs
3
3
  // input: stdin JSON — Claude Code hook event or PI hook-bridge payload; or runHook(payload, env)
4
4
  // output: { hookSpecificOutput: { hookEventName, additionalContext, matched } }
5
5
  // Exported `runHook` is the in-process entry point: the PI hook bridge calls it directly
6
6
  // instead of spawning this file, so every path here takes its scope from the `env`
7
7
  // argument rather than process.env (one daemon process serves many sessions).
8
- // pos: Inject CORTEX.md / CORTEX.local.md ancestor chain into agent context
8
+ // pos: Inject the AGENTS.md / AGENTS.local.md ancestor chain that THE BACKEND DOES NOT LOAD.
9
+ // Both backends load AGENTS.md natively now, so this hook only covers their blind spots
10
+ // (see backendLoadsNatively below for the measured matrix):
11
+ // · paths outside the session cwd tree — neither backend loads these
12
+ // · AGENTS.local.md, anywhere — neither backend has a `.local` name
13
+ // · descendants of cwd, on PI — PI walks cwd→root only, never downward
14
+ // Anything the backend already loaded is recorded in the dedup cache WITHOUT being
15
+ // injected, so the agent never receives the same rules twice.
9
16
  // 2-event dispatch:
10
17
  // PostToolUse (Read|Edit) — from tool_input.file_path/path
11
18
  // SessionStart (startup|resume|clear|compact) — from payload.cwd
12
19
  // Shared per-session cache with remote MCP injection under tmp/cortexmd-cache
13
20
  // — stable session + physical host + path + mtime dedup across tool families
14
21
  // — only files actually injected are marked seen; truncated files stay eligible
15
- // markOnlyPaths: exact CORTEX.md tool target → cache update only, no duplicate
22
+ // markOnlyPaths: exact AGENTS.md tool target → cache update only, no duplicate
16
23
  // Total length guard at 9,500 chars; files that overflow the budget are turned into an
17
24
  // explicit "Read EACH of these files now" instruction instead of a silent drop
18
- // >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
25
+ // >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
19
26
 
20
27
  import {
21
28
  closeSync, existsSync, mkdirSync, openSync, readFileSync,
22
29
  renameSync, rmSync, statSync, writeFileSync,
23
30
  } from 'fs';
24
- import { join, resolve, dirname, basename } from 'path';
31
+ import { join, resolve, dirname, basename, sep } from 'path';
25
32
  import { homedir, hostname } from 'os';
26
33
  import { fileURLToPath } from 'url';
27
34
 
28
35
  const HOSTNAME = hostname();
29
36
  const HOST_ID = HOSTNAME.toLowerCase();
30
- const CORTEX_MD_NAMES = ['CORTEX.md', 'CORTEX.local.md'];
37
+ const AGENTS_MD_NAMES = ['AGENTS.md', 'AGENTS.local.md'];
38
+ /** Names neither backend loads on its own — always ours to inject. */
39
+ const LOCAL_ONLY_NAMES = new Set(['AGENTS.local.md']);
40
+ /** Claude's AGENTS.md fallback is all-or-nothing: a single CLAUDE.md anywhere in the cwd
41
+ * ancestor chain makes it load THAT family and ignore every AGENTS.md. */
42
+ const CLAUDE_MD_NAMES = ['CLAUDE.md', 'CLAUDE.local.md', join('.claude', 'CLAUDE.md')];
31
43
  const MAX_FILE_SIZE = 200 * 1024;
32
44
  const MAX_DEPTH = 20;
33
45
  const MAX_CONTEXT_CHARS = 9500;
@@ -40,7 +52,7 @@ const SESSION_ID_RE = /^[A-Za-z0-9._-]+$/;
40
52
  function hookPaths(env) {
41
53
  const home = env.CORTEX_HOME ? resolve(env.CORTEX_HOME) : join(homedir(), '.cortex');
42
54
  return {
43
- homeFallback: join(home, 'CORTEX.md'),
55
+ homeFallback: join(home, 'AGENTS.md'),
44
56
  cacheDir: join(home, 'tmp', 'cortexmd-cache'),
45
57
  };
46
58
  }
@@ -59,32 +71,34 @@ function tryReadEntry(filePath) {
59
71
  }
60
72
  }
61
73
 
74
+ /** The directory an ancestor walk should start from: the path itself when it is a directory,
75
+ * otherwise its parent (also the right answer for a path that does not exist). */
76
+ function startDir(targetFilePath) {
77
+ const resolved = resolve(targetFilePath);
78
+ try {
79
+ const st = statSync(resolved, { throwIfNoEntry: false });
80
+ return (st && st.isDirectory()) ? resolved : dirname(resolved);
81
+ } catch {
82
+ return dirname(resolved);
83
+ }
84
+ }
85
+
62
86
  /** Walk from the directory containing `targetFilePath` up to the filesystem root,
63
- * collecting CORTEX.md and CORTEX.local.md at each level. Also appends the
64
- * home fallback at ~/.cortex/CORTEX.md if present. Returns leaf→root order.
65
- * If targetFilePath is a directory, scan that directory and its ancestors.
66
- * If it is a file (or does not exist), scan its parent directory and ancestors. */
87
+ * collecting AGENTS.md and AGENTS.local.md at each level. Also appends the
88
+ * home fallback at ~/.cortex/AGENTS.md if present. Returns leaf→root order. */
67
89
  function scanChain(targetFilePath, paths) {
68
90
  const entries = [];
69
91
  const seen = new Set();
70
92
 
71
- let resolved;
72
- try {
73
- resolved = resolve(targetFilePath);
74
- } catch {
75
- return entries;
76
- }
77
-
78
93
  let dir;
79
94
  try {
80
- const st = statSync(resolved, { throwIfNoEntry: false });
81
- dir = (st && st.isDirectory()) ? resolved : dirname(resolved);
95
+ dir = startDir(targetFilePath);
82
96
  } catch {
83
- dir = dirname(resolved);
97
+ return entries;
84
98
  }
85
99
 
86
100
  for (let depth = 0; depth < MAX_DEPTH; depth++) {
87
- for (const name of CORTEX_MD_NAMES) {
101
+ for (const name of AGENTS_MD_NAMES) {
88
102
  const p = join(dir, name);
89
103
  if (seen.has(p)) continue;
90
104
  seen.add(p);
@@ -106,6 +120,66 @@ function scanChain(targetFilePath, paths) {
106
120
  return entries;
107
121
  }
108
122
 
123
+ // ── backend coverage ──
124
+ //
125
+ // Measured against Claude Code 2.1.278 and pi (@earendil-works/pi-coding-agent):
126
+ //
127
+ // memory file location | Claude | PI | ours?
128
+ // --------------------------------+--------+-----+-------
129
+ // ancestor of cwd (incl. cwd) | yes | yes | no
130
+ // descendant of cwd, read by tool | yes | no | PI only
131
+ // outside the cwd tree | no | no | both
132
+ // *.local.md, anywhere | no | no | both
133
+ //
134
+ // Claude resolves its fallback through the `claude-md-or-agents-md` setting, whose default
135
+ // loads AGENTS.md ONLY when no CLAUDE.md exists in the chain — hence the guard below. PI
136
+ // reads ["AGENTS.md","AGENTS.MD","CLAUDE.md","CLAUDE.MD"] per directory, cwd→root, and never
137
+ // descends, so on PI this hook is the only thing that delivers a project's own index file.
138
+
139
+ /** True when a CLAUDE.md-family file sits in the cwd ancestor chain, which switches Claude off
140
+ * the AGENTS.md fallback entirely. Cheap: same walk shape as scanChain, existence checks only. */
141
+ function claudeMdInChain(cwd) {
142
+ let dir;
143
+ try {
144
+ dir = startDir(cwd);
145
+ } catch {
146
+ return false;
147
+ }
148
+ for (let depth = 0; depth < MAX_DEPTH; depth++) {
149
+ for (const name of CLAUDE_MD_NAMES) {
150
+ try {
151
+ if (existsSync(join(dir, name))) return true;
152
+ } catch { /* unreadable — treat as absent */ }
153
+ }
154
+ const parent = dirname(dir);
155
+ if (parent === dir) break;
156
+ dir = parent;
157
+ }
158
+ return false;
159
+ }
160
+
161
+ function isAncestorOrSelf(dir, cwd) {
162
+ return dir === cwd || cwd.startsWith(dir.endsWith(sep) ? dir : dir + sep);
163
+ }
164
+
165
+ function isUnder(dir, cwd) {
166
+ return dir === cwd || dir.startsWith(cwd.endsWith(sep) ? cwd : cwd + sep);
167
+ }
168
+
169
+ /**
170
+ * Whether the backend has already put this entry in the agent's context on its own.
171
+ * Such entries are marked in the dedup cache but never injected — that is the whole point of
172
+ * this hook after both backends gained native AGENTS.md support.
173
+ */
174
+ function backendLoadsNatively(entry, cwd, backend, claudeUsesAgentsMd) {
175
+ if (LOCAL_ONLY_NAMES.has(basename(entry.path))) return false;
176
+ if (!cwd) return false;
177
+ const dir = dirname(entry.path);
178
+ if (backend === 'pi') return isAncestorOrSelf(dir, cwd);
179
+ if (!claudeUsesAgentsMd) return false;
180
+ return isAncestorOrSelf(dir, cwd) || isUnder(dir, cwd);
181
+ }
182
+
109
183
  // ── cache helpers ──
110
184
 
111
185
  function loadCache(sessionId, paths) {
@@ -186,7 +260,7 @@ function buildContext(entries) {
186
260
  // Walk entries in original order (leaf→root), inlining each as a block until the char
187
261
  // budget is exhausted. Once exhausted, the remaining entries are NOT inlined — instead
188
262
  // they are turned into an explicit read-instruction below, so their rules are never
189
- // silently dropped (e.g. a root-level CORTEX.local.md carrying dev/safety rules).
263
+ // silently dropped (e.g. a root-level AGENTS.local.md carrying dev/safety rules).
190
264
  const includedBlocks = [];
191
265
  const includedPaths = [];
192
266
  const truncated = [];
@@ -194,7 +268,7 @@ function buildContext(entries) {
194
268
  let budgetExhausted = false;
195
269
 
196
270
  for (const e of entries) {
197
- const block = `<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>`;
271
+ const block = `<system-reminder>\nAuto-loaded AGENTS.md from ${HOSTNAME}:${e.path} (ancestor of accessed path, outside the session working directory). These instructions apply to files under this directory.\n\n${e.content}\n</system-reminder>`;
198
272
  if (budgetExhausted || totalLen + block.length > MAX_CONTEXT_CHARS) {
199
273
  budgetExhausted = true; // match prior behavior: stop inlining at the first overflow
200
274
  truncated.push(e);
@@ -212,7 +286,7 @@ function buildContext(entries) {
212
286
  if (truncated.length > 0) {
213
287
  const list = truncated.map(e => `- ${e.path}`).join('\n');
214
288
  parts.push(
215
- `<system-reminder>\n⚠️ ${truncated.length} CORTEX rule file(s) were too large to inline here. ` +
289
+ `<system-reminder>\n⚠️ ${truncated.length} AGENTS rule file(s) were too large to inline here. ` +
216
290
  `Read EACH of the following files now to load their rules before proceeding:\n${list}\n</system-reminder>`
217
291
  );
218
292
  }
@@ -227,6 +301,10 @@ function buildContext(entries) {
227
301
  * Run the hook against one payload and one session environment.
228
302
  * Returns the hook output object, or null when this event injects nothing.
229
303
  * Pure of process state apart from the filesystem, so the PI bridge can call it in-process.
304
+ *
305
+ * SessionStart is deliberately mark-only in the common case: the backend has just loaded the
306
+ * cwd ancestor chain itself, so recording those paths in the shared cache is what stops the
307
+ * first PostToolUse from injecting them a second time.
230
308
  */
231
309
  export function runHook(payload, env = process.env) {
232
310
  const paths = hookPaths(env);
@@ -236,6 +314,10 @@ export function runHook(payload, env = process.env) {
236
314
  const sessionId = stableSessionId && SESSION_ID_RE.test(stableSessionId)
237
315
  ? stableSessionId
238
316
  : payload.session_id;
317
+ // Default to PI, the backend with the SMALLER native coverage. Guessing "claude" for an
318
+ // undeclared spawn would make us skip descendants of cwd that PI never loads — a silent loss of
319
+ // rules. Guessing "pi" only risks injecting something Claude already had: wasteful, never wrong.
320
+ const backend = env.CORTEX_BACKEND?.trim() === 'claude' ? 'claude' : 'pi';
239
321
 
240
322
  let scanRoot = null;
241
323
  if (hookEventName === 'PostToolUse') {
@@ -250,13 +332,22 @@ export function runHook(payload, env = process.env) {
250
332
  const entries = scanChain(scanRoot, paths);
251
333
  if (entries.length === 0) return null;
252
334
 
335
+ const cwd = typeof payload.cwd === 'string' && payload.cwd ? resolve(payload.cwd) : null;
336
+ const claudeUsesAgentsMd = backend === 'claude' && cwd ? !claudeMdInChain(cwd) : false;
337
+
253
338
  const lock = acquireLock(sessionId, paths);
254
339
  try {
255
340
  const cache = loadCache(sessionId, paths);
341
+
342
+ // Paths whose mtime we record without injecting: the file the tool just returned in full,
343
+ // plus everything the backend loaded on its own.
256
344
  const markOnlyPaths = new Set();
257
345
  if (hookEventName === 'PostToolUse') {
258
346
  const targetPath = resolve(payload.tool_input?.file_path || payload.tool_input?.path || '');
259
- if (CORTEX_MD_NAMES.includes(basename(targetPath))) markOnlyPaths.add(targetPath);
347
+ if (AGENTS_MD_NAMES.includes(basename(targetPath))) markOnlyPaths.add(targetPath);
348
+ }
349
+ for (const entry of entries) {
350
+ if (backendLoadsNatively(entry, cwd, backend, claudeUsesAgentsMd)) markOnlyPaths.add(entry.path);
260
351
  }
261
352
 
262
353
  let changed = false;
@@ -1,7 +1,7 @@
1
1
  // input: node:http and Cortex hook environment
2
- // output: askUser helper @cortex-hook-version 2026.8.23
2
+ // output: askUser helper @cortex-hook-version 2026.9.15
3
3
  // pos: Hook script interaction client
4
- // >>> If updated, update this header and the folder CORTEX.md <<<
4
+ // >>> If updated, update this header and the folder AGENTS.md <<<
5
5
 
6
6
  import http from 'node:http';
7
7
 
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
- // @cortex-hook-version 2026.6.22-2
2
+ // @cortex-hook-version 2026.9.15-2
3
3
  // input: stdin { channel, sessionId, sessionName, trigger, timestampIso } + env CORTEX_HOOK_*
4
4
  // output: stdout — prompt to inject into the closing session (empty stdout = skip)
5
5
  // pos: !new pre-close memory flush hook — recall valuable user and project info from the session, write to corresponding context files
6
- // >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
6
+ // >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
7
7
 
8
8
  import { execSync } from 'child_process';
9
9
 
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- // @cortex-hook-version 2026.6.22-2
2
+ // @cortex-hook-version 2026.9.15-2
3
3
  // input: stdin JSON — Claude Code PostToolUse event or PI hook-bridge payload
4
4
  // output: { matched: [...], hookSpecificOutput: { additionalContext: "..." } }
5
5
  // pos: Read/Grep hook — check if file path matches scoped rules in ~/.cortex/rules/
6
6
  // On match, return rule content for Claude (additionalContext) and PI (content mutation) injection
7
7
  // Session-level dedup: each rule injected at most once per session (on first match)
8
- // >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
8
+ // >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
9
9
 
10
10
  import { readFileSync, readdirSync, statSync, existsSync, mkdirSync, renameSync, writeFileSync } from 'fs';
11
11
  import { join, resolve, dirname } from 'path';
@@ -1,16 +1,16 @@
1
1
  #!/usr/bin/env node
2
- // @cortex-hook-version 2026.8.2
2
+ // @cortex-hook-version 2026.9.15
3
3
  // input: stdin JSON — Claude Code PreToolUse event payload
4
4
  // output: stdout JSON — { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision, permissionDecisionReason }, systemMessage? }
5
5
  // pos: PreToolUse hook — intercepts Edit/Write on size-capped context files and
6
6
  // enforces their caps (limit table below; rules/status-md.md, rules/issues-md.md,
7
- // rules/cortex-md.md): deny writes whose result exceeds the caps, unless the
7
+ // rules/agents-md.md): deny writes whose result exceeds the caps, unless the
8
8
  // write shrinks an already-over-limit file (so cleanup stays possible); warn
9
9
  // when approaching the cap. Guarded files:
10
10
  // context/projects/<p>/STATUS.md — 80 lines / 6KB (state register)
11
11
  // context/projects/<p>/ISSUES.md — 80 lines / 6KB (friction log)
12
- // CORTEX.md anywhere under a context/ tree — 120 lines / 8KB (injected index)
13
- // >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
12
+ // AGENTS.md anywhere under a context/ tree — 120 lines / 8KB (injected index)
13
+ // >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
14
14
 
15
15
  import { readFileSync, existsSync } from 'fs';
16
16
  import { resolve, sep } from 'path';
@@ -61,16 +61,16 @@ const LIMIT_RULES = [
61
61
  ],
62
62
  },
63
63
  {
64
- name: 'CORTEX.md',
65
- ruleFile: 'rules/cortex-md.md',
66
- matches: (parts) => parts[parts.length - 1] === 'CORTEX.md' && parts.includes('context'),
64
+ name: 'AGENTS.md',
65
+ ruleFile: 'rules/agents-md.md',
66
+ matches: (parts) => parts[parts.length - 1] === 'AGENTS.md' && parts.includes('context'),
67
67
  maxLines: 120,
68
68
  maxBytes: 8 * 1024,
69
69
  warnLines: 90,
70
70
  warnBytes: 6656,
71
71
  capLabel: '120 lines AND 8KB',
72
72
  trimAdvice: [
73
- 'CORTEX.md is an injected index (truncated at 9500 chars): it answers "what is here, where to look", not the content itself. Trim before writing:',
73
+ 'AGENTS.md is a directory index loaded into every agent that works here: it answers "what is here, where to look", not the content itself. Trim before writing:',
74
74
  '- collapse atomic directories (experiments/ knowledge/ patterns/ decisions/) to one line each pointing at their index.md,',
75
75
  '- entry summaries already live in the atomic files and their auto-generated index.md — never duplicate them here,',
76
76
  '- keep each index line to one sentence + pointer (<=200 chars).',
@@ -3,9 +3,9 @@
3
3
  // input: stdin thread lifecycle payload, argv identity fallback
4
4
  // output: HookResult for unresolved dispatch task state
5
5
  // pos: Checks task status after a dispatched thread terminates
6
- // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
6
+ // >>> If I am updated, update my header comment and the parent folder's AGENTS.md <<<
7
7
 
8
- import { readFileSync, existsSync, readdirSync } from 'fs';
8
+ import { readFileSync, existsSync } from 'fs';
9
9
  import * as path from 'path';
10
10
  import { homedir } from 'os';
11
11
 
@@ -16,8 +16,6 @@ const PROJECTS_DIR = process.env.CORTEX_PROJECTS_DIR
16
16
  ? path.resolve(process.env.CORTEX_PROJECTS_DIR)
17
17
  : path.join(DATA_DIR, 'context', 'projects');
18
18
 
19
- const CORTEX_RUN_DIR = path.join(DATA_DIR, 'tmp', 'cortex-run');
20
-
21
19
  function noop() {
22
20
  console.log(JSON.stringify({ insertAgent: false }));
23
21
  }
@@ -79,35 +77,6 @@ function findTaskById(content, taskId) {
79
77
  return task;
80
78
  }
81
79
 
82
- /** Find a cortex-run state file that references the given task. */
83
- function findStateFileForTask(project, taskId) {
84
- try {
85
- if (!existsSync(CORTEX_RUN_DIR)) return null;
86
- for (const entry of readdirSync(CORTEX_RUN_DIR, { withFileTypes: true })) {
87
- if (!entry.isDirectory()) continue;
88
- const statePath = path.join(CORTEX_RUN_DIR, entry.name, 'state.json');
89
- if (!existsSync(statePath)) continue;
90
- try {
91
- const state = JSON.parse(readFileSync(statePath, 'utf8'));
92
- if (state.task_project === project && state.task_id === taskId) {
93
- return { runName: entry.name, ...state };
94
- }
95
- } catch {}
96
- }
97
- } catch {}
98
- return null;
99
- }
100
-
101
- /** Check if a PID is still alive. */
102
- function pidAlive(pid) {
103
- try {
104
- process.kill(pid, 0);
105
- return true;
106
- } catch {
107
- return false;
108
- }
109
- }
110
-
111
80
  async function main() {
112
81
  let input = '';
113
82
  for await (const chunk of process.stdin) input += chunk;
@@ -146,27 +115,20 @@ async function main() {
146
115
  // Task is done — nothing to do.
147
116
  if (task.status === 'done') { noop(); return; }
148
117
 
149
- // Task is pending — cortex-run is handling it. No recovery; just verify.
118
+ // Task is pending — something outside this thread owns its completion (a waitpoint signal, an
119
+ // operator). No recovery is automatic; just make the limbo visible to the agent that ran.
150
120
  if (task.status === 'pending') {
151
- const stateFile = findStateFileForTask(project, taskId);
152
- if (!stateFile || stateFile.status === 'failed') {
153
- // cortex-run state file missing or run failed — but per design, do not auto-recover.
154
- // Just report so it's visible.
155
- const targetAgent = ctx.previousAgent;
156
- if (targetAgent) {
157
- const note = !stateFile
158
- ? 'no state file found (cortex-run may not have started)'
159
- : `state file shows status=${stateFile.status} (exit ${stateFile.exit_code})`;
160
- console.log(JSON.stringify({
161
- insertAgent: false,
162
- targetAgent,
163
- prompt: [
164
- `FYI: task [id: ${taskId}] in project "${project}" is still [pending] but cortex-run ${note}.`,
165
- 'Per current policy, pending→done recovery is not automatic. Check manually if needed.',
166
- ].join('\n'),
167
- }));
168
- return;
169
- }
121
+ const targetAgent = ctx.previousAgent;
122
+ if (targetAgent) {
123
+ console.log(JSON.stringify({
124
+ insertAgent: false,
125
+ targetAgent,
126
+ prompt: [
127
+ `FYI: task [id: ${taskId}] in project "${project}" is still [pending] and the thread has finished.`,
128
+ 'Per current policy, pending→done recovery is not automatic. Check manually if needed.',
129
+ ].join('\n'),
130
+ }));
131
+ return;
170
132
  }
171
133
  noop();
172
134
  return;
@@ -180,37 +142,17 @@ async function main() {
180
142
  const targetAgent = ctx.previousAgent;
181
143
  if (!targetAgent) { noop(); return; }
182
144
 
183
- // Check if there's a cortex-run process handling this task
184
- const stateFile = findStateFileForTask(project, taskId);
185
-
186
- if (stateFile && stateFile.status === 'running') {
187
- // cortex-run is running — this is a legitimate pending case.
188
- // Engineer forgot to call cortex-task pending; auto-transition.
189
- console.log(JSON.stringify({
190
- insertAgent: false,
191
- targetAgent,
192
- prompt: [
193
- `Auto-detected: task [id: ${taskId}] in project "${project}" is still claimed,`,
194
- `but a cortex-run process "(${stateFile.runName})" is running for this task (PID ${stateFile.pid}).`,
195
- `The engineer likely forgot to mark the task pending. Call:`,
196
- ` cortex-task pending --project ${project} --task-id ${taskId}`,
197
- ].join('\n'),
198
- }));
199
- return;
200
- }
201
-
202
- // No cortex-run state file — genuine orphan.
203
- // Unclaim and prompt agent to resolve.
145
+ // The thread finished without transitioning the task — prompt the agent to resolve it.
204
146
  console.log(JSON.stringify({
205
147
  insertAgent: false,
206
148
  targetAgent,
207
149
  prompt: [
208
- `Status check: task [id: ${taskId}] in project "${project}" is still marked [claimed] in TASKS.yaml, but the thread has finished. No running cortex-run process found for this task.`,
150
+ `Status check: task [id: ${taskId}] in project "${project}" is still marked [claimed] in TASKS.yaml, but the thread has finished.`,
209
151
  '',
210
152
  'Resolve the task status now — do not leave it in limbo:',
211
153
  `- If done-when conditions are satisfied: cortex-task complete --project ${project} --task-id ${taskId} --note "<what you did>"`,
212
154
  `- If blocked by external reasons: cortex-task block --project ${project} --task-id ${taskId} --reason "<reason>"`,
213
- `- If a cortex-run is still running: cortex-task pending --project ${project} --task-id ${taskId}`,
155
+ `- If something outside this thread still has to finish: cortex-task pending --project ${project} --task-id ${taskId}`,
214
156
  `- If none of the above apply: cortex-task unclaim --project ${project} --task-id ${taskId}`,
215
157
  '',
216
158
  'After updating the task, commit the TASKS.yaml change.',
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- // @cortex-hook-version 2026.6.22-2
2
+ // @cortex-hook-version 2026.9.15-2
3
3
  // input: stdin JSON — Claude Code PreToolUse event payload
4
4
  // output: stdout JSON — { hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision, permissionDecisionReason } }
5
5
  // pos: PreToolUse hook — intercepts Edit/Write on **/TASKS.yaml, checks project lock
6
6
  // allow when current process holds the lock; deny + helpful message otherwise
7
7
  // Owner identity: process.env.CORTEX_EXECUTION_ID ?? manual:<user>:<pid>
8
- // >>> If I am updated, be sure to update my header comment and the CORTEX.md in the same folder <<<
8
+ // >>> If I am updated, be sure to update my header comment and the AGENTS.md in the same folder <<<
9
9
 
10
10
  import { readFileSync, existsSync } from 'fs';
11
11
  import { basename, resolve } from 'path';
@@ -51,7 +51,7 @@ lark-cli auth status
51
51
  ```
52
52
 
53
53
  Notes:
54
- - Cortex runs on **lab2**; install/run there. `lark-cli` stores credentials in the
54
+ - Cortex runs on the **agent-server host**; install/run there. `lark-cli` stores credentials in the
55
55
  OS keychain (falls back to a local file on headless Linux).
56
56
  - `config init` is non-interactive via `--app-id <id> --app-secret-stdin` and refuses
57
57
  only inside OpenClaw/Hermes agent workspaces (Cortex is neither).
@@ -120,12 +120,12 @@ cd <cortex-repo>/agent-server && node --import tsx src/domain/remote/client-boot
120
120
  or place the bundle by hand:
121
121
 
122
122
  ```bash
123
- # Build from source (dev) — produces dist/client.mjs + dist/cortex-run-watcher.mjs
123
+ # Build from source (dev) — produces dist/client.mjs (+ a cortex-run-watcher.mjs compatibility stub)
124
124
  cd <cortex-repo>/client && npm run bundle
125
125
 
126
126
  # Ship to the device
127
127
  ssh user@host "mkdir -p ~/.cortex/client/current"
128
- scp dist/client.mjs dist/cortex-run-watcher.mjs user@host:.cortex/client/current/
128
+ scp dist/client.mjs dist/cortex-run-watcher.mjs user@host:.cortex/client/current/ # both files: the update protocol checks names
129
129
  ```
130
130
 
131
131
  ### 3. Write the config
@@ -34,7 +34,7 @@ Inspect the project's code and resources. If multiple machines host parts of the
34
34
 
35
35
  Create the project directory and files under `context/projects/<project-name>/`:
36
36
 
37
- ### CORTEX.md (required) — Project index
37
+ ### AGENTS.md (required) — Project index
38
38
 
39
39
  This is the entry point for future sessions. Must include:
40
40
  - One-line project description
@@ -129,13 +129,13 @@ Skip for projects already in late-stage delivery. Create only when the project h
129
129
 
130
130
  ## Step 3: Update Indexes
131
131
 
132
- 1. Add the project to `context/projects/CORTEX.md` project list table
132
+ 1. Add the project to `context/projects/AGENTS.md` project list table
133
133
  2. Add the project to `context/OVERVIEW.md`
134
134
 
135
135
  ## Step 4: Commit
136
136
 
137
137
  ```
138
- git add context/projects/<project-name>/ context/projects/CORTEX.md context/OVERVIEW.md
138
+ git add context/projects/<project-name>/ context/projects/AGENTS.md context/OVERVIEW.md
139
139
  git commit -m "project-init: add <project-name> (<brief description>)"
140
140
  ```
141
141
 
@@ -150,7 +150,7 @@ Output a structured summary:
150
150
  ## Principles
151
151
 
152
152
  - **Read the README and core docs first** — understanding the project is prerequisite to useful context files
153
- - CORTEX.md is the most important file — it's the entry point for all future sessions
153
+ - AGENTS.md is the most important file — it's the entry point for all future sessions
154
154
  - Location map must be exhaustive — every relevant path on every machine
155
155
  - Auto-generated content is clearly marked — the user owns the final version
156
156
  - mission.md is a draft until the user confirms
@@ -146,7 +146,7 @@ The following mutation commands **must** hold the project lock first, otherwise
146
146
  - `decompose` — Decompose into subtasks
147
147
  - `assign-ids` — Assign task IDs
148
148
 
149
- Lifecycle commands (claim / complete / block / unblock / pause / resume / approval series / stop, etc.) **do not need** a lock — they are called routinely by the dispatcher and cortex-run on automated paths.
149
+ Lifecycle commands (claim / complete / block / unblock / pause / resume / approval series / stop, etc.) **do not need** a lock — they are called routinely by the dispatcher on automated paths.
150
150
 
151
151
  ### Lock semantics
152
152