agental 0.40.2 → 0.42.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 +1039 -309
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1122,18 +1122,18 @@ ${indent}${text.slice(fold + 1, end2)}`;
1122
1122
  }
1123
1123
  function consumeMoreIndentedLines(text, i, indent) {
1124
1124
  let end = i;
1125
- let start = i + 1;
1126
- let ch = text[start];
1125
+ let start2 = i + 1;
1126
+ let ch = text[start2];
1127
1127
  while (ch === " " || ch === " ") {
1128
- if (i < start + indent) {
1128
+ if (i < start2 + indent) {
1129
1129
  ch = text[++i];
1130
1130
  } else {
1131
1131
  do {
1132
1132
  ch = text[++i];
1133
1133
  } while (ch && ch !== "\n");
1134
1134
  end = i;
1135
- start = i + 1;
1136
- ch = text[start];
1135
+ start2 = i + 1;
1136
+ ch = text[start2];
1137
1137
  }
1138
1138
  }
1139
1139
  return end;
@@ -1164,39 +1164,39 @@ var require_stringifyString = __commonJS({
1164
1164
  const strLen = str.length;
1165
1165
  if (strLen <= limit)
1166
1166
  return false;
1167
- for (let i = 0, start = 0; i < strLen; ++i) {
1167
+ for (let i = 0, start2 = 0; i < strLen; ++i) {
1168
1168
  if (str[i] === "\n") {
1169
- if (i - start > limit)
1169
+ if (i - start2 > limit)
1170
1170
  return true;
1171
- start = i + 1;
1172
- if (strLen - start <= limit)
1171
+ start2 = i + 1;
1172
+ if (strLen - start2 <= limit)
1173
1173
  return false;
1174
1174
  }
1175
1175
  }
1176
1176
  return true;
1177
1177
  }
1178
1178
  function doubleQuotedString(value, ctx) {
1179
- const json2 = JSON.stringify(value);
1179
+ const json3 = JSON.stringify(value);
1180
1180
  if (ctx.options.doubleQuotedAsJSON)
1181
- return json2;
1181
+ return json3;
1182
1182
  const { implicitKey } = ctx;
1183
1183
  const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
1184
1184
  const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
1185
1185
  let str = "";
1186
- let start = 0;
1187
- for (let i = 0, ch = json2[i]; ch; ch = json2[++i]) {
1188
- if (ch === " " && json2[i + 1] === "\\" && json2[i + 2] === "n") {
1189
- str += json2.slice(start, i) + "\\ ";
1186
+ let start2 = 0;
1187
+ for (let i = 0, ch = json3[i]; ch; ch = json3[++i]) {
1188
+ if (ch === " " && json3[i + 1] === "\\" && json3[i + 2] === "n") {
1189
+ str += json3.slice(start2, i) + "\\ ";
1190
1190
  i += 1;
1191
- start = i;
1191
+ start2 = i;
1192
1192
  ch = "\\";
1193
1193
  }
1194
1194
  if (ch === "\\")
1195
- switch (json2[i + 1]) {
1195
+ switch (json3[i + 1]) {
1196
1196
  case "u":
1197
1197
  {
1198
- str += json2.slice(start, i);
1199
- const code = json2.substr(i + 2, 4);
1198
+ str += json3.slice(start2, i);
1199
+ const code = json3.substr(i + 2, 4);
1200
1200
  switch (code) {
1201
1201
  case "0000":
1202
1202
  str += "\\0";
@@ -1226,33 +1226,33 @@ var require_stringifyString = __commonJS({
1226
1226
  if (code.substr(0, 2) === "00")
1227
1227
  str += "\\x" + code.substr(2);
1228
1228
  else
1229
- str += json2.substr(i, 6);
1229
+ str += json3.substr(i, 6);
1230
1230
  }
1231
1231
  i += 5;
1232
- start = i + 1;
1232
+ start2 = i + 1;
1233
1233
  }
1234
1234
  break;
1235
1235
  case "n":
1236
- if (implicitKey || json2[i + 2] === '"' || json2.length < minMultiLineLength) {
1236
+ if (implicitKey || json3[i + 2] === '"' || json3.length < minMultiLineLength) {
1237
1237
  i += 1;
1238
1238
  } else {
1239
- str += json2.slice(start, i) + "\n\n";
1240
- while (json2[i + 2] === "\\" && json2[i + 3] === "n" && json2[i + 4] !== '"') {
1239
+ str += json3.slice(start2, i) + "\n\n";
1240
+ while (json3[i + 2] === "\\" && json3[i + 3] === "n" && json3[i + 4] !== '"') {
1241
1241
  str += "\n";
1242
1242
  i += 2;
1243
1243
  }
1244
1244
  str += indent;
1245
- if (json2[i + 2] === " ")
1245
+ if (json3[i + 2] === " ")
1246
1246
  str += "\\";
1247
1247
  i += 1;
1248
- start = i + 1;
1248
+ start2 = i + 1;
1249
1249
  }
1250
1250
  break;
1251
1251
  default:
1252
1252
  i += 1;
1253
1253
  }
1254
1254
  }
1255
- str = start ? str + json2.slice(start) : json2;
1255
+ str = start2 ? str + json3.slice(start2) : json3;
1256
1256
  return implicitKey ? str : foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
1257
1257
  }
1258
1258
  function singleQuotedString(value, ctx) {
@@ -1331,10 +1331,10 @@ ${indent}`) + "'";
1331
1331
  else
1332
1332
  break;
1333
1333
  }
1334
- let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);
1335
- if (start) {
1336
- value = value.substring(start.length);
1337
- start = start.replace(/\n+/g, `$&${indent}`);
1334
+ let start2 = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);
1335
+ if (start2) {
1336
+ value = value.substring(start2.length);
1337
+ start2 = start2.replace(/\n+/g, `$&${indent}`);
1338
1338
  }
1339
1339
  const indentSize = indent ? "2" : "1";
1340
1340
  let header = (startWithSpace ? indentSize : "") + chomp;
@@ -1352,14 +1352,14 @@ ${indent}`) + "'";
1352
1352
  literalFallback = true;
1353
1353
  };
1354
1354
  }
1355
- const body = foldFlowLines.foldFlowLines(`${start}${foldedValue}${end}`, indent, foldFlowLines.FOLD_BLOCK, foldOptions);
1355
+ const body = foldFlowLines.foldFlowLines(`${start2}${foldedValue}${end}`, indent, foldFlowLines.FOLD_BLOCK, foldOptions);
1356
1356
  if (!literalFallback)
1357
1357
  return `>${header}
1358
1358
  ${indent}${body}`;
1359
1359
  }
1360
1360
  value = value.replace(/\n+/g, `$&${indent}`);
1361
1361
  return `|${header}
1362
- ${indent}${start}${value}${end}`;
1362
+ ${indent}${start2}${value}${end}`;
1363
1363
  }
1364
1364
  function plainString(item, ctx, onComment, onChompKeep) {
1365
1365
  const { type, value } = item;
@@ -1990,23 +1990,23 @@ ${indent}${line}` : "\n";
1990
1990
  lines.push(str);
1991
1991
  linesAtValue = lines.length;
1992
1992
  }
1993
- const { start, end } = flowChars;
1993
+ const { start: start2, end } = flowChars;
1994
1994
  if (lines.length === 0) {
1995
- return start + end;
1995
+ return start2 + end;
1996
1996
  } else {
1997
1997
  if (!reqNewline) {
1998
1998
  const len = lines.reduce((sum, line) => sum + line.length + 2, 2);
1999
1999
  reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
2000
2000
  }
2001
2001
  if (reqNewline) {
2002
- let str = start;
2002
+ let str = start2;
2003
2003
  for (const line of lines)
2004
2004
  str += line ? `
2005
2005
  ${indentStep}${indent}${line}` : "\n";
2006
2006
  return `${str}
2007
2007
  ${indent}${end}`;
2008
2008
  } else {
2009
- return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
2009
+ return `${start2}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
2010
2010
  }
2011
2011
  }
2012
2012
  }
