@engini/cli 0.28.0 → 0.30.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 (3) hide show
  1. package/README.md +22 -1
  2. package/dist/cli.js +421 -8
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -29,7 +29,7 @@ engini tools result <handle> --select items.email # drill into a large result
29
29
  ## Commands
30
30
 
31
31
  ```
32
- engini login | logout | whoami # auth
32
+ engini login | logout | whoami # auth (whoami also prints an API key's workspace/environment)
33
33
  engini tools list | get | call | result # discover, execute & drill into results
34
34
  engini applications list | get # browse connector apps
35
35
  engini toolsets list | get | create | update | delete # scope an agent's tools/connections/workflows
@@ -45,6 +45,27 @@ engini triggers list | get | create | enable | disable | delete # trigger inst
45
45
  engini triggers events | events get | events replay # the event LOG (real delivery state)
46
46
  engini triggers listen # the live event STREAM (local dev only)
47
47
  engini triggers destinations set | add | list | show | enable | rm | rotate-secret
48
+ engini executions list | get | log | data # read-only run history (no rerun)
49
+ engini workflows search | schema | options | tables | columns | connections # builder lookups
50
+ engini workflows compile | plan | create | update # dry-run a plan; create (turned off) / update from it
51
+ ```
52
+
53
+ `executions list` prints one page as `{ items, next_cursor, total_count }` (keys snake_case);
54
+ `--cursor <next_cursor>` reads the next page and `--all` drains everything. `executions data`
55
+ drains every page of a step's recorded payloads unless `--top` is given (`--offset` needs `--top`).
56
+ Note the difference from `triggers list`: that prints a bare JSON array, while `executions list`
57
+ prints one page as an object (use `--all` to drain, still as the object).
58
+
59
+ The `workflows` group prints the API's own camelCase JSON so `plan <id> > plan.json` feeds
60
+ `update --file plan.json`. `compile`, `create` and `update` read the plan from `--file <path>`
61
+ or stdin; `update` takes `--expected-revision-id` to refuse a stale save. Writes need a
62
+ workspace-scoped API key. A refused plan prints its `code`, message, `fix` and a diagnostics
63
+ table on stderr (a JSON object when piped) and exits 3 (401/403, e.g. `API_KEY_REQUIRED`), 4 (not found) or 5 (400/409/422):
64
+
65
+ ```bash
66
+ engini workflows compile --file plan.json # dry run: hasErrors + diagnostics
67
+ engini workflows create --file plan.json --folder-id 7
68
+ engini workflows plan 1234 > plan.json && engini workflows update 1234 --file plan.json --expected-revision-id 3
48
69
  ```
49
70
 
