@lobu/runtime-device 20.1.0 → 21.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 (121) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +46 -40
  3. package/npm-shrinkwrap.json +283 -237
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.d.ts +7 -2
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +77 -75
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +40 -25
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +31 -39
  9. package/vendor/cli/dist/commands/_lib/apply/deployment.d.ts +1 -1
  10. package/vendor/cli/dist/commands/_lib/apply/deployment.js +2 -2
  11. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +47 -11
  12. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +106 -7
  13. package/vendor/cli/dist/commands/_lib/apply/diff.d.ts +14 -6
  14. package/vendor/cli/dist/commands/_lib/apply/diff.js +42 -23
  15. package/vendor/cli/dist/commands/_lib/apply/map-config.js +2 -3
  16. package/vendor/cli/dist/commands/_lib/apply/render.js +2 -0
  17. package/vendor/cli/dist/commands/_lib/apply/rollback-cmd.js +3 -3
  18. package/vendor/cli/dist/commands/_lib/connector-loader.d.ts +5 -1
  19. package/vendor/cli/dist/commands/_lib/connector-loader.js +1 -1
  20. package/vendor/cli/dist/commands/_lib/ensure-deps-installed.d.ts +15 -26
  21. package/vendor/cli/dist/commands/_lib/ensure-deps-installed.js +227 -136
  22. package/vendor/cli/dist/commands/_lib/view-bundler.d.ts +33 -0
  23. package/vendor/cli/dist/commands/_lib/view-bundler.js +207 -0
  24. package/vendor/cli/dist/commands/_lib/view-reapply.d.ts +60 -0
  25. package/vendor/cli/dist/commands/_lib/view-reapply.js +182 -0
  26. package/vendor/cli/dist/commands/dev.d.ts +14 -5
  27. package/vendor/cli/dist/commands/dev.js +56 -8
  28. package/vendor/cli/dist/commands/init.d.ts +1 -1
  29. package/vendor/cli/dist/commands/init.js +4 -4
  30. package/vendor/cli/dist/commands/login.js +3 -0
  31. package/vendor/cli/dist/config/define.d.ts +25 -8
  32. package/vendor/cli/dist/config/define.js +24 -0
  33. package/vendor/cli/dist/connectors/README.md +15 -16
  34. package/vendor/cli/dist/connectors/chat-user-identity.ts +41 -0
  35. package/vendor/cli/dist/connectors/github.ts +15 -9
  36. package/vendor/cli/dist/connectors/google-identity.ts +11 -0
  37. package/vendor/cli/dist/connectors/google_calendar.ts +21 -31
  38. package/vendor/cli/dist/connectors/google_drive.ts +106 -131
  39. package/vendor/cli/dist/connectors/google_gmail.ts +53 -30
  40. package/vendor/cli/dist/connectors/hackernews.ts +2 -5
  41. package/vendor/cli/dist/connectors/jira.ts +62 -27
  42. package/vendor/cli/dist/connectors/linear.ts +55 -21
  43. package/vendor/cli/dist/connectors/microsoft_outlook.ts +151 -110
  44. package/vendor/cli/dist/connectors/postgres.ts +19 -11
  45. package/vendor/cli/dist/connectors/producthunt.ts +8 -6
  46. package/vendor/cli/dist/connectors/reddit.ts +2 -2
  47. package/vendor/cli/dist/connectors/rss.ts +2 -2
  48. package/vendor/cli/dist/connectors/slack-identity.ts +19 -0
  49. package/vendor/cli/dist/connectors/whatsapp_web.ts +5 -4
  50. package/vendor/cli/dist/connectors/x.ts +32 -17
  51. package/vendor/cli/dist/connectors/youtube.ts +18 -5
  52. package/vendor/cli/dist/internal/connector-compiler.d.ts +1 -1
  53. package/vendor/cli/dist/internal/connector-compiler.js +216 -17
  54. package/vendor/cli/dist/internal/credentials.js +5 -1
  55. package/vendor/cli/dist/internal/oauth.d.ts +15 -1
  56. package/vendor/cli/dist/internal/oauth.js +9 -1
  57. package/vendor/cli/dist/runtime-components.json +4 -4
  58. package/vendor/cli/package.json +2 -1
  59. package/vendor/connector-sdk/dist/connector-runtime.d.ts +4 -6
  60. package/vendor/connector-sdk/dist/connector-runtime.js +3 -5
  61. package/vendor/connector-sdk/dist/connector-types.d.ts +28 -13
  62. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -1
  63. package/vendor/connector-sdk/dist/define-connector.js +4 -1
  64. package/vendor/connector-sdk/dist/http-client.d.ts +18 -7
  65. package/vendor/connector-sdk/dist/http-client.js +15 -13
  66. package/vendor/connector-sdk/dist/index.d.ts +1 -1
  67. package/vendor/connector-sdk/dist/retry.d.ts +15 -3
  68. package/vendor/connector-sdk/dist/retry.js +40 -64
  69. package/vendor/connector-sdk/package.json +1 -1
  70. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +122 -10
  71. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +78 -10
  72. package/vendor/connector-worker/dist/agent-turn/types.d.ts +34 -4
  73. package/vendor/connector-worker/dist/compile/index.d.ts +21 -2
  74. package/vendor/connector-worker/dist/compile/index.js +41 -8
  75. package/vendor/connector-worker/dist/compile/source-capture.d.ts +10 -0
  76. package/vendor/connector-worker/dist/compile/source-capture.js +108 -0
  77. package/vendor/connector-worker/dist/daemon/agent-turn.js +97 -10
  78. package/vendor/connector-worker/dist/daemon/automation-process.d.ts +32 -0
  79. package/vendor/connector-worker/dist/daemon/automation-process.js +102 -1
  80. package/vendor/connector-worker/dist/daemon/automation.d.ts +1 -1
  81. package/vendor/connector-worker/dist/daemon/builtins/index.js +8 -0
  82. package/vendor/connector-worker/dist/daemon/builtins/os-shell.d.ts +13 -1
  83. package/vendor/connector-worker/dist/daemon/builtins/os-shell.js +28 -2
  84. package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -1
  85. package/vendor/connector-worker/dist/daemon/executor.js +42 -51
  86. package/vendor/connector-worker/dist/daemon/start.js +5 -1
  87. package/vendor/connector-worker/dist/executor/interface.d.ts +12 -8
  88. package/vendor/connector-worker/dist/executor/isolate.js +45 -28
  89. package/vendor/connector-worker/dist/self-check/index.js +15 -13
  90. package/vendor/connector-worker/package.json +1 -1
  91. package/vendor/core/dist/agent-policy.js +3 -0
  92. package/vendor/core/dist/connector-query-errors.d.ts +3 -3
  93. package/vendor/core/dist/connector-query-errors.js +8 -3
  94. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +24 -0
  95. package/vendor/core/dist/contracts/tools/manage-connections.js +13 -0
  96. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +15 -25
  97. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +3 -5
  98. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +11 -0
  99. package/vendor/core/dist/contracts/tools/manage-feeds.js +12 -1
  100. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +47 -6
  101. package/vendor/core/dist/contracts/tools/manage-operations.js +36 -1
  102. package/vendor/core/dist/contracts/tools/manage-views.d.ts +293 -0
  103. package/vendor/core/dist/contracts/tools/manage-views.js +203 -0
  104. package/vendor/core/dist/contracts/tools/source-files-schema.d.ts +7 -0
  105. package/vendor/core/dist/contracts/tools/source-files-schema.js +19 -0
  106. package/vendor/core/dist/contracts/tools/source-files.d.ts +14 -0
  107. package/vendor/core/dist/contracts/tools/source-files.js +55 -0
  108. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +37 -0
  109. package/vendor/core/dist/contracts/tools/view-content-hash.js +58 -0
  110. package/vendor/core/dist/contracts/tools/view-path.d.ts +18 -0
  111. package/vendor/core/dist/contracts/tools/view-path.js +24 -0
  112. package/vendor/core/dist/contracts/worker/protocol.d.ts +73 -8
  113. package/vendor/core/dist/contracts/worker/protocol.js +58 -9
  114. package/vendor/core/dist/credentials.d.ts +16 -1
  115. package/vendor/core/dist/credentials.js +10 -1
  116. package/vendor/core/dist/reserved.d.ts +3 -3
  117. package/vendor/core/dist/reserved.js +9 -1
  118. package/vendor/core/dist/utils/secret-redaction.js +2 -0
  119. package/vendor/core/package.json +25 -5
  120. package/vendor/core/dist/contracts/tools/manage-view-templates.d.ts +0 -165
  121. package/vendor/core/dist/contracts/tools/manage-view-templates.js +0 -130
