@cortex-agent/server 2026.9.21 → 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 (139) hide show
  1. package/defaults/config/thread-templates/agents/creative.json +17 -0
  2. package/defaults/prompts/systemPrompts/creative.md +13 -0
  3. package/defaults/prompts/systemPrompts/direct.md +1 -1
  4. package/dist/agent-adapter/claude/adapter.d.ts +12 -0
  5. package/dist/agent-adapter/claude/adapter.js +19 -1
  6. package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
  7. package/dist/agent-adapter/claude/spawn-args.js +10 -0
  8. package/dist/agent-adapter/pi/child-runner.d.ts +4 -2
  9. package/dist/agent-adapter/pi/child-runner.js +5 -1
  10. package/dist/agent-adapter/pi/event-parser.d.ts +3 -2
  11. package/dist/agent-adapter/pi/event-parser.js +46 -2
  12. package/dist/agent-adapter/pi/extensions.d.ts +7 -1
  13. package/dist/agent-adapter/pi/extensions.js +10 -3
  14. package/dist/agent-adapter/pi/mcp-bridge.js +8 -8
  15. package/dist/agent-adapter/pi/pi-session.js +5 -0
  16. package/dist/agent-adapter/pi/runtime.js +3 -0
  17. package/dist/agent-adapter/pi/session-options.js +5 -1
  18. package/dist/agent-adapter/pi/subagent.d.ts +15 -3
  19. package/dist/agent-adapter/pi/subagent.js +18 -0
  20. package/dist/agent-adapter/pi/tool-shims.d.ts +6 -1
  21. package/dist/agent-adapter/pi/tool-shims.js +34 -1
  22. package/dist/agent-adapter/types.d.ts +5 -0
  23. package/dist/core/agents/subagent/types.d.ts +3 -0
  24. package/dist/core/config-generator.js +17 -2
  25. package/dist/core/debug-mode.d.ts +11 -10
  26. package/dist/core/debug-mode.js +12 -18
  27. package/dist/core/exec-async.d.ts +26 -0
  28. package/dist/core/exec-async.js +47 -0
  29. package/dist/core/locales/en.d.ts +14 -1
  30. package/dist/core/locales/slices/commands.d.ts +12 -1
  31. package/dist/core/locales/slices/commands.js +24 -2
  32. package/dist/core/locales/slices/startup.d.ts +2 -0
  33. package/dist/core/locales/slices/startup.js +4 -0
  34. package/dist/core/rebuild-progress.d.ts +58 -0
  35. package/dist/core/rebuild-progress.js +103 -0
  36. package/dist/core/resilient-watch.js +5 -3
  37. package/dist/core/run-registry.d.ts +7 -0
  38. package/dist/core/run-registry.js +6 -0
  39. package/dist/core/types/thread-types.d.ts +23 -4
  40. package/dist/domain/agents/agent-state.d.ts +7 -0
  41. package/dist/domain/agents/agent-state.js +9 -1
  42. package/dist/domain/agents/agent-switch.d.ts +38 -0
  43. package/dist/domain/agents/agent-switch.js +106 -0
  44. package/dist/domain/agents/config.d.ts +20 -2
  45. package/dist/domain/agents/config.js +58 -4
  46. package/dist/domain/agents/index.d.ts +1 -0
  47. package/dist/domain/agents/index.js +1 -0
  48. package/dist/domain/agents/profile-manager.d.ts +6 -0
  49. package/dist/domain/agents/profile-manager.js +14 -1
  50. package/dist/domain/executions/registry.d.ts +2 -0
  51. package/dist/domain/executions/registry.js +84 -7
  52. package/dist/domain/plugins/runtime.js +1 -1
  53. package/dist/domain/plugins/skill-projection.d.ts +8 -2
  54. package/dist/domain/plugins/skill-projection.js +76 -19
  55. package/dist/domain/remote/client-bootstrap.js +1 -1
  56. package/dist/domain/remote/client-hot-reload.d.ts +1 -1
  57. package/dist/domain/remote/client-hot-reload.js +27 -23
  58. package/dist/domain/runs/engine-spec.js +4 -0
  59. package/dist/domain/runs/request.d.ts +6 -0
  60. package/dist/domain/runs/run.js +1 -0
  61. package/dist/domain/runs/spec-loader.d.ts +4 -3
  62. package/dist/domain/runs/spec-loader.js +4 -3
  63. package/dist/domain/scheduling/jobs/sync-public.js +6 -6
  64. package/dist/domain/scheduling/scheduler.js +14 -12
  65. package/dist/domain/sessions/session-lifecycle.d.ts +5 -0
  66. package/dist/domain/sessions/session-lifecycle.js +13 -1
  67. package/dist/domain/system/rebuild-hold.d.ts +44 -0
  68. package/dist/domain/system/rebuild-hold.js +91 -0
  69. package/dist/domain/system/server-update-check.d.ts +2 -1
  70. package/dist/domain/system/server-update-check.js +15 -13
  71. package/dist/domain/tasks/archiver.js +21 -13
  72. package/dist/domain/tasks/mutator.js +60 -59
  73. package/dist/domain/tasks/system/task-completion.d.ts +7 -2
  74. package/dist/domain/tasks/system/task-completion.js +69 -6
  75. package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -1
  76. package/dist/domain/tasks/system/task-lifecycle-edit.js +21 -2
  77. package/dist/domain/tasks/system/task-lock.d.ts +23 -0
  78. package/dist/domain/tasks/system/task-lock.js +29 -1
  79. package/dist/domain/tasks/system/task-mutations.d.ts +14 -1
  80. package/dist/domain/tasks/system/task-mutations.js +25 -2
  81. package/dist/domain/tasks/system/task-state.d.ts +12 -1
  82. package/dist/domain/tasks/system/task-state.js +19 -2
  83. package/dist/domain/threads/prompt-builder.d.ts +9 -6
  84. package/dist/domain/threads/prompt-builder.js +28 -10
  85. package/dist/domain/threads/runner.js +7 -3
  86. package/dist/domain/threads/state-machine.js +15 -11
  87. package/dist/domain/threads/template-loader.js +6 -4
  88. package/dist/domain/threads/template-validate.d.ts +43 -6
  89. package/dist/domain/threads/template-validate.js +12 -0
  90. package/dist/domain/ui-service/app-router.d.ts +10 -0
  91. package/dist/domain/ui-service/app-router.js +2 -1
  92. package/dist/domain/ui-service/input-schemas.d.ts +11 -0
  93. package/dist/domain/ui-service/input-schemas.js +11 -0
  94. package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
  95. package/dist/domain/ui-service/mutate/sessions.js +40 -0
  96. package/dist/domain/ui-service/mutate/tasks.js +4 -3
  97. package/dist/domain/ui-service/query/config.js +19 -1
  98. package/dist/domain/ui-service/query/memory.js +28 -34
  99. package/dist/domain/ui-service/query/sessions.js +89 -12
  100. package/dist/domain/ui-service/query/system.js +19 -0
  101. package/dist/domain/ui-service/query-input-schemas.d.ts +1 -0
  102. package/dist/domain/ui-service/query-input-schemas.js +2 -0
  103. package/dist/domain/ui-service/types.d.ts +97 -3
  104. package/dist/domain/ui-service/ui-service.js +2 -1
  105. package/dist/entry/app.js +23 -4
  106. package/dist/entry/daemon-notice.d.ts +10 -1
  107. package/dist/entry/daemon-notice.js +16 -1
  108. package/dist/entry/daemon.d.ts +43 -2
  109. package/dist/entry/daemon.js +163 -9
  110. package/dist/orchestration/agent-runner.js +16 -0
  111. package/dist/orchestration/conversation-request.d.ts +33 -0
  112. package/dist/orchestration/conversation-request.js +78 -16
  113. package/dist/orchestration/mid-turn-inject.d.ts +3 -0
  114. package/dist/orchestration/mid-turn-inject.js +9 -4
  115. package/dist/orchestration/resume-dispatcher.js +4 -2
  116. package/dist/orchestration/routing/commands/mode.js +114 -63
  117. package/dist/orchestration/thread-executor.js +13 -0
  118. package/dist/orchestration/turn/turn.js +1 -0
  119. package/dist/store/conversation-display-projection.d.ts +9 -1
  120. package/dist/store/conversation-display-projection.js +13 -6
  121. package/dist/store/conversation-history-reader.d.ts +19 -0
  122. package/dist/store/conversation-history-reader.js +163 -44
  123. package/dist/store/conversation-history-repo.d.ts +37 -10
  124. package/dist/store/conversation-history-repo.js +161 -139
  125. package/dist/store/session-registry-journal.d.ts +4 -0
  126. package/dist/store/session-registry-journal.js +4 -0
  127. package/dist/store/session-registry-repo.d.ts +2 -1
  128. package/dist/store/session-registry-repo.js +2 -0
  129. package/dist/store/task-repo.d.ts +6 -3
  130. package/dist/store/task-repo.js +26 -10
  131. package/package.json +2 -1
  132. package/web/dist/AGENTS.md +10 -0
  133. package/web/dist/assets/index-B1dBi8Za.css +1 -0
  134. package/web/dist/assets/{index-DZTuqUO4.js → index-BAeLybF0.js} +1 -1
  135. package/web/dist/assets/index-BcQI8Fh5.js +445 -0
  136. package/web/dist/index.html +12 -4
  137. package/web/dist/theme.css +211 -40
  138. package/web/dist/assets/index-CwwQNMpP.css +0 -1
  139. package/web/dist/assets/index-DLSfgq3o.js +0 -444
