@computesdk/cli 2.6.0 → 2.6.2

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 CHANGED
@@ -4,8 +4,8 @@
4
4
  import "dotenv/config";
5
5
  import { Command } from "commander";
6
6
  import * as p from "@clack/prompts";
7
- import pc5 from "picocolors";
8
- import { readFileSync as readFileSync3 } from "fs";
7
+ import pc6 from "picocolors";
8
+ import { readFileSync as readFileSync4 } from "fs";
9
9
  import { fileURLToPath } from "url";
10
10
  import { dirname as dirname2, join as join4 } from "path";
11
11
 
@@ -3537,11 +3537,281 @@ function formatBytes(n) {
3537
3537
  return `${v >= 100 ? Math.round(v) : v.toFixed(1)} ${units[i]}`;
3538
3538
  }
3539
3539
 
3540
+ // src/agents.ts
3541
+ import pc5 from "picocolors";
3542
+ import { readFileSync as readFileSync3 } from "fs";
3543
+ function formatLocalTime2(iso) {
3544
+ if (iso === null) return "\u2014";
3545
+ const d = new Date(iso);
3546
+ if (Number.isNaN(d.getTime())) return iso;
3547
+ const p2 = (n) => String(n).padStart(2, "0");
3548
+ return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())} ${p2(d.getHours())}:${p2(d.getMinutes())}`;
3549
+ }
3550
+ function printAgent(a) {
3551
+ console.log(
3552
+ `${pc5.cyan(safeTerm(a.name))} ${a.id.slice(0, 8)} ${a.harness}${a.model ? ` ${safeTerm(a.model)}` : ""} sessions: ${a.sessionCount} created: ${formatLocalTime2(a.createdAt)}`
3553
+ );
3554
+ }
3555
+ function printAgentDetail(a) {
3556
+ printAgent(a);
3557
+ if (a.providerOrder) console.log(` order: ${safeTerm(a.providerOrder.join(", "))}`);
3558
+ if (a.secrets.length > 0) console.log(` secrets: ${safeTerm(a.secrets.join(", "))}`);
3559
+ if (a.volume) console.log(` volume: ${a.volume.diskId ?? "\u2014"} at ${a.volume.path ?? "\u2014"}`);
3560
+ }
3561
+ function printSession(s) {
3562
+ console.log(
3563
+ `${pc5.cyan(s.id)} ${s.status} sandbox: ${s.sandboxId ?? "\u2014"} ${formatLocalTime2(s.createdAt)}${s.error ? ` ${pc5.red(safeTerm(s.error))}` : ""}`
3564
+ );
3565
+ }
3566
+ function printEvent(e) {
3567
+ const payload = e.payload ?? {};
3568
+ if (e.kind === "user") {
3569
+ console.log(`${pc5.green("you")} #${e.seq} ${safeTerm(String(payload.message ?? ""))}`);
3570
+ return;
3571
+ }
3572
+ if (e.kind === "turn") {
3573
+ const events = Array.isArray(payload.events) ? payload.events : [payload];
3574
+ for (const ev of events) {
3575
+ const o = ev;
3576
+ const text = o.text ?? o.message ?? o.content;
3577
+ if (typeof text === "string") console.log(pc5.dim(`#${e.seq}`) + ` ${safeTerm(text)}`);
3578
+ else console.log(pc5.dim(`#${e.seq} ${safeTerm(JSON.stringify(o))}`));
3579
+ }
3580
+ return;
3581
+ }
3582
+ console.log(pc5.dim(`#${e.seq} ${e.kind} ${safeTerm(JSON.stringify(payload))}`));
3583
+ }
3584
+ function authOpts(cmd) {
3585
+ 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");
3586
+ }
3587
+ function registerAgentsCommands(program2) {
3588
+ const cmd = program2.command("agents").alias("ag").description("Managed agents: durable agent configs running sessions in routed sandboxes").enablePositionalOptions().configureOutput({ outputError: usageErrorOutput });
3589
+ authOpts(cmd.command("list").alias("ls").description("List agents")).action(
3590
+ async (opts) => {
3591
+ try {
3592
+ const c = await client(opts);
3593
+ const agents = [];
3594
+ let cursor;
3595
+ for (; ; ) {
3596
+ const res = await c.get(
3597
+ "/api/v1/agents",
3598
+ { cursor }
3599
+ );
3600
+ agents.push(...res.agents);
3601
+ if (res.nextCursor === null) break;
3602
+ cursor = res.nextCursor;
3603
+ }
3604
+ output(opts, { agents }, (r) => {
3605
+ if (r.agents.length === 0) console.log("No agents yet \u2014 `compute agents create`.");
3606
+ for (const a of r.agents) printAgent(a);
3607
+ });
3608
+ } catch (e) {
3609
+ fail(e, opts);
3610
+ }
3611
+ }
3612
+ );
3613
+ authOpts(
3614
+ cmd.command("create <name>").description("Create an agent (prompt via --prompt or --prompt-file)").option("--prompt <text>", "the agent's mission / system prompt").option("--prompt-file <path>", "read the prompt from a file").option("--harness <harness>", "pi or opencode (default pi)").option("--model <model>", "model id passed to the harness").option("--secret <name...>", "vault secret names to inject").option("--order <providers>", "provider order, comma-separated").option("--volume-disk <diskId>", "Archil disk id to mount at --volume-path").option("--volume-path <path>", "volume mount path (default /agent)")
3615
+ ).action(
3616
+ async (name, opts) => {
3617
+ try {
3618
+ const prompt = opts.prompt ?? (opts.promptFile ? readFileSync3(opts.promptFile, "utf8") : void 0);
3619
+ if (!prompt?.trim()) fail(new Error("--prompt or --prompt-file is required"), opts);
3620
+ const volume = opts.volumeDisk !== void 0 || opts.volumePath !== void 0 ? { diskId: opts.volumeDisk, path: opts.volumePath } : void 0;
3621
+ const c = await client(opts);
3622
+ const res = await c.post("/api/v1/agents", {
3623
+ name,
3624
+ prompt,
3625
+ harness: opts.harness,
3626
+ model: opts.model,
3627
+ secrets: opts.secret,
3628
+ providerOrder: opts.order?.split(",").map((s) => s.trim()).filter(Boolean),
3629
+ volume
3630
+ });
3631
+ output(opts, res, (r) => {
3632
+ printAgentDetail(r.agent);
3633
+ console.error(pc5.dim(`agent ${r.agent.name} created \u2014 run it with \`compute agents run ${r.agent.name} "\u2026"\``));
3634
+ });
3635
+ } catch (e) {
3636
+ fail(e, opts);
3637
+ }
3638
+ }
3639
+ );
3640
+ authOpts(cmd.command("describe <ref>").alias("get").description("Show one agent (id or name)")).action(
3641
+ async (ref, opts) => {
3642
+ try {
3643
+ const c = await client(opts);
3644
+ const res = await c.get(`/api/v1/agents/${encodeURIComponent(ref)}`);
3645
+ output(opts, res, (r) => printAgentDetail(r.agent));
3646
+ } catch (e) {
3647
+ fail(e, opts);
3648
+ }
3649
+ }
3650
+ );
3651
+ authOpts(
3652
+ cmd.command("update <ref>").description("Update an agent's config").option("--name <name>").option("--prompt <text>").option("--prompt-file <path>").option("--harness <harness>").option("--model <model>").option("--secret <name...>").option("--clear-secrets", "remove all declared vault secrets").option("--order <providers>").option("--volume-disk <diskId>").option("--volume-path <path>")
3653
+ ).action(
3654
+ async (ref, opts) => {
3655
+ try {
3656
+ const prompt = opts.prompt ?? (opts.promptFile ? readFileSync3(opts.promptFile, "utf8") : void 0);
3657
+ const body = {
3658
+ name: opts.name,
3659
+ prompt,
3660
+ harness: opts.harness,
3661
+ model: opts.model,
3662
+ secrets: opts.clearSecrets ? [] : opts.secret,
3663
+ providerOrder: opts.order?.split(",").map((s) => s.trim()).filter(Boolean)
3664
+ };
3665
+ if (opts.volumeDisk !== void 0 || opts.volumePath !== void 0) {
3666
+ body.volume = { diskId: opts.volumeDisk, path: opts.volumePath };
3667
+ }
3668
+ for (const k of Object.keys(body)) if (body[k] === void 0) delete body[k];
3669
+ const c = await client(opts);
3670
+ const res = await c.patch(
3671
+ `/api/v1/agents/${encodeURIComponent(ref)}`,
3672
+ body
3673
+ );
3674
+ output(opts, res, (r) => printAgentDetail(r.agent));
3675
+ } catch (e) {
3676
+ fail(e, opts);
3677
+ }
3678
+ }
3679
+ );
3680
+ authOpts(
3681
+ cmd.command("delete <ref>").alias("rm").description("Delete an agent and stop its live sessions").option("-y, --yes", "skip the confirmation")
3682
+ ).action(async (ref, opts) => {
3683
+ try {
3684
+ const c = await client(opts);
3685
+ if (!opts.yes) {
3686
+ const res = await c.get(`/api/v1/agents/${encodeURIComponent(ref)}`);
3687
+ console.error(`Deleting agent ${pc5.cyan(res.agent.name)} (${res.agent.id}). Pass -y to confirm.`);
3688
+ process.exit(1);
3689
+ }
3690
+ await c.del(`/api/v1/agents/${encodeURIComponent(ref)}`);
3691
+ output(opts, { deleted: ref }, () => console.log(`deleted ${ref}`));
3692
+ } catch (e) {
3693
+ fail(e, opts);
3694
+ }
3695
+ });
3696
+ authOpts(cmd.command("sessions <ref>").description("List an agent's sessions")).action(
3697
+ async (ref, opts) => {
3698
+ try {
3699
+ const c = await client(opts);
3700
+ const res = await c.get(
3701
+ `/api/v1/agents/${encodeURIComponent(ref)}/sessions`
3702
+ );
3703
+ output(opts, res, (r) => {
3704
+ if (r.sessions.length === 0) console.log("No sessions yet.");
3705
+ for (const s of r.sessions) printSession(s);
3706
+ });
3707
+ } catch (e) {
3708
+ fail(e, opts);
3709
+ }
3710
+ }
3711
+ );
3712
+ authOpts(
3713
+ cmd.command("run <ref> [message]").description("Start a session on a routed sandbox and optionally send a first message").option("--size <size>", "platform size for the session's sandbox")
3714
+ ).action(async (ref, message, opts) => {
3715
+ try {
3716
+ const c = await client(opts);
3717
+ const res = await c.post(
3718
+ `/api/v1/agents/${encodeURIComponent(ref)}/sessions`,
3719
+ { message, size: opts.size }
3720
+ );
3721
+ output(opts, res, (r) => {
3722
+ printSession(r.session);
3723
+ for (const e of r.events) printEvent(e);
3724
+ console.error(pc5.dim(`session ${r.session.id} \u2014 continue with \`compute agents send ${r.session.id} "\u2026"\``));
3725
+ });
3726
+ } catch (e) {
3727
+ fail(e, opts);
3728
+ }
3729
+ });
3730
+ authOpts(cmd.command("session <sessionId>").description("Show one session")).action(
3731
+ async (sessionId, opts) => {
3732
+ try {
3733
+ const c = await client(opts);
3734
+ const res = await c.get(
3735
+ `/api/v1/agent-sessions/${encodeURIComponent(sessionId)}`
3736
+ );
3737
+ output(opts, res, (r) => printSession(r.session));
3738
+ } catch (e) {
3739
+ fail(e, opts);
3740
+ }
3741
+ }
3742
+ );
3743
+ authOpts(
3744
+ cmd.command("send <sessionId> <message>").description("Send a message; the agent runs a turn")
3745
+ ).action(async (sessionId, message, opts) => {
3746
+ try {
3747
+ const c = await client(opts);
3748
+ const res = await c.post(
3749
+ `/api/v1/agent-sessions/${encodeURIComponent(sessionId)}/events`,
3750
+ { message }
3751
+ );
3752
+ output(opts, res, (r) => {
3753
+ for (const e of r.events) printEvent(e);
3754
+ });
3755
+ } catch (e) {
3756
+ fail(e, opts);
3757
+ }
3758
+ });
3759
+ authOpts(
3760
+ cmd.command("events <sessionId>").description("Show the session event journal; --follow polls for new events").option("--after <seq>", "only events above this seq").option("--follow", "poll every 2s until the session settles or Ctrl-C")
3761
+ ).action(
3762
+ async (sessionId, opts) => {
3763
+ try {
3764
+ const c = await client(opts);
3765
+ let after = opts.after !== void 0 ? Number(opts.after) : void 0;
3766
+ const once = async () => {
3767
+ const res = await c.get(
3768
+ `/api/v1/agent-sessions/${encodeURIComponent(sessionId)}/events`,
3769
+ { after: after !== void 0 ? String(after) : void 0 }
3770
+ );
3771
+ if (opts.json) {
3772
+ output(opts, res, () => {
3773
+ });
3774
+ } else {
3775
+ for (const e of res.events) printEvent(e);
3776
+ }
3777
+ after = res.latestSeq;
3778
+ return res.events.length;
3779
+ };
3780
+ if (!opts.follow) {
3781
+ await once();
3782
+ return;
3783
+ }
3784
+ for (; ; ) {
3785
+ const status = (await c.get(
3786
+ `/api/v1/agent-sessions/${encodeURIComponent(sessionId)}`
3787
+ )).session.status;
3788
+ await once();
3789
+ if (status !== "running" && status !== "starting") break;
3790
+ await new Promise((r) => setTimeout(r, 2e3));
3791
+ }
3792
+ } catch (e) {
3793
+ fail(e, opts);
3794
+ }
3795
+ }
3796
+ );
3797
+ authOpts(
3798
+ cmd.command("stop <sessionId>").description("Stop a session and release its sandbox")
3799
+ ).action(async (sessionId, opts) => {
3800
+ try {
3801
+ const c = await client(opts);
3802
+ await c.del(`/api/v1/agent-sessions/${encodeURIComponent(sessionId)}`);
3803
+ output(opts, { stopped: sessionId }, () => console.log(`stopped ${sessionId}`));
3804
+ } catch (e) {
3805
+ fail(e, opts);
3806
+ }
3807
+ });
3808
+ }
3809
+
3540
3810
  // src/index.ts