@@ -4,6 +4,7 @@ import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
4
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
5
  import { createAjv } from "@lobu/core/ajv";
6
6
  import { ValidationError } from "../../memory/_lib/errors.js";
7
+ import { checkProjectDeps } from "../ensure-deps-installed.js";
7
8
  import { mapProjectToDesiredState, mergeAgentDirArtifacts, } from "./map-config.js";
8
9
  import { isRecord, } from "./shared.js";
9
10
  async function parseSkillFrontmatter(raw) {
@@ -435,12 +436,107 @@ function resolveConnectorSources(sources, cwd) {
435
436
  key: null,
436
437
  declaredKeyHint: extractDeclaredConnectorKey(sourceCode) ?? undefined,
437
438
  sourcePath: abs,
439
+ sourceRoot: baseDir,
438
440
  sourceCode,
439
441
  sourceFile: rel.replace(/^\.\//, ""),
440
442
  });
441
443
  }
442
444
  return defs.sort((a, b) => a.sourceFile.localeCompare(b.sourceFile));
443
445
  }
446
+ const VIEW_SOURCE_MAX_BYTES = 1_000_000;
447
+ /**
448
+ * Resolve `viewFromFile` entries to bundled views. Same containment shape as
449
+ * connector sources (relative POSIX path under the config directory, no
450
+ * `..`/absolute/backslash, must exist, under the server's source cap).
451
+ *
452
+ * Bundling happens HERE, not in executePlan, for one reason: the diff key
453
+ * must be the server's hash (source plus declared metadata plus the compiled
454
+ * artifact's digest, via the shared content-hash function), and the metadata
455
+ * only exists after the module's `view` export is read. The key comes from
456
+ * that export — there is no path fallback, because a required key has nothing
457
+ * to fall back to.
458
+ * ExecutePlan ships these artifacts verbatim; it never re-bundles.
459
+ *
460
+ * The esbuild + jiti-adjacent imports stay lazy (this async function is the
461
+ * only importer), so the bundler graph never rides the module-load path.
462
+ */
463
+ async function resolveViewSources(sources, cwd) {
464
+ const baseDir = resolve(cwd);
465
+ const views = [];
466
+ const seen = new Set();
467
+ const { bundleViewFromFile } = await import("../view-bundler.js");
468
+ const { contentHash } = await import("@lobu/core/contracts/tools/view-content-hash");
469
+ for (const src of sources) {
470
+ const rel = src.path.trim();
471
+ if (!rel ||
472
+ rel.startsWith("/") ||
473
+ rel.includes("\\") ||
474
+ rel.split("/").some((seg) => seg === "..")) {
475
+ throw new ValidationError(`viewFromFile(${JSON.stringify(src.path)}) must be a relative POSIX path under the config directory (./views/deal/pipeline.tsx)`);
476
+ }
477
+ if (!/\.tsx?$/.test(rel)) {
478
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) must point at a \`.tsx\` or \`.ts\` file`);
479
+ }
480
+ const abs = resolve(baseDir, rel);
481
+ const relPath = relative(baseDir, abs);
482
+ if (relPath === ".." ||
483
+ relPath.startsWith(`..${sep}`) ||
484
+ isAbsolute(relPath)) {
485
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) resolves outside the config directory (${abs})`);
486
+ }
487
+ let sourceCode;
488
+ try {
489
+ sourceCode = readFileSync(abs, "utf-8");
490
+ }
491
+ catch {
492
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) does not exist (resolved to ${abs})`);
493
+ }
494
+ if (Buffer.byteLength(sourceCode, "utf8") > VIEW_SOURCE_MAX_BYTES) {
495
+ throw new ValidationError(`viewFromFile(${JSON.stringify(rel)}) is over the ${VIEW_SOURCE_MAX_BYTES} byte source cap`);
496
+ }
497
+ const bundled = await bundleViewFromFile(abs, baseDir);
498
+ sourceCode = bundled.sourceFiles.files[bundled.sourceFiles.entrypoint];
499
+ const key = bundled.metadata.key;
500
+ if (seen.has(key)) {
501
+ throw new ValidationError(`duplicate view key "${key}" in lobu.config.ts — each viewFromFile must resolve to a unique key`);
502
+ }
503
+ seen.add(key);
504
+ // Hash EXACTLY what the server will store: name defaults to the key,
505
+ // description defaults to empty, metadata JSON-round-tripped (the wire
506
+ // drops undefined, so hash post-round-trip or equivalent declarations
507
+ // compare differently), plus the digest of the bundle produced above
508
+ // (which carries the relative imports the entry source alone omits).
509
+ // Same function, same inputs: same hash.
510
+ const name = key;
511
+ const description = "";
512
+ const attach = JSON.parse(JSON.stringify(bundled.metadata.attach));
513
+ const params = JSON.parse(JSON.stringify(bundled.metadata.params));
514
+ const actions = JSON.parse(JSON.stringify(bundled.metadata.actions));
515
+ views.push({
516
+ key,
517
+ sourcePath: abs,
518
+ sourceCode,
519
+ contentHash: contentHash(sourceCode, {
520
+ name,
521
+ description,
522
+ attach,
523
+ params,
524
+ actions,
525
+ }, bundled.compiledCode, {
526
+ sourceFiles: bundled.sourceFiles,
527
+ dependencies: bundled.dependencies,
528
+ }),
529
+ sourceFile: rel.replace(/^\.\//, ""),
530
+ compiledCode: bundled.compiledCode,
531
+ sourceFiles: bundled.sourceFiles,
532
+ dependencies: bundled.dependencies,
533
+ attach,
534
+ params,
535
+ actions,
536
+ });
537
+ }
538
+ return views.sort((a, b) => a.sourceFile.localeCompare(b.sourceFile));
539
+ }
444
540
  const REACTION_SCRIPT_MAX_BYTES = 256 * 1024;
