@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
@@ -1,6 +1,6 @@
1
1
  /** One replayable conversation message — the full backend-independent history. */
2
2
  export interface TranscriptMessage {
3
- role: 'user' | 'assistant' | 'tool' | 'interaction';
3
+ role: 'user' | 'assistant' | 'thinking' | 'tool' | 'interaction';
4
4
  /** user / assistant text. Empty for tool messages (see toolName/toolInput). */
5
5
  text: string;
6
6
  toolName?: string;
@@ -9,6 +9,8 @@ export function buildTranscriptReplay(data) {
9
9
  const items = [];
10
10
  let seq = 0;
11
11
  messages.forEach((msg, i) => {
12
+ if (msg.role === 'thinking')
13
+ return;
12
14
  const ref = {
13
15
  conduit: sessionId,
14
16
  messageId: `${sessionId}-${i}`,
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The `agent-browser` engine behind `cortex-browser`: locating its native binary and the argument
3
+ * and environment rules every invocation must follow. Shared by the daemon-side broker and the
4
+ * agent-side CLI, so the two can never disagree about which daemon or tab they are talking to.
5
+ */
6
+ /** Operator override for the binary, e.g. a locally built one. */
7
+ export declare const AGENT_BROWSER_BIN_ENV = "CORTEX_AGENT_BROWSER_BIN";
8
+ export interface AgentBrowserRun {
9
+ code: number;
10
+ stdout: string;
11
+ stderr: string;
12
+ }
13
+ export declare class AgentBrowserMissingError extends Error {
14
+ readonly hint: string;
15
+ constructor(message: string, hint: string);
16
+ }
17
+ /** Native binary file name for this host, matching the package's own launcher. */
18
+ export declare function agentBrowserBinaryName(platform?: NodeJS.Platform, arch?: string, musl?: () => boolean): string | null;
19
+ /**
20
+ * Absolute path of the agent-browser native binary. `CORTEX_AGENT_BROWSER_BIN` wins; otherwise the
21
+ * pinned dependency's own binary. Never PATH: a globally installed agent-browser is a different
22
+ * version, and its skill text would not match the commands.
23
+ */
24
+ export declare function resolveAgentBrowserBin(env?: NodeJS.ProcessEnv): string;
25
+ /** The agent-browser session (daemon + pinned tab) for one Cortex session on one device. */
26
+ export declare function agentBrowserSessionName(sessionId: string, device: string): string;
27
+ /**
28
+ * The arguments every call carries. `--cdp` is not sticky: one call without it makes the daemon
29
+ * launch a Chrome of its own. `--pin-tab` keeps the session on its own tab when several sessions
30
+ * share one Chrome.
31
+ */
32
+ export declare function agentBrowserArgs(cdpEndpoint: string, abSession: string, args: string[]): string[];
33
+ /** The bound tab no longer exists (the Chrome behind it was replaced or the tab was closed). */
34
+ export declare function isTabGone(stderr: string): boolean;
35
+ /**
36
+ * The environment agent-browser runs under, computed once in the daemon and handed to every CLI
37
+ * call. Pinning the socket directory is what makes the CLI and the daemon reach the same
38
+ * agent-browser daemon: tab bindings live beside its socket, so two directories would mean two
39
+ * tabs for one session.
40
+ */
41
+ export declare function agentBrowserBaseEnv(env?: NodeJS.ProcessEnv): Record<string, string>;
42
+ /** `base` plus the caller's own AGENT_BROWSER_* tuning (output limits, timeouts), minus anything
43
+ * that would redirect it to another daemon, browser or tab. */
44
+ export declare function agentBrowserCallEnv(base: Record<string, string>, callerEnv: NodeJS.ProcessEnv): Record<string, string>;
45
+ /** Run agent-browser to completion, capturing output. For the daemon's own calls; the CLI streams. */
46
+ export declare function runAgentBrowserProcess(bin: string, args: string[], opts: {
47
+ env: Record<string, string>;
48
+ timeoutMs?: number;
49
+ cwd?: string;
50
+ }): Promise<AgentBrowserRun>;
@@ -0,0 +1,165 @@
1
+ import * as fs from 'node:fs';
2
+ import * as os from 'node:os';
3
+ import * as path from 'node:path';
4
+ import { createRequire } from 'node:module';
5
+ import { spawn } from 'node:child_process';
6
+ /**
7
+ * The `agent-browser` engine behind `cortex-browser`: locating its native binary and the argument
8
+ * and environment rules every invocation must follow. Shared by the daemon-side broker and the
9
+ * agent-side CLI, so the two can never disagree about which daemon or tab they are talking to.
10
+ */
11
+ /** Operator override for the binary, e.g. a locally built one. */
12
+ export const AGENT_BROWSER_BIN_ENV = 'CORTEX_AGENT_BROWSER_BIN';
13
+ export class AgentBrowserMissingError extends Error {
14
+ hint;
15
+ constructor(message, hint) {
16
+ super(message);
17
+ this.name = 'AgentBrowserMissingError';
18
+ this.hint = hint;
19
+ }
20
+ }
21
+ function isMusl() {
22
+ const header = process.report?.getReport?.()?.header;
23
+ return !header?.glibcVersionRuntime;
24
+ }
25
+ /** Native binary file name for this host, matching the package's own launcher. */
26
+ export function agentBrowserBinaryName(platform = process.platform, arch = process.arch, musl = isMusl) {
27
+ const osKey = platform === 'darwin' ? 'darwin'
28
+ : platform === 'linux' ? (musl() ? 'linux-musl' : 'linux')
29
+ : platform === 'win32' ? 'win32' : null;
30
+ // Windows on ARM runs the x64 build under emulation, as the package launcher does.
31
+ const archKey = arch === 'x64' ? 'x64' : arch === 'arm64' ? (platform === 'win32' ? 'x64' : 'arm64') : null;
32
+ if (!osKey || !archKey)
33
+ return null;
34
+ return `agent-browser-${osKey}-${archKey}${platform === 'win32' ? '.exe' : ''}`;
35
+ }
36
+ /** pnpm skips the package's postinstall, which is what normally sets the execute bit. */
37
+ function ensureExecutable(file) {
38
+ if (process.platform === 'win32')
39
+ return;
40
+ try {
41
+ fs.accessSync(file, fs.constants.X_OK);
42
+ }
43
+ catch {
44
+ fs.chmodSync(file, 0o755);
45
+ }
46
+ }
47
+ /**
48
+ * Absolute path of the agent-browser native binary. `CORTEX_AGENT_BROWSER_BIN` wins; otherwise the
49
+ * pinned dependency's own binary. Never PATH: a globally installed agent-browser is a different
50
+ * version, and its skill text would not match the commands.
51
+ */
52
+ export function resolveAgentBrowserBin(env = process.env) {
53
+ const override = env[AGENT_BROWSER_BIN_ENV];
54
+ if (override) {
55
+ if (!fs.existsSync(override)) {
56
+ throw new AgentBrowserMissingError(`${AGENT_BROWSER_BIN_ENV} points at ${override}, which does not exist`, `fix or unset ${AGENT_BROWSER_BIN_ENV}`);
57
+ }
58
+ return override;
59
+ }
60
+ let pkgDir;
61
+ try {
62
+ pkgDir = path.dirname(createRequire(import.meta.url).resolve('agent-browser/package.json'));
63
+ }
64
+ catch {
65
+ throw new AgentBrowserMissingError('the agent-browser package is not installed with this Cortex server', `reinstall @cortex-agent/server, or set ${AGENT_BROWSER_BIN_ENV} to an agent-browser binary`);
66
+ }
67
+ const name = agentBrowserBinaryName();
68
+ const file = name ? path.join(pkgDir, 'bin', name) : null;
69
+ if (!file || !fs.existsSync(file)) {
70
+ throw new AgentBrowserMissingError(`agent-browser has no binary for ${process.platform}-${process.arch}`, `build one and set ${AGENT_BROWSER_BIN_ENV} to its path`);
71
+ }
72
+ ensureExecutable(file);
73
+ return file;
74
+ }
75
+ /** Device names and session ids become part of a socket file name; keep them filesystem-safe. */
76
+ function slug(value, max) {
77
+ return value.replace(/[^A-Za-z0-9_-]/g, '').slice(0, max) || 'x';
78
+ }
79
+ /** The agent-browser session (daemon + pinned tab) for one Cortex session on one device. */
80
+ export function agentBrowserSessionName(sessionId, device) {
81
+ return `cortex-${slug(sessionId, 36)}-${slug(device, 24)}`;
82
+ }
83
+ /**
84
+ * The arguments every call carries. `--cdp` is not sticky: one call without it makes the daemon
85
+ * launch a Chrome of its own. `--pin-tab` keeps the session on its own tab when several sessions
86
+ * share one Chrome.
87
+ */
88
+ export function agentBrowserArgs(cdpEndpoint, abSession, args) {
89
+ return ['--cdp', cdpEndpoint, '--session', abSession, '--pin-tab', ...args];
90
+ }
91
+ /** The bound tab no longer exists (the Chrome behind it was replaced or the tab was closed). */
92
+ export function isTabGone(stderr) {
93
+ return /(^|\s)tab_gone[:\s]/.test(stderr) || stderr.includes('"code":"tab_gone"');
94
+ }
95
+ /** Variables an agent-browser daemon may inherit. Everything else — tokens, API keys, chat
96
+ * credentials — stays out of a long-lived third-party process. */
97
+ const ENV_ALLOW = new Set([
98
+ 'PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'LANG', 'LANGUAGE', 'TZ', 'TMPDIR', 'TMP', 'TEMP',
99
+ 'XDG_RUNTIME_DIR', 'XDG_CONFIG_HOME', 'XDG_CACHE_HOME', 'XDG_DATA_HOME',
100
+ 'SYSTEMROOT', 'WINDIR', 'USERPROFILE', 'APPDATA', 'LOCALAPPDATA', 'PROGRAMFILES', 'PROGRAMDATA',
101
+ 'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'no_proxy', 'all_proxy',
102
+ 'SSL_CERT_FILE',
103
+ ]);
104
+ /** Variables the broker decides and a caller's environment must not override. */
105
+ const ENV_PINNED = new Set([
106
+ 'AGENT_BROWSER_SOCKET_DIR', 'AGENT_BROWSER_SESSION', 'AGENT_BROWSER_CDP', 'AGENT_BROWSER_NAMESPACE',
107
+ 'AGENT_BROWSER_PROVIDER', 'AGENT_BROWSER_AUTO_CONNECT', 'AGENT_BROWSER_PIN_TAB', 'AGENT_BROWSER_ENGINE',
108
+ ]);
109
+ function defaultSocketDir(env) {
110
+ if (env.XDG_RUNTIME_DIR)
111
+ return path.join(env.XDG_RUNTIME_DIR, 'agent-browser');
112
+ return path.join(env.HOME || os.homedir(), '.agent-browser');
113
+ }
114
+ /**
115
+ * The environment agent-browser runs under, computed once in the daemon and handed to every CLI
116
+ * call. Pinning the socket directory is what makes the CLI and the daemon reach the same
117
+ * agent-browser daemon: tab bindings live beside its socket, so two directories would mean two
118
+ * tabs for one session.
119
+ */
120
+ export function agentBrowserBaseEnv(env = process.env) {
121
+ const out = {};
122
+ for (const [key, value] of Object.entries(env)) {
123
+ if (value === undefined)
124
+ continue;
125
+ if (ENV_ALLOW.has(key) || key.startsWith('LC_') || (key.startsWith('AGENT_BROWSER_') && !ENV_PINNED.has(key))) {
126
+ out[key] = value;
127
+ }
128
+ }
129
+ out.AGENT_BROWSER_SOCKET_DIR = env.AGENT_BROWSER_SOCKET_DIR || defaultSocketDir(env);
130
+ return out;
131
+ }
132
+ /** `base` plus the caller's own AGENT_BROWSER_* tuning (output limits, timeouts), minus anything
133
+ * that would redirect it to another daemon, browser or tab. */
134
+ export function agentBrowserCallEnv(base, callerEnv) {
135
+ const out = { ...base };
136
+ for (const [key, value] of Object.entries(callerEnv)) {
137
+ if (value !== undefined && key.startsWith('AGENT_BROWSER_') && !ENV_PINNED.has(key))
138
+ out[key] = value;
139
+ }
140
+ return out;
141
+ }
142
+ /** Run agent-browser to completion, capturing output. For the daemon's own calls; the CLI streams. */
143
+ export function runAgentBrowserProcess(bin, args, opts) {
144
+ return new Promise((resolve) => {
145
+ let stdout = '';
146
+ let stderr = '';
147
+ let settled = false;
148
+ const child = spawn(bin, args, { env: opts.env, cwd: opts.cwd, stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
149
+ const finish = (run) => {
150
+ if (settled)
151
+ return;
152
+ settled = true;
153
+ clearTimeout(timer);
154
+ resolve(run);
155
+ };
156
+ const timer = setTimeout(() => {
157
+ child.kill('SIGKILL');
158
+ finish({ code: 124, stdout, stderr: `${stderr}agent-browser timed out after ${opts.timeoutMs}ms\n` });
159
+ }, opts.timeoutMs ?? 120_000);
160
+ child.stdout.on('data', (chunk) => { stdout += String(chunk); });
161
+ child.stderr.on('data', (chunk) => { stderr += String(chunk); });
162
+ child.on('error', (e) => finish({ code: 127, stdout, stderr: `${stderr}cannot run ${bin}: ${e.message}\n` }));
163
+ child.on('close', (code, signal) => finish({ code: code ?? (signal ? 128 : 1), stdout, stderr }));
164
+ });
165
+ }
@@ -1,6 +1,6 @@
1
1
  import { type BrowserDisplay } from './display.js';
2
2
  export interface ManagedBrowser {
3
- /** What `@playwright/mcp --cdp-endpoint` receives. */
3
+ /** What agent-browser attaches to with `--cdp`. */
4
4
  cdpEndpoint: string;
5
5
  port: number;
6
6
  display: BrowserDisplay;
@@ -9,16 +9,6 @@ export interface ManagedBrowser {
9
9
  /** The device name meaning "this host". Kept next to the local browser rather than in the remote
10
10
  * domain, because it is precisely the value that means "no device is involved". */
11
11
  export declare const BROWSER_DEVICE_SERVER = "server";
12
- /**
13
- * Can this backend actually receive the browser tools?
14
- *
15
- * All three spawn paths compose it now, by three different routes: Claude print and Claude TUI both
16
- * append a `--mcp-config` file, and PI writes the same server descriptor into the envelope its MCP
17
- * bridge reads. The check stays rather than becoming `true` because the cost of getting it wrong is
18
- * asymmetric — starting Chrome for a backend that cannot drive it burns a browser nobody can use
19
- * and leaves the user staring at a window their agent cannot see.
20
- */
21
- export declare function backendSupportsBrowser(backend: string): boolean;
22
12
  /** Acquire the shared browser, starting it on first use. Every caller MUST pair this with
23
13
  * {@link releaseBrowser} — the refcount is what keeps Chrome alive. */
24
14
  export declare function acquireBrowser(): Promise<ManagedBrowser>;
@@ -32,18 +32,6 @@ let restartTimes = [];
32
32
  /** The device name meaning "this host". Kept next to the local browser rather than in the remote
33
33
  * domain, because it is precisely the value that means "no device is involved". */
34
34
  export const BROWSER_DEVICE_SERVER = 'server';
35
- /**
36
- * Can this backend actually receive the browser tools?
37
- *
38
- * All three spawn paths compose it now, by three different routes: Claude print and Claude TUI both
39
- * append a `--mcp-config` file, and PI writes the same server descriptor into the envelope its MCP
40
- * bridge reads. The check stays rather than becoming `true` because the cost of getting it wrong is
41
- * asymmetric — starting Chrome for a backend that cannot drive it burns a browser nobody can use
42
- * and leaves the user staring at a window their agent cannot see.
43
- */
44
- export function backendSupportsBrowser(backend) {
45
- return backend === 'claude' || backend === 'pi';
46
- }
47
35
  /** Acquire the shared browser, starting it on first use. Every caller MUST pair this with
48
36
  * {@link releaseBrowser} — the refcount is what keeps Chrome alive. */
49
37
  export async function acquireBrowser() {
@@ -180,6 +168,10 @@ async function launchInto(attempt) {
180
168
  ];
181
169
  if (display.mode === 'headless')
182
170
  args.push('--headless=new');
171
+ // Without this, Linux Chrome asks the desktop keyring for its cookie key over D-Bus, and the first
172
+ // page load stalls ~25s until that times out — after which Chrome falls back to this store anyway.
173
+ if (process.platform === 'linux')
174
+ args.push('--password-store=basic');
183
175
  const env = { ...process.env };
184
176
  if (displayName)
185
177
  env.DISPLAY = displayName;
@@ -0,0 +1,110 @@
1
+ import type * as http from 'http';
2
+ import type { Duplex } from 'stream';
3
+ import type { CustomRouteHandler } from './ui-http-server.js';
4
+ export declare const BROWSER_SESSIONS_PATH = "/api/browser/sessions";
5
+ export declare const BROWSER_TICKET_PATH = "/api/browser/stream-ticket";
6
+ export declare const BROWSER_STREAM_PATH = "/api/browser/stream";
7
+ export declare const BROWSER_TAKEOVER_PATH = "/api/browser/takeover";
8
+ export declare const BROWSER_INSERT_TEXT_PATH = "/api/browser/insert-text";
9
+ /** The session has no stream to attach to (no lease, still starting, or its daemon went away). */
10
+ export declare const CLOSE_NO_STREAM = 4004;
11
+ /** The upstream stream ended underneath a live viewer. The app reconnects with a fresh ticket. */
12
+ export declare const CLOSE_UPSTREAM_GONE = 4010;
13
+ /** Longest text the paste field may insert at once. */
14
+ export declare const MAX_INSERT_TEXT_CHARS = 4000;
15
+ /** How long a takeover survives its window's stream being gone, so a reload or a blip keeps it. */
16
+ export declare const TAKEOVER_GRACE_MS = 30000;
17
+ /** How long a takeover lasts without any input from the person. */
18
+ export declare const TAKEOVER_IDLE_MS: number;
19
+ /** Message the proxy adds to the stream whenever the takeover changes (and once on connect). */
20
+ export declare const TAKEOVER_MESSAGE = "cortex_takeover";
21
+ export type BrowserSessionState = 'starting' | 'ready' | 'error';
22
+ /** One leased browser as the app sees it. The domain owns the full record. */
23
+ export interface BrowserSessionView {
24
+ sessionId: string;
25
+ device: string;
26
+ state: BrowserSessionState;
27
+ error?: string;
28
+ url?: string;
29
+ title?: string;
30
+ takenOver: boolean;
31
+ lastUsedAt: number;
32
+ }
33
+ /**
34
+ * The browser broker, injected: platform may not depend on domain, and the entry layer already owns
35
+ * joining the two.
36
+ */
37
+ export interface BrowserStreamDeps {
38
+ listSessions: () => BrowserSessionView[];
39
+ /** Loopback port of the session's agent-browser stream, or null when it has none. */
40
+ streamPort: (sessionId: string) => Promise<number | null>;
41
+ setTakeover: (sessionId: string, on: boolean) => void | Promise<void>;
42
+ isTakenOver: (sessionId: string) => boolean;
43
+ insertText: (sessionId: string, text: string) => Promise<void>;
44
+ /** Clock injection for tests. */
45
+ now?: () => number;
46
+ }
47
+ export interface BrowserStreamOptions {
48
+ graceMs?: number;
49
+ idleMs?: number;
50
+ }
51
+ export interface BrowserStreamHandle {
52
+ routes: Record<string, CustomRouteHandler>;
53
+ /** Upgrade handler for BROWSER_STREAM_PATH. Authenticates by ticket itself. */
54
+ handleUpgrade: (req: http.IncomingMessage, socket: Duplex, head: Buffer) => void;
55
+ close: () => void;
56
+ }
57
+ /**
58
+ * Decide what of a viewer's message reaches the page. Acks always pass (they only pace frames);
59
+ * input passes only from the window holding the page, so a watcher can never steer it by accident.
60
+ * Everything else (a `config` raising the frame rate, unknown types) is dropped. `input` marks the
61
+ * person's own activity, which keeps the takeover alive.
62
+ */
63
+ export declare function admitClientMessage(raw: string, holdsPage: boolean): {
64
+ message: string;
65
+ input: boolean;
66
+ } | null;
67
+ /** A body's `client`: '' when absent, null when present but malformed. */
68
+ export declare function parseClientId(value: unknown): string | null;
69
+ /** The frame-rate cap a viewer asked for, clamped to what the tunnel should carry. */
70
+ export declare function clampFps(raw: string | null): number;
71
+ export interface StreamTarget {
72
+ sessionId: string;
73
+ ticket: string;
74
+ fps: number;
75
+ }
76
+ export declare function parseStreamTarget(rawUrl: string): StreamTarget | null;
77
+ export interface TicketStore {
78
+ mint: (sessionId: string, client?: string) => string;
79
+ /** Spend a ticket. The window it was minted for, only for a live ticket of this very session. */
80
+ redeem: (ticket: string, sessionId: string) => {
81
+ client: string;
82
+ } | null;
83
+ size: () => number;
84
+ }
85
+ export declare function createTicketStore(now?: () => number): TicketStore;
86
+ export type ReleaseReason = 'disconnected' | 'idle';
87
+ export interface TakeoverWatchDeps {
88
+ isTakenOver: (sessionId: string) => boolean;
89
+ /** Hand the page back to the agent on the person's behalf. */
90
+ release: (sessionId: string, reason: ReleaseReason) => void;
91
+ /** Whether a stream from this window is open on the session right now. */
92
+ hasClient: (sessionId: string, client: string) => boolean;
93
+ now: () => number;
94
+ graceMs: number;
95
+ idleMs: number;
96
+ }
97
+ export interface TakeoverWatch {
98
+ begin: (sessionId: string, client: string) => void;
99
+ end: (sessionId: string) => void;
100
+ /** The window holding the session's page, or null. */
101
+ holder: (sessionId: string) => string | null;
102
+ /** A stream opened / closed. Call `disconnected` once the stream is out of the live set. */
103
+ connected: (sessionId: string, client: string) => void;
104
+ disconnected: (sessionId: string, client: string) => void;
105
+ /** The person did something: a click, a key, a paste. */
106
+ input: (sessionId: string) => void;
107
+ close: () => void;
108
+ }
109
+ export declare function createTakeoverWatch(deps: TakeoverWatchDeps): TakeoverWatch;
110
+ export declare function createBrowserStream(deps: BrowserStreamDeps, opts?: BrowserStreamOptions): BrowserStreamHandle;