@cortex-agent/server 2026.10.15-2 → 2026.10.21

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 (171) hide show
  1. package/README.md +70 -31
  2. package/defaults/board/board.css +140 -62
  3. package/defaults/board/scaffold.html +36 -13
  4. package/defaults/plugins/cortex-board/skills/board/SKILL.md +30 -22
  5. package/defaults/plugins/cortex-system/plugin.json +2 -2
  6. package/defaults/plugins/cortex-system/skills/browser/SKILL.md +56 -0
  7. package/dist/agent-adapter/claude/adapter.d.ts +2 -5
  8. package/dist/agent-adapter/claude/adapter.js +6 -5
  9. package/dist/agent-adapter/claude/assistant-blocks.d.ts +5 -0
  10. package/dist/agent-adapter/claude/assistant-blocks.js +61 -0
  11. package/dist/agent-adapter/claude/cache-refresh.d.ts +58 -0
  12. package/dist/agent-adapter/claude/cache-refresh.js +145 -0
  13. package/dist/agent-adapter/claude/cache-touch.d.ts +12 -0
  14. package/dist/agent-adapter/claude/cache-touch.js +75 -0
  15. package/dist/agent-adapter/claude/event-parser.d.ts +8 -3
  16. package/dist/agent-adapter/claude/event-parser.js +33 -17
  17. package/dist/agent-adapter/claude/event-translator.d.ts +2 -0
  18. package/dist/agent-adapter/claude/event-translator.js +2 -0
  19. package/dist/agent-adapter/claude/session-options.d.ts +0 -4
  20. package/dist/agent-adapter/claude/session-options.js +0 -9
  21. package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
  22. package/dist/agent-adapter/claude/spawn-args.js +2 -5
  23. package/dist/agent-adapter/claude/transcript-clear.d.ts +42 -0
  24. package/dist/agent-adapter/claude/transcript-clear.js +217 -0
  25. package/dist/agent-adapter/claude/turn-machine.d.ts +3 -2
  26. package/dist/agent-adapter/claude/turn-machine.js +21 -68
  27. package/dist/agent-adapter/claude/window-warmup.d.ts +13 -0
  28. package/dist/agent-adapter/claude/window-warmup.js +38 -0
  29. package/dist/agent-adapter/continuation-phase.js +3 -0
  30. package/dist/agent-adapter/normalize/event-types.d.ts +8 -0
  31. package/dist/agent-adapter/pi/event-parser.d.ts +1 -1
  32. package/dist/agent-adapter/pi/event-parser.js +43 -27
  33. package/dist/agent-adapter/pi/mcp-bridge.d.ts +1 -1
  34. package/dist/agent-adapter/pi/pi-session.d.ts +2 -0
  35. package/dist/agent-adapter/pi/pi-session.js +15 -0
  36. package/dist/agent-adapter/pi/session-options.d.ts +2 -6
  37. package/dist/agent-adapter/pi/session-options.js +2 -11
  38. package/dist/agent-adapter/run-events.d.ts +10 -0
  39. package/dist/agent-adapter/run-events.js +2 -0
  40. package/dist/agent-adapter/types.d.ts +1 -1
  41. package/dist/client-bundle/manifest.json +1 -1
  42. package/dist/core/locales/en.d.ts +1 -0
  43. package/dist/core/locales/slices/commands.d.ts +1 -0
  44. package/dist/core/locales/slices/commands.js +2 -0
  45. package/dist/core/settings-spec.d.ts +25 -0
  46. package/dist/core/settings-spec.js +34 -0
  47. package/dist/domain/agents/engine-selection.js +1 -1
  48. package/dist/domain/agents/subagent/registry.d.ts +2 -0
  49. package/dist/domain/agents/subagent/registry.js +8 -0
  50. package/dist/domain/agents/subagent/runner.js +0 -1
  51. package/dist/domain/browser/broker.d.ts +99 -0
  52. package/dist/domain/browser/broker.js +487 -0
  53. package/dist/domain/costs/claude-account.js +21 -0
  54. package/dist/domain/costs/rate-limit-throttle.js +3 -1
  55. package/dist/domain/costs/reset-account.d.ts +2 -0
  56. package/dist/domain/costs/usage-service.d.ts +1 -1
  57. package/dist/domain/costs/usage-service.js +20 -7
  58. package/dist/domain/mcp/tools/ui-file.js +1 -1
  59. package/dist/domain/remote/device-browser.js +1 -1
  60. package/dist/domain/remote/device-chrome-commands.js +2 -0
  61. package/dist/domain/remote/device-port.js +2 -2
  62. package/dist/domain/runs/builders.d.ts +2 -2
  63. package/dist/domain/runs/builders.js +2 -3
  64. package/dist/domain/runs/engine-spec.d.ts +5 -0
  65. package/dist/domain/runs/engine-spec.js +1 -2
  66. package/dist/domain/runs/request.d.ts +0 -1
  67. package/dist/domain/sessions/session-lifecycle.d.ts +0 -4
  68. package/dist/domain/sessions/session-lifecycle.js +1 -1
  69. package/dist/domain/system/own-bin-path.d.ts +13 -0
  70. package/dist/domain/system/own-bin-path.js +36 -0
  71. package/dist/domain/system/terminal-cli/index.d.ts +58 -0
  72. package/dist/domain/system/terminal-cli/index.js +100 -0
  73. package/dist/domain/system/terminal-cli/posix-profiles.d.ts +23 -0
  74. package/dist/domain/system/terminal-cli/posix-profiles.js +74 -0
  75. package/dist/domain/system/terminal-cli/registrar.d.ts +12 -0
  76. package/dist/domain/system/terminal-cli/registrar.js +1 -0
  77. package/dist/domain/system/terminal-cli/shims.d.ts +27 -0
  78. package/dist/domain/system/terminal-cli/shims.js +108 -0
  79. package/dist/domain/system/terminal-cli/state.d.ts +7 -0
  80. package/dist/domain/system/terminal-cli/state.js +36 -0
  81. package/dist/domain/system/terminal-cli/windows-user-path.d.ts +13 -0
  82. package/dist/domain/system/terminal-cli/windows-user-path.js +67 -0
  83. package/dist/domain/tui-session/tui-session-service.js +1 -1
  84. package/dist/domain/tui-session/types.d.ts +1 -1
  85. package/dist/domain/ui-service/app-router.d.ts +17 -6
  86. package/dist/domain/ui-service/app-router.js +3 -1
  87. package/dist/domain/ui-service/assistant-snapshots.js +2 -0
  88. package/dist/domain/ui-service/inline-media-types.d.ts +18 -0
  89. package/dist/domain/ui-service/inline-media-types.js +1 -0
  90. package/dist/domain/ui-service/input-schemas.d.ts +17 -17
  91. package/dist/domain/ui-service/input-schemas.js +9 -9
  92. package/dist/domain/ui-service/mutate/models.d.ts +3 -0
  93. package/dist/domain/ui-service/mutate/models.js +21 -2
  94. package/dist/domain/ui-service/mutate/resolve-media.d.ts +4 -0
  95. package/dist/domain/ui-service/mutate/resolve-media.js +17 -0
  96. package/dist/domain/ui-service/mutate/sessions.js +1 -4
  97. package/dist/domain/ui-service/query/sessions.js +1 -1
  98. package/dist/domain/ui-service/types.d.ts +8 -10
  99. package/dist/domain/ui-service/ui-service.d.ts +9 -6
  100. package/dist/domain/ui-service/ui-service.js +4 -1
  101. package/dist/entry/app.js +23 -0
  102. package/dist/entry/browser-cli.d.ts +39 -0
  103. package/dist/entry/browser-cli.js +317 -0
  104. package/dist/entry/cli-help.d.ts +1 -0
  105. package/dist/entry/cli-help.js +30 -0
  106. package/dist/entry/cli.js +2 -0
  107. package/dist/entry/daemon.js +2 -0
  108. package/dist/entry/path-cli.d.ts +4 -0
  109. package/dist/entry/path-cli.js +65 -0
  110. package/dist/entry/shutdown.js +7 -0
  111. package/dist/entry/start-ui-http.js +8 -0
  112. package/dist/entry/ui-service-wiring.js +2 -0
  113. package/dist/events/event-types.d.ts +2 -1
  114. package/dist/orchestration/agent-runner.d.ts +2 -2
  115. package/dist/orchestration/agent-runner.js +6 -6
  116. package/dist/orchestration/browser-webhook.d.ts +11 -0
  117. package/dist/orchestration/browser-webhook.js +28 -0
  118. package/dist/orchestration/cache-keep-warm.d.ts +77 -0
  119. package/dist/orchestration/cache-keep-warm.js +213 -0
  120. package/dist/orchestration/claude-window-warmup.d.ts +40 -0
  121. package/dist/orchestration/claude-window-warmup.js +126 -0
  122. package/dist/orchestration/conversation-request.d.ts +4 -7
  123. package/dist/orchestration/conversation-request.js +1 -2
  124. package/dist/orchestration/delta-coalescer.d.ts +4 -2
  125. package/dist/orchestration/delta-coalescer.js +5 -5
  126. package/dist/orchestration/edit-retry.js +3 -6
  127. package/dist/orchestration/inline-media-eager.d.ts +13 -0
  128. package/dist/orchestration/inline-media-eager.js +58 -0
  129. package/dist/orchestration/inline-media.d.ts +22 -0
  130. package/dist/orchestration/inline-media.js +151 -0
  131. package/dist/orchestration/interactions/ask-user-resume.js +3 -7
  132. package/dist/orchestration/routing/commands/usage-format.js +3 -0
  133. package/dist/orchestration/routing/webhook.js +4 -0
  134. package/dist/orchestration/session-compact.js +5 -7
  135. package/dist/orchestration/session-events.d.ts +2 -1
  136. package/dist/orchestration/session-events.js +1 -0
  137. package/dist/orchestration/transcript-sink.d.ts +6 -0
  138. package/dist/orchestration/transcript-sink.js +21 -2
  139. package/dist/orchestration/turn/turn-prep.d.ts +0 -8
  140. package/dist/orchestration/turn/turn-prep.js +0 -51
  141. package/dist/orchestration/turn/turn.js +4 -0
  142. package/dist/platform/adapters/tui/ports.d.ts +1 -1
  143. package/dist/platform/adapters/tui/tui-transcript.js +2 -0
  144. package/dist/platform/browser/agent-browser.d.ts +50 -0
  145. package/dist/platform/browser/agent-browser.js +165 -0
  146. package/dist/platform/browser/managed-browser.d.ts +1 -11
  147. package/dist/platform/browser/managed-browser.js +4 -12
  148. package/dist/platform/ui-http/browser-stream.d.ts +110 -0
  149. package/dist/platform/ui-http/browser-stream.js +447 -0
  150. package/dist/platform/ui-http/ui-http-server.d.ts +12 -0
  151. package/dist/platform/ui-http/ui-http-server.js +23 -6
  152. package/dist/store/conversation-history-reader.js +8 -0
  153. package/dist/store/conversation-history-repo.d.ts +8 -1
  154. package/dist/store/conversation-history-repo.js +5 -0
  155. package/dist/store/session-registry-journal.d.ts +0 -8
  156. package/dist/store/session-registry-journal.js +5 -17
  157. package/dist/store/session-registry-repo.d.ts +2 -3
  158. package/dist/store/session-registry-repo.js +0 -2
  159. package/package.json +4 -2
  160. package/web/dist/assets/board-math-css-CB4GJ6qO.js +2 -0
  161. package/web/dist/assets/index-CaSZPg_H.css +1 -0
  162. package/web/dist/assets/index-CzOR7Edh.js +522 -0
  163. package/web/dist/assets/{index-DaViXAg-.js → index-cIGFv27z.js} +1 -1
  164. package/web/dist/index.html +3 -2
  165. package/web/dist/theme.css +6 -0
  166. package/dist/agent-adapter/browser-mcp-server.d.ts +0 -13
  167. package/dist/agent-adapter/browser-mcp-server.js +0 -28
  168. package/dist/agent-adapter/claude/browser-mcp.d.ts +0 -9
  169. package/dist/agent-adapter/claude/browser-mcp.js +0 -10
  170. package/web/dist/assets/index-Cgx3gdHV.css +0 -1
  171. package/web/dist/assets/index-CpZWBVHr.js +0 -494