@@ -41,7 +41,7 @@ export type Err = {
41
41
  };
42
42
  export type Result<T> = Ok<T> | Err;
43
43
  export type QueryScope = 'projects.list' | 'sessions.list' | 'sessions.transcript' | 'sessions.subagentTranscript' | 'sessions.debugDetails' | 'sessions.pendingInteraction' | 'threads.list' | 'threads.get' | 'tasks.list' | 'tasks.verification' | 'schedules.list' | 'commissions.list' | 'commissions.get' | 'commissions.decisions' | 'executions.list' | 'executions.get' | 'memory.tree' | 'memory.file' | 'approvals.list' | 'issues.list' | 'notes.list' | 'cost.summary' | 'config.get' | 'auth.status' | 'auth.flowState' | 'auth.customProviders' | 'models.catalog' | 'hooks.list' | 'machines.list' | 'machines.detail' | 'skills.list' | 'plugins.list' | 'plugins.skillFile' | 'plugins.mcpRead' | 'threadTemplates.get' | 'threadTemplates.detail' | 'system.daemonStatus' | 'system.rateLimitStatus' | 'system.usageStatus' | 'system.notices' | 'system.updateStatus' | 'waitpoints.list';
44
- export type MutateOp = 'projects.create' | 'sessions.create' | 'sessions.send' | 'sessions.cancel' | 'sessions.compact' | 'sessions.setProfile' | 'sessions.setSelection' | 'sessions.setCommission' | 'sessions.createAndSend' | 'sessions.markRead' | 'sessions.markManyRead' | 'sessions.answerQuestion' | 'sessions.respondPlan' | 'sessions.respondDecision' | 'sessions.cancelResume' | 'sessions.rewind' | 'threads.cancel' | 'executions.cancel' | 'waitpoints.cancel' | 'schedules.pause' | 'schedules.resume' | 'schedules.remove' | 'schedules.add' | 'schedules.update' | 'commissions.close' | 'tasks.claim' | 'tasks.unclaim' | 'tasks.complete' | 'tasks.block' | 'tasks.unblock' | 'approvals.approve' | 'approvals.reject' | 'approvals.request' | 'issues.handle' | 'issues.delete' | 'notes.add' | 'notes.update' | 'notes.setCompleted' | 'notes.delete' | 'notes.clearCompleted' | 'config.set' | 'config.setPlatform' | 'config.setProviderRateLimitPolicy' | 'auth.startLogin' | 'auth.respondPrompt' | 'auth.cancelFlow' | 'auth.logout' | 'auth.syncGateway' | 'auth.upsertCustomProvider' | 'auth.removeCustomProvider' | 'hooks.create' | 'hooks.update' | 'hooks.setEnabled' | 'hooks.remove' | 'hooks.test' | 'profiles.create' | 'profiles.update' | 'profiles.remove' | 'plugins.assign' | 'plugins.skillWrite' | 'plugins.skillCreate' | 'plugins.skillMove' | 'plugins.skillRemove' | 'plugins.create' | 'plugins.remove' | 'plugins.convertToPortable' | 'plugins.mcpWrite' | 'threadTemplates.validate' | 'threadTemplates.save' | 'threadTemplates.remove' | 'system.restart' | 'system.clearRateLimit' | 'system.refreshUsage' | 'system.applyUpdate' | 'system.skipUpdate';
44
+ export type MutateOp = 'projects.create' | 'sessions.create' | 'sessions.send' | 'sessions.cancel' | 'sessions.compact' | 'sessions.setProfile' | 'sessions.setAgent' | 'sessions.setSelection' | 'sessions.setCommission' | 'sessions.createAndSend' | 'sessions.markRead' | 'sessions.markManyRead' | 'sessions.answerQuestion' | 'sessions.respondPlan' | 'sessions.respondDecision' | 'sessions.cancelResume' | 'sessions.rewind' | 'threads.cancel' | 'executions.cancel' | 'waitpoints.cancel' | 'schedules.pause' | 'schedules.resume' | 'schedules.remove' | 'schedules.add' | 'schedules.update' | 'commissions.close' | 'tasks.claim' | 'tasks.unclaim' | 'tasks.complete' | 'tasks.block' | 'tasks.unblock' | 'approvals.approve' | 'approvals.reject' | 'approvals.request' | 'issues.handle' | 'issues.delete' | 'notes.add' | 'notes.update' | 'notes.setCompleted' | 'notes.delete' | 'notes.clearCompleted' | 'config.set' | 'config.setPlatform' | 'config.setProviderRateLimitPolicy' | 'auth.startLogin' | 'auth.respondPrompt' | 'auth.cancelFlow' | 'auth.logout' | 'auth.syncGateway' | 'auth.upsertCustomProvider' | 'auth.removeCustomProvider' | 'hooks.create' | 'hooks.update' | 'hooks.setEnabled' | 'hooks.remove' | 'hooks.test' | 'profiles.create' | 'profiles.update' | 'profiles.remove' | 'plugins.assign' | 'plugins.skillWrite' | 'plugins.skillCreate' | 'plugins.skillMove' | 'plugins.skillRemove' | 'plugins.create' | 'plugins.remove' | 'plugins.convertToPortable' | 'plugins.mcpWrite' | 'threadTemplates.validate' | 'threadTemplates.save' | 'threadTemplates.remove' | 'system.restart' | 'system.clearRateLimit' | 'system.refreshUsage' | 'system.applyUpdate' | 'system.skipUpdate';
45
45
  export interface SubscribeFilter {
46
46
  events: string[];
47
47
  projectId?: string | null;
@@ -67,6 +67,9 @@ export interface SessionsListParams {
67
67
  export interface SessionsTranscriptParams {
68
68
  sessionId: string;
69
69
  compactSubagents?: boolean;
70
+ /** Cursor from a previous response's `cursor`. Compact reads only; a matching cursor is answered
71
+ * with a `delta` instead of the whole transcript. */
72
+ since?: string;
70
73
  }
71
74
  export interface SessionsSubagentTranscriptParams {
72
75
  sessionId: string;
@@ -292,6 +295,13 @@ export interface SessionsSetProfileArgs {
292
295
  /** The profile to switch the session to. Must exist in profiles.json. */
293
296
  profileName: string;
294
297
  }
298
+ export interface SessionsSetAgentArgs {
299
+ sessionId: string;
300
+ /** The agent template to run this session as — its execution environment. `null` (or an absent
301
+ * field, which the browser client sends instead — see `sessionsSetAgentInput`) hands the session
302
+ * back to the global default agent. */
303
+ agentName?: string | null;
304
+ }
295
305
  /** The part of a session's engine selection that came from the user rather than from its profile.
296
306
  * Every field is optional: a session may override only its thinking level, only its model, or any
297
307
  * mix. Backend is never here — it belongs to the profile (and a live conversation cannot change it). */
@@ -401,6 +411,9 @@ export interface SessionsCreateAndSendArgs {
401
411
  projectId: string;
402
412
  /** The profile to create the session with. Omitted → system default. */
403
413
  profileName?: string;
414
+ /** The agent template — the environment — the new session runs as. Omitted → whatever the
415
+ * global default agent is. Applied at creation, so the first turn already runs in it. */
416
+ agentName?: string;
404
417
  /** The model / provider / thinking the draft composer had selected on top of that profile.
405
418
  * Omitted (or empty) → the profile's own values: this call always comes from a composer, so
406
419
  * "nothing overridden" is a statement ("run the profile as declared"), not silence, and is
@@ -626,6 +639,10 @@ export interface SessionInfo {
626
639
  /** The session's active agent profile (registry record). Null when never explicitly set — the
627
640
  * client falls back to the config default. Kept in sync by the shared profile-switch rule. */
628
641
  profileName: string | null;
642
+ /** The agent template the session runs as — its environment (prompt, tools, skills, rules), the
643
+ * other half of "what will the next turn be". Null when the session follows its channel's
644
+ * selection and, beneath that, the global default. Kept in sync by the agent-switch rule. */
645
+ agentName?: string | null;
629
646
  /** What the user selected on top of that profile (model / provider / thinking), or null when the
630
647
  * session runs its profile as declared. The composer needs both halves to show what the next turn
631
648
  * will actually run; the profile alone would lie whenever a model was picked. */
@@ -839,6 +856,18 @@ export interface TranscriptSubagentSummary {
839
856
  hasDetails: boolean;
840
857
  structurallyOpen: boolean;
841
858
  }
859
+ /** Rows that changed since a client's cursor, addressed by flat position across the transcript. */
860
+ export interface TranscriptDeltaRow {
861
+ /** Position in the flattened row stream (turns concatenated in order). */
862
+ index: number;
863
+ turnIndex: number;
864
+ message: TranscriptMessage;
865
+ }
866
+ export interface TranscriptDelta {
867
+ changed: TranscriptDeltaRow[];
868
+ /** Row count now. A client drops anything at or past it, which is how a rewind shortens. */
869
+ total: number;
870
+ }
842
871
  export interface SessionTranscript {
843
872
  sessionId: string;
844
873
  turns: TranscriptTurn[];
@@ -847,6 +876,12 @@ export interface SessionTranscript {
847
876
  pendingUserMessages?: PendingTranscriptUserMessage[];
848
877
  /** Compact opt-in only. Present even when empty; absent on full transcript responses. */
849
878
  subagentSummaries?: TranscriptSubagentSummary[];
879
+ /** Compact opt-in only. Pass back as `since` to get the next response as a delta. Absent when
880
+ * the server cannot serve deltas for this read. */
881
+ cursor?: string;
882
+ /** Present INSTEAD of a populated `turns` when the response answers a `since` cursor. A client
883
+ * that does not understand it must not send `since`. */
884
+ delta?: TranscriptDelta;
850
885
  }
851
886
  export interface SessionSubagentTranscript {
852
887
  sessionId: string;
@@ -1247,6 +1282,14 @@ export interface ConfigThreadTemplates {
1247
1282
  templates: string[];
1248
1283
  shells: string[];
1249
1284
  }
1285
+ /** One agent template as a picker needs it: what it is for, and which profile it pins (or
1286
+ * `__active__` — it runs whatever the conversation's own profile resolves to). Richer than
1287
+ * {@link ConfigThreadTemplates.agents}, which is the bare file listing the config editor uses. */
1288
+ export interface ConfigAgentEntry {
1289
+ name: string;
1290
+ description?: string;
1291
+ profile: string;
1292
+ }
1250
1293
  export interface ConfigEnvEntry {
1251
1294
  key: string;
1252
1295
  present: boolean;
@@ -1371,6 +1414,9 @@ export interface HooksTestReturn {
1371
1414
  * nobody has picked anything yet — the composer then falls back to the default profile. */
1372
1415
  export interface ConfigSelectionDefault extends SessionSelectionOverride {
1373
1416
  profileName?: string;
1417
+ /** The agent the last composer pick ran as — a draft opens in the environment the previous
1418
+ * conversation was working in, the same way it opens on its profile. */
1419
+ agentName?: string;
1374
1420
  }
1375
1421
  export interface ConfigSnapshot {
1376
1422
  platforms?: PlatformSettingsSnapshot[];
@@ -1379,6 +1425,9 @@ export interface ConfigSnapshot {
1379
1425
  machines: ConfigMachine[];
1380
1426
  mcp: ConfigMcp | null;
1381
1427
  threadTemplates: ConfigThreadTemplates;
1428
+ /** The agent templates a composer may pick from, with what each one is and pins. Always emitted
1429
+ * by current servers; optional while clients and servers roll independently. */
1430
+ agents?: ConfigAgentEntry[];
1382
1431
  hooks: ConfigHook[];
1383
1432
  env: ConfigEnvEntry[];
1384
1433
  /** Always emitted by current servers; optional while clients and servers roll independently. */
@@ -1875,6 +1924,8 @@ export interface IssueInfo {
1875
1924
  body: string;
1876
1925
  }
1877
1926
  export type NoteInfo = ProjectNote;
1927
+ import type { RebuildProgress as DaemonRebuildProgress, RebuildStepState as DaemonRebuildStep, RebuildStepName as DaemonRebuildStepName, RebuildStepStatus as DaemonRebuildStepStatus, RebuildStatus as DaemonRebuildStatus } from '../../core/rebuild-progress.js';
1928
+ export type { DaemonRebuildProgress, DaemonRebuildStep, DaemonRebuildStepName, DaemonRebuildStepStatus, DaemonRebuildStatus, };
1878
1929
  export interface DaemonProcessInfo {
1879
1930
  name: string;
1880
1931
  label: string;
@@ -1890,6 +1941,10 @@ export interface SystemDaemonStatus {
1890
1941
  at: string | null;
1891
1942
  reason: string | null;
1892
1943
  };
1944
+ /** The supervisor's hot-rebuild pipeline: the run in flight, or the last one it finished. Null
1945
+ * when no rebuild has run (production installs never rebuild) or when the record belongs to a
1946
+ * supervisor that is no longer alive. */
1947
+ rebuild: DaemonRebuildProgress | null;
1893
1948
  }
1894
1949
  export type SystemNoticesParams = {
1895
1950
  limit?: number;
@@ -1991,6 +2046,15 @@ export interface SessionsSetProfileReturn {
1991
2046
  /** True when the switch moved to a different backend (only possible on a session with no history). */
1992
2047
  backendChanged: boolean;
1993
2048
  }
2049
+ export interface SessionsSetAgentReturn {
2050
+ /** The agent now selected for the session; null when it follows the global default again. */
2051
+ agentName: string | null;
2052
+ /** The profile that agent will run under — its own when it pins one, the channel's otherwise.
2053
+ * For display: the switch never writes the channel's profile. */
2054
+ profileName: string;
2055
+ /** True when the switch moved to a different backend (only possible on a session with no history). */
2056
+ backendChanged: boolean;
2057
+ }
1994
2058
  /** What the session will run on its next turn, after the change — effective values, so the client
1995
2059
  * can render the chip without re-deriving the profile/override layering. */
1996
2060
  export interface SessionsSetSelectionReturn {
@@ -2150,6 +2214,7 @@ export interface MutateArgsMap {
2150
2214
  'sessions.cancel': SessionsCancelArgs;
2151
2215
  'sessions.compact': SessionsCompactArgs;
2152
2216
  'sessions.setProfile': SessionsSetProfileArgs;
2217
+ 'sessions.setAgent': SessionsSetAgentArgs;
2153
2218
  'sessions.setSelection': SessionsSetSelectionArgs;
2154
2219
  'sessions.setCommission': SessionsSetCommissionArgs;
2155
2220
  'sessions.createAndSend': SessionsCreateAndSendArgs;
@@ -2227,6 +2292,7 @@ export interface MutateReturnMap {
2227
2292
  'sessions.cancel': SessionsCancelReturn;
2228
2293
  'sessions.compact': SessionsCompactReturn;
2229
2294
  'sessions.setProfile': SessionsSetProfileReturn;
2295
+ 'sessions.setAgent': SessionsSetAgentReturn;
2230
2296
  'sessions.setSelection': SessionsSetSelectionReturn;
2231
2297
  'sessions.setCommission': SessionsSetCommissionReturn;
2232
2298
  'sessions.createAndSend': SessionsCreateAndSendReturn;
@@ -2341,8 +2407,10 @@ export interface UiServiceDeps {
2341
2407
  * facade/test fixtures need not provide it (the handler no-ops when absent). */
2342
2408
  markRead?(sessionId: string): Promise<void>;
2343
2409
  };
2344
- /** Capability hint for sessions.list; execution revalidates inside orchestration. */
2345
- supportsSessionCompaction?: (session: Session) => boolean;
2410
+ /** Capability hint for sessions.list; execution revalidates inside orchestration. Narrowed to
2411
+ * the two fields the answer depends on so the list can answer it once per distinct profile
2412
+ * instead of once per row. */
2413
+ supportsSessionCompaction?: (session: Pick<Session, 'backend' | 'profileName'>) => boolean;
2346
2414
  /** Latest task-list snapshot for a session (in-memory registry). Optional so facade/test
2347
2415
  * fixtures need not provide it — absent means the session reports no task list. */
2348
2416
  getSessionTodos?: (sessionId: string) => TodoSnapshot | null;
@@ -2363,6 +2431,12 @@ export interface UiServiceDeps {
2363
2431
  includeToolDebug?: boolean;
2364
2432
  }): Promise<SessionHistory | null>;
2365
2433
  getCompactHistory?(sessionId: string): Promise<import('../../store/conversation-history-repo.js').CompactConversationHistory | null>;
2434
+ /** Compact history plus the cursor that makes the next read a delta. Optional: a store without
2435
+ * it simply never serves deltas. */
2436
+ getCompactHistoryAt?(sessionId: string): Promise<{
2437
+ value: import('../../store/conversation-history-repo.js').CompactConversationHistory | null;
2438
+ cursor: string;
2439
+ }>;
2366
2440
  getSubagentHistory?(sessionId: string, subagentId: string): Promise<import('../../store/conversation-history-repo.js').SubagentConversationHistory>;
2367
2441
  getToolDebugDetails?(sessionId: string, toolRef: string): Promise<TranscriptDebugDetails | null>;
2368
2442
  /** First user message text — used to title a label-less session in `sessions.list`. Optional so
@@ -2436,6 +2510,7 @@ export interface UiServiceDeps {
2436
2510
  projectId: string;
2437
2511
  sessionId?: string;
2438
2512
  profileName?: string | null;
2513
+ agentName?: string | null;
2439
2514
  selection?: SessionSelectionOverride | null;
2440
2515
  browser?: {
2441
2516
  device: string;
@@ -2491,6 +2566,25 @@ export interface UiServiceDeps {
2491
2566
  backendChanged: boolean;
2492
2567
  reason?: 'unknown-profile' | 'cross-backend-live-session';
2493
2568
  }>;
2569
+ /**
2570
+ * Switch the agent — the execution environment — a session's channel runs, under the shared
2571
+ * agent-switch rule (the same `switchChannelAgent` the Slack/Feishu `!agent` command uses). A
2572
+ * null name clears the channel's selection. Wired in the entry layer (app.ts) for the same reason
2573
+ * as the profile switch above: the ui-service domain never imports domain/agents.
2574
+ */
2575
+ switchSessionAgent?: (opts: {
2576
+ channel: string;
2577
+ name: string | null;
2578
+ }) => Promise<{
2579
+ ok: boolean;
2580
+ agentName: string | null;
2581
+ /** The profile the agent will run under, for display. */
2582
+ effectiveProfile: string;
2583
+ backendChanged: boolean;
2584
+ reason?: 'unknown-agent' | 'cross-backend-live-session';
2585
+ currentBackend?: string;
2586
+ targetBackend?: string;
2587
+ }>;
2494
2588
  /**
2495
2589
  * Apply a session's engine selection (profile and/or model / provider / thinking) under the
2496
2590
  * shared rule — the domain `applyChannelSelection`, wired in the entry layer (app.ts) so the
@@ -37,7 +37,7 @@ import { handleThreadTemplatesValidate, handleThreadTemplatesSave, handleThreadT
37
37
  import { handlePluginsAssign } from './mutate/plugins.js';
38
38
  import { handlePluginsSkillWrite, handlePluginsSkillCreate, handlePluginsSkillMove, handlePluginsSkillRemove, handlePluginsCreate, handlePluginsRemove, handlePluginsConvertToPortable, handlePluginsMcpWrite, } from './mutate/plugin-packages.js';
39
39
  import { handleCreateProject } from './mutate/projects.js';
40
- import { handleCreateSession, handleSendSession, handleCancelSession, handleCompactSession, handleSetProfile, handleSetSelection, handleSetCommission, handleCreateAndSend, handleMarkReadSession, handleMarkManyReadSessions, handleAnswerQuestion, handleRespondPlan, handleRespondDecision, handleCancelResume, handleRewindSession } from './mutate/sessions.js';
40
+ import { handleCreateSession, handleSendSession, handleCancelSession, handleCompactSession, handleSetProfile, handleSetAgent, handleSetSelection, handleSetCommission, handleCreateAndSend, handleMarkReadSession, handleMarkManyReadSessions, handleAnswerQuestion, handleRespondPlan, handleRespondDecision, handleCancelResume, handleRewindSession } from './mutate/sessions.js';
41
41
  import { handleCancelThread } from './mutate/threads.js';
42
42
  import { handleCancelExecution } from './mutate/executions.js';
43
43
  import { handleCancelWaitpoint } from './mutate/waitpoints.js';
@@ -102,6 +102,7 @@ const mutateHandlers = {
102
102
  'sessions.cancel': (deps, args) => handleCancelSession(deps, args),
103
103
  'sessions.compact': (deps, args) => handleCompactSession(deps, args),
104
104
  'sessions.setProfile': (deps, args) => handleSetProfile(deps, args),
105
+ 'sessions.setAgent': (deps, args) => handleSetAgent(deps, args),
105
106
  'sessions.setSelection': (deps, args) => handleSetSelection(deps, args),
106
107
  'sessions.setCommission': (deps, args) => handleSetCommission(deps, args),
107
108
  'sessions.createAndSend': (deps, args) => handleCreateAndSend(deps, args),
package/dist/entry/app.js CHANGED
@@ -102,7 +102,7 @@ import { runSessionRetentionSweep } from '../domain/sessions/session-retention.j
102
102
  import { pruneInboundAttachments } from '../orchestration/attachments-store.js';
103
103
  import { syncClaudeUserCleanupPeriodDays } from '../domain/auth/claude-user-settings.js';
104
104
  import { setSessionAsync, getSessionAsync } from '../domain/sessions/session.js';
105
- import { applyChannelSelection, getChannelOverride, getSelectionDefault, resolveBackendForChannel, switchChannelProfile, } from '../domain/agents/index.js';
105
+ import { applyChannelSelection, clearChannelAgentSelection, getActiveProfile, getChannelOverride, getSelectionDefault, resolveBackendForChannel, switchChannelAgent, switchChannelProfile, } from '../domain/agents/index.js';
106
106
  import { isSessionCompactionSupported } from '../domain/runs/compact.js';
107
107
  import { initDiskMonitor, stopDiskMonitor } from '../domain/monitor/disk-monitor.js';
108
108
  import { startEventLoopMonitor, stopEventLoopMonitor } from '../domain/monitor/event-loop-monitor.js';
@@ -601,6 +601,21 @@ process.on('SIGTERM', async () => {
601
601
  // Web profile switch: apply the shared per-channel profile-switch rule (same one the Slack/Feishu
602
602
  // `!profile` command uses). Wired here so the ui-service domain never imports domain/agents.
603
603
  switchSessionProfile: (opts) => switchChannelProfile(opts),
604
+ // Web agent picker: the same per-channel agent-switch rule the `!agent` command applies. A null
605
+ // name is the "follow the global default" row, which clears the channel's selection instead.
606
+ switchSessionAgent: async ({ channel, name }) => {
607
+ if (name === null) {
608
+ await clearChannelAgentSelection(channel);
609
+ return { ok: true, agentName: null, effectiveProfile: getActiveProfile(channel) ?? '', backendChanged: false };
610
+ }
611
+ const res = await switchChannelAgent({ channel, name });
612
+ return res.ok === true
613
+ ? { ok: true, agentName: res.agentName, effectiveProfile: res.effectiveProfile, backendChanged: res.backendChanged }
614
+ : {
615
+ ok: false, agentName: null, effectiveProfile: '', backendChanged: false,
616
+ reason: res.reason, currentBackend: res.currentBackend, targetBackend: res.targetBackend,
617
+ };
618
+ },
604
619
  // Web model picker: the composer's profile / model / provider / thinking choice, applied under
605
620
  // the one domain rule. Wired here for the same reason as the profile switch above.
606
621
  applySessionSelection: (opts) => applyChannelSelection(opts),
@@ -778,8 +793,10 @@ process.on('SIGTERM', async () => {
778
793
  prewarmPiBackend();
779
794
  startClientManager(parseInt(process.env.CORTEX_CLIENT_PORT || '3002', 10));
780
795
  startClientHotReloadJob(getSettings().clientHotReloadEnabled, () => initClientHotReload((text) => { void emitSystemNotice(adapter, { text }); }), startAllRemoteClients);
781
- // DR-0013: server auto-update — first check after 60s, then every 24h
782
- setTimeout(async () => {
796
+ // DR-0013: server auto-update — first check after 60s, then every 24h.
797
+ // Both timers are unref'd so they never hold the process open, and the default latest-version
798
+ // probe is async (runFile), so neither blocks the event loop.
799
+ const bootUpdateCheck = setTimeout(async () => {
783
800
  try {
784
801
  await checkServerUpdate({ prompt: updatePrompt });
785
802
  }
@@ -787,7 +804,8 @@ process.on('SIGTERM', async () => {
787
804
  log.error(`Server auto-update check failed: ${e.message}`);
788
805
  }
789
806
  }, 60_000);
790
- setInterval(async () => {
807
+ bootUpdateCheck.unref?.();
808
+ const dailyUpdateCheck = setInterval(async () => {
791
809
  try {
792
810
  await checkServerUpdate({ prompt: updatePrompt });
793
811
  }
@@ -795,6 +813,7 @@ process.on('SIGTERM', async () => {
795
813
  log.error(`Server auto-update check failed: ${e.message}`);
796
814
  }
797
815
  }, 24 * 60 * 60 * 1000);
816
+ dailyUpdateCheck.unref?.();
798
817
  await scheduler.start();
799
818
  // One-time migration: resume tasks left paused by the old scheduler-based rate-limit mechanism.
800
819
  // The new provider-aware rate-limit-throttle no longer pauses tasks via the scheduler guard.
@@ -4,6 +4,12 @@ import type { PlatformAdapter } from '../platform/index.js';
4
4
  export interface DaemonMessage {
5
5
  type?: string;
6
6
  text?: string;
7
+ /** 'rebuild-hold': whether new turns must be refused. */
8
+ hold?: boolean;
9
+ /** 'rebuild-hold': the pipeline step in flight, when the supervisor named one. */
10
+ phase?: string | null;
11
+ /** 'rebuild-hold': what triggered the rebuild. */
12
+ reason?: string | null;
7
13
  }
8
14
  /** Broadcast a supervisor-side notice to the admin channel and the Web toaster.
9
15
  *
@@ -13,5 +19,8 @@ export interface DaemonMessage {
13
19
  * change is invisible until someone notices. Logging alone made that failure silent. */
14
20
  export declare function handleDaemonMessage(msg: DaemonMessage | undefined | null, adapter: PlatformAdapter): Promise<boolean>;
15
21
  /** Wire the fork IPC channel to the notice broadcast. No-op when the process was not forked by
16
- * the daemon (standalone `cortex serve`, tests), where `process.send` is undefined. */
22
+ * the daemon (standalone `cortex serve`, tests), where `process.send` is undefined.
23
+ *
24
+ * `disconnect` lifts any hold: the supervisor that asked for it is gone, so nothing is going to
25
+ * restart this process and refusing work would only strand the operator. */
17
26
  export declare function subscribeDaemonNotices(adapter: PlatformAdapter): void;
@@ -1,4 +1,5 @@
1
1
  import { emitSystemNotice } from '../domain/system/system-notice.js';
2
+ import { holdNewTurns, releaseNewTurnHold } from '../domain/system/rebuild-hold.js';
2
3
  /** Broadcast a supervisor-side notice to the admin channel and the Web toaster.
3
4
  *
4
5
  * Returns whether a notice was emitted, so an unrelated IPC message is distinguishable from a
@@ -6,17 +7,31 @@ import { emitSystemNotice } from '../domain/system/system-notice.js';
6
7
  * install+restart, so the process stays on the previously installed build and every later code
7
8
  * change is invisible until someone notices. Logging alone made that failure silent. */
8
9
  export async function handleDaemonMessage(msg, adapter) {
10
+ // Admission control. Silent on purpose: the operator hears about a rebuild through the daemon page
11
+ // and through the abort notice, and a toast per phase would be noise. Handled without a notice, so
12
+ // it returns before the notice branch below.
13
+ if (msg?.type === 'rebuild-hold') {
14
+ if (msg.hold)
15
+ holdNewTurns({ phase: msg.phase ?? null, reason: msg.reason ?? null });
16
+ else
17
+ releaseNewTurnHold();
18
+ return true;
19
+ }
9
20
  if (msg?.type !== 'rebuild-aborted' || !msg.text)
10
21
  return false;
11
22
  await emitSystemNotice(adapter, { level: 'error', title: 'Rebuild', text: msg.text });
12
23
  return true;
13
24
  }
14
25
  /** Wire the fork IPC channel to the notice broadcast. No-op when the process was not forked by
15
- * the daemon (standalone `cortex serve`, tests), where `process.send` is undefined. */
26
+ * the daemon (standalone `cortex serve`, tests), where `process.send` is undefined.
27
+ *
28
+ * `disconnect` lifts any hold: the supervisor that asked for it is gone, so nothing is going to
29
+ * restart this process and refusing work would only strand the operator. */
16
30
  export function subscribeDaemonNotices(adapter) {
17
31
  if (!process.send)
18
32
  return;
19
33
  process.on('message', (msg) => {
20
34
  void handleDaemonMessage(msg, adapter).catch(() => { });
21
35
  });
36
+ process.on('disconnect', () => { releaseNewTurnHold(); });
22
37
  }
@@ -9,6 +9,18 @@
9
9
  * { type: 'rebuild-aborted', text } — pipeline stopped early; app.ts broadcasts it as an
10
10
  * error-level system notice. The daemon has no platform adapter, so this is its only
11
11
  * way to reach the operator.
12
+ * { type: 'rebuild-hold', hold, phase, reason } — admission control for the last seconds before
13
+ * this process is replaced: while `hold` is true the app refuses to START new turns, because a
14
+ * turn spawned now is orphaned by the SIGTERM. Scope is deliberately narrow — the install and
15
+ * restart steps and a queued restart, never the build (see `rebuildHoldsTurns`). Re-sent on every
16
+ * phase change: the app's hold expires on its own, so a daemon that dies mid-pipeline fails open
17
+ * instead of muting the app forever.
18
+ *
19
+ * Rebuild progress:
20
+ * The pipeline publishes its plan and each step transition to STORE_DIR/daemon-rebuild.json
21
+ * (core/rebuild-progress.ts), which `system.daemonStatus` reads for the daemon page. It is a file
22
+ * and not in-app state on purpose: the pipeline's last act replaces the process that would have
23
+ * held it, so only a file can tell the new app what the rebuild it was born from did.
12
24
  *
13
25
  * Restart serialization:
14
26
  * Only ONE restart cycle (stop → start) runs at a time. Concurrent requests
@@ -31,9 +43,21 @@
31
43
  * types and web typechecks against ui-contract's built dist, so skipping the middle package
32
44
  * makes web fail on every newly added server DTO.
33
45
  *
46
+ * Every step is paid on every rebuild, including a web build that a server-only edit almost
47
+ * never changes, so the cost of each is kept down at the package level rather than by skipping
48
+ * steps here: both tsconfigs carry an incremental cache, and web's `build` runs its typecheck
49
+ * and its bundle concurrently. The server's cache lives inside dist/ on purpose — tsc trusts
50
+ * its buildinfo over the filesystem, so a cache that outlived its output would let a deleted
51
+ * dist file stay deleted.
52
+ *
34
53
  * Any step failing → log + notify the operator + skip (no restart), so an abort never looks
35
- * like a no-op restart. busy/idle gating is reused: a rebuild during an in-flight Slack
36
- * request defers the final restart() step until the child reports idle.
54
+ * like a no-op restart.
55
+ *
56
+ * busy/idle gating is checked twice, because only the tail of the pipeline is dangerous to a live
57
+ * turn. Once before the build, and again after it: the build takes minutes, so a turn can have
58
+ * started meanwhile, and everything past that point replaces the files app.js is running from and
59
+ * then kills it. A busy child there parks the reason in `pendingRebuild` and the whole pipeline
60
+ * runs again on the idle transition — waiting for real work to finish, rather than refusing it.
37
61
  *
38
62
  * Manual upgrade workflow (still supported):
39
63
  * npm run build && npm pack && npm install -g ./cortex-agent-server-X.Y.Z.tgz (package: @cortex-agent/server)
@@ -41,6 +65,7 @@
41
65
  * watcher below picks up. In dev mode (CORTEX_REPO set) this triggers the full
42
66
  * rebuild pipeline; in production mode it just respawns app.js.
43
67
  */
68
+ import { type RebuildProgress, type RebuildStepName } from '../core/rebuild-progress.js';
44
69
  declare function buildChildProcessConfig(restartReason?: string | null): {
45
70
  cwd: string;
46
71
  stdio: ("pipe" | "ignore" | "ipc")[];
@@ -72,5 +97,21 @@ export declare function buildRebuildAbortNotice(p: {
72
97
  detail: string;
73
98
  reason: string;
74
99
  }): string;
100
+ /** Which published states close the child's turn gate.
101
+ *
102
+ * Only the two steps that touch the running process: `install` overwrites the files app.js loaded,
103
+ * `restart` kills it. The build steps before them read the repo and write `dist/` — a turn running
104
+ * during those is in no danger, and refusing it would be worse than useless: a refused waitpoint
105
+ * wake or background-agent result is dropped work, not delayed work (2026-09-21). Those two steps
106
+ * are only entered when app.ts is idle anyway, so the gate exists for the tick-level race — a
107
+ * message landing between the idle check and the SIGTERM.
108
+ *
109
+ * A queued restart (`pendingRestart`) holds regardless of the record: the build is over, but the
110
+ * process a turn would run in is still going to be replaced. */
111
+ export declare function rebuildHoldsTurns(progress: Pick<RebuildProgress, 'status' | 'current'> | null, queuedRestart: boolean): boolean;
112
+ /** The steps a checkout will actually run, in order. Derived from `planRebuildSteps` so the build
113
+ * half cannot drift — a package that is absent is never published as pending — plus the two phases
114
+ * the build planner does not own. */
115
+ export declare function planRebuildStepNames(dirs: Parameters<typeof planRebuildSteps>[0]): RebuildStepName[];
75
116
  declare function main(): void;
76
117
  export { main, buildChildProcessConfig };