kenso 0.1.148 → 0.1.151

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.
package/dist/kenso.js CHANGED
@@ -3389,7 +3389,7 @@ var VERSION;
3389
3389
  var init_version = __esm({
3390
3390
  "src/core/version.ts"() {
3391
3391
  "use strict";
3392
- VERSION = true ? "0.1.148" : "0.0.0-dev";
3392
+ VERSION = true ? "0.1.151" : "0.0.0-dev";
3393
3393
  }
3394
3394
  });
3395
3395
 
@@ -3684,9 +3684,9 @@ async function readAnswer(ctx) {
3684
3684
  const lines = createInterface({ input: ctx.stdin ?? process.stdin, terminal: false });
3685
3685
  let onAbort;
3686
3686
  try {
3687
- return await new Promise((resolve21, reject) => {
3688
- lines.once("line", resolve21);
3689
- lines.once("close", () => resolve21(""));
3687
+ return await new Promise((resolve22, reject) => {
3688
+ lines.once("line", resolve22);
3689
+ lines.once("close", () => resolve22(""));
3690
3690
  onAbort = () => reject(interrupted());
3691
3691
  ctx.signal.addEventListener("abort", onAbort, { once: true });
3692
3692
  });
@@ -4702,9 +4702,9 @@ async function readRun(dir3) {
4702
4702
  return null;
4703
4703
  }
4704
4704
  if (!raw) return null;
4705
- const { runId, command: command87, createdAt, status } = raw;
4705
+ const { runId, command: command89, createdAt, status } = raw;
4706
4706
  if (typeof runId !== "string" || !RUN_ID_PATTERN.test(runId)) return null;
4707
- if (typeof command87 !== "string" || typeof createdAt !== "string") return null;
4707
+ if (typeof command89 !== "string" || typeof createdAt !== "string") return null;
4708
4708
  if (typeof status !== "string" || !STATUSES.includes(status)) return null;
4709
4709
  let chunksDone = chunkList(raw.chunksDone) ?? [];
4710
4710
  try {
@@ -4715,7 +4715,7 @@ async function readRun(dir3) {
4715
4715
  const record3 = {
4716
4716
  ...raw,
4717
4717
  runId,
4718
- command: command87,
4718
+ command: command89,
4719
4719
  args: asRecord3(raw.args) ?? {},
4720
4720
  createdAt,
4721
4721
  status,
@@ -4775,11 +4775,11 @@ async function loadRun(runId, env = process.env) {
4775
4775
  }
4776
4776
  return run;
4777
4777
  }
4778
- async function findIdentical(command87, args, inputSha256, env, workspaceId, anyWorkspace = false) {
4778
+ async function findIdentical(command89, args, inputSha256, env, workspaceId, anyWorkspace = false) {
4779
4779
  const identity = argsIdentity(args);
4780
4780
  const runs = await listRuns(env);
4781
4781
  return runs.filter(
4782
- (run) => run.command === command87 && (run.inputSha256 || void 0) === (inputSha256 || void 0) && (anyWorkspace || (run.workspaceId || void 0) === (workspaceId || void 0)) && argsIdentity(run.args) === identity
4782
+ (run) => run.command === command89 && (run.inputSha256 || void 0) === (inputSha256 || void 0) && (anyWorkspace || (run.workspaceId || void 0) === (workspaceId || void 0)) && argsIdentity(run.args) === identity
4783
4783
  );
4784
4784
  }
4785
4785
  function isOtherLiveProcess(pid) {
@@ -8202,8 +8202,8 @@ async function ask(ctx, path, body2, read2) {
8202
8202
  const res = await ctx.client.request({ method: "POST", path, body: body2 });
8203
8203
  const data = unwrap(res.body);
8204
8204
  if (!isRecord4(data)) return { estimate: data ?? null };
8205
- const estimate = Object.fromEntries(Object.entries(data).filter(([key]) => key !== "totalAmount" && !/usd/i.test(key)));
8206
- return { estimate, credits: await read2(data) };
8205
+ const estimate2 = Object.fromEntries(Object.entries(data).filter(([key]) => key !== "totalAmount" && !/usd/i.test(key)));
8206
+ return { estimate: estimate2, credits: await read2(data) };
8207
8207
  } catch (err) {
8208
8208
  if (mustRethrow(err)) throw err;
8209
8209
  ctx.output.warn(`Could not estimate the credits: ${err instanceof Error ? err.message : String(err)}`);
@@ -8212,10 +8212,10 @@ async function ask(ctx, path, body2, read2) {
8212
8212
  }
8213
8213
  async function creditEstimate(ctx, body2) {
8214
8214
  return ask(ctx, "/v1/credits/estimates", body2, (data) => {
8215
- const credits2 = (key) => typeof data[key] === "number" ? data[key] / 1e3 : null;
8215
+ const credits3 = (key) => typeof data[key] === "number" ? data[key] / 1e3 : null;
8216
8216
  return {
8217
- needed: credits2("totalMillicredits"),
8218
- available: credits2("availableMillicredits"),
8217
+ needed: credits3("totalMillicredits"),
8218
+ available: credits3("availableMillicredits"),
8219
8219
  sufficient: typeof data.sufficient === "boolean" ? data.sufficient : null
8220
8220
  };
8221
8221
  });
@@ -8305,8 +8305,8 @@ function idValue(value, field) {
8305
8305
  function shellQuote3(arg) {
8306
8306
  return /^[A-Za-z0-9_./:=@%+,-]+$/.test(arg) ? arg : `'${arg.replace(/'/g, `'\\''`)}'`;
8307
8307
  }
8308
- function commandLine2(ctx, command87, args, extra = []) {
8309
- const parts2 = ["kenso", ...command87.split(" "), ...(args.positionals ?? []).map(shellQuote3)];
8308
+ function commandLine2(ctx, command89, args, extra = []) {
8309
+ const parts2 = ["kenso", ...command89.split(" "), ...(args.positionals ?? []).map(shellQuote3)];
8310
8310
  for (const [name, value] of Object.entries(args.flags)) {
8311
8311
  if (value === void 0 || value === false) continue;
8312
8312
  if (value === true) parts2.push(`--${name}`);
@@ -8581,8 +8581,8 @@ var init_import = __esm({
8581
8581
  });
8582
8582
  const dryRun2 = ctx.flags.dryRun === true || ctx.flags.yes !== true;
8583
8583
  const mapping = Object.fromEntries(Object.entries(columns2.mapping).map(([header, field]) => [header, field === "domain" ? "domains" : field]));
8584
- const estimate = dryRun2 ? await estimateAccounts(ctx, items.length) : null;
8585
- const credits2 = estimate ? { ...creditsCheck(estimate.totalMillicredits, estimate.availableMillicredits), sufficient: estimate.sufficient } : creditsCheck(0, void 0);
8584
+ const estimate2 = dryRun2 ? await estimateAccounts(ctx, items.length) : null;
8585
+ const credits3 = estimate2 ? { ...creditsCheck(estimate2.totalMillicredits, estimate2.availableMillicredits), sufficient: estimate2.sufficient } : creditsCheck(0, void 0);
8586
8586
  const outcome = await runBatch(
8587
8587
  {
8588
8588
  command: COMMAND,
@@ -8595,7 +8595,7 @@ var init_import = __esm({
8595
8595
  execChunk: sendChunk,
8596
8596
  invalid: invalid2,
8597
8597
  dryRun: dryRun2,
8598
- dryRunExtra: dryRun2 ? { mapping, ignoredColumns: columns2.ignored, estimate, credits: credits2 } : void 0,
8598
+ dryRunExtra: dryRun2 ? { mapping, ignoredColumns: columns2.ignored, estimate: estimate2, credits: credits3 } : void 0,
8599
8599
  applyCommand: commandLine2(ctx, COMMAND, args, ["--yes"]),
8600
8600
  outDir: stringFlag(flags.out),
8601
8601
  summarize
@@ -8619,9 +8619,9 @@ function stringFlag2(flags, name) {
8619
8619
  const text4 = value.trim();
8620
8620
  return text4 === "" ? void 0 : text4;
8621
8621
  }
8622
- function requireFlag(flags, name, command87, hint) {
8622
+ function requireFlag(flags, name, command89, hint) {
8623
8623
  const value = stringFlag2(flags, name);
8624
- if (value === void 0) throw usageError(`--${name} is required for ${command87}.`, { field: name, next: `${command87} --help`, ...hint ? { hint } : {} });
8624
+ if (value === void 0) throw usageError(`--${name} is required for ${command89}.`, { field: name, next: `${command89} --help`, ...hint ? { hint } : {} });
8625
8625
  return value;
8626
8626
  }
8627
8627
  function positiveId(value) {
@@ -8630,8 +8630,8 @@ function positiveId(value) {
8630
8630
  const id = Number(text4);
8631
8631
  return Number.isSafeInteger(id) && id > 0 ? id : void 0;
8632
8632
  }
8633
- function idFlag(flags, name, command87) {
8634
- const raw = requireFlag(flags, name, command87);
8633
+ function idFlag(flags, name, command89) {
8634
+ const raw = requireFlag(flags, name, command89);
8635
8635
  const id = positiveId(raw);
8636
8636
  if (id === void 0) throw usageError(`--${name} must be a positive whole number (got "${raw}").`, { field: name });
8637
8637
  return id;
@@ -8651,8 +8651,8 @@ function isDryRun(ctx) {
8651
8651
  function shellQuote4(value) {
8652
8652
  return /^[A-Za-z0-9_\-.,:/@=+%]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
8653
8653
  }
8654
- function sameCommand2(command87, flags, ctx, extra = []) {
8655
- const parts2 = [command87];
8654
+ function sameCommand2(command89, flags, ctx, extra = []) {
8655
+ const parts2 = [command89];
8656
8656
  for (const [name, value] of Object.entries(flags)) {
8657
8657
  if (value === void 0 || value === false) continue;
8658
8658
  if (value === true) parts2.push(`--${name}`);
@@ -8884,12 +8884,12 @@ function filterBody(flags) {
8884
8884
  }
8885
8885
  return parsed2;
8886
8886
  }
8887
- function targetBody(flags, target2, command87) {
8887
+ function targetBody(flags, target2, command89) {
8888
8888
  const ids2 = idList(flags, "ids");
8889
8889
  const filter = filterBody(flags);
8890
8890
  const everything = flags.all === true;
8891
8891
  if (ids2 !== void 0 === (filter !== void 0 || everything)) {
8892
- throw usageError(`Name the ${target2.plural} one way: --ids, --filter, or --all for every ${target2.noun} in the workspace.`, { field: "ids", next: `${command87} --help` });
8892
+ throw usageError(`Name the ${target2.plural} one way: --ids, --filter, or --all for every ${target2.noun} in the workspace.`, { field: "ids", next: `${command89} --help` });
8893
8893
  }
8894
8894
  const exclude = idList(flags, "exclude-ids");
8895
8895
  if (exclude !== void 0 && ids2 !== void 0) throw usageError("--exclude-ids goes with --filter or --all.", { field: "exclude-ids" });
@@ -8910,14 +8910,14 @@ function tagSet(flags) {
8910
8910
  return set2;
8911
8911
  }
8912
8912
  function requestBody(flags, target2, dryRun2) {
8913
- const command87 = `kenso ${target2.resource} bulk-update`;
8913
+ const command89 = `kenso ${target2.resource} bulk-update`;
8914
8914
  const pairs = Array.isArray(flags.set) ? flags.set : typeof flags.set === "string" ? [flags.set] : [];
8915
8915
  const tags = target2.tags ? tagSet(flags) : {};
8916
8916
  if (pairs.length === 0 && Object.keys(tags).length === 0) {
8917
- throw usageError(`--set${target2.tags ? " or --add-tag" : ""} is required for ${command87}.`, { field: "set", hint: "For example --set stage=engaged.", next: `${command87} --help` });
8917
+ throw usageError(`--set${target2.tags ? " or --add-tag" : ""} is required for ${command89}.`, { field: "set", hint: "For example --set stage=engaged.", next: `${command89} --help` });
8918
8918
  }
8919
8919
  return {
8920
- ...targetBody(flags, target2, command87),
8920
+ ...targetBody(flags, target2, command89),
8921
8921
  set: { ...parseSet(pairs, target2.aliases, target2.textFields), ...tags },
8922
8922
  ...dryRun2 ? { dryRun: true } : {},
8923
8923
  ...flags["overwrite-pinned"] === true ? { overwritePinned: true } : {}
@@ -8983,7 +8983,7 @@ function bulkUpdateCommand(target2) {
8983
8983
  };
8984
8984
  }
8985
8985
  function bulkDeleteCommand(target2) {
8986
- const command87 = `kenso ${target2.resource} bulk-delete`;
8986
+ const command89 = `kenso ${target2.resource} bulk-delete`;
8987
8987
  return {
8988
8988
  resource: target2.resource,
8989
8989
  action: "bulk-delete",
@@ -9007,7 +9007,7 @@ function bulkDeleteCommand(target2) {
9007
9007
  beta: { featureGates: { all: target2.featureGates } },
9008
9008
  operationIds: [`${target2.resource}.bulk-delete`, "changes.get"],
9009
9009
  dryRun: true,
9010
- run: (ctx, { flags }) => runChange(ctx, flags, `/v1/${target2.resource}/bulk-delete`, (dryRun2) => ({ ...targetBody(flags, target2, command87), dryRun: dryRun2 }))
9010
+ run: (ctx, { flags }) => runChange(ctx, flags, `/v1/${target2.resource}/bulk-delete`, (dryRun2) => ({ ...targetBody(flags, target2, command89), dryRun: dryRun2 }))
9011
9011
  };
9012
9012
  }
9013
9013
  async function runChange(ctx, flags, path, body2) {
@@ -11043,8 +11043,8 @@ var init_browser_login = __esm({
11043
11043
  defaultDeps = {
11044
11044
  sleep: (ms, signal) => delay5(ms, void 0, signal ? { signal } : void 0),
11045
11045
  now: () => Date.now(),
11046
- spawn: (command87, args) => {
11047
- const child = nodeSpawn(command87, args, { detached: true, stdio: "ignore" });
11046
+ spawn: (command89, args) => {
11047
+ const child = nodeSpawn(command89, args, { detached: true, stdio: "ignore" });
11048
11048
  child.on("error", () => {
11049
11049
  });
11050
11050
  child.unref();
@@ -12435,8 +12435,8 @@ var init_run = __esm({
12435
12435
  defaultDeps2 = {
12436
12436
  sleep: (ms, signal) => delay6(ms, void 0, signal ? { signal } : void 0),
12437
12437
  now: () => Date.now(),
12438
- spawn: (command87, args) => {
12439
- const child = nodeSpawn2(command87, args, { detached: true, stdio: "ignore" });
12438
+ spawn: (command89, args) => {
12439
+ const child = nodeSpawn2(command89, args, { detached: true, stdio: "ignore" });
12440
12440
  child.on("error", () => {
12441
12441
  });
12442
12442
  child.unref();
@@ -13414,12 +13414,12 @@ import { join as join17 } from "node:path";
13414
13414
  function whereDir(env) {
13415
13415
  return join17(runsRoot(env), WHERE_DIR);
13416
13416
  }
13417
- async function unfinishedWhereIds(ctx, command87, args) {
13417
+ async function unfinishedWhereIds(ctx, command89, args) {
13418
13418
  const dir3 = whereDir(ctx.env);
13419
13419
  const identity = argsIdentity(args);
13420
13420
  const workspaceId = ctx.client.workspaceId ?? ctx.auth.workspaceId;
13421
13421
  for (const run of await listRuns(ctx.env)) {
13422
- if (run.command !== command87 || run.status === "done" || run.status === "planned") continue;
13422
+ if (run.command !== command89 || run.status === "done" || run.status === "planned") continue;
13423
13423
  if ((run.workspaceId || void 0) !== (workspaceId || void 0) || argsIdentity(run.args) !== identity) continue;
13424
13424
  if (run.inputPath?.startsWith(`${dir3}/`) && existsSync7(run.inputPath)) return run.inputPath;
13425
13425
  }
@@ -13565,14 +13565,14 @@ async function idsFromRun(ctx, runId) {
13565
13565
  return { ...idItems(ids2), source: "run" };
13566
13566
  }
13567
13567
  async function collectIds(ctx, flags, kind, dryRun2) {
13568
- const command87 = `kenso contacts ${kind}`;
13568
+ const command89 = `kenso contacts ${kind}`;
13569
13569
  const ids2 = stringFlag2(flags, "ids");
13570
13570
  const where = kind === "restore" ? void 0 : stringFlag2(flags, "where");
13571
13571
  const run = kind === "restore" ? stringFlag2(flags, "run") : void 0;
13572
13572
  const given = [ids2, where, run].filter((v) => v !== void 0).length;
13573
13573
  if (given !== 1) {
13574
13574
  const choices = kind === "restore" ? "--ids <file|-> or --run <runId>" : "--ids <file|-> or --where '<json>'";
13575
- throw usageError(`${command87} needs exactly one of ${choices}.`, { field: "ids", next: `${command87} --help` });
13575
+ throw usageError(`${command89} needs exactly one of ${choices}.`, { field: "ids", next: `${command89} --help` });
13576
13576
  }
13577
13577
  if (ids2 !== void 0) return idsFromFile(ctx, ids2);
13578
13578
  if (where !== void 0) return idsFromWhere(ctx, kind, flags, where, dryRun2);
@@ -14848,15 +14848,15 @@ function candidate(entry, costNote) {
14848
14848
  function specEntry(spec) {
14849
14849
  if (spec.brief?.startsWith("same as ")) return void 0;
14850
14850
  const id = commandName(spec).slice("kenso ".length);
14851
- const credits2 = spec.cost ?? [];
14852
- const actions39 = credits2.map((c) => c.action);
14851
+ const credits3 = spec.cost ?? [];
14852
+ const actions39 = credits3.map((c) => c.action);
14853
14853
  return {
14854
14854
  kind: "command",
14855
14855
  id,
14856
14856
  summary: spec.summary,
14857
14857
  terms: termsOf(id, spec.summary, spec.description, spec.doc?.when, Object.keys(spec.flags).join(" "), actions39.join(" ")),
14858
14858
  effect: spec.effect,
14859
- ...credits2.length > 0 ? { costActions: actions39, credits: credits2 } : {},
14859
+ ...credits3.length > 0 ? { costActions: actions39, credits: credits3 } : {},
14860
14860
  ...spec.beta ? { beta: true } : {},
14861
14861
  describe: `kenso describe ${id}`
14862
14862
  };
@@ -16611,8 +16611,10 @@ var init_opportunities = __esm({
16611
16611
  // src/commands/people/import.ts
16612
16612
  var import_exports4 = {};
16613
16613
  __export(import_exports4, {
16614
+ ALIASES: () => ALIASES3,
16614
16615
  default: () => import_default4,
16615
- personResult: () => personResult
16616
+ personResult: () => personResult,
16617
+ toBody: () => toBody2
16616
16618
  });
16617
16619
  function toBody2(row, columns2) {
16618
16620
  const value = (field) => firstValue(row, columns2.sources.get(field));
@@ -16685,8 +16687,8 @@ async function emailFindCredits(ctx, items, findEmails) {
16685
16687
  const price = unitMillicredits("email_found", await loadRateCards(ctx));
16686
16688
  const { available, estimateError } = await readAvailable(ctx);
16687
16689
  const check = creditsCheck(rows * (price ?? 0), available);
16688
- const credits2 = price === void 0 && rows > 0 ? { ...check, needed: null, sufficient: null } : check;
16689
- return { emailFindRows: rows, credits: credits2, ...estimateError ? { estimateError } : {} };
16690
+ const credits3 = price === void 0 && rows > 0 ? { ...check, needed: null, sufficient: null } : check;
16691
+ return { emailFindRows: rows, credits: credits3, ...estimateError ? { estimateError } : {} };
16690
16692
  }
16691
16693
  var COMMAND5, CHUNK_SIZE6, ALIASES3, PERSON_FIELDS, ACCOUNT_NOT_FOUND, command46, import_default4;
16692
16694
  var init_import5 = __esm({
@@ -17338,8 +17340,8 @@ import { resolve as resolve11 } from "node:path";
17338
17340
  function kebab(key) {
17339
17341
  return key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
17340
17342
  }
17341
- function commandWords(command87) {
17342
- return command87.trim().split(/\s+/).filter((t) => t !== "");
17343
+ function commandWords(command89) {
17344
+ return command89.trim().split(/\s+/).filter((t) => t !== "");
17343
17345
  }
17344
17346
  function flagValue(value) {
17345
17347
  return typeof value === "string" ? value : typeof value === "object" ? JSON.stringify(value) : String(value);
@@ -17811,12 +17813,105 @@ var init_sandbox2 = __esm({
17811
17813
  }
17812
17814
  });
17813
17815
 
17816
+ // src/core/step-types.ts
17817
+ function loadStepTypes() {
17818
+ return readDataFile("step-types.json")?.stepTypes ?? [];
17819
+ }
17820
+ function rateCardAction(stepCostAction) {
17821
+ return stepCostAction.replace(/LinkedIn/g, "Linkedin").replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
17822
+ }
17823
+ var init_step_types = __esm({
17824
+ "src/core/step-types.ts"() {
17825
+ "use strict";
17826
+ init_data();
17827
+ }
17828
+ });
17829
+
17830
+ // src/commands/signals/types.ts
17831
+ var types_exports = {};
17832
+ __export(types_exports, {
17833
+ default: () => types_default
17834
+ });
17835
+ function choice(flag, value, allowed, fallback) {
17836
+ if (value === void 0) return fallback;
17837
+ if (typeof value === "string" && allowed.includes(value)) return value;
17838
+ const words2 = `${allowed.slice(0, -1).join(", ")} or ${allowed[allowed.length - 1]}`;
17839
+ throw usageError(`--${flag} must be ${words2} (got "${String(value)}").`, { field: flag });
17840
+ }
17841
+ function scopeOf(inputSchema) {
17842
+ const properties = inputSchema?.properties;
17843
+ return properties !== null && typeof properties === "object" && !Array.isArray(properties) ? Object.keys(properties) : [];
17844
+ }
17845
+ function costOf(step, cards) {
17846
+ if (step.cost?.free === true) return "free";
17847
+ const actions39 = step.cost?.action ? [step.cost.action] : [...new Set(Object.values(step.cost?.actionByTier ?? {}))];
17848
+ if (actions39.length === 0) return priceLine({ action: step.key, pricing: "unlisted" }, cards);
17849
+ return actions39.map((action) => priceLine({ action: rateCardAction(action), pricing: "fixed" }, cards)).join("; ");
17850
+ }
17851
+ function toRow(step, cards) {
17852
+ return {
17853
+ type: step.type,
17854
+ title: step.title,
17855
+ recordType: step.recordType ?? null,
17856
+ workflowType: step.workflowType ?? null,
17857
+ sourceGroup: step.sourceGroup ?? null,
17858
+ scope: scopeOf(step.inputSchema),
17859
+ requires: (step.requires ?? []).map((need) => `${need.kind}:${need.key}`),
17860
+ cost: costOf(step, cards)
17861
+ };
17862
+ }
17863
+ var WORKFLOW_TYPES, RECORD_TYPES, FOOTER, command59, types_default;
17864
+ var init_types = __esm({
17865
+ "src/commands/signals/types.ts"() {
17866
+ "use strict";
17867
+ init_errors();
17868
+ init_exit_codes();
17869
+ init_rate_card();
17870
+ init_step_types();
17871
+ WORKFLOW_TYPES = ["signal", "bulk_import", "all"];
17872
+ RECORD_TYPES = ["account", "person", "lead", "place"];
17873
+ FOOTER = "Hiring signals come from a scheduled source: kenso signals types --workflow-type bulk_import. Templates that start from a signal: kenso workflow-templates list";
17874
+ command59 = {
17875
+ resource: "signals",
17876
+ action: "types",
17877
+ summary: "List the signal triggers a workflow can start from, offline",
17878
+ brief: "offline",
17879
+ description: "Lists the triggers a workflow can start from, read from the step types this CLI ships: no request and no sign-in. By default the signal triggers (a change at an account or a person); --workflow-type bulk_import lists the scheduled sources and all lists both. scope names the trigger's settings, what a watch can be narrowed by today; requires names the flags and apps it needs; cost is free, or the price from your cached or bundled rate card.",
17880
+ effect: "read",
17881
+ flags: {
17882
+ "workflow-type": { type: "string", default: "signal", description: "signal (default), bulk_import or all" },
17883
+ "record-type": { type: "string", description: "Only the triggers that run on account, person, lead or place records" }
17884
+ },
17885
+ examples: [
17886
+ "kenso signals types",
17887
+ "kenso signals types --workflow-type bulk_import -o json",
17888
+ "kenso signals types --record-type account --fields type,scope"
17889
+ ],
17890
+ operationIds: [],
17891
+ async run(ctx, { flags }) {
17892
+ const workflowType = choice("workflow-type", flags["workflow-type"], WORKFLOW_TYPES, "signal");
17893
+ const recordType = choice("record-type", flags["record-type"], RECORD_TYPES);
17894
+ const triggers = loadStepTypes().filter(
17895
+ (step) => step.kind === "trigger" && step.systemOnly !== true && (workflowType === "all" ? step.workflowType === "signal" || step.workflowType === "bulk_import" : step.workflowType === workflowType) && (recordType === void 0 || step.recordType === recordType)
17896
+ );
17897
+ const cards = triggers.some((step) => step.cost?.free !== true) ? await loadRateCards(ctx, { live: false }) : [];
17898
+ await ctx.output.list(triggers.map((step) => toRow(step, cards)));
17899
+ ctx.output.info(FOOTER);
17900
+ return ExitCode.Ok;
17901
+ }
17902
+ };
17903
+ types_default = command59;
17904
+ }
17905
+ });
17906
+
17814
17907
  // src/commands/signals/index.ts
17815
17908
  var actions28;
17816
17909
  var init_signals = __esm({
17817
17910
  "src/commands/signals/index.ts"() {
17818
17911
  "use strict";
17819
- actions28 = {};
17912
+ actions28 = {
17913
+ types: () => Promise.resolve().then(() => (init_types(), types_exports)).then((m) => m.default)
17914
+ };
17820
17915
  }
17821
17916
  });
17822
17917
 
@@ -17856,14 +17951,14 @@ function unexpectedAnswer(tool) {
17856
17951
  exitCode: ExitCode.Server
17857
17952
  });
17858
17953
  }
17859
- var command59, list_default4;
17954
+ var command60, list_default4;
17860
17955
  var init_list4 = __esm({
17861
17956
  "src/commands/skill/list.ts"() {
17862
17957
  "use strict";
17863
17958
  init_errors();
17864
17959
  init_exit_codes();
17865
17960
  init_connect4();
17866
- command59 = {
17961
+ command60 = {
17867
17962
  resource: "skill",
17868
17963
  action: "list",
17869
17964
  effect: "read",
@@ -17888,7 +17983,7 @@ var init_list4 = __esm({
17888
17983
  return ExitCode.Ok;
17889
17984
  }
17890
17985
  };
17891
- list_default4 = command59;
17986
+ list_default4 = command60;
17892
17987
  }
17893
17988
  });
17894
17989
 
@@ -17897,7 +17992,7 @@ var show_exports3 = {};
17897
17992
  __export(show_exports3, {
17898
17993
  default: () => show_default3
17899
17994
  });
17900
- var command60, show_default3;
17995
+ var command61, show_default3;
17901
17996
  var init_show3 = __esm({
17902
17997
  "src/commands/skill/show.ts"() {
17903
17998
  "use strict";
@@ -17905,7 +18000,7 @@ var init_show3 = __esm({
17905
18000
  init_connect4();
17906
18001
  init_bundled();
17907
18002
  init_list4();
17908
- command60 = {
18003
+ command61 = {
17909
18004
  resource: "skill",
17910
18005
  action: "show",
17911
18006
  effect: "read",
@@ -17932,7 +18027,7 @@ var init_show3 = __esm({
17932
18027
  return ExitCode.Ok;
17933
18028
  }
17934
18029
  };
17935
- show_default3 = command60;
18030
+ show_default3 = command61;
17936
18031
  }
17937
18032
  });
17938
18033
 
@@ -18275,7 +18370,7 @@ __export(pull_exports, {
18275
18370
  });
18276
18371
  import { mkdir, readFile as readFile11, writeFile as writeFile5 } from "node:fs/promises";
18277
18372
  import { dirname as dirname3, join as join20, resolve as resolve13 } from "node:path";
18278
- var command61, pull_default;
18373
+ var command62, pull_default;
18279
18374
  var init_pull = __esm({
18280
18375
  "src/commands/studio/pull.ts"() {
18281
18376
  "use strict";
@@ -18286,7 +18381,7 @@ var init_pull = __esm({
18286
18381
  init_common4();
18287
18382
  init_folder2();
18288
18383
  init_transfer2();
18289
- command61 = {
18384
+ command62 = {
18290
18385
  resource: "studio",
18291
18386
  action: "pull",
18292
18387
  summary: "Write a template version's files to a folder",
@@ -18368,7 +18463,7 @@ var init_pull = __esm({
18368
18463
  return ExitCode.Ok;
18369
18464
  }
18370
18465
  };
18371
- pull_default = command61;
18466
+ pull_default = command62;
18372
18467
  }
18373
18468
  });
18374
18469
 
@@ -18409,7 +18504,7 @@ __export(push_exports, {
18409
18504
  default: () => push_default
18410
18505
  });
18411
18506
  import { resolve as resolve14 } from "node:path";
18412
- var BUILT_BY, DEFAULT_MESSAGE, command62, push_default;
18507
+ var BUILT_BY, DEFAULT_MESSAGE, command63, push_default;
18413
18508
  var init_push = __esm({
18414
18509
  "src/commands/studio/push.ts"() {
18415
18510
  "use strict";
@@ -18423,7 +18518,7 @@ var init_push = __esm({
18423
18518
  init_transfer2();
18424
18519
  BUILT_BY = "customer_agent";
18425
18520
  DEFAULT_MESSAGE = "Pushed with the Kenso CLI";
18426
- command62 = {
18521
+ command63 = {
18427
18522
  resource: "studio",
18428
18523
  action: "push",
18429
18524
  summary: "Save a folder's files to a template's draft and print the validation",
@@ -18518,7 +18613,7 @@ var init_push = __esm({
18518
18613
  );
18519
18614
  }
18520
18615
  };
18521
- push_default = command62;
18616
+ push_default = command63;
18522
18617
  }
18523
18618
  });
18524
18619
 
@@ -18527,7 +18622,7 @@ var validate_exports = {};
18527
18622
  __export(validate_exports, {
18528
18623
  default: () => validate_default
18529
18624
  });
18530
- var command63, validate_default;
18625
+ var command64, validate_default;
18531
18626
  var init_validate = __esm({
18532
18627
  "src/commands/studio/validate.ts"() {
18533
18628
  "use strict";
@@ -18536,7 +18631,7 @@ var init_validate = __esm({
18536
18631
  init_columns();
18537
18632
  init_common4();
18538
18633
  init_read();
18539
- command63 = {
18634
+ command64 = {
18540
18635
  resource: "studio",
18541
18636
  action: "validate",
18542
18637
  summary: "Validate a folder's files against a template without saving them",
@@ -18566,7 +18661,7 @@ var init_validate = __esm({
18566
18661
  throw validationFailed(validation, "The files have validation errors", commandLine2(ctx, "studio validate", args));
18567
18662
  }
18568
18663
  };
18569
- validate_default = command63;
18664
+ validate_default = command64;
18570
18665
  }
18571
18666
  });
18572
18667
 
@@ -18615,7 +18710,7 @@ function accountIds(value) {
18615
18710
  }
18616
18711
  return ids2.map(Number);
18617
18712
  }
18618
- var SHOWN2, command64, preview_default;
18713
+ var SHOWN2, command65, preview_default;
18619
18714
  var init_preview = __esm({
18620
18715
  "src/commands/studio/preview.ts"() {
18621
18716
  "use strict";
@@ -18627,7 +18722,7 @@ var init_preview = __esm({
18627
18722
  init_common4();
18628
18723
  init_folder2();
18629
18724
  SHOWN2 = 5;
18630
- command64 = {
18725
+ command65 = {
18631
18726
  resource: "studio",
18632
18727
  action: "preview",
18633
18728
  summary: "Render a saved version for up to 3 accounts; for local edits, studio push them to the draft first",
@@ -18677,7 +18772,7 @@ var init_preview = __esm({
18677
18772
  return ExitCode.Ok;
18678
18773
  }
18679
18774
  };
18680
- preview_default = command64;
18775
+ preview_default = command65;
18681
18776
  }
18682
18777
  });
18683
18778
 
@@ -18867,18 +18962,18 @@ async function fillChunk(ctx, templateId, target2, wait3, chunk, chunkCtx) {
18867
18962
  }
18868
18963
  return { results: runResults(chunk, run, target2.key) };
18869
18964
  }
18870
- function estimateOutput(templateId, target2, estimate) {
18965
+ function estimateOutput(templateId, target2, estimate2) {
18871
18966
  return {
18872
18967
  templateId,
18873
18968
  ...target2.campaignId !== void 0 ? { campaignId: target2.campaignId } : {},
18874
18969
  [target2.flag]: target2.items.length,
18875
18970
  ...target2.duplicates > 0 ? { duplicates: target2.duplicates } : {},
18876
18971
  runs: Math.ceil(target2.items.length / RUN_SIZE),
18877
- estimate,
18972
+ estimate: estimate2,
18878
18973
  ...target2.campaignId !== void 0 ? { estimateNote: "An upper bound: it counts one page per lead, and a campaign run builds one page per company." } : {}
18879
18974
  };
18880
18975
  }
18881
- var COMMAND6, sha2564, command65, fill_default;
18976
+ var COMMAND6, sha2564, command66, fill_default;
18882
18977
  var init_fill = __esm({
18883
18978
  "src/commands/studio/fill.ts"() {
18884
18979
  "use strict";
@@ -18896,7 +18991,7 @@ var init_fill = __esm({
18896
18991
  init_fill_runs();
18897
18992
  COMMAND6 = "studio fill";
18898
18993
  sha2564 = (data) => createHash10("sha256").update(data).digest("hex");
18899
- command65 = {
18994
+ command66 = {
18900
18995
  resource: "studio",
18901
18996
  action: "fill",
18902
18997
  summary: "Fill a template on many accounts or campaign leads (estimate first)",
@@ -18933,12 +19028,12 @@ var init_fill = __esm({
18933
19028
  const target2 = await readTarget(ctx, flags);
18934
19029
  const batchArgs = { ...flags, positionals };
18935
19030
  if (ctx.flags.yes === true) await refuseRefill(ctx, batchArgs, target2);
18936
- const estimate = await estimateFill(ctx, templateId, target2.items.length);
19031
+ const estimate2 = await estimateFill(ctx, templateId, target2.items.length);
18937
19032
  if (ctx.flags.yes !== true) {
18938
19033
  const next = commandLine2(ctx, COMMAND6, { flags: { ...flags, estimate: void 0 }, positionals }, ["--yes"]);
18939
19034
  const { available, estimateError } = await readAvailable(ctx);
18940
- const credits2 = creditsCheck(estimate.millicredits, available);
18941
- ctx.output.object({ ...estimateOutput(templateId, target2, estimate), credits: credits2, ...estimateError ? { estimateError } : {}, next });
19035
+ const credits3 = creditsCheck(estimate2.millicredits, available);
19036
+ ctx.output.object({ ...estimateOutput(templateId, target2, estimate2), credits: credits3, ...estimateError ? { estimateError } : {}, next });
18942
19037
  return ExitCode.Ok;
18943
19038
  }
18944
19039
  const wait3 = flags.wait === true;
@@ -18956,7 +19051,7 @@ var init_fill = __esm({
18956
19051
  templateId,
18957
19052
  ...target2.campaignId !== void 0 ? { campaignId: target2.campaignId } : {},
18958
19053
  ...target2.duplicates > 0 ? { duplicates: target2.duplicates } : {},
18959
- estimatedMillicredits: estimate.millicredits,
19054
+ estimatedMillicredits: estimate2.millicredits,
18960
19055
  runs: runsOf(results)
18961
19056
  })
18962
19057
  },
@@ -18965,7 +19060,7 @@ var init_fill = __esm({
18965
19060
  return outcome.exitCode;
18966
19061
  }
18967
19062
  };
18968
- fill_default = command65;
19063
+ fill_default = command66;
18969
19064
  }
18970
19065
  });
18971
19066
 
@@ -19072,7 +19167,7 @@ var add_exports2 = {};
19072
19167
  __export(add_exports2, {
19073
19168
  default: () => add_default2
19074
19169
  });
19075
- var NEXT, command66, add_default2;
19170
+ var NEXT, command67, add_default2;
19076
19171
  var init_add2 = __esm({
19077
19172
  "src/commands/tasks/add.ts"() {
19078
19173
  "use strict";
@@ -19082,7 +19177,7 @@ var init_add2 = __esm({
19082
19177
  init_http();
19083
19178
  init_shared2();
19084
19179
  NEXT = 'kenso tasks add "Send the deck" --due tomorrow --account 812';
19085
- command66 = {
19180
+ command67 = {
19086
19181
  resource: "tasks",
19087
19182
  action: "add",
19088
19183
  summary: "Add a task: a title, an optional due day and time, assignee and the account, person or deal it is about",
@@ -19120,7 +19215,7 @@ var init_add2 = __esm({
19120
19215
  return ExitCode.Ok;
19121
19216
  }
19122
19217
  };
19123
- add_default2 = command66;
19218
+ add_default2 = command67;
19124
19219
  }
19125
19220
  });
19126
19221
 
@@ -19157,7 +19252,7 @@ function stoppedAt(error, id, finished, status) {
19157
19252
  details: error.details
19158
19253
  });
19159
19254
  }
19160
- var command67, done_default;
19255
+ var command68, done_default;
19161
19256
  var init_done = __esm({
19162
19257
  "src/commands/tasks/done.ts"() {
19163
19258
  "use strict";
@@ -19166,7 +19261,7 @@ var init_done = __esm({
19166
19261
  init_exit_codes();
19167
19262
  init_http();
19168
19263
  init_shared2();
19169
- command67 = {
19264
+ command68 = {
19170
19265
  resource: "tasks",
19171
19266
  action: "done",
19172
19267
  summary: "Complete one or more tasks (--undo reopens them)",
@@ -19200,7 +19295,7 @@ var init_done = __esm({
19200
19295
  return ExitCode.Ok;
19201
19296
  }
19202
19297
  };
19203
- done_default = command67;
19298
+ done_default = command68;
19204
19299
  }
19205
19300
  });
19206
19301
 
@@ -19209,7 +19304,7 @@ var assign_exports = {};
19209
19304
  __export(assign_exports, {
19210
19305
  default: () => assign_default
19211
19306
  });
19212
- var NEXT2, command68, assign_default;
19307
+ var NEXT2, command69, assign_default;
19213
19308
  var init_assign = __esm({
19214
19309
  "src/commands/tasks/assign.ts"() {
19215
19310
  "use strict";
@@ -19218,7 +19313,7 @@ var init_assign = __esm({
19218
19313
  init_done();
19219
19314
  init_shared2();
19220
19315
  NEXT2 = "kenso tasks assign <taskId> <me|memberId|email>";
19221
- command68 = {
19316
+ command69 = {
19222
19317
  resource: "tasks",
19223
19318
  action: "assign",
19224
19319
  summary: "Give a task to a member",
@@ -19242,7 +19337,7 @@ var init_assign = __esm({
19242
19337
  return ExitCode.Ok;
19243
19338
  }
19244
19339
  };
19245
- assign_default = command68;
19340
+ assign_default = command69;
19246
19341
  }
19247
19342
  });
19248
19343
 
@@ -19251,14 +19346,14 @@ var queue_exports = {};
19251
19346
  __export(queue_exports, {
19252
19347
  default: () => queue_default
19253
19348
  });
19254
- var SCOPES, command69, queue_default;
19349
+ var SCOPES, command70, queue_default;
19255
19350
  var init_queue = __esm({
19256
19351
  "src/commands/tasks/queue.ts"() {
19257
19352
  "use strict";
19258
19353
  init_errors();
19259
19354
  init_exit_codes();
19260
19355
  SCOPES = ["mine", "assigned_by_me", "everyone"];
19261
- command69 = {
19356
+ command70 = {
19262
19357
  resource: "tasks",
19263
19358
  action: "queue",
19264
19359
  summary: "Your open work by due day: tasks, touches, call tasks, reply reminders and Ken follow-ups",
@@ -19280,7 +19375,7 @@ var init_queue = __esm({
19280
19375
  return ExitCode.Ok;
19281
19376
  }
19282
19377
  };
19283
- queue_default = command69;
19378
+ queue_default = command70;
19284
19379
  }
19285
19380
  });
19286
19381
 
@@ -19507,7 +19602,7 @@ async function poll2(ctx, types, cursor2) {
19507
19602
  return unwrap(res.body) ?? {};
19508
19603
  }
19509
19604
  function readBody(req) {
19510
- return new Promise((resolve21, reject) => {
19605
+ return new Promise((resolve22, reject) => {
19511
19606
  let size = 0;
19512
19607
  const chunks = [];
19513
19608
  req.on("data", (chunk) => {
@@ -19515,14 +19610,14 @@ function readBody(req) {
19515
19610
  if (size > MAX_TRIGGER_BYTES) req.destroy(new Error("too large"));
19516
19611
  else chunks.push(chunk);
19517
19612
  });
19518
- req.on("end", () => resolve21(Buffer.concat(chunks).toString("utf8")));
19613
+ req.on("end", () => resolve22(Buffer.concat(chunks).toString("utf8")));
19519
19614
  req.on("error", reject);
19520
19615
  });
19521
19616
  }
19522
19617
  function reply(res, status, body2) {
19523
19618
  res.writeHead(status, { "content-type": "application/json" }).end(JSON.stringify(body2));
19524
19619
  }
19525
- var MIN_POLL_MS, MAX_POLL_MS, MAX_TRIGGER_BYTES, command70, listen_default;
19620
+ var MIN_POLL_MS, MAX_POLL_MS, MAX_TRIGGER_BYTES, command71, listen_default;
19526
19621
  var init_listen = __esm({
19527
19622
  "src/commands/webhooks/listen.ts"() {
19528
19623
  "use strict";
@@ -19533,7 +19628,7 @@ var init_listen = __esm({
19533
19628
  MIN_POLL_MS = 1e3;
19534
19629
  MAX_POLL_MS = 6e4;
19535
19630
  MAX_TRIGGER_BYTES = 1e6;
19536
- command70 = {
19631
+ command71 = {
19537
19632
  resource: "webhooks",
19538
19633
  action: "listen",
19539
19634
  summary: "Stream the workspace's events and forward them, signed, to a local handler",
@@ -19604,7 +19699,7 @@ var init_listen = __esm({
19604
19699
  reply(res, 200, { forward: result ?? null });
19605
19700
  }).catch(() => reply(res, 400, { error: "invalid_event" }));
19606
19701
  });
19607
- await new Promise((resolve21) => server.listen(0, "127.0.0.1", resolve21));
19702
+ await new Promise((resolve22) => server.listen(0, "127.0.0.1", resolve22));
19608
19703
  const url = `http://127.0.0.1:${server.address().port}/events`;
19609
19704
  writeListenerState(ctx.env, workspaceId, { pid: process.pid, url, token, forwardTo: target2, startedAt: (/* @__PURE__ */ new Date()).toISOString() });
19610
19705
  try {
@@ -19640,7 +19735,7 @@ var init_listen = __esm({
19640
19735
  return ExitCode.Ok;
19641
19736
  }
19642
19737
  };
19643
- listen_default = command70;
19738
+ listen_default = command71;
19644
19739
  }
19645
19740
  });
19646
19741
 
@@ -19659,7 +19754,7 @@ function notRunning() {
19659
19754
  next: LISTEN_NEXT
19660
19755
  });
19661
19756
  }
19662
- var LISTEN_NEXT, command71, trigger_default;
19757
+ var LISTEN_NEXT, command72, trigger_default;
19663
19758
  var init_trigger = __esm({
19664
19759
  "src/commands/webhooks/trigger.ts"() {
19665
19760
  "use strict";
@@ -19668,7 +19763,7 @@ var init_trigger = __esm({
19668
19763
  init_http();
19669
19764
  init_local();
19670
19765
  LISTEN_NEXT = "kenso webhooks listen --forward-to http://localhost:3000/hook";
19671
- command71 = {
19766
+ command72 = {
19672
19767
  resource: "webhooks",
19673
19768
  action: "trigger",
19674
19769
  summary: "Send a sample event of one type through the running kenso webhooks listen",
@@ -19726,7 +19821,7 @@ var init_trigger = __esm({
19726
19821
  return ExitCode.Ok;
19727
19822
  }
19728
19823
  };
19729
- trigger_default = command71;
19824
+ trigger_default = command72;
19730
19825
  }
19731
19826
  });
19732
19827
 
@@ -19747,14 +19842,14 @@ var status_exports3 = {};
19747
19842
  __export(status_exports3, {
19748
19843
  default: () => status_default3
19749
19844
  });
19750
- var command72, status_default3;
19845
+ var command73, status_default3;
19751
19846
  var init_status3 = __esm({
19752
19847
  "src/commands/work/status.ts"() {
19753
19848
  "use strict";
19754
19849
  init_exit_codes();
19755
19850
  init_http();
19756
19851
  init_common2();
19757
- command72 = {
19852
+ command73 = {
19758
19853
  resource: "work",
19759
19854
  action: "status",
19760
19855
  summary: "Show the Kenso AI work waiting for your own agent, per kind",
@@ -19789,7 +19884,7 @@ var init_status3 = __esm({
19789
19884
  return ExitCode.Ok;
19790
19885
  }
19791
19886
  };
19792
- status_default3 = command72;
19887
+ status_default3 = command73;
19793
19888
  }
19794
19889
  });
19795
19890
 
@@ -19921,9 +20016,9 @@ var init_files = __esm({
19921
20016
  import { execFile, spawnSync as spawnSync2 } from "node:child_process";
19922
20017
  import { readFileSync as readFileSync18 } from "node:fs";
19923
20018
  import { isAbsolute as isAbsolute2 } from "node:path";
19924
- function sudoArgs(user, command87, args, keep = [], set2 = {}) {
20019
+ function sudoArgs(user, command89, args, keep = [], set2 = {}) {
19925
20020
  const assignments = Object.entries(set2).map(([name, value]) => `${name}=${value}`);
19926
- return ["-n", "-u", user, "-H", ...keep.length > 0 ? [`--preserve-env=${keep.join(",")}`] : [], ...assignments, "--", command87, ...args];
20021
+ return ["-n", "-u", user, "-H", ...keep.length > 0 ? [`--preserve-env=${keep.join(",")}`] : [], ...assignments, "--", command89, ...args];
19927
20022
  }
19928
20023
  function agentKensoEnv(opts) {
19929
20024
  return {
@@ -19933,16 +20028,16 @@ function agentKensoEnv(opts) {
19933
20028
  AI_AGENT: opts.agentName
19934
20029
  };
19935
20030
  }
19936
- function sudoExec(user, command87, args, opts = {}) {
20031
+ function sudoExec(user, command89, args, opts = {}) {
19937
20032
  const [sudo = "/usr/bin/sudo", ...lead] = user.sudo;
19938
- return new Promise((resolve21) => {
20033
+ return new Promise((resolve22) => {
19939
20034
  execFile(
19940
20035
  sudo,
19941
- [...lead, ...sudoArgs(user.name, command87, args)],
20036
+ [...lead, ...sudoArgs(user.name, command89, args)],
19942
20037
  { env: { PATH: SUDO_PATH }, cwd: "/", timeout: opts.timeoutMs ?? PROBE_TIMEOUT_MS, maxBuffer: opts.maxBuffer ?? 1024 * 1024, encoding: "utf8", windowsHide: true, shell: false },
19943
20038
  (err, stdout, stderr) => {
19944
20039
  const code = err ? err.code : 0;
19945
- resolve21({ exitCode: typeof code === "number" ? code : null, stdout, stderr });
20040
+ resolve22({ exitCode: typeof code === "number" ? code : null, stdout, stderr });
19946
20041
  }
19947
20042
  );
19948
20043
  });
@@ -20048,9 +20143,9 @@ var init_folder3 = __esm({
20048
20143
  init_redact();
20049
20144
  init_agent_user();
20050
20145
  WorkRunFolder = class {
20051
- constructor(ctx, command87, args, outDir, shared = false) {
20146
+ constructor(ctx, command89, args, outDir, shared = false) {
20052
20147
  this.ctx = ctx;
20053
- this.command = command87;
20148
+ this.command = command89;
20054
20149
  this.args = args;
20055
20150
  this.outDir = outDir;
20056
20151
  this.shared = shared;
@@ -20165,7 +20260,7 @@ var pull_exports2 = {};
20165
20260
  __export(pull_exports2, {
20166
20261
  default: () => pull_default2
20167
20262
  });
20168
- var MAX_FILES, command73, pull_default2;
20263
+ var MAX_FILES, command74, pull_default2;
20169
20264
  var init_pull2 = __esm({
20170
20265
  "src/commands/work/pull.ts"() {
20171
20266
  "use strict";
@@ -20174,7 +20269,7 @@ var init_pull2 = __esm({
20174
20269
  init_common2();
20175
20270
  init_folder3();
20176
20271
  MAX_FILES = 100;
20177
- command73 = {
20272
+ command74 = {
20178
20273
  resource: "work",
20179
20274
  action: "pull",
20180
20275
  summary: "Claim waiting work into local work files, to answer by hand",
@@ -20253,7 +20348,7 @@ var init_pull2 = __esm({
20253
20348
  return interrupted7 ? ExitCode.Interrupted : ExitCode.Ok;
20254
20349
  }
20255
20350
  };
20256
- pull_default2 = command73;
20351
+ pull_default2 = command74;
20257
20352
  }
20258
20353
  });
20259
20354
 
@@ -20395,7 +20490,7 @@ __export(submit_exports, {
20395
20490
  default: () => submit_default
20396
20491
  });
20397
20492
  import { resolve as resolve17 } from "node:path";
20398
- var command74, submit_default;
20493
+ var command75, submit_default;
20399
20494
  var init_submit = __esm({
20400
20495
  "src/commands/work/submit.ts"() {
20401
20496
  "use strict";
@@ -20404,7 +20499,7 @@ var init_submit = __esm({
20404
20499
  init_files();
20405
20500
  init_answers();
20406
20501
  init_common2();
20407
- command74 = {
20502
+ command75 = {
20408
20503
  resource: "work",
20409
20504
  action: "submit",
20410
20505
  summary: "Send answers files to Kenso and write each one's results",
@@ -20437,7 +20532,7 @@ var init_submit = __esm({
20437
20532
  return totals.rejected > 0 ? ExitCode.Partial : ExitCode.Ok;
20438
20533
  }
20439
20534
  };
20440
- submit_default = command74;
20535
+ submit_default = command75;
20441
20536
  }
20442
20537
  });
20443
20538
 
@@ -20458,7 +20553,7 @@ function claimIdOf(arg) {
20458
20553
  if (!CLAIM_ID.test(arg)) throw usageError(`"${arg}" is neither a claim id nor a work file.`, { field: "claim", hint: "Claim ids look like awc_8fK2..." });
20459
20554
  return arg;
20460
20555
  }
20461
- var CLAIM_ID, command75, release_default;
20556
+ var CLAIM_ID, command76, release_default;
20462
20557
  var init_release = __esm({
20463
20558
  "src/commands/work/release.ts"() {
20464
20559
  "use strict";
@@ -20467,7 +20562,7 @@ var init_release = __esm({
20467
20562
  init_files();
20468
20563
  init_common2();
20469
20564
  CLAIM_ID = /^[A-Za-z0-9_-]{1,64}$/;
20470
- command75 = {
20565
+ command76 = {
20471
20566
  resource: "work",
20472
20567
  action: "release",
20473
20568
  summary: "Give claimed work back to the queue now",
@@ -20487,7 +20582,7 @@ var init_release = __esm({
20487
20582
  return ExitCode.Ok;
20488
20583
  }
20489
20584
  };
20490
- release_default = command75;
20585
+ release_default = command76;
20491
20586
  }
20492
20587
  });
20493
20588
 
@@ -20601,7 +20696,7 @@ async function groupGone(pid, runAs) {
20601
20696
  }
20602
20697
  }
20603
20698
  function runChild(spawnFn, bin, built, job, env, signal, runAs) {
20604
- return new Promise((resolve21) => {
20699
+ return new Promise((resolve22) => {
20605
20700
  const stdout = new Tail(OUTPUT_CAP_BYTES);
20606
20701
  const stderr = new Tail(OUTPUT_CAP_BYTES);
20607
20702
  let child;
@@ -20616,7 +20711,7 @@ function runChild(spawnFn, bin, built, job, env, signal, runAs) {
20616
20711
  shell: false
20617
20712
  });
20618
20713
  } catch (err) {
20619
- resolve21({ exitCode: null, stdout: "", stderr: "", spawnError: err });
20714
+ resolve22({ exitCode: null, stdout: "", stderr: "", spawnError: err });
20620
20715
  return;
20621
20716
  }
20622
20717
  let stopped;
@@ -20634,7 +20729,7 @@ function runChild(spawnFn, bin, built, job, env, signal, runAs) {
20634
20729
  signal?.removeEventListener("abort", onAbort);
20635
20730
  void groupGone(pid, runAs).then(() => {
20636
20731
  if (pid !== void 0) liveGroups.delete(pid);
20637
- resolve21({ exitCode, stdout: stdout.text(), stderr: stderr.text(), stopped, spawnError });
20732
+ resolve22({ exitCode, stdout: stdout.text(), stderr: stderr.text(), stopped, spawnError });
20638
20733
  });
20639
20734
  };
20640
20735
  const stop = (why) => {
@@ -20826,25 +20921,25 @@ function plain(text4) {
20826
20921
  return text4.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "");
20827
20922
  }
20828
20923
  function runStatus(bin, args, env, adapter, runAs) {
20829
- const command87 = runAs ? runAs.sudo[0] ?? "/usr/bin/sudo" : bin;
20924
+ const command89 = runAs ? runAs.sudo[0] ?? "/usr/bin/sudo" : bin;
20830
20925
  const commandArgs2 = runAs ? [...runAs.sudo.slice(1), ...sudoArgs(runAs.name, bin, args)] : args;
20831
20926
  const options = runAs ? { env: { PATH: SUDO_PATH }, cwd: "/" } : { env: childEnv(env, adapter) };
20832
- return new Promise((resolve21) => {
20927
+ return new Promise((resolve22) => {
20833
20928
  execFile2(
20834
- command87,
20929
+ command89,
20835
20930
  commandArgs2,
20836
20931
  { ...options, timeout: STATUS_TIMEOUT_MS, maxBuffer: 1024 * 1024, windowsHide: true, shell: false },
20837
20932
  (err, stdout, stderr) => {
20838
20933
  if (err && typeof err.code === "string") {
20839
- resolve21(void 0);
20934
+ resolve22(void 0);
20840
20935
  return;
20841
20936
  }
20842
20937
  if (err && err.killed) {
20843
- resolve21(void 0);
20938
+ resolve22(void 0);
20844
20939
  return;
20845
20940
  }
20846
20941
  const exitCode = err ? err.code ?? null : 0;
20847
- resolve21({ exitCode: typeof exitCode === "number" ? exitCode : null, stdout: plain(String(stdout)), stderr: plain(String(stderr)) });
20942
+ resolve22({ exitCode: typeof exitCode === "number" ? exitCode : null, stdout: plain(String(stdout)), stderr: plain(String(stderr)) });
20848
20943
  }
20849
20944
  );
20850
20945
  });
@@ -21626,7 +21721,7 @@ var init_instruction = __esm({
21626
21721
  // src/work/pool.ts
21627
21722
  function runPool(opts) {
21628
21723
  const limit = Math.min(MAX_PARALLEL, Math.max(1, Math.floor(Number.isFinite(opts.parallel) ? opts.parallel : 1)));
21629
- return new Promise((resolve21, reject) => {
21724
+ return new Promise((resolve22, reject) => {
21630
21725
  let running = 0;
21631
21726
  let filling = false;
21632
21727
  let again = false;
@@ -21666,7 +21761,7 @@ function runPool(opts) {
21666
21761
  const stopping = empty || failure !== void 0 || opts.signal?.aborted === true;
21667
21762
  if (stopping && running === 0 && !again) {
21668
21763
  if (failure) reject(failure.error);
21669
- else resolve21();
21764
+ else resolve22();
21670
21765
  return;
21671
21766
  }
21672
21767
  } while (again);
@@ -21913,7 +22008,7 @@ var run_exports3 = {};
21913
22008
  __export(run_exports3, {
21914
22009
  default: () => run_default2
21915
22010
  });
21916
- var FAILURES_IN_A_ROW, command76, run_default2;
22011
+ var FAILURES_IN_A_ROW, command77, run_default2;
21917
22012
  var init_run3 = __esm({
21918
22013
  "src/commands/work/run.ts"() {
21919
22014
  "use strict";
@@ -21934,7 +22029,7 @@ var init_run3 = __esm({
21934
22029
  init_folder3();
21935
22030
  init_stop();
21936
22031
  FAILURES_IN_A_ROW = 3;
21937
- command76 = {
22032
+ command77 = {
21938
22033
  resource: "work",
21939
22034
  action: "run",
21940
22035
  summary: "Run your own coding agent on the waiting work until the queue is empty",
@@ -22260,7 +22355,7 @@ var init_run3 = __esm({
22260
22355
  return exitCodeFor(reason, totals.rejected > 0 || jobsFailed > 0);
22261
22356
  }
22262
22357
  };
22263
- run_default2 = command76;
22358
+ run_default2 = command77;
22264
22359
  }
22265
22360
  });
22266
22361
 
@@ -22384,6 +22479,11 @@ async function getVersion(ctx, workflowId, number) {
22384
22479
  const res = await ctx.client.request({ method: "GET", path: `/v1/workflows/${workflowId}/versions/${number}`, signal: ctx.signal });
22385
22480
  return unwrap(res.body) ?? {};
22386
22481
  }
22482
+ async function publishedDefinition(ctx, workflow) {
22483
+ const number = workflow.published?.number;
22484
+ if (typeof number !== "number") return void 0;
22485
+ return (await getVersion(ctx, workflow.id, number)).definition ?? void 0;
22486
+ }
22387
22487
  function sortKeys(value) {
22388
22488
  if (Array.isArray(value)) return value.map(sortKeys);
22389
22489
  if (value !== null && typeof value === "object") {
@@ -22421,7 +22521,7 @@ __export(init_exports, {
22421
22521
  });
22422
22522
  import { existsSync as existsSync13 } from "node:fs";
22423
22523
  import { join as join31, resolve as resolve20 } from "node:path";
22424
- var STEM, command77, init_default;
22524
+ var STEM, command78, init_default;
22425
22525
  var init_init = __esm({
22426
22526
  "src/commands/workflows/init.ts"() {
22427
22527
  "use strict";
@@ -22431,7 +22531,7 @@ var init_init = __esm({
22431
22531
  init_http();
22432
22532
  init_files2();
22433
22533
  STEM = /^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;
22434
- command77 = {
22534
+ command78 = {
22435
22535
  resource: "workflows",
22436
22536
  action: "init",
22437
22537
  summary: "Start a workflow file in this folder",
@@ -22487,7 +22587,7 @@ var init_init = __esm({
22487
22587
  return ExitCode.Ok;
22488
22588
  }
22489
22589
  };
22490
- init_default = command77;
22590
+ init_default = command78;
22491
22591
  }
22492
22592
  });
22493
22593
 
@@ -22500,7 +22600,7 @@ import { existsSync as existsSync14 } from "node:fs";
22500
22600
  function slugOf(name) {
22501
22601
  return name.normalize("NFKD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60).replace(/-+$/, "");
22502
22602
  }
22503
- var command78, pull_default3;
22603
+ var command79, pull_default3;
22504
22604
  var init_pull3 = __esm({
22505
22605
  "src/commands/workflows/pull.ts"() {
22506
22606
  "use strict";
@@ -22508,7 +22608,7 @@ var init_pull3 = __esm({
22508
22608
  init_exit_codes();
22509
22609
  init_common4();
22510
22610
  init_files2();
22511
- command78 = {
22611
+ command79 = {
22512
22612
  resource: "workflows",
22513
22613
  action: "pull",
22514
22614
  summary: "Write a workflow's definition to a file and bind it",
@@ -22567,7 +22667,7 @@ var init_pull3 = __esm({
22567
22667
  return ExitCode.Ok;
22568
22668
  }
22569
22669
  };
22570
- pull_default3 = command78;
22670
+ pull_default3 = command79;
22571
22671
  }
22572
22672
  });
22573
22673
 
@@ -22592,15 +22692,15 @@ function boundFile(ctx, file, action) {
22592
22692
  function currentHash(workflow) {
22593
22693
  return (workflow.draft ?? workflow.published)?.definitionHash ?? void 0;
22594
22694
  }
22595
- function perRecord(estimate) {
22596
- if (estimate === null || typeof estimate !== "object") return null;
22597
- const totals = estimate;
22695
+ function perRecord(estimate2) {
22696
+ if (estimate2 === null || typeof estimate2 !== "object") return null;
22697
+ const totals = estimate2;
22598
22698
  const bulk = totals.bulkPriceApplies === true;
22599
22699
  const expected = bulk ? totals.bulkExpectedMillicredits : totals.expectedMillicredits;
22600
22700
  const max = bulk ? totals.bulkMaxMillicredits : totals.maxMillicredits;
22601
22701
  return typeof expected === "number" && typeof max === "number" ? { expectedCredits: expected / 1e3, maxCredits: max / 1e3 } : null;
22602
22702
  }
22603
- var FILE3, command79, check_default;
22703
+ var FILE3, command80, check_default;
22604
22704
  var init_check = __esm({
22605
22705
  "src/commands/workflows/check.ts"() {
22606
22706
  "use strict";
@@ -22611,7 +22711,7 @@ var init_check = __esm({
22611
22711
  init_columns();
22612
22712
  init_files2();
22613
22713
  FILE3 = { name: "file", required: true, description: "The workflow file (<name>.workflow.json)" };
22614
- command79 = {
22714
+ command80 = {
22615
22715
  resource: "workflows",
22616
22716
  action: "check",
22617
22717
  summary: "Validate a workflow file on the server and print one record's credit estimate",
@@ -22635,7 +22735,7 @@ var init_check = __esm({
22635
22735
  signal: ctx.signal
22636
22736
  });
22637
22737
  const validation = unwrap(validated.body) ?? {};
22638
- const estimate = await workflowEstimate(ctx, { definition: target2.definition, records: 1 });
22738
+ const estimate2 = await workflowEstimate(ctx, { definition: target2.definition, records: 1 });
22639
22739
  const workflow = await getWorkflow(ctx, target2.workflowId);
22640
22740
  const valid = validation.valid === true;
22641
22741
  const inSync = sameDefinition(target2.definition, workflow.definition ?? {});
@@ -22643,8 +22743,8 @@ var init_check = __esm({
22643
22743
  ctx.output.object({
22644
22744
  valid,
22645
22745
  issues: (validation.issues ?? []).map((i) => ({ path: i.path, code: i.code, message: i.message, fix: i.fix ?? null, severity: i.severity })),
22646
- perRecord: perRecord(estimate.estimate),
22647
- ...estimate.estimateError ? { estimateError: estimate.estimateError } : {},
22746
+ perRecord: perRecord(estimate2.estimate),
22747
+ ...estimate2.estimateError ? { estimateError: estimate2.estimateError } : {},
22648
22748
  draftHash: currentHash(workflow) ?? null,
22649
22749
  inSync,
22650
22750
  next: !valid ? nextLine(ctx, "check", file, again) : nextLine(ctx, inSync ? "test" : "push", file)
@@ -22652,7 +22752,7 @@ var init_check = __esm({
22652
22752
  return valid ? ExitCode.Ok : ExitCode.Partial;
22653
22753
  }
22654
22754
  };
22655
- check_default = command79;
22755
+ check_default = command80;
22656
22756
  }
22657
22757
  });
22658
22758
 
@@ -22716,7 +22816,7 @@ function state(workflow, saved, published, extra = {}) {
22716
22816
  ...extra
22717
22817
  };
22718
22818
  }
22719
- var command80, push_default2;
22819
+ var command81, push_default2;
22720
22820
  var init_push2 = __esm({
22721
22821
  "src/commands/workflows/push.ts"() {
22722
22822
  "use strict";
@@ -22726,7 +22826,7 @@ var init_push2 = __esm({
22726
22826
  init_columns();
22727
22827
  init_check();
22728
22828
  init_files2();
22729
- command80 = {
22829
+ command81 = {
22730
22830
  resource: "workflows",
22731
22831
  action: "push",
22732
22832
  summary: "Save a workflow file as the workflow's draft, and publish it with --publish",
@@ -22830,7 +22930,7 @@ var init_push2 = __esm({
22830
22930
  return ExitCode.Ok;
22831
22931
  }
22832
22932
  };
22833
- push_default2 = command80;
22933
+ push_default2 = command81;
22834
22934
  }
22835
22935
  });
22836
22936
 
@@ -22843,8 +22943,8 @@ function recordOf(value) {
22843
22943
  if (value === void 0) return void 0;
22844
22944
  const at = value.indexOf(":");
22845
22945
  const record3 = { type: value.slice(0, Math.max(at, 0)), id: value.slice(at + 1).trim() };
22846
- if (at < 0 || !RECORD_TYPES.includes(record3.type) || record3.id === "") {
22847
- throw usageError(`--record is <type>:<id>, with type ${RECORD_TYPES.join(", ")} (got "${value}").`, { field: "record" });
22946
+ if (at < 0 || !RECORD_TYPES2.includes(record3.type) || record3.id === "") {
22947
+ throw usageError(`--record is <type>:<id>, with type ${RECORD_TYPES2.join(", ")} (got "${value}").`, { field: "record" });
22848
22948
  }
22849
22949
  return record3;
22850
22950
  }
@@ -22863,7 +22963,7 @@ async function startTest(ctx, workflowId, body2) {
22863
22963
  });
22864
22964
  }
22865
22965
  }
22866
- var RECORD_TYPES, MAX_WAIT_SECONDS, command81, test_default;
22966
+ var RECORD_TYPES2, MAX_WAIT_SECONDS, command82, test_default;
22867
22967
  var init_test = __esm({
22868
22968
  "src/commands/workflows/test.ts"() {
22869
22969
  "use strict";
@@ -22873,9 +22973,9 @@ var init_test = __esm({
22873
22973
  init_columns();
22874
22974
  init_check();
22875
22975
  init_files2();
22876
- RECORD_TYPES = ["account", "person", "lead", "place"];
22976
+ RECORD_TYPES2 = ["account", "person", "lead", "place"];
22877
22977
  MAX_WAIT_SECONDS = 50;
22878
- command81 = {
22978
+ command82 = {
22879
22979
  resource: "workflows",
22880
22980
  action: "test",
22881
22981
  summary: "Run the saved draft of a workflow file on one record and print the hash to publish with",
@@ -22931,7 +23031,7 @@ var init_test = __esm({
22931
23031
  return passed ? ExitCode.Ok : ExitCode.Error;
22932
23032
  }
22933
23033
  };
22934
- test_default = command81;
23034
+ test_default = command82;
22935
23035
  }
22936
23036
  });
22937
23037
 
@@ -22965,7 +23065,7 @@ function diffDefinitions(from, to) {
22965
23065
  stepsChanged: [...after.keys()].filter((id) => before.has(id) && differs(before.get(id), after.get(id)))
22966
23066
  };
22967
23067
  }
22968
- var command82, diff_default;
23068
+ var command83, diff_default;
22969
23069
  var init_diff = __esm({
22970
23070
  "src/commands/workflows/diff.ts"() {
22971
23071
  "use strict";
@@ -22974,7 +23074,7 @@ var init_diff = __esm({
22974
23074
  init_columns();
22975
23075
  init_check();
22976
23076
  init_files2();
22977
- command82 = {
23077
+ command83 = {
22978
23078
  resource: "workflows",
22979
23079
  action: "diff",
22980
23080
  summary: "Compare a workflow file with the published version or the draft",
@@ -23002,18 +23102,7 @@ var init_diff = __esm({
23002
23102
  return ExitCode.Ok;
23003
23103
  }
23004
23104
  };
23005
- diff_default = command82;
23006
- }
23007
- });
23008
-
23009
- // src/core/step-types.ts
23010
- function loadStepTypes() {
23011
- return readDataFile("step-types.json")?.stepTypes ?? [];
23012
- }
23013
- var init_step_types = __esm({
23014
- "src/core/step-types.ts"() {
23015
- "use strict";
23016
- init_data();
23105
+ diff_default = command83;
23017
23106
  }
23018
23107
  });
23019
23108
 
@@ -23097,7 +23186,7 @@ function workflowFileSchema(stepTypes) {
23097
23186
  }
23098
23187
  };
23099
23188
  }
23100
- var SCHEMA_ID, STEP_ID, MORE_THAN_ZERO, command83, schema_default;
23189
+ var SCHEMA_ID, STEP_ID, MORE_THAN_ZERO, command84, schema_default;
23101
23190
  var init_schema = __esm({
23102
23191
  "src/commands/workflows/schema.ts"() {
23103
23192
  "use strict";
@@ -23108,7 +23197,7 @@ var init_schema = __esm({
23108
23197
  SCHEMA_ID = "https://ken.so/schemas/workflow-file.json";
23109
23198
  STEP_ID = "^[a-z][a-z0-9_]{0,39}$";
23110
23199
  MORE_THAN_ZERO = { type: "number", exclusiveMinimum: 0 };
23111
- command83 = {
23200
+ command84 = {
23112
23201
  resource: "workflows",
23113
23202
  action: "schema",
23114
23203
  summary: "Print a JSON Schema for workflow files, for editors",
@@ -23134,7 +23223,7 @@ var init_schema = __esm({
23134
23223
  return ExitCode.Ok;
23135
23224
  }
23136
23225
  };
23137
- schema_default = command83;
23226
+ schema_default = command84;
23138
23227
  }
23139
23228
  });
23140
23229
 
@@ -23155,12 +23244,542 @@ var init_file_actions = __esm({
23155
23244
  }
23156
23245
  });
23157
23246
 
23247
+ // src/commands/workflows/run-cap.ts
23248
+ function credits2(value) {
23249
+ return Math.round(value * 1e3) / 1e3;
23250
+ }
23251
+ function maxCreditsOf(value) {
23252
+ if (value === void 0) return void 0;
23253
+ const number = typeof value === "string" && value.trim() !== "" ? Number(value) : Number.NaN;
23254
+ if (!Number.isFinite(number) || number <= 0) {
23255
+ throw usageError(`--max-credits must be a number above 0 (got "${String(value)}").`, { field: "max-credits" });
23256
+ }
23257
+ return number;
23258
+ }
23259
+ function hardCeiling(definition) {
23260
+ const value = definition?.limits?.creditsPerRun;
23261
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
23262
+ }
23263
+ function planCap(maxCredits, records, kind, ceiling, retry) {
23264
+ const willStart = ceiling <= 0 ? records : Math.min(records, Math.floor(maxCredits / ceiling + 1e-9));
23265
+ if (willStart === 0 && records > 0) {
23266
+ const smallest = Math.ceil(ceiling * 1e3) / 1e3;
23267
+ throw new KensoError({
23268
+ code: "cap_too_low",
23269
+ message: `--max-credits ${maxCredits} is below one record's ceiling of ${smallest} credits, so nothing would start.`,
23270
+ exitCode: ExitCode.RateLimited,
23271
+ field: "max-credits",
23272
+ next: retry(smallest)
23273
+ });
23274
+ }
23275
+ return { maxCredits, kind, perRecord: credits2(ceiling), willStart, notStarted: records - willStart };
23276
+ }
23277
+ var init_run_cap = __esm({
23278
+ "src/commands/workflows/run-cap.ts"() {
23279
+ "use strict";
23280
+ init_errors();
23281
+ init_exit_codes();
23282
+ }
23283
+ });
23284
+
23285
+ // src/commands/workflows/run-input.ts
23286
+ import { createHash as createHash12 } from "node:crypto";
23287
+ import { resolve as resolve21 } from "node:path";
23288
+ import { Readable as Readable2 } from "node:stream";
23289
+ function validId(id, type) {
23290
+ return type === "place" ? /^plc_[A-Za-z0-9_-]+$/.test(id) : /^[1-9]\d*$/.test(id);
23291
+ }
23292
+ function fromIds(ctx, raw, type) {
23293
+ const records = [];
23294
+ const invalid2 = [];
23295
+ const seen = /* @__PURE__ */ new Set();
23296
+ let repeats = 0;
23297
+ raw.forEach((id, i) => {
23298
+ const row = i + 1;
23299
+ if (!validId(id, type)) {
23300
+ invalid2.push({ row, status: "invalid", reason: "invalid_id", error: `"${id}" is not ${type === "place" ? "a place id (plc_...)" : `a ${type} id`}.` });
23301
+ } else if (seen.has(id)) {
23302
+ repeats++;
23303
+ } else {
23304
+ seen.add(id);
23305
+ records.push({ row, id });
23306
+ }
23307
+ });
23308
+ if (repeats > 0) ctx.output.warn(`${repeats} repeated id${repeats === 1 ? "" : "s"} left out: each record runs once.`);
23309
+ return { people: false, records, invalid: invalid2 };
23310
+ }
23311
+ async function readRunInput(ctx, opts) {
23312
+ const type = opts.recordType;
23313
+ if (opts.ids === "-") {
23314
+ const text4 = await readStream(ctx.stdin ?? process.stdin);
23315
+ const ids2 = await readIds("-", { stdin: Readable2.from([text4]) });
23316
+ return { input: { path: "-", sha256: createHash12("sha256").update(text4).digest("hex") }, ...fromIds(ctx, ids2, type) };
23317
+ }
23318
+ if (opts.ids !== void 0) {
23319
+ return { input: { path: resolve21(opts.ids), sha256: await fileSha256(opts.ids) }, ...fromIds(ctx, await readIds(opts.ids), type) };
23320
+ }
23321
+ const name = opts.file ?? "";
23322
+ const file = await readInput(name, { stdin: ctx.stdin });
23323
+ const input = { path: file.path, sha256: file.sha256 };
23324
+ const idColumn = file.headers.find((header) => header.trim().toLowerCase() === "id");
23325
+ if (idColumn !== void 0) {
23326
+ return { input, ...fromIds(ctx, file.rows.map((row) => String(row[idColumn] ?? "").trim()), type) };
23327
+ }
23328
+ if (type !== "person") {
23329
+ const importer = IMPORT_COMMANDS[type];
23330
+ throw new KensoError({
23331
+ code: "ids_required",
23332
+ message: `${name} has no id column, and only people can be matched from a file: a run on ${type} records needs their ids.`,
23333
+ exitCode: ExitCode.Usage,
23334
+ field: "file",
23335
+ hint: importer ? `${importer} creates the records and prints their ids.` : "Pass the ids with --ids, one per line.",
23336
+ ...importer ? { next: `${importer} --help` } : {}
23337
+ });
23338
+ }
23339
+ const columns2 = mapColumns(file.headers, ALIASES3);
23340
+ const records = [];
23341
+ const invalid2 = [];
23342
+ file.rows.forEach((row, i) => {
23343
+ try {
23344
+ records.push({ row: i + 1, person: toBody2(row, columns2) });
23345
+ } catch (err) {
23346
+ if (!(err instanceof RowInvalid)) throw err;
23347
+ invalid2.push({ row: i + 1, status: "invalid", reason: err.reason, error: err.message });
23348
+ }
23349
+ });
23350
+ return { input, people: true, records, invalid: invalid2 };
23351
+ }
23352
+ async function matchPeople(ctx, records) {
23353
+ const matched = [];
23354
+ const invalid2 = [];
23355
+ const seen = /* @__PURE__ */ new Set();
23356
+ for (let at = 0; at < records.length; at += PEOPLE_CHUNK) {
23357
+ const chunk = records.slice(at, at + PEOPLE_CHUNK);
23358
+ const res = await ctx.client.request({
23359
+ method: "POST",
23360
+ path: "/v1/people/batch",
23361
+ body: { rows: chunk.map((record3) => record3.person) },
23362
+ retrySafe: true,
23363
+ signal: ctx.signal
23364
+ });
23365
+ const byIndex = new Map((unwrap(res.body)?.results ?? []).map((result) => [result.index, result]));
23366
+ chunk.forEach((record3, index2) => {
23367
+ const saved = byIndex.get(index2);
23368
+ const id = saved?.personId !== void 0 && saved.personId !== null ? String(saved.personId) : void 0;
23369
+ if (id === void 0) {
23370
+ invalid2.push({ row: record3.row, status: "invalid", reason: saved?.reason || "person_not_saved", error: saved?.error || "The API saved no person for this row." });
23371
+ } else if (!seen.has(id)) {
23372
+ seen.add(id);
23373
+ matched.push({ row: record3.row, id });
23374
+ }
23375
+ });
23376
+ }
23377
+ return { records: matched, invalid: invalid2 };
23378
+ }
23379
+ var RECORD_TYPES3, PEOPLE_CHUNK, IMPORT_COMMANDS;
23380
+ var init_run_input = __esm({
23381
+ "src/commands/workflows/run-input.ts"() {
23382
+ "use strict";
23383
+ init_input2();
23384
+ init_errors();
23385
+ init_exit_codes();
23386
+ init_http();
23387
+ init_input();
23388
+ init_common();
23389
+ init_columns();
23390
+ init_import5();
23391
+ RECORD_TYPES3 = ["account", "person", "lead", "place"];
23392
+ PEOPLE_CHUNK = 200;
23393
+ IMPORT_COMMANDS = { lead: "kenso contacts import", account: "kenso accounts import" };
23394
+ }
23395
+ });
23396
+
23397
+ // src/commands/workflows/run-start.ts
23398
+ import { readFileSync as readFileSync21 } from "node:fs";
23399
+ import { unlink as unlink4 } from "node:fs/promises";
23400
+ import { join as join32 } from "node:path";
23401
+ function readJournal(file) {
23402
+ try {
23403
+ return JSON.parse(readFileSync21(file, "utf8"));
23404
+ } catch {
23405
+ return void 0;
23406
+ }
23407
+ }
23408
+ function unknownOutcome(workflowId, journal) {
23409
+ return {
23410
+ exitCode: ExitCode.Partial,
23411
+ code: "chunk_outcome_unknown",
23412
+ message: `Rows ${journal.firstRow} to ${journal.lastRow} were sent at ${journal.sentAt} and no answer was recorded, so they are not sent again.`,
23413
+ next: `kenso workflow-runs list --workflow-id ${workflowId} --created-after ${journal.sentAt}`
23414
+ };
23415
+ }
23416
+ function answeredJournals(run, workflowId) {
23417
+ if (run.status === "running" && isOtherLiveProcess(run.pid)) {
23418
+ const { runId, pid } = run;
23419
+ throw new KensoError({ code: "run_in_progress", message: `Run ${runId} on this input is running in process ${pid}.`, exitCode: ExitCode.Conflict, next: `kenso runs show ${runId}` });
23420
+ }
23421
+ const journals = [];
23422
+ for (let index2 = 0; index2 < run.chunkCount; index2++) {
23423
+ const journal = readJournal(journalFile(run.dir, index2));
23424
+ if (journal && journal.response === void 0) throw new KensoError(unknownOutcome(workflowId, journal));
23425
+ if (journal) journals.push(journal);
23426
+ }
23427
+ return journals;
23428
+ }
23429
+ async function earlierRun(ctx, args, sha2565, workflowId) {
23430
+ const earlier = (await findIdentical(COMMAND7, args, sha2565, ctx.env, ctx.client.workspaceId ?? ctx.auth.workspaceId)).filter((run) => run.status !== "planned");
23431
+ const open2 = earlier.find((run) => run.status !== "done");
23432
+ if (open2) {
23433
+ answeredJournals(open2, workflowId);
23434
+ return void 0;
23435
+ }
23436
+ const done2 = earlier[0];
23437
+ if (!done2) return void 0;
23438
+ const summary = readSummary(filesOf(done2.dir).summaryJson) ?? { run: done2.runId };
23439
+ ctx.output.info(`Run ${done2.runId} already finished on this input, so nothing was started again. To run the same records again, pass a changed input file.`);
23440
+ ctx.output.summary({ ...summary, alreadyDone: true });
23441
+ return Number(summary.notStarted ?? 0) + Number(summary.failed ?? 0) > 0 ? ExitCode.Partial : ExitCode.Ok;
23442
+ }
23443
+ async function refuseRestart(ctx, run) {
23444
+ const loose = (args) => argsIdentity({ ...args, "max-credits": void 0 });
23445
+ const workspaceId = ctx.client.workspaceId ?? ctx.auth.workspaceId;
23446
+ const itemsSha256 = hashItems(run.items);
23447
+ for (const earlier of await listRuns(ctx.env)) {
23448
+ if (earlier.command !== COMMAND7 || earlier.status === "planned" || earlier.inputSha256 !== run.sha256 || loose(earlier.args) !== loose(run.args)) continue;
23449
+ if ((earlier.workspaceId || void 0) !== (workspaceId || void 0)) continue;
23450
+ if (earlier.status !== "done" && argsIdentity(earlier.args) === argsIdentity(run.args) && (earlier.itemsSha256 ?? itemsSha256) === itemsSha256) continue;
23451
+ const sent = /* @__PURE__ */ new Set();
23452
+ for (const journal of answeredJournals(earlier, run.workflowId)) for (const item of run.items) if (item.row >= journal.firstRow && item.row <= journal.lastRow) sent.add(item.row);
23453
+ for (const [row, { status }] of await readResults(filesOf(earlier.dir).resultsNdjson)) if (!["not_started", "invalid"].includes(status)) sent.add(row);
23454
+ if (sent.size === 0) continue;
23455
+ const rest = run.items.filter((item) => !sent.has(item.row));
23456
+ const file = join32(earlier.dir, "not-started.txt");
23457
+ if (rest.length > 0) await writeFileAtomic(file, rest.map((item) => `${item.id}
23458
+ `).join(""));
23459
+ throw new KensoError({
23460
+ code: "already_started",
23461
+ message: `Run ${earlier.runId} already sent starts for ${sent.size} records of this input, so this run would start them twice.`,
23462
+ exitCode: ExitCode.Conflict,
23463
+ hint: rest.length > 0 ? `${file} holds the ${rest.length} ids that run did not start; next runs only those.` : "That run sent every record of this input.",
23464
+ next: rest.length > 0 ? run.rerun(file) : `kenso workflow-runs list --workflow-id ${run.workflowId}`
23465
+ });
23466
+ }
23467
+ }
23468
+ async function startChunk(chunk, cc, run) {
23469
+ const held = notStarted(chunk.filter((item) => !run.start.has(item.row)), "over --max-credits");
23470
+ const starters = chunk.filter((item) => run.start.has(item.row));
23471
+ if (starters.length === 0) return { results: held };
23472
+ const file = journalFile(run.dirOf(cc.runId), cc.chunkIndex);
23473
+ const stopOn = (sent) => {
23474
+ const { next, ...stop } = unknownOutcome(run.workflowId, sent);
23475
+ return { results: held, stop: { ...stop, hint: `See what started: ${next}` } };
23476
+ };
23477
+ let journal = readJournal(file);
23478
+ let remaining;
23479
+ if (journal?.response === void 0) {
23480
+ if (journal) return stopOn(journal);
23481
+ const sent = { sentAt: (/* @__PURE__ */ new Date()).toISOString(), firstRow: starters[0].row, lastRow: starters[starters.length - 1].row };
23482
+ await writeJsonAtomic(file, sent);
23483
+ try {
23484
+ const res = await cc.client.request({
23485
+ method: "POST",
23486
+ path: `/v1/workflows/${run.workflowId}/runs`,
23487
+ body: { records: starters.map(({ type, id }) => ({ type, id })) },
23488
+ signal: cc.signal
23489
+ });
23490
+ journal = { ...sent, response: unwrap(res.body) ?? {} };
23491
+ await writeJsonAtomic(file, journal);
23492
+ remaining = rateLimitRemaining2(res.headers);
23493
+ } catch (err) {
23494
+ const error = err instanceof KensoError ? err : void 0;
23495
+ if (error?.httpStatus !== void 0 && error.httpStatus < 500) {
23496
+ await unlink4(file).catch(() => void 0);
23497
+ const exitCode = error.httpStatus === 402 ? ExitCode.RateLimited : error.exitCode;
23498
+ const stop = { exitCode, code: error.code, message: error.message, ...error.hint ? { hint: error.hint } : {} };
23499
+ return { results: [...notStarted(starters, error.code), ...held], stop };
23500
+ }
23501
+ if (cc.signal.aborted || error?.exitCode === ExitCode.Interrupted) throw err;
23502
+ return stopOn(sent);
23503
+ }
23504
+ }
23505
+ const answers = journal.response?.results ?? [];
23506
+ const results = starters.map((item, i) => {
23507
+ const answer = answers[i];
23508
+ return {
23509
+ row: item.row,
23510
+ id: item.id,
23511
+ // The API's own status: started, deduplicated, over_limit, not_live, not_found or failed.
23512
+ status: answer?.status ?? "failed",
23513
+ ...answer?.runId !== void 0 && answer.runId !== null ? { runId: answer.runId } : {},
23514
+ ...answer?.status ? {} : { reason: "no_result" }
23515
+ };
23516
+ });
23517
+ return { results: [...results, ...held], rateLimitRemaining: remaining };
23518
+ }
23519
+ var COMMAND7, journalFile, notStarted;
23520
+ var init_run_start = __esm({
23521
+ "src/commands/workflows/run-start.ts"() {
23522
+ "use strict";
23523
+ init_results();
23524
+ init_runs();
23525
+ init_errors();
23526
+ init_exit_codes();
23527
+ init_http();
23528
+ init_columns();
23529
+ COMMAND7 = "workflows run";
23530
+ journalFile = (dir3, index2) => join32(dir3, `chunk-${index2}.json`);
23531
+ notStarted = (items, reason) => items.map((item) => ({ row: item.row, ...item.id ? { id: item.id } : {}, status: "not_started", reason }));
23532
+ }
23533
+ });
23534
+
23535
+ // src/commands/workflows/run.ts
23536
+ var run_exports4 = {};
23537
+ __export(run_exports4, {
23538
+ default: () => run_default3
23539
+ });
23540
+ import { join as join33 } from "node:path";
23541
+ async function resolveTarget(ctx, target2) {
23542
+ const isId = /^[1-9]\d*$/.test(target2);
23543
+ const file = isId ? void 0 : readWorkflowFile(target2).definition;
23544
+ const workflowId = isId ? Number(target2) : findBinding(target2, ctx.auth).workflowId;
23545
+ if (workflowId === void 0) throw notBoundError(target2, `${target2} is not bound to a workflow: run needs a published one.`);
23546
+ const workflow = await getWorkflow(ctx, workflowId);
23547
+ const published = await publishedDefinition(ctx, workflow);
23548
+ if (file !== void 0 && (published === void 0 || !sameDefinition(file, published))) {
23549
+ const hash = workflow.draft?.definitionHash;
23550
+ const inDraft = typeof hash === "string" && sameDefinition(file, workflow.definition);
23551
+ const push = `kenso workflows push ${shellQuote3(target2)}`;
23552
+ throw new KensoError({
23553
+ code: "unpublished_changes",
23554
+ message: "This file differs from the published version.",
23555
+ exitCode: ExitCode.Conflict,
23556
+ hint: inDraft ? "The saved draft holds this file: publish it once kenso workflows test passed on it." : "Save the file, test it, then publish it.",
23557
+ next: inDraft ? `${push} --publish --expected-hash ${hash}` : push
23558
+ });
23559
+ }
23560
+ if (workflow.status !== "live" || published === void 0) {
23561
+ throw new KensoError({ code: "invalid_state", message: `Workflow ${workflowId} is not live.`, exitCode: ExitCode.Conflict, next: `kenso workflows publish --workflow-id ${workflowId}` });
23562
+ }
23563
+ return { workflowId, definition: published };
23564
+ }
23565
+ function recordTypeOf(definition, flag) {
23566
+ const known = (value) => RECORD_TYPES3.includes(value);
23567
+ if (flag !== void 0) {
23568
+ if (!known(flag)) throw usageError(`--record-type must be one of ${RECORD_TYPES3.join(", ")} (got "${flag}").`, { field: "record-type" });
23569
+ return flag;
23570
+ }
23571
+ const trigger = definition?.trigger;
23572
+ const declared = trigger?.type === "trigger.manual@1" ? trigger.with?.recordType : loadStepTypes().find((type) => type.type === trigger?.type)?.recordType;
23573
+ if (known(declared)) return declared;
23574
+ throw new KensoError({
23575
+ code: "not_runnable_on_records",
23576
+ message: `The trigger ${trigger?.type ?? "of this workflow"} names no record type, so it cannot run on records.`,
23577
+ exitCode: ExitCode.Usage,
23578
+ field: "record-type",
23579
+ hint: `Pass --record-type ${RECORD_TYPES3.join(", ")} when the workflow can run on picked records.`
23580
+ });
23581
+ }
23582
+ function totalsOf(estimate2) {
23583
+ const e = estimate2 ?? {};
23584
+ const n = (key) => typeof e[key] === "number" ? e[key] : 0;
23585
+ return e.bulkPriceApplies === true ? { max: n("bulkMaxMillicredits"), expected: n("bulkExpectedMillicredits") } : { max: n("maxMillicredits"), expected: n("expectedMillicredits") };
23586
+ }
23587
+ async function estimate(ctx, target2, type, records, peopleRows) {
23588
+ if (peopleRows !== void 0) {
23589
+ if (peopleRows === 0) return { max: 0, expected: 0 };
23590
+ const result = await workflowEstimate(ctx, { definition: target2.definition, records: peopleRows });
23591
+ const failed = result.estimateError;
23592
+ if (failed) throw new KensoError({ code: failed.code ?? "estimate_failed", message: failed.message, exitCode: ExitCode.Error });
23593
+ return totalsOf(result.estimate);
23594
+ }
23595
+ const total = { max: 0, expected: 0 };
23596
+ for (let at = 0; at < records.length; at += CHUNK_SIZE7) {
23597
+ const res = await ctx.client.request({
23598
+ method: "POST",
23599
+ path: `/v1/workflows/${target2.workflowId}/runs`,
23600
+ body: { records: records.slice(at, at + CHUNK_SIZE7).map((record3) => ({ type, id: record3.id })), estimateOnly: true },
23601
+ retrySafe: true,
23602
+ signal: ctx.signal
23603
+ });
23604
+ const part = totalsOf(unwrap(res.body)?.estimate);
23605
+ total.max += part.max;
23606
+ total.expected += part.expected;
23607
+ }
23608
+ return total;
23609
+ }
23610
+ function summarize4(workflowId, records, cap) {
23611
+ return (results) => {
23612
+ const count = (...statuses) => results.filter((result) => statuses.includes(result.status)).length;
23613
+ return {
23614
+ workflowId,
23615
+ records,
23616
+ started: count("started"),
23617
+ deduplicated: count("deduplicated"),
23618
+ notStarted: count("not_started", "over_limit", "not_live", "not_found"),
23619
+ succeeded: 0,
23620
+ failed: count("failed", "invalid"),
23621
+ waiting: 0,
23622
+ missed: {},
23623
+ creditsCharged: "pending",
23624
+ cap: cap(),
23625
+ resultsCsv: null,
23626
+ appUrl: `${APP_URL}/workflows/${workflowId}`,
23627
+ next: `kenso workflow-runs list --workflow-id ${workflowId}`
23628
+ };
23629
+ };
23630
+ }
23631
+ var NAME2, CHUNK_SIZE7, APP_URL, LIST_HINT, command85, run_default3;
23632
+ var init_run4 = __esm({
23633
+ "src/commands/workflows/run.ts"() {
23634
+ "use strict";
23635
+ init_engine();
23636
+ init_runs();
23637
+ init_confirm();
23638
+ init_errors();
23639
+ init_estimate();
23640
+ init_exit_codes();
23641
+ init_http();
23642
+ init_step_types();
23643
+ init_columns();
23644
+ init_files2();
23645
+ init_run_cap();
23646
+ init_run_input();
23647
+ init_run_start();
23648
+ NAME2 = `kenso ${COMMAND7}`;
23649
+ CHUNK_SIZE7 = 1e3;
23650
+ APP_URL = "https://app.ken.so";
23651
+ LIST_HINT = "A saved list runs through a workflow whose trigger is trigger.saved_list@1 or trigger.csv@1; kenso workflows run takes --ids or --file.";
23652
+ command85 = {
23653
+ resource: "workflows",
23654
+ action: "run",
23655
+ summary: "Run a published workflow on records from an ids file or a CSV",
23656
+ brief: "on ids or a CSV",
23657
+ description: "Starts one run per record on the workflow's published version. The target is a workflow id, or a workflow file bound in kenso.json that equals the published version. --ids is one id per line; --file is a CSV with an id column, or for a workflow that runs on people a CSV of people (the columns of kenso people import), matched or created first. Without --yes it prints the plan with the credit estimate and starts nothing. --max-credits starts only as many records as the cap covers and reports the rest as not_started. The same command on the same input never starts its records twice; another --max-credits on that input is refused with an ids file of the records not started yet. Exit 5 when some records failed, were not found or were not started, 6 when the cap starts nothing or the workspace is out of credits, 7 when the file differs from the published version or the workflow is not live.",
23658
+ effect: "send",
23659
+ doc: {
23660
+ when: "You have a published workflow and the records to run it on.",
23661
+ cost: "the workflow's steps; --dry-run prints the estimate",
23662
+ next: "kenso workflow-runs list --workflow-id <id>"
23663
+ },
23664
+ flags: {
23665
+ ids: { type: "string", description: "A file with one record id per line, or - for stdin" },
23666
+ file: { type: "string", description: "A CSV with an id column, or a CSV of people for a workflow that runs on people" },
23667
+ "record-type": { type: "string", description: "account, person, lead or place (default: the type the trigger runs on)" },
23668
+ "max-credits": { type: "string", description: "Start only as many records as this many credits cover" },
23669
+ // Declared only so the refusal can carry its hint: main refuses an undeclared flag before the command runs.
23670
+ list: { type: "string", helpHidden: true, description: "Not a flag: a saved list runs through its own trigger" }
23671
+ },
23672
+ positionals: [{ name: "target", required: true, description: "A workflow file bound in kenso.json, or a workflow id" }],
23673
+ examples: [
23674
+ "kenso workflows run qualify.workflow.json --ids ids.txt --dry-run",
23675
+ "kenso workflows run qualify.workflow.json --ids ids.txt --max-credits 50 --yes",
23676
+ "kenso workflows run 412 --file people.csv --record-type person --dry-run"
23677
+ ],
23678
+ beta: { featureGates: WORKFLOWS_GATES },
23679
+ // workflow-runs.get is read by --wait.
23680
+ operationIds: ["workflows.get", "workflow-runs.run-on-records", "workflow-runs.get", "workflow-estimates.create", "credits.get", "people.batch", "workflow-versions.get"],
23681
+ dryRun: true,
23682
+ batch: true,
23683
+ async run(ctx, { flags, positionals }) {
23684
+ if (flags.list !== void 0) {
23685
+ throw new KensoError({ code: "unknown_flag", message: `Unknown flag --list for ${NAME2}.`, exitCode: ExitCode.Usage, field: "list", hint: LIST_HINT, next: `${NAME2} --help` });
23686
+ }
23687
+ const ids2 = stringFlag(flags.ids);
23688
+ const csv = stringFlag(flags.file);
23689
+ if (ids2 === void 0 === (csv === void 0)) throw usageError("Pass one of --ids and --file.", { field: "ids", next: `${NAME2} --help` });
23690
+ const maxCredits = maxCreditsOf(flags["max-credits"]);
23691
+ const apply = ctx.flags.yes === true;
23692
+ const target2 = await resolveTarget(ctx, positionals[0] ?? "");
23693
+ const { workflowId } = target2;
23694
+ const type = recordTypeOf(target2.definition, stringFlag(flags["record-type"]));
23695
+ const input = await readRunInput(ctx, { ids: ids2, file: csv, recordType: type });
23696
+ const rows = input.records.length + input.invalid.length;
23697
+ const basis = input.people ? rows : input.records.length;
23698
+ let totals;
23699
+ let check;
23700
+ let estimateError;
23701
+ try {
23702
+ totals = await estimate(ctx, target2, type, input.records, input.people ? rows : void 0);
23703
+ const balance = await ctx.client.request({ method: "GET", path: "/v1/credits", signal: ctx.signal });
23704
+ check = creditsCheck(totals.max, unwrap(balance.body)?.availableMillicredits);
23705
+ } catch (err) {
23706
+ if (apply || !(err instanceof KensoError) || err.exitCode === ExitCode.Auth || err.exitCode === ExitCode.Interrupted) throw err;
23707
+ estimateError = { code: err.code, message: err.message };
23708
+ }
23709
+ const hard = hardCeiling(target2.definition);
23710
+ const ceiling = hard ?? (totals && basis > 0 ? totals.max / basis / 1e3 : void 0);
23711
+ const retry = (cap2) => commandLine2(ctx, COMMAND7, { flags: { ...flags, "max-credits": String(cap2) }, positionals });
23712
+ const capFor = (count) => maxCredits !== void 0 && ceiling !== void 0 ? planCap(maxCredits, count, hard !== void 0 ? "hard" : "estimate", ceiling, retry) : null;
23713
+ let cap = capFor(input.records.length);
23714
+ const args = { ...flags, positionals };
23715
+ const applyCommand = commandLine2(ctx, COMMAND7, { flags, positionals }, ["--yes"]);
23716
+ const plan2 = {
23717
+ workflowId,
23718
+ records: rows,
23719
+ recordType: type,
23720
+ ...check ? { credits: check } : {},
23721
+ perRecord: totals && basis > 0 ? { expectedCredits: credits2(totals.expected / basis / 1e3), maxCredits: credits2(totals.max / basis / 1e3) } : null,
23722
+ expectedCredits: totals ? credits2(totals.expected / 1e3) : null,
23723
+ cap,
23724
+ ...estimateError ? { estimateError } : {}
23725
+ };
23726
+ let start = /* @__PURE__ */ new Set();
23727
+ const spec = (dryRun2, records2, invalid3) => ({
23728
+ command: COMMAND7,
23729
+ args,
23730
+ input: input.input,
23731
+ items: records2.map((record3) => ({ row: record3.row, type, ...record3.id !== void 0 ? { id: record3.id } : {} })),
23732
+ rowOf: (item) => item.row,
23733
+ chunkSize: CHUNK_SIZE7,
23734
+ concurrency: 1,
23735
+ execChunk: (chunk, cc) => startChunk(chunk, cc, { dirOf: (runId) => join33(runsRoot(ctx.env), runId), workflowId, start }),
23736
+ invalid: invalid3,
23737
+ dryRun: dryRun2,
23738
+ dryRunExtra: plan2,
23739
+ applyCommand,
23740
+ summarize: summarize4(workflowId, records2.length + invalid3.length, () => cap)
23741
+ });
23742
+ if (!apply) {
23743
+ const planned = await runBatch(spec(true, input.records, input.invalid), ctx);
23744
+ if (ctx.flags.dryRun === true || !canAsk(ctx) || estimateError) return planned.exitCode;
23745
+ await confirmDestructive(ctx, `Start ${cap ? cap.willStart : input.records.length} of ${rows} records on workflow ${workflowId}`, applyCommand);
23746
+ }
23747
+ const answered = await earlierRun(ctx, args, input.input.sha256, workflowId);
23748
+ if (answered !== void 0) return answered;
23749
+ if (check?.available != null && check.available <= 0 && (check.needed ?? 0) > 0) {
23750
+ throw new KensoError({ code: "out_of_credits", message: "The workspace is out of credits, so nothing was started.", exitCode: ExitCode.RateLimited });
23751
+ }
23752
+ let records = input.records;
23753
+ let invalid2 = input.invalid;
23754
+ if (input.people) {
23755
+ const matched = await matchPeople(ctx, records);
23756
+ records = matched.records;
23757
+ invalid2 = [...invalid2, ...matched.invalid];
23758
+ cap = capFor(records.length);
23759
+ }
23760
+ start = new Set(records.slice(0, cap ? cap.willStart : records.length).map((record3) => record3.row));
23761
+ const applied = spec(false, records, invalid2);
23762
+ const rerun = (ids3) => commandLine2(ctx, COMMAND7, { flags: { ...flags, ids: ids3, file: void 0 }, positionals }, ["--yes"]);
23763
+ await refuseRestart(ctx, { args, sha256: input.input.sha256, workflowId, items: applied.items, rerun });
23764
+ const outcome = await runBatch(applied, ctx);
23765
+ const s = outcome.summary;
23766
+ ctx.output.info(`workflow ${workflowId}: ${s.started} started, ${s.deduplicated} deduplicated, ${s.notStarted} not started, ${s.failed} failed of ${s.records} records`);
23767
+ if (outcome.exitCode !== ExitCode.Ok) return outcome.exitCode;
23768
+ return Number(s.notStarted ?? 0) + Number(s.failed ?? 0) > 0 ? ExitCode.Partial : ExitCode.Ok;
23769
+ }
23770
+ };
23771
+ run_default3 = command85;
23772
+ }
23773
+ });
23774
+
23158
23775
  // src/commands/workflows/run-actions.ts
23159
23776
  var runActions;
23160
23777
  var init_run_actions = __esm({
23161
23778
  "src/commands/workflows/run-actions.ts"() {
23162
23779
  "use strict";
23163
- runActions = {};
23780
+ runActions = {
23781
+ run: () => Promise.resolve().then(() => (init_run4(), run_exports4)).then((m) => m.default)
23782
+ };
23164
23783
  }
23165
23784
  });
23166
23785
 
@@ -23196,7 +23815,7 @@ function rewrap(err, overrides2) {
23196
23815
  details: err.details
23197
23816
  });
23198
23817
  }
23199
- var TEMPLATES, APP_NEXT_STEP, NOT_AVAILABLE, command84, keys_default;
23818
+ var TEMPLATES, APP_NEXT_STEP, NOT_AVAILABLE, command86, keys_default;
23200
23819
  var init_keys = __esm({
23201
23820
  "src/commands/workspace/keys.ts"() {
23202
23821
  "use strict";
@@ -23206,7 +23825,7 @@ var init_keys = __esm({
23206
23825
  TEMPLATES = ["admin", "editor", "viewer"];
23207
23826
  APP_NEXT_STEP = "A workspace admin can create it in the app: Settings > API keys > Workspace keys";
23208
23827
  NOT_AVAILABLE = "Workspace keys are not available for this workspace yet.";
23209
- command84 = {
23828
+ command86 = {
23210
23829
  resource: "workspace",
23211
23830
  action: "keys",
23212
23831
  summary: "Create an API key the workspace owns",
@@ -23268,7 +23887,7 @@ var init_keys = __esm({
23268
23887
  return ExitCode.Ok;
23269
23888
  }
23270
23889
  };
23271
- keys_default = command84;
23890
+ keys_default = command86;
23272
23891
  }
23273
23892
  });
23274
23893
 
@@ -23286,14 +23905,14 @@ function parseLimit2(value) {
23286
23905
  }
23287
23906
  return limit;
23288
23907
  }
23289
- var MAX_LIMIT2, command85, list_default5;
23908
+ var MAX_LIMIT2, command87, list_default5;
23290
23909
  var init_list5 = __esm({
23291
23910
  "src/commands/workspace/list.ts"() {
23292
23911
  "use strict";
23293
23912
  init_errors();
23294
23913
  init_exit_codes();
23295
23914
  MAX_LIMIT2 = 200;
23296
- command85 = {
23915
+ command87 = {
23297
23916
  resource: "workspace",
23298
23917
  action: "list",
23299
23918
  summary: "List the workspaces your key can use",
@@ -23322,7 +23941,7 @@ var init_list5 = __esm({
23322
23941
  return ExitCode.Ok;
23323
23942
  }
23324
23943
  };
23325
- list_default5 = command85;
23944
+ list_default5 = command87;
23326
23945
  }
23327
23946
  });
23328
23947
 
@@ -23331,7 +23950,7 @@ var use_exports = {};
23331
23950
  __export(use_exports, {
23332
23951
  default: () => use_default
23333
23952
  });
23334
- var command86, use_default;
23953
+ var command88, use_default;
23335
23954
  var init_use = __esm({
23336
23955
  "src/commands/workspace/use.ts"() {
23337
23956
  "use strict";
@@ -23339,7 +23958,7 @@ var init_use = __esm({
23339
23958
  init_errors();
23340
23959
  init_exit_codes();
23341
23960
  init_http();
23342
- command86 = {
23961
+ command88 = {
23343
23962
  resource: "workspace",
23344
23963
  action: "use",
23345
23964
  summary: "Set the profile's default workspace",
@@ -23401,7 +24020,7 @@ var init_use = __esm({
23401
24020
  return ExitCode.Ok;
23402
24021
  }
23403
24022
  };
23404
- use_default = command86;
24023
+ use_default = command88;
23405
24024
  }
23406
24025
  });
23407
24026
 
@@ -24019,14 +24638,14 @@ var init_pre_run = __esm({
24019
24638
  });
24020
24639
 
24021
24640
  // src/core/update-notice.ts
24022
- import { mkdirSync as mkdirSync8, readFileSync as readFileSync21, realpathSync as realpathSync2, renameSync as renameSync8, writeFileSync as writeFileSync13 } from "node:fs";
24023
- import { dirname as dirname7, join as join32, sep as sep4 } from "node:path";
24641
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync22, realpathSync as realpathSync2, renameSync as renameSync8, writeFileSync as writeFileSync13 } from "node:fs";
24642
+ import { dirname as dirname7, join as join34, sep as sep4 } from "node:path";
24024
24643
  function installKind(script = process.argv[1], execPath = process.execPath, platform = process.platform) {
24025
24644
  try {
24026
24645
  if (!script) return "npm";
24027
24646
  const bundle = realpathSync2(script);
24028
24647
  const lib = dirname7(dirname7(dirname7(bundle)));
24029
- if (execPath !== join32(lib, platform === "win32" ? "node.exe" : "node")) return "npm";
24648
+ if (execPath !== join34(lib, platform === "win32" ? "node.exe" : "node")) return "npm";
24030
24649
  return bundle.includes(`${sep4}Cellar${sep4}kenso${sep4}`) ? "homebrew" : "standalone";
24031
24650
  } catch {
24032
24651
  return "npm";
@@ -24039,7 +24658,7 @@ function updateCommand(install, platform) {
24039
24658
  }
24040
24659
  function readCheck(file) {
24041
24660
  try {
24042
- const parsed2 = JSON.parse(readFileSync21(file, "utf8"));
24661
+ const parsed2 = JSON.parse(readFileSync22(file, "utf8"));
24043
24662
  if (typeof parsed2?.checkedAt !== "string") return void 0;
24044
24663
  return { checkedAt: parsed2.checkedAt, ...typeof parsed2.latest === "string" ? { latest: parsed2.latest } : {} };
24045
24664
  } catch {
@@ -24080,13 +24699,13 @@ async function fetchLatest(fetchImpl, signal, install) {
24080
24699
  return typeof body2?.version === "string" && RELEASE.test(body2.version) ? body2.version : void 0;
24081
24700
  }
24082
24701
  function agentNotice(env, agent, version, stderr, opts) {
24083
- const latest = readCheck(join32(configDir(env), UPDATE_CHECK_FILE))?.latest;
24702
+ const latest = readCheck(join34(configDir(env), UPDATE_CHECK_FILE))?.latest;
24084
24703
  if (latest === void 0 || !isNewer(latest, version)) return done;
24085
24704
  return async () => {
24086
24705
  try {
24087
24706
  if (!firstInSession(env, agent, "update")) return;
24088
- const command87 = updateCommand(opts.install ?? installKind(), opts.platform ?? process.platform);
24089
- stderr.write(`kenso ${latest} is out (you have ${version}): ${command87}
24707
+ const command89 = updateCommand(opts.install ?? installKind(), opts.platform ?? process.platform);
24708
+ stderr.write(`kenso ${latest} is out (you have ${version}): ${command89}
24090
24709
  `);
24091
24710
  } catch {
24092
24711
  }
@@ -24102,7 +24721,7 @@ function startUpdateNotice(argv, opts = {}) {
24102
24721
  const agent = detectAgent(env);
24103
24722
  if (agent !== null) return agentNotice(env, agent, version, stderr, opts);
24104
24723
  if (!(opts.stderrIsTTY ?? process.stderr.isTTY === true)) return done;
24105
- const file = join32(configDir(env), UPDATE_CHECK_FILE);
24724
+ const file = join34(configDir(env), UPDATE_CHECK_FILE);
24106
24725
  const now = (opts.now ?? Date.now)();
24107
24726
  const cached = readCheck(file);
24108
24727
  const checkedAt = Date.parse(cached?.checkedAt ?? "");
@@ -24121,8 +24740,8 @@ function startUpdateNotice(argv, opts = {}) {
24121
24740
  if (!found) return;
24122
24741
  writeCheck(file, { checkedAt: new Date(now).toISOString(), latest: found });
24123
24742
  if (isNewer(found, version)) {
24124
- const command87 = updateCommand(install, opts.platform ?? process.platform);
24125
- stderr.write(`kenso ${found} is out (you have ${version}): ${command87}
24743
+ const command89 = updateCommand(install, opts.platform ?? process.platform);
24744
+ stderr.write(`kenso ${found} is out (you have ${version}): ${command89}
24126
24745
  Turn this off with KENSO_NO_UPDATE_NOTIFIER=1.
24127
24746
  `);
24128
24747
  }