445
541
  const ENTITY_RULES_MAX_BYTES = 32 * 1024;
446
542
  /**
@@ -540,12 +636,8 @@ export async function loadProjectConfig(cwd) {
540
636
  throw new ValidationError(`No lobu.config.ts found in ${cwd}`);
541
637
  }
542
638
  const { createJiti } = await import("jiti");
543
- // Resolve the SDK imports the config will reference (`@lobu/cli/config`,
544
- // `@lobu/connector-sdk`) against the running CLI's own copies — not the
545
- // project's `node_modules`. This lets a freshly-scaffolded project
546
- // `validate`/`run` with zero install: the user has the CLI, that's enough.
547
- // Falls through silently if a symbol can't be resolved from here (the
548
- // catch-all error below still surfaces real problems).
639
+ // SDK config imports use the running CLI's copies. Ordinary project
640
+ // dependencies are checked before desired-state loading.
549
641
  const alias = {};
550
642
  for (const spec of ["@lobu/cli/config", "@lobu/connector-sdk"]) {
551
643
  try {
@@ -555,7 +647,9 @@ export async function loadProjectConfig(cwd) {
555
647
  // CLI dist may not expose this symbol in some packaging layouts; skip.
556
648
  }
557
649
  }
558
- const jiti = createJiti(pathToFileURL(configPath).href, Object.keys(alias).length > 0 ? { alias } : undefined);
650
+ const jiti = createJiti(pathToFileURL(configPath).href,
651
+ // Validation must not populate node_modules/.cache/jiti.
652
+ { alias, fsCache: false });
559
653
  let project;
560
654
  try {
561
655
  project = await jiti.import(configPath, { default: true });
@@ -578,6 +672,7 @@ export async function loadProjectConfig(cwd) {
578
672
  * reaction scripts, local connector source).
579
673
  */
