agental 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +93 -15
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -7411,7 +7411,7 @@ import { parseArgs } from "node:util";
7411
7411
 
7412
7412
  // ../src/cli-build.ts
7413
7413
  var PUBLISHED = true;
7414
- var CLI_VERSION = true ? "0.22.0" : "dev";
7414
+ var CLI_VERSION = true ? "0.23.0" : "dev";
7415
7415
  var DEFAULT_API_URL = true ? "https://agental.io" : "http://127.0.0.1:8741";
7416
7416
  var PACKAGE_NAME = "agental";
7417
7417
  var USER_AGENT = `agental-cli/${CLI_VERSION}`;
@@ -9363,6 +9363,9 @@ var COMMANDS = [
9363
9363
  ["--input <NAME>=<default>", "add, update: a variable a run is given, with its default; NAME alone: a run must give it"],
9364
9364
  ["--secret-input <NAME>[=<default>]", "add, update: an input sealed where it is kept, \u2022\u2022\u2022\u2022 in output"],
9365
9365
  ["--input <NAME>=<value>", "run: a value for one of its inputs, over the default"],
9366
+ ["--after-job <job>[:succeeded|failed]", "add, update: run it when a run of that job ends (any end, or that one)"],
9367
+ ["--on-mail <sandbox>", "add, update: run it when mail arrives at that sandbox's address"],
9368
+ ["--no-events", "update: take away every event that starts it"],
9366
9369
  ["--name <name>", "update: a new name"],
9367
9370
  ["--wait[=<seconds>]", "run, again: wait for it to end, print its output, exit with its exit code"],
9368
9371
  ["--prune", "apply: delete the jobs the file does not name"],
@@ -10421,7 +10424,7 @@ function sandboxDoneOf(run2) {
10421
10424
  }
10422
10425
  return run2.stoppedSandbox === null ? "started, left running" : `started, stopped (${run2.stoppedSandbox})`;
10423
10426
  }
