agental 0.32.0 → 0.34.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.
- package/dist/cli.js +598 -312
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -126,17 +126,17 @@ var require_visit = __commonJS({
|
|
|
126
126
|
visit.BREAK = BREAK;
|
|
127
127
|
visit.SKIP = SKIP;
|
|
128
128
|
visit.REMOVE = REMOVE;
|
|
129
|
-
function visit_(key2, node, visitor,
|
|
130
|
-
const ctrl = callVisitor(key2, node, visitor,
|
|
129
|
+
function visit_(key2, node, visitor, path6) {
|
|
130
|
+
const ctrl = callVisitor(key2, node, visitor, path6);
|
|
131
131
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
132
|
-
replaceNode(key2,
|
|
133
|
-
return visit_(key2, ctrl, visitor,
|
|
132
|
+
replaceNode(key2, path6, ctrl);
|
|
133
|
+
return visit_(key2, ctrl, visitor, path6);
|
|
134
134
|
}
|
|
135
135
|
if (typeof ctrl !== "symbol") {
|
|
136
136
|
if (identity.isCollection(node)) {
|
|
137
|
-
|
|
137
|
+
path6 = Object.freeze(path6.concat(node));
|
|
138
138
|
for (let i = 0; i < node.items.length; ++i) {
|
|
139
|
-
const ci2 = visit_(i, node.items[i], visitor,
|
|
139
|
+
const ci2 = visit_(i, node.items[i], visitor, path6);
|
|
140
140
|
if (typeof ci2 === "number")
|
|
141
141
|
i = ci2 - 1;
|
|
142
142
|
else if (ci2 === BREAK)
|
|
@@ -147,13 +147,13 @@ var require_visit = __commonJS({
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
} else if (identity.isPair(node)) {
|
|
150
|
-
|
|
151
|
-
const ck = visit_("key", node.key, visitor,
|
|
150
|
+
path6 = Object.freeze(path6.concat(node));
|
|
151
|
+
const ck = visit_("key", node.key, visitor, path6);
|
|
152
152
|
if (ck === BREAK)
|
|
153
153
|
return BREAK;
|
|
154
154
|
else if (ck === REMOVE)
|
|
155
155
|
node.key = null;
|
|
156
|
-
const cv = visit_("value", node.value, visitor,
|
|
156
|
+
const cv = visit_("value", node.value, visitor, path6);
|
|
157
157
|
if (cv === BREAK)
|
|
158
158
|
return BREAK;
|
|
159
159
|
else if (cv === REMOVE)
|
|
@@ -174,17 +174,17 @@ var require_visit = __commonJS({
|
|
|
174
174
|
visitAsync.BREAK = BREAK;
|
|
175
175
|
visitAsync.SKIP = SKIP;
|
|
176
176
|
visitAsync.REMOVE = REMOVE;
|
|
177
|
-
async function visitAsync_(key2, node, visitor,
|
|
178
|
-
const ctrl = await callVisitor(key2, node, visitor,
|
|
177
|
+
async function visitAsync_(key2, node, visitor, path6) {
|
|
178
|
+
const ctrl = await callVisitor(key2, node, visitor, path6);
|
|
179
179
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
180
|
-
replaceNode(key2,
|
|
181
|
-
return visitAsync_(key2, ctrl, visitor,
|
|
180
|
+
replaceNode(key2, path6, ctrl);
|
|
181
|
+
return visitAsync_(key2, ctrl, visitor, path6);
|
|
182
182
|
}
|
|
183
183
|
if (typeof ctrl !== "symbol") {
|
|
184
184
|
if (identity.isCollection(node)) {
|
|
185
|
-
|
|
185
|
+
path6 = Object.freeze(path6.concat(node));
|
|
186
186
|
for (let i = 0; i < node.items.length; ++i) {
|
|
187
|
-
const ci2 = await visitAsync_(i, node.items[i], visitor,
|
|
187
|
+
const ci2 = await visitAsync_(i, node.items[i], visitor, path6);
|
|
188
188
|
if (typeof ci2 === "number")
|
|
189
189
|
i = ci2 - 1;
|
|
190
190
|
else if (ci2 === BREAK)
|
|
@@ -195,13 +195,13 @@ var require_visit = __commonJS({
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
} else if (identity.isPair(node)) {
|
|
198
|
-
|
|
199
|
-
const ck = await visitAsync_("key", node.key, visitor,
|
|
198
|
+
path6 = Object.freeze(path6.concat(node));
|
|
199
|
+
const ck = await visitAsync_("key", node.key, visitor, path6);
|
|
200
200
|
if (ck === BREAK)
|
|
201
201
|
return BREAK;
|
|
202
202
|
else if (ck === REMOVE)
|
|
203
203
|
node.key = null;
|
|
204
|
-
const cv = await visitAsync_("value", node.value, visitor,
|
|
204
|
+
const cv = await visitAsync_("value", node.value, visitor, path6);
|
|
205
205
|
if (cv === BREAK)
|
|
206
206
|
return BREAK;
|
|
207
207
|
else if (cv === REMOVE)
|
|
@@ -228,23 +228,23 @@ var require_visit = __commonJS({
|
|
|
228
228
|
}
|
|
229
229
|
return visitor;
|
|
230
230
|
}
|
|
231
|
-
function callVisitor(key2, node, visitor,
|
|
231
|
+
function callVisitor(key2, node, visitor, path6) {
|
|
232
232
|
if (typeof visitor === "function")
|
|
233
|
-
return visitor(key2, node,
|
|
233
|
+
return visitor(key2, node, path6);
|
|
234
234
|
if (identity.isMap(node))
|
|
235
|
-
return visitor.Map?.(key2, node,
|
|
235
|
+
return visitor.Map?.(key2, node, path6);
|
|
236
236
|
if (identity.isSeq(node))
|
|
237
|
-
return visitor.Seq?.(key2, node,
|
|
237
|
+
return visitor.Seq?.(key2, node, path6);
|
|
238
238
|
if (identity.isPair(node))
|
|
239
|
-
return visitor.Pair?.(key2, node,
|
|
239
|
+
return visitor.Pair?.(key2, node, path6);
|
|
240
240
|
if (identity.isScalar(node))
|
|
241
|
-
return visitor.Scalar?.(key2, node,
|
|
241
|
+
return visitor.Scalar?.(key2, node, path6);
|
|
242
242
|
if (identity.isAlias(node))
|
|
243
|
-
return visitor.Alias?.(key2, node,
|
|
243
|
+
return visitor.Alias?.(key2, node, path6);
|
|
244
244
|
return void 0;
|
|
245
245
|
}
|
|
246
|
-
function replaceNode(key2,
|
|
247
|
-
const parent =
|
|
246
|
+
function replaceNode(key2, path6, node) {
|
|
247
|
+
const parent = path6[path6.length - 1];
|
|
248
248
|
if (identity.isCollection(parent)) {
|
|
249
249
|
parent.items[key2] = node;
|
|
250
250
|
} else if (identity.isPair(parent)) {
|
|
@@ -856,10 +856,10 @@ var require_Collection = __commonJS({
|
|
|
856
856
|
var createNode = require_createNode();
|
|
857
857
|
var identity = require_identity();
|
|
858
858
|
var Node = require_Node();
|
|
859
|
-
function collectionFromPath(schema,
|
|
859
|
+
function collectionFromPath(schema, path6, value) {
|
|
860
860
|
let v = value;
|
|
861
|
-
for (let i =
|
|
862
|
-
const k =
|
|
861
|
+
for (let i = path6.length - 1; i >= 0; --i) {
|
|
862
|
+
const k = path6[i];
|
|
863
863
|
if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
|
|
864
864
|
const a = [];
|
|
865
865
|
a[k] = v;
|
|
@@ -878,7 +878,7 @@ var require_Collection = __commonJS({
|
|
|
878
878
|
sourceObjects: /* @__PURE__ */ new Map()
|
|
879
879
|
});
|
|
880
880
|
}
|
|
881
|
-
var isEmptyPath = (
|
|
881
|
+
var isEmptyPath = (path6) => path6 == null || typeof path6 === "object" && !!path6[Symbol.iterator]().next().done;
|
|
882
882
|
var Collection = class extends Node.NodeBase {
|
|
883
883
|
constructor(type, schema) {
|
|
884
884
|
super(type);
|
|
@@ -908,11 +908,11 @@ var require_Collection = __commonJS({
|
|
|
908
908
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
909
909
|
* that already exists in the map.
|
|
910
910
|
*/
|
|
911
|
-
addIn(
|
|
912
|
-
if (isEmptyPath(
|
|
911
|
+
addIn(path6, value) {
|
|
912
|
+
if (isEmptyPath(path6))
|
|
913
913
|
this.add(value);
|
|
914
914
|
else {
|
|
915
|
-
const [key2, ...rest] =
|
|
915
|
+
const [key2, ...rest] = path6;
|
|
916
916
|
const node = this.get(key2, true);
|
|
917
917
|
if (identity.isCollection(node))
|
|
918
918
|
node.addIn(rest, value);
|
|
@@ -926,8 +926,8 @@ var require_Collection = __commonJS({
|
|
|
926
926
|
* Removes a value from the collection.
|
|
927
927
|
* @returns `true` if the item was found and removed.
|
|
928
928
|
*/
|
|
929
|
-
deleteIn(
|
|
930
|
-
const [key2, ...rest] =
|
|
929
|
+
deleteIn(path6) {
|
|
930
|
+
const [key2, ...rest] = path6;
|
|
931
931
|
if (rest.length === 0)
|
|
932
932
|
return this.delete(key2);
|
|
933
933
|
const node = this.get(key2, true);
|
|
@@ -941,8 +941,8 @@ var require_Collection = __commonJS({
|
|
|
941
941
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
942
942
|
* `true` (collections are always returned intact).
|
|
943
943
|
*/
|
|
944
|
-
getIn(
|
|
945
|
-
const [key2, ...rest] =
|
|
944
|
+
getIn(path6, keepScalar) {
|
|
945
|
+
const [key2, ...rest] = path6;
|
|
946
946
|
const node = this.get(key2, true);
|
|
947
947
|
if (rest.length === 0)
|
|
948
948
|
return !keepScalar && identity.isScalar(node) ? node.value : node;
|
|
@@ -960,8 +960,8 @@ var require_Collection = __commonJS({
|
|
|
960
960
|
/**
|
|
961
961
|
* Checks if the collection includes a value with the key `key`.
|
|
962
962
|
*/
|
|
963
|
-
hasIn(
|
|
964
|
-
const [key2, ...rest] =
|
|
963
|
+
hasIn(path6) {
|
|
964
|
+
const [key2, ...rest] = path6;
|
|
965
965
|
if (rest.length === 0)
|
|
966
966
|
return this.has(key2);
|
|
967
967
|
const node = this.get(key2, true);
|
|
@@ -971,8 +971,8 @@ var require_Collection = __commonJS({
|
|
|
971
971
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
972
972
|
* boolean to add/remove the item from the set.
|
|
973
973
|
*/
|
|
974
|
-
setIn(
|
|
975
|
-
const [key2, ...rest] =
|
|
974
|
+
setIn(path6, value) {
|
|
975
|
+
const [key2, ...rest] = path6;
|
|
976
976
|
if (rest.length === 0) {
|
|
977
977
|
this.set(key2, value);
|
|
978
978
|
} else {
|
|
@@ -3487,9 +3487,9 @@ var require_Document = __commonJS({
|
|
|
3487
3487
|
this.contents.add(value);
|
|
3488
3488
|
}
|
|
3489
3489
|
/** Adds a value to the document. */
|
|
3490
|
-
addIn(
|
|
3490
|
+
addIn(path6, value) {
|
|
3491
3491
|
if (assertCollection(this.contents))
|
|
3492
|
-
this.contents.addIn(
|
|
3492
|
+
this.contents.addIn(path6, value);
|
|
3493
3493
|
}
|
|
3494
3494
|
/**
|
|
3495
3495
|
* Create a new `Alias` node, ensuring that the target `node` has the required anchor.
|
|
@@ -3564,14 +3564,14 @@ var require_Document = __commonJS({
|
|
|
3564
3564
|
* Removes a value from the document.
|
|
3565
3565
|
* @returns `true` if the item was found and removed.
|
|
3566
3566
|
*/
|
|
3567
|
-
deleteIn(
|
|
3568
|
-
if (Collection.isEmptyPath(
|
|
3567
|
+
deleteIn(path6) {
|
|
3568
|
+
if (Collection.isEmptyPath(path6)) {
|
|
3569
3569
|
if (this.contents == null)
|
|
3570
3570
|
return false;
|
|
3571
3571
|
this.contents = null;
|
|
3572
3572
|
return true;
|
|
3573
3573
|
}
|
|
3574
|
-
return assertCollection(this.contents) ? this.contents.deleteIn(
|
|
3574
|
+
return assertCollection(this.contents) ? this.contents.deleteIn(path6) : false;
|
|
3575
3575
|
}
|
|
3576
3576
|
/**
|
|
3577
3577
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
@@ -3586,10 +3586,10 @@ var require_Document = __commonJS({
|
|
|
3586
3586
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
3587
3587
|
* `true` (collections are always returned intact).
|
|
3588
3588
|
*/
|
|
3589
|
-
getIn(
|
|
3590
|
-
if (Collection.isEmptyPath(
|
|
3589
|
+
getIn(path6, keepScalar) {
|
|
3590
|
+
if (Collection.isEmptyPath(path6))
|
|
3591
3591
|
return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
|
|
3592
|
-
return identity.isCollection(this.contents) ? this.contents.getIn(
|
|
3592
|
+
return identity.isCollection(this.contents) ? this.contents.getIn(path6, keepScalar) : void 0;
|
|
3593
3593
|
}
|
|
3594
3594
|
/**
|
|
3595
3595
|
* Checks if the document includes a value with the key `key`.
|
|
@@ -3600,10 +3600,10 @@ var require_Document = __commonJS({
|
|
|
3600
3600
|
/**
|
|
3601
3601
|
* Checks if the document includes a value at `path`.
|
|
3602
3602
|
*/
|
|
3603
|
-
hasIn(
|
|
3604
|
-
if (Collection.isEmptyPath(
|
|
3603
|
+
hasIn(path6) {
|
|
3604
|
+
if (Collection.isEmptyPath(path6))
|
|
3605
3605
|
return this.contents !== void 0;
|
|
3606
|
-
return identity.isCollection(this.contents) ? this.contents.hasIn(
|
|
3606
|
+
return identity.isCollection(this.contents) ? this.contents.hasIn(path6) : false;
|
|
3607
3607
|
}
|
|
3608
3608
|
/**
|
|
3609
3609
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
@@ -3620,13 +3620,13 @@ var require_Document = __commonJS({
|
|
|
3620
3620
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
3621
3621
|
* boolean to add/remove the item from the set.
|
|
3622
3622
|
*/
|
|
3623
|
-
setIn(
|
|
3624
|
-
if (Collection.isEmptyPath(
|
|
3623
|
+
setIn(path6, value) {
|
|
3624
|
+
if (Collection.isEmptyPath(path6)) {
|
|
3625
3625
|
this.contents = value;
|
|
3626
3626
|
} else if (this.contents == null) {
|
|
3627
|
-
this.contents = Collection.collectionFromPath(this.schema, Array.from(
|
|
3627
|
+
this.contents = Collection.collectionFromPath(this.schema, Array.from(path6), value);
|
|
3628
3628
|
} else if (assertCollection(this.contents)) {
|
|
3629
|
-
this.contents.setIn(
|
|
3629
|
+
this.contents.setIn(path6, value);
|
|
3630
3630
|
}
|
|
3631
3631
|
}
|
|
3632
3632
|
/**
|
|
@@ -5587,9 +5587,9 @@ var require_cst_visit = __commonJS({
|
|
|
5587
5587
|
visit.BREAK = BREAK;
|
|
5588
5588
|
visit.SKIP = SKIP;
|
|
5589
5589
|
visit.REMOVE = REMOVE;
|
|
5590
|
-
visit.itemAtPath = (cst,
|
|
5590
|
+
visit.itemAtPath = (cst, path6) => {
|
|
5591
5591
|
let item = cst;
|
|
5592
|
-
for (const [field, index] of
|
|
5592
|
+
for (const [field, index] of path6) {
|
|
5593
5593
|
const tok = item?.[field];
|
|
5594
5594
|
if (tok && "items" in tok) {
|
|
5595
5595
|
item = tok.items[index];
|
|
@@ -5598,23 +5598,23 @@ var require_cst_visit = __commonJS({
|
|
|
5598
5598
|
}
|
|
5599
5599
|
return item;
|
|
5600
5600
|
};
|
|
5601
|
-
visit.parentCollection = (cst,
|
|
5602
|
-
const parent = visit.itemAtPath(cst,
|
|
5603
|
-
const field =
|
|
5601
|
+
visit.parentCollection = (cst, path6) => {
|
|
5602
|
+
const parent = visit.itemAtPath(cst, path6.slice(0, -1));
|
|
5603
|
+
const field = path6[path6.length - 1][0];
|
|
5604
5604
|
const coll = parent?.[field];
|
|
5605
5605
|
if (coll && "items" in coll)
|
|
5606
5606
|
return coll;
|
|
5607
5607
|
throw new Error("Parent collection not found");
|
|
5608
5608
|
};
|
|
5609
|
-
function _visit(
|
|
5610
|
-
let ctrl = visitor(item,
|
|
5609
|
+
function _visit(path6, item, visitor) {
|
|
5610
|
+
let ctrl = visitor(item, path6);
|
|
5611
5611
|
if (typeof ctrl === "symbol")
|
|
5612
5612
|
return ctrl;
|
|
5613
5613
|
for (const field of ["key", "value"]) {
|
|
5614
5614
|
const token = item[field];
|
|
5615
5615
|
if (token && "items" in token) {
|
|
5616
5616
|
for (let i = 0; i < token.items.length; ++i) {
|
|
5617
|
-
const ci2 = _visit(Object.freeze(
|
|
5617
|
+
const ci2 = _visit(Object.freeze(path6.concat([[field, i]])), token.items[i], visitor);
|
|
5618
5618
|
if (typeof ci2 === "number")
|
|
5619
5619
|
i = ci2 - 1;
|
|
5620
5620
|
else if (ci2 === BREAK)
|
|
@@ -5625,10 +5625,10 @@ var require_cst_visit = __commonJS({
|
|
|
5625
5625
|
}
|
|
5626
5626
|
}
|
|
5627
5627
|
if (typeof ctrl === "function" && field === "key")
|
|
5628
|
-
ctrl = ctrl(item,
|
|
5628
|
+
ctrl = ctrl(item, path6);
|
|
5629
5629
|
}
|
|
5630
5630
|
}
|
|
5631
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
5631
|
+
return typeof ctrl === "function" ? ctrl(item, path6) : ctrl;
|
|
5632
5632
|
}
|
|
5633
5633
|
exports.visit = visit;
|
|
5634
5634
|
}
|
|
@@ -5641,7 +5641,7 @@ var require_cst = __commonJS({
|
|
|
5641
5641
|
var cstScalar = require_cst_scalar();
|
|
5642
5642
|
var cstStringify = require_cst_stringify();
|
|
5643
5643
|
var cstVisit = require_cst_visit();
|
|
5644
|
-
var
|
|
5644
|
+
var BOM2 = "\uFEFF";
|
|
5645
5645
|
var DOCUMENT = "";
|
|
5646
5646
|
var FLOW_END = "";
|
|
5647
5647
|
var SCALAR = "";
|
|
@@ -5649,7 +5649,7 @@ var require_cst = __commonJS({
|
|
|
5649
5649
|
var isScalar = (token) => !!token && (token.type === "scalar" || token.type === "single-quoted-scalar" || token.type === "double-quoted-scalar" || token.type === "block-scalar");
|
|
5650
5650
|
function prettyToken(token) {
|
|
5651
5651
|
switch (token) {
|
|
5652
|
-
case
|
|
5652
|
+
case BOM2:
|
|
5653
5653
|
return "<BOM>";
|
|
5654
5654
|
case DOCUMENT:
|
|
5655
5655
|
return "<DOC>";
|
|
@@ -5663,7 +5663,7 @@ var require_cst = __commonJS({
|
|
|
5663
5663
|
}
|
|
5664
5664
|
function tokenType(source) {
|
|
5665
5665
|
switch (source) {
|
|
5666
|
-
case
|
|
5666
|
+
case BOM2:
|
|
5667
5667
|
return "byte-order-mark";
|
|
5668
5668
|
case DOCUMENT:
|
|
5669
5669
|
return "doc-mode";
|
|
@@ -5725,7 +5725,7 @@ var require_cst = __commonJS({
|
|
|
5725
5725
|
exports.setScalarValue = cstScalar.setScalarValue;
|
|
5726
5726
|
exports.stringify = cstStringify.stringify;
|
|
5727
5727
|
exports.visit = cstVisit.visit;
|
|
5728
|
-
exports.BOM =
|
|
5728
|
+
exports.BOM = BOM2;
|
|
5729
5729
|
exports.DOCUMENT = DOCUMENT;
|
|
5730
5730
|
exports.FLOW_END = FLOW_END;
|
|
5731
5731
|
exports.SCALAR = SCALAR;
|
|
@@ -7404,14 +7404,14 @@ var init_cli_operator = __esm({
|
|
|
7404
7404
|
|
|
7405
7405
|
// ../src/cli.ts
|
|
7406
7406
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
7407
|
-
import { readFileSync as
|
|
7408
|
-
import
|
|
7407
|
+
import { readFileSync as readFileSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7408
|
+
import os7 from "node:os";
|
|
7409
7409
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
7410
7410
|
import { parseArgs } from "node:util";
|
|
7411
7411
|
|
|
7412
7412
|
// ../src/cli-build.ts
|
|
7413
7413
|
var PUBLISHED = true;
|
|
7414
|
-
var CLI_VERSION = true ? "0.
|
|
7414
|
+
var CLI_VERSION = true ? "0.34.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}`;
|
|
@@ -7803,27 +7803,27 @@ ${USAGE2}`);
|
|
|
7803
7803
|
return;
|
|
7804
7804
|
}
|
|
7805
7805
|
case "cat": {
|
|
7806
|
-
const
|
|
7807
|
-
const body = await ask2(client, "GET", `${base}/files?path=${encodeURIComponent(
|
|
7806
|
+
const path6 = need(first, "a path");
|
|
7807
|
+
const body = await ask2(client, "GET", `${base}/files?path=${encodeURIComponent(path6)}&encoding=base64`);
|
|
7808
7808
|
process.stdout.write(Buffer.from(String(body["base64"] ?? ""), "base64"));
|
|
7809
7809
|
return;
|
|
7810
7810
|
}
|
|
7811
7811
|
case "put": {
|
|
7812
7812
|
const local = need(first, "a local file and a path in the sandbox");
|
|
7813
|
-
const
|
|
7813
|
+
const path6 = need(second, "a path in the sandbox");
|
|
7814
7814
|
const bytes3 = await readFile(local);
|
|
7815
7815
|
if (bytes3.length > LIMIT) {
|
|
7816
7816
|
throw new Error(`${local} is ${size(bytes3.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:
|
|
7818
|
+
const body = await ask2(client, "PUT", `${base}/files`, { path: path6, base64: bytes3.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
|
`);
|
|
7822
7822
|
return;
|
|
7823
7823
|
}
|
|
7824
7824
|
case "get": {
|
|
7825
|
-
const
|
|
7826
|
-
const response = await client.request(`${base}/artifacts?path=${encodeURIComponent(
|
|
7825
|
+
const path6 = need(first, "a path");
|
|
7826
|
+
const response = await client.request(`${base}/artifacts?path=${encodeURIComponent(path6)}`, { method: "GET", headers: { Accept: "application/octet-stream" } });
|
|
7827
7827
|
if (!response.ok) {
|
|
7828
7828
|
client.fail(response.status, await readObject2(response));
|
|
7829
7829
|
}
|
|
@@ -7852,8 +7852,8 @@ ${USAGE2}`);
|
|
|
7852
7852
|
return;
|
|
7853
7853
|
}
|
|
7854
7854
|
case "rm": {
|
|
7855
|
-
const
|
|
7856
|
-
await ask2(client, "DELETE", `${base}/files?path=${encodeURIComponent(
|
|
7855
|
+
const path6 = need(first, "a path");
|
|
7856
|
+
await ask2(client, "DELETE", `${base}/files?path=${encodeURIComponent(path6)}${options.recursive ? "&recursive=true" : ""}`);
|
|
7857
7857
|
return;
|
|
7858
7858
|
}
|
|
7859
7859
|
case "link": {
|
|
@@ -8519,19 +8519,205 @@ async function readAll(stream) {
|
|
|
8519
8519
|
}
|
|
8520
8520
|
|
|
8521
8521
|
// ../src/cli-onboard.ts
|
|
8522
|
-
import { execFile, spawnSync as spawnSync3 } from "node:child_process";
|
|
8522
|
+
import { execFile as execFile2, spawnSync as spawnSync3 } from "node:child_process";
|
|
8523
8523
|
import { randomUUID, randomBytes as randomBytes3 } from "node:crypto";
|
|
8524
|
-
import { existsSync as
|
|
8525
|
-
import
|
|
8526
|
-
import
|
|
8524
|
+
import { existsSync as existsSync3, readFileSync as readFileSync4, realpathSync as realpathSync2, statSync as statSync2 } from "node:fs";
|
|
8525
|
+
import os5 from "node:os";
|
|
8526
|
+
import path4 from "node:path";
|
|
8527
8527
|
import { createInterface } from "node:readline/promises";
|
|
8528
8528
|
|
|
8529
|
+
// ../src/cli-mcp.ts
|
|
8530
|
+
import { execFile } from "node:child_process";
|
|
8531
|
+
import { chmodSync as chmodSync2, existsSync, readFileSync as readFileSync2, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
8532
|
+
import os3 from "node:os";
|
|
8533
|
+
import path2 from "node:path";
|
|
8534
|
+
var CONNECTOR_NAME = "agental";
|
|
8535
|
+
function placesFrom(env = process.env) {
|
|
8536
|
+
const home = env["HOME"] || os3.homedir();
|
|
8537
|
+
return {
|
|
8538
|
+
home,
|
|
8539
|
+
config: env["XDG_CONFIG_HOME"]?.trim() || path2.join(home, ".config"),
|
|
8540
|
+
claudeDir: env["CLAUDE_CONFIG_DIR"]?.trim() || path2.join(home, ".claude"),
|
|
8541
|
+
codexDir: env["CODEX_HOME"]?.trim() || path2.join(home, ".codex")
|
|
8542
|
+
};
|
|
8543
|
+
}
|
|
8544
|
+
var SIGN_IN = {
|
|
8545
|
+
"Claude Code": "/mcp, then agental, then Authenticate",
|
|
8546
|
+
Codex: "codex mcp login agental",
|
|
8547
|
+
Cursor: "Settings \u203A MCP, turn agental on, then log in",
|
|
8548
|
+
Windsurf: "its MCP servers list, then agental",
|
|
8549
|
+
"Gemini CLI": "/mcp auth agental",
|
|
8550
|
+
opencode: "opencode mcp auth agental"
|
|
8551
|
+
};
|
|
8552
|
+
var JSON_AGENTS = [
|
|
8553
|
+
{ agent: "Cursor", folder: (p) => path2.join(p.home, ".cursor"), file: "mcp.json", key: "mcpServers", entry: (url) => ({ url }) },
|
|
8554
|
+
{ agent: "Windsurf", folder: (p) => path2.join(p.home, ".codeium", "windsurf"), file: "mcp_config.json", key: "mcpServers", entry: (url) => ({ serverUrl: url }) },
|
|
8555
|
+
{ agent: "Gemini CLI", folder: (p) => path2.join(p.home, ".gemini"), file: "settings.json", key: "mcpServers", entry: (url) => ({ httpUrl: url }) },
|
|
8556
|
+
{ agent: "opencode", folder: (p) => path2.join(p.config, "opencode"), file: "opencode.json", other: "opencode.jsonc", key: "mcp", entry: (url) => ({ type: "remote", url }) }
|
|
8557
|
+
];
|
|
8558
|
+
function replaceFile(file, text) {
|
|
8559
|
+
const target = existsSync(file) ? realpathSync(file) : file;
|
|
8560
|
+
const mode = existsSync(target) ? statSync(target).mode & 511 : 420;
|
|
8561
|
+
const next = `${target}.agental-${process.pid}`;
|
|
8562
|
+
try {
|
|
8563
|
+
writeFileSync2(next, text, { mode });
|
|
8564
|
+
chmodSync2(next, mode);
|
|
8565
|
+
renameSync2(next, target);
|
|
8566
|
+
} catch (error) {
|
|
8567
|
+
rmSync2(next, { force: true });
|
|
8568
|
+
throw error;
|
|
8569
|
+
}
|
|
8570
|
+
}
|
|
8571
|
+
var BOM = "\uFEFF";
|
|
8572
|
+
function addToJson(agent, places, url) {
|
|
8573
|
+
const folder = agent.folder(places);
|
|
8574
|
+
if (!existsSync(folder)) {
|
|
8575
|
+
return null;
|
|
8576
|
+
}
|
|
8577
|
+
const file = path2.join(folder, agent.file);
|
|
8578
|
+
const lines = JSON.stringify({ [agent.key]: { [CONNECTOR_NAME]: agent.entry(url) } });
|
|
8579
|
+
if (agent.other && existsSync(path2.join(folder, agent.other))) {
|
|
8580
|
+
return { agent: agent.agent, did: "left", why: `its settings are in ${path2.join(folder, agent.other)}, which this does not change: add ${lines}` };
|
|
8581
|
+
}
|
|
8582
|
+
let settings = {};
|
|
8583
|
+
let bom = "";
|
|
8584
|
+
if (existsSync(file)) {
|
|
8585
|
+
try {
|
|
8586
|
+
const text = readFileSync2(file, "utf8");
|
|
8587
|
+
bom = text.startsWith(BOM) ? BOM : "";
|
|
8588
|
+
const read2 = JSON.parse(text.slice(bom.length));
|
|
8589
|
+
if (!read2 || typeof read2 !== "object" || Array.isArray(read2)) {
|
|
8590
|
+
throw new Error("not an object");
|
|
8591
|
+
}
|
|
8592
|
+
settings = read2;
|
|
8593
|
+
} catch {
|
|
8594
|
+
return { agent: agent.agent, did: "left", why: `${file} is not plain JSON, so it was left as it is: add ${lines}` };
|
|
8595
|
+
}
|
|
8596
|
+
}
|
|
8597
|
+
const servers = settings[agent.key] ?? {};
|
|
8598
|
+
if (typeof servers !== "object" || servers === null || Array.isArray(servers)) {
|
|
8599
|
+
return { agent: agent.agent, did: "left", why: `${agent.key} in ${file} is not a list of servers, so it was left as it is: add ${lines}` };
|
|
8600
|
+
}
|
|
8601
|
+
if (CONNECTOR_NAME in servers) {
|
|
8602
|
+
return { agent: agent.agent, did: "already" };
|
|
8603
|
+
}
|
|
8604
|
+
settings[agent.key] = { ...servers, [CONNECTOR_NAME]: agent.entry(url) };
|
|
8605
|
+
replaceFile(file, `${bom}${JSON.stringify(settings, null, 2)}
|
|
8606
|
+
`);
|
|
8607
|
+
return { agent: agent.agent, did: "added" };
|
|
8608
|
+
}
|
|
8609
|
+
function codexHas(text) {
|
|
8610
|
+
const has = /^\s*\[\s*mcp_servers\s*\.\s*["']?agental["']?\s*[\].]/m.test(text) || /^\s*mcp_servers\s*\.\s*["']?agental["']?\s*[.=]/m.test(text) || /^\s*\[\s*mcp_servers\s*\]/m.test(text) && /^\s*["']?agental["']?\s*[.=]/m.test(text);
|
|
8611
|
+
if (has) {
|
|
8612
|
+
return "agental";
|
|
8613
|
+
}
|
|
8614
|
+
return /^\s*mcp_servers\s*=/m.test(text) ? "inline" : null;
|
|
8615
|
+
}
|
|
8616
|
+
function addToCodex(places, url) {
|
|
8617
|
+
if (!existsSync(places.codexDir)) {
|
|
8618
|
+
return null;
|
|
8619
|
+
}
|
|
8620
|
+
const file = path2.join(places.codexDir, "config.toml");
|
|
8621
|
+
const text = existsSync(file) ? readFileSync2(file, "utf8") : "";
|
|
8622
|
+
const has = codexHas(text);
|
|
8623
|
+
if (has === "agental") {
|
|
8624
|
+
return { agent: "Codex", did: "already" };
|
|
8625
|
+
}
|
|
8626
|
+
if (has === "inline") {
|
|
8627
|
+
return { agent: "Codex", did: "left", why: `${file} lists its servers inline, so it was left as it is: add agental = { url = "${url}" } to them` };
|
|
8628
|
+
}
|
|
8629
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
8630
|
+
const lead = text === "" ? "" : text.endsWith("\n") ? eol : eol + eol;
|
|
8631
|
+
replaceFile(file, `${text}${lead}[mcp_servers.${CONNECTOR_NAME}]${eol}url = "${url}"${eol}`);
|
|
8632
|
+
return { agent: "Codex", did: "added" };
|
|
8633
|
+
}
|
|
8634
|
+
function run(command2, args, cwd) {
|
|
8635
|
+
return new Promise((resolve) => {
|
|
8636
|
+
execFile(command2, args, { encoding: "utf8", timeout: 6e4, cwd, shell: process.platform === "win32" }, (error, stdout, stderr) => {
|
|
8637
|
+
const out = `${stdout}${stderr}`.trim();
|
|
8638
|
+
const missing = error?.code === "ENOENT" || process.platform === "win32" && /is not recognized as an internal or external command/i.test(out);
|
|
8639
|
+
resolve({ ok: !error, out, missing });
|
|
8640
|
+
});
|
|
8641
|
+
});
|
|
8642
|
+
}
|
|
8643
|
+
async function addToClaudeCode(places, url) {
|
|
8644
|
+
if (!existsSync(places.claudeDir)) {
|
|
8645
|
+
return null;
|
|
8646
|
+
}
|
|
8647
|
+
const add = `claude mcp add --transport http --scope user ${CONNECTOR_NAME} ${url}`;
|
|
8648
|
+
const found = await run("claude", ["mcp", "get", CONNECTOR_NAME], places.home);
|
|
8649
|
+
if (found.missing) {
|
|
8650
|
+
return { agent: "Claude Code", did: "left", why: `the claude command is not on the PATH: run ${add}` };
|
|
8651
|
+
}
|
|
8652
|
+
if (found.ok) {
|
|
8653
|
+
return { agent: "Claude Code", did: "already" };
|
|
8654
|
+
}
|
|
8655
|
+
const added = await run("claude", ["mcp", "add", "--transport", "http", "--scope", "user", CONNECTOR_NAME, url], places.home);
|
|
8656
|
+
if (!added.ok) {
|
|
8657
|
+
const last = added.out.split("\n").filter((line) => line.trim()).pop() ?? "it failed";
|
|
8658
|
+
return { agent: "Claude Code", did: "left", why: `claude mcp add failed (${last.slice(0, 160)}): run ${add}` };
|
|
8659
|
+
}
|
|
8660
|
+
return { agent: "Claude Code", did: "added" };
|
|
8661
|
+
}
|
|
8662
|
+
async function step(agent, add) {
|
|
8663
|
+
try {
|
|
8664
|
+
return await add();
|
|
8665
|
+
} catch (error) {
|
|
8666
|
+
return { agent, did: "left", why: `it could not be added (${error instanceof Error ? error.message : String(error)})` };
|
|
8667
|
+
}
|
|
8668
|
+
}
|
|
8669
|
+
async function addConnector(url, places = placesFrom()) {
|
|
8670
|
+
const outcomes = [await step("Claude Code", () => addToClaudeCode(places, url)), await step("Codex", () => addToCodex(places, url))];
|
|
8671
|
+
for (const agent of JSON_AGENTS) {
|
|
8672
|
+
outcomes.push(await step(agent.agent, () => addToJson(agent, places, url)));
|
|
8673
|
+
}
|
|
8674
|
+
return outcomes.filter((outcome) => outcome !== null);
|
|
8675
|
+
}
|
|
8676
|
+
function claudeDesktopHere(places, platform = process.platform, env = process.env) {
|
|
8677
|
+
const folder = platform === "darwin" ? path2.join(places.home, "Library", "Application Support", "Claude") : platform === "win32" ? path2.join(env["APPDATA"] ?? path2.join(places.home, "AppData", "Roaming"), "Claude") : path2.join(places.config, "Claude");
|
|
8678
|
+
return existsSync(folder);
|
|
8679
|
+
}
|
|
8680
|
+
function addToClaudeLink(url) {
|
|
8681
|
+
return `https://claude.ai/customize/connectors?modal=add-custom-connector&connectorName=${CONNECTOR_NAME}&connectorUrl=${encodeURIComponent(url)}`;
|
|
8682
|
+
}
|
|
8683
|
+
function names(list3) {
|
|
8684
|
+
return list3.length < 2 ? list3[0] ?? "" : `${list3.slice(0, -1).join(", ")} and ${list3.at(-1)}`;
|
|
8685
|
+
}
|
|
8686
|
+
async function ensureConnector(site2, places = placesFrom()) {
|
|
8687
|
+
const url = `${site2}/v1/mcp`;
|
|
8688
|
+
const outcomes = await addConnector(url, places);
|
|
8689
|
+
const lines = [];
|
|
8690
|
+
const added = outcomes.filter((outcome) => outcome.did === "added").map((outcome) => outcome.agent);
|
|
8691
|
+
const already = outcomes.filter((outcome) => outcome.did === "already").map((outcome) => outcome.agent);
|
|
8692
|
+
if (added.length > 0) {
|
|
8693
|
+
lines.push(done(`connector added to ${names(added)} ${dim("\xB7 sign in once from each:")}`));
|
|
8694
|
+
for (const agent of added) {
|
|
8695
|
+
lines.push(` ${dim(`${agent}:`)} ${SIGN_IN[agent] ?? ""}`);
|
|
8696
|
+
}
|
|
8697
|
+
}
|
|
8698
|
+
if (already.length > 0) {
|
|
8699
|
+
lines.push(done(`connector already in ${names(already)}`));
|
|
8700
|
+
}
|
|
8701
|
+
for (const outcome of outcomes) {
|
|
8702
|
+
if (outcome.did === "left") {
|
|
8703
|
+
lines.push(`${bold("!")} connector not added to ${outcome.agent}: ${outcome.why}`);
|
|
8704
|
+
}
|
|
8705
|
+
}
|
|
8706
|
+
if (claudeDesktopHere(places)) {
|
|
8707
|
+
lines.push(`${dim("Claude Desktop adds connectors in its own window:")} ${addToClaudeLink(url)}`);
|
|
8708
|
+
}
|
|
8709
|
+
if (outcomes.length === 0) {
|
|
8710
|
+
lines.push(`${dim("no coding agent found here to add the connector to \xB7 any MCP client takes")} ${url}`);
|
|
8711
|
+
}
|
|
8712
|
+
return lines;
|
|
8713
|
+
}
|
|
8714
|
+
|
|
8529
8715
|
// ../src/cli-ssh.ts
|
|
8530
8716
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
8531
|
-
import { existsSync, mkdirSync as mkdirSync2, readFileSync as
|
|
8717
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8532
8718
|
import net from "node:net";
|
|
8533
|
-
import
|
|
8534
|
-
import
|
|
8719
|
+
import os4 from "node:os";
|
|
8720
|
+
import path3 from "node:path";
|
|
8535
8721
|
var Refused2 = class extends Error {
|
|
8536
8722
|
constructor(code, said) {
|
|
8537
8723
|
super(`${code}: ${said}`);
|
|
@@ -8550,22 +8736,22 @@ var TRIES_IN_A_ROW = 3;
|
|
|
8550
8736
|
var TAKES_A_VALUE = new Set("BbcDEeFIiJLlmOoPpQRSWw".split("").map((letter) => `-${letter}`));
|
|
8551
8737
|
var TMUX = "tmux new-session -A -s agental";
|
|
8552
8738
|
function keyPath() {
|
|
8553
|
-
return process.env["AGENTAL_SSH_KEY"] ||
|
|
8739
|
+
return process.env["AGENTAL_SSH_KEY"] || path3.join(os4.homedir(), ".ssh", "agental_ed25519");
|
|
8554
8740
|
}
|
|
8555
8741
|
function knownHostsPath() {
|
|
8556
|
-
return process.env["AGENTAL_SSH_KNOWN_HOSTS"] ||
|
|
8742
|
+
return process.env["AGENTAL_SSH_KNOWN_HOSTS"] || path3.join(os4.homedir(), ".ssh", "agental_known_hosts");
|
|
8557
8743
|
}
|
|
8558
8744
|
function publicKey() {
|
|
8559
8745
|
const key2 = keyPath();
|
|
8560
|
-
if (!
|
|
8561
|
-
mkdirSync2(
|
|
8746
|
+
if (!existsSync2(key2)) {
|
|
8747
|
+
mkdirSync2(path3.dirname(key2), { recursive: true, mode: 448 });
|
|
8562
8748
|
const made = spawnSync2("ssh-keygen", ["-q", "-t", "ed25519", "-N", "", "-C", "agental", "-f", key2], { stdio: ["ignore", "ignore", "inherit"] });
|
|
8563
8749
|
if (made.error || made.status !== 0) {
|
|
8564
8750
|
throw new Error(`No key pair at ${key2}, and ssh-keygen could not make one${made.error ? `: ${made.error.message}` : "."}`);
|
|
8565
8751
|
}
|
|
8566
8752
|
}
|
|
8567
8753
|
try {
|
|
8568
|
-
return
|
|
8754
|
+
return readFileSync3(`${key2}.pub`, "utf8").trim();
|
|
8569
8755
|
} catch {
|
|
8570
8756
|
throw new Error(`${key2}.pub could not be read. It is the public half of the key the CLI logs in with.`);
|
|
8571
8757
|
}
|
|
@@ -8614,14 +8800,14 @@ async function letIn(client, sandboxId) {
|
|
|
8614
8800
|
}
|
|
8615
8801
|
function pin(sandboxId, hostKey) {
|
|
8616
8802
|
const file = knownHostsPath();
|
|
8617
|
-
mkdirSync2(
|
|
8803
|
+
mkdirSync2(path3.dirname(file), { recursive: true, mode: 448 });
|
|
8618
8804
|
let lines = [];
|
|
8619
8805
|
try {
|
|
8620
|
-
lines =
|
|
8806
|
+
lines = readFileSync3(file, "utf8").split("\n").filter((line) => line.trim() !== "" && !line.startsWith(`${sandboxId} `));
|
|
8621
8807
|
} catch {
|
|
8622
8808
|
}
|
|
8623
8809
|
lines.push(`${sandboxId} ${hostKey}`);
|
|
8624
|
-
|
|
8810
|
+
writeFileSync3(file, `${lines.join("\n")}
|
|
8625
8811
|
`, { mode: 384 });
|
|
8626
8812
|
}
|
|
8627
8813
|
function kept(sandboxId, user, given) {
|
|
@@ -8639,7 +8825,7 @@ function kept(sandboxId, user, given) {
|
|
|
8639
8825
|
function flags(sandboxId, access, given) {
|
|
8640
8826
|
return [["HostName", access.host], ["Port", String(access.port)], ...kept(sandboxId, access.user, given)].flatMap(([name, value]) => ["-o", `${name}=${value}`]);
|
|
8641
8827
|
}
|
|
8642
|
-
async function
|
|
8828
|
+
async function run2(program, args) {
|
|
8643
8829
|
const child = spawn2(program, args, { stdio: "inherit" });
|
|
8644
8830
|
return await new Promise((resolve, reject) => {
|
|
8645
8831
|
child.on("error", (error) => reject(new Error(`${program} could not be run: ${error.message}`)));
|
|
@@ -8674,7 +8860,7 @@ async function ssh(client, args) {
|
|
|
8674
8860
|
await letIn(client, sandboxId);
|
|
8675
8861
|
for (let soon2 = 0; ; ) {
|
|
8676
8862
|
const began = Date.now();
|
|
8677
|
-
const code = await
|
|
8863
|
+
const code = await run2("ssh", [...flags(sandboxId, access, passed), ...tmux ? ["-t"] : [], sandboxId, ...passed, ...tmux ? [TMUX] : []]);
|
|
8678
8864
|
if (tmux && code === 127) {
|
|
8679
8865
|
process.stderr.write("tmux is not in this sandbox. Install it there, with apt-get update && apt-get install -y tmux, or leave --tmux out.\n");
|
|
8680
8866
|
}
|
|
@@ -8712,7 +8898,7 @@ async function scp(client, args) {
|
|
|
8712
8898
|
}
|
|
8713
8899
|
const access = await reach(client, sandboxId);
|
|
8714
8900
|
await letIn(client, sandboxId);
|
|
8715
|
-
process.exitCode = await
|
|
8901
|
+
process.exitCode = await run2("scp", [...flags(sandboxId, access, args), ...args]);
|
|
8716
8902
|
}
|
|
8717
8903
|
function quoted(argument) {
|
|
8718
8904
|
return `'${argument.replaceAll("'", `'\\''`)}'`;
|
|
@@ -8785,14 +8971,14 @@ function errorOf(answer3) {
|
|
|
8785
8971
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
8786
8972
|
function real(file) {
|
|
8787
8973
|
try {
|
|
8788
|
-
return
|
|
8974
|
+
return realpathSync2(file);
|
|
8789
8975
|
} catch {
|
|
8790
8976
|
return file;
|
|
8791
8977
|
}
|
|
8792
8978
|
}
|
|
8793
8979
|
function runnable(file) {
|
|
8794
8980
|
try {
|
|
8795
|
-
const stat =
|
|
8981
|
+
const stat = statSync2(file);
|
|
8796
8982
|
return stat.isFile() && (stat.mode & 73) !== 0;
|
|
8797
8983
|
} catch {
|
|
8798
8984
|
return false;
|
|
@@ -8801,12 +8987,12 @@ function runnable(file) {
|
|
|
8801
8987
|
function installedCommand() {
|
|
8802
8988
|
const self = real(process.argv[1] ?? "");
|
|
8803
8989
|
const name = process.platform === "win32" ? "agental.cmd" : "agental";
|
|
8804
|
-
for (const dir of (process.env["PATH"] ?? "").split(
|
|
8805
|
-
if (!dir || dir.includes(`${
|
|
8990
|
+
for (const dir of (process.env["PATH"] ?? "").split(path4.delimiter)) {
|
|
8991
|
+
if (!dir || dir.includes(`${path4.sep}_npx${path4.sep}`)) {
|
|
8806
8992
|
continue;
|
|
8807
8993
|
}
|
|
8808
|
-
const file =
|
|
8809
|
-
if (runnable(file) && !real(file).includes(`${
|
|
8994
|
+
const file = path4.join(dir, name);
|
|
8995
|
+
if (runnable(file) && !real(file).includes(`${path4.sep}_npx${path4.sep}`)) {
|
|
8810
8996
|
return { file, self: real(file) === self };
|
|
8811
8997
|
}
|
|
8812
8998
|
}
|
|
@@ -8814,7 +9000,7 @@ function installedCommand() {
|
|
|
8814
9000
|
}
|
|
8815
9001
|
function versionOf(file) {
|
|
8816
9002
|
return new Promise((resolve) => {
|
|
8817
|
-
|
|
9003
|
+
execFile2(file, ["--version"], { encoding: "utf8", timeout: 1e4 }, (error, stdout) => {
|
|
8818
9004
|
resolve(error ? null : /^agental (\S+)$/m.exec(String(stdout).trim())?.[1] ?? null);
|
|
8819
9005
|
});
|
|
8820
9006
|
});
|
|
@@ -8831,7 +9017,7 @@ function older(version, than) {
|
|
|
8831
9017
|
}
|
|
8832
9018
|
function npm(args) {
|
|
8833
9019
|
return new Promise((resolve) => {
|
|
8834
|
-
|
|
9020
|
+
execFile2(process.platform === "win32" ? "npm.cmd" : "npm", args, { encoding: "utf8", timeout: 5 * 6e4, shell: process.platform === "win32" }, (error, stdout, stderr) => {
|
|
8835
9021
|
resolve({ ok: !error, out: `${stdout}${stderr}`.trim() });
|
|
8836
9022
|
});
|
|
8837
9023
|
});
|
|
@@ -8864,8 +9050,8 @@ async function ensureCommand(options) {
|
|
|
8864
9050
|
return `${bold("!")} agental was not installed${permission ? ", as npm's global folder needs more rights than you have" : ""}. Run ${bold(permission ? `sudo ${INSTALL}` : INSTALL)} to install it.`;
|
|
8865
9051
|
}
|
|
8866
9052
|
const prefix = (await npm(["prefix", "-g"])).out.split("\n").pop()?.trim() ?? "";
|
|
8867
|
-
const bin = process.platform === "win32" ? prefix :
|
|
8868
|
-
const onPath = (process.env["PATH"] ?? "").split(
|
|
9053
|
+
const bin = process.platform === "win32" ? prefix : path4.join(prefix, "bin");
|
|
9054
|
+
const onPath = (process.env["PATH"] ?? "").split(path4.delimiter).some((dir) => real(dir) === real(bin));
|
|
8869
9055
|
return done(`agental ${CLI_VERSION} ${found ? "updated" : "installed"} ${dim("\xB7 try")} agental list`) + (onPath ? "" : `
|
|
8870
9056
|
${dim("npm put it in")} ${bin}${dim(", which is not on your PATH: add it, as")} export PATH="${bin}:$PATH"`);
|
|
8871
9057
|
}
|
|
@@ -8893,13 +9079,13 @@ var AGENT_HOMES = [
|
|
|
8893
9079
|
];
|
|
8894
9080
|
var AGENT_CONFIGS = ["opencode", "amp", "goose"];
|
|
8895
9081
|
function codingAgentHere(env = process.env) {
|
|
8896
|
-
const home = env["HOME"] ||
|
|
8897
|
-
const config = env["XDG_CONFIG_HOME"]?.trim() ||
|
|
9082
|
+
const home = env["HOME"] || os5.homedir();
|
|
9083
|
+
const config = env["XDG_CONFIG_HOME"]?.trim() || path4.join(home, ".config");
|
|
8898
9084
|
return [
|
|
8899
|
-
...AGENT_HOMES.map((folder) =>
|
|
8900
|
-
...AGENT_CONFIGS.map((folder) =>
|
|
9085
|
+
...AGENT_HOMES.map((folder) => path4.join(home, folder)),
|
|
9086
|
+
...AGENT_CONFIGS.map((folder) => path4.join(config, folder)),
|
|
8901
9087
|
...[env["CLAUDE_CONFIG_DIR"], env["CODEX_HOME"]].filter((folder) => Boolean(folder?.trim()))
|
|
8902
|
-
].some((folder) =>
|
|
9088
|
+
].some((folder) => existsSync3(folder));
|
|
8903
9089
|
}
|
|
8904
9090
|
async function ensureSkills(options, site2) {
|
|
8905
9091
|
if (!options.installSkills) {
|
|
@@ -8910,7 +9096,7 @@ async function ensureSkills(options, site2) {
|
|
|
8910
9096
|
}
|
|
8911
9097
|
const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => !/^npm_(config_package|config_call|command|execpath|lifecycle_)/i.test(name)));
|
|
8912
9098
|
const ran = await new Promise((resolve) => {
|
|
8913
|
-
|
|
9099
|
+
execFile2(
|
|
8914
9100
|
process.platform === "win32" ? "npx.cmd" : "npx",
|
|
8915
9101
|
["--yes", `--package=${SKILLS_CLI}`, "--", "skills", "add", site2, "-g", "-y"],
|
|
8916
9102
|
{ encoding: "utf8", timeout: 5 * 6e4, shell: process.platform === "win32", env },
|
|
@@ -9044,14 +9230,14 @@ async function hourly(base, key2, size2) {
|
|
|
9044
9230
|
return typeof micros === "number" ? micros : null;
|
|
9045
9231
|
}
|
|
9046
9232
|
var perHour = (micros) => `$${(micros / 1e6).toFixed(micros < 1e5 ? 4 : 3)} an hour`;
|
|
9047
|
-
function completionStep(shell2 = process.env["SHELL"], home =
|
|
9048
|
-
const name =
|
|
9233
|
+
function completionStep(shell2 = process.env["SHELL"], home = os5.homedir()) {
|
|
9234
|
+
const name = path4.basename(shell2 ?? "");
|
|
9049
9235
|
const config = name === "zsh" ? ".zshrc" : name === "bash" ? ".bashrc" : name === "fish" ? ".config/fish/config.fish" : null;
|
|
9050
9236
|
if (config === null) {
|
|
9051
9237
|
return null;
|
|
9052
9238
|
}
|
|
9053
9239
|
try {
|
|
9054
|
-
if (
|
|
9240
|
+
if (readFileSync4(path4.join(home, config), "utf8").includes("agental completion")) {
|
|
9055
9241
|
return null;
|
|
9056
9242
|
}
|
|
9057
9243
|
} catch {
|
|
@@ -9092,7 +9278,7 @@ async function onboard(base, options) {
|
|
|
9092
9278
|
term.say(` ${dim("signed in as")} ${bold(describe2(account3))} ${dim(`\xB7 with the key ${credentials.keyName ?? "pasted in"} \xB7 not you?`)} agental logout`);
|
|
9093
9279
|
}
|
|
9094
9280
|
const site2 = new URL(base).origin;
|
|
9095
|
-
const installs = (async () => [await ensureCommand(options), await ensureSkills(options, site2)])();
|
|
9281
|
+
const installs = (async () => [await ensureCommand(options), await ensureSkills(options, site2), ...options.installConnector ? await ensureConnector(site2) : []])();
|
|
9096
9282
|
const report = async () => {
|
|
9097
9283
|
for (const line of await installs) {
|
|
9098
9284
|
if (line) {
|
|
@@ -9171,9 +9357,9 @@ async function onboard(base, options) {
|
|
|
9171
9357
|
|
|
9172
9358
|
// ../src/cli-completion.ts
|
|
9173
9359
|
import { createHash as createHash2 } from "node:crypto";
|
|
9174
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
9175
|
-
import
|
|
9176
|
-
import
|
|
9360
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
9361
|
+
import os6 from "node:os";
|
|
9362
|
+
import path5 from "node:path";
|
|
9177
9363
|
|
|
9178
9364
|
// ../src/cli-help.ts
|
|
9179
9365
|
function isTerminal(stream) {
|
|
@@ -9202,6 +9388,9 @@ var COMMANDS = [
|
|
|
9202
9388
|
[" --ttl <time>", "stop it after this long, as 30m or 2h"],
|
|
9203
9389
|
[" --allow <addresses>", "reach only these addresses, comma-separated"],
|
|
9204
9390
|
[" --egress <egress>", "box, or residential:<country>[:sticky|rotating]"],
|
|
9391
|
+
[" --spot", "half the price, in spare room taken back when needed"],
|
|
9392
|
+
[" --on-reclaim <what>", "with --spot: stop (default), delete or upgrade"],
|
|
9393
|
+
[" --warn-at <chance>", "with --spot: warn at this chance, as 0.5 or 50%"],
|
|
9205
9394
|
[" --ssh-key <key or file>", "let this key in over SSH (may be given again)"],
|
|
9206
9395
|
[" --tag <tag>", "label it (may be given again)"],
|
|
9207
9396
|
[" --meta <key>=<value>", "attach data to it (may be given again)"],
|
|
@@ -9324,6 +9513,11 @@ var COMMANDS = [
|
|
|
9324
9513
|
{ name: "regions", summary: "List where sandboxes run, and how much room each has now." },
|
|
9325
9514
|
{ name: "network", summary: "Say what a sandbox may reach outside itself.", examples: ["agental network sbx_2a9a47e50daec64a --allow github.com,registry.npmjs.org", "agental network sbx_2a9a47e50daec64a --none"] },
|
|
9326
9515
|
{ name: "egress", summary: "Say where a sandbox's web traffic leaves from, or read your residential egress.", examples: ["agental egress sbx_2a9a47e50daec64a residential de"] },
|
|
9516
|
+
{
|
|
9517
|
+
name: "spot",
|
|
9518
|
+
summary: "Read a spot sandbox's chance of being stopped, change what a reclaim does to it, or turn off spot.",
|
|
9519
|
+
examples: ["agental spot sbx_2a9a47e50daec64a", "agental spot sbx_2a9a47e50daec64a --on-reclaim upgrade --warn-at 30%", "agental spot sbx_2a9a47e50daec64a off"]
|
|
9520
|
+
},
|
|
9327
9521
|
{ name: "templates", summary: "List your templates: what new sandboxes start from." },
|
|
9328
9522
|
{
|
|
9329
9523
|
name: "template",
|
|
@@ -9519,7 +9713,7 @@ var MAP = [
|
|
|
9519
9713
|
[
|
|
9520
9714
|
["start, stop, delete", "one sandbox, or every one --where finds"],
|
|
9521
9715
|
["recover, auto-stop", "get a stuck one going, say when one stops"],
|
|
9522
|
-
["resize", "a larger size
|
|
9716
|
+
["resize, spot", "a larger size; a spot one's chance of being stopped"],
|
|
9523
9717
|
["job", "run a command on a timer"],
|
|
9524
9718
|
["secret", "values and files kept out of the sandbox"],
|
|
9525
9719
|
["site", "share a port on a public link"],
|
|
@@ -9558,13 +9752,13 @@ var MAP = [
|
|
|
9558
9752
|
];
|
|
9559
9753
|
var DOCS = "https://agental.io/docs/cli";
|
|
9560
9754
|
function shortHelp() {
|
|
9561
|
-
const width = Math.max(...MAP.flatMap(([, rows]) => rows.map(([
|
|
9755
|
+
const width = Math.max(...MAP.flatMap(([, rows]) => rows.map(([names2]) => names2.length))) + 3;
|
|
9562
9756
|
const lines = [`${strong("agental")} \xB7 Linux sandboxes for your agents`, "", `${strong("Usage")} agental <command> [flags]`];
|
|
9563
9757
|
for (const [group, rows] of MAP) {
|
|
9564
9758
|
lines.push("", strong(group));
|
|
9565
|
-
for (const [
|
|
9566
|
-
const painted =
|
|
9567
|
-
lines.push(` ${painted}${" ".repeat(width -
|
|
9759
|
+
for (const [names2, what] of rows) {
|
|
9760
|
+
const painted = names2.split(", ").map((name) => command(name)).join(", ");
|
|
9761
|
+
lines.push(` ${painted}${" ".repeat(width - names2.length)}${what}`);
|
|
9568
9762
|
}
|
|
9569
9763
|
}
|
|
9570
9764
|
lines.push("", faint("Each thing takes list, show, add or create, update and delete, as agental key list."));
|
|
@@ -9969,10 +10163,10 @@ async function jobs(api2) {
|
|
|
9969
10163
|
}
|
|
9970
10164
|
var KEPT_MS = 3e4;
|
|
9971
10165
|
async function cached(what, as, ask10) {
|
|
9972
|
-
const folder =
|
|
9973
|
-
const file =
|
|
10166
|
+
const folder = path5.join(process.env["XDG_CACHE_HOME"] || path5.join(os6.homedir(), ".cache"), "agental");
|
|
10167
|
+
const file = path5.join(folder, `complete-${what}-${createHash2("sha256").update(as).digest("hex").slice(0, 16)}.json`);
|
|
9974
10168
|
try {
|
|
9975
|
-
const kept2 = JSON.parse(
|
|
10169
|
+
const kept2 = JSON.parse(readFileSync5(file, "utf8"));
|
|
9976
10170
|
if (Date.now() - kept2.at < KEPT_MS) {
|
|
9977
10171
|
return kept2.body;
|
|
9978
10172
|
}
|
|
@@ -9986,7 +10180,7 @@ async function cached(what, as, ask10) {
|
|
|
9986
10180
|
}
|
|
9987
10181
|
try {
|
|
9988
10182
|
mkdirSync3(folder, { recursive: true, mode: 448 });
|
|
9989
|
-
|
|
10183
|
+
writeFileSync4(file, JSON.stringify({ at: Date.now(), body }), { mode: 384 });
|
|
9990
10184
|
} catch {
|
|
9991
10185
|
}
|
|
9992
10186
|
return body;
|
|
@@ -10293,7 +10487,7 @@ async function invite(client, positionals, options) {
|
|
|
10293
10487
|
|
|
10294
10488
|
// ../src/cli-jobs.ts
|
|
10295
10489
|
var import_yaml = __toESM(require_dist(), 1);
|
|
10296
|
-
import { readFileSync as
|
|
10490
|
+
import { readFileSync as readFileSync6 } from "node:fs";
|
|
10297
10491
|
var USAGE4 = "job takes add, list, get, update, delete, pause, resume, run, again, runs, logs, keep, apply, trigger or calls. agental job --help shows each.";
|
|
10298
10492
|
var OVERLAPS = ["skip", "replace", "parallel"];
|
|
10299
10493
|
var ALERTS = ["email", "webhook", "both", "none"];
|
|
@@ -10437,40 +10631,40 @@ function nextOf(job2, terse) {
|
|
|
10437
10631
|
}
|
|
10438
10632
|
return job2.every === null && job2.cron === null ? "when asked" : "never";
|
|
10439
10633
|
}
|
|
10440
|
-
function lastOf(
|
|
10441
|
-
if (
|
|
10634
|
+
function lastOf(run3) {
|
|
10635
|
+
if (run3 === null) {
|
|
10442
10636
|
return "none yet";
|
|
10443
10637
|
}
|
|
10444
|
-
const code =
|
|
10445
|
-
return `${
|
|
10638
|
+
const code = run3.exitCode === null ? "" : ` (exit ${run3.exitCode})`;
|
|
10639
|
+
return `${run3.outcome}${code} ${past(run3.dueAt)}`;
|
|
10446
10640
|
}
|
|
10447
|
-
function tookOf(
|
|
10448
|
-
if (
|
|
10641
|
+
function tookOf(run3) {
|
|
10642
|
+
if (run3.startedAt === null || run3.finishedAt === null) {
|
|
10449
10643
|
return "-";
|
|
10450
10644
|
}
|
|
10451
|
-
const seconds2 = Math.max(0, Math.round((Date.parse(
|
|
10645
|
+
const seconds2 = Math.max(0, Math.round((Date.parse(run3.finishedAt) - Date.parse(run3.startedAt)) / 1e3));
|
|
10452
10646
|
return seconds2 < 60 ? `${seconds2}s` : seconds2 < 3600 ? `${Math.floor(seconds2 / 60)}m${String(seconds2 % 60).padStart(2, "0")}s` : `${Math.floor(seconds2 / 3600)}h${String(Math.floor(seconds2 % 3600 / 60)).padStart(2, "0")}m`;
|
|
10453
10647
|
}
|
|
10454
|
-
function sandboxDoneOf(
|
|
10455
|
-
if (
|
|
10456
|
-
if (
|
|
10648
|
+
function sandboxDoneOf(run3) {
|
|
10649
|
+
if (run3.fresh === true) {
|
|
10650
|
+
if (run3.sandboxKept === true) {
|
|
10457
10651
|
return "fresh, kept by you";
|
|
10458
10652
|
}
|
|
10459
|
-
if (
|
|
10653
|
+
if (run3.deletedSandbox) {
|
|
10460
10654
|
return "fresh, deleted";
|
|
10461
10655
|
}
|
|
10462
|
-
if (
|
|
10463
|
-
return `fresh, kept until ${soon(
|
|
10656
|
+
if (run3.keepUntil) {
|
|
10657
|
+
return `fresh, kept until ${soon(run3.keepUntil)}`;
|
|
10464
10658
|
}
|
|
10465
|
-
return
|
|
10659
|
+
return run3.sandboxId === null ? "fresh, not made" : "fresh";
|
|
10466
10660
|
}
|
|
10467
|
-
if (
|
|
10468
|
-
return
|
|
10661
|
+
if (run3.deletedSandbox) {
|
|
10662
|
+
return run3.startedSandbox ? "started, deleted" : "deleted";
|
|
10469
10663
|
}
|
|
10470
|
-
if (!
|
|
10664
|
+
if (!run3.startedSandbox) {
|
|
10471
10665
|
return "-";
|
|
10472
10666
|
}
|
|
10473
|
-
return
|
|
10667
|
+
return run3.stoppedSandbox === null ? "started, left running" : `started, stopped (${run3.stoppedSandbox})`;
|
|
10474
10668
|
}
|
|
10475
10669
|
var BY = { timer: "timer", run_now: "by hand", api: "api", http: "http", event: "event" };
|
|
10476
10670
|
function commandLine(words2) {
|
|
@@ -10721,33 +10915,33 @@ async function listJobs(client, options) {
|
|
|
10721
10915
|
}
|
|
10722
10916
|
table2([["NAME", "SANDBOX", "WHEN", "NEXT", "LAST RUN"], ...jobs2.map((job2) => [job2.name, sandboxOf(job2), whenOf(job2), nextOf(job2, true), lastOf(job2.lastRun)])], 2);
|
|
10723
10917
|
}
|
|
10724
|
-
function writeOutput(
|
|
10725
|
-
if (
|
|
10726
|
-
process.stdout.write(
|
|
10918
|
+
function writeOutput(run3) {
|
|
10919
|
+
if (run3.stdout) {
|
|
10920
|
+
process.stdout.write(run3.stdout);
|
|
10727
10921
|
}
|
|
10728
|
-
if (
|
|
10729
|
-
process.stderr.write(
|
|
10922
|
+
if (run3.stderr) {
|
|
10923
|
+
process.stderr.write(run3.stderr);
|
|
10730
10924
|
}
|
|
10731
|
-
if ((
|
|
10732
|
-
const said =
|
|
10733
|
-
process.stderr.write(`Run ${
|
|
10925
|
+
if ((run3.stdout ?? null) === null && (run3.stderr ?? null) === null) {
|
|
10926
|
+
const said = run3.outputHidden === true ? "Its output needs a key that may run commands in its sandbox (exec)." : run3.commandId === null ? "It ran no command." : "Its output is no longer kept.";
|
|
10927
|
+
process.stderr.write(`Run ${run3.id} ${run3.outcome}${why(run3)}. ${said}
|
|
10734
10928
|
`);
|
|
10735
10929
|
}
|
|
10736
10930
|
}
|
|
10737
|
-
function writeNotes(
|
|
10738
|
-
const cut = [
|
|
10931
|
+
function writeNotes(run3, name) {
|
|
10932
|
+
const cut = [run3.stdoutCut === true ? "stdout" : null, run3.stderrCut === true ? "stderr" : null].filter((each) => each !== null);
|
|
10739
10933
|
if (cut.length > 0) {
|
|
10740
10934
|
process.stderr.write(faint(`Only the end of its ${cut.join(" and ")} was kept.
|
|
10741
10935
|
`, process.stderr));
|
|
10742
10936
|
}
|
|
10743
|
-
if (
|
|
10744
|
-
process.stderr.write(`Its sandbox ${
|
|
10937
|
+
if (run3.fresh === true && run3.keepUntil && run3.sandboxKept !== true && run3.sandboxId !== null) {
|
|
10938
|
+
process.stderr.write(`Its sandbox ${run3.sandboxId} is kept, stopped, until ${at2(run3.keepUntil)}, then deleted. agental job keep ${name} ${run3.id} keeps it for good.
|
|
10745
10939
|
`);
|
|
10746
10940
|
}
|
|
10747
10941
|
}
|
|
10748
|
-
var why = (
|
|
10749
|
-
function exitOf(
|
|
10750
|
-
return
|
|
10942
|
+
var why = (run3) => run3.reason ? `: ${run3.reason.replace(/\.$/, "")}` : "";
|
|
10943
|
+
function exitOf(run3) {
|
|
10944
|
+
return run3.exitCode ?? (run3.outcome === "succeeded" ? 0 : 1);
|
|
10751
10945
|
}
|
|
10752
10946
|
async function job(client, positionals, command2, options) {
|
|
10753
10947
|
const [what, name, ...rest] = positionals;
|
|
@@ -10818,10 +11012,10 @@ async function job(client, positionals, command2, options) {
|
|
|
10818
11012
|
if (name === void 0) {
|
|
10819
11013
|
throw new Error(`job ${what} needs the job, by its name or id: agental job ${what} <job>`);
|
|
10820
11014
|
}
|
|
10821
|
-
const
|
|
11015
|
+
const path6 = jobPath(name);
|
|
10822
11016
|
switch (what) {
|
|
10823
11017
|
case "get":
|
|
10824
|
-
print3(await ask6(client, "GET",
|
|
11018
|
+
print3(await ask6(client, "GET", path6), options.json);
|
|
10825
11019
|
return;
|
|
10826
11020
|
case "update": {
|
|
10827
11021
|
const changes = { ...fieldsOf(options), ...options.name === void 0 ? {} : { name: options.name }, ...command2 !== null && command2.length > 0 ? { command: commandLine(command2) } : {} };
|
|
@@ -10830,43 +11024,43 @@ async function job(client, positionals, command2, options) {
|
|
|
10830
11024
|
"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 --."
|
|
10831
11025
|
);
|
|
10832
11026
|
}
|
|
10833
|
-
print3(await ask6(client, "PATCH",
|
|
11027
|
+
print3(await ask6(client, "PATCH", path6, changes), options.json);
|
|
10834
11028
|
return;
|
|
10835
11029
|
}
|
|
10836
11030
|
case "delete":
|
|
10837
|
-
await ask6(client, "DELETE",
|
|
11031
|
+
await ask6(client, "DELETE", path6);
|
|
10838
11032
|
process.stdout.write(`Deleted job ${name}, with its runs.
|
|
10839
11033
|
`);
|
|
10840
11034
|
return;
|
|
10841
11035
|
case "pause":
|
|
10842
11036
|
case "resume":
|
|
10843
|
-
print3(await ask6(client, "PATCH",
|
|
11037
|
+
print3(await ask6(client, "PATCH", path6, { enabled: what === "resume" }), options.json);
|
|
10844
11038
|
return;
|
|
10845
11039
|
case "runs": {
|
|
10846
11040
|
const limit = options.limit === void 0 ? "" : `?limit=${encodeURIComponent(options.limit)}`;
|
|
10847
|
-
const retries = options.json ? 0 : (await ask6(client, "GET",
|
|
10848
|
-
const runs = (await ask6(client, "GET", `${
|
|
11041
|
+
const retries = options.json ? 0 : (await ask6(client, "GET", path6))?.retries ?? 0;
|
|
11042
|
+
const runs = (await ask6(client, "GET", `${path6}/runs${limit}`))?.runs ?? [];
|
|
10849
11043
|
if (options.json) {
|
|
10850
11044
|
json(runs);
|
|
10851
11045
|
} else if (runs.length === 0) {
|
|
10852
11046
|
process.stdout.write(`No runs yet. agental job run ${name} runs it now.
|
|
10853
11047
|
`);
|
|
10854
11048
|
} else {
|
|
10855
|
-
const tries = retries > 0 || runs.some((
|
|
10856
|
-
const outcomeOf = (
|
|
10857
|
-
const tryOf = (
|
|
11049
|
+
const tries = retries > 0 || runs.some((run3) => (run3.attempt ?? 1) > 1);
|
|
11050
|
+
const outcomeOf = (run3) => tries && run3.failedForGood === true ? `${run3.outcome}, for good` : run3.outcome;
|
|
11051
|
+
const tryOf = (run3) => `${run3.attempt ?? 1} of ${Math.max(retries + 1, run3.attempt ?? 1)}`;
|
|
10858
11052
|
table2([
|
|
10859
11053
|
["RUN", "DUE", ...tries ? ["TRY"] : [], "OUTCOME", "EXIT", "TOOK", "SANDBOX", "BY", "WHY"],
|
|
10860
|
-
...runs.map((
|
|
10861
|
-
|
|
10862
|
-
past(
|
|
10863
|
-
...tries ? [tryOf(
|
|
10864
|
-
outcomeOf(
|
|
10865
|
-
|
|
10866
|
-
tookOf(
|
|
10867
|
-
sandboxDoneOf(
|
|
10868
|
-
BY[
|
|
10869
|
-
|
|
11054
|
+
...runs.map((run3) => [
|
|
11055
|
+
run3.id,
|
|
11056
|
+
past(run3.dueAt),
|
|
11057
|
+
...tries ? [tryOf(run3)] : [],
|
|
11058
|
+
outcomeOf(run3),
|
|
11059
|
+
run3.exitCode === null ? "-" : String(run3.exitCode),
|
|
11060
|
+
tookOf(run3),
|
|
11061
|
+
sandboxDoneOf(run3),
|
|
11062
|
+
BY[run3.startedBy] ?? run3.startedBy,
|
|
11063
|
+
run3.reason ?? ""
|
|
10870
11064
|
])
|
|
10871
11065
|
]);
|
|
10872
11066
|
}
|
|
@@ -10875,23 +11069,23 @@ async function job(client, positionals, command2, options) {
|
|
|
10875
11069
|
case "logs": {
|
|
10876
11070
|
let runId = rest[0];
|
|
10877
11071
|
if (runId === void 0) {
|
|
10878
|
-
const latest = (await ask6(client, "GET", `${
|
|
11072
|
+
const latest = (await ask6(client, "GET", `${path6}/runs?limit=1`))?.runs?.[0];
|
|
10879
11073
|
if (latest === void 0) {
|
|
10880
11074
|
throw new Error(`Job ${name} has not run yet. agental job run ${name} runs it now.`);
|
|
10881
11075
|
}
|
|
10882
11076
|
runId = latest.id;
|
|
10883
11077
|
}
|
|
10884
|
-
const
|
|
11078
|
+
const run3 = await ask6(client, "GET", `${path6}/runs/${encodeURIComponent(runId)}`);
|
|
10885
11079
|
if (options.json) {
|
|
10886
|
-
json(
|
|
11080
|
+
json(run3);
|
|
10887
11081
|
return;
|
|
10888
11082
|
}
|
|
10889
|
-
writeOutput(
|
|
10890
|
-
if (
|
|
10891
|
-
process.stderr.write(faint(`Run ${
|
|
11083
|
+
writeOutput(run3);
|
|
11084
|
+
if (run3.outcome === "running") {
|
|
11085
|
+
process.stderr.write(faint(`Run ${run3.id} is still running: this is its output so far.
|
|
10892
11086
|
`, process.stderr));
|
|
10893
11087
|
}
|
|
10894
|
-
writeNotes(
|
|
11088
|
+
writeNotes(run3, name);
|
|
10895
11089
|
return;
|
|
10896
11090
|
}
|
|
10897
11091
|
case "keep": {
|
|
@@ -10899,11 +11093,11 @@ async function job(client, positionals, command2, options) {
|
|
|
10899
11093
|
if (runId === void 0) {
|
|
10900
11094
|
throw new Error(`job keep needs the run whose fresh sandbox to keep: agental job keep ${name} <run-id>, as job runs ${name} lists them.`);
|
|
10901
11095
|
}
|
|
10902
|
-
const
|
|
11096
|
+
const run3 = await ask6(client, "POST", `${path6}/runs/${encodeURIComponent(runId)}/keep-sandbox`);
|
|
10903
11097
|
if (options.json) {
|
|
10904
|
-
json(
|
|
11098
|
+
json(run3);
|
|
10905
11099
|
} else {
|
|
10906
|
-
process.stdout.write(`Kept ${
|
|
11100
|
+
process.stdout.write(`Kept ${run3.sandboxId ?? "the sandbox"} of run ${run3.id}: it is an ordinary sandbox now, out of the job, and is deleted only by you.
|
|
10907
11101
|
`);
|
|
10908
11102
|
}
|
|
10909
11103
|
return;
|
|
@@ -10911,7 +11105,7 @@ async function job(client, positionals, command2, options) {
|
|
|
10911
11105
|
case "run": {
|
|
10912
11106
|
const inputs = runInputsOf(options);
|
|
10913
11107
|
const query = options.wait ? `?wait=${waitSecondsOf(options)}` : "";
|
|
10914
|
-
await follow(client, name,
|
|
11108
|
+
await follow(client, name, path6, await answer(client, "POST", `${path6}/run${query}`, inputs === void 0 ? void 0 : { inputs }), options);
|
|
10915
11109
|
return;
|
|
10916
11110
|
}
|
|
10917
11111
|
case "again": {
|
|
@@ -10920,47 +11114,47 @@ async function job(client, positionals, command2, options) {
|
|
|
10920
11114
|
throw new Error(`job again needs the run whose inputs to run it with again: agental job again ${name} <run-id>, as job runs ${name} lists them.`);
|
|
10921
11115
|
}
|
|
10922
11116
|
const query = options.wait ? `?wait=${waitSecondsOf(options)}` : "";
|
|
10923
|
-
await follow(client, name,
|
|
11117
|
+
await follow(client, name, path6, await answer(client, "POST", `${path6}/runs/${encodeURIComponent(runId)}/again${query}`), options);
|
|
10924
11118
|
return;
|
|
10925
11119
|
}
|
|
10926
11120
|
}
|
|
10927
11121
|
}
|
|
10928
|
-
async function follow(client, name,
|
|
10929
|
-
let
|
|
11122
|
+
async function follow(client, name, path6, made, options) {
|
|
11123
|
+
let run3 = made.body;
|
|
10930
11124
|
if (!options.wait) {
|
|
10931
11125
|
if (options.json) {
|
|
10932
|
-
json(
|
|
11126
|
+
json(run3);
|
|
10933
11127
|
} else {
|
|
10934
|
-
process.stdout.write(
|
|
10935
|
-
` : `Run ${
|
|
11128
|
+
process.stdout.write(run3.outcome === "running" ? `Run ${run3.id} started. agental job logs ${name} ${run3.id} prints its output.
|
|
11129
|
+
` : `Run ${run3.id} ${run3.outcome}${run3.reason ? `: ${run3.reason}` : ""}
|
|
10936
11130
|
`);
|
|
10937
11131
|
}
|
|
10938
11132
|
return;
|
|
10939
11133
|
}
|
|
10940
11134
|
if (made.status !== 200) {
|
|
10941
|
-
if (!options.json &&
|
|
10942
|
-
process.stderr.write(faint(`Run ${
|
|
11135
|
+
if (!options.json && run3.outcome === "running") {
|
|
11136
|
+
process.stderr.write(faint(`Run ${run3.id} is still running; waiting for it to end.
|
|
10943
11137
|
`, process.stderr));
|
|
10944
11138
|
}
|
|
10945
11139
|
for (; ; ) {
|
|
10946
|
-
|
|
10947
|
-
if (
|
|
11140
|
+
run3 = await ask6(client, "GET", `${path6}/runs/${encodeURIComponent(run3.id)}`);
|
|
11141
|
+
if (run3.outcome !== "running") {
|
|
10948
11142
|
break;
|
|
10949
11143
|
}
|
|
10950
11144
|
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
10951
11145
|
}
|
|
10952
11146
|
}
|
|
10953
11147
|
if (options.json) {
|
|
10954
|
-
json(
|
|
11148
|
+
json(run3);
|
|
10955
11149
|
} else {
|
|
10956
|
-
writeOutput(
|
|
10957
|
-
if (
|
|
10958
|
-
process.stderr.write(`Run ${
|
|
11150
|
+
writeOutput(run3);
|
|
11151
|
+
if (run3.outcome !== "succeeded" && (run3.stdout != null || run3.stderr != null)) {
|
|
11152
|
+
process.stderr.write(`Run ${run3.id} ${run3.outcome}${run3.exitCode === null ? "" : ` (exit ${run3.exitCode})`}${why(run3)}.
|
|
10959
11153
|
`);
|
|
10960
11154
|
}
|
|
10961
|
-
writeNotes(
|
|
11155
|
+
writeNotes(run3, name);
|
|
10962
11156
|
}
|
|
10963
|
-
process.exitCode = exitOf(
|
|
11157
|
+
process.exitCode = exitOf(run3);
|
|
10964
11158
|
}
|
|
10965
11159
|
var SIGNATURES = ["bearer", "github", "stripe", "hmac-sha256"];
|
|
10966
11160
|
var RESPONDS = ["accepted", "wait"];
|
|
@@ -11048,8 +11242,8 @@ async function trigger(client, verb, rest, options) {
|
|
|
11048
11242
|
if ((options.respond !== void 0 || options.rate !== void 0) && verb !== "add" && verb !== "update") {
|
|
11049
11243
|
throw new Error("--respond and --rate go with job trigger add or update.");
|
|
11050
11244
|
}
|
|
11051
|
-
const
|
|
11052
|
-
const one = (id) => `${
|
|
11245
|
+
const path6 = `${jobPath(name)}/triggers`;
|
|
11246
|
+
const one = (id) => `${path6}/${encodeURIComponent(id)}`;
|
|
11053
11247
|
switch (verb) {
|
|
11054
11248
|
case "add": {
|
|
11055
11249
|
if (options.signature !== void 0 && !SIGNATURES.includes(options.signature)) {
|
|
@@ -11063,12 +11257,12 @@ async function trigger(client, verb, rest, options) {
|
|
|
11063
11257
|
throw new Error("--header names the header an hmac-sha256 signature is sent in, and goes with --signature hmac-sha256: GitHub's and Stripe's have their own.");
|
|
11064
11258
|
}
|
|
11065
11259
|
const body = { ...options.signature === void 0 ? {} : { signature: options.signature }, ...header === void 0 ? {} : { header }, ...triggerFieldsOf(options) };
|
|
11066
|
-
printSecret(await ask6(client, "POST",
|
|
11260
|
+
printSecret(await ask6(client, "POST", path6, body), options);
|
|
11067
11261
|
return;
|
|
11068
11262
|
}
|
|
11069
11263
|
case "list":
|
|
11070
11264
|
case "url": {
|
|
11071
|
-
const triggers = (await ask6(client, "GET",
|
|
11265
|
+
const triggers = (await ask6(client, "GET", path6))?.triggers ?? [];
|
|
11072
11266
|
const chosen = triggerId === void 0 ? triggers : triggers.filter((each) => each.id === triggerId);
|
|
11073
11267
|
if (triggerId !== void 0 && chosen.length === 0) {
|
|
11074
11268
|
throw new Error(`Job ${name} has no trigger ${triggerId}. agental job trigger list ${name} lists its triggers.`);
|
|
@@ -11178,17 +11372,17 @@ function byEvents(jobs2) {
|
|
|
11178
11372
|
const named = new Map(jobs2.map((each) => [each.name, each]));
|
|
11179
11373
|
const done2 = /* @__PURE__ */ new Set();
|
|
11180
11374
|
const ordered2 = [];
|
|
11181
|
-
const visit = (each,
|
|
11182
|
-
if (done2.has(each.name) ||
|
|
11375
|
+
const visit = (each, path6) => {
|
|
11376
|
+
if (done2.has(each.name) || path6.has(each.name)) {
|
|
11183
11377
|
return;
|
|
11184
11378
|
}
|
|
11185
|
-
|
|
11379
|
+
path6.add(each.name);
|
|
11186
11380
|
const events = Array.isArray(each.body["events"]) ? each.body["events"] : [];
|
|
11187
11381
|
for (const event of events) {
|
|
11188
11382
|
const job2 = event !== null && typeof event === "object" ? event["job"] : void 0;
|
|
11189
11383
|
const before = typeof job2 === "string" ? named.get(job2) : void 0;
|
|
11190
11384
|
if (before !== void 0) {
|
|
11191
|
-
visit(before,
|
|
11385
|
+
visit(before, path6);
|
|
11192
11386
|
}
|
|
11193
11387
|
}
|
|
11194
11388
|
done2.add(each.name);
|
|
@@ -11202,7 +11396,7 @@ function byEvents(jobs2) {
|
|
|
11202
11396
|
function fileJobsOf(file) {
|
|
11203
11397
|
let text;
|
|
11204
11398
|
try {
|
|
11205
|
-
text =
|
|
11399
|
+
text = readFileSync6(file === "-" ? 0 : file, "utf8");
|
|
11206
11400
|
} catch (error) {
|
|
11207
11401
|
throw new Error(`Could not read ${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
11208
11402
|
}
|
|
@@ -11217,8 +11411,8 @@ function fileJobsOf(file) {
|
|
|
11217
11411
|
throw new Error(`${file} has no jobs: list. It is a map whose jobs: lists each job, with its name, command, and sandbox or template.`);
|
|
11218
11412
|
}
|
|
11219
11413
|
const jobs2 = listed.map((item, index) => fileJobOf(item, index));
|
|
11220
|
-
const
|
|
11221
|
-
const twice =
|
|
11414
|
+
const names2 = jobs2.map((each) => each.name);
|
|
11415
|
+
const twice = names2.filter((each, index) => names2.indexOf(each) !== index);
|
|
11222
11416
|
if (twice.length > 0) {
|
|
11223
11417
|
throw new Error(`${file} lists ${[...new Set(twice)].join(", ")} more than once: each job is listed once, by its name.`);
|
|
11224
11418
|
}
|
|
@@ -11241,9 +11435,9 @@ async function apply(client, file, options) {
|
|
|
11241
11435
|
};
|
|
11242
11436
|
if (options["dry-run"]) {
|
|
11243
11437
|
const there = (await ask6(client, "GET", "/v1/jobs"))?.jobs ?? [];
|
|
11244
|
-
const
|
|
11438
|
+
const names2 = new Set(there.map((each) => each.name));
|
|
11245
11439
|
for (const each of jobs2) {
|
|
11246
|
-
say(
|
|
11440
|
+
say(names2.has(each.name) ? "would_put" : "would_make", each.name);
|
|
11247
11441
|
}
|
|
11248
11442
|
if (options.prune) {
|
|
11249
11443
|
const orgs = new Set(there.filter((one) => named.has(one.name)).map(orgOf));
|
|
@@ -11307,7 +11501,9 @@ var LIFECYCLE_EVENTS = [
|
|
|
11307
11501
|
"sandbox.deleted",
|
|
11308
11502
|
"sandbox.auto_stop_set",
|
|
11309
11503
|
"sandbox.labels_changed",
|
|
11310
|
-
"sandbox.low_cpu"
|
|
11504
|
+
"sandbox.low_cpu",
|
|
11505
|
+
"sandbox.upgraded",
|
|
11506
|
+
"sandbox.reclaim_chance"
|
|
11311
11507
|
];
|
|
11312
11508
|
var WEBHOOK_EVENTS = [...LIFECYCLE_EVENTS, "prompt.created"];
|
|
11313
11509
|
var EMAIL_EVENTS = ["email.received", "email.delivered", "email.bounced"];
|
|
@@ -11941,15 +12137,15 @@ function clamp(value, fallback) {
|
|
|
11941
12137
|
function sizeOf(stdout) {
|
|
11942
12138
|
return stdout.isTTY ? { cols: clamp(stdout.columns, 80), rows: clamp(stdout.rows, 24) } : { cols: 80, rows: 24 };
|
|
11943
12139
|
}
|
|
11944
|
-
function webSocketUrl(base,
|
|
11945
|
-
if (typeof
|
|
12140
|
+
function webSocketUrl(base, path6) {
|
|
12141
|
+
if (typeof path6 !== "string" || !path6.startsWith("/") || path6.startsWith("//") || /[\\\s]/.test(path6)) {
|
|
11946
12142
|
throw new Error("The API gave the terminal a path that is not one on its own address.");
|
|
11947
12143
|
}
|
|
11948
12144
|
const url = new URL(base);
|
|
11949
12145
|
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
11950
12146
|
throw new Error(`A terminal is opened on an http: or https: API, not ${url.protocol}`);
|
|
11951
12147
|
}
|
|
11952
|
-
return `${url.protocol === "https:" ? "wss:" : "ws:"}//${url.host}${url.pathname.replace(/\/+$/, "")}${
|
|
12148
|
+
return `${url.protocol === "https:" ? "wss:" : "ws:"}//${url.host}${url.pathname.replace(/\/+$/, "")}${path6}`;
|
|
11953
12149
|
}
|
|
11954
12150
|
function whyClosed(code, reason, error) {
|
|
11955
12151
|
const said = error?.message || reason;
|
|
@@ -12262,10 +12458,23 @@ var MACHINE_SIZES = {
|
|
|
12262
12458
|
large: { vcpu: 8, memoryMb: 16384, diskGb: 160 }
|
|
12263
12459
|
};
|
|
12264
12460
|
var MACHINE_SIZE_NAMES = ["tiny", "small", "medium", "large"];
|
|
12461
|
+
var LIST_PRICE_MICROS_PER_HOUR = {
|
|
12462
|
+
tiny: 13500,
|
|
12463
|
+
small: 27e3,
|
|
12464
|
+
medium: 54e3,
|
|
12465
|
+
large: 108e3
|
|
12466
|
+
};
|
|
12467
|
+
var SPOT_PRICE_MICROS_PER_HOUR = {
|
|
12468
|
+
tiny: LIST_PRICE_MICROS_PER_HOUR.tiny / 2,
|
|
12469
|
+
small: LIST_PRICE_MICROS_PER_HOUR.small / 2,
|
|
12470
|
+
medium: LIST_PRICE_MICROS_PER_HOUR.medium / 2,
|
|
12471
|
+
large: LIST_PRICE_MICROS_PER_HOUR.large / 2
|
|
12472
|
+
};
|
|
12265
12473
|
var HOURS_PER_MONTH = 730;
|
|
12266
12474
|
var STOPPED_MICROS_PER_GB_MONTH = 5e4;
|
|
12267
12475
|
var BYTES_PER_GB = 1e9;
|
|
12268
12476
|
var NEVER_PAID_MAX_STORED_BYTES = 20 * BYTES_PER_GB;
|
|
12477
|
+
var STOPPED_DELETION_NOTICE_MS = 3 * 864e5;
|
|
12269
12478
|
function stoppedMicrosPerHour(storedBytes) {
|
|
12270
12479
|
if (storedBytes <= 0) {
|
|
12271
12480
|
return 0;
|
|
@@ -12469,18 +12678,19 @@ var SSH_COMMANDS = {
|
|
|
12469
12678
|
};
|
|
12470
12679
|
async function setUp(args) {
|
|
12471
12680
|
const [command2, ...rest] = args;
|
|
12472
|
-
const onboarding = command2 === void 0 || command2 === "sh" || command2 === "--no-skills" || command2 === "--no-install" || command2 === "--json";
|
|
12681
|
+
const onboarding = command2 === void 0 || command2 === "sh" || command2 === "--no-skills" || command2 === "--no-install" || command2 === "--no-mcp" || command2 === "--json";
|
|
12473
12682
|
if (onboarding) {
|
|
12474
12683
|
const flags2 = command2 === "sh" ? rest : args;
|
|
12475
|
-
const unknown = flags2.filter((flag) => !["--json", "--no-skills", "--no-install"].includes(flag));
|
|
12684
|
+
const unknown = flags2.filter((flag) => !["--json", "--no-skills", "--no-install", "--no-mcp"].includes(flag));
|
|
12476
12685
|
if (unknown.length > 0) {
|
|
12477
|
-
throw new Error(`${command2 === "sh" ? "sh" : "agental"} takes --json, --no-skills and --no-
|
|
12686
|
+
throw new Error(`${command2 === "sh" ? "sh" : "agental"} takes --json, --no-skills, --no-install and --no-mcp, not ${unknown.join(" ")}`);
|
|
12478
12687
|
}
|
|
12479
12688
|
await onboard(apiBase(), {
|
|
12480
12689
|
sandbox: command2 === "sh",
|
|
12481
12690
|
json: flags2.includes("--json"),
|
|
12482
12691
|
installCommand: !flags2.includes("--no-install"),
|
|
12483
|
-
installSkills: !flags2.includes("--no-skills")
|
|
12692
|
+
installSkills: !flags2.includes("--no-skills"),
|
|
12693
|
+
installConnector: !flags2.includes("--no-mcp")
|
|
12484
12694
|
});
|
|
12485
12695
|
return true;
|
|
12486
12696
|
}
|
|
@@ -12696,6 +12906,10 @@ async function main() {
|
|
|
12696
12906
|
ttl: { type: "string" },
|
|
12697
12907
|
// agental create: what its time limit does when it runs out, delete or stop.
|
|
12698
12908
|
"on-timeout": { type: "string" },
|
|
12909
|
+
// agental create and agental spot: a spot sandbox, what is done when its room is taken back, and the chance it is warned at.
|
|
12910
|
+
spot: { type: "boolean", default: false },
|
|
12911
|
+
"on-reclaim": { type: "string" },
|
|
12912
|
+
"warn-at": { type: "string" },
|
|
12699
12913
|
"max-burst-fee": { type: "string" },
|
|
12700
12914
|
in: { type: "string" },
|
|
12701
12915
|
never: { type: "boolean", default: false },
|
|
@@ -12879,6 +13093,9 @@ async function main() {
|
|
|
12879
13093
|
case "egress":
|
|
12880
13094
|
await egress(positionals.slice(1), values);
|
|
12881
13095
|
return;
|
|
13096
|
+
case "spot":
|
|
13097
|
+
await spot(positionals.slice(1), values);
|
|
13098
|
+
return;
|
|
12882
13099
|
case "templates":
|
|
12883
13100
|
await listTemplates(values.json);
|
|
12884
13101
|
return;
|
|
@@ -12991,6 +13208,10 @@ async function create(values) {
|
|
|
12991
13208
|
if (values.size !== void 0 && !isMachineSize(values.size)) {
|
|
12992
13209
|
throw new Error("--size must be tiny, small, medium or large");
|
|
12993
13210
|
}
|
|
13211
|
+
if (!values.spot && (values["on-reclaim"] !== void 0 || values["warn-at"] !== void 0)) {
|
|
13212
|
+
throw new Error("--on-reclaim and --warn-at are for a spot sandbox: add --spot.");
|
|
13213
|
+
}
|
|
13214
|
+
const spotAsked = values.spot ? spotSettingsFrom(values) : void 0;
|
|
12994
13215
|
if (values.outbound !== void 0) {
|
|
12995
13216
|
throw new Error(
|
|
12996
13217
|
"--outbound is gone: a sandbox's rule comes from its template. Set it with agental template network <template> open|blocked|allowlist <address>..., and make the sandbox with --template <template>. --allow gives it addresses of its own on top."
|
|
@@ -13014,6 +13235,7 @@ async function create(values) {
|
|
|
13014
13235
|
...egressAsked ? { egress: egressAsked } : {},
|
|
13015
13236
|
...ttlSeconds === void 0 ? {} : { ttlSeconds },
|
|
13016
13237
|
...onTimeout === void 0 ? {} : { onTimeout: onTimeout.replaceAll("-", "_") },
|
|
13238
|
+
...spotAsked === void 0 ? {} : { spot: spotAsked },
|
|
13017
13239
|
...sshKeys2 === void 0 ? {} : { sshKeys: sshKeys2 },
|
|
13018
13240
|
...given
|
|
13019
13241
|
})
|
|
@@ -13064,17 +13286,17 @@ async function sshKeys(id, keyId, remove3, json2) {
|
|
|
13064
13286
|
if (!id) {
|
|
13065
13287
|
throw new Error("ssh-keys requires <sandbox-id>");
|
|
13066
13288
|
}
|
|
13067
|
-
const
|
|
13289
|
+
const path6 = `/v1/sandboxes/${encodeURIComponent(id)}/ssh/keys`;
|
|
13068
13290
|
if (remove3) {
|
|
13069
13291
|
if (!keyId) {
|
|
13070
13292
|
throw new Error("ssh-keys --remove requires <key-id>, as ssh-keys lists it");
|
|
13071
13293
|
}
|
|
13072
|
-
await call2(`${
|
|
13294
|
+
await call2(`${path6}/${encodeURIComponent(keyId)}`, { method: "DELETE" });
|
|
13073
13295
|
process.stdout.write(`${keyId} may log in to ${id} no longer.
|
|
13074
13296
|
`);
|
|
13075
13297
|
return;
|
|
13076
13298
|
}
|
|
13077
|
-
const body = await call2(
|
|
13299
|
+
const body = await call2(path6, { method: "GET" });
|
|
13078
13300
|
const keys = body?.keys ?? [];
|
|
13079
13301
|
if (json2) {
|
|
13080
13302
|
process.stdout.write(`${JSON.stringify(keys, null, 2)}
|
|
@@ -13088,10 +13310,10 @@ function publicKeysFrom(given) {
|
|
|
13088
13310
|
if (SSH_PUBLIC_KEY.test(each.trim())) {
|
|
13089
13311
|
return [each.trim()];
|
|
13090
13312
|
}
|
|
13091
|
-
const file = each.startsWith("~/") ? `${
|
|
13313
|
+
const file = each.startsWith("~/") ? `${os7.homedir()}${each.slice(1)}` : each;
|
|
13092
13314
|
let text;
|
|
13093
13315
|
try {
|
|
13094
|
-
text =
|
|
13316
|
+
text = readFileSync7(file, "utf8");
|
|
13095
13317
|
} catch {
|
|
13096
13318
|
throw new Error(`${each} is neither a public key nor a file that can be read. Give a key line, as ssh-ed25519 AAAA... you@laptop, or its file, as ~/.ssh/id_ed25519.pub.`);
|
|
13097
13319
|
}
|
|
@@ -13177,9 +13399,9 @@ async function list2(asJson, filter, sort, limit, wide = false) {
|
|
|
13177
13399
|
process.stdout.write(filter.size > 0 ? "No sandboxes match.\n" : "No sandboxes.\n");
|
|
13178
13400
|
return;
|
|
13179
13401
|
}
|
|
13180
|
-
const
|
|
13402
|
+
const names2 = sandboxes2.some((sandbox) => typeof sandbox["templateId"] === "string") ? await templateNames() : /* @__PURE__ */ new Map();
|
|
13181
13403
|
if (isTerminal(process.stdout) && !wide) {
|
|
13182
|
-
process.stdout.write(sandboxesForPeople(sandboxes2,
|
|
13404
|
+
process.stdout.write(sandboxesForPeople(sandboxes2, names2, sort !== void 0));
|
|
13183
13405
|
return;
|
|
13184
13406
|
}
|
|
13185
13407
|
const tagged = sandboxes2.some((sandbox) => Array.isArray(sandbox["tags"]));
|
|
@@ -13196,7 +13418,7 @@ async function list2(asJson, filter, sort, limit, wide = false) {
|
|
|
13196
13418
|
pad2(typeof sandbox["pendingSize"] === "string" ? `${String(sandbox["size"] ?? "")}>${sandbox["pendingSize"]}` : String(sandbox["size"] ?? "")),
|
|
13197
13419
|
pad2(String(sandbox["status"] ?? "")),
|
|
13198
13420
|
sandbox["vmIsolation"] === true ? "yes" : "no ",
|
|
13199
|
-
pad2(templateId === null ? "-" :
|
|
13421
|
+
pad2(templateId === null ? "-" : names2.get(templateId) ?? templateId),
|
|
13200
13422
|
// An API from before sandboxes said their rule says nothing, and nothing is shown for it.
|
|
13201
13423
|
(tagged ? pad2 : (word) => word)(rule && typeof rule === "object" ? String(rule["outbound"] ?? "") : ""),
|
|
13202
13424
|
...tagged ? [Array.isArray(sandbox["tags"]) && sandbox["tags"].length > 0 ? sandbox["tags"].join(",") : "-"] : []
|
|
@@ -13293,8 +13515,8 @@ async function bulk(action, filter, options, yes2, asJson, confirm) {
|
|
|
13293
13515
|
`);
|
|
13294
13516
|
const pausing = read2.jobsPaused ?? 0;
|
|
13295
13517
|
if (pausing > 0) {
|
|
13296
|
-
const
|
|
13297
|
-
process.stderr.write(`It pauses ${pausing} ${pausing === 1 ? "job" : "jobs"} that run in them: ${
|
|
13518
|
+
const names2 = read2.jobsPausedNames ?? [];
|
|
13519
|
+
process.stderr.write(`It pauses ${pausing} ${pausing === 1 ? "job" : "jobs"} that run in them: ${names2.join(", ")}${pausing > names2.length ? `, and ${pausing - names2.length} more` : ""}.
|
|
13298
13520
|
`);
|
|
13299
13521
|
}
|
|
13300
13522
|
let count = null;
|
|
@@ -13340,11 +13562,11 @@ async function bulk(action, filter, options, yes2, asJson, confirm) {
|
|
|
13340
13562
|
}
|
|
13341
13563
|
async function bulkActionsCommand(positionals, asJson) {
|
|
13342
13564
|
const [verb, id] = positionals;
|
|
13343
|
-
const
|
|
13344
|
-
if (
|
|
13565
|
+
const path6 = verb === void 0 || verb === "list" ? "/v1/bulk-actions" : verb === "show" && id ? `/v1/bulk-actions/${encodeURIComponent(id)}` : verb === "cancel" && id ? `/v1/bulk-actions/${encodeURIComponent(id)}/cancel` : null;
|
|
13566
|
+
if (path6 === null) {
|
|
13345
13567
|
throw new Error("bulk-actions takes list, show <id> or cancel <id>");
|
|
13346
13568
|
}
|
|
13347
|
-
const response = await request(
|
|
13569
|
+
const response = await request(path6, { method: verb === "cancel" ? "POST" : "GET" });
|
|
13348
13570
|
const body = await readBody(response);
|
|
13349
13571
|
if (!response.ok) {
|
|
13350
13572
|
fail(response.status, body);
|
|
@@ -13471,8 +13693,8 @@ async function resize(id, size2, now, cancel, maxBurstFee, asJson) {
|
|
|
13471
13693
|
throw new Error("--max-burst-fee goes with --now: it caps what the restart's start pays in burst fees");
|
|
13472
13694
|
}
|
|
13473
13695
|
const headers = maxBurstFeeHeaders(maxBurstFee);
|
|
13474
|
-
const
|
|
13475
|
-
const before = await call2(
|
|
13696
|
+
const path6 = `/v1/sandboxes/${encodeURIComponent(id)}`;
|
|
13697
|
+
const before = await call2(path6, { method: "GET" });
|
|
13476
13698
|
const name = before.name || id;
|
|
13477
13699
|
const print4 = (sandbox, line) => process.stdout.write(asJson ? `${JSON.stringify(sandbox, null, 2)}
|
|
13478
13700
|
` : `${line}
|
|
@@ -13488,11 +13710,11 @@ async function resize(id, size2, now, cancel, maxBurstFee, asJson) {
|
|
|
13488
13710
|
process.stderr.write(`Restarting ${name} as a ${to}: every process in it ends, as on a stop. Its files stay.
|
|
13489
13711
|
`);
|
|
13490
13712
|
}
|
|
13491
|
-
const response = await request(`${
|
|
13713
|
+
const response = await request(`${path6}/resize`, { method: "POST", headers: restart ? headers : {}, body: JSON.stringify({ size: to, ...restart ? { restart: true } : {} }) });
|
|
13492
13714
|
const body = await readBody(response);
|
|
13493
13715
|
if (!response.ok) {
|
|
13494
13716
|
if (cancel && response.status === 409 && isApiError(body) && body.error.code === "size_smaller") {
|
|
13495
|
-
const read2 = await call2(
|
|
13717
|
+
const read2 = await call2(path6, { method: "GET" });
|
|
13496
13718
|
print4(read2, `${read2.name || id} is already a ${read2.size}; nothing was waiting.`);
|
|
13497
13719
|
return;
|
|
13498
13720
|
}
|
|
@@ -13645,18 +13867,18 @@ async function autoStop(id, inText, at4, never, asJson) {
|
|
|
13645
13867
|
if ([inText !== void 0, at4 !== void 0, never].filter(Boolean).length > 1) {
|
|
13646
13868
|
throw new Error("--in, --at and --never say different things: give one.");
|
|
13647
13869
|
}
|
|
13648
|
-
const
|
|
13870
|
+
const path6 = `/v1/sandboxes/${encodeURIComponent(id)}/auto-stop`;
|
|
13649
13871
|
let body;
|
|
13650
13872
|
if (never) {
|
|
13651
|
-
body = await call2(
|
|
13873
|
+
body = await call2(path6, { method: "DELETE" });
|
|
13652
13874
|
} else if (inText === void 0 && at4 === void 0) {
|
|
13653
|
-
body = await call2(
|
|
13875
|
+
body = await call2(path6, { method: "GET" });
|
|
13654
13876
|
} else {
|
|
13655
13877
|
const inSeconds = inText === void 0 ? void 0 : seconds(inText);
|
|
13656
13878
|
if (inSeconds === null) {
|
|
13657
13879
|
throw new Error("--in is a time from now, such as 30m, 2h or 1d");
|
|
13658
13880
|
}
|
|
13659
|
-
body = await call2(
|
|
13881
|
+
body = await call2(path6, { method: "PUT", body: JSON.stringify(inSeconds === void 0 ? { at: at4 } : { inSeconds }) });
|
|
13660
13882
|
}
|
|
13661
13883
|
if (asJson) {
|
|
13662
13884
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
@@ -13712,7 +13934,7 @@ async function screenshot(id, file, options) {
|
|
|
13712
13934
|
fail(response.status, await readBody(response));
|
|
13713
13935
|
}
|
|
13714
13936
|
const picture = Buffer.from(await response.arrayBuffer());
|
|
13715
|
-
|
|
13937
|
+
writeFileSync5(file, picture);
|
|
13716
13938
|
const size2 = pictureSize(picture);
|
|
13717
13939
|
process.stderr.write(`A picture of the screen of ${id} is in ${file}: ${size2 ? `${size2.width} by ${size2.height}, ` : ""}${picture.length} bytes.
|
|
13718
13940
|
`);
|
|
@@ -13747,7 +13969,7 @@ async function clipboard(id, text) {
|
|
|
13747
13969
|
process.stdout.write(String(body.text ?? ""));
|
|
13748
13970
|
return;
|
|
13749
13971
|
}
|
|
13750
|
-
const given = text === "-" ?
|
|
13972
|
+
const given = text === "-" ? readFileSync7(0, "utf8") : text;
|
|
13751
13973
|
const response = await request(at4, { method: "PUT", body: JSON.stringify({ text: given }) });
|
|
13752
13974
|
if (!response.ok) {
|
|
13753
13975
|
fail(response.status, await readBody(response));
|
|
@@ -13921,10 +14143,10 @@ async function labels(what, holder, positionals, asJson) {
|
|
|
13921
14143
|
throw new Error(`${command2} requires <${holder}>: ${usage}`);
|
|
13922
14144
|
}
|
|
13923
14145
|
const id = holder === "template" ? (await templateNamed(named)).id : named;
|
|
13924
|
-
const
|
|
14146
|
+
const path6 = `/v1/${holder === "template" ? "templates" : "sandboxes"}/${encodeURIComponent(id)}`;
|
|
13925
14147
|
let body;
|
|
13926
14148
|
if (action === void 0) {
|
|
13927
|
-
body = await call2(
|
|
14149
|
+
body = await call2(path6, { method: "GET" });
|
|
13928
14150
|
} else if (what === "tags" && (action === "add" || action === "rm")) {
|
|
13929
14151
|
const tags = listedIn(words2).map((tag) => tag.toLowerCase());
|
|
13930
14152
|
if (tags.length === 0) {
|
|
@@ -13935,14 +14157,14 @@ async function labels(what, holder, positionals, asJson) {
|
|
|
13935
14157
|
throw new Error(`A tag is lowercase letters, digits and hyphens, 1 to 63 characters, not starting or ending with a hyphen, not ${JSON.stringify(bad2)}.`);
|
|
13936
14158
|
}
|
|
13937
14159
|
for (const tag of tags) {
|
|
13938
|
-
body = await call2(`${
|
|
14160
|
+
body = await call2(`${path6}/tags/${encodeURIComponent(tag)}`, { method: action === "add" ? "PUT" : "DELETE" });
|
|
13939
14161
|
}
|
|
13940
14162
|
} else if (what === "meta" && (action === "set" || action === "unset")) {
|
|
13941
14163
|
if (words2.length === 0) {
|
|
13942
14164
|
throw new Error(`${command2} ${action} requires ${action === "set" ? "<key>=<value>" : "<key>"}...`);
|
|
13943
14165
|
}
|
|
13944
14166
|
const metadata = action === "set" ? metadataGiven(words2) : Object.fromEntries(words2.map((key2) => [key2, null]));
|
|
13945
|
-
body = await call2(
|
|
14167
|
+
body = await call2(path6, { method: "PATCH", body: JSON.stringify({ metadata }) });
|
|
13946
14168
|
} else {
|
|
13947
14169
|
throw new Error(`${command2} takes ${usage}`);
|
|
13948
14170
|
}
|
|
@@ -13969,9 +14191,9 @@ async function network(positionals, values) {
|
|
|
13969
14191
|
if (values.allow !== void 0 && values.none) {
|
|
13970
14192
|
throw new Error("--allow and --none say two things: give one.");
|
|
13971
14193
|
}
|
|
13972
|
-
const
|
|
14194
|
+
const path6 = `/v1/sandboxes/${encodeURIComponent(id)}/network`;
|
|
13973
14195
|
const allow = values.none ? [] : values.allow === void 0 ? void 0 : listedIn(values.allow);
|
|
13974
|
-
const body = await call2(
|
|
14196
|
+
const body = await call2(path6, allow === void 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify({ allow }) });
|
|
13975
14197
|
if (values.json) {
|
|
13976
14198
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
13977
14199
|
`);
|
|
@@ -14047,12 +14269,56 @@ async function egress(positionals, values) {
|
|
|
14047
14269
|
`);
|
|
14048
14270
|
return;
|
|
14049
14271
|
}
|
|
14050
|
-
const
|
|
14272
|
+
const path6 = `/v1/sandboxes/${encodeURIComponent(first)}/egress`;
|
|
14051
14273
|
const how = `egress takes <sandbox-id>, and then nothing, box, or residential <country> [sticky|rotating], as agental egress ${first} residential de.`;
|
|
14052
|
-
const body = await call2(
|
|
14274
|
+
const body = await call2(path6, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
|
|
14053
14275
|
print4(body, `${first}: ${egressInWords(body)}
|
|
14054
14276
|
`);
|
|
14055
14277
|
}
|
|
14278
|
+
function spotSettingsFrom(values) {
|
|
14279
|
+
const onReclaim = values["on-reclaim"];
|
|
14280
|
+
if (onReclaim !== void 0 && onReclaim !== "delete" && onReclaim !== "stop" && onReclaim !== "upgrade") {
|
|
14281
|
+
throw new Error("--on-reclaim is delete, stop or upgrade: what is done to a spot sandbox when its room is taken back.");
|
|
14282
|
+
}
|
|
14283
|
+
const given = values["warn-at"];
|
|
14284
|
+
const percent = given?.endsWith("%") ? Number(given.slice(0, -1)) / 100 : Number(given);
|
|
14285
|
+
if (given !== void 0 && (!/^(\d+(\.\d+)?|\.\d+)%?$/.test(given) || percent > 1)) {
|
|
14286
|
+
throw new Error(`--warn-at is the chance of being stopped at which sandbox.reclaim_chance is sent, from 0 to 1 or 0% to 100%, as 0.5 or 50%. It was given ${given}.`);
|
|
14287
|
+
}
|
|
14288
|
+
return { ...onReclaim === void 0 ? {} : { onReclaim }, ...given === void 0 ? {} : { warnAt: percent } };
|
|
14289
|
+
}
|
|
14290
|
+
function spotInWords(sandbox) {
|
|
14291
|
+
const spot2 = sandbox?.["spot"];
|
|
14292
|
+
if (!spot2) {
|
|
14293
|
+
return "spot off: a standard sandbox, at the list price";
|
|
14294
|
+
}
|
|
14295
|
+
const done2 = {
|
|
14296
|
+
delete: "deleted when its room is taken back",
|
|
14297
|
+
stop: "stopped when its room is taken back, its disk kept",
|
|
14298
|
+
upgrade: "made standard at the list price when its room is taken back, or stopped where that frees nothing"
|
|
14299
|
+
};
|
|
14300
|
+
const chance = typeof spot2.reclaimChance === "number" ? `${Math.round(spot2.reclaimChance * 100)}% chance of being stopped in the next minute` : "no chance worked out while it is not running";
|
|
14301
|
+
const warnAt = typeof spot2.warnAt === "number" ? `, warned at ${Math.round(spot2.warnAt * 100)}%` : "";
|
|
14302
|
+
return `spot, ${done2[String(spot2.onReclaim)] ?? String(spot2.onReclaim)}; ${chance}${warnAt}`;
|
|
14303
|
+
}
|
|
14304
|
+
async function spot(positionals, values) {
|
|
14305
|
+
const [id, given, ...rest] = positionals;
|
|
14306
|
+
const word = given === "normal" ? "off" : given;
|
|
14307
|
+
const how = "spot takes <sandbox-id>, and then nothing, off, or --on-reclaim delete|stop|upgrade and --warn-at <chance>, as agental spot sbx_2a9a47e50daec64a --on-reclaim upgrade.";
|
|
14308
|
+
if (id === void 0 || rest.length > 0 || word !== void 0 && word !== "off") {
|
|
14309
|
+
throw new Error(how);
|
|
14310
|
+
}
|
|
14311
|
+
const settings = spotSettingsFrom(values);
|
|
14312
|
+
if (word === "off" && Object.keys(settings).length > 0) {
|
|
14313
|
+
throw new Error(how);
|
|
14314
|
+
}
|
|
14315
|
+
const path6 = `/v1/sandboxes/${encodeURIComponent(id)}`;
|
|
14316
|
+
const change = word === "off" ? { spot: null } : Object.keys(settings).length > 0 ? { spot: settings } : null;
|
|
14317
|
+
const body = await call2(path6, change === null ? { method: "GET" } : { method: "PATCH", body: JSON.stringify(change) });
|
|
14318
|
+
process.stdout.write(values.json ? `${JSON.stringify(body?.["spot"] ?? null, null, 2)}
|
|
14319
|
+
` : `${id}: ${spotInWords(body)}
|
|
14320
|
+
`);
|
|
14321
|
+
}
|
|
14056
14322
|
function templateSshInWords(ssh2) {
|
|
14057
14323
|
const keys = ssh2.keys.length === 1 ? "1 key" : `${ssh2.keys.length} keys`;
|
|
14058
14324
|
return `${ssh2.enabled ? "on" : "off"} as a sandbox is made, ${keys} let in`;
|
|
@@ -14203,7 +14469,7 @@ async function template(positionals, values) {
|
|
|
14203
14469
|
}
|
|
14204
14470
|
case "start": {
|
|
14205
14471
|
const found = await templateNamed(need(first, "<template>"));
|
|
14206
|
-
const
|
|
14472
|
+
const path6 = `/v1/templates/${encodeURIComponent(found.id)}/start`;
|
|
14207
14473
|
if (values.snapshot !== void 0 && values["new-machine"]) {
|
|
14208
14474
|
throw new Error("--snapshot and --new-machine say two things: give one.");
|
|
14209
14475
|
}
|
|
@@ -14213,12 +14479,12 @@ async function template(positionals, values) {
|
|
|
14213
14479
|
const ttlSeconds = ttlOption(values.ttl);
|
|
14214
14480
|
let start;
|
|
14215
14481
|
if (values.size === void 0 && values.snapshot === void 0 && !values["new-machine"] && ttlSeconds === void 0) {
|
|
14216
|
-
start = await call2(
|
|
14482
|
+
start = await call2(path6, { method: "GET" });
|
|
14217
14483
|
} else {
|
|
14218
|
-
const current = await call2(
|
|
14484
|
+
const current = await call2(path6, { method: "GET" });
|
|
14219
14485
|
const snapshotId = values["new-machine"] ? null : values.snapshot ?? current?.snapshotId ?? null;
|
|
14220
14486
|
const ttl = ttlSeconds === void 0 ? current?.ttlSeconds ?? null : ttlSeconds;
|
|
14221
|
-
start = await call2(
|
|
14487
|
+
start = await call2(path6, { method: "PUT", body: JSON.stringify({ size: values.size ?? current?.size, snapshotId, ttlSeconds: ttl }) });
|
|
14222
14488
|
}
|
|
14223
14489
|
print4(start, `start: ${startInWords(start)}
|
|
14224
14490
|
`);
|
|
@@ -14226,11 +14492,11 @@ async function template(positionals, values) {
|
|
|
14226
14492
|
}
|
|
14227
14493
|
case "network": {
|
|
14228
14494
|
const found = await templateNamed(need(first, "<template>"));
|
|
14229
|
-
const
|
|
14495
|
+
const path6 = `/v1/templates/${encodeURIComponent(found.id)}/network`;
|
|
14230
14496
|
const [mode, ...addresses] = rest;
|
|
14231
14497
|
let rule;
|
|
14232
14498
|
if (mode === void 0) {
|
|
14233
|
-
rule = await call2(
|
|
14499
|
+
rule = await call2(path6, { method: "GET" });
|
|
14234
14500
|
} else {
|
|
14235
14501
|
if (!OUTBOUND_MODES.some((known) => known === mode)) {
|
|
14236
14502
|
throw new Error("template network requires <template>, and then nothing, open, blocked, or allowlist <address>...");
|
|
@@ -14242,7 +14508,7 @@ async function template(positionals, values) {
|
|
|
14242
14508
|
if (mode === "allowlist" && listed.length === 0) {
|
|
14243
14509
|
throw new Error(`allowlist needs at least one address, as agental template network ${first ?? ""} allowlist 203.0.113.7 198.51.100.0/24`);
|
|
14244
14510
|
}
|
|
14245
|
-
rule = await call2(
|
|
14511
|
+
rule = await call2(path6, { method: "PUT", body: JSON.stringify(mode === "allowlist" ? { outbound: mode, allow: listed } : { outbound: mode }) });
|
|
14246
14512
|
}
|
|
14247
14513
|
print4(
|
|
14248
14514
|
rule,
|
|
@@ -14253,37 +14519,37 @@ ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now
|
|
|
14253
14519
|
}
|
|
14254
14520
|
case "egress": {
|
|
14255
14521
|
const found = await templateNamed(need(first, "<template>"));
|
|
14256
|
-
const
|
|
14522
|
+
const path6 = `/v1/templates/${encodeURIComponent(found.id)}/egress`;
|
|
14257
14523
|
const how = `template egress takes <template>, and then nothing, box, or residential <country> [sticky|rotating], as agental template egress ${first ?? ""} residential de.`;
|
|
14258
|
-
const set = await call2(
|
|
14524
|
+
const set = await call2(path6, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
|
|
14259
14525
|
print4(set, `${found.name}: ${egressInWords(set)}${rest.length === 0 ? "" : ", for sandboxes made from it from now on"}
|
|
14260
14526
|
`);
|
|
14261
14527
|
return;
|
|
14262
14528
|
}
|
|
14263
14529
|
case "ssh": {
|
|
14264
14530
|
const found = await templateNamed(need(first, "<template>"));
|
|
14265
|
-
const
|
|
14531
|
+
const path6 = `/v1/templates/${encodeURIComponent(found.id)}/ssh`;
|
|
14266
14532
|
const [turn] = rest;
|
|
14267
14533
|
if (turn !== void 0 && turn !== "on" && turn !== "off") {
|
|
14268
14534
|
throw new Error("template ssh requires <template>, and then nothing, on or off");
|
|
14269
14535
|
}
|
|
14270
|
-
const ssh2 = await call2(
|
|
14536
|
+
const ssh2 = await call2(path6, { method: turn === "on" ? "PUT" : turn === "off" ? "DELETE" : "GET" });
|
|
14271
14537
|
print4(ssh2, `${found.name}: SSH ${templateSshInWords(ssh2)}
|
|
14272
14538
|
`);
|
|
14273
14539
|
return;
|
|
14274
14540
|
}
|
|
14275
14541
|
case "ssh-keys": {
|
|
14276
14542
|
const found = await templateNamed(need(first, "<template>"));
|
|
14277
|
-
const
|
|
14543
|
+
const path6 = `/v1/templates/${encodeURIComponent(found.id)}/ssh/keys`;
|
|
14278
14544
|
if (values.remove) {
|
|
14279
14545
|
const keyId = need(rest[0], "<template> --remove <key-id>");
|
|
14280
|
-
await call2(`${
|
|
14546
|
+
await call2(`${path6}/${encodeURIComponent(keyId)}`, { method: "DELETE" });
|
|
14281
14547
|
process.stdout.write(`${keyId} is let in to no sandbox made from ${found.name} from now on. The sandboxes made already keep it.
|
|
14282
14548
|
`);
|
|
14283
14549
|
return;
|
|
14284
14550
|
}
|
|
14285
14551
|
for (const publicKey2 of publicKeysFrom(rest)) {
|
|
14286
|
-
await call2(
|
|
14552
|
+
await call2(path6, { method: "POST", body: JSON.stringify({ publicKey: publicKey2 }) });
|
|
14287
14553
|
}
|
|
14288
14554
|
const ssh2 = await call2(`/v1/templates/${encodeURIComponent(found.id)}/ssh`, { method: "GET" });
|
|
14289
14555
|
if (values.json) {
|
|
@@ -14345,8 +14611,8 @@ up to date: ${body["upToDate"] === true ? "yes" : "no: it takes the template whe
|
|
|
14345
14611
|
function keptOutInWords(variable) {
|
|
14346
14612
|
return [`${variable.name} is kept out of the sandbox, and its value is never given back.`, `stand-in: ${variable.standIn}`, `hosts: ${variable.hosts.join(", ")}`, ""].join("\n");
|
|
14347
14613
|
}
|
|
14348
|
-
async function keptOutNow(
|
|
14349
|
-
const response = await request(
|
|
14614
|
+
async function keptOutNow(path6) {
|
|
14615
|
+
const response = await request(path6, { method: "GET" });
|
|
14350
14616
|
const body = await readBody(response);
|
|
14351
14617
|
if (response.status === 404) {
|
|
14352
14618
|
return false;
|
|
@@ -14371,30 +14637,30 @@ async function secrets(positionals, values) {
|
|
|
14371
14637
|
base = `/v1/sandboxes/${encodeURIComponent(sandboxId)}/secrets`;
|
|
14372
14638
|
}
|
|
14373
14639
|
const [action, ...args] = words2;
|
|
14374
|
-
const fileQuery = (
|
|
14375
|
-
if (!
|
|
14640
|
+
const fileQuery = (path6) => {
|
|
14641
|
+
if (!path6) {
|
|
14376
14642
|
throw new Error(`secrets ${action ?? ""} requires <path>`);
|
|
14377
14643
|
}
|
|
14378
|
-
return `${base}/files?path=${encodeURIComponent(
|
|
14644
|
+
return `${base}/files?path=${encodeURIComponent(path6)}`;
|
|
14379
14645
|
};
|
|
14380
14646
|
switch (action) {
|
|
14381
14647
|
case void 0: {
|
|
14382
14648
|
const listed = await call2(`${base}/variables`, { method: "GET" });
|
|
14383
|
-
const
|
|
14649
|
+
const names2 = listed.names;
|
|
14384
14650
|
const hidden2 = listed.hidden ?? [];
|
|
14385
14651
|
const paths = (await call2(`${base}/files`, { method: "GET" })).paths;
|
|
14386
14652
|
if (values.json) {
|
|
14387
|
-
process.stdout.write(`${JSON.stringify({ variables:
|
|
14653
|
+
process.stdout.write(`${JSON.stringify({ variables: names2, hidden: hidden2, files: paths }, null, 2)}
|
|
14388
14654
|
`);
|
|
14389
14655
|
return;
|
|
14390
14656
|
}
|
|
14391
|
-
if (
|
|
14657
|
+
if (names2.length === 0 && paths.length === 0) {
|
|
14392
14658
|
process.stdout.write("No secrets.\n");
|
|
14393
14659
|
return;
|
|
14394
14660
|
}
|
|
14395
14661
|
process.stdout.write(
|
|
14396
|
-
[...
|
|
14397
|
-
`), ...paths.map((
|
|
14662
|
+
[...names2.map((name) => `variable ${name}${hidden2.includes(name) ? " kept out of the sandbox" : ""}
|
|
14663
|
+
`), ...paths.map((path6) => `file ${path6}
|
|
14398
14664
|
`)].join("")
|
|
14399
14665
|
);
|
|
14400
14666
|
return;
|
|
@@ -14432,11 +14698,11 @@ async function secrets(positionals, values) {
|
|
|
14432
14698
|
}
|
|
14433
14699
|
return [arg.slice(0, at4), arg.slice(at4 + 1)];
|
|
14434
14700
|
});
|
|
14435
|
-
const
|
|
14701
|
+
const path6 = (name) => `${base}/variables/${encodeURIComponent(name)}`;
|
|
14436
14702
|
if (hosts === void 0 && !values.plain) {
|
|
14437
14703
|
const byTemplate = sandboxId === void 0 ? [] : (await call2(`/v1/sandboxes/${encodeURIComponent(sandboxId)}/template`, { method: "GET" }))?.hidden ?? [];
|
|
14438
14704
|
for (const [name] of pairs) {
|
|
14439
|
-
if (await keptOutNow(
|
|
14705
|
+
if (await keptOutNow(path6(name))) {
|
|
14440
14706
|
throw new Error(
|
|
14441
14707
|
`${name} is kept out of the sandbox. Set without --host it would be plain, and its commands would read its value. Give its hosts again with --host to keep it out, or --plain for its commands to read it. Nothing was set.`
|
|
14442
14708
|
);
|
|
@@ -14449,7 +14715,7 @@ async function secrets(positionals, values) {
|
|
|
14449
14715
|
}
|
|
14450
14716
|
}
|
|
14451
14717
|
for (const [name, value] of pairs) {
|
|
14452
|
-
const body = await call2(
|
|
14718
|
+
const body = await call2(path6(name), { method: "PUT", body: JSON.stringify(hosts === void 0 ? { value } : { value, hosts }) });
|
|
14453
14719
|
process.stdout.write(
|
|
14454
14720
|
body.hidden === true ? `set ${name}, kept out of the sandbox: its commands see ${body.standIn}, and its value is sent only to ${body.hosts.join(", ")}
|
|
14455
14721
|
` : `set ${name}
|
|
@@ -14491,12 +14757,12 @@ async function secrets(positionals, values) {
|
|
|
14491
14757
|
return;
|
|
14492
14758
|
}
|
|
14493
14759
|
case "put-file": {
|
|
14494
|
-
const [
|
|
14495
|
-
if (!
|
|
14760
|
+
const [path6, local] = args;
|
|
14761
|
+
if (!path6 || local === void 0 === (values.text === void 0)) {
|
|
14496
14762
|
throw new Error("secrets put-file requires <path>, and then a local file to read it from or --text with what it holds");
|
|
14497
14763
|
}
|
|
14498
14764
|
const text = values.text ?? await readFile2(local ?? "", "utf8");
|
|
14499
|
-
const body = await call2(`${base}/files`, { method: "PUT", body: JSON.stringify({ path:
|
|
14765
|
+
const body = await call2(`${base}/files`, { method: "PUT", body: JSON.stringify({ path: path6, text }) });
|
|
14500
14766
|
process.stdout.write(`put ${body.path}
|
|
14501
14767
|
`);
|
|
14502
14768
|
return;
|
|
@@ -14531,9 +14797,9 @@ async function metrics(id, asked2) {
|
|
|
14531
14797
|
query.set(name, value);
|
|
14532
14798
|
}
|
|
14533
14799
|
}
|
|
14534
|
-
const
|
|
14800
|
+
const path6 = asked2.running ? "/v1/metrics/running" : id === void 0 ? "/v1/metrics" : `/v1/sandboxes/${encodeURIComponent(id)}/metrics`;
|
|
14535
14801
|
const search = query.toString();
|
|
14536
|
-
const response = await request(search === "" ?
|
|
14802
|
+
const response = await request(search === "" ? path6 : `${path6}?${search}`, { method: "GET" });
|
|
14537
14803
|
const body = await readBody(response);
|
|
14538
14804
|
if (!response.ok) {
|
|
14539
14805
|
fail(response.status, body);
|
|
@@ -14582,7 +14848,7 @@ async function account2(positionals, out) {
|
|
|
14582
14848
|
process.stdout.write(text);
|
|
14583
14849
|
return;
|
|
14584
14850
|
}
|
|
14585
|
-
|
|
14851
|
+
writeFileSync5(out, text, { mode: 384 });
|
|
14586
14852
|
process.stdout.write(`Written to ${out}.
|
|
14587
14853
|
`);
|
|
14588
14854
|
}
|
|
@@ -14661,9 +14927,9 @@ async function ci(positionals, options) {
|
|
|
14661
14927
|
if (repo === void 0 || !/^[^/\s]+\/[^/\s]+$/.test(repo)) {
|
|
14662
14928
|
throw new Error(`ci ${what} needs the repository, as agental ci ${what} acme/app`);
|
|
14663
14929
|
}
|
|
14664
|
-
const
|
|
14930
|
+
const path6 = `/v1/runs-on/repositories/${repo.split("/").map(encodeURIComponent).join("/")}`;
|
|
14665
14931
|
if (what === "reset") {
|
|
14666
|
-
const response = await request(
|
|
14932
|
+
const response = await request(path6, { method: "DELETE" });
|
|
14667
14933
|
if (!response.ok) {
|
|
14668
14934
|
fail(response.status, await readBody(response));
|
|
14669
14935
|
}
|
|
@@ -14685,7 +14951,7 @@ async function ci(positionals, options) {
|
|
|
14685
14951
|
if (options.template !== void 0) {
|
|
14686
14952
|
templateId = options.template === "default" ? null : (await templateNamed(options.template)).id;
|
|
14687
14953
|
}
|
|
14688
|
-
const saved = await asked(
|
|
14954
|
+
const saved = await asked(path6, { method: "PUT", body: JSON.stringify({ poolMax, templateId }) });
|
|
14689
14955
|
if (options.json) {
|
|
14690
14956
|
process.stdout.write(`${JSON.stringify(saved, null, 2)}
|
|
14691
14957
|
`);
|
|
@@ -14915,7 +15181,7 @@ function describeBilling(body, card = null) {
|
|
|
14915
15181
|
if (free.cardSaved) {
|
|
14916
15182
|
lines.push([
|
|
14917
15183
|
"Allowance",
|
|
14918
|
-
allowance > 0 ? `${money(allowance)}, ${money(Math.max(0, allowance - (free.allowanceUsedMicros ?? 0)))} left. It starts again on
|
|
15184
|
+
allowance > 0 ? `${money(allowance)}, ${money(Math.max(0, allowance - (free.allowanceUsedMicros ?? 0)))} left. It starts again ${body.period ? `on ${dayOf(body.period.end)}` : "next month"}.` : "none: the card you saved had the free allowance on another account."
|
|
14919
15185
|
]);
|
|
14920
15186
|
}
|
|
14921
15187
|
lines.push(["Credits left", `${money(body.topUpMicros)} of top-ups, used after the free allowance. They do not expire.`]);
|
|
@@ -15314,8 +15580,8 @@ function duration(ms) {
|
|
|
15314
15580
|
const minutes = Math.round(ms / 6e4);
|
|
15315
15581
|
return minutes < 60 ? `${minutes} min` : `${Math.floor(minutes / 60)} h${minutes % 60 === 0 ? "" : ` ${minutes % 60} min`}`;
|
|
15316
15582
|
}
|
|
15317
|
-
async function asked(
|
|
15318
|
-
const response = await request(
|
|
15583
|
+
async function asked(path6, init) {
|
|
15584
|
+
const response = await request(path6, init);
|
|
15319
15585
|
const body = await readBody(response);
|
|
15320
15586
|
if (!response.ok) {
|
|
15321
15587
|
fail(response.status, body);
|
|
@@ -15394,7 +15660,7 @@ function table3(rows) {
|
|
|
15394
15660
|
`).join("");
|
|
15395
15661
|
}
|
|
15396
15662
|
var ACTIVE = /* @__PURE__ */ new Set(["running", "starting", "stopping", "restoring", "creating"]);
|
|
15397
|
-
function sandboxesForPeople(sandboxes2,
|
|
15663
|
+
function sandboxesForPeople(sandboxes2, names2, sorted) {
|
|
15398
15664
|
const text = (value) => typeof value === "string" ? value : "";
|
|
15399
15665
|
const changed = (sandbox) => Date.parse(text(sandbox["stoppedAt"]) || text(sandbox["updatedAt"]) || text(sandbox["createdAt"])) || 0;
|
|
15400
15666
|
const shown = sorted ? sandboxes2 : [...sandboxes2].sort((a, b) => Number(ACTIVE.has(text(b["status"]))) - Number(ACTIVE.has(text(a["status"]))) || changed(b) - changed(a));
|
|
@@ -15406,6 +15672,14 @@ function sandboxesForPeople(sandboxes2, names, sorted) {
|
|
|
15406
15672
|
const showVm = differs((sandbox) => String(sandbox["vmIsolation"] === true));
|
|
15407
15673
|
const showOutbound = differs(outbound);
|
|
15408
15674
|
const showTags = shown.some((sandbox) => Array.isArray(sandbox["tags"]) && sandbox["tags"].length > 0);
|
|
15675
|
+
const showSpot = shown.some((sandbox) => sandbox["spot"] !== null && typeof sandbox["spot"] === "object");
|
|
15676
|
+
const spotWord = (sandbox) => {
|
|
15677
|
+
const spot2 = sandbox["spot"];
|
|
15678
|
+
if (!spot2) {
|
|
15679
|
+
return "-";
|
|
15680
|
+
}
|
|
15681
|
+
return typeof spot2.reclaimChance === "number" ? `spot ${Math.round(spot2.reclaimChance * 100)}%` : "spot";
|
|
15682
|
+
};
|
|
15409
15683
|
const status = (sandbox) => {
|
|
15410
15684
|
const word = text(sandbox["status"]) || "unknown";
|
|
15411
15685
|
const stops = word === "running" ? until(text(sandbox["autoStopAt"])) : null;
|
|
@@ -15413,7 +15687,7 @@ function sandboxesForPeople(sandboxes2, names, sorted) {
|
|
|
15413
15687
|
return stops ? `running, stops ${stops}` : stopped ? `stopped ${stopped}` : word;
|
|
15414
15688
|
};
|
|
15415
15689
|
const rows = [
|
|
15416
|
-
["", "ID", "NAME", "SIZE", "TEMPLATE", "STATUS", ...showVm ? ["VM"] : [], ...showOutbound ? ["OUTBOUND"] : [], ...showTags ? ["TAGS"] : []],
|
|
15690
|
+
["", "ID", "NAME", "SIZE", "TEMPLATE", "STATUS", ...showSpot ? ["SPOT"] : [], ...showVm ? ["VM"] : [], ...showOutbound ? ["OUTBOUND"] : [], ...showTags ? ["TAGS"] : []],
|
|
15417
15691
|
...shown.map((sandbox) => {
|
|
15418
15692
|
const templateId = text(sandbox["templateId"]);
|
|
15419
15693
|
return [
|
|
@@ -15421,8 +15695,9 @@ function sandboxesForPeople(sandboxes2, names, sorted) {
|
|
|
15421
15695
|
text(sandbox["id"]),
|
|
15422
15696
|
text(sandbox["name"]),
|
|
15423
15697
|
sizeOf2(sandbox),
|
|
15424
|
-
templateId ?
|
|
15698
|
+
templateId ? names2.get(templateId) ?? templateId : "-",
|
|
15425
15699
|
status(sandbox),
|
|
15700
|
+
...showSpot ? [spotWord(sandbox)] : [],
|
|
15426
15701
|
...showVm ? [sandbox["vmIsolation"] === true ? "yes" : "no"] : [],
|
|
15427
15702
|
...showOutbound ? [outbound(sandbox)] : [],
|
|
15428
15703
|
...showTags ? [Array.isArray(sandbox["tags"]) ? sandbox["tags"].join(",") : ""] : []
|
|
@@ -15551,8 +15826,8 @@ async function helpText() {
|
|
|
15551
15826
|
return `agental \u2014 Linux sandboxes for your agents
|
|
15552
15827
|
|
|
15553
15828
|
Setting up
|
|
15554
|
-
agental [--json] [--no-install] [--no-skills]
|
|
15555
|
-
agental sh [--json] [--no-install] [--no-skills]
|
|
15829
|
+
agental [--json] [--no-install] [--no-skills] [--no-mcp]
|
|
15830
|
+
agental sh [--json] [--no-install] [--no-skills] [--no-mcp]
|
|
15556
15831
|
agental login [--key]
|
|
15557
15832
|
agental logout
|
|
15558
15833
|
agental whoami [--json]
|
|
@@ -15561,6 +15836,7 @@ Setting up
|
|
|
15561
15836
|
|
|
15562
15837
|
Usage
|
|
15563
15838
|
agental create [--name <name>] [--template <template>] [--size tiny|small|medium|large] [--region <region>[,<region>...]] [--ttl <time> | --ttl default] [--on-timeout delete|stop|stop-with-memory] [--idempotency-key <key>]
|
|
15839
|
+
[--spot [--on-reclaim delete|stop|upgrade] [--warn-at <chance>]]
|
|
15564
15840
|
${operator ? "[--box <name-or-id>] " : ""}[--allow <address>[,<address>...]] [--egress box | residential:<country>[:sticky|rotating]] [--max-burst-fee <dollars>]
|
|
15565
15841
|
[--ssh-key <public-key-or-file>]... [--tag <tag>[,<tag>...]]... [--meta <key>=<value>]...
|
|
15566
15842
|
agental summary [--where '<words>'] [--tag <tag>[,<tag>...]]... [--meta <key>=<value>]... [--facets <field>[,<field>...]] [--json]
|
|
@@ -15586,6 +15862,7 @@ Usage
|
|
|
15586
15862
|
agental auto-stop <sandbox-id> [--in <time> | --at <date-time> | --never] [--json]
|
|
15587
15863
|
agental network <sandbox-id> [--allow <address>[,<address>...] | --none] [--json]
|
|
15588
15864
|
agental egress <sandbox-id> [box | residential <country> [sticky | rotating]] [--json]
|
|
15865
|
+
agental spot <sandbox-id> [off] [--on-reclaim delete|stop|upgrade] [--warn-at <chance>] [--json]
|
|
15589
15866
|
agental templates [--json]
|
|
15590
15867
|
agental template create <name> [--tag <tag>[,<tag>...]]... [--meta <key>=<value>]...
|
|
15591
15868
|
agental template show <template> [--json]
|
|
@@ -15704,12 +15981,13 @@ ${FILES_USAGE.map((line) => ` ${line}`).join("\n")}
|
|
|
15704
15981
|
agental browser <sandbox-id> [--headless | --headed] [--off] [--status]
|
|
15705
15982
|
${operator ? operator.OPERATOR_USAGE : ""}
|
|
15706
15983
|
With no command, as npx agental@latest runs it, agental signs in the first time on a computer,
|
|
15707
|
-
installs itself with npm where it stays on the PATH,
|
|
15708
|
-
agents it finds here
|
|
15984
|
+
installs itself with npm where it stays on the PATH, installs the agent skills for the coding
|
|
15985
|
+
agents it finds here, and adds agental's MCP server to them (Claude Code, Codex, Cursor, Windsurf,
|
|
15986
|
+
Gemini CLI and opencode), which each signs in to through the browser the first time. sh does the same, then makes a sandbox on your default template and opens a
|
|
15709
15987
|
shell in it over SSH. Run with no terminal, as an agent runs it, sh prints the commands to use the
|
|
15710
15988
|
sandbox with instead, and --json prints the sandbox as JSON. At your plan's limit it makes none:
|
|
15711
15989
|
in a terminal it offers to open your newest running sandbox instead, and otherwise lists them.
|
|
15712
|
-
--no-install leaves the command as it is, and --no-
|
|
15990
|
+
--no-install leaves the command as it is, --no-skills the skills, and --no-mcp the agents' MCP servers.
|
|
15713
15991
|
login signs in through the browser: the page asks you to allow this computer, and the command is
|
|
15714
15992
|
given an API key of its own, named CLI on <this computer>, which is in the console under API keys.
|
|
15715
15993
|
--key reads a key from standard input instead, for a computer with no browser.
|
|
@@ -15741,6 +16019,14 @@ start carries on where it was (after the account's first top-up: before it, refu
|
|
|
15741
16019
|
memory_needs_top_up); agental stop always keeps the disk. auto-stop
|
|
15742
16020
|
says when a running sandbox is to be stopped, with --in or --at moves that stop, later or sooner,
|
|
15743
16021
|
for the run under way, and with --never takes its time limit away, for this run and the next.
|
|
16022
|
+
create --spot makes a spot sandbox: half the list price, in room on our servers nobody else is
|
|
16023
|
+
paying for, taken back when a standard sandbox needs it. --on-reclaim says what is then done to it:
|
|
16024
|
+
stop (the default) stops it and keeps its disk, never its memory; delete deletes it; upgrade
|
|
16025
|
+
makes it a standard sandbox at the list price and keeps it running, where that frees what was
|
|
16026
|
+
needed, and stops it otherwise. It is not counted in the plan's running count, and comes with
|
|
16027
|
+
the account's first top-up. agental spot shows its chance of being stopped in the next minute, a
|
|
16028
|
+
hint and not a promise, and with --warn-at sets the chance at which sandbox.reclaim_chance is sent
|
|
16029
|
+
(0.5 when left out); agental spot <sandbox-id> off turns off spot: a standard sandbox from then on.
|
|
15744
16030
|
${operator ? operator.OPERATOR_HELP : ""}template network says what a sandbox on a template may reach outside itself, and with open,
|
|
15745
16031
|
blocked or allowlist sets it: everything, nothing, or only the addresses that follow, which are
|
|
15746
16032
|
IPv4 addresses and ranges such as 203.0.113.7 and 198.51.100.0/24. The rule that is given takes
|