580
674
  export async function loadDesiredStateFromConfig(opts) {
675
+ checkProjectDeps(opts.cwd);
581
676
  const env = opts.env ?? process.env;
582
677
  const { project: typedProject, configPath } = await loadProjectConfig(opts.cwd);
583
678
  const state = mapProjectToDesiredState(typedProject, env, opts.only);
@@ -690,6 +785,10 @@ export async function loadDesiredStateFromConfig(opts) {
690
785
  // ship local connector source for those runs either.
691
786
  if (!opts.only) {
692
787
  state.connectors.definitions = resolveConnectorSources(typedProject.connectors ?? [], opts.cwd);
788
+ // Views are neither agents nor memory: a targeted apply skips them too.
789
+ // Bundled here so the diff key is the server's hash (same function, same
790
+ // inputs); executePlan ships these artifacts verbatim.
791
+ state.views = await resolveViewSources(typedProject.views ?? [], opts.cwd);
693
792
  }
694
793
  // Surface load-time warnings to `lobu apply` (which prints them). #1010's
695
794
  // "ignored connectors because [memory] is disabled" case is obsolete here —
@@ -1,7 +1,7 @@
1
1
  import { type AgentSettings } from "@lobu/core";
2
2
  import type { InferenceModality } from "../../../config/define.js";
3
- import type { RemoteAgent, RemoteAuthProfile, RemoteAutomation, RemoteConnection, RemoteConnectorDefinition, RemoteEntityType, RemoteFeed, RemoteInferenceProvider, RemoteRelationshipType, UpdateConnectionPayload, UpdateFeedPayload } from "./client.js";
4
- import type { DesiredAgent, DesiredAuthProfile, DesiredAutomationTrigger, DesiredConnection, DesiredConnectorDefinition, DesiredEntityType, DesiredFeed, DesiredOrgProvider, DesiredRelationshipType, DesiredState, DesiredAutomation } from "./desired-state.js";
3
+ import type { RemoteAgent, RemoteAuthProfile, RemoteAutomation, RemoteConnection, RemoteConnectorDefinition, RemoteEntityType, RemoteFeed, RemoteInferenceProvider, RemoteRelationshipType, RemoteView, UpdateConnectionPayload, UpdateFeedPayload } from "./client.js";
4
+ import type { DesiredAgent, DesiredAuthProfile, DesiredAutomationTrigger, DesiredConnection, DesiredConnectorDefinition, DesiredEntityType, DesiredFeed, DesiredOrgProvider, DesiredRelationshipType, DesiredState, DesiredAutomation, DesiredView } from "./desired-state.js";
5
5
  import { type AutomationSource } from "./shared.js";
6
6
  type DiffVerb = "create" | "update" | "noop" | "drift" | "delete";
7
7
  interface BaseRow {
@@ -115,6 +115,13 @@ export interface InferenceProviderDiffRow extends ResourceRow<DesiredOrgProvider
115
115
  */
116
116
  capabilityModalities?: InferenceModality[];
117
117
  }
118
+ /** A `viewFromFile` module vs the org's applied view of the same key. */
119
+ export interface ViewDiffRow extends BaseRow {
120
+ kind: "view";
121
+ desired?: DesiredView;
122
+ /** Module key resolved at bundle time; the diff keys on the content hash. */
123
+ remote?: RemoteView;
124
+ }
118
125
  /**
119
126
  * A blocking drift item: either a field moved remotely or a remote-only
120
127
  * definition is not safe to delete. Apply must not converge over it — the
@@ -161,7 +168,7 @@ export interface Baseline {
161
168
  connectorVersions?: Record<string, string>;
162
169
  }
163
170
  export declare const ownedKey: (kind: string, id: number | string | undefined) => string;
164
- export type DiffRow = AgentDiffRow | SettingsDiffRow | EntityTypeDiffRow | RelationshipTypeDiffRow | AutomationDiffRow | ConnectorDefinitionDiffRow | AuthProfileDiffRow | ConnectionDiffRow | FeedDiffRow | InferenceProviderDiffRow | BlockingDriftRow;
171
+ export type DiffRow = AgentDiffRow | SettingsDiffRow | EntityTypeDiffRow | RelationshipTypeDiffRow | AutomationDiffRow | ConnectorDefinitionDiffRow | AuthProfileDiffRow | ConnectionDiffRow | FeedDiffRow | InferenceProviderDiffRow | ViewDiffRow | BlockingDriftRow;
165
172
  export interface DiffPlan {
166
173
  rows: DiffRow[];
167
174
  /** Aggregate counters for the summary line. */
@@ -247,7 +254,6 @@ export interface EntityTypeFacets {
247
254
  backing: unknown;
248
255
  metrics: unknown;
249
256
  eventKinds: unknown;
250
- viewTemplate: unknown;
251
257
  schemaExtras: Record<string, unknown>;
252
258
  }
253
259
  /**
@@ -260,7 +266,7 @@ export interface EntityTypeFacets {
260
266
  * Single source for BOTH the recorded attribution baseline and the
261
267
  * "already in sync?" test that lets an existing org establish its first
262
268
  * baseline: a second, prune-blind projection is what made prune-managed
263
- * eventKinds/viewTemplate/backing look inherited and recorded a phantom noop.
269
+ * eventKinds/backing look inherited and recorded a phantom noop.
264
270
  */
265
271
  export declare const effectiveEntityTypeAfterApply: (d: DesiredEntityType, r: RemoteEntityType | undefined, prune: boolean) => EntityTypeFacets;
266
272
  export interface RelationshipTypeFacets {
@@ -317,12 +323,14 @@ export interface RemoteSnapshot {
317
323
  feedsByConnectionId: Map<number, RemoteFeed[]>;
318
324
  /** Org-owned inference providers (from `GET /inference-providers`). */
319
325
  inferenceProviders: RemoteInferenceProvider[];
326
+ /** Applied views (`manage_views list`). Full-apply only. */
327
+ views: RemoteView[];
320
328
  }
321
329
  /**
322
330
  * The subset of {@link DesiredState} the diff consumes — everything except the
323
331
  * apply-only knobs (prune flag, org metadata, requiredSecrets).
324
332
  */
325
- type DesiredStateForDiff = Pick<DesiredState, "agents" | "memorySchema" | "automations" | "connectors" | "providers">;
333
+ type DesiredStateForDiff = Pick<DesiredState, "agents" | "memorySchema" | "automations" | "connectors" | "providers" | "views">;
326
334
  interface ComputeDiffOptions {
327
335
  /** Limit the diff to a subset of resource kinds. */
328
336
  only?: "agents" | "memory";
@@ -312,7 +312,7 @@ function diffEntityType(desired, remote, prune) {
312
312
  changed: (d, r) => !deepEqual(d.metrics, r.metrics),
313
313
  },
314
314
  {
315
- // event_kinds — prune-aware, like viewTemplate. event_kinds can be
315
+ // event_kinds — prune-aware. event_kinds can be
316
316
  // authored out-of-band via manage_entity_schema (a connector feed, the
317
317
  // UI, an agent), so a config that simply doesn't declare them must NOT
318
318
  // wipe them. Declared: diff and set on change. Omitted + prune: a
@@ -349,16 +349,6 @@ function diffEntityType(desired, remote, prune) {
349
349
  ? d.rulesSource.sourceCode !== (r.rulesSource ?? undefined)
350
350
  : prune && r.rulesSource != null,
351
351
  },
352
- {
353
- // View template — prune-aware. Declared: diff against the remote current
354
- // default (apply sets on change). Omitted + prune: a present remote
355
- // template is a removal (apply clears it). Omitted + no prune: unmanaged
356
- // (never churns), so a UI-authored template is left alone.
357
- name: "viewTemplate",
358
- changed: (d, r) => d.viewTemplate !== undefined
359
- ? !deepEqual(d.viewTemplate, r.viewTemplate)
360
- : prune && r.viewTemplate !== undefined,
361
- },
362
352
  ],
363
353
  });
364
354
  }
@@ -457,12 +447,6 @@ function compareEntityTypeThreeWay(desired, remote, attribution, prune) {
457
447
  remote: remote.eventKinds,
458
448
  attribution: attribution?.eventKinds,
459
449
  },
460
- {
461
- field: "viewTemplate",
462
- desired: desired.viewTemplate,
463
- remote: remote.viewTemplate,
464
- attribution: attribution?.viewTemplate,
465
- },
466
450
  {
467
451
  field: "resolutionPolicy",
468
452
  desired: desired.resolutionPolicy?.["x-lobu-resolution"],
@@ -490,7 +474,7 @@ function compareEntityTypeThreeWay(desired, remote, attribution, prune) {
490
474
  });
491
475
  }
