@lobu/runtime-device 21.2.1 → 22.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 (196) 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/commands/_lib/apply/apply-cmd.js +5 -6
  6. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +1 -0
  7. package/vendor/cli/dist/commands/_lib/apply/client.js +26 -7
  8. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +9 -1
  9. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +1 -0
  10. package/vendor/cli/dist/commands/_lib/apply/diff.js +46 -4
  11. package/vendor/cli/dist/commands/_lib/apply/map-config.js +18 -38
  12. package/vendor/cli/dist/commands/_lib/init-from-org/bootstrap.js +5 -17
  13. package/vendor/cli/dist/commands/init.d.ts +0 -2
  14. package/vendor/cli/dist/commands/init.js +0 -27
  15. package/vendor/cli/dist/commands/login.d.ts +17 -0
  16. package/vendor/cli/dist/commands/login.js +43 -17
  17. package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +0 -8
  18. package/vendor/cli/dist/commands/memory/_lib/errors.js +0 -12
  19. package/vendor/cli/dist/commands/memory/_lib/mcp.js +6 -6
  20. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +4 -10
  21. package/vendor/cli/dist/config/define.d.ts +21 -15
  22. package/vendor/cli/dist/config/define.js +2 -2
  23. package/vendor/cli/dist/connectors/README.md +7 -5
  24. package/vendor/cli/dist/connectors/_google/actions.ts +270 -0
  25. package/vendor/cli/dist/connectors/_google/discovery/calendar_v3.json +1 -0
  26. package/vendor/cli/dist/connectors/_google/discovery/chat_v1.json +1 -0
  27. package/vendor/cli/dist/connectors/_google/discovery/docs_v1.json +1 -0
  28. package/vendor/cli/dist/connectors/_google/discovery/drive_v3.json +1 -0
  29. package/vendor/cli/dist/connectors/_google/discovery/gmail_v1.json +1 -0
  30. package/vendor/cli/dist/connectors/_google/discovery/people_v1.json +1 -0
  31. package/vendor/cli/dist/connectors/_google/discovery/sheets_v4.json +1 -0
  32. package/vendor/cli/dist/connectors/_google/discovery/tasks_v1.json +1 -0
  33. package/vendor/cli/dist/connectors/_google/discovery/youtube_v3.json +1 -0
  34. package/vendor/cli/dist/connectors/_google/discovery.ts +442 -0
  35. package/vendor/cli/dist/connectors/_google/errors.ts +91 -0
  36. package/vendor/cli/dist/connectors/_google/list-feed.ts +223 -0
  37. package/vendor/cli/dist/connectors/_google/policies.ts +127 -0
  38. package/vendor/cli/dist/connectors/agentid.ts +43 -0
  39. package/vendor/cli/dist/connectors/chat-user-identity.ts +2 -1
  40. package/vendor/cli/dist/connectors/github-automation-events.ts +9 -0
  41. package/vendor/cli/dist/connectors/github-identity.ts +28 -3
  42. package/vendor/cli/dist/connectors/github.ts +101 -59
  43. package/vendor/cli/dist/connectors/google_calendar.ts +207 -719
  44. package/vendor/cli/dist/connectors/google_drive.ts +16 -2
  45. package/vendor/cli/dist/connectors/google_gmail.ts +51 -33
  46. package/vendor/cli/dist/connectors/herdr.ts +406 -0
  47. package/vendor/cli/dist/connectors/jira.ts +6 -6
  48. package/vendor/cli/dist/connectors/linear.ts +7 -4
  49. package/vendor/cli/dist/connectors/postgres.ts +27 -2
  50. package/vendor/cli/dist/connectors/tiktok-inbox-page.js +230 -0
  51. package/vendor/cli/dist/connectors/tiktok-web-page.js +211 -0
  52. package/vendor/cli/dist/connectors/tiktok_web.ts +286 -0
  53. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +228 -10
  54. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +47 -14
  55. package/vendor/cli/dist/connectors/whatsapp-web-identity.ts +121 -0
  56. package/vendor/cli/dist/connectors/whatsapp_web.ts +170 -29
  57. package/vendor/cli/dist/connectors/x.ts +276 -136
  58. package/vendor/cli/dist/index.js +1 -37
  59. package/vendor/cli/dist/internal/context.d.ts +10 -0
  60. package/vendor/cli/dist/internal/context.js +26 -16
  61. package/vendor/cli/dist/internal/node-version.d.ts +1 -1
  62. package/vendor/cli/dist/internal/node-version.js +1 -1
  63. package/vendor/cli/dist/internal/oauth.d.ts +3 -1
  64. package/vendor/cli/dist/internal/oauth.js +4 -3
  65. package/vendor/cli/dist/internal/runtime-components.d.ts +9 -0
  66. package/vendor/cli/dist/internal/runtime-components.js +67 -2
  67. package/vendor/cli/dist/mac-auth.js +17 -1
  68. package/vendor/cli/dist/providers.json +1 -1
  69. package/vendor/cli/dist/runtime-components.json +4 -4
  70. package/vendor/cli/dist/templates/AGENTS.md.tmpl +11 -4
  71. package/vendor/cli/dist/templates/README.md.tmpl +1 -1
  72. package/vendor/cli/dist/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  73. package/vendor/cli/dist/vendor/ora/index.d.ts +332 -0
  74. package/vendor/cli/dist/vendor/ora/index.js +424 -0
  75. package/vendor/cli/dist/vendor/ora/license +9 -0
  76. package/vendor/cli/dist/vendor/ora/package.json +64 -0
  77. package/vendor/cli/dist/vendor/ora/readme.md +329 -0
  78. package/vendor/cli/package.json +2 -2
  79. package/vendor/connector-sdk/dist/browser-requirement.d.ts +36 -0
  80. package/vendor/connector-sdk/dist/browser-requirement.js +60 -0
  81. package/vendor/connector-sdk/dist/connector-runtime.d.ts +3 -1
  82. package/vendor/connector-sdk/dist/connector-runtime.js +10 -0
  83. package/vendor/connector-sdk/dist/connector-types.d.ts +159 -45
  84. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -2
  85. package/vendor/connector-sdk/dist/define-connector.js +3 -0
  86. package/vendor/connector-sdk/dist/index.d.ts +5 -2
  87. package/vendor/connector-sdk/dist/index.js +1 -0
  88. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +16 -21
  89. package/vendor/connector-sdk/dist/reaction-client-types.typecheck.d.ts +5 -0
  90. package/vendor/connector-sdk/package.json +5 -1
  91. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +31 -27
  92. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +131 -185
  93. package/vendor/connector-worker/dist/agent-turn/memory.d.ts +3 -2
  94. package/vendor/connector-worker/dist/agent-turn/memory.js +3 -20
  95. package/vendor/connector-worker/dist/agent-turn/types.d.ts +3 -15
  96. package/vendor/connector-worker/dist/agent-turn/workspace.d.ts +2 -2
  97. package/vendor/connector-worker/dist/agent-turn/workspace.js +2 -4
  98. package/vendor/connector-worker/dist/daemon/action-monitor.d.ts +12 -0
  99. package/vendor/connector-worker/dist/daemon/action-monitor.js +25 -0
  100. package/vendor/connector-worker/dist/daemon/agent-turn.js +0 -9
  101. package/vendor/connector-worker/dist/daemon/builtins/index.d.ts +12 -0
  102. package/vendor/connector-worker/dist/daemon/builtins/index.js +61 -1
  103. package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +2 -1
  104. package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +40 -27
  105. package/vendor/connector-worker/dist/daemon/client.d.ts +5 -1
  106. package/vendor/connector-worker/dist/daemon/client.js +3 -0
  107. package/vendor/connector-worker/dist/daemon/device-concurrency.d.ts +8 -0
  108. package/vendor/connector-worker/dist/daemon/device-concurrency.js +13 -0
  109. package/vendor/connector-worker/dist/daemon/executor.d.ts +1 -1
  110. package/vendor/connector-worker/dist/daemon/executor.js +48 -117
  111. package/vendor/connector-worker/dist/daemon/log.d.ts +2 -0
  112. package/vendor/connector-worker/dist/daemon/log.js +23 -2
  113. package/vendor/connector-worker/dist/daemon/mac-device-daemon.d.ts +20 -4
  114. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +53 -13
  115. package/vendor/connector-worker/dist/daemon/native-bridge/client.d.ts +6 -0
  116. package/vendor/connector-worker/dist/daemon/native-bridge/client.js +15 -0
  117. package/vendor/connector-worker/dist/daemon/native-bridge/executor.js +2 -0
  118. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.d.ts +1 -1
  119. package/vendor/connector-worker/dist/daemon/native-bridge/protocol.js +1 -0
  120. package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +3 -0
  121. package/vendor/connector-worker/dist/daemon/poll-loop.js +5 -1
  122. package/vendor/connector-worker/dist/daemon/start.d.ts +1 -0
  123. package/vendor/connector-worker/dist/daemon/start.js +12 -5
  124. package/vendor/connector-worker/dist/executor/interface.d.ts +34 -2
  125. package/vendor/connector-worker/dist/executor/isolate.js +66 -15
  126. package/vendor/connector-worker/dist/executor/redact.d.ts +1 -0
  127. package/vendor/connector-worker/dist/executor/redact.js +97 -26
  128. package/vendor/connector-worker/dist/executor/runtime.d.ts +7 -0
  129. package/vendor/connector-worker/dist/executor/runtime.js +26 -0
  130. package/vendor/connector-worker/dist/isolate/bridge.js +3 -1
  131. package/vendor/connector-worker/dist/mac-device-daemon.js +10 -3
  132. package/vendor/connector-worker/package.json +2 -2
  133. package/vendor/core/dist/agent-policy.js +1 -1
  134. package/vendor/core/dist/agent-store.d.ts +2 -0
  135. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  136. package/vendor/core/dist/agent-tooling.js +1 -1
  137. package/vendor/core/dist/capabilities.js +2 -0
  138. package/vendor/core/dist/contracts/agent-settings.d.ts +0 -11
  139. package/vendor/core/dist/contracts/agent-settings.js +1 -7
  140. package/vendor/core/dist/contracts/tools/collection-presentation.d.ts +93 -0
  141. package/vendor/core/dist/contracts/tools/collection-presentation.js +88 -0
  142. package/vendor/core/dist/contracts/tools/collection-selection.d.ts +47 -0
  143. package/vendor/core/dist/contracts/tools/collection-selection.js +74 -0
  144. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +10 -4
  145. package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +1 -1
  146. package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +5 -1
  147. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +19 -4
  148. package/vendor/core/dist/contracts/tools/manage-automations.js +25 -8
  149. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +1 -0
  150. package/vendor/core/dist/contracts/tools/manage-connections.js +3 -0
  151. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +11 -0
  152. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +42 -3
  153. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +181 -152
  154. package/vendor/core/dist/contracts/tools/manage-entity.js +118 -162
  155. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +41 -3
  156. package/vendor/core/dist/contracts/tools/manage-operations.js +40 -2
  157. package/vendor/core/dist/contracts/tools/manage-views.d.ts +182 -7
  158. package/vendor/core/dist/contracts/tools/manage-views.js +49 -13
  159. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +11 -2
  160. package/vendor/core/dist/contracts/tools/read-knowledge.js +23 -3
  161. package/vendor/core/dist/contracts/tools/save-memory.d.ts +3 -6
  162. package/vendor/core/dist/contracts/tools/save-memory.js +2 -6
  163. package/vendor/core/dist/contracts/tools/view-attach.d.ts +2 -1
  164. package/vendor/core/dist/contracts/tools/view-attach.js +7 -2
  165. package/vendor/core/dist/contracts/worker/protocol.d.ts +122 -28
  166. package/vendor/core/dist/contracts/worker/protocol.js +81 -17
  167. package/vendor/core/dist/index.d.ts +3 -4
  168. package/vendor/core/dist/index.js +3 -6
  169. package/vendor/core/dist/json-template.d.ts +6 -10
  170. package/vendor/core/dist/json-template.js +5 -9
  171. package/vendor/core/dist/logger.js +11 -5
  172. package/vendor/core/dist/shell-safety.d.ts +9 -0
  173. package/vendor/core/dist/shell-safety.js +154 -0
  174. package/vendor/core/dist/suggestions.d.ts +1 -1
  175. package/vendor/core/dist/suggestions.js +1 -1
  176. package/vendor/core/dist/tool-trace-summary.d.ts +1 -1
  177. package/vendor/core/dist/tool-trace-summary.js +1 -1
  178. package/vendor/core/dist/types.d.ts +1 -3
  179. package/vendor/core/dist/utils/diagnostic-scrubber.d.ts +7 -0
  180. package/vendor/core/dist/utils/{sentry-scrubber.js → diagnostic-scrubber.js} +25 -53
  181. package/vendor/core/dist/worker/auth.d.ts +44 -6
  182. package/vendor/core/dist/worker/auth.js +44 -11
  183. package/vendor/core/package.json +15 -6
  184. package/vendor/ora/.bun-tag-fde20e9a6df212fa +0 -0
  185. package/vendor/ora/index.d.ts +332 -0
  186. package/vendor/ora/index.js +424 -0
  187. package/vendor/ora/license +9 -0
  188. package/vendor/ora/package.json +53 -0
  189. package/vendor/ora/readme.md +329 -0
  190. package/vendor/cli/dist/commands/telemetry.d.ts +0 -10
  191. package/vendor/cli/dist/commands/telemetry.js +0 -66
  192. package/vendor/core/dist/sentry.d.ts +0 -26
  193. package/vendor/core/dist/sentry.js +0 -133
  194. package/vendor/core/dist/tool-policy.d.ts +0 -74
  195. package/vendor/core/dist/tool-policy.js +0 -305
  196. package/vendor/core/dist/utils/sentry-scrubber.d.ts +0 -29
