@lobu/runtime-device 21.2.1 → 23.0.0

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 (233) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +91 -83
  3. package/npm-shrinkwrap.json +492 -438
  4. package/package.json +12 -2
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +1 -1
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +5 -6
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +1 -0
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +26 -7
  9. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +9 -1
  10. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +1 -0
  11. package/vendor/cli/dist/commands/_lib/apply/diff.js +46 -4
  12. package/vendor/cli/dist/commands/_lib/apply/map-config.js +18 -38
  13. package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +5 -17
  14. package/vendor/cli/dist/commands/init.d.ts +0 -2
  15. package/vendor/cli/dist/commands/init.js +0 -27
  16. package/vendor/cli/dist/commands/login.d.ts +17 -0
  17. package/vendor/cli/dist/commands/login.js +43 -17
  18. package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +0 -8
  19. package/vendor/cli/dist/commands/memory/_lib/errors.js +0 -12
  20. package/vendor/cli/dist/commands/memory/_lib/mcp.js +6 -6
  21. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +4 -10
  22. package/vendor/cli/dist/config/define.d.ts +21 -15
  23. package/vendor/cli/dist/config/define.js +2 -2
  24. package/vendor/cli/dist/connectors/README.md +21 -6
  25. package/vendor/cli/dist/connectors/_google/actions.ts +270 -0
  26. package/vendor/cli/dist/connectors/_google/discovery/calendar_v3.json +1 -0
  27. package/vendor/cli/dist/connectors/_google/discovery/chat_v1.json +1 -0
  28. package/vendor/cli/dist/connectors/_google/discovery/docs_v1.json +1 -0
  29. package/vendor/cli/dist/connectors/_google/discovery/drive_v3.json +1 -0
  30. package/vendor/cli/dist/connectors/_google/discovery/gmail_v1.json +1 -0
  31. package/vendor/cli/dist/connectors/_google/discovery/people_v1.json +1 -0
  32. package/vendor/cli/dist/connectors/_google/discovery/sheets_v4.json +1 -0
  33. package/vendor/cli/dist/connectors/_google/discovery/tasks_v1.json +1 -0
  34. package/vendor/cli/dist/connectors/_google/discovery/youtube_v3.json +1 -0
  35. package/vendor/cli/dist/connectors/_google/discovery.ts +442 -0
  36. package/vendor/cli/dist/connectors/_google/errors.ts +91 -0
  37. package/vendor/cli/dist/connectors/_google/list-feed.ts +223 -0
  38. package/vendor/cli/dist/connectors/_google/policies.ts +127 -0
  39. package/vendor/cli/dist/connectors/agentid.ts +43 -0
  40. package/vendor/cli/dist/connectors/chat-user-identity.ts +2 -1
  41. package/vendor/cli/dist/connectors/github-automation-events.ts +9 -0
  42. package/vendor/cli/dist/connectors/github-identity.ts +28 -3
  43. package/vendor/cli/dist/connectors/github.ts +101 -59
  44. package/vendor/cli/dist/connectors/google_calendar.ts +207 -719
  45. package/vendor/cli/dist/connectors/google_drive.ts +16 -2
  46. package/vendor/cli/dist/connectors/google_gmail.ts +52 -33
  47. package/vendor/cli/dist/connectors/herdr.ts +406 -0
  48. package/vendor/cli/dist/connectors/jira-helpers.ts +313 -0
  49. package/vendor/cli/dist/connectors/jira.ts +35 -227
  50. package/vendor/cli/dist/connectors/linear.ts +7 -4
  51. package/vendor/cli/dist/connectors/linkedin-browser-script.ts +13 -0
  52. package/vendor/cli/dist/connectors/linkedin-draft-page.js +104 -0
  53. package/vendor/cli/dist/connectors/linkedin-drafts.ts +73 -0
  54. package/vendor/cli/dist/connectors/linkedin-identity.ts +32 -0
  55. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +1185 -0
  56. package/vendor/cli/dist/connectors/linkedin-inbox.ts +156 -0
  57. package/vendor/cli/dist/connectors/linkedin-like.ts +114 -0
  58. package/vendor/cli/dist/connectors/linkedin-takeout.ts +577 -0
  59. package/vendor/cli/dist/connectors/linkedin.ts +3998 -0
  60. package/vendor/cli/dist/connectors/postgres.ts +27 -2
  61. package/vendor/cli/dist/connectors/takeout-utils.ts +240 -0
  62. package/vendor/cli/dist/connectors/tiktok-inbox-page.js +230 -0
  63. package/vendor/cli/dist/connectors/tiktok-web-page.js +217 -0
  64. package/vendor/cli/dist/connectors/tiktok_web.ts +319 -0
  65. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +285 -567
  66. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +74 -455
  67. package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +135 -0
  68. package/vendor/cli/dist/connectors/whatsapp_web.ts +159 -618
  69. package/vendor/cli/dist/connectors/x-dm-adapter.js +556 -0
  70. package/vendor/cli/dist/connectors/x-identity.ts +31 -2
  71. package/vendor/cli/dist/connectors/x.ts +539 -253
  72. package/vendor/cli/dist/index.js +1 -37
  73. package/vendor/cli/dist/internal/context.d.ts +10 -0
  74. package/vendor/cli/dist/internal/context.js +26 -16
  75. package/vendor/cli/dist/internal/node-version.d.ts +1 -1
  76. package/vendor/cli/dist/internal/node-version.js +1 -1
  77. package/vendor/cli/dist/internal/oauth.d.ts +3 -1
  78. package/vendor/cli/dist/internal/oauth.js +4 -3
  79. package/vendor/cli/dist/internal/runtime-components.d.ts +9 -0
  80. package/vendor/cli/dist/internal/runtime-components.js +67 -2
  81. package/vendor/cli/dist/mac-auth.js +17 -1
  82. package/vendor/cli/dist/providers.json +1 -1
  83. package/vendor/cli/dist/runtime-components.json +4 -4
  84. package/vendor/cli/dist/templates/AGENTS.md.tmpl +12 -5
  85. package/vendor/cli/dist/templates/README.md.tmpl +1 -1
  86. package/vendor/cli/dist/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  87. package/vendor/cli/dist/vendor/ora/index.d.ts +332 -0
  88. package/vendor/cli/dist/vendor/ora/index.js +424 -0
  89. package/vendor/cli/dist/vendor/ora/license +9 -0
  90. package/vendor/cli/dist/vendor/ora/package.json +64 -0
  91. package/vendor/cli/dist/vendor/ora/readme.md +329 -0
  92. package/vendor/cli/package.json +2 -2
  93. package/vendor/connector-sdk/dist/browser-handoff-banner.d.ts +39 -0
  94. package/vendor/connector-sdk/dist/browser-handoff-banner.js +175 -0
  95. package/vendor/connector-sdk/dist/browser-requirement.d.ts +36 -0
  96. package/vendor/connector-sdk/dist/browser-requirement.js +60 -0
  97. package/vendor/connector-sdk/dist/browser-source-read.d.ts +52 -0
  98. package/vendor/connector-sdk/dist/browser-source-read.js +107 -0
  99. package/vendor/connector-sdk/dist/connector-runtime.d.ts +3 -1
  100. package/vendor/connector-sdk/dist/connector-runtime.js +10 -0
  101. package/vendor/connector-sdk/dist/connector-types.d.ts +169 -45
  102. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -2
  103. package/vendor/connector-sdk/dist/define-connector.js +3 -0
  104. package/vendor/connector-sdk/dist/index.d.ts +8 -2
  105. package/vendor/connector-sdk/dist/index.js +3 -0
  106. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +16 -21
  107. package/vendor/connector-sdk/dist/reaction-client-types.typecheck.d.ts +5 -0
  108. package/vendor/connector-sdk/package.json +13 -1
  109. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +43 -30
  110. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +416 -330
  111. package/vendor/connector-worker/dist/agent-turn/memory.d.ts +3 -2
  112. package/vendor/connector-worker/dist/agent-turn/memory.js +3 -20
  113. package/vendor/connector-worker/dist/agent-turn/types.d.ts +3 -15
  114. package/vendor/connector-worker/dist/agent-turn/workspace.d.ts +2 -2
  115. package/vendor/connector-worker/dist/agent-turn/workspace.js +2 -4
  116. package/vendor/connector-worker/dist/daemon/action-monitor.d.ts +12 -0
  117. package/vendor/connector-worker/dist/daemon/action-monitor.js +25 -0
  118. package/vendor/connector-worker/dist/daemon/agent-turn.js +0 -9
  119. package/vendor/connector-worker/dist/daemon/automation.d.ts +4 -11
  120. package/vendor/connector-worker/dist/daemon/automation.js +6 -6
  121. package/vendor/connector-worker/dist/daemon/builtins/index.d.ts +12 -0
  122. package/vendor/connector-worker/dist/daemon/builtins/index.js +61 -1
  123. package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +2 -1
  124. package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +40 -27
  125. package/vendor/connector-worker/dist/daemon/client.d.ts +6 -4
  126. package/vendor/connector-worker/dist/daemon/client.js +3 -3
  127. package/vendor/connector-worker/dist/daemon/device-concurrency.d.ts +8 -0
  128. package/vendor/connector-worker/dist/daemon/device-concurrency.js +13 -0
  129. package/vendor/connector-worker/dist/daemon/executor.d.ts +1 -1
  130. package/vendor/connector-worker/dist/daemon/executor.js +48 -120
  131. package/vendor/connector-worker/dist/daemon/log.d.ts +2 -0
  132. package/vendor/connector-worker/dist/daemon/log.js +23 -2
  133. package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +23 -6
  134. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +57 -23
  135. package/vendor/connector-worker/dist/daemon/native-bridge/client.d.ts +6 -0
  136. package/vendor/connector-worker/dist/daemon/native-bridge/client.js +15 -0
  137. package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +29 -25
  138. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.d.ts +1 -1
  139. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.js +1 -0
  140. package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +3 -0
  141. package/vendor/connector-worker/dist/daemon/poll-loop.js +5 -1
  142. package/vendor/connector-worker/dist/daemon/start.d.ts +1 -0
  143. package/vendor/connector-worker/dist/daemon/start.js +15 -20
  144. package/vendor/connector-worker/dist/daemon/terminal-failure.js +0 -11
  145. package/vendor/connector-worker/dist/daemon/worker-id.d.ts +17 -0
  146. package/vendor/connector-worker/dist/daemon/worker-id.js +22 -0
  147. package/vendor/connector-worker/dist/executor/interface.d.ts +34 -2
  148. package/vendor/connector-worker/dist/executor/isolate.js +66 -15
  149. package/vendor/connector-worker/dist/executor/redact.d.ts +1 -0
  150. package/vendor/connector-worker/dist/executor/redact.js +97 -26
  151. package/vendor/connector-worker/dist/executor/runtime.d.ts +7 -0
  152. package/vendor/connector-worker/dist/executor/runtime.js +26 -0
  153. package/vendor/connector-worker/dist/isolate/bridge.js +3 -1
  154. package/vendor/connector-worker/dist/mac-device-daemon.js +24 -29
  155. package/vendor/connector-worker/package.json +2 -2
  156. package/vendor/core/dist/agent-policy.js +1 -1
  157. package/vendor/core/dist/agent-store.d.ts +2 -0
  158. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  159. package/vendor/core/dist/agent-tooling.js +1 -1
  160. package/vendor/core/dist/capabilities.d.ts +1 -1
  161. package/vendor/core/dist/capabilities.js +2 -1
  162. package/vendor/core/dist/connector-query-errors.d.ts +32 -0
  163. package/vendor/core/dist/connector-query-errors.js +41 -1
  164. package/vendor/core/dist/contracts/agent-settings.d.ts +0 -11
  165. package/vendor/core/dist/contracts/agent-settings.js +1 -7
  166. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +93 -0
  167. package/vendor/core/dist/contracts/tools/collection-presentation.js +88 -0
  168. package/vendor/core/dist/contracts/tools/collection-selection.d.ts +47 -0
  169. package/vendor/core/dist/contracts/tools/collection-selection.js +74 -0
  170. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +10 -4
  171. package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +1 -1
  172. package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +5 -1
  173. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +19 -4
  174. package/vendor/core/dist/contracts/tools/manage-automations.js +25 -8
  175. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +1 -0
  176. package/vendor/core/dist/contracts/tools/manage-connections.js +3 -0
  177. package/vendor/core/dist/contracts/tools/manage-conversations.js +2 -2
  178. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +11 -0
  179. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +42 -3
  180. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +181 -152
  181. package/vendor/core/dist/contracts/tools/manage-entity.js +118 -162
  182. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +14 -0
  183. package/vendor/core/dist/contracts/tools/manage-feeds.js +17 -0
  184. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +41 -3
  185. package/vendor/core/dist/contracts/tools/manage-operations.js +40 -2
  186. package/vendor/core/dist/contracts/tools/manage-views.d.ts +182 -7
  187. package/vendor/core/dist/contracts/tools/manage-views.js +49 -13
  188. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +11 -2
  189. package/vendor/core/dist/contracts/tools/read-knowledge.js +23 -3
  190. package/vendor/core/dist/contracts/tools/save-memory.d.ts +3 -6
  191. package/vendor/core/dist/contracts/tools/save-memory.js +2 -6
  192. package/vendor/core/dist/contracts/tools/view-attach.d.ts +2 -1
  193. package/vendor/core/dist/contracts/tools/view-attach.js +7 -2
  194. package/vendor/core/dist/contracts/worker/protocol.d.ts +130 -159
  195. package/vendor/core/dist/contracts/worker/protocol.js +88 -76
  196. package/vendor/core/dist/device-pin-tombstones.d.ts +44 -0
  197. package/vendor/core/dist/device-pin-tombstones.js +57 -0
  198. package/vendor/core/dist/index.d.ts +5 -5
  199. package/vendor/core/dist/index.js +4 -6
  200. package/vendor/core/dist/json-template.d.ts +6 -10
  201. package/vendor/core/dist/json-template.js +5 -9
  202. package/vendor/core/dist/logger.js +17 -26
  203. package/vendor/core/dist/shell-safety.d.ts +9 -0
  204. package/vendor/core/dist/shell-safety.js +154 -0
  205. package/vendor/core/dist/suggestions.d.ts +1 -1
  206. package/vendor/core/dist/suggestions.js +1 -1
  207. package/vendor/core/dist/tool-trace-summary.d.ts +1 -1
  208. package/vendor/core/dist/tool-trace-summary.js +1 -1
  209. package/vendor/core/dist/types.d.ts +1 -3
  210. package/vendor/core/dist/utils/diagnostic-scrubber.d.ts +7 -0
  211. package/vendor/core/dist/utils/diagnostic-scrubber.js +437 -0
  212. package/vendor/core/dist/worker/auth.d.ts +44 -6
  213. package/vendor/core/dist/worker/auth.js +44 -11
  214. package/vendor/core/dist/worker/wire.d.ts +0 -10
  215. package/vendor/core/package.json +20 -11
  216. package/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  217. package/vendor/ora/index.d.ts +332 -0
  218. package/vendor/ora/index.js +424 -0
  219. package/vendor/ora/license +9 -0
  220. package/vendor/ora/package.json +53 -0
  221. package/vendor/ora/readme.md +329 -0
  222. package/vendor/cli/dist/commands/telemetry.d.ts +0 -10
  223. package/vendor/cli/dist/commands/telemetry.js +0 -66
  224. package/vendor/connector-worker/dist/daemon/device-chat.d.ts +0 -9
  225. package/vendor/connector-worker/dist/daemon/device-chat.js +0 -61
  226. package/vendor/core/dist/contracts/worker/device-chat.d.ts +0 -4
  227. package/vendor/core/dist/contracts/worker/device-chat.js +0 -26
  228. package/vendor/core/dist/sentry.d.ts +0 -26
  229. package/vendor/core/dist/sentry.js +0 -133
  230. package/vendor/core/dist/tool-policy.d.ts +0 -74
  231. package/vendor/core/dist/tool-policy.js +0 -305
  232. package/vendor/core/dist/utils/sentry-scrubber.d.ts +0 -29
  233. package/vendor/core/dist/utils/sentry-scrubber.js +0 -228