492
476
  // Facets the config omits are UNMANAGED outside prune (the server keeps them
493
- // — eventKinds/viewTemplate/properties round-trip untouched). Only under
477
+ // — eventKinds/properties round-trip untouched). Only under
494
478
  // prune does omission mean "remove". Without this, an unchanged omitted facet
495
479
  // would be misclassified as config-moved and executePlan would clear it.
496
480
  // name/description are unmanaged under BOTH prune and non-prune: upsert
@@ -502,7 +486,6 @@ function compareEntityTypeThreeWay(desired, remote, attribution, prune) {
502
486
  "backing",
503
487
  "metrics",
504
488
  "eventKinds",
505
- "viewTemplate",
506
489
  "resolutionPolicy",
507
490
  "rules",
508
491
  ]);
@@ -564,7 +547,7 @@ function diffEntityTypeWithBaseline(desired, remote, baseline, prune) {
564
547
  // the remote. A definition the apply leaves untouched is a noop, so an
565
548
  // existing org can establish its first baseline without blocking. The test
566
549
  // is prune-aware because the projection is: under prune an omitted
567
- // eventKinds/viewTemplate/backing is a removal, so it does not compare
550
+ // eventKinds/backing is a removal, so it does not compare
568
551
  // equal and the ambiguity blocks instead of recording a phantom baseline.
569
552
  const inSync = deepEqual(effectiveEntityTypeAfterApply(desired, remote, prune), remoteEntityTypeFacets(remote));
570
553
  if (inSync) {
@@ -722,7 +705,6 @@ const normalizeEntityFacets = (e) => ({
722
705
  backing: e.backing,
723
706
  metrics: e.metrics,
724
707
  eventKinds: e.eventKinds,
725
- viewTemplate: e.viewTemplate,
726
708
  schemaExtras: e.schemaExtras ?? {},
727
709
  });
728
710
  /** The live remote entity type, in the comparable facet shape. */
@@ -737,7 +719,7 @@ const remoteEntityTypeFacets = (r) => normalizeEntityFacets(r);
737
719
  * Single source for BOTH the recorded attribution baseline and the
738
720
  * "already in sync?" test that lets an existing org establish its first
739
721
  * baseline: a second, prune-blind projection is what made prune-managed
740
- * eventKinds/viewTemplate/backing look inherited and recorded a phantom noop.
722
+ * eventKinds/backing look inherited and recorded a phantom noop.
741
723
  */
742
724
  export const effectiveEntityTypeAfterApply = (d, r, prune) => {
743
725
  // Outside prune, extras authored out-of-band survive; under prune the apply
@@ -773,7 +755,6 @@ export const effectiveEntityTypeAfterApply = (d, r, prune) => {
773
755
  backing: inherit(d.backing, r?.backing),
774
756
  metrics: inherit(d.metrics, r?.metrics),
775
757
  eventKinds: inherit(d.eventKinds, r?.eventKinds),
776
- viewTemplate: inherit(d.viewTemplate, r?.viewTemplate),
777
758
  schemaExtras,
778
759
  });
779
760
  };
@@ -1613,6 +1594,44 @@ export function computeDiff(desired, remote, opts = {}) {
1613
1594
  }
1614
1595
  }
