agental 0.49.0 → 0.51.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 +578 -140
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3037,18 +3037,18 @@ var require_set = __commonJS({
|
|
|
3037
3037
|
}
|
|
3038
3038
|
static from(schema, iterable, ctx) {
|
|
3039
3039
|
const { replacer } = ctx;
|
|
3040
|
-
const
|
|
3040
|
+
const set3 = new this(schema);
|
|
3041
3041
|
if (iterable && Symbol.iterator in Object(iterable))
|
|
3042
3042
|
for (let value of iterable) {
|
|
3043
3043
|
if (typeof replacer === "function")
|
|
3044
3044
|
value = replacer.call(iterable, value, value);
|
|
3045
|
-
|
|
3045
|
+
set3.items.push(Pair.createPair(value, null, ctx));
|
|
3046
3046
|
}
|
|
3047
|
-
return
|
|
3047
|
+
return set3;
|
|
3048
3048
|
}
|
|
3049
3049
|
};
|
|
3050
3050
|
YAMLSet.tag = "tag:yaml.org,2002:set";
|
|
3051
|
-
var
|
|
3051
|
+
var set2 = {
|
|
3052
3052
|
collection: "map",
|
|
3053
3053
|
identify: (value) => value instanceof Set,
|
|
3054
3054
|
nodeClass: YAMLSet,
|
|
@@ -3067,7 +3067,7 @@ var require_set = __commonJS({
|
|
|
3067
3067
|
}
|
|
3068
3068
|
};
|
|
3069
3069
|
exports.YAMLSet = YAMLSet;
|
|
3070
|
-
exports.set =
|
|
3070
|
+
exports.set = set2;
|
|
3071
3071
|
}
|
|
3072
3072
|
});
|
|
3073
3073
|
|
|
@@ -3174,7 +3174,7 @@ var require_schema3 = __commonJS({
|
|
|
3174
3174
|
var merge = require_merge();
|
|
3175
3175
|
var omap = require_omap();
|
|
3176
3176
|
var pairs = require_pairs();
|
|
3177
|
-
var
|
|
3177
|
+
var set2 = require_set();
|
|
3178
3178
|
var timestamp = require_timestamp();
|
|
3179
3179
|
var schema = [
|
|
3180
3180
|
map.map,
|
|
@@ -3194,7 +3194,7 @@ var require_schema3 = __commonJS({
|
|
|
3194
3194
|
merge.merge,
|
|
3195
3195
|
omap.omap,
|
|
3196
3196
|
pairs.pairs,
|
|
3197
|
-
|
|
3197
|
+
set2.set,
|
|
3198
3198
|
timestamp.intTime,
|
|
3199
3199
|
timestamp.floatTime,
|
|
3200
3200
|
timestamp.timestamp
|
|
@@ -3221,7 +3221,7 @@ var require_tags = __commonJS({
|
|
|
3221
3221
|
var omap = require_omap();
|
|
3222
3222
|
var pairs = require_pairs();
|
|
3223
3223
|
var schema$2 = require_schema3();
|
|
3224
|
-
var
|
|
3224
|
+
var set2 = require_set();
|
|
3225
3225
|
var timestamp = require_timestamp();
|
|
3226
3226
|
var schemas = /* @__PURE__ */ new Map([
|
|
3227
3227
|
["core", schema.schema],
|
|
@@ -3247,7 +3247,7 @@ var require_tags = __commonJS({
|
|
|
3247
3247
|
omap: omap.omap,
|
|
3248
3248
|
pairs: pairs.pairs,
|
|
3249
3249
|
seq: seq.seq,
|
|
3250
|
-
set:
|
|
3250
|
+
set: set2.set,
|
|
3251
3251
|
timestamp: timestamp.timestamp
|
|
3252
3252
|
};
|
|
3253
3253
|
var coreKnownTags = {
|
|
@@ -3255,7 +3255,7 @@ var require_tags = __commonJS({
|
|
|
3255
3255
|
"tag:yaml.org,2002:merge": merge.merge,
|
|
3256
3256
|
"tag:yaml.org,2002:omap": omap.omap,
|
|
3257
3257
|
"tag:yaml.org,2002:pairs": pairs.pairs,
|
|
3258
|
-
"tag:yaml.org,2002:set":
|
|
3258
|
+
"tag:yaml.org,2002:set": set2.set,
|
|
3259
3259
|
"tag:yaml.org,2002:timestamp": timestamp.timestamp
|
|
3260
3260
|
};
|
|
3261
3261
|
function getTags(customTags, schemaName, addMergeTag) {
|
|
@@ -6363,15 +6363,15 @@ var require_parser = __commonJS({
|
|
|
6363
6363
|
var node_process = __require("process");
|
|
6364
6364
|
var cst = require_cst();
|
|
6365
6365
|
var lexer = require_lexer();
|
|
6366
|
-
function includesToken(
|
|
6367
|
-
for (let i = 0; i <
|
|
6368
|
-
if (
|
|
6366
|
+
function includesToken(list5, type) {
|
|
6367
|
+
for (let i = 0; i < list5.length; ++i)
|
|
6368
|
+
if (list5[i].type === type)
|
|
6369
6369
|
return true;
|
|
6370
6370
|
return false;
|
|
6371
6371
|
}
|
|
6372
|
-
function findNonEmptyIndex(
|
|
6373
|
-
for (let i = 0; i <
|
|
6374
|
-
switch (
|
|
6372
|
+
function findNonEmptyIndex(list5) {
|
|
6373
|
+
for (let i = 0; i < list5.length; ++i) {
|
|
6374
|
+
switch (list5[i].type) {
|
|
6375
6375
|
case "space":
|
|
6376
6376
|
case "comment":
|
|
6377
6377
|
case "newline":
|
|
@@ -7411,7 +7411,7 @@ import { parseArgs } from "node:util";
|
|
|
7411
7411
|
|
|
7412
7412
|
// ../src/cli-build.ts
|
|
7413
7413
|
var PUBLISHED = true;
|
|
7414
|
-
var CLI_VERSION = true ? "0.
|
|
7414
|
+
var CLI_VERSION = true ? "0.51.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}`;
|
|
@@ -7905,6 +7905,8 @@ var KEY_ACTIONS = [
|
|
|
7905
7905
|
"network.write",
|
|
7906
7906
|
"secret.read",
|
|
7907
7907
|
"secret.write",
|
|
7908
|
+
"tailscale.read",
|
|
7909
|
+
"tailscale.write",
|
|
7908
7910
|
"email.read",
|
|
7909
7911
|
"email.send",
|
|
7910
7912
|
"email.manage",
|
|
@@ -7969,8 +7971,8 @@ function keyOf(body) {
|
|
|
7969
7971
|
throw new Error("The answer was not an API key.");
|
|
7970
7972
|
}
|
|
7971
7973
|
const key2 = body;
|
|
7972
|
-
const
|
|
7973
|
-
return { ...key2, actions:
|
|
7974
|
+
const list5 = (value) => Array.isArray(value) ? value.map(String) : [];
|
|
7975
|
+
return { ...key2, actions: list5(key2.actions), sandboxIds: list5(key2.sandboxIds), templateIds: list5(key2.templateIds), allowFrom: list5(key2.allowFrom) };
|
|
7974
7976
|
}
|
|
7975
7977
|
function keysOf(body) {
|
|
7976
7978
|
const listed2 = body?.apiKeys;
|
|
@@ -8303,7 +8305,7 @@ async function pushRequest(base, ask13) {
|
|
|
8303
8305
|
async function listen() {
|
|
8304
8306
|
let arrived = () => {
|
|
8305
8307
|
};
|
|
8306
|
-
let
|
|
8308
|
+
let answer4 = () => {
|
|
8307
8309
|
};
|
|
8308
8310
|
const next = new Promise((resolve) => arrived = resolve);
|
|
8309
8311
|
let taken = false;
|
|
@@ -8318,7 +8320,7 @@ async function listen() {
|
|
|
8318
8320
|
return;
|
|
8319
8321
|
}
|
|
8320
8322
|
taken = true;
|
|
8321
|
-
|
|
8323
|
+
answer4 = (to) => response.writeHead(302, { location: to, "cache-control": "no-store" }).end();
|
|
8322
8324
|
arrived(url);
|
|
8323
8325
|
});
|
|
8324
8326
|
await new Promise((resolve, reject) => {
|
|
@@ -8326,7 +8328,7 @@ async function listen() {
|
|
|
8326
8328
|
server2.listen(0, "127.0.0.1", resolve);
|
|
8327
8329
|
});
|
|
8328
8330
|
const { port } = server2.address();
|
|
8329
|
-
return { server: server2, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) =>
|
|
8331
|
+
return { server: server2, redirectUri: `http://127.0.0.1:${port}/callback`, next, answer: (to) => answer4(to) };
|
|
8330
8332
|
}
|
|
8331
8333
|
async function browserSignIn(base, term, organizationId) {
|
|
8332
8334
|
const verifier = randomBytes2(32).toString("base64url");
|
|
@@ -8691,8 +8693,8 @@ function claudeDesktopHere(places, platform = process.platform, env = process.en
|
|
|
8691
8693
|
function addToClaudeLink(url) {
|
|
8692
8694
|
return `https://claude.ai/customize/connectors?modal=add-custom-connector&connectorName=${CONNECTOR_NAME}&connectorUrl=${encodeURIComponent(url)}`;
|
|
8693
8695
|
}
|
|
8694
|
-
function names(
|
|
8695
|
-
return
|
|
8696
|
+
function names(list5) {
|
|
8697
|
+
return list5.length < 2 ? list5[0] ?? "" : `${list5.slice(0, -1).join(", ")} and ${list5.at(-1)}`;
|
|
8696
8698
|
}
|
|
8697
8699
|
async function ensureConnector(site2, places = placesFrom()) {
|
|
8698
8700
|
const url = `${site2}/v1/mcp`;
|
|
@@ -8994,9 +8996,9 @@ async function api(base, key2, method, pathname, body, headers = {}) {
|
|
|
8994
8996
|
}
|
|
8995
8997
|
return { status: response.status, body: parsed && typeof parsed === "object" ? parsed : {} };
|
|
8996
8998
|
}
|
|
8997
|
-
function errorOf(
|
|
8998
|
-
const error =
|
|
8999
|
-
return { code: String(error["code"] ?? `http_${
|
|
8999
|
+
function errorOf(answer4) {
|
|
9000
|
+
const error = answer4.body["error"] && typeof answer4.body["error"] === "object" ? answer4.body["error"] : {};
|
|
9001
|
+
return { code: String(error["code"] ?? `http_${answer4.status}`), message: String(error["message"] ?? `HTTP ${answer4.status}`) };
|
|
9000
9002
|
}
|
|
9001
9003
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9002
9004
|
function real(file) {
|
|
@@ -9613,6 +9615,18 @@ var COMMANDS = [
|
|
|
9613
9615
|
["--json", "print as JSON"]
|
|
9614
9616
|
]
|
|
9615
9617
|
},
|
|
9618
|
+
{
|
|
9619
|
+
name: "secret",
|
|
9620
|
+
summary: "Keep your organization's secrets, sealed on this machine before they are sent, and give them to templates and sandboxes.",
|
|
9621
|
+
examples: ["agental secret set GITHUB_TOKEN --host api.github.com,github.com", "agental secret use GITHUB_TOKEN --template default", "agental secret list"],
|
|
9622
|
+
flags: [
|
|
9623
|
+
["--host <host>[,<host>...]", "set, seal: the hosts its value may go to, and no other"],
|
|
9624
|
+
["--template <template>", "use, unuse: the template whose sandboxes see it"],
|
|
9625
|
+
["--sandbox <sandbox-id>", "use, unuse: the one sandbox that sees it"],
|
|
9626
|
+
["--yes", "delete: go on without asking"],
|
|
9627
|
+
["--json", "print as JSON"]
|
|
9628
|
+
]
|
|
9629
|
+
},
|
|
9616
9630
|
{ name: "jobs", summary: "List your jobs, or one sandbox's, or one template's." },
|
|
9617
9631
|
{
|
|
9618
9632
|
name: "job",
|
|
@@ -10473,12 +10487,12 @@ async function organizations(client) {
|
|
|
10473
10487
|
const me = await ask5(client, "GET", "/v1/me");
|
|
10474
10488
|
return { organizations: Array.isArray(listed2) ? listed2 : [], acting: String(me["activeOrganizationId"] ?? "") };
|
|
10475
10489
|
}
|
|
10476
|
-
function organizationNamed(
|
|
10477
|
-
const byId =
|
|
10490
|
+
function organizationNamed(list5, given) {
|
|
10491
|
+
const byId = list5.find((organization) => organization.id === given);
|
|
10478
10492
|
if (byId) {
|
|
10479
10493
|
return byId;
|
|
10480
10494
|
}
|
|
10481
|
-
const byName =
|
|
10495
|
+
const byName = list5.filter((organization) => organization.name.toLowerCase() === given.toLowerCase());
|
|
10482
10496
|
if (byName.length === 1 && byName[0]) {
|
|
10483
10497
|
return byName[0];
|
|
10484
10498
|
}
|
|
@@ -10491,14 +10505,14 @@ async function org(client, positionals, options, signInTo) {
|
|
|
10491
10505
|
const [verb = "list", ...rest] = positionals;
|
|
10492
10506
|
switch (verb) {
|
|
10493
10507
|
case "list": {
|
|
10494
|
-
const { organizations:
|
|
10508
|
+
const { organizations: list5, acting } = await organizations(client);
|
|
10495
10509
|
if (options.json) {
|
|
10496
|
-
print2(true, { organizations:
|
|
10510
|
+
print2(true, { organizations: list5.map((organization) => ({ ...organization, acting: organization.id === acting })) }, "");
|
|
10497
10511
|
return;
|
|
10498
10512
|
}
|
|
10499
10513
|
process.stdout.write(` ${[pad("ID", 22), pad("NAME", 24), "ROLE"].join(" ")}
|
|
10500
10514
|
`);
|
|
10501
|
-
for (const organization of
|
|
10515
|
+
for (const organization of list5) {
|
|
10502
10516
|
const role = organization.personal ? "your own" : organization.role ?? "";
|
|
10503
10517
|
process.stdout.write(`${organization.id === acting ? "*" : " "} ${[pad(organization.id, 22), pad(organization.name, 24), role].join(" ")}
|
|
10504
10518
|
`);
|
|
@@ -10511,8 +10525,8 @@ async function org(client, positionals, options, signInTo) {
|
|
|
10511
10525
|
if (!given) {
|
|
10512
10526
|
throw new Error("org use takes the organization's id or name: agental org use Acme.");
|
|
10513
10527
|
}
|
|
10514
|
-
const { organizations:
|
|
10515
|
-
const chosen = organizationNamed(
|
|
10528
|
+
const { organizations: list5, acting } = await organizations(client);
|
|
10529
|
+
const chosen = organizationNamed(list5, given);
|
|
10516
10530
|
if (chosen.id === acting) {
|
|
10517
10531
|
process.stdout.write(`This command's key acts in ${chosen.name} already.
|
|
10518
10532
|
`);
|
|
@@ -10542,15 +10556,15 @@ agental org use ${organization.id} signs this command in to it.
|
|
|
10542
10556
|
}
|
|
10543
10557
|
}
|
|
10544
10558
|
async function actingTeam(client) {
|
|
10545
|
-
const { organizations:
|
|
10546
|
-
const team =
|
|
10559
|
+
const { organizations: list5, acting } = await organizations(client);
|
|
10560
|
+
const team = list5.find((organization) => organization.id === acting);
|
|
10547
10561
|
if (!team) {
|
|
10548
10562
|
throw new Error("This command's key acts in no organization you are in. agental org use <organization> signs it in to one.");
|
|
10549
10563
|
}
|
|
10550
10564
|
return team;
|
|
10551
10565
|
}
|
|
10552
|
-
function memberNamed(
|
|
10553
|
-
const found =
|
|
10566
|
+
function memberNamed(list5, given) {
|
|
10567
|
+
const found = list5.find((member) => member.userId === given || member.email?.toLowerCase() === given.toLowerCase());
|
|
10554
10568
|
if (!found) {
|
|
10555
10569
|
throw new Error(`No member ${given} in this team. agental members lists them.`);
|
|
10556
10570
|
}
|
|
@@ -10560,7 +10574,7 @@ async function members(client, positionals, options) {
|
|
|
10560
10574
|
const [verb = "list", target] = positionals;
|
|
10561
10575
|
const team = await actingTeam(client);
|
|
10562
10576
|
const listed2 = await ask5(client, "GET", `/v1/organizations/${encodeURIComponent(team.id)}/members`);
|
|
10563
|
-
const
|
|
10577
|
+
const list5 = Array.isArray(listed2["members"]) ? listed2["members"] : [];
|
|
10564
10578
|
switch (verb) {
|
|
10565
10579
|
case "list": {
|
|
10566
10580
|
if (options.json) {
|
|
@@ -10572,7 +10586,7 @@ async function members(client, positionals, options) {
|
|
|
10572
10586
|
`);
|
|
10573
10587
|
process.stdout.write(`${[pad("ID", 34), pad("EMAIL", 30), pad("ROLE", 8), "ADDED"].join(" ")}
|
|
10574
10588
|
`);
|
|
10575
|
-
for (const member of
|
|
10589
|
+
for (const member of list5) {
|
|
10576
10590
|
process.stdout.write(`${[pad(member.userId, 34), pad(member.email ?? member.name ?? "", 30), pad(member.role, 8), member.addedAt.slice(0, 10)].join(" ")}
|
|
10577
10591
|
`);
|
|
10578
10592
|
}
|
|
@@ -10582,7 +10596,7 @@ async function members(client, positionals, options) {
|
|
|
10582
10596
|
if (!target) {
|
|
10583
10597
|
throw new Error("members remove takes the member's id or email: agental members remove cy@example.com.");
|
|
10584
10598
|
}
|
|
10585
|
-
const member = memberNamed(
|
|
10599
|
+
const member = memberNamed(list5, target);
|
|
10586
10600
|
const query = options.revokeKeys ? "?revokeKeys=true" : "";
|
|
10587
10601
|
const removed = await ask5(client, "DELETE", `/v1/organizations/${encodeURIComponent(team.id)}/members/${encodeURIComponent(member.userId)}${query}`);
|
|
10588
10602
|
const revoked = Number(removed["revokedKeys"] ?? 0);
|
|
@@ -10864,15 +10878,15 @@ function jobInputsOf(options) {
|
|
|
10864
10878
|
return void 0;
|
|
10865
10879
|
}
|
|
10866
10880
|
const inputs = {};
|
|
10867
|
-
const add = (given,
|
|
10881
|
+
const add = (given, secret2) => {
|
|
10868
10882
|
const [name, value] = pairOf(given);
|
|
10869
10883
|
if (name === "") {
|
|
10870
|
-
throw new Error(`${
|
|
10884
|
+
throw new Error(`${secret2 ? "--secret-input" : "--input"} is NAME=DEFAULT, or NAME for one a run must be given: ${given} has no name.`);
|
|
10871
10885
|
}
|
|
10872
10886
|
if (Object.hasOwn(inputs, name)) {
|
|
10873
10887
|
throw new Error(`The input ${name} is given twice.`);
|
|
10874
10888
|
}
|
|
10875
|
-
inputs[name] =
|
|
10889
|
+
inputs[name] = secret2 ? { default: value, secret: true } : value;
|
|
10876
10890
|
};
|
|
10877
10891
|
for (const given of options.input ?? []) {
|
|
10878
10892
|
add(given, false);
|
|
@@ -11323,11 +11337,11 @@ function signatureOf(trigger2) {
|
|
|
11323
11337
|
}
|
|
11324
11338
|
}
|
|
11325
11339
|
var addressOf = (trigger2) => trigger2.url ?? "none: this API serves no addresses";
|
|
11326
|
-
function printTrigger(trigger2,
|
|
11340
|
+
function printTrigger(trigger2, secret2) {
|
|
11327
11341
|
const rows = [
|
|
11328
11342
|
["id", trigger2.id],
|
|
11329
11343
|
["address", addressOf(trigger2)],
|
|
11330
|
-
...
|
|
11344
|
+
...secret2 === void 0 ? [] : [["secret", `${secret2} (shown this once: keep it now)`]],
|
|
11331
11345
|
["signature", signatureOf(trigger2)],
|
|
11332
11346
|
["respond", trigger2.respond === "wait" ? "wait: a call is held until the run ends, up to 60 s" : "accepted: a call is answered at once with its run's id"],
|
|
11333
11347
|
["rate", `${trigger2.ratePerMinute} calls a minute`],
|
|
@@ -12431,11 +12445,11 @@ async function offload(client, words2, options) {
|
|
|
12431
12445
|
return;
|
|
12432
12446
|
}
|
|
12433
12447
|
const enabled = turn === void 0 ? (await ask8(client, "GET", "/v1/offload")).enabled : turn === "on";
|
|
12434
|
-
const
|
|
12448
|
+
const set2 = await ask8(client, "PUT", "/v1/offload", { enabled, ...overPercent === void 0 ? {} : { overPercent } });
|
|
12435
12449
|
if (options.json) {
|
|
12436
|
-
printJson2(
|
|
12450
|
+
printJson2(set2);
|
|
12437
12451
|
} else {
|
|
12438
|
-
sayOffload(
|
|
12452
|
+
sayOffload(set2);
|
|
12439
12453
|
}
|
|
12440
12454
|
}
|
|
12441
12455
|
async function coreDays(client, options) {
|
|
@@ -12793,9 +12807,9 @@ function describe4(webhook2) {
|
|
|
12793
12807
|
""
|
|
12794
12808
|
].join("\n");
|
|
12795
12809
|
}
|
|
12796
|
-
function saySecret(
|
|
12797
|
-
if (
|
|
12798
|
-
process.stdout.write(`secret: ${
|
|
12810
|
+
function saySecret(secret2) {
|
|
12811
|
+
if (secret2) {
|
|
12812
|
+
process.stdout.write(`secret: ${secret2}
|
|
12799
12813
|
`);
|
|
12800
12814
|
process.stderr.write("The signing secret is shown this once. Keep it where your receiver checks the X-Agental-Signature of each post.\n");
|
|
12801
12815
|
}
|
|
@@ -13222,16 +13236,16 @@ async function snapshot(client, positionals, options) {
|
|
|
13222
13236
|
if (found.kept === STORAGE_ONLY) {
|
|
13223
13237
|
process.stderr.write("Its server no longer holds it: it is fetched from storage first, which takes a few minutes.\n");
|
|
13224
13238
|
}
|
|
13225
|
-
const
|
|
13239
|
+
const answer4 = await ask10(client, "POST", `/v1/sandboxes/${encodeURIComponent(found.sandboxId)}/restore`, {
|
|
13226
13240
|
headers: { "Idempotency-Key": options.idempotencyKey ?? `cli-${randomUUID2()}` },
|
|
13227
13241
|
body: { snapshotId: found.id }
|
|
13228
13242
|
});
|
|
13229
13243
|
if (options.json) {
|
|
13230
|
-
process.stdout.write(`${JSON.stringify(
|
|
13244
|
+
process.stdout.write(`${JSON.stringify(answer4, null, 2)}
|
|
13231
13245
|
`);
|
|
13232
13246
|
return;
|
|
13233
13247
|
}
|
|
13234
|
-
const read2 =
|
|
13248
|
+
const read2 = answer4;
|
|
13235
13249
|
const discarded = Array.isArray(read2?.discarded) ? read2.discarded.map(String) : [];
|
|
13236
13250
|
const status = typeof read2?.sandbox?.status === "string" ? `, and ${read2.sandbox.status}` : "";
|
|
13237
13251
|
process.stdout.write(`${sandbox} is as it was at ${found.name}${status}.
|
|
@@ -13260,8 +13274,379 @@ async function snapshot(client, positionals, options) {
|
|
|
13260
13274
|
}
|
|
13261
13275
|
}
|
|
13262
13276
|
|
|
13277
|
+
// ../sdk/typescript/src/sealed.ts
|
|
13278
|
+
var SEALED_SUITE = "x25519-hkdf-sha256-aes256gcm";
|
|
13279
|
+
var ROOT_PUBLIC_KEYS = [];
|
|
13280
|
+
var SEALED_PURPOSES = ["variable", "tailscale-oauth"];
|
|
13281
|
+
var KEM_ID = 32;
|
|
13282
|
+
var KDF_ID = 1;
|
|
13283
|
+
var AEAD_ID = 2;
|
|
13284
|
+
var INFO = "agental sealed secret v1";
|
|
13285
|
+
var AAD_LABEL = "agental sealed secret aad v1";
|
|
13286
|
+
var KEY_MESSAGE_LABEL = "agental sealing key v1";
|
|
13287
|
+
var SealingError = class extends Error {
|
|
13288
|
+
name = "SealingError";
|
|
13289
|
+
};
|
|
13290
|
+
async function seal(key2, secret2, roots = ROOT_PUBLIC_KEYS) {
|
|
13291
|
+
await verifySealingKey(key2, roots);
|
|
13292
|
+
const ephemeral = await subtle().generateKey({ name: "X25519" }, true, ["deriveBits"]);
|
|
13293
|
+
return sealWith(key2, secret2, ephemeral);
|
|
13294
|
+
}
|
|
13295
|
+
async function verifySealingKey(key2, roots = ROOT_PUBLIC_KEYS) {
|
|
13296
|
+
if (key2.suite !== SEALED_SUITE) throw new SealingError(`sealing key ${key2.kid} is for suite ${key2.suite}, not ${SEALED_SUITE}`);
|
|
13297
|
+
if ([key2.kid, key2.owner, key2.publicKey, key2.signature].some((field) => !field || /[\n\u0000]/.test(field))) {
|
|
13298
|
+
throw new SealingError(`sealing key ${key2.kid} has an empty field or one holding a newline`);
|
|
13299
|
+
}
|
|
13300
|
+
const publicKey2 = fromBase64url(key2.publicKey);
|
|
13301
|
+
if (publicKey2.length !== 32) throw new SealingError(`sealing key ${key2.kid} is not a 32-byte X25519 key`);
|
|
13302
|
+
if (key2.kid !== await sealingKeyId(publicKey2)) throw new SealingError(`sealing key ${key2.kid} does not have the id its public key gives`);
|
|
13303
|
+
if (roots.length === 0) throw new SealingError("no root key is known yet, so no sealing key can be trusted");
|
|
13304
|
+
const message = utf8(sealingKeyMessage(key2));
|
|
13305
|
+
const signature = fromBase64url(key2.signature);
|
|
13306
|
+
for (const root of roots) {
|
|
13307
|
+
let rootKey;
|
|
13308
|
+
try {
|
|
13309
|
+
rootKey = await subtle().importKey("raw", fromBase64url(root), { name: "Ed25519" }, false, ["verify"]);
|
|
13310
|
+
} catch {
|
|
13311
|
+
continue;
|
|
13312
|
+
}
|
|
13313
|
+
if (await subtle().verify({ name: "Ed25519" }, rootKey, signature, message)) return;
|
|
13314
|
+
}
|
|
13315
|
+
throw new SealingError(`sealing key ${key2.kid} is not signed by agental's root key`);
|
|
13316
|
+
}
|
|
13317
|
+
function sealingKeyMessage(key2) {
|
|
13318
|
+
return [KEY_MESSAGE_LABEL, key2.kid, key2.suite, key2.owner, key2.publicKey].join("\n");
|
|
13319
|
+
}
|
|
13320
|
+
async function sealingKeyId(publicKey2) {
|
|
13321
|
+
const digest = new Uint8Array(await subtle().digest("SHA-256", publicKey2));
|
|
13322
|
+
return `sk_${[...digest.subarray(0, 12)].map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
13323
|
+
}
|
|
13324
|
+
function sealedAad(org2, name) {
|
|
13325
|
+
return utf8(`${AAD_LABEL}\0${org2}\0${name}`);
|
|
13326
|
+
}
|
|
13327
|
+
async function sealWith(key2, secret2, ephemeral) {
|
|
13328
|
+
checkSecret(key2, secret2);
|
|
13329
|
+
const recipient = await subtle().importKey("raw", fromBase64url(key2.publicKey), { name: "X25519" }, false, []);
|
|
13330
|
+
const dh = new Uint8Array(await subtle().deriveBits({ name: "X25519", public: recipient }, ephemeral.privateKey, 256));
|
|
13331
|
+
const enc = new Uint8Array(await subtle().exportKey("raw", ephemeral.publicKey));
|
|
13332
|
+
const sharedSecret = await kemSharedSecret(dh, enc, fromBase64url(key2.publicKey));
|
|
13333
|
+
const { aeadKey, baseNonce } = await keySchedule(sharedSecret, utf8(INFO));
|
|
13334
|
+
const plaintext = utf8(
|
|
13335
|
+
JSON.stringify({
|
|
13336
|
+
value: secret2.value,
|
|
13337
|
+
hosts: secret2.hosts,
|
|
13338
|
+
org: secret2.org,
|
|
13339
|
+
name: secret2.name,
|
|
13340
|
+
purpose: secret2.purpose ?? "variable",
|
|
13341
|
+
sealedAt: secret2.sealedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
13342
|
+
})
|
|
13343
|
+
);
|
|
13344
|
+
const aes = await subtle().importKey("raw", aeadKey, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
13345
|
+
const ct = new Uint8Array(
|
|
13346
|
+
await subtle().encrypt({ name: "AES-GCM", iv: baseNonce, additionalData: sealedAad(secret2.org, secret2.name) }, aes, plaintext)
|
|
13347
|
+
);
|
|
13348
|
+
return { v: 1, kid: key2.kid, suite: SEALED_SUITE, enc: toBase64url(enc), ct: toBase64url(ct) };
|
|
13349
|
+
}
|
|
13350
|
+
function checkSecret(key2, secret2) {
|
|
13351
|
+
if (key2.owner !== "agental" && key2.owner !== secret2.org) {
|
|
13352
|
+
throw new SealingError(`sealing key ${key2.kid} holds ${key2.owner}'s secrets, not ${secret2.org}'s`);
|
|
13353
|
+
}
|
|
13354
|
+
if (!secret2.org || !secret2.name) throw new SealingError("a secret needs its organization and its name");
|
|
13355
|
+
if (secret2.purpose !== void 0 && !SEALED_PURPOSES.includes(secret2.purpose)) {
|
|
13356
|
+
throw new SealingError(`a secret is sealed for one of ${SEALED_PURPOSES.join(", ")}, not ${String(secret2.purpose)}`);
|
|
13357
|
+
}
|
|
13358
|
+
if (secret2.org.includes("\0") || secret2.name.includes("\0")) throw new SealingError("an organization or a name cannot hold a NUL");
|
|
13359
|
+
if (!Array.isArray(secret2.hosts) || secret2.hosts.length === 0) throw new SealingError("a secret needs at least one host it may be sent to");
|
|
13360
|
+
if (secret2.hosts.some((host) => typeof host !== "string" || host === "")) throw new SealingError("a host cannot be empty");
|
|
13361
|
+
if (/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(secret2.value)) {
|
|
13362
|
+
throw new SealingError("the value holds a broken character (a lone surrogate)");
|
|
13363
|
+
}
|
|
13364
|
+
}
|
|
13365
|
+
async function kemSharedSecret(dh, enc, recipientPublic) {
|
|
13366
|
+
const kemSuite = concat(utf8("KEM"), i2osp(KEM_ID, 2));
|
|
13367
|
+
const eaePrk = await labeledExtract(kemSuite, new Uint8Array(), "eae_prk", dh);
|
|
13368
|
+
return labeledExpand(kemSuite, eaePrk, "shared_secret", concat(enc, recipientPublic), 32);
|
|
13369
|
+
}
|
|
13370
|
+
async function keySchedule(sharedSecret, info) {
|
|
13371
|
+
const suite = concat(utf8("HPKE"), i2osp(KEM_ID, 2), i2osp(KDF_ID, 2), i2osp(AEAD_ID, 2));
|
|
13372
|
+
const pskIdHash = await labeledExtract(suite, new Uint8Array(), "psk_id_hash", new Uint8Array());
|
|
13373
|
+
const infoHash = await labeledExtract(suite, new Uint8Array(), "info_hash", info);
|
|
13374
|
+
const context = concat(new Uint8Array([0]), pskIdHash, infoHash);
|
|
13375
|
+
const secret2 = await labeledExtract(suite, sharedSecret, "secret", new Uint8Array());
|
|
13376
|
+
return {
|
|
13377
|
+
aeadKey: await labeledExpand(suite, secret2, "key", context, 32),
|
|
13378
|
+
baseNonce: await labeledExpand(suite, secret2, "base_nonce", context, 12)
|
|
13379
|
+
};
|
|
13380
|
+
}
|
|
13381
|
+
function labeledExtract(suite, salt, label, ikm) {
|
|
13382
|
+
return hkdfExtract(salt, concat(utf8("HPKE-v1"), suite, utf8(label), ikm));
|
|
13383
|
+
}
|
|
13384
|
+
function labeledExpand(suite, prk, label, info, length) {
|
|
13385
|
+
return hkdfExpand(prk, concat(i2osp(length, 2), utf8("HPKE-v1"), suite, utf8(label), info), length);
|
|
13386
|
+
}
|
|
13387
|
+
async function hkdfExtract(salt, ikm) {
|
|
13388
|
+
return hmac(salt.length > 0 ? salt : new Uint8Array(32), ikm);
|
|
13389
|
+
}
|
|
13390
|
+
async function hkdfExpand(prk, info, length) {
|
|
13391
|
+
const out = new Uint8Array(length);
|
|
13392
|
+
let block = new Uint8Array();
|
|
13393
|
+
for (let counter = 1, filled = 0; filled < length; counter++) {
|
|
13394
|
+
block = await hmac(prk, concat(block, info, new Uint8Array([counter])));
|
|
13395
|
+
out.set(block.subarray(0, Math.min(block.length, length - filled)), filled);
|
|
13396
|
+
filled += block.length;
|
|
13397
|
+
}
|
|
13398
|
+
return out;
|
|
13399
|
+
}
|
|
13400
|
+
async function hmac(key2, data) {
|
|
13401
|
+
const hmacKey = await subtle().importKey("raw", key2, { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
13402
|
+
return new Uint8Array(await subtle().sign("HMAC", hmacKey, data));
|
|
13403
|
+
}
|
|
13404
|
+
function subtle() {
|
|
13405
|
+
const webCrypto = globalThis.crypto?.subtle;
|
|
13406
|
+
if (!webCrypto) throw new SealingError("this runtime has no WebCrypto, so it cannot seal");
|
|
13407
|
+
return webCrypto;
|
|
13408
|
+
}
|
|
13409
|
+
function i2osp(value, length) {
|
|
13410
|
+
const out = new Uint8Array(length);
|
|
13411
|
+
for (let i = length - 1, v = value; i >= 0; i--, v >>>= 8) out[i] = v & 255;
|
|
13412
|
+
return out;
|
|
13413
|
+
}
|
|
13414
|
+
function concat(...parts) {
|
|
13415
|
+
const out = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
13416
|
+
let offset = 0;
|
|
13417
|
+
for (const part of parts) {
|
|
13418
|
+
out.set(part, offset);
|
|
13419
|
+
offset += part.length;
|
|
13420
|
+
}
|
|
13421
|
+
return out;
|
|
13422
|
+
}
|
|
13423
|
+
function utf8(text) {
|
|
13424
|
+
return new Uint8Array(new TextEncoder().encode(text));
|
|
13425
|
+
}
|
|
13426
|
+
function toBase64url(bytes4) {
|
|
13427
|
+
let binary = "";
|
|
13428
|
+
for (const byte of bytes4) binary += String.fromCharCode(byte);
|
|
13429
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
13430
|
+
}
|
|
13431
|
+
function fromBase64url(text) {
|
|
13432
|
+
if (!/^[A-Za-z0-9_-]*$/.test(text) || text.length % 4 === 1) throw new SealingError("not base64url");
|
|
13433
|
+
const binary = atob(text.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - text.length % 4) % 4));
|
|
13434
|
+
return Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
13435
|
+
}
|
|
13436
|
+
|
|
13437
|
+
// ../src/cli-secret.ts
|
|
13438
|
+
var ROOT_KEYS = ["jNdFf3FKdbFQ5J-1e_NE7ZzuaNPRdci-mzlGj384Rmw"];
|
|
13439
|
+
var USAGE8 = "secret takes list, get, set, seal, delete, use or unuse. agental secret --help shows each.";
|
|
13440
|
+
var NAME = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
|
|
13441
|
+
var HOST = /^(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
13442
|
+
var SHORTEST_VALUE = 8;
|
|
13443
|
+
var MOST_HOSTS = 10;
|
|
13444
|
+
async function secret(client, positionals, options) {
|
|
13445
|
+
const [verb, ...args] = positionals;
|
|
13446
|
+
switch (verb) {
|
|
13447
|
+
case void 0:
|
|
13448
|
+
case "list":
|
|
13449
|
+
return list3(client, options);
|
|
13450
|
+
case "get":
|
|
13451
|
+
return get(client, nameOf2(args[0], "get"), options);
|
|
13452
|
+
case "set":
|
|
13453
|
+
return set(client, args[0], options);
|
|
13454
|
+
case "seal":
|
|
13455
|
+
return printSealed(client, args[0], options);
|
|
13456
|
+
case "delete":
|
|
13457
|
+
return remove2(client, nameOf2(args[0], "delete"), options);
|
|
13458
|
+
case "use":
|
|
13459
|
+
case "unuse":
|
|
13460
|
+
return use(client, verb === "use", nameOf2(args[0], verb), options);
|
|
13461
|
+
default:
|
|
13462
|
+
throw new Error(`agental secret ${verb} is not a command. ${USAGE8}`);
|
|
13463
|
+
}
|
|
13464
|
+
}
|
|
13465
|
+
async function list3(client, options) {
|
|
13466
|
+
const { secrets: secrets2 } = await answer2(client, "/v1/secrets", { method: "GET" });
|
|
13467
|
+
if (options.json) {
|
|
13468
|
+
process.stdout.write(`${JSON.stringify({ secrets: secrets2 }, null, 2)}
|
|
13469
|
+
`);
|
|
13470
|
+
return;
|
|
13471
|
+
}
|
|
13472
|
+
if (secrets2.length === 0) {
|
|
13473
|
+
process.stdout.write("No secrets. agental secret set <NAME> --host <host> keeps one.\n");
|
|
13474
|
+
return;
|
|
13475
|
+
}
|
|
13476
|
+
for (const s of secrets2) {
|
|
13477
|
+
process.stdout.write(`${s.name} ${s.hosts.join(",")} ${usedWords(s)}
|
|
13478
|
+
`);
|
|
13479
|
+
}
|
|
13480
|
+
}
|
|
13481
|
+
async function get(client, name, options) {
|
|
13482
|
+
const view = await answer2(client, `/v1/secrets/${encodeURIComponent(name)}`, { method: "GET" });
|
|
13483
|
+
if (options.json) {
|
|
13484
|
+
process.stdout.write(`${JSON.stringify(view, null, 2)}
|
|
13485
|
+
`);
|
|
13486
|
+
return;
|
|
13487
|
+
}
|
|
13488
|
+
process.stdout.write(
|
|
13489
|
+
`${view.name}
|
|
13490
|
+
goes to ${view.hosts.join(", ")}
|
|
13491
|
+
sealed to ${view.sealedTo.join(", ")}
|
|
13492
|
+
used by ${usedWords(view)}
|
|
13493
|
+
changed ${view.updatedAt}
|
|
13494
|
+
Its value is sealed, and nothing shows it: not the API, the console or this command.
|
|
13495
|
+
`
|
|
13496
|
+
);
|
|
13497
|
+
}
|
|
13498
|
+
async function set(client, given, options) {
|
|
13499
|
+
const { name, value, hosts } = await toSeal(client, given, options, "set");
|
|
13500
|
+
const { sealed, org: org2 } = await sealFor(client, name, value, hosts);
|
|
13501
|
+
const made = await client.request("/v1/secrets", { method: "POST", headers: JSON_HEADERS, body: JSON.stringify({ name, hosts, sealed }) });
|
|
13502
|
+
let view;
|
|
13503
|
+
if (made.ok) {
|
|
13504
|
+
view = await made.json();
|
|
13505
|
+
} else {
|
|
13506
|
+
const body = await made.json().catch(() => null);
|
|
13507
|
+
if (made.status !== 409 || codeOf(body) !== "secret_exists") {
|
|
13508
|
+
refused(client, made.status, body);
|
|
13509
|
+
}
|
|
13510
|
+
view = await answer2(client, `/v1/secrets/${encodeURIComponent(name)}`, { method: "PUT", headers: JSON_HEADERS, body: JSON.stringify({ hosts, sealed }) });
|
|
13511
|
+
}
|
|
13512
|
+
if (options.json) {
|
|
13513
|
+
process.stdout.write(`${JSON.stringify(view, null, 2)}
|
|
13514
|
+
`);
|
|
13515
|
+
return;
|
|
13516
|
+
}
|
|
13517
|
+
process.stdout.write(
|
|
13518
|
+
`Kept ${view.name} for the organization ${org2}, sealed here before it was sent; it goes only to ${view.hosts.join(", ")}. ${usedWords(view) === "nothing" ? `agental secret use ${view.name} --template <template> gives it to a template's sandboxes.` : `Used by ${usedWords(view)}.`}
|
|
13519
|
+
`
|
|
13520
|
+
);
|
|
13521
|
+
}
|
|
13522
|
+
async function printSealed(client, given, options) {
|
|
13523
|
+
const { name, value, hosts } = await toSeal(client, given, options, "seal");
|
|
13524
|
+
const { sealed, org: org2 } = await sealFor(client, name, value, hosts);
|
|
13525
|
+
process.stderr.write(`Sealed ${name} for the organization ${org2}.
|
|
13526
|
+
`);
|
|
13527
|
+
process.stdout.write(`${JSON.stringify(options.json ? { name, hosts, sealed } : sealed)}
|
|
13528
|
+
`);
|
|
13529
|
+
}
|
|
13530
|
+
async function remove2(client, name, options) {
|
|
13531
|
+
if (!options.yes && !await client.confirmed(`Delete the secret ${name}, and take it from every template and sandbox that uses it?`)) {
|
|
13532
|
+
throw new Error("Nothing was deleted. Give --yes to delete without asking.");
|
|
13533
|
+
}
|
|
13534
|
+
const { usedBy } = await answer2(client, `/v1/secrets/${encodeURIComponent(name)}`, { method: "DELETE" });
|
|
13535
|
+
if (options.json) {
|
|
13536
|
+
process.stdout.write(`${JSON.stringify({ deleted: name, usedBy }, null, 2)}
|
|
13537
|
+
`);
|
|
13538
|
+
return;
|
|
13539
|
+
}
|
|
13540
|
+
const from = usedBy.templates.length + usedBy.sandboxes.length;
|
|
13541
|
+
process.stdout.write(`Deleted ${name}${from > 0 ? `, and took it from ${usedWords({ usedBy })}` : ""}.
|
|
13542
|
+
`);
|
|
13543
|
+
}
|
|
13544
|
+
async function use(client, on, name, options) {
|
|
13545
|
+
if (options.template === void 0 === (options.sandbox === void 0)) {
|
|
13546
|
+
throw new Error(`secret ${on ? "use" : "unuse"} takes --template <template> or --sandbox <sandbox-id>, one of them.`);
|
|
13547
|
+
}
|
|
13548
|
+
const where = options.template !== void 0 ? { path: `/v1/templates/${encodeURIComponent(await client.templateId(options.template))}`, words: `the template ${options.template}` } : { path: `/v1/sandboxes/${encodeURIComponent(options.sandbox ?? "")}`, words: `the sandbox ${options.sandbox}` };
|
|
13549
|
+
const path6 = `${where.path}/secrets/${encodeURIComponent(name)}`;
|
|
13550
|
+
if (on) {
|
|
13551
|
+
const view = await answer2(client, path6, { method: "PUT" });
|
|
13552
|
+
process.stdout.write(options.json ? `${JSON.stringify(view, null, 2)}
|
|
13553
|
+
` : `${where.words} uses ${name}: its commands see the variable, and its value goes only to ${view.hosts.join(", ")}.
|
|
13554
|
+
`);
|
|
13555
|
+
return;
|
|
13556
|
+
}
|
|
13557
|
+
const res = await client.request(path6, { method: "DELETE" });
|
|
13558
|
+
if (!res.ok) {
|
|
13559
|
+
refused(client, res.status, await res.json().catch(() => null));
|
|
13560
|
+
}
|
|
13561
|
+
process.stdout.write(options.json ? `${JSON.stringify({ unused: name }, null, 2)}
|
|
13562
|
+
` : `${where.words} no longer uses ${name}.
|
|
13563
|
+
`);
|
|
13564
|
+
}
|
|
13565
|
+
async function toSeal(client, given, options, verb) {
|
|
13566
|
+
if (!given) {
|
|
13567
|
+
throw new Error(`secret ${verb} requires <NAME>, and --host: agental secret ${verb} GITHUB_TOKEN --host api.github.com`);
|
|
13568
|
+
}
|
|
13569
|
+
const at4 = given.indexOf("=");
|
|
13570
|
+
const name = nameOf2(at4 < 0 ? given : given.slice(0, at4), verb);
|
|
13571
|
+
const hosts = hostsOf(options.host, verb);
|
|
13572
|
+
const value = at4 < 0 ? await client.readValue(`${name}'s value (not shown): `) : given.slice(at4 + 1);
|
|
13573
|
+
if (value.length < SHORTEST_VALUE) {
|
|
13574
|
+
throw new Error(`${name}'s value is ${value.length} characters: a secret is at least ${SHORTEST_VALUE}, and the API cannot check a sealed one, so it is refused here.`);
|
|
13575
|
+
}
|
|
13576
|
+
return { name, value, hosts };
|
|
13577
|
+
}
|
|
13578
|
+
async function sealFor(client, name, value, hosts) {
|
|
13579
|
+
const { keys } = await answer2(client, "/v1/secrets/key", { method: "GET" });
|
|
13580
|
+
const org2 = String((await answer2(client, "/v1/me", { method: "GET" })).activeOrganizationId ?? "");
|
|
13581
|
+
if (!org2) {
|
|
13582
|
+
throw new Error("The API did not say which organization this key acts in, so nothing could be sealed for it.");
|
|
13583
|
+
}
|
|
13584
|
+
const mine = keys.filter((key2) => key2.owner === "agental");
|
|
13585
|
+
if (mine.length === 0) {
|
|
13586
|
+
throw new Error("The API publishes no key of agental's boxes, so nothing was sealed or sent.");
|
|
13587
|
+
}
|
|
13588
|
+
for (const key2 of mine) {
|
|
13589
|
+
await verifySealingKey(key2, client.roots ?? ROOT_KEYS);
|
|
13590
|
+
}
|
|
13591
|
+
const sealed = await Promise.all(mine.map((key2) => seal(key2, { value, hosts, org: org2, name, purpose: "variable" }, client.roots ?? ROOT_KEYS)));
|
|
13592
|
+
return { sealed, org: org2 };
|
|
13593
|
+
}
|
|
13594
|
+
function nameOf2(given, verb) {
|
|
13595
|
+
if (!given) {
|
|
13596
|
+
throw new Error(`secret ${verb} requires <NAME>`);
|
|
13597
|
+
}
|
|
13598
|
+
if (!NAME.test(given)) {
|
|
13599
|
+
throw new Error(`${given} is not a secret's name: letters, digits and _, not starting with a digit, up to 128.`);
|
|
13600
|
+
}
|
|
13601
|
+
return given;
|
|
13602
|
+
}
|
|
13603
|
+
function hostsOf(given, verb) {
|
|
13604
|
+
const hosts = (given ?? []).flatMap((h) => h.split(",")).map((h) => h.trim().toLowerCase()).filter((h) => h.length > 0);
|
|
13605
|
+
if (hosts.length === 0) {
|
|
13606
|
+
throw new Error(`secret ${verb} requires --host: the hosts its value may go to, as --host api.github.com`);
|
|
13607
|
+
}
|
|
13608
|
+
if (hosts.length > MOST_HOSTS) {
|
|
13609
|
+
throw new Error(`A secret goes to at most ${MOST_HOSTS} hosts, not ${hosts.length}.`);
|
|
13610
|
+
}
|
|
13611
|
+
for (const h of hosts) {
|
|
13612
|
+
if (!HOST.test(h)) {
|
|
13613
|
+
throw new Error(`${h} is not a host: a name such as api.github.com, or *.example.com.`);
|
|
13614
|
+
}
|
|
13615
|
+
}
|
|
13616
|
+
return [...new Set(hosts)];
|
|
13617
|
+
}
|
|
13618
|
+
function usedWords(view) {
|
|
13619
|
+
const t = view.usedBy.templates.length;
|
|
13620
|
+
const s = view.usedBy.sandboxes.length;
|
|
13621
|
+
if (t + s === 0) {
|
|
13622
|
+
return "nothing";
|
|
13623
|
+
}
|
|
13624
|
+
return [t > 0 ? `${t} template${t === 1 ? "" : "s"}` : "", s > 0 ? `${s} sandbox${s === 1 ? "" : "es"}` : ""].filter(Boolean).join(" and ");
|
|
13625
|
+
}
|
|
13626
|
+
function codeOf(body) {
|
|
13627
|
+
const error = body?.error;
|
|
13628
|
+
return typeof error?.code === "string" ? error.code : void 0;
|
|
13629
|
+
}
|
|
13630
|
+
var JSON_HEADERS = { "content-type": "application/json" };
|
|
13631
|
+
async function answer2(client, path6, init) {
|
|
13632
|
+
const res = await client.request(path6, init);
|
|
13633
|
+
const body = await res.json().catch(() => null);
|
|
13634
|
+
if (!res.ok) {
|
|
13635
|
+
refused(client, res.status, body);
|
|
13636
|
+
}
|
|
13637
|
+
return body;
|
|
13638
|
+
}
|
|
13639
|
+
function refused(client, status, body) {
|
|
13640
|
+
if (status === 403 && codeOf(body) === "key_reach_limited") {
|
|
13641
|
+
throw new Error(
|
|
13642
|
+
"This API key is held to some sandboxes or templates, and the account's secrets are the whole organization's: it cannot list, keep, change or give them. Use a key that reaches everything, or sign in with agental login."
|
|
13643
|
+
);
|
|
13644
|
+
}
|
|
13645
|
+
client.fail(status, body);
|
|
13646
|
+
}
|
|
13647
|
+
|
|
13263
13648
|
// ../src/cli-sites.ts
|
|
13264
|
-
var
|
|
13649
|
+
var USAGE9 = "site takes a sandbox, or list, add, rm, stats or analytics, then the sandbox. agental site --help shows each.";
|
|
13265
13650
|
var ANALYTICS_USAGE = "site analytics takes on or off, then the sandbox and the site's id, or org, with on or off to change it.";
|
|
13266
13651
|
var REPORT_ROWS = 5;
|
|
13267
13652
|
async function bodyOf2(response) {
|
|
@@ -13408,9 +13793,9 @@ async function organizationSwitch(client, words2, options) {
|
|
|
13408
13793
|
const put2 = (body) => client.request("/v1/site-analytics", { method: "PUT", body: JSON.stringify(body) });
|
|
13409
13794
|
let response = await put2({ enabled: turn === "on" });
|
|
13410
13795
|
let answered = await bodyOf2(response);
|
|
13411
|
-
const
|
|
13412
|
-
if (response.status === 409 &&
|
|
13413
|
-
process.stderr.write(`${
|
|
13796
|
+
const refused2 = answered?.error;
|
|
13797
|
+
if (response.status === 409 && refused2?.code === "notice_required") {
|
|
13798
|
+
process.stderr.write(`${refused2.message ?? ""}
|
|
13414
13799
|
`);
|
|
13415
13800
|
if (!options.informed) {
|
|
13416
13801
|
process.stderr.write("Nothing was changed. If your organization accepts this: agental site analytics org on --informed\n");
|
|
@@ -13450,13 +13835,13 @@ async function site(client, positionals, options) {
|
|
|
13450
13835
|
const verb = positionals[0] === "list" || positionals[0] === "add" || positionals[0] === "rm" || positionals[0] === "stats" ? positionals[0] : null;
|
|
13451
13836
|
const [sandbox, target, ...rest] = verb === null ? positionals : positionals.slice(1);
|
|
13452
13837
|
if (sandbox === void 0) {
|
|
13453
|
-
throw new Error(
|
|
13838
|
+
throw new Error(USAGE9);
|
|
13454
13839
|
}
|
|
13455
13840
|
switch (verb) {
|
|
13456
13841
|
case null:
|
|
13457
13842
|
case "list": {
|
|
13458
13843
|
if (target !== void 0) {
|
|
13459
|
-
throw new Error(
|
|
13844
|
+
throw new Error(USAGE9);
|
|
13460
13845
|
}
|
|
13461
13846
|
const sites = await sitesOf(client, sandbox);
|
|
13462
13847
|
if (options.json) {
|
|
@@ -13476,7 +13861,7 @@ async function site(client, positionals, options) {
|
|
|
13476
13861
|
}
|
|
13477
13862
|
case "add": {
|
|
13478
13863
|
if (rest.length > 0) {
|
|
13479
|
-
throw new Error(
|
|
13864
|
+
throw new Error(USAGE9);
|
|
13480
13865
|
}
|
|
13481
13866
|
const port = portFrom(target);
|
|
13482
13867
|
const made = routeOf(await ask11(client, "POST", `/v1/sandboxes/${encodeURIComponent(sandbox)}/host`, { port, title: `port-${port}`, public: true }));
|
|
@@ -13527,7 +13912,7 @@ async function site(client, positionals, options) {
|
|
|
13527
13912
|
}
|
|
13528
13913
|
|
|
13529
13914
|
// ../src/cli-claude.ts
|
|
13530
|
-
var
|
|
13915
|
+
var USAGE10 = "claude takes connect, show, update or disconnect. agental claude --help shows each.";
|
|
13531
13916
|
var KEY_VARIABLE = "ANTHROPIC_ENVIRONMENT_KEY";
|
|
13532
13917
|
var SECRET_VARIABLE = "ANTHROPIC_WEBHOOK_SIGNING_KEY";
|
|
13533
13918
|
async function ask12(client, method, pathname, body) {
|
|
@@ -13612,10 +13997,10 @@ async function hidden(question) {
|
|
|
13612
13997
|
const muted = lines;
|
|
13613
13998
|
process.stderr.write(question);
|
|
13614
13999
|
muted._writeToOutput = () => void 0;
|
|
13615
|
-
lines.question("", (
|
|
14000
|
+
lines.question("", (answer4) => {
|
|
13616
14001
|
lines.close();
|
|
13617
14002
|
process.stderr.write("\n");
|
|
13618
|
-
resolve(
|
|
14003
|
+
resolve(answer4.trim());
|
|
13619
14004
|
});
|
|
13620
14005
|
});
|
|
13621
14006
|
}
|
|
@@ -13642,7 +14027,7 @@ async function listClaude(client, asJson) {
|
|
|
13642
14027
|
async function claude(client, positionals, options) {
|
|
13643
14028
|
const [what, target, ...rest] = positionals;
|
|
13644
14029
|
if (rest.length > 0) {
|
|
13645
|
-
throw new Error(
|
|
14030
|
+
throw new Error(USAGE10);
|
|
13646
14031
|
}
|
|
13647
14032
|
switch (what) {
|
|
13648
14033
|
case "connect": {
|
|
@@ -13710,7 +14095,7 @@ async function claude(client, positionals, options) {
|
|
|
13710
14095
|
return;
|
|
13711
14096
|
}
|
|
13712
14097
|
default:
|
|
13713
|
-
throw new Error(
|
|
14098
|
+
throw new Error(USAGE10);
|
|
13714
14099
|
}
|
|
13715
14100
|
}
|
|
13716
14101
|
function needId2(id, what) {
|
|
@@ -13761,7 +14146,7 @@ function whyClosed(code, reason2, error) {
|
|
|
13761
14146
|
return `The terminal was closed (${code})${said ? `: ${said}` : ""}.`;
|
|
13762
14147
|
}
|
|
13763
14148
|
}
|
|
13764
|
-
async function
|
|
14149
|
+
async function answer3(response) {
|
|
13765
14150
|
const body = await response.json().catch(() => null);
|
|
13766
14151
|
if (!response.ok) {
|
|
13767
14152
|
const error = body?.error;
|
|
@@ -13770,7 +14155,7 @@ async function answer2(response) {
|
|
|
13770
14155
|
return body;
|
|
13771
14156
|
}
|
|
13772
14157
|
async function keptShells2(client, id) {
|
|
13773
|
-
const body = await
|
|
14158
|
+
const body = await answer3(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals`, { method: "GET" }));
|
|
13774
14159
|
if (!body || !Array.isArray(body.terminals)) {
|
|
13775
14160
|
throw new Error("The list of kept shells was missing terminals.");
|
|
13776
14161
|
}
|
|
@@ -13824,7 +14209,7 @@ async function listShells(client, id, json3, stdout) {
|
|
|
13824
14209
|
}
|
|
13825
14210
|
async function closeShell(client, id, given, stdout) {
|
|
13826
14211
|
const found = await shellNamed(client, id, given, "--close");
|
|
13827
|
-
await
|
|
14212
|
+
await answer3(await client.request(`/v1/sandboxes/${encodeURIComponent(id)}/terminals/${encodeURIComponent(found.id)}`, { method: "DELETE" }));
|
|
13828
14213
|
stdout.write(`Closed ${found.n === null ? "shell" : `shell ${found.n}`} (${found.id}).
|
|
13829
14214
|
`);
|
|
13830
14215
|
}
|
|
@@ -14534,7 +14919,7 @@ async function main() {
|
|
|
14534
14919
|
await create({ ...values, template: once(values.template, "--template") });
|
|
14535
14920
|
return;
|
|
14536
14921
|
case "list":
|
|
14537
|
-
await
|
|
14922
|
+
await list4(values.json, whereQuery(values.where ?? "", labelsFilter(values)), values.sort, values.limit, values.wide);
|
|
14538
14923
|
return;
|
|
14539
14924
|
case "bulk-actions":
|
|
14540
14925
|
await bulkActionsCommand(positionals.slice(1), values.json);
|
|
@@ -14570,7 +14955,7 @@ async function main() {
|
|
|
14570
14955
|
await bulk("delete", whereQuery(values.where, labelsFilter(values)), {}, values.yes === true, values.json, values.confirm);
|
|
14571
14956
|
return;
|
|
14572
14957
|
}
|
|
14573
|
-
await
|
|
14958
|
+
await remove3(positionals[1], values["pause-jobs"] === true);
|
|
14574
14959
|
return;
|
|
14575
14960
|
case "start":
|
|
14576
14961
|
if (values.where !== void 0) {
|
|
@@ -14617,31 +15002,31 @@ async function main() {
|
|
|
14617
15002
|
await files({ request, fail }, positionals.slice(1), { json: values.json, recursive: values.recursive === true });
|
|
14618
15003
|
return;
|
|
14619
15004
|
case "desktop": {
|
|
14620
|
-
const
|
|
15005
|
+
const use2 = DESKTOP_USES.filter((name) => values[name] !== void 0);
|
|
14621
15006
|
const shotOptions = { crop: values.crop, scale: values.scale, quality: values.quality, cursor: values["no-cursor"] === true ? false : void 0 };
|
|
14622
15007
|
const linkOptions = { expires: values.expires, keepStreams: values["keep-streams"] === true };
|
|
14623
15008
|
const treeOptions = { window: values.window, query: values.query, limit: values.limit };
|
|
14624
15009
|
const shaping = Object.values(shotOptions).some((value) => value !== void 0);
|
|
14625
15010
|
const linking = linkOptions.expires !== void 0 || linkOptions.keepStreams;
|
|
14626
15011
|
const narrowing = Object.values(treeOptions).some((value) => value !== void 0);
|
|
14627
|
-
if (
|
|
15012
|
+
if (use2.length === 0 && !shaping && !linking && !narrowing) {
|
|
14628
15013
|
await desktop(positionals[1], values.screen, values.off, values.status);
|
|
14629
|
-
} else if (
|
|
15014
|
+
} else if (use2.length !== 1 || values.screen !== void 0 || values.off || values.status) {
|
|
14630
15015
|
throw new Error(
|
|
14631
|
-
|
|
15016
|
+
use2.length === 0 ? "desktop takes --crop, --scale, --quality and --no-cursor with --screenshot, --window, --query and --limit with --tree, and --expires and --keep-streams with --link" : `desktop does one thing at a time: --${use2[0]} goes with no other of its options`
|
|
14632
15017
|
);
|
|
14633
|
-
} else if (shaping &&
|
|
15018
|
+
} else if (shaping && use2[0] !== "screenshot" || linking && use2[0] !== "link" || narrowing && use2[0] !== "tree") {
|
|
14634
15019
|
throw new Error(shaping ? "--crop, --scale, --quality and --no-cursor go with --screenshot" : linking ? "--expires and --keep-streams go with --link" : "--window, --query and --limit go with --tree");
|
|
14635
|
-
} else if (
|
|
15020
|
+
} else if (use2[0] === "tree") {
|
|
14636
15021
|
await desktopTree(positionals[1], treeOptions, values.json);
|
|
14637
|
-
} else if (
|
|
15022
|
+
} else if (use2[0] === "screenshot") {
|
|
14638
15023
|
await screenshot(positionals[1], values.screenshot, shotOptions);
|
|
14639
|
-
} else if (
|
|
15024
|
+
} else if (use2[0] === "clipboard" || use2[0] === "set-clipboard") {
|
|
14640
15025
|
await clipboard(positionals[1], values["set-clipboard"]);
|
|
14641
|
-
} else if (
|
|
14642
|
-
await desktopLinks(positionals[1],
|
|
15026
|
+
} else if (use2[0] === "link" || use2[0] === "links" || use2[0] === "unlink") {
|
|
15027
|
+
await desktopLinks(positionals[1], use2[0], values[use2[0]], linkOptions);
|
|
14643
15028
|
} else {
|
|
14644
|
-
await useDesktop(positionals[1],
|
|
15029
|
+
await useDesktop(positionals[1], use2[0], String(values[use2[0]]));
|
|
14645
15030
|
}
|
|
14646
15031
|
return;
|
|
14647
15032
|
}
|
|
@@ -14669,6 +15054,13 @@ async function main() {
|
|
|
14669
15054
|
case "secrets":
|
|
14670
15055
|
await secrets(positionals.slice(1), { ...values, template: once(values.template, "--template") });
|
|
14671
15056
|
return;
|
|
15057
|
+
case "secret":
|
|
15058
|
+
await secret(
|
|
15059
|
+
{ request, fail, confirmed, templateId: async (given) => (await templateNamed(given)).id, readValue: hiddenValue },
|
|
15060
|
+
positionals.slice(1),
|
|
15061
|
+
{ json: values.json, ...values.host === void 0 ? {} : { host: values.host }, template: once(values.template, "--template"), sandbox: once(values.sandbox, "--sandbox"), yes: values.yes === true }
|
|
15062
|
+
);
|
|
15063
|
+
return;
|
|
14672
15064
|
case "metrics":
|
|
14673
15065
|
await metrics(positionals[1], values);
|
|
14674
15066
|
return;
|
|
@@ -14868,12 +15260,12 @@ function regionsOption(given) {
|
|
|
14868
15260
|
const named = listedIn([given]);
|
|
14869
15261
|
return named.length === 1 ? { region: named[0] } : { regions: named };
|
|
14870
15262
|
}
|
|
14871
|
-
async function sshKeys(id, keyId,
|
|
15263
|
+
async function sshKeys(id, keyId, remove4, json3) {
|
|
14872
15264
|
if (!id) {
|
|
14873
15265
|
throw new Error("ssh-keys requires <sandbox-id>");
|
|
14874
15266
|
}
|
|
14875
15267
|
const path6 = `/v1/sandboxes/${encodeURIComponent(id)}/ssh/keys`;
|
|
14876
|
-
if (
|
|
15268
|
+
if (remove4) {
|
|
14877
15269
|
if (!keyId) {
|
|
14878
15270
|
throw new Error("ssh-keys --remove requires <key-id>, as ssh-keys lists it");
|
|
14879
15271
|
}
|
|
@@ -14950,7 +15342,7 @@ async function regions(asJson) {
|
|
|
14950
15342
|
}
|
|
14951
15343
|
process.stdout.write("* where a sandbox is made when no region is named\n");
|
|
14952
15344
|
}
|
|
14953
|
-
async function
|
|
15345
|
+
async function list4(asJson, filter, sort, limit, wide = false) {
|
|
14954
15346
|
const sandboxes2 = [];
|
|
14955
15347
|
let cursor = null;
|
|
14956
15348
|
do {
|
|
@@ -15076,6 +15468,52 @@ async function typedCount(count) {
|
|
|
15076
15468
|
lines.close();
|
|
15077
15469
|
}
|
|
15078
15470
|
}
|
|
15471
|
+
async function hiddenValue(prompt) {
|
|
15472
|
+
if (!process.stdin.isTTY) {
|
|
15473
|
+
process.stderr.write(`${prompt.replace(/: $/, "")}: read from stdin
|
|
15474
|
+
`);
|
|
15475
|
+
const chunks = [];
|
|
15476
|
+
for await (const chunk of process.stdin) {
|
|
15477
|
+
chunks.push(chunk);
|
|
15478
|
+
}
|
|
15479
|
+
return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
|
|
15480
|
+
}
|
|
15481
|
+
process.stderr.write(prompt);
|
|
15482
|
+
process.stdin.setEncoding("utf8");
|
|
15483
|
+
process.stdin.setRawMode(true);
|
|
15484
|
+
process.stdin.resume();
|
|
15485
|
+
try {
|
|
15486
|
+
let value = "";
|
|
15487
|
+
for await (const chunk of process.stdin) {
|
|
15488
|
+
const text = chunk;
|
|
15489
|
+
for (let i = 0; i < text.length; i++) {
|
|
15490
|
+
const ch = text[i] ?? "";
|
|
15491
|
+
if (ch === "\r" || ch === "\n") {
|
|
15492
|
+
if (text.slice(i + 1).replace(/^\n/, "").length > 0) {
|
|
15493
|
+
throw new Error("A value of more than one line was pasted: nothing was sealed or sent. Give such a value on stdin: agental secret set NAME --host \u2026 < file");
|
|
15494
|
+
}
|
|
15495
|
+
return value;
|
|
15496
|
+
}
|
|
15497
|
+
if (ch === "") {
|
|
15498
|
+
throw new Error("Nothing was sealed or sent.");
|
|
15499
|
+
}
|
|
15500
|
+
if (ch === "\x7F" || ch === "\b") {
|
|
15501
|
+
value = [...value].slice(0, -1).join("");
|
|
15502
|
+
continue;
|
|
15503
|
+
}
|
|
15504
|
+
if (ch < " " && ch !== " ") {
|
|
15505
|
+
throw new Error("A control or arrow key was typed in the value: nothing was sealed or sent.");
|
|
15506
|
+
}
|
|
15507
|
+
value += ch;
|
|
15508
|
+
}
|
|
15509
|
+
}
|
|
15510
|
+
return value;
|
|
15511
|
+
} finally {
|
|
15512
|
+
process.stdin.setRawMode(false);
|
|
15513
|
+
process.stdin.pause();
|
|
15514
|
+
process.stderr.write("\n");
|
|
15515
|
+
}
|
|
15516
|
+
}
|
|
15079
15517
|
async function confirmed(question) {
|
|
15080
15518
|
if (!process.stdin.isTTY) {
|
|
15081
15519
|
return false;
|
|
@@ -15204,7 +15642,7 @@ async function exec(positionals) {
|
|
|
15204
15642
|
}
|
|
15205
15643
|
process.exitCode = typeof record["exitCode"] === "number" ? record["exitCode"] : 1;
|
|
15206
15644
|
}
|
|
15207
|
-
async function
|
|
15645
|
+
async function remove3(id, pauseJobs) {
|
|
15208
15646
|
if (!id) {
|
|
15209
15647
|
throw new Error("delete requires <sandbox-id>");
|
|
15210
15648
|
}
|
|
@@ -15593,12 +16031,12 @@ async function desktopTree(id, options, json3) {
|
|
|
15593
16031
|
` : `${treeText(body)}
|
|
15594
16032
|
`);
|
|
15595
16033
|
}
|
|
15596
|
-
async function desktopLinks(id,
|
|
16034
|
+
async function desktopLinks(id, use2, given, options) {
|
|
15597
16035
|
if (!id) {
|
|
15598
16036
|
throw new Error("desktop requires <sandbox-id>");
|
|
15599
16037
|
}
|
|
15600
16038
|
const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/links`;
|
|
15601
|
-
if (
|
|
16039
|
+
if (use2 === "unlink") {
|
|
15602
16040
|
const response2 = await request(`${at4}/${encodeURIComponent(String(given))}`, { method: "DELETE" });
|
|
15603
16041
|
if (!response2.ok) {
|
|
15604
16042
|
fail(response2.status, await readBody(response2));
|
|
@@ -15607,7 +16045,7 @@ async function desktopLinks(id, use, given, options) {
|
|
|
15607
16045
|
`);
|
|
15608
16046
|
return;
|
|
15609
16047
|
}
|
|
15610
|
-
if (
|
|
16048
|
+
if (use2 === "links") {
|
|
15611
16049
|
const response2 = await request(at4, { method: "GET" });
|
|
15612
16050
|
const body2 = await readBody(response2);
|
|
15613
16051
|
if (!response2.ok) {
|
|
@@ -15645,38 +16083,38 @@ function numbers(text, least, most, signedFrom = most) {
|
|
|
15645
16083
|
const whole = parts.every((part, index) => (index >= signedFrom ? /^-?\d+$/ : /^\d+$/).test(part));
|
|
15646
16084
|
return whole && parts.length >= least && parts.length <= most ? parts.map(Number) : null;
|
|
15647
16085
|
}
|
|
15648
|
-
async function useDesktop(id,
|
|
16086
|
+
async function useDesktop(id, use2, given) {
|
|
15649
16087
|
if (!id) {
|
|
15650
16088
|
throw new Error("desktop requires <sandbox-id>");
|
|
15651
16089
|
}
|
|
15652
|
-
const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/${
|
|
16090
|
+
const at4 = `/v1/sandboxes/${encodeURIComponent(id)}/desktop/${use2}`;
|
|
15653
16091
|
let body;
|
|
15654
|
-
if (
|
|
16092
|
+
if (use2 === "click") {
|
|
15655
16093
|
const [x, y, button, count, ...more] = given.split(",");
|
|
15656
16094
|
const point = numbers(`${x ?? ""},${y ?? ""}`, 2, 2);
|
|
15657
16095
|
if (!point || more.length > 0 || button !== void 0 && !["left", "middle", "right"].includes(button) || count !== void 0 && !/^[123]$/.test(count)) {
|
|
15658
16096
|
throw new Error("--click is where to click, as x,y, with the button and how many times after it when they are not left and once: 640,400 or 640,400,right or 640,400,left,2");
|
|
15659
16097
|
}
|
|
15660
16098
|
body = { x: point[0], y: point[1], ...button ? { button } : {}, ...count ? { count: Number(count) } : {} };
|
|
15661
|
-
} else if (
|
|
16099
|
+
} else if (use2 === "move") {
|
|
15662
16100
|
const point = numbers(given, 2, 2);
|
|
15663
16101
|
if (!point) {
|
|
15664
16102
|
throw new Error("--move is where the pointer goes, as x,y: 640,400");
|
|
15665
16103
|
}
|
|
15666
16104
|
body = { x: point[0], y: point[1] };
|
|
15667
|
-
} else if (
|
|
16105
|
+
} else if (use2 === "drag") {
|
|
15668
16106
|
const points = numbers(given, 4, 4);
|
|
15669
16107
|
if (!points) {
|
|
15670
16108
|
throw new Error("--drag is where the button goes down and where it comes up, as x,y,x,y: 10,20,300,400");
|
|
15671
16109
|
}
|
|
15672
16110
|
body = { from: { x: points[0], y: points[1] }, to: { x: points[2], y: points[3] } };
|
|
15673
|
-
} else if (
|
|
16111
|
+
} else if (use2 === "scroll") {
|
|
15674
16112
|
const turn = numbers(given, 3, 4, 2);
|
|
15675
16113
|
if (!turn) {
|
|
15676
16114
|
throw new Error("--scroll is where the pointer is and how many notches the wheel turns, down or with a minus up, as x,y,notches: 640,400,3. A fourth number turns it to the right, or with a minus to the left.");
|
|
15677
16115
|
}
|
|
15678
16116
|
body = { x: turn[0], y: turn[1], dy: turn[2], ...turn[3] !== void 0 ? { dx: turn[3] } : {} };
|
|
15679
|
-
} else if (
|
|
16117
|
+
} else if (use2 === "type") {
|
|
15680
16118
|
body = { text: given };
|
|
15681
16119
|
} else {
|
|
15682
16120
|
body = { keys: given };
|
|
@@ -15864,9 +16302,9 @@ async function egress(positionals, values) {
|
|
|
15864
16302
|
card: "a card saved: agental billing card save",
|
|
15865
16303
|
use_case: 'what your sandboxes will use it for: agental egress use-case "<what for>"'
|
|
15866
16304
|
};
|
|
15867
|
-
const
|
|
16305
|
+
const refused2 = account3["refused"];
|
|
15868
16306
|
const lines = !account3["offered"] ? ["Residential egress is not offered here."] : [
|
|
15869
|
-
`residential: ${account3["enabled"] ? "on for this account" :
|
|
16307
|
+
`residential: ${account3["enabled"] ? "on for this account" : refused2 ? `refused: ${String(refused2.reason ?? "")}` : "not yet"}`,
|
|
15870
16308
|
...missing.map((need) => ` needs ${needs[need] ?? need}`),
|
|
15871
16309
|
`price: ${money(number("microsPerGb"))} a GB, both directions counted`,
|
|
15872
16310
|
`this month: ${money(number("spentMicros"))} of a ${money(number("budgetMicros"))} budget${account3["budgetSet"] ? "" : " (the default)"}`,
|
|
@@ -15998,15 +16436,15 @@ ${faint("The default is used when a sandbox is made without naming one. agental
|
|
|
15998
16436
|
process.stdout.write("* used when a sandbox is made without naming one\n");
|
|
15999
16437
|
}
|
|
16000
16438
|
function showTemplate(each) {
|
|
16001
|
-
const
|
|
16439
|
+
const list5 = (items) => items && items.length > 0 ? items.join(", ") : "none";
|
|
16002
16440
|
return [
|
|
16003
16441
|
`id: ${each.id}`,
|
|
16004
16442
|
`name: ${each.name}${each.default ? " (default: used when a sandbox is made without naming one)" : ""}`,
|
|
16005
16443
|
`start: ${startInWords(each.start)}`,
|
|
16006
|
-
`variables: ${
|
|
16444
|
+
`variables: ${list5(each.variables)}`,
|
|
16007
16445
|
// Said only where some are. An API from before variables could be kept out of the sandbox says nothing of them.
|
|
16008
|
-
...each.hidden && each.hidden.length > 0 ? [`kept out: ${
|
|
16009
|
-
`files: ${
|
|
16446
|
+
...each.hidden && each.hidden.length > 0 ? [`kept out: ${list5(each.hidden)}`] : [],
|
|
16447
|
+
`files: ${list5(each.files)}`,
|
|
16010
16448
|
// An API from before templates held rules says nothing of one.
|
|
16011
16449
|
...each.network ? [`network: ${ruleInWords(each.network)}`] : [],
|
|
16012
16450
|
// An API from before templates gave SSH says nothing of it.
|
|
@@ -16143,8 +16581,8 @@ ${mode === void 0 ? "" : "A sandbox on it takes this when it next starts, or now
|
|
|
16143
16581
|
const found = await templateNamed(need(first, "<template>"));
|
|
16144
16582
|
const path6 = `/v1/templates/${encodeURIComponent(found.id)}/egress`;
|
|
16145
16583
|
const how = `template egress takes <template>, and then nothing, box, or residential <country> [sticky|rotating], as agental template egress ${first ?? ""} residential de.`;
|
|
16146
|
-
const
|
|
16147
|
-
print4(
|
|
16584
|
+
const set2 = await call2(path6, rest.length === 0 ? { method: "GET" } : { method: "PUT", body: JSON.stringify(egressFrom(rest, how)) });
|
|
16585
|
+
print4(set2, `${found.name}: ${egressInWords(set2)}${rest.length === 0 ? "" : ", for sandboxes made from it from now on"}
|
|
16148
16586
|
`);
|
|
16149
16587
|
return;
|
|
16150
16588
|
}
|
|
@@ -16426,8 +16864,8 @@ async function metrics(id, asked2) {
|
|
|
16426
16864
|
if (!response.ok) {
|
|
16427
16865
|
fail(response.status, body);
|
|
16428
16866
|
}
|
|
16429
|
-
const
|
|
16430
|
-
const fromTo = typeof
|
|
16867
|
+
const answer4 = body && typeof body === "object" ? body : {};
|
|
16868
|
+
const fromTo = typeof answer4["since"] === "string" && typeof answer4["until"] === "string" ? ` from ${answer4["since"]} to ${answer4["until"]}` : "";
|
|
16431
16869
|
if (asked2.json) {
|
|
16432
16870
|
process.stdout.write(`${JSON.stringify(body, null, 2)}
|
|
16433
16871
|
`);
|
|
@@ -16452,7 +16890,7 @@ async function metrics(id, asked2) {
|
|
|
16452
16890
|
])
|
|
16453
16891
|
);
|
|
16454
16892
|
}
|
|
16455
|
-
if (
|
|
16893
|
+
if (answer4["complete"] === false) {
|
|
16456
16894
|
process.stderr.write(
|
|
16457
16895
|
id === void 0 ? "A server did not answer, so a sandbox on it has no reading here though it may have been running. Ask again in a minute.\n" : `A server did not answer, so readings may be missing: those from any time ${id} was on that server. Ask again in a minute.
|
|
16458
16896
|
`
|
|
@@ -16495,8 +16933,8 @@ async function dataRetention(positionals, asJson) {
|
|
|
16495
16933
|
`);
|
|
16496
16934
|
return;
|
|
16497
16935
|
}
|
|
16498
|
-
const
|
|
16499
|
-
const days =
|
|
16936
|
+
const answer4 = body ?? {};
|
|
16937
|
+
const days = answer4.keepDays ?? null;
|
|
16500
16938
|
const kept2 = days === null ? "until their sandbox is deleted" : days === 1 ? "1 day" : `${days} days`;
|
|
16501
16939
|
process.stdout.write(`${period === void 0 ? "" : "Saved. "}Command output, agent conversations and events are kept ${kept2}.
|
|
16502
16940
|
`);
|
|
@@ -16504,7 +16942,7 @@ async function dataRetention(positionals, asJson) {
|
|
|
16504
16942
|
process.stdout.write(`What is older is deleted within the hour, and cannot be brought back.
|
|
16505
16943
|
`);
|
|
16506
16944
|
}
|
|
16507
|
-
const last =
|
|
16945
|
+
const last = answer4.lastCleared;
|
|
16508
16946
|
if (period === void 0) {
|
|
16509
16947
|
process.stdout.write(
|
|
16510
16948
|
last ? `Last clean-up ${last.at}: ${last.commands} commands' output, ${last.conversations} conversations and ${last.events} events deleted.
|
|
@@ -16650,8 +17088,8 @@ async function telemetry(positionals, given, asJson) {
|
|
|
16650
17088
|
`);
|
|
16651
17089
|
return;
|
|
16652
17090
|
}
|
|
16653
|
-
const
|
|
16654
|
-
process.stdout.write(
|
|
17091
|
+
const set2 = settingsIn(body);
|
|
17092
|
+
process.stdout.write(set2 === null ? "No collector is set. agental telemetry set <endpoint> sets one.\n" : describeSettings(set2));
|
|
16655
17093
|
return;
|
|
16656
17094
|
}
|
|
16657
17095
|
case "set": {
|
|
@@ -16672,8 +17110,8 @@ async function telemetry(positionals, given, asJson) {
|
|
|
16672
17110
|
process.stdout.write(`${JSON.stringify({ ...saved, test: tested }, null, 2)}
|
|
16673
17111
|
`);
|
|
16674
17112
|
} else {
|
|
16675
|
-
const
|
|
16676
|
-
process.stdout.write(
|
|
17113
|
+
const set2 = settingsIn(saved);
|
|
17114
|
+
process.stdout.write(set2 === null ? "" : describeSettings(set2));
|
|
16677
17115
|
}
|
|
16678
17116
|
sayTest(tested, "Saved. ");
|
|
16679
17117
|
return;
|
|
@@ -17187,10 +17625,10 @@ async function showLimits(positionals, options) {
|
|
|
17187
17625
|
`);
|
|
17188
17626
|
return;
|
|
17189
17627
|
}
|
|
17190
|
-
const
|
|
17191
|
-
const spent = typeof
|
|
17192
|
-
const budget = typeof
|
|
17193
|
-
process.stdout.write(`Budget for burst fees: ${money(budget)} a month${
|
|
17628
|
+
const answer4 = body2 && typeof body2 === "object" ? body2 : {};
|
|
17629
|
+
const spent = typeof answer4["spentMicros"] === "number" ? answer4["spentMicros"] : 0;
|
|
17630
|
+
const budget = typeof answer4["budgetMicros"] === "number" ? answer4["budgetMicros"] : 0;
|
|
17631
|
+
process.stdout.write(`Budget for burst fees: ${money(budget)} a month${answer4["budgetSet"] === true ? "" : " (the default)"}; ${money(spent)} spent this month.
|
|
17194
17632
|
`);
|
|
17195
17633
|
return;
|
|
17196
17634
|
}
|
|
@@ -17220,8 +17658,8 @@ async function showLimits(positionals, options) {
|
|
|
17220
17658
|
process.stdout.write(describeLimits(body, options.from === void 0 && options.to === void 0, options.to === void 0));
|
|
17221
17659
|
}
|
|
17222
17660
|
function describeLimits(body, today, endsNow) {
|
|
17223
|
-
const
|
|
17224
|
-
const now =
|
|
17661
|
+
const answer4 = body && typeof body === "object" ? body : {};
|
|
17662
|
+
const now = answer4["now"] && typeof answer4["now"] === "object" ? answer4["now"] : {};
|
|
17225
17663
|
const number = (from, name) => typeof from[name] === "number" ? from[name] : 0;
|
|
17226
17664
|
const units = (mb) => {
|
|
17227
17665
|
const value = mb / 2048;
|
|
@@ -17231,11 +17669,11 @@ function describeLimits(body, today, endsNow) {
|
|
|
17231
17669
|
const at4 = new Date(iso).toISOString();
|
|
17232
17670
|
return at4.slice(0, 10) === (/* @__PURE__ */ new Date()).toISOString().slice(0, 10) ? `${at4.slice(11, 16)} UTC` : `${at4.slice(0, 10)} ${at4.slice(11, 16)} UTC`;
|
|
17233
17671
|
};
|
|
17234
|
-
const range = today ? "today (UTC)" : `from ${String(
|
|
17672
|
+
const range = today ? "today (UTC)" : `from ${String(answer4["from"] ?? "")} to ${String(answer4["to"] ?? "")}`;
|
|
17235
17673
|
const lines = [
|
|
17236
|
-
`running: ${units(number(now, "runningMb"))} of ${number(now, "runningUnits").toLocaleString("en-US")} units (a tiny is 1, a small 2, a medium 4, a large 8); at the running count ${duration(number(
|
|
17674
|
+
`running: ${units(number(now, "runningMb"))} of ${number(now, "runningUnits").toLocaleString("en-US")} units (a tiny is 1, a small 2, a medium 4, a large 8); at the running count ${duration(number(answer4, "atRunningCountMs"))} ${range}`
|
|
17237
17675
|
];
|
|
17238
|
-
const bursts = Array.isArray(
|
|
17676
|
+
const bursts = Array.isArray(answer4["bursts"]) ? answer4["bursts"] : [];
|
|
17239
17677
|
const open = endsNow ? bursts.find((one) => one["endedAt"] === null && typeof one["startedAt"] === "string") : void 0;
|
|
17240
17678
|
const over = number(now, "overMb") > 0;
|
|
17241
17679
|
const nextStart = Array.isArray(now["nextStart"]) ? now["nextStart"] : [];
|
|
@@ -17251,9 +17689,9 @@ function describeLimits(body, today, endsNow) {
|
|
|
17251
17689
|
const budgetMonth = now["budgetMonth"] && typeof now["budgetMonth"] === "object" ? now["budgetMonth"] : null;
|
|
17252
17690
|
const since = typeof budgetMonth?.start === "string" && budgetMonth.start.slice(8, 10) !== "01" ? ` (since ${shortDayOf(budgetMonth.start)})` : "";
|
|
17253
17691
|
lines.push(`fees: ${money(number(now, "spentMicros"))} this month${since} of a ${money(number(now, "budgetMicros"))} budget`);
|
|
17254
|
-
const
|
|
17255
|
-
const total = number(
|
|
17256
|
-
const byReason = Array.isArray(
|
|
17692
|
+
const refused2 = answer4["refused"] && typeof answer4["refused"] === "object" ? answer4["refused"] : {};
|
|
17693
|
+
const total = number(refused2, "total");
|
|
17694
|
+
const byReason = Array.isArray(refused2["byReason"]) ? refused2["byReason"] : [];
|
|
17257
17695
|
lines.push(
|
|
17258
17696
|
`did not start: ${total.toLocaleString("en-US")} ${range}${byReason.length > 0 ? `: ${byReason.map((one) => `${one.count.toLocaleString("en-US")} ${REASON_WORDS[one.reason] ?? one.reason} (${one.code})`).join(", ")}` : ""}`
|
|
17259
17697
|
);
|
|
@@ -17280,22 +17718,22 @@ async function asked(path6, init) {
|
|
|
17280
17718
|
return body;
|
|
17281
17719
|
}
|
|
17282
17720
|
function settingsIn(body) {
|
|
17283
|
-
const
|
|
17284
|
-
if (
|
|
17721
|
+
const set2 = body && typeof body === "object" ? body["telemetry"] : void 0;
|
|
17722
|
+
if (set2 === null) {
|
|
17285
17723
|
return null;
|
|
17286
17724
|
}
|
|
17287
|
-
if (!
|
|
17725
|
+
if (!set2 || typeof set2 !== "object") {
|
|
17288
17726
|
throw new Error("Telemetry response was missing telemetry");
|
|
17289
17727
|
}
|
|
17290
|
-
return
|
|
17728
|
+
return set2;
|
|
17291
17729
|
}
|
|
17292
|
-
function describeSettings(
|
|
17293
|
-
const headers = Array.isArray(
|
|
17294
|
-
const error =
|
|
17730
|
+
function describeSettings(set2) {
|
|
17731
|
+
const headers = Array.isArray(set2["headers"]) ? set2["headers"].map(String) : [];
|
|
17732
|
+
const error = set2["lastError"] && typeof set2["lastError"] === "object" ? set2["lastError"] : null;
|
|
17295
17733
|
return [
|
|
17296
|
-
String(
|
|
17734
|
+
String(set2["endpoint"] ?? ""),
|
|
17297
17735
|
` headers ${headers.length === 0 ? NO_FIGURE : headers.join(", ")}`,
|
|
17298
|
-
` last export ${typeof
|
|
17736
|
+
` last export ${typeof set2["lastExportAt"] === "string" ? set2["lastExportAt"] : NO_FIGURE}`,
|
|
17299
17737
|
` last error ${error === null ? NO_FIGURE : `${String(error["message"] ?? "")}, at ${String(error["at"] ?? "")}`}`,
|
|
17300
17738
|
""
|
|
17301
17739
|
].join("\n");
|
|
@@ -17501,11 +17939,11 @@ function readSandboxes(body) {
|
|
|
17501
17939
|
return body.sandboxes.filter((item) => Boolean(item) && typeof item === "object");
|
|
17502
17940
|
}
|
|
17503
17941
|
function readList(body, name) {
|
|
17504
|
-
const
|
|
17505
|
-
if (!Array.isArray(
|
|
17942
|
+
const list5 = body && typeof body === "object" ? body[name] : void 0;
|
|
17943
|
+
if (!Array.isArray(list5)) {
|
|
17506
17944
|
throw new Error(`Metrics response was missing ${name}`);
|
|
17507
17945
|
}
|
|
17508
|
-
return
|
|
17946
|
+
return list5.filter((item) => Boolean(item) && typeof item === "object");
|
|
17509
17947
|
}
|
|
17510
17948
|
function teamOptions(values) {
|
|
17511
17949
|
return { json: values.json, revokeKeys: values["revoke-keys"], ...values.role === void 0 ? {} : { role: values.role } };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agental",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "The agental command: Linux sandboxes for your agents, from the terminal. npx agental@latest signs you in and installs the agent skills.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "VERTIXER LTD",
|