3541
3811
  var __filename2 = fileURLToPath(import.meta.url);
3542
3812
  var __dirname2 = dirname2(__filename2);
3543
3813
  var packageJson = JSON.parse(
3544
- readFileSync3(join4(__dirname2, "..", "package.json"), "utf-8")
3814
+ readFileSync4(join4(__dirname2, "..", "package.json"), "utf-8")
3545
3815
  );
3546
3816
  var isDevBuild = import.meta.url.includes("worktrees") || import.meta.url.includes("/packages/cli/");
3547
3817
  var VERSION = isDevBuild ? `${packageJson.version}-dev` : packageJson.version;
@@ -3592,18 +3862,18 @@ async function runLogout() {
3592
3862
  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) => {
3593
3863
  if (opts.logout) {
3594
3864
  console.log();
3595
- p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
3865
+ p.intro(pc6.cyan(`@computesdk/cli v${VERSION}`));
3596
3866
  await runLogout();
3597
3867
  p.log.success("Logged out. Stored credentials removed.");
3598
- p.outro(pc5.green("Done!"));
3868
+ p.outro(pc6.green("Done!"));
3599
3869
  process.exit(0);
3600
3870
  }
3601
3871
  if (opts.login) {
3602
3872
  console.log();
3603
- p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
3873
+ p.intro(pc6.cyan(`@computesdk/cli v${VERSION}`));
3604
3874
  await runLogin();
3605
3875
  await printSessionLine();
3606
- p.outro(pc5.green("Authenticated!"));
3876
+ p.outro(pc6.green("Authenticated!"));
3607
3877
  process.exit(0);
3608
3878
  }
3609
3879
  program.help();
@@ -3614,23 +3884,23 @@ program.hook("preAction", (thisCommand) => {
3614
3884
  });
3615
3885
  program.command("providers").description("List all providers and their configuration status").action(async () => {
3616
3886
  console.log();
3617
- p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
3887
+ p.intro(pc6.cyan(`@computesdk/cli v${VERSION}`));
3618
3888
  const statuses = getProviderStatus();
3619
3889
  console.log();
3620
3890
  for (const status of statuses) {
3621
- const icon = status.ready ? pc5.green("\u25CF") : pc5.gray("\u25CB");
3622
- const name = status.ready ? pc5.white(status.name) : pc5.gray(status.name);
3623
- const detail = status.ready ? pc5.green("ready") : pc5.gray(`missing: ${status.missing.join(", ")}`);
3891
+ const icon = status.ready ? pc6.green("\u25CF") : pc6.gray("\u25CB");
3892
+ const name = status.ready ? pc6.white(status.name) : pc6.gray(status.name);
3893
+ const detail = status.ready ? pc6.green("ready") : pc6.gray(`missing: ${status.missing.join(", ")}`);
3624
3894
  console.log(` ${icon} ${name} ${detail}`);
3625
3895
  }
3626
3896
  console.log();
3627
3897
  });
3628
3898
  program.command("login").description("Authenticate with ComputeSDK (OAuth device flow)").option("--base-url <url>", "platform URL to authenticate against").action(async (opts) => {
3629
3899
  console.log();
3630
- p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
3900
+ p.intro(pc6.cyan(`@computesdk/cli v${VERSION}`));
3631
3901
  await runLogin({ baseUrl: opts.baseUrl });
3632
3902
  await printSessionLine({ baseUrl: opts.baseUrl });
3633
- p.outro(pc5.green("Authenticated!"));
3903
+ p.outro(pc6.green("Authenticated!"));
3634
3904
  });
3635
3905
  program.command("logout").description("Clear stored credentials").option("--json", "print machine-readable JSON").action(async (opts) => {
3636
3906
  await runLogout();
@@ -3639,9 +3909,9 @@ program.command("logout").description("Clear stored credentials").option("--json
3639
3909
  return;
3640
3910
  }
3641
3911
  console.log();
3642
- p.intro(pc5.cyan(`@computesdk/cli v${VERSION}`));
3912
+ p.intro(pc6.cyan(`@computesdk/cli v${VERSION}`));
3643
3913
  p.log.success("Logged out. Stored credentials removed.");
3644
- p.outro(pc5.green("Done!"));
3914
+ p.outro(pc6.green("Done!"));
3645
3915
  });
3646
3916
  async function printWhoami(options = {}) {
3647
3917
  const { getMe } = await import("@benchsdk/cli");
@@ -3666,8 +3936,8 @@ org.command("list").description("List your organizations").option("--json", "pri
3666
3936
  return;
3667
3937
  }
3668
3938
  for (const o of organizations) {
3669
- const marker = o.id === me.activeOrganizationId ? pc5.green("*") : " ";
3670
- console.log(`${marker} ${pc5.cyan(o.slug)} ${o.name ?? ""} ${pc5.dim(o.id)}`);
3939
+ const marker = o.id === me.activeOrganizationId ? pc6.green("*") : " ";
3940
+ console.log(`${marker} ${pc6.cyan(o.slug)} ${o.name ?? ""} ${pc6.dim(o.id)}`);
3671
3941
  }
3672
3942
  });
3673
3943
  org.command("use <slug>").description("Set the active organization (persisted to the stored login)").action(async (slug) => {
@@ -3701,6 +3971,7 @@ program.command("whoami").description("Show the current user and active organiza
3701
3971
  registerActionsCommands(program);
3702
3972
  registerMarketCommands(program);
3703
3973
  registerSandboxesCommands(program);
3974
+ registerAgentsCommands(program);
3704
3975
  program.command("bench").description("Benchmarks platform CLI (run, auth, org, benchmarks, runs, results, artifacts, export, ...)").allowUnknownOption().helpOption(false).action(() => {
3705
3976
  });
3706
3977
  async function main() {
@@ -3712,7 +3983,7 @@ async function main() {
3712
3983
  await program.parseAsync(process.argv);
3713
3984
  }
3714
3985
  main().catch((error) => {
3715
- console.error(pc5.red(`
3986
+ console.error(pc6.red(`
3716
3987
  Error: ${error.message}`));
3717
3988
  process.exit(1);
3718
3989
  });