@@ -3674,11 +3674,11 @@ var require_Document = __commonJS({
3674
3674
  throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
3675
3675
  }
3676
3676
  // json & jsonArg are only used from toJSON()
3677
- toJS({ json: json2, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
3677
+ toJS({ json: json3, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
3678
3678
  const ctx = {
3679
3679
  anchors: /* @__PURE__ */ new Map(),
3680
3680
  doc: this,
3681
- keep: !json2,
3681
+ keep: !json3,
3682
3682
  mapAsMap: mapAsMap === true,
3683
3683
  mapKeyWarned: false,
3684
3684
  maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
@@ -3801,7 +3801,7 @@ var require_resolve_props = __commonJS({
3801
3801
  let newlineAfterProp = null;
3802
3802
  let comma = null;
3803
3803
  let found = null;
3804
- let start = null;
3804
+ let start2 = null;
3805
3805
  for (const token of tokens) {
3806
3806
  if (reqSpace) {
3807
3807
  if (token.type !== "space" && token.type !== "newline" && token.type !== "comma")
@@ -3853,7 +3853,7 @@ var require_resolve_props = __commonJS({
3853
3853
  if (token.source.endsWith(":"))
3854
3854
  onError(token.offset + token.source.length - 1, "BAD_ALIAS", "Anchor ending in : is ambiguous", true);
3855
3855
  anchor = token;
3856
- start ?? (start = token.offset);
3856
+ start2 ?? (start2 = token.offset);
3857
3857
  atNewline = false;
3858
3858
  hasSpace = false;
3859
3859
  reqSpace = true;
@@ -3862,7 +3862,7 @@ var require_resolve_props = __commonJS({
3862
3862
  if (tag)
3863
3863
  onError(token, "MULTIPLE_TAGS", "A node can have at most one tag");
3864
3864
  tag = token;
3865
- start ?? (start = token.offset);
3865
+ start2 ?? (start2 = token.offset);
3866
3866
  atNewline = false;
3867
3867
  hasSpace = false;
3868
3868
  reqSpace = true;
@@ -3910,7 +3910,7 @@ var require_resolve_props = __commonJS({
3910
3910
  tag,
3911
3911
  newlineAfterProp,
3912
3912
  end,
3913
- start: start ?? end
3913
+ start: start2 ?? end
3914
3914
  };
3915
3915
  }
3916
3916
  exports.resolveProps = resolveProps;
@@ -4012,8 +4012,8 @@ var require_resolve_block_map = __commonJS({
4012
4012
  let offset = bm.offset;
4013
4013
  let commentEnd = null;
4014
4014
  for (const collItem of bm.items) {
4015
- const { start, key: key2, sep, value } = collItem;
4016
- const keyProps = resolveProps.resolveProps(start, {
4015
+ const { start: start2, key: key2, sep, value } = collItem;
4016
+ const keyProps = resolveProps.resolveProps(start2, {
4017
4017
  indicator: "explicit-key-ind",
4018
4018
  next: key2 ?? sep?.[0],
4019
4019
  offset,
@@ -4040,14 +4040,14 @@ var require_resolve_block_map = __commonJS({
4040
4040
  continue;
4041
4041
  }
4042
4042
  if (keyProps.newlineAfterProp || utilContainsNewline.containsNewline(key2)) {
4043
- onError(key2 ?? start[start.length - 1], "MULTILINE_IMPLICIT_KEY", "Implicit keys need to be on a single line");
4043
+ onError(key2 ?? start2[start2.length - 1], "MULTILINE_IMPLICIT_KEY", "Implicit keys need to be on a single line");
4044
4044
  }
4045
4045
  } else if (keyProps.found?.indent !== bm.indent) {
4046
4046
  onError(offset, "BAD_INDENT", startColMsg);
4047
4047
  }
4048
4048
  ctx.atKey = true;
4049
4049
  const keyStart = keyProps.end;
4050
- const keyNode = key2 ? composeNode(ctx, key2, keyProps, onError) : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
4050
+ const keyNode = key2 ? composeNode(ctx, key2, keyProps, onError) : composeEmptyNode(ctx, keyStart, start2, null, keyProps, onError);
4051
4051
  if (ctx.schema.compat)
4052
4052
  utilFlowIndentCheck.flowIndentCheck(bm.indent, key2, onError);
4053
4053
  ctx.atKey = false;
@@ -4117,8 +4117,8 @@ var require_resolve_block_seq = __commonJS({
4117
4117
  ctx.atKey = false;
4118
4118
  let offset = bs.offset;
4119
4119
  let commentEnd = null;
4120
- for (const { start, value } of bs.items) {
4121
- const props = resolveProps.resolveProps(start, {
4120
+ for (const { start: start2, value } of bs.items) {
4121
+ const props = resolveProps.resolveProps(start2, {
4122
4122
  indicator: "seq-item-ind",
4123
4123
  next: value,
4124
4124
  offset,
@@ -4139,7 +4139,7 @@ var require_resolve_block_seq = __commonJS({
4139
4139
  continue;
4140
4140
  }
4141
4141
  }
4142
- const node = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, start, null, props, onError);
4142
+ const node = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, start2, null, props, onError);
4143
4143
  if (ctx.schema.compat)
4144
4144
  utilFlowIndentCheck.flowIndentCheck(bs.indent, value, onError);
4145
4145
  offset = node.range[2];
@@ -4223,8 +4223,8 @@ var require_resolve_flow_collection = __commonJS({
4223
4223
  let offset = fc.offset + fc.start.source.length;
4224
4224
  for (let i = 0; i < fc.items.length; ++i) {
4225
4225
  const collItem = fc.items[i];
4226
- const { start, key: key2, sep, value } = collItem;
4227
- const props = resolveProps.resolveProps(start, {
4226
+ const { start: start2, key: key2, sep, value } = collItem;
4227
+ const props = resolveProps.resolveProps(start2, {
4228
4228
  flow: fcName,
4229
4229
  indicator: "explicit-key-ind",
4230
4230
  next: key2 ?? sep?.[0],
@@ -4264,7 +4264,7 @@ var require_resolve_flow_collection = __commonJS({
4264
4264
  onError(props.start, "MISSING_CHAR", `Missing , between ${fcName} items`);
4265
4265
  if (props.comment) {
4266
4266
  let prevItemComment = "";
4267
- loop: for (const st of start) {
4267
+ loop: for (const st of start2) {
4268
4268
  switch (st.type) {
4269
4269
  case "comma":
4270
4270
  case "space":
@@ -4297,7 +4297,7 @@ var require_resolve_flow_collection = __commonJS({
4297
4297
  } else {
4298
4298
  ctx.atKey = true;
4299
4299
  const keyStart = props.end;
4300
- const keyNode = key2 ? composeNode(ctx, key2, props, onError) : composeEmptyNode(ctx, keyStart, start, null, props, onError);
4300
+ const keyNode = key2 ? composeNode(ctx, key2, props, onError) : composeEmptyNode(ctx, keyStart, start2, null, props, onError);
4301
4301
  if (isBlock(key2))
4302
4302
  onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
4303
4303
  ctx.atKey = false;
@@ -4460,10 +4460,10 @@ var require_resolve_block_scalar = __commonJS({
4460
4460
  "use strict";
4461
4461
  var Scalar = require_Scalar();
4462
4462
  function resolveBlockScalar(ctx, scalar, onError) {
4463
- const start = scalar.offset;
4463
+ const start2 = scalar.offset;
4464
4464
  const header = parseBlockScalarHeader(scalar, ctx.options.strict, onError);
4465
4465
  if (!header)
4466
- return { value: "", type: null, comment: "", range: [start, start, start] };
4466
+ return { value: "", type: null, comment: "", range: [start2, start2, start2] };
4467
4467
  const type = header.mode === ">" ? Scalar.Scalar.BLOCK_FOLDED : Scalar.Scalar.BLOCK_LITERAL;
4468
4468
  const lines = scalar.source ? splitLines(scalar.source) : [];
4469
4469
  let chompStart = lines.length;
@@ -4476,10 +4476,10 @@ var require_resolve_block_scalar = __commonJS({
4476
4476
  }
4477
4477
  if (chompStart === 0) {
4478
4478
  const value2 = header.chomp === "+" && lines.length > 0 ? "\n".repeat(Math.max(1, lines.length - 1)) : "";
4479
- let end2 = start + header.length;
4479
+ let end2 = start2 + header.length;
4480
4480
  if (scalar.source)
4481
4481
  end2 += scalar.source.length;
4482
- return { value: value2, type, comment: header.comment, range: [start, end2, end2] };
4482
+ return { value: value2, type, comment: header.comment, range: [start2, end2, end2] };
4483
4483
  }
4484
4484
  let trimIndent = scalar.indent + header.indent;
4485
4485
  let offset = scalar.offset + header.length;
@@ -4560,8 +4560,8 @@ var require_resolve_block_scalar = __commonJS({
4560
4560
  default:
4561
4561
  value += "\n";
4562
4562
  }
4563
- const end = start + header.length + scalar.source.length;
4564
- return { value, type, comment: header.comment, range: [start, end, end] };
4563
+ const end = start2 + header.length + scalar.source.length;
4564
+ return { value, type, comment: header.comment, range: [start2, end, end] };
4565
4565
  }
4566
4566
  function parseBlockScalarHeader({ offset, props }, strict, onError) {
4567
4567
  if (props[0].type !== "block-scalar-header") {
@@ -5083,7 +5083,7 @@ var require_compose_doc = __commonJS({
5083
5083
  var composeNode = require_compose_node();
5084
5084
  var resolveEnd = require_resolve_end();
5085
5085
  var resolveProps = require_resolve_props();
5086
- function composeDoc(options, directives, { offset, start, value, end }, onError) {
5086
+ function composeDoc(options, directives, { offset, start: start2, value, end }, onError) {
5087
5087
  const opts = Object.assign({ _directives: directives }, options);
5088
5088
  const doc = new Document.Document(void 0, opts);
5089
5089
  const ctx = {
@@ -5093,7 +5093,7 @@ var require_compose_doc = __commonJS({
5093
5093
  options: doc.options,
5094
5094
  schema: doc.schema
5095
5095
  };
5096
- const props = resolveProps.resolveProps(start, {
5096
+ const props = resolveProps.resolveProps(start2, {
5097
5097
  indicator: "doc-start",
5098
5098
  next: value ?? end?.[0],
5099
5099
  offset,
@@ -5106,7 +5106,7 @@ var require_compose_doc = __commonJS({
5106
5106
  if (value && (value.type === "block-map" || value.type === "block-seq") && !props.hasNewline)
5107
5107
  onError(props.end, "MISSING_CHAR", "Block collection cannot start on same line with directives-end marker");
5108
5108
  }
5109
- doc.contents = value ? composeNode.composeNode(ctx, value, props, onError) : composeNode.composeEmptyNode(ctx, props.end, start, null, props, onError);
5109
+ doc.contents = value ? composeNode.composeNode(ctx, value, props, onError) : composeNode.composeEmptyNode(ctx, props.end, start2, null, props, onError);
5110
5110
  const contentEnd = doc.contents.range[2];
5111
5111
  const re = resolveEnd.resolveEnd(end, contentEnd, false, onError);
5112
5112
  if (re.comment)
@@ -5555,9 +5555,9 @@ var require_cst_stringify = __commonJS({
5555
5555
  }
5556
5556
  }
5557
5557
  }
5558
- function stringifyItem({ start, key: key2, sep, value }) {
5558
+ function stringifyItem({ start: start2, key: key2, sep, value }) {
5559
5559
  let res = "";
5560
- for (const st of start)
5560
+ for (const st of start2)
5561
5561
  res += st.source;
5562
5562
  if (key2)
5563
5563
  res += stringifyToken(key2);
@@ -6347,8 +6347,8 @@ var require_line_counter = __commonJS({
6347
6347
  return { line: low + 1, col: 1 };
6348
6348
  if (low === 0)
6349
6349
  return { line: 0, col: offset };
6350
- const start = this.lineStarts[low - 1];
6351
- return { line: low, col: offset - start + 1 };
6350
+ const start2 = this.lineStarts[low - 1];
6351
+ return { line: low, col: offset - start2 + 1 };
6352
6352
  };
6353
6353
  }
6354
6354
  };
@@ -6363,15 +6363,15 @@ var require_parser = __commonJS({
6363
6363
  var node_process = __require("process");
6364
6364
  var cst = require_cst();
6365
6365
  var lexer = require_lexer();
6366
- function includesToken(list3, type) {
6367
- for (let i = 0; i < list3.length; ++i)
6368
- if (list3[i].type === type)
6366
+ function includesToken(list4, type) {
6367
+ for (let i = 0; i < list4.length; ++i)
6368
+ if (list4[i].type === type)
6369
6369
  return true;
6370
6370
  return false;
6371
6371
  }
6372
- function findNonEmptyIndex(list3) {
6373
- for (let i = 0; i < list3.length; ++i) {
6374
- switch (list3[i].type) {
6372
+ function findNonEmptyIndex(list4) {
6373
+ for (let i = 0; i < list4.length; ++i) {
6374
+ switch (list4[i].type) {
6375
6375
  case "space":
6376
6376
  case "comment":
6377
6377
  case "newline":
@@ -6728,7 +6728,7 @@ var require_parser = __commonJS({
6728
6728
  *scalar(scalar) {
6729
6729
  if (this.type === "map-value-ind") {
6730
6730
  const prev = getPrevProps(this.peek(2));
6731
- const start = getFirstKeyStartProps(prev);
6731
+ const start2 = getFirstKeyStartProps(prev);
6732
6732
  let sep;
6733
6733
  if (scalar.end) {
6734
6734
  sep = scalar.end;
@@ -6740,7 +6740,7 @@ var require_parser = __commonJS({
6740
6740
  type: "block-map",
6741
6741
  offset: scalar.offset,
6742
6742
  indent: scalar.indent,
6743
- items: [{ start, key: scalar, sep }]
6743
+ items: [{ start: start2, key: scalar, sep }]
6744
6744
  };
6745
6745
  this.onKeyLine = true;
6746
6746
  this.stack[this.stack.length - 1] = map;
@@ -6815,7 +6815,7 @@ var require_parser = __commonJS({
6815
6815
  if (this.indent >= map.indent) {
6816
6816
  const atMapIndent = !this.onKeyLine && this.indent === map.indent;
6817
6817
  const atNextItem = atMapIndent && (it.sep || it.explicitKey) && this.type !== "seq-item-ind";
6818
- let start = [];
6818
+ let start2 = [];
6819
6819
  if (atNextItem && it.sep && !it.value) {
6820
6820
  const nl = [];
6821
6821
  for (let i = 0; i < it.sep.length; ++i) {
@@ -6835,14 +6835,14 @@ var require_parser = __commonJS({
6835
6835
  }
6836
6836
  }
6837
6837
  if (nl.length >= 2)
6838
- start = it.sep.splice(nl[1]);
6838
+ start2 = it.sep.splice(nl[1]);
6839
6839
  }
6840
6840
  switch (this.type) {
6841
6841
  case "anchor":
6842
6842
  case "tag":
6843
6843
  if (atNextItem || it.value) {
6844
- start.push(this.sourceToken);
6845
- map.items.push({ start });
6844
+ start2.push(this.sourceToken);
6845
+ map.items.push({ start: start2 });
6846
6846
  this.onKeyLine = true;
6847
6847
  } else if (it.sep) {
6848
6848
  it.sep.push(this.sourceToken);
@@ -6855,8 +6855,8 @@ var require_parser = __commonJS({
6855
6855
  it.start.push(this.sourceToken);
6856
6856
  it.explicitKey = true;
6857
6857
  } else if (atNextItem || it.value) {
6858
- start.push(this.sourceToken);
6859
- map.items.push({ start, explicitKey: true });
6858
+ start2.push(this.sourceToken);
6859
+ map.items.push({ start: start2, explicitKey: true });
6860
6860
  } else {
6861
6861
  this.stack.push({
6862
6862
  type: "block-map",
@@ -6873,12 +6873,12 @@ var require_parser = __commonJS({
6873
6873
  if (includesToken(it.start, "newline")) {
6874
6874
  Object.assign(it, { key: null, sep: [this.sourceToken] });
6875
6875
  } else {
6876
- const start2 = getFirstKeyStartProps(it.start);
6876
+ const start3 = getFirstKeyStartProps(it.start);
6877
6877
  this.stack.push({
6878
6878
  type: "block-map",
6879
6879
  offset: this.offset,
6880
6880
  indent: this.indent,
6881
- items: [{ start: start2, key: null, sep: [this.sourceToken] }]
6881
+ items: [{ start: start3, key: null, sep: [this.sourceToken] }]
6882
6882
  });
6883
6883
  }
6884
6884
  } else if (it.value) {
@@ -6888,10 +6888,10 @@ var require_parser = __commonJS({
6888
6888
  type: "block-map",
6889
6889
  offset: this.offset,
6890
6890
  indent: this.indent,
6891
- items: [{ start, key: null, sep: [this.sourceToken] }]
6891
+ items: [{ start: start2, key: null, sep: [this.sourceToken] }]
6892
6892
  });
6893
6893
  } else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
6894
- const start2 = getFirstKeyStartProps(it.start);
6894
+ const start3 = getFirstKeyStartProps(it.start);
6895
6895
  const key2 = it.key;
6896
6896
  const sep = it.sep;
6897
6897
  sep.push(this.sourceToken);
@@ -6901,10 +6901,10 @@ var require_parser = __commonJS({
6901
6901
  type: "block-map",
6902
6902
  offset: this.offset,
6903
6903
  indent: this.indent,
6904
- items: [{ start: start2, key: key2, sep }]
6904
+ items: [{ start: start3, key: key2, sep }]
6905
6905
  });
6906
- } else if (start.length > 0) {
6907
- it.sep = it.sep.concat(start, this.sourceToken);
6906
+ } else if (start2.length > 0) {
6907
+ it.sep = it.sep.concat(start2, this.sourceToken);
6908
6908
  } else {
6909
6909
  it.sep.push(this.sourceToken);
6910
6910
  }
@@ -6912,7 +6912,7 @@ var require_parser = __commonJS({
6912
6912
  if (!it.sep) {
6913
6913
  Object.assign(it, { key: null, sep: [this.sourceToken] });
6914
6914
  } else if (it.value || atNextItem) {
6915
- map.items.push({ start, key: null, sep: [this.sourceToken] });
6915
+ map.items.push({ start: start2, key: null, sep: [this.sourceToken] });
6916
6916
  } else if (includesToken(it.sep, "map-value-ind")) {
6917
6917
  this.stack.push({
6918
6918
  type: "block-map",
@@ -6932,7 +6932,7 @@ var require_parser = __commonJS({
6932
6932
  case "double-quoted-scalar": {
6933
6933
  const fs = this.flowScalar(this.type);
6934
6934
  if (atNextItem || it.value) {
6935
- map.items.push({ start, key: fs, sep: [] });
6935
+ map.items.push({ start: start2, key: fs, sep: [] });
6936
6936
  this.onKeyLine = true;
6937
6937
  } else if (it.sep) {
6938
6938
  this.stack.push(fs);
@@ -6956,7 +6956,7 @@ var require_parser = __commonJS({
6956
6956
  return;
6957
6957
  }
6958
6958
  } else if (atMapIndent) {
6959
- map.items.push({ start });
6959
+ map.items.push({ start: start2 });
6960
6960
  }
6961
6961
  this.stack.push(bv);
6962
6962
  return;
@@ -7093,7 +7093,7 @@ var require_parser = __commonJS({
7093
7093
  yield* this.step();
7094
7094
  } else if (this.type === "map-value-ind" && parent.type !== "flow-collection") {
7095
7095
  const prev = getPrevProps(parent);
7096
- const start = getFirstKeyStartProps(prev);
7096
+ const start2 = getFirstKeyStartProps(prev);
7097
7097
  fixFlowSeqItems(fc);
7098
7098
  const sep = fc.end.splice(1, fc.end.length);
7099
7099
  sep.push(this.sourceToken);
@@ -7101,7 +7101,7 @@ var require_parser = __commonJS({
7101
7101
  type: "block-map",
7102
7102
  offset: fc.offset,
7103
7103
  indent: fc.indent,
7104
- items: [{ start, key: fc, sep }]
7104
+ items: [{ start: start2, key: fc, sep }]
7105
7105
  };
7106
7106
  this.onKeyLine = true;
7107
7107
  this.stack[this.stack.length - 1] = map;
@@ -7160,35 +7160,35 @@ var require_parser = __commonJS({
7160
7160
  case "explicit-key-ind": {
7161
7161
  this.onKeyLine = true;
7162
7162
  const prev = getPrevProps(parent);
7163
- const start = getFirstKeyStartProps(prev);
7164
- start.push(this.sourceToken);
7163
+ const start2 = getFirstKeyStartProps(prev);
7164
+ start2.push(this.sourceToken);
7165
7165
  return {
7166
7166
  type: "block-map",
7167
7167
  offset: this.offset,
7168
7168
  indent: this.indent,
7169
- items: [{ start, explicitKey: true }]
7169
+ items: [{ start: start2, explicitKey: true }]
7170
7170
  };
7171
7171
  }
7172
7172
  case "map-value-ind": {
7173
7173
  this.onKeyLine = true;
7174
7174
  const prev = getPrevProps(parent);
7175
- const start = getFirstKeyStartProps(prev);
7175
+ const start2 = getFirstKeyStartProps(prev);
7176
7176
  return {
7177
7177
  type: "block-map",
7178
7178
  offset: this.offset,
7179
7179
  indent: this.indent,
7180
- items: [{ start, key: null, sep: [this.sourceToken] }]
7180
+ items: [{ start: start2, key: null, sep: [this.sourceToken] }]
7181
7181
  };
7182
7182
  }
7183
7183
  }
7184
7184
  return null;
7185
7185
  }
7186
- atIndentedComment(start, indent) {
7186
+ atIndentedComment(start2, indent) {
7187
7187
  if (this.type !== "comment")
7188
7188
  return false;
7189
7189
  if (this.indent <= indent)
7190
7190
  return false;
7191
- return start.every((st) => st.type === "newline" || st.type === "space");
7191
+ return start2.every((st) => st.type === "newline" || st.type === "space");
7192
7192
  }
7193
7193
  *documentEnd(docEnd) {
7194
7194
  if (this.type !== "doc-mode") {
@@ -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.40.2" : "dev";
7414
+ var CLI_VERSION = true ? "0.42.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}`;
@@ -7539,9 +7539,9 @@ function printState(state2, asJson) {
7539
7539
  `domain: ${typeof state2["domain"] === "string" ? state2["domain"] : "none. No mail is offered here: GET /v1/policy says so as email."}`
7540
7540
  ]);
7541
7541
  }
7542
- async function state(client, method, sandboxId, command2, options) {
7542
+ async function state(client, method, sandboxId, command3, options) {
7543
7543
  if (!sandboxId) {
7544
- throw new Error(`${command2} requires <sandbox-id>`);
7544
+ throw new Error(`${command3} requires <sandbox-id>`);
7545
7545
  }
7546
7546
  printState((await ask(client, method, mailOf(sandboxId))).body, options.json);
7547
7547
  }
@@ -7764,10 +7764,10 @@ async function ask2(client, method, pathname, body) {
7764
7764
  }
7765
7765
  return answered ?? {};
7766
7766
  }
7767
- function size(bytes3) {
7768
- if (bytes3 < 1e3) return `${bytes3} B`;
7769
- if (bytes3 < 1e6) return `${(bytes3 / 1e3).toFixed(1)} kB`;
7770
- return `${(bytes3 / 1e6).toFixed(1)} MB`;
7767
+ function size(bytes4) {
7768
+ if (bytes4 < 1e3) return `${bytes4} B`;
7769
+ if (bytes4 < 1e6) return `${(bytes4 / 1e3).toFixed(1)} kB`;
7770
+ return `${(bytes4 / 1e6).toFixed(1)} MB`;
7771
7771
  }
7772
7772
  async function files(client, args, options) {
7773
7773
  const [sandboxId, verb, first, second] = args;
@@ -7793,8 +7793,8 @@ ${USAGE2}`);
7793
7793
  const width = Math.max(0, ...entries.map((entry) => (entry["kind"] === "folder" ? "" : size(Number(entry["bytes"]))).length));
7794
7794
  for (const entry of entries) {
7795
7795
  const name = String(entry["name"]) + (entry["kind"] === "folder" ? "/" : "") + (entry["kind"] === "link" ? ` -> ${String(entry["target"] ?? "")}` : "");
7796
- const bytes3 = entry["kind"] === "folder" ? "" : size(Number(entry["bytes"]));
7797
- process.stdout.write(`${bytes3.padStart(width)} ${String(entry["modifiedAt"] ?? "").slice(0, 16).replace("T", " ")} ${name}
7796
+ const bytes4 = entry["kind"] === "folder" ? "" : size(Number(entry["bytes"]));
7797
+ process.stdout.write(`${bytes4.padStart(width)} ${String(entry["modifiedAt"] ?? "").slice(0, 16).replace("T", " ")} ${name}
7798
7798
  `);
7799
7799
  }
7800
7800
  if (body["truncated"] === true) {
@@ -7811,11 +7811,11 @@ ${USAGE2}`);
7811
7811
  case "put": {
7812
7812
  const local = need(first, "a local file and a path in the sandbox");
7813
7813
  const path6 = need(second, "a path in the sandbox");
7814
- const bytes3 = await readFile(local);
7815
- if (bytes3.length > LIMIT) {
7816
- throw new Error(`${local} is ${size(bytes3.length)}, over the 10 MB files put sends. agental scp copies bigger ones.`);
7814
+ const bytes4 = await readFile(local);
7815
+ if (bytes4.length > LIMIT) {
7816
+ throw new Error(`${local} is ${size(bytes4.length)}, over the 10 MB files put sends. agental scp copies bigger ones.`);
7817
7817
  }
7818
- const body = await ask2(client, "PUT", `${base}/files`, { path: path6, base64: bytes3.toString("base64") });
7818
+ const body = await ask2(client, "PUT", `${base}/files`, { path: path6, base64: bytes4.toString("base64") });
7819
7819
  process.stdout.write(options.json ? `${JSON.stringify(body, null, 2)}
7820
7820
  ` : `${String(body["path"])}: ${size(Number(body["bytes"]))}
7821
7821
  `);
@@ -7827,13 +7827,13 @@ ${USAGE2}`);
7827
7827
  if (!response.ok) {
7828
7828
  client.fail(response.status, await readObject2(response));
7829
7829
  }
7830
- const bytes3 = Buffer.from(await response.arrayBuffer());
7830
+ const bytes4 = Buffer.from(await response.arrayBuffer());
7831
7831
  if (second) {
7832
- await writeFile(second, bytes3);
7833
- process.stderr.write(`${second}: ${size(bytes3.length)}
7832
+ await writeFile(second, bytes4);
7833
+ process.stderr.write(`${second}: ${size(bytes4.length)}
7834
7834
  `);
7835
7835
  } else {
7836
- process.stdout.write(bytes3);
7836
+ process.stdout.write(bytes4);
7837
7837
  }
7838
7838
  return;
7839
7839
  }
@@ -7967,15 +7967,15 @@ function keyOf(body) {
7967
7967
  throw new Error("The answer was not an API key.");
7968
7968
  }
7969
7969
  const key2 = body;
7970
- const list3 = (value) => Array.isArray(value) ? value.map(String) : [];
7971
- return { ...key2, actions: list3(key2.actions), sandboxIds: list3(key2.sandboxIds), templateIds: list3(key2.templateIds), allowFrom: list3(key2.allowFrom) };
7970
+ const list4 = (value) => Array.isArray(value) ? value.map(String) : [];
7971
+ return { ...key2, actions: list4(key2.actions), sandboxIds: list4(key2.sandboxIds), templateIds: list4(key2.templateIds), allowFrom: list4(key2.allowFrom) };
7972
7972
  }
7973
7973
  function keysOf(body) {
7974
7974
  const listed = body?.apiKeys;
7975
7975
  return (Array.isArray(listed) ? listed : []).map(keyOf);
7976
7976
  }
7977
- function at(moment) {
7978
- return new Date(moment).toISOString().replace(/\.\d+Z$/, "Z");
7977
+ function at(moment2) {
7978
+ return new Date(moment2).toISOString().replace(/\.\d+Z$/, "Z");
7979
7979
  }
7980
7980
  function listIn(given) {
7981
7981
  return (given ?? []).flatMap((each) => each.split(",")).map((each) => each.trim()).filter((each) => each !== "");
@@ -8070,15 +8070,15 @@ function grantFrom(options) {
8070
8070
  }
8071
8071
  function expiryFrom(given, now = Date.now()) {
8072
8072
  const text = given.trim();
8073
- const span2 = /^(\d+)([dh])$/.exec(text);
8074
- if (span2 && Number(span2[1]) > 0) {
8075
- return at(now + Number(span2[1]) * (span2[2] === "d" ? 24 : 1) * HOUR_MS);
8073
+ const span3 = /^(\d+)([dh])$/.exec(text);
8074
+ if (span3 && Number(span3[1]) > 0) {
8075
+ return at(now + Number(span3[1]) * (span3[2] === "d" ? 24 : 1) * HOUR_MS);
8076
8076
  }
8077
- const moment = /^\d{4}-\d{2}-\d{2}/.test(text) ? Date.parse(text) : Number.NaN;
8078
- if (Number.isNaN(moment)) {
8077
+ const moment2 = /^\d{4}-\d{2}-\d{2}/.test(text) ? Date.parse(text) : Number.NaN;
8078
+ if (Number.isNaN(moment2)) {
8079
8079
  throw new Error("--expires is when the key stops working: a date, as 2026-12-31, a date and time, as 2026-12-31T18:00:00Z, or days or hours from now, as 30d or 12h.");
8080
8080
  }
8081
- return new Date(moment).toISOString();
8081
+ return new Date(moment2).toISOString();
8082
8082
  }
8083
8083
  async function templateIdsOf(client, words2) {
8084
8084
  if (words2.every((word) => word.startsWith("tpl_"))) {
@@ -8216,8 +8216,8 @@ import { createServer } from "node:http";
8216
8216
  import os2 from "node:os";
8217
8217
  var WAIT_MS = 10 * 60 * 1e3;
8218
8218
  var tty = () => Boolean(process.stdin.isTTY && process.stdout.isTTY);
8219
- function terminal(json2) {
8220
- const stream = json2 ? process.stderr : process.stdout;
8219
+ function terminal(json3) {
8220
+ const stream = json3 ? process.stderr : process.stdout;
8221
8221
  return { interactive: tty(), say: (line) => stream.write(`${line}
8222
8222
  `) };
8223
8223
  }
@@ -8283,10 +8283,10 @@ async function whoIs(base, key2) {
8283
8283
  throw error;
8284
8284
  }
8285
8285
  }
8286
- async function pushRequest(base, ask10) {
8286
+ async function pushRequest(base, ask11) {
8287
8287
  let made;
8288
8288
  try {
8289
- made = await call(base, "POST", "/v1/cli-sign-ins", ask10);
8289
+ made = await call(base, "POST", "/v1/cli-sign-ins", ask11);
8290
8290
  } catch (error) {
8291
8291
  if (error instanceof Refused && (error.status === 401 || error.status === 404)) {
8292
8292
  throw new Error(`${base} does not sign the command in through the browser. Make a key in its console, under API keys, and run agental login --key.`);
@@ -8488,12 +8488,12 @@ async function useOrganization(base, organization) {
8488
8488
  )
8489
8489
  );
8490
8490
  }
8491
- async function whoami(base, key2, json2) {
8491
+ async function whoami(base, key2, json3) {
8492
8492
  const fromEnv = Boolean(process.env["AGENTAL_API_KEY"]?.trim());
8493
8493
  const saved = loadCredentials();
8494
8494
  const who = key2 ? await whoIs(base, key2) : null;
8495
8495
  const source = fromEnv ? "AGENTAL_API_KEY" : saved && sameApi(saved.apiUrl, base) ? credentialsPath() : null;
8496
- if (json2) {
8496
+ if (json3) {
8497
8497
  process.stdout.write(`${JSON.stringify({ apiUrl: base, signedIn: who !== null, account: who, keyFrom: source, keyName: fromEnv ? null : saved?.keyName ?? null }, null, 2)}
8498
8498
  `);
8499
8499
  if (!who) {
@@ -8633,9 +8633,9 @@ function addToToml(agent, folder, url) {
8633
8633
  replaceFile(file, `${text}${lead}[mcp_servers.${CONNECTOR_NAME}]${eol}url = "${url}"${eol}`);
8634
8634
  return { agent, did: "added" };
8635
8635
  }
8636
- function run(command2, args, cwd) {
8636
+ function run(command3, args, cwd) {
8637
8637
  return new Promise((resolve) => {
8638
- execFile(command2, args, { encoding: "utf8", timeout: 6e4, cwd, shell: process.platform === "win32" }, (error, stdout, stderr) => {
8638
+ execFile(command3, args, { encoding: "utf8", timeout: 6e4, cwd, shell: process.platform === "win32" }, (error, stdout, stderr) => {
8639
8639
  const out = `${stdout}${stderr}`.trim();
8640
8640
  const missing = error?.code === "ENOENT" || process.platform === "win32" && /is not recognized as an internal or external command/i.test(out);
8641
8641
  resolve({ ok: !error, out, missing });
@@ -8686,8 +8686,8 @@ function claudeDesktopHere(places, platform = process.platform, env = process.en
8686
8686
  function addToClaudeLink(url) {
8687
8687
  return `https://claude.ai/customize/connectors?modal=add-custom-connector&connectorName=${CONNECTOR_NAME}&connectorUrl=${encodeURIComponent(url)}`;
8688
8688
  }
8689
- function names(list3) {
8690
- return list3.length < 2 ? list3[0] ?? "" : `${list3.slice(0, -1).join(", ")} and ${list3.at(-1)}`;
8689
+ function names(list4) {
8690
+ return list4.length < 2 ? list4[0] ?? "" : `${list4.slice(0, -1).join(", ")} and ${list4.at(-1)}`;
8691
8691
  }
8692
8692
  async function ensureConnector(site2, places = placesFrom()) {
8693
8693
  const url = `${site2}/v1/mcp`;
@@ -9271,11 +9271,11 @@ function completionStep(shell2 = process.env["SHELL"], home = os5.homedir()) {
9271
9271
  return [`echo '${line}' >> ~/${config}`, "Tab completion, from your next terminal"];
9272
9272
  }
9273
9273
  function nextSteps(term, rows) {
9274
- const width = Math.max(...rows.map(([command2]) => command2.length));
9274
+ const width = Math.max(...rows.map(([command3]) => command3.length));
9275
9275
  term.say(`
9276
9276
  ${bold("Next")}`);
9277
- for (const [command2, what] of rows) {
9278
- term.say(` ${command2.padEnd(width)} ${dim(what)}`);
9277
+ for (const [command3, what] of rows) {
9278
+ term.say(` ${command3.padEnd(width)} ${dim(what)}`);
9279
9279
  }
9280
9280
  term.say("");
9281
9281
  }
@@ -9446,6 +9446,30 @@ var COMMANDS = [
9446
9446
  ["-- <command> [args...]", "what to run; everything after -- is the command's own"]
9447
9447
  ]
9448
9448
  },
9449
+ {
9450
+ name: "command",
9451
+ summary: "Start a command in a sandbox that runs on by itself, follow its output, write its stdin and signal it.",
9452
+ examples: [
9453
+ "agental command start sbx_2a9a47e50daec64a --name build --no-timeout -- npm run build",
9454
+ "agental command logs sbx_2a9a47e50daec64a cmd_0123456789abcdef --follow",
9455
+ "agental command start sbx_2a9a47e50daec64a --stdin -- sh -c 'wc -l'",
9456
+ "agental command stdin sbx_2a9a47e50daec64a cmd_0123456789abcdef < big.csv",
9457
+ "agental command kill sbx_2a9a47e50daec64a cmd_0123456789abcdef --grace 10"
9458
+ ],
9459
+ flags: [
9460
+ ["-- <command> [args...]", "start: what to run, with no shell; everything after -- is the command's own"],
9461
+ ["--name <name>", 'start: what it is for, as lists and the console show it, such as "dev server"; never a secret'],
9462
+ ["--cwd <dir>", "start: the absolute folder it runs in (default: the sandbox's work folder)"],
9463
+ ["--env <NAME>=<value>", "start: a variable for it alone, or NAME for the value it has here (may be given again); never printed"],
9464
+ ["--timeout <seconds>", "start: end it after this long, as 90 or 10m, up to 10m (default 60s)"],
9465
+ ["--no-timeout", "start: no limit of its own: it runs until it exits or its sandbox stops"],
9466
+ ["--stdin", "start: let command stdin write its stdin (default: /dev/null)"],
9467
+ ["-f, --follow", "logs: follow it to its end, and exit with its exit code"],
9468
+ ["--grace <seconds>", "kill: how long to wait between TERM and KILL (default 5)"],
9469
+ ["--limit <n>", "list: how many, 1 to 100 (default 50)"],
9470
+ ["--json", "start, list, get, signal, kill: print as JSON"]
9471
+ ]
9472
+ },
9449
9473
  {
9450
9474
  name: "shell",
9451
9475
  summary: "Open a login shell in a sandbox, in this terminal, with no SSH key or port. It is kept: ~d leaves it running.",
@@ -9498,8 +9522,9 @@ var COMMANDS = [
9498
9522
  {
9499
9523
  name: "start",
9500
9524
  summary: "Start a stopped sandbox, or every one --where finds.",
9501
- examples: ["agental start sbx_2a9a47e50daec64a"],
9525
+ examples: ["agental start sbx_2a9a47e50daec64a", "agental start sbx_2a9a47e50daec64a --without-memory"],
9502
9526
  flags: [
9527
+ ["--without-memory", "start from its disk and let its kept memory go for good: files kept, running programs lost"],
9503
9528
  ["--where '<words>'", "every sandbox the words find, as one bulk action"],
9504
9529
  ["--yes", "with --where: start them without asking"],
9505
9530
  ["--max-burst-fee <dollars>", "the most this start may pay in burst fees"]
@@ -9741,7 +9766,7 @@ var MAP = [
9741
9766
  ["sh", "make a sandbox and open a shell in it"],
9742
9767
  ["create", "make a sandbox"],
9743
9768
  ["list", "your sandboxes"],
9744
- ["exec", "run a command in a sandbox"],
9769
+ ["exec, command", "run a command in a sandbox, or start one that runs on"],
9745
9770
  ["shell, ssh", "open a shell in a sandbox, here or over SSH"]
9746
9771
  ]
9747
9772
  ],
@@ -9806,9 +9831,9 @@ function usageOf(reference) {
9806
9831
  const found = /* @__PURE__ */ new Map();
9807
9832
  let open = null;
9808
9833
  for (const line of reference.split("\n")) {
9809
- const start = /^ {2}agental ([a-z][a-z-]*)\b/.exec(line);
9810
- if (start) {
9811
- const name = start[1];
9834
+ const start2 = /^ {2}agental ([a-z][a-z-]*)\b/.exec(line);
9835
+ if (start2) {
9836
+ const name = start2[1];
9812
9837
  open = found.get(name) ?? [];
9813
9838
  open.push(line.trim());
9814
9839
  found.set(name, open);
@@ -10046,7 +10071,7 @@ function wordsOf(part) {
10046
10071
  if (first.startsWith("-") || first.startsWith("<") || first === "") {
10047
10072
  return [];
10048
10073
  }
10049
- return first.split("|").filter((word) => /^[a-z][a-z-]*$/.test(word));
10074
+ return first.split("|").filter((word) => /^[A-Za-z][A-Za-z0-9-]*$/.test(word));
10050
10075
  }
10051
10076
  function flagsOf(usages) {
10052
10077
  const flags2 = /* @__PURE__ */ new Map();
@@ -10066,6 +10091,7 @@ var SANDBOX_VERBS2 = /* @__PURE__ */ new Set(["list", "create", "start", "stop",
10066
10091
  var TEMPLATE = /^<template>/;
10067
10092
  var JOB = /^<job>/;
10068
10093
  var KEPT_SHELL = /^<shell>/;
10094
+ var COMMAND_ID = /^<command-id>/;
10069
10095
  async function complete(typed, reference, operator, fetchJson) {
10070
10096
  if (typed[0] === "sandbox" && typed.length > 2 && SANDBOX_VERBS2.has(typed[1])) {
10071
10097
  return complete(typed.slice(1), reference, operator, fetchJson);
@@ -10112,8 +10138,8 @@ async function complete(typed, reference, operator, fetchJson) {
10112
10138
  return starting(await sandboxes(fetchJson));
10113
10139
  }
10114
10140
  if (KEPT_SHELL.test(valueOf)) {
10115
- const sandbox = before.slice(1).find((word) => /^sbx_[A-Za-z0-9]+$/.test(word));
10116
- return sandbox ? starting(await keptShells(fetchJson, sandbox)) : [];
10141
+ const sandbox2 = before.slice(1).find((word) => /^sbx_[A-Za-z0-9]+$/.test(word));
10142
+ return sandbox2 ? starting(await keptShells(fetchJson, sandbox2)) : [];
10117
10143
  }
10118
10144
  const choices = valueOf.split("|").filter((word) => /^[a-z0-9][a-z0-9.-]*$/i.test(word));
10119
10145
  return starting(choices.map((value) => ({ value })));
@@ -10134,6 +10160,7 @@ async function complete(typed, reference, operator, fetchJson) {
10134
10160
  let wantsSandbox = false;
10135
10161
  let wantsTemplate = false;
10136
10162
  let wantsJob = false;
10163
+ let wantsCommand = false;
10137
10164
  for (const usage of usages) {
10138
10165
  const parts = partsOf(usage).slice(1);
10139
10166
  const fits = positionals.every((word, index) => {
@@ -10155,6 +10182,7 @@ async function complete(typed, reference, operator, fetchJson) {
10155
10182
  wantsSandbox ||= SANDBOX.test(inner);
10156
10183
  wantsTemplate ||= TEMPLATE.test(inner);
10157
10184
  wantsJob ||= JOB.test(inner);
10185
+ wantsCommand ||= COMMAND_ID.test(inner);
10158
10186
  }
10159
10187
  if (positionals.length === 0) {
10160
10188
  for (const word of SUBCOMMANDS[name] ?? []) {
@@ -10164,7 +10192,13 @@ async function complete(typed, reference, operator, fetchJson) {
10164
10192
  if (name === "billing" && positionals[0] === "card" && positionals.length === 1) {
10165
10193
  candidates.set("save", { value: "save", about: "save a card, charged nothing" });
10166
10194
  }
10167
- const asked2 = [...wantsSandbox ? await sandboxes(fetchJson) : [], ...wantsTemplate ? await templates(fetchJson) : [], ...wantsJob ? await jobs(fetchJson) : []];
10195
+ const sandbox = positionals.find((word) => /^sbx_[A-Za-z0-9]+$/.test(word));
10196
+ const asked2 = [
10197
+ ...wantsSandbox ? await sandboxes(fetchJson) : [],
10198
+ ...wantsTemplate ? await templates(fetchJson) : [],
10199
+ ...wantsJob ? await jobs(fetchJson) : [],
10200
+ ...wantsCommand && sandbox !== void 0 ? await commandsIn(fetchJson, sandbox) : []
10201
+ ];
10168
10202
  return starting([...candidates.values(), ...asked2]);
10169
10203
  }
10170
10204
  async function sandboxes(api2) {
@@ -10184,6 +10218,19 @@ async function keptShells(api2, sandbox) {
10184
10218
  return about ? { value: String(each["n"]), about } : { value: String(each["n"]) };
10185
10219
  });
10186
10220
  }
10221
+ async function commandsIn(api2, sandbox) {
10222
+ let listed;
10223
+ try {
10224
+ const body = await api2.get(`/v1/sandboxes/${encodeURIComponent(sandbox)}/commands?limit=50`);
10225
+ listed = Array.isArray(body?.commands) ? body.commands : [];
10226
+ } catch {
10227
+ return [];
10228
+ }
10229
+ return listed.filter((each) => typeof each["id"] === "string").map((each) => {
10230
+ const about = each["status"] === "running" ? "running" : typeof each["exitCode"] === "number" ? `exited ${each["exitCode"]}` : typeof each["endReason"] === "string" ? each["endReason"].replace(/_/g, " ") : typeof each["status"] === "string" ? each["status"] : "";
10231
+ return about ? { value: each["id"], about } : { value: each["id"] };
10232
+ });
10233
+ }
10187
10234
  async function templates(api2) {
10188
10235
  const body = await cached("templates", api2.as, () => api2.get("/v1/templates"));
10189
10236
  const listed = Array.isArray(body) ? body : body?.templates ?? [];
@@ -10199,7 +10246,7 @@ async function jobs(api2) {
10199
10246
  });
10200
10247
  }
10201
10248
  var KEPT_MS = 3e4;
10202
- async function cached(what, as, ask10) {
10249
+ async function cached(what, as, ask11) {
10203
10250
  const folder = path5.join(process.env["XDG_CACHE_HOME"] || path5.join(os6.homedir(), ".cache"), "agental");
10204
10251
  const file = path5.join(folder, `complete-${what}-${createHash2("sha256").update(as).digest("hex").slice(0, 16)}.json`);
10205
10252
  try {
@@ -10211,7 +10258,7 @@ async function cached(what, as, ask10) {
10211
10258
  }
10212
10259
  let body = null;
10213
10260
  try {
10214
- body = await ask10();
10261
+ body = await ask11();
10215
10262
  } catch {
10216
10263
  return null;
10217
10264
  }
@@ -10366,8 +10413,8 @@ async function ask5(client, method, pathname, body) {
10366
10413
  function pad(text, width) {
10367
10414
  return text.length >= width ? `${text.slice(0, width - 1)}\u2026 ` : text.padEnd(width + 1);
10368
10415
  }
10369
- function print2(json2, body, words2) {
10370
- process.stdout.write(json2 ? `${JSON.stringify(body, null, 2)}
10416
+ function print2(json3, body, words2) {
10417
+ process.stdout.write(json3 ? `${JSON.stringify(body, null, 2)}
10371
10418
  ` : words2);
10372
10419
  }
10373
10420
  async function organizations(client) {
@@ -10375,12 +10422,12 @@ async function organizations(client) {
10375
10422
  const me = await ask5(client, "GET", "/v1/me");
10376
10423
  return { organizations: Array.isArray(listed) ? listed : [], acting: String(me["activeOrganizationId"] ?? "") };
10377
10424
  }
10378
- function organizationNamed(list3, given) {
10379
- const byId = list3.find((organization) => organization.id === given);
10425
+ function organizationNamed(list4, given) {
10426
+ const byId = list4.find((organization) => organization.id === given);
10380
10427
  if (byId) {
10381
10428
  return byId;
10382
10429
  }
10383
- const byName = list3.filter((organization) => organization.name.toLowerCase() === given.toLowerCase());
10430
+ const byName = list4.filter((organization) => organization.name.toLowerCase() === given.toLowerCase());
10384
10431
  if (byName.length === 1 && byName[0]) {
10385
10432
  return byName[0];
10386
10433
  }
@@ -10393,14 +10440,14 @@ async function org(client, positionals, options, signInTo) {
10393
10440
  const [verb = "list", ...rest] = positionals;
10394
10441
  switch (verb) {
10395
10442
  case "list": {
10396
- const { organizations: list3, acting } = await organizations(client);
10443
+ const { organizations: list4, acting } = await organizations(client);
10397
10444
  if (options.json) {
10398
- print2(true, { organizations: list3.map((organization) => ({ ...organization, acting: organization.id === acting })) }, "");
10445
+ print2(true, { organizations: list4.map((organization) => ({ ...organization, acting: organization.id === acting })) }, "");
10399
10446
  return;
10400
10447
  }
10401
10448
  process.stdout.write(` ${[pad("ID", 22), pad("NAME", 24), "ROLE"].join(" ")}
10402
10449
  `);
10403
- for (const organization of list3) {
10450
+ for (const organization of list4) {
10404
10451
  const role = organization.personal ? "your own" : organization.role ?? "";
10405
10452
  process.stdout.write(`${organization.id === acting ? "*" : " "} ${[pad(organization.id, 22), pad(organization.name, 24), role].join(" ")}
10406
10453
  `);
@@ -10413,8 +10460,8 @@ async function org(client, positionals, options, signInTo) {
10413
10460
  if (!given) {
10414
10461
  throw new Error("org use takes the organization's id or name: agental org use Acme.");
10415
10462
  }
10416
- const { organizations: list3, acting } = await organizations(client);
10417
- const chosen = organizationNamed(list3, given);
10463
+ const { organizations: list4, acting } = await organizations(client);
10464
+ const chosen = organizationNamed(list4, given);
10418
10465
  if (chosen.id === acting) {
10419
10466
  process.stdout.write(`This command's key acts in ${chosen.name} already.
10420
10467
  `);
@@ -10444,15 +10491,15 @@ agental org use ${organization.id} signs this command in to it.
10444
10491
  }
10445
10492
  }
10446
10493
  async function actingTeam(client) {
10447
- const { organizations: list3, acting } = await organizations(client);
10448
- const team = list3.find((organization) => organization.id === acting);
10494
+ const { organizations: list4, acting } = await organizations(client);
10495
+ const team = list4.find((organization) => organization.id === acting);
10449
10496
  if (!team) {
10450
10497
  throw new Error("This command's key acts in no organization you are in. agental org use <organization> signs it in to one.");
10451
10498
  }
10452
10499
  return team;
10453
10500
  }
10454
- function memberNamed(list3, given) {
10455
- const found = list3.find((member) => member.userId === given || member.email?.toLowerCase() === given.toLowerCase());
10501
+ function memberNamed(list4, given) {
10502
+ const found = list4.find((member) => member.userId === given || member.email?.toLowerCase() === given.toLowerCase());
10456
10503
  if (!found) {
10457
10504
  throw new Error(`No member ${given} in this team. agental members lists them.`);
10458
10505
  }
@@ -10462,7 +10509,7 @@ async function members(client, positionals, options) {
10462
10509
  const [verb = "list", target] = positionals;
10463
10510
  const team = await actingTeam(client);
10464
10511
  const listed = await ask5(client, "GET", `/v1/organizations/${encodeURIComponent(team.id)}/members`);
10465
- const list3 = Array.isArray(listed["members"]) ? listed["members"] : [];
10512
+ const list4 = Array.isArray(listed["members"]) ? listed["members"] : [];
10466
10513
  switch (verb) {
10467
10514
  case "list": {
10468
10515
  if (options.json) {
@@ -10474,7 +10521,7 @@ async function members(client, positionals, options) {
10474
10521
  `);
10475
10522
  process.stdout.write(`${[pad("ID", 34), pad("EMAIL", 30), pad("ROLE", 8), "ADDED"].join(" ")}
10476
10523
  `);
10477
- for (const member of list3) {
10524
+ for (const member of list4) {
10478
10525
  process.stdout.write(`${[pad(member.userId, 34), pad(member.email ?? member.name ?? "", 30), pad(member.role, 8), member.addedAt.slice(0, 10)].join(" ")}
10479
10526
  `);
10480
10527
  }
@@ -10484,7 +10531,7 @@ async function members(client, positionals, options) {
10484
10531
  if (!target) {
10485
10532
  throw new Error("members remove takes the member's id or email: agental members remove cy@example.com.");
10486
10533
  }
10487
- const member = memberNamed(list3, target);
10534
+ const member = memberNamed(list4, target);
10488
10535
  const query = options.revokeKeys ? "?revokeKeys=true" : "";
10489
10536
  const removed = await ask5(client, "DELETE", `/v1/organizations/${encodeURIComponent(team.id)}/members/${encodeURIComponent(member.userId)}${query}`);
10490
10537
  const revoked = Number(removed["revokedKeys"] ?? 0);
@@ -10574,14 +10621,14 @@ var json = (value) => {
10574
10621
  process.stdout.write(`${JSON.stringify(value, null, 2)}
10575
10622
  `);
10576
10623
  };
10577
- function at2(moment) {
10578
- return new Date(moment).toISOString().replace(/\.\d+Z$/, "Z");
10624
+ function at2(moment2) {
10625
+ return new Date(moment2).toISOString().replace(/\.\d+Z$/, "Z");
10579
10626
  }
10580
- function soon(moment) {
10581
- return isTerminal(process.stdout) ? until(moment) ?? at2(moment) : at2(moment);
10627
+ function soon(moment2) {
10628
+ return isTerminal(process.stdout) ? until(moment2) ?? at2(moment2) : at2(moment2);
10582
10629
  }
10583
- function past(moment) {
10584
- return isTerminal(process.stdout) ? ago(moment) ?? at2(moment) : at2(moment);
10630
+ function past(moment2) {
10631
+ return isTerminal(process.stdout) ? ago(moment2) ?? at2(moment2) : at2(moment2);
10585
10632
  }
10586
10633
  function whenOf(job2) {
10587
10634
  if (job2.at) {
@@ -10719,11 +10766,11 @@ function timeoutMsOf(text) {
10719
10766
  return Number(match[1]) * unit * 1e3;
10720
10767
  }
10721
10768
  function atOf(text) {
10722
- const moment = Date.parse(text);
10723
- if (Number.isNaN(moment)) {
10769
+ const moment2 = Date.parse(text);
10770
+ if (Number.isNaN(moment2)) {
10724
10771
  throw new Error(`--at is a date and time, as 2026-11-04T09:00:00Z or 2026-11-04T09:00 in your own time: ${text} is not.`);
10725
10772
  }
10726
- return new Date(moment).toISOString();
10773
+ return new Date(moment2).toISOString();
10727
10774
  }
10728
10775
  function sandboxGiven(options) {
10729
10776
  if (options.sandbox !== void 0 && options.sandbox.length > 1) {
@@ -10980,7 +11027,7 @@ var why = (run3) => run3.reason ? `: ${run3.reason.replace(/\.$/, "")}` : "";
10980
11027
  function exitOf(run3) {
10981
11028
  return run3.exitCode ?? (run3.outcome === "succeeded" ? 0 : 1);
10982
11029
  }
10983
- async function job(client, positionals, command2, options) {
11030
+ async function job(client, positionals, command3, options) {
10984
11031
  const [what, name, ...rest] = positionals;
10985
11032
  if (what === void 0) {
10986
11033
  throw new Error(USAGE4);
@@ -10992,7 +11039,7 @@ async function job(client, positionals, command2, options) {
10992
11039
  await listJobs(client, options);
10993
11040
  return;
10994
11041
  }
10995
- if (command2 !== null && what !== "add" && what !== "update") {
11042
+ if (command3 !== null && what !== "add" && what !== "update") {
10996
11043
  throw new Error(`job ${what} takes no command after --.`);
10997
11044
  }
10998
11045
  if ([options.signature, options.header, options.respond, options.rate].some((given) => given !== void 0) && what !== "trigger") {
@@ -11029,7 +11076,7 @@ async function job(client, positionals, command2, options) {
11029
11076
  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);
11030
11077
  }
11031
11078
  if (what === "add") {
11032
- if (command2 === null || command2.length === 0) {
11079
+ if (command3 === null || command3.length === 0) {
11033
11080
  throw new Error("job add needs a command after --, as agental job add nightly --sandbox <sandbox> --every 1h -- python scrape.py");
11034
11081
  }
11035
11082
  if (sandboxGiven(options) === void 0 && templateGiven(options) === void 0) {
@@ -11039,7 +11086,7 @@ async function job(client, positionals, command2, options) {
11039
11086
  throw new Error("Give the job's name once: agental job add <name> ...");
11040
11087
  }
11041
11088
  const given = name ?? options.name;
11042
- const made = await ask6(client, "POST", "/v1/jobs", { ...given === void 0 ? {} : { name: given }, command: commandLine(command2), ...fieldsOf(options) });
11089
+ const made = await ask6(client, "POST", "/v1/jobs", { ...given === void 0 ? {} : { name: given }, command: commandLine(command3), ...fieldsOf(options) });
11043
11090
  print3(made, options.json);
11044
11091
  return;
11045
11092
  }
@@ -11055,7 +11102,7 @@ async function job(client, positionals, command2, options) {
11055
11102
  print3(await ask6(client, "GET", path6), options.json);
11056
11103
  return;
11057
11104
  case "update": {
11058
- const changes = { ...fieldsOf(options), ...options.name === void 0 ? {} : { name: options.name }, ...command2 !== null && command2.length > 0 ? { command: commandLine(command2) } : {} };
11105
+ const changes = { ...fieldsOf(options), ...options.name === void 0 ? {} : { name: options.name }, ...command3 !== null && command3.length > 0 ? { command: commandLine(command3) } : {} };
11059
11106
  if (Object.keys(changes).length === 0) {
11060
11107
  throw new Error(
11061
11108
  "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, --max-monthly-spend, --input or --secret-input, --after-job, --on-mail or --no-events, --name for a new name, or a new command after --."
@@ -11508,9 +11555,9 @@ async function apply(client, file, options) {
11508
11555
  `);
11509
11556
  client.fail(response.status, body);
11510
11557
  }
11511
- const put = body;
11512
- applied ??= orgOf(put);
11513
- say(response.status === 201 ? "made" : response.headers.get("agental-changed") === "false" ? "unchanged" : "changed", each.name, put.id);
11558
+ const put2 = body;
11559
+ applied ??= orgOf(put2);
11560
+ say(response.status === 201 ? "made" : response.headers.get("agental-changed") === "false" ? "unchanged" : "changed", each.name, put2.id);
11514
11561
  }
11515
11562
  if (options.prune) {
11516
11563
  if (applied === void 0) {
@@ -11527,6 +11574,639 @@ async function apply(client, file, options) {
11527
11574
  }
11528
11575
  }
11529
11576
 
11577
+ // ../src/cli-command.ts
11578
+ var SIGNALS = ["TERM", "KILL", "INT", "HUP", "QUIT", "USR1", "USR2", "STOP", "CONT"];
11579
+ var SIGNAL_NAMES = { 1: "HUP", 2: "INT", 3: "QUIT", 4: "ILL", 5: "TRAP", 6: "ABRT", 7: "BUS", 8: "FPE", 9: "KILL", 10: "USR1", 11: "SEGV", 12: "USR2", 13: "PIPE", 14: "ALRM", 15: "TERM", 18: "CONT", 19: "STOP", 24: "XCPU", 25: "XFSZ" };
11580
+ var STDIN_PIECE = 1024 * 1024;
11581
+ var TRIES = 6;
11582
+ var FIRST_WAIT_MS = 250;
11583
+ var MOST_WAIT_MS = 4e3;
11584
+ var SILENT_MS = 6e4;
11585
+ var GRACE_SECONDS = 5;
11586
+ var LOOK_MS = 500;
11587
+ var AFTER_KILL_MS = 3e4;
11588
+ var TIMED_OUT_EXIT = 124;
11589
+ var NO_EXIT = 255;
11590
+ var USAGE5 = "command takes start, list, get, logs, signal, kill, stdin or delete, then the sandbox: agental command start <sandbox-id> -- npm test. agental command --help shows each.";
11591
+ var json2 = (value) => {
11592
+ process.stdout.write(`${JSON.stringify(value, null, 2)}
11593
+ `);
11594
+ };
11595
+ var sleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
11596
+ var waitBefore = (tried) => Math.min(MOST_WAIT_MS, FIRST_WAIT_MS * 2 ** (tried - 1));
11597
+ var errorText = (error) => error instanceof Error ? error.message : String(error);
11598
+ var reason = (text) => text.replace(/\.$/, "");
11599
+ async function bodyOf(response) {
11600
+ try {
11601
+ return await response.json();
11602
+ } catch {
11603
+ return null;
11604
+ }
11605
+ }
11606
+ async function ask7(client, method, pathname, body) {
11607
+ const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
11608
+ const answered = response.status === 204 ? null : await bodyOf(response);
11609
+ if (!response.ok) {
11610
+ client.fail(response.status, answered);
11611
+ }
11612
+ return answered;
11613
+ }
11614
+ async function command2(client, words2, argv, options) {
11615
+ const [verb, sandbox, ...rest] = words2;
11616
+ if (verb === void 0) {
11617
+ throw new Error(USAGE5);
11618
+ }
11619
+ if (sandbox === void 0) {
11620
+ throw new Error(`command ${verb} needs the sandbox${verb === "start" || verb === "list" ? "" : " and the command"}: agental command ${verb} <sandbox-id>${verb === "start" ? " -- <command> [args...]" : verb === "list" ? "" : " <command-id>"}. agental list shows your sandboxes' ids.`);
11621
+ }
11622
+ if (verb !== "start" && argv !== null) {
11623
+ throw new Error(`command ${verb} takes nothing after --: only command start runs what follows it.`);
11624
+ }
11625
+ const commands = `/v1/sandboxes/${encodeURIComponent(sandbox)}/commands`;
11626
+ if (verb === "start") {
11627
+ await start(client, sandbox, commands, argv ?? rest, argv !== null && rest.length > 0 ? rest : [], options);
11628
+ return;
11629
+ }
11630
+ if (verb === "list") {
11631
+ nothingMore(verb, rest);
11632
+ await list2(client, sandbox, commands, options);
11633
+ return;
11634
+ }
11635
+ const [id, ...after] = rest;
11636
+ if (id === void 0) {
11637
+ throw new Error(`command ${verb} needs the command: agental command ${verb} ${sandbox} <command-id>${verb === "signal" ? " TERM" : ""}. agental command list ${sandbox} lists them.`);
11638
+ }
11639
+ const one = `${commands}/${encodeURIComponent(id)}`;
11640
+ switch (verb) {
11641
+ case "get":
11642
+ nothingMore(verb, after);
11643
+ show(await ask7(client, "GET", one), sandbox, options.json);
11644
+ return;
11645
+ case "logs":
11646
+ nothingMore(verb, after);
11647
+ await logs(client, sandbox, id, one, options.follow === true);
11648
+ return;
11649
+ case "signal": {
11650
+ const [given, ...more] = after;
11651
+ nothingMore(verb, more);
11652
+ if (given === void 0) {
11653
+ throw new Error(`command signal needs the signal to send, one of ${SIGNALS.join(", ")}: agental command signal ${sandbox} ${id} TERM`);
11654
+ }
11655
+ const signal = signalNamed(given);
11656
+ const sent = await ask7(client, "POST", `${one}/signal`, { signal });
11657
+ if (options.json) {
11658
+ json2(sent);
11659
+ return;
11660
+ }
11661
+ process.stdout.write(`Sent ${signal} to ${sent.signaled} ${sent.signaled === 1 ? "process" : "processes"} of ${id}.
11662
+ `);
11663
+ return;
11664
+ }
11665
+ case "kill":
11666
+ nothingMore(verb, after);
11667
+ await kill(client, id, one, options);
11668
+ return;
11669
+ case "stdin":
11670
+ nothingMore(verb, after);
11671
+ await writeStdin(client, sandbox, id, one);
11672
+ return;
11673
+ case "delete":
11674
+ nothingMore(verb, after);
11675
+ await ask7(client, "DELETE", one);
11676
+ process.stdout.write(`deleted ${id}
11677
+ `);
11678
+ return;
11679
+ default:
11680
+ throw new Error(USAGE5);
11681
+ }
11682
+ }
11683
+ function nothingMore(verb, words2) {
11684
+ if (words2.length > 0) {
11685
+ throw new Error(`command ${verb} does not take ${words2.join(" ")}. agental command --help shows what it takes.`);
11686
+ }
11687
+ }
11688
+ function signalNamed(given) {
11689
+ const name = given.toUpperCase().replace(/^SIG/, "");
11690
+ if (!SIGNALS.includes(name)) {
11691
+ throw new Error(`${given} is not a signal a command can be sent: ${SIGNALS.join(", ")}.`);
11692
+ }
11693
+ return name;
11694
+ }
11695
+ function timeoutMsOf2(text) {
11696
+ const match = /^([0-9]+(?:\.[0-9]+)?)(s|m)?$/.exec(text.trim());
11697
+ const ms = match ? Math.round(Number(match[1]) * (match[2] === "m" ? 6e4 : 1e3)) : NaN;
11698
+ if (!Number.isFinite(ms) || ms < 100 || ms > 6e5) {
11699
+ throw new Error("--timeout is how long it may run, in seconds as 90, or as 90s or 10m, from 0.1s to 10m. --no-timeout gives it no limit of its own.");
11700
+ }
11701
+ return ms;
11702
+ }
11703
+ function envOf(given) {
11704
+ const env = {};
11705
+ for (const each of given) {
11706
+ const equals = each.indexOf("=");
11707
+ const name = equals < 0 ? each : each.slice(0, equals);
11708
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) {
11709
+ throw new Error("--env takes NAME=VALUE, or NAME alone for the value it has here, with a name of letters, digits and underscores.");
11710
+ }
11711
+ const value = equals < 0 ? process.env[name] : each.slice(equals + 1);
11712
+ if (value === void 0) {
11713
+ throw new Error(`--env ${name} sends the value of ${name} here, and it is not set.`);
11714
+ }
11715
+ env[name] = value;
11716
+ }
11717
+ return env;
11718
+ }
11719
+ async function start(client, sandbox, commands, run3, extra, options) {
11720
+ if (extra.length > 0) {
11721
+ throw new Error(`command start takes the sandbox, then what to run after --: ${extra.join(" ")} is before it.`);
11722
+ }
11723
+ if (run3.length === 0) {
11724
+ throw new Error(`command start needs what to run, after --: agental command start ${sandbox} -- npm test`);
11725
+ }
11726
+ if (options.timeout !== void 0 && options["no-timeout"] === true) {
11727
+ throw new Error("command start takes --timeout or --no-timeout, not both.");
11728
+ }
11729
+ const body = {
11730
+ command: run3,
11731
+ ...options["no-timeout"] === true ? { timeoutMs: null } : options.timeout !== void 0 ? { timeoutMs: timeoutMsOf2(options.timeout) } : {},
11732
+ ...options.cwd !== void 0 ? { cwd: options.cwd } : {},
11733
+ ...options.env !== void 0 && options.env.length > 0 ? { env: envOf(options.env) } : {},
11734
+ ...options.stdin === true ? { stdin: true } : {},
11735
+ ...options.name !== void 0 ? { name: options.name } : {}
11736
+ };
11737
+ const started = await ask7(client, "POST", commands, body);
11738
+ if (options.json) {
11739
+ json2(started);
11740
+ return;
11741
+ }
11742
+ process.stdout.write(`${started.id}
11743
+ `);
11744
+ if (isTerminal(process.stderr)) {
11745
+ const next = [`agental command logs ${sandbox} ${started.id} --follow follows its output`, ...options.stdin === true ? [`agental command stdin ${sandbox} ${started.id} < <file> writes its input`] : []];
11746
+ process.stderr.write(faint(`${next.join("; ")}.
11747
+ `, process.stderr));
11748
+ }
11749
+ }
11750
+ var BYTE_UNITS = ["B", "KiB", "MiB", "GiB"];
11751
+ function bytes2(count) {
11752
+ let value = count;
11753
+ let unit = 0;
11754
+ while (unit < BYTE_UNITS.length - 1 && Math.round(value * 10) / 10 >= 1024) {
11755
+ value /= 1024;
11756
+ unit += 1;
11757
+ }
11758
+ return unit === 0 ? `${Math.round(value)} B` : `${value.toFixed(1)} ${BYTE_UNITS[unit]}`;
11759
+ }
11760
+ function span2(ms) {
11761
+ if (ms < 1e3) {
11762
+ return `${Math.max(0, Math.round(ms))}ms`;
11763
+ }
11764
+ const seconds2 = Math.round(ms / 1e3);
11765
+ if (seconds2 < 60) {
11766
+ return `${seconds2}s`;
11767
+ }
11768
+ if (seconds2 < 3600) {
11769
+ return `${Math.floor(seconds2 / 60)}m${seconds2 % 60 === 0 ? "" : ` ${seconds2 % 60}s`}`;
11770
+ }
11771
+ const minutes = Math.round(seconds2 / 60);
11772
+ return `${Math.floor(minutes / 60)}h${minutes % 60 === 0 ? "" : ` ${minutes % 60}m`}`;
11773
+ }
11774
+ var signalName = (signal) => signal === null ? "a signal" : `SIG${SIGNAL_NAMES[signal] ?? signal}`;
11775
+ function stateOf(command3) {
11776
+ if (command3.status === "running") {
11777
+ return command3.paused ? "running, paused while its sandbox is stopped with its memory" : command3.launched === false ? "starting: not yet known to have started" : "running";
11778
+ }
11779
+ switch (command3.endReason) {
11780
+ case "exited":
11781
+ return `exited ${command3.exitCode ?? "with no code"}`;
11782
+ case "signaled":
11783
+ return `ended by ${signalName(command3.signal)}`;
11784
+ case "timed_out":
11785
+ return command3.timeoutMs === null ? "timed out" : `timed out after ${span2(command3.timeoutMs)}`;
11786
+ case "failed_to_start":
11787
+ return "never started";
11788
+ case "sandbox_stopped":
11789
+ return "ended as its sandbox stopped";
11790
+ case "sandbox_restarted":
11791
+ return "ended as its sandbox restarted";
11792
+ case "sandbox_moved":
11793
+ return "ended as its sandbox moved to another server";
11794
+ case "lost":
11795
+ return "lost: what ran it died, and anything left of it was killed";
11796
+ default:
11797
+ return command3.exitCode === null ? command3.status.replace("_", " ") : `${command3.status} with ${command3.exitCode}`;
11798
+ }
11799
+ }
11800
+ function exitOf2(command3) {
11801
+ switch (command3.endReason) {
11802
+ case "exited":
11803
+ return command3.exitCode ?? NO_EXIT;
11804
+ case "signaled":
11805
+ return command3.signal === null ? NO_EXIT : 128 + command3.signal;
11806
+ case "timed_out":
11807
+ return TIMED_OUT_EXIT;
11808
+ case null:
11809
+ return command3.exitCode ?? (command3.status === "succeeded" ? 0 : command3.status === "timed_out" ? TIMED_OUT_EXIT : NO_EXIT);
11810
+ default:
11811
+ return NO_EXIT;
11812
+ }
11813
+ }
11814
+ function moment(iso) {
11815
+ const at4 = new Date(iso).toISOString().replace(/\.\d+Z$/, "Z");
11816
+ return isTerminal(process.stdout) ? ago(iso) ?? at4 : at4;
11817
+ }
11818
+ function tookOf2(command3) {
11819
+ const began = Date.parse(command3.startedAt);
11820
+ const ended2 = command3.finishedAt === null ? Date.now() : Date.parse(command3.finishedAt);
11821
+ return Number.isFinite(began) && Number.isFinite(ended2) ? span2(ended2 - began) : "-";
11822
+ }
11823
+ async function list2(client, sandbox, commands, options) {
11824
+ const body = await ask7(client, "GET", `${commands}${options.limit === void 0 ? "" : `?limit=${encodeURIComponent(options.limit)}`}`);
11825
+ const listed = body?.commands ?? [];
11826
+ if (options.json) {
11827
+ json2(listed);
11828
+ return;
11829
+ }
11830
+ if (listed.length === 0) {
11831
+ process.stdout.write(`No commands in ${sandbox}. agental command start ${sandbox} -- <command> starts one.
11832
+ `);
11833
+ return;
11834
+ }
11835
+ const terminal2 = isTerminal(process.stdout);
11836
+ const sized = listed.some((each) => typeof each.stdoutBytes === "number");
11837
+ const written = (count) => typeof count === "number" ? bytes2(count) : "-";
11838
+ const named = listed.some((each) => each.name != null);
11839
+ const rows = [
11840
+ ["ID", ...named ? ["NAME"] : [], "STATE", "STARTED", "TOOK", ...sized ? ["STDOUT", "STDERR"] : []],
11841
+ ...listed.map((each) => [each.id, ...named ? [each.name ?? "-"] : [], stateOf(each), moment(each.startedAt), tookOf2(each), ...sized ? [written(each.stdoutBytes), written(each.stderrBytes)] : []])
11842
+ ];
11843
+ process.stdout.write(fitted(rows, { ...terminal2 ? { give: 1 } : { width: Number.MAX_SAFE_INTEGER }, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
11844
+ }
11845
+ function show(command3, sandbox, asJson) {
11846
+ if (asJson) {
11847
+ json2(command3);
11848
+ return;
11849
+ }
11850
+ const kept2 = (stream) => {
11851
+ const written = command3[`${stream}Bytes`];
11852
+ if (typeof written !== "number") {
11853
+ return [];
11854
+ }
11855
+ const from = command3.outputFrom?.[stream] ?? 0;
11856
+ return [[stream, `${bytes2(written)} written${from > 0 ? `, readable from byte ${from}` : ""}`]];
11857
+ };
11858
+ const rows = [
11859
+ ["id", command3.id],
11860
+ ...command3.name == null ? [] : [["name", command3.name]],
11861
+ ["sandbox", command3.sandboxId],
11862
+ ["state", stateOf(command3)],
11863
+ ...command3.pid === null ? [] : [["pid", String(command3.pid)]],
11864
+ ["cwd", command3.cwd ?? "-"],
11865
+ ...command3.timeoutMs === void 0 ? [] : [["time limit", command3.timeoutMs === null ? "none" : span2(command3.timeoutMs)]],
11866
+ ["started", moment(command3.startedAt)],
11867
+ ...command3.finishedAt === null ? [] : [["finished", moment(command3.finishedAt)]],
11868
+ ["took", tookOf2(command3)],
11869
+ ...kept2("stdout"),
11870
+ ...kept2("stderr"),
11871
+ ...command3.stdin == null ? [] : [["stdin", `${command3.stdin.open ? "open" : "closed"}, ${bytes2(command3.stdin.offset)} taken`]]
11872
+ ];
11873
+ process.stdout.write(rows.map(([label, value]) => `${`${label}:`.padEnd(12)}${value}`).join("\n") + "\n");
11874
+ process.stdout.write(faint(`agental command logs ${sandbox} ${command3.id} prints its output.
11875
+ `));
11876
+ }
11877
+ function put(stream, data) {
11878
+ return new Promise((resolve, reject) => stream.write(data, (error) => error ? reject(error) : resolve()));
11879
+ }
11880
+ async function readOutput(client, path6, at4, follow2, wrote) {
11881
+ const controller = new AbortController();
11882
+ let silence = setTimeout(() => controller.abort(), SILENT_MS);
11883
+ const heard = () => {
11884
+ clearTimeout(silence);
11885
+ silence = setTimeout(() => controller.abort(), SILENT_MS);
11886
+ };
11887
+ let progressed = false;
11888
+ try {
11889
+ let response;
11890
+ try {
11891
+ response = await client.request(`${path6}?stdout=${at4.stdout}&stderr=${at4.stderr}${follow2 ? "&follow=1" : ""}`, { method: "GET", headers: { Accept: "text/event-stream" }, signal: controller.signal });
11892
+ } catch (error) {
11893
+ return { kind: "cut", why: errorText(error), progressed };
11894
+ }
11895
+ if (!response.ok) {
11896
+ const body = await bodyOf(response);
11897
+ if (response.status === 410) {
11898
+ return { kind: "gone" };
11899
+ }
11900
+ if (response.status >= 500) {
11901
+ const said = body?.error?.message;
11902
+ return { kind: "cut", why: typeof said === "string" ? said : `HTTP ${response.status}`, progressed };
11903
+ }
11904
+ client.fail(response.status, body);
11905
+ }
11906
+ if (response.body === null) {
11907
+ return { kind: "cut", why: "the answer had no body", progressed };
11908
+ }
11909
+ const handle = async (event2, data2) => {
11910
+ switch (event2) {
11911
+ case "output": {
11912
+ const piece = JSON.parse(data2);
11913
+ const raw = Buffer.from(piece.data, "base64");
11914
+ const skip = Math.max(0, at4[piece.stream] - piece.offset);
11915
+ if (skip < raw.length) {
11916
+ await put(piece.stream === "stdout" ? process.stdout : process.stderr, raw.subarray(skip));
11917
+ wrote();
11918
+ }
11919
+ at4[piece.stream] = Math.max(at4[piece.stream], piece.offset + raw.length);
11920
+ progressed = true;
11921
+ return null;
11922
+ }
11923
+ case "gap": {
11924
+ const gap = JSON.parse(data2);
11925
+ await put(process.stderr, `[agental: bytes ${gap.from} to ${gap.to} of its ${gap.stream} were overwritten in the sandbox before they were read: each stream keeps its last 1 MiB]
11926
+ `);
11927
+ at4[gap.stream] = Math.max(at4[gap.stream], gap.to);
11928
+ progressed = true;
11929
+ return null;
11930
+ }
11931
+ case "continue": {
11932
+ const next = JSON.parse(data2);
11933
+ at4.stdout = Math.max(at4.stdout, next.stdout);
11934
+ at4.stderr = Math.max(at4.stderr, next.stderr);
11935
+ return { kind: "continue" };
11936
+ }
11937
+ case "end":
11938
+ return { kind: "end", command: JSON.parse(data2) };
11939
+ case "gone":
11940
+ return { kind: "gone" };
11941
+ case "error":
11942
+ return { kind: "cut", why: data2, progressed };
11943
+ default:
11944
+ return null;
11945
+ }
11946
+ };
11947
+ const decoder = new TextDecoder();
11948
+ let buffer = "";
11949
+ let event = "";
11950
+ let data = [];
11951
+ let read2 = null;
11952
+ try {
11953
+ reading: for await (const chunk of response.body) {
11954
+ heard();
11955
+ buffer += decoder.decode(chunk, { stream: true });
11956
+ let newline;
11957
+ while ((newline = buffer.indexOf("\n")) >= 0) {
11958
+ const line = buffer.slice(0, newline).replace(/\r$/, "");
11959
+ buffer = buffer.slice(newline + 1);
11960
+ if (line === "") {
11961
+ read2 = event === "" && data.length === 0 ? null : await handle(event, data.join("\n"));
11962
+ event = "";
11963
+ data = [];
11964
+ if (read2 !== null) {
11965
+ break reading;
11966
+ }
11967
+ } else if (!line.startsWith(":")) {
11968
+ const colon = line.indexOf(":");
11969
+ const field = colon < 0 ? line : line.slice(0, colon);
11970
+ const value = colon < 0 ? "" : line.slice(colon + 1).replace(/^ /, "");
11971
+ if (field === "event") {
11972
+ event = value;
11973
+ } else if (field === "data") {
11974
+ data.push(value);
11975
+ }
11976
+ }
11977
+ }
11978
+ }
11979
+ } catch (error) {
11980
+ return { kind: "cut", why: controller.signal.aborted ? `nothing came for ${SILENT_MS / 1e3} seconds` : errorText(error), progressed };
11981
+ }
11982
+ return read2 ?? { kind: "cut", why: "the stream closed before the command ended", progressed };
11983
+ } finally {
11984
+ clearTimeout(silence);
11985
+ }
11986
+ }
11987
+ async function logs(client, sandbox, id, one, follow2) {
11988
+ process.stdout.on("error", (error) => {
11989
+ if (error.code === "EPIPE") {
11990
+ process.exit(0);
11991
+ }
11992
+ });
11993
+ const at4 = { stdout: 0, stderr: 0 };
11994
+ let wrote = false;
11995
+ let failed = 0;
11996
+ let idle = 0;
11997
+ for (; ; ) {
11998
+ const from = { ...at4 };
11999
+ const read2 = await readOutput(client, `${one}/output`, at4, follow2, () => wrote = true);
12000
+ switch (read2.kind) {
12001
+ case "end":
12002
+ if (follow2) {
12003
+ ended(read2.command);
12004
+ }
12005
+ return;
12006
+ case "continue":
12007
+ if (!follow2) {
12008
+ process.stderr.write(faint(`${id} is still running: this is its output so far. --follow follows it.
12009
+ `, process.stderr));
12010
+ return;
12011
+ }
12012
+ if (at4.stdout === from.stdout && at4.stderr === from.stderr) {
12013
+ idle += 1;
12014
+ await sleep2(waitBefore(idle));
12015
+ continue;
12016
+ }
12017
+ idle = 0;
12018
+ failed = 0;
12019
+ continue;
12020
+ case "gone": {
12021
+ const command3 = await ask7(client, "GET", one);
12022
+ if (!wrote) {
12023
+ await put(process.stdout, command3.stdout ?? "");
12024
+ await put(process.stderr, command3.stderr ?? "");
12025
+ }
12026
+ process.stderr.write(`The rest of the output of ${id} is gone with its sandbox's machine${wrote ? "" : ": this is the last of it, as it was saved"}.
12027
+ `);
12028
+ if (follow2) {
12029
+ if (command3.status === "running") {
12030
+ process.exitCode = NO_EXIT;
12031
+ return;
12032
+ }
12033
+ ended(command3);
12034
+ }
12035
+ return;
12036
+ }
12037
+ case "cut": {
12038
+ failed = read2.progressed ? 1 : failed + 1;
12039
+ if (failed >= TRIES) {
12040
+ process.stderr.write(`Could not read the output of ${id}, ${TRIES} tries in a row: ${reason(read2.why)}. The command runs on whatever this does; agental command get ${sandbox} ${id} says how it is.
12041
+ `);
12042
+ process.exitCode = NO_EXIT;
12043
+ return;
12044
+ }
12045
+ await sleep2(waitBefore(failed));
12046
+ continue;
12047
+ }
12048
+ }
12049
+ }
12050
+ }
12051
+ function ended(command3) {
12052
+ if (command3.endReason !== "exited") {
12053
+ process.stderr.write(`${command3.id} ${stateOf(command3)}.
12054
+ `);
12055
+ }
12056
+ process.exitCode = exitOf2(command3);
12057
+ }
12058
+ async function kill(client, id, one, options) {
12059
+ const grace = options.grace === void 0 ? GRACE_SECONDS : Number(options.grace);
12060
+ if (options.grace !== void 0 && (!/^[0-9]+(\.[0-9]+)?$/.test(options.grace.trim()) || !Number.isFinite(grace))) {
12061
+ throw new Error("--grace is the seconds between TERM and KILL, as 5 or 0.5.");
12062
+ }
12063
+ await ask7(client, "POST", `${one}/signal`, { signal: "TERM" });
12064
+ const endBy = async (deadline) => {
12065
+ for (; ; ) {
12066
+ const command4 = await ask7(client, "GET", one);
12067
+ if (command4.status !== "running" || Date.now() >= deadline) {
12068
+ return command4;
12069
+ }
12070
+ await sleep2(Math.min(LOOK_MS, Math.max(1, deadline - Date.now())));
12071
+ }
12072
+ };
12073
+ let command3 = await endBy(Date.now() + grace * 1e3);
12074
+ if (command3.status === "running") {
12075
+ await ask7(client, "POST", `${one}/signal`, { signal: "KILL" });
12076
+ command3 = await endBy(Date.now() + AFTER_KILL_MS);
12077
+ }
12078
+ if (options.json) {
12079
+ json2(command3);
12080
+ } else {
12081
+ process.stdout.write(`${id} ${stateOf(command3)}.
12082
+ `);
12083
+ }
12084
+ if (command3.status === "running") {
12085
+ process.stderr.write(`${id} was sent KILL and still runs ${AFTER_KILL_MS / 1e3} seconds later.
12086
+ `);
12087
+ process.exitCode = 1;
12088
+ }
12089
+ }
12090
+ function stdinPieces(input) {
12091
+ const waiting = [];
12092
+ let size2 = 0;
12093
+ let ended2 = false;
12094
+ let failure = null;
12095
+ let wake = null;
12096
+ const nudge = () => {
12097
+ wake?.();
12098
+ wake = null;
12099
+ };
12100
+ input.on("data", (chunk) => {
12101
+ waiting.push(chunk);
12102
+ size2 += chunk.length;
12103
+ if (size2 >= STDIN_PIECE) {
12104
+ input.pause();
12105
+ }
12106
+ nudge();
12107
+ });
12108
+ input.on("end", () => {
12109
+ ended2 = true;
12110
+ nudge();
12111
+ });
12112
+ input.on("error", (error) => {
12113
+ failure = error;
12114
+ nudge();
12115
+ });
12116
+ return async () => {
12117
+ while (size2 === 0 && !ended2 && failure === null) {
12118
+ await new Promise((resolve) => wake = resolve);
12119
+ }
12120
+ if (failure !== null) {
12121
+ throw failure;
12122
+ }
12123
+ if (size2 === 0) {
12124
+ return null;
12125
+ }
12126
+ const all = Buffer.concat(waiting.splice(0));
12127
+ const piece = all.subarray(0, STDIN_PIECE);
12128
+ if (all.length > STDIN_PIECE) {
12129
+ waiting.push(all.subarray(STDIN_PIECE));
12130
+ }
12131
+ size2 = all.length - piece.length;
12132
+ if (size2 < STDIN_PIECE) {
12133
+ input.resume();
12134
+ }
12135
+ return piece;
12136
+ };
12137
+ }
12138
+ async function writeStdin(client, sandbox, id, one) {
12139
+ const command3 = await ask7(client, "GET", one);
12140
+ if (command3.stdin == null) {
12141
+ throw new Error(`${id} was started without --stdin: its stdin is /dev/null. agental command start ${sandbox} --stdin -- <command> starts one whose stdin can be written.`);
12142
+ }
12143
+ if (!command3.stdin.open) {
12144
+ throw new Error(`The stdin of ${id} is closed: it takes no more.`);
12145
+ }
12146
+ let offset = command3.stdin.offset;
12147
+ let sent = 0;
12148
+ const next = stdinPieces(process.stdin);
12149
+ for (let piece = await next(); piece !== null; piece = await next()) {
12150
+ const start2 = offset;
12151
+ let left = piece;
12152
+ let failed = 0;
12153
+ let moved = 0;
12154
+ while (left.length > 0) {
12155
+ let response = null;
12156
+ let why2;
12157
+ try {
12158
+ response = await client.request(`${one}/stdin?offset=${offset}`, { method: "POST", headers: { "Content-Type": "application/octet-stream" }, body: left });
12159
+ why2 = `HTTP ${response.status}`;
12160
+ } catch (error) {
12161
+ why2 = errorText(error);
12162
+ }
12163
+ const body = response === null ? null : await bodyOf(response);
12164
+ const refusal = body?.error;
12165
+ if (response !== null && response.ok) {
12166
+ const taken = body.offset - offset;
12167
+ if (taken < 0 || taken > left.length) {
12168
+ throw new Error(`The API said the stdin of ${id} stands at ${body.offset}, which is not where ${left.length} bytes from ${offset} could take it.`);
12169
+ }
12170
+ offset += taken;
12171
+ sent += taken;
12172
+ left = left.subarray(taken);
12173
+ failed = 0;
12174
+ if (taken === 0) {
12175
+ await sleep2(LOOK_MS);
12176
+ }
12177
+ continue;
12178
+ }
12179
+ if (response !== null && response.status === 409 && refusal?.code === "stdin_offset" && typeof refusal.offset === "number") {
12180
+ moved += 1;
12181
+ if (refusal.offset < start2 || refusal.offset > offset) {
12182
+ throw new Error(`The stdin of ${id} stands at byte ${refusal.offset}, outside the bytes ${start2} to ${offset} this write still holds: what it is missing cannot be sent again from here. Its stdin is left open.`);
12183
+ }
12184
+ if (moved > TRIES) {
12185
+ throw new Error(`The stdin of ${id} kept moving back under this write: ${reason(String(refusal.message))}. Its stdin is left open.`);
12186
+ }
12187
+ sent -= offset - refusal.offset;
12188
+ offset = refusal.offset;
12189
+ left = piece.subarray(offset - start2);
12190
+ continue;
12191
+ }
12192
+ const again = response === null || response.status >= 500;
12193
+ if (!again) {
12194
+ client.fail(response.status, body);
12195
+ }
12196
+ failed += 1;
12197
+ if (failed >= TRIES) {
12198
+ throw new Error(`Could not write to the stdin of ${id}, ${TRIES} tries in a row: ${reason(typeof refusal?.message === "string" ? refusal.message : why2)}. ${sent} bytes were taken; its stdin is left open.`);
12199
+ }
12200
+ await sleep2(waitBefore(failed));
12201
+ }
12202
+ }
12203
+ await ask7(client, "POST", `${one}/stdin/close`);
12204
+ if (isTerminal(process.stderr)) {
12205
+ process.stderr.write(faint(`Sent ${bytes2(sent)} and closed the stdin of ${id}.
12206
+ `, process.stderr));
12207
+ }
12208
+ }
12209
+
11530
12210
  // ../src/event-kinds.ts
11531
12211
  var LIFECYCLE_EVENTS = [
11532
12212
  "sandbox.created",
@@ -11594,10 +12274,10 @@ var WEBHOOK_RETRY_AFTER_MS = [6e4, 5 * 6e4, 15 * 6e4, 60 * 6e4, 3 * 36e5, 6 * 36
11594
12274
  var WEBHOOK_OFF_AFTER_MS = 3 * 864e5;
11595
12275
 
11596
12276
  // ../src/cli-webhooks.ts
11597
- var USAGE5 = "webhook takes add, show, update, on, off, rotate or delete. agental webhook --help shows each.";
12277
+ var USAGE6 = "webhook takes add, show, update, on, off, rotate or delete. agental webhook --help shows each.";
11598
12278
  var EVERY = "*";
11599
- var TRIES = WEBHOOK_RETRY_AFTER_MS.length + 1;
11600
- async function ask7(client, method, pathname, body) {
12279
+ var TRIES2 = WEBHOOK_RETRY_AFTER_MS.length + 1;
12280
+ async function ask8(client, method, pathname, body) {
11601
12281
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
11602
12282
  let answered = null;
11603
12283
  if (response.status !== 204) {
@@ -11619,8 +12299,8 @@ function webhookOf(body) {
11619
12299
  const webhook2 = body;
11620
12300
  return { ...webhook2, deliveries: Array.isArray(webhook2.deliveries) ? webhook2.deliveries : [] };
11621
12301
  }
11622
- function at3(moment) {
11623
- return new Date(moment).toISOString().replace(/\.\d+Z$/, "Z");
12302
+ function at3(moment2) {
12303
+ return new Date(moment2).toISOString().replace(/\.\d+Z$/, "Z");
11624
12304
  }
11625
12305
  function nameOf(webhook2) {
11626
12306
  if (webhook2.description.trim()) {
@@ -11650,7 +12330,7 @@ function eventsOf2(deliveries) {
11650
12330
  const first = tries[0];
11651
12331
  const last = tries[tries.length - 1];
11652
12332
  const taken = tries.some((one) => one.status === "succeeded");
11653
- const finalTry = last.attempt === null || last.attempt >= TRIES;
12333
+ const finalTry = last.attempt === null || last.attempt >= TRIES2;
11654
12334
  const lastAt = Date.parse(last.createdAt);
11655
12335
  events.push({
11656
12336
  key: key2,
@@ -11680,7 +12360,7 @@ function standingOf(events) {
11680
12360
  }
11681
12361
  return `given up (${answerOf(latest.tries[latest.tries.length - 1])}) ${at3(latest.lastAt)}`;
11682
12362
  }
11683
- function stateOf(webhook2) {
12363
+ function stateOf2(webhook2) {
11684
12364
  if (webhook2.enabled !== false) {
11685
12365
  return "on";
11686
12366
  }
@@ -11716,7 +12396,7 @@ function describe3(webhook2) {
11716
12396
  `url: ${webhook2.url}`,
11717
12397
  `sent: ${sentOf(webhook2.events)}`,
11718
12398
  `added: ${at3(webhook2.createdAt)}`,
11719
- `state: ${stateOf(webhook2)}`,
12399
+ `state: ${stateOf2(webhook2)}`,
11720
12400
  `last post: ${standingOf(eventsOf2(webhook2.deliveries))}`,
11721
12401
  ""
11722
12402
  ].join("\n");
@@ -11729,7 +12409,7 @@ function saySecret(secret) {
11729
12409
  }
11730
12410
  }
11731
12411
  async function listWebhooks(client, asJson) {
11732
- const body = await ask7(client, "GET", "/v1/webhooks");
12412
+ const body = await ask8(client, "GET", "/v1/webhooks");
11733
12413
  if (asJson) {
11734
12414
  process.stdout.write(`${JSON.stringify(body, null, 2)}
11735
12415
  `);
@@ -11746,7 +12426,7 @@ async function listWebhooks(client, asJson) {
11746
12426
  for (const webhook2 of webhooks) {
11747
12427
  const listed = webhook2.events.join(",");
11748
12428
  const sent = webhook2.events.includes(EVERY) ? "every event" : listed.length <= 33 ? listed : `${webhook2.events.length} kinds`;
11749
- const standing = webhook2.enabled === false ? stateOf(webhook2) : standingOf(eventsOf2(webhook2.deliveries));
12429
+ const standing = webhook2.enabled === false ? stateOf2(webhook2) : standingOf(eventsOf2(webhook2.deliveries));
11750
12430
  process.stdout.write(`${[pad3(webhook2.id, 22), pad3(nameOf(webhook2), 18), pad3(sent, 34), standing].join(" ")}
11751
12431
  `);
11752
12432
  }
@@ -11754,7 +12434,7 @@ async function listWebhooks(client, asJson) {
11754
12434
  async function webhook(client, positionals, options) {
11755
12435
  const [what, target, ...rest] = positionals;
11756
12436
  if (rest.length > 0) {
11757
- throw new Error(USAGE5);
12437
+ throw new Error(USAGE6);
11758
12438
  }
11759
12439
  switch (what) {
11760
12440
  case "add": {
@@ -11766,7 +12446,7 @@ async function webhook(client, positionals, options) {
11766
12446
  }
11767
12447
  const events = eventsFrom(options, true);
11768
12448
  const made = webhookOf(
11769
- await ask7(client, "POST", "/v1/webhooks", { url: target, events, ...options.description !== void 0 ? { description: options.description } : {} })
12449
+ await ask8(client, "POST", "/v1/webhooks", { url: target, events, ...options.description !== void 0 ? { description: options.description } : {} })
11770
12450
  );
11771
12451
  if (options.json) {
11772
12452
  process.stdout.write(`${JSON.stringify(made, null, 2)}
@@ -11779,7 +12459,7 @@ async function webhook(client, positionals, options) {
11779
12459
  return;
11780
12460
  }
11781
12461
  case "show": {
11782
- const found = webhookOf(await ask7(client, "GET", `/v1/webhooks/${encodeURIComponent(needId(target, "show"))}`));
12462
+ const found = webhookOf(await ask8(client, "GET", `/v1/webhooks/${encodeURIComponent(needId(target, "show"))}`));
11783
12463
  if (options.json) {
11784
12464
  process.stdout.write(`${JSON.stringify(found, null, 2)}
11785
12465
  `);
@@ -11813,14 +12493,14 @@ async function webhook(client, positionals, options) {
11813
12493
  if (Object.keys(patch).length === 0) {
11814
12494
  throw new Error("webhook update changes --url, --events (or --all) and --description, and was given none of them.");
11815
12495
  }
11816
- const updated = webhookOf(await ask7(client, "PATCH", `/v1/webhooks/${encodeURIComponent(id)}`, patch));
12496
+ const updated = webhookOf(await ask8(client, "PATCH", `/v1/webhooks/${encodeURIComponent(id)}`, patch));
11817
12497
  process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
11818
12498
  ` : describe3(updated));
11819
12499
  return;
11820
12500
  }
11821
12501
  case "on":
11822
12502
  case "off": {
11823
- const turned = webhookOf(await ask7(client, "PATCH", `/v1/webhooks/${encodeURIComponent(needId(target, what))}`, { enabled: what === "on" }));
12503
+ const turned = webhookOf(await ask8(client, "PATCH", `/v1/webhooks/${encodeURIComponent(needId(target, what))}`, { enabled: what === "on" }));
11824
12504
  if (options.json) {
11825
12505
  process.stdout.write(`${JSON.stringify(turned, null, 2)}
11826
12506
  `);
@@ -11833,7 +12513,7 @@ async function webhook(client, positionals, options) {
11833
12513
  return;
11834
12514
  }
11835
12515
  case "rotate": {
11836
- const rotated = webhookOf(await ask7(client, "POST", `/v1/webhooks/${encodeURIComponent(needId(target, "rotate"))}/rotate`));
12516
+ const rotated = webhookOf(await ask8(client, "POST", `/v1/webhooks/${encodeURIComponent(needId(target, "rotate"))}/rotate`));
11837
12517
  if (options.json) {
11838
12518
  process.stdout.write(`${JSON.stringify(rotated, null, 2)}
11839
12519
  `);
@@ -11844,12 +12524,12 @@ async function webhook(client, positionals, options) {
11844
12524
  return;
11845
12525
  }
11846
12526
  case "delete": {
11847
- await ask7(client, "DELETE", `/v1/webhooks/${encodeURIComponent(needId(target, "delete"))}`);
12527
+ await ask8(client, "DELETE", `/v1/webhooks/${encodeURIComponent(needId(target, "delete"))}`);
11848
12528
  process.stdout.write("Deleted. Nothing more is posted to it, and its tries are gone.\n");
11849
12529
  return;
11850
12530
  }
11851
12531
  default:
11852
- throw new Error(USAGE5);
12532
+ throw new Error(USAGE6);
11853
12533
  }
11854
12534
  }
11855
12535
  function needId(id, what) {
@@ -11860,19 +12540,19 @@ function needId(id, what) {
11860
12540
  }
11861
12541
 
11862
12542
  // ../src/cli-sites.ts
11863
- var USAGE6 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
12543
+ var USAGE7 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
11864
12544
  var ANALYTICS_USAGE = "site analytics takes on or off, then the sandbox and the site's id, or org, with on or off to change it.";
11865
12545
  var REPORT_ROWS = 5;
11866
- async function bodyOf(response) {
12546
+ async function bodyOf2(response) {
11867
12547
  try {
11868
12548
  return await response.json();
11869
12549
  } catch {
11870
12550
  return null;
11871
12551
  }
11872
12552
  }
11873
- async function ask8(client, method, pathname, body) {
12553
+ async function ask9(client, method, pathname, body) {
11874
12554
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
11875
- const answered = await bodyOf(response);
12555
+ const answered = await bodyOf2(response);
11876
12556
  if (!response.ok) {
11877
12557
  client.fail(response.status, answered);
11878
12558
  }
@@ -11886,10 +12566,10 @@ function routeOf(body) {
11886
12566
  }
11887
12567
  var isSite = (route) => route.public && !route.hidden;
11888
12568
  async function sitesOf(client, sandbox) {
11889
- const body = await ask8(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
12569
+ const body = await ask9(client, "GET", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`);
11890
12570
  return (Array.isArray(body?.routes) ? body.routes : []).map(routeOf).filter(isSite);
11891
12571
  }
11892
- function stateOf2(route) {
12572
+ function stateOf3(route) {
11893
12573
  if (route.proxy !== "available") {
11894
12574
  return "not reachable: is the sandbox running?";
11895
12575
  }
@@ -11943,11 +12623,11 @@ function reportIn(report, sandbox, siteId) {
11943
12623
  return `Analytics are off for this site, so nothing is counted. agental site analytics on ${sandbox} ${siteId} turns them on.
11944
12624
  `;
11945
12625
  }
11946
- const span2 = report.range === "24h" ? "in the last 24 hours" : "in the last 7 days";
12626
+ const span3 = report.range === "24h" ? "in the last 24 hours" : "in the last 7 days";
11947
12627
  const today = report.range === "24h" ? " today (UTC)" : "";
11948
12628
  const worked = report.requests > 0 ? ` ${Math.floor((report.requests - report.errors) * 1e3 / report.requests) / 10}% of requests worked${today}.` : "";
11949
12629
  return [
11950
- `${report.visits} ${report.visits === 1 ? "visit" : "visits"} ${span2}.
12630
+ `${report.visits} ${report.visits === 1 ? "visit" : "visits"} ${span3}.
11951
12631
  `,
11952
12632
  `${comparedIn(report)} They opened ${report.pageViews} ${report.pageViews === 1 ? "page" : "pages"}.${worked}
11953
12633
  `,
@@ -11971,7 +12651,7 @@ async function siteSwitch(client, turn, words2, options) {
11971
12651
  process.exitCode = 1;
11972
12652
  return;
11973
12653
  }
11974
- const report = await ask8(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
12654
+ const report = await ask9(client, "PUT", `/v1/host-routes/${encodeURIComponent(target)}/analytics`, { enabled: turn === "on" });
11975
12655
  if (options.json) {
11976
12656
  process.stdout.write(`${reportJson(report)}
11977
12657
  `);
@@ -11997,16 +12677,16 @@ async function organizationSwitch(client, words2, options) {
11997
12677
  }
11998
12678
  let setting;
11999
12679
  if (turn === void 0) {
12000
- setting = await ask8(client, "GET", "/v1/site-analytics");
12680
+ setting = await ask9(client, "GET", "/v1/site-analytics");
12001
12681
  } else {
12002
12682
  if (turn === "off" && !options.yes && !await client.confirmed("Turn site analytics off for this organization? Every site's figures are deleted now and cannot be brought back.")) {
12003
12683
  process.stderr.write("Nothing was changed. --yes goes on without asking.\n");
12004
12684
  process.exitCode = 1;
12005
12685
  return;
12006
12686
  }
12007
- const put = (body) => client.request("/v1/site-analytics", { method: "PUT", body: JSON.stringify(body) });
12008
- let response = await put({ enabled: turn === "on" });
12009
- let answered = await bodyOf(response);
12687
+ const put2 = (body) => client.request("/v1/site-analytics", { method: "PUT", body: JSON.stringify(body) });
12688
+ let response = await put2({ enabled: turn === "on" });
12689
+ let answered = await bodyOf2(response);
12010
12690
  const refused = answered?.error;
12011
12691
  if (response.status === 409 && refused?.code === "notice_required") {
12012
12692
  process.stderr.write(`${refused.message ?? ""}
@@ -12016,8 +12696,8 @@ async function organizationSwitch(client, words2, options) {
12016
12696
  process.exitCode = 1;
12017
12697
  return;
12018
12698
  }
12019
- response = await put({ enabled: true, informed: true });
12020
- answered = await bodyOf(response);
12699
+ response = await put2({ enabled: true, informed: true });
12700
+ answered = await bodyOf2(response);
12021
12701
  }
12022
12702
  if (!response.ok) {
12023
12703
  client.fail(response.status, answered);
@@ -12049,13 +12729,13 @@ async function site(client, positionals, options) {
12049
12729
  const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" || positionals[0] === "stats" ? positionals[0] : null;
12050
12730
  const [sandbox, target, ...rest] = verb === null ? positionals : positionals.slice(1);
12051
12731
  if (sandbox === void 0) {
12052
- throw new Error(USAGE6);
12732
+ throw new Error(USAGE7);
12053
12733
  }
12054
12734
  switch (verb) {
12055
12735
  case null:
12056
12736
  case "list": {
12057
12737
  if (target !== void 0) {
12058
- throw new Error(USAGE6);
12738
+ throw new Error(USAGE7);
12059
12739
  }
12060
12740
  const sites = await sitesOf(client, sandbox);
12061
12741
  if (options.json) {
@@ -12068,17 +12748,17 @@ async function site(client, positionals, options) {
12068
12748
  `);
12069
12749
  return;
12070
12750
  }
12071
- const rows = [["ID", "ADDRESS", "PORT", "STATE"], ...sites.map((route) => [route.id, route.url ?? "no public address here", String(route.port), stateOf2(route)])];
12751
+ const rows = [["ID", "ADDRESS", "PORT", "STATE"], ...sites.map((route) => [route.id, route.url ?? "no public address here", String(route.port), stateOf3(route)])];
12072
12752
  const terminal2 = isTerminal(process.stdout);
12073
12753
  process.stdout.write(fitted(rows, { ...terminal2 ? { give: 1 } : { width: Number.MAX_SAFE_INTEGER }, paint: (cell, row) => row === 0 ? faint(cell) : cell }));
12074
12754
  return;
12075
12755
  }
12076
12756
  case "add": {
12077
12757
  if (rest.length > 0) {
12078
- throw new Error(USAGE6);
12758
+ throw new Error(USAGE7);
12079
12759
  }
12080
12760
  const port = portFrom(target);
12081
- const made = routeOf(await ask8(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
12761
+ const made = routeOf(await ask9(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
12082
12762
  if (options.json) {
12083
12763
  process.stdout.write(`${JSON.stringify(made, null, 2)}
12084
12764
  `);
@@ -12103,7 +12783,7 @@ async function site(client, positionals, options) {
12103
12783
  throw new Error(`site rm needs the sandbox and the site's id, as agental site ${sandbox} lists them.`);
12104
12784
  }
12105
12785
  const found = await siteOn(client, sandbox, target);
12106
- await ask8(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
12786
+ await ask9(client, "POST", `/v1/host-routes/${encodeURIComponent(target)}/hide`);
12107
12787
  process.stdout.write(`Removed. ${found.url ?? `Port ${found.port}`} stops working now; adding port ${found.port} again gives a new link.
12108
12788
  `);
12109
12789
  return;
@@ -12117,7 +12797,7 @@ async function site(client, positionals, options) {
12117
12797
  throw new Error(`--range is 24h or 7d. It was given ${range}.`);
12118
12798
  }
12119
12799
  await siteOn(client, sandbox, target);
12120
- const report = await ask8(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
12800
+ const report = await ask9(client, "GET", `/v1/host-routes/${encodeURIComponent(target)}/analytics?range=${range}`);
12121
12801
  process.stdout.write(options.json ? `${reportJson(report)}
12122
12802
  ` : reportIn(report, sandbox, target));
12123
12803
  return;
@@ -12126,10 +12806,10 @@ async function site(client, positionals, options) {
12126
12806
  }
12127
12807
 
12128
12808
  // ../src/cli-claude.ts
12129
- var USAGE7 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
12809
+ var USAGE8 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
12130
12810
  var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
12131
12811
  var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
12132
- async function ask9(client, method, pathname, body) {
12812
+ async function ask10(client, method, pathname, body) {
12133
12813
  const response = await client.request(pathname, { method, ...body === void 0 ? {} : { body: JSON.stringify(body) } });
12134
12814
  let answered = null;
12135
12815
  if (response.status !== 204) {
@@ -12219,7 +12899,7 @@ async function hidden(question) {
12219
12899
  });
12220
12900
  }
12221
12901
  async function listClaude(client, asJson) {
12222
- const body = await ask9(client, "GET", "/v1/claude/connections");
12902
+ const body = await ask10(client, "GET", "/v1/claude/connections");
12223
12903
  if (asJson) {
12224
12904
  process.stdout.write(`${JSON.stringify(body, null, 2)}
12225
12905
  `);
@@ -12241,7 +12921,7 @@ async function listClaude(client, asJson) {
12241
12921
  async function claude(client, positionals, options) {
12242
12922
  const [what, target, ...rest] = positionals;
12243
12923
  if (rest.length > 0) {
12244
- throw new Error(USAGE7);
12924
+ throw new Error(USAGE8);
12245
12925
  }
12246
12926
  switch (what) {
12247
12927
  case "connect": {
@@ -12253,7 +12933,7 @@ async function claude(client, positionals, options) {
12253
12933
  const environmentKey = await secretFrom(KEY_VARIABLE, "environment key", true);
12254
12934
  const webhookSecret = await secretFrom(SECRET_VARIABLE, "webhook signing secret", false);
12255
12935
  const made = connectionOf(
12256
- await ask9(client, "POST", "/v1/claude/connections", {
12936
+ await ask10(client, "POST", "/v1/claude/connections", {
12257
12937
  environmentId: target,
12258
12938
  environmentKey,
12259
12939
  ...webhookSecret !== void 0 ? { webhookSecret } : {},
@@ -12275,7 +12955,7 @@ async function claude(client, positionals, options) {
12275
12955
  return;
12276
12956
  }
12277
12957
  case "show": {
12278
- const found = connectionOf(await ask9(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
12958
+ const found = connectionOf(await ask10(client, "GET", `/v1/claude/connections/${encodeURIComponent(needId2(target, "show"))}`));
12279
12959
  process.stdout.write(options.json ? `${JSON.stringify(found, null, 2)}
12280
12960
  ` : describe4(found));
12281
12961
  return;
@@ -12298,18 +12978,18 @@ async function claude(client, positionals, options) {
12298
12978
  if (Object.keys(patch).length === 0) {
12299
12979
  throw new Error("claude update changes --template, --keep-days, --new-key, --webhook-secret or --no-webhook-secret, and was given none of them.");
12300
12980
  }
12301
- const updated = connectionOf(await ask9(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
12981
+ const updated = connectionOf(await ask10(client, "PATCH", `/v1/claude/connections/${encodeURIComponent(id)}`, patch));
12302
12982
  process.stdout.write(options.json ? `${JSON.stringify(updated, null, 2)}
12303
12983
  ` : describe4(updated));
12304
12984
  return;
12305
12985
  }
12306
12986
  case "disconnect": {
12307
- await ask9(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
12987
+ await ask10(client, "DELETE", `/v1/claude/connections/${encodeURIComponent(needId2(target, "disconnect"))}`);
12308
12988
  process.stdout.write("Disconnected: its key and signing secret are forgotten, and no more of its work is claimed. Its sessions' sandboxes are left as they are.\n");
12309
12989
  return;
12310
12990
  }
12311
12991
  default:
12312
- throw new Error(USAGE7);
12992
+ throw new Error(USAGE8);
12313
12993
  }
12314
12994
  }
12315
12995
  function needId2(id, what) {
@@ -12343,8 +13023,8 @@ function webSocketUrl(base, path6) {
12343
13023
  }
12344
13024
  return `${url.protocol === "https:" ? "wss:" : "ws:"}//${url.host}${url.pathname.replace(/\/+$/, "")}${path6}`;
12345
13025
  }
12346
- function whyClosed(code, reason, error) {
12347
- const said = error?.message || reason;
13026
+ function whyClosed(code, reason2, error) {
13027
+ const said = error?.message || reason2;
12348
13028
  switch (code) {
12349
13029
  case 4003:
12350
13030
  return `The terminal was closed: what let it be opened no longer does${said ? ` (${said})` : ""}.`;
@@ -12397,15 +13077,15 @@ async function shellNamed(client, id, given, flag) {
12397
13077
  }
12398
13078
  throw new Error(`Sandbox ${id} keeps no shell ${given}${listed.length > 0 ? `; it keeps ${listed.map((each) => each.n).join(", ")}` : ""}. agental shell ${id} --list lists them.`);
12399
13079
  }
12400
- function stateOf3(each) {
13080
+ function stateOf4(each) {
12401
13081
  if (each.exit) {
12402
13082
  return each.exit.signal > 0 ? `ended by signal ${each.exit.signal}` : `exited ${each.exit.code}`;
12403
13083
  }
12404
13084
  return each.running ?? "";
12405
13085
  }
12406
- async function listShells(client, id, json2, stdout) {
13086
+ async function listShells(client, id, json3, stdout) {
12407
13087
  const listed = await keptShells2(client, id);
12408
- if (json2) {
13088
+ if (json3) {
12409
13089
  stdout.write(`${JSON.stringify(listed, null, 2)}
12410
13090
  `);
12411
13091
  return;
@@ -12417,7 +13097,7 @@ async function listShells(client, id, json2, stdout) {
12417
13097
  }
12418
13098
  const rows = [
12419
13099
  ["N", "ID", "RUNNING", "CWD", "ATTACHED", "STARTED"],
12420
- ...listed.map((each) => [String(each.n), each.id, stateOf3(each), each.cwd ?? "", each.attached ? "yes" : "no", ago(each.startedAt) ?? each.startedAt])
13100
+ ...listed.map((each) => [String(each.n), each.id, stateOf4(each), each.cwd ?? "", each.attached ? "yes" : "no", ago(each.startedAt) ?? each.startedAt])
12421
13101
  ];
12422
13102
  stdout.write(fitted(rows, { give: 2, paint: (cell, row) => row === 0 ? faint(cell, stdout) : cell }));
12423
13103
  }
@@ -12466,16 +13146,16 @@ async function shell(client, id, options = {}, streams = process) {
12466
13146
  const verifier = randomBytes4(32).toString("base64url");
12467
13147
  const challenge = createHash3("sha256").update(verifier).digest("base64url");
12468
13148
  const interactive = stdin.isTTY === true && typeof stdin.setRawMode === "function";
12469
- const ask10 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
13149
+ const ask11 = async (keep) => await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminal`, {
12470
13150
  method: "POST",
12471
13151
  body: JSON.stringify({ ...size2, challenge, ...again ? { terminal: again.id } : keep ? { keep: true } : {} })
12472
13152
  });
12473
- let response = await ask10(interactive);
13153
+ let response = await ask11(interactive);
12474
13154
  let body = await response.json().catch(() => null);
12475
13155
  if (!again && interactive && response.status === 409 && body?.error?.code === "terminal_unavailable" && /keeps \d+ terminals/.test(String(body.error.message ?? ""))) {
12476
13156
  stderr.write(`${String(body.error.message)} This one is not kept.
12477
13157
  `);
12478
- response = await ask10(false);
13158
+ response = await ask11(false);
12479
13159
  body = await response.json().catch(() => null);
12480
13160
  }
12481
13161
  if (!response.ok || typeof body?.ticket !== "string") {
@@ -12537,10 +13217,10 @@ async function shell(client, id, options = {}, streams = process) {
12537
13217
  return Buffer.from(out);
12538
13218
  };
12539
13219
  const typed = (chunk) => {
12540
- const bytes3 = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
12541
- send2(raw ? escaped(bytes3) : bytes3);
13220
+ const bytes4 = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
13221
+ send2(raw ? escaped(bytes4) : bytes4);
12542
13222
  };
12543
- const ended = () => send2(Buffer.from(lastSent === 10 ? [4] : [4, 4]));
13223
+ const ended2 = () => send2(Buffer.from(lastSent === 10 ? [4] : [4, 4]));
12544
13224
  const resized = () => {
12545
13225
  if (socket.readyState === WebSocket.OPEN) {
12546
13226
  socket.send(JSON.stringify({ type: "resize", ...sizeOf(stdout) }));
@@ -12549,7 +13229,7 @@ async function shell(client, id, options = {}, streams = process) {
12549
13229
  const started = () => {
12550
13230
  stdin.on("data", typed);
12551
13231
  if (!raw) {
12552
- stdin.once("end", ended);
13232
+ stdin.once("end", ended2);
12553
13233
  }
12554
13234
  stdin.resume();
12555
13235
  };
@@ -12597,7 +13277,7 @@ async function shell(client, id, options = {}, streams = process) {
12597
13277
  });
12598
13278
  socket.addEventListener("close", (event) => {
12599
13279
  stdin.off("data", typed);
12600
- stdin.off("end", ended);
13280
+ stdin.off("end", ended2);
12601
13281
  stdout.off("resize", resized);
12602
13282
  if (raw) {
12603
13283
  stdin.setRawMode(false);
@@ -12876,16 +13556,16 @@ var SSH_COMMANDS = {
12876
13556
  "ssh-connect": sshConnect
12877
13557
  };
12878
13558
  async function setUp(args) {
12879
- const [command2, ...rest] = args;
12880
- const onboarding = command2 === void 0 || command2 === "sh" || command2 === "--no-skills" || command2 === "--no-install" || command2 === "--no-mcp" || command2 === "--json";
13559
+ const [command3, ...rest] = args;
13560
+ const onboarding = command3 === void 0 || command3 === "sh" || command3 === "--no-skills" || command3 === "--no-install" || command3 === "--no-mcp" || command3 === "--json";
12881
13561
  if (onboarding) {
12882
- const flags2 = command2 === "sh" ? rest : args;
13562
+ const flags2 = command3 === "sh" ? rest : args;
12883
13563
  const unknown = flags2.filter((flag) => !["--json", "--no-skills", "--no-install", "--no-mcp"].includes(flag));
12884
13564
  if (unknown.length > 0) {
12885
- throw new Error(`${command2 === "sh" ? "sh" : "agental"} takes --json, --no-skills, --no-install and --no-mcp, not ${unknown.join(" ")}`);
13565
+ throw new Error(`${command3 === "sh" ? "sh" : "agental"} takes --json, --no-skills, --no-install and --no-mcp, not ${unknown.join(" ")}`);
12886
13566
  }
12887
13567
  await onboard(apiBase(), {
12888
- sandbox: command2 === "sh",
13568
+ sandbox: command3 === "sh",
12889
13569
  json: flags2.includes("--json"),
12890
13570
  installCommand: !flags2.includes("--no-install"),
12891
13571
  installSkills: !flags2.includes("--no-skills"),
@@ -12893,7 +13573,7 @@ async function setUp(args) {
12893
13573
  });
12894
13574
  return true;
12895
13575
  }
12896
- switch (command2) {
13576
+ switch (command3) {
12897
13577
  case "--version":
12898
13578
  case "-v":
12899
13579
  case "version":
@@ -13062,6 +13742,7 @@ async function main() {
13062
13742
  expires: { type: "string" },
13063
13743
  "keep-streams": { type: "boolean" },
13064
13744
  "keep-memory": { type: "boolean" },
13745
+ "without-memory": { type: "boolean" },
13065
13746
  // agental delete and template delete: delete a sandbox that jobs run in, or a template they make their sandboxes from, and pause them.
13066
13747
  "pause-jobs": { type: "boolean" },
13067
13748
  // agental resize: the size now, with a restart, or a waiting size taken away.
@@ -13163,20 +13844,28 @@ async function main() {
13163
13844
  "revoke-keys": { type: "boolean", default: false },
13164
13845
  // agental list in a terminal: every column, as piped.
13165
13846
  wide: { type: "boolean", default: false },
13847
+ // agental command start: the folder it runs in, its own variables, no time limit (--timeout gives one), and a stdin to write.
13848
+ cwd: { type: "string" },
13849
+ env: { type: "string", multiple: true },
13850
+ "no-timeout": { type: "boolean" },
13851
+ stdin: { type: "boolean" },
13852
+ // agental command logs: follow it to its end. agental command kill: the seconds between TERM and KILL.
13853
+ follow: { type: "boolean", short: "f" },
13854
+ grace: { type: "string" },
13166
13855
  help: { type: "boolean", short: "h", default: false }
13167
13856
  }
13168
13857
  });
13169
- const command2 = positionals[0];
13170
- if (!command2) {
13858
+ const command3 = positionals[0];
13859
+ if (!command3) {
13171
13860
  process.stdout.write(isTerminal(process.stdout) ? shortHelp() : await helpText());
13172
13861
  return;
13173
13862
  }
13174
- switch (command2) {
13863
+ switch (command3) {
13175
13864
  case "create":
13176
13865
  await create({ ...values, template: once(values.template, "--template") });
13177
13866
  return;
13178
13867
  case "list":
13179
- await list2(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
13868
+ await list3(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
13180
13869
  return;
13181
13870
  case "bulk-actions":
13182
13871
  await bulkActionsCommand(positionals.slice(1), values.json);
@@ -13216,10 +13905,13 @@ async function main() {
13216
13905
  return;
13217
13906
  case "start":
13218
13907
  if (values.where !== void 0) {
13908
+ if (values["without-memory"] === true) {
13909
+ throw new Error("--without-memory starts one sandbox at a time: name it, without --where.");
13910
+ }
13219
13911
  await bulk("start", whereQuery(values.where, labelsFilter(values)), {}, values.yes === true, values.json);
13220
13912
  return;
13221
13913
  }
13222
- await lifecycle("start", positionals[1], maxBurstFeeHeaders(values["max-burst-fee"]));
13914
+ await lifecycle("start", positionals[1], maxBurstFeeHeaders(values["max-burst-fee"]), values["without-memory"] === true ? { withoutMemory: true } : void 0);
13223
13915
  return;
13224
13916
  case "auto-stop":
13225
13917
  await autoStop(positionals[1], values.in, values.at, values.never === true, values.json);
@@ -13328,8 +14020,14 @@ async function main() {
13328
14020
  return;
13329
14021
  case "job": {
13330
14022
  const dashes = process.argv.indexOf("--", 2);
13331
- const command3 = dashes < 0 ? null : process.argv.slice(dashes + 1);
13332
- await job({ request, fail }, positionals.slice(1, positionals.length - (command3?.length ?? 0)), command3, values);
14023
+ const command4 = dashes < 0 ? null : process.argv.slice(dashes + 1);
14024
+ await job({ request, fail }, positionals.slice(1, positionals.length - (command4?.length ?? 0)), command4, values);
14025
+ return;
14026
+ }
14027
+ case "command": {
14028
+ const dashes = process.argv.indexOf("--", 2);
14029
+ const argv = dashes < 0 ? null : process.argv.slice(dashes + 1);
14030
+ await command2({ request, fail }, positionals.slice(1, positionals.length - (argv?.length ?? 0)), argv, values);
13333
14031
  return;
13334
14032
  }
13335
14033
  case "webhooks":
@@ -13375,10 +14073,10 @@ async function main() {
13375
14073
  case "unsuspend":
13376
14074
  case "suspensions": {
13377
14075
  if (PUBLISHED) {
13378
- throw new Error(`${command2} is for whoever runs agental, from its repository.`);
14076
+ throw new Error(`${command3} is for whoever runs agental, from its repository.`);
13379
14077
  }
13380
14078
  const { suspensions: suspensions2 } = await Promise.resolve().then(() => (init_cli_operator(), cli_operator_exports));
13381
- await suspensions2({ request, fail }, command2, positionals[1], values.reason, values.json);
14079
+ await suspensions2({ request, fail }, command3, positionals[1], values.reason, values.json);
13382
14080
  return;
13383
14081
  }
13384
14082
  case "smoke": {
@@ -13390,7 +14088,7 @@ async function main() {
13390
14088
  return;
13391
14089
  }
13392
14090
  default:
13393
- process.stderr.write(noSuchCommand(command2, !PUBLISHED));
14091
+ process.stderr.write(noSuchCommand(command3, !PUBLISHED));
13394
14092
  process.exitCode = 1;
13395
14093
  }
13396
14094
  }
@@ -13485,7 +14183,7 @@ function regionsOption(given) {
13485
14183
  const named = listedIn([given]);
13486
14184
  return named.length === 1 ? { region: named[0] } : { regions: named };
13487
14185
  }
13488
- async function sshKeys(id, keyId, remove3, json2) {
14186
+ async function sshKeys(id, keyId, remove3, json3) {
13489
14187
  if (!id) {
13490
14188
  throw new Error("ssh-keys requires <sandbox-id>");
13491
14189
  }
@@ -13501,7 +14199,7 @@ async function sshKeys(id, keyId, remove3, json2) {
13501
14199
  }
13502
14200
  const body = await call2(path6, { method: "GET" });
13503
14201
  const keys = body?.keys ?? [];
13504
- if (json2) {
14202
+ if (json3) {
13505
14203
  process.stdout.write(`${JSON.stringify(keys, null, 2)}
13506
14204
  `);
13507
14205
  return;
@@ -13567,7 +14265,7 @@ async function regions(asJson) {
13567
14265
  }
13568
14266
  process.stdout.write("* where a sandbox is made when no region is named\n");
13569
14267
  }
13570
- async function list2(asJson, filter, sort, limit, wide = false) {
14268
+ async function list3(asJson, filter, sort, limit, wide = false) {
13571
14269
  const sandboxes2 = [];
13572
14270
  let cursor = null;
13573
14271
  do {
@@ -13797,13 +14495,13 @@ async function bulkActionsCommand(positionals, asJson) {
13797
14495
  }
13798
14496
  async function exec(positionals) {
13799
14497
  const id = positionals[0];
13800
- const command2 = positionals.slice(1);
13801
- if (!id || command2.length === 0) {
14498
+ const command3 = positionals.slice(1);
14499
+ if (!id || command3.length === 0) {
13802
14500
  throw new Error("exec needs the sandbox and what to run in it, after --: agental exec <sandbox-id> -- ls -la. agental list shows your sandboxes' ids.");
13803
14501
  }
13804
14502
  const response = await request(`/v1/sandboxes/${encodeURIComponent(id)}/exec`, {
13805
14503
  method: "POST",
13806
- body: JSON.stringify({ command: command2 })
14504
+ body: JSON.stringify({ command: command3 })
13807
14505
  });
13808
14506
  const body = await readBody(response);
13809
14507
  if (!response.ok) {
@@ -13853,6 +14551,10 @@ async function lifecycle(action, id, headers = {}, sent) {
13853
14551
  if (!id) {
13854
14552
  throw new Error(`${action} requires <sandbox-id>`);
13855
14553
  }
14554
+ if (sent?.["withoutMemory"] === true) {
14555
+ process.stderr.write(`Starting ${id} from its disk. The memory it was stopped with is let go for good: its files are kept, and the programs that ran in it are not.
14556
+ `);
14557
+ }
13856
14558
  if (sent?.["keepMemory"] === true) {
13857
14559
  process.stderr.write(`Stopping ${id} with its memory kept. It ends once the memory is written, about a second for every 2 to 3 GiB.
13858
14560
  `);
@@ -14142,19 +14844,19 @@ async function screenshot(id, file, options) {
14142
14844
  process.stderr.write(`A picture of the screen of ${id} is in ${file}: ${size2 ? `${size2.width} by ${size2.height}, ` : ""}${picture.length} bytes.
14143
14845
  `);
14144
14846
  }
14145
- function pictureSize(bytes3) {
14146
- if (bytes3.length >= 24 && bytes3.toString("latin1", 1, 4) === "PNG") {
14147
- return { width: bytes3.readUInt32BE(16), height: bytes3.readUInt32BE(20) };
14847
+ function pictureSize(bytes4) {
14848
+ if (bytes4.length >= 24 && bytes4.toString("latin1", 1, 4) === "PNG") {
14849
+ return { width: bytes4.readUInt32BE(16), height: bytes4.readUInt32BE(20) };
14148
14850
  }
14149
- for (let at4 = 2; bytes3[0] === 255 && bytes3[1] === 216 && at4 + 9 <= bytes3.length; ) {
14150
- const marker = bytes3[at4 + 1];
14151
- if (bytes3[at4] !== 255) {
14851
+ for (let at4 = 2; bytes4[0] === 255 && bytes4[1] === 216 && at4 + 9 <= bytes4.length; ) {
14852
+ const marker = bytes4[at4 + 1];
14853
+ if (bytes4[at4] !== 255) {
14152
14854
  return null;
14153
14855
  }
14154
14856
  if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
14155
- return { width: bytes3.readUInt16BE(at4 + 7), height: bytes3.readUInt16BE(at4 + 5) };
14857
+ return { width: bytes4.readUInt16BE(at4 + 7), height: bytes4.readUInt16BE(at4 + 5) };
14156
14858
  }
14157
- at4 += 2 + bytes3.readUInt16BE(at4 + 2);
14859
+ at4 += 2 + bytes4.readUInt16BE(at4 + 2);
14158
14860
  }
14159
14861
  return null;
14160
14862
  }
@@ -14180,7 +14882,7 @@ async function clipboard(id, text) {
14180
14882
  process.stderr.write(`The text is on the clipboard of ${id}. It is pasted where the keyboard's focus is by agental desktop ${id} --key ctrl+v.
14181
14883
  `);
14182
14884
  }
14183
- async function desktopTree(id, options, json2) {
14885
+ async function desktopTree(id, options, json3) {
14184
14886
  if (!id) {
14185
14887
  throw new Error("desktop requires <sandbox-id>");
14186
14888
  }
@@ -14202,7 +14904,7 @@ async function desktopTree(id, options, json2) {
14202
14904
  if (!response.ok) {
14203
14905
  fail(response.status, body);
14204
14906
  }
14205
- process.stdout.write(json2 ? `${JSON.stringify(body, null, 2)}
14907
+ process.stdout.write(json3 ? `${JSON.stringify(body, null, 2)}
14206
14908
  ` : `${treeText(body)}
14207
14909
  `);
14208
14910
  }
@@ -14340,10 +15042,10 @@ function labelsInWords(body) {
14340
15042
  }
14341
15043
  async function labels(what, holder, positionals, asJson) {
14342
15044
  const [named, action, ...words2] = positionals;
14343
- const command2 = `${holder === "template" ? "template " : ""}${what}`;
14344
- const usage = what === "tags" ? `${command2} <${holder}> [add|rm <tag>...]` : `${command2} <${holder}> [set <key>=<value>... | unset <key>...]`;
15045
+ const command3 = `${holder === "template" ? "template " : ""}${what}`;
15046
+ const usage = what === "tags" ? `${command3} <${holder}> [add|rm <tag>...]` : `${command3} <${holder}> [set <key>=<value>... | unset <key>...]`;
14345
15047
  if (!named) {
14346
- throw new Error(`${command2} requires <${holder}>: ${usage}`);
15048
+ throw new Error(`${command3} requires <${holder}>: ${usage}`);
14347
15049
  }
14348
15050
  const id = holder === "template" ? (await templateNamed(named)).id : named;
14349
15051
  const path6 = `/v1/${holder === "template" ? "templates" : "sandboxes"}/${encodeURIComponent(id)}`;
@@ -14353,7 +15055,7 @@ async function labels(what, holder, positionals, asJson) {
14353
15055
  } else if (what === "tags" && (action === "add" || action === "rm")) {
14354
15056
  const tags = listedIn(words2).map((tag) => tag.toLowerCase());
14355
15057
  if (tags.length === 0) {
14356
- throw new Error(`${command2} ${action} requires <tag>...`);
15058
+ throw new Error(`${command3} ${action} requires <tag>...`);
14357
15059
  }
14358
15060
  const bad2 = tags.find((tag) => !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(tag));
14359
15061
  if (bad2 !== void 0) {
@@ -14364,12 +15066,12 @@ async function labels(what, holder, positionals, asJson) {
14364
15066
  }
14365
15067
  } else if (what === "meta" && (action === "set" || action === "unset")) {
14366
15068
  if (words2.length === 0) {
14367
- throw new Error(`${command2} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
15069
+ throw new Error(`${command3} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
14368
15070
  }
14369
15071
  const metadata = action === "set" ? metadataGiven(words2) : Object.fromEntries(words2.map((key2) => [key2, null]));
14370
15072
  body = await call2(path6, { method: "PATCH", body: JSON.stringify({ metadata }) });
14371
15073
  } else {
14372
- throw new Error(`${command2} takes ${usage}`);
15074
+ throw new Error(`${command3} takes ${usage}`);
14373
15075
  }
14374
15076
  process.stdout.write(asJson ? `${JSON.stringify(body, null, 2)}
14375
15077
  ` : labelsInWords(body));
@@ -14577,9 +15279,9 @@ async function templateNamed(word) {
14577
15279
  }
14578
15280
  return found;
14579
15281
  }
14580
- function startInWords(start) {
14581
- const runs = typeof start?.ttlSeconds === "number" ? `, runs ${timeInWords(start.ttlSeconds)} after each start` : "";
14582
- return `${start?.size ?? ""}, ${start?.snapshotId ? `from snapshot ${start.snapshotId}` : "a new machine"}${runs}`;
15282
+ function startInWords(start2) {
15283
+ const runs = typeof start2?.ttlSeconds === "number" ? `, runs ${timeInWords(start2.ttlSeconds)} after each start` : "";
15284
+ return `${start2?.size ?? ""}, ${start2?.snapshotId ? `from snapshot ${start2.snapshotId}` : "a new machine"}${runs}`;
14583
15285
  }
14584
15286
  async function listTemplates(asJson) {
14585
15287
  const listed = await templatesListed();
@@ -14602,22 +15304,22 @@ ${faint("The default is used when a sandbox is made without naming one. agental
14602
15304
  process.stdout.write(`${[pad2("ID"), pad2("NAME"), pad2("START"), "SANDBOXES"].join(" ")}
14603
15305
  `);
14604
15306
  for (const each of listed) {
14605
- const start = `${each.start?.size ?? ""}${each.start?.snapshotId ? ` from ${each.start.snapshotId}` : ""}`;
14606
- process.stdout.write(`${[pad2(each.id), pad2(each.default ? `${each.name} *` : each.name), pad2(start), String(each.sandboxes ?? 0)].join(" ")}
15307
+ const start2 = `${each.start?.size ?? ""}${each.start?.snapshotId ? ` from ${each.start.snapshotId}` : ""}`;
15308
+ process.stdout.write(`${[pad2(each.id), pad2(each.default ? `${each.name} *` : each.name), pad2(start2), String(each.sandboxes ?? 0)].join(" ")}
14607
15309
  `);
14608
15310
  }
14609
15311
  process.stdout.write("* used when a sandbox is made without naming one\n");
14610
15312
  }
14611
15313
  function showTemplate(each) {
14612
- const list3 = (items) => items && items.length > 0 ? items.join(", ") : "none";
15314
+ const list4 = (items) => items && items.length > 0 ? items.join(", ") : "none";
14613
15315
  return [
14614
15316
  `id: ${each.id}`,
14615
15317
  `name: ${each.name}${each.default ? " (default: used when a sandbox is made without naming one)" : ""}`,
14616
15318
  `start: ${startInWords(each.start)}`,
14617
- `variables: ${list3(each.variables)}`,
15319
+ `variables: ${list4(each.variables)}`,
14618
15320
  // Said only where some are. An API from before variables could be kept out of the sandbox says nothing of them.
14619
- ...each.hidden && each.hidden.length > 0 ? [`kept out: ${list3(each.hidden)}`] : [],
14620
- `files: ${list3(each.files)}`,
15321
+ ...each.hidden && each.hidden.length > 0 ? [`kept out: ${list4(each.hidden)}`] : [],
15322
+ `files: ${list4(each.files)}`,
14621
15323
  // An API from before templates held rules says nothing of one.
14622
15324
  ...each.network ? [`network: ${ruleInWords(each.network)}`] : [],
14623
15325
  // An API from before templates gave SSH says nothing of it.
@@ -14696,16 +15398,16 @@ async function template(positionals, values) {
14696
15398
  throw new Error("--size must be tiny, small, medium or large");
14697
15399
  }
14698
15400
  const ttlSeconds = ttlOption(values.ttl);
14699
- let start;
15401
+ let start2;
14700
15402
  if (values.size === void 0 && values.snapshot === void 0 && !values["new-machine"] && ttlSeconds === void 0) {
14701
- start = await call2(path6, { method: "GET" });
15403
+ start2 = await call2(path6, { method: "GET" });
14702
15404
  } else {
14703
15405
  const current = await call2(path6, { method: "GET" });
14704
15406
  const snapshotId = values["new-machine"] ? null : values.snapshot ?? current?.snapshotId ?? null;
14705
15407
  const ttl = ttlSeconds === void 0 ? current?.ttlSeconds ?? null : ttlSeconds;
14706
- start = await call2(path6, { method: "PUT", body: JSON.stringify({ size: values.size ?? current?.size, snapshotId, ttlSeconds: ttl }) });
15408
+ start2 = await call2(path6, { method: "PUT", body: JSON.stringify({ size: values.size ?? current?.size, snapshotId, ttlSeconds: ttl }) });
14707
15409
  }
14708
- print4(start, `start: ${startInWords(start)}
15410
+ print4(start2, `start: ${startInWords(start2)}
14709
15411
  `);
14710
15412
  return;
14711
15413
  }
@@ -15866,8 +16568,8 @@ function figuresOf(reading) {
15866
16568
  const value = read2[name];
15867
16569
  return typeof value === "number" ? value : null;
15868
16570
  };
15869
- const usedOf = (used, total) => used === null ? NO_FIGURE : total === null ? bytes2(used) : `${bytes2(used)} of ${bytes2(total)}`;
15870
- const aSecond = (count) => count === null ? NO_FIGURE : `${bytes2(count)}/s`;
16571
+ const usedOf = (used, total) => used === null ? NO_FIGURE : total === null ? bytes3(used) : `${bytes3(used)} of ${bytes3(total)}`;
16572
+ const aSecond = (count) => count === null ? NO_FIGURE : `${bytes3(count)}/s`;
15871
16573
  const cpu = figure("cpuUtilization");
15872
16574
  return [
15873
16575
  cpu === null ? NO_FIGURE : `${(cpu * 100).toFixed(1)}%`,
@@ -15877,15 +16579,15 @@ function figuresOf(reading) {
15877
16579
  aSecond(figure("networkSentBytesPerSecond"))
15878
16580
  ];
15879
16581
  }
15880
- var BYTE_UNITS = ["B", "KiB", "MiB", "GiB", "TiB"];
15881
- function bytes2(count) {
16582
+ var BYTE_UNITS2 = ["B", "KiB", "MiB", "GiB", "TiB"];
16583
+ function bytes3(count) {
15882
16584
  let value = count;
15883
16585
  let unit = 0;
15884
- while (unit < BYTE_UNITS.length - 1 && Math.round(value * 10) / 10 >= 1024) {
16586
+ while (unit < BYTE_UNITS2.length - 1 && Math.round(value * 10) / 10 >= 1024) {
15885
16587
  value /= 1024;
15886
16588
  unit += 1;
15887
16589
  }
15888
- return unit === 0 ? `${Math.round(value)} B` : `${value.toFixed(1)} ${BYTE_UNITS[unit]}`;
16590
+ return unit === 0 ? `${Math.round(value)} B` : `${value.toFixed(1)} ${BYTE_UNITS2[unit]}`;
15889
16591
  }
15890
16592
  function table3(rows) {
15891
16593
  const widths = [];
@@ -16009,11 +16711,11 @@ function readSandboxes(body) {
16009
16711
  return body.sandboxes.filter((item) => Boolean(item) && typeof item === "object");
16010
16712
  }
16011
16713
  function readList(body, name) {
16012
- const list3 = body && typeof body === "object" ? body[name] : void 0;
16013
- if (!Array.isArray(list3)) {
16714
+ const list4 = body && typeof body === "object" ? body[name] : void 0;
16715
+ if (!Array.isArray(list4)) {
16014
16716
  throw new Error(`Metrics response was missing ${name}`);
16015
16717
  }
16016
- return list3.filter((item) => Boolean(item) && typeof item === "object");
16718
+ return list4.filter((item) => Boolean(item) && typeof item === "object");
16017
16719
  }
16018
16720
  function teamOptions(values) {
16019
16721
  return { json: values.json, revokeKeys: values["revoke-keys"], ...values.role === void 0 ? {} : { role: values.role } };
@@ -16083,12 +16785,20 @@ Usage
16083
16785
  agental meta <sandbox-id> [set <key>=<value>... | unset <key>...] [--json]
16084
16786
  agental regions [--json]
16085
16787
  agental exec <sandbox-id> -- <command> [args...]
16788
+ agental command start <sandbox-id> [--name <name>] [--cwd <dir>] [--env <NAME>=<value>]... [--timeout <seconds> | --no-timeout] [--stdin] [--json] -- <command> [args...]
16789
+ agental command list <sandbox-id> [--limit <n>] [--json]
16790
+ agental command get <sandbox-id> <command-id> [--json]
16791
+ agental command logs <sandbox-id> <command-id> [--follow]
16792
+ agental command signal <sandbox-id> <command-id> TERM|KILL|INT|HUP|QUIT|USR1|USR2|STOP|CONT [--json]
16793
+ agental command kill <sandbox-id> <command-id> [--grace <seconds>] [--json] TERM, then KILL
16794
+ agental command stdin <sandbox-id> <command-id> this process's stdin into its, then closed
16795
+ agental command delete <sandbox-id> <command-id> forget one that has ended
16086
16796
  agental shell <sandbox-id> a login shell in it, in this terminal, kept: ~d leaves it running
16087
16797
  agental shell <sandbox-id> --attach <shell> a kept shell again, by its number or id
16088
16798
  agental shell <sandbox-id> --list [--json] the shells kept in it
16089
16799
  agental shell <sandbox-id> --close <shell> end a kept shell
16090
16800
  agental delete <sandbox-id>
16091
- agental start <sandbox-id> [--max-burst-fee <dollars>]
16801
+ agental start <sandbox-id> [--max-burst-fee <dollars>] [--without-memory]
16092
16802
  agental stop <sandbox-id> [--keep-memory]
16093
16803
  agental stop --where '<words>' [--keep-memory] [--yes] every sandbox the words find, as one bulk action
16094
16804
  agental start --where '<words>' [--yes]
@@ -16476,6 +17186,26 @@ account export prints everything agental keeps about your account and you, as JS
16476
17186
  account, its sessions with the address and browser each began from, its keys by name, billing,
16477
17187
  payments, usage, and what it has made. Secrets are named, never given. --out writes it to a file
16478
17188
  only you can read. An account is closed from Settings in the console: a key cannot close one.
17189
+ command start starts a command in a running sandbox and prints its id: what comes after -- is
17190
+ its program and arguments, run as root with no shell (sh -c "..." for pipes), which runs on
17191
+ whether or not anything watches it. --name gives it a short name that lists and the console show,
17192
+ since agental keeps no command line. It runs in the sandbox's work folder unless --cwd names an
17193
+ absolute one, with the sandbox's variables and those --env gives it, NAME=VALUE or NAME alone for
17194
+ the value it has here; their values are never printed or kept in agental's records. It is ended
17195
+ after 60 seconds unless --timeout says, up to 10m, or --no-timeout gives it no limit of its own:
17196
+ then it runs until it exits or its sandbox stops. With --stdin, command stdin writes its stdin;
17197
+ without, it is /dev/null. list lists a sandbox's commands, the latest first, and get says how one
17198
+ is: running, or how it ended, and how much it wrote. logs prints a command's output, its stdout to
17199
+ stdout and its stderr to stderr, as the bytes it wrote; each stream keeps its last 1 MiB in the
17200
+ sandbox, and bytes overwritten before they were read are said on stderr. With --follow it follows
17201
+ the command to its end, going on by itself when a stream ends or is cut, and exits with the
17202
+ command's exit code; with 128 and the signal's number when a signal ended it, 124 when its time
17203
+ limit did, and 255, with why on stderr, when it ended any other way, as when its sandbox stopped,
17204
+ or its output could not be read 6 tries in a row. signal sends a signal to the command and every
17205
+ process it started; kill sends TERM, waits --grace seconds (5) for it to end, then sends KILL.
17206
+ stdin sends what this process reads on its stdin to the command's, as it comes, and closes it at
17207
+ its end. delete forgets a command that has ended, and its output. They need a sandbox whose agent
17208
+ has them: a sandbox stopped and started again has.
16479
17209
  shell opens a login shell in a running sandbox, in this terminal, over the API: no SSH key or
16480
17210
  port. It exits with what the shell exits with, or 255 when the connection ends first. The shell
16481
17211
  is kept: it runs on in the sandbox when the connection closes, until it exits, is closed, or the