10424
- var BY = { timer: "timer", run_now: "by hand", api: "api", http: "http" };
10427
+ var BY = { timer: "timer", run_now: "by hand", api: "api", http: "http", event: "event" };
10425
10428
  function commandLine(words2) {
10426
10429
  if (words2.length === 1) {
10427
10430
  return words2[0] ?? "";
@@ -10522,6 +10525,37 @@ function runInputsOf(options) {
10522
10525
  }
10523
10526
  return inputs;
10524
10527
  }
10528
+ function eventsOf(options) {
10529
+ const afterJob = options["after-job"] ?? [];
10530
+ const onMail = options["on-mail"] ?? [];
10531
+ if (options["no-events"]) {
10532
+ if (afterJob.length > 0 || onMail.length > 0) {
10533
+ throw new Error("--no-events takes away every event that starts the job: give it without --after-job and --on-mail.");
10534
+ }
10535
+ return [];
10536
+ }
10537
+ if (afterJob.length === 0 && onMail.length === 0) {
10538
+ return void 0;
10539
+ }
10540
+ return [
10541
+ ...afterJob.map((given) => {
10542
+ const colon = given.lastIndexOf(":");
10543
+ const [job2, outcome] = colon < 0 ? [given, "any"] : [given.slice(0, colon), given.slice(colon + 1)];
10544
+ if (job2 === "" || !["succeeded", "failed", "any"].includes(outcome)) {
10545
+ throw new Error(`--after-job is a job, by its name or id, and :succeeded or :failed for one end of its runs alone, as --after-job build:succeeded: ${given} is not.`);
10546
+ }
10547
+ return { on: "job.run_finished", job: job2, outcome };
10548
+ }),
10549
+ ...onMail.map((sandbox) => ({ on: "email.received", sandbox }))
10550
+ ];
10551
+ }
10552
+ function eventsOfJob(job2) {
10553
+ const events = job2.events ?? [];
10554
+ if (events.length === 0) {
10555
+ return null;
10556
+ }
10557
+ return events.map((event) => event.on === "job.run_finished" ? `after ${event.jobName ?? event.job}${event.outcome === "any" ? "" : ` (${event.outcome})`}` : `mail to ${event.sandboxName ?? event.sandbox}`).join(", ");
10558
+ }
10525
10559
  function waitSecondsOf(options) {
10526
10560
  const given = options["wait-seconds"];
10527
10561
  if (given === void 0) {
@@ -10554,6 +10588,7 @@ function fieldsOf(options) {
10554
10588
  }
10555
10589
  const target = targetOf(options);
10556
10590
  const inputs = jobInputsOf(options);
10591
+ const events = eventsOf(options);
10557
10592
  return {
10558
10593
  ...target === void 0 ? {} : { target },
10559
10594
  ...options.every === void 0 ? {} : { every: options.every },
@@ -10567,7 +10602,8 @@ function fieldsOf(options) {
10567
10602
  ...options["keep-failed-for"] === void 0 ? {} : { keepFailedFor: options["keep-failed-for"] },
10568
10603
  ...options.retries === void 0 ? {} : { retries: Number(options.retries.trim()) },
10569
10604
  ...options.alerts === void 0 ? {} : { alerts: options.alerts },
10570
- ...inputs === void 0 ? {} : { inputs }
10605
+ ...inputs === void 0 ? {} : { inputs },
10606
+ ...events === void 0 ? {} : { events }
10571
10607
  };
10572
10608
  }
10573
10609
  function inputsOfJob(job2) {
@@ -10599,6 +10635,7 @@ function print3(job2, asJson) {
10599
10635
  ["retries", retriesOf(job2)],
10600
10636
  ["alerts", alertsOf(job2)],
10601
10637
  ...inputsOfJob(job2) === null ? [] : [["inputs", inputsOfJob(job2)]],
10638
+ ...eventsOfJob(job2) === null ? [] : [["events", eventsOfJob(job2)]],
10602
10639
  ["next", nextOf(job2, false)],
10603
10640
  ...job2.failingSince ? [["failing", `since ${at2(job2.failingSince)}`]] : [],
10604
10641
  ["last run", lastOf(job2.lastRun)],
@@ -10703,6 +10740,9 @@ async function job(client, positionals, command2, options) {
10703
10740
  if ((options.input !== void 0 || options["secret-input"] !== void 0) && !["add", "update", "run"].includes(what)) {
10704
10741
  throw new Error("--input goes with job add, update or run, and --secret-input with add or update.");
10705
10742
  }
10743
+ if ((options["after-job"] !== void 0 || options["on-mail"] !== void 0 || options["no-events"]) && !["add", "update"].includes(what)) {
10744
+ throw new Error("--after-job, --on-mail and --no-events go with job add or update.");
10745
+ }
10706
10746
  if (rest.length > (what === "logs" || what === "keep" || what === "again" ? 1 : 0)) {
10707
10747
  throw new Error(what === "add" ? "job add takes its name, then its command after --: agental job add nightly --sandbox <sandbox> --every 1h -- npm test" : USAGE4);
10708
10748
  }
@@ -10736,7 +10776,7 @@ async function job(client, positionals, command2, options) {
10736
10776
  const changes = { ...fieldsOf(options), ...options.name === void 0 ? {} : { name: options.name }, ...command2 !== null && command2.length > 0 ? { command: commandLine(command2) } : {} };
10737
10777
  if (Object.keys(changes).length === 0) {
10738
10778
  throw new Error(
10739
- "job update needs something to change: --sandbox, --template (and --size), --keep-failed-for, --every, --cron, --at, --tz, --timeout, --overlap, --if-stopped, --keep-memory, --delete-after or --disk-only, --retries, --alerts, --input or --secret-input, --name for a new name, or a new command after --."
10779
+ "job update needs something to change: --sandbox, --template (and --size), --keep-failed-for, --every, --cron, --at, --tz, --timeout, --overlap, --if-stopped, --keep-memory, --delete-after or --disk-only, --retries, --alerts, --input or --secret-input, --after-job, --on-mail or --no-events, --name for a new name, or a new command after --."
10740
10780
  );
10741
10781
  }
10742
10782
  print3(await ask6(client, "PATCH", path5, changes), options.json);
@@ -11051,7 +11091,7 @@ async function refusedCalls(client, name, options) {
11051
11091
  }
11052
11092
  table2([["AT", "STATUS", "TRIGGER", "FROM", "WHY"], ...calls.map((call3) => [past(call3.at), String(call3.status), call3.triggerId, call3.from ?? "-", call3.reason])]);
11053
11093
  }
11054
- var FILE_KEYS = ["name", "sandbox", "template", "size", "command", "every", "cron", "at", "timeZone", "timeoutMs", "overlap", "ifStopped", "after", "keepFailedFor", "retries", "alerts", "inputs", "enabled"];
11094
+ var FILE_KEYS = ["name", "sandbox", "template", "size", "command", "every", "cron", "at", "timeZone", "timeoutMs", "overlap", "ifStopped", "after", "keepFailedFor", "retries", "alerts", "inputs", "events", "enabled"];
11055
11095
  function fileJobOf(item, index) {
11056
11096
  const where = `jobs[${index}]`;
11057
11097
  if (item === null || typeof item !== "object" || Array.isArray(item)) {
@@ -11083,6 +11123,31 @@ function fileJobOf(item, index) {
11083
11123
  const target = template2 === void 0 ? { sandbox } : { template: template2, ...size2 === void 0 ? {} : { size: size2 } };
11084
11124
  return { name, body: { target, ...fields } };
11085
11125
  }
11126
+ function byEvents(jobs2) {
11127
+ const named = new Map(jobs2.map((each) => [each.name, each]));
11128
+ const done2 = /* @__PURE__ */ new Set();
11129
+ const ordered2 = [];
11130
+ const visit = (each, path5) => {
11131
+ if (done2.has(each.name) || path5.has(each.name)) {
11132
+ return;
11133
+ }
11134
+ path5.add(each.name);
11135
+ const events = Array.isArray(each.body["events"]) ? each.body["events"] : [];
11136
+ for (const event of events) {
11137
+ const job2 = event !== null && typeof event === "object" ? event["job"] : void 0;
11138
+ const before = typeof job2 === "string" ? named.get(job2) : void 0;
11139
+ if (before !== void 0) {
11140
+ visit(before, path5);
11141
+ }
11142
+ }
11143
+ done2.add(each.name);
11144
+ ordered2.push(each);
11145
+ };
11146
+ for (const each of jobs2) {
11147
+ visit(each, /* @__PURE__ */ new Set());
11148
+ }
11149
+ return ordered2;
11150
+ }
11086
11151
  function fileJobsOf(file) {
11087
11152
  let text;
11088
11153
  try {
@@ -11148,7 +11213,7 @@ async function apply(client, file, options) {
11148
11213
  return;
11149
11214
  }
11150
11215
  let applied;
11151
- for (const [index, each] of jobs2.entries()) {
11216
+ for (const [index, each] of byEvents(jobs2).entries()) {
11152
11217
  const response = await client.request(jobPath(each.name), { method: "PUT", body: JSON.stringify(each.body) });
11153
11218
  let body = null;
11154
11219
  try {
@@ -11287,7 +11352,7 @@ function sentOf(events) {
11287
11352
  function answerOf(delivery) {
11288
11353
  return delivery.httpStatus === null ? "none" : String(delivery.httpStatus);
11289
11354
  }
11290
- function eventsOf(deliveries) {
11355
+ function eventsOf2(deliveries) {
11291
11356
  const byEvent = /* @__PURE__ */ new Map();
11292
11357
  for (const delivery of deliveries) {
11293
11358
  const key2 = delivery.eventId ?? delivery.id;
@@ -11358,7 +11423,7 @@ function describe3(webhook2) {
11358
11423
  `url: ${webhook2.url}`,
11359
11424
  `sent: ${sentOf(webhook2.events)}`,
11360
11425
  `added: ${at3(webhook2.createdAt)}`,
11361
- `last post: ${standingOf(eventsOf(webhook2.deliveries))}`,
11426
+ `last post: ${standingOf(eventsOf2(webhook2.deliveries))}`,
11362
11427
  ""
11363
11428
  ].join("\n");
11364
11429
  }
@@ -11387,7 +11452,7 @@ async function listWebhooks(client, asJson) {
11387
11452
  for (const webhook2 of webhooks) {
11388
11453
  const listed = webhook2.events.join(",");
11389
11454
  const sent = webhook2.events.includes(EVERY) ? "every event" : listed.length <= 33 ? listed : `${webhook2.events.length} kinds`;
11390
- process.stdout.write(`${[pad3(webhook2.id, 22), pad3(nameOf(webhook2), 18), pad3(sent, 34), standingOf(eventsOf(webhook2.deliveries))].join(" ")}
11455
+ process.stdout.write(`${[pad3(webhook2.id, 22), pad3(nameOf(webhook2), 18), pad3(sent, 34), standingOf(eventsOf2(webhook2.deliveries))].join(" ")}
11391
11456
  `);
11392
11457
  }
11393
11458
  }
@@ -11426,7 +11491,7 @@ async function webhook(client, positionals, options) {
11426
11491
  return;
11427
11492
  }
11428
11493
  process.stdout.write(describe3(found));
11429
- const slow = eventsOf(found.deliveries).filter((one) => one.tries.length > 1 || one.outcome !== "taken");
11494
+ const slow = eventsOf2(found.deliveries).filter((one) => one.tries.length > 1 || one.outcome !== "taken");
11430
11495
  if (slow.length > 0) {
11431
11496
  process.stdout.write("\nEvents not taken at the first try, newest first:\n");
11432
11497
  for (const one of slow.slice(0, 10)) {
@@ -12429,6 +12494,10 @@ async function main() {
12429
12494
  // agental job add and update: the inputs a run may be given, and those that are secret; job run: the values a run is given.
12430
12495
  input: { type: "string", multiple: true },
12431
12496
  "secret-input": { type: "string", multiple: true },
12497
+ // agental job add and update: the events that start a job, another job's run ending and mail to a sandbox; or none.
12498
+ "after-job": { type: "string", multiple: true },
12499
+ "on-mail": { type: "string", multiple: true },
12500
+ "no-events": { type: "boolean", default: false },
12432
12501
  // agental job apply: delete the jobs the file does not name, or say what it would do and change nothing.
12433
12502
  prune: { type: "boolean", default: false },
12434
12503
  "dry-run": { type: "boolean", default: false },
@@ -15306,16 +15375,18 @@ Usage
15306
15375
  agental jobs [--sandbox <sandbox-id> | --template <template>] [--json]
15307
15376
  agental job add [<name>] --sandbox <sandbox-id> [--every 1m|15m|1h|1d | --cron "<m h dom mon dow>" [--tz <zone>] | --at <date-time>] [--timeout <time>]
15308
15377
  [--if-stopped start|skip] [--keep-memory | --delete-after] [--overlap skip|replace|parallel] [--retries <0-5>] [--alerts email|webhook|both|none]
15309
- [--input <NAME>[=<default>]]... [--secret-input <NAME>[=<default>]]... [--json] -- <command> [args...]
15378
+ [--input <NAME>[=<default>]]... [--secret-input <NAME>[=<default>]]... [--after-job <job>[:succeeded|failed]]... [--on-mail <sandbox>]...
15379
+ [--json] -- <command> [args...]
15310
15380
  agental job add [<name>] --template <template> [--size tiny|small|medium|large] [--keep-failed-for 0|30m|24h|7d] [--every 1m|15m|1h|1d | --cron "<m h dom mon dow>" [--tz <zone>] | --at <date-time>]
15311
15381
  [--timeout <time>] [--overlap skip|replace|parallel] [--retries <0-5>] [--alerts email|webhook|both|none]
15312
- [--input <NAME>[=<default>]]... [--secret-input <NAME>[=<default>]]... [--json] -- <command> [args...] a fresh sandbox for each run
15382
+ [--input <NAME>[=<default>]]... [--secret-input <NAME>[=<default>]]... [--after-job <job>[:succeeded|failed]]... [--on-mail <sandbox>]...
15383
+ [--json] -- <command> [args...] a fresh sandbox for each run
15313
15384
  agental job list [--sandbox <sandbox-id> | --template <template>] [--json]
15314
15385
  agental job get|delete|pause|resume <job> [--json]
15315
15386
  agental job update <job> [--sandbox <sandbox-id> | --template <template> [--size <size>]] [--keep-failed-for <time>] [--every <time> | --cron "<expr>" | --at <date-time>] [--tz <zone>]
15316
15387
  [--name <name>] [--timeout <time>] [--if-stopped start|skip] [--keep-memory | --delete-after | --disk-only] [--overlap skip|replace|parallel]
15317
15388
  [--retries <0-5>] [--alerts email|webhook|both|none] [--input <NAME>[=<default>]]... [--secret-input <NAME>[=<default>]]...
15318
- [--json] [-- <command> [args...]]
15389
+ [--after-job <job>[:succeeded|failed]]... [--on-mail <sandbox>]... [--no-events] [--json] [-- <command> [args...]]
15319
15390
  agental job run <job> [--input <NAME>=<value>]... [--wait[=<seconds>]] [--json]
15320
15391
  agental job again <job> <run-id> [--wait[=<seconds>]] [--json] run it again with what that run was given
15321
15392
  agental job runs <job> [--limit <n>] [--json]
@@ -15510,14 +15581,21 @@ is kept and masked as \u2022\u2022\u2022\u2022 in output. A name is upper-case l
15510
15581
  to update, they replace the ones the job had. A run by the clock is given the defaults; job run
15511
15582
  --input NAME=VALUE gives a run a value over its default, and again runs a job once more with what
15512
15583
  one of its runs was given, secret values too.
15584
+ Events start a job too: add and update take --after-job JOB to run it when a run of JOB ends,
15585
+ --after-job JOB:succeeded or JOB:failed for one end alone (failed: for good, after its retries),
15586
+ and --on-mail SANDBOX to run it when mail arrives at that sandbox's address. Its command is told
15587
+ what started it: AGENTAL_TRIGGER_JOB, AGENTAL_TRIGGER_RUN and AGENTAL_TRIGGER_OUTCOME, or
15588
+ AGENTAL_TRIGGER_SANDBOX and AGENTAL_TRIGGER_EMAIL, the message's id. Given to update, they replace
15589
+ the events the job had; --no-events takes them all away. A chain that comes back to the job is
15590
+ refused, and events that start 60 runs of a job in a minute pause it.
15513
15591
  job apply puts the jobs a file lists, each by its name: one not there is made, and one that is
15514
15592
  is changed to exactly what the file says, whatever it leaves out going back to its default; each
15515
15593
  is said to be made, changed or unchanged. --prune deletes the jobs the file does not name;
15516
15594
  --dry-run changes nothing, and says which would be made, put or deleted. The file is YAML, or
15517
15595
  JSON, a map whose jobs: lists each job: its name, command, sandbox: for a sandbox you keep or
15518
15596
  template: (and size:) for a fresh sandbox at each run, and any of every, cron, at, timeZone,
15519
- timeoutMs, overlap, ifStopped, after, keepFailedFor, retries, alerts, inputs and enabled, as
15520
- POST /v1/jobs takes them:
15597
+ timeoutMs, overlap, ifStopped, after, keepFailedFor, retries, alerts, inputs, events and enabled,
15598
+ as POST /v1/jobs takes them; a job named in another's events is listed before it:
15521
15599
  jobs:
15522
15600
  - name: nightly
15523
15601
  sandbox: build
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agental",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "The agental command: Linux sandboxes for your agents, from the terminal. npx agental@latest signs you in and installs the agent skills.",
5
5
  "license": "MIT",
6
6
  "author": "VERTIXER LTD",