50
71
  The `mcp` group maintains the MCP endpoints Engini **exposes** (not the
package/dist/cli.js CHANGED
@@ -285,10 +285,13 @@ function printOutput(obj) {
285
285
  function progress(message) {
286
286
  if (isTty() && !context.quiet) console.error(message);
287
287
  }
288
- function fail(code, message, hint2) {
288
+ function fail(code, message, hint2, extra) {
289
289
  if (isTty()) {
290
290
  console.error(`Error: ${message}`);
291
291
  if (hint2) console.error(`Hint: ${hint2}`);
292
+ if (extra?.diagnostics?.length) {
293
+ for (const line of diagnosticTable(extra.diagnostics)) console.error(line);
294
+ }
292
295
  } else {
293
296
  const payload = {
294
297
  error: ERROR_NAMES[code] ?? "Error",
@@ -296,10 +299,21 @@ function fail(code, message, hint2) {
296
299
  exit_code: code
297
300
  };
298
301
  if (hint2) payload.hint = hint2;
302
+ if (extra?.code !== void 0) payload.code = extra.code;
303
+ if (extra?.path) payload.path = extra.path;
304
+ if (extra?.currentRevisionId != null) payload.current_revision_id = extra.currentRevisionId;
305
+ if (extra?.diagnostics?.length) payload.diagnostics = extra.diagnostics;
299
306
  console.error(JSON.stringify(payload));
300
307
  }
301
308
  throw new CliError(code);
302
309
  }
310
+ function diagnosticTable(rows) {
311
+ const header = ["SEVERITY", "CODE", "STEP", "FIELD", "MESSAGE"];
312
+ const body = rows.map((d) => [d.severity, d.code, d.stepKey ?? "-", d.field ?? "-", d.message]);
313
+ const widths = header.map((h, i) => Math.max(h.length, ...body.map((r) => r[i].length)));
314
+ const line = (cells) => cells.map((c, i) => i === cells.length - 1 ? c : c.padEnd(widths[i])).join(" ");
315
+ return [line(header), ...body.map(line)];
316
+ }
303
317
  function mapCommanderExitCode(exitCode) {
304
318
  const code = exitCode ?? 1;
305
319
  return code === 0 ? 0 /* OK */ : 2 /* USAGE */;
@@ -390,6 +404,7 @@ import {
390
404
  ENV_COMPANY_TOKEN_VAR,
391
405
  ENV_TOKEN_VAR,
392
406
  EnginiAuthError,
407
+ EnginiBuilderError,
393
408
  EnginiConflictError,
394
409
  EnginiError,
395
410
  EnginiMcpServerNotFoundError,
@@ -450,7 +465,7 @@ function saveConfig(config, path = configPath()) {
450
465
  }
451
466
 
452
467
  // src/version.ts
453
- var VERSION = true ? "0.28.0" : "0.0.0";
468
+ var VERSION = true ? "0.30.0" : "0.0.0";
454
469
 
455
470
  // src/http.ts
456
471
  var USER_AGENT_PREFIX = `engini-cli/${VERSION}`;
@@ -480,6 +495,14 @@ var AUTH_PROVIDER_CONFLICT_CODES = /* @__PURE__ */ new Set([
480
495
  ]);
481
496
  function exitForError(err) {
482
497
  if (err instanceof EnginiAuthError) return 3 /* AUTH */;
498
+ if (err instanceof EnginiBuilderError) {
499
+ if (err.status === 401 || err.status === 403) return 3 /* AUTH */;
500
+ if (err.status === 404) return 4 /* NOT_FOUND */;
501
+ if (err.status !== void 0 && err.status >= 400 && err.status < 500 && err.status !== 429) {
502
+ return 5 /* VALIDATION */;
503
+ }
504
+ return 1 /* GENERIC */;
505
+ }
483
506
  if (err instanceof EnginiOpaApplicationAmbiguousError) return 5 /* VALIDATION */;
484
507
  if (err instanceof EnginiOpaAgentTimeoutError) return 124 /* TIMEOUT */;
485
508
  if (err instanceof EnginiConflictError && err.errorCode !== void 0 && AUTH_PROVIDER_CONFLICT_CODES.has(err.errorCode)) {
@@ -497,6 +520,14 @@ async function apiErrors(fn) {
497
520
  try {
498
521
  return await fn();
499
522
  } catch (err) {
523
+ if (err instanceof EnginiBuilderError) {
524
+ fail(exitForError(err), err.message, err.fix ?? void 0, {
525
+ code: err.code,
526
+ path: err.path,
527
+ currentRevisionId: err.currentRevisionId,
528
+ diagnostics: err.diagnostics
529
+ });
530
+ }
500
531
  if (err instanceof EnginiError) {
501
532
  fail(exitForError(err), err.message);
502
533
  }
@@ -2169,7 +2200,8 @@ ACCOUNT
2169
2200
  The key must start with "eng_"; a malformed or empty one exits 2 and
2170
2201
  stores nothing. Interactive entry needs a terminal on stdin AND stdout.
2171
2202
  logout Clear the stored credentials.
2172
- whoami Show the authenticated user/company.
2203
+ whoami Show the authenticated user/company, and the workspace + environment an
2204
+ API key is scoped to (both null for a login token or an unscoped key).
2173
2205
 
2174
2206
  CONNECTIONS
2175
2207
  connect [<app>] [--provider <name|id|none>]
@@ -2306,6 +2338,35 @@ TRIGGERS
2306
2338
  triggers destinations rotate-secret <name> [--force]
2307
2339
  Note: add/rotate-secret/set(create) print the signing secret in the clear, once.
2308
2340
 
2341
+ EXECUTIONS
2342
+ Read-only run history of workflows, table automations and business rules (no rerun).
2343
+ executions list [--workflow <id>] [--type <t>] [--trigger-type <t>] [--status <s>...]
2344
+ [--context <text>] [--created-by <id>] [--created-after|--created-before <iso>]
2345
+ [--closed-after|--closed-before <iso>] [--sort <spec>] [--cursor <c>] [--top <n>] [--all]
2346
+ One page -> { items, next_cursor, total_count }; --all drains.
2347
+ executions get <execution_id> Status, timing, activities run, who started it.
2348
+ executions log <execution_id> Per-step log (step_no, status, runs_count, duration, loop).
2349
+ executions data <execution_id> <step_no> [--type <kind>] [--loop-path <s:i>...] [--run-number <n>]
2350
+ [--retry-no <n>] [--status <s>] [--top <n>] [--offset <n>]
2351
+ Recorded step payloads; drains every page unless --top.
2352
+ Note: step detail is deleted after the workflow's history retention window (410).
2353
+
2354
+ WORKFLOW BUILDER
2355
+ Build a workflow from a plan (JSON). Output is the API's own camelCase JSON, so
2356
+ 'plan <id> > p.json' feeds 'update'. Writes need a workspace-scoped API key; workflows
2357
+ are always created turned off. A refused plan prints code, message, fix and a
2358
+ diagnostics table on stderr and exits non-zero (404 -> 4; 400/409/422 -> 5).
2359
+ workflows search [query] [--kind <k>] [--app <slug>] [--table <id>] [--top <n>]
2360
+ workflows schema <slug> [--connection <id>] [--kind <k>] [--table <id>]
2361
+ workflows options <slug> [--field <f>] [--connection <id>] [--depends-on <field=value>...]
2362
+ workflows tables | workflows columns <table_id> [--trigger <slug>]
2363
+ workflows connections [--app <slug>]
2364
+ workflows compile [--file <path>|stdin] [--base-workflow-id <id>] Dry run; nothing written.
2365
+ workflows plan <workflow_id> A saved workflow read back as a plan.
2366
+ workflows create [--file <path>|stdin] [--folder-id <id>] Created turned off.
2367
+ workflows update <workflow_id> [--file <path>|stdin] [--expected-revision-id <n>]
2368
+ Note: compile returns a plan with errors (hasErrors: true); create/update refuse it.
2369
+
2309
2370
  OUTPUT & EXIT CODES
2310
2371
  Output adapts to context: human-readable on a TTY, compact JSON when piped, pretty
2311
2372
  JSON with --json. Universal flags on every command:
@@ -5093,14 +5154,360 @@ function registerTriggers(program) {
5093
5154
  registerTriggerDestinations(triggers);
5094
5155
  }
5095
5156
 
5157
+ // src/shared/input.ts
5158
+ import { readFileSync as readFileSync5 } from "fs";
5159
+ function parseInt1(raw, what) {
5160
+ if (raw === void 0 || raw === "") fail(2 /* USAGE */, `${what} is required.`);
5161
+ if (!/^\d+$/.test(raw) || Number(raw) < 1) {
5162
+ fail(2 /* USAGE */, `'${raw}' is not a valid ${what} (expected a positive integer).`);
5163
+ }
5164
+ return Number(raw);
5165
+ }
5166
+ function parseCount(raw, flag) {
5167
+ if (raw === void 0) return void 0;
5168
+ if (!/^\d+$/.test(raw)) fail(2 /* USAGE */, `${flag} must be a non-negative integer, got '${raw}'.`);
5169
+ return Number(raw);
5170
+ }
5171
+ function parseOptId(raw, flag) {
5172
+ return raw === void 0 ? void 0 : parseInt1(raw, flag);
5173
+ }
5174
+ function collect4(value, previous = []) {
5175
+ return [...previous, value];
5176
+ }
5177
+ function readJsonObject(file, what) {
5178
+ let text;
5179
+ if (file === void 0 && process.stdin.isTTY) {
5180
+ fail(2 /* USAGE */, `Pass the ${what} with --file <path>, or pipe it on stdin.`);
5181
+ }
5182
+ try {
5183
+ text = readFileSync5(file === void 0 || file === "-" ? 0 : file, "utf8");
5184
+ } catch (err) {
5185
+ return fail(
5186
+ 2 /* USAGE */,
5187
+ file === void 0 || file === "-" ? `Cannot read the ${what} from stdin: ${err.message}` : `Cannot read ${file}: ${err.message}`
5188
+ );
5189
+ }
5190
+ let data;
5191
+ try {
5192
+ data = JSON.parse(text);
5193
+ } catch (err) {
5194
+ return fail(2 /* USAGE */, `The ${what} is not valid JSON: ${err.message}`);
5195
+ }
5196
+ if (data === null || typeof data !== "object" || Array.isArray(data)) {
5197
+ return fail(2 /* USAGE */, `The ${what} must be a JSON object.`);
5198
+ }
5199
+ return data;
5200
+ }
5201
+ var snake = (key) => key.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
5202
+ function snakeKeys(value, keep = []) {
5203
+ if (Array.isArray(value)) return value.map((v) => snakeKeys(v, keep));
5204
+ if (value === null || typeof value !== "object") return value;
5205
+ const out = {};
5206
+ for (const [k, v] of Object.entries(value)) {
5207
+ out[snake(k)] = keep.includes(k) ? v : snakeKeys(v, keep);
5208
+ }
5209
+ return out;
5210
+ }
5211
+
5212
+ // src/executions/index.ts
5213
+ async function listBody14(opts) {
5214
+ const top = parseCount(opts.top, "--top");
5215
+ const offset = parseCount(opts.offset, "--offset");
5216
+ if (opts.all && (top !== void 0 || opts.cursor !== void 0 || offset !== void 0)) {
5217
+ fail(2 /* USAGE */, "--all drains every page; it cannot be combined with --top, --cursor or --offset.");
5218
+ }
5219
+ if (opts.cursor !== void 0 && offset !== void 0) {
5220
+ fail(2 /* USAGE */, "--cursor and --offset are alternatives; the server ignores --offset with a cursor.");
5221
+ }
5222
+ const filters = {
5223
+ workflowId: parseOptId(opts.workflow, "--workflow"),
5224
+ type: opts.type,
5225
+ triggerType: opts.triggerType,
5226
+ status: opts.status,
5227
+ context: opts.context,
5228
+ createdBy: parseOptId(opts.createdBy, "--created-by"),
5229
+ createdAfter: opts.createdAfter,
5230
+ createdBefore: opts.createdBefore,
5231
+ closedAfter: opts.closedAfter,
5232
+ closedBefore: opts.closedBefore,
5233
+ sort: opts.sort
5234
+ };
5235
+ const client = buildClient();
5236
+ if (opts.all) {
5237
+ const items = await apiErrors(async () => client.executions.list(filters));
5238
+ printOutput({ items: snakeKeys(items), next_cursor: null, total_count: items.length });
5239
+ return;
5240
+ }
5241
+ const page = await apiErrors(
5242
+ async () => client.executions.listPage({ ...filters, top, cursor: opts.cursor, offset })
5243
+ );
5244
+ printOutput({
5245
+ items: snakeKeys(page.items ?? []),
5246
+ next_cursor: page.nextCursor ?? null,
5247
+ total_count: page.totalCount ?? null
5248
+ });
5249
+ }
5250
+ async function getBody12(rawId) {
5251
+ const id = parseInt1(rawId, "execution id");
5252
+ printOutput(snakeKeys(await apiErrors(async () => buildClient().executions.get(id))));
5253
+ }
5254
+ async function logBody(rawId) {
5255
+ const id = parseInt1(rawId, "execution id");
5256
+ printOutput(snakeKeys(await apiErrors(async () => buildClient().executions.log(id))));
5257
+ }
5258
+ async function dataBody(rawId, rawStep, opts) {
5259
+ const id = parseInt1(rawId, "execution id");
5260
+ const step2 = parseInt1(rawStep, "step number");
5261
+ if (opts.offset !== void 0 && opts.top === void 0) {
5262
+ fail(2 /* USAGE */, "--offset needs --top: without --top every page is drained from the start.");
5263
+ }
5264
+ const entries = await apiErrors(
5265
+ async () => buildClient().executions.data(id, step2, {
5266
+ type: opts.type,
5267
+ loopPath: opts.loopPath,
5268
+ runNumber: parseCount(opts.runNumber, "--run-number"),
5269
+ retryNo: parseCount(opts.retryNo, "--retry-no"),
5270
+ status: opts.status,
5271
+ top: parseCount(opts.top, "--top"),
5272
+ offset: parseCount(opts.offset, "--offset")
5273
+ })
5274
+ );
5275
+ printOutput(snakeKeys(entries, ["value", "additional"]));
5276
+ }
5277
+ function registerExecutions(program) {
5278
+ const executions = program.command("executions").description("Read-only run history: list, inspect, step log and recorded step data.");
5279
+ const list = executions.command("list").description("List executions, newest first. Prints { items, next_cursor, total_count }.").option("--workflow <id>", "Only this workflow / automation / business rule").option("--type <type>", "workflow | automation | businessRule").option("--trigger-type <type>", "instant, scheduled, recordUpdate, api, \u2026").option("--status <status>", "Match a status; repeat to match any of several", collect4).option("--context <text>", "Substring of the caller-supplied context id").option("--created-by <id>", "Account-user id that started the run").option("--created-after <iso>", "Queued at or after").option("--created-before <iso>", "Queued at or before").option("--closed-after <iso>", "Finished at or after").option("--closed-before <iso>", "Finished at or before").option("--sort <spec>", "e.g. 'createdAt desc' (cursor paging needs one createdAt/executionId key)").option("--cursor <cursor>", "next_cursor from a previous page").option("--top <n>", "Page size (server cap 100; default 100)").option("--offset <n>", "Skip n rows (ignored by the server with --cursor)").option("--all", "Drain every page (follows next_cursor); not with --top/--cursor/--offset");
5280
+ list.addHelpText(
5281
+ "after",
5282
+ "\nExamples:\n engini executions list --workflow 123 --status failed --top 20\n engini executions list --cursor <next_cursor> --top 20\n engini executions list --created-after 2026-11-01T00:00:00Z --all --json\nNote: one page by default; pass --all to read everything that matches."
5283
+ );
5284
+ addUniversalOptions(list);
5285
+ list.action(async (opts, command) => {
5286
+ await runCommand(command, opts, false, () => listBody14(opts));
5287
+ });
5288
+ const get = executions.command("get").description("One execution: status, timing, activities run, who started it.").argument("[execution_id]", "Execution id");
5289
+ get.addHelpText("after", "\nExamples:\n engini executions get 4567 --json");
5290
+ addUniversalOptions(get);
5291
+ get.action(async (id, opts, command) => {
5292
+ await runCommand(command, opts, false, () => getBody12(id));
5293
+ });
5294
+ const log = executions.command("log").description("The execution's per-step log (step_no, status, runs_count, duration, loop).").argument("[execution_id]", "Execution id");
5295
+ log.addHelpText(
5296
+ "after",
5297
+ "\nExamples:\n engini executions log 4567\nNote: step detail is deleted after the workflow's history retention window (410); the execution stays listed."
5298
+ );
5299
+ addUniversalOptions(log);
5300
+ log.action(async (id, opts, command) => {
5301
+ await runCommand(command, opts, false, () => logBody(id));
5302
+ });
5303
+ const data = executions.command("data").description("Recorded request / response / input / status payloads of one step.").argument("[execution_id]", "Execution id").argument("[step_no]", "Step number from `executions log`").option("--type <kind>", "request | response | input | status").option("--loop-path <step:iteration>", "Loop position, repeat per nesting level, outermost first", collect4).option("--run-number <n>", "Only this run of the step").option("--retry-no <n>", "Only this retry attempt").option("--status <status>", "Only payloads recorded at this step status").option("--top <n>", "One page of at most n entries (server cap 10); default drains every page").option("--offset <n>", "With --top: skip n entries");
5304
+ data.addHelpText("after", "\nExamples:\n engini executions data 4567 3 --type response --json");
5305
+ addUniversalOptions(data);
5306
+ data.action(
5307
+ async (id, step2, opts, command) => {
5308
+ await runCommand(command, opts, false, () => dataBody(id, step2, opts));
5309
+ }
5310
+ );
5311
+ }
5312
+
5313
+ // src/workflows/index.ts
5314
+ var PLAN_HELP = "Plan JSON: --file <path>, --file -, or piped stdin. A bare WorkflowPlan ({name, trigger, steps, \u2026}) \u2014 the same shape `engini workflows plan <id>` prints.";
5315
+ function fileOption(cmd) {
5316
+ return cmd.option("--file <path>", "Plan JSON file ('-' or omit to read stdin)");
5317
+ }
5318
+ async function searchBody(query, opts) {
5319
+ const hits = await apiErrors(
5320
+ async () => buildClient().workflows.searchCatalog({
5321
+ q: query,
5322
+ kind: opts.kind,
5323
+ app: opts.app,
5324
+ top: parseCount(opts.top, "--top"),
5325
+ table: opts.table
5326
+ })
5327
+ );
5328
+ printOutput(hits);
5329
+ }
5330
+ async function schemaBody(slug, opts) {
5331
+ if (!slug) fail(2 /* USAGE */, "A catalog slug is required.");
5332
+ const schema = await apiErrors(
5333
+ async () => buildClient().workflows.getSchema(slug, {
5334
+ connectionId: parseOptId(opts.connection, "--connection"),
5335
+ kind: opts.kind,
5336
+ table: opts.table
5337
+ })
5338
+ );
5339
+ printOutput(schema);
5340
+ }
5341
+ function parseDependsOn(pairs) {
5342
+ if (pairs === void 0) return void 0;
5343
+ const out = {};
5344
+ for (const pair of pairs) {
5345
+ const eq = pair.indexOf("=");
5346
+ if (eq <= 0) fail(2 /* USAGE */, `--depends-on must be field=value, got '${pair}'.`);
5347
+ out[pair.slice(0, eq)] = pair.slice(eq + 1);
5348
+ }
5349
+ return out;
5350
+ }
5351
+ async function optionsBody(slug, opts) {
5352
+ if (!slug) fail(2 /* USAGE */, "A catalog slug is required.");
5353
+ const items = await apiErrors(
5354
+ async () => buildClient().workflows.getOptions(slug, {
5355
+ field: opts.field,
5356
+ connectionId: parseOptId(opts.connection, "--connection"),
5357
+ kind: opts.kind,
5358
+ dependsOn: parseDependsOn(opts.dependsOn)
5359
+ })
5360
+ );
5361
+ printOutput(items);
5362
+ }
5363
+ function registerWorkflows(program) {
5364
+ const workflows = program.command("workflows").description("Build workflows from a plan: catalog lookups, dry-run compile, create, update.");
5365
+ const search = workflows.command("search").description("Search the catalog of actions, triggers and blocks a plan step can name.").argument("[query]", "Free-text query").option("--kind <kind>", "action | trigger | block").option("--app <slug>", "Narrow to one application").option("--table <id>", "Narrow to a table's trigger / actions").option("--top <n>", "Maximum hits");
5366
+ search.addHelpText("after", "\nExamples:\n engini workflows search 'post message' --app slack --kind action");
5367
+ addUniversalOptions(search);
5368
+ search.action(async (q, opts, command) => {
5369
+ await runCommand(command, opts, false, () => searchBody(q, opts));
5370
+ });
5371
+ const schema = workflows.command("schema").description("Input/output schema of one catalog entry (the slug from `search`).").argument("[slug]", "Catalog slug, e.g. slack.post_message").option("--connection <id>", "Resolve dynamic fields against this connection").option("--kind <kind>", "action | trigger | block").option("--table <id>", "Table the entry is used on");
5372
+ addUniversalOptions(schema);
5373
+ schema.action(async (slug, opts, command) => {
5374
+ await runCommand(command, opts, false, () => schemaBody(slug, opts));
5375
+ });
5376
+ const options = workflows.command("options").description("Dropdown values ({id, label}) for one field of a catalog entry.").argument("[slug]", "Catalog slug").option("--field <name>", "The field to list values for").option("--connection <id>", "Connection to read the values through").option("--kind <kind>", "action | trigger | block").option("--depends-on <field=value>", "Value of a parent field; repeatable", collect4);
5377
+ options.addHelpText(
5378
+ "after",
5379
+ "\nExamples:\n engini workflows options slack.post_message --field channel --connection 42"
5380
+ );
5381
+ addUniversalOptions(options);
5382
+ options.action(
5383
+ async (slug, opts, command) => {
5384
+ await runCommand(command, opts, false, () => optionsBody(slug, opts));
5385
+ }
5386
+ );
5387
+ const tables = workflows.command("tables").description("The caller's tables ({id, name}).");
5388
+ addUniversalOptions(tables);
5389
+ tables.action(async (opts, command) => {
5390
+ await runCommand(command, opts, false, async () => {
5391
+ printOutput(await apiErrors(async () => buildClient().workflows.listTables()));
5392
+ });
5393
+ });
5394
+ const columns = workflows.command("columns").description("A table's columns, as a table automation reads them.").argument("[table_id]", "Table id from `workflows tables`").option("--trigger <slug>", "The automation's Tables trigger slug, e.g. tables.Tableonrecordupdated");
5395
+ addUniversalOptions(columns);
5396
+ columns.action(async (tableId, opts, command) => {
5397
+ await runCommand(command, opts, false, async () => {
5398
+ if (!tableId) fail(2 /* USAGE */, "A table id is required.");
5399
+ printOutput(
5400
+ await apiErrors(async () => buildClient().workflows.listTableColumns(tableId, { trigger: opts.trigger }))
5401
+ );
5402
+ });
5403
+ });
5404
+ const connections = workflows.command("connections").description("Connections a plan step may bind to.").option("--app <slug>", "Narrow to one application");
5405
+ addUniversalOptions(connections);
5406
+ connections.action(async (opts, command) => {
5407
+ await runCommand(command, opts, false, async () => {
5408
+ printOutput(await apiErrors(async () => buildClient().workflows.listConnections({ app: opts.app })));
5409
+ });
5410
+ });
5411
+ const compile = workflows.command("compile").description("Dry-run a plan: nothing is written. Prints the compiled workflow with its diagnostics and hasErrors.").option("--base-workflow-id <id>", "Compile the plan as an edit of this saved workflow");
5412
+ fileOption(compile);
5413
+ compile.addHelpText(
5414
+ "after",
5415
+ `
5416
+ ${PLAN_HELP}
5417
+ Examples:
5418
+ engini workflows compile --file plan.json
5419
+ cat plan.json | engini workflows compile --json
5420
+ Note: a plan with errors is printed (hasErrors: true), not failed; create/update refuse it.`
5421
+ );
5422
+ addUniversalOptions(compile);
5423
+ compile.action(
5424
+ async (opts, command) => {
5425
+ await runCommand(command, opts, false, async () => {
5426
+ const baseWorkflowId = parseOptId(opts.baseWorkflowId, "--base-workflow-id");
5427
+ const plan2 = readJsonObject(opts.file, "plan");
5428
+ printOutput(await apiErrors(async () => buildClient().workflows.compile({ plan: plan2, baseWorkflowId })));
5429
+ });
5430
+ }
5431
+ );
5432
+ const plan = workflows.command("plan").description("A saved workflow read back as a plan (the input to `update`).").argument("[workflow_id]", "Workflow id");
5433
+ plan.addHelpText("after", "\nExamples:\n engini workflows plan 1234 > plan.json");
5434
+ addUniversalOptions(plan);
5435
+ plan.action(async (id, opts, command) => {
5436
+ await runCommand(command, opts, false, async () => {
5437
+ const workflowId = parseInt1(id, "workflow id");
5438
+ printOutput(await apiErrors(async () => buildClient().workflows.getPlan(workflowId)));
5439
+ });
5440
+ });
5441
+ const create = workflows.command("create").description("Create a workflow from a plan. It is created turned off.").option("--folder-id <id>", "Folder to put the workflow in");
5442
+ fileOption(create);
5443
+ create.addHelpText(
5444
+ "after",
5445
+ `
5446
+ ${PLAN_HELP}
5447
+ Examples:
5448
+ engini workflows create --file plan.json --folder-id 7
5449
+ Note: needs a workspace-scoped API key (SCOPE_REQUIRED otherwise). Run \`compile\` first.`
5450
+ );
5451
+ addUniversalOptions(create, { mutating: true });
5452
+ create.action(
5453
+ async (opts, command) => {
5454
+ await runCommand(command, opts, true, async () => {
5455
+ const folderId = parseOptId(opts.folderId, "--folder-id");
5456
+ const body = readJsonObject(opts.file, "plan");
5457
+ if (dryRun()) {
5458
+ printOutput({ would_create: { name: body.name ?? null, folder_id: folderId ?? null } });
5459
+ return;
5460
+ }
5461
+ printOutput(
5462
+ await apiErrors(async () => buildClient().workflows.create({ plan: body, folderId }))
5463
+ );
5464
+ });
5465
+ }
5466
+ );
5467
+ const update = workflows.command("update").description("Replace a turned-off workflow's contents from a plan.").argument("[workflow_id]", "Workflow id").option("--expected-revision-id <n>", "Refuse (REVISION_CONFLICT) if the workflow was saved since this revision");
5468
+ fileOption(update);
5469
+ update.addHelpText(
5470
+ "after",
5471
+ `
5472
+ ${PLAN_HELP}
5473
+ Examples:
5474
+ engini workflows plan 1234 > plan.json # edit plan.json
5475
+ engini workflows update 1234 --file plan.json --expected-revision-id 3
5476
+ Note: a turned-on workflow is refused (WORKFLOW_ACTIVE); turn it off in the designer first.`
5477
+ );
5478
+ addUniversalOptions(update, { mutating: true });
5479
+ update.action(
5480
+ async (id, opts, command) => {
5481
+ await runCommand(command, opts, true, async () => {
5482
+ const workflowId = parseInt1(id, "workflow id");
5483
+ const expectedRevisionId = parseOptId(opts.expectedRevisionId, "--expected-revision-id");
5484
+ const body = readJsonObject(opts.file, "plan");
5485
+ if (dryRun()) {
5486
+ printOutput({ would_update: workflowId, expected_revision_id: expectedRevisionId ?? null });
5487
+ return;
5488
+ }
5489
+ printOutput(
5490
+ await apiErrors(
5491
+ async () => buildClient().workflows.update(workflowId, { plan: body, expectedRevisionId })
5492
+ )
5493
+ );
5494
+ });
5495
+ }
5496
+ );
5497
+ }
5498
+
5096
5499
  // src/whoami.ts
5097
5500
  function summary5(me) {
5501
+ const ws = me.workspace;
5502
+ const env = me.environment;
5098
5503
  return {
5099
5504
  full_name: clean(me.fullName),
5100
5505
  email: clean(me.email),
5101
5506
  current_company: clean(me.currentCompany),
5102
5507
  role: clean(me.role),
5103
- user_type: me.userType
5508
+ user_type: me.userType,
5509
+ workspace: ws ? { id: ws.id, name: clean(ws.name) } : null,
5510
+ environment: env ? { id: env.id, name: clean(env.name), type: clean(env.type) } : null
5104
5511
  };
5105
5512
  }
5106
5513
  async function whoamiBody() {
@@ -5111,8 +5518,12 @@ async function whoamiBody() {
5111
5518
  printOutput(summary5(me));
5112
5519
  }
5113
5520
  function registerWhoami(program) {
5114
- const cmd = program.command("whoami").description("Report the authenticated user/company.");
5115
- cmd.addHelpText("after", "\nExamples:\n engini whoami\n engini whoami --json | jq -r '.email'");
5521
+ const cmd = program.command("whoami").description("Report the authenticated user/company and the key's workspace/environment.");
5522
+ cmd.addHelpText("after", `
5523
+ Examples:
5524
+ engini whoami
5525
+ engini whoami --json | jq -r '.email'
5526
+ engini whoami --json | jq -r '.workspace.id // "unscoped"'`);
5116
5527
  addUniversalOptions(cmd);
5117
5528
  cmd.action(async (opts, command) => {
5118
5529
  await runCommand(command, opts, false, () => whoamiBody());
@@ -5134,12 +5545,14 @@ function buildProgram() {
5134
5545
  registerMcp(program);
5135
5546
  registerOpa(program);
5136
5547
  registerTriggers(program);
5548
+ registerExecutions(program);
5549
+ registerWorkflows(program);
5137
5550
  installHelp(program);
5138
5551
  return program;
5139
5552
  }
5140
5553
 
5141
5554
  // src/update-notice.ts
5142
- import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
5555
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "fs";
5143
5556
  import { dirname as dirname2, join as join3 } from "path";
5144
5557
  var REGISTRY_DIST_TAGS_URL = "https://registry.npmjs.org/-/package/%40engini%2Fcli/dist-tags";
5145
5558
  var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
@@ -5150,7 +5563,7 @@ function defaultCachePath() {
5150
5563
  }
5151
5564
  function readCache(path) {
5152
5565
  try {
5153
- const data = JSON.parse(readFileSync5(path, "utf8"));
5566
+ const data = JSON.parse(readFileSync6(path, "utf8"));
5154
5567
  if (typeof data.checked_at === "number" && typeof data.channel === "string" && (data.latest_version === null || typeof data.latest_version === "string")) {
5155
5568
  return data;
5156
5569
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@engini/cli",
3
- "version": "0.28.0",
3
+ "version": "0.30.0",
4
4
  "description": "Engini CLI — machine-first command line over the Engini Public API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,7 +26,7 @@
26
26
  "test": "vitest run"
27
27
  },
28
28
  "dependencies": {
29
- "@engini/sdk": "^0.28.0",
29
+ "@engini/sdk": "^0.30.0",
30
30
  "commander": "^12.1.0",
31
31
  "smol-toml": "^1.3.0"
32
32
  },