@computesdk/cli 2.6.3 → 2.6.5
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/README.md +383 -4
- package/cli-manifest.json +3425 -0
- package/dist/index.js +2130 -486
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
package/dist/index.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
|
-
import
|
|
8
|
-
import { readFileSync as
|
|
7
|
+
import pc13 from "picocolors";
|
|
8
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
|
-
import { dirname as
|
|
10
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
11
11
|
|
|
12
12
|
// src/providers.ts
|
|
13
13
|
var PROVIDER_ENV = {
|
|
@@ -65,12 +65,12 @@ function getProviderStatus() {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// src/actions.ts
|
|
68
|
-
import
|
|
69
|
-
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
68
|
+
import pc7 from "picocolors";
|
|
69
|
+
import { mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
70
70
|
import { spawnSync } from "child_process";
|
|
71
71
|
|
|
72
72
|
// src/settings.ts
|
|
73
|
-
import
|
|
73
|
+
import pc2 from "picocolors";
|
|
74
74
|
|
|
75
75
|
// src/actions-client.ts
|
|
76
76
|
import {
|
|
@@ -146,6 +146,32 @@ function formatUsdPer(rate) {
|
|
|
146
146
|
return formatRateAllUnits(rateAllUnits(rate));
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
// src/term.ts
|
|
150
|
+
import pc from "picocolors";
|
|
151
|
+
function safeTerm(s) {
|
|
152
|
+
return s.replace(/[\u0000-\u001F\u007F-\u009F]/g, "\uFFFD");
|
|
153
|
+
}
|
|
154
|
+
function safeTermText(s) {
|
|
155
|
+
return s.replace(/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g, "\uFFFD");
|
|
156
|
+
}
|
|
157
|
+
function conclusionLabel(conclusion) {
|
|
158
|
+
switch (conclusion) {
|
|
159
|
+
case "passed":
|
|
160
|
+
return pc.green("passed");
|
|
161
|
+
case "failed":
|
|
162
|
+
return pc.red("failed");
|
|
163
|
+
case "running":
|
|
164
|
+
return pc.yellow("running");
|
|
165
|
+
case "cancelled":
|
|
166
|
+
return pc.gray("cancelled");
|
|
167
|
+
case "none":
|
|
168
|
+
return pc.yellow("queued");
|
|
169
|
+
// Anything else is the server's string verbatim.
|
|
170
|
+
default:
|
|
171
|
+
return safeTerm(conclusion);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
149
175
|
// src/settings.ts
|
|
150
176
|
var PLATFORM_SIZES = ["small", "medium", "large", "xlarge"];
|
|
151
177
|
function parseMaxPrice(value, per) {
|
|
@@ -193,14 +219,62 @@ function parseSizeCap(entry) {
|
|
|
193
219
|
}
|
|
194
220
|
return { size, cap };
|
|
195
221
|
}
|
|
222
|
+
var MAX_WARM_POOL_SIZE = 16;
|
|
223
|
+
var MAX_SNAPSHOT_POOL_SIZE = 32;
|
|
224
|
+
function parseResourcesFlag(entry) {
|
|
225
|
+
const eq = entry.indexOf("=");
|
|
226
|
+
const provider = eq === -1 ? "" : entry.slice(0, eq).trim();
|
|
227
|
+
const preset = eq === -1 ? "" : entry.slice(eq + 1).trim();
|
|
228
|
+
if (provider === "" || preset === "") {
|
|
229
|
+
throw new PlatformClientError(
|
|
230
|
+
"invalid_argument",
|
|
231
|
+
`Invalid --resources "${entry}" \u2014 expected <provider>=<preset> (e.g. blaxel=large) or <provider>=none.`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
return { provider, preset: preset === "none" ? null : preset };
|
|
235
|
+
}
|
|
236
|
+
function parsePoolFlag(flag, entry, max) {
|
|
237
|
+
const eq = entry.indexOf("=");
|
|
238
|
+
const key = eq === -1 ? "" : entry.slice(0, eq).trim();
|
|
239
|
+
const value = eq === -1 ? "" : entry.slice(eq + 1).trim();
|
|
240
|
+
const size = Number(value);
|
|
241
|
+
if (key === "" || !/^\d+$/.test(value) || size > max) {
|
|
242
|
+
throw new PlatformClientError(
|
|
243
|
+
"invalid_argument",
|
|
244
|
+
`Invalid ${flag} "${entry}" \u2014 expected <provider>[:<region>]=<n> with n in 0..${max} (0 clears it).`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
return { key, size };
|
|
248
|
+
}
|
|
249
|
+
function parseWarmPoolFlag(entry) {
|
|
250
|
+
return parsePoolFlag("--warm-pool", entry, MAX_WARM_POOL_SIZE);
|
|
251
|
+
}
|
|
252
|
+
function parseSnapshotPoolFlag(entry) {
|
|
253
|
+
return parsePoolFlag("--snapshot-pool", entry, MAX_SNAPSHOT_POOL_SIZE);
|
|
254
|
+
}
|
|
255
|
+
function poolPatch(entries, parse) {
|
|
256
|
+
const pool = {};
|
|
257
|
+
for (const entry of entries) {
|
|
258
|
+
const { key, size } = parse(entry);
|
|
259
|
+
pool[key] = size;
|
|
260
|
+
}
|
|
261
|
+
return pool;
|
|
262
|
+
}
|
|
263
|
+
function formatResources(r) {
|
|
264
|
+
const parts = [];
|
|
265
|
+
if (r.cpus !== void 0) parts.push(`${r.cpus} vCPU`);
|
|
266
|
+
if (r.memoryMb !== void 0) parts.push(`${r.memoryMb} MB`);
|
|
267
|
+
if (r.ephemeralDiskMb) parts.push(`${r.ephemeralDiskMb} MB disk`);
|
|
268
|
+
return parts.join(" / ") || "\u2014";
|
|
269
|
+
}
|
|
196
270
|
var fmtRate = (cap) => cap ? formatUsdPer(cap) : "\u2014";
|
|
197
|
-
var fmtRef = (ref) => ref ? ` ${
|
|
271
|
+
var fmtRef = (ref) => ref ? ` ${pc2.dim(`reference ${formatUsdPer(ref)}`)}` : "";
|
|
198
272
|
function printLaneSettings(s, lane) {
|
|
199
273
|
const sandbox = lane === "sandboxes";
|
|
200
274
|
const orderType = s.marketOrderType ?? (sandbox ? "inherit" : "\u2014");
|
|
201
|
-
const orderSuffix = sandbox && s.marketOrderType == null ?
|
|
275
|
+
const orderSuffix = sandbox && s.marketOrderType == null ? pc2.dim(` (Actions: ${s.actionsMarketOrderType ?? "\u2014"})`) : "";
|
|
202
276
|
console.log(`order type: ${orderType}${orderSuffix}`);
|
|
203
|
-
const capSuffix = sandbox && s.marketCap == null ?
|
|
277
|
+
const capSuffix = sandbox && s.marketCap == null ? pc2.dim(` (inherits Actions: ${fmtRate(s.actionsMarketCap)})`) : "";
|
|
204
278
|
console.log(`general cap: ${fmtRate(s.marketCap)}${capSuffix}`);
|
|
205
279
|
console.log("per-size caps:");
|
|
206
280
|
for (const size of PLATFORM_SIZES) {
|
|
@@ -209,15 +283,14 @@ function printLaneSettings(s, lane) {
|
|
|
209
283
|
` ${size.padEnd(7)} ${fmtRate(cap)}${cap ? "" : fmtRef(s.referencePrices?.[size])}`
|
|
210
284
|
);
|
|
211
285
|
}
|
|
212
|
-
const
|
|
213
|
-
console.log(`provider order: ${
|
|
286
|
+
const orderText2 = s.providerOrder.length > 0 ? s.providerOrder.join(", ") : sandbox ? pc2.dim(`inherit (Actions: ${(s.actionsProviderOrder ?? []).join(", ") || "\u2014"})`) : s.defaultProviderOrder && s.defaultProviderOrder.length > 0 ? pc2.dim(`default (${s.defaultProviderOrder.join(", ")})`) : "\u2014";
|
|
287
|
+
console.log(`provider order: ${orderText2}`);
|
|
214
288
|
const resources = Object.entries(s.providerResources ?? {});
|
|
215
|
-
console.log("
|
|
289
|
+
console.log("resources:");
|
|
216
290
|
if (resources.length === 0) console.log(" \u2014");
|
|
217
291
|
for (const [provider, r] of resources) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
);
|
|
292
|
+
const preset = s.providerResourcePresets?.[provider];
|
|
293
|
+
console.log(preset ? ` ${provider} ${preset} (${formatResources(r)})` : ` ${provider} ${formatResources(r)}`);
|
|
221
294
|
}
|
|
222
295
|
const pool = Object.entries(s.warmPool ?? {});
|
|
223
296
|
console.log("warm pool:");
|
|
@@ -227,7 +300,22 @@ function printLaneSettings(s, lane) {
|
|
|
227
300
|
const snap = Object.entries(s.snapshotPool);
|
|
228
301
|
console.log("snapshot pool:");
|
|
229
302
|
if (snap.length === 0) console.log(" \u2014");
|
|
230
|
-
for (const [entry, cap] of snap) console.log(` ${entry} ${cap}`);
|
|
303
|
+
for (const [entry, cap] of snap) console.log(` ${safeTerm(entry)} ${cap}`);
|
|
304
|
+
}
|
|
305
|
+
if (s.snapshotSummary !== void 0) printSnapshotSummary(s.snapshotSummary);
|
|
306
|
+
}
|
|
307
|
+
function printSnapshotSummary(summary) {
|
|
308
|
+
const capped = summary.workflows.filter((w) => w.snapshotCap !== null);
|
|
309
|
+
console.log("workflow snapshot caps:");
|
|
310
|
+
if (capped.length === 0) console.log(` ${pc2.dim("\u2014 (every workflow uses the dynamic pool)")}`);
|
|
311
|
+
for (const w of capped) {
|
|
312
|
+
const cap = w.snapshotCap === 0 ? "off" : String(w.snapshotCap);
|
|
313
|
+
console.log(` ${safeTerm(w.repoFullName)} ${safeTerm(w.path)} ${cap}`);
|
|
314
|
+
}
|
|
315
|
+
console.log("live snapshots:");
|
|
316
|
+
if (summary.live.length === 0) console.log(" \u2014");
|
|
317
|
+
for (const row of summary.live) {
|
|
318
|
+
console.log(` ${safeTerm(row.repoFullName)} ${row.workflowPath === null ? pc2.dim("(no workflow)") : safeTerm(row.workflowPath)} ${row.count}`);
|
|
231
319
|
}
|
|
232
320
|
}
|
|
233
321
|
function settingsFail(e, opts, lane, verb, deps) {
|
|
@@ -243,8 +331,8 @@ function settingsFail(e, opts, lane, verb, deps) {
|
|
|
243
331
|
}
|
|
244
332
|
return deps.fail(e, opts);
|
|
245
333
|
}
|
|
246
|
-
function registerSettingsCommands(group, lane,
|
|
247
|
-
const settings =
|
|
334
|
+
function registerSettingsCommands(group, lane, common2, deps) {
|
|
335
|
+
const settings = common2(
|
|
248
336
|
group.command("settings").description(`Show the org's ${lane} routing policy (order, caps, sizes, pools)`).configureOutput({
|
|
249
337
|
outputError: (str, write) => deps.usageErrorOutput(str, write)
|
|
250
338
|
})
|
|
@@ -257,7 +345,7 @@ function registerSettingsCommands(group, lane, common, deps) {
|
|
|
257
345
|
settingsFail(e, opts, lane, "view", deps);
|
|
258
346
|
}
|
|
259
347
|
});
|
|
260
|
-
|
|
348
|
+
const set = common2(
|
|
261
349
|
settings.command("set").description(`Update the org's ${lane} routing policy`).option(
|
|
262
350
|
"--cap <size=rate>",
|
|
263
351
|
"per-size cap: <size>=<usd>/<unit> or <size>=none to clear (repeatable)",
|
|
@@ -270,55 +358,838 @@ function registerSettingsCommands(group, lane, common, deps) {
|
|
|
270
358
|
"--order <providers>",
|
|
271
359
|
lane === "sandboxes" ? 'provider order, comma-separated (e.g. "market,blaxel,vercel"); "inherit" restores the Actions order' : 'provider order, comma-separated (e.g. "market,blaxel,vercel"); "default" restores the platform default'
|
|
272
360
|
)
|
|
361
|
+
);
|
|
362
|
+
set.option(
|
|
363
|
+
"--resources <provider=preset>",
|
|
364
|
+
"per-provider size preset (e.g. blaxel=large); <provider>=none clears it (repeatable)",
|
|
365
|
+
(v, a) => a.concat(v),
|
|
366
|
+
[]
|
|
367
|
+
).option(
|
|
368
|
+
"--warm-pool <provider[:region]=n>",
|
|
369
|
+
`warm pool size per placement entry, 0..${MAX_WARM_POOL_SIZE}; 0 clears it (repeatable)`,
|
|
370
|
+
(v, a) => a.concat(v),
|
|
371
|
+
[]
|
|
372
|
+
);
|
|
373
|
+
if (lane === "actions") {
|
|
374
|
+
set.option(
|
|
375
|
+
"--snapshot-pool <provider[:region]=n>",
|
|
376
|
+
`snapshot cap per placement entry, 0..${MAX_SNAPSHOT_POOL_SIZE}; 0 clears it (repeatable)`,
|
|
377
|
+
(v, a) => a.concat(v),
|
|
378
|
+
[]
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
set.action(async (opts) => {
|
|
382
|
+
try {
|
|
383
|
+
const body = {};
|
|
384
|
+
if (opts.cap.length > 0) {
|
|
385
|
+
const caps = {};
|
|
386
|
+
for (const entry of opts.cap) {
|
|
387
|
+
const { size, cap } = parseSizeCap(entry);
|
|
388
|
+
caps[size] = cap;
|
|
389
|
+
}
|
|
390
|
+
body.marketCaps = caps;
|
|
391
|
+
}
|
|
392
|
+
if (opts.generalCap !== void 0) {
|
|
393
|
+
body.marketCap = opts.generalCap === "none" ? null : parseMaxPrice(opts.generalCap, void 0);
|
|
394
|
+
}
|
|
395
|
+
if (opts.orderType !== void 0) {
|
|
396
|
+
if (lane === "sandboxes" && opts.orderType === "inherit") {
|
|
397
|
+
body.marketOrderType = null;
|
|
398
|
+
} else if (opts.orderType === "limit" || opts.orderType === "market") {
|
|
399
|
+
body.marketOrderType = opts.orderType;
|
|
400
|
+
} else {
|
|
401
|
+
throw new Error(
|
|
402
|
+
lane === "sandboxes" ? "--order-type must be limit, market, or inherit." : "--order-type must be limit or market."
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (opts.order !== void 0) {
|
|
407
|
+
if (opts.order === "inherit" && lane === "sandboxes") {
|
|
408
|
+
body.providerOrder = [];
|
|
409
|
+
} else if (opts.order === "default" && lane === "actions") {
|
|
410
|
+
body.providerOrder = [];
|
|
411
|
+
} else {
|
|
412
|
+
body.providerOrder = opts.order.split(",").map((s) => s.trim()).filter(Boolean);
|
|
413
|
+
if (body.providerOrder.length === 0) {
|
|
414
|
+
throw new Error(
|
|
415
|
+
lane === "sandboxes" ? `--order "${opts.order}" names no providers \u2014 pass a comma-separated list or "inherit".` : `--order "${opts.order}" names no providers \u2014 pass a comma-separated list or "default".`
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (opts.resources && opts.resources.length > 0) {
|
|
421
|
+
const resources = {};
|
|
422
|
+
for (const entry of opts.resources) {
|
|
423
|
+
const { provider, preset } = parseResourcesFlag(entry);
|
|
424
|
+
resources[provider] = preset;
|
|
425
|
+
}
|
|
426
|
+
body.providerResources = resources;
|
|
427
|
+
}
|
|
428
|
+
if (opts.warmPool && opts.warmPool.length > 0) {
|
|
429
|
+
body.warmPool = poolPatch(opts.warmPool, parseWarmPoolFlag);
|
|
430
|
+
}
|
|
431
|
+
if (opts.snapshotPool && opts.snapshotPool.length > 0) {
|
|
432
|
+
body.snapshotPool = poolPatch(opts.snapshotPool, parseSnapshotPoolFlag);
|
|
433
|
+
}
|
|
434
|
+
if (Object.keys(body).length === 0) {
|
|
435
|
+
throw new Error(
|
|
436
|
+
lane === "sandboxes" ? "Nothing to change \u2014 pass --cap, --general-cap, --order-type, --order, --resources, or --warm-pool." : "Nothing to change \u2014 pass --cap, --general-cap, --order-type, --order, --resources, --warm-pool, or --snapshot-pool."
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
const c = await deps.client(opts);
|
|
440
|
+
const res = await c.patch(`/api/v1/${lane}/settings`, body);
|
|
441
|
+
deps.output(opts, res, (s) => printLaneSettings(s, lane));
|
|
442
|
+
} catch (e) {
|
|
443
|
+
settingsFail(e, opts, lane, "change", deps);
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// src/actions-repos.ts
|
|
449
|
+
import pc5 from "picocolors";
|
|
450
|
+
import { readFileSync } from "fs";
|
|
451
|
+
|
|
452
|
+
// src/actions-workflows.ts
|
|
453
|
+
import pc4 from "picocolors";
|
|
454
|
+
|
|
455
|
+
// src/actions-runs.ts
|
|
456
|
+
import pc3 from "picocolors";
|
|
457
|
+
|
|
458
|
+
// src/confirm.ts
|
|
459
|
+
import { createInterface } from "readline/promises";
|
|
460
|
+
async function confirmWrite(question, opts) {
|
|
461
|
+
if (opts.yes) return;
|
|
462
|
+
if (!process.stdin.isTTY) {
|
|
463
|
+
throw new PlatformClientError("confirmation_required", `${question} Pass -y to confirm.`);
|
|
464
|
+
}
|
|
465
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
466
|
+
let answer;
|
|
467
|
+
try {
|
|
468
|
+
answer = await rl.question(`${question} [y/N] `);
|
|
469
|
+
} finally {
|
|
470
|
+
rl.close();
|
|
471
|
+
}
|
|
472
|
+
if (!/^y(es)?$/i.test(answer.trim())) {
|
|
473
|
+
throw new PlatformClientError("cancelled", "Cancelled; nothing was changed.");
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// src/actions-runs.ts
|
|
478
|
+
var WORKFLOW_PATH_PREFIX = ".github/";
|
|
479
|
+
function plural(n, noun) {
|
|
480
|
+
return `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
481
|
+
}
|
|
482
|
+
function resolveWorkflowPaths(workflows, selectors) {
|
|
483
|
+
const paths = [];
|
|
484
|
+
for (const selector of selectors) {
|
|
485
|
+
const matchers = [
|
|
486
|
+
(w) => w.path === selector,
|
|
487
|
+
(w) => w.name === selector,
|
|
488
|
+
(w) => w.path.split("/").pop() === selector,
|
|
489
|
+
(w) => w.id === selector
|
|
490
|
+
];
|
|
491
|
+
let found = [];
|
|
492
|
+
for (const matches of matchers) {
|
|
493
|
+
found = workflows.filter(matches);
|
|
494
|
+
if (found.length > 0) break;
|
|
495
|
+
}
|
|
496
|
+
if (found.length === 0) {
|
|
497
|
+
const choices = [...new Set(workflows.map((w) => `${w.path} (${w.name})`))].join(", ") || "none";
|
|
498
|
+
throw new PlatformClientError("workflow_not_found", `No workflow "${selector}". Available: ${choices}`);
|
|
499
|
+
}
|
|
500
|
+
for (const w of found) if (!paths.includes(w.path)) paths.push(w.path);
|
|
501
|
+
}
|
|
502
|
+
return paths;
|
|
503
|
+
}
|
|
504
|
+
async function runFilterQuery(c, repo, opts) {
|
|
505
|
+
let workflow;
|
|
506
|
+
if (opts.workflow && opts.workflow.length > 0) {
|
|
507
|
+
const lookups = opts.workflow.filter((s) => !s.startsWith(WORKFLOW_PATH_PREFIX));
|
|
508
|
+
const catalog = lookups.length === 0 ? [] : (await c.get("/api/v1/actions/workflows", { repo, include: "all" })).workflows;
|
|
509
|
+
workflow = [];
|
|
510
|
+
for (const selector of opts.workflow) {
|
|
511
|
+
const paths = selector.startsWith(WORKFLOW_PATH_PREFIX) ? [selector] : resolveWorkflowPaths(catalog, [selector]);
|
|
512
|
+
for (const path2 of paths) if (!workflow.includes(path2)) workflow.push(path2);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
repo,
|
|
517
|
+
status: opts.status,
|
|
518
|
+
branch: opts.branch,
|
|
519
|
+
event: opts.event,
|
|
520
|
+
workflow,
|
|
521
|
+
q: opts.search,
|
|
522
|
+
archived: opts.archived ? "only" : void 0,
|
|
523
|
+
reliability: opts.reliability ? "1" : void 0
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
function parseDayCursor(value) {
|
|
527
|
+
const comma = value.lastIndexOf(",");
|
|
528
|
+
if (comma <= 0 || comma === value.length - 1) {
|
|
529
|
+
throw new PlatformClientError(
|
|
530
|
+
"invalid_argument",
|
|
531
|
+
`Invalid --cursor "${value}". Expected <startedAt>,<id>, as printed after a page.`
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
return { startedAt: value.slice(0, comma), id: value.slice(comma + 1) };
|
|
535
|
+
}
|
|
536
|
+
async function listDayRuns(c, day, query, { all, cursor }) {
|
|
537
|
+
const runs = [];
|
|
538
|
+
const seen = /* @__PURE__ */ new Set();
|
|
539
|
+
let next = cursor ?? null;
|
|
540
|
+
for (; ; ) {
|
|
541
|
+
const page = await c.get(`/api/v1/actions/runs/day/${encodeURIComponent(day)}`, {
|
|
542
|
+
...query,
|
|
543
|
+
cursorStartedAt: next?.startedAt,
|
|
544
|
+
cursorId: next?.id
|
|
545
|
+
});
|
|
546
|
+
runs.push(...page.runs);
|
|
547
|
+
next = page.nextCursor ?? null;
|
|
548
|
+
if (!all || next === null) return { runs, nextCursor: next };
|
|
549
|
+
const key = `${next.startedAt},${next.id}`;
|
|
550
|
+
if (seen.has(key)) throw new PlatformClientError("invalid_argument", `The platform repeated cursor ${key}; stopping.`);
|
|
551
|
+
seen.add(key);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function formatRunDays(days) {
|
|
555
|
+
if (days.length === 0) return "No runs found.";
|
|
556
|
+
return days.map((d) => `${safeTerm(d.day)} ${plural(d.count, "run")}`).join("\n");
|
|
557
|
+
}
|
|
558
|
+
function formatDayCursor(cursor) {
|
|
559
|
+
return `more: --cursor ${safeTerm(cursor.startedAt)},${safeTerm(cursor.id)}`;
|
|
560
|
+
}
|
|
561
|
+
function archiveQuestion(count, archived) {
|
|
562
|
+
return archived ? `Archive ${plural(count, "run")}? Archived runs leave the run lists and counts; \`compute actions runs unarchive\` restores them.` : `Unarchive ${plural(count, "run")}? They return to the run lists and counts.`;
|
|
563
|
+
}
|
|
564
|
+
function notFoundIds(error) {
|
|
565
|
+
if (!(error instanceof PlatformApiError)) return [];
|
|
566
|
+
const ids = error.details?.notFound;
|
|
567
|
+
return Array.isArray(ids) ? ids.filter((id) => typeof id === "string") : [];
|
|
568
|
+
}
|
|
569
|
+
function registerRunsCommands(actions, common2, deps) {
|
|
570
|
+
const withFilters = (cmd) => cmd.option("--status <status...>", "filter by conclusion: passed, failed, running, cancelled, none").option("--branch <branch...>", "filter by branch/ref").option("--event <event...>", "filter by trigger: push, pull_request, schedule, workflow_dispatch").option("--workflow <path|name...>", "filter by workflow path, name or file name (e.g. ci.yml)").option("--search <text>", "search title, ref, SHA prefix, workflow, #run or #PR number").option("--archived", "archived runs only (hidden by default)").option("--reliability", "reliability runs only (hidden by default)");
|
|
571
|
+
const printRuns = (runs2) => {
|
|
572
|
+
if (runs2.length === 0) {
|
|
573
|
+
console.log("No runs found.");
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
for (const run of runs2) console.log(deps.formatRunRow(run));
|
|
577
|
+
};
|
|
578
|
+
const runs = actions.command("runs").description("List recent runs (every repo, or one), or one day's runs with --day");
|
|
579
|
+
common2(
|
|
580
|
+
withFilters(runs.argument("[repo]", "repository in owner/repo format (default: every repo)")).option("--day <YYYY-MM-DD>", "list one day's runs, page by page, instead of the newest 100").option("--time-zone <iana>", "with --day: the time zone the day is read in (default: UTC)").option("--cursor <startedAt,id>", "with --day: continue after this cursor (printed after a page)").option("--all", "with --day: follow every page")
|
|
581
|
+
).action(async (repo, opts) => {
|
|
582
|
+
try {
|
|
583
|
+
if (opts.day === void 0 && (opts.all || opts.timeZone !== void 0 || opts.cursor !== void 0)) {
|
|
584
|
+
throw new PlatformClientError("invalid_argument", "--all, --time-zone and --cursor page one day's runs: pass --day <YYYY-MM-DD>.");
|
|
585
|
+
}
|
|
586
|
+
const cursor = opts.cursor === void 0 ? void 0 : parseDayCursor(opts.cursor);
|
|
587
|
+
const c = await deps.client(opts);
|
|
588
|
+
const query = await runFilterQuery(c, repo, opts);
|
|
589
|
+
if (opts.day !== void 0) {
|
|
590
|
+
const page = await listDayRuns(c, opts.day, { ...query, timeZone: opts.timeZone }, { all: opts.all === true, cursor });
|
|
591
|
+
deps.output(opts, page, (p2) => {
|
|
592
|
+
printRuns(p2.runs);
|
|
593
|
+
if (p2.nextCursor) console.log(pc3.dim(formatDayCursor(p2.nextCursor)));
|
|
594
|
+
});
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
const { runs: list } = await c.get("/api/v1/actions/runs", query);
|
|
598
|
+
deps.output(opts, list, printRuns);
|
|
599
|
+
} catch (e) {
|
|
600
|
+
deps.fail(e, opts);
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
common2(
|
|
604
|
+
withFilters(
|
|
605
|
+
runs.command("days").description("How many runs each day holds, newest first (same filters as runs)").argument("[repo]", "repository in owner/repo format (default: every repo)")
|
|
606
|
+
).option("--time-zone <iana>", "the time zone days are read in (default: UTC)")
|
|
607
|
+
).action(async (repo, opts) => {
|
|
608
|
+
try {
|
|
609
|
+
const c = await deps.client(opts);
|
|
610
|
+
const query = await runFilterQuery(c, repo, opts);
|
|
611
|
+
const data = await c.get("/api/v1/actions/run-days", { ...query, timeZone: opts.timeZone });
|
|
612
|
+
deps.output(opts, data, (d) => console.log(formatRunDays(d.days)));
|
|
613
|
+
} catch (e) {
|
|
614
|
+
deps.fail(e, opts);
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
for (const archived of [true, false]) {
|
|
618
|
+
const verb = archived ? "archive" : "unarchive";
|
|
619
|
+
common2(
|
|
620
|
+
runs.command(verb).description(
|
|
621
|
+
archived ? "Archive runs: hide them from run lists and counts, still reachable by id (owner/admin)" : "Restore archived runs to the run lists (owner/admin)"
|
|
622
|
+
).argument("<run-id...>", "run IDs").option("-y, --yes", "skip the confirmation")
|
|
623
|
+
).action(async (runIds, opts) => {
|
|
624
|
+
try {
|
|
625
|
+
await confirmWrite(archiveQuestion(runIds.length, archived), opts);
|
|
626
|
+
const result = await (await deps.client(opts)).post("/api/v1/actions/runs/archive", {
|
|
627
|
+
runIds,
|
|
628
|
+
archived
|
|
629
|
+
});
|
|
630
|
+
deps.output(opts, result, (r) => console.log(`${verb}d ${plural(r.archived, "run")}`));
|
|
631
|
+
} catch (e) {
|
|
632
|
+
const missing = notFoundIds(e);
|
|
633
|
+
if (!opts.json && missing.length > 0 && e instanceof PlatformApiError) {
|
|
634
|
+
deps.fail(new PlatformApiError(e.status, `${e.message} \u2014 not found: ${missing.join(", ")}`, e.body), opts);
|
|
635
|
+
}
|
|
636
|
+
deps.fail(e, opts);
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// src/actions-workflows.ts
|
|
643
|
+
function formatAgo(iso, now = Date.now()) {
|
|
644
|
+
const s = Math.max(0, Math.round((now - Date.parse(iso)) / 1e3));
|
|
645
|
+
if (s < 60) return `${s}s ago`;
|
|
646
|
+
const m = Math.floor(s / 60);
|
|
647
|
+
if (m < 60) return `${m}m ago`;
|
|
648
|
+
const h = Math.floor(m / 60);
|
|
649
|
+
if (h < 48) return `${h}h ago`;
|
|
650
|
+
return `${Math.floor(h / 24)}d ago`;
|
|
651
|
+
}
|
|
652
|
+
function orderText(order) {
|
|
653
|
+
return order && order.length > 0 ? order.map(safeTerm).join(",") : "inherits";
|
|
654
|
+
}
|
|
655
|
+
function snapshotText(cap) {
|
|
656
|
+
if (cap === null || cap === void 0) return "dynamic";
|
|
657
|
+
return cap === 0 ? "off" : String(cap);
|
|
658
|
+
}
|
|
659
|
+
function formatWorkflowInputs(inputs) {
|
|
660
|
+
return inputs.map((i) => {
|
|
661
|
+
const name = safeTerm(i.name);
|
|
662
|
+
if (i.required) return `${name}* (required)`;
|
|
663
|
+
return i.default !== "" ? `${name} default=${safeTerm(i.default)}` : name;
|
|
664
|
+
}).join(", ");
|
|
665
|
+
}
|
|
666
|
+
function stateLabel(w) {
|
|
667
|
+
if (w.repoEnabled === false) return pc4.gray("\u25CB repo disabled");
|
|
668
|
+
if (w.enabled === false || w.userDisabledAt) return pc4.gray("\u25CB disabled (user)");
|
|
669
|
+
return pc4.green("\u25CF enabled");
|
|
670
|
+
}
|
|
671
|
+
function formatWorkflowRow(w, now = Date.now()) {
|
|
672
|
+
const last = w.lastRun ? `${conclusionLabel(w.lastRun.conclusion)} ${formatAgo(w.lastRun.queuedAt, now)}` : "never";
|
|
673
|
+
const inputs = formatWorkflowInputs(w.inputs ?? []);
|
|
674
|
+
return [
|
|
675
|
+
stateLabel(w),
|
|
676
|
+
pc4.dim(safeTerm(w.repoFullName)),
|
|
677
|
+
`${safeTerm(w.path)} (${safeTerm(w.name)})`,
|
|
678
|
+
`order: ${orderText(w.providerOrder)}`,
|
|
679
|
+
`snapshots: ${snapshotText(w.snapshotCap)}`,
|
|
680
|
+
`last: ${last}`,
|
|
681
|
+
...inputs ? [pc4.dim(`inputs: ${inputs}`)] : []
|
|
682
|
+
].join(" ");
|
|
683
|
+
}
|
|
684
|
+
function formatRefOnlyRow(w) {
|
|
685
|
+
const inputs = formatWorkflowInputs(w.inputs);
|
|
686
|
+
return [
|
|
687
|
+
pc4.cyan("\u25C7 ref-only"),
|
|
688
|
+
`${safeTerm(w.path)} (${safeTerm(w.name)})`,
|
|
689
|
+
w.dispatchable ? inputs ? `inputs: ${inputs}` : pc4.dim("no inputs") : pc4.dim("push-only: dispatch with --manual")
|
|
690
|
+
].join(" ");
|
|
691
|
+
}
|
|
692
|
+
function matchRefOnly(refOnly, selector) {
|
|
693
|
+
const byPath = refOnly.find((w) => w.path === selector);
|
|
694
|
+
if (byPath) return byPath;
|
|
695
|
+
const byName = refOnly.filter((w) => w.name === selector);
|
|
696
|
+
if (byName.length > 1) {
|
|
697
|
+
throw new PlatformClientError(
|
|
698
|
+
"invalid_argument",
|
|
699
|
+
`"${selector}" matches ${byName.length} workflows only on this ref: ${byName.map((w) => safeTerm(w.path)).join(", ")}. Pass the path.`
|
|
700
|
+
);
|
|
701
|
+
}
|
|
702
|
+
return byName[0];
|
|
703
|
+
}
|
|
704
|
+
function workflowChoices(workflows) {
|
|
705
|
+
return [...new Set(workflows.map((w) => `${w.path} (${w.name})`))].join(", ") || "none";
|
|
706
|
+
}
|
|
707
|
+
function resolveControlTarget(catalog, repo, selector) {
|
|
708
|
+
const inRepo = catalog.filter((w) => w.repoFullName === repo);
|
|
709
|
+
let paths;
|
|
710
|
+
try {
|
|
711
|
+
paths = resolveWorkflowPaths(inRepo, [selector]);
|
|
712
|
+
} catch (e) {
|
|
713
|
+
if (e instanceof PlatformClientError && e.code === "workflow_not_found") {
|
|
714
|
+
throw new PlatformClientError("workflow_not_found", `No workflow "${selector}" in ${repo}. Available: ${workflowChoices(inRepo)}`);
|
|
715
|
+
}
|
|
716
|
+
throw e;
|
|
717
|
+
}
|
|
718
|
+
if (paths.length > 1) {
|
|
719
|
+
throw new PlatformClientError(
|
|
720
|
+
"invalid_argument",
|
|
721
|
+
`"${selector}" matches ${paths.length} workflows in ${repo}: ${paths.join(", ")}. Pass the path.`
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
return paths[0];
|
|
725
|
+
}
|
|
726
|
+
function setControls(opts) {
|
|
727
|
+
const controls = {};
|
|
728
|
+
if (opts.order !== void 0 && opts.inheritOrder) {
|
|
729
|
+
throw new PlatformClientError("invalid_argument", "Pass --order or --inherit-order, not both.");
|
|
730
|
+
}
|
|
731
|
+
if (opts.snapshotCap !== void 0 && opts.dynamicSnapshots) {
|
|
732
|
+
throw new PlatformClientError("invalid_argument", "Pass --snapshot-cap or --dynamic-snapshots, not both.");
|
|
733
|
+
}
|
|
734
|
+
if (opts.inheritOrder) controls.providerOrder = null;
|
|
735
|
+
if (opts.order !== void 0) {
|
|
736
|
+
const order = opts.order.split(",").map((s) => s.trim()).filter(Boolean);
|
|
737
|
+
if (order.length === 0) {
|
|
738
|
+
throw new PlatformClientError(
|
|
739
|
+
"invalid_argument",
|
|
740
|
+
`--order "${opts.order}" names no providers \u2014 pass a comma-separated list, or --inherit-order.`
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
controls.providerOrder = order;
|
|
744
|
+
}
|
|
745
|
+
if (opts.dynamicSnapshots) controls.snapshotCap = null;
|
|
746
|
+
if (opts.snapshotCap !== void 0) {
|
|
747
|
+
if (!/^\d+$/.test(opts.snapshotCap.trim())) {
|
|
748
|
+
throw new PlatformClientError(
|
|
749
|
+
"invalid_argument",
|
|
750
|
+
`Invalid --snapshot-cap "${opts.snapshotCap}". Expected a whole number (0 turns snapshots off), or --dynamic-snapshots.`
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
controls.snapshotCap = Number(opts.snapshotCap.trim());
|
|
754
|
+
}
|
|
755
|
+
if (Object.keys(controls).length === 0) {
|
|
756
|
+
throw new PlatformClientError(
|
|
757
|
+
"invalid_argument",
|
|
758
|
+
"Nothing to change \u2014 pass --order, --inherit-order, --snapshot-cap or --dynamic-snapshots."
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
return controls;
|
|
762
|
+
}
|
|
763
|
+
function describeControls(c) {
|
|
764
|
+
const parts = [];
|
|
765
|
+
if (c.providerOrder !== void 0) parts.push(`order: ${orderText(c.providerOrder)}`);
|
|
766
|
+
if (c.snapshotCap !== void 0) parts.push(`snapshots: ${snapshotText(c.snapshotCap)}`);
|
|
767
|
+
return parts.join(", ");
|
|
768
|
+
}
|
|
769
|
+
function formatControlsResult(verb, r) {
|
|
770
|
+
const detail = verb === "set" ? ` order: ${orderText(r.providerOrder)} snapshots: ${snapshotText(r.snapshotCap)}` : "";
|
|
771
|
+
return `${verb} ${pc4.cyan(safeTerm(r.repoFullName))} ${safeTerm(r.path)}${detail}`;
|
|
772
|
+
}
|
|
773
|
+
function registerWorkflowsCommands(actions, common2, deps) {
|
|
774
|
+
const workflows = actions.command("workflows").description("List workflows with their controls (every repo, or one); --all adds disabled ones, --ref the files only a branch has");
|
|
775
|
+
common2(
|
|
776
|
+
workflows.argument("[repo]", "repository in owner/repo format (default: every repo)").option("--all", "include user-disabled workflows and workflows on disabled repos").option("--ref <ref>", "with a repo: also list the workflow files only this branch or tag has (dispatchable by path)")
|
|
777
|
+
).action(async (repo, opts) => {
|
|
778
|
+
try {
|
|
779
|
+
if (opts.ref !== void 0 && repo === void 0) {
|
|
780
|
+
throw new PlatformClientError("invalid_argument", "--ref needs a repo: compute actions workflows <owner/repo> --ref <ref>.");
|
|
781
|
+
}
|
|
782
|
+
const c = await deps.client(opts);
|
|
783
|
+
const data = await c.get("/api/v1/actions/workflows", {
|
|
784
|
+
repo,
|
|
785
|
+
include: opts.all ? "all" : void 0,
|
|
786
|
+
ref: opts.ref
|
|
787
|
+
});
|
|
788
|
+
deps.output(opts, data, (d) => {
|
|
789
|
+
if (d.workflows.length === 0 && (d.refOnly ?? []).length === 0) {
|
|
790
|
+
console.log("No workflows found.");
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
for (const w of d.workflows) console.log(formatWorkflowRow(w));
|
|
794
|
+
if (opts.ref !== void 0) {
|
|
795
|
+
const refOnly = d.refOnly ?? [];
|
|
796
|
+
console.log(pc4.dim(refOnly.length === 0 ? `only on ${safeTerm(opts.ref)}: none` : `only on ${safeTerm(opts.ref)}:`));
|
|
797
|
+
for (const w of refOnly) console.log(formatRefOnlyRow(w));
|
|
798
|
+
}
|
|
799
|
+
});
|
|
800
|
+
} catch (e) {
|
|
801
|
+
deps.fail(e, opts);
|
|
802
|
+
}
|
|
803
|
+
});
|
|
804
|
+
async function writeControls(repo, selector, controls, question, verb, opts) {
|
|
805
|
+
await confirmWrite(question, opts);
|
|
806
|
+
const c = await deps.client(opts);
|
|
807
|
+
const { workflows: catalog } = await c.get("/api/v1/actions/workflows", {
|
|
808
|
+
repo,
|
|
809
|
+
include: "all"
|
|
810
|
+
});
|
|
811
|
+
const path2 = resolveControlTarget(catalog, repo, selector);
|
|
812
|
+
const result = await c.patch("/api/v1/actions/workflows", {
|
|
813
|
+
repoFullName: repo,
|
|
814
|
+
path: path2,
|
|
815
|
+
...controls
|
|
816
|
+
});
|
|
817
|
+
deps.output(opts, result, (r) => console.log(formatControlsResult(verb, r)));
|
|
818
|
+
}
|
|
819
|
+
for (const enabled of [true, false]) {
|
|
820
|
+
const verb = enabled ? "enable" : "disable";
|
|
821
|
+
common2(
|
|
822
|
+
workflows.command(verb).description(
|
|
823
|
+
enabled ? "Turn a workflow back on (owner/admin)" : "Turn a workflow off: no pushes, schedules or dispatches run it until enabled (owner/admin)"
|
|
824
|
+
).argument("<repo>", "repository in owner/repo format").argument("<workflow>", "workflow path, name, file name (ci.yml) or id").option("-y, --yes", "skip the confirmation")
|
|
825
|
+
).action(async (repo, selector, opts) => {
|
|
826
|
+
try {
|
|
827
|
+
const question = enabled ? `Enable workflow "${selector}" in ${repo}? It runs again on its triggers.` : `Disable workflow "${selector}" in ${repo}? Pushes, schedules and dispatches stop running it until it is enabled.`;
|
|
828
|
+
await writeControls(repo, selector, { enabled }, question, `${verb}d`, opts);
|
|
829
|
+
} catch (e) {
|
|
830
|
+
deps.fail(e, opts);
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
common2(
|
|
835
|
+
workflows.command("set").description("Set a workflow's provider order and snapshot cap (owner/admin)").argument("<repo>", "repository in owner/repo format").argument("<workflow>", "workflow path, name, file name (ci.yml) or id").option("--order <providers>", 'provider order for this workflow, comma-separated (e.g. "market,blaxel,vercel")').option("--inherit-order", "drop the workflow's order: it follows the org order").option("--snapshot-cap <n>", "most snapshots this workflow keeps (0 turns them off)").option("--dynamic-snapshots", "drop the cap: the workflow uses the dynamic snapshot pool").option("-y, --yes", "skip the confirmation")
|
|
836
|
+
).action(async (repo, selector, opts) => {
|
|
837
|
+
try {
|
|
838
|
+
const controls = setControls(opts);
|
|
839
|
+
await writeControls(
|
|
840
|
+
repo,
|
|
841
|
+
selector,
|
|
842
|
+
controls,
|
|
843
|
+
`Change workflow "${selector}" in ${repo} (${describeControls(controls)})?`,
|
|
844
|
+
"set",
|
|
845
|
+
opts
|
|
846
|
+
);
|
|
847
|
+
} catch (e) {
|
|
848
|
+
deps.fail(e, opts);
|
|
849
|
+
}
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// src/actions-repos.ts
|
|
854
|
+
var FORK_PRS = { allow: true, refuse: false };
|
|
855
|
+
function plural2(n, noun) {
|
|
856
|
+
return `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
857
|
+
}
|
|
858
|
+
function formatIn(iso, now = Date.now()) {
|
|
859
|
+
const s = Math.max(0, Math.round((Date.parse(iso) - now) / 1e3));
|
|
860
|
+
if (s < 60) return `in ${s}s`;
|
|
861
|
+
const m = Math.round(s / 60);
|
|
862
|
+
if (m < 60) return `in ${m}m`;
|
|
863
|
+
const h = Math.round(m / 60);
|
|
864
|
+
if (h < 48) return `in ${h}h`;
|
|
865
|
+
return `in ${Math.round(h / 24)}d`;
|
|
866
|
+
}
|
|
867
|
+
function pollText(r, now) {
|
|
868
|
+
if (!r.enabled) return null;
|
|
869
|
+
if (r.pollSchedule === "never") return "not polled yet";
|
|
870
|
+
if (!r.nextPollDueAt) return null;
|
|
871
|
+
return Date.parse(r.nextPollDueAt) <= now ? "poll due" : `next poll ${formatIn(r.nextPollDueAt, now)}`;
|
|
872
|
+
}
|
|
873
|
+
function formatRepoRow(r, now = Date.now()) {
|
|
874
|
+
const head = r.enabled ? pc5.green("enabled") : pc5.dim("disabled");
|
|
875
|
+
const via = r.authType === "github_app" ? "github-app" : r.authType;
|
|
876
|
+
const parts = [
|
|
877
|
+
safeTerm(via),
|
|
878
|
+
safeTerm(r.defaultBranch),
|
|
879
|
+
r.workflowPaths.length > 0 ? plural2(r.workflowPaths.length, "workflow") : "no workflows yet"
|
|
880
|
+
];
|
|
881
|
+
if (r.runs) {
|
|
882
|
+
parts.push(plural2(r.runs.total, "run"));
|
|
883
|
+
if (r.runs.lastRunState && r.runs.lastRunQueuedAt) {
|
|
884
|
+
parts.push(`last ${conclusionLabel(r.runs.lastRunState)} ${formatAgo(r.runs.lastRunQueuedAt, now)}`);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
const poll = pollText(r, now);
|
|
888
|
+
if (poll) parts.push(poll);
|
|
889
|
+
if (r.forkPullRequests) parts.push("fork PRs on");
|
|
890
|
+
const error = r.lastPollError ? pc5.red(` poll error: ${safeTerm(r.lastPollError)}`) : "";
|
|
891
|
+
return `${head} ${safeTerm(r.fullName)} ${pc5.dim(parts.join(" \xB7 "))}${error}`;
|
|
892
|
+
}
|
|
893
|
+
function formatBranchRow(b, now = Date.now(), defaultBranch) {
|
|
894
|
+
const isDefault = defaultBranch !== void 0 && b.ref === `refs/heads/${defaultBranch}`;
|
|
895
|
+
const at = Number.isNaN(Date.parse(b.lastRunAt)) ? null : formatAgo(b.lastRunAt, now);
|
|
896
|
+
return [
|
|
897
|
+
safeTerm(b.ref) + (isDefault ? pc5.dim(" (default)") : ""),
|
|
898
|
+
...b.prNumber !== null ? [`PR #${b.prNumber}`] : [],
|
|
899
|
+
b.watched ? pc5.green("watched") : pc5.dim("history only"),
|
|
900
|
+
plural2(b.runCount, "run"),
|
|
901
|
+
...at ? [b.runCount > 0 ? `last ${at}` : pc5.dim(`moved ${at}`)] : [],
|
|
902
|
+
...b.latestRunId ? [pc5.dim(safeTerm(b.latestRunId))] : []
|
|
903
|
+
].join(" ");
|
|
904
|
+
}
|
|
905
|
+
function printDiscovery(d) {
|
|
906
|
+
if (d.error) {
|
|
907
|
+
console.log(pc5.yellow(`discovery: ${safeTerm(d.error)} (the poll cron retries)`));
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
console.log(pc5.dim(`discovery: ${d.workflowsFound ? "workflows found" : "no workflows yet"}${d.seeded ? ", cursors seeded" : ""}`));
|
|
911
|
+
}
|
|
912
|
+
function withRetryAfter(error) {
|
|
913
|
+
if (!(error instanceof PlatformApiError) || error.status !== 429) return error;
|
|
914
|
+
const next = error.details?.nextAllowedAt;
|
|
915
|
+
if (typeof next !== "string") return error;
|
|
916
|
+
const rewritten = new PlatformApiError(error.status, `${error.message}; retry after ${next} (${formatIn(next)})`, error.body);
|
|
917
|
+
rewritten.retryAfterMs = error.retryAfterMs;
|
|
918
|
+
return rewritten;
|
|
919
|
+
}
|
|
920
|
+
function parseForkPrs(value) {
|
|
921
|
+
if (!Object.prototype.hasOwnProperty.call(FORK_PRS, value)) {
|
|
922
|
+
throw new PlatformClientError("invalid_argument", `Invalid --fork-prs "${value}". Expected allow or refuse.`);
|
|
923
|
+
}
|
|
924
|
+
return FORK_PRS[value];
|
|
925
|
+
}
|
|
926
|
+
var repoIdBody = (opts) => opts.repoId !== void 0 ? { repoId: opts.repoId } : {};
|
|
927
|
+
var REPO_ID_HELP = "scope to one row when two installations grant the same name";
|
|
928
|
+
function registerReposCommands(actions, common2, deps) {
|
|
929
|
+
const { client: client2, output: output2, fail: fail3 } = deps;
|
|
930
|
+
const repos = actions.command("repos").description("List the org's connected repositories: run counts, last run and next poll");
|
|
931
|
+
common2(repos).action(async (opts) => {
|
|
932
|
+
try {
|
|
933
|
+
const data = await (await client2(opts)).get("/api/v1/actions/repos");
|
|
934
|
+
output2(opts, data, (d) => {
|
|
935
|
+
if (d.repos.length === 0) {
|
|
936
|
+
console.log("No repositories connected.");
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
for (const r of d.repos) console.log(formatRepoRow(r));
|
|
940
|
+
});
|
|
941
|
+
} catch (e) {
|
|
942
|
+
fail3(e, opts);
|
|
943
|
+
}
|
|
944
|
+
});
|
|
945
|
+
common2(
|
|
946
|
+
repos.command("connect").description("Connect a git remote (validated by a real ls-remote; lands enabled)").argument("<cloneUrl>", "http(s) or ssh git remote URL").option("--name <owner/repo>", "repo name override (default: derived from cloneUrl)").option("--branch <branch>", "default branch (default: main, else the remote's first)").option("--token <token>", "credential for private http(s) remotes").option("--username <user>", 'username \u2014 with --token, makes auth "basic" instead of "token"').option("--ssh-key-file <path>", "OpenSSH/PEM private key file for ssh remotes").option("--known-hosts-file <path>", "known_hosts pin for ssh remotes")
|
|
947
|
+
).action(async (cloneUrl, opts) => {
|
|
948
|
+
try {
|
|
949
|
+
let body;
|
|
950
|
+
if (opts.sshKeyFile !== void 0) {
|
|
951
|
+
if (opts.token !== void 0 || opts.username !== void 0) {
|
|
952
|
+
throw new Error("Pass either --ssh-key-file or --token/--username, not both.");
|
|
953
|
+
}
|
|
954
|
+
body = {
|
|
955
|
+
authType: "ssh",
|
|
956
|
+
credential: readFileSync(opts.sshKeyFile, "utf8"),
|
|
957
|
+
...opts.knownHostsFile !== void 0 && {
|
|
958
|
+
knownHosts: readFileSync(opts.knownHostsFile, "utf8")
|
|
959
|
+
}
|
|
960
|
+
};
|
|
961
|
+
} else if (opts.username !== void 0) {
|
|
962
|
+
if (opts.token === void 0) throw new Error("--username requires --token.");
|
|
963
|
+
body = { authType: "basic", username: opts.username, credential: opts.token };
|
|
964
|
+
} else if (opts.token !== void 0) {
|
|
965
|
+
body = { authType: "token", credential: opts.token };
|
|
966
|
+
} else {
|
|
967
|
+
body = { authType: "none" };
|
|
968
|
+
}
|
|
969
|
+
if (opts.knownHostsFile !== void 0 && opts.sshKeyFile === void 0) {
|
|
970
|
+
throw new Error("--known-hosts-file requires --ssh-key-file.");
|
|
971
|
+
}
|
|
972
|
+
const result = await (await client2(opts)).post("/api/v1/actions/repos", {
|
|
973
|
+
cloneUrl,
|
|
974
|
+
...body,
|
|
975
|
+
...opts.name !== void 0 && { name: opts.name },
|
|
976
|
+
...opts.branch !== void 0 && { defaultBranch: opts.branch }
|
|
977
|
+
});
|
|
978
|
+
output2(opts, result, (r) => {
|
|
979
|
+
console.log(`connected ${pc5.cyan(safeTerm(r.fullName))} ${pc5.dim(`(${safeTerm(r.authType)}, ${safeTerm(r.defaultBranch)})`)}`);
|
|
980
|
+
printDiscovery(r.discovery);
|
|
981
|
+
});
|
|
982
|
+
} catch (e) {
|
|
983
|
+
fail3(e, opts);
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
common2(
|
|
987
|
+
repos.command("sync").description("Re-read the GitHub App installation so repos granted after install show up (owner/admin key)")
|
|
988
|
+
).action(async (opts) => {
|
|
989
|
+
try {
|
|
990
|
+
const result = await (await client2(opts)).post("/api/v1/actions/repos/sync", {});
|
|
991
|
+
output2(opts, result, (r) => {
|
|
992
|
+
for (const a of r.accounts) {
|
|
993
|
+
console.log(a.error === null ? `synced ${pc5.cyan(safeTerm(a.account))}` : `failed ${pc5.cyan(safeTerm(a.account))} ${pc5.red(safeTerm(a.error))}`);
|
|
994
|
+
}
|
|
995
|
+
console.log(pc5.dim(`${r.repos.length} repos visible`));
|
|
996
|
+
});
|
|
997
|
+
if (result.accounts.some((a) => a.error !== null)) process.exitCode = 1;
|
|
998
|
+
} catch (e) {
|
|
999
|
+
fail3(e, opts);
|
|
1000
|
+
}
|
|
1001
|
+
});
|
|
1002
|
+
common2(
|
|
1003
|
+
repos.command("enable").description("Enable a repo the org can already see (granted by a GitHub App install, or a connected remote)").argument("<repo>", "repository in owner/repo format").option("--repo-id <id>", REPO_ID_HELP)
|
|
1004
|
+
).action(async (repo, opts) => {
|
|
1005
|
+
try {
|
|
1006
|
+
const result = await (await client2(opts)).patch("/api/v1/actions/repos", {
|
|
1007
|
+
fullName: repo,
|
|
1008
|
+
enabled: true,
|
|
1009
|
+
...repoIdBody(opts)
|
|
1010
|
+
});
|
|
1011
|
+
output2(opts, result, (r) => {
|
|
1012
|
+
console.log(`enabled ${pc5.cyan(safeTerm(r.fullName))}`);
|
|
1013
|
+
if (r.discovery) printDiscovery(r.discovery);
|
|
1014
|
+
});
|
|
1015
|
+
} catch (e) {
|
|
1016
|
+
fail3(e, opts);
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
common2(
|
|
1020
|
+
repos.command("disable").description("Disable a repo \u2014 it stays connected but no runs are scheduled").argument("<repo>", "repository in owner/repo format").option("--repo-id <id>", REPO_ID_HELP)
|
|
1021
|
+
).action(async (repo, opts) => {
|
|
1022
|
+
try {
|
|
1023
|
+
const result = await (await client2(opts)).patch("/api/v1/actions/repos", {
|
|
1024
|
+
fullName: repo,
|
|
1025
|
+
enabled: false,
|
|
1026
|
+
...repoIdBody(opts)
|
|
1027
|
+
});
|
|
1028
|
+
output2(opts, result, (r) => console.log(`disabled ${pc5.cyan(safeTerm(r.fullName))}`));
|
|
1029
|
+
} catch (e) {
|
|
1030
|
+
fail3(e, opts);
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
common2(
|
|
1034
|
+
repos.command("poll").description("Poll a repo now: fetch its refs and start the runs new commits call for (owner/admin; at most every 30 s)").argument("<repo>", "repository in owner/repo format").option("--repo-id <id>", REPO_ID_HELP).option("-y, --yes", "skip the confirmation")
|
|
1035
|
+
).action(async (repo, opts) => {
|
|
1036
|
+
try {
|
|
1037
|
+
await confirmWrite(`Poll ${repo} now? New commits on its watched refs start the runs their workflows call for.`, opts);
|
|
1038
|
+
const c = await client2(opts);
|
|
1039
|
+
let result;
|
|
1040
|
+
try {
|
|
1041
|
+
result = await c.post("/api/v1/actions/repos/poll", { fullName: repo, ...repoIdBody(opts) });
|
|
1042
|
+
} catch (e) {
|
|
1043
|
+
throw withRetryAfter(e);
|
|
1044
|
+
}
|
|
1045
|
+
output2(opts, result, (r) => {
|
|
1046
|
+
console.log(`polled ${pc5.cyan(safeTerm(r.fullName))} ${plural2(r.createdRunIds.length, "run")} started`);
|
|
1047
|
+
if (r.error) console.log(pc5.red(`poll error: ${safeTerm(r.error)}`));
|
|
1048
|
+
});
|
|
1049
|
+
if (result.error) process.exitCode = 1;
|
|
1050
|
+
} catch (e) {
|
|
1051
|
+
fail3(e, opts);
|
|
1052
|
+
}
|
|
1053
|
+
});
|
|
1054
|
+
common2(
|
|
1055
|
+
repos.command("set").description("Change a repo's settings: whether pull requests from forks run CI (owner/admin)").argument("<repo>", "repository in owner/repo format").requiredOption("--fork-prs <allow|refuse>", "run pull requests from forks (isolated: no org secrets, no GitHub token), or refuse them").option("--repo-id <id>", REPO_ID_HELP).option("-y, --yes", "skip the confirmation")
|
|
1056
|
+
).action(async (repo, opts) => {
|
|
1057
|
+
try {
|
|
1058
|
+
const forkPullRequests = parseForkPrs(opts.forkPrs);
|
|
1059
|
+
await confirmWrite(
|
|
1060
|
+
forkPullRequests ? `Run pull requests from forks on ${repo}? They run isolated: no org secrets, no GitHub token, and the base branch's workflow definition.` : `Refuse pull requests from forks on ${repo}? Fork pull requests stop running CI.`,
|
|
1061
|
+
opts
|
|
1062
|
+
);
|
|
1063
|
+
const result = await (await client2(opts)).patch("/api/v1/actions/repos", {
|
|
1064
|
+
fullName: repo,
|
|
1065
|
+
forkPullRequests,
|
|
1066
|
+
...repoIdBody(opts)
|
|
1067
|
+
});
|
|
1068
|
+
output2(
|
|
1069
|
+
opts,
|
|
1070
|
+
result,
|
|
1071
|
+
(r) => console.log(`fork PRs ${r.forkPullRequests === false ? "refused" : "allowed"} ${pc5.cyan(safeTerm(r.fullName))}`)
|
|
1072
|
+
);
|
|
1073
|
+
} catch (e) {
|
|
1074
|
+
fail3(e, opts);
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
1077
|
+
common2(
|
|
1078
|
+
actions.command("branches").description("List a repo's refs: watched branches and pull requests, then refs with run history only").argument("<repo>", "repository in owner/repo format").option("--search <text>", "only refs containing this text (case-insensitive)").option("--archived", "count archived runs instead of active ones").option("--repo-id <id>", REPO_ID_HELP)
|
|
1079
|
+
).action(async (repo, opts) => {
|
|
1080
|
+
try {
|
|
1081
|
+
const data = await (await client2(opts)).get("/api/v1/actions/repos/branches", {
|
|
1082
|
+
repo,
|
|
1083
|
+
repoId: opts.repoId,
|
|
1084
|
+
q: opts.search,
|
|
1085
|
+
archived: opts.archived ? "1" : void 0
|
|
1086
|
+
});
|
|
1087
|
+
output2(opts, data, (d) => {
|
|
1088
|
+
console.log(`${pc5.bold(safeTerm(d.repo))} ${pc5.dim(`default: ${safeTerm(d.defaultBranch)}`)}`);
|
|
1089
|
+
if (d.branches.length === 0) {
|
|
1090
|
+
console.log("No branches found.");
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
const now = Date.now();
|
|
1094
|
+
for (const b of d.branches) console.log(formatBranchRow(b, now, d.defaultBranch));
|
|
1095
|
+
});
|
|
1096
|
+
} catch (e) {
|
|
1097
|
+
fail3(e, opts);
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
// src/actions-integrations.ts
|
|
1103
|
+
import pc6 from "picocolors";
|
|
1104
|
+
function formatInstallationRow(i) {
|
|
1105
|
+
const head = i.suspended ? pc6.yellow(safeTerm(i.account)) : pc6.cyan(safeTerm(i.account));
|
|
1106
|
+
const parts = [
|
|
1107
|
+
i.accountType ? safeTerm(i.accountType) : "account",
|
|
1108
|
+
i.repoSelection === "all" ? "all repos" : "selected repos",
|
|
1109
|
+
`${i.repos.granted} granted, ${i.repos.enabled} enabled`,
|
|
1110
|
+
...i.suspended ? [pc6.yellow(`suspended ${safeTerm(i.suspendedAt ?? "")}`.trim())] : [],
|
|
1111
|
+
pc6.dim(`installed ${safeTerm(i.installedAt)}`)
|
|
1112
|
+
];
|
|
1113
|
+
return `${head} ${parts.join(" ")}`;
|
|
1114
|
+
}
|
|
1115
|
+
function formatInstallations(data) {
|
|
1116
|
+
if (data.installations.length === 0) {
|
|
1117
|
+
return ["No GitHub App installations. Run `compute actions installations install-url` for where to install it."];
|
|
1118
|
+
}
|
|
1119
|
+
const lines = [];
|
|
1120
|
+
for (const i of data.installations) {
|
|
1121
|
+
lines.push(formatInstallationRow(i));
|
|
1122
|
+
if (i.configureUrl) lines.push(` ${pc6.dim(`configure: ${safeTerm(i.configureUrl)}`)}`);
|
|
1123
|
+
}
|
|
1124
|
+
return lines;
|
|
1125
|
+
}
|
|
1126
|
+
function formatSlack(s) {
|
|
1127
|
+
if (!s.installed) {
|
|
1128
|
+
return ["Slack is not connected. Run `compute actions slack install-url` for where to connect it."];
|
|
1129
|
+
}
|
|
1130
|
+
const channel = s.channelId ? `${s.channelName ? `#${safeTerm(s.channelName)} ` : ""}${pc6.dim(safeTerm(s.channelId))}` : pc6.gray("no channel picked");
|
|
1131
|
+
const brief = s.brief.enabled ? `${s.brief.times.map(safeTerm).join(", ")} ${safeTerm(s.brief.timeZone)}${s.brief.categories.length > 0 ? ` categories: ${s.brief.categories.map(safeTerm).join(", ")}` : ""}` : pc6.gray("off");
|
|
1132
|
+
return [
|
|
1133
|
+
`workspace: ${s.teamName ? safeTerm(s.teamName) : pc6.gray("(unnamed)")}`,
|
|
1134
|
+
`channel: ${channel}`,
|
|
1135
|
+
`notify on: ${s.notifyOn === "failure" ? "failures and cancels" : "every conclusion"}`,
|
|
1136
|
+
`daily brief: ${brief}`
|
|
1137
|
+
];
|
|
1138
|
+
}
|
|
1139
|
+
function formatInstallLink(link, what) {
|
|
1140
|
+
if (!link.configured || link.url === null) {
|
|
1141
|
+
return [what === "github" ? "This deployment has no GitHub App configured." : "This deployment has no Slack app configured."];
|
|
1142
|
+
}
|
|
1143
|
+
return [
|
|
1144
|
+
safeTerm(link.url),
|
|
1145
|
+
pc6.dim(
|
|
1146
|
+
what === "github" ? "Open it signed in as an org owner/admin and press Install GitHub App." : "Open it in a browser signed in as an org owner/admin; it continues to Slack."
|
|
1147
|
+
)
|
|
1148
|
+
];
|
|
1149
|
+
}
|
|
1150
|
+
function registerIntegrationsCommands(actions, common2, deps) {
|
|
1151
|
+
const { client: client2, output: output2, fail: fail3 } = deps;
|
|
1152
|
+
const print = (lines) => {
|
|
1153
|
+
for (const line of lines) console.log(line);
|
|
1154
|
+
};
|
|
1155
|
+
const installations = common2(
|
|
1156
|
+
actions.command("installations").description("List the org's GitHub App installations (account, repo selection and counts, suspension)")
|
|
1157
|
+
).action(async (opts) => {
|
|
1158
|
+
try {
|
|
1159
|
+
const data = await (await client2(opts)).get("/api/v1/actions/installations");
|
|
1160
|
+
output2(opts, data, (d) => print(formatInstallations(d)));
|
|
1161
|
+
} catch (e) {
|
|
1162
|
+
fail3(e, opts);
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
common2(
|
|
1166
|
+
installations.command("install-url").description("Print where an owner/admin installs the GitHub App into another account")
|
|
1167
|
+
).action(async (opts) => {
|
|
1168
|
+
try {
|
|
1169
|
+
const data = await (await client2(opts)).get("/api/v1/actions/installations/install-url");
|
|
1170
|
+
output2(opts, data, (d) => print(formatInstallLink(d, "github")));
|
|
1171
|
+
} catch (e) {
|
|
1172
|
+
fail3(e, opts);
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
const slack = common2(
|
|
1176
|
+
actions.command("slack").description("Show the org's Slack connection (workspace, channel, notify rule, daily brief; owner/admin)")
|
|
1177
|
+
).action(async (opts) => {
|
|
1178
|
+
try {
|
|
1179
|
+
const data = await (await client2(opts)).get("/api/v1/actions/slack");
|
|
1180
|
+
output2(opts, data, (d) => print(formatSlack(d)));
|
|
1181
|
+
} catch (e) {
|
|
1182
|
+
fail3(e, opts);
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
common2(
|
|
1186
|
+
slack.command("install-url").description("Print where an owner/admin connects a Slack workspace")
|
|
273
1187
|
).action(async (opts) => {
|
|
274
1188
|
try {
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
const caps = {};
|
|
278
|
-
for (const entry of opts.cap) {
|
|
279
|
-
const { size, cap } = parseSizeCap(entry);
|
|
280
|
-
caps[size] = cap;
|
|
281
|
-
}
|
|
282
|
-
body.marketCaps = caps;
|
|
283
|
-
}
|
|
284
|
-
if (opts.generalCap !== void 0) {
|
|
285
|
-
body.marketCap = opts.generalCap === "none" ? null : parseMaxPrice(opts.generalCap, void 0);
|
|
286
|
-
}
|
|
287
|
-
if (opts.orderType !== void 0) {
|
|
288
|
-
if (lane === "sandboxes" && opts.orderType === "inherit") {
|
|
289
|
-
body.marketOrderType = null;
|
|
290
|
-
} else if (opts.orderType === "limit" || opts.orderType === "market") {
|
|
291
|
-
body.marketOrderType = opts.orderType;
|
|
292
|
-
} else {
|
|
293
|
-
throw new Error(
|
|
294
|
-
lane === "sandboxes" ? "--order-type must be limit, market, or inherit." : "--order-type must be limit or market."
|
|
295
|
-
);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (opts.order !== void 0) {
|
|
299
|
-
if (opts.order === "inherit" && lane === "sandboxes") {
|
|
300
|
-
body.providerOrder = [];
|
|
301
|
-
} else if (opts.order === "default" && lane === "actions") {
|
|
302
|
-
body.providerOrder = [];
|
|
303
|
-
} else {
|
|
304
|
-
body.providerOrder = opts.order.split(",").map((s) => s.trim()).filter(Boolean);
|
|
305
|
-
if (body.providerOrder.length === 0) {
|
|
306
|
-
throw new Error(
|
|
307
|
-
lane === "sandboxes" ? `--order "${opts.order}" names no providers \u2014 pass a comma-separated list or "inherit".` : `--order "${opts.order}" names no providers \u2014 pass a comma-separated list or "default".`
|
|
308
|
-
);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
if (Object.keys(body).length === 0) {
|
|
313
|
-
throw new Error(
|
|
314
|
-
"Nothing to change \u2014 pass --cap, --general-cap, --order-type, or --order."
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
const c = await deps.client(opts);
|
|
318
|
-
const res = await c.patch(`/api/v1/${lane}/settings`, body);
|
|
319
|
-
deps.output(opts, res, (s) => printLaneSettings(s, lane));
|
|
1189
|
+
const data = await (await client2(opts)).get("/api/v1/actions/slack/install-url");
|
|
1190
|
+
output2(opts, data, (d) => print(formatInstallLink(d, "slack")));
|
|
320
1191
|
} catch (e) {
|
|
321
|
-
|
|
1192
|
+
fail3(e, opts);
|
|
322
1193
|
}
|
|
323
1194
|
});
|
|
324
1195
|
}
|
|
@@ -330,6 +1201,75 @@ function sanitizePathPart(name) {
|
|
|
330
1201
|
if (base === "" || base === "." || base === "..") return "artifact";
|
|
331
1202
|
return base;
|
|
332
1203
|
}
|
|
1204
|
+
function scheduleQuery(opts) {
|
|
1205
|
+
const from = opts.from === void 0 ? /* @__PURE__ */ new Date() : new Date(opts.from);
|
|
1206
|
+
const to = opts.to === void 0 ? new Date(from.getTime() + 7 * 864e5) : new Date(opts.to);
|
|
1207
|
+
if (!Number.isFinite(from.getTime()) || !Number.isFinite(to.getTime())) {
|
|
1208
|
+
throw new PlatformClientError("invalid_argument", "--from and --to must be valid timestamps.");
|
|
1209
|
+
}
|
|
1210
|
+
return {
|
|
1211
|
+
from: from.toISOString(),
|
|
1212
|
+
to: to.toISOString(),
|
|
1213
|
+
repo: opts.repo,
|
|
1214
|
+
workflow: opts.workflow,
|
|
1215
|
+
event: opts.event,
|
|
1216
|
+
status: opts.status,
|
|
1217
|
+
reliability: opts.reliability ? "1" : void 0,
|
|
1218
|
+
timeZone: opts.tz ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1219
|
+
limit: opts.limit,
|
|
1220
|
+
cursor: opts.cursor
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
function nextScheduleCommand(data, opts) {
|
|
1224
|
+
const args = ["compute", "actions", "schedule", "--from", data.from, "--to", data.to, "--tz", data.timeZone];
|
|
1225
|
+
for (const key of ["repo", "workflow", "event", "status", "limit", "org", "baseUrl"]) {
|
|
1226
|
+
const value = opts[key];
|
|
1227
|
+
if (value === void 0) continue;
|
|
1228
|
+
for (const item of Array.isArray(value) ? value : [value]) args.push(`--${key === "baseUrl" ? "base-url" : key}`, item);
|
|
1229
|
+
}
|
|
1230
|
+
if (opts.reliability) args.push("--reliability");
|
|
1231
|
+
if (opts.allowUntrustedHost) args.push("--allow-untrusted-host");
|
|
1232
|
+
args.push("--cursor", data.nextCursor);
|
|
1233
|
+
return args.map((value) => /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`).join(" ");
|
|
1234
|
+
}
|
|
1235
|
+
function formatSchedule(data, nextCommand) {
|
|
1236
|
+
const time = new Intl.DateTimeFormat("en-CA", {
|
|
1237
|
+
timeZone: data.timeZone,
|
|
1238
|
+
year: "numeric",
|
|
1239
|
+
month: "2-digit",
|
|
1240
|
+
day: "2-digit",
|
|
1241
|
+
hour: "2-digit",
|
|
1242
|
+
minute: "2-digit",
|
|
1243
|
+
second: "2-digit",
|
|
1244
|
+
hourCycle: "h23",
|
|
1245
|
+
timeZoneName: "short"
|
|
1246
|
+
});
|
|
1247
|
+
const lines = [pc7.bold(`Upcoming fires (${safeTerm(data.timeZone)})`)];
|
|
1248
|
+
const fires = data.upcoming.flatMap((schedule) => schedule.occurrences.map((at) => ({ at, schedule }))).sort((a, b) => a.at.localeCompare(b.at));
|
|
1249
|
+
if (fires.length === 0) lines.push("No upcoming fires.");
|
|
1250
|
+
for (const { at, schedule } of fires) {
|
|
1251
|
+
lines.push([time.format(new Date(at)), safeTerm(schedule.workflowName || schedule.workflowPath), safeTerm(schedule.repoFullName), safeTerm(schedule.description)].join(" "));
|
|
1252
|
+
}
|
|
1253
|
+
for (const schedule of data.upcoming) {
|
|
1254
|
+
const remaining = schedule.occurrenceCount - schedule.occurrences.length;
|
|
1255
|
+
if (remaining > 0) lines.push(`+${remaining.toLocaleString("en-US")} more scheduled for ${safeTerm(schedule.workflowName || schedule.workflowPath)} ${safeTerm(schedule.repoFullName)} ${safeTerm(schedule.description)}`);
|
|
1256
|
+
}
|
|
1257
|
+
lines.push("", pc7.bold(`Past runs (${safeTerm(data.timeZone)})`));
|
|
1258
|
+
if (data.runs.length === 0) lines.push("No past runs found.");
|
|
1259
|
+
for (const run of data.runs) {
|
|
1260
|
+
lines.push([
|
|
1261
|
+
time.format(new Date(run.startedAt ?? run.createdAt)),
|
|
1262
|
+
safeTerm(run.workflowName || run.workflowPath),
|
|
1263
|
+
safeTerm(run.repoFullName),
|
|
1264
|
+
safeTerm(run.event),
|
|
1265
|
+
conclusionLabel(safeTerm(run.status === "completed" ? run.conclusion : run.status))
|
|
1266
|
+
].join(" "));
|
|
1267
|
+
}
|
|
1268
|
+
if (data.countsTruncated) lines.push("Warning: some schedule totals reached the safety limit; use a smaller window for exact counts.");
|
|
1269
|
+
if (nextCommand) lines.push("", `Next page (reuse the same credentials):
|
|
1270
|
+
${safeTerm(nextCommand)}`);
|
|
1271
|
+
return lines.join("\n");
|
|
1272
|
+
}
|
|
333
1273
|
async function client(opts) {
|
|
334
1274
|
return new ActionsClient(await resolveActionsAuth(opts));
|
|
335
1275
|
}
|
|
@@ -386,7 +1326,7 @@ async function fetchRunSummary(c, runId) {
|
|
|
386
1326
|
} catch (e) {
|
|
387
1327
|
if (!(e instanceof PlatformApiError && e.status === 404)) {
|
|
388
1328
|
console.error(
|
|
389
|
-
|
|
1329
|
+
pc7.dim(`summary unavailable: ${e instanceof Error ? e.message : String(e)}`)
|
|
390
1330
|
);
|
|
391
1331
|
}
|
|
392
1332
|
return null;
|
|
@@ -396,9 +1336,9 @@ function fail(error, opts = {}) {
|
|
|
396
1336
|
if (opts.json) {
|
|
397
1337
|
process.stderr.write(JSON.stringify(toErrorEnvelope(error)) + "\n");
|
|
398
1338
|
} else if (error instanceof PlatformApiError) {
|
|
399
|
-
console.error(
|
|
1339
|
+
console.error(pc7.red(`Error (${error.status}): ${safeTermText(error.message)}`));
|
|
400
1340
|
} else {
|
|
401
|
-
console.error(
|
|
1341
|
+
console.error(pc7.red(`Error: ${safeTermText(error instanceof Error ? error.message : String(error))}`));
|
|
402
1342
|
}
|
|
403
1343
|
process.exit(1);
|
|
404
1344
|
}
|
|
@@ -423,39 +1363,24 @@ function formatDuration(ms) {
|
|
|
423
1363
|
function shortSha(sha) {
|
|
424
1364
|
return sha.slice(0, 8);
|
|
425
1365
|
}
|
|
426
|
-
function conclusionLabel(conclusion) {
|
|
427
|
-
switch (conclusion) {
|
|
428
|
-
case "passed":
|
|
429
|
-
return pc2.green("passed");
|
|
430
|
-
case "failed":
|
|
431
|
-
return pc2.red("failed");
|
|
432
|
-
case "running":
|
|
433
|
-
return pc2.yellow("running");
|
|
434
|
-
case "cancelled":
|
|
435
|
-
return pc2.gray("cancelled");
|
|
436
|
-
case "none":
|
|
437
|
-
return pc2.yellow("queued");
|
|
438
|
-
default:
|
|
439
|
-
return conclusion;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
1366
|
function formatRunRow(run) {
|
|
443
1367
|
const num = run.runNumber === null ? "-" : `#${run.runNumber}`;
|
|
444
1368
|
return [
|
|
445
1369
|
run.id,
|
|
446
|
-
|
|
1370
|
+
pc7.dim(num),
|
|
447
1371
|
run.workflowName || run.workflowPath,
|
|
448
1372
|
conclusionLabel(run.conclusion),
|
|
449
|
-
|
|
1373
|
+
pc7.dim(`${run.repoFullName}@${run.ref}`),
|
|
450
1374
|
shortSha(run.headSha),
|
|
451
1375
|
formatDuration(run.durationMs),
|
|
452
|
-
run.startedAt
|
|
1376
|
+
run.startedAt,
|
|
1377
|
+
...run.archivedAt ? [pc7.dim("archived")] : []
|
|
453
1378
|
].join(" ");
|
|
454
1379
|
}
|
|
455
1380
|
function formatRunDetail(run, runUrl) {
|
|
456
1381
|
const lines = [];
|
|
457
|
-
lines.push(`${
|
|
458
|
-
lines.push(
|
|
1382
|
+
lines.push(`${pc7.bold(run.workflowName || run.workflowPath)} ${conclusionLabel(run.conclusion)}`);
|
|
1383
|
+
lines.push(pc7.dim(`run ${run.id}${run.runNumber === null ? "" : ` #${run.runNumber}`}`));
|
|
459
1384
|
lines.push(`${run.repoFullName} @ ${run.ref} ${shortSha(run.headSha)} ${run.event}${run.prNumber ? ` PR #${run.prNumber}` : ""}`);
|
|
460
1385
|
lines.push(`title: ${run.title}`);
|
|
461
1386
|
lines.push(`started: ${run.startedAt} duration: ${formatDuration(run.durationMs)}`);
|
|
@@ -466,16 +1391,16 @@ function formatRunDetail(run, runUrl) {
|
|
|
466
1391
|
if (run.benchmarks && run.benchmarks.length > 0) lines.push(`benchmarks: ${resultsSummary(run.benchmarks)}`);
|
|
467
1392
|
if (run.jobs.length > 0) {
|
|
468
1393
|
lines.push("");
|
|
469
|
-
lines.push(
|
|
1394
|
+
lines.push(pc7.bold("jobs"));
|
|
470
1395
|
for (const job of run.jobs) {
|
|
471
1396
|
const placement = job.provider ? `${job.provider}${job.region ? `:${job.region}` : ""}` : "-";
|
|
472
1397
|
lines.push(` ${job.id} ${job.name} ${conclusionLabel(job.state)} ${placement} ${formatDuration(job.durationMs)}`);
|
|
473
1398
|
for (const attempt of job.placementAttempts) {
|
|
474
|
-
lines.push(
|
|
1399
|
+
lines.push(pc7.dim(` placement failed on ${attempt.provider}${attempt.region ? `:${attempt.region}` : ""}: ${attempt.error}`));
|
|
475
1400
|
}
|
|
476
1401
|
for (const step of job.steps) {
|
|
477
1402
|
const exit = step.exitCode === null ? "" : ` (exit ${step.exitCode})`;
|
|
478
|
-
lines.push(
|
|
1403
|
+
lines.push(pc7.dim(` ${step.name} ${step.state}${exit} ${formatDuration(step.durationMs)}`));
|
|
479
1404
|
}
|
|
480
1405
|
}
|
|
481
1406
|
}
|
|
@@ -511,22 +1436,22 @@ function formatRate(n) {
|
|
|
511
1436
|
return n === null ? "-" : `${Math.round(n * 100)}%`;
|
|
512
1437
|
}
|
|
513
1438
|
function formatRunResults(results) {
|
|
514
|
-
if (results.length === 0) return
|
|
1439
|
+
if (results.length === 0) return pc7.dim("no benchmark results on this run");
|
|
515
1440
|
const lines = [];
|
|
516
1441
|
for (const [i, result] of results.entries()) {
|
|
517
1442
|
if (i > 0) lines.push("");
|
|
518
|
-
lines.push(`${
|
|
519
|
-
lines.push(
|
|
1443
|
+
lines.push(`${pc7.bold(safeTerm(result.benchmarkName))} ${safeTerm(result.status)}`);
|
|
1444
|
+
lines.push(pc7.dim(`${safeTerm(result.benchmarkRunId)} ${safeTerm(result.dashboardUrl)}`));
|
|
520
1445
|
const rows = [...overallRows(result)].sort((a, b) => (b.compositeScore ?? -1) - (a.compositeScore ?? -1));
|
|
521
1446
|
if (rows.length === 0) {
|
|
522
|
-
lines.push(
|
|
1447
|
+
lines.push(pc7.dim(result.status === "failed" ? " failed before reporting results" : " no results yet"));
|
|
523
1448
|
continue;
|
|
524
1449
|
}
|
|
525
1450
|
const width = Math.max(8, ...rows.map((p2) => p2.provider.length));
|
|
526
|
-
lines.push(
|
|
1451
|
+
lines.push(pc7.dim(` ${"provider".padEnd(width)} ${"score".padStart(7)} ${"success".padStart(7)} metrics`));
|
|
527
1452
|
for (const p2 of rows) {
|
|
528
1453
|
const metrics = Object.entries(p2.metrics).map(([name, m]) => `${safeTerm(name)} ${formatMetric(m.median)}${m.unit ? safeTerm(m.unit) : ""}`).join(" ");
|
|
529
|
-
const status = p2.skipped ?
|
|
1454
|
+
const status = p2.skipped ? pc7.dim(`skipped${p2.skipReason ? `: ${safeTerm(p2.skipReason)}` : ""}`) : metrics;
|
|
530
1455
|
lines.push(` ${safeTerm(p2.provider).padEnd(width)} ${formatScore(p2.compositeScore).padStart(7)} ${formatRate(p2.successRate).padStart(7)} ${status}`);
|
|
531
1456
|
}
|
|
532
1457
|
}
|
|
@@ -534,18 +1459,18 @@ function formatRunResults(results) {
|
|
|
534
1459
|
}
|
|
535
1460
|
function formatRunInspection(run) {
|
|
536
1461
|
const lines = [];
|
|
537
|
-
lines.push(`${
|
|
538
|
-
lines.push(
|
|
1462
|
+
lines.push(`${pc7.bold("run")} ${conclusionLabel(run.conclusion)}${run.runNumber === null ? "" : ` #${run.runNumber}`}`);
|
|
1463
|
+
lines.push(pc7.dim(run.id));
|
|
539
1464
|
lines.push(`${safeTerm(run.ref)} ${shortSha(run.headSha)} ${safeTerm(run.event)}`);
|
|
540
1465
|
lines.push(`queued: ${run.queuedAt} started: ${run.startedAt} finished: ${run.finishedAt}`);
|
|
541
1466
|
if (run.cancellationReason) lines.push(`cancelled: ${run.cancellationReason}`);
|
|
542
1467
|
if (run.supersededByRunId) lines.push(`superseded by: ${run.supersededByRunId}`);
|
|
543
|
-
if (run.blockedReason) lines.push(
|
|
1468
|
+
if (run.blockedReason) lines.push(pc7.red(`blocked: ${safeTerm(run.blockedReason)}`));
|
|
544
1469
|
if (run.concurrencyGroup) lines.push(`concurrency: ${safeTerm(run.concurrencyGroup)}`);
|
|
545
1470
|
if (run.providerOverride) lines.push(`dispatched to: ${safeTerm(run.providerOverride)}`);
|
|
546
1471
|
if (run.definitionStale) {
|
|
547
1472
|
const parsed = run.workflowParsedFromSha ? shortSha(run.workflowParsedFromSha) : "unknown";
|
|
548
|
-
lines.push(
|
|
1473
|
+
lines.push(pc7.yellow(`definition: stored parse is from ${parsed}, not this head \u2014 context may be newer than the run`));
|
|
549
1474
|
}
|
|
550
1475
|
if (run.dispatchInputs && Object.keys(run.dispatchInputs).length > 0) {
|
|
551
1476
|
lines.push(`inputs: ${Object.entries(run.dispatchInputs).map(([k, v]) => `${safeTerm(k)}=${safeTerm(v)}`).join(" ")}`);
|
|
@@ -556,24 +1481,24 @@ function formatRunInspection(run) {
|
|
|
556
1481
|
}
|
|
557
1482
|
if (run.caches.length > 0) {
|
|
558
1483
|
lines.push("");
|
|
559
|
-
lines.push(
|
|
1484
|
+
lines.push(pc7.bold("caches"));
|
|
560
1485
|
for (const cache of run.caches) {
|
|
561
1486
|
const action = [cache.restoredAt ? "restored" : null, cache.savedAt ? "saved" : null].filter(Boolean).join("+");
|
|
562
|
-
lines.push(` ${safeTerm(cache.key)} ${
|
|
1487
|
+
lines.push(` ${safeTerm(cache.key)} ${pc7.dim(`${action} ${safeTerm(cache.scopeRef)} ${cache.sizeBytes}B`)}`);
|
|
563
1488
|
}
|
|
564
1489
|
}
|
|
565
1490
|
if (run.jobs.length > 0) {
|
|
566
1491
|
lines.push("");
|
|
567
|
-
lines.push(
|
|
1492
|
+
lines.push(pc7.bold("jobs"));
|
|
568
1493
|
for (const job of run.jobs) {
|
|
569
1494
|
const placement = job.provider ? `${safeTerm(job.provider)}${job.region ? `:${safeTerm(job.region)}` : ""}` : "-";
|
|
570
1495
|
lines.push(` ${safeTerm(job.name)} ${conclusionLabel(job.state)} ${placement}`);
|
|
571
|
-
lines.push(
|
|
1496
|
+
lines.push(pc7.dim(` ${job.id}`));
|
|
572
1497
|
if (job.runsOn.length > 0 || job.resolvedRunsOn !== null) {
|
|
573
1498
|
const resolved = job.resolvedRunsOn !== null && job.resolvedRunsOn.join(",") !== job.runsOn.join(",") ? ` \u2192 ${job.resolvedRunsOn.map(safeTerm).join(", ")}` : "";
|
|
574
1499
|
lines.push(` runs-on: ${job.runsOn.map(safeTerm).join(", ") || "(none)"}${resolved}`);
|
|
575
1500
|
}
|
|
576
|
-
if (job.runsOnHasExpression) lines.push(
|
|
1501
|
+
if (job.runsOnHasExpression) lines.push(pc7.dim(" runs-on resolves at runtime (expression)"));
|
|
577
1502
|
if (job.container) lines.push(` container: ${safeTerm(job.container)}`);
|
|
578
1503
|
if (job.runnerImage) lines.push(` image: ${safeTerm(job.runnerImage)}`);
|
|
579
1504
|
if (job.placementHint) {
|
|
@@ -590,9 +1515,9 @@ function formatRunInspection(run) {
|
|
|
590
1515
|
if (job.matrix) {
|
|
591
1516
|
lines.push(` matrix: ${Object.entries(job.matrix).map(([k, v]) => `${safeTerm(k)}=${safeTerm(v)}`).join(" ")}`);
|
|
592
1517
|
}
|
|
593
|
-
if (job.failureReason) lines.push(
|
|
1518
|
+
if (job.failureReason) lines.push(pc7.red(` failed: ${safeTerm(job.failureReason)}`));
|
|
594
1519
|
for (const attempt of job.placementAttempts) {
|
|
595
|
-
lines.push(
|
|
1520
|
+
lines.push(pc7.dim(` placement failed on ${safeTerm(attempt.provider)}${attempt.region ? `:${safeTerm(attempt.region)}` : ""}: ${safeTerm(attempt.error)}`));
|
|
596
1521
|
}
|
|
597
1522
|
}
|
|
598
1523
|
}
|
|
@@ -600,7 +1525,7 @@ function formatRunInspection(run) {
|
|
|
600
1525
|
}
|
|
601
1526
|
function formatRunSummary(summary) {
|
|
602
1527
|
const lines = [];
|
|
603
|
-
lines.push(
|
|
1528
|
+
lines.push(pc7.bold(`failures \u2014 run ${summary.runId} ${conclusionLabel(summary.conclusion)}`));
|
|
604
1529
|
if (summary.failures.length === 0) {
|
|
605
1530
|
lines.push(" no failed jobs");
|
|
606
1531
|
return lines.join("\n");
|
|
@@ -608,7 +1533,7 @@ function formatRunSummary(summary) {
|
|
|
608
1533
|
for (const job of summary.failures) {
|
|
609
1534
|
const placement = job.provider ? `${safeTerm(job.provider)}${job.region ? `:${safeTerm(job.region)}` : ""}` : "-";
|
|
610
1535
|
lines.push(` ${job.id} ${safeTerm(job.name)} ${conclusionLabel(job.conclusion)} ${placement}`);
|
|
611
|
-
if (job.failureReason) lines.push(
|
|
1536
|
+
if (job.failureReason) lines.push(pc7.dim(` ${safeTerm(job.failureReason)}`));
|
|
612
1537
|
for (const step of job.failedSteps) {
|
|
613
1538
|
const exit = step.exitCode === null ? "" : ` (exit ${step.exitCode})`;
|
|
614
1539
|
lines.push(` step ${step.ordinal} ${safeTerm(step.name)}${exit}`);
|
|
@@ -616,7 +1541,7 @@ function formatRunSummary(summary) {
|
|
|
616
1541
|
if (job.excerpt) {
|
|
617
1542
|
const scope = job.excerpt.stepOrdinal === null ? "job log" : `step ${job.excerpt.stepOrdinal}`;
|
|
618
1543
|
const cut = job.excerpt.truncated ? ", truncated" : "";
|
|
619
|
-
lines.push(
|
|
1544
|
+
lines.push(pc7.dim(` \u2500\u2500 ${scope} tail${cut} \u2500\u2500`));
|
|
620
1545
|
for (const line of job.excerpt.text.split("\n")) lines.push(` ${safeTerm(line)}`);
|
|
621
1546
|
}
|
|
622
1547
|
}
|
|
@@ -709,24 +1634,21 @@ async function* followRunLogs(client2, runId, jobs, step) {
|
|
|
709
1634
|
await new Promise((r) => setTimeout(r, 1e3));
|
|
710
1635
|
}
|
|
711
1636
|
}
|
|
712
|
-
function safeTerm(s) {
|
|
713
|
-
return s.replace(/[\u0000-\u001F\u007F-\u009F]/g, "\uFFFD");
|
|
714
|
-
}
|
|
715
1637
|
function formatRunHistory(history) {
|
|
716
1638
|
const lines = [];
|
|
717
1639
|
const parts = Object.entries(history.conclusions).map(([c, n]) => `${n} ${c}`).join(", ");
|
|
718
1640
|
lines.push(`last ${history.runCount} runs: ${parts || "none"}`);
|
|
719
1641
|
if (history.jobs.length > 0) {
|
|
720
1642
|
lines.push("");
|
|
721
|
-
lines.push(
|
|
1643
|
+
lines.push(pc7.bold("jobs"));
|
|
722
1644
|
for (const job of history.jobs) {
|
|
723
1645
|
const rate = job.runs > 0 ? Math.round(job.failedRuns / job.runs * 100) : 0;
|
|
724
|
-
const platform = job.failedBeforeSteps > 0 ?
|
|
1646
|
+
const platform = job.failedBeforeSteps > 0 ? pc7.dim(` (${job.failedBeforeSteps} failed before steps)`) : "";
|
|
725
1647
|
const count = `${job.failedRuns}/${job.runs} runs failed`;
|
|
726
|
-
const label = job.failedRuns > 0 ?
|
|
1648
|
+
const label = job.failedRuns > 0 ? pc7.red(count) : pc7.green(count);
|
|
727
1649
|
lines.push(` ${safeTerm(job.job)} ${label} ${rate}%${platform}`);
|
|
728
1650
|
for (const step of job.steps) {
|
|
729
|
-
lines.push(
|
|
1651
|
+
lines.push(pc7.dim(` step "${safeTerm(step.step)}" failed in ${step.failedRuns} run${step.failedRuns === 1 ? "" : "s"}`));
|
|
730
1652
|
}
|
|
731
1653
|
}
|
|
732
1654
|
}
|
|
@@ -735,46 +1657,39 @@ function formatRunHistory(history) {
|
|
|
735
1657
|
);
|
|
736
1658
|
if (failed.length > 0) {
|
|
737
1659
|
lines.push("");
|
|
738
|
-
lines.push(
|
|
1660
|
+
lines.push(pc7.bold("failed runs"));
|
|
739
1661
|
for (const run of failed) {
|
|
740
|
-
const blame = run.failedJobs.length > 0 ? run.failedJobs.map((j) => safeTerm(j.step === null ? j.job : `${j.job}:${j.step}`)).join(", ") :
|
|
741
|
-
lines.push(` ${shortSha(run.headSha)} ${
|
|
1662
|
+
const blame = run.failedJobs.length > 0 ? run.failedJobs.map((j) => safeTerm(j.step === null ? j.job : `${j.job}:${j.step}`)).join(", ") : pc7.dim("(no failed job recorded)");
|
|
1663
|
+
lines.push(` ${shortSha(run.headSha)} ${pc7.dim(run.startedAt)} ${blame}`);
|
|
742
1664
|
}
|
|
743
1665
|
}
|
|
744
1666
|
return lines.join("\n");
|
|
745
1667
|
}
|
|
1668
|
+
function keyStatusText(p2) {
|
|
1669
|
+
const status = p2.status === "connected" ? pc7.green("connected") : p2.status === "error" ? pc7.red("error") : pc7.gray("unconfigured");
|
|
1670
|
+
const hint = p2.keyHint ? ` ${pc7.dim(safeTerm(p2.keyHint))}` : "";
|
|
1671
|
+
const detail = p2.status === "error" && p2.statusDetail ? ` ${pc7.dim(`(${safeTerm(p2.statusDetail)})`)}` : "";
|
|
1672
|
+
return `${status}${hint}${detail}`;
|
|
1673
|
+
}
|
|
746
1674
|
function formatProviderRow(p2) {
|
|
747
|
-
const icon = p2.usable ?
|
|
748
|
-
const name = p2.usable ?
|
|
1675
|
+
const icon = p2.usable ? pc7.green("\u25CF") : pc7.gray("\u25CB");
|
|
1676
|
+
const name = p2.usable ? pc7.white(p2.provider) : pc7.gray(p2.provider);
|
|
749
1677
|
const flags = [
|
|
750
1678
|
p2.credential,
|
|
751
|
-
p2.actCapable ?
|
|
1679
|
+
p2.actCapable ? pc7.green("act") : pc7.gray("no-act"),
|
|
752
1680
|
p2.regions.length > 0 ? `regions: ${p2.regions.join(",")}` : "no region choice",
|
|
753
|
-
p2.position === null ?
|
|
1681
|
+
p2.position === null ? pc7.gray("not in provider order") : `order #${p2.position}`,
|
|
1682
|
+
...p2.credential !== "ambient" && p2.status !== void 0 ? [keyStatusText(p2)] : []
|
|
754
1683
|
].join(" ");
|
|
755
1684
|
return ` ${icon} ${name} ${flags}`;
|
|
756
1685
|
}
|
|
757
1686
|
function formatVerifyResult(r) {
|
|
758
1687
|
const ok = r.verified === true;
|
|
759
|
-
const head = ok ?
|
|
760
|
-
const detail = r.key.statusDetail ?
|
|
761
|
-
const act = r.key.actCapable ?
|
|
1688
|
+
const head = ok ? pc7.green("verified") : pc7.red("not verified");
|
|
1689
|
+
const detail = r.key.statusDetail ? pc7.dim(` ${r.key.statusDetail}`) : "";
|
|
1690
|
+
const act = r.key.actCapable ? pc7.green(" act-capable") : "";
|
|
762
1691
|
return `${head} ${r.key.provider}${act}${detail}`;
|
|
763
1692
|
}
|
|
764
|
-
function formatRepoRow(r) {
|
|
765
|
-
const head = r.enabled ? pc2.green("enabled") : pc2.dim("disabled");
|
|
766
|
-
const via = r.authType === "github_app" ? "github-app" : r.authType;
|
|
767
|
-
const workflows = r.workflowPaths.length > 0 ? `${r.workflowPaths.length} workflow${r.workflowPaths.length === 1 ? "" : "s"}` : "no workflows yet";
|
|
768
|
-
const error = r.lastPollError ? pc2.red(` poll error: ${safeTerm(r.lastPollError)}`) : "";
|
|
769
|
-
return `${head} ${safeTerm(r.fullName)} ${pc2.dim(`${safeTerm(via)} \xB7 ${safeTerm(r.defaultBranch)} \xB7 ${workflows}`)}${error}`;
|
|
770
|
-
}
|
|
771
|
-
function printDiscovery(d) {
|
|
772
|
-
if (d.error) {
|
|
773
|
-
console.log(pc2.yellow(`discovery: ${safeTerm(d.error)} (the poll cron retries)`));
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
console.log(pc2.dim(`discovery: ${d.workflowsFound ? "workflows found" : "no workflows yet"}${d.seeded ? ", cursors seeded" : ""}`));
|
|
777
|
-
}
|
|
778
1693
|
function isPatchedWorkflowTarget(target) {
|
|
779
1694
|
return "workflowPath" in target;
|
|
780
1695
|
}
|
|
@@ -788,16 +1703,18 @@ function patchTouches(patch, path2) {
|
|
|
788
1703
|
}
|
|
789
1704
|
function dispatchBody(workflow, opts) {
|
|
790
1705
|
const patched = isPatchedWorkflowTarget(workflow);
|
|
791
|
-
|
|
1706
|
+
const path2 = patched ? workflow.workflowPath : workflow.path;
|
|
1707
|
+
const pushOnly = workflow.dispatchable === false;
|
|
1708
|
+
if (pushOnly && !opts.manual) {
|
|
792
1709
|
throw new PlatformClientError(
|
|
793
1710
|
"invalid_argument",
|
|
794
|
-
`Workflow "${
|
|
1711
|
+
`Workflow "${path2}" does not declare workflow_dispatch. Pass --manual to run it anyway (no inputs).`
|
|
795
1712
|
);
|
|
796
1713
|
}
|
|
797
|
-
if (
|
|
1714
|
+
if (pushOnly && opts.inputs !== void 0 && opts.inputs.length > 0) {
|
|
798
1715
|
throw new PlatformClientError(
|
|
799
1716
|
"invalid_argument",
|
|
800
|
-
`Workflow "${
|
|
1717
|
+
`Workflow "${path2}" has no workflow_dispatch inputs; --manual runs of it take no --inputs.`
|
|
801
1718
|
);
|
|
802
1719
|
}
|
|
803
1720
|
const ref = opts.ref ?? (patched ? void 0 : workflow.refs[0]);
|
|
@@ -961,13 +1878,13 @@ function formatVaultRow(item) {
|
|
|
961
1878
|
...item.source === "organization" ? ["inherited"] : [],
|
|
962
1879
|
...item.overridesOrganization ? ["overrides org"] : []
|
|
963
1880
|
];
|
|
964
|
-
return `${
|
|
1881
|
+
return `${pc7.cyan(safeTerm(item.name))} ${pc7.dim(flags.join(", "))} ${pc7.dim(`updated ${safeTerm(item.updatedAt)}`)}`;
|
|
965
1882
|
}
|
|
966
1883
|
function registerActionsCommands(program2) {
|
|
967
1884
|
const actions = program2.command("actions").alias("ci").description("Drive the benchmarks-platform Actions API").configureOutput({ outputError: usageErrorOutput });
|
|
968
|
-
const
|
|
969
|
-
|
|
970
|
-
actions.command("dispatch").description("Dispatch a workflow_dispatch run (or any workflow with --manual)").argument("<repo>", "repository in owner/repo format").requiredOption("--workflow <path|name>", "workflow path or name").option("--ref <ref>", "git ref to run (default: the workflow's first watched ref)").option("--inputs <pairs...>", "workflow inputs as key=value (workflow_dispatch inputs only)").option("--manual", "run a workflow even if it does not declare workflow_dispatch (such runs take no --inputs)").option("--provider <id>", "place the run on one provider (e.g. namespace, vercel:sfo1) instead of the org provider order").option("--provider-region <region>", "region for --provider (same as --provider <id>:<region>)").option("--max-bid <usd>", "max price per vCPU for a market fill (e.g. 0.12); unfilled jobs fall through to the next provider").option("--max-bid-per <unit>", "time unit --max-bid is priced in: second, minute, or hour (default: second)").option("--with-changes", "run your local changes: everything the working tree has beyond origin/<ref> is sent as a diff and applied after checkout (default --ref: the current branch)")
|
|
1885
|
+
const common2 = (cmd) => cmd.option("--api-key <key>", "API key (default: $COMPUTE_API_KEY)").option("--base-url <url>", "API base URL (default: https://platform.computesdk.com)").option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)").option("--allow-untrusted-host", "send an explicit --api-key/env key to a non-computesdk, non-localhost --base-url (stored login credentials are never sent)").option("--json", "print machine-readable JSON");
|
|
1886
|
+
common2(
|
|
1887
|
+
actions.command("dispatch").description("Dispatch a workflow_dispatch run (or any workflow with --manual)").argument("<repo>", "repository in owner/repo format").requiredOption("--workflow <path|name>", "workflow path or name").option("--ref <ref>", "git ref to run (default: the workflow's first watched ref); also finds a workflow file only this ref has").option("--inputs <pairs...>", "workflow inputs as key=value (workflow_dispatch inputs only)").option("--manual", "run a workflow even if it does not declare workflow_dispatch (such runs take no --inputs)").option("--provider <id>", "place the run on one provider (e.g. namespace, vercel:sfo1) instead of the org provider order").option("--provider-region <region>", "region for --provider (same as --provider <id>:<region>)").option("--max-bid <usd>", "max price per vCPU for a market fill (e.g. 0.12); unfilled jobs fall through to the next provider").option("--max-bid-per <unit>", "time unit --max-bid is priced in: second, minute, or hour (default: second)").option("--with-changes", "run your local changes: everything the working tree has beyond origin/<ref> is sent as a diff and applied after checkout (default --ref: the current branch)")
|
|
971
1888
|
).action(async (repo, opts) => {
|
|
972
1889
|
try {
|
|
973
1890
|
const c = await client(opts);
|
|
@@ -978,15 +1895,21 @@ function registerActionsCommands(program2) {
|
|
|
978
1895
|
if (!ref) throw new PlatformClientError("invalid_argument", "--with-changes needs a branch: check one out or pass --ref.");
|
|
979
1896
|
local = localChangesPatch(ref, void 0, repo);
|
|
980
1897
|
} else if (!opts.json && hasLocalChanges()) {
|
|
981
|
-
console.error(
|
|
1898
|
+
console.error(pc7.dim("You have uncommitted changes. Add --with-changes to run them."));
|
|
982
1899
|
}
|
|
983
1900
|
const { workflows } = await c.get(
|
|
984
1901
|
"/api/v1/actions/workflows",
|
|
985
1902
|
{ repo }
|
|
986
1903
|
);
|
|
987
|
-
|
|
1904
|
+
let workflow = matchWorkflow(workflows, opts.workflow) ?? (local && patchTouches(local.patch, opts.workflow) ? { repoFullName: repo, workflowPath: opts.workflow } : void 0);
|
|
1905
|
+
let refOnly;
|
|
1906
|
+
if (!workflow && ref !== void 0) {
|
|
1907
|
+
refOnly = (await c.get("/api/v1/actions/workflows", { repo, ref })).refOnly ?? [];
|
|
1908
|
+
const match = matchRefOnly(refOnly, opts.workflow);
|
|
1909
|
+
if (match) workflow = { repoFullName: repo, workflowPath: match.path, dispatchable: match.dispatchable };
|
|
1910
|
+
}
|
|
988
1911
|
if (!workflow) {
|
|
989
|
-
const choices = workflows
|
|
1912
|
+
const choices = workflowChoices(workflows) + (refOnly && refOnly.length > 0 ? `; only on ${ref}: ${workflowChoices(refOnly)}` : "");
|
|
990
1913
|
const hint = !opts.withChanges && hasLocalChanges() && /^\.github\/workflows\//.test(opts.workflow) ? " If it only exists in your working tree, add --with-changes." : "";
|
|
991
1914
|
throw new PlatformClientError(
|
|
992
1915
|
"workflow_not_found",
|
|
@@ -1002,7 +1925,7 @@ function registerActionsCommands(program2) {
|
|
|
1002
1925
|
);
|
|
1003
1926
|
patch = { patchId: uploaded.patchId, files: uploaded.files, bytes: uploaded.bytes };
|
|
1004
1927
|
} else if (opts.withChanges && !opts.json && ref) {
|
|
1005
|
-
console.error(
|
|
1928
|
+
console.error(pc7.dim(`no local changes beyond origin/${ref.replace(/^refs\/heads\//, "")}; running the ref as is`));
|
|
1006
1929
|
}
|
|
1007
1930
|
const body = dispatchBody(workflow, { ...opts, ref, patchId: patch?.patchId });
|
|
1008
1931
|
const result = await c.post(
|
|
@@ -1012,7 +1935,7 @@ function registerActionsCommands(program2) {
|
|
|
1012
1935
|
const org2 = await c.org();
|
|
1013
1936
|
const url = `${c.baseUrl}/${org2.slug}/actions/runs/${result.runId}`;
|
|
1014
1937
|
output(opts, { ...result, url, ...patch && { patch } }, (r) => {
|
|
1015
|
-
console.log(`${r.created ? "dispatched" : "already running"} ${
|
|
1938
|
+
console.log(`${r.created ? "dispatched" : "already running"} ${pc7.cyan(r.runId)}`);
|
|
1016
1939
|
console.log(`sha: ${r.headSha}${r.patch ? ` + ${r.patch.files} changed file${r.patch.files === 1 ? "" : "s"} (uncommitted)` : ""}`);
|
|
1017
1940
|
console.log(`url: ${r.url}`);
|
|
1018
1941
|
});
|
|
@@ -1020,26 +1943,21 @@ function registerActionsCommands(program2) {
|
|
|
1020
1943
|
fail(e, opts);
|
|
1021
1944
|
}
|
|
1022
1945
|
});
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1946
|
+
registerRunsCommands(actions, common2, { client, fail, output, formatRunRow });
|
|
1947
|
+
registerWorkflowsCommands(actions, common2, { client, fail, output });
|
|
1948
|
+
common2(
|
|
1949
|
+
actions.command("schedule").description("List upcoming scheduled fires and past runs in a time window").option("--reliability", "show only reliability runs and workflows (hidden by default)").option("--from <timestamp>", "inclusive start timestamp (default: now)").option("--to <timestamp>", "exclusive end timestamp (default: seven days after --from)").option("--repo <repo>", "repository in owner/repo format").option("--workflow <path...>", "workflow file paths; repeatable").option("--event <event...>", "trigger events: schedule, push, pull_request, workflow_dispatch").option("--status <status...>", "run conclusions: passed, failed, running, cancelled, none (excludes upcoming)").option("--tz <zone>", "IANA time zone (default: local)").option("--limit <n>", "past-run page size (default 100, max 500)").option("--cursor <cursor>", "nextCursor from a prior page; keep the window and filters unchanged")
|
|
1950
|
+
).action(async (opts) => {
|
|
1951
|
+
opts.org ?? (opts.org = program2.opts().org);
|
|
1026
1952
|
try {
|
|
1027
|
-
const
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
);
|
|
1031
|
-
output(opts, runs, (rs) => {
|
|
1032
|
-
if (rs.length === 0) {
|
|
1033
|
-
console.log("No runs found.");
|
|
1034
|
-
return;
|
|
1035
|
-
}
|
|
1036
|
-
for (const run of rs) console.log(formatRunRow(run));
|
|
1037
|
-
});
|
|
1953
|
+
const query = scheduleQuery(opts);
|
|
1954
|
+
const data = await (await client(opts)).get("/api/v1/actions/schedule", query);
|
|
1955
|
+
output(opts, data, (result) => console.log(formatSchedule(result, result.nextCursor ? nextScheduleCommand(result, opts) : void 0)));
|
|
1038
1956
|
} catch (e) {
|
|
1039
1957
|
fail(e, opts);
|
|
1040
1958
|
}
|
|
1041
1959
|
});
|
|
1042
|
-
|
|
1960
|
+
common2(
|
|
1043
1961
|
actions.command("history").description("Recent run history for a workflow \u2014 per-job/step failure rates (is this failure flaky?)").argument("<repo>", "repository in owner/repo format").requiredOption("--workflow <path|name>", "workflow path or name").option("--branch <branch...>", "narrow the window to branches/refs").option("--job <job>", "narrow the rollup to one job name or workflow job id").option("--limit <n>", "runs in the window (default 10, max 50)")
|
|
1044
1962
|
).action(async (repo, opts) => {
|
|
1045
1963
|
try {
|
|
@@ -1062,7 +1980,7 @@ function registerActionsCommands(program2) {
|
|
|
1062
1980
|
fail(e, opts);
|
|
1063
1981
|
}
|
|
1064
1982
|
});
|
|
1065
|
-
|
|
1983
|
+
common2(
|
|
1066
1984
|
actions.command("run").description("Show a run: jobs, provider:region placement, placement attempts").argument("<run-id>", "run ID")
|
|
1067
1985
|
).action(async (runId, opts) => {
|
|
1068
1986
|
try {
|
|
@@ -1082,7 +2000,7 @@ function registerActionsCommands(program2) {
|
|
|
1082
2000
|
fail(e, opts);
|
|
1083
2001
|
}
|
|
1084
2002
|
});
|
|
1085
|
-
|
|
2003
|
+
common2(
|
|
1086
2004
|
actions.command("summary").description("Show a run's failure digest: failed jobs, failed steps, bounded log tails").argument("<run-id>", "run ID")
|
|
1087
2005
|
).action(async (runId, opts) => {
|
|
1088
2006
|
try {
|
|
@@ -1092,7 +2010,7 @@ function registerActionsCommands(program2) {
|
|
|
1092
2010
|
fail(e, opts);
|
|
1093
2011
|
}
|
|
1094
2012
|
});
|
|
1095
|
-
|
|
2013
|
+
common2(
|
|
1096
2014
|
actions.command("benchmarks").description("Show the benchmark runs this run produced: per-provider score and success rate").argument("<run-id>", "run ID")
|
|
1097
2015
|
).action(async (runId, opts) => {
|
|
1098
2016
|
try {
|
|
@@ -1103,7 +2021,7 @@ function registerActionsCommands(program2) {
|
|
|
1103
2021
|
fail(e, opts);
|
|
1104
2022
|
}
|
|
1105
2023
|
});
|
|
1106
|
-
|
|
2024
|
+
common2(
|
|
1107
2025
|
actions.command("inspect").description("Inspect a run: resolved runner image, caches, secret names, concurrency, placement context").argument("<run-id>", "run ID")
|
|
1108
2026
|
).action(async (runId, opts) => {
|
|
1109
2027
|
try {
|
|
@@ -1116,7 +2034,7 @@ function registerActionsCommands(program2) {
|
|
|
1116
2034
|
fail(e, opts);
|
|
1117
2035
|
}
|
|
1118
2036
|
});
|
|
1119
|
-
|
|
2037
|
+
common2(
|
|
1120
2038
|
actions.command("logs").description("Print or follow a run's job logs").argument("<run-id>", "run ID").option("--job <job>", "job ID or name (default: all jobs)").option("--step <step>", 'step ordinal or "runner" (default: whole job)').option("--follow", "stream logs while the run is live")
|
|
1121
2039
|
).action(async (runId, opts) => {
|
|
1122
2040
|
try {
|
|
@@ -1143,7 +2061,7 @@ function registerActionsCommands(program2) {
|
|
|
1143
2061
|
if (opts.json) {
|
|
1144
2062
|
process.stdout.write(JSON.stringify({ jobId: job.id, name: job.name, slice }) + "\n");
|
|
1145
2063
|
} else {
|
|
1146
|
-
if (jobs.length > 1) console.log(
|
|
2064
|
+
if (jobs.length > 1) console.log(pc7.bold(`\u2500\u2500 ${job.name} \u2500\u2500`));
|
|
1147
2065
|
for (const seg of slice.segments) process.stdout.write(seg.text);
|
|
1148
2066
|
}
|
|
1149
2067
|
}
|
|
@@ -1174,8 +2092,8 @@ function registerActionsCommands(program2) {
|
|
|
1174
2092
|
fail(e, opts);
|
|
1175
2093
|
}
|
|
1176
2094
|
});
|
|
1177
|
-
const providers = actions.command("providers").description("List the
|
|
1178
|
-
|
|
2095
|
+
const providers = actions.command("providers").description("List the providers Actions can place on (order, act/usable, key status); keys and rates: compute byok");
|
|
2096
|
+
common2(providers).action(async (opts) => {
|
|
1179
2097
|
try {
|
|
1180
2098
|
const data = await (await client(opts)).get("/api/v1/actions/providers");
|
|
1181
2099
|
output(opts, data, (d) => {
|
|
@@ -1185,11 +2103,11 @@ function registerActionsCommands(program2) {
|
|
|
1185
2103
|
fail(e, opts);
|
|
1186
2104
|
}
|
|
1187
2105
|
});
|
|
1188
|
-
|
|
1189
|
-
providers.command("configure").description("Save the org's credential for a provider (owner/admin
|
|
2106
|
+
common2(
|
|
2107
|
+
providers.command("configure").description("Deprecated: use `compute byok configure`. Save the org's credential for a provider (owner/admin)").argument("<provider>", "provider id (e.g. tensorlake, blaxel)").option("--key <key>", "provider API key (single-field credentials)").option("--field <pair...>", "credential fields as name=value (multi-field providers)").option("--verify", "run the placement probe after saving")
|
|
1190
2108
|
).action(async (provider, opts) => {
|
|
1191
2109
|
try {
|
|
1192
|
-
const c = await
|
|
2110
|
+
const c = await secretValueClient(opts, "provider keys");
|
|
1193
2111
|
let body;
|
|
1194
2112
|
if (opts.field !== void 0) {
|
|
1195
2113
|
if (opts.key !== void 0) throw new Error("Pass either --key or --field, not both.");
|
|
@@ -1207,7 +2125,7 @@ function registerActionsCommands(program2) {
|
|
|
1207
2125
|
`/api/v1/actions/providers/${provider}/verify`
|
|
1208
2126
|
) : void 0;
|
|
1209
2127
|
output(opts, verification ? { key: saved.key, verification } : saved, () => {
|
|
1210
|
-
console.log(`saved ${saved.key.provider} ${
|
|
2128
|
+
console.log(`saved ${saved.key.provider} ${pc7.dim(saved.key.keyHint)} ${saved.key.status}`);
|
|
1211
2129
|
if (verification) console.log(formatVerifyResult(verification));
|
|
1212
2130
|
});
|
|
1213
2131
|
if (verification?.verified === false) process.exitCode = 1;
|
|
@@ -1215,8 +2133,8 @@ function registerActionsCommands(program2) {
|
|
|
1215
2133
|
fail(e, opts);
|
|
1216
2134
|
}
|
|
1217
2135
|
});
|
|
1218
|
-
|
|
1219
|
-
providers.command("verify").description(
|
|
2136
|
+
common2(
|
|
2137
|
+
providers.command("verify").description("Deprecated: use `compute byok verify`. Probe the stored provider key with a real sandbox").argument("<provider>", "provider id")
|
|
1220
2138
|
).action(async (provider, opts) => {
|
|
1221
2139
|
try {
|
|
1222
2140
|
const result = await (await client(opts)).post(
|
|
@@ -1228,8 +2146,8 @@ function registerActionsCommands(program2) {
|
|
|
1228
2146
|
fail(e, opts);
|
|
1229
2147
|
}
|
|
1230
2148
|
});
|
|
1231
|
-
|
|
1232
|
-
providers.command("remove").description("Delete the org's stored credential for a provider").argument("<provider>", "provider id")
|
|
2149
|
+
common2(
|
|
2150
|
+
providers.command("remove").description("Deprecated: use `compute byok remove`. Delete the org's stored credential for a provider").argument("<provider>", "provider id")
|
|
1233
2151
|
).action(async (provider, opts) => {
|
|
1234
2152
|
try {
|
|
1235
2153
|
const result = await (await client(opts)).del(
|
|
@@ -1242,107 +2160,10 @@ function registerActionsCommands(program2) {
|
|
|
1242
2160
|
fail(e, opts);
|
|
1243
2161
|
}
|
|
1244
2162
|
});
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
try {
|
|
1248
|
-
const data = await (await client(opts)).get("/api/v1/actions/repos");
|
|
1249
|
-
output(opts, data, (d) => {
|
|
1250
|
-
for (const r of d.repos) console.log(formatRepoRow(r));
|
|
1251
|
-
});
|
|
1252
|
-
} catch (e) {
|
|
1253
|
-
fail(e, opts);
|
|
1254
|
-
}
|
|
1255
|
-
});
|
|
1256
|
-
common(
|
|
1257
|
-
repos.command("connect").description("Connect a git remote (validated by a real ls-remote; lands enabled)").argument("<cloneUrl>", "http(s) or ssh git remote URL").option("--name <owner/repo>", "repo name override (default: derived from cloneUrl)").option("--branch <branch>", "default branch (default: main, else the remote's first)").option("--token <token>", "credential for private http(s) remotes").option("--username <user>", 'username \u2014 with --token, makes auth "basic" instead of "token"').option("--ssh-key-file <path>", "OpenSSH/PEM private key file for ssh remotes").option("--known-hosts-file <path>", "known_hosts pin for ssh remotes")
|
|
1258
|
-
).action(async (cloneUrl, opts) => {
|
|
1259
|
-
try {
|
|
1260
|
-
let body;
|
|
1261
|
-
if (opts.sshKeyFile !== void 0) {
|
|
1262
|
-
if (opts.token !== void 0 || opts.username !== void 0) {
|
|
1263
|
-
throw new Error("Pass either --ssh-key-file or --token/--username, not both.");
|
|
1264
|
-
}
|
|
1265
|
-
body = {
|
|
1266
|
-
authType: "ssh",
|
|
1267
|
-
credential: readFileSync(opts.sshKeyFile, "utf8"),
|
|
1268
|
-
...opts.knownHostsFile !== void 0 && {
|
|
1269
|
-
knownHosts: readFileSync(opts.knownHostsFile, "utf8")
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
} else if (opts.username !== void 0) {
|
|
1273
|
-
if (opts.token === void 0) throw new Error("--username requires --token.");
|
|
1274
|
-
body = { authType: "basic", username: opts.username, credential: opts.token };
|
|
1275
|
-
} else if (opts.token !== void 0) {
|
|
1276
|
-
body = { authType: "token", credential: opts.token };
|
|
1277
|
-
} else {
|
|
1278
|
-
body = { authType: "none" };
|
|
1279
|
-
}
|
|
1280
|
-
if (opts.knownHostsFile !== void 0 && opts.sshKeyFile === void 0) {
|
|
1281
|
-
throw new Error("--known-hosts-file requires --ssh-key-file.");
|
|
1282
|
-
}
|
|
1283
|
-
const result = await (await client(opts)).post("/api/v1/actions/repos", {
|
|
1284
|
-
cloneUrl,
|
|
1285
|
-
...body,
|
|
1286
|
-
...opts.name !== void 0 && { name: opts.name },
|
|
1287
|
-
...opts.branch !== void 0 && { defaultBranch: opts.branch }
|
|
1288
|
-
});
|
|
1289
|
-
output(opts, result, (r) => {
|
|
1290
|
-
console.log(`connected ${pc2.cyan(safeTerm(r.fullName))} ${pc2.dim(`(${safeTerm(r.authType)}, ${safeTerm(r.defaultBranch)})`)}`);
|
|
1291
|
-
printDiscovery(r.discovery);
|
|
1292
|
-
});
|
|
1293
|
-
} catch (e) {
|
|
1294
|
-
fail(e, opts);
|
|
1295
|
-
}
|
|
1296
|
-
});
|
|
1297
|
-
common(
|
|
1298
|
-
repos.command("sync").description("Re-read the GitHub App installation so repos granted after install show up (owner/admin key)")
|
|
1299
|
-
).action(async (opts) => {
|
|
1300
|
-
try {
|
|
1301
|
-
const result = await (await client(opts)).post("/api/v1/actions/repos/sync", {});
|
|
1302
|
-
output(opts, result, (r) => {
|
|
1303
|
-
for (const a of r.accounts) {
|
|
1304
|
-
console.log(a.error === null ? `synced ${pc2.cyan(safeTerm(a.account))}` : `failed ${pc2.cyan(safeTerm(a.account))} ${pc2.red(safeTerm(a.error))}`);
|
|
1305
|
-
}
|
|
1306
|
-
console.log(pc2.dim(`${r.repos.length} repos visible`));
|
|
1307
|
-
});
|
|
1308
|
-
if (result.accounts.some((a) => a.error !== null)) process.exitCode = 1;
|
|
1309
|
-
} catch (e) {
|
|
1310
|
-
fail(e, opts);
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
common(
|
|
1314
|
-
repos.command("enable").description("Enable a repo the org can already see (granted by a GitHub App install, or a connected remote)").argument("<repo>", "repository in owner/repo format").option("--repo-id <id>", "scope to one row when two installations grant the same name")
|
|
1315
|
-
).action(async (repo, opts) => {
|
|
1316
|
-
try {
|
|
1317
|
-
const result = await (await client(opts)).patch("/api/v1/actions/repos", {
|
|
1318
|
-
fullName: repo,
|
|
1319
|
-
enabled: true,
|
|
1320
|
-
...opts.repoId !== void 0 && { repoId: opts.repoId }
|
|
1321
|
-
});
|
|
1322
|
-
output(opts, result, (r) => {
|
|
1323
|
-
console.log(`enabled ${pc2.cyan(safeTerm(r.fullName))}`);
|
|
1324
|
-
if (r.discovery) printDiscovery(r.discovery);
|
|
1325
|
-
});
|
|
1326
|
-
} catch (e) {
|
|
1327
|
-
fail(e, opts);
|
|
1328
|
-
}
|
|
1329
|
-
});
|
|
1330
|
-
common(
|
|
1331
|
-
repos.command("disable").description("Disable a repo \u2014 it stays connected but no runs are scheduled").argument("<repo>", "repository in owner/repo format").option("--repo-id <id>", "scope to one row when two installations grant the same name")
|
|
1332
|
-
).action(async (repo, opts) => {
|
|
1333
|
-
try {
|
|
1334
|
-
const result = await (await client(opts)).patch("/api/v1/actions/repos", {
|
|
1335
|
-
fullName: repo,
|
|
1336
|
-
enabled: false,
|
|
1337
|
-
...opts.repoId !== void 0 && { repoId: opts.repoId }
|
|
1338
|
-
});
|
|
1339
|
-
output(opts, result, (r) => console.log(`disabled ${pc2.cyan(safeTerm(r.fullName))}`));
|
|
1340
|
-
} catch (e) {
|
|
1341
|
-
fail(e, opts);
|
|
1342
|
-
}
|
|
1343
|
-
});
|
|
2163
|
+
registerReposCommands(actions, common2, { client, fail, output });
|
|
2164
|
+
registerIntegrationsCommands(actions, common2, { client, fail, output });
|
|
1344
2165
|
const vault = actions.command("vault").description("The org vault: secrets and variables (owner/admin key)");
|
|
1345
|
-
const vaultScope = (cmd) =>
|
|
2166
|
+
const vaultScope = (cmd) => common2(cmd).option("--repo <owner/repo>", "scope to a repo's own items instead of the org's").option("--kind <kind>", "secret or variable", "secret");
|
|
1346
2167
|
vaultScope(
|
|
1347
2168
|
vault.command("ls").description("List names and metadata (never values)")
|
|
1348
2169
|
).action(async (opts) => {
|
|
@@ -1366,7 +2187,7 @@ function registerActionsCommands(program2) {
|
|
|
1366
2187
|
'Pipe the value on stdin (e.g. printf %s "$VALUE" | compute actions vault set NAME) or pass --from-file.'
|
|
1367
2188
|
);
|
|
1368
2189
|
}
|
|
1369
|
-
const value =
|
|
2190
|
+
const value = readFileSync2(opts.fromFile ?? 0, "utf8");
|
|
1370
2191
|
const kind = parseVaultKind(opts.kind);
|
|
1371
2192
|
const labels = vaultSetLabels(opts);
|
|
1372
2193
|
const body = vaultSetBody(name, value, { ...opts, kind, labels });
|
|
@@ -1376,9 +2197,9 @@ function registerActionsCommands(program2) {
|
|
|
1376
2197
|
);
|
|
1377
2198
|
output(opts, result, (r) => {
|
|
1378
2199
|
const where = opts.repo ? safeTerm(opts.repo) : "org";
|
|
1379
|
-
console.log(`saved ${
|
|
2200
|
+
console.log(`saved ${pc7.cyan(safeTerm(r.item.name))} ${pc7.dim(`(${r.item.kind}, v${r.item.version}, ${where})`)}`);
|
|
1380
2201
|
if (/\r?\n$/.test(value)) {
|
|
1381
|
-
console.error(
|
|
2202
|
+
console.error(pc7.yellow("note: the stored value ends with a newline; use printf %s rather than echo to avoid one."));
|
|
1382
2203
|
}
|
|
1383
2204
|
});
|
|
1384
2205
|
} catch (e) {
|
|
@@ -1412,7 +2233,7 @@ function registerActionsCommands(program2) {
|
|
|
1412
2233
|
output(opts, result, (r) => {
|
|
1413
2234
|
const where = opts.repo ? safeTerm(opts.repo) : "org";
|
|
1414
2235
|
console.log(
|
|
1415
|
-
`reclassified ${
|
|
2236
|
+
`reclassified ${pc7.cyan(safeTerm(r.item.name))} ${pc7.dim(`(labels: ${r.item.labels.join(", ") || "none"}, v${r.item.version}, ${where})`)}`
|
|
1416
2237
|
);
|
|
1417
2238
|
});
|
|
1418
2239
|
} catch (e) {
|
|
@@ -1425,12 +2246,12 @@ function registerActionsCommands(program2) {
|
|
|
1425
2246
|
try {
|
|
1426
2247
|
const path2 = vaultPath("/api/v1/vault", { repo: opts.repo, kind: parseVaultKind(opts.kind), name });
|
|
1427
2248
|
const result = await (await client(opts)).del(path2);
|
|
1428
|
-
output(opts, result, (r) => console.log(`deleted ${
|
|
2249
|
+
output(opts, result, (r) => console.log(`deleted ${pc7.cyan(safeTerm(r.name))} ${pc7.dim(`(${r.kind})`)}`));
|
|
1429
2250
|
} catch (e) {
|
|
1430
2251
|
fail(e, opts);
|
|
1431
2252
|
}
|
|
1432
2253
|
});
|
|
1433
|
-
|
|
2254
|
+
common2(
|
|
1434
2255
|
actions.command("cancel").description("Cancel a run").argument("<run-id>", "run ID")
|
|
1435
2256
|
).action(async (runId, opts) => {
|
|
1436
2257
|
try {
|
|
@@ -1444,7 +2265,7 @@ function registerActionsCommands(program2) {
|
|
|
1444
2265
|
fail(e, opts);
|
|
1445
2266
|
}
|
|
1446
2267
|
});
|
|
1447
|
-
|
|
2268
|
+
common2(
|
|
1448
2269
|
actions.command("rerun").description("Re-run a finished run at the same commit").argument("<run-id>", "run ID")
|
|
1449
2270
|
).action(async (runId, opts) => {
|
|
1450
2271
|
try {
|
|
@@ -1455,14 +2276,14 @@ function registerActionsCommands(program2) {
|
|
|
1455
2276
|
const org2 = await c.org();
|
|
1456
2277
|
const url = `${c.baseUrl}/${org2.slug}/actions/runs/${result.runId}`;
|
|
1457
2278
|
output(opts, { ...result, url }, (r) => {
|
|
1458
|
-
console.log(`${r.created ? "rerun dispatched" : "rerun already running"} ${
|
|
2279
|
+
console.log(`${r.created ? "rerun dispatched" : "rerun already running"} ${pc7.cyan(r.runId)}`);
|
|
1459
2280
|
console.log(`url: ${r.url}`);
|
|
1460
2281
|
});
|
|
1461
2282
|
} catch (e) {
|
|
1462
2283
|
fail(e, opts);
|
|
1463
2284
|
}
|
|
1464
2285
|
});
|
|
1465
|
-
|
|
2286
|
+
common2(
|
|
1466
2287
|
actions.command("artifacts").description("List or download a run's artifacts").argument("<run-id>", "run ID").option("--job <job>", "job ID or name (default: all jobs)").option("--out <dir>", "download artifacts into this directory instead of listing")
|
|
1467
2288
|
).action(async (runId, opts) => {
|
|
1468
2289
|
try {
|
|
@@ -1518,7 +2339,7 @@ function registerActionsCommands(program2) {
|
|
|
1518
2339
|
fail(e, opts);
|
|
1519
2340
|
}
|
|
1520
2341
|
});
|
|
1521
|
-
registerSettingsCommands(actions, "actions",
|
|
2342
|
+
registerSettingsCommands(actions, "actions", common2, {
|
|
1522
2343
|
client,
|
|
1523
2344
|
fail,
|
|
1524
2345
|
output,
|
|
@@ -1526,10 +2347,160 @@ function registerActionsCommands(program2) {
|
|
|
1526
2347
|
});
|
|
1527
2348
|
}
|
|
1528
2349
|
|
|
2350
|
+
// src/byok.ts
|
|
2351
|
+
import pc8 from "picocolors";
|
|
2352
|
+
var RATE_UNITS = ["second", "minute", "hour"];
|
|
2353
|
+
var MAX_RATE_USD = 1e3;
|
|
2354
|
+
function providerPath(provider, rest = "") {
|
|
2355
|
+
return `/api/v1/providers/${encodeURIComponent(provider)}${rest}`;
|
|
2356
|
+
}
|
|
2357
|
+
function keyText(key) {
|
|
2358
|
+
if (key.keyHint === null) return pc8.gray("no key");
|
|
2359
|
+
const status = key.status === "connected" ? pc8.green("connected") : key.status === "error" ? pc8.red("error") : pc8.yellow("untested");
|
|
2360
|
+
const hints = key.pairs?.length ? key.pairs.map((p2) => `${safeTerm(p2.keyHint ?? "\u2014")}@${safeTerm(p2.region)}`).join(",") : safeTerm(key.keyHint);
|
|
2361
|
+
return `${status} ${pc8.dim(hints)}`;
|
|
2362
|
+
}
|
|
2363
|
+
function rateText(p2) {
|
|
2364
|
+
return p2.customRate ? `${formatRateAllUnits(p2.customRate.rateUsd)} ${pc8.cyan("custom")}` : `${formatRateAllUnits(p2.platformRate.rateUsd)} ${pc8.dim("platform")}`;
|
|
2365
|
+
}
|
|
2366
|
+
function formatByokRow(p2) {
|
|
2367
|
+
const ready = p2.key.status === "connected";
|
|
2368
|
+
const icon = ready ? pc8.green("\u25CF") : pc8.gray("\u25CB");
|
|
2369
|
+
const name = ready ? pc8.white(safeTerm(p2.provider)) : pc8.gray(safeTerm(p2.provider));
|
|
2370
|
+
return ` ${icon} ${name} ${keyText(p2.key)} ${rateText(p2)}`;
|
|
2371
|
+
}
|
|
2372
|
+
function formatByokDetail(p2) {
|
|
2373
|
+
const lines = [
|
|
2374
|
+
`${pc8.white(safeTerm(p2.provider))} ${keyText(p2.key)}`,
|
|
2375
|
+
` regions ${p2.regions.length > 0 ? p2.regions.map(safeTerm).join(", ") : "account default"}`,
|
|
2376
|
+
` last tested ${p2.key.lastCheckedAt === null ? "\u2014" : safeTerm(p2.key.lastCheckedAt)}`,
|
|
2377
|
+
` platform rate ${formatRateAllUnits(p2.platformRate.rateUsd)}`,
|
|
2378
|
+
` custom rate ${p2.customRate ? formatRateAllUnits(p2.customRate.rateUsd) : pc8.dim("none (costs report at the platform rate)")}`
|
|
2379
|
+
];
|
|
2380
|
+
if (p2.key.status === "error" && p2.key.statusDetail) lines.push(` last error ${pc8.dim(safeTerm(p2.key.statusDetail))}`);
|
|
2381
|
+
return lines.join("\n");
|
|
2382
|
+
}
|
|
2383
|
+
function formatByokVerify(r) {
|
|
2384
|
+
const head = r.verified === true ? pc8.green("verified") : pc8.red("not verified");
|
|
2385
|
+
const detail = r.key.statusDetail ? pc8.dim(` ${safeTerm(r.key.statusDetail)}`) : "";
|
|
2386
|
+
const act = r.key.actCapable ? pc8.green(" act-capable") : "";
|
|
2387
|
+
return `${head} ${safeTerm(r.key.provider)}${act}${detail}`;
|
|
2388
|
+
}
|
|
2389
|
+
function parseRateArgs(usd, per) {
|
|
2390
|
+
const amount = Number(usd);
|
|
2391
|
+
if (usd.trim() === "" || !Number.isFinite(amount) || amount < 0 || amount > MAX_RATE_USD) {
|
|
2392
|
+
throw new Error(`<usd> must be a number from 0 to ${MAX_RATE_USD}`);
|
|
2393
|
+
}
|
|
2394
|
+
const unit = per ?? "hour";
|
|
2395
|
+
if (!RATE_UNITS.includes(unit)) throw new Error("--per must be second, minute or hour");
|
|
2396
|
+
return { usd: amount, per: unit };
|
|
2397
|
+
}
|
|
2398
|
+
function keyBody(opts) {
|
|
2399
|
+
if (opts.field !== void 0) {
|
|
2400
|
+
if (opts.key !== void 0) throw new Error("Pass either --key or --field, not both.");
|
|
2401
|
+
return { fields: parseInputs(opts.field) };
|
|
2402
|
+
}
|
|
2403
|
+
if (opts.key !== void 0) return { key: opts.key };
|
|
2404
|
+
throw new Error("Pass --key <key> or --field name=value.");
|
|
2405
|
+
}
|
|
2406
|
+
function registerByokCommands(program2) {
|
|
2407
|
+
const byok = program2.command("byok").description("The org's BYOK providers: their keys and custom rates, shared by Actions and sandboxes").configureOutput({ outputError: usageErrorOutput });
|
|
2408
|
+
const common2 = (cmd) => cmd.option("--api-key <key>", "API key (default: $COMPUTE_API_KEY)").option("--base-url <url>", "API base URL (default: https://platform.computesdk.com)").option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)").option("--allow-untrusted-host", "send an explicit --api-key/env key to a non-computesdk, non-localhost --base-url (stored login credentials are never sent)").option("--json", "print machine-readable JSON");
|
|
2409
|
+
const list = async (opts) => {
|
|
2410
|
+
try {
|
|
2411
|
+
const data = await (await client(opts)).get("/api/v1/providers");
|
|
2412
|
+
output(opts, data, (d) => {
|
|
2413
|
+
for (const p2 of d.providers) console.log(formatByokRow(p2));
|
|
2414
|
+
});
|
|
2415
|
+
} catch (e) {
|
|
2416
|
+
fail(e, opts);
|
|
2417
|
+
}
|
|
2418
|
+
};
|
|
2419
|
+
common2(byok).action(list);
|
|
2420
|
+
common2(byok.command("list").alias("ls").description("Every provider the org may bring a key for, with key state and rate")).action(list);
|
|
2421
|
+
common2(
|
|
2422
|
+
byok.command("show").description("One provider's key state, platform rate and custom rate").argument("<provider>", "provider id (e.g. tensorlake, blaxel)")
|
|
2423
|
+
).action(async (provider, opts) => {
|
|
2424
|
+
try {
|
|
2425
|
+
const data = await (await client(opts)).get(providerPath(provider));
|
|
2426
|
+
output(opts, data, (d) => console.log(formatByokDetail(d.provider)));
|
|
2427
|
+
} catch (e) {
|
|
2428
|
+
fail(e, opts);
|
|
2429
|
+
}
|
|
2430
|
+
});
|
|
2431
|
+
common2(
|
|
2432
|
+
byok.command("configure").description("Save the org's key for a provider; untested until verified (owner/admin)").argument("<provider>", "provider id (e.g. tensorlake, blaxel)").option("--key <key>", "provider API key (single-field credentials)").option("--field <pair...>", "credential fields as name=value (multi-field providers)").option("--verify", "test the key with a real sandbox after saving")
|
|
2433
|
+
).action(async (provider, opts) => {
|
|
2434
|
+
try {
|
|
2435
|
+
const c = await secretValueClient(opts, "provider keys");
|
|
2436
|
+
const saved = await c.put(providerPath(provider, "/key"), keyBody(opts));
|
|
2437
|
+
const verification = opts.verify ? await c.post(providerPath(provider, "/verify")) : void 0;
|
|
2438
|
+
output(opts, verification ? { key: saved.key, verification } : saved, () => {
|
|
2439
|
+
console.log(`saved ${safeTerm(saved.key.provider)} ${pc8.dim(safeTerm(saved.key.keyHint ?? ""))} ${safeTerm(saved.key.status)}`);
|
|
2440
|
+
if (verification) console.log(formatByokVerify(verification));
|
|
2441
|
+
});
|
|
2442
|
+
if (verification?.verified === false) process.exitCode = 1;
|
|
2443
|
+
} catch (e) {
|
|
2444
|
+
fail(e, opts);
|
|
2445
|
+
}
|
|
2446
|
+
});
|
|
2447
|
+
common2(
|
|
2448
|
+
byok.command("verify").description('Test the stored key by placing a real sandbox with it ("Test" in Settings; owner/admin)').argument("<provider>", "provider id")
|
|
2449
|
+
).action(async (provider, opts) => {
|
|
2450
|
+
try {
|
|
2451
|
+
const result = await (await client(opts)).post(providerPath(provider, "/verify"));
|
|
2452
|
+
output(opts, result, (r) => console.log(formatByokVerify(r)));
|
|
2453
|
+
if (result.verified === false) process.exitCode = 1;
|
|
2454
|
+
} catch (e) {
|
|
2455
|
+
fail(e, opts);
|
|
2456
|
+
}
|
|
2457
|
+
});
|
|
2458
|
+
common2(
|
|
2459
|
+
byok.command("remove").alias("rm").description("Delete the org's stored key for a provider; nothing places on it until a new key passes (owner/admin)").argument("<provider>", "provider id").option("-y, --yes", "skip the confirmation")
|
|
2460
|
+
).action(async (provider, opts) => {
|
|
2461
|
+
try {
|
|
2462
|
+
await confirmWrite(`Remove the ${provider} key? Sandboxes and Actions jobs stop placing on ${provider}.`, opts);
|
|
2463
|
+
const result = await (await client(opts)).del(providerPath(provider, "/key"));
|
|
2464
|
+
output(opts, result, (r) => console.log(`deleted ${safeTerm(r.provider)}`));
|
|
2465
|
+
} catch (e) {
|
|
2466
|
+
fail(e, opts);
|
|
2467
|
+
}
|
|
2468
|
+
});
|
|
2469
|
+
const rate = byok.command("rate").description("Custom rates: report sandbox costs at your own price. Reporting only; billing is unchanged");
|
|
2470
|
+
common2(
|
|
2471
|
+
rate.command("set").description("Report a provider's sandbox costs at your own rate, e.g. what you pay it (owner/admin). Doesn't change what you're billed").argument("<provider>", "provider id").argument("<usd>", "the rate in USD").option("--per <unit>", "second, minute or hour", "hour")
|
|
2472
|
+
).action(async (provider, usd, opts) => {
|
|
2473
|
+
try {
|
|
2474
|
+
const body = parseRateArgs(usd, opts.per);
|
|
2475
|
+
const data = await (await client(opts)).put(providerPath(provider, "/rate"), body);
|
|
2476
|
+
output(opts, data, (d) => {
|
|
2477
|
+
console.log(`${safeTerm(d.provider.provider)} costs now report at ${formatRateAllUnits(d.provider.rate.rateUsd)}`);
|
|
2478
|
+
console.log(pc8.dim("Reporting only: billing is unchanged. Applies to sandboxes created from now on."));
|
|
2479
|
+
});
|
|
2480
|
+
} catch (e) {
|
|
2481
|
+
fail(e, opts);
|
|
2482
|
+
}
|
|
2483
|
+
});
|
|
2484
|
+
common2(
|
|
2485
|
+
rate.command("clear").description("Drop a provider's custom rate; its costs report at the platform rate again (owner/admin)").argument("<provider>", "provider id")
|
|
2486
|
+
).action(async (provider, opts) => {
|
|
2487
|
+
try {
|
|
2488
|
+
const data = await (await client(opts)).del(providerPath(provider, "/rate"));
|
|
2489
|
+
output(
|
|
2490
|
+
opts,
|
|
2491
|
+
data,
|
|
2492
|
+
(d) => console.log(`${safeTerm(d.provider.provider)} costs now report at the platform rate, ${formatRateAllUnits(d.provider.platformRate.rateUsd)}`)
|
|
2493
|
+
);
|
|
2494
|
+
} catch (e) {
|
|
2495
|
+
fail(e, opts);
|
|
2496
|
+
}
|
|
2497
|
+
});
|
|
2498
|
+
}
|
|
2499
|
+
|
|
1529
2500
|
// src/market.ts
|
|
1530
|
-
import
|
|
2501
|
+
import pc9 from "picocolors";
|
|
1531
2502
|
var USD_RE = /^\d+(\.\d+)?([eE][+-]?\d+)?$/;
|
|
1532
|
-
var
|
|
2503
|
+
var RATE_UNITS2 = ["second", "minute", "hour"];
|
|
1533
2504
|
var MARKET_LANES = ["actions", "sandbox"];
|
|
1534
2505
|
function parseMarketLane(value) {
|
|
1535
2506
|
if (value === void 0) return "actions";
|
|
@@ -1572,7 +2543,7 @@ function parseRate(price, per) {
|
|
|
1572
2543
|
"--price needs a unit \u2014 write it as <usd>/<unit> (e.g. --price 0.12/hour) or pass --per hour."
|
|
1573
2544
|
);
|
|
1574
2545
|
}
|
|
1575
|
-
if (!
|
|
2546
|
+
if (!RATE_UNITS2.includes(unit)) {
|
|
1576
2547
|
throw new PlatformClientError(
|
|
1577
2548
|
"invalid_argument",
|
|
1578
2549
|
`The unit must be second, minute, or hour, got "${unit}".`
|
|
@@ -1686,12 +2657,12 @@ function formatRate2(usd, per) {
|
|
|
1686
2657
|
}
|
|
1687
2658
|
function formatListingStatus(ask) {
|
|
1688
2659
|
let label;
|
|
1689
|
-
if (ask.status === "withdrawn") label =
|
|
1690
|
-
else if (ask.status === "paused") label =
|
|
1691
|
-
else if (!ask.live) label =
|
|
1692
|
-
else label =
|
|
2660
|
+
if (ask.status === "withdrawn") label = pc9.gray("withdrawn");
|
|
2661
|
+
else if (ask.status === "paused") label = pc9.yellow("paused");
|
|
2662
|
+
else if (!ask.live) label = pc9.gray("expired");
|
|
2663
|
+
else label = pc9.green("live");
|
|
1693
2664
|
if (ask.pendingUsd !== null && ask.pendingPer !== null) {
|
|
1694
|
-
label +=
|
|
2665
|
+
label += pc9.dim(` \u2192 ${formatRate2(ask.pendingUsd, ask.pendingPer)} next window`);
|
|
1695
2666
|
}
|
|
1696
2667
|
return label;
|
|
1697
2668
|
}
|
|
@@ -1700,22 +2671,22 @@ function formatListingRow(ask) {
|
|
|
1700
2671
|
return [
|
|
1701
2672
|
ask.id,
|
|
1702
2673
|
formatListingStatus(ask),
|
|
1703
|
-
|
|
2674
|
+
pc9.dim(ask.useCase === "sandbox" ? "sandbox" : "actions"),
|
|
1704
2675
|
safeTerm(ask.size),
|
|
1705
2676
|
safeTerm(ask.region ?? "-"),
|
|
1706
2677
|
formatRate2(ask.usd, ask.per),
|
|
1707
|
-
|
|
1708
|
-
|
|
2678
|
+
pc9.dim(`\xD7${ask.maxConcurrent}`),
|
|
2679
|
+
pc9.dim(expiry)
|
|
1709
2680
|
].join(" ");
|
|
1710
2681
|
}
|
|
1711
2682
|
function formatProviderStatus(p2) {
|
|
1712
2683
|
const lines = [];
|
|
1713
|
-
lines.push(`${
|
|
2684
|
+
lines.push(`${pc9.bold(safeTerm(p2.name))} ${pc9.dim(`selling ${safeTerm(p2.provider)}`)}`);
|
|
1714
2685
|
lines.push(`id: ${p2.id}`);
|
|
1715
2686
|
lines.push(
|
|
1716
|
-
`credential: ${p2.executorCredentialConnected ?
|
|
2687
|
+
`credential: ${p2.executorCredentialConnected ? pc9.green("connected") : pc9.yellow("not connected \u2014 your listings cannot fill until `compute market credential connect`")}`
|
|
1717
2688
|
);
|
|
1718
|
-
if (p2.revokedAt) lines.push(
|
|
2689
|
+
if (p2.revokedAt) lines.push(pc9.red(`revoked: ${p2.revokedAt}`));
|
|
1719
2690
|
lines.push(
|
|
1720
2691
|
`lanes: ${(p2.useCases ?? ["actions"]).join(", ")}`
|
|
1721
2692
|
);
|
|
@@ -1733,41 +2704,41 @@ function formatProviderStatus(p2) {
|
|
|
1733
2704
|
}
|
|
1734
2705
|
function formatBook(book) {
|
|
1735
2706
|
const lines = [];
|
|
1736
|
-
const lane = (useCase) =>
|
|
1737
|
-
lines.push(
|
|
1738
|
-
if (book.asks.length === 0) lines.push(
|
|
2707
|
+
const lane = (useCase) => pc9.dim(useCase === "sandbox" ? "sandbox" : "actions");
|
|
2708
|
+
lines.push(pc9.bold("sellers' asking prices"));
|
|
2709
|
+
if (book.asks.length === 0) lines.push(pc9.dim(" no listings are live"));
|
|
1739
2710
|
for (const ask of book.asks) {
|
|
1740
2711
|
const where = ask.region ? safeTerm(ask.region) : "any region";
|
|
1741
|
-
const expiry = ask.expiresAt ?
|
|
2712
|
+
const expiry = ask.expiresAt ? pc9.dim(ask.rollover ? ` renews ${ask.expiresAt}` : ` until ${ask.expiresAt}`) : "";
|
|
1742
2713
|
lines.push(
|
|
1743
2714
|
` ${lane(ask.useCase)} ${formatRate2(ask.usd, ask.per)} ${safeTerm(ask.providerName)} ${safeTerm(ask.size)} ${where} up to ${ask.maxConcurrent} at once${expiry}`
|
|
1744
2715
|
);
|
|
1745
2716
|
}
|
|
1746
2717
|
lines.push("");
|
|
1747
|
-
lines.push(
|
|
1748
|
-
if (book.bids.length === 0) lines.push(
|
|
2718
|
+
lines.push(pc9.bold("buyer offers"));
|
|
2719
|
+
if (book.bids.length === 0) lines.push(pc9.dim(" no open offers"));
|
|
1749
2720
|
for (const bid of book.bids) {
|
|
1750
2721
|
const where = bid.region ? safeTerm(bid.region) : "anywhere";
|
|
1751
|
-
const yours = bid.mine ?
|
|
2722
|
+
const yours = bid.mine ? pc9.cyan(" (yours)") : "";
|
|
1752
2723
|
lines.push(
|
|
1753
|
-
` ${lane(bid.useCase)} pays up to ${formatRate2(bid.maxUsd, bid.per)} ${safeTerm(bid.size)} ${where} ${
|
|
2724
|
+
` ${lane(bid.useCase)} pays up to ${formatRate2(bid.maxUsd, bid.per)} ${safeTerm(bid.size)} ${where} ${pc9.dim(`posted ${bid.createdAt}`)}${yours}`
|
|
1754
2725
|
);
|
|
1755
2726
|
}
|
|
1756
2727
|
lines.push("");
|
|
1757
|
-
lines.push(
|
|
1758
|
-
if (book.fills.length === 0) lines.push(
|
|
2728
|
+
lines.push(pc9.bold("recent sales"));
|
|
2729
|
+
if (book.fills.length === 0) lines.push(pc9.dim(" nothing has sold yet"));
|
|
1759
2730
|
for (const fill of book.fills) {
|
|
1760
|
-
const statusNote = fill.status === "replaced" ?
|
|
2731
|
+
const statusNote = fill.status === "replaced" ? pc9.yellow(" replaced") : fill.status === "closed" ? pc9.gray(" closed") : "";
|
|
1761
2732
|
lines.push(
|
|
1762
|
-
` ${
|
|
2733
|
+
` ${pc9.dim(fill.id)} ${lane(fill.useCase)} ${formatRate2(fill.usd, fill.per)} ${safeTerm(fill.provider)} ${safeTerm(fill.size)} ${safeTerm(fill.region ?? "-")} ${pc9.dim(fill.createdAt)}${statusNote}`
|
|
1763
2734
|
);
|
|
1764
2735
|
}
|
|
1765
2736
|
return lines.join("\n");
|
|
1766
2737
|
}
|
|
1767
2738
|
function formatReplacedFill(fill) {
|
|
1768
2739
|
const settled = formatMoney(fill.settledMicroUsd / 1e6);
|
|
1769
|
-
const job = fill.jobRequeued ?
|
|
1770
|
-
return `replaced ${
|
|
2740
|
+
const job = fill.jobRequeued ? pc9.dim(" \u2014 job re-places on the buyer's next provider") : "";
|
|
2741
|
+
return `replaced ${pc9.cyan(fill.fillId)} settled ${settled}${job}`;
|
|
1771
2742
|
}
|
|
1772
2743
|
function replaceTarget(listingId, fillId) {
|
|
1773
2744
|
if (fillId !== void 0) {
|
|
@@ -1789,9 +2760,9 @@ function replaceTarget(listingId, fillId) {
|
|
|
1789
2760
|
}
|
|
1790
2761
|
function formatSettlementRow(s) {
|
|
1791
2762
|
const period = `${s.periodStart.slice(0, 10)} \u2192 ${s.periodEnd.slice(0, 10)}`;
|
|
1792
|
-
const paid = s.paidAt ?
|
|
2763
|
+
const paid = s.paidAt ? pc9.green(`paid ${s.paidAt.slice(0, 10)}`) : s.invoiceRef ? pc9.yellow(`invoiced ${safeTerm(s.invoiceRef)}`) : pc9.dim("unpaid");
|
|
1793
2764
|
return [
|
|
1794
|
-
|
|
2765
|
+
pc9.dim(period),
|
|
1795
2766
|
`${s.vcpuSeconds.toLocaleString("en-US")} vCPU\xB7s`,
|
|
1796
2767
|
`gross ${formatMoney(s.grossUsd)}`,
|
|
1797
2768
|
`net ${formatMoney(s.netUsd)}`,
|
|
@@ -1825,22 +2796,22 @@ function formatCap(cap) {
|
|
|
1825
2796
|
return cap === null ? "No market cap \u2014 market-placed jobs need their own bid to fill." : `market cap ${formatRate2(cap.usd, cap.per)}`;
|
|
1826
2797
|
}
|
|
1827
2798
|
function formatBidRow(bid) {
|
|
1828
|
-
const status = bid.status === "open" ?
|
|
2799
|
+
const status = bid.status === "open" ? pc9.green("open") : bid.status === "filled" ? pc9.cyan("filled") : pc9.gray("cancelled");
|
|
1829
2800
|
return [
|
|
1830
2801
|
bid.id,
|
|
1831
2802
|
status,
|
|
1832
|
-
|
|
2803
|
+
pc9.dim(bid.useCase === "sandbox" ? "sandbox" : "actions"),
|
|
1833
2804
|
safeTerm(bid.size),
|
|
1834
2805
|
safeTerm(bid.region ?? "any region"),
|
|
1835
2806
|
`\u2264 ${formatRate2(bid.maxUsd, bid.per)}`,
|
|
1836
|
-
|
|
2807
|
+
pc9.dim(bid.expiresAt ? `expires ${bid.expiresAt}` : "standing")
|
|
1837
2808
|
].join(" ");
|
|
1838
2809
|
}
|
|
1839
2810
|
function formatCredits(b) {
|
|
1840
2811
|
const lines = [`available ${formatMoney(b.balanceMicroUsd / MICRO_USD)}`];
|
|
1841
2812
|
if (b.holds.length > 0) {
|
|
1842
2813
|
lines.push(
|
|
1843
|
-
|
|
2814
|
+
pc9.dim(`reserved ${formatMoney(b.heldMicroUsd / MICRO_USD)} across ${b.holds.length} running job${b.holds.length === 1 ? "" : "s"}`)
|
|
1844
2815
|
);
|
|
1845
2816
|
}
|
|
1846
2817
|
return lines.join("\n");
|
|
@@ -1849,29 +2820,29 @@ function formatLedgerRow(e) {
|
|
|
1849
2820
|
const usd = e.microUsd / MICRO_USD;
|
|
1850
2821
|
const amount = usd < 0 ? `-${formatMoney(-usd)}` : `+${formatMoney(usd)}`;
|
|
1851
2822
|
return [
|
|
1852
|
-
|
|
1853
|
-
(usd < 0 ?
|
|
2823
|
+
pc9.dim(e.createdAt.slice(0, 19).replace("T", " ")),
|
|
2824
|
+
(usd < 0 ? pc9.red : pc9.green)(amount.padStart(10)),
|
|
1854
2825
|
safeTerm(e.label),
|
|
1855
|
-
|
|
2826
|
+
pc9.dim(e.jobId ? `job ${e.jobId}` : "")
|
|
1856
2827
|
].join(" ").trimEnd();
|
|
1857
2828
|
}
|
|
1858
2829
|
function formatPurchaseRow(p2) {
|
|
1859
|
-
const cost = p2.costMicroUsd !== null ? formatMoney(p2.costMicroUsd / MICRO_USD) : p2.status === "live" ?
|
|
2830
|
+
const cost = p2.costMicroUsd !== null ? formatMoney(p2.costMicroUsd / MICRO_USD) : p2.status === "live" ? pc9.yellow("running") : "-";
|
|
1860
2831
|
return [
|
|
1861
|
-
|
|
2832
|
+
pc9.dim(p2.startedAt.slice(0, 19).replace("T", " ")),
|
|
1862
2833
|
cost.padStart(10),
|
|
1863
|
-
|
|
1864
|
-
|
|
2834
|
+
pc9.cyan(safeTerm(p2.sellerName)),
|
|
2835
|
+
pc9.dim(`${safeTerm(p2.provider)}/${safeTerm(p2.region ?? "any")}`),
|
|
1865
2836
|
formatRate2(p2.usd, p2.per),
|
|
1866
|
-
p2.secondsBilled !== null ?
|
|
1867
|
-
p2.status === "replaced" ?
|
|
1868
|
-
|
|
2837
|
+
p2.secondsBilled !== null ? pc9.dim(`${p2.secondsBilled}s`) : "",
|
|
2838
|
+
p2.status === "replaced" ? pc9.yellow("replaced") : "",
|
|
2839
|
+
pc9.dim(p2.runId ? `run ${p2.runId}` : p2.sandboxId ? `sandbox ${p2.sandboxId}` : "")
|
|
1869
2840
|
].filter((part) => part !== "").join(" ");
|
|
1870
2841
|
}
|
|
1871
2842
|
function registerMarketCommands(program2) {
|
|
1872
2843
|
const market = program2.command("market").description("Buy and sell compute capacity on the compute market").configureOutput({ outputError: usageErrorOutput });
|
|
1873
|
-
const
|
|
1874
|
-
|
|
2844
|
+
const common2 = (cmd) => cmd.option("--api-key <key>", "API key (default: $COMPUTE_API_KEY)").option("--base-url <url>", "API base URL (default: https://platform.computesdk.com)").option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)").option("--allow-untrusted-host", "send an explicit --api-key/env key to a non-computesdk, non-localhost --base-url (stored login credentials are never sent)").option("--json", "print machine-readable JSON");
|
|
2845
|
+
common2(
|
|
1875
2846
|
market.command("listings").alias("list").description("Your listings \u2014 live, paused, expired, and withdrawn")
|
|
1876
2847
|
).action(async (opts) => {
|
|
1877
2848
|
try {
|
|
@@ -1889,7 +2860,7 @@ function registerMarketCommands(program2) {
|
|
|
1889
2860
|
fail(e, opts);
|
|
1890
2861
|
}
|
|
1891
2862
|
});
|
|
1892
|
-
|
|
2863
|
+
common2(
|
|
1893
2864
|
market.command("sell").description("Post a listing: sell capacity at a price").requiredOption("--price <usd/unit>", "price per unit of time (e.g. 0.12/hour)").option("--per <unit>", "unit for a bare --price usd (second, minute, or hour)").option("--size <tier>", "size tier to sell (default: medium, else the provider's first tier)").option("--use-case <lane>", "lane to sell into: actions or sandbox (default: actions)").option("--region <region>", "region to sell in (default: anywhere the provider runs)").option("--capacity <n>", "max simultaneous fills (default: 1)").option("--expires-in <hours>", "delist after this many hours (default: standing)").option("--renew", "re-list for the same window each time it expires (requires --expires-in)")
|
|
1894
2865
|
).action(async (opts) => {
|
|
1895
2866
|
try {
|
|
@@ -1908,21 +2879,21 @@ function registerMarketCommands(program2) {
|
|
|
1908
2879
|
);
|
|
1909
2880
|
}
|
|
1910
2881
|
size = preset.name;
|
|
1911
|
-
console.error(
|
|
2882
|
+
console.error(pc9.dim(`no --size given \u2014 listing at "${size}"`));
|
|
1912
2883
|
}
|
|
1913
2884
|
const result = await c.post(
|
|
1914
2885
|
"/api/v1/market/asks",
|
|
1915
2886
|
sellBody({ ...opts, size, useCase })
|
|
1916
2887
|
);
|
|
1917
2888
|
output(opts, result, (r) => {
|
|
1918
|
-
console.log(`listed ${
|
|
2889
|
+
console.log(`listed ${pc9.cyan(r.ask.id)}`);
|
|
1919
2890
|
console.log(formatListingRow(r.ask));
|
|
1920
2891
|
});
|
|
1921
2892
|
} catch (e) {
|
|
1922
2893
|
fail(e, opts);
|
|
1923
2894
|
}
|
|
1924
2895
|
});
|
|
1925
|
-
|
|
2896
|
+
common2(
|
|
1926
2897
|
market.command("price").description("Reprice a listing").argument("<listing-id>", "listing ID").requiredOption("--price <usd/unit>", "new price per unit of time (e.g. 0.08/hour)").option("--per <unit>", "unit for a bare --price usd (second, minute, or hour)")
|
|
1927
2898
|
).action(async (listingId, opts) => {
|
|
1928
2899
|
try {
|
|
@@ -1931,8 +2902,8 @@ function registerMarketCommands(program2) {
|
|
|
1931
2902
|
listingPatchBody(listingId, { price: opts.price, per: opts.per })
|
|
1932
2903
|
);
|
|
1933
2904
|
output(opts, result, (r) => {
|
|
1934
|
-
const rate = r.ask.pendingUsd !== null && r.ask.pendingPer !== null ? `${formatRate2(r.ask.pendingUsd, r.ask.pendingPer)} ${
|
|
1935
|
-
console.log(`repriced ${
|
|
2905
|
+
const rate = r.ask.pendingUsd !== null && r.ask.pendingPer !== null ? `${formatRate2(r.ask.pendingUsd, r.ask.pendingPer)} ${pc9.dim("(applies next window)")}` : formatRate2(r.ask.usd, r.ask.per);
|
|
2906
|
+
console.log(`repriced ${pc9.cyan(r.ask.id)} ${rate}`);
|
|
1936
2907
|
});
|
|
1937
2908
|
} catch (e) {
|
|
1938
2909
|
fail(e, opts);
|
|
@@ -1945,19 +2916,19 @@ function registerMarketCommands(program2) {
|
|
|
1945
2916
|
listingPatchBody(listingId, { status })
|
|
1946
2917
|
);
|
|
1947
2918
|
output(opts, result, (r) => {
|
|
1948
|
-
console.log(`${status === "live" ? "resumed" : "paused"} ${
|
|
2919
|
+
console.log(`${status === "live" ? "resumed" : "paused"} ${pc9.cyan(r.ask.id)}`);
|
|
1949
2920
|
});
|
|
1950
2921
|
} catch (e) {
|
|
1951
2922
|
fail(e, opts);
|
|
1952
2923
|
}
|
|
1953
2924
|
};
|
|
1954
|
-
|
|
2925
|
+
common2(
|
|
1955
2926
|
market.command("pause").description("Pause a listing \u2014 it stays posted but cannot fill").argument("<listing-id>", "listing ID")
|
|
1956
2927
|
).action((listingId, opts) => setStatus(listingId, "paused", opts));
|
|
1957
|
-
|
|
2928
|
+
common2(
|
|
1958
2929
|
market.command("resume").description("Resume a paused listing").argument("<listing-id>", "listing ID")
|
|
1959
2930
|
).action((listingId, opts) => setStatus(listingId, "live", opts));
|
|
1960
|
-
|
|
2931
|
+
common2(
|
|
1961
2932
|
market.command("withdraw").description("Withdraw a listing \u2014 it leaves the book for good").argument("<listing-id>", "listing ID")
|
|
1962
2933
|
).action(async (listingId, opts) => {
|
|
1963
2934
|
try {
|
|
@@ -1965,13 +2936,13 @@ function registerMarketCommands(program2) {
|
|
|
1965
2936
|
`/api/v1/market/asks?id=${encodeURIComponent(listingId)}`
|
|
1966
2937
|
);
|
|
1967
2938
|
output(opts, result, (r) => {
|
|
1968
|
-
console.log(`withdrew ${
|
|
2939
|
+
console.log(`withdrew ${pc9.cyan(r.ask.id)}`);
|
|
1969
2940
|
});
|
|
1970
2941
|
} catch (e) {
|
|
1971
2942
|
fail(e, opts);
|
|
1972
2943
|
}
|
|
1973
2944
|
});
|
|
1974
|
-
|
|
2945
|
+
common2(
|
|
1975
2946
|
market.command("replace").description(
|
|
1976
2947
|
"Take capacity back: evict a sale, or pause a listing and evict every sale on it.\nAn evicted Actions job restarts on the buyer's next provider; the buyer pays\nonly for the seconds the sale actually ran."
|
|
1977
2948
|
).argument("[listing-id]", "listing to pause and evict every sale on").option("--fill <fill-id>", "evict one sale without touching the listing")
|
|
@@ -1986,14 +2957,14 @@ function registerMarketCommands(program2) {
|
|
|
1986
2957
|
} else {
|
|
1987
2958
|
const result = await c.post(target.path, {});
|
|
1988
2959
|
output(opts, result, (r) => {
|
|
1989
|
-
console.log(`paused ${
|
|
2960
|
+
console.log(`paused ${pc9.cyan(r.listing.id)}`);
|
|
1990
2961
|
if (r.fills.length === 0) {
|
|
1991
|
-
console.log(
|
|
2962
|
+
console.log(pc9.dim(" no live sales to evict"));
|
|
1992
2963
|
return;
|
|
1993
2964
|
}
|
|
1994
2965
|
for (const f of r.fills) {
|
|
1995
2966
|
if (f.ok) console.log(formatReplacedFill(f.fill));
|
|
1996
|
-
else console.log(
|
|
2967
|
+
else console.log(pc9.red(` could not evict a sale \u2014 ${f.error}`));
|
|
1997
2968
|
}
|
|
1998
2969
|
});
|
|
1999
2970
|
if (result.fills.some((f) => !f.ok)) process.exitCode = 1;
|
|
@@ -2003,7 +2974,7 @@ function registerMarketCommands(program2) {
|
|
|
2003
2974
|
}
|
|
2004
2975
|
}
|
|
2005
2976
|
);
|
|
2006
|
-
|
|
2977
|
+
common2(
|
|
2007
2978
|
market.command("book").description("Live prices: sellers' asking prices, buyer offers, recent sales").option("--use-case <lane>", "only this lane: actions or sandbox (default: both)")
|
|
2008
2979
|
).action(async (opts) => {
|
|
2009
2980
|
try {
|
|
@@ -2016,7 +2987,7 @@ function registerMarketCommands(program2) {
|
|
|
2016
2987
|
fail(e, opts);
|
|
2017
2988
|
}
|
|
2018
2989
|
});
|
|
2019
|
-
|
|
2990
|
+
common2(
|
|
2020
2991
|
market.command("settlements").description("Your monthly payout reports")
|
|
2021
2992
|
).action(async (opts) => {
|
|
2022
2993
|
try {
|
|
@@ -2032,7 +3003,7 @@ function registerMarketCommands(program2) {
|
|
|
2032
3003
|
fail(e, opts);
|
|
2033
3004
|
}
|
|
2034
3005
|
});
|
|
2035
|
-
|
|
3006
|
+
common2(
|
|
2036
3007
|
market.command("status").description("Who you are on the market: seller identity, credential, sizes, regions")
|
|
2037
3008
|
).action(async (opts) => {
|
|
2038
3009
|
try {
|
|
@@ -2043,7 +3014,7 @@ function registerMarketCommands(program2) {
|
|
|
2043
3014
|
}
|
|
2044
3015
|
});
|
|
2045
3016
|
const cap = market.command("cap").description("The org market cap: the most a market-placed job pays without its own bid");
|
|
2046
|
-
|
|
3017
|
+
common2(cap.command("show", { isDefault: true }).description("Show the current cap")).action(
|
|
2047
3018
|
async (opts) => {
|
|
2048
3019
|
try {
|
|
2049
3020
|
const { marketCap } = await (await client(opts)).get(
|
|
@@ -2055,7 +3026,7 @@ function registerMarketCommands(program2) {
|
|
|
2055
3026
|
}
|
|
2056
3027
|
}
|
|
2057
3028
|
);
|
|
2058
|
-
|
|
3029
|
+
common2(
|
|
2059
3030
|
cap.command("set").description("Set the cap").requiredOption("--price <usd/unit>", "max price per unit of time (e.g. 0.40/hour)").option("--per <unit>", "unit for a bare --price usd (second, minute, or hour)")
|
|
2060
3031
|
).action(async (opts) => {
|
|
2061
3032
|
try {
|
|
@@ -2069,7 +3040,7 @@ function registerMarketCommands(program2) {
|
|
|
2069
3040
|
fail(e, opts);
|
|
2070
3041
|
}
|
|
2071
3042
|
});
|
|
2072
|
-
|
|
3043
|
+
common2(
|
|
2073
3044
|
cap.command("clear").description("Remove the cap (refused while your placement order still names market)")
|
|
2074
3045
|
).action(async (opts) => {
|
|
2075
3046
|
try {
|
|
@@ -2082,7 +3053,7 @@ function registerMarketCommands(program2) {
|
|
|
2082
3053
|
fail(e, opts);
|
|
2083
3054
|
}
|
|
2084
3055
|
});
|
|
2085
|
-
|
|
3056
|
+
common2(
|
|
2086
3057
|
market.command("bids").description("Your org's standing bids \u2014 open, filled, and cancelled")
|
|
2087
3058
|
).action(async (opts) => {
|
|
2088
3059
|
try {
|
|
@@ -2100,7 +3071,7 @@ function registerMarketCommands(program2) {
|
|
|
2100
3071
|
fail(e, opts);
|
|
2101
3072
|
}
|
|
2102
3073
|
});
|
|
2103
|
-
|
|
3074
|
+
common2(
|
|
2104
3075
|
market.command("bid").description("Post a standing bid: the most you will pay for a size tier").requiredOption("--size <tier>", "size tier to buy (e.g. xlarge)").requiredOption("--price <usd/unit>", "max price per unit of time (e.g. 0.40/hour)").option("--per <unit>", "unit for a bare --price usd (second, minute, or hour)").option("--region <region>", "only fill in this region (default: any)").option("--use-case <lane>", "lane to buy on: actions or sandbox (default: actions)").option("--expires-in <hours>", "cancel after this many hours (default: standing)")
|
|
2105
3076
|
).action(async (opts) => {
|
|
2106
3077
|
try {
|
|
@@ -2109,26 +3080,26 @@ function registerMarketCommands(program2) {
|
|
|
2109
3080
|
bidBody(opts)
|
|
2110
3081
|
);
|
|
2111
3082
|
output(opts, result, (r) => {
|
|
2112
|
-
console.log(`bid placed ${
|
|
3083
|
+
console.log(`bid placed ${pc9.cyan(r.bid.id)}`);
|
|
2113
3084
|
console.log(formatBidRow(r.bid));
|
|
2114
3085
|
});
|
|
2115
3086
|
} catch (e) {
|
|
2116
3087
|
fail(e, opts);
|
|
2117
3088
|
}
|
|
2118
3089
|
});
|
|
2119
|
-
|
|
3090
|
+
common2(
|
|
2120
3091
|
market.command("cancel-bid").description("Cancel an open standing bid").argument("<bid-id>", "bid ID")
|
|
2121
3092
|
).action(async (bidId, opts) => {
|
|
2122
3093
|
try {
|
|
2123
3094
|
const result = await (await client(opts)).del(
|
|
2124
3095
|
`/api/v1/market/bids?id=${encodeURIComponent(bidId)}`
|
|
2125
3096
|
);
|
|
2126
|
-
output(opts, result, (r) => console.log(`cancelled ${
|
|
3097
|
+
output(opts, result, (r) => console.log(`cancelled ${pc9.cyan(r.bid.id)}`));
|
|
2127
3098
|
} catch (e) {
|
|
2128
3099
|
fail(e, opts);
|
|
2129
3100
|
}
|
|
2130
3101
|
});
|
|
2131
|
-
|
|
3102
|
+
common2(
|
|
2132
3103
|
market.command("purchases").description("What the market ran for you: seller, price, duration, and cost, newest first").option("--limit <n>", "purchases per page (max 200, default 50)").option("--cursor <cursor>", "continue from a previous page")
|
|
2133
3104
|
).action(async (opts) => {
|
|
2134
3105
|
try {
|
|
@@ -2139,13 +3110,13 @@ function registerMarketCommands(program2) {
|
|
|
2139
3110
|
return;
|
|
2140
3111
|
}
|
|
2141
3112
|
for (const row of p2.purchases) console.log(formatPurchaseRow(row));
|
|
2142
|
-
if (p2.nextCursor) console.log(
|
|
3113
|
+
if (p2.nextCursor) console.log(pc9.dim(`more: --cursor ${p2.nextCursor}`));
|
|
2143
3114
|
});
|
|
2144
3115
|
} catch (e) {
|
|
2145
3116
|
fail(e, opts);
|
|
2146
3117
|
}
|
|
2147
3118
|
});
|
|
2148
|
-
|
|
3119
|
+
common2(
|
|
2149
3120
|
market.command("credits").description("Prepaid market credits: available balance and reserved holds")
|
|
2150
3121
|
).action(async (opts) => {
|
|
2151
3122
|
try {
|
|
@@ -2157,7 +3128,7 @@ function registerMarketCommands(program2) {
|
|
|
2157
3128
|
fail(e, opts);
|
|
2158
3129
|
}
|
|
2159
3130
|
});
|
|
2160
|
-
|
|
3131
|
+
common2(
|
|
2161
3132
|
market.command("ledger").description("Credit history, newest first: top-ups, charges, holds, refunds").option("--limit <n>", "entries per page (max 200, default 50)").option("--cursor <cursor>", "continue from a previous page")
|
|
2162
3133
|
).action(async (opts) => {
|
|
2163
3134
|
try {
|
|
@@ -2168,13 +3139,13 @@ function registerMarketCommands(program2) {
|
|
|
2168
3139
|
return;
|
|
2169
3140
|
}
|
|
2170
3141
|
for (const entry of p2.entries) console.log(formatLedgerRow(entry));
|
|
2171
|
-
if (p2.nextCursor) console.log(
|
|
3142
|
+
if (p2.nextCursor) console.log(pc9.dim(`more: --cursor ${p2.nextCursor}`));
|
|
2172
3143
|
});
|
|
2173
3144
|
} catch (e) {
|
|
2174
3145
|
fail(e, opts);
|
|
2175
3146
|
}
|
|
2176
3147
|
});
|
|
2177
|
-
|
|
3148
|
+
common2(
|
|
2178
3149
|
market.command("topup").description("Buy prepaid credits \u2014 prints a Stripe checkout link to pay in your browser").argument("<usd>", "amount in USD (e.g. 50)")
|
|
2179
3150
|
).action(async (amount, opts) => {
|
|
2180
3151
|
try {
|
|
@@ -2191,7 +3162,7 @@ function registerMarketCommands(program2) {
|
|
|
2191
3162
|
}
|
|
2192
3163
|
});
|
|
2193
3164
|
const credential = market.command("credential").description("Connect the credential your listings fill under");
|
|
2194
|
-
|
|
3165
|
+
common2(
|
|
2195
3166
|
credential.command("connect").description(
|
|
2196
3167
|
"Save the executor credential your sold capacity runs under. Each field is read from\na <PROVIDER>_<FIELD> env var (e.g. TENSORLAKE_API_KEY) \u2014 never pass secrets in argv;\n--field name=value overrides a field (visible in shell history)"
|
|
2197
3168
|
).option("--field <pairs...>", "credential fields as name=value (prefer env vars for secrets)")
|
|
@@ -2222,7 +3193,7 @@ ${hints}`
|
|
|
2222
3193
|
}
|
|
2223
3194
|
if (resolved.fromFlag.some((name) => provider.credentialFields.find((f) => f.name === name)?.secret)) {
|
|
2224
3195
|
console.error(
|
|
2225
|
-
|
|
3196
|
+
pc9.yellow("note: a secret passed via --field stays in your shell history \u2014 prefer the env vars.")
|
|
2226
3197
|
);
|
|
2227
3198
|
}
|
|
2228
3199
|
const result = await c.post(
|
|
@@ -2230,13 +3201,13 @@ ${hints}`
|
|
|
2230
3201
|
credentialBody(provider.credentialFields, resolved.values)
|
|
2231
3202
|
);
|
|
2232
3203
|
output(opts, result, (r) => {
|
|
2233
|
-
console.log(`connected ${
|
|
3204
|
+
console.log(`connected ${pc9.cyan(safeTerm(r.provider.name))} credential saved`);
|
|
2234
3205
|
});
|
|
2235
3206
|
} catch (e) {
|
|
2236
3207
|
fail(e, opts);
|
|
2237
3208
|
}
|
|
2238
3209
|
});
|
|
2239
|
-
|
|
3210
|
+
common2(
|
|
2240
3211
|
credential.command("disconnect").description("Remove the stored credential \u2014 listings stop filling until a new one connects")
|
|
2241
3212
|
).action(async (opts) => {
|
|
2242
3213
|
try {
|
|
@@ -2244,7 +3215,7 @@ ${hints}`
|
|
|
2244
3215
|
"/api/v1/market/provider/credential"
|
|
2245
3216
|
);
|
|
2246
3217
|
output(opts, result, (r) => {
|
|
2247
|
-
console.log(`disconnected ${
|
|
3218
|
+
console.log(`disconnected ${pc9.cyan(safeTerm(r.provider.name))} credential removed`);
|
|
2248
3219
|
});
|
|
2249
3220
|
} catch (e) {
|
|
2250
3221
|
fail(e, opts);
|
|
@@ -2258,13 +3229,13 @@ import * as os from "os";
|
|
|
2258
3229
|
import * as path from "path";
|
|
2259
3230
|
import * as readline from "readline";
|
|
2260
3231
|
import { Readable } from "stream";
|
|
2261
|
-
import
|
|
3232
|
+
import pc10 from "picocolors";
|
|
2262
3233
|
import * as tar from "tar";
|
|
2263
3234
|
|
|
2264
3235
|
// src/current-instance.ts
|
|
2265
3236
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
2266
3237
|
import { createHash } from "crypto";
|
|
2267
|
-
import { existsSync, mkdirSync as mkdirSync2, readFileSync as
|
|
3238
|
+
import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
2268
3239
|
import { homedir } from "os";
|
|
2269
3240
|
import { join as join2 } from "path";
|
|
2270
3241
|
function stateDir() {
|
|
@@ -2287,7 +3258,7 @@ function orgKey(opts) {
|
|
|
2287
3258
|
const key = opts.apiKey || process.env.COMPUTE_API_KEY || process.env.BENCHMARKS_PLATFORM_API_KEY;
|
|
2288
3259
|
if (key) return `key:${createHash("sha256").update(key).digest("hex").slice(0, 12)}`;
|
|
2289
3260
|
try {
|
|
2290
|
-
const raw = JSON.parse(
|
|
3261
|
+
const raw = JSON.parse(readFileSync3(join2(stateDir(), "credentials.json"), "utf8"));
|
|
2291
3262
|
const org2 = raw?.orgId ?? raw?.orgSlug;
|
|
2292
3263
|
if (org2) return `org:${org2}`;
|
|
2293
3264
|
} catch {
|
|
@@ -2296,7 +3267,7 @@ function orgKey(opts) {
|
|
|
2296
3267
|
}
|
|
2297
3268
|
function readStore() {
|
|
2298
3269
|
try {
|
|
2299
|
-
const parsed = JSON.parse(
|
|
3270
|
+
const parsed = JSON.parse(readFileSync3(statePath(), "utf8"));
|
|
2300
3271
|
if (typeof parsed !== "object" || parsed === null) return {};
|
|
2301
3272
|
return parsed;
|
|
2302
3273
|
} catch {
|
|
@@ -2364,6 +3335,55 @@ function shortId(id) {
|
|
|
2364
3335
|
return id.length > 8 ? `${id.slice(0, 4)}\u2026` : id;
|
|
2365
3336
|
}
|
|
2366
3337
|
|
|
3338
|
+
// src/sandbox-billing.ts
|
|
3339
|
+
function printTable(header, rows) {
|
|
3340
|
+
const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i].length)));
|
|
3341
|
+
const line = (cells) => cells.map((c, i) => c.padEnd(widths[i])).join(" ").trimEnd();
|
|
3342
|
+
console.log(line(header));
|
|
3343
|
+
for (const row of rows) console.log(line(row));
|
|
3344
|
+
}
|
|
3345
|
+
function printCosts(c, customerOnly) {
|
|
3346
|
+
if (customerOnly) console.log("customer sandboxes only");
|
|
3347
|
+
printTable(
|
|
3348
|
+
["PROVIDER", "SANDBOXES", "RUNNING", "RUNNING COST", "SETTLED", "TOTAL"],
|
|
3349
|
+
[
|
|
3350
|
+
[
|
|
3351
|
+
"all",
|
|
3352
|
+
String(c.running.count + c.settled.count),
|
|
3353
|
+
String(c.running.count),
|
|
3354
|
+
formatMoney(c.running.costUsd),
|
|
3355
|
+
`${c.settled.count} \xB7 ${formatMoney(c.settled.costUsd)}`,
|
|
3356
|
+
formatMoney(c.totalUsd)
|
|
3357
|
+
],
|
|
3358
|
+
...c.byProvider.map((p2) => [
|
|
3359
|
+
safeTerm(p2.provider),
|
|
3360
|
+
String(p2.count),
|
|
3361
|
+
p2.running ? String(p2.running.count) : "\u2014",
|
|
3362
|
+
p2.running ? formatMoney(p2.running.costUsd) : "\u2014",
|
|
3363
|
+
p2.settled ? `${p2.settled.count} \xB7 ${formatMoney(p2.settled.costUsd)}` : "\u2014",
|
|
3364
|
+
formatMoney(p2.costUsd)
|
|
3365
|
+
])
|
|
3366
|
+
]
|
|
3367
|
+
);
|
|
3368
|
+
if (c.currency !== "USD") console.log(`currency: ${safeTerm(c.currency)}`);
|
|
3369
|
+
}
|
|
3370
|
+
function registerBillingCommands(group, common2, deps) {
|
|
3371
|
+
common2(
|
|
3372
|
+
group.command("costs").description("Show the org's sandbox spend: running, settled and per provider").option("--customer-only", "exclude idle platform sandboxes (warm pool, CI sync, snapshot builds); Actions job sandboxes stay")
|
|
3373
|
+
).action(async (opts) => {
|
|
3374
|
+
try {
|
|
3375
|
+
const c = await deps.client(opts);
|
|
3376
|
+
const res = await c.get(
|
|
3377
|
+
"/api/v1/sandboxes/costs",
|
|
3378
|
+
opts.customerOnly ? { customerOnly: "true" } : void 0
|
|
3379
|
+
);
|
|
3380
|
+
deps.output(opts, res, (data) => printCosts(data, opts.customerOnly === true));
|
|
3381
|
+
} catch (e) {
|
|
3382
|
+
deps.fail(e, opts);
|
|
3383
|
+
}
|
|
3384
|
+
});
|
|
3385
|
+
}
|
|
3386
|
+
|
|
2367
3387
|
// src/sandboxes.ts
|
|
2368
3388
|
function shellQuote(arg) {
|
|
2369
3389
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
@@ -2380,16 +3400,16 @@ function formatLocalTime(iso) {
|
|
|
2380
3400
|
function printSandbox(s, verbose = false) {
|
|
2381
3401
|
const p2 = s.placement;
|
|
2382
3402
|
console.log(
|
|
2383
|
-
`${
|
|
3403
|
+
`${pc10.cyan(s.id)} ${s.status} ${p2?.box?.provider ?? s.provider ?? "\u2014"} ${p2?.size ?? "\u2014"} ${p2 ? shortRate(p2.rate) : "\u2014"}`
|
|
2384
3404
|
);
|
|
2385
3405
|
if (s.label) {
|
|
2386
3406
|
console.log(` label: ${s.label} created: ${formatLocalTime(s.createdAt)}`);
|
|
2387
3407
|
}
|
|
2388
|
-
if (s.destroyError) console.log(` destroyError: ${
|
|
3408
|
+
if (s.destroyError) console.log(` destroyError: ${pc10.red(s.destroyError)}`);
|
|
2389
3409
|
if (!verbose) return;
|
|
2390
3410
|
console.log(` providerSandboxId: ${s.providerSandboxId ?? "\u2014"} commands: ${s.commandCount}`);
|
|
2391
3411
|
if (s.image !== void 0) {
|
|
2392
|
-
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${
|
|
3412
|
+
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${pc10.dim(`(requested: ${s.requestedImage})`)}` : ""}`);
|
|
2393
3413
|
}
|
|
2394
3414
|
if (p2) {
|
|
2395
3415
|
const box = p2.box ? ` / ${p2.box.sizeName ?? "custom"}${p2.box.resources ? ` (${p2.box.resources.cpus ?? "?"} vCPU / ${p2.box.resources.memoryMb ?? "?"} MB)` : ""}` : "";
|
|
@@ -2407,7 +3427,7 @@ function printSandbox(s, verbose = false) {
|
|
|
2407
3427
|
var perHour = (n) => n === void 0 ? "\u2014" : formatRateAllUnits(rateAllUnits({ usd: n, per: "hour" }));
|
|
2408
3428
|
var usdAmount = (n) => n === void 0 ? "\u2014" : formatMoney(n);
|
|
2409
3429
|
function printQuote(q, timeoutMs) {
|
|
2410
|
-
console.log(`quote: ${q.ok ?
|
|
3430
|
+
console.log(`quote: ${q.ok ? pc10.green("ok") : pc10.red(q.reason ?? "unfillable")}`);
|
|
2411
3431
|
const box = q.placement?.box;
|
|
2412
3432
|
console.log(
|
|
2413
3433
|
` size: ${q.placement?.size ?? "\u2014"} provider: ${q.placement?.provider ?? "\u2014"}` + (box ? ` box: ${box.sizeName ?? "custom"} (${box.provider}${box.resources ? `, ${box.resources.cpus ?? "?"} vCPU / ${box.resources.memoryMb ?? "?"} MB` : ""})` : "")
|
|
@@ -2426,17 +3446,17 @@ function printQuote(q, timeoutMs) {
|
|
|
2426
3446
|
);
|
|
2427
3447
|
console.log(` cap: ${q.maxPrice ? formatUsdPer(q.maxPrice) : perHour(q.marketCapUsdPerHour)}`);
|
|
2428
3448
|
console.log(` protection limit: ${perHour(q.protectionLimitUsdPerHour)}`);
|
|
2429
|
-
if (!q.ok && q.topUpPath) console.log(` ${
|
|
2430
|
-
if (q.liveAskDepth !== void 0) console.log(` ${
|
|
3449
|
+
if (!q.ok && q.topUpPath) console.log(` ${pc10.dim(`\u2192 ${q.topUpPath}`)}`);
|
|
3450
|
+
if (q.liveAskDepth !== void 0) console.log(` ${pc10.dim(`live asks: ${q.liveAskDepth}`)}`);
|
|
2431
3451
|
}
|
|
2432
3452
|
function printProcess(p2) {
|
|
2433
3453
|
const exit = p2.status === "exited" ? `exit=${p2.exitCode ?? "?"}${p2.signal ? ` (${p2.signal})` : ""}` : "";
|
|
2434
3454
|
const stdin = p2.stdin && p2.status === "running" ? " [stdin open]" : "";
|
|
2435
|
-
console.log(`${
|
|
3455
|
+
console.log(`${pc10.cyan(p2.jobId)} ${p2.status}${exit ? " " + exit : ""}${stdin} ${p2.command}`);
|
|
2436
3456
|
}
|
|
2437
3457
|
function printSnapshot(s) {
|
|
2438
|
-
const state = s.deletedAt !== null ? ` ${
|
|
2439
|
-
console.log(`${
|
|
3458
|
+
const state = s.deletedAt !== null ? ` ${pc10.dim(`(deleted ${s.deletedAt})`)}` : "";
|
|
3459
|
+
console.log(`${pc10.cyan(s.id)} ${s.providerSnapshotId}${state}`);
|
|
2440
3460
|
console.log(
|
|
2441
3461
|
` provider: ${s.provider}${s.region ? ` (${s.region})` : ""} label: ${s.label ?? "\u2014"} created: ${s.createdAt}${s.expiresAt ? ` expires: ${s.expiresAt}` : ""}`
|
|
2442
3462
|
);
|
|
@@ -2539,7 +3559,7 @@ function resolveSandbox(argId, opts) {
|
|
|
2539
3559
|
if (!r) throw new Error(NO_INSTANCE_HINT);
|
|
2540
3560
|
if (r.source !== "argument" && !opts.json && !opts.quiet) {
|
|
2541
3561
|
console.error(
|
|
2542
|
-
|
|
3562
|
+
pc10.dim(
|
|
2543
3563
|
`instance ${shortId(r.id)} (${r.source === "env" ? "COMPUTE_INSTANCE" : `current for ${r.dir}`})`
|
|
2544
3564
|
)
|
|
2545
3565
|
);
|
|
@@ -2550,7 +3570,7 @@ function resolveSandbox(argId, opts) {
|
|
|
2550
3570
|
clearStale: (error) => {
|
|
2551
3571
|
if (r.source === "file" && error instanceof PlatformApiError && error.status === 404 && readFileCurrent(org2) === r.id) {
|
|
2552
3572
|
clearCurrentInstance(org2);
|
|
2553
|
-
console.error(
|
|
3573
|
+
console.error(pc10.dim(`cleared stale current instance ${shortId(r.id)}`));
|
|
2554
3574
|
}
|
|
2555
3575
|
}
|
|
2556
3576
|
};
|
|
@@ -2604,6 +3624,24 @@ function fmtTimeout(ms) {
|
|
|
2604
3624
|
return `${ms}ms`;
|
|
2605
3625
|
}
|
|
2606
3626
|
var PLATFORM_DEFAULT_TIMEOUT_MS = 30 * 6e4;
|
|
3627
|
+
var LIST_SORTS = ["created", "name", "cost", "runtime"];
|
|
3628
|
+
function listQuery(opts) {
|
|
3629
|
+
if (opts.sort !== void 0 && !LIST_SORTS.includes(opts.sort)) {
|
|
3630
|
+
throw new Error(`--sort must be one of ${LIST_SORTS.join(", ")}`);
|
|
3631
|
+
}
|
|
3632
|
+
if (opts.direction !== void 0 && opts.direction !== "asc" && opts.direction !== "desc") {
|
|
3633
|
+
throw new Error("--direction must be asc or desc");
|
|
3634
|
+
}
|
|
3635
|
+
return {
|
|
3636
|
+
status: opts.status,
|
|
3637
|
+
customerOnly: opts.customerOnly ? "true" : void 0,
|
|
3638
|
+
q: opts.search,
|
|
3639
|
+
sort: opts.sort,
|
|
3640
|
+
direction: opts.direction,
|
|
3641
|
+
limit: opts.limit,
|
|
3642
|
+
cursor: opts.cursor
|
|
3643
|
+
};
|
|
3644
|
+
}
|
|
2607
3645
|
function registerSandboxesCommands(program2) {
|
|
2608
3646
|
const cmd = program2.command("instances").alias("sandboxes").alias("sbx").description("Create and drive compute instances through the platform").enablePositionalOptions().configureOutput({ outputError: usageErrorOutput });
|
|
2609
3647
|
addCreateFlags(
|
|
@@ -2616,7 +3654,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2616
3654
|
if (opts.use !== false) {
|
|
2617
3655
|
setCurrentInstance(res.sandbox.id, orgKey(opts));
|
|
2618
3656
|
if (!opts.json && !opts.quiet) {
|
|
2619
|
-
console.error(
|
|
3657
|
+
console.error(pc10.dim(`instance ${shortId(res.sandbox.id)} (current for ${dirKey()})`));
|
|
2620
3658
|
}
|
|
2621
3659
|
}
|
|
2622
3660
|
emitResult(opts, res.sandbox, (s) => s.id, (s) => printSandbox(s, opts.verbose));
|
|
@@ -2653,13 +3691,13 @@ function registerSandboxesCommands(program2) {
|
|
|
2653
3691
|
fail(e, opts);
|
|
2654
3692
|
}
|
|
2655
3693
|
});
|
|
2656
|
-
cmd.command("list").description("List sandboxes").option("--status <status>", "creating | running | destroyed").option("--limit <n>", "page size").option("--cursor <cursor>", "page cursor from a previous response").option("-q, --quiet", "print only instance IDs, one per line").option("--verbose", "print the full instance details").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (opts) => {
|
|
3694
|
+
cmd.command("list").description("List sandboxes").option("--status <status>", "active (not destroyed) | creating | running | destroyed").option("--customer-only", "exclude idle platform sandboxes (warm pool, CI sync, snapshot builds); Actions job sandboxes stay").option("--search <text>", "match label, id, provider, provider sandbox id or product (Sandboxes, Actions)").option("--sort <column>", "created (default, newest first) | name | cost | runtime").option("--direction <dir>", "asc | desc (default: asc for name, desc for the others)").option("--limit <n>", "page size").option("--cursor <cursor>", "page cursor from a previous response (pass the same --sort and --direction)").option("-q, --quiet", "print only instance IDs, one per line").option("--verbose", "print the full instance details").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (opts) => {
|
|
2657
3695
|
try {
|
|
2658
3696
|
checkQuietJson(opts);
|
|
2659
3697
|
const c = await client(opts);
|
|
2660
3698
|
const res = await c.get(
|
|
2661
3699
|
"/api/v1/sandboxes",
|
|
2662
|
-
|
|
3700
|
+
listQuery(opts)
|
|
2663
3701
|
);
|
|
2664
3702
|
emitResult(
|
|
2665
3703
|
opts,
|
|
@@ -2667,7 +3705,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2667
3705
|
(page) => page.sandboxes.map((s) => s.id).join("\n"),
|
|
2668
3706
|
(page) => {
|
|
2669
3707
|
page.sandboxes.forEach((s) => printSandbox(s, opts.verbose));
|
|
2670
|
-
if (page.nextCursor) console.log(
|
|
3708
|
+
if (page.nextCursor) console.log(pc10.dim(`nextCursor: ${page.nextCursor}`));
|
|
2671
3709
|
}
|
|
2672
3710
|
);
|
|
2673
3711
|
} catch (e) {
|
|
@@ -2740,7 +3778,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2740
3778
|
if (readFileCurrent(org2) === resolved.id) {
|
|
2741
3779
|
clearCurrentInstance(org2);
|
|
2742
3780
|
if (!opts.json) {
|
|
2743
|
-
console.error(
|
|
3781
|
+
console.error(pc10.dim(`cleared current instance ${shortId(resolved.id)}`));
|
|
2744
3782
|
}
|
|
2745
3783
|
}
|
|
2746
3784
|
output(opts, res.sandbox, printSandbox);
|
|
@@ -2759,9 +3797,9 @@ function registerSandboxesCommands(program2) {
|
|
|
2759
3797
|
if (opts.keep && opts.detach) throw new Error("--keep and --detach are mutually exclusive.");
|
|
2760
3798
|
const lead = takeLeadingOptions(rawCommand, EXEC_LEAD_OPTS);
|
|
2761
3799
|
opts = mergeLeadOpts(rawOpts, lead.inline);
|
|
2762
|
-
const
|
|
2763
|
-
if (
|
|
2764
|
-
await runInstanceCommand(
|
|
3800
|
+
const command2 = lead.command;
|
|
3801
|
+
if (command2.length === 0) throw new Error("missing command to run");
|
|
3802
|
+
await runInstanceCommand(command2, opts);
|
|
2765
3803
|
} catch (e) {
|
|
2766
3804
|
fail(e, opts);
|
|
2767
3805
|
}
|
|
@@ -2776,15 +3814,15 @@ function registerSandboxesCommands(program2) {
|
|
|
2776
3814
|
}
|
|
2777
3815
|
const lead = takeLeadingOptions(rawCommand, SERVE_LEAD_OPTS);
|
|
2778
3816
|
opts = mergeLeadOpts(rawOpts, lead.inline);
|
|
2779
|
-
const
|
|
2780
|
-
if (
|
|
3817
|
+
const command2 = lead.command;
|
|
3818
|
+
if (command2.length === 0) throw new Error("missing command to serve");
|
|
2781
3819
|
if (opts.port === void 0) throw new Error("--port is required");
|
|
2782
3820
|
const port = Number(opts.port);
|
|
2783
3821
|
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
2784
3822
|
throw new Error("--port must be an integer between 1 and 65535");
|
|
2785
3823
|
}
|
|
2786
3824
|
const resolved = resolveSandbox(argId, opts);
|
|
2787
|
-
await serveInstanceCommand(resolved.id,
|
|
3825
|
+
await serveInstanceCommand(resolved.id, command2, port, opts);
|
|
2788
3826
|
} catch (e) {
|
|
2789
3827
|
fail(e, opts);
|
|
2790
3828
|
}
|
|
@@ -2798,14 +3836,14 @@ function registerSandboxesCommands(program2) {
|
|
|
2798
3836
|
}
|
|
2799
3837
|
const lead = takeLeadingOptions(rawCommand, EXEC_LEAD_OPTS);
|
|
2800
3838
|
opts = mergeLeadOpts(rawOpts, lead.inline);
|
|
2801
|
-
const
|
|
2802
|
-
if (
|
|
3839
|
+
const command2 = lead.command;
|
|
3840
|
+
if (command2.length === 0) throw new Error("missing command to run");
|
|
2803
3841
|
const resolved = resolveSandbox(argId, opts);
|
|
2804
3842
|
const c = await client(opts);
|
|
2805
3843
|
const res = await c.post(
|
|
2806
3844
|
`/api/v1/sandboxes/${resolved.id}/commands`,
|
|
2807
3845
|
{
|
|
2808
|
-
command:
|
|
3846
|
+
command: command2.map(shellQuote).join(" "),
|
|
2809
3847
|
...opts.cwd ? { cwd: opts.cwd } : {},
|
|
2810
3848
|
...opts.env && opts.env.length > 0 ? { env: parseInputs(opts.env) } : {},
|
|
2811
3849
|
...opts.timeoutMs ? { timeoutMs: Number(opts.timeoutMs) } : {}
|
|
@@ -2834,14 +3872,14 @@ function registerSandboxesCommands(program2) {
|
|
|
2834
3872
|
const lead = takeLeadingOptions(rawCommand, SPAWN_LEAD_OPTS);
|
|
2835
3873
|
opts = mergeLeadOpts(rawOpts, lead.inline);
|
|
2836
3874
|
checkQuietJson(opts);
|
|
2837
|
-
const
|
|
2838
|
-
if (
|
|
3875
|
+
const command2 = lead.command;
|
|
3876
|
+
if (command2.length === 0) throw new Error("missing command to spawn");
|
|
2839
3877
|
const resolved = resolveSandbox(argId, opts);
|
|
2840
3878
|
const c = await client(opts);
|
|
2841
3879
|
const res = await c.post(
|
|
2842
3880
|
`/api/v1/sandboxes/${resolved.id}/processes`,
|
|
2843
3881
|
{
|
|
2844
|
-
command:
|
|
3882
|
+
command: command2.map(shellQuote).join(" "),
|
|
2845
3883
|
...opts.cwd ? { cwd: opts.cwd } : {},
|
|
2846
3884
|
...opts.env && opts.env.length > 0 ? { env: parseInputs(opts.env) } : {},
|
|
2847
3885
|
...opts.stdin ? { stdin: true } : {}
|
|
@@ -2933,7 +3971,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2933
3971
|
data = opts.base64 ? piped.toString("base64") : piped.toString("utf8");
|
|
2934
3972
|
}
|
|
2935
3973
|
if (data === void 0 || data === "") {
|
|
2936
|
-
console.error(
|
|
3974
|
+
console.error(pc10.red("Pass --data, --file, or pipe stdin"));
|
|
2937
3975
|
process.exit(1);
|
|
2938
3976
|
}
|
|
2939
3977
|
if (opts.base64 && opts.data !== void 0) {
|
|
@@ -2981,7 +4019,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2981
4019
|
output(opts, res, (view) => {
|
|
2982
4020
|
if (view.type === "directory") {
|
|
2983
4021
|
for (const e of view.entries) {
|
|
2984
|
-
console.log(`${e.type === "directory" ?
|
|
4022
|
+
console.log(`${e.type === "directory" ? pc10.blue("d") : " "} ${e.name}${e.size !== void 0 ? ` ${pc10.dim(String(e.size))}` : ""}`);
|
|
2985
4023
|
}
|
|
2986
4024
|
} else {
|
|
2987
4025
|
console.log(`${view.path} file ${view.content.length} chars`);
|
|
@@ -3008,7 +4046,7 @@ function registerSandboxesCommands(program2) {
|
|
|
3008
4046
|
const res = await c.get(`/api/v1/sandboxes/${resolved.id}/files`, { path: p2 });
|
|
3009
4047
|
output(opts, res, (view) => {
|
|
3010
4048
|
if (view.type !== "file") {
|
|
3011
|
-
console.error(
|
|
4049
|
+
console.error(pc10.red(`${view.path} is a directory`));
|
|
3012
4050
|
process.exit(1);
|
|
3013
4051
|
}
|
|
3014
4052
|
process.stdout.write(view.content);
|
|
@@ -3045,7 +4083,7 @@ function registerSandboxesCommands(program2) {
|
|
|
3045
4083
|
});
|
|
3046
4084
|
}
|
|
3047
4085
|
if (content === void 0) {
|
|
3048
|
-
console.error(
|
|
4086
|
+
console.error(pc10.red("Pass --content, --file, or pipe stdin"));
|
|
3049
4087
|
process.exit(1);
|
|
3050
4088
|
}
|
|
3051
4089
|
const c = await client(opts);
|
|
@@ -3165,12 +4203,9 @@ function registerSandboxesCommands(program2) {
|
|
|
3165
4203
|
for (const sub of cmd.commands) {
|
|
3166
4204
|
sub.option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)");
|
|
3167
4205
|
}
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
(sub) => sub.option("--api-key <key>", "platform API key (or COMPUTE_API_KEY)").option("--base-url <url>", "platform base URL").option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)").option("--allow-untrusted-host", "allow non-computesdk.com base URLs").option("--json", "print the raw response"),
|
|
3172
|
-
{ client, fail, output, usageErrorOutput }
|
|
3173
|
-
);
|
|
4206
|
+
const nestedCommon = (sub) => sub.option("--api-key <key>", "platform API key (or COMPUTE_API_KEY)").option("--base-url <url>", "platform base URL").option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)").option("--allow-untrusted-host", "allow non-computesdk.com base URLs").option("--json", "print the raw response");
|
|
4207
|
+
registerSettingsCommands(cmd, "sandboxes", nestedCommon, { client, fail, output, usageErrorOutput });
|
|
4208
|
+
registerBillingCommands(cmd, nestedCommon, { client, fail, output });
|
|
3174
4209
|
}
|
|
3175
4210
|
async function followProcess(c, sandboxId, jobId) {
|
|
3176
4211
|
let exitCode = 0;
|
|
@@ -3184,11 +4219,11 @@ async function followProcess(c, sandboxId, jobId) {
|
|
|
3184
4219
|
exitCode = typeof payload.exitCode === "number" ? payload.exitCode : 128;
|
|
3185
4220
|
return finish();
|
|
3186
4221
|
} else if (event === "error") {
|
|
3187
|
-
console.error(
|
|
4222
|
+
console.error(pc10.red(`Error: ${String(payload.error ?? "stream error")}`));
|
|
3188
4223
|
return finish(1);
|
|
3189
4224
|
}
|
|
3190
4225
|
}
|
|
3191
|
-
console.error(
|
|
4226
|
+
console.error(pc10.yellow("stream ended before the process exited"));
|
|
3192
4227
|
return finish(2);
|
|
3193
4228
|
function finish(code) {
|
|
3194
4229
|
if (code !== void 0) exitCode = code;
|
|
@@ -3204,15 +4239,15 @@ function printDetachSummary(sandboxId, jobId, timeoutText) {
|
|
|
3204
4239
|
function runTimeoutText(opts) {
|
|
3205
4240
|
return opts.timeoutMs ? `instance timeout: ${fmtTimeout(Number(opts.timeoutMs))}` : `instance timeout: ${fmtTimeout(PLATFORM_DEFAULT_TIMEOUT_MS)} (platform default)`;
|
|
3206
4241
|
}
|
|
3207
|
-
async function runInstanceCommand(
|
|
4242
|
+
async function runInstanceCommand(command2, opts) {
|
|
3208
4243
|
const c = await client(opts);
|
|
3209
4244
|
const created = await c.post("/api/v1/sandboxes", buildCreateBody(opts));
|
|
3210
4245
|
const sandbox = created.sandbox;
|
|
3211
4246
|
const org2 = orgKey(opts);
|
|
3212
|
-
console.error(
|
|
4247
|
+
console.error(pc10.dim(`instance ${sandbox.id}`));
|
|
3213
4248
|
const spawned = await c.post(
|
|
3214
4249
|
`/api/v1/sandboxes/${sandbox.id}/processes`,
|
|
3215
|
-
{ command:
|
|
4250
|
+
{ command: command2.map(shellQuote).join(" ") }
|
|
3216
4251
|
).catch(async (e) => {
|
|
3217
4252
|
try {
|
|
3218
4253
|
await c.del(`/api/v1/sandboxes/${sandbox.id}`);
|
|
@@ -3287,7 +4322,7 @@ async function runInstanceCommand(command, opts) {
|
|
|
3287
4322
|
setCurrentInstance(sandbox.id, org2);
|
|
3288
4323
|
if (opts.quiet) console.log(sandbox.id);
|
|
3289
4324
|
else {
|
|
3290
|
-
console.error(
|
|
4325
|
+
console.error(pc10.dim(`kept instance ${shortId(sandbox.id)} (current for ${dirKey()})`));
|
|
3291
4326
|
console.log(sandbox.id);
|
|
3292
4327
|
}
|
|
3293
4328
|
} else {
|
|
@@ -3295,7 +4330,7 @@ async function runInstanceCommand(command, opts) {
|
|
|
3295
4330
|
await c.del(`/api/v1/sandboxes/${sandbox.id}`);
|
|
3296
4331
|
} catch (e) {
|
|
3297
4332
|
console.error(
|
|
3298
|
-
|
|
4333
|
+
pc10.red(`destroy failed for ${sandbox.id}: ${e instanceof Error ? e.message : String(e)}`)
|
|
3299
4334
|
);
|
|
3300
4335
|
if (exitCode === null || exitCode === 0) exitCode = 1;
|
|
3301
4336
|
}
|
|
@@ -3307,12 +4342,12 @@ async function runInstanceCommand(command, opts) {
|
|
|
3307
4342
|
}
|
|
3308
4343
|
var SERVE_POLL_MS = 3e4;
|
|
3309
4344
|
var SERVE_DEFAULT_WAIT_MS = 12e4;
|
|
3310
|
-
async function serveInstanceCommand(id,
|
|
4345
|
+
async function serveInstanceCommand(id, command2, port, opts) {
|
|
3311
4346
|
const c = await client(opts);
|
|
3312
4347
|
const spawned = await c.post(
|
|
3313
4348
|
`/api/v1/sandboxes/${id}/processes`,
|
|
3314
4349
|
{
|
|
3315
|
-
command:
|
|
4350
|
+
command: command2.map(shellQuote).join(" "),
|
|
3316
4351
|
...opts.cwd ? { cwd: opts.cwd } : {},
|
|
3317
4352
|
...opts.env?.length ? { env: parseInputs(opts.env) } : {}
|
|
3318
4353
|
}
|
|
@@ -3323,7 +4358,7 @@ async function serveInstanceCommand(id, command, port, opts) {
|
|
|
3323
4358
|
if (!opts.json) {
|
|
3324
4359
|
const logs = `${proc.stdout}${proc.stderr}`.trimEnd().split("\n");
|
|
3325
4360
|
if (logs.length > 0 && logs[0] !== "") {
|
|
3326
|
-
console.error(
|
|
4361
|
+
console.error(pc10.dim("--- last log lines ---"));
|
|
3327
4362
|
for (const line of logs.slice(-50)) console.error(safeTerm(line));
|
|
3328
4363
|
}
|
|
3329
4364
|
}
|
|
@@ -3378,9 +4413,9 @@ async function serveInstanceCommand(id, command, port, opts) {
|
|
|
3378
4413
|
});
|
|
3379
4414
|
}
|
|
3380
4415
|
function printServeJobFooter(sandboxId, jobId) {
|
|
3381
|
-
console.error(
|
|
3382
|
-
console.error(
|
|
3383
|
-
console.error(
|
|
4416
|
+
console.error(pc10.dim(` job ${jobId}`));
|
|
4417
|
+
console.error(pc10.dim(` logs: compute instances logs ${sandboxId} ${jobId}`));
|
|
4418
|
+
console.error(pc10.dim(` kill: compute instances kill ${sandboxId} ${jobId}`));
|
|
3384
4419
|
}
|
|
3385
4420
|
var CP_PROGRESS_MIN_BYTES = 10 * 1024 * 1024;
|
|
3386
4421
|
function assertTransferUrl(raw) {
|
|
@@ -3538,8 +4573,8 @@ function formatBytes(n) {
|
|
|
3538
4573
|
}
|
|
3539
4574
|
|
|
3540
4575
|
// src/agents.ts
|
|
3541
|
-
import
|
|
3542
|
-
import { readFileSync as
|
|
4576
|
+
import pc11 from "picocolors";
|
|
4577
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
3543
4578
|
function formatLocalTime2(iso) {
|
|
3544
4579
|
if (iso === null) return "\u2014";
|
|
3545
4580
|
const d = new Date(iso);
|
|
@@ -3549,7 +4584,7 @@ function formatLocalTime2(iso) {
|
|
|
3549
4584
|
}
|
|
3550
4585
|
function printAgent(a) {
|
|
3551
4586
|
console.log(
|
|
3552
|
-
`${
|
|
4587
|
+
`${pc11.cyan(safeTerm(a.name))} ${a.id.slice(0, 8)} ${a.harness}${a.model ? ` ${safeTerm(a.model)}` : ""} sessions: ${a.sessionCount} created: ${formatLocalTime2(a.createdAt)}`
|
|
3553
4588
|
);
|
|
3554
4589
|
}
|
|
3555
4590
|
function printAgentDetail(a) {
|
|
@@ -3560,13 +4595,13 @@ function printAgentDetail(a) {
|
|
|
3560
4595
|
}
|
|
3561
4596
|
function printSession(s) {
|
|
3562
4597
|
console.log(
|
|
3563
|
-
`${
|
|
4598
|
+
`${pc11.cyan(s.id)} ${s.status} sandbox: ${s.sandboxId ?? "\u2014"} ${formatLocalTime2(s.createdAt)}${s.error ? ` ${pc11.red(safeTerm(s.error))}` : ""}`
|
|
3564
4599
|
);
|
|
3565
4600
|
}
|
|
3566
4601
|
function printEvent(e) {
|
|
3567
4602
|
const payload = e.payload ?? {};
|
|
3568
4603
|
if (e.kind === "user") {
|
|
3569
|
-
console.log(`${
|
|
4604
|
+
console.log(`${pc11.green("you")} #${e.seq} ${safeTerm(String(payload.message ?? ""))}`);
|
|
3570
4605
|
return;
|
|
3571
4606
|
}
|
|
3572
4607
|
if (e.kind === "turn") {
|
|
@@ -3574,12 +4609,12 @@ function printEvent(e) {
|
|
|
3574
4609
|
for (const ev of events) {
|
|
3575
4610
|
const o = ev;
|
|
3576
4611
|
const text = o.text ?? o.message ?? o.content;
|
|
3577
|
-
if (typeof text === "string") console.log(
|
|
3578
|
-
else console.log(
|
|
4612
|
+
if (typeof text === "string") console.log(pc11.dim(`#${e.seq}`) + ` ${safeTerm(text)}`);
|
|
4613
|
+
else console.log(pc11.dim(`#${e.seq} ${safeTerm(JSON.stringify(o))}`));
|
|
3579
4614
|
}
|
|
3580
4615
|
return;
|
|
3581
4616
|
}
|
|
3582
|
-
console.log(
|
|
4617
|
+
console.log(pc11.dim(`#${e.seq} ${e.kind} ${safeTerm(JSON.stringify(payload))}`));
|
|
3583
4618
|
}
|
|
3584
4619
|
function authOpts(cmd) {
|
|
3585
4620
|
return cmd.option("--api-key <key>", "platform API key (or COMPUTE_API_KEY)").option("--base-url <url>", "platform base URL").option("--allow-untrusted-host", "allow non-computesdk.com base URLs").option("--org <slug>", "organization slug (or COMPUTE_ORG)").option("--json", "print the raw response");
|
|
@@ -3615,7 +4650,7 @@ function registerAgentsCommands(program2) {
|
|
|
3615
4650
|
).action(
|
|
3616
4651
|
async (name, opts) => {
|
|
3617
4652
|
try {
|
|
3618
|
-
const prompt = opts.prompt ?? (opts.promptFile ?
|
|
4653
|
+
const prompt = opts.prompt ?? (opts.promptFile ? readFileSync4(opts.promptFile, "utf8") : void 0);
|
|
3619
4654
|
if (!prompt?.trim()) fail(new Error("--prompt or --prompt-file is required"), opts);
|
|
3620
4655
|
const volume = opts.volumeDisk !== void 0 || opts.volumePath !== void 0 ? { diskId: opts.volumeDisk, path: opts.volumePath } : void 0;
|
|
3621
4656
|
const c = await client(opts);
|
|
@@ -3630,7 +4665,7 @@ function registerAgentsCommands(program2) {
|
|
|
3630
4665
|
});
|
|
3631
4666
|
output(opts, res, (r) => {
|
|
3632
4667
|
printAgentDetail(r.agent);
|
|
3633
|
-
console.error(
|
|
4668
|
+
console.error(pc11.dim(`agent ${r.agent.name} created \u2014 run it with \`compute agents run ${r.agent.name} "\u2026"\``));
|
|
3634
4669
|
});
|
|
3635
4670
|
} catch (e) {
|
|
3636
4671
|
fail(e, opts);
|
|
@@ -3653,7 +4688,7 @@ function registerAgentsCommands(program2) {
|
|
|
3653
4688
|
).action(
|
|
3654
4689
|
async (ref, opts) => {
|
|
3655
4690
|
try {
|
|
3656
|
-
const prompt = opts.prompt ?? (opts.promptFile ?
|
|
4691
|
+
const prompt = opts.prompt ?? (opts.promptFile ? readFileSync4(opts.promptFile, "utf8") : void 0);
|
|
3657
4692
|
const body = {
|
|
3658
4693
|
name: opts.name,
|
|
3659
4694
|
prompt,
|
|
@@ -3684,7 +4719,7 @@ function registerAgentsCommands(program2) {
|
|
|
3684
4719
|
const c = await client(opts);
|
|
3685
4720
|
if (!opts.yes) {
|
|
3686
4721
|
const res = await c.get(`/api/v1/agents/${encodeURIComponent(ref)}`);
|
|
3687
|
-
console.error(`Deleting agent ${
|
|
4722
|
+
console.error(`Deleting agent ${pc11.cyan(res.agent.name)} (${res.agent.id}). Pass -y to confirm.`);
|
|
3688
4723
|
process.exit(1);
|
|
3689
4724
|
}
|
|
3690
4725
|
await c.del(`/api/v1/agents/${encodeURIComponent(ref)}`);
|
|
@@ -3721,7 +4756,7 @@ function registerAgentsCommands(program2) {
|
|
|
3721
4756
|
output(opts, res, (r) => {
|
|
3722
4757
|
printSession(r.session);
|
|
3723
4758
|
for (const e of r.events) printEvent(e);
|
|
3724
|
-
console.error(
|
|
4759
|
+
console.error(pc11.dim(`session ${r.session.id} \u2014 continue with \`compute agents send ${r.session.id} "\u2026"\``));
|
|
3725
4760
|
});
|
|
3726
4761
|
} catch (e) {
|
|
3727
4762
|
fail(e, opts);
|
|
@@ -3807,11 +4842,625 @@ function registerAgentsCommands(program2) {
|
|
|
3807
4842
|
});
|
|
3808
4843
|
}
|
|
3809
4844
|
|
|
4845
|
+
// src/bench.ts
|
|
4846
|
+
import { DEFAULT_BASE_URL as DEFAULT_BASE_URL3 } from "@computesdk/platform";
|
|
4847
|
+
|
|
4848
|
+
// src/net.ts
|
|
4849
|
+
function isFetchFailure(error) {
|
|
4850
|
+
return error instanceof TypeError && /fetch failed/i.test(error.message);
|
|
4851
|
+
}
|
|
4852
|
+
function describeFetchFailure(error, url) {
|
|
4853
|
+
let target = url;
|
|
4854
|
+
try {
|
|
4855
|
+
const parsed = new URL(url);
|
|
4856
|
+
target = `${parsed.origin}${parsed.pathname}`;
|
|
4857
|
+
} catch {
|
|
4858
|
+
}
|
|
4859
|
+
const cause = error.cause;
|
|
4860
|
+
const described = new TypeError(`fetch failed (${target})${cause instanceof Error ? `: ${cause.message}` : ""}`);
|
|
4861
|
+
described.cause = cause;
|
|
4862
|
+
return described;
|
|
4863
|
+
}
|
|
4864
|
+
function requestUrl(input) {
|
|
4865
|
+
if (typeof input === "string") return input;
|
|
4866
|
+
if (input instanceof URL) return input.href;
|
|
4867
|
+
return input.url;
|
|
4868
|
+
}
|
|
4869
|
+
function withFetchFailureContext(fetchImpl) {
|
|
4870
|
+
return async (input, init) => {
|
|
4871
|
+
try {
|
|
4872
|
+
return await fetchImpl(input, init);
|
|
4873
|
+
} catch (error) {
|
|
4874
|
+
if (isFetchFailure(error)) throw describeFetchFailure(error, requestUrl(input));
|
|
4875
|
+
throw error;
|
|
4876
|
+
}
|
|
4877
|
+
};
|
|
4878
|
+
}
|
|
4879
|
+
|
|
4880
|
+
// src/session.ts
|
|
4881
|
+
import { DEFAULT_BASE_URL as DEFAULT_BASE_URL2, isSecurePlatformTransport as isSecurePlatformTransport2, isTrustedPlatformHost as isTrustedPlatformHost2 } from "@computesdk/platform";
|
|
4882
|
+
function envBaseUrl(env = process.env) {
|
|
4883
|
+
return env.COMPUTE_PLATFORM_URL || env.BENCHMARKS_PLATFORM_URL || void 0;
|
|
4884
|
+
}
|
|
4885
|
+
function assertComputeKeyDestination(baseUrl) {
|
|
4886
|
+
const url = baseUrl.replace(/\/+$/, "");
|
|
4887
|
+
if (!isTrustedPlatformHost2(url)) {
|
|
4888
|
+
throw new Error(
|
|
4889
|
+
`Refusing to send COMPUTE_API_KEY to ${url}: it is not a computesdk.com or localhost host. To use a key with a host you trust, set BENCHMARKS_PLATFORM_API_KEY for it instead.`
|
|
4890
|
+
);
|
|
4891
|
+
}
|
|
4892
|
+
if (!isSecurePlatformTransport2(url)) {
|
|
4893
|
+
throw new Error(`Refusing to send COMPUTE_API_KEY over plaintext HTTP to ${url}; use https://.`);
|
|
4894
|
+
}
|
|
4895
|
+
}
|
|
4896
|
+
function benchAuthOverrides(opts = {}, env = process.env) {
|
|
4897
|
+
const baseUrl = opts.baseUrl ?? envBaseUrl(env);
|
|
4898
|
+
const apiKey = env.COMPUTE_API_KEY || void 0;
|
|
4899
|
+
if (apiKey) assertComputeKeyDestination(baseUrl ?? DEFAULT_BASE_URL2);
|
|
4900
|
+
return { baseUrl, apiKey };
|
|
4901
|
+
}
|
|
4902
|
+
async function benchAuth(opts = {}) {
|
|
4903
|
+
const { resolveAuth } = await import("@benchsdk/cli");
|
|
4904
|
+
return resolveAuth(benchAuthOverrides(opts));
|
|
4905
|
+
}
|
|
4906
|
+
function errorReason(body) {
|
|
4907
|
+
if (typeof body !== "string" || body === "") return void 0;
|
|
4908
|
+
try {
|
|
4909
|
+
const parsed = JSON.parse(body);
|
|
4910
|
+
const reason = parsed.message ?? parsed.error;
|
|
4911
|
+
return typeof reason === "string" ? reason : void 0;
|
|
4912
|
+
} catch {
|
|
4913
|
+
return body.slice(0, 200);
|
|
4914
|
+
}
|
|
4915
|
+
}
|
|
4916
|
+
function httpStatus(error) {
|
|
4917
|
+
const status = error?.status;
|
|
4918
|
+
return typeof status === "number" ? status : void 0;
|
|
4919
|
+
}
|
|
4920
|
+
async function apiKeyOrganization(auth, apiKey) {
|
|
4921
|
+
const url = `${auth.apiBaseUrl}/actions/org`;
|
|
4922
|
+
let response;
|
|
4923
|
+
try {
|
|
4924
|
+
response = await fetch(url, { headers: { Authorization: `Bearer ${apiKey}` } });
|
|
4925
|
+
} catch (error) {
|
|
4926
|
+
throw isFetchFailure(error) ? describeFetchFailure(error, url) : error;
|
|
4927
|
+
}
|
|
4928
|
+
const text = await response.text();
|
|
4929
|
+
if (!response.ok) {
|
|
4930
|
+
const reason = errorReason(text);
|
|
4931
|
+
throw new Error(
|
|
4932
|
+
`This API key has no user identity, and its organization could not be read (${response.status}${reason ? `: ${reason}` : ""}).`
|
|
4933
|
+
);
|
|
4934
|
+
}
|
|
4935
|
+
const org2 = JSON.parse(text);
|
|
4936
|
+
return { id: org2.organizationId, name: org2.name, slug: org2.slug };
|
|
4937
|
+
}
|
|
4938
|
+
async function fetchWhoami(auth) {
|
|
4939
|
+
const { getMe } = await import("@benchsdk/cli");
|
|
4940
|
+
try {
|
|
4941
|
+
return await getMe(auth);
|
|
4942
|
+
} catch (error) {
|
|
4943
|
+
if (isFetchFailure(error)) throw describeFetchFailure(error, `${auth.apiBaseUrl}/me`);
|
|
4944
|
+
if (httpStatus(error) !== 401) throw error;
|
|
4945
|
+
const reason = errorReason(error.body);
|
|
4946
|
+
if (auth.apiKey && !auth.token && reason === "User credential required") {
|
|
4947
|
+
const org2 = await apiKeyOrganization(auth, auth.apiKey);
|
|
4948
|
+
return { user: null, activeOrganizationId: org2.id, organizations: [org2], credential: "api_key" };
|
|
4949
|
+
}
|
|
4950
|
+
throw new Error(
|
|
4951
|
+
`Authentication failed (401 Unauthorized)${reason ? `: ${reason}` : ""}. Check COMPUTE_API_KEY / the stored login, or run \`compute login\`.`
|
|
4952
|
+
);
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4955
|
+
function formatWhoami(me) {
|
|
4956
|
+
const active = me.organizations.find((o) => o.id === me.activeOrganizationId);
|
|
4957
|
+
const who = me.user ? me.user.email ?? me.user.name ?? me.user.id : "API key (no user identity)";
|
|
4958
|
+
return [
|
|
4959
|
+
who,
|
|
4960
|
+
`active org: ${active ? `${active.slug} (${active.id})` : "\u2014"}${me.organizations.length > 1 ? " \u2014 change with `compute org use <slug>`" : ""}`
|
|
4961
|
+
];
|
|
4962
|
+
}
|
|
4963
|
+
|
|
4964
|
+
// src/bench.ts
|
|
4965
|
+
var BENCH_COMMANDS = /* @__PURE__ */ new Set(["bench", "benchmark"]);
|
|
4966
|
+
var RUNNER_VERBS = /* @__PURE__ */ new Set(["run", "check", "__manifest"]);
|
|
4967
|
+
function parseBenchDispatch(args) {
|
|
4968
|
+
let org2;
|
|
4969
|
+
let i = 0;
|
|
4970
|
+
while (i < args.length && !BENCH_COMMANDS.has(args[i])) {
|
|
4971
|
+
const arg = args[i];
|
|
4972
|
+
if (arg === "--org" && i + 1 < args.length) {
|
|
4973
|
+
org2 = args[i + 1];
|
|
4974
|
+
i += 2;
|
|
4975
|
+
} else if (arg.startsWith("--org=")) {
|
|
4976
|
+
org2 = arg.slice("--org=".length);
|
|
4977
|
+
i += 1;
|
|
4978
|
+
} else {
|
|
4979
|
+
return null;
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4982
|
+
if (i >= args.length) return null;
|
|
4983
|
+
const argv = args.slice(i + 1);
|
|
4984
|
+
return org2 ? { argv, org: org2 } : { argv };
|
|
4985
|
+
}
|
|
4986
|
+
function baseUrlFlag(argv) {
|
|
4987
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
4988
|
+
const arg = argv[i];
|
|
4989
|
+
if (arg === "--") return void 0;
|
|
4990
|
+
if (arg === "--base-url") return argv[i + 1];
|
|
4991
|
+
if (arg.startsWith("--base-url=")) return arg.slice("--base-url=".length);
|
|
4992
|
+
}
|
|
4993
|
+
return void 0;
|
|
4994
|
+
}
|
|
4995
|
+
function hasOrgFlag(argv) {
|
|
4996
|
+
for (const arg of argv) {
|
|
4997
|
+
if (arg === "--") return false;
|
|
4998
|
+
if (arg === "--org" || arg.startsWith("--org=")) return true;
|
|
4999
|
+
}
|
|
5000
|
+
return false;
|
|
5001
|
+
}
|
|
5002
|
+
function benchInvocation(argv, env, computeOrg) {
|
|
5003
|
+
const out = {};
|
|
5004
|
+
if (env.COMPUTE_PLATFORM_URL && !env.BENCHMARKS_PLATFORM_URL) {
|
|
5005
|
+
out.BENCHMARKS_PLATFORM_URL = env.COMPUTE_PLATFORM_URL;
|
|
5006
|
+
}
|
|
5007
|
+
if (env.COMPUTE_API_KEY && !env.BENCHMARKS_PLATFORM_API_KEY) {
|
|
5008
|
+
assertComputeKeyDestination(
|
|
5009
|
+
baseUrlFlag(argv) || env.BENCHMARKS_PLATFORM_URL || env.COMPUTE_PLATFORM_URL || DEFAULT_BASE_URL3
|
|
5010
|
+
);
|
|
5011
|
+
out.BENCHMARKS_PLATFORM_API_KEY = env.COMPUTE_API_KEY;
|
|
5012
|
+
}
|
|
5013
|
+
const org2 = computeOrg || env.COMPUTE_ORG;
|
|
5014
|
+
if (!org2 || RUNNER_VERBS.has(argv[0]) || hasOrgFlag(argv)) return { argv, env: out };
|
|
5015
|
+
return { argv: ["--org", org2, ...argv], env: out };
|
|
5016
|
+
}
|
|
5017
|
+
async function runBench(dispatch) {
|
|
5018
|
+
const inv = benchInvocation(dispatch.argv, process.env, dispatch.org);
|
|
5019
|
+
Object.assign(process.env, inv.env);
|
|
5020
|
+
globalThis.fetch = withFetchFailureContext(globalThis.fetch);
|
|
5021
|
+
const { run } = await import("@benchsdk/runner");
|
|
5022
|
+
await run(inv.argv);
|
|
5023
|
+
}
|
|
5024
|
+
|
|
5025
|
+
// src/manifest.ts
|
|
5026
|
+
import { createRequire } from "module";
|
|
5027
|
+
import { existsSync as existsSync2, readFileSync as readFileSync5, realpathSync } from "fs";
|
|
5028
|
+
import { dirname as dirname2, join as join4, sep } from "path";
|
|
5029
|
+
var MANIFEST_COMMAND = "__manifest";
|
|
5030
|
+
function resolvedPackage(name, fromDir) {
|
|
5031
|
+
const require2 = createRequire(join4(fromDir, "noop.js"));
|
|
5032
|
+
let dir = dirname2(require2.resolve(name));
|
|
5033
|
+
for (; ; ) {
|
|
5034
|
+
const file = join4(dir, "package.json");
|
|
5035
|
+
if (existsSync2(file)) {
|
|
5036
|
+
const pkg = JSON.parse(readFileSync5(file, "utf-8"));
|
|
5037
|
+
if (pkg.name === name) return { dir, version: pkg.version };
|
|
5038
|
+
}
|
|
5039
|
+
const parent = dirname2(dir);
|
|
5040
|
+
if (parent === dir) throw new Error(`package.json for ${name} not found from ${fromDir}`);
|
|
5041
|
+
dir = parent;
|
|
5042
|
+
}
|
|
5043
|
+
}
|
|
5044
|
+
function isLinkedPackage(realDir) {
|
|
5045
|
+
return !realDir.split(sep).includes("node_modules");
|
|
5046
|
+
}
|
|
5047
|
+
function packageVersion(name, resolved) {
|
|
5048
|
+
const entry = { package: name, version: resolved.version };
|
|
5049
|
+
if (isLinkedPackage(realpathSync(resolved.dir))) {
|
|
5050
|
+
entry.linked = true;
|
|
5051
|
+
entry.released = false;
|
|
5052
|
+
}
|
|
5053
|
+
return entry;
|
|
5054
|
+
}
|
|
5055
|
+
function bundledBench(fromDir) {
|
|
5056
|
+
const runner = resolvedPackage("@benchsdk/runner", fromDir);
|
|
5057
|
+
const cli = resolvedPackage("@benchsdk/cli", runner.dir);
|
|
5058
|
+
return {
|
|
5059
|
+
runner: packageVersion("@benchsdk/runner", runner),
|
|
5060
|
+
cli: packageVersion("@benchsdk/cli", cli)
|
|
5061
|
+
};
|
|
5062
|
+
}
|
|
5063
|
+
function isHidden(cmd) {
|
|
5064
|
+
return cmd._hidden === true;
|
|
5065
|
+
}
|
|
5066
|
+
function flagsOf(cmd) {
|
|
5067
|
+
const flags = cmd.createHelp().visibleOptions(cmd).map((o) => o.long ?? o.short).filter((f) => Boolean(f));
|
|
5068
|
+
return [...new Set(flags)];
|
|
5069
|
+
}
|
|
5070
|
+
function argsOf(cmd) {
|
|
5071
|
+
return cmd.registeredArguments.map((a) => {
|
|
5072
|
+
const name = `${a.name()}${a.variadic ? "..." : ""}`;
|
|
5073
|
+
return a.required ? `<${name}>` : `[${name}]`;
|
|
5074
|
+
});
|
|
5075
|
+
}
|
|
5076
|
+
function summaryOf(cmd) {
|
|
5077
|
+
return (cmd.summary() || cmd.description()).split("\n")[0].trim();
|
|
5078
|
+
}
|
|
5079
|
+
function aliasPaths(names) {
|
|
5080
|
+
let paths = [[]];
|
|
5081
|
+
for (const choices of names) paths = paths.flatMap((p2) => choices.map((c) => [...p2, c]));
|
|
5082
|
+
return paths.slice(1);
|
|
5083
|
+
}
|
|
5084
|
+
function walk(cmd, ancestors, skip, out) {
|
|
5085
|
+
for (const sub of cmd.commands) {
|
|
5086
|
+
if (isHidden(sub) || ancestors.length === 0 && skip.has(sub.name())) continue;
|
|
5087
|
+
const names = [...ancestors, [sub.name(), ...sub.aliases()]];
|
|
5088
|
+
out.push({
|
|
5089
|
+
path: names.map((n) => n[0]),
|
|
5090
|
+
aliases: aliasPaths(names),
|
|
5091
|
+
args: argsOf(sub),
|
|
5092
|
+
flags: flagsOf(sub),
|
|
5093
|
+
summary: summaryOf(sub)
|
|
5094
|
+
});
|
|
5095
|
+
walk(sub, names, skip, out);
|
|
5096
|
+
}
|
|
5097
|
+
}
|
|
5098
|
+
function buildCliManifest(program2, options) {
|
|
5099
|
+
const [benchName, ...benchAliases] = [...BENCH_COMMANDS];
|
|
5100
|
+
const commands = [];
|
|
5101
|
+
walk(program2, [], /* @__PURE__ */ new Set([benchName]), commands);
|
|
5102
|
+
return {
|
|
5103
|
+
schemaVersion: 1,
|
|
5104
|
+
bin: "compute",
|
|
5105
|
+
package: "@computesdk/cli",
|
|
5106
|
+
version: options.version,
|
|
5107
|
+
source: { repo: "computesdk/computesdk", released: options.released },
|
|
5108
|
+
globalFlags: flagsOf(program2),
|
|
5109
|
+
commands,
|
|
5110
|
+
passthrough: {
|
|
5111
|
+
bench: {
|
|
5112
|
+
path: [benchName],
|
|
5113
|
+
aliases: benchAliases.map((a) => [a]),
|
|
5114
|
+
...bundledBench(options.packageDir)
|
|
5115
|
+
}
|
|
5116
|
+
}
|
|
5117
|
+
};
|
|
5118
|
+
}
|
|
5119
|
+
function manifestJson(manifest) {
|
|
5120
|
+
return `${JSON.stringify(manifest, null, 2)}
|
|
5121
|
+
`;
|
|
5122
|
+
}
|
|
5123
|
+
function manifestMatches(fileContent, generated) {
|
|
5124
|
+
let committed;
|
|
5125
|
+
try {
|
|
5126
|
+
committed = JSON.parse(fileContent);
|
|
5127
|
+
} catch {
|
|
5128
|
+
return false;
|
|
5129
|
+
}
|
|
5130
|
+
if (committed.source) delete committed.source.ref;
|
|
5131
|
+
return JSON.stringify(committed) === JSON.stringify(generated);
|
|
5132
|
+
}
|
|
5133
|
+
function registerManifestCommand(program2, options) {
|
|
5134
|
+
program2.command(MANIFEST_COMMAND, { hidden: true }).description("Print the command tree as JSON (for the benchmarks platform surface map)").option("--released", "mark the manifest as describing a version published to npm").option("--check <file>", "exit 1 unless <file> equals the generated manifest (ignoring source.ref)").action((opts) => {
|
|
5135
|
+
const manifest = buildCliManifest(program2, {
|
|
5136
|
+
version: options.version,
|
|
5137
|
+
released: Boolean(opts.released),
|
|
5138
|
+
packageDir: options.packageDir
|
|
5139
|
+
});
|
|
5140
|
+
if (opts.check) {
|
|
5141
|
+
if (!manifestMatches(readFileSync5(opts.check, "utf-8"), manifest)) {
|
|
5142
|
+
console.error(
|
|
5143
|
+
`${opts.check} is out of date. Regenerate it with \`pnpm --filter @computesdk/cli run manifest\`.`
|
|
5144
|
+
);
|
|
5145
|
+
process.exit(1);
|
|
5146
|
+
}
|
|
5147
|
+
console.log(`${opts.check} matches the ${manifest.commands.length}-command manifest.`);
|
|
5148
|
+
return;
|
|
5149
|
+
}
|
|
5150
|
+
process.stdout.write(manifestJson(manifest));
|
|
5151
|
+
});
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
// src/org-members.ts
|
|
5155
|
+
import pc12 from "picocolors";
|
|
5156
|
+
var ORG_PATH = "/api/v1/organizations/current";
|
|
5157
|
+
var MEMBER_ROLES = ["member", "admin"];
|
|
5158
|
+
var USER_LOGIN_HINT = "This needs a user login, and org API keys have no user: run `compute login`, and drop --api-key / unset COMPUTE_API_KEY.";
|
|
5159
|
+
function isOrgApiKey(key) {
|
|
5160
|
+
return /^(bp|csdk)_/.test(key);
|
|
5161
|
+
}
|
|
5162
|
+
var segment = (id) => encodeURIComponent(id);
|
|
5163
|
+
function orgName(opts) {
|
|
5164
|
+
return opts.org || process.env.COMPUTE_ORG || void 0;
|
|
5165
|
+
}
|
|
5166
|
+
async function orgClient(opts) {
|
|
5167
|
+
return new ActionsClient(await resolveActionsAuth(opts));
|
|
5168
|
+
}
|
|
5169
|
+
async function userClient(opts, what) {
|
|
5170
|
+
const auth = await resolveActionsAuth(opts);
|
|
5171
|
+
if (isOrgApiKey(auth.apiKey)) {
|
|
5172
|
+
throw new PlatformClientError(
|
|
5173
|
+
"user_credential_required",
|
|
5174
|
+
`${what} needs a user login, and org API keys have no user. Run \`compute login\`, and drop --api-key / unset COMPUTE_API_KEY.`
|
|
5175
|
+
);
|
|
5176
|
+
}
|
|
5177
|
+
return new ActionsClient(auth);
|
|
5178
|
+
}
|
|
5179
|
+
function apiHint(error) {
|
|
5180
|
+
const body = error.body;
|
|
5181
|
+
if (body && typeof body === "object" && typeof body.hint === "string") {
|
|
5182
|
+
return body.hint;
|
|
5183
|
+
}
|
|
5184
|
+
return error.code === "user_credential_required" ? USER_LOGIN_HINT : void 0;
|
|
5185
|
+
}
|
|
5186
|
+
function fail2(error, opts = {}) {
|
|
5187
|
+
const hint = error instanceof PlatformApiError ? apiHint(error) : void 0;
|
|
5188
|
+
if (opts.json) {
|
|
5189
|
+
const envelope = toErrorEnvelope(error);
|
|
5190
|
+
if (hint) envelope.error.hint = hint;
|
|
5191
|
+
process.stderr.write(JSON.stringify(envelope) + "\n");
|
|
5192
|
+
} else if (error instanceof PlatformApiError) {
|
|
5193
|
+
const code = error.code !== codeForStatus(error.status) ? ` ${error.code}` : "";
|
|
5194
|
+
console.error(pc12.red(`Error (${error.status}${code}): ${error.message}`));
|
|
5195
|
+
if (hint) console.error(pc12.dim(`hint: ${hint}`));
|
|
5196
|
+
} else {
|
|
5197
|
+
console.error(pc12.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
5198
|
+
}
|
|
5199
|
+
process.exit(1);
|
|
5200
|
+
}
|
|
5201
|
+
function memberRole(role, ownerMessage) {
|
|
5202
|
+
if (role === "owner") throw new PlatformClientError("invalid_argument", ownerMessage);
|
|
5203
|
+
if (!MEMBER_ROLES.includes(role)) {
|
|
5204
|
+
throw new PlatformClientError("invalid_argument", `Invalid role "${role}" \u2014 use member or admin.`);
|
|
5205
|
+
}
|
|
5206
|
+
return role;
|
|
5207
|
+
}
|
|
5208
|
+
function printTable2(header, rows) {
|
|
5209
|
+
const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i].length)));
|
|
5210
|
+
const line = (cells) => cells.map((c, i) => c.padEnd(widths[i])).join(" ").trimEnd();
|
|
5211
|
+
console.log(line(header));
|
|
5212
|
+
for (const row of rows) console.log(line(row));
|
|
5213
|
+
}
|
|
5214
|
+
function printMembers(res) {
|
|
5215
|
+
if (res.members.length === 0) {
|
|
5216
|
+
console.log("No members.");
|
|
5217
|
+
return;
|
|
5218
|
+
}
|
|
5219
|
+
printTable2(
|
|
5220
|
+
["EMAIL", "ROLE", "NAME", "MEMBER ID", "JOINED"],
|
|
5221
|
+
res.members.map((m) => [safeTerm(m.email), safeTerm(m.role), safeTerm(m.name ?? "\u2014"), safeTerm(m.id), safeTerm(m.createdAt)])
|
|
5222
|
+
);
|
|
5223
|
+
}
|
|
5224
|
+
function printOrgInvitations(res) {
|
|
5225
|
+
if (res.invitations.length === 0) {
|
|
5226
|
+
console.log("No pending invitations.");
|
|
5227
|
+
return;
|
|
5228
|
+
}
|
|
5229
|
+
printTable2(
|
|
5230
|
+
["ID", "EMAIL", "ROLE", "EXPIRES", "LINK"],
|
|
5231
|
+
res.invitations.map((i) => [safeTerm(i.id), safeTerm(i.email), safeTerm(i.role), safeTerm(i.expiresAt), safeTerm(i.url)])
|
|
5232
|
+
);
|
|
5233
|
+
}
|
|
5234
|
+
function printUserInvitations(res) {
|
|
5235
|
+
if (res.invitations.length === 0) {
|
|
5236
|
+
console.log("No pending invitations.");
|
|
5237
|
+
return;
|
|
5238
|
+
}
|
|
5239
|
+
printTable2(
|
|
5240
|
+
["ID", "ORG", "ROLE", "EXPIRES", "ORG NAME"],
|
|
5241
|
+
res.invitations.map((i) => [
|
|
5242
|
+
safeTerm(i.id),
|
|
5243
|
+
safeTerm(i.organization.slug),
|
|
5244
|
+
safeTerm(i.role),
|
|
5245
|
+
safeTerm(i.expiresAt),
|
|
5246
|
+
safeTerm(i.organization.name)
|
|
5247
|
+
])
|
|
5248
|
+
);
|
|
5249
|
+
console.log(pc12.dim("Accept with `compute invitations accept <id>`; decline with `compute invitations decline <id> -y`."));
|
|
5250
|
+
}
|
|
5251
|
+
function printInvitationDetail(inv) {
|
|
5252
|
+
const rows = [
|
|
5253
|
+
["invitation", safeTerm(inv.id)],
|
|
5254
|
+
["org", `${safeTerm(inv.organization.slug)} (${safeTerm(inv.organization.name)})`],
|
|
5255
|
+
["email", safeTerm(inv.email)],
|
|
5256
|
+
["role", safeTerm(inv.role)],
|
|
5257
|
+
["status", safeTerm(inv.status)],
|
|
5258
|
+
["expires", safeTerm(inv.expiresAt)],
|
|
5259
|
+
["link", safeTerm(inv.url)]
|
|
5260
|
+
];
|
|
5261
|
+
for (const [k, v] of rows) console.log(`${k.padEnd(10)} ${v}`);
|
|
5262
|
+
}
|
|
5263
|
+
function printInvite(res) {
|
|
5264
|
+
const inv = res.invitation;
|
|
5265
|
+
console.log(`Invited ${safeTerm(inv.email)} as ${safeTerm(inv.role)} (invitation ${safeTerm(inv.id)}, expires ${safeTerm(inv.expiresAt)}).`);
|
|
5266
|
+
if (res.emailSent) {
|
|
5267
|
+
console.log(`Emailed ${safeTerm(inv.email)} the invitation link.`);
|
|
5268
|
+
} else {
|
|
5269
|
+
const reason = res.emailError ? ` (${safeTerm(res.emailError)})` : "";
|
|
5270
|
+
console.log(pc12.yellow(`The invitation email was not sent${reason}; share the link instead.`));
|
|
5271
|
+
}
|
|
5272
|
+
console.log(`Link: ${safeTerm(inv.url)}`);
|
|
5273
|
+
}
|
|
5274
|
+
function findMember(members, ref) {
|
|
5275
|
+
const lower = ref.toLowerCase();
|
|
5276
|
+
return members.find((m) => m.id === ref) ?? members.find((m) => m.userId === ref) ?? members.find((m) => m.email.toLowerCase() === lower);
|
|
5277
|
+
}
|
|
5278
|
+
async function resolveMember(c, ref, opts) {
|
|
5279
|
+
const { members } = await c.get(`${ORG_PATH}/members`);
|
|
5280
|
+
const member = findMember(members, ref);
|
|
5281
|
+
if (!member) {
|
|
5282
|
+
const org2 = orgName(opts);
|
|
5283
|
+
throw new PlatformClientError("not_found", `No member ${ref} in ${org2 ? `org ${org2}` : "this organization"}.`);
|
|
5284
|
+
}
|
|
5285
|
+
return member;
|
|
5286
|
+
}
|
|
5287
|
+
var EMAIL = /^[^\s@]+@[^\s@]+$/;
|
|
5288
|
+
function command(parent, name) {
|
|
5289
|
+
return parent.command(name).configureOutput({ outputError: usageErrorOutput });
|
|
5290
|
+
}
|
|
5291
|
+
function common(cmd) {
|
|
5292
|
+
return cmd.option("--api-key <key>", "API key (default: $COMPUTE_API_KEY)").option("--base-url <url>", "API base URL (default: https://platform.computesdk.com)").option("--org <slug>", "organization slug for this command, for a user login (or $COMPUTE_ORG)").option("--allow-untrusted-host", "send an explicit --api-key/env key to a non-computesdk, non-localhost --base-url (stored login credentials are never sent)").option("--json", "print machine-readable JSON");
|
|
5293
|
+
}
|
|
5294
|
+
function registerOrgMemberCommands(org2) {
|
|
5295
|
+
common(
|
|
5296
|
+
command(org2, "members").description("List the organization's members with their roles")
|
|
5297
|
+
).action(async (opts) => {
|
|
5298
|
+
try {
|
|
5299
|
+
const c = await orgClient(opts);
|
|
5300
|
+
output(opts, await c.get(`${ORG_PATH}/members`), printMembers);
|
|
5301
|
+
} catch (e) {
|
|
5302
|
+
fail2(e, opts);
|
|
5303
|
+
}
|
|
5304
|
+
});
|
|
5305
|
+
const invitations = common(
|
|
5306
|
+
command(org2, "invitations").description("List the organization's pending invitations with their links (owner/admin)").allowExcessArguments(false)
|
|
5307
|
+
).action(async (opts) => {
|
|
5308
|
+
try {
|
|
5309
|
+
const c = await orgClient(opts);
|
|
5310
|
+
output(opts, await c.get(`${ORG_PATH}/invitations`), printOrgInvitations);
|
|
5311
|
+
} catch (e) {
|
|
5312
|
+
fail2(e, opts);
|
|
5313
|
+
}
|
|
5314
|
+
});
|
|
5315
|
+
common(
|
|
5316
|
+
command(invitations, "cancel").description("Cancel a pending invitation; its link stops working (owner/admin)").argument("<invitationId>", "invitation id (see `compute org invitations`)").option("-y, --yes", "skip the confirmation")
|
|
5317
|
+
).action(async (invitationId, opts) => {
|
|
5318
|
+
try {
|
|
5319
|
+
await confirmWrite(`Cancel invitation ${invitationId}? Its link stops working.`, opts);
|
|
5320
|
+
const c = await orgClient(opts);
|
|
5321
|
+
const res = await c.del(`${ORG_PATH}/invitations/${segment(invitationId)}`);
|
|
5322
|
+
output(
|
|
5323
|
+
opts,
|
|
5324
|
+
res,
|
|
5325
|
+
(r) => console.log(`Cancelled the invitation for ${safeTerm(r.invitation.email)} (${r.invitation.id}).`)
|
|
5326
|
+
);
|
|
5327
|
+
} catch (e) {
|
|
5328
|
+
fail2(e, opts);
|
|
5329
|
+
}
|
|
5330
|
+
});
|
|
5331
|
+
common(
|
|
5332
|
+
command(org2, "invite").description("Invite someone to the organization by email and print the invite link (owner/admin)").argument("<email>", "email address to invite").option("--role <role>", "member | admin (owners are invited in the web app)", "member").option("-y, --yes", "skip the confirmation")
|
|
5333
|
+
).action(async (email, opts) => {
|
|
5334
|
+
try {
|
|
5335
|
+
const role = memberRole(opts.role, "Owner invitations require the web app.");
|
|
5336
|
+
if (!EMAIL.test(email)) {
|
|
5337
|
+
throw new PlatformClientError("invalid_argument", `Invalid email "${email}".`);
|
|
5338
|
+
}
|
|
5339
|
+
const target = orgName(opts);
|
|
5340
|
+
await confirmWrite(`Invite ${email} as ${role}${target ? ` to ${target}` : ""}?`, opts);
|
|
5341
|
+
const c = await orgClient(opts);
|
|
5342
|
+
output(opts, await c.post(`${ORG_PATH}/invitations`, { email, role }), printInvite);
|
|
5343
|
+
} catch (e) {
|
|
5344
|
+
fail2(e, opts);
|
|
5345
|
+
}
|
|
5346
|
+
});
|
|
5347
|
+
const member = command(org2, "member").description("Change a member's role or remove a member (owner/admin)");
|
|
5348
|
+
common(
|
|
5349
|
+
command(member, "set-role").description("Change a member's role between member and admin (owner roles change in the web app)").argument("<member>", "member id or email (see `compute org members`)").argument("<role>", "member | admin").option("-y, --yes", "skip the confirmation")
|
|
5350
|
+
).action(async (ref, roleArg, opts) => {
|
|
5351
|
+
try {
|
|
5352
|
+
const role = memberRole(roleArg, "Owner role changes require the web app.");
|
|
5353
|
+
const c = await orgClient(opts);
|
|
5354
|
+
const target = await resolveMember(c, ref, opts);
|
|
5355
|
+
await confirmWrite(`Change ${target.email} from ${target.role} to ${role}?`, opts);
|
|
5356
|
+
const res = await c.patch(`${ORG_PATH}/members/${segment(target.id)}`, { role });
|
|
5357
|
+
output(opts, res, (r) => console.log(`${safeTerm(r.member.email)} is now ${safeTerm(r.member.role)}.`));
|
|
5358
|
+
} catch (e) {
|
|
5359
|
+
fail2(e, opts);
|
|
5360
|
+
}
|
|
5361
|
+
});
|
|
5362
|
+
common(
|
|
5363
|
+
command(member, "remove").alias("rm").description("Remove a member from the organization (owners are removed in the web app)").argument("<member>", "member id or email (see `compute org members`)").option("-y, --yes", "skip the confirmation")
|
|
5364
|
+
).action(async (ref, opts) => {
|
|
5365
|
+
try {
|
|
5366
|
+
const c = await orgClient(opts);
|
|
5367
|
+
const target = await resolveMember(c, ref, opts);
|
|
5368
|
+
const org3 = orgName(opts);
|
|
5369
|
+
await confirmWrite(
|
|
5370
|
+
`Remove ${target.email} (${target.role}) from ${org3 ?? "the organization"}? They lose access at once.`,
|
|
5371
|
+
opts
|
|
5372
|
+
);
|
|
5373
|
+
const res = await c.del(`${ORG_PATH}/members/${segment(target.id)}`);
|
|
5374
|
+
output(
|
|
5375
|
+
opts,
|
|
5376
|
+
res,
|
|
5377
|
+
(r) => console.log(`Removed ${safeTerm(r.removed.email)} (${safeTerm(r.removed.role)}) from ${org3 ?? "the organization"}.`)
|
|
5378
|
+
);
|
|
5379
|
+
} catch (e) {
|
|
5380
|
+
fail2(e, opts);
|
|
5381
|
+
}
|
|
5382
|
+
});
|
|
5383
|
+
common(
|
|
5384
|
+
command(org2, "leave").description("Leave the organization (needs a user login; the last owner cannot leave)").option("-y, --yes", "skip the confirmation")
|
|
5385
|
+
).action(async (opts) => {
|
|
5386
|
+
try {
|
|
5387
|
+
const c = await userClient(opts, "`compute org leave`");
|
|
5388
|
+
const org3 = orgName(opts);
|
|
5389
|
+
await confirmWrite(`Leave ${org3 ?? "the active organization"}? You lose access to it at once.`, opts);
|
|
5390
|
+
const res = await c.post(`${ORG_PATH}/leave`, {});
|
|
5391
|
+
output(opts, res, () => {
|
|
5392
|
+
console.log(`Left ${org3 ?? "the organization"}.`);
|
|
5393
|
+
console.log(
|
|
5394
|
+
pc12.dim("If your login was granted for that organization, it no longer works: run `compute login` again.")
|
|
5395
|
+
);
|
|
5396
|
+
});
|
|
5397
|
+
} catch (e) {
|
|
5398
|
+
fail2(e, opts);
|
|
5399
|
+
}
|
|
5400
|
+
});
|
|
5401
|
+
}
|
|
5402
|
+
function registerInvitationsCommands(program2) {
|
|
5403
|
+
const invitations = common(
|
|
5404
|
+
command(program2, "invitations").description("Your pending invitations to other organizations (needs a user login)").allowExcessArguments(false)
|
|
5405
|
+
).action(async (opts) => {
|
|
5406
|
+
try {
|
|
5407
|
+
const c = await userClient(opts, "`compute invitations`");
|
|
5408
|
+
output(opts, await c.get("/api/v1/me/invitations"), printUserInvitations);
|
|
5409
|
+
} catch (e) {
|
|
5410
|
+
fail2(e, opts);
|
|
5411
|
+
}
|
|
5412
|
+
});
|
|
5413
|
+
common(
|
|
5414
|
+
command(invitations, "show").description("Show one of your invitations").argument("<invitationId>", "invitation id (see `compute invitations`)")
|
|
5415
|
+
).action(async (invitationId, opts) => {
|
|
5416
|
+
try {
|
|
5417
|
+
const c = await userClient(opts, "`compute invitations show`");
|
|
5418
|
+
const res = await c.get(`/api/v1/invitations/${segment(invitationId)}`);
|
|
5419
|
+
output(opts, res, (r) => printInvitationDetail(r.invitation));
|
|
5420
|
+
} catch (e) {
|
|
5421
|
+
fail2(e, opts);
|
|
5422
|
+
}
|
|
5423
|
+
});
|
|
5424
|
+
common(
|
|
5425
|
+
command(invitations, "accept").description("Accept an invitation and join its organization (no confirmation)").argument("<invitationId>", "invitation id (see `compute invitations`)").option("-y, --yes", "accepted for symmetry with decline; accept never asks")
|
|
5426
|
+
).action(async (invitationId, opts) => {
|
|
5427
|
+
try {
|
|
5428
|
+
const c = await userClient(opts, "`compute invitations accept`");
|
|
5429
|
+
const res = await c.post(`/api/v1/invitations/${segment(invitationId)}/accept`, {});
|
|
5430
|
+
output(opts, res, (r) => {
|
|
5431
|
+
const slug = safeTerm(r.organization.slug);
|
|
5432
|
+
console.log(`Joined ${slug} as ${safeTerm(r.member.role)}.`);
|
|
5433
|
+
console.log(pc12.dim(`Switch to it with \`compute org use ${slug}\`, or pass --org ${slug}.`));
|
|
5434
|
+
});
|
|
5435
|
+
} catch (e) {
|
|
5436
|
+
fail2(e, opts);
|
|
5437
|
+
}
|
|
5438
|
+
});
|
|
5439
|
+
common(
|
|
5440
|
+
command(invitations, "decline").description("Decline an invitation").argument("<invitationId>", "invitation id (see `compute invitations`)").option("-y, --yes", "skip the confirmation")
|
|
5441
|
+
).action(async (invitationId, opts) => {
|
|
5442
|
+
try {
|
|
5443
|
+
const c = await userClient(opts, "`compute invitations decline`");
|
|
5444
|
+
await confirmWrite(`Decline invitation ${invitationId}? Its link stops working.`, opts);
|
|
5445
|
+
const res = await c.post(
|
|
5446
|
+
`/api/v1/invitations/${segment(invitationId)}/decline`,
|
|
5447
|
+
{}
|
|
5448
|
+
);
|
|
5449
|
+
output(opts, res, (r) => {
|
|
5450
|
+
const org2 = r.invitation.organization?.slug;
|
|
5451
|
+
console.log(org2 ? `Declined the invitation to ${safeTerm(org2)}.` : `Declined invitation ${r.invitation.id}.`);
|
|
5452
|
+
});
|
|
5453
|
+
} catch (e) {
|
|
5454
|
+
fail2(e, opts);
|
|
5455
|
+
}
|
|
5456
|
+
});
|
|
5457
|
+
}
|
|
5458
|
+
|
|
3810
5459
|
// src/index.ts
|
|
3811
5460
|
var __filename2 = fileURLToPath(import.meta.url);
|
|
3812
|
-
var __dirname2 =
|
|
5461
|
+
var __dirname2 = dirname3(__filename2);
|
|
3813
5462
|
var packageJson = JSON.parse(
|
|
3814
|
-
|
|
5463
|
+
readFileSync6(join5(__dirname2, "..", "package.json"), "utf-8")
|
|
3815
5464
|
);
|
|
3816
5465
|
var isDevBuild = import.meta.url.includes("worktrees") || import.meta.url.includes("/packages/cli/");
|
|
3817
5466
|
var VERSION = isDevBuild ? `${packageJson.version}-dev` : packageJson.version;
|
|
@@ -3825,17 +5474,10 @@ process.stderr.on("error", (err) => {
|
|
|
3825
5474
|
});
|
|
3826
5475
|
var program = new Command();
|
|
3827
5476
|
program.name("compute").description("ComputeSDK CLI").version(VERSION).enablePositionalOptions().passThroughOptions();
|
|
3828
|
-
function envBaseUrl() {
|
|
3829
|
-
return process.env.COMPUTE_PLATFORM_URL ?? process.env.BENCHMARKS_PLATFORM_URL;
|
|
3830
|
-
}
|
|
3831
|
-
async function benchAuth(opts = {}) {
|
|
3832
|
-
const { resolveAuth } = await import("@benchsdk/cli");
|
|
3833
|
-
return resolveAuth({ baseUrl: opts.baseUrl ?? envBaseUrl() });
|
|
3834
|
-
}
|
|
3835
5477
|
async function printSessionLine(options) {
|
|
3836
5478
|
try {
|
|
3837
|
-
const { getMe } = await import("@benchsdk/cli");
|
|
3838
|
-
const me = await getMe(await
|
|
5479
|
+
const { getMe, resolveAuth } = await import("@benchsdk/cli");
|
|
5480
|
+
const me = await getMe(await resolveAuth({ baseUrl: options?.baseUrl ?? envBaseUrl() }));
|
|
3839
5481
|
const active = me.organizations.find((o) => o.id === me.activeOrganizationId);
|
|
3840
5482
|
const who = me.user.email ?? me.user.name ?? me.user.id;
|
|
3841
5483
|
if (active) {
|
|
@@ -3862,18 +5504,18 @@ async function runLogout() {
|
|
|
3862
5504
|
program.option("--login", "force re-authentication").option("--logout", "clear stored credentials").option("--org <slug>", "organization slug override for this invocation (or $COMPUTE_ORG)").action(async (opts) => {
|
|
3863
5505
|
if (opts.logout) {
|
|
3864
5506
|
console.log();
|
|
3865
|
-
p.intro(
|
|
5507
|
+
p.intro(pc13.cyan(`@computesdk/cli v${VERSION}`));
|
|
3866
5508
|
await runLogout();
|
|
3867
5509
|
p.log.success("Logged out. Stored credentials removed.");
|
|
3868
|
-
p.outro(
|
|
5510
|
+
p.outro(pc13.green("Done!"));
|
|
3869
5511
|
process.exit(0);
|
|
3870
5512
|
}
|
|
3871
5513
|
if (opts.login) {
|
|
3872
5514
|
console.log();
|
|
3873
|
-
p.intro(
|
|
5515
|
+
p.intro(pc13.cyan(`@computesdk/cli v${VERSION}`));
|
|
3874
5516
|
await runLogin();
|
|
3875
5517
|
await printSessionLine();
|
|
3876
|
-
p.outro(
|
|
5518
|
+
p.outro(pc13.green("Authenticated!"));
|
|
3877
5519
|
process.exit(0);
|
|
3878
5520
|
}
|
|
3879
5521
|
program.help();
|
|
@@ -3884,23 +5526,23 @@ program.hook("preAction", (thisCommand) => {
|
|
|
3884
5526
|
});
|
|
3885
5527
|
program.command("providers").description("List all providers and their configuration status").action(async () => {
|
|
3886
5528
|
console.log();
|
|
3887
|
-
p.intro(
|
|
5529
|
+
p.intro(pc13.cyan(`@computesdk/cli v${VERSION}`));
|
|
3888
5530
|
const statuses = getProviderStatus();
|
|
3889
5531
|
console.log();
|
|
3890
5532
|
for (const status of statuses) {
|
|
3891
|
-
const icon = status.ready ?
|
|
3892
|
-
const name = status.ready ?
|
|
3893
|
-
const detail = status.ready ?
|
|
5533
|
+
const icon = status.ready ? pc13.green("\u25CF") : pc13.gray("\u25CB");
|
|
5534
|
+
const name = status.ready ? pc13.white(status.name) : pc13.gray(status.name);
|
|
5535
|
+
const detail = status.ready ? pc13.green("ready") : pc13.gray(`missing: ${status.missing.join(", ")}`);
|
|
3894
5536
|
console.log(` ${icon} ${name} ${detail}`);
|
|
3895
5537
|
}
|
|
3896
5538
|
console.log();
|
|
3897
5539
|
});
|
|
3898
5540
|
program.command("login").description("Authenticate with ComputeSDK (OAuth device flow)").option("--base-url <url>", "platform URL to authenticate against").action(async (opts) => {
|
|
3899
5541
|
console.log();
|
|
3900
|
-
p.intro(
|
|
5542
|
+
p.intro(pc13.cyan(`@computesdk/cli v${VERSION}`));
|
|
3901
5543
|
await runLogin({ baseUrl: opts.baseUrl });
|
|
3902
5544
|
await printSessionLine({ baseUrl: opts.baseUrl });
|
|
3903
|
-
p.outro(
|
|
5545
|
+
p.outro(pc13.green("Authenticated!"));
|
|
3904
5546
|
});
|
|
3905
5547
|
program.command("logout").description("Clear stored credentials").option("--json", "print machine-readable JSON").action(async (opts) => {
|
|
3906
5548
|
await runLogout();
|
|
@@ -3909,24 +5551,19 @@ program.command("logout").description("Clear stored credentials").option("--json
|
|
|
3909
5551
|
return;
|
|
3910
5552
|
}
|
|
3911
5553
|
console.log();
|
|
3912
|
-
p.intro(
|
|
5554
|
+
p.intro(pc13.cyan(`@computesdk/cli v${VERSION}`));
|
|
3913
5555
|
p.log.success("Logged out. Stored credentials removed.");
|
|
3914
|
-
p.outro(
|
|
5556
|
+
p.outro(pc13.green("Done!"));
|
|
3915
5557
|
});
|
|
3916
5558
|
async function printWhoami(options = {}) {
|
|
3917
|
-
const
|
|
3918
|
-
const me = await getMe(await benchAuth({ baseUrl: options.baseUrl }));
|
|
5559
|
+
const me = await fetchWhoami(await benchAuth({ baseUrl: options.baseUrl }));
|
|
3919
5560
|
if (options.json) {
|
|
3920
5561
|
console.log(JSON.stringify(me, null, 2));
|
|
3921
5562
|
return;
|
|
3922
5563
|
}
|
|
3923
|
-
const
|
|
3924
|
-
console.log(me.user.email ?? me.user.name ?? me.user.id);
|
|
3925
|
-
console.log(
|
|
3926
|
-
`active org: ${active ? `${active.slug} (${active.id})` : "\u2014"}${me.organizations.length > 1 ? " \u2014 change with `compute org use <slug>`" : ""}`
|
|
3927
|
-
);
|
|
5564
|
+
for (const line of formatWhoami(me)) console.log(line);
|
|
3928
5565
|
}
|
|
3929
|
-
var org = program.command("org").description("Manage the active organization");
|
|
5566
|
+
var org = program.command("org").description("Manage the active organization, its members and invitations");
|
|
3930
5567
|
org.command("list").description("List your organizations").option("--json", "print machine-readable JSON").action(async (opts) => {
|
|
3931
5568
|
const { listOrganizations, getMe } = await import("@benchsdk/cli");
|
|
3932
5569
|
const auth = await benchAuth();
|
|
@@ -3936,8 +5573,8 @@ org.command("list").description("List your organizations").option("--json", "pri
|
|
|
3936
5573
|
return;
|
|
3937
5574
|
}
|
|
3938
5575
|
for (const o of organizations) {
|
|
3939
|
-
const marker = o.id === me.activeOrganizationId ?
|
|
3940
|
-
console.log(`${marker} ${
|
|
5576
|
+
const marker = o.id === me.activeOrganizationId ? pc13.green("*") : " ";
|
|
5577
|
+
console.log(`${marker} ${pc13.cyan(o.slug)} ${o.name ?? ""} ${pc13.dim(o.id)}`);
|
|
3941
5578
|
}
|
|
3942
5579
|
});
|
|
3943
5580
|
org.command("use <slug>").description("Set the active organization (persisted to the stored login)").action(async (slug) => {
|
|
@@ -3967,23 +5604,30 @@ org.command("use <slug>").description("Set the active organization (persisted to
|
|
|
3967
5604
|
console.log(`Active organization set to ${result.organization.slug} (${result.organization.id})`);
|
|
3968
5605
|
});
|
|
3969
5606
|
org.command("current").description("Show the current user and active organization").option("--base-url <url>", "platform URL to query").option("--json", "print machine-readable JSON").action((opts) => printWhoami(opts));
|
|
5607
|
+
registerOrgMemberCommands(org);
|
|
3970
5608
|
program.command("whoami").description("Show the current user and active organization").option("--base-url <url>", "platform URL to query").option("--json", "print machine-readable JSON").action((opts) => printWhoami(opts));
|
|
5609
|
+
registerInvitationsCommands(program);
|
|
3971
5610
|
registerActionsCommands(program);
|
|
5611
|
+
registerByokCommands(program);
|
|
3972
5612
|
registerMarketCommands(program);
|
|
3973
5613
|
registerSandboxesCommands(program);
|
|
3974
5614
|
registerAgentsCommands(program);
|
|
3975
|
-
program.command("bench").description("Benchmarks platform CLI (run, auth, org, benchmarks, runs, results, artifacts, export, ...)").allowUnknownOption().helpOption(false).action(() => {
|
|
5615
|
+
program.command("bench").description("Benchmarks platform CLI (run, auth, org, benchmarks, runs, results, fork, artifacts, export, ...)").allowUnknownOption().helpOption(false).action(() => {
|
|
5616
|
+
});
|
|
5617
|
+
registerManifestCommand(program, {
|
|
5618
|
+
version: packageJson.version,
|
|
5619
|
+
packageDir: join5(__dirname2, "..")
|
|
3976
5620
|
});
|
|
3977
5621
|
async function main() {
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
await
|
|
5622
|
+
const bench = parseBenchDispatch(process.argv.slice(2));
|
|
5623
|
+
if (bench) {
|
|
5624
|
+
await runBench(bench);
|
|
3981
5625
|
return;
|
|
3982
5626
|
}
|
|
3983
5627
|
await program.parseAsync(process.argv);
|
|
3984
5628
|
}
|
|
3985
5629
|
main().catch((error) => {
|
|
3986
|
-
console.error(
|
|
5630
|
+
console.error(pc13.red(`
|
|
3987
5631
|
Error: ${error.message}`));
|
|
3988
5632
|
process.exit(1);
|
|
3989
5633
|
});
|