@@ -16,7 +16,7 @@
16
16
  * 2. The SETTLE. `agentEnd` starts the `save_memory` write and returns
17
17
  * without waiting, which is correct on a runtime that outlives the turn and
18
18
  * silently lossy on one that does not: this isolate is disposed the moment
19
- * `runAgentTurn` resolves. `runTurnMemory` therefore awaits the plugin's
19
+ * `runAgentTurn` resolves. `capture` therefore awaits the plugin's
20
20
  * `settle()` before returning, so the capture actually reaches the gateway.
21
21
  */
22
22
  import { PluginHost } from '@lobu/plugin-host';
@@ -30,22 +30,7 @@ function createTurnMemory(context) {
30
30
  // The plugin addresses its server as `lobu`; the turn says which server that
31
31
  // actually is. Routing on the turn's id rather than the plugin's literal is
32
32
  // what keeps the guest free of a hardcoded server name.
33
- const invoke = async (_gateway, _mcpId, toolName, args, options) => {
34
- // The plugin's contract is a `TextResult`; a failed call is text the hook
35
- // inspects (it skips a recall whose text starts with "error:"), never a
36
- // throw. Matching that here keeps the hook's own branches live.
37
- try {
38
- const text = await context.callTool(context.mcpId, toolName, args, options);
39
- return { content: [{ type: 'text', text }] };
40
- }
41
- catch (error) {
42
- return {
43
- content: [
44
- { type: 'text', text: `Error: ${error instanceof Error ? error.message : String(error)}` },
45
- ],
46
- };
47
- }
48
- };
33
+ const invoke = (_gateway, _mcpId, toolName, args, options) => context.callTool(context.mcpId, toolName, args, options);
49
34
  const plugin = createMemoryPlugin({
50
35
  // The plugin passes these straight back to the invoker, which ignores
51
36
  // them: this lane addresses the MCP route itself. They are filled in
@@ -55,9 +40,7 @@ function createTurnMemory(context) {
55
40
  channelId: '',
56
41
  conversationId: context.conversationId,
57
42
  }, invoke);
58
- // `PluginRuntimeContext` carries more than the memory hooks read (they use
59
- // `logger` and `agentId`). The rest is filled
60
- // with what this lane actually knows, and nothing is invented: a field this
43
+ // Fill `PluginRuntimeContext` with what this lane actually knows: a field this
61
44
  // lane has no value for stays empty rather than carrying a plausible lie.
62
45
  const runtime = {
63
46
  logger: context.logger,
@@ -120,28 +120,16 @@ export type AgentTurnGatewayTool = 'list_conversations' | 'read_conversation' |
120
120
  * plugin's on both lanes.
121
121
  */
122
122
  export type AgentTurnMediaTool = 'upload_file' | 'generate_image' | 'generate_audio';
123
- /**
124
- * The agent's bash prefix policy, in the shape `@lobu/core/tool-policy`
125
- * enforces. Restated rather than imported on purpose: this file is the
126
- * host-side contract, and a type import here would be the first step toward a
127
- * value import from the same module, which the guest bundle cannot take.
128
- */
129
- export interface AgentTurnBashPolicy {
130
- allowAll: boolean;
131
- allowPrefixes: string[];
132
- denyPrefixes: string[];
133
- }
134
123
  /** The tools of a turn and where they are called. */
135
124
  export interface AgentTurnTools {
136
125
  /** Gateway base URL, mount path included; the MCP route hangs off it. */
137
126
  gatewayUrl: string;
138
127
  definitions: AgentTurnTool[];
139
128
  /**
140
- * Workspace tools the agent's policy admits. They run inside the isolate
129
+ * Workspace tools available for this turn. They run inside the isolate
141
130
  * against a filesystem that lives for this turn only.
142
131
  */
143
132
  builtin?: AgentTurnBuiltinTool[];
144
- bashPolicy?: AgentTurnBashPolicy;
145
133
  /**
146
134
  * The conversation is pinned to a remote runtime sandbox: `bash` runs there
147
135
  * through the host, not in the in-memory workspace. Absent → local bash.
@@ -150,12 +138,12 @@ export interface AgentTurnTools {
150
138
  providerId: string;
151
139
  };
152
140
  /**
153
- * Gateway tools the agent's policy admits, by name. Their routing lives in
141
+ * Gateway tools available for this turn, by name. Their routing lives in
154
142
  * the plugin package, so the wire carries only the names.
155
143
  */
156
144
  gateway?: AgentTurnGatewayTool[];
157
145
  /**
158
- * Media tools the agent's policy admits, by name. Same contract as
146
+ * Media tools available for this turn, by name. Same contract as
159
147
  * `gateway`: names only, because the routing lives in the plugin package.
160
148
  * `upload_file` additionally needs `builtin` to include a workspace tool —
161
149
  * with no filesystem there is no file to show — and the guest drops it if
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import type { AgentTool } from '@mariozechner/pi-agent-core';
20
20
  import { InMemoryFs } from 'just-bash/browser';
21
- import type { AgentTurnBashPolicy, AgentTurnBuiltinTool, RuntimeExecRequest, RuntimeExecResult } from './types.js';
21
+ import type { AgentTurnBuiltinTool, RuntimeExecRequest, RuntimeExecResult } from './types.js';
22
22
  /** Where a turn's files live; also the shell's working directory. */
23
23
  export declare const WORKSPACE_ROOT = "/workspace";
24
24
  /**
@@ -100,5 +100,5 @@ export interface RemoteRuntime {
100
100
  * sees. A supplied remote runtime replaces only `bash`; file tools remain on
101
101
  * this in-memory filesystem.
102
102
  */
103
- export declare function createWorkspace(names: readonly AgentTurnBuiltinTool[], bashPolicy?: AgentTurnBashPolicy, remote?: RemoteRuntime): AgentWorkspace;
103
+ export declare function createWorkspace(names: readonly AgentTurnBuiltinTool[], remote?: RemoteRuntime): AgentWorkspace;
104
104
  //# sourceMappingURL=workspace.d.ts.map
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { withLobuFileParameters } from '@lobu/core/agent-tooling';
20
20
  import { createEditTool, createFindTool, createLsTool, createReadTool, createWriteTool, DEFAULT_MAX_BYTES as MAX_BYTES, DEFAULT_MAX_LINES as MAX_LINES, formatSize, truncateHead, truncateLine, truncateTail, } from '@mariozechner/pi-coding-agent';
21
- import { enforceBashCommandPolicy, isDirectPackageInstallCommand } from '@lobu/core/tool-policy';
21
+ import { isDirectPackageInstallCommand } from '@lobu/core/shell-safety';
22
22
  import { Bash, InMemoryFs } from 'just-bash/browser';
23
23
  /** Where a turn's files live; also the shell's working directory. */
24
24
  export const WORKSPACE_ROOT = '/workspace';
@@ -202,7 +202,7 @@ async function runRemoteBash(remote, command, timeout) {
202
202
  * sees. A supplied remote runtime replaces only `bash`; file tools remain on
203
203
  * this in-memory filesystem.
204
204
  */
205
- export function createWorkspace(names, bashPolicy, remote) {
205
+ export function createWorkspace(names, remote) {
206
206
  const fs = new InMemoryFs();
207
207
  const ready = fs.mkdir(WORKSPACE_ROOT, { recursive: true });
208
208
  const shell = new Bash({ fs, cwd: WORKSPACE_ROOT, executionLimits: BASH_LIMITS });
@@ -341,8 +341,6 @@ export function createWorkspace(names, bashPolicy, remote) {
341
341
  execute: async (_id, args) => {
342
342
  const command = requireString(args, 'command');
343
343
  const timeout = optionalNumber(args, 'timeout');
344
- if (bashPolicy)
345
- enforceBashCommandPolicy(command, bashPolicy);
346
344
  if (isDirectPackageInstallCommand(command)) {
347
345
  throw new Error(remote
348
346
  ? 'DIRECT PACKAGE INSTALL BLOCKED. Use the sandbox packages configured by an admin.'
@@ -0,0 +1,12 @@
1
+ import { type ExecutorClient } from './client.js';
2
+ /** Action work stops when its durable lease is revoked. Network failures alone
3
+ * do not prove revocation; the gateway's structured 409 does. */
4
+ export declare function monitorActionRun(client: ExecutorClient, runId: number, cfg: {
5
+ heartbeatIntervalMs: number;
6
+ shutdownSignal?: AbortSignal;
7
+ }): {
8
+ signal: AbortSignal;
9
+ revoked: () => boolean;
10
+ stop: () => void;
11
+ };
12
+ //# sourceMappingURL=action-monitor.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { WorkerHttpError } from './client.js';
2
+ import { log } from './log.js';
3
+ /** Action work stops when its durable lease is revoked. Network failures alone
4
+ * do not prove revocation; the gateway's structured 409 does. */
5
+ export function monitorActionRun(client, runId, cfg) {
6
+ const controller = new AbortController();
7
+ const signal = cfg.shutdownSignal
8
+ ? AbortSignal.any([controller.signal, cfg.shutdownSignal])
9
+ : controller.signal;
10
+ const interval = setInterval(async () => {
11
+ try {
12
+ const response = await client.heartbeat(runId);
13
+ if (response?.continue === false)
14
+ controller.abort();
15
+ }
16
+ catch (error) {
17
+ if (error instanceof WorkerHttpError && error.status === 409)
18
+ controller.abort();
19
+ else
20
+ log.debug('[executor] Action heartbeat failed:', error);
21
+ }
22
+ }, cfg.heartbeatIntervalMs);
23
+ return { signal, revoked: () => controller.signal.aborted, stop: () => clearInterval(interval) };
24
+ }
25
+ //# sourceMappingURL=action-monitor.js.map
@@ -379,15 +379,6 @@ export async function executeAgentTurnRun(client, job, env, cfg) {
379
379
  })),
380
380
  ...(turn.tools.builtin ? { builtin: turn.tools.builtin } : {}),
381
381
  ...(turn.tools.remote_runtime ? { remoteRuntime: { providerId: turn.tools.remote_runtime.provider_id } } : {}),
382
- ...(turn.tools.bash_policy
383
- ? {
384
- bashPolicy: {
385
- allowAll: turn.tools.bash_policy.allow_all,
386
- allowPrefixes: turn.tools.bash_policy.allow_prefixes,
387
- denyPrefixes: turn.tools.bash_policy.deny_prefixes,
388
- },
389
- }
390
- : {}),
391
382
  // Names only; the guest selects them out of the plugin
392
383
  // package, which is where their routing and schemas live.
393
384
  // Without the conversation they address there is nothing to
@@ -1,3 +1,5 @@
1
+ import type { ExecutorClient, PollResponse } from '../client.js';
2
+ import { type ShellPlatform } from './os-shell.js';
1
3
  export type DaemonBuiltinErrorCode = 'invalid_operation_input' | 'operation_backend_unavailable' | 'operation_execution_failed';
2
4
  export type DaemonBuiltinResult = {
3
5
  ok: true;
@@ -22,5 +24,15 @@ export declare function executeDaemonBuiltin(params: {
22
24
  actionKey: string;
23
25
  input: Record<string, unknown>;
24
26
  shutdownSignal?: AbortSignal;
27
+ platform?: ShellPlatform;
25
28
  }): Promise<DaemonBuiltinResult>;
29
+ /** Run one claimed built-in action and report its single terminal result. */
30
+ export declare function executeDaemonBuiltinActionRun(client: ExecutorClient, job: PollResponse, cfg: {
31
+ heartbeatIntervalMs: number;
32
+ shutdownSignal?: AbortSignal;
33
+ platform?: ShellPlatform;
34
+ }): Promise<{
35
+ itemsCollected: number;
36
+ error?: string;
37
+ }>;
26
38
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,6 @@
1
+ import { monitorActionRun } from '../action-monitor.js';
2
+ import { log } from '../log.js';
3
+ import { completeActionOnce } from '../terminal-delivery.js';
1
4
  import { ShellInputError, runShellBuiltin } from './os-shell.js';
2
5
  function describeShellFailure(output) {
3
6
  if (output.timed_out) {
@@ -72,7 +75,7 @@ export async function executeDaemonBuiltin(params) {
72
75
  };
73
76
  }
74
77
  try {
75
- const output = await builtin(params.input, params.shutdownSignal);
78
+ const output = await builtin(params.input, params.shutdownSignal, params.platform ?? 'headless');
76
79
  if (!output.success) {
77
80
  return {
78
81
  ok: false,
@@ -95,4 +98,61 @@ export async function executeDaemonBuiltin(params) {
95
98
  };
96
99
  }
97
100
  }
101
+ /** Run one claimed built-in action and report its single terminal result. */
102
+ export async function executeDaemonBuiltinActionRun(client, job, cfg) {
103
+ const { run_id, connector_key, action_key, action_input } = job;
104
+ if (!run_id || !connector_key || !action_key) {
105
+ throw new Error('Invalid daemon built-in action: missing run_id, connector_key, or action_key');
106
+ }
107
+ if (job.compiled_code) {
108
+ const message = 'operation_backend_unavailable: a daemon built-in payload must not contain compiled_code';
109
+ await completeActionOnce(client, {
110
+ run_id,
111
+ worker_id: client.id,
112
+ status: 'failed',
113
+ error_message: message,
114
+ });
115
+ return { itemsCollected: 0, error: message };
116
+ }
117
+ const monitor = monitorActionRun(client, run_id, cfg);
118
+ try {
119
+ const result = await executeDaemonBuiltin({
120
+ connectorKey: connector_key,
121
+ actionKey: action_key,
122
+ input: (action_input ?? {}),
123
+ shutdownSignal: monitor.signal,
124
+ ...(cfg.platform ? { platform: cfg.platform } : {}),
125
+ });
126
+ if (monitor.revoked())
127
+ return { itemsCollected: 0 };
128
+ if (!result.ok) {
129
+ const message = `${result.code}: ${result.error}`;
130
+ await completeActionOnce(client, {
131
+ run_id,
132
+ worker_id: client.id,
133
+ status: 'failed',
134
+ error_message: message,
135
+ ...(result.output ? { action_output: result.output } : {}),
136
+ });
137
+ return { itemsCollected: 0, error: message };
138
+ }
139
+ await completeActionOnce(client, {
140
+ run_id,
141
+ worker_id: client.id,
142
+ status: 'success',
143
+ action_output: result.output,
144
+ });
145
+ return { itemsCollected: 0 };
146
+ }
147
+ catch (error) {
148
+ // Delivery uncertainty is not an execution failure. The immutable payload
149
+ // was retried above; never send a contradictory terminal result here.
150
+ const message = error instanceof Error ? error.message : String(error);
151
+ log.info(`[executor] Daemon built-in terminal delivery uncertain for ${run_id}:`, message);
152
+ return { itemsCollected: 0, error: message };
153
+ }
154
+ finally {
155
+ monitor.stop();
156
+ }
157
+ }
98
158
  //# sourceMappingURL=index.js.map
@@ -31,5 +31,6 @@ export interface ShellRunOutput {
31
31
  timed_out: boolean;
32
32
  duration_ms: number;
33
33
  }
34
- export declare function runShellBuiltin(input: Record<string, unknown>, shutdownSignal?: AbortSignal): Promise<ShellRunOutput>;
34
+ export type ShellPlatform = 'headless' | 'macos';
35
+ export declare function runShellBuiltin(input: Record<string, unknown>, shutdownSignal?: AbortSignal, platform?: ShellPlatform): Promise<ShellRunOutput>;
35
36
  //# sourceMappingURL=os-shell.d.ts.map
@@ -2,27 +2,26 @@
2
2
  * os.shell as a daemon builtin — the ONLY implementation.
3
3
  *
4
4
  * Every endpoint that offers the shared `os.shell` contract implements it
5
- * locally: this file on a headless server/VM/pod, the Mac app's own bridge on a
6
- * Mac. Neither implementation is named in the contract — it is hashed, and a
7
- * contract that carried its implementation could not be offered by both. There
8
- * is deliberately no gateway-compiled connector either: shell execution needs a
9
- * real process, which the isolate lane does not have, and running it on the
10
- * daemon's own supervisor is what lets a device whose connector compiler is
11
- * broken still be recovered.
5
+ * locally through this daemon builtin, on both headless hosts and Macs. The
6
+ * implementation is not named in the hashed contract, so both endpoints can
7
+ * offer the same contract. There is deliberately no gateway-compiled connector:
8
+ * shell execution needs a real process, which the isolate lane does not have,
9
+ * and running it on the daemon's own supervisor lets a device whose connector
10
+ * compiler is broken still be recovered.
12
11
  *
13
- * Keep the CONTRACT — the argv (`bash --noprofile --norc -c`), the timeout
14
- * bounds, the 1MB output cap and the returned shape — in step with
15
- * the generated headless manifest in `../device-manifests.ts`, which is what the
16
- * gateway and the agent see.
17
- *
18
- * This runs in the daemon's own process, so it REPLACES the environment rather
19
- * than inheriting it: an inherited env would hand the command the daemon's
20
- * credentials.
12
+ * Keep the argv, timeout bounds and returned shape in step with the shared
13
+ * contract in `packages/device-connectors/src/os-shell.ts`. Output is capped
14
+ * at 1MB per stream. A headless host runs `bash --noprofile --norc -c` in a
15
+ * minimal replacement environment so commands do not inherit daemon
16
+ * credentials. A Mac runs the signed-in user's `zsh -l -c` with the user's
17
+ * environment minus the daemon's credentials; the Mac app starts this daemon
18
+ * as its own child.
21
19
  *
22
20
  * LIFETIME: a run owns a process group for the duration of the call and no
23
21
  * longer. Everything still in that group when the command returns is killed,
24
- * which is what keeps a daemon from leaking processes, and it means `&`,
25
- * `nohup` and `setsid` do not buy a caller a surviving daemon. That cleanup is
22
+ * which is what keeps a daemon from leaking processes: `&` and `nohup` alone
23
+ * do not leave that group. A process that explicitly creates a new session
24
+ * leaves the daemon's group ownership and is outside this cleanup. Cleanup is
26
25
  * deliberate; what was a bug (#3629) is doing it QUIETLY -- a run used to
27
26
  * report exit 0 while the poller it had just launched was being killed, so the
28
27
  * loss surfaced as an unrelated failure much later. A run that leaves
@@ -33,6 +32,7 @@
33
32
  import { existsSync } from 'node:fs';
34
33
  import { homedir } from 'node:os';
35
34
  import { isAbsolute } from 'node:path';
35
+ import { searchDirs } from '../agent-binaries.js';
36
36
  import { countOwnedGroupSurvivors, releaseSupervisor, signalOwnedPosixProcessGroup, spawnSupervisedCli, terminateChild, } from '../automation-process.js';
37
37
  /**
38
38
  * A caller-supplied argument the builtin rejects before spawning anything.
@@ -69,17 +69,29 @@ function readTimeout(value) {
69
69
  }
70
70
  return Number(value);
71
71
  }
72
- function shellEnvironment() {
73
- const env = {
74
- PATH: process.env.PATH ?? '/usr/bin:/bin',
75
- HOME: process.env.HOME ?? homedir(),
76
- TMPDIR: process.env.TMPDIR ?? '/tmp',
77
- LANG: 'C',
78
- LC_ALL: 'C',
72
+ function shellInvocation(platform, command) {
73
+ if (platform === 'macos') {
74
+ const env = { ...process.env };
75
+ delete env.WORKER_API_TOKEN;
76
+ delete env.LOBU_API_TOKEN;
77
+ delete env.LOBU_MEMORY_URL;
78
+ // An app-launched process starts with a stripped PATH.
79
+ env.PATH = [...searchDirs(), env.PATH ?? '/usr/bin:/bin'].join(':');
80
+ return { file: '/bin/zsh', args: ['-l', '-c', command], env };
81
+ }
82
+ return {
83
+ file: 'bash',
84
+ args: ['--noprofile', '--norc', '-c', command],
85
+ env: {
86
+ PATH: process.env.PATH ?? '/usr/bin:/bin',
87
+ HOME: process.env.HOME ?? homedir(),
88
+ TMPDIR: process.env.TMPDIR ?? '/tmp',
89
+ LANG: 'C',
90
+ LC_ALL: 'C',
91
+ },
79
92
  };
80
- return env;
81
93
  }
82
- export async function runShellBuiltin(input, shutdownSignal) {
94
+ export async function runShellBuiltin(input, shutdownSignal, platform = 'headless') {
83
95
  const command = typeof input.command === 'string' ? input.command.trim() : '';
84
96
  if (!command)
85
97
  throw new ShellInputError('command is required');
@@ -101,7 +113,8 @@ export async function runShellBuiltin(input, shutdownSignal) {
101
113
  return await new Promise((resolve) => {
102
114
  let supervised;
103
115
  try {
104
- supervised = spawnSupervisedCli('bash', ['--noprofile', '--norc', '-c', command], shellEnvironment(), { stdin: 'pipe', cwd });
116
+ const shell = shellInvocation(platform, command);
117
+ supervised = spawnSupervisedCli(shell.file, shell.args, shell.env, { stdin: 'pipe', cwd });
105
118
  }
106
119
  catch (error) {
107
120
  const code = error.code;
@@ -40,6 +40,8 @@ export interface ExecutorClient {
40
40
  * — multi-replica safe because the wait is Postgres-mediated.
41
41
  */
42
42
  dispatchChromeAction(req: DispatchChromeActionRequest): Promise<Record<string, unknown>>;
43
+ /** Delegate a native device operation on behalf of the running parent action. */
44
+ executeConnectorOperation?(req: ExecuteConnectorOperationRequest, signal?: AbortSignal): Promise<ConnectorOperationResult>;
43
45
  /** Spend only the current run's gateway-held HTTP credentials. */
44
46
  httpFetch(runId: number, request: ConnectorHttpRequest, signal?: AbortSignal): Promise<ConnectorHttpResponse>;
45
47
  /**
@@ -69,7 +71,8 @@ export interface ExecutorClient {
69
71
  * its request-body reads with the same shapes from that file.
70
72
  */
71
73
  export type { CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteDeviceChatRequest, CompleteDeviceChatResponse, CompleteEmbeddingsRequest, CompleteRequest, ContentItem, DispatchChromeActionRequest, DispatchChromeActionResponse, EmbedEvent, EmitAuthArtifactRequest, HeartbeatRequest, HeartbeatResponse, OAuthCredentials, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch, } from "@lobu/core/contracts/worker/protocol";
72
- import type { ConnectorHttpRequest, ConnectorHttpResponse, CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteDeviceChatRequest, CompleteDeviceChatResponse, CompleteEmbeddingsRequest, CompleteRequest, DispatchChromeActionRequest, EmbedEvent, EmitAuthArtifactRequest, HeartbeatRequest, HeartbeatResponse, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch } from "@lobu/core/contracts/worker/protocol";
74
+ import type { ConnectorHttpRequest, ConnectorHttpResponse, CompleteActionRequest, CompleteAgentTurnRequest, CompleteAgentTurnResponse, CompleteAuthRequest, CompleteAutomationRequest, CompleteAutomationResponse, CompleteDeviceChatRequest, CompleteDeviceChatResponse, CompleteEmbeddingsRequest, CompleteRequest, DispatchChromeActionRequest, EmbedEvent, EmitAuthArtifactRequest, ExecuteConnectorOperationRequest, HeartbeatRequest, HeartbeatResponse, PollAuthSignalRequest, PollAuthSignalResponse, PollResponse, StreamBatch } from "@lobu/core/contracts/worker/protocol";
75
+ import type { ConnectorOperationResult } from "@lobu/core/contracts/tools/manage-operations";
73
76
  import type { AgentKind } from "@lobu/core/contracts/worker/device-automation";
74
77
  /** Capability strings the worker advertises, keyed by name (e.g. `browser.debugger`). */
75
78
  export type WorkerCapabilities = Record<string, boolean>;
@@ -229,6 +232,7 @@ export declare class WorkerClient implements ExecutorClient {
229
232
  * times out. Throws on failure/timeout with the gateway's error message.
230
233
  */
231
234
  dispatchChromeAction(req: DispatchChromeActionRequest): Promise<Record<string, unknown>>;
235
+ executeConnectorOperation(req: ExecuteConnectorOperationRequest, signal?: AbortSignal): Promise<ConnectorOperationResult>;
232
236
  httpFetch(runId: number, request: ConnectorHttpRequest, signal?: AbortSignal): Promise<ConnectorHttpResponse>;
233
237
  /**
234
238
  * Health check
@@ -311,6 +311,9 @@ export class WorkerClient {
311
311
  throw new Error(result.error_message ??
312
312
  `Chrome action '${req.action_key}' ${result.status === 'timeout' ? 'timed out' : 'failed'}`);
313
313
  }
314
+ async executeConnectorOperation(req, signal) {
315
+ return this.requestJson('/api/workers/execute-operation', req, signal);
316
+ }
314
317
  async httpFetch(runId, request, signal) {
315
318
  return this.requestJson('/api/workers/http-fetch', { worker_id: this.id, run_id: runId, request }, signal);
316
319
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Default active-run limit for paired device daemons (macOS and headless).
3
+ * Device runs mostly wait on I/O, so half the host's threads leaves room for
4
+ * the user's own work; keep at least two slots so a long command cannot
5
+ * monopolize the daemon, and cap the default to bound local agent load.
6
+ */
7
+ export declare function defaultDeviceMaxConcurrentJobs(hostThreads?: number): number;
8
+ //# sourceMappingURL=device-concurrency.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { availableParallelism } from 'node:os';
2
+ const MIN_DEVICE_MAX_CONCURRENT_JOBS = 2;
3
+ const MAX_DEVICE_MAX_CONCURRENT_JOBS = 8;
4
+ /**
5
+ * Default active-run limit for paired device daemons (macOS and headless).
6
+ * Device runs mostly wait on I/O, so half the host's threads leaves room for
7
+ * the user's own work; keep at least two slots so a long command cannot
8
+ * monopolize the daemon, and cap the default to bound local agent load.
9
+ */
10
+ export function defaultDeviceMaxConcurrentJobs(hostThreads = availableParallelism()) {
11
+ return Math.min(MAX_DEVICE_MAX_CONCURRENT_JOBS, Math.max(MIN_DEVICE_MAX_CONCURRENT_JOBS, Math.floor(hostThreads / 2)));
12
+ }
13
+ //# sourceMappingURL=device-concurrency.js.map
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import type { Env } from '@lobu/connector-sdk';
8
8
  import type { AgentKind } from '@lobu/core/contracts/worker/device-automation';
9
- import type { ExecutorClient, PollResponse } from './client.js';
9
+ import { type ExecutorClient, type PollResponse } from './client.js';
10
10
  import type { SyncExecutor } from '../executor/interface.js';
11
11
  /**
12
12
  * Resolve the executable compiled code for a job.