@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
@@ -1,7 +1,7 @@
1
1
  export { platformSettingsInput } from '../../core/platform-settings-spec.js';
2
2
  import { z } from 'zod';
3
- import { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput } from './query-input-schemas.js';
4
- export { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput, };
3
+ import { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, waitpointsListInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput } from './query-input-schemas.js';
4
+ export { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, waitpointsListInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput, };
5
5
  export declare const projectsListInput: z.ZodObject<{}, z.core.$strip>;
6
6
  export declare const costSummaryInput: z.ZodObject<{
7
7
  projectId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -27,9 +27,6 @@ export declare const systemNoticesInput: z.ZodObject<{
27
27
  limit: z.ZodOptional<z.ZodNumber>;
28
28
  }, z.core.$strip>;
29
29
  export declare const systemUpdateStatusInput: z.ZodObject<{}, z.core.$strip>;
30
- export declare const executionsLogInput: z.ZodObject<{
31
- executionId: z.ZodString;
32
- }, z.core.$strip>;
33
30
  export declare const authStartLoginInput: z.ZodObject<{
34
31
  backend: z.ZodEnum<{
35
32
  claude: "claude";
@@ -156,10 +153,17 @@ export declare const sessionsCompactInput: z.ZodObject<{
156
153
  export declare const sessionsMarkReadInput: z.ZodObject<{
157
154
  sessionId: z.ZodString;
158
155
  }, z.core.$strip>;
156
+ export declare const sessionsMarkManyReadInput: z.ZodObject<{
157
+ sessionIds: z.ZodArray<z.ZodString>;
158
+ }, z.core.$strip>;
159
159
  export declare const sessionsSetProfileInput: z.ZodObject<{
160
160
  sessionId: z.ZodString;
161
161
  profileName: z.ZodString;
162
162
  }, z.core.$strip>;
163
+ export declare const sessionsSetAgentInput: z.ZodObject<{
164
+ sessionId: z.ZodString;
165
+ agentName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
166
+ }, z.core.$strip>;
163
167
  export declare const sessionsSetSelectionInput: z.ZodObject<{
164
168
  sessionId: z.ZodString;
165
169
  profileName: z.ZodOptional<z.ZodString>;
@@ -200,6 +204,7 @@ export declare const sessionsRewindInput: z.ZodObject<{
200
204
  export declare const sessionsCreateAndSendInput: z.ZodObject<{
201
205
  projectId: z.ZodString;
202
206
  profileName: z.ZodOptional<z.ZodString>;
207
+ agentName: z.ZodOptional<z.ZodString>;
203
208
  selection: z.ZodOptional<z.ZodObject<{
204
209
  model: z.ZodOptional<z.ZodString>;
205
210
  provider: z.ZodOptional<z.ZodString>;
@@ -232,6 +237,9 @@ export declare const sessionsCreateAndSendInput: z.ZodObject<{
232
237
  export declare const threadsCancelInput: z.ZodObject<{
233
238
  threadId: z.ZodString;
234
239
  }, z.core.$strip>;
240
+ export declare const waitpointsCancelInput: z.ZodObject<{
241
+ waitpointId: z.ZodString;
242
+ }, z.core.$strip>;
235
243
  export declare const executionsCancelInput: z.ZodObject<{
236
244
  executionId: z.ZodString;
237
245
  }, z.core.$strip>;
@@ -607,6 +615,7 @@ export declare const queryInputSchemas: {
607
615
  'sessions.transcript': z.ZodObject<{
608
616
  sessionId: z.ZodString;
609
617
  compactSubagents: z.ZodOptional<z.ZodBoolean>;
618
+ since: z.ZodOptional<z.ZodString>;
610
619
  }, z.core.$strip>;
611
620
  'sessions.subagentTranscript': z.ZodObject<{
612
621
  sessionId: z.ZodString;
@@ -662,6 +671,9 @@ export declare const queryInputSchemas: {
662
671
  status: z.ZodOptional<z.ZodArray<z.ZodString>>;
663
672
  limit: z.ZodOptional<z.ZodNumber>;
664
673
  }, z.core.$strip>;
674
+ 'waitpoints.list': z.ZodObject<{
675
+ sessionId: z.ZodString;
676
+ }, z.core.$strip>;
665
677
  'executions.get': z.ZodObject<{
666
678
  executionId: z.ZodString;
667
679
  }, z.core.$strip>;
@@ -769,6 +781,10 @@ export declare const mutateInputSchemas: {
769
781
  sessionId: z.ZodString;
770
782
  profileName: z.ZodString;
771
783
  }, z.core.$strip>;
784
+ 'sessions.setAgent': z.ZodObject<{
785
+ sessionId: z.ZodString;
786
+ agentName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
787
+ }, z.core.$strip>;
772
788
  'sessions.setSelection': z.ZodObject<{
773
789
  sessionId: z.ZodString;
774
790
  profileName: z.ZodOptional<z.ZodString>;
@@ -793,6 +809,7 @@ export declare const mutateInputSchemas: {
793
809
  'sessions.createAndSend': z.ZodObject<{
794
810
  projectId: z.ZodString;
795
811
  profileName: z.ZodOptional<z.ZodString>;
812
+ agentName: z.ZodOptional<z.ZodString>;
796
813
  selection: z.ZodOptional<z.ZodObject<{
797
814
  model: z.ZodOptional<z.ZodString>;
798
815
  provider: z.ZodOptional<z.ZodString>;
@@ -825,6 +842,9 @@ export declare const mutateInputSchemas: {
825
842
  'sessions.markRead': z.ZodObject<{
826
843
  sessionId: z.ZodString;
827
844
  }, z.core.$strip>;
845
+ 'sessions.markManyRead': z.ZodObject<{
846
+ sessionIds: z.ZodArray<z.ZodString>;
847
+ }, z.core.$strip>;
828
848
  'sessions.answerQuestion': z.ZodObject<{
829
849
  requestId: z.ZodString;
830
850
  answers: z.ZodRecord<z.ZodString, z.ZodString>;
@@ -858,6 +878,9 @@ export declare const mutateInputSchemas: {
858
878
  'executions.cancel': z.ZodObject<{
859
879
  executionId: z.ZodString;
860
880
  }, z.core.$strip>;
881
+ 'waitpoints.cancel': z.ZodObject<{
882
+ waitpointId: z.ZodString;
883
+ }, z.core.$strip>;
861
884
  'schedules.pause': z.ZodObject<{
862
885
  scheduleId: z.ZodString;
863
886
  }, z.core.$strip>;
@@ -1,7 +1,7 @@
1
1
  // input: Zod, settings specs and UI operation unions
2
2
  // output: UI input validation schemas and operation maps
3
3
  // pos: Runtime validation source for UI contract
4
- // >>> Once updated, update this header and parent CORTEX.md <<<
4
+ // >>> Once updated, update this header and parent AGENTS.md <<<
5
5
  import { platformSettingsInput } from '../../core/platform-settings-spec.js';
6
6
  export { platformSettingsInput } from '../../core/platform-settings-spec.js';
7
7
  import { z } from 'zod';
@@ -9,8 +9,8 @@ import { SETTINGS_SPEC } from '../../core/settings-spec.js';
9
9
  // Import the leaf model module, not the pi-providers barrel: this file is bundled for the browser
10
10
  // through @cortex-agent/ui-contract, and that module is pure data with no imports of its own.
11
11
  import { CUSTOM_PROVIDER_APIS, CUSTOM_PROVIDER_NAME_RE, } from '../pi-providers/custom-provider-model.js';
12
- import { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput, } from './query-input-schemas.js';
13
- export { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput, };
12
+ import { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, waitpointsListInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput, } from './query-input-schemas.js';
13
+ export { sessionsListInput, sessionsTranscriptInput, sessionsSubagentTranscriptInput, sessionsDebugDetailsInput, sessionsPendingInteractionInput, threadsListInput, threadsGetInput, tasksListInput, taskVerificationInput, schedulesListInput, commissionsListInput, commissionsGetInput, commissionsDecisionsInput, executionsListInput, executionsGetInput, waitpointsListInput, memoryTreeInput, memoryFileInput, approvalsListInput, issuesListInput, notesListInput, };
14
14
  // ── Query input schemas ───────────────────────────────────────────
15
15
  export const projectsListInput = z.object({});
16
16
  export const costSummaryInput = z.object({
@@ -35,12 +35,6 @@ export const systemRateLimitStatusInput = z.object({});
35
35
  export const systemUsageStatusInput = z.object({});
36
36
  export const systemNoticesInput = z.object({ limit: z.number().int().positive().max(50).optional() });
37
37
  export const systemUpdateStatusInput = z.object({});
38
- // ── Subscription input schemas ────────────────────────────────────
39
- // Subscriptions are not part of the query/mutate keyed maps; their input schemas live here too so
40
- // the AppRouter and the browser (@cortex-agent/ui-contract) share one source of truth (B2-C).
41
- export const executionsLogInput = z.object({
42
- executionId: z.string(),
43
- });
44
38
  // ── Mutate input schemas ──────────────────────────────────────────
45
39
  export const authStartLoginInput = z.object({
46
40
  backend: z.enum(['claude', 'pi']),
@@ -139,10 +133,23 @@ export const sessionsCompactInput = z.object({
139
133
  export const sessionsMarkReadInput = z.object({
140
134
  sessionId: z.string(),
141
135
  });
136
+ // Bounded batch: the run list of one schedule, never "every session on the box".
137
+ export const sessionsMarkManyReadInput = z.object({
138
+ sessionIds: z.array(z.string()).min(1).max(500),
139
+ });
142
140
  export const sessionsSetProfileInput = z.object({
143
141
  sessionId: z.string(),
144
142
  profileName: z.string().min(1),
145
143
  });
144
+ // sessions.setAgent — which agent template (execution environment) the session runs as. "Follow the
145
+ // global default again" is sayable two ways, `null` and absent, because the browser client cannot
146
+ // say the first one: this project compiles without strictNullChecks, so the `| null` of an INFERRED
147
+ // schema type is stripped from the emitted declaration the web typechecks against. Both forms mean
148
+ // the same thing to the handler.
149
+ export const sessionsSetAgentInput = z.object({
150
+ sessionId: z.string(),
151
+ agentName: z.string().min(1).nullable().optional(),
152
+ });
146
153
  /** What a session runs on top of its profile. Stated WHOLE, never patched: a field the object does
147
154
  * not carry is a field that follows the profile, so "go back to the profile's model" needs no null
148
155
  * (which the typed tRPC client cannot express through an optional input anyway). */
@@ -190,6 +197,7 @@ export const sessionsRewindInput = z.object({
190
197
  export const sessionsCreateAndSendInput = z.object({
191
198
  projectId: z.string(),
192
199
  profileName: z.string().optional(),
200
+ agentName: z.string().min(1).optional(),
193
201
  selection: sessionSelectionInput.optional(),
194
202
  browser: sessionBrowserInput.nullish(),
195
203
  commission: sessionCommissionInput.nullish(),
@@ -206,6 +214,9 @@ export const sessionsCreateAndSendInput = z.object({
206
214
  export const threadsCancelInput = z.object({
207
215
  threadId: z.string(),
208
216
  });
217
+ export const waitpointsCancelInput = z.object({
218
+ waitpointId: z.string().min(1),
219
+ });
209
220
  export const executionsCancelInput = z.object({
210
221
  executionId: z.string(),
211
222
  });
@@ -684,6 +695,7 @@ export const queryInputSchemas = {
684
695
  'commissions.get': commissionsGetInput,
685
696
  'commissions.decisions': commissionsDecisionsInput,
686
697
  'executions.list': executionsListInput,
698
+ 'waitpoints.list': waitpointsListInput,
687
699
  'executions.get': executionsGetInput,
688
700
  'memory.tree': memoryTreeInput,
689
701
  'memory.file': memoryFileInput,
@@ -718,10 +730,12 @@ export const mutateInputSchemas = {
718
730
  'sessions.cancel': sessionsCancelInput,
719
731
  'sessions.compact': sessionsCompactInput,
720
732
  'sessions.setProfile': sessionsSetProfileInput,
733
+ 'sessions.setAgent': sessionsSetAgentInput,
721
734
  'sessions.setSelection': sessionsSetSelectionInput,
722
735
  'sessions.setCommission': sessionsSetCommissionInput,
723
736
  'sessions.createAndSend': sessionsCreateAndSendInput,
724
737
  'sessions.markRead': sessionsMarkReadInput,
738
+ 'sessions.markManyRead': sessionsMarkManyReadInput,
725
739
  'sessions.answerQuestion': sessionsAnswerQuestionInput,
726
740
  'sessions.respondPlan': sessionsRespondPlanInput,
727
741
  'sessions.respondDecision': sessionsRespondDecisionInput,
@@ -729,6 +743,7 @@ export const mutateInputSchemas = {
729
743
  'sessions.rewind': sessionsRewindInput,
730
744
  'threads.cancel': threadsCancelInput,
731
745
  'executions.cancel': executionsCancelInput,
746
+ 'waitpoints.cancel': waitpointsCancelInput,
732
747
  'schedules.pause': scheduleActionInput,
733
748
  'schedules.resume': scheduleActionInput,
734
749
  'schedules.remove': scheduleActionInput,
@@ -1,7 +1,7 @@
1
1
  // input: platform patch schema, config path and credential writer
2
2
  // output: validated platform writes with secret-free errors
3
3
  // pos: Platform settings mutation boundary
4
- // >>> Once updated, update this header and parent CORTEX.md <<<
4
+ // >>> Once updated, update this header and parent AGENTS.md <<<
5
5
  import path from 'node:path';
6
6
  import { CONFIG_DIR } from '../../../core/paths.js';
7
7
  import { platformSettingsInput } from '../../../core/platform-settings-spec.js';
@@ -1,4 +1,4 @@
1
- import type { UiServiceDeps, Result, SessionsCreateArgs, SessionsCreateReturn, SessionsSendArgs, SessionsSendReturn, SessionsCancelArgs, SessionsCompactArgs, SessionsCompactReturn, SessionsMarkReadArgs, SessionsCancelReturn, SessionsSetProfileArgs, SessionsSetProfileReturn, SessionsSetSelectionArgs, SessionsSetSelectionReturn, SessionsSetCommissionArgs, SessionsSetCommissionReturn, SessionsCreateAndSendArgs, SessionsCreateAndSendReturn, SessionsAnswerQuestionArgs, SessionsRespondPlanArgs, SessionsRespondDecisionArgs, SessionsRespondDecisionReturn, SessionsInteractionMutateReturn, SessionsRewindArgs, SessionsRewindReturn, SessionsCancelResumeArgs, SessionsCancelResumeReturn } from '../types.js';
1
+ import type { UiServiceDeps, Result, SessionsCreateArgs, SessionsCreateReturn, SessionsSendArgs, SessionsSendReturn, SessionsCancelArgs, SessionsCompactArgs, SessionsCompactReturn, SessionsMarkReadArgs, SessionsMarkManyReadArgs, SessionsMarkManyReadReturn, SessionsCancelReturn, SessionsSetProfileArgs, SessionsSetProfileReturn, SessionsSetAgentArgs, SessionsSetAgentReturn, SessionsSetSelectionArgs, SessionsSetSelectionReturn, SessionsSetCommissionArgs, SessionsSetCommissionReturn, SessionsCreateAndSendArgs, SessionsCreateAndSendReturn, SessionsAnswerQuestionArgs, SessionsRespondPlanArgs, SessionsRespondDecisionArgs, SessionsRespondDecisionReturn, SessionsInteractionMutateReturn, SessionsRewindArgs, SessionsRewindReturn, SessionsCancelResumeArgs, SessionsCancelResumeReturn } from '../types.js';
2
2
  export declare function handleCreateSession(deps: UiServiceDeps, args: SessionsCreateArgs): Promise<Result<SessionsCreateReturn>>;
3
3
  /**
4
4
  * Switch a LIVE session in or out of commission mode (DR-0037 v4).
@@ -16,8 +16,13 @@ export declare function handleSendSession(deps: UiServiceDeps, args: SessionsSen
16
16
  export declare function handleCancelSession(deps: UiServiceDeps, args: SessionsCancelArgs): Promise<Result<SessionsCancelReturn>>;
17
17
  export declare function handleCompactSession(deps: UiServiceDeps, args: SessionsCompactArgs): Promise<Result<SessionsCompactReturn>>;
18
18
  export declare function handleMarkReadSession(deps: UiServiceDeps, args: SessionsMarkReadArgs): Promise<Result<void>>;
19
+ /** Batch mark-read behind the run list's「mark all read」. Deliberately forgiving: a session that
20
+ * no longer resolves (purged run, stale client list) is skipped instead of failing the batch —
21
+ * the user asked to clear what they see, and a half-stale list must still clear. */
22
+ export declare function handleMarkManyReadSessions(deps: UiServiceDeps, args: SessionsMarkManyReadArgs): Promise<Result<SessionsMarkManyReadReturn>>;
19
23
  export declare function handleCreateAndSend(deps: UiServiceDeps, args: SessionsCreateAndSendArgs): Promise<Result<SessionsCreateAndSendReturn>>;
20
24
  export declare function handleSetProfile(deps: UiServiceDeps, args: SessionsSetProfileArgs): Promise<Result<SessionsSetProfileReturn>>;
25
+ export declare function handleSetAgent(deps: UiServiceDeps, args: SessionsSetAgentArgs): Promise<Result<SessionsSetAgentReturn>>;
21
26
  export declare function handleSetSelection(deps: UiServiceDeps, args: SessionsSetSelectionArgs): Promise<Result<SessionsSetSelectionReturn>>;
22
27
  export declare function handleRewindSession(deps: UiServiceDeps, args: SessionsRewindArgs): Promise<Result<SessionsRewindReturn>>;
23
28
  export declare function handleAnswerQuestion(deps: UiServiceDeps, args: SessionsAnswerQuestionArgs): Promise<Result<SessionsInteractionMutateReturn>>;
@@ -177,6 +177,20 @@ export async function handleMarkReadSession(deps, args) {
177
177
  await deps.sessionStore.markRead?.(args.sessionId);
178
178
  return { ok: true, data: undefined };
179
179
  }
180
+ /** Batch mark-read behind the run list's「mark all read」. Deliberately forgiving: a session that
181
+ * no longer resolves (purged run, stale client list) is skipped instead of failing the batch —
182
+ * the user asked to clear what they see, and a half-stale list must still clear. */
183
+ export async function handleMarkManyReadSessions(deps, args) {
184
+ let marked = 0;
185
+ for (const sessionId of new Set(args.sessionIds)) {
186
+ const session = await deps.sessionStore.getById(sessionId);
187
+ if (!session)
188
+ continue;
189
+ await deps.sessionStore.markRead?.(sessionId);
190
+ marked += 1;
191
+ }
192
+ return { ok: true, data: { marked } };
193
+ }
180
194
  // Create a fresh session AND send the first message in one atomic operation. Used by the workbench
181
195
  // "New Conversation" draft flow (task 15b): the session is created only when the user sends their
182
196
  // first message, at which point the profile is already known and the backend is resolved correctly.
@@ -193,6 +207,10 @@ export async function handleCreateAndSend(deps, args) {
193
207
  const { sessionId, channel } = await deps.createDirectSession({
194
208
  projectId: args.projectId,
195
209
  profileName: args.profileName ?? null,
210
+ // The draft composer's environment choice, applied at creation for the same reason as the
211
+ // selection below: the agent decides the spawned process's prompt and tool surface, and there
212
+ // is no session to `setAgent` on before the first turn.
213
+ agentName: args.agentName ?? null,
196
214
  // The draft composer's model/thinking choice, applied at creation so the FIRST turn already
197
215
  // runs it — there is no session to `setSelection` on before this call. A composer that sends
198
216
  // none is stating the empty selection ("follow the profile"), not staying silent: this is the
@@ -245,6 +263,42 @@ export async function handleSetProfile(deps, args) {
245
263
  }
246
264
  return { ok: true, data: { profileName: res.name, backendChanged: res.backendChanged } };
247
265
  }
266
+ // Switch the session's agent — its execution environment — under the shared agent-switch rule (the
267
+ // same `switchChannelAgent` the Slack/Feishu `!agent` command uses, injected as `switchSessionAgent`).
268
+ // The error mapping is `handleSetProfile`'s, for the same reasons:
269
+ // • unknown-agent → invalid-args
270
+ // • cross-backend-live-session → conflict (an agent pinning a profile on the other backend is a
271
+ // backend move; a live conversation can't be resumed there)
272
+ // A null `agentName` clears the selection: the session follows the global default again.
273
+ export async function handleSetAgent(deps, args) {
274
+ const session = await deps.sessionStore.getById(args.sessionId);
275
+ if (!session) {
276
+ return { ok: false, code: 'not-found', message: `Session not found: ${args.sessionId}` };
277
+ }
278
+ if (!deps.switchSessionAgent) {
279
+ return { ok: false, code: 'not-available', message: 'Agent selection is not available' };
280
+ }
281
+ const name = args.agentName ?? null;
282
+ const res = await deps.switchSessionAgent({ channel: session.channel, name });
283
+ if (!res.ok) {
284
+ if (res.reason === 'unknown-agent') {
285
+ return { ok: false, code: 'invalid-args', message: `Unknown agent: ${String(name)}` };
286
+ }
287
+ return {
288
+ ok: false,
289
+ code: 'backend-locked', // maps to CONFLICT in the tRPC layer
290
+ message: `Can't switch to "${String(name)}" (${res.targetBackend}) — this conversation runs on ${res.currentBackend}. Start a new session to change backend.`,
291
+ };
292
+ }
293
+ return {
294
+ ok: true,
295
+ data: {
296
+ agentName: res.agentName,
297
+ profileName: res.effectiveProfile,
298
+ backendChanged: res.backendChanged,
299
+ },
300
+ };
301
+ }
248
302
  // Change what the session's next turn runs — its profile, its model, its PI provider, its thinking
249
303
  // level, or any combination — through the ONE domain rule (`applyChannelSelection`, injected as
250
304
  // `applySessionSelection`). The composer's greying-out is a preview of that rule; this is where it
@@ -2,10 +2,11 @@
2
2
  // output: claim/unclaim/complete/block/unblock handlers → Ok<void> | Err
3
3
  // pos: mutate handlers for 'tasks.{claim,unclaim,complete,block,unblock}'
4
4
  import { taskMutator } from '../../tasks/mutator.js';
5
- import { acquireLock, releaseLock, getOwnerIdentity } from '../../tasks/system/task-lock.js';
5
+ import { acquireLockAsync, releaseLockAsync, getOwnerIdentity } from '../../tasks/system/task-lock.js';
6
6
  async function withTaskLock(deps, projectId, fn) {
7
7
  const owner = getOwnerIdentity();
8
- const acq = acquireLock(projectId, { owner });
8
+ // Async lock: the UI mutation must not park the event loop while another process holds the lock.
9
+ const acq = await acquireLockAsync(projectId, { owner });
9
10
  if (!acq.acquired) {
10
11
  return { ok: false, code: 'task-lock-busy', message: acq.message || 'Task lock is busy' };
11
12
  }
@@ -14,7 +15,7 @@ async function withTaskLock(deps, projectId, fn) {
14
15
  return { ok: true, data: result };
15
16
  }
16
17
  finally {
17
- releaseLock(projectId, owner);
18
+ await releaseLockAsync(projectId, owner);
18
19
  }
19
20
  }
20
21
  export async function handleClaimTask(deps, args) {
@@ -0,0 +1,2 @@
1
+ import type { Result, UiServiceDeps, WaitpointsCancelArgs, WaitpointsCancelReturn } from '../types.js';
2
+ export declare function handleCancelWaitpoint(deps: UiServiceDeps, args: WaitpointsCancelArgs): Promise<Result<WaitpointsCancelReturn>>;
@@ -0,0 +1,20 @@
1
+ // input: UiServiceDeps + WaitpointsCancelArgs
2
+ // output: handleCancelWaitpoint → Result<WaitpointsCancelReturn>
3
+ // pos: mutate handler for 'waitpoints.cancel' — the human escape hatch for a waitpoint whose
4
+ // signal is never coming. The state guard lives in the waitpoint service (a non-armed
5
+ // waitpoint refuses), so this handler only translates the outcome.
6
+ export async function handleCancelWaitpoint(deps, args) {
7
+ if (!deps.waitpointRegistry) {
8
+ return { ok: false, code: 'not-available', message: 'Waitpoints are not available on this server' };
9
+ }
10
+ try {
11
+ const outcome = await deps.waitpointRegistry.cancel(args.waitpointId);
12
+ if (!outcome.cancelled && !outcome.state) {
13
+ return { ok: false, code: 'not-found', message: `Waitpoint not found: ${args.waitpointId}` };
14
+ }
15
+ return { ok: true, data: { cancelled: outcome.cancelled, state: outcome.state ?? null } };
16
+ }
17
+ catch (err) {
18
+ return { ok: false, code: 'internal', message: err?.message || String(err) };
19
+ }
20
+ }
@@ -1,7 +1,7 @@
1
1
  // input: dotenv files, live environment, atomic mutation and schema
2
2
  // output: redacted platform snapshots and serialized credential patches
3
3
  // pos: Platform configuration persistence and pending-state reader
4
- // >>> Once updated, update this header and parent CORTEX.md <<<
4
+ // >>> Once updated, update this header and parent AGENTS.md <<<
5
5
  import fs from 'node:fs/promises';
6
6
  import { parse } from 'dotenv';
7
7
  import { mutateFileAtomically } from '../../core/atomic-write.js';
@@ -1,7 +1,7 @@
1
1
  // input: plugin catalog, settings and plugin directories
2
2
  // output: normalized plugin entries and effective scopes
3
3
  // pos: Shared plugin helpers for UI service
4
- // >>> Once updated, update this header and parent CORTEX.md <<<
4
+ // >>> Once updated, update this header and parent AGENTS.md <<<
5
5
  import fs from 'node:fs';
6
6
  import { getSettings } from '../../core/settings.js';
7
7
  import path from 'node:path';
@@ -1,7 +1,7 @@
1
1
  // input: config root, platform settings, hook registry, live locale and its source
2
2
  // output: config snapshot with redacted platform fields and the active UI/server language
3
3
  // pos: Config snapshot reader
4
- // >>> Once updated, update this header and parent CORTEX.md <<<
4
+ // >>> Once updated, update this header and parent AGENTS.md <<<
5
5
  import fs from 'node:fs/promises';
6
6
  import { readPlatformSettings } from '../platform-settings.js';
7
7
  import path from 'node:path';
@@ -19,6 +19,22 @@ async function readJson(file) {
19
19
  return null;
20
20
  }
21
21
  }
22
+ /** The agent templates, read as documents rather than filenames: a picker has to say what each
23
+ * environment is for and which profile it pins. Read from the same directory the bare listing
24
+ * comes from, so the snapshot stays hermetic to `configDir`; a malformed file is skipped rather
25
+ * than failing the whole snapshot. */
26
+ async function readAgentEntries(dir, names) {
27
+ const entries = await Promise.all(names.map(async (name) => {
28
+ const raw = await readJson(path.join(dir, `${name}.json`));
29
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
30
+ return null;
31
+ const doc = raw;
32
+ const profile = typeof doc.profile === 'string' && doc.profile ? doc.profile : '__active__';
33
+ const description = typeof doc.description === 'string' && doc.description ? doc.description : undefined;
34
+ return { name, profile, ...(description ? { description } : {}) };
35
+ }));
36
+ return entries.filter((entry) => entry !== null);
37
+ }
22
38
  async function listJsonBasenames(dir) {
23
39
  try {
24
40
  return (await fs.readdir(dir))
@@ -174,7 +190,9 @@ export async function readConfigSnapshot(configDir, liveSettings, lang) {
174
190
  return {
175
191
  platforms: await readPlatformSettings(path.join(configDir, '.env')),
176
192
  budget: parseBudget(budget), profiles: parseProfiles(profiles), machines: parseMachines(machines),
177
- mcp: parseMcp(mcp), threadTemplates, hooks, env, settings,
193
+ mcp: parseMcp(mcp), threadTemplates,
194
+ agents: await readAgentEntries(path.join(tt, 'agents'), agents),
195
+ hooks, env, settings,
178
196
  ...(lang ? { lang } : {}),
179
197
  };
180
198
  }
@@ -61,7 +61,6 @@ export async function handleExecutionsGet(deps, params) {
61
61
  tmuxName: e.dispatch.tmuxName ?? null,
62
62
  sessionName: e.dispatch.sessionName ?? null,
63
63
  scheduleTaskId: e.dispatch.scheduleTaskId ?? null,
64
- runName: e.dispatch.runName ?? null,
65
64
  }
66
65
  : null,
67
66
  metrics: {
@@ -69,7 +68,6 @@ export async function handleExecutionsGet(deps, params) {
69
68
  numTurns: e.metrics?.numTurns ?? null,
70
69
  durationS: e.metrics?.durationS ?? null,
71
70
  },
72
- gpu: e.gpu ?? null,
73
71
  text: {
74
72
  label: e.text?.label ?? null,
75
73
  finalOutput: e.text?.finalOutput ?? null,
@@ -1,10 +1,7 @@
1
1
  import { buildProbeCommand, parseMachineProbe, PROBE_TIMEOUT_MS } from './machine-probe.js';
2
- /**
3
- * Running dispatch executions on this machine. `gpuIndices` is the ordinal set the client watcher
4
- * actually acquired for the run — the only recorded run↔GPU link, which is what lets the UI badge a
5
- * GPU row with its owning run. Process pids are deliberately NOT matched: dispatch.pid is the
6
- * cortex-run launcher, not the CUDA process, so any such join would be fabricated.
7
- */
2
+ /** Running dispatch executions on this machine. Process pids are deliberately NOT matched against
3
+ * the GPU probe: dispatch.pid is the launcher, not the CUDA process, so any such join would be
4
+ * fabricated. */
8
5
  function collectLiveRuns(deps, machine) {
9
6
  return deps.executionRegistry
10
7
  .getAll()
@@ -12,9 +9,7 @@ function collectLiveRuns(deps, machine) {
12
9
  .map((exec) => ({
13
10
  executionId: String(exec.id),
14
11
  taskId: exec.dispatch?.taskId ?? null,
15
- runName: exec.dispatch?.runName ?? null,
16
12
  project: exec.project ?? null,
17
- gpuIndices: Array.isArray(exec.gpu?.indices) ? exec.gpu.indices : [],
18
13
  startedAt: exec.runtime?.startedAt ?? null,
19
14
  }));
20
15
  }
@@ -5,7 +5,7 @@
5
5
  // absolute paths, and symlink escape are rejected. No write API is used.
6
6
  import * as fs from 'node:fs';
7
7
  import * as path from 'node:path';
8
- import { execFileSync } from 'node:child_process';
8
+ import { runFile } from '../../../core/exec-async.js';
9
9
  // Canonical top-level memory files, in display order. Missing ones are omitted (not errored).
10
10
  const TOP_LEVEL_FILES = ['mission.md', 'roadmap.md', 'STATUS.md', 'TASKS.yaml'];
11
11
  // Memory subdirectories whose `*.md` entries are counted (excluding the auto-generated index.md).
@@ -81,7 +81,7 @@ export async function handleMemoryTree(deps, params) {
81
81
  return [];
82
82
  }
83
83
  const entries = dirents
84
- .filter((e) => e.isFile() && e.name.endsWith('.md') && e.name !== 'index.md' && e.name !== 'CORTEX.md')
84
+ .filter((e) => e.isFile() && e.name.endsWith('.md') && e.name !== 'index.md' && e.name !== 'AGENTS.md')
85
85
  .map((e) => {
86
86
  const st = fs.statSync(path.join(abs, e.name));
87
87
  return { name: e.name, sizeBytes: st.size, modifiedAt: st.mtime.toISOString() };
@@ -95,22 +95,17 @@ export async function handleMemoryTree(deps, params) {
95
95
  // never fabricated) when the project dir is not a git work tree, git is unavailable, or the diff is
96
96
  // binary/unresolvable. Read-only; array args (no shell) — `relPath` is the already-validated
97
97
  // project-relative path, so there is no injection surface.
98
- function gitLineDiff(root, relPath) {
99
- let out;
100
- try {
101
- out = execFileSync('git', ['diff', '--numstat', 'HEAD', '--', relPath], {
102
- cwd: root,
103
- encoding: 'utf8',
104
- timeout: 5000,
105
- maxBuffer: 1024 * 1024,
106
- stdio: ['ignore', 'pipe', 'ignore'],
107
- env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
108
- });
109
- }
110
- catch {
111
- // git missing / not a repo / non-zero exit → unknown, not fabricated.
98
+ async function gitLineDiff(root, relPath) {
99
+ const result = await runFile('git', ['diff', '--numstat', 'HEAD', '--', relPath], {
100
+ cwd: root,
101
+ timeoutMs: 5000,
102
+ maxBuffer: 1024 * 1024,
103
+ env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
104
+ });
105
+ // git missing / not a repo / non-zero exit → unknown, not fabricated.
106
+ if (!result.ok)
112
107
  return null;
113
- }
108
+ const out = result.stdout;
114
109
  const line = out.split('\n').find((l) => l.trim().length > 0);
115
110
  // No diff vs HEAD (e.g. a clean auto-committed file) → the real answer is 0/0.
116
111
  if (!line)
@@ -166,36 +161,35 @@ export function parseBlamePorcelain(out) {
166
161
  // Real per-line blame (commit hash + parsed task ref). Returns null (honest placeholder, never
167
162
  // fabricated) when the project dir is not a git work tree, git is unavailable, or the file is
168
163
  // binary/unblameable. Read-only; array args (no shell) — `relPath` is already validated.
169
- function gitBlame(root, relPath) {
170
- let out;
171
- try {
172
- out = execFileSync('git', ['blame', '--line-porcelain', 'HEAD', '--', relPath], {
173
- cwd: root,
174
- encoding: 'utf8',
175
- timeout: 5000,
176
- maxBuffer: 8 * 1024 * 1024,
177
- stdio: ['ignore', 'pipe', 'ignore'],
178
- env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
179
- });
180
- }
181
- catch {
182
- // git missing / not a repo / binary / non-zero exit → unknown, not fabricated.
164
+ async function gitBlame(root, relPath) {
165
+ const result = await runFile('git', ['blame', '--line-porcelain', 'HEAD', '--', relPath], {
166
+ cwd: root,
167
+ timeoutMs: 5000,
168
+ maxBuffer: 8 * 1024 * 1024,
169
+ env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
170
+ });
171
+ // git missing / not a repo / binary / non-zero exit → unknown, not fabricated.
172
+ if (!result.ok)
183
173
  return null;
184
- }
185
- return parseBlamePorcelain(out);
174
+ return parseBlamePorcelain(result.stdout);
186
175
  }
187
176
  export async function handleMemoryFile(deps, params) {
188
177
  const root = resolveProjectRoot(deps, params.projectId);
189
178
  const abs = resolveMemoryFilePath(root, params.path);
190
179
  const st = fs.statSync(abs);
191
180
  const content = fs.readFileSync(abs, 'utf8');
181
+ // Both git probes are independent child processes: run them concurrently.
182
+ const [lineDiff, blame] = await Promise.all([
183
+ gitLineDiff(root, params.path),
184
+ gitBlame(root, params.path),
185
+ ]);
192
186
  return {
193
187
  projectId: params.projectId,
194
188
  path: params.path,
195
189
  content,
196
190
  sizeBytes: st.size,
197
191
  modifiedAt: st.mtime.toISOString(),
198
- lineDiff: gitLineDiff(root, params.path),
199
- blame: gitBlame(root, params.path),
192
+ lineDiff,
193
+ blame,
200
194
  };
201
195
  }