@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.
Files changed (503) hide show
  1. package/defaults/.claude/settings.json +13 -0
  2. package/defaults/CORTEX.md +15 -0
  3. package/defaults/config/budget.json +4 -0
  4. package/defaults/config/session-hooks.json +7 -0
  5. package/defaults/config/thread-templates.json +528 -0
  6. package/defaults/context/CORTEX.md +40 -0
  7. package/defaults/context/decisions/DR-0012.md +54 -0
  8. package/defaults/context/ideas/CORTEX.md +10 -0
  9. package/defaults/context/projects/CORTEX.md +25 -0
  10. package/defaults/context/scans/CORTEX.md +13 -0
  11. package/defaults/context/user/CORTEX.md +21 -0
  12. package/defaults/data/schedules.json +52 -0
  13. package/defaults/gitignore +44 -0
  14. package/defaults/hooks/ask-user-question-hook.mjs +66 -0
  15. package/defaults/hooks/cortex-md-injector.mjs +237 -0
  16. package/defaults/hooks/exit-plan-mode-hook.mjs +84 -0
  17. package/defaults/hooks/memory-ref-tracker.mjs +154 -0
  18. package/defaults/hooks/new-session-hook.mjs +83 -0
  19. package/defaults/hooks/post-task-hook.mjs +63 -0
  20. package/defaults/hooks/rules-loader.mjs +212 -0
  21. package/defaults/hooks/sensitive-file-edit.mjs +84 -0
  22. package/defaults/hooks/session-activity-tracker.mjs +254 -0
  23. package/defaults/hooks/task-status-check.mjs +218 -0
  24. package/defaults/hooks/tasks-yaml-guard.mjs +230 -0
  25. package/defaults/plugins/cortex-coder/.claude-plugin/plugin.json +5 -0
  26. package/defaults/plugins/cortex-coder/skills/cli-standards/SKILL.md +208 -0
  27. package/defaults/plugins/cortex-coder/skills/code-standards/SKILL.md +146 -0
  28. package/defaults/plugins/cortex-coder/skills/develop/SKILL.md +164 -0
  29. package/defaults/plugins/cortex-common/.claude-plugin/plugin.json +5 -0
  30. package/defaults/plugins/cortex-common/skills/compound/SKILL.md +349 -0
  31. package/defaults/plugins/cortex-common/skills/compound-simple/SKILL.md +104 -0
  32. package/defaults/plugins/cortex-common/skills/critique/SKILL.md +88 -0
  33. package/defaults/plugins/cortex-common/skills/debug-campaign/SKILL.md +508 -0
  34. package/defaults/plugins/cortex-common/skills/diagnose/SKILL.md +169 -0
  35. package/defaults/plugins/cortex-common/skills/postmortem/SKILL.md +135 -0
  36. package/defaults/plugins/cortex-common/skills/solution-design/SKILL.md +183 -0
  37. package/defaults/plugins/cortex-common/skills/synthesize/SKILL.md +120 -0
  38. package/defaults/plugins/cortex-stage-gate/.claude-plugin/plugin.json +5 -0
  39. package/defaults/plugins/cortex-stage-gate/skills/need-approval/SKILL.md +89 -0
  40. package/defaults/plugins/cortex-stage-gate/skills/reorient/SKILL.md +163 -0
  41. package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +425 -0
  42. package/defaults/plugins/cortex-system/.claude-plugin/plugin.json +5 -0
  43. package/defaults/plugins/cortex-system/skills/approval/SKILL.md +84 -0
  44. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +199 -0
  45. package/defaults/plugins/cortex-system/skills/deep-retrospective/CORTEX.md +8 -0
  46. package/defaults/plugins/cortex-system/skills/deep-retrospective/SKILL.md +201 -0
  47. package/defaults/plugins/cortex-system/skills/deep-retrospective/scripts/CORTEX.md +8 -0
  48. package/defaults/plugins/cortex-system/skills/deep-retrospective/scripts/extract_session.py +165 -0
  49. package/defaults/plugins/cortex-system/skills/deep-retrospective/scripts/scan_logs.py +402 -0
  50. package/defaults/plugins/cortex-system/skills/evolve/SKILL.md +115 -0
  51. package/defaults/plugins/cortex-system/skills/feedback/SKILL.md +262 -0
  52. package/defaults/plugins/cortex-system/skills/gravity/SKILL.md +125 -0
  53. package/defaults/plugins/cortex-system/skills/orient/SKILL.md +310 -0
  54. package/defaults/plugins/cortex-system/skills/orient-project/SKILL.md +85 -0
  55. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +167 -0
  56. package/defaults/plugins/cortex-system/skills/refresh-skills/SKILL.md +153 -0
  57. package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +209 -0
  58. package/defaults/plugins/cortex-system/skills/thread/SKILL.md +478 -0
  59. package/defaults/plugins/cortex-system/skills/user-learn/SKILL.md +95 -0
  60. package/defaults/prompts/directives/coder-reviewer.md +106 -0
  61. package/defaults/prompts/directives/coder.md +90 -0
  62. package/defaults/prompts/directives/director.md +97 -0
  63. package/defaults/prompts/directives/doc-reviewer.md +93 -0
  64. package/defaults/prompts/directives/doc-writer.md +85 -0
  65. package/defaults/prompts/directives/executor-reviewer.md +96 -0
  66. package/defaults/prompts/directives/executor.md +85 -0
  67. package/defaults/prompts/directives/milestone-executor.md +119 -0
  68. package/defaults/prompts/directives/milestone-reviewer.md +108 -0
  69. package/defaults/prompts/directives/plan-executor.md +121 -0
  70. package/defaults/prompts/directives/plan-reviewer.md +99 -0
  71. package/defaults/prompts/systemPrompts/coder.md +64 -0
  72. package/defaults/prompts/systemPrompts/direct.md +92 -0
  73. package/defaults/prompts/systemPrompts/web-opus-4-6.md +68 -0
  74. package/defaults/prompts/systemPrompts/web-sonnet-4-6.md +76 -0
  75. package/defaults/prompts/systemPrompts/web.md +50 -0
  76. package/defaults/prompts/systemPrompts/worker.md +67 -0
  77. package/defaults/rules/correction-propagation.md +31 -0
  78. package/defaults/rules/decision-records.md +49 -0
  79. package/defaults/rules/experiment-format.md +165 -0
  80. package/defaults/rules/issues-md.md +37 -0
  81. package/defaults/rules/meta-conventions.md +45 -0
  82. package/defaults/rules/mission-md.md +47 -0
  83. package/defaults/rules/overview-md.md +41 -0
  84. package/defaults/rules/roadmap-md.md +55 -0
  85. package/defaults/rules/status-md.md +49 -0
  86. package/defaults/rules/task-system.md +53 -0
  87. package/dist/agent-adapter/capabilities.d.ts +12 -0
  88. package/dist/agent-adapter/capabilities.js +52 -0
  89. package/dist/agent-adapter/claude/adapter-tui.d.ts +140 -0
  90. package/dist/agent-adapter/claude/adapter-tui.js +422 -0
  91. package/dist/agent-adapter/claude/adapter.d.ts +85 -0
  92. package/dist/agent-adapter/claude/adapter.js +771 -0
  93. package/dist/agent-adapter/claude/cost-from-usage.d.ts +62 -0
  94. package/dist/agent-adapter/claude/cost-from-usage.js +97 -0
  95. package/dist/agent-adapter/claude/defaults.d.ts +30 -0
  96. package/dist/agent-adapter/claude/defaults.js +49 -0
  97. package/dist/agent-adapter/claude/event-parser.d.ts +28 -0
  98. package/dist/agent-adapter/claude/event-parser.js +173 -0
  99. package/dist/agent-adapter/claude/hooks-builder.d.ts +36 -0
  100. package/dist/agent-adapter/claude/hooks-builder.js +57 -0
  101. package/dist/agent-adapter/claude/jsonl-tail.d.ts +68 -0
  102. package/dist/agent-adapter/claude/jsonl-tail.js +344 -0
  103. package/dist/agent-adapter/claude/spawn-args.d.ts +38 -0
  104. package/dist/agent-adapter/claude/spawn-args.js +83 -0
  105. package/dist/agent-adapter/claude/tmux-control.d.ts +69 -0
  106. package/dist/agent-adapter/claude/tmux-control.js +127 -0
  107. package/dist/agent-adapter/claude/tool-summarizers.d.ts +2 -0
  108. package/dist/agent-adapter/claude/tool-summarizers.js +24 -0
  109. package/dist/agent-adapter/codex/adapter.d.ts +42 -0
  110. package/dist/agent-adapter/codex/adapter.js +916 -0
  111. package/dist/agent-adapter/codex/event-parser.d.ts +17 -0
  112. package/dist/agent-adapter/codex/event-parser.js +41 -0
  113. package/dist/agent-adapter/codex/spawn-args.d.ts +6 -0
  114. package/dist/agent-adapter/codex/spawn-args.js +30 -0
  115. package/dist/agent-adapter/index.d.ts +8 -0
  116. package/dist/agent-adapter/index.js +33 -0
  117. package/dist/agent-adapter/normalize/event-stream.d.ts +6 -0
  118. package/dist/agent-adapter/normalize/event-stream.js +47 -0
  119. package/dist/agent-adapter/normalize/event-types.d.ts +58 -0
  120. package/dist/agent-adapter/normalize/event-types.js +5 -0
  121. package/dist/agent-adapter/normalize/hooks.d.ts +26 -0
  122. package/dist/agent-adapter/normalize/hooks.js +5 -0
  123. package/dist/agent-adapter/normalize/prompt-builder.d.ts +6 -0
  124. package/dist/agent-adapter/normalize/prompt-builder.js +23 -0
  125. package/dist/agent-adapter/normalize/tool-names.d.ts +6 -0
  126. package/dist/agent-adapter/normalize/tool-names.js +73 -0
  127. package/dist/agent-adapter/pi/adapter.d.ts +60 -0
  128. package/dist/agent-adapter/pi/adapter.js +626 -0
  129. package/dist/agent-adapter/pi/agent-dir.d.ts +11 -0
  130. package/dist/agent-adapter/pi/agent-dir.js +34 -0
  131. package/dist/agent-adapter/pi/event-parser.d.ts +26 -0
  132. package/dist/agent-adapter/pi/event-parser.js +313 -0
  133. package/dist/agent-adapter/pi/framing.d.ts +6 -0
  134. package/dist/agent-adapter/pi/framing.js +35 -0
  135. package/dist/agent-adapter/pi/hook-bridge.d.ts +59 -0
  136. package/dist/agent-adapter/pi/hook-bridge.js +233 -0
  137. package/dist/agent-adapter/pi/mcp-bridge.d.ts +26 -0
  138. package/dist/agent-adapter/pi/mcp-bridge.js +140 -0
  139. package/dist/agent-adapter/pi/pi-ext-types.d.ts +90 -0
  140. package/dist/agent-adapter/pi/pi-ext-types.js +5 -0
  141. package/dist/agent-adapter/pi/spawn-args.d.ts +20 -0
  142. package/dist/agent-adapter/pi/spawn-args.js +54 -0
  143. package/dist/agent-adapter/pi/tool-shims.d.ts +2 -0
  144. package/dist/agent-adapter/pi/tool-shims.js +181 -0
  145. package/dist/agent-adapter/types.d.ts +94 -0
  146. package/dist/agent-adapter/types.js +5 -0
  147. package/dist/core/async-mutex.d.ts +6 -0
  148. package/dist/core/async-mutex.js +36 -0
  149. package/dist/core/cli-utils.d.ts +37 -0
  150. package/dist/core/cli-utils.js +69 -0
  151. package/dist/core/config-generator.d.ts +9 -0
  152. package/dist/core/config-generator.js +58 -0
  153. package/dist/core/gateway-generator.d.ts +46 -0
  154. package/dist/core/gateway-generator.js +336 -0
  155. package/dist/core/log.d.ts +7 -0
  156. package/dist/core/log.js +103 -0
  157. package/dist/core/paths.d.ts +32 -0
  158. package/dist/core/paths.js +49 -0
  159. package/dist/core/profile-generator.d.ts +65 -0
  160. package/dist/core/profile-generator.js +310 -0
  161. package/dist/core/running-executions.d.ts +88 -0
  162. package/dist/core/running-executions.js +186 -0
  163. package/dist/core/status-format.d.ts +18 -0
  164. package/dist/core/status-format.js +31 -0
  165. package/dist/core/task-parser.d.ts +69 -0
  166. package/dist/core/task-parser.js +423 -0
  167. package/dist/core/types/agent-types.d.ts +31 -0
  168. package/dist/core/types/agent-types.js +5 -0
  169. package/dist/core/types/thread-types.d.ts +261 -0
  170. package/dist/core/types/thread-types.js +5 -0
  171. package/dist/core/utils.d.ts +29 -0
  172. package/dist/core/utils.js +98 -0
  173. package/dist/core/version.d.ts +3 -0
  174. package/dist/core/version.js +12 -0
  175. package/dist/domain/agents/config.d.ts +58 -0
  176. package/dist/domain/agents/config.js +313 -0
  177. package/dist/domain/agents/facade.d.ts +52 -0
  178. package/dist/domain/agents/facade.js +264 -0
  179. package/dist/domain/agents/index.d.ts +2 -0
  180. package/dist/domain/agents/index.js +4 -0
  181. package/dist/domain/agents/profile-manager.d.ts +54 -0
  182. package/dist/domain/agents/profile-manager.js +161 -0
  183. package/dist/domain/costs/codex-event-format.d.ts +4 -0
  184. package/dist/domain/costs/codex-event-format.js +66 -0
  185. package/dist/domain/costs/codex-usage-monitor.d.ts +7 -0
  186. package/dist/domain/costs/codex-usage-monitor.js +72 -0
  187. package/dist/domain/costs/cost-tracker.d.ts +115 -0
  188. package/dist/domain/costs/cost-tracker.js +327 -0
  189. package/dist/domain/costs/gateway-manager.d.ts +6 -0
  190. package/dist/domain/costs/gateway-manager.js +228 -0
  191. package/dist/domain/costs/rate-limit-parser.d.ts +11 -0
  192. package/dist/domain/costs/rate-limit-parser.js +87 -0
  193. package/dist/domain/costs/rate-limit-throttle.d.ts +32 -0
  194. package/dist/domain/costs/rate-limit-throttle.js +129 -0
  195. package/dist/domain/executions/registry.d.ts +20 -0
  196. package/dist/domain/executions/registry.js +124 -0
  197. package/dist/domain/mcp/core-server.d.ts +2 -0
  198. package/dist/domain/mcp/core-server.js +34 -0
  199. package/dist/domain/mcp/server.d.ts +3 -0
  200. package/dist/domain/mcp/server.js +78 -0
  201. package/dist/domain/mcp/tools/context.d.ts +23 -0
  202. package/dist/domain/mcp/tools/context.js +51 -0
  203. package/dist/domain/mcp/tools/cortex-md.d.ts +17 -0
  204. package/dist/domain/mcp/tools/cortex-md.js +36 -0
  205. package/dist/domain/mcp/tools/cost.d.ts +2 -0
  206. package/dist/domain/mcp/tools/cost.js +54 -0
  207. package/dist/domain/mcp/tools/executions.d.ts +2 -0
  208. package/dist/domain/mcp/tools/executions.js +94 -0
  209. package/dist/domain/mcp/tools/schedule.d.ts +23 -0
  210. package/dist/domain/mcp/tools/schedule.js +245 -0
  211. package/dist/domain/mcp/tools/slack.d.ts +21 -0
  212. package/dist/domain/mcp/tools/slack.js +124 -0
  213. package/dist/domain/mcp/tools/task-ops.d.ts +2 -0
  214. package/dist/domain/mcp/tools/task-ops.js +509 -0
  215. package/dist/domain/mcp/tools/tui-ask.d.ts +31 -0
  216. package/dist/domain/mcp/tools/tui-ask.js +108 -0
  217. package/dist/domain/mcp/tools/tui-plan.d.ts +28 -0
  218. package/dist/domain/mcp/tools/tui-plan.js +118 -0
  219. package/dist/domain/mcp/tui-server.d.ts +2 -0
  220. package/dist/domain/mcp/tui-server.js +69 -0
  221. package/dist/domain/memory/consolidate.d.ts +55 -0
  222. package/dist/domain/memory/consolidate.js +471 -0
  223. package/dist/domain/memory/cortex-md-injector.d.ts +30 -0
  224. package/dist/domain/memory/cortex-md-injector.js +123 -0
  225. package/dist/domain/memory/cortex-md-scanner.d.ts +9 -0
  226. package/dist/domain/memory/cortex-md-scanner.js +67 -0
  227. package/dist/domain/memory/index-regen.d.ts +19 -0
  228. package/dist/domain/memory/index-regen.js +398 -0
  229. package/dist/domain/memory/rules-loader.d.ts +27 -0
  230. package/dist/domain/memory/rules-loader.js +97 -0
  231. package/dist/domain/memory/skill-scanner.d.ts +5 -0
  232. package/dist/domain/memory/skill-scanner.js +132 -0
  233. package/dist/domain/memory/user-context.d.ts +5 -0
  234. package/dist/domain/memory/user-context.js +34 -0
  235. package/dist/domain/memory/watcher.d.ts +2 -0
  236. package/dist/domain/memory/watcher.js +81 -0
  237. package/dist/domain/monitor/disk-monitor.d.ts +20 -0
  238. package/dist/domain/monitor/disk-monitor.js +97 -0
  239. package/dist/domain/monitor/gpu-monitor.d.ts +26 -0
  240. package/dist/domain/monitor/gpu-monitor.js +135 -0
  241. package/dist/domain/remote/client-bootstrap.d.ts +1 -0
  242. package/dist/domain/remote/client-bootstrap.js +139 -0
  243. package/dist/domain/remote/client-hot-reload.d.ts +18 -0
  244. package/dist/domain/remote/client-hot-reload.js +142 -0
  245. package/dist/domain/remote/client-manager.d.ts +50 -0
  246. package/dist/domain/remote/client-manager.js +452 -0
  247. package/dist/domain/remote/cortex-client.d.ts +1 -0
  248. package/dist/domain/remote/cortex-client.js +704 -0
  249. package/dist/domain/scheduling/job-registry.d.ts +31 -0
  250. package/dist/domain/scheduling/job-registry.js +34 -0
  251. package/dist/domain/scheduling/jobs/_shared.d.ts +14 -0
  252. package/dist/domain/scheduling/jobs/_shared.js +45 -0
  253. package/dist/domain/scheduling/jobs/memory-index-regen.d.ts +1 -0
  254. package/dist/domain/scheduling/jobs/memory-index-regen.js +16 -0
  255. package/dist/domain/scheduling/jobs/scheduled-task.d.ts +11 -0
  256. package/dist/domain/scheduling/jobs/scheduled-task.js +186 -0
  257. package/dist/domain/scheduling/jobs/target-dispatch.d.ts +41 -0
  258. package/dist/domain/scheduling/jobs/target-dispatch.js +48 -0
  259. package/dist/domain/scheduling/jobs/task-archive.d.ts +1 -0
  260. package/dist/domain/scheduling/jobs/task-archive.js +19 -0
  261. package/dist/domain/scheduling/jobs/task-dispatch.d.ts +12 -0
  262. package/dist/domain/scheduling/jobs/task-dispatch.js +214 -0
  263. package/dist/domain/scheduling/runner.d.ts +13 -0
  264. package/dist/domain/scheduling/runner.js +24 -0
  265. package/dist/domain/scheduling/schedule-cli.d.ts +16 -0
  266. package/dist/domain/scheduling/schedule-cli.js +268 -0
  267. package/dist/domain/scheduling/schedule-command.d.ts +4 -0
  268. package/dist/domain/scheduling/schedule-command.js +274 -0
  269. package/dist/domain/scheduling/scheduler.d.ts +86 -0
  270. package/dist/domain/scheduling/scheduler.js +544 -0
  271. package/dist/domain/sessions/session-backup.d.ts +49 -0
  272. package/dist/domain/sessions/session-backup.js +217 -0
  273. package/dist/domain/sessions/session-hooks.d.ts +103 -0
  274. package/dist/domain/sessions/session-hooks.js +311 -0
  275. package/dist/domain/sessions/session-registry.d.ts +21 -0
  276. package/dist/domain/sessions/session-registry.js +31 -0
  277. package/dist/domain/sessions/session.d.ts +3 -0
  278. package/dist/domain/sessions/session.js +14 -0
  279. package/dist/domain/tasks/archiver.d.ts +9 -0
  280. package/dist/domain/tasks/archiver.js +123 -0
  281. package/dist/domain/tasks/dispatch-utils.d.ts +37 -0
  282. package/dist/domain/tasks/dispatch-utils.js +143 -0
  283. package/dist/domain/tasks/dispatcher.d.ts +48 -0
  284. package/dist/domain/tasks/dispatcher.js +285 -0
  285. package/dist/domain/tasks/lint.d.ts +12 -0
  286. package/dist/domain/tasks/lint.js +102 -0
  287. package/dist/domain/tasks/mutator.d.ts +21 -0
  288. package/dist/domain/tasks/mutator.js +208 -0
  289. package/dist/domain/tasks/parser.d.ts +1 -0
  290. package/dist/domain/tasks/parser.js +6 -0
  291. package/dist/domain/tasks/pending-tracker.d.ts +67 -0
  292. package/dist/domain/tasks/pending-tracker.js +163 -0
  293. package/dist/domain/tasks/recommendation/extractor.d.ts +12 -0
  294. package/dist/domain/tasks/recommendation/extractor.js +563 -0
  295. package/dist/domain/tasks/recommendation/patterns.d.ts +11 -0
  296. package/dist/domain/tasks/recommendation/patterns.js +99 -0
  297. package/dist/domain/tasks/recommendation/types.d.ts +67 -0
  298. package/dist/domain/tasks/recommendation/types.js +5 -0
  299. package/dist/domain/tasks/store.d.ts +1 -0
  300. package/dist/domain/tasks/store.js +3 -0
  301. package/dist/domain/tasks/system/cortex-run.d.ts +24 -0
  302. package/dist/domain/tasks/system/cortex-run.js +342 -0
  303. package/dist/domain/tasks/system/task-cli.d.ts +49 -0
  304. package/dist/domain/tasks/system/task-cli.js +664 -0
  305. package/dist/domain/tasks/system/task-completion.d.ts +22 -0
  306. package/dist/domain/tasks/system/task-completion.js +89 -0
  307. package/dist/domain/tasks/system/task-id-utils.d.ts +24 -0
  308. package/dist/domain/tasks/system/task-id-utils.js +84 -0
  309. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +34 -0
  310. package/dist/domain/tasks/system/task-lifecycle-edit.js +208 -0
  311. package/dist/domain/tasks/system/task-lock.d.ts +25 -0
  312. package/dist/domain/tasks/system/task-lock.js +139 -0
  313. package/dist/domain/tasks/system/task-mutations.d.ts +31 -0
  314. package/dist/domain/tasks/system/task-mutations.js +110 -0
  315. package/dist/domain/tasks/system/task-process.d.ts +37 -0
  316. package/dist/domain/tasks/system/task-process.js +119 -0
  317. package/dist/domain/tasks/system/task-state.d.ts +70 -0
  318. package/dist/domain/tasks/system/task-state.js +176 -0
  319. package/dist/domain/threads/artifact-io.d.ts +18 -0
  320. package/dist/domain/threads/artifact-io.js +182 -0
  321. package/dist/domain/threads/auto-thread.d.ts +3 -0
  322. package/dist/domain/threads/auto-thread.js +19 -0
  323. package/dist/domain/threads/hook-runner.d.ts +4 -0
  324. package/dist/domain/threads/hook-runner.js +250 -0
  325. package/dist/domain/threads/index.d.ts +5 -0
  326. package/dist/domain/threads/index.js +7 -0
  327. package/dist/domain/threads/prompt-builder.d.ts +25 -0
  328. package/dist/domain/threads/prompt-builder.js +176 -0
  329. package/dist/domain/threads/runner.d.ts +83 -0
  330. package/dist/domain/threads/runner.js +434 -0
  331. package/dist/domain/threads/state-machine.d.ts +61 -0
  332. package/dist/domain/threads/state-machine.js +440 -0
  333. package/dist/domain/threads/template-loader.d.ts +20 -0
  334. package/dist/domain/threads/template-loader.js +189 -0
  335. package/dist/domain/threads/template-resolver.d.ts +1 -0
  336. package/dist/domain/threads/template-resolver.js +95 -0
  337. package/dist/domain/threads/utils.d.ts +19 -0
  338. package/dist/domain/threads/utils.js +49 -0
  339. package/dist/entry/app.d.ts +1 -0
  340. package/dist/entry/app.js +234 -0
  341. package/dist/entry/cli.d.ts +12 -0
  342. package/dist/entry/cli.js +254 -0
  343. package/dist/entry/daemon.d.ts +11 -0
  344. package/dist/entry/daemon.js +521 -0
  345. package/dist/entry/init.d.ts +93 -0
  346. package/dist/entry/init.js +1299 -0
  347. package/dist/entry/startup-helpers.d.ts +2 -0
  348. package/dist/entry/startup-helpers.js +56 -0
  349. package/dist/entry/startup-notify.d.ts +10 -0
  350. package/dist/entry/startup-notify.js +20 -0
  351. package/dist/events/event-bus.d.ts +42 -0
  352. package/dist/events/event-bus.js +84 -0
  353. package/dist/events/event-logger.d.ts +12 -0
  354. package/dist/events/event-logger.js +135 -0
  355. package/dist/events/event-replay.d.ts +1 -0
  356. package/dist/events/event-replay.js +51 -0
  357. package/dist/events/event-types.d.ts +145 -0
  358. package/dist/events/event-types.js +5 -0
  359. package/dist/events/index.d.ts +5 -0
  360. package/dist/events/index.js +6 -0
  361. package/dist/hooks/ask-user-question-hook.mjs +66 -0
  362. package/dist/hooks/cortex-md-injector.mjs +237 -0
  363. package/dist/hooks/exit-plan-mode-hook.mjs +84 -0
  364. package/dist/hooks/memory-ref-tracker.mjs +154 -0
  365. package/dist/hooks/new-session-hook.mjs +83 -0
  366. package/dist/hooks/post-task-hook.mjs +63 -0
  367. package/dist/hooks/rules-loader.mjs +212 -0
  368. package/dist/hooks/sensitive-file-edit.mjs +84 -0
  369. package/dist/hooks/session-activity-tracker.mjs +254 -0
  370. package/dist/hooks/task-status-check.mjs +218 -0
  371. package/dist/hooks/tasks-yaml-guard.mjs +230 -0
  372. package/dist/orchestration/agent-runner.d.ts +72 -0
  373. package/dist/orchestration/agent-runner.js +289 -0
  374. package/dist/orchestration/busy-tracker.d.ts +12 -0
  375. package/dist/orchestration/busy-tracker.js +35 -0
  376. package/dist/orchestration/channel-queue.d.ts +18 -0
  377. package/dist/orchestration/channel-queue.js +32 -0
  378. package/dist/orchestration/dispatch-reconciler.d.ts +1 -0
  379. package/dist/orchestration/dispatch-reconciler.js +16 -0
  380. package/dist/orchestration/durable-helpers.d.ts +4 -0
  381. package/dist/orchestration/durable-helpers.js +42 -0
  382. package/dist/orchestration/interactions/ask-user-question.d.ts +32 -0
  383. package/dist/orchestration/interactions/ask-user-question.js +182 -0
  384. package/dist/orchestration/interactions/command-action-router.d.ts +47 -0
  385. package/dist/orchestration/interactions/command-action-router.js +91 -0
  386. package/dist/orchestration/interactions/interaction-handlers.d.ts +5 -0
  387. package/dist/orchestration/interactions/interaction-handlers.js +279 -0
  388. package/dist/orchestration/interactions/plan-approvals.d.ts +47 -0
  389. package/dist/orchestration/interactions/plan-approvals.js +77 -0
  390. package/dist/orchestration/interactions/plan-handler.d.ts +6 -0
  391. package/dist/orchestration/interactions/plan-handler.js +12 -0
  392. package/dist/orchestration/lifecycle.d.ts +50 -0
  393. package/dist/orchestration/lifecycle.js +308 -0
  394. package/dist/orchestration/orchestrator.d.ts +29 -0
  395. package/dist/orchestration/orchestrator.js +25 -0
  396. package/dist/orchestration/routing/commands/cancel.d.ts +10 -0
  397. package/dist/orchestration/routing/commands/cancel.js +136 -0
  398. package/dist/orchestration/routing/commands/channel.d.ts +11 -0
  399. package/dist/orchestration/routing/commands/channel.js +219 -0
  400. package/dist/orchestration/routing/commands/command-context.d.ts +29 -0
  401. package/dist/orchestration/routing/commands/command-context.js +4 -0
  402. package/dist/orchestration/routing/commands/cost.d.ts +3 -0
  403. package/dist/orchestration/routing/commands/cost.js +22 -0
  404. package/dist/orchestration/routing/commands/device.d.ts +6 -0
  405. package/dist/orchestration/routing/commands/device.js +83 -0
  406. package/dist/orchestration/routing/commands/dispatch.d.ts +2 -0
  407. package/dist/orchestration/routing/commands/dispatch.js +49 -0
  408. package/dist/orchestration/routing/commands/index.d.ts +15 -0
  409. package/dist/orchestration/routing/commands/index.js +130 -0
  410. package/dist/orchestration/routing/commands/mode.d.ts +13 -0
  411. package/dist/orchestration/routing/commands/mode.js +290 -0
  412. package/dist/orchestration/routing/commands/nvtop.d.ts +3 -0
  413. package/dist/orchestration/routing/commands/nvtop.js +103 -0
  414. package/dist/orchestration/routing/commands/orient.d.ts +2 -0
  415. package/dist/orchestration/routing/commands/orient.js +3 -0
  416. package/dist/orchestration/routing/commands/schedule.d.ts +4 -0
  417. package/dist/orchestration/routing/commands/schedule.js +132 -0
  418. package/dist/orchestration/routing/commands/sendfile.d.ts +2 -0
  419. package/dist/orchestration/routing/commands/sendfile.js +92 -0
  420. package/dist/orchestration/routing/commands/session.d.ts +9 -0
  421. package/dist/orchestration/routing/commands/session.js +153 -0
  422. package/dist/orchestration/routing/commands/status.d.ts +7 -0
  423. package/dist/orchestration/routing/commands/status.js +180 -0
  424. package/dist/orchestration/routing/commands/tail.d.ts +2 -0
  425. package/dist/orchestration/routing/commands/tail.js +73 -0
  426. package/dist/orchestration/routing/commands/task.d.ts +6 -0
  427. package/dist/orchestration/routing/commands/task.js +142 -0
  428. package/dist/orchestration/routing/commands/thread-handlers.d.ts +2 -0
  429. package/dist/orchestration/routing/commands/thread-handlers.js +138 -0
  430. package/dist/orchestration/routing/commands/thread.d.ts +2 -0
  431. package/dist/orchestration/routing/commands/thread.js +2 -0
  432. package/dist/orchestration/routing/edit-handler.d.ts +24 -0
  433. package/dist/orchestration/routing/edit-handler.js +161 -0
  434. package/dist/orchestration/routing/file-handler.d.ts +6 -0
  435. package/dist/orchestration/routing/file-handler.js +23 -0
  436. package/dist/orchestration/routing/hook-bridge-subscribers.d.ts +4 -0
  437. package/dist/orchestration/routing/hook-bridge-subscribers.js +79 -0
  438. package/dist/orchestration/routing/hook-bridge.d.ts +30 -0
  439. package/dist/orchestration/routing/hook-bridge.js +112 -0
  440. package/dist/orchestration/routing/message-router.d.ts +6 -0
  441. package/dist/orchestration/routing/message-router.js +70 -0
  442. package/dist/orchestration/routing/webhook.d.ts +10 -0
  443. package/dist/orchestration/routing/webhook.js +239 -0
  444. package/dist/orchestration/status-helpers.d.ts +66 -0
  445. package/dist/orchestration/status-helpers.js +222 -0
  446. package/dist/orchestration/superseded-edits.d.ts +22 -0
  447. package/dist/orchestration/superseded-edits.js +31 -0
  448. package/dist/orchestration/thread-executor.d.ts +31 -0
  449. package/dist/orchestration/thread-executor.js +234 -0
  450. package/dist/platform/adapter.d.ts +28 -0
  451. package/dist/platform/adapter.js +5 -0
  452. package/dist/platform/adapters/feishu.d.ts +66 -0
  453. package/dist/platform/adapters/feishu.js +558 -0
  454. package/dist/platform/adapters/index.d.ts +16 -0
  455. package/dist/platform/adapters/index.js +65 -0
  456. package/dist/platform/adapters/slack.d.ts +90 -0
  457. package/dist/platform/adapters/slack.js +630 -0
  458. package/dist/platform/index.d.ts +12 -0
  459. package/dist/platform/index.js +10 -0
  460. package/dist/platform/interactive-builder.d.ts +27 -0
  461. package/dist/platform/interactive-builder.js +120 -0
  462. package/dist/platform/testing.d.ts +100 -0
  463. package/dist/platform/testing.js +190 -0
  464. package/dist/platform/tool-trace.d.ts +33 -0
  465. package/dist/platform/tool-trace.js +165 -0
  466. package/dist/platform/types.d.ts +176 -0
  467. package/dist/platform/types.js +5 -0
  468. package/dist/platform/utils/rate-limiter.d.ts +92 -0
  469. package/dist/platform/utils/rate-limiter.js +213 -0
  470. package/dist/platform/virtual-message.d.ts +68 -0
  471. package/dist/platform/virtual-message.js +464 -0
  472. package/dist/store/atomic-write.d.ts +6 -0
  473. package/dist/store/atomic-write.js +18 -0
  474. package/dist/store/channel-repo.d.ts +21 -0
  475. package/dist/store/channel-repo.js +55 -0
  476. package/dist/store/conversation-ledger-repo.d.ts +86 -0
  477. package/dist/store/conversation-ledger-repo.js +220 -0
  478. package/dist/store/cost-repo.d.ts +57 -0
  479. package/dist/store/cost-repo.js +135 -0
  480. package/dist/store/execution-repo.d.ts +172 -0
  481. package/dist/store/execution-repo.js +343 -0
  482. package/dist/store/in-memory-repository.d.ts +14 -0
  483. package/dist/store/in-memory-repository.js +31 -0
  484. package/dist/store/json-repository.d.ts +51 -0
  485. package/dist/store/json-repository.js +118 -0
  486. package/dist/store/outbound-queue.d.ts +65 -0
  487. package/dist/store/outbound-queue.js +269 -0
  488. package/dist/store/profile-repo.d.ts +36 -0
  489. package/dist/store/profile-repo.js +144 -0
  490. package/dist/store/project-dir-repo.d.ts +22 -0
  491. package/dist/store/project-dir-repo.js +60 -0
  492. package/dist/store/schedule-repo.d.ts +92 -0
  493. package/dist/store/schedule-repo.js +88 -0
  494. package/dist/store/session-registry-repo.d.ts +38 -0
  495. package/dist/store/session-registry-repo.js +96 -0
  496. package/dist/store/session-repo.d.ts +14 -0
  497. package/dist/store/session-repo.js +56 -0
  498. package/dist/store/task-repo.d.ts +41 -0
  499. package/dist/store/task-repo.js +137 -0
  500. package/dist/store/thread-repo.d.ts +50 -0
  501. package/dist/store/thread-repo.js +190 -0
  502. package/package.json +58 -0
  503. package/scripts/postinstall-restart-trigger.mjs +39 -0
