@computesdk/cli 2.3.2 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +445 -185
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import "dotenv/config";
|
|
5
5
|
import { Command } from "commander";
|
|
6
6
|
import * as p from "@clack/prompts";
|
|
7
|
-
import
|
|
7
|
+
import pc5 from "picocolors";
|
|
8
8
|
import { readFileSync as readFileSync2 } from "fs";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { dirname, join as join2 } from "path";
|
|
@@ -65,9 +65,11 @@ function getProviderStatus() {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// src/actions.ts
|
|
68
|
-
import
|
|
68
|
+
import pc2 from "picocolors";
|
|
69
69
|
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
70
|
-
|
|
70
|
+
|
|
71
|
+
// src/settings.ts
|
|
72
|
+
import pc from "picocolors";
|
|
71
73
|
|
|
72
74
|
// src/actions-client.ts
|
|
73
75
|
var DEFAULT_BASE_URL = "https://platform.computesdk.com";
|
|
@@ -400,7 +402,224 @@ function isTrustedActionsHost(baseUrl) {
|
|
|
400
402
|
return host === "computesdk.com" || host.endsWith(".computesdk.com") || isLoopbackHost(host);
|
|
401
403
|
}
|
|
402
404
|
|
|
405
|
+
// src/rate-display.ts
|
|
406
|
+
var SECONDS_PER_MINUTE = 60;
|
|
407
|
+
var SECONDS_PER_HOUR = 3600;
|
|
408
|
+
function rateAllUnits(rate) {
|
|
409
|
+
const perSecond = rate.per === "second" ? rate.usd : rate.per === "minute" ? rate.usd / SECONDS_PER_MINUTE : rate.usd / SECONDS_PER_HOUR;
|
|
410
|
+
return {
|
|
411
|
+
perSecond,
|
|
412
|
+
perMinute: perSecond * SECONDS_PER_MINUTE,
|
|
413
|
+
perHour: perSecond * SECONDS_PER_HOUR
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function formatUsd(usd) {
|
|
417
|
+
if (!Number.isFinite(usd)) return "$\u2014";
|
|
418
|
+
if (usd === 0) return "$0";
|
|
419
|
+
const decimals = Math.min(100, Math.max(0, 3 - Math.floor(Math.log10(Math.abs(usd)))));
|
|
420
|
+
const fixed = usd.toFixed(decimals);
|
|
421
|
+
const trimmed = fixed.includes(".") ? fixed.replace(/0+$/, "").replace(/\.$/, "") : fixed;
|
|
422
|
+
return `$${trimmed}`;
|
|
423
|
+
}
|
|
424
|
+
function formatMoney(usd) {
|
|
425
|
+
if (!Number.isFinite(usd)) return "$\u2014";
|
|
426
|
+
const sign = usd < 0 ? "-" : "";
|
|
427
|
+
const abs = Math.abs(usd);
|
|
428
|
+
if (abs !== 0 && abs < 0.01) {
|
|
429
|
+
return `${sign}${formatUsd(abs)}`;
|
|
430
|
+
}
|
|
431
|
+
const s = abs.toLocaleString("en-US", {
|
|
432
|
+
minimumFractionDigits: 2,
|
|
433
|
+
maximumFractionDigits: 2
|
|
434
|
+
});
|
|
435
|
+
return `${sign}$${s}`;
|
|
436
|
+
}
|
|
437
|
+
function formatRateAllUnits(rate) {
|
|
438
|
+
return `${formatUsd(rate.perHour)}/hr \xB7 ${formatUsd(rate.perMinute)}/min \xB7 ${formatUsd(rate.perSecond)}/s`;
|
|
439
|
+
}
|
|
440
|
+
function formatUsdPer(rate) {
|
|
441
|
+
return formatRateAllUnits(rateAllUnits(rate));
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// src/settings.ts
|
|
445
|
+
var PLATFORM_SIZES = ["small", "medium", "large", "xlarge"];
|
|
446
|
+
function parseMaxPrice(value, per) {
|
|
447
|
+
if (value === void 0) {
|
|
448
|
+
if (per !== void 0) throw new Error("--max-price-per requires --max-price.");
|
|
449
|
+
return void 0;
|
|
450
|
+
}
|
|
451
|
+
let usdText = value;
|
|
452
|
+
let unit = per;
|
|
453
|
+
const slash = value.indexOf("/");
|
|
454
|
+
if (slash !== -1) {
|
|
455
|
+
usdText = value.slice(0, slash);
|
|
456
|
+
const inline = value.slice(slash + 1);
|
|
457
|
+
if (per !== void 0 && per !== inline) {
|
|
458
|
+
throw new Error(`--max-price "${value}" conflicts with --max-price-per "${per}".`);
|
|
459
|
+
}
|
|
460
|
+
unit = inline;
|
|
461
|
+
}
|
|
462
|
+
const usd = Number(usdText);
|
|
463
|
+
if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(usdText) || !Number.isFinite(usd) || usd <= 0) {
|
|
464
|
+
throw new Error(`Invalid --max-price "${value}". Expected a positive dollar amount like 0.12/hour.`);
|
|
465
|
+
}
|
|
466
|
+
if (unit !== "second" && unit !== "minute" && unit !== "hour") {
|
|
467
|
+
throw new Error(
|
|
468
|
+
"a unit is required \u2014 write it as <usd>/<unit> (e.g. 0.12/hour)"
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
return { usd, per: unit };
|
|
472
|
+
}
|
|
473
|
+
function parseSizeCap(entry) {
|
|
474
|
+
const eq = entry.indexOf("=");
|
|
475
|
+
const size = eq === -1 ? entry : entry.slice(0, eq);
|
|
476
|
+
if (!PLATFORM_SIZES.includes(size)) {
|
|
477
|
+
throw new Error(
|
|
478
|
+
`Invalid --cap "${entry}" \u2014 size must be one of ${PLATFORM_SIZES.join(", ")}.`
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
const value = eq === -1 ? "" : entry.slice(eq + 1);
|
|
482
|
+
if (value === "none") return { size, cap: null };
|
|
483
|
+
const cap = parseMaxPrice(value, void 0);
|
|
484
|
+
if (!cap) {
|
|
485
|
+
throw new Error(
|
|
486
|
+
`Invalid --cap "${entry}" \u2014 expected <size>=<usd>/<unit> (e.g. small=0.11/hour) or <size>=none.`
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
return { size, cap };
|
|
490
|
+
}
|
|
491
|
+
var fmtRate = (cap) => cap ? formatUsdPer(cap) : "\u2014";
|
|
492
|
+
var fmtRef = (ref) => ref ? ` ${pc.dim(`reference ${formatUsdPer(ref)}`)}` : "";
|
|
493
|
+
function printLaneSettings(s, lane) {
|
|
494
|
+
const sandbox = lane === "sandboxes";
|
|
495
|
+
const orderType = s.marketOrderType ?? (sandbox ? "inherit" : "\u2014");
|
|
496
|
+
const orderSuffix = sandbox && s.marketOrderType == null ? pc.dim(` (Actions: ${s.actionsMarketOrderType ?? "\u2014"})`) : "";
|
|
497
|
+
console.log(`order type: ${orderType}${orderSuffix}`);
|
|
498
|
+
const capSuffix = sandbox && s.marketCap == null ? pc.dim(` (inherits Actions: ${fmtRate(s.actionsMarketCap)})`) : "";
|
|
499
|
+
console.log(`general cap: ${fmtRate(s.marketCap)}${capSuffix}`);
|
|
500
|
+
console.log("per-size caps:");
|
|
501
|
+
for (const size of PLATFORM_SIZES) {
|
|
502
|
+
const cap = s.marketCaps?.[size];
|
|
503
|
+
console.log(
|
|
504
|
+
` ${size.padEnd(7)} ${fmtRate(cap)}${cap ? "" : fmtRef(s.referencePrices?.[size])}`
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
const orderText = s.providerOrder.length > 0 ? s.providerOrder.join(", ") : sandbox ? pc.dim(`inherit (Actions: ${(s.actionsProviderOrder ?? []).join(", ") || "\u2014"})`) : "\u2014";
|
|
508
|
+
console.log(`provider order: ${orderText}`);
|
|
509
|
+
const resources = Object.entries(s.providerResources ?? {});
|
|
510
|
+
console.log("sizes:");
|
|
511
|
+
if (resources.length === 0) console.log(" \u2014");
|
|
512
|
+
for (const [provider, r] of resources) {
|
|
513
|
+
console.log(
|
|
514
|
+
` ${provider} ${r.cpus ?? "?"} vCPU / ${r.memoryMb ?? "?"} MB${r.ephemeralDiskMb ? ` / ${r.ephemeralDiskMb} MB disk` : ""}`
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
const pool = Object.entries(s.warmPool ?? {});
|
|
518
|
+
console.log("warm pool:");
|
|
519
|
+
if (pool.length === 0) console.log(" \u2014");
|
|
520
|
+
for (const [entry, floor] of pool) console.log(` ${entry} ${floor}`);
|
|
521
|
+
if (s.snapshotPool !== void 0) {
|
|
522
|
+
const snap = Object.entries(s.snapshotPool);
|
|
523
|
+
console.log("snapshot pool:");
|
|
524
|
+
if (snap.length === 0) console.log(" \u2014");
|
|
525
|
+
for (const [entry, cap] of snap) console.log(` ${entry} ${cap}`);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function settingsFail(e, opts, lane, verb, deps) {
|
|
529
|
+
if (e instanceof ActionsApiError && e.status === 403) {
|
|
530
|
+
return deps.fail(
|
|
531
|
+
new ActionsApiError(
|
|
532
|
+
403,
|
|
533
|
+
`Only org owners/admins can ${verb} ${lane} settings`,
|
|
534
|
+
e.body
|
|
535
|
+
),
|
|
536
|
+
opts
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
return deps.fail(e, opts);
|
|
540
|
+
}
|
|
541
|
+
function registerSettingsCommands(group, lane, common, deps) {
|
|
542
|
+
const settings = common(
|
|
543
|
+
group.command("settings").description(`Show the org's ${lane} routing policy (order, caps, sizes, pools)`).configureOutput({
|
|
544
|
+
outputError: (str, write) => deps.usageErrorOutput(str, write)
|
|
545
|
+
})
|
|
546
|
+
).action(async (opts) => {
|
|
547
|
+
try {
|
|
548
|
+
const c = await deps.client(opts);
|
|
549
|
+
const res = await c.get(`/api/v1/${lane}/settings`);
|
|
550
|
+
deps.output(opts, res, (s) => printLaneSettings(s, lane));
|
|
551
|
+
} catch (e) {
|
|
552
|
+
settingsFail(e, opts, lane, "view", deps);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
common(
|
|
556
|
+
settings.command("set").description(`Update the org's ${lane} routing policy`).option(
|
|
557
|
+
"--cap <size=rate>",
|
|
558
|
+
"per-size cap: <size>=<usd>/<unit> or <size>=none to clear (repeatable)",
|
|
559
|
+
(v, a) => a.concat(v),
|
|
560
|
+
[]
|
|
561
|
+
).option("--general-cap <rate|none>", 'whole-lane price cap (e.g. 0.40/hour); "none" clears it').option(
|
|
562
|
+
"--order-type <type>",
|
|
563
|
+
lane === "sandboxes" ? "market order type: limit | market | inherit (the Actions value)" : "market order type: limit | market"
|
|
564
|
+
).option(
|
|
565
|
+
"--order <providers>",
|
|
566
|
+
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'
|
|
567
|
+
)
|
|
568
|
+
).action(async (opts) => {
|
|
569
|
+
try {
|
|
570
|
+
const body = {};
|
|
571
|
+
if (opts.cap.length > 0) {
|
|
572
|
+
const caps = {};
|
|
573
|
+
for (const entry of opts.cap) {
|
|
574
|
+
const { size, cap } = parseSizeCap(entry);
|
|
575
|
+
caps[size] = cap;
|
|
576
|
+
}
|
|
577
|
+
body.marketCaps = caps;
|
|
578
|
+
}
|
|
579
|
+
if (opts.generalCap !== void 0) {
|
|
580
|
+
body.marketCap = opts.generalCap === "none" ? null : parseMaxPrice(opts.generalCap, void 0);
|
|
581
|
+
}
|
|
582
|
+
if (opts.orderType !== void 0) {
|
|
583
|
+
if (lane === "sandboxes" && opts.orderType === "inherit") {
|
|
584
|
+
body.marketOrderType = null;
|
|
585
|
+
} else if (opts.orderType === "limit" || opts.orderType === "market") {
|
|
586
|
+
body.marketOrderType = opts.orderType;
|
|
587
|
+
} else {
|
|
588
|
+
throw new Error(
|
|
589
|
+
lane === "sandboxes" ? "--order-type must be limit, market, or inherit." : "--order-type must be limit or market."
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (opts.order !== void 0) {
|
|
594
|
+
if (opts.order === "inherit" && lane === "sandboxes") {
|
|
595
|
+
body.providerOrder = [];
|
|
596
|
+
} else if (opts.order === "default" && lane === "actions") {
|
|
597
|
+
body.providerOrder = [];
|
|
598
|
+
} else {
|
|
599
|
+
body.providerOrder = opts.order.split(",").map((s) => s.trim()).filter(Boolean);
|
|
600
|
+
if (body.providerOrder.length === 0) {
|
|
601
|
+
throw new Error(
|
|
602
|
+
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".`
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (Object.keys(body).length === 0) {
|
|
608
|
+
throw new Error(
|
|
609
|
+
"Nothing to change \u2014 pass --cap, --general-cap, --order-type, or --order."
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
const c = await deps.client(opts);
|
|
613
|
+
const res = await c.patch(`/api/v1/${lane}/settings`, body);
|
|
614
|
+
deps.output(opts, res, (s) => printLaneSettings(s, lane));
|
|
615
|
+
} catch (e) {
|
|
616
|
+
settingsFail(e, opts, lane, "change", deps);
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
|
|
403
621
|
// src/actions.ts
|
|
622
|
+
import { basename, join } from "path";
|
|
404
623
|
function sanitizePathPart(name) {
|
|
405
624
|
const base = basename(name);
|
|
406
625
|
if (base === "" || base === "." || base === "..") return "artifact";
|
|
@@ -462,7 +681,7 @@ async function fetchRunSummary(c, runId) {
|
|
|
462
681
|
} catch (e) {
|
|
463
682
|
if (!(e instanceof ActionsApiError && e.status === 404)) {
|
|
464
683
|
console.error(
|
|
465
|
-
|
|
684
|
+
pc2.dim(`summary unavailable: ${e instanceof Error ? e.message : String(e)}`)
|
|
466
685
|
);
|
|
467
686
|
}
|
|
468
687
|
return null;
|
|
@@ -472,9 +691,9 @@ function fail(error, opts = {}) {
|
|
|
472
691
|
if (opts.json) {
|
|
473
692
|
process.stderr.write(JSON.stringify(toErrorEnvelope(error)) + "\n");
|
|
474
693
|
} else if (error instanceof ActionsApiError) {
|
|
475
|
-
console.error(
|
|
694
|
+
console.error(pc2.red(`Error (${error.status}): ${error.message}`));
|
|
476
695
|
} else {
|
|
477
|
-
console.error(
|
|
696
|
+
console.error(pc2.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
478
697
|
}
|
|
479
698
|
process.exit(1);
|
|
480
699
|
}
|
|
@@ -502,15 +721,15 @@ function shortSha(sha) {
|
|
|
502
721
|
function conclusionLabel(conclusion) {
|
|
503
722
|
switch (conclusion) {
|
|
504
723
|
case "passed":
|
|
505
|
-
return
|
|
724
|
+
return pc2.green("passed");
|
|
506
725
|
case "failed":
|
|
507
|
-
return
|
|
726
|
+
return pc2.red("failed");
|
|
508
727
|
case "running":
|
|
509
|
-
return
|
|
728
|
+
return pc2.yellow("running");
|
|
510
729
|
case "cancelled":
|
|
511
|
-
return
|
|
730
|
+
return pc2.gray("cancelled");
|
|
512
731
|
case "none":
|
|
513
|
-
return
|
|
732
|
+
return pc2.yellow("queued");
|
|
514
733
|
default:
|
|
515
734
|
return conclusion;
|
|
516
735
|
}
|
|
@@ -519,10 +738,10 @@ function formatRunRow(run) {
|
|
|
519
738
|
const num = run.runNumber === null ? "-" : `#${run.runNumber}`;
|
|
520
739
|
return [
|
|
521
740
|
run.id,
|
|
522
|
-
|
|
741
|
+
pc2.dim(num),
|
|
523
742
|
run.workflowName || run.workflowPath,
|
|
524
743
|
conclusionLabel(run.conclusion),
|
|
525
|
-
|
|
744
|
+
pc2.dim(`${run.repoFullName}@${run.ref}`),
|
|
526
745
|
shortSha(run.headSha),
|
|
527
746
|
formatDuration(run.durationMs),
|
|
528
747
|
run.startedAt
|
|
@@ -530,8 +749,8 @@ function formatRunRow(run) {
|
|
|
530
749
|
}
|
|
531
750
|
function formatRunDetail(run, runUrl) {
|
|
532
751
|
const lines = [];
|
|
533
|
-
lines.push(`${
|
|
534
|
-
lines.push(
|
|
752
|
+
lines.push(`${pc2.bold(run.workflowName || run.workflowPath)} ${conclusionLabel(run.conclusion)}`);
|
|
753
|
+
lines.push(pc2.dim(`run ${run.id}${run.runNumber === null ? "" : ` #${run.runNumber}`}`));
|
|
535
754
|
lines.push(`${run.repoFullName} @ ${run.ref} ${shortSha(run.headSha)} ${run.event}${run.prNumber ? ` PR #${run.prNumber}` : ""}`);
|
|
536
755
|
lines.push(`title: ${run.title}`);
|
|
537
756
|
lines.push(`started: ${run.startedAt} duration: ${formatDuration(run.durationMs)}`);
|
|
@@ -541,16 +760,16 @@ function formatRunDetail(run, runUrl) {
|
|
|
541
760
|
if (runUrl) lines.push(`url: ${runUrl}`);
|
|
542
761
|
if (run.jobs.length > 0) {
|
|
543
762
|
lines.push("");
|
|
544
|
-
lines.push(
|
|
763
|
+
lines.push(pc2.bold("jobs"));
|
|
545
764
|
for (const job of run.jobs) {
|
|
546
765
|
const placement = job.provider ? `${job.provider}${job.region ? `:${job.region}` : ""}` : "-";
|
|
547
766
|
lines.push(` ${job.id} ${job.name} ${conclusionLabel(job.state)} ${placement} ${formatDuration(job.durationMs)}`);
|
|
548
767
|
for (const attempt of job.placementAttempts) {
|
|
549
|
-
lines.push(
|
|
768
|
+
lines.push(pc2.dim(` placement failed on ${attempt.provider}${attempt.region ? `:${attempt.region}` : ""}: ${attempt.error}`));
|
|
550
769
|
}
|
|
551
770
|
for (const step of job.steps) {
|
|
552
771
|
const exit = step.exitCode === null ? "" : ` (exit ${step.exitCode})`;
|
|
553
|
-
lines.push(
|
|
772
|
+
lines.push(pc2.dim(` ${step.name} ${step.state}${exit} ${formatDuration(step.durationMs)}`));
|
|
554
773
|
}
|
|
555
774
|
}
|
|
556
775
|
}
|
|
@@ -558,18 +777,18 @@ function formatRunDetail(run, runUrl) {
|
|
|
558
777
|
}
|
|
559
778
|
function formatRunInspection(run) {
|
|
560
779
|
const lines = [];
|
|
561
|
-
lines.push(`${
|
|
562
|
-
lines.push(
|
|
780
|
+
lines.push(`${pc2.bold("run")} ${conclusionLabel(run.conclusion)}${run.runNumber === null ? "" : ` #${run.runNumber}`}`);
|
|
781
|
+
lines.push(pc2.dim(run.id));
|
|
563
782
|
lines.push(`${safeTerm(run.ref)} ${shortSha(run.headSha)} ${safeTerm(run.event)}`);
|
|
564
783
|
lines.push(`queued: ${run.queuedAt} started: ${run.startedAt} finished: ${run.finishedAt}`);
|
|
565
784
|
if (run.cancellationReason) lines.push(`cancelled: ${run.cancellationReason}`);
|
|
566
785
|
if (run.supersededByRunId) lines.push(`superseded by: ${run.supersededByRunId}`);
|
|
567
|
-
if (run.blockedReason) lines.push(
|
|
786
|
+
if (run.blockedReason) lines.push(pc2.red(`blocked: ${safeTerm(run.blockedReason)}`));
|
|
568
787
|
if (run.concurrencyGroup) lines.push(`concurrency: ${safeTerm(run.concurrencyGroup)}`);
|
|
569
788
|
if (run.providerOverride) lines.push(`dispatched to: ${safeTerm(run.providerOverride)}`);
|
|
570
789
|
if (run.definitionStale) {
|
|
571
790
|
const parsed = run.workflowParsedFromSha ? shortSha(run.workflowParsedFromSha) : "unknown";
|
|
572
|
-
lines.push(
|
|
791
|
+
lines.push(pc2.yellow(`definition: stored parse is from ${parsed}, not this head \u2014 context may be newer than the run`));
|
|
573
792
|
}
|
|
574
793
|
if (run.dispatchInputs && Object.keys(run.dispatchInputs).length > 0) {
|
|
575
794
|
lines.push(`inputs: ${Object.entries(run.dispatchInputs).map(([k, v]) => `${safeTerm(k)}=${safeTerm(v)}`).join(" ")}`);
|
|
@@ -580,24 +799,24 @@ function formatRunInspection(run) {
|
|
|
580
799
|
}
|
|
581
800
|
if (run.caches.length > 0) {
|
|
582
801
|
lines.push("");
|
|
583
|
-
lines.push(
|
|
802
|
+
lines.push(pc2.bold("caches"));
|
|
584
803
|
for (const cache of run.caches) {
|
|
585
804
|
const action = [cache.restoredAt ? "restored" : null, cache.savedAt ? "saved" : null].filter(Boolean).join("+");
|
|
586
|
-
lines.push(` ${safeTerm(cache.key)} ${
|
|
805
|
+
lines.push(` ${safeTerm(cache.key)} ${pc2.dim(`${action} ${safeTerm(cache.scopeRef)} ${cache.sizeBytes}B`)}`);
|
|
587
806
|
}
|
|
588
807
|
}
|
|
589
808
|
if (run.jobs.length > 0) {
|
|
590
809
|
lines.push("");
|
|
591
|
-
lines.push(
|
|
810
|
+
lines.push(pc2.bold("jobs"));
|
|
592
811
|
for (const job of run.jobs) {
|
|
593
812
|
const placement = job.provider ? `${safeTerm(job.provider)}${job.region ? `:${safeTerm(job.region)}` : ""}` : "-";
|
|
594
813
|
lines.push(` ${safeTerm(job.name)} ${conclusionLabel(job.state)} ${placement}`);
|
|
595
|
-
lines.push(
|
|
814
|
+
lines.push(pc2.dim(` ${job.id}`));
|
|
596
815
|
if (job.runsOn.length > 0 || job.resolvedRunsOn !== null) {
|
|
597
816
|
const resolved = job.resolvedRunsOn !== null && job.resolvedRunsOn.join(",") !== job.runsOn.join(",") ? ` \u2192 ${job.resolvedRunsOn.map(safeTerm).join(", ")}` : "";
|
|
598
817
|
lines.push(` runs-on: ${job.runsOn.map(safeTerm).join(", ") || "(none)"}${resolved}`);
|
|
599
818
|
}
|
|
600
|
-
if (job.runsOnHasExpression) lines.push(
|
|
819
|
+
if (job.runsOnHasExpression) lines.push(pc2.dim(" runs-on resolves at runtime (expression)"));
|
|
601
820
|
if (job.container) lines.push(` container: ${safeTerm(job.container)}`);
|
|
602
821
|
if (job.runnerImage) lines.push(` image: ${safeTerm(job.runnerImage)}`);
|
|
603
822
|
if (job.placementHint) {
|
|
@@ -614,9 +833,9 @@ function formatRunInspection(run) {
|
|
|
614
833
|
if (job.matrix) {
|
|
615
834
|
lines.push(` matrix: ${Object.entries(job.matrix).map(([k, v]) => `${safeTerm(k)}=${safeTerm(v)}`).join(" ")}`);
|
|
616
835
|
}
|
|
617
|
-
if (job.failureReason) lines.push(
|
|
836
|
+
if (job.failureReason) lines.push(pc2.red(` failed: ${safeTerm(job.failureReason)}`));
|
|
618
837
|
for (const attempt of job.placementAttempts) {
|
|
619
|
-
lines.push(
|
|
838
|
+
lines.push(pc2.dim(` placement failed on ${safeTerm(attempt.provider)}${attempt.region ? `:${safeTerm(attempt.region)}` : ""}: ${safeTerm(attempt.error)}`));
|
|
620
839
|
}
|
|
621
840
|
}
|
|
622
841
|
}
|
|
@@ -624,7 +843,7 @@ function formatRunInspection(run) {
|
|
|
624
843
|
}
|
|
625
844
|
function formatRunSummary(summary) {
|
|
626
845
|
const lines = [];
|
|
627
|
-
lines.push(
|
|
846
|
+
lines.push(pc2.bold(`failures \u2014 run ${summary.runId} ${conclusionLabel(summary.conclusion)}`));
|
|
628
847
|
if (summary.failures.length === 0) {
|
|
629
848
|
lines.push(" no failed jobs");
|
|
630
849
|
return lines.join("\n");
|
|
@@ -632,7 +851,7 @@ function formatRunSummary(summary) {
|
|
|
632
851
|
for (const job of summary.failures) {
|
|
633
852
|
const placement = job.provider ? `${safeTerm(job.provider)}${job.region ? `:${safeTerm(job.region)}` : ""}` : "-";
|
|
634
853
|
lines.push(` ${job.id} ${safeTerm(job.name)} ${conclusionLabel(job.conclusion)} ${placement}`);
|
|
635
|
-
if (job.failureReason) lines.push(
|
|
854
|
+
if (job.failureReason) lines.push(pc2.dim(` ${safeTerm(job.failureReason)}`));
|
|
636
855
|
for (const step of job.failedSteps) {
|
|
637
856
|
const exit = step.exitCode === null ? "" : ` (exit ${step.exitCode})`;
|
|
638
857
|
lines.push(` step ${step.ordinal} ${safeTerm(step.name)}${exit}`);
|
|
@@ -640,7 +859,7 @@ function formatRunSummary(summary) {
|
|
|
640
859
|
if (job.excerpt) {
|
|
641
860
|
const scope = job.excerpt.stepOrdinal === null ? "job log" : `step ${job.excerpt.stepOrdinal}`;
|
|
642
861
|
const cut = job.excerpt.truncated ? ", truncated" : "";
|
|
643
|
-
lines.push(
|
|
862
|
+
lines.push(pc2.dim(` \u2500\u2500 ${scope} tail${cut} \u2500\u2500`));
|
|
644
863
|
for (const line of job.excerpt.text.split("\n")) lines.push(` ${safeTerm(line)}`);
|
|
645
864
|
}
|
|
646
865
|
}
|
|
@@ -742,15 +961,15 @@ function formatRunHistory(history) {
|
|
|
742
961
|
lines.push(`last ${history.runCount} runs: ${parts || "none"}`);
|
|
743
962
|
if (history.jobs.length > 0) {
|
|
744
963
|
lines.push("");
|
|
745
|
-
lines.push(
|
|
964
|
+
lines.push(pc2.bold("jobs"));
|
|
746
965
|
for (const job of history.jobs) {
|
|
747
966
|
const rate = job.runs > 0 ? Math.round(job.failedRuns / job.runs * 100) : 0;
|
|
748
|
-
const platform = job.failedBeforeSteps > 0 ?
|
|
967
|
+
const platform = job.failedBeforeSteps > 0 ? pc2.dim(` (${job.failedBeforeSteps} failed before steps)`) : "";
|
|
749
968
|
const count = `${job.failedRuns}/${job.runs} runs failed`;
|
|
750
|
-
const label = job.failedRuns > 0 ?
|
|
969
|
+
const label = job.failedRuns > 0 ? pc2.red(count) : pc2.green(count);
|
|
751
970
|
lines.push(` ${safeTerm(job.job)} ${label} ${rate}%${platform}`);
|
|
752
971
|
for (const step of job.steps) {
|
|
753
|
-
lines.push(
|
|
972
|
+
lines.push(pc2.dim(` step "${safeTerm(step.step)}" failed in ${step.failedRuns} run${step.failedRuns === 1 ? "" : "s"}`));
|
|
754
973
|
}
|
|
755
974
|
}
|
|
756
975
|
}
|
|
@@ -759,45 +978,45 @@ function formatRunHistory(history) {
|
|
|
759
978
|
);
|
|
760
979
|
if (failed.length > 0) {
|
|
761
980
|
lines.push("");
|
|
762
|
-
lines.push(
|
|
981
|
+
lines.push(pc2.bold("failed runs"));
|
|
763
982
|
for (const run of failed) {
|
|
764
|
-
const blame = run.failedJobs.length > 0 ? run.failedJobs.map((j) => safeTerm(j.step === null ? j.job : `${j.job}:${j.step}`)).join(", ") :
|
|
765
|
-
lines.push(` ${shortSha(run.headSha)} ${
|
|
983
|
+
const blame = run.failedJobs.length > 0 ? run.failedJobs.map((j) => safeTerm(j.step === null ? j.job : `${j.job}:${j.step}`)).join(", ") : pc2.dim("(no failed job recorded)");
|
|
984
|
+
lines.push(` ${shortSha(run.headSha)} ${pc2.dim(run.startedAt)} ${blame}`);
|
|
766
985
|
}
|
|
767
986
|
}
|
|
768
987
|
return lines.join("\n");
|
|
769
988
|
}
|
|
770
989
|
function formatProviderRow(p2) {
|
|
771
|
-
const icon = p2.usable ?
|
|
772
|
-
const name = p2.usable ?
|
|
990
|
+
const icon = p2.usable ? pc2.green("\u25CF") : pc2.gray("\u25CB");
|
|
991
|
+
const name = p2.usable ? pc2.white(p2.provider) : pc2.gray(p2.provider);
|
|
773
992
|
const flags = [
|
|
774
993
|
p2.credential,
|
|
775
|
-
p2.actCapable ?
|
|
994
|
+
p2.actCapable ? pc2.green("act") : pc2.gray("no-act"),
|
|
776
995
|
p2.regions.length > 0 ? `regions: ${p2.regions.join(",")}` : "no region choice",
|
|
777
|
-
p2.position === null ?
|
|
996
|
+
p2.position === null ? pc2.gray("not in provider order") : `order #${p2.position}`
|
|
778
997
|
].join(" ");
|
|
779
998
|
return ` ${icon} ${name} ${flags}`;
|
|
780
999
|
}
|
|
781
1000
|
function formatVerifyResult(r) {
|
|
782
1001
|
const ok = r.verified === true;
|
|
783
|
-
const head = ok ?
|
|
784
|
-
const detail = r.key.statusDetail ?
|
|
785
|
-
const act = r.key.actCapable ?
|
|
1002
|
+
const head = ok ? pc2.green("verified") : pc2.red("not verified");
|
|
1003
|
+
const detail = r.key.statusDetail ? pc2.dim(` ${r.key.statusDetail}`) : "";
|
|
1004
|
+
const act = r.key.actCapable ? pc2.green(" act-capable") : "";
|
|
786
1005
|
return `${head} ${r.key.provider}${act}${detail}`;
|
|
787
1006
|
}
|
|
788
1007
|
function formatRepoRow(r) {
|
|
789
|
-
const head = r.enabled ?
|
|
1008
|
+
const head = r.enabled ? pc2.green("enabled") : pc2.dim("disabled");
|
|
790
1009
|
const via = r.authType === "github_app" ? "github-app" : r.authType;
|
|
791
1010
|
const workflows = r.workflowPaths.length > 0 ? `${r.workflowPaths.length} workflow${r.workflowPaths.length === 1 ? "" : "s"}` : "no workflows yet";
|
|
792
|
-
const error = r.lastPollError ?
|
|
793
|
-
return `${head} ${safeTerm(r.fullName)} ${
|
|
1011
|
+
const error = r.lastPollError ? pc2.red(` poll error: ${safeTerm(r.lastPollError)}`) : "";
|
|
1012
|
+
return `${head} ${safeTerm(r.fullName)} ${pc2.dim(`${safeTerm(via)} \xB7 ${safeTerm(r.defaultBranch)} \xB7 ${workflows}`)}${error}`;
|
|
794
1013
|
}
|
|
795
1014
|
function printDiscovery(d) {
|
|
796
1015
|
if (d.error) {
|
|
797
|
-
console.log(
|
|
1016
|
+
console.log(pc2.yellow(`discovery: ${safeTerm(d.error)} (the poll cron retries)`));
|
|
798
1017
|
return;
|
|
799
1018
|
}
|
|
800
|
-
console.log(
|
|
1019
|
+
console.log(pc2.dim(`discovery: ${d.workflowsFound ? "workflows found" : "no workflows yet"}${d.seeded ? ", cursors seeded" : ""}`));
|
|
801
1020
|
}
|
|
802
1021
|
function dispatchBody(workflow, opts) {
|
|
803
1022
|
if (!workflow.dispatchable && !opts.manual) {
|
|
@@ -835,15 +1054,15 @@ function maxPriceFields(maxBid, maxBidPer) {
|
|
|
835
1054
|
throw new ActionsCliError("invalid_argument", "--max-bid-per requires --max-bid.");
|
|
836
1055
|
}
|
|
837
1056
|
if (maxBid === void 0) return void 0;
|
|
838
|
-
const
|
|
839
|
-
if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(maxBid) || !Number.isFinite(
|
|
1057
|
+
const usd = Number(maxBid);
|
|
1058
|
+
if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(maxBid) || !Number.isFinite(usd) || usd <= 0) {
|
|
840
1059
|
throw new ActionsCliError("invalid_argument", `Invalid --max-bid "${maxBid}". Expected a positive dollar amount (e.g. 0.12).`);
|
|
841
1060
|
}
|
|
842
1061
|
const per = maxBidPer ?? "second";
|
|
843
1062
|
if (per !== "second" && per !== "minute" && per !== "hour") {
|
|
844
1063
|
throw new ActionsCliError("invalid_argument", `--max-bid-per must be second, minute, or hour, got "${maxBidPer}".`);
|
|
845
1064
|
}
|
|
846
|
-
return { maxPriceUsd:
|
|
1065
|
+
return { maxPriceUsd: usd, maxPricePer: per };
|
|
847
1066
|
}
|
|
848
1067
|
function parseVaultKind(kind) {
|
|
849
1068
|
if (kind === void 0 || kind === "secret" || kind === "variable") return kind ?? "secret";
|
|
@@ -871,15 +1090,49 @@ function vaultSetBody(name, value, opts) {
|
|
|
871
1090
|
...opts.labels !== void 0 && opts.labels.length > 0 && { labels: opts.labels }
|
|
872
1091
|
};
|
|
873
1092
|
}
|
|
1093
|
+
function vaultDeliveryLabels(opts) {
|
|
1094
|
+
if (opts.proxy && opts.inject) {
|
|
1095
|
+
throw new ActionsCliError("invalid_argument", "--proxy and --inject are mutually exclusive.");
|
|
1096
|
+
}
|
|
1097
|
+
const hosts = (opts.hosts ?? []).flatMap((host) => host.split(/[\s,]+/)).map((host) => host.trim().toLowerCase()).filter((host) => host !== "");
|
|
1098
|
+
if (opts.inject) {
|
|
1099
|
+
if (hosts.length > 0) {
|
|
1100
|
+
throw new ActionsCliError(
|
|
1101
|
+
"invalid_argument",
|
|
1102
|
+
"--inject takes no --hosts \u2014 host rules only apply to --proxy."
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
return ["materialize"];
|
|
1106
|
+
}
|
|
1107
|
+
if (!opts.proxy) {
|
|
1108
|
+
throw new ActionsCliError("invalid_argument", "Pick a delivery: --proxy (with --hosts) or --inject.");
|
|
1109
|
+
}
|
|
1110
|
+
if (hosts.length === 0) {
|
|
1111
|
+
throw new ActionsCliError(
|
|
1112
|
+
"invalid_argument",
|
|
1113
|
+
"--proxy needs --hosts \u2014 the hosts the real value may be attached to."
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
return [`hosts:${hosts.join(",")}`];
|
|
1117
|
+
}
|
|
1118
|
+
function vaultSetLabels(opts) {
|
|
1119
|
+
const flagged = opts.proxy === true || opts.inject === true || (opts.hosts?.length ?? 0) > 0;
|
|
1120
|
+
if (flagged && (opts.labels?.length ?? 0) > 0) {
|
|
1121
|
+
throw new ActionsCliError("invalid_argument", "Use --labels or --proxy/--inject --hosts, not both.");
|
|
1122
|
+
}
|
|
1123
|
+
if (!flagged) return opts.labels;
|
|
1124
|
+
return vaultDeliveryLabels(opts);
|
|
1125
|
+
}
|
|
874
1126
|
function formatVaultRow(item) {
|
|
875
1127
|
const flags = [
|
|
876
1128
|
item.kind,
|
|
877
1129
|
...item.revealable && item.kind === "secret" ? ["revealable"] : [],
|
|
1130
|
+
...item.labels.map(safeTerm),
|
|
878
1131
|
`v${item.version}`,
|
|
879
1132
|
...item.source === "organization" ? ["inherited"] : [],
|
|
880
1133
|
...item.overridesOrganization ? ["overrides org"] : []
|
|
881
1134
|
];
|
|
882
|
-
return `${
|
|
1135
|
+
return `${pc2.cyan(safeTerm(item.name))} ${pc2.dim(flags.join(", "))} ${pc2.dim(`updated ${safeTerm(item.updatedAt)}`)}`;
|
|
883
1136
|
}
|
|
884
1137
|
function registerActionsCommands(program2) {
|
|
885
1138
|
const actions = program2.command("actions").alias("ci").description("Drive the benchmarks-platform Actions API").configureOutput({ outputError: usageErrorOutput });
|
|
@@ -909,7 +1162,7 @@ function registerActionsCommands(program2) {
|
|
|
909
1162
|
const org2 = await c.org();
|
|
910
1163
|
const url = `${c.baseUrl}/${org2.slug}/actions/runs/${result.runId}`;
|
|
911
1164
|
output(opts, { ...result, url }, (r) => {
|
|
912
|
-
console.log(`${r.created ? "dispatched" : "already running"} ${
|
|
1165
|
+
console.log(`${r.created ? "dispatched" : "already running"} ${pc2.cyan(r.runId)}`);
|
|
913
1166
|
console.log(`sha: ${r.headSha}`);
|
|
914
1167
|
console.log(`url: ${r.url}`);
|
|
915
1168
|
});
|
|
@@ -1029,7 +1282,7 @@ function registerActionsCommands(program2) {
|
|
|
1029
1282
|
if (opts.json) {
|
|
1030
1283
|
process.stdout.write(JSON.stringify({ jobId: job.id, name: job.name, slice }) + "\n");
|
|
1031
1284
|
} else {
|
|
1032
|
-
if (jobs.length > 1) console.log(
|
|
1285
|
+
if (jobs.length > 1) console.log(pc2.bold(`\u2500\u2500 ${job.name} \u2500\u2500`));
|
|
1033
1286
|
for (const seg of slice.segments) process.stdout.write(seg.text);
|
|
1034
1287
|
}
|
|
1035
1288
|
}
|
|
@@ -1093,7 +1346,7 @@ function registerActionsCommands(program2) {
|
|
|
1093
1346
|
`/api/v1/actions/providers/${provider}/verify`
|
|
1094
1347
|
) : void 0;
|
|
1095
1348
|
output(opts, verification ? { key: saved.key, verification } : saved, () => {
|
|
1096
|
-
console.log(`saved ${saved.key.provider} ${
|
|
1349
|
+
console.log(`saved ${saved.key.provider} ${pc2.dim(saved.key.keyHint)} ${saved.key.status}`);
|
|
1097
1350
|
if (verification) console.log(formatVerifyResult(verification));
|
|
1098
1351
|
});
|
|
1099
1352
|
if (verification?.verified === false) process.exitCode = 1;
|
|
@@ -1173,7 +1426,7 @@ function registerActionsCommands(program2) {
|
|
|
1173
1426
|
...opts.branch !== void 0 && { defaultBranch: opts.branch }
|
|
1174
1427
|
});
|
|
1175
1428
|
output(opts, result, (r) => {
|
|
1176
|
-
console.log(`connected ${
|
|
1429
|
+
console.log(`connected ${pc2.cyan(safeTerm(r.fullName))} ${pc2.dim(`(${safeTerm(r.authType)}, ${safeTerm(r.defaultBranch)})`)}`);
|
|
1177
1430
|
printDiscovery(r.discovery);
|
|
1178
1431
|
});
|
|
1179
1432
|
} catch (e) {
|
|
@@ -1190,7 +1443,7 @@ function registerActionsCommands(program2) {
|
|
|
1190
1443
|
...opts.repoId !== void 0 && { repoId: opts.repoId }
|
|
1191
1444
|
});
|
|
1192
1445
|
output(opts, result, (r) => {
|
|
1193
|
-
console.log(`enabled ${
|
|
1446
|
+
console.log(`enabled ${pc2.cyan(safeTerm(r.fullName))}`);
|
|
1194
1447
|
if (r.discovery) printDiscovery(r.discovery);
|
|
1195
1448
|
});
|
|
1196
1449
|
} catch (e) {
|
|
@@ -1206,7 +1459,7 @@ function registerActionsCommands(program2) {
|
|
|
1206
1459
|
enabled: false,
|
|
1207
1460
|
...opts.repoId !== void 0 && { repoId: opts.repoId }
|
|
1208
1461
|
});
|
|
1209
|
-
output(opts, result, (r) => console.log(`disabled ${
|
|
1462
|
+
output(opts, result, (r) => console.log(`disabled ${pc2.cyan(safeTerm(r.fullName))}`));
|
|
1210
1463
|
} catch (e) {
|
|
1211
1464
|
fail(e, opts);
|
|
1212
1465
|
}
|
|
@@ -1227,7 +1480,7 @@ function registerActionsCommands(program2) {
|
|
|
1227
1480
|
}
|
|
1228
1481
|
});
|
|
1229
1482
|
vaultScope(
|
|
1230
|
-
vault.command("set").description("Store a value, read from stdin (or --from-file) and sent exactly as read").argument("<name>", "item name, e.g. NPM_TOKEN").option("--from-file <path>", "read the value from a file instead of stdin").option("--revealable", "let the value be read back with `vault get` (secrets; fixed at creation)").option("--description <text>", "what the item is for").option("--labels <labels...>", "labels (fixed at creation)")
|
|
1483
|
+
vault.command("set").description("Store a value, read from stdin (or --from-file) and sent exactly as read").argument("<name>", "item name, e.g. NPM_TOKEN").option("--from-file <path>", "read the value from a file instead of stdin").option("--revealable", "let the value be read back with `vault get` (secrets; fixed at creation)").option("--description <text>", "what the item is for").option("--labels <labels...>", "labels (fixed at creation)").option("--proxy", "hand the job a placeholder; the value is attached to requests for --hosts at egress").option("--inject", "inject the real value into the job environment (the default)").option("--hosts <hosts...>", "hosts the proxied value may be attached to (comma or space separated, *.example.com covers subdomains)")
|
|
1231
1484
|
).action(async (name, opts) => {
|
|
1232
1485
|
try {
|
|
1233
1486
|
if (opts.fromFile === void 0 && process.stdin.isTTY) {
|
|
@@ -1238,16 +1491,17 @@ function registerActionsCommands(program2) {
|
|
|
1238
1491
|
}
|
|
1239
1492
|
const value = readFileSync(opts.fromFile ?? 0, "utf8");
|
|
1240
1493
|
const kind = parseVaultKind(opts.kind);
|
|
1241
|
-
const
|
|
1494
|
+
const labels = vaultSetLabels(opts);
|
|
1495
|
+
const body = vaultSetBody(name, value, { ...opts, kind, labels });
|
|
1242
1496
|
const result = await (await vaultValueClient(opts)).put(
|
|
1243
1497
|
vaultPath("/api/v1/vault", { repo: opts.repo }),
|
|
1244
1498
|
body
|
|
1245
1499
|
);
|
|
1246
1500
|
output(opts, result, (r) => {
|
|
1247
1501
|
const where = opts.repo ? safeTerm(opts.repo) : "org";
|
|
1248
|
-
console.log(`saved ${
|
|
1502
|
+
console.log(`saved ${pc2.cyan(safeTerm(r.item.name))} ${pc2.dim(`(${r.item.kind}, v${r.item.version}, ${where})`)}`);
|
|
1249
1503
|
if (/\r?\n$/.test(value)) {
|
|
1250
|
-
console.error(
|
|
1504
|
+
console.error(pc2.yellow("note: the stored value ends with a newline; use printf %s rather than echo to avoid one."));
|
|
1251
1505
|
}
|
|
1252
1506
|
});
|
|
1253
1507
|
} catch (e) {
|
|
@@ -1268,13 +1522,33 @@ function registerActionsCommands(program2) {
|
|
|
1268
1522
|
fail(e, opts);
|
|
1269
1523
|
}
|
|
1270
1524
|
});
|
|
1525
|
+
vaultScope(
|
|
1526
|
+
vault.command("delivery").description("Reclassify how a secret reaches a job \u2014 labels only, no value needed").argument("<name>", "item name").option("--proxy", "hand the job a placeholder; the value is attached to requests for --hosts at egress").option("--inject", "inject the real value into the job environment").option("--hosts <hosts...>", "hosts the proxied value may be attached to (comma or space separated, *.example.com covers subdomains)")
|
|
1527
|
+
).action(async (name, opts) => {
|
|
1528
|
+
try {
|
|
1529
|
+
const kind = parseVaultKind(opts.kind);
|
|
1530
|
+
const labels = vaultDeliveryLabels(opts);
|
|
1531
|
+
const result = await (await client(opts)).patch(
|
|
1532
|
+
vaultPath("/api/v1/vault", { repo: opts.repo }),
|
|
1533
|
+
{ name, kind, labels }
|
|
1534
|
+
);
|
|
1535
|
+
output(opts, result, (r) => {
|
|
1536
|
+
const where = opts.repo ? safeTerm(opts.repo) : "org";
|
|
1537
|
+
console.log(
|
|
1538
|
+
`reclassified ${pc2.cyan(safeTerm(r.item.name))} ${pc2.dim(`(labels: ${r.item.labels.join(", ") || "none"}, v${r.item.version}, ${where})`)}`
|
|
1539
|
+
);
|
|
1540
|
+
});
|
|
1541
|
+
} catch (e) {
|
|
1542
|
+
fail(e, opts);
|
|
1543
|
+
}
|
|
1544
|
+
});
|
|
1271
1545
|
vaultScope(
|
|
1272
1546
|
vault.command("rm").description("Delete an item (with --repo, only the repo's override)").argument("<name>", "item name")
|
|
1273
1547
|
).action(async (name, opts) => {
|
|
1274
1548
|
try {
|
|
1275
1549
|
const path = vaultPath("/api/v1/vault", { repo: opts.repo, kind: parseVaultKind(opts.kind), name });
|
|
1276
1550
|
const result = await (await client(opts)).del(path);
|
|
1277
|
-
output(opts, result, (r) => console.log(`deleted ${
|
|
1551
|
+
output(opts, result, (r) => console.log(`deleted ${pc2.cyan(safeTerm(r.name))} ${pc2.dim(`(${r.kind})`)}`));
|
|
1278
1552
|
} catch (e) {
|
|
1279
1553
|
fail(e, opts);
|
|
1280
1554
|
}
|
|
@@ -1304,7 +1578,7 @@ function registerActionsCommands(program2) {
|
|
|
1304
1578
|
const org2 = await c.org();
|
|
1305
1579
|
const url = `${c.baseUrl}/${org2.slug}/actions/runs/${result.runId}`;
|
|
1306
1580
|
output(opts, { ...result, url }, (r) => {
|
|
1307
|
-
console.log(`${r.created ? "rerun dispatched" : "rerun already running"} ${
|
|
1581
|
+
console.log(`${r.created ? "rerun dispatched" : "rerun already running"} ${pc2.cyan(r.runId)}`);
|
|
1308
1582
|
console.log(`url: ${r.url}`);
|
|
1309
1583
|
});
|
|
1310
1584
|
} catch (e) {
|
|
@@ -1367,10 +1641,16 @@ function registerActionsCommands(program2) {
|
|
|
1367
1641
|
fail(e, opts);
|
|
1368
1642
|
}
|
|
1369
1643
|
});
|
|
1644
|
+
registerSettingsCommands(actions, "actions", common, {
|
|
1645
|
+
client,
|
|
1646
|
+
fail,
|
|
1647
|
+
output,
|
|
1648
|
+
usageErrorOutput
|
|
1649
|
+
});
|
|
1370
1650
|
}
|
|
1371
1651
|
|
|
1372
1652
|
// src/market.ts
|
|
1373
|
-
import
|
|
1653
|
+
import pc3 from "picocolors";
|
|
1374
1654
|
var USD_RE = /^\d+(\.\d+)?([eE][+-]?\d+)?$/;
|
|
1375
1655
|
var RATE_UNITS = ["second", "minute", "hour"];
|
|
1376
1656
|
var MARKET_LANES = ["actions", "sandbox"];
|
|
@@ -1402,8 +1682,8 @@ function parseRate(price, per) {
|
|
|
1402
1682
|
}
|
|
1403
1683
|
unit = inline;
|
|
1404
1684
|
}
|
|
1405
|
-
const
|
|
1406
|
-
if (!USD_RE.test(usdText) || !Number.isFinite(
|
|
1685
|
+
const usd = Number(usdText);
|
|
1686
|
+
if (!USD_RE.test(usdText) || !Number.isFinite(usd) || usd <= 0) {
|
|
1407
1687
|
throw new ActionsCliError(
|
|
1408
1688
|
"invalid_argument",
|
|
1409
1689
|
`Invalid --price "${price}". Expected a positive dollar amount (e.g. 0.12/hour).`
|
|
@@ -1421,7 +1701,7 @@ function parseRate(price, per) {
|
|
|
1421
1701
|
`The unit must be second, minute, or hour, got "${unit}".`
|
|
1422
1702
|
);
|
|
1423
1703
|
}
|
|
1424
|
-
return { usd
|
|
1704
|
+
return { usd, per: unit };
|
|
1425
1705
|
}
|
|
1426
1706
|
function parseCapacity(value) {
|
|
1427
1707
|
if (value === void 0) return void 0;
|
|
@@ -1524,20 +1804,17 @@ function credentialBody(fields, values) {
|
|
|
1524
1804
|
}
|
|
1525
1805
|
return { fields: values };
|
|
1526
1806
|
}
|
|
1527
|
-
function
|
|
1528
|
-
return
|
|
1529
|
-
}
|
|
1530
|
-
function formatRate(usd2, per) {
|
|
1531
|
-
return `${formatUsd(usd2)}/${per}`;
|
|
1807
|
+
function formatRate(usd, per) {
|
|
1808
|
+
return formatUsdPer({ usd, per });
|
|
1532
1809
|
}
|
|
1533
1810
|
function formatListingStatus(ask) {
|
|
1534
1811
|
let label;
|
|
1535
|
-
if (ask.status === "withdrawn") label =
|
|
1536
|
-
else if (ask.status === "paused") label =
|
|
1537
|
-
else if (!ask.live) label =
|
|
1538
|
-
else label =
|
|
1812
|
+
if (ask.status === "withdrawn") label = pc3.gray("withdrawn");
|
|
1813
|
+
else if (ask.status === "paused") label = pc3.yellow("paused");
|
|
1814
|
+
else if (!ask.live) label = pc3.gray("expired");
|
|
1815
|
+
else label = pc3.green("live");
|
|
1539
1816
|
if (ask.pendingUsd !== null && ask.pendingPer !== null) {
|
|
1540
|
-
label +=
|
|
1817
|
+
label += pc3.dim(` \u2192 ${formatRate(ask.pendingUsd, ask.pendingPer)} next window`);
|
|
1541
1818
|
}
|
|
1542
1819
|
return label;
|
|
1543
1820
|
}
|
|
@@ -1546,22 +1823,22 @@ function formatListingRow(ask) {
|
|
|
1546
1823
|
return [
|
|
1547
1824
|
ask.id,
|
|
1548
1825
|
formatListingStatus(ask),
|
|
1549
|
-
|
|
1826
|
+
pc3.dim(ask.useCase === "sandbox" ? "sandbox" : "actions"),
|
|
1550
1827
|
safeTerm(ask.size),
|
|
1551
1828
|
safeTerm(ask.region ?? "-"),
|
|
1552
1829
|
formatRate(ask.usd, ask.per),
|
|
1553
|
-
|
|
1554
|
-
|
|
1830
|
+
pc3.dim(`\xD7${ask.maxConcurrent}`),
|
|
1831
|
+
pc3.dim(expiry)
|
|
1555
1832
|
].join(" ");
|
|
1556
1833
|
}
|
|
1557
1834
|
function formatProviderStatus(p2) {
|
|
1558
1835
|
const lines = [];
|
|
1559
|
-
lines.push(`${
|
|
1836
|
+
lines.push(`${pc3.bold(safeTerm(p2.name))} ${pc3.dim(`selling ${safeTerm(p2.provider)}`)}`);
|
|
1560
1837
|
lines.push(`id: ${p2.id}`);
|
|
1561
1838
|
lines.push(
|
|
1562
|
-
`credential: ${p2.executorCredentialConnected ?
|
|
1839
|
+
`credential: ${p2.executorCredentialConnected ? pc3.green("connected") : pc3.yellow("not connected \u2014 your listings cannot fill until `compute market credential connect`")}`
|
|
1563
1840
|
);
|
|
1564
|
-
if (p2.revokedAt) lines.push(
|
|
1841
|
+
if (p2.revokedAt) lines.push(pc3.red(`revoked: ${p2.revokedAt}`));
|
|
1565
1842
|
lines.push(
|
|
1566
1843
|
`lanes: ${(p2.useCases ?? ["actions"]).join(", ")}`
|
|
1567
1844
|
);
|
|
@@ -1579,41 +1856,41 @@ function formatProviderStatus(p2) {
|
|
|
1579
1856
|
}
|
|
1580
1857
|
function formatBook(book) {
|
|
1581
1858
|
const lines = [];
|
|
1582
|
-
const lane = (useCase) =>
|
|
1583
|
-
lines.push(
|
|
1584
|
-
if (book.asks.length === 0) lines.push(
|
|
1859
|
+
const lane = (useCase) => pc3.dim(useCase === "sandbox" ? "sandbox" : "actions");
|
|
1860
|
+
lines.push(pc3.bold("sellers' asking prices"));
|
|
1861
|
+
if (book.asks.length === 0) lines.push(pc3.dim(" no listings are live"));
|
|
1585
1862
|
for (const ask of book.asks) {
|
|
1586
1863
|
const where = ask.region ? safeTerm(ask.region) : "any region";
|
|
1587
|
-
const expiry = ask.expiresAt ?
|
|
1864
|
+
const expiry = ask.expiresAt ? pc3.dim(ask.rollover ? ` renews ${ask.expiresAt}` : ` until ${ask.expiresAt}`) : "";
|
|
1588
1865
|
lines.push(
|
|
1589
1866
|
` ${lane(ask.useCase)} ${formatRate(ask.usd, ask.per)} ${safeTerm(ask.providerName)} ${safeTerm(ask.size)} ${where} up to ${ask.maxConcurrent} at once${expiry}`
|
|
1590
1867
|
);
|
|
1591
1868
|
}
|
|
1592
1869
|
lines.push("");
|
|
1593
|
-
lines.push(
|
|
1594
|
-
if (book.bids.length === 0) lines.push(
|
|
1870
|
+
lines.push(pc3.bold("buyer offers"));
|
|
1871
|
+
if (book.bids.length === 0) lines.push(pc3.dim(" no open offers"));
|
|
1595
1872
|
for (const bid of book.bids) {
|
|
1596
1873
|
const where = bid.region ? safeTerm(bid.region) : "anywhere";
|
|
1597
|
-
const yours = bid.mine ?
|
|
1874
|
+
const yours = bid.mine ? pc3.cyan(" (yours)") : "";
|
|
1598
1875
|
lines.push(
|
|
1599
|
-
` ${lane(bid.useCase)} pays up to ${formatRate(bid.maxUsd, bid.per)} ${safeTerm(bid.size)} ${where} ${
|
|
1876
|
+
` ${lane(bid.useCase)} pays up to ${formatRate(bid.maxUsd, bid.per)} ${safeTerm(bid.size)} ${where} ${pc3.dim(`posted ${bid.createdAt}`)}${yours}`
|
|
1600
1877
|
);
|
|
1601
1878
|
}
|
|
1602
1879
|
lines.push("");
|
|
1603
|
-
lines.push(
|
|
1604
|
-
if (book.fills.length === 0) lines.push(
|
|
1880
|
+
lines.push(pc3.bold("recent sales"));
|
|
1881
|
+
if (book.fills.length === 0) lines.push(pc3.dim(" nothing has sold yet"));
|
|
1605
1882
|
for (const fill of book.fills) {
|
|
1606
|
-
const statusNote = fill.status === "replaced" ?
|
|
1883
|
+
const statusNote = fill.status === "replaced" ? pc3.yellow(" replaced") : fill.status === "closed" ? pc3.gray(" closed") : "";
|
|
1607
1884
|
lines.push(
|
|
1608
|
-
` ${
|
|
1885
|
+
` ${pc3.dim(fill.id)} ${lane(fill.useCase)} ${formatRate(fill.usd, fill.per)} ${safeTerm(fill.provider)} ${safeTerm(fill.size)} ${safeTerm(fill.region ?? "-")} ${pc3.dim(fill.createdAt)}${statusNote}`
|
|
1609
1886
|
);
|
|
1610
1887
|
}
|
|
1611
1888
|
return lines.join("\n");
|
|
1612
1889
|
}
|
|
1613
1890
|
function formatReplacedFill(fill) {
|
|
1614
|
-
const settled =
|
|
1615
|
-
const job = fill.jobRequeued ?
|
|
1616
|
-
return `replaced ${
|
|
1891
|
+
const settled = formatMoney(fill.settledMicroUsd / 1e6);
|
|
1892
|
+
const job = fill.jobRequeued ? pc3.dim(" \u2014 job re-places on the buyer's next provider") : "";
|
|
1893
|
+
return `replaced ${pc3.cyan(fill.fillId)} settled ${settled}${job}`;
|
|
1617
1894
|
}
|
|
1618
1895
|
function replaceTarget(listingId, fillId) {
|
|
1619
1896
|
if (fillId !== void 0) {
|
|
@@ -1635,12 +1912,12 @@ function replaceTarget(listingId, fillId) {
|
|
|
1635
1912
|
}
|
|
1636
1913
|
function formatSettlementRow(s) {
|
|
1637
1914
|
const period = `${s.periodStart.slice(0, 10)} \u2192 ${s.periodEnd.slice(0, 10)}`;
|
|
1638
|
-
const paid = s.paidAt ?
|
|
1915
|
+
const paid = s.paidAt ? pc3.green(`paid ${s.paidAt.slice(0, 10)}`) : s.invoiceRef ? pc3.yellow(`invoiced ${safeTerm(s.invoiceRef)}`) : pc3.dim("unpaid");
|
|
1639
1916
|
return [
|
|
1640
|
-
|
|
1917
|
+
pc3.dim(period),
|
|
1641
1918
|
`${s.vcpuSeconds.toLocaleString("en-US")} vCPU\xB7s`,
|
|
1642
|
-
`gross ${
|
|
1643
|
-
`net ${
|
|
1919
|
+
`gross ${formatMoney(s.grossUsd)}`,
|
|
1920
|
+
`net ${formatMoney(s.netUsd)}`,
|
|
1644
1921
|
paid
|
|
1645
1922
|
].join(" ");
|
|
1646
1923
|
}
|
|
@@ -1684,14 +1961,14 @@ function registerMarketCommands(program2) {
|
|
|
1684
1961
|
);
|
|
1685
1962
|
}
|
|
1686
1963
|
size = preset.name;
|
|
1687
|
-
console.error(
|
|
1964
|
+
console.error(pc3.dim(`no --size given \u2014 listing at "${size}"`));
|
|
1688
1965
|
}
|
|
1689
1966
|
const result = await c.post(
|
|
1690
1967
|
"/api/v1/market/asks",
|
|
1691
1968
|
sellBody({ ...opts, size, useCase })
|
|
1692
1969
|
);
|
|
1693
1970
|
output(opts, result, (r) => {
|
|
1694
|
-
console.log(`listed ${
|
|
1971
|
+
console.log(`listed ${pc3.cyan(r.ask.id)}`);
|
|
1695
1972
|
console.log(formatListingRow(r.ask));
|
|
1696
1973
|
});
|
|
1697
1974
|
} catch (e) {
|
|
@@ -1707,8 +1984,8 @@ function registerMarketCommands(program2) {
|
|
|
1707
1984
|
listingPatchBody(listingId, { price: opts.price, per: opts.per })
|
|
1708
1985
|
);
|
|
1709
1986
|
output(opts, result, (r) => {
|
|
1710
|
-
const rate = r.ask.pendingUsd !== null && r.ask.pendingPer !== null ? `${formatRate(r.ask.pendingUsd, r.ask.pendingPer)} ${
|
|
1711
|
-
console.log(`repriced ${
|
|
1987
|
+
const rate = r.ask.pendingUsd !== null && r.ask.pendingPer !== null ? `${formatRate(r.ask.pendingUsd, r.ask.pendingPer)} ${pc3.dim("(applies next window)")}` : formatRate(r.ask.usd, r.ask.per);
|
|
1988
|
+
console.log(`repriced ${pc3.cyan(r.ask.id)} ${rate}`);
|
|
1712
1989
|
});
|
|
1713
1990
|
} catch (e) {
|
|
1714
1991
|
fail(e, opts);
|
|
@@ -1721,7 +1998,7 @@ function registerMarketCommands(program2) {
|
|
|
1721
1998
|
listingPatchBody(listingId, { status })
|
|
1722
1999
|
);
|
|
1723
2000
|
output(opts, result, (r) => {
|
|
1724
|
-
console.log(`${status === "live" ? "resumed" : "paused"} ${
|
|
2001
|
+
console.log(`${status === "live" ? "resumed" : "paused"} ${pc3.cyan(r.ask.id)}`);
|
|
1725
2002
|
});
|
|
1726
2003
|
} catch (e) {
|
|
1727
2004
|
fail(e, opts);
|
|
@@ -1741,7 +2018,7 @@ function registerMarketCommands(program2) {
|
|
|
1741
2018
|
`/api/v1/market/asks?id=${encodeURIComponent(listingId)}`
|
|
1742
2019
|
);
|
|
1743
2020
|
output(opts, result, (r) => {
|
|
1744
|
-
console.log(`withdrew ${
|
|
2021
|
+
console.log(`withdrew ${pc3.cyan(r.ask.id)}`);
|
|
1745
2022
|
});
|
|
1746
2023
|
} catch (e) {
|
|
1747
2024
|
fail(e, opts);
|
|
@@ -1762,14 +2039,14 @@ function registerMarketCommands(program2) {
|
|
|
1762
2039
|
} else {
|
|
1763
2040
|
const result = await c.post(target.path, {});
|
|
1764
2041
|
output(opts, result, (r) => {
|
|
1765
|
-
console.log(`paused ${
|
|
2042
|
+
console.log(`paused ${pc3.cyan(r.listing.id)}`);
|
|
1766
2043
|
if (r.fills.length === 0) {
|
|
1767
|
-
console.log(
|
|
2044
|
+
console.log(pc3.dim(" no live sales to evict"));
|
|
1768
2045
|
return;
|
|
1769
2046
|
}
|
|
1770
2047
|
for (const f of r.fills) {
|
|
1771
2048
|
if (f.ok) console.log(formatReplacedFill(f.fill));
|
|
1772
|
-
else console.log(
|
|
2049
|
+
else console.log(pc3.red(` could not evict a sale \u2014 ${f.error}`));
|
|
1773
2050
|
}
|
|
1774
2051
|
});
|
|
1775
2052
|
if (result.fills.some((f) => !f.ok)) process.exitCode = 1;
|
|
@@ -1850,7 +2127,7 @@ ${hints}`
|
|
|
1850
2127
|
}
|
|
1851
2128
|
if (resolved.fromFlag.some((name) => provider.credentialFields.find((f) => f.name === name)?.secret)) {
|
|
1852
2129
|
console.error(
|
|
1853
|
-
|
|
2130
|
+
pc3.yellow("note: a secret passed via --field stays in your shell history \u2014 prefer the env vars.")
|
|
1854
2131
|
);
|
|
1855
2132
|
}
|
|
1856
2133
|
const result = await c.post(
|
|
@@ -1858,7 +2135,7 @@ ${hints}`
|
|
|
1858
2135
|
credentialBody(provider.credentialFields, resolved.values)
|
|
1859
2136
|
);
|
|
1860
2137
|
output(opts, result, (r) => {
|
|
1861
|
-
console.log(`connected ${
|
|
2138
|
+
console.log(`connected ${pc3.cyan(safeTerm(r.provider.name))} credential saved`);
|
|
1862
2139
|
});
|
|
1863
2140
|
} catch (e) {
|
|
1864
2141
|
fail(e, opts);
|
|
@@ -1872,7 +2149,7 @@ ${hints}`
|
|
|
1872
2149
|
"/api/v1/market/provider/credential"
|
|
1873
2150
|
);
|
|
1874
2151
|
output(opts, result, (r) => {
|
|
1875
|
-
console.log(`disconnected ${
|
|
2152
|
+
console.log(`disconnected ${pc3.cyan(safeTerm(r.provider.name))} credential removed`);
|
|
1876
2153
|
});
|
|
1877
2154
|
} catch (e) {
|
|
1878
2155
|
fail(e, opts);
|
|
@@ -1881,50 +2158,23 @@ ${hints}`
|
|
|
1881
2158
|
}
|
|
1882
2159
|
|
|
1883
2160
|
// src/sandboxes.ts
|
|
1884
|
-
import
|
|
1885
|
-
function parseMaxPrice(value, per) {
|
|
1886
|
-
if (value === void 0) {
|
|
1887
|
-
if (per !== void 0) throw new Error("--max-price-per requires --max-price.");
|
|
1888
|
-
return void 0;
|
|
1889
|
-
}
|
|
1890
|
-
let usdText = value;
|
|
1891
|
-
let unit = per;
|
|
1892
|
-
const slash = value.indexOf("/");
|
|
1893
|
-
if (slash !== -1) {
|
|
1894
|
-
usdText = value.slice(0, slash);
|
|
1895
|
-
const inline = value.slice(slash + 1);
|
|
1896
|
-
if (per !== void 0 && per !== inline) {
|
|
1897
|
-
throw new Error(`--max-price "${value}" conflicts with --max-price-per "${per}".`);
|
|
1898
|
-
}
|
|
1899
|
-
unit = inline;
|
|
1900
|
-
}
|
|
1901
|
-
const usd2 = Number(usdText);
|
|
1902
|
-
if (!/^\d+(\.\d+)?([eE][+-]?\d+)?$/.test(usdText) || !Number.isFinite(usd2) || usd2 <= 0) {
|
|
1903
|
-
throw new Error(`Invalid --max-price "${value}". Expected a positive dollar amount like 0.12/hour.`);
|
|
1904
|
-
}
|
|
1905
|
-
if (unit !== "second" && unit !== "minute" && unit !== "hour") {
|
|
1906
|
-
throw new Error(
|
|
1907
|
-
"--max-price needs a unit \u2014 write it as <usd>/<unit> (e.g. --max-price 0.12/hour) or pass --max-price-per hour."
|
|
1908
|
-
);
|
|
1909
|
-
}
|
|
1910
|
-
return { usd: usd2, per: unit };
|
|
1911
|
-
}
|
|
2161
|
+
import pc4 from "picocolors";
|
|
1912
2162
|
function shellQuote(arg) {
|
|
1913
2163
|
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
1914
2164
|
}
|
|
1915
2165
|
function printSandbox(s) {
|
|
1916
2166
|
const attach = "attach" in s ? s.attach : void 0;
|
|
1917
|
-
console.log(`${
|
|
2167
|
+
console.log(`${pc4.cyan(s.id)} ${s.status} ${s.provider ?? "\u2014"} ${s.providerSandboxId ?? "\u2014"}`);
|
|
1918
2168
|
console.log(` label: ${s.label ?? "\u2014"} commands: ${s.commandCount} created: ${s.createdAt}`);
|
|
1919
2169
|
if (s.image !== void 0) {
|
|
1920
|
-
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${
|
|
2170
|
+
console.log(` image: ${s.image ?? "\u2014"}${s.requestedImage !== null && s.requestedImage !== s.image ? ` ${pc4.dim(`(requested: ${s.requestedImage})`)}` : ""}`);
|
|
1921
2171
|
}
|
|
1922
|
-
if (s.destroyError) console.log(` destroyError: ${
|
|
2172
|
+
if (s.destroyError) console.log(` destroyError: ${pc4.red(s.destroyError)}`);
|
|
1923
2173
|
if (s.placement) {
|
|
1924
2174
|
const p2 = s.placement;
|
|
1925
2175
|
const box = p2.box ? ` / ${p2.box.sizeName ?? "custom"}${p2.box.resources ? ` (${p2.box.resources.cpus ?? "?"} vCPU / ${p2.box.resources.memoryMb ?? "?"} MB)` : ""}` : "";
|
|
1926
2176
|
console.log(
|
|
1927
|
-
` provider: ${p2.box?.provider ?? s.provider ?? "\u2014"}${box} size: ${p2.size ?? "\u2014"} order: ${p2.orderType ?? "\u2014"} rate:
|
|
2177
|
+
` provider: ${p2.box?.provider ?? s.provider ?? "\u2014"}${box} size: ${p2.size ?? "\u2014"} order: ${p2.orderType ?? "\u2014"} rate: ${formatUsdPer(p2.rate)}${p2.maxPrice ? ` max price: ${formatUsdPer(p2.maxPrice)}` : ""}`
|
|
1928
2178
|
);
|
|
1929
2179
|
}
|
|
1930
2180
|
if (attach !== void 0) {
|
|
@@ -1933,35 +2183,39 @@ function printSandbox(s) {
|
|
|
1933
2183
|
);
|
|
1934
2184
|
}
|
|
1935
2185
|
}
|
|
1936
|
-
var
|
|
2186
|
+
var perHour = (n) => n === void 0 ? "\u2014" : formatRateAllUnits(rateAllUnits({ usd: n, per: "hour" }));
|
|
2187
|
+
var usdAmount = (n) => n === void 0 ? "\u2014" : formatMoney(n);
|
|
1937
2188
|
function printQuote(q, timeoutMs) {
|
|
1938
|
-
console.log(`quote: ${q.ok ?
|
|
2189
|
+
console.log(`quote: ${q.ok ? pc4.green("ok") : pc4.red(q.reason ?? "unfillable")}`);
|
|
1939
2190
|
const box = q.placement?.box;
|
|
1940
2191
|
console.log(
|
|
1941
2192
|
` 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` : ""})` : "")
|
|
1942
2193
|
);
|
|
1943
2194
|
console.log(` order type: ${q.orderType} order: ${q.providerOrder.join(", ")}`);
|
|
1944
2195
|
if (q.rateUsd) {
|
|
1945
|
-
console.log(` rate: ${
|
|
2196
|
+
console.log(` rate: ${formatRateAllUnits(q.rateUsd)}`);
|
|
1946
2197
|
} else if (q.rate) {
|
|
1947
|
-
console.log(` rate:
|
|
2198
|
+
console.log(` rate: ${formatUsdPer(q.rate)}`);
|
|
1948
2199
|
}
|
|
2200
|
+
console.log(` cheapest live: ${perHour(q.cheapestLiveUsdPerHour)}`);
|
|
2201
|
+
console.log(` reference: ${perHour(q.referenceUsdPerHour)}`);
|
|
1949
2202
|
const timeout = timeoutMs !== void 0 ? ` for ${timeoutMs}ms` : "";
|
|
1950
|
-
console.log(` est. cost${timeout}: ${usd(q.estimatedCostUsd)} required hold: ${usd(q.requiredHoldUsd)}`);
|
|
1951
2203
|
console.log(
|
|
1952
|
-
`
|
|
2204
|
+
` est. cost${timeout}: ${usdAmount(q.estimatedCostUsd)} required hold: ${usdAmount(q.requiredHoldUsd)} balance: ${usdAmount(q.creditBalanceUsd)}`
|
|
1953
2205
|
);
|
|
1954
|
-
|
|
1955
|
-
|
|
2206
|
+
console.log(` cap: ${q.maxPrice ? formatUsdPer(q.maxPrice) : perHour(q.marketCapUsdPerHour)}`);
|
|
2207
|
+
console.log(` protection limit: ${perHour(q.protectionLimitUsdPerHour)}`);
|
|
2208
|
+
if (!q.ok && q.topUpPath) console.log(` ${pc4.dim(`\u2192 ${q.topUpPath}`)}`);
|
|
2209
|
+
if (q.liveAskDepth !== void 0) console.log(` ${pc4.dim(`live asks: ${q.liveAskDepth}`)}`);
|
|
1956
2210
|
}
|
|
1957
2211
|
function printProcess(p2) {
|
|
1958
2212
|
const exit = p2.status === "exited" ? `exit=${p2.exitCode ?? "?"}${p2.signal ? ` (${p2.signal})` : ""}` : "";
|
|
1959
2213
|
const stdin = p2.stdin && p2.status === "running" ? " [stdin open]" : "";
|
|
1960
|
-
console.log(`${
|
|
2214
|
+
console.log(`${pc4.cyan(p2.jobId)} ${p2.status}${exit ? " " + exit : ""}${stdin} ${p2.command}`);
|
|
1961
2215
|
}
|
|
1962
2216
|
function printSnapshot(s) {
|
|
1963
|
-
const state = s.deletedAt !== null ? ` ${
|
|
1964
|
-
console.log(`${
|
|
2217
|
+
const state = s.deletedAt !== null ? ` ${pc4.dim(`(deleted ${s.deletedAt})`)}` : "";
|
|
2218
|
+
console.log(`${pc4.cyan(s.id)} ${s.providerSnapshotId}${state}`);
|
|
1965
2219
|
console.log(
|
|
1966
2220
|
` provider: ${s.provider}${s.region ? ` (${s.region})` : ""} label: ${s.label ?? "\u2014"} created: ${s.createdAt}${s.expiresAt ? ` expires: ${s.expiresAt}` : ""}`
|
|
1967
2221
|
);
|
|
@@ -2042,7 +2296,7 @@ function mergeLeadOpts(opts, inline) {
|
|
|
2042
2296
|
}
|
|
2043
2297
|
function registerSandboxesCommands(program2) {
|
|
2044
2298
|
const cmd = program2.command("sandboxes").alias("sbx").description("Create and drive sandboxes through the platform").enablePositionalOptions().configureOutput({ outputError: usageErrorOutput });
|
|
2045
|
-
cmd.command("create").description('Place a sandbox (provider order walks 1,2,3; "market" bids first)').option("--order <providers>", 'provider order, comma-separated (e.g. "market,blaxel,vercel")').option("--size <size>", "platform size: small (1 vCPU/2 GB), medium, large, xlarge (8/16 GB); default medium").option("--label <label>", "label for the sandbox").option("--image <image>", "container image to boot").option("--snapshot-id <id>", "provider snapshot to resume").option("--cpus <n>", "CPU cores (raw resources \u2014 mutually exclusive with --size)").option("--memory-mb <n>", "memory in MB (raw resources)").option("--disk-mb <n>", "ephemeral disk in MB (raw resources)").option("--max-price <usd/unit>", "max price for a market fill (e.g. 0.12/hour); makes the create a limit order").option("--max-price-per <unit>", "unit for a bare --max-price usd (second, minute, or hour)").option("--market", 'place the create on the compute market (order type "market")').option("--order-type <type>", "explicit market order type: market or limit").option("--timeout-ms <ms>", "sandbox timeout in ms").option("--secret <name>", "vault secret name to inject (repeatable)", (v, a) => a.concat(v), []).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("--json", "print the raw response").action(async (opts) => {
|
|
2299
|
+
cmd.command("create").description('Place a sandbox (provider order walks 1,2,3; "market" bids first)').option("--order <providers>", 'provider order, comma-separated (e.g. "market,blaxel,vercel")').option("--size <size>", "platform size: small (1 vCPU/2 GB), medium, large, xlarge (8/16 GB); default medium").option("--label <label>", "label for the sandbox").option("--image <image>", "container image to boot").option("--snapshot-id <id>", "provider snapshot to resume").option("--cpus <n>", "CPU cores (raw resources \u2014 mutually exclusive with --size)").option("--memory-mb <n>", "memory in MB (raw resources)").option("--disk-mb <n>", "ephemeral disk in MB (raw resources)").option("--max-price <usd/unit>", "max price for a market fill (e.g. 0.12/hour); makes the create a limit order").option("--max-price-per <unit>", "unit for a bare --max-price usd (second, minute, or hour)").option("--market", 'place the create on the compute market (order type "market")').option("--order-type <type>", "explicit market order type: market or limit").option("--timeout-ms <ms>", "sandbox timeout in ms (provider minimums apply, e.g. blaxel \u22655m)").option("--secret <name>", "vault secret name to inject (repeatable)", (v, a) => a.concat(v), []).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("--json", "print the raw response").action(async (opts) => {
|
|
2046
2300
|
try {
|
|
2047
2301
|
const c = await client(opts);
|
|
2048
2302
|
const resources = {};
|
|
@@ -2071,7 +2325,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2071
2325
|
fail(e, opts);
|
|
2072
2326
|
}
|
|
2073
2327
|
});
|
|
2074
|
-
cmd.command("quote").description("Quote a sandbox create: placement, rate, caps and credits \u2014 creates nothing").option("--size <size>", "platform size (or raw resource flags; default medium)").option("--cpus <n>", "CPU cores").option("--memory-mb <n>", "memory in MB").option("--disk-mb <n>", "ephemeral disk in MB").option("--region <region>", "pin the placement region").option("--timeout-ms <ms>", "sandbox timeout in ms").option("--order-type <type>", "market order type: market or limit").option("--market", "quote a market order (fills at the live price, protection-bounded)").option("--max-price <usd/unit>", "max price for a market fill (e.g. 0.12/hour)").option("--max-price-per <unit>", "unit for a bare --max-price usd (second, minute, or hour)").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (opts) => {
|
|
2328
|
+
cmd.command("quote").description("Quote a sandbox create: placement, rate, caps and credits \u2014 creates nothing").option("--size <size>", "platform size (or raw resource flags; default medium)").option("--cpus <n>", "CPU cores").option("--memory-mb <n>", "memory in MB").option("--disk-mb <n>", "ephemeral disk in MB").option("--region <region>", "pin the placement region").option("--timeout-ms <ms>", "sandbox timeout in ms (provider minimums apply, e.g. blaxel \u22655m)").option("--order-type <type>", "market order type: market or limit").option("--market", "quote a market order (fills at the live price, protection-bounded)").option("--max-price <usd/unit>", "max price for a market fill (e.g. 0.12/hour)").option("--max-price-per <unit>", "unit for a bare --max-price usd (second, minute, or hour)").option("--api-key <key>").option("--base-url <url>").option("--allow-untrusted-host").option("--json", "print the raw response").action(async (opts) => {
|
|
2075
2329
|
try {
|
|
2076
2330
|
const c = await client(opts);
|
|
2077
2331
|
const params = {
|
|
@@ -2109,7 +2363,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2109
2363
|
);
|
|
2110
2364
|
output(opts, res, (page) => {
|
|
2111
2365
|
page.sandboxes.forEach(printSandbox);
|
|
2112
|
-
if (page.nextCursor) console.log(
|
|
2366
|
+
if (page.nextCursor) console.log(pc4.dim(`nextCursor: ${page.nextCursor}`));
|
|
2113
2367
|
});
|
|
2114
2368
|
} catch (e) {
|
|
2115
2369
|
fail(e, opts);
|
|
@@ -2253,7 +2507,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2253
2507
|
data = opts.base64 ? piped.toString("base64") : piped.toString("utf8");
|
|
2254
2508
|
}
|
|
2255
2509
|
if (data === void 0 || data === "") {
|
|
2256
|
-
console.error(
|
|
2510
|
+
console.error(pc4.red("Pass --data, --file, or pipe stdin"));
|
|
2257
2511
|
process.exit(1);
|
|
2258
2512
|
}
|
|
2259
2513
|
if (opts.base64 && opts.data !== void 0) {
|
|
@@ -2290,7 +2544,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2290
2544
|
output(opts, res, (view) => {
|
|
2291
2545
|
if (view.type === "directory") {
|
|
2292
2546
|
for (const e of view.entries) {
|
|
2293
|
-
console.log(`${e.type === "directory" ?
|
|
2547
|
+
console.log(`${e.type === "directory" ? pc4.blue("d") : " "} ${e.name}${e.size !== void 0 ? ` ${pc4.dim(String(e.size))}` : ""}`);
|
|
2294
2548
|
}
|
|
2295
2549
|
} else {
|
|
2296
2550
|
console.log(`${view.path} file ${view.content.length} chars`);
|
|
@@ -2306,7 +2560,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2306
2560
|
const res = await c.get(`/api/v1/sandboxes/${sandboxId}/files`, { path });
|
|
2307
2561
|
output(opts, res, (view) => {
|
|
2308
2562
|
if (view.type !== "file") {
|
|
2309
|
-
console.error(
|
|
2563
|
+
console.error(pc4.red(`${view.path} is a directory`));
|
|
2310
2564
|
process.exit(1);
|
|
2311
2565
|
}
|
|
2312
2566
|
process.stdout.write(view.content);
|
|
@@ -2332,7 +2586,7 @@ function registerSandboxesCommands(program2) {
|
|
|
2332
2586
|
});
|
|
2333
2587
|
}
|
|
2334
2588
|
if (content === void 0) {
|
|
2335
|
-
console.error(
|
|
2589
|
+
console.error(pc4.red("Pass --content, --file, or pipe stdin"));
|
|
2336
2590
|
process.exit(1);
|
|
2337
2591
|
}
|
|
2338
2592
|
const c = await client(opts);
|
|
@@ -2417,6 +2671,12 @@ function registerSandboxesCommands(program2) {
|
|
|
2417
2671
|
for (const sub of cmd.commands) {
|
|
2418
2672
|
sub.option("--org <slug>", "organization slug for this command (or $COMPUTE_ORG)");
|
|
2419
2673
|
}
|
|
2674
|
+
registerSettingsCommands(
|
|
2675
|
+
cmd,
|
|
2676
|
+
"sandboxes",
|
|
2677
|
+
(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"),
|
|
2678
|
+
{ client, fail, output, usageErrorOutput }
|
|
2679
|
+
);
|
|
2420
2680
|
}
|
|
2421
2681
|
async function followProcess(c, sandboxId, jobId) {
|
|
2422
2682
|
let exitCode = 0;
|
|
@@ -2430,11 +2690,11 @@ async function followProcess(c, sandboxId, jobId) {
|
|
|
2430
2690
|
exitCode = typeof payload.exitCode === "number" ? payload.exitCode : 128;
|
|
2431
2691
|
return finish();
|
|
2432
2692
|
} else if (event === "error") {
|
|
2433
|
-
console.error(
|
|
2693
|
+
console.error(pc4.red(`Error: ${String(payload.error ?? "stream error")}`));
|
|
2434
2694
|
return finish(1);
|
|
2435
2695
|
}
|
|
2436
2696
|
}
|
|
2437
|
-
console.error(
|
|
2697
|
+
console.error(pc4.yellow("stream ended before the process exited"));
|
|
2438
2698
|
return finish(2);
|
|
2439
2699
|
function finish(code) {
|
|
2440
2700
|
if (code !== void 0) exitCode = code;
|
|
@@ -2497,18 +2757,18 @@ async function runLogout() {
|
|
|
2497
2757
|
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) => {
|
|
2498
2758
|
if (opts.logout) {
|
|
2499
2759
|
console.log();
|
|
2500
|
-
p.intro(
|
|
2760
|
+
p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
|
|
2501
2761
|
await runLogout();
|
|
2502
2762
|
p.log.success("Logged out. Stored credentials removed.");
|
|
2503
|
-
p.outro(
|
|
2763
|
+
p.outro(pc5.green("Done!"));
|
|
2504
2764
|
process.exit(0);
|
|
2505
2765
|
}
|
|
2506
2766
|
if (opts.login) {
|
|
2507
2767
|
console.log();
|
|
2508
|
-
p.intro(
|
|
2768
|
+
p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
|
|
2509
2769
|
await runLogin();
|
|
2510
2770
|
await printSessionLine();
|
|
2511
|
-
p.outro(
|
|
2771
|
+
p.outro(pc5.green("Authenticated!"));
|
|
2512
2772
|
process.exit(0);
|
|
2513
2773
|
}
|
|
2514
2774
|
program.help();
|
|
@@ -2519,23 +2779,23 @@ program.hook("preAction", (thisCommand) => {
|
|
|
2519
2779
|
});
|
|
2520
2780
|
program.command("providers").description("List all providers and their configuration status").action(async () => {
|
|
2521
2781
|
console.log();
|
|
2522
|
-
p.intro(
|
|
2782
|
+
p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
|
|
2523
2783
|
const statuses = getProviderStatus();
|
|
2524
2784
|
console.log();
|
|
2525
2785
|
for (const status of statuses) {
|
|
2526
|
-
const icon = status.ready ?
|
|
2527
|
-
const name = status.ready ?
|
|
2528
|
-
const detail = status.ready ?
|
|
2786
|
+
const icon = status.ready ? pc5.green("\u25CF") : pc5.gray("\u25CB");
|
|
2787
|
+
const name = status.ready ? pc5.white(status.name) : pc5.gray(status.name);
|
|
2788
|
+
const detail = status.ready ? pc5.green("ready") : pc5.gray(`missing: ${status.missing.join(", ")}`);
|
|
2529
2789
|
console.log(` ${icon} ${name} ${detail}`);
|
|
2530
2790
|
}
|
|
2531
2791
|
console.log();
|
|
2532
2792
|
});
|
|
2533
2793
|
program.command("login").description("Authenticate with ComputeSDK (OAuth device flow)").option("--base-url <url>", "platform URL to authenticate against").action(async (opts) => {
|
|
2534
2794
|
console.log();
|
|
2535
|
-
p.intro(
|
|
2795
|
+
p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
|
|
2536
2796
|
await runLogin({ baseUrl: opts.baseUrl });
|
|
2537
2797
|
await printSessionLine({ baseUrl: opts.baseUrl });
|
|
2538
|
-
p.outro(
|
|
2798
|
+
p.outro(pc5.green("Authenticated!"));
|
|
2539
2799
|
});
|
|
2540
2800
|
program.command("logout").description("Clear stored credentials").option("--json", "print machine-readable JSON").action(async (opts) => {
|
|
2541
2801
|
await runLogout();
|
|
@@ -2544,9 +2804,9 @@ program.command("logout").description("Clear stored credentials").option("--json
|
|
|
2544
2804
|
return;
|
|
2545
2805
|
}
|
|
2546
2806
|
console.log();
|
|
2547
|
-
p.intro(
|
|
2807
|
+
p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
|
|
2548
2808
|
p.log.success("Logged out. Stored credentials removed.");
|
|
2549
|
-
p.outro(
|
|
2809
|
+
p.outro(pc5.green("Done!"));
|
|
2550
2810
|
});
|
|
2551
2811
|
async function printWhoami(options = {}) {
|
|
2552
2812
|
const { getMe } = await import("@benchsdk/cli");
|
|
@@ -2571,8 +2831,8 @@ org.command("list").description("List your organizations").option("--json", "pri
|
|
|
2571
2831
|
return;
|
|
2572
2832
|
}
|
|
2573
2833
|
for (const o of organizations) {
|
|
2574
|
-
const marker = o.id === me.activeOrganizationId ?
|
|
2575
|
-
console.log(`${marker} ${
|
|
2834
|
+
const marker = o.id === me.activeOrganizationId ? pc5.green("*") : " ";
|
|
2835
|
+
console.log(`${marker} ${pc5.cyan(o.slug)} ${o.name ?? ""} ${pc5.dim(o.id)}`);
|
|
2576
2836
|
}
|
|
2577
2837
|
});
|
|
2578
2838
|
org.command("use <slug>").description("Set the active organization (persisted to the stored login)").action(async (slug) => {
|
|
@@ -2617,7 +2877,7 @@ async function main() {
|
|
|
2617
2877
|
await program.parseAsync(process.argv);
|
|
2618
2878
|
}
|
|
2619
2879
|
main().catch((error) => {
|
|
2620
|
-
console.error(
|
|
2880
|
+
console.error(pc5.red(`
|
|
2621
2881
|
Error: ${error.message}`));
|
|
2622
2882
|
process.exit(1);
|
|
2623
2883
|
});
|