@@ -316,6 +316,9 @@ export function sinkToRunEvents(emit) {
316
316
  ...(subagent !== undefined ? { subagent } : {}),
317
317
  });
318
318
  },
319
+ onAssistantThinking: (text, blockId) => emit({
320
+ type: 'assistant_thinking', text, phase: 'background', ...(blockId ? { blockId } : {}),
321
+ }),
319
322
  onToolUse: (name, input, toolUseId, subagent) => {
320
323
  emit({
321
324
  type: 'tool_use', toolUseId: toolUseId ?? '', name, input, phase: 'background',
@@ -41,6 +41,14 @@ export type NormalizedEvent = {
41
41
  type: 'assistant_delta';
42
42
  text: string;
43
43
  blockId: string;
44
+ } | {
45
+ type: 'assistant_thinking';
46
+ text: string;
47
+ blockId?: string;
48
+ } | {
49
+ type: 'assistant_thinking_delta';
50
+ text: string;
51
+ blockId: string;
44
52
  } | {
45
53
  type: 'tool_use';
46
54
  toolUseId: string;
@@ -20,7 +20,7 @@ export declare function createPIEventParserState(): PIEventParserState;
20
20
  * NormalizedEvents.
21
21
  *
22
22
  * Dropped events (return []): turn_start, turn_end, message_start, agent_start,
23
- * queue_update, compaction_end, auto_retry_start/end, message_update without text_delta,
23
+ * queue_update, compaction_end, auto_retry_start/end, unsupported message_update events,
24
24
  * fire-and-forget extension_ui_request.
25
25
  * message_end emits a turn_progress heartbeat (non-terminal, state.turnProgressCount++).
26
26
  * compaction_start emits a context_compacted event (user notification); compaction_end is dropped
@@ -15,7 +15,7 @@ export function createPIEventParserState() {
15
15
  * NormalizedEvents.
16
16
  *
17
17
  * Dropped events (return []): turn_start, turn_end, message_start, agent_start,
18
- * queue_update, compaction_end, auto_retry_start/end, message_update without text_delta,
18
+ * queue_update, compaction_end, auto_retry_start/end, unsupported message_update events,
19
19
  * fire-and-forget extension_ui_request.
20
20
  * message_end emits a turn_progress heartbeat (non-terminal, state.turnProgressCount++).
21
21
  * compaction_start emits a context_compacted event (user notification); compaction_end is dropped
@@ -27,32 +27,8 @@ export function piEventToNormalized(event, state) {
27
27
  if (typeof ev['type'] !== 'string')
28
28
  return [];
29
29
  const type = ev['type'];
30
- // --- message_update → assistant_text (text_delta only) ---
31
- if (type === 'message_update') {
32
- const ame = ev['assistantMessageEvent'];
33
- if (ame && typeof ame === 'object') {
34
- const delta = ame['delta'];
35
- if (ame['type'] === 'text_delta' &&
36
- typeof delta === 'string' &&
37
- delta.length > 0) {
38
- // blockId groups every delta of one assistant message and ties them to the finalizing
39
- // whole-message assistant_text. PI's AssistantMessage carries no `id`: the stable
40
- // per-message identifier is `responseId`, which the provider assigns once when the
41
- // stream opens (anthropic msg_… / openai-compatible chatcmpl-…), before any text_delta.
42
- // `id` is kept first so any producer that does supply one keeps working.
43
- const msgObj = ev['message'];
44
- const blockId = msgObj && typeof msgObj === 'object'
45
- ? (msgObj['id'] ??
46
- msgObj['responseId'])
47
- : undefined;
48
- const result = { type: 'assistant_text', text: delta };
49
- if (typeof blockId === 'string')
50
- result.blockId = blockId;
51
- return [result];
52
- }
53
- }
54
- return [];
55
- }
30
+ if (type === 'message_update')
31
+ return handleMessageUpdate(ev);
56
32
  // --- tool_execution_start → tool_use ---
57
33
  if (type === 'tool_execution_start') {
58
34
  return handleToolExecutionStart(ev);
@@ -107,6 +83,46 @@ export function piEventToNormalized(event, state) {
107
83
  // ---------------------------------------------------------------------------
108
84
  // Private helpers
109
85
  // ---------------------------------------------------------------------------
86
+ function record(value) {
87
+ return value !== null && typeof value === 'object' ? value : undefined;
88
+ }
89
+ /** Real PI messages use responseId; keep id first for producers that already supply it. */
90
+ function messageId(message) {
91
+ const msg = record(message);
92
+ const id = msg?.id ?? msg?.responseId;
93
+ return typeof id === 'string' ? id : undefined;
94
+ }
95
+ function redactedBlock(message, index) {
96
+ const content = record(message)?.content;
97
+ if (!Array.isArray(content) || typeof index !== 'number')
98
+ return false;
99
+ return record(content[index])?.redacted === true;
100
+ }
101
+ function handleThinkingUpdate(ev, ame) {
102
+ const redacted = ame.redacted === true
103
+ || redactedBlock(ev.message, ame.contentIndex)
104
+ || redactedBlock(ame.partial, ame.contentIndex);
105
+ const text = ame.type === 'thinking_end' ? ame.content : ame.delta;
106
+ if (redacted || typeof text !== 'string' || text.length === 0)
107
+ return [];
108
+ const id = messageId(ev.message);
109
+ const blockId = id !== undefined && typeof ame.contentIndex === 'number' ? `${id}:t${ame.contentIndex}` : undefined;
110
+ if (ame.type === 'thinking_end') {
111
+ return [{ type: 'assistant_thinking', text, ...(blockId !== undefined ? { blockId } : {}) }];
112
+ }
113
+ return blockId !== undefined ? [{ type: 'assistant_thinking_delta', text, blockId }] : [];
114
+ }
115
+ function handleMessageUpdate(ev) {
116
+ const ame = record(ev.assistantMessageEvent);
117
+ if (!ame)
118
+ return [];
119
+ if (ame.type === 'thinking_delta' || ame.type === 'thinking_end')
120
+ return handleThinkingUpdate(ev, ame);
121
+ if (ame.type !== 'text_delta' || typeof ame.delta !== 'string' || ame.delta.length === 0)
122
+ return [];
123
+ const blockId = messageId(ev.message);
124
+ return [{ type: 'assistant_text', text: ame.delta, ...(blockId !== undefined ? { blockId } : {}) }];
125
+ }
110
126
  function handleToolExecutionStart(ev) {
111
127
  const toolCallId = ev['toolCallId'];
112
128
  const toolName = ev['toolName'];
@@ -41,7 +41,7 @@ export type OpenBundledMcpServer = (bundles: McpBundleName[], env: Record<string
41
41
  export interface McpBridgeDeps {
42
42
  /** The session's environment: composition markers, channel, Cortex context, tool gate. */
43
43
  env: NodeJS.ProcessEnv;
44
- /** Plugin (and browser) servers for this session, already filtered by composition. */
44
+ /** Plugin servers for this session, already filtered by composition. */
45
45
  pluginServers?: readonly McpServerConfig[];
46
46
  spawnClient(state: ServerState): Promise<McpClientHandle>;
47
47
  reportFailure(error: unknown): void;
@@ -130,6 +130,8 @@ export declare class PISession {
130
130
  private buildAgentResult;
131
131
  /** Buffer deltas into whole assistant messages while preserving Web preview events. */
132
132
  private emitNormalizedEvent;
133
+ private emitThinkingEvent;
134
+ private bufferTextEvent;
133
135
  /**
134
136
  * Hand the opening prompt to PI. The call resolves only when the whole agent run has finished,
135
137
  * so it is not awaited here; the turn is settled off the event stream instead. A rejection
@@ -424,6 +424,10 @@ export class PISession {
424
424
  this.turnStream?.push(evt);
425
425
  return;
426
426
  }
427
+ if (evt.type === 'assistant_thinking' || evt.type === 'assistant_thinking_delta') {
428
+ this.emitThinkingEvent(evt);
429
+ return;
430
+ }
427
431
  // Forwarded subagent prose is already a complete message, not a token delta. Putting it in the
428
432
  // main-agent text buffer would erase attribution when flushTextBuffer reconstructs the event.
429
433
  if (evt.type === 'assistant_text' && evt.subagent) {
@@ -440,6 +444,17 @@ export class PISession {
440
444
  this.closeTurnStream();
441
445
  return;
442
446
  }
447
+ this.bufferTextEvent(evt);
448
+ }
449
+ emitThinkingEvent(evt) {
450
+ if (!getSettings().showThinking)
451
+ return;
452
+ this.flushTextBuffer();
453
+ if (evt.type === 'assistant_thinking_delta' && !this.request.streamDeltas)
454
+ return;
455
+ this.turnStream?.push(evt);
456
+ }
457
+ bufferTextEvent(evt) {
443
458
  const blockId = evt.blockId ?? null;
444
459
  if (this.textBuffer.length > 0 && blockId !== this.textBlockId)
445
460
  this.flushTextBuffer();
@@ -56,7 +56,7 @@ export interface PiSessionRequest {
56
56
  disableHooks: boolean;
57
57
  /** Gateway-routed runs report provider quota read off response headers. */
58
58
  reportsProviderQuota: boolean;
59
- /** Plugin/browser MCP servers, already filtered by composition. Empty when none apply. */
59
+ /** Plugin MCP servers, already filtered by composition. Empty when none apply. */
60
60
  pluginMcpServers: McpServerConfig[];
61
61
  /**
62
62
  * The session's CORTEX_* environment. Both in-process MCP context and child processes (hook
@@ -75,11 +75,7 @@ export interface SessionRequestInputs {
75
75
  }
76
76
  /** Strip a context-window suffix like "[1m]" (e.g. "deepseek-v4-flash[1m]" → "deepseek-v4-flash"). */
77
77
  export declare function stripModelSuffix(model: string): string;
78
- /**
79
- * Plugin MCP servers for this session. Browser control rides along like any other plugin server,
80
- * gated on `direct` for the same reason Claude gates it: an unattended worker sharing one browser
81
- * is a cross-run side channel, not a feature.
82
- */
78
+ /** Plugin MCP servers for this session; only the direct composition carries them. */
83
79
  export declare function pluginMcpServers(spec: EngineSpec, composition: McpComposition): McpServerConfig[];
84
80
  export declare function buildSessionRequest(spec: EngineSpec, inputs: SessionRequestInputs): PiSessionRequest;
85
81
  /**
@@ -1,6 +1,5 @@
1
1
  import { resolveMcpComposition } from '../types.js';
2
2
  import { fromCanonical } from '../../core/tool-names.js';
3
- import { browserMcpServer } from '../browser-mcp-server.js';
4
3
  import { MCP_TOOL_ALLOWLIST_ENV } from '../../core/mcp-tool-gate.js';
5
4
  export const PI_MCP_COMPOSITION_ENV = 'CORTEX_PI_MCP_COMPOSITION';
6
5
  export const PI_INTERACTION_BRIDGE_ENV = 'CORTEX_PI_INTERACTION_BRIDGE';
@@ -87,19 +86,11 @@ function allowedToolLabels(spec) {
87
86
  function subagentMarker(spec) {
88
87
  return spec.env.sets?.CORTEX_PI_SUBAGENT === '1' ? '1' : undefined;
89
88
  }
90
- /**
91
- * Plugin MCP servers for this session. Browser control rides along like any other plugin server,
92
- * gated on `direct` for the same reason Claude gates it: an unattended worker sharing one browser
93
- * is a cross-run side channel, not a feature.
94
- */
89
+ /** Plugin MCP servers for this session; only the direct composition carries them. */
95
90
  export function pluginMcpServers(spec, composition) {
96
91
  if (composition !== 'direct')
97
92
  return [];
98
- const servers = [...(spec.mcp.servers ?? [])];
99
- if (spec.mcp.browserCdpEndpoint && composition === 'direct') {
100
- servers.push(browserMcpServer(spec.mcp.browserCdpEndpoint));
101
- }
102
- return servers;
93
+ return [...(spec.mcp.servers ?? [])];
103
94
  }
104
95
  export function buildSessionRequest(spec, inputs) {
105
96
  const composition = resolveMcpComposition(spec.mcp.composition);
@@ -32,6 +32,16 @@ export type RunEvent = {
32
32
  text: string;
33
33
  blockId: string;
34
34
  phase: RunPhase;
35
+ } | {
36
+ type: 'assistant_thinking';
37
+ text: string;
38
+ blockId?: string;
39
+ phase: RunPhase;
40
+ } | {
41
+ type: 'assistant_thinking_delta';
42
+ text: string;
43
+ blockId: string;
44
+ phase: RunPhase;
35
45
  } | {
36
46
  type: 'tool_use';
37
47
  toolUseId: string;
@@ -34,6 +34,8 @@ export function toRunEvent(event, phase) {
34
34
  };
35
35
  case 'assistant_text':
36
36
  return { ...event, phase };
37
+ case 'assistant_thinking':
38
+ case 'assistant_thinking_delta':
37
39
  case 'assistant_delta':
38
40
  return { ...event, phase };
39
41
  case 'tool_use':
@@ -79,7 +79,6 @@ export interface EngineSpec {
79
79
  servers?: McpServerConfig[];
80
80
  allowlist?: string[];
81
81
  configPaths?: string[];
82
- browserCdpEndpoint?: string;
83
82
  };
84
83
  env: {
85
84
  sets?: Record<string, string>;
@@ -194,6 +193,7 @@ export interface BackgroundTurnSink {
194
193
  /** Assistant text from the continuation turn (append to the original reply). `subagent` is set
195
194
  * only when a native subagent produced it (see ToolUseSubagent). */
196
195
  onAssistantText: (text: string, model?: string | null, subagent?: ToolUseSubagent) => void;
196
+ onAssistantThinking?: (text: string, blockId?: string) => void;
197
197
  /** Optional tool_use trace from the continuation turn, preserving its correlation id and,
198
198
  * when a native subagent made the call, its attribution. */
199
199
  onToolUse?: (name: string, input: any, toolUseId?: string, subagent?: ToolUseSubagent) => void;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "version": "2026.10.15",
3
3
  "hash": "8427e6d35fd14a8701b97c5d80cca778f5fc0340d0c938a485e25b666757cfcd",
4
- "source": "0d37d50a1e7af04c74dc517febf19bf278642845"
4
+ "source": "3d9dd5c4e1df1c572d6146f72b8dca90ee53e0f5"
5
5
  }
@@ -292,6 +292,7 @@ export declare const en: {
292
292
  'cmd.usage.window.sevenDay': '7 day';
293
293
  'cmd.usage.window.sevenDayOpus': '7 day Opus';
294
294
  'cmd.usage.window.sevenDayOverage': '7 day (incl. overage)';
295
+ 'cmd.usage.window.sevenDayModel': '7 day (${model})';
295
296
  'cmd.usage.window.codexPrimary': 'Primary';
296
297
  'cmd.usage.window.codexSecondary': 'Secondary';
297
298
  'cmd.usage.windowLine': '• ${label}: ${utilization}${reset}';
@@ -236,6 +236,7 @@ export declare const commandsEn: {
236
236
  readonly 'cmd.usage.window.sevenDay': '7 day';
237
237
  readonly 'cmd.usage.window.sevenDayOpus': '7 day Opus';
238
238
  readonly 'cmd.usage.window.sevenDayOverage': '7 day (incl. overage)';
239
+ readonly 'cmd.usage.window.sevenDayModel': '7 day (${model})';
239
240
  readonly 'cmd.usage.window.codexPrimary': 'Primary';
240
241
  readonly 'cmd.usage.window.codexSecondary': 'Secondary';
241
242
  readonly 'cmd.usage.windowLine': '• ${label}: ${utilization}${reset}';
@@ -247,6 +247,7 @@ export const commandsEn = {
247
247
  'cmd.usage.window.sevenDay': '7 day',
248
248
  'cmd.usage.window.sevenDayOpus': '7 day Opus',
249
249
  'cmd.usage.window.sevenDayOverage': '7 day (incl. overage)',
250
+ 'cmd.usage.window.sevenDayModel': '7 day (${model})',
250
251
  'cmd.usage.window.codexPrimary': 'Primary',
251
252
  'cmd.usage.window.codexSecondary': 'Secondary',
252
253
  'cmd.usage.windowLine': '• ${label}: ${utilization}${reset}',
@@ -563,6 +564,7 @@ export const commandsZh = {
563
564
  'cmd.usage.window.sevenDay': '7 天',
564
565
  'cmd.usage.window.sevenDayOpus': '7 天 Opus',
565
566
  'cmd.usage.window.sevenDayOverage': '7 天(含超额)',
567
+ 'cmd.usage.window.sevenDayModel': '7 天(${model})',
566
568
  'cmd.usage.window.codexPrimary': '主要窗口',
567
569
  'cmd.usage.window.codexSecondary': '次要窗口',
568
570
  'cmd.usage.windowLine': '• ${label}:${utilization}${reset}',
@@ -17,6 +17,7 @@ export interface Settings {
17
17
  showToolCalls: boolean;
18
18
  statusNewqButton: boolean;
19
19
  autoResume: boolean;
20
+ showThinking: boolean;
20
21
  streamDeltas: boolean;
21
22
  bgContinuation: boolean;
22
23
  eventLog: boolean;
@@ -35,6 +36,7 @@ export interface Settings {
35
36
  subscriptionBillingModes: string[];
36
37
  providerUsageCollectionEnabled: boolean;
37
38
  providerUsageCollectionIntervalMs: number;
39
+ claudeWindowWarmupEnabled: boolean;
38
40
  providerRateLimits: ProviderRateLimits;
39
41
  storeArchiveEnabled: boolean;
40
42
  memoryIndexRegenEnabled: boolean;
@@ -42,6 +44,8 @@ export interface Settings {
42
44
  sessionRetentionDays: number;
43
45
  piCompactReserveTokens: number;
44
46
  maxContextTokens: number | null;
47
+ cacheKeepWarmHours: number;
48
+ coldResumeClearToolResults: boolean;
45
49
  uiCorsOrigins: string[];
46
50
  adminChannel: string | null;
47
51
  feishuAdminChannel: string | null;
@@ -83,6 +87,8 @@ export declare const MIN_MAX_CONTEXT_TOKENS = 100000;
83
87
  export declare const MAX_MAX_CONTEXT_TOKENS = 1000000;
84
88
  declare function validateMaxContextTokens(value: number | null): string | null;
85
89
  declare function validateSessionRetentionDays(value: number): string | null;
90
+ export declare const MAX_CACHE_KEEP_WARM_HOURS = 24;
91
+ declare function validateCacheKeepWarmHours(value: number): string | null;
86
92
  export declare const SETTINGS_SPEC: {
87
93
  turnNotify: {
88
94
  envVar: string;
@@ -120,6 +126,12 @@ export declare const SETTINGS_SPEC: {
120
126
  default: true;
121
127
  legacyParse: (raw: string) => boolean;
122
128
  };
129
+ showThinking: {
130
+ envVar: string;
131
+ type: "boolean";
132
+ default: true;
133
+ legacyParse: (raw: string) => boolean;
134
+ };
123
135
  streamDeltas: {
124
136
  envVar: string;
125
137
  type: "boolean";
@@ -215,6 +227,10 @@ export declare const SETTINGS_SPEC: {
215
227
  default: number;
216
228
  validate: typeof validateJobInterval;
217
229
  };
230
+ claudeWindowWarmupEnabled: {
231
+ type: "boolean";
232
+ default: false;
233
+ };
218
234
  providerRateLimits: {
219
235
  type: "provider-rate-limits";
220
236
  default: {};
@@ -249,6 +265,15 @@ export declare const SETTINGS_SPEC: {
249
265
  default: any;
250
266
  validate: typeof validateMaxContextTokens;
251
267
  };
268
+ cacheKeepWarmHours: {
269
+ type: "number";
270
+ default: number;
271
+ validate: typeof validateCacheKeepWarmHours;
272
+ };
273
+ coldResumeClearToolResults: {
274
+ type: "boolean";
275
+ default: true;
276
+ };
252
277
  uiCorsOrigins: {
253
278
  envVar: string;
254
279
  type: "string[]";
@@ -55,6 +55,15 @@ function validateSessionRetentionDays(value) {
55
55
  }
56
56
  return null;
57
57
  }
58
+ export const MAX_CACHE_KEEP_WARM_HOURS = 24;
59
+ function validateCacheKeepWarmHours(value) {
60
+ if (!Number.isFinite(value))
61
+ return 'must be a number of hours';
62
+ if (value < 0 || value > MAX_CACHE_KEEP_WARM_HOURS) {
63
+ return `must be between 0 and ${MAX_CACHE_KEEP_WARM_HOURS} hours`;
64
+ }
65
+ return null;
66
+ }
58
67
  export const SETTINGS_SPEC = {
59
68
  turnNotify: {
60
69
  envVar: 'CORTEX_TURN_NOTIFY',
@@ -98,6 +107,12 @@ export const SETTINGS_SPEC = {
98
107
  default: true,
99
108
  legacyParse: (raw) => raw !== '0' && raw !== 'false',
100
109
  },
110
+ showThinking: {
111
+ envVar: 'CORTEX_SHOW_THINKING',
112
+ type: 'boolean',
113
+ default: true,
114
+ legacyParse: (raw) => !['0', 'false', 'off', 'no'].includes(raw.trim().toLowerCase()),
115
+ },
101
116
  streamDeltas: {
102
117
  envVar: 'CORTEX_STREAM_DELTAS',
103
118
  type: 'boolean',
@@ -208,6 +223,12 @@ export const SETTINGS_SPEC = {
208
223
  default: 5 * 60 * 1000,
209
224
  validate: validateJobInterval,
210
225
  },
226
+ // Claude on a subscription mode only: once the five-hour usage window has closed and no Claude
227
+ // run has started for ten minutes, send one tiny request to open the next window.
228
+ claudeWindowWarmupEnabled: {
229
+ type: 'boolean',
230
+ default: false,
231
+ },
211
232
  providerRateLimits: {
212
233
  type: 'provider-rate-limits',
213
234
  default: {},
@@ -250,6 +271,19 @@ export const SETTINGS_SPEC = {
250
271
  default: null,
251
272
  validate: validateMaxContextTokens,
252
273
  },
274
+ // Claude on a subscription mode only: how long an idle session that still expects a wake keeps
275
+ // its one-hour prompt cache refreshed, counted from its last model activity. 0 turns it off.
276
+ cacheKeepWarmHours: {
277
+ type: 'number',
278
+ default: 6,
279
+ validate: validateCacheKeepWarmHours,
280
+ },
281
+ // Claude only: on a --resume whose prompt cache has certainly expired, stub out all but the most
282
+ // recent tool results in the transcript before the CLI re-sends it.
283
+ coldResumeClearToolResults: {
284
+ type: 'boolean',
285
+ default: true,
286
+ },
253
287
  uiCorsOrigins: {
254
288
  envVar: 'CORTEX_UI_CORS_ORIGINS',
255
289
  type: 'string[]',
@@ -3,7 +3,7 @@ export function modelKey(ref) {
3
3
  }
4
4
  export const THINKING_LEVELS_BY_BACKEND = {
5
5
  claude: ['low', 'medium', 'high', 'xhigh', 'max'],
6
- pi: ['off', 'minimal', 'low', 'medium', 'high', 'xhigh'],
6
+ pi: ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'],
7
7
  };
8
8
  export function isValidThinkingLevel(backend, level) {
9
9
  return THINKING_LEVELS_BY_BACKEND[backend]?.includes(level) ?? false;
@@ -70,6 +70,8 @@ export declare function trackSubagentChildren(runId: string, blockId: (index: nu
70
70
  * Native CLI tasks have their own lifecycle tracker and are not represented here. */
71
71
  export declare function getSubagentChildStatuses(sessionId: string): ReadonlyMap<string, 'running' | SubagentEndStatus>;
72
72
  export declare function getSubagentRun(id: string): SubagentRunView | null;
73
+ /** Whether the session owns a background run still going, whose result will wake it. */
74
+ export declare function hasRunningBackgroundRuns(sessionId: string): boolean;
73
75
  export interface SubagentRunOutcome {
74
76
  view: SubagentRunView;
75
77
  /** Present only once the run has completed successfully. */
@@ -133,6 +133,14 @@ export function getSubagentRun(id) {
133
133
  const record = runs.get(id);
134
134
  return record ? viewOf(record) : null;
135
135
  }
136
+ /** Whether the session owns a background run still going, whose result will wake it. */
137
+ export function hasRunningBackgroundRuns(sessionId) {
138
+ for (const record of runs.values()) {
139
+ if (record.sessionId === sessionId && record.background && record.status === 'running')
140
+ return true;
141
+ }
142
+ return false;
143
+ }
136
144
  /**
137
145
  * Wait up to `sliceMs` for a run to settle, then answer with whatever state it is in.
138
146
  *
@@ -186,7 +186,6 @@ function claudeChildRequest(request, config) {
186
186
  loadRules: false, // loadCortexRules: false
187
187
  mcpComposition: 'direct',
188
188
  mcpToolAllowlist,
189
- browserCdpEndpoint: null,
190
189
  captureTranscripts: false, // captureTranscriptLogs: false
191
190
  },
192
191
  };
@@ -0,0 +1,99 @@
1
+ import { type AgentBrowserRun } from '../../platform/browser/agent-browser.js';
2
+ /**
3
+ * Browser leases for `cortex-browser`, held per Cortex session rather than per turn.
4
+ *
5
+ * A lease ties one session to one device's shared Chrome (server-local, or a device's through the
6
+ * reverse channel) and to one agent-browser session pinned to its own tab there. It holds one
7
+ * reference on that Chrome, is renewed by every call, and is released, closing its tab, after
8
+ * {@link LEASE_IDLE_MS} without one. Page state survives between turns because nothing here is torn
9
+ * down per turn.
10
+ */
11
+ export declare const LEASE_IDLE_MS: number;
12
+ export type BrowserSessionState = 'starting' | 'ready' | 'error';
13
+ export interface BrowserSessionInfo {
14
+ sessionId: string;
15
+ device: string;
16
+ abSession: string;
17
+ state: BrowserSessionState;
18
+ error?: string;
19
+ url?: string;
20
+ title?: string;
21
+ takenOver: boolean;
22
+ lastUsedAt: number;
23
+ }
24
+ export interface BrowserLease {
25
+ device: string;
26
+ cdpEndpoint: string;
27
+ abSession: string;
28
+ }
29
+ export type BrowserLeaseErrorCode = 'bad-request' | 'unknown-device' | 'device-offline' | 'taken-over' | 'chrome-failed' | 'engine-missing' | 'no-lease';
30
+ /** A lease failure meant for a human: what went wrong, and what to do about it. */
31
+ export declare class BrowserLeaseError extends Error {
32
+ readonly code: BrowserLeaseErrorCode;
33
+ readonly hint?: string;
34
+ constructor(code: BrowserLeaseErrorCode, message: string, hint?: string);
35
+ }
36
+ /** Device states the broker distinguishes when asked for one. */
37
+ export type DeviceAvailability = 'online' | 'offline' | 'unknown';
38
+ export interface BrokerDeps {
39
+ /** Take one reference on the device's Chrome, starting it if needed. */
40
+ acquire(device: string): Promise<string>;
41
+ /** Drop one reference taken by {@link acquire}. */
42
+ release(device: string): void;
43
+ /**
44
+ * The device's live endpoint for a lease that already holds a reference, relaunching Chrome if
45
+ * it died. Must leave the reference count as it found it.
46
+ */
47
+ refresh(device: string, cdpEndpoint: string): Promise<string>;
48
+ availability(device: string): {
49
+ state: DeviceAvailability;
50
+ online: string[];
51
+ };
52
+ resolveBin(): string;
53
+ baseEnv(): Record<string, string>;
54
+ run(bin: string, args: string[], env: Record<string, string>): Promise<AgentBrowserRun>;
55
+ now(): number;
56
+ idleMs: number;
57
+ }
58
+ export interface BrowserBroker {
59
+ leaseBrowser(input: {
60
+ sessionId: string;
61
+ device?: string | null;
62
+ }): Promise<BrowserLease>;
63
+ listBrowserSessions(): BrowserSessionInfo[];
64
+ runAgentBrowser(sessionId: string, args: string[]): Promise<AgentBrowserRun>;
65
+ streamPort(sessionId: string): Promise<number | null>;
66
+ setTakeover(sessionId: string, on: boolean): void;
67
+ isTakenOver(sessionId: string): boolean;
68
+ insertText(sessionId: string, text: string): Promise<void>;
69
+ /** A CLI call finished: refresh the URL and title shown for the session. */
70
+ noteBrowserCommand(sessionId: string): void;
71
+ /** The binary and environment a CLI call must use to reach this broker's daemons. */
72
+ agentBrowserRuntime(): {
73
+ bin: string;
74
+ env: Record<string, string>;
75
+ };
76
+ onBrowserSessionsChanged(listener: () => void): () => void;
77
+ /** Forget every lease (daemon shutdown). Chrome itself is stopped by its own owner. */
78
+ shutdown(): void;
79
+ }
80
+ /** Turn a device launch failure (often a bare marker from the launch script) into a sentence. */
81
+ export declare function describeDeviceFailure(device: string, raw: string): {
82
+ message: string;
83
+ hint?: string;
84
+ };
85
+ export declare function createBrowserBroker(deps: BrokerDeps): BrowserBroker;
86
+ export declare function defaultBrokerDeps(): BrokerDeps;
87
+ /** Test seam: swap the process-wide broker (pass null to rebuild it from the real deps). */
88
+ export declare function _setBrowserBroker(next: BrowserBroker | null): void;
89
+ export declare const leaseBrowser: BrowserBroker['leaseBrowser'];
90
+ export declare const listBrowserSessions: BrowserBroker['listBrowserSessions'];
91
+ export declare const runAgentBrowser: BrowserBroker['runAgentBrowser'];
92
+ export declare const streamPort: BrowserBroker['streamPort'];
93
+ export declare const setTakeover: BrowserBroker['setTakeover'];
94
+ export declare const isTakenOver: BrowserBroker['isTakenOver'];
95
+ export declare const insertText: BrowserBroker['insertText'];
96
+ export declare const noteBrowserCommand: BrowserBroker['noteBrowserCommand'];
97
+ export declare const agentBrowserRuntime: BrowserBroker['agentBrowserRuntime'];
98
+ export declare const onBrowserSessionsChanged: BrowserBroker['onBrowserSessionsChanged'];
99
+ export declare function shutdownBrowserBroker(): void;