@lumerahq/cli 0.30.2 → 0.30.3-dev.1

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.
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  createApiClient,
6
6
  isApiErrorStatus
7
- } from "./chunk-U3ZLIXGD.js";
7
+ } from "./chunk-KZEOP5YF.js";
8
8
  import {
9
9
  findProjectRoot,
10
10
  getAppName
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  userContextHeaders
3
- } from "./chunk-U3ZLIXGD.js";
3
+ } from "./chunk-KZEOP5YF.js";
4
4
  import {
5
5
  fetchWithRetry
6
6
  } from "./chunk-FJFIWC7G.js";
@@ -282,6 +282,12 @@ var ApiClient = class {
282
282
  const result = await this.request(`/api/agents?${params}`);
283
283
  return result.agents || [];
284
284
  }
285
+ async compileAgentPolicy(script) {
286
+ await this.request("/api/agents/policy/compile", {
287
+ method: "POST",
288
+ body: JSON.stringify({ script })
289
+ });
290
+ }
285
291
  async createAgent(def) {
286
292
  return this.request("/api/agents", {
287
293
  method: "POST",
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  deps,
3
3
  syncDeps
4
- } from "./chunk-YMWDIAUG.js";
4
+ } from "./chunk-2K2LYH5O.js";
5
5
  import "./chunk-2CR762KB.js";
6
- import "./chunk-U3ZLIXGD.js";
6
+ import "./chunk-KZEOP5YF.js";
7
7
  import "./chunk-JLVVHTBY.js";
8
8
  import "./chunk-FJFIWC7G.js";
9
9
  import "./chunk-PNKVD2UK.js";
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  dev
3
- } from "./chunk-LVIIWE44.js";
3
+ } from "./chunk-ASPEK3I6.js";
4
4
  import {
5
5
  syncDeps
6
- } from "./chunk-YMWDIAUG.js";
6
+ } from "./chunk-2K2LYH5O.js";
7
7
  import {
8
8
  loadEnv
9
9
  } from "./chunk-2CR762KB.js";
