@lobu/runtime-device 24.4.0 → 24.5.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 (90) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +45 -47
  3. package/dist/verify.mjs +1 -1
  4. package/npm-shrinkwrap.json +42 -58
  5. package/package.json +2 -2
  6. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +8 -2
  7. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +20 -13
  8. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +48 -100
  9. package/vendor/cli/dist/commands/_lib/apply/client.js +76 -27
  10. package/vendor/cli/dist/commands/_lib/apply/deployment.js +1 -1
  11. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +7 -11
  12. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +9 -40
  13. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +4 -4
  14. package/vendor/cli/dist/commands/_lib/apply/diff.js +37 -33
  15. package/vendor/cli/dist/commands/_lib/apply/map-config.d.ts +1 -1
  16. package/vendor/cli/dist/commands/_lib/apply/map-config.js +79 -92
  17. package/vendor/cli/dist/commands/_lib/apply/shared.d.ts +3 -6
  18. package/vendor/cli/dist/commands/_lib/apply/shared.js +8 -19
  19. package/vendor/cli/dist/commands/dev.js +21 -7
  20. package/vendor/cli/dist/commands/doctor.js +1 -8
  21. package/vendor/cli/dist/commands/init.js +4 -5
  22. package/vendor/cli/dist/config/define.d.ts +27 -28
  23. package/vendor/cli/dist/config/define.js +4 -5
  24. package/vendor/cli/dist/connectors/postgres.ts +77 -48
  25. package/vendor/cli/dist/internal/api-client.d.ts +2 -0
  26. package/vendor/cli/dist/internal/api-client.js +6 -1
  27. package/vendor/cli/dist/internal/node-binary.d.ts +22 -0
  28. package/vendor/cli/dist/internal/node-binary.js +73 -0
  29. package/vendor/cli/dist/internal/node-version.d.ts +7 -12
  30. package/vendor/cli/dist/internal/node-version.js +16 -20
  31. package/vendor/cli/dist/runtime-components.json +4 -4
  32. package/vendor/cli/dist/templates/AGENTS.md.tmpl +2 -2
  33. package/vendor/cli/package.json +2 -2
  34. package/vendor/connector-sdk/dist/reaction-client-types.d.ts +8 -2
  35. package/vendor/connector-sdk/dist/reaction-sdk.d.ts +5 -1
  36. package/vendor/connector-sdk/package.json +1 -1
  37. package/vendor/connector-worker/dist/daemon/acp-adapters/claude.js +1 -1
  38. package/vendor/connector-worker/dist/daemon/agent-turn.js +21 -10
  39. package/vendor/connector-worker/dist/daemon/client.d.ts +25 -8
  40. package/vendor/connector-worker/dist/daemon/client.js +25 -3
  41. package/vendor/connector-worker/dist/daemon/mac-device-daemon.js +7 -1
  42. package/vendor/connector-worker/dist/daemon/poll-loop.d.ts +17 -0
  43. package/vendor/connector-worker/dist/daemon/poll-loop.js +75 -6
  44. package/vendor/connector-worker/dist/daemon/resource-admission.d.ts +19 -0
  45. package/vendor/connector-worker/dist/daemon/resource-admission.js +59 -0
  46. package/vendor/connector-worker/dist/daemon/resources.d.ts +20 -0
  47. package/vendor/connector-worker/dist/daemon/resources.js +163 -0
  48. package/vendor/connector-worker/dist/daemon/start.js +29 -4
  49. package/vendor/connector-worker/dist/daemon/worker.d.ts +2 -0
  50. package/vendor/connector-worker/dist/daemon/worker.js +4 -0
  51. package/vendor/connector-worker/dist/executor/select.d.ts +1 -1
  52. package/vendor/connector-worker/dist/executor/select.js +1 -1
  53. package/vendor/connector-worker/dist/isolate/ivm-types.d.ts +1 -2
  54. package/vendor/connector-worker/dist/isolate/ivm-types.js +1 -2
  55. package/vendor/connector-worker/dist/isolate/load.d.ts +10 -12
  56. package/vendor/connector-worker/dist/isolate/load.js +23 -27
  57. package/vendor/connector-worker/dist/self-check/index.d.ts +2 -2
  58. package/vendor/connector-worker/dist/self-check/index.js +2 -2
  59. package/vendor/connector-worker/package.json +3 -4
  60. package/vendor/core/dist/contracts/agent-settings.d.ts +61 -6
  61. package/vendor/core/dist/contracts/agent-settings.js +10 -7
  62. package/vendor/core/dist/contracts/tools/manage-agents.d.ts +473 -98
  63. package/vendor/core/dist/contracts/tools/manage-agents.js +111 -2
  64. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +21 -18
  65. package/vendor/core/dist/contracts/tools/manage-automations.js +15 -15
  66. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +2 -2
  67. package/vendor/core/dist/contracts/tools/manage-inference-providers.d.ts +445 -0
  68. package/vendor/core/dist/contracts/tools/manage-inference-providers.js +133 -0
  69. package/vendor/core/dist/contracts/tools/manage-views.d.ts +4 -4
  70. package/vendor/core/dist/contracts/tools/manage-views.js +5 -3
  71. package/vendor/core/dist/contracts/worker/device-automation.js +4 -2
  72. package/vendor/core/dist/error-report.d.ts +73 -0
  73. package/vendor/core/dist/error-report.js +346 -0
  74. package/vendor/core/dist/index.d.ts +3 -1
  75. package/vendor/core/dist/index.js +4 -1
  76. package/vendor/core/dist/logger.js +7 -4
  77. package/vendor/core/dist/otel-fetch.d.ts +19 -0
  78. package/vendor/core/dist/otel-fetch.js +96 -0
  79. package/vendor/core/dist/otel.d.ts +9 -0
  80. package/vendor/core/dist/otel.js +28 -7
  81. package/vendor/core/dist/reserved.d.ts +1 -1
  82. package/vendor/core/dist/reserved.js +6 -4
  83. package/vendor/core/dist/tool-result.d.ts +8 -0
  84. package/vendor/core/dist/tool-result.js +61 -0
  85. package/vendor/core/dist/utils/diagnostic-scrubber.js +1 -1
  86. package/vendor/core/dist/worker/auth.js +4 -0
  87. package/vendor/core/package.json +6 -1
  88. /package/vendor/cli/dist/vendor/ora/{.bun-tag-fde20e9a6df212fa → .bun-tag-77bb9b258a474a18} +0 -0
  89. /package/vendor/ora/{.bun-tag-fde20e9a6df212fa → .bun-tag-77bb9b258a474a18} +0 -0
  90. /package/vendor/postgres/{.bun-tag-22d644c2873790db → .bun-tag-c81dacd34e959a7a} +0 -0