1615
1596
  }
1597
+ // Views. Full-apply only (neither "agents" nor "memory"). Keyed on the
1598
+ // module's declared key; the change signal is the server's content hash
1599
+ // (source plus declared metadata plus the compiled artifact's digest,
1600
+ // computed at load with the same function the server hashes with — so a
1601
+ // diff noop means the server will no-write). Remote-only views are
1602
+ // config-owned only under prune; otherwise reported as drift.
1603
+ if (only === undefined) {
1604
+ // `?? []` mirrors the providers default above — test literals build a
1605
+ // partial DesiredStateForDiff.
1606
+ const desiredViews = desired.views ?? [];
1607
+ const remoteViews = remote.views ?? [];
1608
+ const remoteViewByKey = new Map(remoteViews.map((v) => [v.key, v]));
1609
+ const desiredViewKeys = new Set(desiredViews.map((v) => v.key));
1610
+ for (const view of desiredViews) {
1611
+ const r = remoteViewByKey.get(view.key);
1612
+ rows.push({
1613
+ kind: "view",
1614
+ id: view.key,
1615
+ desired: view,
1616
+ remote: r,
1617
+ verb: !r
1618
+ ? "create"
1619
+ : r.content_hash !== view.contentHash
1620
+ ? "update"
1621
+ : "noop",
1622
+ });
1623
+ }
1624
+ for (const r of remoteViews) {
1625
+ if (desiredViewKeys.has(r.key))
1626
+ continue;
1627
+ rows.push({
1628
+ kind: "view",
1629
+ id: r.key,
1630
+ remote: r,
1631
+ verb: prune ? "delete" : "drift",
1632
+ });
1633
+ }
1634
+ }
1616
1635
  const counts = { create: 0, update: 0, noop: 0, drift: 0, delete: 0 };
1617
1636
  for (const row of rows)
1618
1637
  counts[row.verb]++;
@@ -377,9 +377,6 @@ function mapEntityType(entity) {
377
377
  },
378
378
  }
379
379
  : {}),
380
- // View template included only when declared so absence never churns the diff
381
- // (a no-prune apply leaves any UI-authored template untouched).
382
- ...(entity.viewTemplate ? { viewTemplate: entity.viewTemplate } : {}),
383
380
  // metadata is carried for config-API compat (defineEntityType consumers may
384
381
  // attach it) but is neither diffed nor sent to the server.
385
382
  ...(entity.metadata ? { metadata: entity.metadata } : {}),
@@ -816,6 +813,8 @@ export function mapProjectToDesiredState(project, env = process.env, only) {
816
813
  memorySchema: { entityTypes, relationshipTypes },
817
814
  automations,
818
815
  connectors: { definitions: [], authProfiles, connections },
816
+ // View modules resolve in the loader (file IO): the mapper stays pure.
817
+ views: [],
819
818
  providers,
820
819
  requiredSecrets: [...required].sort(),
821
820
  };
@@ -13,6 +13,7 @@ const KIND_LABEL = {
13
13
  "relationship-type": "relationship-type",
14
14
  automation: "automation",
15
15
  "connector-definition": "connector-definition",
16
+ view: "view",
16
17
  "auth-profile": "auth-profile",
17
18
  connection: "connection",
18
19
  feed: "feed",
@@ -25,6 +26,7 @@ const KIND_HEADING = {
25
26
  "relationship-type": "relationship-types",
26
27
  automation: "automations",
27
28
  "connector-definition": "connector-definitions",
29
+ view: "views",
28
30
  "auth-profile": "auth-profiles",
29
31
  connection: "connections",
30
32
  feed: "feeds",
@@ -96,7 +96,7 @@ export function sanitizeSnapshotState(raw, remoteConnectionConfigs = new Map())
96
96
  export async function rollbackCommand(opts) {
97
97
  const cwd = opts.cwd ?? process.cwd();
98
98
  const newApplyId = mintApplyId();
99
- const { client, orgSlug } = await resolveApplyClient({
99
+ const { client, apiBaseUrl, orgSlug } = await resolveApplyClient({
100
100
  url: opts.url,
101
101
  org: opts.org,
102
102
  applyId: newApplyId,
@@ -207,7 +207,7 @@ export async function rollbackCommand(opts) {
207
207
  if (hasResourceWork) {
208
208
  printText(chalk.bold("\nApplying snapshot:"));
209
209
  const pendingAuth = [];
210
- await executePlan({ client, state: sanitized.state, plan, remote }, pendingAuth);
210
+ await executePlan({ client, state: sanitized.state, plan, remote, apiBaseUrl, orgSlug }, pendingAuth);
211
211
  }
212
212
  printText(chalk.green("\nRollback complete."));
213
213
  }
@@ -234,7 +234,7 @@ export async function rollbackCommand(opts) {
234
234
  let remoteForBaseline = remote;
235
235
  if (!rollbackErr) {
236
236
  try {
237
- remoteForBaseline = await fetchRemoteSnapshot(client, sanitized.state, undefined, false, orgId);
237
+ remoteForBaseline = await fetchRemoteSnapshot(client, sanitized.state, undefined, false);
238
238
  }
239
239
  catch {
240
240
  // Fall back to pre-rollback remote (over-blocks next prune, fail-closed).
@@ -1,3 +1,7 @@
1
1
  export declare function findBundledConnectorFile(key: string): string | null;
2
- export declare const compileConnectorForIsolateFromFile: (filePath: string) => Promise<string>;
2
+ export declare const compileConnectorArtifactFromFile: (filePath: string, projectRoot: string) => Promise<{
3
+ sourceFiles: import("@lobu/core/contracts/tools/source-files").SourceFiles;
4
+ dependencies: import("@lobu/core/contracts/tools/source-files").SourceDependencies;
5
+ compiledCode: string;
6
+ }>;
3
7
  //# sourceMappingURL=connector-loader.d.ts.map
@@ -37,5 +37,5 @@ export function findBundledConnectorFile(key) {
37
37
  // SDK as ESM for a forked Node child to resolve at runtime; that child is gone,
38
38
  // and a bundle shaped for it cannot load in an isolate at all.
39
39
  const compiler = createIsolateConnectorCompiler();
40
- export const compileConnectorForIsolateFromFile = compiler.compileConnectorForIsolateFromFile;
40
+ export const compileConnectorArtifactFromFile = compiler.compileConnectorArtifactFromFile;
41
41
  //# sourceMappingURL=connector-loader.js.map
@@ -1,29 +1,18 @@
1
- /**
2
- * Ensure a connector project's npm dependencies are installed before the CLI
3
- * compiles its connectors. esbuild bundles a connector's imports relative to
4
- * the connector file's directory, so the project's own `node_modules` (next to
5
- * `package.json`) must exist. We install when stale, preferring `bun` (faster,
6
- * if the user has it) and falling back to `npm` (always present with Node) so
7
- * the lobu CLI never forces a bun install on the user's machine.
8
- * `--ignore-scripts` keeps install-time supply-chain surface off the user's
9
- * machine — packages that need build scripts (native bindings) belong in
10
- * `runtime.nix.packages`, not bundled npm.
11
- */
12
- /**
13
- * Run the project's dependency install in `root` with the picked installer
14
- * (bun if available, else npm; `--ignore-scripts` always). Throws when the
15
- * install fails or the installer binary is missing — callers decide whether
16
- * that's fatal (`lobu apply` compile path) or a warning (`lobu init`).
17
- */
1
+ /** Owned by one apply or one running local stack, never a process-global cache. */
2
+ export type DependencySession = Map<string, string>;
3
+ type Mode = "create" | "frozen" | "read";
4
+ /** Read-only consumers must never install through desired-state loading. */
5
+ export declare function checkProjectDeps(cwd: string): void;
6
+ /** Hold the project lock through compilation so another Lobu install cannot race it. */
7
+ export declare function withProjectDependencies<T>(cwd: string, options: {
8
+ mode?: Mode;
9
+ session?: DependencySession;
10
+ log?: (message: string) => void;
11
+ stdio?: "inherit" | "pipe";
12
+ }, use: () => Promise<T>): Promise<T>;
13
+ /** Init alone may create/update the project's lockfile. */
18
14
  export declare function installProjectDeps(root: string, opts?: {
19
- /** "inherit" streams installer output to the terminal; "pipe" keeps it quiet. */
20
15
  stdio?: "inherit" | "pipe";
21
- }): {
22
- installer: string;
23
- };
24
- /**
25
- * Install the connector project's deps if missing/stale. No-op when the
26
- * connector has no `package.json` (no declared npm deps to bundle).
27
- */
28
- export declare function ensureProjectDepsInstalled(connectorFilePath: string, log: (message: string) => void): void;
16
+ }): Promise<void>;
17
+ export {};
29
18
  //# sourceMappingURL=ensure-deps-installed.d.ts.map