@@ -0,0 +1,135 @@
1
+ ---
2
+ name: postmortem
3
+ description: "Use when an agent or pipeline produced a flawed output that was presented as correct — the question is 'why wasn't this caught?'"
4
+ allowed-tools:
5
+ - Read
6
+ - Grep
7
+ - Glob
8
+ argument-hint: "[file path, log entry, or description of the failure]"
9
+ ---
10
+
11
+ # /postmortem <path or failure description>
12
+
13
+ Analyze why an agent (LLM or pipeline) produced a flawed output. The goal is not to explain the technical mechanism but to identify the reasoning failure that led to the flaw being produced and not caught. The argument is a file path or description of the failure. Read relevant files first.
14
+
15
+ ## When to use this vs alternatives
16
+
17
+ - **Use `/postmortem`** when an agent or pipeline produced a flawed output that was *presented as correct* — the question is "why wasn't this caught?" not "what went wrong in the data?"
18
+ - **Use `/diagnose`** when the focus is on understanding *empirical results* — error distributions, root-cause hypotheses, validity. Diagnose analyzes data; postmortem analyzes agent reasoning.
19
+ - **Use `/critique`** for a broad review of an artifact's quality. Critique is proactive ("find problems"); postmortem is reactive ("explain this specific failure").
20
+ - **Use `/debug-campaign`** for multi-round system debugging with multiple failure modes. Debug-campaign is strategic debugging; postmortem is single-incident reasoning analysis.
21
+
22
+ ## Key distinction
23
+
24
+ The question is never "why is the output wrong?" — it is "why was this output presented as correct?"
25
+
26
+ A wrong prediction is expected. A wrong prediction reported as a finding, used to make a decision, or committed to the repo as fact is a reasoning failure worth analyzing.
27
+
28
+ ## Procedure
29
+
30
+ ### 1. Identify the flaw
31
+
32
+ State precisely what was wrong, with evidence. Quote the flawed output.
33
+
34
+ ### 2. Trace the production chain
35
+
36
+ Walk backward through the chain that produced the flaw:
37
+ - **Who generated it?** (which agent, script, or pipeline step)
38
+ - **What inputs did they have?** (were the inputs sufficient to detect the flaw?)
39
+ - **What checks were skipped?** (was there a review step that should have caught it?)
40
+ - **What structural condition enabled it?** (missing verification gate, context window limits, anchoring on prior output, pattern-matching without verification, ungrounded generation beyond reliable recall)
41
+
42
+ ### 3. Classify the failure mode
43
+
44
+ Which of these caused the flaw?
45
+
46
+ - **Design-as-discovery**: A constraint of the experimental setup was reported as an empirical finding. The agent failed to ask "could this have been different?"
47
+ - **Layer misattribution**: A property of one system layer was attributed to another (e.g., pipeline constraint reported as model behavior)
48
+ - **Momentum override**: The agent was executing a plan and did not pause to verify intermediate results. Production outpaced reflection.
49
+ - **Anchoring**: The agent saw a number or pattern and built a narrative around it without checking the generating process.
50
+ - **Missing mental model**: The agent lacked understanding of how the metric/system works and could not detect the flaw even in principle.
51
+ - **Context loss**: The relevant information existed but was not in the agent's working context when the decision was made (e.g., schema defined in a different file than the analysis).
52
+ - **Social proof**: The agent reported something because it looked like what a finding "should" look like, not because it was verified.
53
+ - **Ungrounded generation**: The model produced plausible but factually false content because autoregressive generation cannot distinguish retrieval from novel generation. This is the default behavior of foundation models, not a situational failure.
54
+
55
+ **Anti-anthropomorphism constraint:** Never attribute model failures to human psychological states (pressure, confusion, fatigue, rushing, carelessness). LLMs do not experience these. Use mechanistic explanations grounded in model architecture: ungrounded generation, token probability vs truth, context window limits, training distribution mismatch, missing verification gate. Anthropomorphic framings foreclose deeper investigation by implying the fix is "less pressure" rather than architectural safeguards.
56
+
57
+ (Cross-reference K-017: analogical reasoning must be labeled as hypothesis, not conclusion.)
58
+
59
+ ### 4. Identify the prevention
60
+
61
+ What specific check, convention, or tool would have caught this flaw before it was produced?
62
+
63
+ - Is there an existing convention in CORTEX.md that was not followed?
64
+ - Should a new convention be added?
65
+ - Would a skill (`/review`, `/critique`) have caught it?
66
+ - Should the pipeline itself include a validation step?
67
+
68
+ If the prevention involves creating a Decision Record, and the DR includes unimplemented action items, create corresponding tasks.
69
+
70
+ ### 5. Record model limits (if applicable)
71
+
72
+ If the failure mode involves model capability limitations (ungrounded generation, missing mental model due to capability gap), record it:
73
+
74
+ 1. As a new knowledge entry (knowledge/K-NNN.md) in the relevant project
75
+ 2. In the postmortem itself with evidence and mitigation
76
+ 3. In the relevant project's STATUS.md as a known limitation
77
+
78
+ Skip this step only if the root cause is entirely at non-model layers.
79
+
80
+ ## Output format
81
+
82
+ ```
83
+ ## Postmortem: <brief title>
84
+
85
+ ### The flaw
86
+ <what was wrong, with direct quote>
87
+
88
+ ### Production chain
89
+ 1. <step> — <what happened>
90
+ 2. <step> — <what happened>
91
+ 3. <step> — <where the flaw was introduced or missed>
92
+
93
+ ### Failure mode
94
+ <classified type>: <specific explanation>
95
+
96
+ ### Root cause
97
+ <one sentence: why the flaw was produced AND not caught>
98
+
99
+ ### Prevention
100
+ - Existing convention missed: <reference or "none">
101
+ - New convention needed: <specific proposal or "none">
102
+ - Skill that would catch this: <name or "none">
103
+ - Pipeline change needed: <specific proposal or "none">
104
+
105
+ ### Downstream Impact
106
+ <If the postmortem corrects previously-reported findings, list downstream consumers.
107
+ Search: `grep -r "EXP-ID" context/` or `grep -r "erroneous value" context/`
108
+ Classify each: corrected | needs-update | no-impact
109
+ Create tasks for needs-update items.
110
+ Omit this section if the error did not produce any cited findings.>
111
+
112
+ ### Severity
113
+ <high | medium | low> — <consequence if the flaw had not been caught>
114
+
115
+ ### Model-limit notes
116
+ <"Recorded: <what was added/changed>" or "No model-layer component — skip">
117
+ ```
118
+
119
+ ## Save to disk
120
+
121
+ Write the postmortem under `context/projects/<project>/`. Reference it in the relevant experiment file (`experiments/EXP-NNN.md`) if related to a specific experiment.
122
+
123
+ ## Task Bridge
124
+
125
+ After saving the postmortem, convert prevention actions to tasks:
126
+
127
+ 1. For each item in the "Prevention" section:
128
+ - If "New convention needed" → create a task to update the relevant convention/skill
129
+ - If "Pipeline change needed" → create a task for the code change
130
+ - If "Skill that would catch this" → check if the skill exists; if not, create a task
131
+ - Check TASKS.md for existing tasks before creating duplicates
132
+ 2. Tag each task appropriately with `[template: ...]` and lifecycle tags
133
+ 3. Reference this postmortem in each task's `Why:` field
134
+
135
+ This ensures prevention actions are executed rather than rediscovered in future postmortems of the same failure mode.
@@ -0,0 +1,183 @@
1
+ ---
2
+ name: solution-design
3
+ description: "Use before implementing any non-trivial code change — especially when modifying architecture, adding components, or choosing between multiple technical approaches"
4
+ author: Cortex
5
+ version: 1.0.0
6
+ date: 2026-03-06
7
+ ---
8
+
9
+ # Solution Design Protocol
10
+
11
+ You are about to design a solution. Before writing any implementation code, walk through these three gates in order. Each gate has a stop condition — if you can't pass it, pause and rethink rather than pushing forward.
12
+
13
+ The goal of this protocol is to prevent two failure modes:
14
+ 1. **Solving the wrong problem** — jumping to implementation based on analogy or theory instead of evidence
15
+ 2. **Patching the wrong architecture** — iterating within a code structure that doesn't match the problem structure, accumulating complexity without progress
16
+
17
+ ## Gate 1: Problem Framing
18
+
19
+ Ensure you're solving the right problem before thinking about solutions.
20
+
21
+ **1a. What specific behavior needs to change?**
22
+
23
+ Write it as a concrete before/after:
24
+ - Before: [what happens now — with evidence]
25
+ - After: [what should happen — with success criteria]
26
+
27
+ If you can't state this concretely, you don't understand the problem yet. Investigate more before designing.
28
+
29
+ **1b. Is your diagnosis evidence-based or analogical?**
30
+
31
+ Classify the source of your understanding:
32
+ - **Direct evidence**: error messages, stack traces, measured metrics, observed behavior
33
+ - **Analogical reasoning**: "a similar issue existed in X", code comments suggest Y, intuition says Z
34
+
35
+ Analogical diagnoses feel like conclusions but they're hypotheses. If your diagnosis is analogical, design a <30 min verification step before committing to a solution direction. Don't invest hours implementing a fix for an unverified root cause.
36
+
37
+ **1c. Does the existing system already handle this?**
38
+
39
+ Before building anything new, check:
40
+ - Does an existing component already cover this need? What's the actual gap?
41
+ - If you removed the proposed solution entirely, what specifically would break?
42
+
43
+ If you can't name a concrete loss, you probably don't need to build it.
44
+
45
+ ## Gate 2: Solution Space Exploration
46
+
47
+ Prevent anchoring on the first approach that comes to mind — especially one shaped by the existing code.
48
+
49
+ **2a. The blank-slate question**
50
+
51
+ Ask yourself: *"If I were solving this problem from scratch with no existing code, what would I build?"*
52
+
53
+ Write down the approach in 2-3 sentences. This is your reference design.
54
+
55
+ **2b. Compare with the patch approach**
56
+
57
+ Now look at what you'd actually do given the existing code. Ask:
58
+ - Is the patch approach structurally similar to the blank-slate design?
59
+ - Or am I patching within the existing structure because it's *easier*, not because it's *right*?
60
+
61
+ If the blank-slate design is structurally different from the patch, that's a yellow flag. The existing code may be anchoring your solution to the wrong architecture.
62
+
63
+ **2c. Is there a simpler way?**
64
+
65
+ Before committing, check: is there a way to get 80% of the benefit with 20% of the complexity? Sometimes the right answer is a smaller intervention than you're planning.
66
+
67
+ **2d. Will this solution hold at scale?**
68
+
69
+ > Provenance: 2026-03-15 PI feedback — flywheel registry exclusion was O(N) in prompt tokens, guaranteed to hit context window ceiling at ~1000 objects. Four rounds of token-cap increases (1024→2048→4096→8192) masked this structural limit. See flywheel KNOWLEDGE.md § 7.
70
+
71
+ For the proposed approach, identify the key resource it consumes (tokens, memory, time, API calls, storage) and apply five tests:
72
+
73
+ 1. **Understanding**: Can you explain the mechanism by which this approach consumes the resource — not just "it uses tokens" but "it uses O(N) tokens because each registry entry adds ~3 tokens to the prompt"?
74
+ 2. **Generalization**: Would anyone building a similar system face this resource constraint, or is it specific to our implementation?
75
+ 3. **Solution existence**: If the resource grows unsustainably, is there a known solution in literature/practice?
76
+ 4. **Recurrence**: Have we already adjusted this resource limit before (timeout increases, token cap bumps, batch size changes)? Repeated adjustments signal a structural problem.
77
+ 5. **Trade-off nature**: Can we simply throw more resources at this (bigger context window, more memory), or is there a fundamental tension?
78
+
79
+ If ≥2 tests suggest structural concern → note the ceiling in the Output and flag a structural review task before implementing.
80
+
81
+ Note in the Output section:
82
+ ```
83
+ Scalability: [resource] grows [O(1)/O(N)/O(N²)] — ceiling at [N] | no ceiling identified
84
+ ```
85
+
86
+ ## Gate 3: Iterate or Redesign?
87
+
88
+ You've framed the problem and explored options. Now decide your implementation strategy.
89
+
90
+ **3a. Architecture match check**
91
+
92
+ Does your solution structure match the problem structure? Examples:
93
+ - Global planning problem → needs a global planning solution (not greedy + backtrack)
94
+ - One-time configuration → needs a static config (not a runtime check on every call)
95
+ - Cross-cutting concern → needs a shared mechanism (not per-site patches)
96
+
97
+ **3b. If architecture matches: iterate**
98
+
99
+ When the existing approach is structurally right and just needs tuning:
100
+ - Make one change at a time
101
+ - Each change has a controlled comparison (same inputs, measure the delta)
102
+ - Don't change multiple variables simultaneously — you won't know what helped
103
+
104
+ **3c. If architecture doesn't match: redesign the relevant part**
105
+
106
+ Three signals that patches won't work — any one is sufficient:
107
+
108
+ 1. **Orthogonal concepts**: The patch requires introducing a concept that's fundamentally at odds with the current architecture (e.g., adding global planning logic inside a per-item generation loop)
109
+ 2. **Whack-a-mole**: Each patch fixes one problem but creates another (e.g., tighter validation → higher failure rate → more retries → worse retry quality)
110
+ 3. **Complexity crossover**: The cumulative patch complexity already exceeds what a clean rewrite would cost
111
+
112
+ When these signals appear, stop patching. Do a local redesign of the affected component — don't try to force-fit the current structure.
113
+
114
+ ## Output
115
+
116
+ After passing all three gates, state your plan concisely:
117
+
118
+ ```
119
+ Problem: [1-2 sentences, the concrete before/after]
120
+ Approach: [blank-slate or patch, and why]
121
+ Scalability: [resource] grows [O(1)/O(N)/O(N²)] — ceiling at [N] | no ceiling identified
122
+ First step: [the smallest verifiable action]
123
+ ```
124
+
125
+ If this design produced a significant choice between alternatives (not just "implement the obvious approach"), create a Decision Record in the appropriate `decisions/` directory (system-level for cross-project impact, project-level otherwise), then add an inline reference in the corresponding CORTEX.md.
126
+
127
+ Then implement. If at any point during implementation you hit a Gate 3 signal (orthogonal concept, whack-a-mole, complexity crossover), stop and re-run this protocol rather than pushing through.
128
+
129
+ ## Examples
130
+
131
+ ### Example 1: Gate 2 catches architecture mismatch (flywheel prompt dedup)
132
+
133
+ **Context**: prompt_generation repeatedly generated similar objects for the same category (e.g., multiple "blue ceramic mugs"). The existing code was a for loop generating artifacts one by one.
134
+
135
+ **Gate 1 passed**: The problem was clear — Before: 5-9 duplicates out of 20 objects; After: semantically unique count >=18. Sufficient evidence (EXP-015 quantified duplicate rates across 5 categories).
136
+
137
+ **Gate 2 flagged**:
138
+ - 2a blank-slate: "Let the LLM list 20 different types at once, then generate concrete objects for each type" — a two-phase approach
139
+ - 2b patch: "Add `used_names` check + reject + retry in the for loop" — because the existing code generates one by one
140
+ - **The two are structurally completely different**. The blank-slate approach is global planning, the patch is greedy step-by-step + backtracking. Yellow flag.
141
+
142
+ **What actually happened (consequences of not passing Gate 2)**:
143
+ - EXP-016: Added name-level dedup → exact duplicates dropped to 0%, but semantic duplicates remained
144
+ - EXP-017: Validation confirmed semantic duplicates at 13-25%
145
+ - EXP-018: Added prototype extraction + diversity prompt + retry modification → semantic duplicates dropped to 0%, but success rate dropped to 70% (whack-a-mole)
146
+ - EXP-019: Broader validation success rate only 38% (further deterioration)
147
+ - Three rounds of iteration added 5 methods, introduced fragile head noun parsing, and could not deduplicate across batches
148
+
149
+ **If Gate 2 had been passed**: Directly adopt the two-phase approach (1 LLM call for type planning + N independent instantiations), simpler implementation, naturally cross-batch, no reject-retry loop.
150
+
151
+ ---
152
+
153
+ ### Example 2: Gate 3b — architecture matches, iterate is correct (flywheel VLM size estimation)
154
+
155
+ **Context**: VLM severely hallucinated when estimating object sizes, with only 40% reasonable rate.
156
+
157
+ **Gate 1**: Before: 40% reasonable rate; After: >90%. Direct evidence (compared against actual sizes).
158
+
159
+ **Gate 2**:
160
+ - 2a blank-slate: "Use VLM + some calibration method"
161
+ - 2b patch: "Modify VLM prompt + input format"
162
+ - The structure is consistent — both are "use VLM for estimation, optimize input and output". No yellow flag.
163
+
164
+ **Gate 3b → iterate**:
165
+ - Step A: Normalize input (ratios instead of absolute values) → 40%→80%
166
+ - Step B: Few-shot calibration anchors → 80%→90%
167
+ - Step C: Multiple sampling with median → 90%→100%
168
+ - Each step has a control, knowing the independent contribution of each change. Three steps completed, no whack-a-mole.
169
+
170
+ **Why iteration is correct here**: The problem structure (single-point estimation accuracy) and the architecture (VLM prompt tuning) are naturally aligned. Each improvement is an accumulation in the same direction, not orthogonal concepts.
171
+
172
+ ---
173
+
174
+ ### Example 3: Gate 1 catches wrong problem (cortex-self episodes layer)
175
+
176
+ **Context**: Literature survey suggested agents need "episodic memory". Was about to design an episodes/ layer to store work segments.
177
+
178
+ **Gate 1 flagged**:
179
+ - 1a: Could not write the Before/After. "Before: no episodic memory" is not a concrete behavior description. What specific operation failed because there were no episodes? Could not answer.
180
+ - 1c: Checked the existing system — experiment files (experiments/EXP-NNN.md) already record the complete context (goal, method, results, reflection) of each experiment chronologically. This is essentially episodic memory.
181
+ - **Stop**: If episodes/ were removed, nothing would break, because experiment files already cover the need.
182
+
183
+ **If Gate 1 had not been passed**: Would have built a system with significant overlap with experiment files, increasing maintenance burden without adding value.
@@ -0,0 +1,120 @@
1
+ ---
2
+ name: synthesize
3
+ description: "Use when multiple experiments or analyses have accumulated and their findings need to be interpreted together — cross-experiment patterns, contradictions, and gaps"
4
+ allowed-tools:
5
+ - Read
6
+ - Grep
7
+ - Glob
8
+ argument-hint: "[project name, time range, topic, or file paths]"
9
+ ---
10
+
11
+ # /synthesize <scope>
12
+
13
+ You are synthesizing accumulated findings to surface patterns, contradictions, and insights that individual experiment entries or analyses miss on their own. The argument specifies the scope: a project name, a time range, a topic, or specific file paths.
14
+
15
+ This is the analytical complement to `/compound` (which embeds learnings from a single session); `/synthesize` works across multiple experiments and sessions to find emergent patterns.
16
+
17
+ ## When to use this vs alternatives
18
+
19
+ - **Use `/synthesize`** when you have accumulated findings across multiple experiments or sessions and want to find cross-cutting patterns, contradictions, or gaps.
20
+ - **Use `/diagnose`** when you want to understand a single result set — error patterns and root causes within one experiment.
21
+ - **Use `/compound`** for end-of-session learning embedding — single-session scope.
22
+ - **Use `/critique`** for adversarial review of a single artifact's quality.
23
+
24
+ ## Pre-flight audit
25
+
26
+ Before writing synthesis output, verify upstream data quality:
27
+
28
+ 1. **Enumerate upstream sources** — list every experiment, analysis, and note you'll cite
29
+ 2. **Flag provisional data** — check experiment status fields (completed vs running vs planned)
30
+ 3. **Spot-check key numerical claims** — for numbers that will drive conclusions, trace to the computational source (script + data file) and re-verify. Do NOT accept numbers copied from text.
31
+ 4. **Check cross-experiment comparisons** — verify denominators match and are explicitly stated
32
+
33
+ This prevents the most common synthesis failure: propagating contaminated or stale numbers from prior sessions.
34
+
35
+ ## Step 1: Gather material
36
+
37
+ Based on the scope argument:
38
+
39
+ - If a project name: read the project's experiments/index.md for overview, then Read specific EXP-NNN.md files for full entries. Also read STATUS.md, mission.md, and any relevant decisions/ files.
40
+ - If a time range: scan experiments/index.md across all active projects for entries in that range, then drill into relevant EXP-NNN.md files.
41
+ - If a topic: grep across projects for relevant material.
42
+ - If file paths: read those files directly.
43
+
44
+ Also check `context/decisions/` for relevant recorded choices.
45
+
46
+ ## Step 2: Analyze across dimensions
47
+
48
+ For the gathered material, identify:
49
+
50
+ ### 1. Cross-layer causal chains
51
+ Findings that connect across system layers. (e.g., "The evaluation gap exists because the interface can't present 3D interactively, which limits what the model can judge.") Trace cause → effect across at least 2 layers.
52
+
53
+ ### 2. Convergent signals
54
+ Multiple independent findings pointing to the same conclusion. What do they converge on? How strong is the convergence (same method, same data vs independent replication)?
55
+
56
+ ### 3. Contradictions
57
+ Findings that conflict with each other. Which is better grounded? What would resolve the disagreement? Check:
58
+ - Were the experimental conditions actually comparable?
59
+ - Are the contradictions at the same system layer or different layers?
60
+ - Does one have better provenance (more data, controlled experiment vs observational)?
61
+
62
+ ### 4. Gaps
63
+ What questions remain unasked? What system layers are underrepresented in the findings? What experiments would fill the gaps?
64
+
65
+ ### 5. Gravity candidates
66
+ Recurring patterns that should be formalized. What manual work could become automated? What judgment has become routine enough to be a convention? (Reference `/gravity` for evaluation.)
67
+
68
+ ## Step 3: Generate insights
69
+
70
+ For each pattern found, assess:
71
+ - **Confidence**: How many independent data points support this? (1 = anecdotal, 2-3 = pattern, 4+ = established)
72
+ - **Actionability**: What concrete action does this insight enable?
73
+ - **Novelty**: Is this genuinely new understanding, or restating what individual experiments already said?
74
+
75
+ Prioritize insight density over comprehensiveness. A synthesis that surfaces one genuine cross-layer insight is more valuable than one that restates what the experiments already say.
76
+
77
+ ## Output format
78
+
79
+ ```
80
+ ## Synthesis: <scope>
81
+
82
+ ### Material reviewed
83
+ <bulleted list of files/entries consulted, with verification status>
84
+
85
+ ### Cross-layer chains
86
+ <numbered findings, each tracing a connection across 2+ system layers>
87
+
88
+ ### Convergent signals
89
+ <what multiple findings agree on — with specific references>
90
+
91
+ ### Contradictions
92
+ <conflicting findings and what would resolve them>
93
+
94
+ ### Gaps
95
+ <what's missing — specific questions or unexamined areas>
96
+
97
+ ### Gravity candidates
98
+ <patterns that should move downward — from manual to convention to code>
99
+
100
+ ### Implications
101
+ <1-3 concrete recommendations for what to do next, referencing specific projects or actions>
102
+ ```
103
+
104
+ ## Save to disk
105
+
106
+ Write the synthesis to the relevant project's directory under `context/projects/<project>/`. If cross-project, save to `context/` root level. Reference in STATUS.md as appropriate.
107
+
108
+ ## Task Bridge
109
+
110
+ After saving the synthesis, convert actionable findings to tasks:
111
+
112
+ 1. For each item in "Implications" with a concrete action verb (implement, create, run, update, design, investigate, fix):
113
+ - Check the project's TASKS.md for existing task
114
+ - If none, create one with provenance referencing this synthesis
115
+ 2. For "Gaps" that suggest specific experiments: create tasks referencing `/solution-design`
116
+ 3. For "Gravity candidates" rated "formalize now": create a task to run `/gravity`
117
+ 4. For "Contradictions" needing resolution: create investigation tasks
118
+ 5. Skip implications that are purely observational or contextual
119
+
120
+ Cross-session synthesis insights are among the highest-value outputs. Converting them to tasks ensures they are acted upon.
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "cortex-stage-gate",
3
+ "version": "0.1.0",
4
+ "description": "Cortex stage-gate skill bundle — reorient / task creation / approval primitives"
5
+ }
@@ -0,0 +1,89 @@
1
+ ---
2
+ name: need-approval
3
+ description: "Use when Cortex is about to perform a potentially high-privilege operation and needs to check whether user approval is required"
4
+ author: Cortex
5
+ version: 1.0.0
6
+ allowed-tools:
7
+ - Read
8
+ - Write
9
+ - Edit
10
+ date: 2026-02-28
11
+ ---
12
+
13
+ # Need Approval
14
+
15
+ You are Cortex, checking whether an operation requires user approval before execution.
16
+
17
+ This is the gatekeeper for high-privilege operations. When you're about to do something that might need confirmation, run it through this check. If approval is needed, record it to the queue instead of executing immediately.
18
+
19
+ ## Operation to check
20
+ $ARGUMENTS
21
+
22
+ ## Step 1: Classify the Operation
23
+
24
+ Check the operation against CORTEX.md "Safety Boundaries". The judgment criterion is **behavioral impact**, not file category.
25
+
26
+ **Needs approval:**
27
+ - Modify CORTEX.md or CLAUDE.local.md
28
+ - New skills or skill behavioral changes (new triggers, new workflow steps, capability expansion)
29
+ - Agent-server behavioral or architectural changes (new features, protocol changes, API changes)
30
+ - Over-budget training tasks, large-scale architecture modifications
31
+ - Delete files or data
32
+ - Modify model code or training configs
33
+ - Kill app.js or daemon processes
34
+
35
+ **Does NOT need approval (self-serve):**
36
+ - Read files, check GPU status, read logs
37
+ - Update context files (STATUS.md, experiments/, knowledge/, OVERVIEW.md, TASKS.md)
38
+ - rsync to sync result files
39
+ - Web search, knowledge scan
40
+ - Training tasks within budget (with GPU preflight check)
41
+ - Analysis scripts, small tools
42
+ - Skill maintenance changes (typo, format alignment, description rewording — no behavioral change)
43
+ - Agent-server non-behavioral fixes (syntax errors, log messages, comment updates)
44
+ - Information gathering and analysis
45
+
46
+ **Examples:**
47
+ | Operation | Classification | Reason |
48
+ |-----------|---------------|--------|
49
+ | Fix typo in skill SKILL.md | Self-serve | Maintenance, no behavioral change |
50
+ | Add new workflow step to a skill | Needs approval | Changes behavioral logic |
51
+ | Fix agent-server syntax error | Self-serve | Non-behavioral fix |
52
+ | Add new guard logic to agent-server | Needs approval | Changes behavior |
53
+ | Start GPU training within budget | Self-serve | Within budget, but must do GPU preflight |
54
+ | Modify CORTEX.md rules | Needs approval | System convention change |
55
+
56
+ ## Step 2: If Approval Needed — Record It
57
+
58
+ Append the operation to `context/PENDING_APPROVALS.md`:
59
+
60
+ ```markdown
61
+ ## [timestamp]
62
+ - **Operation**: [concise description of what will be done]
63
+ - **Reason**: [why this operation is needed]
64
+ - **Impact**: [what it affects — files, machines, resources]
65
+ - **Command/Action**: [the specific command or change to execute]
66
+ - **Status**: pending
67
+ ```
68
+
69
+ Create the file if it doesn't exist. Always append — don't overwrite existing entries.
70
+
71
+ Then output:
72
+ ```
73
+ Queued for approval: [one-line summary]
74
+ Use /approval to review pending operations.
75
+ ```
76
+
77
+ ## Step 3: If No Approval Needed
78
+
79
+ Output:
80
+ ```
81
+ No approval needed — safe to execute.
82
+ ```
83
+
84
+ And proceed with the operation directly.
85
+
86
+ ## Principles
87
+ - When in doubt, queue it. Better to over-ask than to break something.
88
+ - The record must contain enough detail for the user to make a decision without asking follow-up questions.
89
+ - Never execute a high-privilege operation without going through this check first.