@@ -9,32 +9,12 @@
9
9
  */
10
10
  import { validateEntityMetrics } from "@lobu/connector-sdk/metrics";
11
11
  import { isChatPlatform, normalizeEntityTypeSlug, } from "@lobu/core";
12
+ import { AgentSettingsPatchSchema } from "@lobu/core/contracts/agent-settings";
12
13
  import { parseCollectionPresentation } from "@lobu/core/contracts/tools/collection-presentation";
13
- import { normalizeWorkspaceEventTrigger, resolvedEventExecution, } from "@lobu/core/contracts/tools/manage-automations";
14
+ import { AutomationExecutionConfigSchema, ManageAutomationsSchema, normalizeWorkspaceEventTrigger, resolvedEventExecution, } from "@lobu/core/contracts/tools/manage-automations";
14
15
  import { InvalidEntityResolutionPolicyError, parseEntityResolutionPolicy, } from "@lobu/core/contracts/tools/manage-entity-schema";
15
- /**
16
- * Marker for each stored field's declarative status. Also exhaustive over the
17
- * same key set, so a new field with no policy entry also fails to compile.
18
- * - "mapped": produced by this converter
19
- * - "unsupported": not declarable in lobu.config.ts (intentional)
20
- * - "post-load": filled later by mergeAgentDirArtifacts
21
- */
22
- const AGENT_SETTINGS_FIELD_POLICY = {
23
- models: "mapped",
24
- networkConfig: "mapped",
25
- nixConfig: "mapped",
26
- soulMd: "post-load",
27
- userMd: "post-load",
28
- identityMd: "post-load",
29
- skillsConfig: "post-load",
30
- guardrails: "mapped",
31
- guardrailsInline: "unsupported",
32
- sandboxId: "unsupported",
33
- verboseLogging: "unsupported",
34
- showToolCalls: "unsupported",
35
- starters: "mapped",
36
- };
37
- void AGENT_SETTINGS_FIELD_POLICY;
16
+ import { InferenceModalitySchema, InferenceProviderSlugSchema, } from "@lobu/core/contracts/tools/manage-inference-providers";
17
+ import { Value } from "@sinclair/typebox/value";
38
18
  import { CronExpressionParser } from "cron-parser";
39
19
  import { isSecretRef, UNRESOLVED_MODEL_SUFFIX } from "../../../config/index.js";
40
20
  import { ValidationError } from "../../memory/_lib/errors.js";