10
10
  import {
11
11
  createApiClient
12
- } from "./chunk-U3ZLIXGD.js";
12
+ } from "./chunk-KZEOP5YF.js";
13
13
  import {
14
14
  findProjectRoot,
15
15
  getApiUrl,
package/dist/index.js CHANGED
@@ -240,32 +240,32 @@ async function main() {
240
240
  switch (command) {
241
241
  // Resource commands
242
242
  case "plan":
243
- await import("./resources-5YWEX6DG.js").then((m) => m.plan(args.slice(1)));
243
+ await import("./resources-OLDTUSKL.js").then((m) => m.plan(args.slice(1)));
244
244
  break;
245
245
  case "apply":
246
- await import("./resources-5YWEX6DG.js").then((m) => m.apply(args.slice(1)));
246
+ await import("./resources-OLDTUSKL.js").then((m) => m.apply(args.slice(1)));
247
247
  break;
248
248
  case "pull":
249
- await import("./resources-5YWEX6DG.js").then((m) => m.pull(args.slice(1)));
249
+ await import("./resources-OLDTUSKL.js").then((m) => m.pull(args.slice(1)));
250
250
  break;
251
251
  case "destroy":
252
- await import("./resources-5YWEX6DG.js").then((m) => m.destroy(args.slice(1)));
252
+ await import("./resources-OLDTUSKL.js").then((m) => m.destroy(args.slice(1)));
253
253
  break;
254
254
  case "list":
255
- await import("./resources-5YWEX6DG.js").then((m) => m.list(args.slice(1)));
255
+ await import("./resources-OLDTUSKL.js").then((m) => m.list(args.slice(1)));
256
256
  break;
257
257
  case "show":
258
- await import("./resources-5YWEX6DG.js").then((m) => m.show(args.slice(1)));
258
+ await import("./resources-OLDTUSKL.js").then((m) => m.show(args.slice(1)));
259
259
  break;
260
260
  case "diff":
261
- await import("./resources-5YWEX6DG.js").then((m) => m.diff(args.slice(1)));
261
+ await import("./resources-OLDTUSKL.js").then((m) => m.diff(args.slice(1)));
262
262
  break;
263
263
  // Development
264
264
  case "dev":
265
- await import("./dev-IWTA5G5M.js").then((m) => m.dev(args.slice(1)));
265
+ await import("./dev-XBOHUDPR.js").then((m) => m.dev(args.slice(1)));
266
266
  break;
267
267
  case "run":
268
- await import("./run-SLLDX3RF.js").then((m) => m.run(args.slice(1)));
268
+ await import("./run-EBTA3FKD.js").then((m) => m.run(args.slice(1)));
269
269
  break;
270
270
  case "functions":
271
271
  await import("./functions-55J6E2RF.js").then(
@@ -279,10 +279,10 @@ async function main() {
279
279
  break;
280
280
  // Project
281
281
  case "init":
282
- await import("./init-I4FECTEL.js").then((m) => m.init(args.slice(1)));
282
+ await import("./init-L6D5OHMY.js").then((m) => m.init(args.slice(1)));
283
283
  break;
284
284
  case "register":
285
- await import("./register-OBQZPOGC.js").then((m) => m.register(args.slice(1)));
285
+ await import("./register-SBXONOFY.js").then((m) => m.register(args.slice(1)));
286
286
  break;
287
287
  case "templates":
288
288
  await import("./templates-LNUOTNLN.js").then((m) => m.templates(subcommand, args.slice(2)));
@@ -299,7 +299,7 @@ async function main() {
299
299
  break;
300
300
  // Dependencies
301
301
  case "deps":
302
- await import("./deps-NHVL4DMD.js").then((m) => m.deps(args.slice(1)));
302
+ await import("./deps-22CUIP2M.js").then((m) => m.deps(args.slice(1)));
303
303
  break;
304
304
  // Feature flags (read the in-sandbox snapshot)
305
305
  case "flags":
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  createApiClient,
14
14
  validateProjectNameLength
15
- } from "./chunk-U3ZLIXGD.js";
15
+ } from "./chunk-KZEOP5YF.js";
16
16
  import {
17
17
  getToken,
18
18
  init_auth,
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  createApiClient,
9
9
  validateProjectExternalId
10
- } from "./chunk-U3ZLIXGD.js";
10
+ } from "./chunk-KZEOP5YF.js";
11
11
  import {
12
12
  findProjectRoot,
13
13
  getAppName,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  deploy
3
- } from "./chunk-LVIIWE44.js";
3
+ } from "./chunk-ASPEK3I6.js";
4
4
  import {
5
5
  syncDeps
6
- } from "./chunk-YMWDIAUG.js";
6
+ } from "./chunk-2K2LYH5O.js";
7
7
  import {
8
8
  loadEnv
9
9
  } from "./chunk-2CR762KB.js";
@@ -12,7 +12,7 @@ import {
12
12
  createApiClient,
13
13
  isApiErrorStatus,
14
14
  validateCollectionNameLength
15
- } from "./chunk-U3ZLIXGD.js";
15
+ } from "./chunk-KZEOP5YF.js";
16
16
  import {
17
17
  findProjectRoot,
18
18
  getApiUrl,
@@ -38,6 +38,57 @@ import { join as join2, resolve } from "path";
38
38
  import { existsSync, readFileSync, readdirSync } from "fs";
39
39
  import { basename, dirname, join } from "path";
40
40
 
41
+ // src/lib/lint/rules/agent-policy-compile.ts
42
+ function compileDiagnostic(value) {
43
+ if (!value || typeof value !== "object") return void 0;
44
+ const diagnostic = value;
45
+ if (typeof diagnostic.message !== "string") return void 0;
46
+ return {
47
+ message: diagnostic.message,
48
+ line: typeof diagnostic.line === "number" && diagnostic.line > 0 ? diagnostic.line : void 0,
49
+ column: typeof diagnostic.column === "number" && diagnostic.column > 0 ? diagnostic.column : void 0
50
+ };
51
+ }
52
+ function apiCompileDiagnostics(err) {
53
+ const detail = err.body.trim();
54
+ try {
55
+ const parsed = JSON.parse(detail);
56
+ if (parsed && typeof parsed === "object") {
57
+ const diagnostics = Array.isArray(parsed.errors) ? parsed.errors.map(compileDiagnostic).filter((item) => !!item) : [];
58
+ if (diagnostics.length > 0) return diagnostics;
59
+ const legacyDiagnostic = compileDiagnostic(parsed);
60
+ if (legacyDiagnostic) return [legacyDiagnostic];
61
+ }
62
+ } catch {
63
+ }
64
+ return [{ message: detail }];
65
+ }
66
+ function compileError(target, diagnostic) {
67
+ const position = diagnostic.line ? ` at compiler line ${diagnostic.line}${diagnostic.column ? `, column ${diagnostic.column}` : ""}` : "";
68
+ return {
69
+ ruleId: "agent-policy-compile",
70
+ target,
71
+ severity: "error",
72
+ message: `Agent policy failed to compile${position}: ${diagnostic.message}`
73
+ };
74
+ }
75
+ var agentPolicyCompileRule = {
76
+ id: "agent-policy-compile",
77
+ description: "Verifies agent policy scripts compile with the backend runtime compiler.",
78
+ appliesTo: ["agent-policy"],
79
+ async check(target, ctx) {
80
+ if (!target.source.trim() || !ctx.api) return [];
81
+ const script = ctx.appName ? target.source.replaceAll("{{app}}", ctx.appName) : target.source;
82
+ try {
83
+ await ctx.api.compileAgentPolicy(script);
84
+ } catch (err) {
85
+ const diagnostics = err instanceof ApiError ? apiCompileDiagnostics(err) : [{ message: err instanceof Error ? err.message : String(err) }];
86
+ return diagnostics.map((diagnostic) => compileError(target, diagnostic));
87
+ }
88
+ return [];
89
+ }
90
+ };
91
+
41
92
  // src/lib/lint/rules/automation-config.ts
42
93
  function isRecord(value) {
43
94
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -776,6 +827,7 @@ var llmImportRule = {
776
827
 
777
828
  // src/lib/lint/registry.ts
778
829
  var ALL_RULES = [
830
+ agentPolicyCompileRule,
779
831
  automationConfigRule,
780
832
  automationMainGuardRule,
781
833
  collectionSchemaRule,
@@ -889,6 +941,42 @@ function buildHookTargets(platformDir, filterName) {
889
941
  }
890
942
  return targets;
891
943
  }
944
+ function buildAgentPolicyTargets(platformDir, filterName, appName) {
945
+ const agentsDir = join(platformDir, "agents");
946
+ if (!existsSync(agentsDir)) return [];
947
+ const targets = [];
948
+ for (const entry of readdirSync(agentsDir, { withFileTypes: true })) {
949
+ if (!entry.isDirectory()) continue;
950
+ const agentDir = join(agentsDir, entry.name);
951
+ const policyPath = join(agentDir, "policy.js");
952
+ if (!existsSync(policyPath)) continue;
953
+ let externalID = appName ? `${appName}:${entry.name}` : "";
954
+ let displayName = "";
955
+ const configPath = join(agentDir, "config.json");
956
+ if (existsSync(configPath)) {
957
+ try {
958
+ const config = JSON.parse(readFileSync(configPath, "utf-8"));
959
+ if (typeof config.external_id === "string" && config.external_id.trim()) {
960
+ externalID = config.external_id;
961
+ }
962
+ if (typeof config.name === "string") {
963
+ displayName = config.name;
964
+ }
965
+ } catch {
966
+ }
967
+ }
968
+ if (filterName && entry.name !== filterName && externalID !== filterName && displayName !== filterName) {
969
+ continue;
970
+ }
971
+ targets.push({
972
+ kind: "agent-policy",
973
+ name: externalID || displayName || entry.name,
974
+ filePath: policyPath,
975
+ source: readFileSync(policyPath, "utf-8")
976
+ });
977
+ }
978
+ return targets;
979
+ }
892
980
 
893
981
  // src/commands/resources.ts
894
982
  init_auth();
@@ -940,6 +1028,18 @@ async function lintHookFiles(api, projectRoot, platformDir, appName, filterName)
940
1028
  throw new Error(`Found ${result.errors.length} hook lint error(s)`);
941
1029
  }
942
1030
  }
1031
+ async function lintAgentPolicyFiles(api, projectRoot, platformDir, appName, filterName) {
1032
+ const result = await safeLintPass("agent policy", async () => {
1033
+ const targets = buildAgentPolicyTargets(platformDir, filterName, appName);
1034
+ if (targets.length === 0) return [];
1035
+ return runLint({ projectRoot, targets, api, appName });
1036
+ });
1037
+ if (!result || result.issues.length === 0) return;
1038
+ safePrintLint(result.issues, projectRoot);
1039
+ if (result.errors.length > 0) {
1040
+ throw new Error(`Found ${result.errors.length} agent policy lint error(s)`);
1041
+ }
1042
+ }
943
1043
  var PACKAGE_MANAGERS = ["bun", "pnpm", "yarn", "npm"];
944
1044
  var PACKAGE_MANAGER_VALUE_FLAGS = /* @__PURE__ */ new Set(["--package-manager"]);
945
1045
  function isPackageManager(value) {
@@ -2177,6 +2277,8 @@ async function applyAutomations(api, localAutomations, projectId) {
2177
2277
  const remoteByExternalId = new Map(remoteAutomations.filter((a) => a.external_id).map((a) => [a.external_id, a]));
2178
2278
  for (const { automation, code } of localAutomations) {
2179
2279
  const remote = remoteByExternalId.get(automation.external_id);
2280
+ const appliedAction = remote ? "updated" : "created";
2281
+ let baseApplied = false;
2180
2282
  const payload = {
2181
2283
  external_id: automation.external_id,
2182
2284
  name: automation.name,
@@ -2194,35 +2296,35 @@ async function applyAutomations(api, localAutomations, projectId) {
2194
2296
  if (remote) {
2195
2297
  await api.updateAutomation(remote.id, payload);
2196
2298
  automationId = remote.id;
2197
- console.log(pc2.green(" \u2713"), `${automation.name} (updated)`);
2198
2299
  } else {
2199
2300
  const created = await api.createAutomation(payload);
2200
2301
  automationId = created.id;
2201
- console.log(pc2.green(" \u2713"), `${automation.name} (created)`);
2202
2302
  }
2303
+ baseApplied = true;
2203
2304
  const localPresets = automation.inputs?.presets;
2305
+ let current;
2204
2306
  if (localPresets) {
2205
2307
  await syncPresets(api, automationId, localPresets);
2206
2308
  }
2207
2309
  if (automation.schedule) {
2208
- await setSchedule(api, automationId, automation.schedule, localPresets || {});
2310
+ current = await setSchedule(api, automationId, automation.schedule, localPresets || {});
2209
2311
  } else if (remote?.schedule) {
2210
2312
  await api.updateAutomation(automationId, { schedule: "", schedule_tz: "" });
2211
2313
  console.log(pc2.dim(` Cleared schedule`));
2212
2314
  }
2213
2315
  if (localPresets) {
2214
- const current = await api.getAutomation(automationId).catch(() => null);
2215
- if (current) {
2216
- await deleteStalePresets(
2217
- api,
2218
- automationId,
2219
- localPresets,
2220
- current.schedule_preset_id ? /* @__PURE__ */ new Set([current.schedule_preset_id]) : /* @__PURE__ */ new Set()
2221
- );
2222
- }
2316
+ current ??= await api.getAutomation(automationId);
2317
+ await deleteStalePresets(
2318
+ api,
2319
+ automationId,
2320
+ localPresets,
2321
+ current.schedule_preset_id ? /* @__PURE__ */ new Set([current.schedule_preset_id]) : /* @__PURE__ */ new Set()
2322
+ );
2223
2323
  }
2324
+ console.log(pc2.green(" \u2713"), `${automation.name} (${appliedAction})`);
2224
2325
  } catch (e) {
2225
- console.log(pc2.red(" \u2717"), `${automation.name}: ${e}`);
2326
+ const partialState = baseApplied ? ` (${appliedAction}, configuration failed)` : "";
2327
+ console.log(pc2.red(" \u2717"), `${automation.name}${partialState}: ${e}`);
2226
2328
  errors++;
2227
2329
  }
2228
2330
  }
@@ -2234,16 +2336,20 @@ async function syncPresets(api, automationId, localPresets) {
2234
2336
  for (const [presetKey, preset] of Object.entries(localPresets)) {
2235
2337
  const presetName = preset.label || presetKey;
2236
2338
  const existing = remoteByName.get(presetName);
2237
- try {
2238
- if (existing) {
2339
+ if (existing) {
2340
+ try {
2239
2341
  await api.updatePreset(existing.id, { name: presetName, inputs: preset.inputs });
2240
2342
  console.log(pc2.dim(` Updated preset: ${presetName}`));
2241
- } else {
2343
+ } catch (e) {
2344
+ throw new Error(`Failed to update preset '${presetName}': ${String(e)}`);
2345
+ }
2346
+ } else {
2347
+ try {
2242
2348
  await api.createPreset(automationId, { name: presetName, inputs: preset.inputs });
2243
2349
  console.log(pc2.dim(` Created preset: ${presetName}`));
2350
+ } catch (e) {
2351
+ throw new Error(`Failed to create preset '${presetName}': ${String(e)}`);
2244
2352
  }
2245
- } catch (e) {
2246
- console.log(pc2.yellow(` \u26A0 Failed to sync preset ${presetName}: ${e}`));
2247
2353
  }
2248
2354
  }
2249
2355
  }
@@ -2260,7 +2366,7 @@ async function deleteStalePresets(api, automationId, localPresets, preservePrese
2260
2366
  await api.deletePreset(remote.id);
2261
2367
  console.log(pc2.dim(` Deleted preset: ${remote.name}`));
2262
2368
  } catch (e) {
2263
- console.log(pc2.yellow(` \u26A0 Failed to delete preset ${remote.name}: ${e}`));
2369
+ throw new Error(`Failed to delete preset '${remote.name}': ${String(e)}`);
2264
2370
  }
2265
2371
  }
2266
2372
  }
@@ -2269,19 +2375,28 @@ async function setSchedule(api, automationId, schedule, localPresets) {
2269
2375
  const remotePresets = await api.listPresets(automationId);
2270
2376
  const preset = remotePresets.find((p) => p.name === presetName);
2271
2377
  if (!preset) {
2272
- console.log(pc2.yellow(` \u26A0 Schedule preset '${schedule.preset}' not found, skipping schedule`));
2273
- return;
2378
+ throw new Error(`Schedule preset '${presetName}' not found`);
2274
2379
  }
2380
+ const expectedSchedule = {
2381
+ schedule: schedule.cron,
2382
+ schedule_tz: schedule.timezone || "UTC",
2383
+ schedule_preset_id: preset.id
2384
+ };
2385
+ await api.updateAutomation(automationId, expectedSchedule);
2386
+ let persisted;
2275
2387
  try {
2276
- await api.updateAutomation(automationId, {
2277
- schedule: schedule.cron,
2278
- schedule_tz: schedule.timezone || "UTC",
2279
- schedule_preset_id: preset.id
2280
- });
2281
- console.log(pc2.dim(` Set schedule: ${schedule.cron}`));
2388
+ persisted = await api.getAutomation(automationId);
2282
2389
  } catch (e) {
2283
- console.log(pc2.yellow(` \u26A0 Failed to set schedule: ${e}`));
2390
+ throw new Error(`Failed to verify persisted schedule: ${String(e)}`);
2391
+ }
2392
+ const mismatches = Object.keys(expectedSchedule).filter((field) => persisted[field] !== expectedSchedule[field]).map(
2393
+ (field) => `${field} expected ${JSON.stringify(expectedSchedule[field])}, got ${JSON.stringify(persisted[field])}`
2394
+ );
2395
+ if (mismatches.length > 0) {
2396
+ throw new Error(`Schedule update was not persisted: ${mismatches.join("; ")}`);
2284
2397
  }
2398
+ console.log(pc2.dim(` Set schedule: ${schedule.cron}`));
2399
+ return persisted;
2285
2400
  }
2286
2401
  async function applyHooks(api, localHooks, collections, projectId) {
2287
2402
  let errors = 0;
@@ -3733,6 +3848,9 @@ async function plan(args) {
3733
3848
  if (!type || type === "hooks") {
3734
3849
  await lintHookFiles(api, projectRoot, platformDir, appName, name || void 0);
3735
3850
  }
3851
+ if (!type || type === "agents") {
3852
+ await lintAgentPolicyFiles(api, projectRoot, platformDir, appName, name || void 0);
3853
+ }
3736
3854
  await syncDeps(projectRoot, { ignorePermissionDenied: true });
3737
3855
  const allChanges = [];
3738
3856
  let planValidationErrors = 0;
@@ -3900,6 +4018,9 @@ async function apply(args) {
3900
4018
  if (!type || type === "hooks") {
3901
4019
  await lintHookFiles(api, projectRoot, platformDir, appName, name || void 0);
3902
4020
  }
4021
+ if (!type || type === "agents") {
4022
+ await lintAgentPolicyFiles(api, projectRoot, platformDir, appName, name || void 0);
4023
+ }
3903
4024
  await syncDeps(projectRoot, { ignorePermissionDenied: true });
3904
4025
  let collections;
3905
4026
  try {
@@ -4519,6 +4640,7 @@ async function diff(args) {
4519
4640
  export {
4520
4641
  apply,
4521
4642
  applyAgents,
4643
+ applyAutomations,
4522
4644
  applyCollections,
4523
4645
  applySkills,
4524
4646
  convertCollectionToApiFormat,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-2CR762KB.js";
4
4
  import {
5
5
  createApiClient
6
- } from "./chunk-U3ZLIXGD.js";
6
+ } from "./chunk-KZEOP5YF.js";
7
7
  import {
8
8
  findProjectRoot,
9
9
  getApiUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumerahq/cli",
3
- "version": "0.30.2",
3
+ "version": "0.30.3-dev.1",
4
4
  "description": "CLI for building and deploying Lumera apps",
5
5
  "type": "module",
6
6
  "engines": {