@@ -4,15 +4,17 @@
4
4
  * Executes sync and action runs in a V8 isolate from compiled connector code.
5
5
  * Generates embeddings and streams results.
6
6
  */
7
+ import { validateBrowserRequirement } from '@lobu/connector-sdk';
7
8
  import { stableStringify } from '@lobu/core/contracts/tools/view-content-hash';
8
9
  import { executeAutomationRun } from './automation.js';
9
- import { executeDaemonBuiltin, hasDaemonBuiltin, hasDaemonBuiltinConnector, } from './builtins/index.js';
10
+ import { monitorActionRun } from './action-monitor.js';
11
+ import { executeDaemonBuiltinActionRun, hasDaemonBuiltin, hasDaemonBuiltinConnector, } from './builtins/index.js';
10
12
  import { executeAgentTurnRun } from './agent-turn.js';
11
- import { executeDeviceChatRun } from './device-chat.js';
12
13
  import { attachedInteractiveSession, attachInteractiveSession } from './interactive-session.js';
13
14
  import { log } from './log.js';
14
15
  import { reportTerminalFailure } from './terminal-failure.js';
15
16
  import { completeActionOnce } from './terminal-delivery.js';
17
+ import { envelopeToContentItem } from '../executor/runtime.js';
16
18
  import { withoutDeploymentProviderKeys } from '../env.js';
17
19
  export async function resolveJobCode(job) {
18
20
  if (job.compiled_code)
@@ -77,7 +79,20 @@ async function resolveJobExecution(select, job, timeoutMs, customExecutor) {
77
79
  return { ok: true, code: codeResult.code, executor: customExecutor };
78
80
  }
79
81
  try {
80
- const executor = await select.selectExecutor({ timeoutMs });
82
+ const executor = await select.selectExecutor({
83
+ timeoutMs,
84
+ logSink: (level, line) => {
85
+ const context = { run_id: job.run_id, connector_key: job.connector_key, source: 'connector' };
86
+ if (level === 'error')
87
+ log.error(context, line);
88
+ else if (level === 'warn')
89
+ log.warn(context, line);
90
+ else if (level === 'debug')
91
+ log.debug(context, line);
92
+ else
93
+ log.info(context, line);
94
+ },
95
+ });
81
96
  return { ok: true, code: codeResult.code, executor };
82
97
  }
83
98
  catch (err) {
@@ -176,7 +191,7 @@ export async function executeRun(client, job, workerEnv, config = {}) {
176
191
  await reportTerminalFailure(client, job, message, 'error_message');
177
192
  }
178
193
  catch (error) {
179
- log.info('[executor] Failed to reject invalid daemon built-in run:', error);
194
+ log.error('[executor] Failed to reject invalid daemon built-in run:', error);
180
195
  }
181
196
  return { itemsCollected: 0, error: message };
182
197
  }
@@ -201,8 +216,6 @@ export async function executeRun(client, job, workerEnv, config = {}) {
201
216
  // unreachable for them — but if a run does slip through (deploy skew), the
202
217
  // dispatcher reports the failure rather than stomping the run.
203
218
  return await executeAutomationRun(client, job, cfg);
204
- case 'chat_message':
205
- return await executeDeviceChatRun(client, job, cfg);
206
219
  case 'agent_turn':
207
220
  return await executeAgentTurnRun(client, job, env, cfg);
208
221
  case 'embed_backfill':
@@ -215,12 +228,12 @@ export async function executeRun(client, job, workerEnv, config = {}) {
215
228
  }
216
229
  catch (error) {
217
230
  const message = error instanceof Error ? error.message : String(error);
218
- log.info(`[executor] Unhandled ${job.run_type ?? 'unknown'} run ${job.run_id} failure:`, message);
231
+ log.error(`[executor] Unhandled ${job.run_type ?? 'unknown'} run ${job.run_id} failure:`, error);
219
232
  try {
220
233
  await reportTerminalFailure(client, job, message);
221
234
  }
222
235
  catch (completeErr) {
223
- log.info('[executor] Terminal completion after unhandled failure errored:', completeErr);
236
+ log.error('[executor] Terminal completion after unhandled failure errored:', completeErr);
224
237
  }
225
238
  return { itemsCollected: 0, error: message };
226
239
  }
@@ -237,7 +250,7 @@ async function executeSyncRun(client, job, env, cfg) {
237
250
  const execution = await resolveJobExecution(select, job, cfg.timeoutMs, cfg.executor);
238
251
  if (!execution.ok) {
239
252
  const errorMessage = `Run ${run_id} (${connector_key}): ${execution.error}`;
240
- log.info('[executor]', errorMessage);
253
+ log.error('[executor]', errorMessage);
241
254
  await client.complete({
242
255
  run_id,
243
256
  worker_id: client.id,
@@ -282,6 +295,7 @@ async function executeSyncRun(client, job, env, cfg) {
282
295
  executor: laneExecutor,
283
296
  job: {
284
297
  mode: 'sync',
298
+ browser: validatedBrowserGrant(job.browser_grant),
285
299
  httpAuth: job.http_auth,
286
300
  config: mergeEnv(env, job.connection_credentials, feedConfig),
287
301
  checkpoint: checkpoint,
@@ -348,7 +362,7 @@ async function executeSyncRun(client, job, env, cfg) {
348
362
  catch (error) {
349
363
  stopHeartbeat();
350
364
  const errorMessage = error instanceof Error ? error.message : String(error);
351
- log.info(`[executor] Sync run ${run_id} failed:`, errorMessage);
365
+ log.error(`[executor] Sync run ${run_id} failed:`, error);
352
366
  const diag = extractExecutionDiagnostics(error);
353
367
  await client.complete({
354
368
  run_id,
@@ -412,7 +426,7 @@ async function executeActionRun(client, job, env, cfg) {
412
426
  const execution = await resolveJobExecution(select, job, cfg.timeoutMs, cfg.executor);
413
427
  if (!execution.ok) {
414
428
  const errorMessage = `Action run ${run_id} (${connector_key}): ${execution.error}`;
415
- log.info('[executor]', errorMessage);
429
+ log.error('[executor]', errorMessage);
416
430
  await completeActionOnce(client, {
417
431
  run_id,
418
432
  worker_id: client.id,
@@ -424,21 +438,7 @@ async function executeActionRun(client, job, env, cfg) {
424
438
  const compiled_code = execution.code;
425
439
  const laneExecutor = execution.executor;
426
440
  log.info(`[executor] Starting action run ${run_id} (${connector_key}/${action_key})`);
427
- // Heartbeat so the gateway's stale-run reaper doesn't write us off
428
- // mid-action. Action runs can legitimately take minutes (LLM calls,
429
- // long Playwright sessions, third-party API rate-limit waits); the
430
- // reaper's default threshold is 120s, so a 30s heartbeat gives ~3
431
- // ticks of grace. Without this the row sits "running" until the worker
432
- // process dies, and the lane was previously excluded from the reaper
433
- // (lobu#859) because the heartbeat was missing.
434
- const heartbeatInterval = setInterval(async () => {
435
- try {
436
- await client.heartbeat(run_id);
437
- }
438
- catch (err) {
439
- log.debug('[executor] Action heartbeat failed:', err);
440
- }
441
- }, cfg.heartbeatIntervalMs);
441
+ const monitor = monitorActionRun(client, run_id, cfg);
442
442
  let terminalPayloadStarted = false;
443
443
  try {
444
444
  const result = await executeCompiledConnector({
@@ -446,6 +446,7 @@ async function executeActionRun(client, job, env, cfg) {
446
446
  executor: laneExecutor,
447
447
  job: {
448
448
  mode: 'action',
449
+ browser: validatedBrowserGrant(job.browser_grant),
449
450
  httpAuth: job.http_auth,
450
451
  // NOTE: unlike the gateway's inline action path (manage_operations
451
452
  // `executeLocalActionInline`, which merges the connection's own config
@@ -466,7 +467,13 @@ async function executeActionRun(client, job, env, cfg) {
466
467
  credentials: credentials ?? null,
467
468
  },
468
469
  hooks: {
470
+ signal: monitor.signal,
469
471
  ...(job.http_auth ? { onHttpFetch: (request, signal) => client.httpFetch(run_id, request, signal) } : {}),
472
+ onOperationExecute: async (request) => {
473
+ if (!client.executeConnectorOperation)
474
+ throw new Error('Connector operations are not available on this host');
475
+ return client.executeConnectorOperation({ parent_run_id: run_id, worker_id: client.id, request }, monitor.signal);
476
+ },
470
477
  onChromeDispatch: async (actionKey, actionInput) => {
471
478
  return client.dispatchChromeAction({
472
479
  parent_run_id: run_id,
@@ -481,6 +488,8 @@ async function executeActionRun(client, job, env, cfg) {
481
488
  throw new Error(`Expected action result, got mode=${result.mode}`);
482
489
  }
483
490
  const actionOutput = result.output;
491
+ if (monitor.revoked())
492
+ return { itemsCollected: 0 };
484
493
  terminalPayloadStarted = true;
485
494
  await completeActionOnce(client, {
486
495
  run_id,
@@ -493,8 +502,8 @@ async function executeActionRun(client, job, env, cfg) {
493
502
  }
494
503
  catch (error) {
495
504
  const errorMessage = error instanceof Error ? error.message : String(error);
496
- log.info(`[executor] Action run ${run_id} failed:`, errorMessage);
497
- if (terminalPayloadStarted) {
505
+ log.error(`[executor] Action run ${run_id} failed:`, error);
506
+ if (terminalPayloadStarted || monitor.revoked()) {
498
507
  return { itemsCollected: 0, error: errorMessage };
499
508
  }
500
509
  await completeActionOnce(client, {
@@ -506,67 +515,7 @@ async function executeActionRun(client, job, env, cfg) {
506
515
  return { itemsCollected: 0, error: errorMessage };
507
516
  }
508
517
  finally {
509
- clearInterval(heartbeatInterval);
510
- }
511
- }
512
- async function executeDaemonBuiltinActionRun(client, job, cfg) {
513
- const { run_id, connector_key, action_key, action_input } = job;
514
- if (!run_id || !connector_key || !action_key) {
515
- throw new Error('Invalid daemon built-in action: missing run_id, connector_key, or action_key');
516
- }
517
- if (job.compiled_code) {
518
- const message = 'operation_backend_unavailable: a daemon built-in payload must not contain compiled_code';
519
- await completeActionOnce(client, {
520
- run_id,
521
- worker_id: client.id,
522
- status: 'failed',
523
- error_message: message,
524
- });
525
- return { itemsCollected: 0, error: message };
526
- }
527
- const heartbeatInterval = setInterval(async () => {
528
- try {
529
- await client.heartbeat(run_id);
530
- }
531
- catch (error) {
532
- log.debug('[executor] Daemon built-in heartbeat failed:', error);
533
- }
534
- }, cfg.heartbeatIntervalMs);
535
- try {
536
- const result = await executeDaemonBuiltin({
537
- connectorKey: connector_key,
538
- actionKey: action_key,
539
- input: (action_input ?? {}),
540
- shutdownSignal: cfg.shutdownSignal,
541
- });
542
- if (!result.ok) {
543
- const message = `${result.code}: ${result.error}`;
544
- await completeActionOnce(client, {
545
- run_id,
546
- worker_id: client.id,
547
- status: 'failed',
548
- error_message: message,
549
- ...(result.output ? { action_output: result.output } : {}),
550
- });
551
- return { itemsCollected: 0, error: message };
552
- }
553
- await completeActionOnce(client, {
554
- run_id,
555
- worker_id: client.id,
556
- status: 'success',
557
- action_output: result.output,
558
- });
559
- return { itemsCollected: 0 };
560
- }
561
- catch (error) {
562
- // Delivery uncertainty is not an execution failure. The immutable payload
563
- // was retried above; never send a contradictory terminal result here.
564
- const message = error instanceof Error ? error.message : String(error);
565
- log.info(`[executor] Daemon built-in terminal delivery uncertain for ${run_id}:`, message);
566
- return { itemsCollected: 0, error: message };
567
- }
568
- finally {
569
- clearInterval(heartbeatInterval);
518
+ monitor.stop();
570
519
  }
571
520
  }
572
521
  /**
@@ -585,7 +534,7 @@ async function executeAuthRun(client, job, env, cfg) {
585
534
  const execution = await resolveJobExecution(select, job, 0, cfg.executor);
586
535
  if (!execution.ok) {
587
536
  const errorMessage = `Auth run ${run_id} (${connector_key}): ${execution.error}`;
588
- log.info('[executor]', errorMessage);
537
+ log.error('[executor]', errorMessage);
589
538
  await client.completeAuth({
590
539
  run_id,
591
540
  worker_id: client.id,
@@ -670,7 +619,7 @@ async function executeAuthRun(client, job, env, cfg) {
670
619
  catch (error) {
671
620
  clearInterval(heartbeatInterval);
672
621
  const errorMessage = error instanceof Error ? error.message : String(error);
673
- log.info(`[executor] Auth run ${run_id} failed:`, errorMessage);
622
+ log.error(`[executor] Auth run ${run_id} failed:`, error);
674
623
  const diag = extractExecutionDiagnostics(error);
675
624
  try {
676
625
  await client.completeAuth({
@@ -818,7 +767,7 @@ async function executeEmbedBackfillRun(client, job, _env, cfg) {
818
767
  }
819
768
  catch (error) {
820
769
  const errorMessage = error instanceof Error ? error.message : String(error);
821
- log.info(`[executor] Embed backfill run ${run_id} failed:`, errorMessage);
770
+ log.error(`[executor] Embed backfill run ${run_id} failed:`, error);
822
771
  await client.complete({
823
772
  run_id,
824
773
  worker_id: client.id,
@@ -844,33 +793,6 @@ function mergeEnv(env, connectionCredentials, feedConfig) {
844
793
  ...(feedConfig ?? {}),
845
794
  };
846
795
  }
847
- /**
848
- * Convert a V1 EventEnvelope (the SDK's standard sync output) into the
849
- * gateway-bound ContentItem shape (without an embedding).
850
- */
851
- function toContentItem(event) {
852
- const occurredAtIso = event.occurred_at instanceof Date
853
- ? event.occurred_at.toISOString()
854
- : event.occurred_at;
855
- return {
856
- id: event.origin_id,
857
- title: event.title,
858
- payload_type: event.payload_type,
859
- payload_text: event.payload_text,
860
- payload_data: event.payload_data,
861
- payload_template: event.payload_template,
862
- attachments: event.attachments,
863
- author_name: event.author_name,
864
- occurred_at: occurredAtIso,
865
- source_url: event.source_url ?? undefined,
866
- score: typeof event.score === 'number' ? event.score : 0,
867
- metadata: event.metadata ?? {},
868
- origin_parent_id: event.origin_parent_id ?? undefined,
869
- origin_type: event.origin_type,
870
- semantic_type: event.semantic_type ?? event.origin_type,
871
- automation_signals: event.automation_signals,
872
- };
873
- }
874
796
  /**
875
797
  * Convert a chunk of events into ContentItems, generating embeddings for the
876
798
  * whole chunk in a single batch call (one HTTP round-trip / vectorized local
@@ -880,7 +802,7 @@ function toContentItem(event) {
880
802
  * semantics as the previous per-event path).
881
803
  */
882
804
  async function processEventChunk(events, generateEmbeddings) {
883
- const contentItems = events.map(toContentItem);
805
+ const contentItems = events.map(envelopeToContentItem);
884
806
  if (!generateEmbeddings || contentItems.length === 0) {
885
807
  return contentItems;
886
808
  }
@@ -918,4 +840,10 @@ async function processEventChunk(events, generateEmbeddings) {
918
840
  }
919
841
  return contentItems;
920
842
  }
843
+ function validatedBrowserGrant(value) {
844
+ if (value == null)
845
+ return undefined;
846
+ validateBrowserRequirement(value);
847
+ return value;
848
+ }
921
849
  //# sourceMappingURL=executor.js.map
@@ -10,6 +10,8 @@ export declare function setDebug(enabled: boolean): void;
10
10
  export declare const log: {
11
11
  /** Always-on: one line per run, startup/shutdown, and hard failures. */
12
12
  info: (...parts: unknown[]) => void;
13
+ warn: (...parts: unknown[]) => void;
14
+ error: (...parts: unknown[]) => void;
13
15
  /** Debug-only: poll chatter, heartbeats, retry and backoff detail. */
14
16
  debug: (...parts: unknown[]) => void;
15
17
  };
@@ -6,19 +6,40 @@
6
6
  * the run's start and its terminal result — plus startup/shutdown and hard
7
7
  * failures. Pass `--debug` to enable the poll/heartbeat/retry chatter.
8
8
  */
9
+ import { scrubDiagnosticValue } from '@lobu/core';
9
10
  let debugEnabled = false;
11
+ function write(level, parts) {
12
+ let line;
13
+ try {
14
+ const record = scrubDiagnosticValue({
15
+ timestamp: new Date().toISOString(), level, service: 'lobu-worker',
16
+ release: process.env.APP_GIT_SHA,
17
+ message: parts.filter((part) => typeof part === 'string').join(' '),
18
+ data: parts.filter((part) => typeof part !== 'string'),
19
+ });
20
+ line = JSON.stringify(record, (_key, value) => typeof value === 'bigint' ? String(value) : value);
21
+ }
22
+ catch {
23
+ // A diagnostic must not prevent a run from reporting its terminal state.
24
+ line = JSON.stringify({ level, service: 'lobu-worker', message: 'Log record could not be serialized safely' });
25
+ }
26
+ // stderr is intentional: stdout belongs to the CLI's machine protocol.
27
+ console.error(line);
28
+ }
10
29
  export function setDebug(enabled) {
11
30
  debugEnabled = enabled;
12
31
  }
13
32
  export const log = {
14
33
  /** Always-on: one line per run, startup/shutdown, and hard failures. */
15
34
  info: (...parts) => {
16
- console.error(...parts);
35
+ write('info', parts);
17
36
  },
37
+ warn: (...parts) => write('warn', parts),
38
+ error: (...parts) => write('error', parts),
18
39
  /** Debug-only: poll chatter, heartbeats, retry and backoff detail. */
19
40
  debug: (...parts) => {
20
41
  if (debugEnabled)
21
- console.error(...parts);
42
+ write('debug', parts);
22
43
  },
23
44
  };
24
45
  //# sourceMappingURL=log.js.map
@@ -1,10 +1,11 @@
1
1
  import { type AgentKind } from '@lobu/core/contracts/worker/device-automation';
2
2
  import type { PollResponse } from '@lobu/core/contracts/worker/protocol';
3
- import { MutableWorkerAdvertisementProvider } from './client.js';
3
+ import { MutableWorkerAdvertisementProvider, WorkerClient } from './client.js';
4
4
  import { WorkerPollLoop } from './poll-loop.js';
5
5
  import { NativeBridgeClient } from './native-bridge/client.js';
6
6
  import { NATIVE_BRIDGE_PROTOCOL } from './native-bridge/protocol.js';
7
7
  export declare const MAC_DEVICE_PLATFORM = "macos";
8
+ export type ValidatedMacDeviceDaemonOptions = Required<Pick<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>> & Omit<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>;
8
9
  export declare const INTERNAL_ACP_ADAPTER_ARG = "--internal-acp-adapter";
9
10
  export interface MacDeviceDaemonOptions {
10
11
  apiUrl?: string;
@@ -25,6 +26,12 @@ export interface MacDeviceDaemonMetadata {
25
26
  platform: typeof MAC_DEVICE_PLATFORM;
26
27
  artifact: 'standalone-bun-macho-arm64';
27
28
  }
29
+ /**
30
+ * EX_NOPERM: the server rejected the device credential (401/403). The app
31
+ * must resolve authorization instead of restarting with the same key.
32
+ */
33
+ export declare const MAC_DAEMON_CREDENTIAL_REJECTED_EXIT = 77;
34
+ export declare function macDeviceDaemonExitCode(error: unknown): number;
28
35
  export declare function macDeviceDaemonMetadata(version: string): MacDeviceDaemonMetadata;
29
36
  /**
30
37
  * Argv for re-entering this daemon's own entrypoint. A compiled artifact is its
@@ -34,9 +41,9 @@ export declare function macDeviceDaemonMetadata(version: string): MacDeviceDaemo
34
41
  export declare function packagedDaemonArgs(...args: string[]): string[];
35
42
  export declare function selectMacDeviceDaemonAgentKind(runnableAgentKinds: readonly AgentKind[], explicitAgentKind?: AgentKind): AgentKind | undefined;
36
43
  export declare function createMacDeviceDaemonShutdown(controller: AbortController, loop: WorkerPollLoop, bridge?: NativeBridgeClient, shutdownTimeoutMs?: number): () => Promise<void>;
37
- export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonOptions): Required<Pick<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>> & Omit<MacDeviceDaemonOptions, 'apiUrl' | 'workerId' | 'workerApiToken'>;
44
+ export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonOptions, hostThreads?: number): ValidatedMacDeviceDaemonOptions;
38
45
  /**
39
- * Whether the native bridge implements this run's connector.
46
+ * Whether the app advertised a local implementation of this run's connector.
40
47
  *
41
48
  * The daemon answers from the inventory the Mac app itself declared over the
42
49
  * bridge — the same manifests it advertises to the gateway — so what it will
@@ -46,14 +53,24 @@ export declare function validateMacDeviceDaemonOptions(options: MacDeviceDaemonO
46
53
  * the contract's identity; a contract carrying its implementation cannot be
47
54
  * shared with a second endpoint.
48
55
  *
49
- * A payload carrying `compiled_code` is not bridge work by construction: the
56
+ * A payload carrying `compiled_code` is not local connector work: the
50
57
  * gateway ships code only for connectors the device does NOT implement.
51
58
  */
52
59
  export declare function bridgeImplementsRun(job: PollResponse, advertisementProvider: MutableWorkerAdvertisementProvider | undefined): boolean;
53
- export declare function createMacDeviceDaemon(options: MacDeviceDaemonOptions, dependencies?: {
60
+ /**
61
+ * Run a connector claim the app advertised. A daemon built-in (os.shell) runs
62
+ * here, with the built-in owning timeout, cancellation and process reaping.
63
+ * Everything else is native app work over the bridge.
64
+ */
65
+ export declare function executeAdvertisedConnectorRun(client: WorkerClient, job: PollResponse, dependencies: {
66
+ advertisementProvider: MutableWorkerAdvertisementProvider | undefined;
67
+ bridge: NativeBridgeClient | undefined;
68
+ shutdownSignal?: AbortSignal;
69
+ }): Promise<unknown>;
70
+ export declare function createMacDeviceDaemon(options: ValidatedMacDeviceDaemonOptions, dependencies?: {
54
71
  advertisementProvider?: MutableWorkerAdvertisementProvider;
55
72
  bridge?: NativeBridgeClient;
56
73
  shutdownController?: AbortController;
57
74
  }): WorkerPollLoop;
58
- export declare function runMacDeviceDaemon(options: MacDeviceDaemonOptions): Promise<void>;
75
+ export declare function runMacDeviceDaemon(options: ValidatedMacDeviceDaemonOptions): Promise<void>;
59
76
  //# sourceMappingURL=mac-device-daemon.d.ts.map
@@ -1,26 +1,36 @@
1
1
  import { hostname } from 'node:os';
2
2
  import { AGENT_KINDS, } from '@lobu/core/contracts/worker/device-automation';
3
3
  import { executeAutomationRun } from './automation.js';
4
- import { executeDeviceChatRun } from './device-chat.js';
4
+ import { executeDaemonBuiltinActionRun, hasDaemonBuiltin } from './builtins/index.js';
5
+ import { defaultDeviceMaxConcurrentJobs } from './device-concurrency.js';
5
6
  import { locateBinary, resolveRunnableAgentKinds, supportsOpenCodeAcp, } from './agent-binaries.js';
6
- import { MutableWorkerAdvertisementProvider, WorkerClient, } from './client.js';
7
+ import { MutableWorkerAdvertisementProvider, WorkerClient, WorkerHttpError, } from './client.js';
7
8
  import { installWorkerPollLoopSignals, WorkerPollLoop } from './poll-loop.js';
8
9
  import { setDebug } from './log.js';
9
10
  import { NativeBridgeClient } from './native-bridge/client.js';
10
11
  import { executeNativeBridgeRun } from './native-bridge/executor.js';
11
12
  import { NATIVE_BRIDGE_PROTOCOL } from './native-bridge/protocol.js';
12
13
  import { reportTerminalFailure } from './terminal-failure.js';
14
+ import { assertValidWorkerId } from './worker-id.js';
13
15
  export const MAC_DEVICE_PLATFORM = 'macos';
14
- const WORKER_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
15
16
  const WORKER_PAT_PATTERN = /^owl_pat_[A-Za-z0-9_-]{32}$/;
16
17
  const DEFAULT_POLL_INTERVAL_MS = 10000;
17
18
  // Source reads default to a ten-second end-to-end deadline. Keep the signed
18
19
  // Mac daemon's claim latency well below that even when the server returns its
19
20
  // normal ten-second idle hint.
20
21
  const SOURCE_READ_IDLE_DELAY_CEILING_MS = 1000;
21
- const DEFAULT_MAX_CONCURRENT_JOBS = 1;
22
22
  const NATIVE_BRIDGE_SHUTDOWN_TIMEOUT_MS = 5000;
23
23
  export const INTERNAL_ACP_ADAPTER_ARG = '--internal-acp-adapter';
24
+ /**
25
+ * EX_NOPERM: the server rejected the device credential (401/403). The app
26
+ * must resolve authorization instead of restarting with the same key.
27
+ */
28
+ export const MAC_DAEMON_CREDENTIAL_REJECTED_EXIT = 77;
29
+ export function macDeviceDaemonExitCode(error) {
30
+ return error instanceof WorkerHttpError && (error.status === 401 || error.status === 403)
31
+ ? MAC_DAEMON_CREDENTIAL_REJECTED_EXIT
32
+ : 1;
33
+ }
24
34
  export function macDeviceDaemonMetadata(version) {
25
35
  return {
26
36
  name: 'lobu-device-daemon',
@@ -107,11 +117,9 @@ function withTimeout(promise, timeoutMs, label) {
107
117
  });
108
118
  });
109
119
  }
110
- export function validateMacDeviceDaemonOptions(options) {
120
+ export function validateMacDeviceDaemonOptions(options, hostThreads) {
111
121
  const workerId = options.workerId?.trim() || defaultWorkerId();
112
- if (!WORKER_ID_PATTERN.test(workerId)) {
113
- throw new Error(`invalid --worker-id '${workerId}': expected 1-128 characters of letters, digits, dot, underscore, colon or hyphen`);
114
- }
122
+ assertValidWorkerId(workerId);
115
123
  const pollIntervalMs = validateNumber(options.pollIntervalMs, '--poll-interval-ms');
116
124
  const maxConcurrentJobs = validateNumber(options.maxConcurrentJobs, '--max-concurrent-jobs');
117
125
  const defaultAgentKind = validateAgentKind(options.defaultAgentKind);
@@ -151,7 +159,7 @@ export function validateMacDeviceDaemonOptions(options) {
151
159
  workerId,
152
160
  workerApiToken,
153
161
  pollIntervalMs: pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS,
154
- maxConcurrentJobs: maxConcurrentJobs ?? DEFAULT_MAX_CONCURRENT_JOBS,
162
+ maxConcurrentJobs: maxConcurrentJobs ?? defaultDeviceMaxConcurrentJobs(hostThreads),
155
163
  ...(defaultAgentKind ? { defaultAgentKind } : {}),
156
164
  };
157
165
  }
@@ -164,7 +172,7 @@ async function rejectUnadvertisedConnector(client, job) {
164
172
  await reportTerminalFailure(client, job, message, 'error_message');
165
173
  }
166
174
  /**
167
- * Whether the native bridge implements this run's connector.
175
+ * Whether the app advertised a local implementation of this run's connector.
168
176
  *
169
177
  * The daemon answers from the inventory the Mac app itself declared over the
170
178
  * bridge — the same manifests it advertises to the gateway — so what it will
@@ -174,7 +182,7 @@ async function rejectUnadvertisedConnector(client, job) {
174
182
  * the contract's identity; a contract carrying its implementation cannot be
175
183
  * shared with a second endpoint.
176
184
  *
177
- * A payload carrying `compiled_code` is not bridge work by construction: the
185
+ * A payload carrying `compiled_code` is not local connector work: the
178
186
  * gateway ships code only for connectors the device does NOT implement.
179
187
  */
180
188
  export function bridgeImplementsRun(job, advertisementProvider) {
@@ -185,8 +193,31 @@ export function bridgeImplementsRun(job, advertisementProvider) {
185
193
  manifest !== null &&
186
194
  manifest.key === job.connector_key);
187
195
  }
196
+ /**
197
+ * Run a connector claim the app advertised. A daemon built-in (os.shell) runs
198
+ * here, with the built-in owning timeout, cancellation and process reaping.
199
+ * Everything else is native app work over the bridge.
200
+ */
201
+ export async function executeAdvertisedConnectorRun(client, job, dependencies) {
202
+ if (!bridgeImplementsRun(job, dependencies.advertisementProvider)) {
203
+ return rejectUnadvertisedConnector(client, job);
204
+ }
205
+ if (job.run_type === 'action' &&
206
+ job.connector_key &&
207
+ job.action_key &&
208
+ hasDaemonBuiltin(job.connector_key, job.action_key)) {
209
+ return executeDaemonBuiltinActionRun(client, job, {
210
+ heartbeatIntervalMs: 30000,
211
+ ...(dependencies.shutdownSignal ? { shutdownSignal: dependencies.shutdownSignal } : {}),
212
+ platform: 'macos',
213
+ });
214
+ }
215
+ if (!dependencies.bridge)
216
+ return rejectUnsupportedRun(client, job);
217
+ return executeNativeBridgeRun(client, dependencies.bridge, job);
218
+ }
188
219
  export function createMacDeviceDaemon(options, dependencies = {}) {
189
- const validated = validateMacDeviceDaemonOptions(options);
220
+ const validated = options;
190
221
  if (validated.noPoll)
191
222
  throw new Error('cannot create a polling daemon with --no-poll');
192
223
  const discoveredAgentKinds = resolveRunnableAgentKinds();
@@ -271,21 +302,24 @@ export function createMacDeviceDaemon(options, dependencies = {}) {
271
302
  pollIntervalMs: validated.pollIntervalMs,
272
303
  maxIdleDelayMs: SOURCE_READ_IDLE_DELAY_CEILING_MS,
273
304
  maxConcurrentJobs: validated.maxConcurrentJobs,
305
+ ...(nativeBridge
306
+ ? {
307
+ onActiveJobsChange: (activeJobs) => {
308
+ nativeBridge.reportActivity(activeJobs).catch(() => { });
309
+ },
310
+ }
311
+ : {}),
312
+ failClosedOnPollAuthError: true,
274
313
  execute: async (job) => {
275
314
  if (job.run_type === 'automation') {
276
315
  return executeAutomationRun(client, job, automationConfig);
277
316
  }
278
- if (job.run_type === 'chat_message') {
279
- return executeDeviceChatRun(client, job, automationConfig);
280
- }
281
317
  if (job.run_type === 'sync' || job.run_type === 'action' || job.run_type === 'auth') {
282
- if (!bridgeImplementsRun(job, dependencies.advertisementProvider)) {
283
- return rejectUnadvertisedConnector(client, job);
284
- }
285
- if (!nativeBridge) {
286
- return rejectUnsupportedRun(client, job);
287
- }
288
- return executeNativeBridgeRun(client, nativeBridge, job);
318
+ return executeAdvertisedConnectorRun(client, job, {
319
+ advertisementProvider: dependencies.advertisementProvider,
320
+ bridge: nativeBridge,
321
+ shutdownSignal: shutdownController.signal,
322
+ });
289
323
  }
290
324
  return rejectUnsupportedRun(client, job);
291
325
  },
@@ -297,7 +331,7 @@ export function createMacDeviceDaemon(options, dependencies = {}) {
297
331
  }
298
332
  export async function runMacDeviceDaemon(options) {
299
333
  setDebug(options.debug === true);
300
- const validated = validateMacDeviceDaemonOptions(options);
334
+ const validated = options;
301
335
  if (validated.noPoll)
302
336
  return;
303
337
  if (validated.supervisedStdio) {
@@ -37,6 +37,12 @@ export declare class NativeBridgeClient {
37
37
  cancel(requestId: string, runId: number): Promise<void>;
38
38
  cancelAndAbandon(requestId: string, runId: number, error: Error): Promise<void>;
39
39
  cancelActiveRuns(): Promise<void>;
40
+ /**
41
+ * Tell the app how many runs this daemon is executing. The app holds staged
42
+ * updates while any are live: work the daemon runs itself (shell commands,
43
+ * Automations, chat) never passes through the app's own run table.
44
+ */
45
+ reportActivity(activeRuns: number): Promise<void>;
40
46
  shutdown(): Promise<void>;
41
47
  close(error?: NativeBridgeProtocolError): void;
42
48
  onTransportFailure(handler: (error: Error) => void): () => void;
@@ -144,6 +144,21 @@ export class NativeBridgeClient {
144
144
  const cancellations = [...this.pending.values()].map((pending) => this.cancel(pending.requestId, pending.runId));
145
145
  await Promise.allSettled(cancellations);
146
146
  }
147
+ /**
148
+ * Tell the app how many runs this daemon is executing. The app holds staged
149
+ * updates while any are live: work the daemon runs itself (shell commands,
150
+ * Automations, chat) never passes through the app's own run table.
151
+ */
152
+ async reportActivity(activeRuns) {
153
+ if (!this.handshakeComplete || this.failure)
154
+ return;
155
+ await this.send({
156
+ version: NATIVE_BRIDGE_PROTOCOL_VERSION,
157
+ kind: 'activity',
158
+ request_id: randomUUID(),
159
+ payload: { active_runs: activeRuns },
160
+ });
161
+ }
147
162
  async shutdown() {
148
163
  if (!this.handshakeComplete || this.failure)
149
164
  return;