@@ -80,22 +60,10 @@ function envRefName(value) {
80
60
  function providerId(provider) {
81
61
  return (provider.id ?? "").trim();
82
62
  }
83
- /**
84
- * Org-provider slug rules — MUST match the DB CHECK in the inference_providers
85
- * migration exactly (`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`): lowercase
86
- * alphanumeric + hyphen, 1-63 chars, no leading/trailing hyphen. Kept in lockstep
87
- * so `lobu apply` rejects a bad slug up front instead of the server 500ing on the
88
- * CHECK. Single-char slugs are allowed; a trailing hyphen (`myvllm-`) is not.
89
- */
90
- const ORG_PROVIDER_SLUG_PATTERN = /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
63
+ /** Use the same provider-slug bounds as REST and MCP. */
64
+ const ORG_PROVIDER_SLUG_PATTERN = new RegExp(InferenceProviderSlugSchema.pattern);
91
65
  /** Modalities the server accepts for an inference-provider capability block. */
92
- const INFERENCE_MODALITIES = new Set([
93
- "text",
94
- "image",
95
- "stt",
96
- "tts",
97
- "embedding",
98
- ]);
66
+ const INFERENCE_MODALITIES = new Set(InferenceModalitySchema.anyOf.map((modality) => modality.const));
99
67
  /**
100
68
  * Map an org-owned inference provider (`defineConfig({ providers })`) to its
101
69
  * `DesiredOrgProvider`. Resolves the API key from its `secret()` / `$VAR` ref
@@ -115,7 +83,7 @@ function mapOrgProvider(provider, required, env) {
115
83
  const capabilities = {};
116
84
  for (const [modality, block] of Object.entries(provider.capabilities ?? {})) {
117
85
  if (!INFERENCE_MODALITIES.has(modality)) {
118
- throw new ValidationError(`provider "${provider.slug}" declares unknown modality "${modality}" (expected text|image|stt|tts|embedding)`);
86
+ throw new ValidationError(`provider "${provider.slug}" declares unknown modality "${modality}" (expected ${[...INFERENCE_MODALITIES].join("|")})`);
119
87
  }
120
88
  if (block)
121
89
  capabilities[modality] = block;
@@ -182,19 +150,41 @@ function resolveConnectionConfigValue(value, required, env) {
182
150
  * connector `agentTooling`, never from skills.
183
151
  */
184
152
  export function mergeAgentDirArtifacts(settings, markdown, localSkills) {
185
- if (markdown.soulMd)
186
- settings.soulMd = markdown.soulMd;
187
- if (markdown.identityMd)
188
- settings.identityMd = markdown.identityMd;
189
- if (markdown.userMd)
190
- settings.userMd = markdown.userMd;
191
- if (localSkills.length > 0) {
153
+ for (const key of ["soulMd", "identityMd", "userMd"]) {
154
+ if (markdown[key] === undefined)
155
+ continue;
156
+ if (settings[key] !== undefined) {
157
+ throw new ValidationError(`Declare ${key} either in settings or in its Markdown file, not both`);
158
+ }
159
+ settings[key] = markdown[key];
160
+ }
161
+ if (localSkills !== undefined) {
162
+ if (settings.skillsConfig !== undefined) {
163
+ throw new ValidationError("Declare either skills or settings.skillsConfig, not both");
164
+ }
192
165
  settings.skillsConfig = { skills: localSkills };
193
166
  }
194
167
  }
195
168
  function mapAgent(agent, env, required) {
196
- const settings = {};
197
- if (agent.providers?.length) {
169
+ if (agent.settings !== undefined &&
170
+ !Value.Check(AgentSettingsPatchSchema, agent.settings)) {
171
+ const error = Value.Errors(AgentSettingsPatchSchema, agent.settings).First();
172
+ throw new ValidationError(`Agent "${agent.id}" settings${error?.path ?? ""}: ${error?.message ?? "invalid settings"}`);
173
+ }
174
+ const settings = { ...agent.settings };
175
+ for (const [helper, key] of [
176
+ ["providers", "models"],
177
+ ["network", "networkConfig"],
178
+ ["nixPackages", "nixConfig"],
179
+ ["guardrails", "guardrails"],
180
+ ["starters", "starters"],
181
+ ["skills", "skillsConfig"],
182
+ ]) {
183
+ if (agent[helper] !== undefined && settings[key] !== undefined) {
184
+ throw new ValidationError(`Agent "${agent.id}" must declare either ${helper} or settings.${key}, not both`);
185
+ }
186
+ }
187
+ if (agent.providers !== undefined) {
198
188
  // Each declared provider becomes one explicit ref in the ordered `models`
199
189
  // list (index 0 = the primary/default). A provider WITH a concrete model
200
190
  // emits `<providerId>/<model>` (never `<providerId>/auto` — auto is gone);
@@ -218,18 +208,19 @@ function mapAgent(agent, env, required) {
218
208
  return model.startsWith(`${id}/`) ? model : `${id}/${model}`;
219
209
  });
220
210
  }
221
- const allowed = agent.network?.allowed ?? [];
222
- const denied = agent.network?.denied ?? [];
223
- if (allowed.length > 0 || denied.length > 0) {
211
+ if (agent.network !== undefined) {
212
+ const { allowed, denied } = agent.network;
224
213
  settings.networkConfig = {
225
- ...(allowed.length > 0 ? { allowedDomains: [...new Set(allowed)] } : {}),
226
- ...(denied.length > 0 ? { deniedDomains: [...new Set(denied)] } : {}),
214
+ ...(allowed !== undefined
215
+ ? { allowedDomains: [...new Set(allowed)] }
216
+ : {}),
217
+ ...(denied !== undefined ? { deniedDomains: [...new Set(denied)] } : {}),
227
218
  };
228
219
  }
229
- if (agent.guardrails?.length) {
220
+ if (agent.guardrails !== undefined) {
230
221
  settings.guardrails = [...new Set(agent.guardrails)];
231
222
  }
232
- if (agent.nixPackages?.length) {
223
+ if (agent.nixPackages !== undefined) {
233
224
  settings.nixConfig = { packages: [...new Set(agent.nixPackages)] };
234
225
  }
235
226
  if (agent.starters !== undefined) {
@@ -266,32 +257,8 @@ function mapAgent(agent, env, required) {
266
257
  agentId: agent.id,
267
258
  name: agent.name ?? agent.id,
268
259
  };
269
- if (agent.description)
260
+ if (agent.description !== undefined)
270
261
  metadata.description = agent.description;
271
- // Exhaustiveness guard (compile-time): construct a projection object that
272
- // includes EVERY stored key (mapped → the computed value, unsupported/post-
273
- // load → undefined) and assert it satisfies AgentSettingsProjection. If a
274
- // field is added to AgentSettingsStoredSchema without an entry here, tsc
275
- // fails with "Property X is missing". This makes "declarative layer forgot
276
- // to wire a field" a compile error — the whole point of the schema. The
277
- // projection object is discarded; the real `settings` (Partial, only the
278
- // non-undefined fields) is what flows to apply.
279
- const _exhaustive = {
280
- models: settings.models,
281
- networkConfig: settings.networkConfig,
282
- nixConfig: settings.nixConfig,
283
- soulMd: settings.soulMd,
284
- userMd: settings.userMd,
285
- identityMd: settings.identityMd,
286
- skillsConfig: settings.skillsConfig,
287
- guardrails: settings.guardrails,
288
- guardrailsInline: settings.guardrailsInline,
289
- sandboxId: settings.sandboxId,
290
- verboseLogging: settings.verboseLogging,
291
- showToolCalls: settings.showToolCalls,
292
- starters: settings.starters,
293
- };
294
- void _exhaustive;
295
262
  return { metadata, settings, providerKeys };
296
263
  }
297
264
  function mapEntityType(entity) {
@@ -416,7 +383,7 @@ const MAX_AUTOMATION_SKILLS = 5;
416
383
  * content (the incoming message/event), so it may run with zero instructions on
417
384
  * the built-in default. Everything else — schedule triggers, event triggers with
418
385
  * execution "window", and Automations with no triggers at all (manual runs) —
419
- * needs a prompt, at least one skill, a reaction script, or a script executor.
386
+ * needs a prompt, at least one skill, a code module.
420
387
  *
421
388
  * This CLI preflight mirrors the server rule, catching the error against the
422
389
  * config file (naming the slug) rather than as a 422 mid-apply. When both
@@ -445,7 +412,7 @@ function assertAutomationSkills(automation, instructionSourceDeclared) {
445
412
  // Any instruction source satisfies the rule. An Automation
446
413
  // whose whole job is "run this skill" has no task statement to write, one
447
414
  // that spells its task out inline needs no skill, and one that runs entirely
448
- // as a reaction or executor script needs neither — demanding two would be
415
+ // as a code module needs neither — demanding two would be
449
416
  // stricter than the server and would reject configs the API accepts. The
450
417
  // mapper runs BEFORE the loader reads either file, so this boolean is the
451
418
  // config marker; the loader validates the file and the server enforces the
@@ -454,10 +421,30 @@ function assertAutomationSkills(automation, instructionSourceDeclared) {
454
421
  skills.length === 0 &&
455
422
  !automation.prompt.trim() &&
456
423
  !instructionSourceDeclared) {
457
- throw new ValidationError(`Automation "${automation.slug}" needs instructions: schedule triggers, event triggers with execution "window", and Automations with no triggers run on stored instructions alone, so give it a "prompt", at least one skill, a reaction script, or a script executor. Only event triggers with execution "turn" may omit all instruction sources.`);
424
+ throw new ValidationError(`Automation "${automation.slug}" needs instructions: schedule triggers, event triggers with execution "window", and Automations with no triggers run on stored instructions alone, so give it a "prompt", at least one skill, a code module. Only event triggers with execution "turn" may omit all instruction sources.`);
458
425
  }
459
426
  }
460
427
  function mapAutomation(automation) {
428
+ if (Object.hasOwn(automation, "executor")) {
429
+ throw new ValidationError(`Automation "${automation.slug}": executor is retired; use reactionFromFile("./job.ts") and clear a legacy configuration explicitly with executionConfig: null.`);
430
+ }
431
+ if (automation.executionConfig !== undefined) {
432
+ if (automation.model !== undefined) {
433
+ throw new ValidationError(`Automation "${automation.slug}" must declare either executionConfig or the model helper, not both`);
434
+ }
435
+ if (automation.executionConfig !== null &&
436
+ !Value.Check(AutomationExecutionConfigSchema, automation.executionConfig)) {
437
+ const error = Value.Errors(AutomationExecutionConfigSchema, automation.executionConfig).First();
438
+ throw new ValidationError(`Automation "${automation.slug}" executionConfig${error?.path ?? ""}: ${error?.message ?? "invalid execution options"}`);
439
+ }
440
+ }
441
+ let agentKind;
442
+ if (automation.agentKind !== undefined) {
443
+ if (!Value.Check(ManageAutomationsSchema.properties.agent_kind, automation.agentKind)) {
444
+ throw new ValidationError(`Automation "${automation.slug}" has an invalid agentKind: ${automation.agentKind}`);
445
+ }
446
+ agentKind = automation.agentKind;
447
+ }
461
448
  const sources = automation.sources
462
449
  ? Object.entries(automation.sources).map(([name, value]) => {
463
450
  if (typeof value === "string")
@@ -525,8 +512,7 @@ function mapAutomation(automation) {
525
512
  });
526
513
  return {
527
514
  slug: automation.slug,
528
- agent: agentId(automation.agent),
529
- ...(automation.executor === "agent" ? { executor: null } : {}),
515
+ agent: automation.agent == null ? null : agentId(automation.agent),
530
516
  // The author's task statement, carried straight through. Skill BODIES are
531
517
  // no longer folded in here — the loader resolves them into `skillSnapshots`
532
518
  // (see `resolveAutomationSkills` in desired-state.ts), because the mapper is
@@ -552,11 +538,14 @@ function mapAutomation(automation) {
552
538
  ...(automation.reactionsGuidance
553
539
  ? { reactionsGuidance: automation.reactionsGuidance }
554
540
  : {}),
555
- ...(automation.agentKind ? { agentKind: automation.agentKind } : {}),
541
+ ...(agentKind ? { agentKind } : {}),
556
542
  ...(automation.deviceWorkerId !== undefined
557
543
  ? { deviceWorkerId: automation.deviceWorkerId }
558
544
  : {}),
559
545
  ...(automation.model !== undefined ? { model: automation.model } : {}),
546
+ ...(automation.executionConfig !== undefined
547
+ ? { executionConfig: automation.executionConfig }
548
+ : {}),
560
549
  };
561
550
  }
562
551
  function mapAuthProfile(profile, required, env) {
@@ -752,7 +741,7 @@ export function mapProjectToDesiredState(project, env = process.env, only) {
752
741
  const automation = automations[i];
753
742
  if (!automation)
754
743
  continue;
755
- if (!agentIds.has(automation.agent)) {
744
+ if (automation.agent != null && !agentIds.has(automation.agent)) {
756
745
  throw new ValidationError(`Automation "${automation.slug}" names agent "${automation.agent}", but no agent with that id is declared in lobu.config.ts`);
757
746
  }
758
747
  // The config's `reaction` marker (from `reactionFromFile(path)`) drives the
@@ -760,10 +749,8 @@ export function mapProjectToDesiredState(project, env = process.env, only) {
760
749
  // later by the loader. `automations` is index-aligned with
761
750
  // `project.automations` (the mapper maps in order). An explicit
762
751
  // `reaction: null` is a removal, not an instruction source.
763
- assertAutomationSkills(automation, (project.automations?.[i]?.reaction !== undefined &&
764
- project.automations?.[i]?.reaction !== null) ||
765
- (project.automations?.[i]?.executor !== undefined &&
766
- project.automations?.[i]?.executor !== "agent"));
752
+ assertAutomationSkills(automation, project.automations?.[i]?.reaction !== undefined &&
753
+ project.automations?.[i]?.reaction !== null);
767
754
  for (const trigger of automation.triggers ?? []) {
768
755
  if (trigger.kind !== "event" ||
769
756
  trigger.source === "workspace" ||
@@ -1,3 +1,4 @@
1
+ import type { AutomationExecutionConfig, LegacyAutomationExecutionConfig } from "@lobu/core/contracts/tools/manage-automations";
1
2
  /**
2
3
  * Shared structural types + tiny helpers used across the apply pipeline
3
4
  * (desired-state IR, wire client, diff, apply-cmd).
@@ -30,12 +31,8 @@ export interface AutomationSource {
30
31
  context?: boolean;
31
32
  }
32
33
  export declare function isRecord(value: unknown): value is Record<string, unknown>;
33
- /** Apply declared model/executor fields while preserving unmanaged execution options. */
34
- export declare function automationExecutionConfig(model: string | null | undefined, remote?: Record<string, unknown> | null, executor?: {
35
- kind: "script";
36
- source: string;
37
- params?: Record<string, unknown>;
38
- } | null): Record<string, unknown> | null;
34
+ /** Preserve omitted options; replacing a legacy definition must be explicit. */
35
+ export declare function automationExecutionConfig(model: string | null | undefined, remote?: LegacyAutomationExecutionConfig | null, declared?: AutomationExecutionConfig | null): LegacyAutomationExecutionConfig | null;
39
36
  /**
40
37
  * Keys of locally-declared connector definitions whose key is already known.
41
38
  * A `null` key (an auto-discovered `*.connector.ts` the server compiles) can't
@@ -1,29 +1,18 @@
1
- /**
2
- * Shared structural types + tiny helpers used across the apply pipeline
3
- * (desired-state IR, wire client, diff, apply-cmd).
4
- *
5
- * Only shapes that are genuinely IDENTICAL on both sides of the wire belong
6
- * here — anything that encodes a server-specific response shape stays a
7
- * `Remote*` type in client.ts.
8
- */
9
1
  export function isRecord(value) {
10
2
  return typeof value === "object" && value !== null && !Array.isArray(value);
11
3
  }
12
- /** Apply declared model/executor fields while preserving unmanaged execution options. */
13
- export function automationExecutionConfig(model, remote, executor) {
14
- if (executor) {
15
- if (model != null)
16
- throw new Error("Script Automations do not use a model override.");
17
- return { executor };
18
- }
19
- if (model === undefined && executor === undefined)
4
+ /** Preserve omitted options; replacing a legacy definition must be explicit. */
5
+ export function automationExecutionConfig(model, remote, declared) {
6
+ if (declared !== undefined)
7
+ return declared;
8
+ if (model === undefined)
20
9
  return remote ?? null;
10
+ if (remote?.executor)
11
+ throw new Error("Clear the legacy executor explicitly with executionConfig before changing its model.");
21
12
  const config = { ...remote };
22
- if (executor === null)
23
- delete config.executor;
24
13
  if (model === null)
25
14
  delete config.model;
26
- else if (model !== undefined)
15
+ else
27
16
  config.model = model;
28
17
  return Object.keys(config).length > 0 ? config : null;
29
18
  }
@@ -12,6 +12,7 @@ import { addContext, getCurrentContextName, getServerConfig, loadContextConfig,
12
12
  import { saveCredentials } from "../internal/credentials.js";
13
13
  import { agentApiBase } from "../internal/gateway-url.js";
14
14
  import { parseEnvContent } from "../internal/index.js";
15
+ import { resolveNode26Binary } from "../internal/node-binary.js";
15
16
  import { checkNodeSupport } from "../internal/node-version.js";
16
17
  import { loadProjectLink } from "../internal/project-link.js";
17
18
  import { prepareRuntime } from "../internal/runtime-components.js";
@@ -105,13 +106,21 @@ export function shouldRefuseSharedDatabaseUrl(input) {
105
106
  */
106
107
  export async function devCommand(cwd, options = {}) {
107
108
  const spinner = ora("Validating environment...").start();
108
- // The server also warns on Node 25, but only after the CLI's boot output.
109
- // Surface the sandbox limitation before validation so it is hard to miss.
109
+ // The backend loads isolated-vm, whose native build is Node-26-only. Fail
110
+ // before validation so an unsupported (or Bun-hosted) launch is obvious.
110
111
  const nodeSupport = checkNodeSupport();
111
- if (nodeSupport.ok && !nodeSupport.sandbox) {
112
- spinner.warn(chalk.yellow(`Node ${process.versions.node}: the agent-code sandbox (query_sdk / run_sdk) is unavailable.`));
113
- console.warn(chalk.dim(" isolated-vm has no Node 25 build. Use Node 24 (LTS) or 26+ to enable the sandbox.\n"));
114
- spinner.start("Validating environment...");
112
+ if (!nodeSupport.ok) {
113
+ spinner.fail(chalk.red(nodeSupport.reason));
114
+ console.error(chalk.dim(` ${nodeSupport.why}\n`));
115
+ process.exit(1);
116
+ }
117
+ let nodeBinary;
118
+ try {
119
+ nodeBinary = resolveNode26Binary();
120
+ }
121
+ catch (error) {
122
+ spinner.fail(chalk.red(error instanceof Error ? error.message : String(error)));
123
+ process.exit(1);
115
124
  }
116
125
  const envPath = join(cwd, ".env");
117
126
  let envVars = {};
@@ -256,7 +265,12 @@ export async function devCommand(cwd, options = {}) {
256
265
  GATEWAY_PORT: String(portNum),
257
266
  ...(logLevel ? { LOG_LEVEL: logLevel } : {}),
258
267
  };
259
- const child = spawn(process.execPath, [bundlePath], {
268
+ // Never `process.execPath`: when the CLI itself was launched through Bun,
269
+ // that is Bun, which cannot dlopen the V8 isolated-vm addon. `nodeBinary`
270
+ // is a verified Node 26 binary (the current process when it already is one).
271
+ // `--no-node-snapshot` is isolated-vm's upstream launch requirement on
272
+ // Node 20+.
273
+ const child = spawn(nodeBinary, ["--no-node-snapshot", bundlePath], {
260
274
  cwd,
261
275
  env: childEnv,
262
276
  stdio: "inherit",
@@ -56,14 +56,7 @@ function checkNodeVersion() {
56
56
  return {
57
57
  name: "node",
58
58
  status: "fail",
59
- detail: `${version} (needs >=${MIN_NODE_MAJOR})`,
60
- };
61
- }
62
- if (!support.sandbox) {
63
- return {
64
- name: "node",
65
- status: "warn",
66
- detail: `${version} (SDK sandbox unavailable; use 24 LTS or 26+)`,
59
+ detail: `${version} (needs ${MIN_NODE_MAJOR}.x)`,
67
60
  };
68
61
  }
69
62
  return { name: "node", status: "ok", detail: version };
@@ -521,11 +521,10 @@ export async function initCommand(cwd = process.cwd(), projectNameArg, options =
521
521
  WORKER_DISALLOWED_DOMAINS: answers.disallowedDomains,
522
522
  };
523
523
  await renderTemplate(".env.tmpl", variables, join(projectDir, ".env"));
524
- // Pin Node 22 for nvm / fnm / mise / asdf / volta — Lobu refuses to boot
525
- // on Node 25+ (isolated-vm has no prebuilt). Homebrew's `node` now
526
- // resolves to 26, so without these files a fresh `lobu run` fails.
527
- await writeFile(join(projectDir, ".nvmrc"), "22\n");
528
- await writeFile(join(projectDir, ".node-version"), "22\n");
524
+ // Pin Node 26 for nvm / fnm / mise / asdf / volta — Lobu's gateway and
525
+ // worker load the Node-26-only isolated-vm native build.
526
+ await writeFile(join(projectDir, ".nvmrc"), "26\n");
527
+ await writeFile(join(projectDir, ".node-version"), "26\n");
529
528
  // `.env` carries ENCRYPTION_KEY + provider API keys / OAuth tokens
530
529
  // appended via setLocalEnvValue below. Tighten now so the initial
531
530
  // write isn't world-readable on multi-user hosts (default umask 022).
@@ -9,7 +9,9 @@
9
9
  * Automation reactions) live in their own modules; these objects only declare
10
10
  * config and references.
11
11
  */
12
- import type { AutomationEventTrigger, AutomationScheduleTrigger, AutomationWorkspaceEventTrigger, ConnectorClass, ConnectorRuntime, CollectionPresentation, Dimension, EventSet, Measure, ReactionClient, AutomationScriptContext, ReactionContext, Segment } from "@lobu/connector-sdk";
12
+ import type { AutomationEventTrigger, AutomationScheduleTrigger, AutomationScriptContext, AutomationWorkspaceEventTrigger, CollectionPresentation, ConnectorClass, ConnectorRuntime, Dimension, EventSet, Measure, ReactionClient, ReactionContext, Segment } from "@lobu/connector-sdk";
13
+ import type { AgentSettingsPatch } from "@lobu/core/contracts/agent-settings";
14
+ import type { AutomationExecutionConfig } from "@lobu/core/contracts/tools/manage-automations";
13
15
  import { type StringOptions, type TOptional, type TSchema, type TString } from "@sinclair/typebox";
14
16
  import type { SecretRef } from "./secret.js";
15
17
  /** A connector referenced by its key, or by the class produced by `defineConnector`. */
@@ -428,17 +430,11 @@ export declare function viewFromFile(path: string): ViewSource;
428
430
  * `<Handler>` generic on {@link reactionFromFile} against the referenced module.
429
431
  */
430
432
  export type ReactionHandler = (ctx: ReactionContext, client: ReactionClient, params?: Record<string, unknown>) => Promise<unknown>;
431
- export type AutomationScriptHandler = (ctx: AutomationScriptContext, client: ReactionClient, params?: Record<string, unknown>) => Promise<unknown>;
432
- export interface ScriptSource {
433
- readonly kind: "scriptSource";
434
- path: string;
435
- params?: Record<string, unknown>;
436
- }
437
- /** Execute a local TypeScript job directly, with the owning agent's SDK permissions. */
438
- export declare function scriptFromFile<_Handler extends AutomationScriptHandler = AutomationScriptHandler>(path: string, params?: Record<string, unknown>): ScriptSource;
433
+ /** Optional preparation export in an Automation reaction module. */
434
+ export type PreparationHandler = (ctx: AutomationScriptContext, client: ReactionClient) => Promise<Record<string, Record<string, unknown>[]>>;
439
435
  /**
440
- * A local reaction source file to compile + run in a sandboxed isolate when the
441
- * Automation fires. Built with {@link reactionFromFile} and set on
436
+ * A local lifecycle module: optional `prepare` before the native agent and/or
437
+ * a default completion reaction, both run in the shared sandbox. Built with {@link reactionFromFile} and set on
442
438
  * {@link Automation.reaction}. Like {@link ConnectorSource}, this carries only the
443
439
  * path as plain data — the handler module is NOT imported at config-eval time;
444
440
  * `lobu apply` reads the raw source and the server compiles it.
@@ -449,7 +445,10 @@ export interface ReactionSource {
449
445
  path: string;
450
446
  }
451
447
  /**
452
- * Reference a local reaction source file to compile + ship at apply time.
448
+ * Reference a local lifecycle module to compile + ship at apply time.
449
+ * A preparation-only module needs no generic: `reactionFromFile("./prepare.ts")`.
450
+ * Its `prepare` export returns named arrays of records, saved per run and read
451
+ * by the agent through `knowledge.read({ automation_id, run_id }).sources`.
453
452
  *
454
453
  * Pass the handler's module type via the generic for go-to-def / rename and a
455
454
  * `tsc` error if the module's default export drifts from {@link ReactionHandler}:
@@ -462,7 +461,7 @@ export interface ReactionSource {
462
461
  * The `import type` is erased at compile time (zero runtime cost; jiti drops it),
463
462
  * so the handler module is never imported during config eval.
464
463
  */
465
- export declare function reactionFromFile<_Handler extends ReactionHandler = ReactionHandler>(path: string): ReactionSource;
464
+ export declare function reactionFromFile<_Handler extends (...args: never[]) => Promise<unknown> = ReactionHandler>(path: string): ReactionSource;
466
465
  export interface AutomationEntityOutput {
467
466
  /** Stored entity type (a config handle or slug). */
468
467
  entity: EntityType | string;
@@ -505,10 +504,10 @@ export interface Automation {
505
504
  readonly kind: "automation";
506
505
  /** Stable slug — diff key. */
507
506
  slug: string;
508
- /** Owning agent (handle or id). Every Automation belongs to exactly one agent. */
509
- agent: Agent | string;
510
- /** Script job or agent execution. Omitted preserves the stored executor; "agent" clears a script executor. */
511
- executor?: ScriptSource | "agent";
507
+ /** Managed agent identity. Omit for device-only or external analysis. */
508
+ agent?: Agent | string | null;
509
+ /** Canonical execution options. Omit to preserve; null clears. Cannot overlap the model helper. */
510
+ executionConfig?: AutomationExecutionConfig | null;
512
511
  name?: string;
513
512
  description?: string;
514
513
  /**
@@ -536,7 +535,7 @@ export interface Automation {
536
535
  * action for a declarative project.
537
536
  *
538
537
  * Supply {@link Automation.prompt}, `skills`, a {@link Automation.reaction}
539
- * script, or an {@link Automation.executor} script. Any one is required for schedule triggers, event
538
+ * script. Any one is required for schedule triggers, event
540
539
  * triggers with execution `"window"`, and Automations with no triggers
541
540
  * (manual runs); an event trigger with execution `"turn"` may omit all
542
541
  * instruction sources, since the incoming event is the content and a built-in
@@ -565,7 +564,7 @@ export interface Automation {
565
564
  tags?: string[];
566
565
  /** LLM guidance for the Automation's downstream reaction agent. */
567
566
  reactionsGuidance?: string;
568
- /** Agent-kind override for firings (e.g. "background", "notifier"). */
567
+ /** Agent runtime override for firings. */
569
568
  agentKind?: string;
570
569
  /**
571
570
  * UUID pinning this Automation's runs to a specific device worker. Only
@@ -579,16 +578,14 @@ export interface Automation {
579
578
  */
580
579
  model?: string | null;
581
580
  /**
582
- * A sibling `.ts` reaction script (`./reactions/foo.reaction.ts`) compiled +
583
- * run in a sandboxed isolate when the Automation fires, built with
584
- * {@link reactionFromFile}. The script must `export default async (ctx,
585
- * client, params?) => …` ({@link ReactionHandler}). Kept in its own file (not
586
- * inline) so your IDE type-checks it; the path must stay under the config
587
- * directory.
581
+ * A sibling TypeScript module, built with {@link reactionFromFile}. Export
582
+ * `prepare` to save named sources before analysis and/or a default handler
583
+ * for completion. Without prompt, skills, input schema or declared outputs,
584
+ * the module runs as code without a model. The path stays under the config
585
+ * directory so it can be typechecked and bundled portably.
588
586
  *
589
587
  * Omit to preserve a previously installed reaction. Set explicitly to `null`
590
- * to remove it — required when switching a reaction-driven Automation to a
591
- * script executor so the same work is not performed twice.
588
+ * to remove it after the remaining definition has its required instructions.
592
589
  */
593
590
  reaction?: ReactionSource | null;
594
591
  }
@@ -673,7 +670,7 @@ export interface ProviderConfig {
673
670
  key?: string | SecretRef;
674
671
  }
675
672
  /** Modalities an org inference provider may declare a capability block for. */
676
- export type InferenceModality = "text" | "image" | "stt" | "tts" | "embedding";
673
+ export type InferenceModality = "text" | "image" | "stt" | "tts";
677
674
  /**
678
675
  * Per-modality upstream override for an {@link OrgProvider}. Omit a modality
679
676
  * entirely to keep the provider's static (built-in) semantics for it. All fields
@@ -719,6 +716,8 @@ export interface Agent {
719
716
  id: string;
720
717
  name?: string;
721
718
  description?: string;
719
+ /** Canonical settings. Omitted keys stay unmanaged; supplied settings replace their stored value. */
720
+ settings?: AgentSettingsPatch;
722
721
  /**
723
722
  * Agent directory holding `SOUL.md` / `IDENTITY.md` / `USER.md`. Relative to
724
723
  * the config file; defaults to `./agents/<id>`. (Skills are referenced
@@ -163,12 +163,11 @@ export function connectorFromFile(path) {
163
163
  export function viewFromFile(path) {
164
164
  return { kind: "viewSource", path };
165
165
  }
166
- /** Execute a local TypeScript job directly, with the owning agent's SDK permissions. */
167
- export function scriptFromFile(path, params) {
168
- return { kind: "scriptSource", path, ...(params ? { params } : {}) };
169
- }
170
166
  /**
171
- * Reference a local reaction source file to compile + ship at apply time.
167
+ * Reference a local lifecycle module to compile + ship at apply time.
168
+ * A preparation-only module needs no generic: `reactionFromFile("./prepare.ts")`.
169
+ * Its `prepare` export returns named arrays of records, saved per run and read
170
+ * by the agent through `knowledge.read({ automation_id, run_id }).sources`.
172
171
  *
173
172
  * Pass the handler's module type via the generic for go-to-def / rename and a
174
173
  * `tsc` error if the module's default export drifts from {@link ReactionHandler}: