@munitoai/cli 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -22,9 +22,12 @@ import {
22
22
  createAgentSandbox,
23
23
  deployBody,
24
24
  drop,
25
+ endpoints,
25
26
  findBase,
27
+ findProxy,
26
28
  job,
27
29
  mask,
30
+ opencodeMajor,
28
31
  registryAuth,
29
32
  require as require2,
30
33
  resolveHost,
@@ -33,7 +36,7 @@ import {
33
36
  waitForBuild,
34
37
  warm,
35
38
  wire
36
- } from "./chunk-EZEXBJTZ.js";
39
+ } from "./chunk-7XUGUENM.js";
37
40
 
38
41
  // src/cli.ts
39
42
  import { runCommand, runMain } from "citty";
@@ -110,7 +113,7 @@ async function applyPatch(patch, dir) {
110
113
  }
111
114
 
112
115
  // src/cli/main.ts
113
- import { defineCommand as defineCommand9 } from "citty";
116
+ import { defineCommand as defineCommand10 } from "citty";
114
117
 
115
118
  // src/cli/commands/agent.ts
116
119
  import { defineCommand } from "citty";
@@ -681,10 +684,20 @@ var herdr = defineCommand4({
681
684
  });
682
685
 
683
686
  // src/cli/commands/init.ts
687
+ import { execFile as execFile2 } from "child_process";
684
688
  import { mkdir, writeFile as writeFile2 } from "fs/promises";
685
689
  import { homedir } from "os";
686
690
  import { dirname } from "path";
691
+ import { promisify as promisify2 } from "util";
687
692
  import { defineCommand as defineCommand5 } from "citty";
693
+ async function installedOpencode() {
694
+ try {
695
+ const { stdout } = await promisify2(execFile2)("opencode", ["--version"], { timeout: 1e4 });
696
+ return opencodeMajor(stdout);
697
+ } catch {
698
+ return null;
699
+ }
700
+ }
688
701
  var init = defineCommand5({
689
702
  meta: {
690
703
  name: "init",
@@ -718,6 +731,11 @@ var init = defineCommand5({
718
731
  out2.result("", { agent: name, plugin, guide });
719
732
  return;
720
733
  }
734
+ if (name === "opencode" && (await installedOpencode() ?? 2) < 2) {
735
+ throw new Error(
736
+ "munito init needs OpenCode 2, and this machine has OpenCode 1. See https://opencode.ai/docs/#cli"
737
+ );
738
+ }
721
739
  const wiring = wire(
722
740
  name,
723
741
  args.provider,
@@ -749,6 +767,9 @@ var init = defineCommand5({
749
767
  out2.line(` export ${key}=${shown}`);
750
768
  }
751
769
  }
770
+ if (name === "opencode" && exports.length) {
771
+ out2.line(out2.p.dim(" Then restart the server of OpenCode: opencode service restart"));
772
+ }
752
773
  if (wiring.unset.length && !args["dry-run"]) {
753
774
  out2.line();
754
775
  out2.line(out2.p.dim(` Clear these if your shell sets them: ${wiring.unset.join(", ")}`));
@@ -870,9 +891,148 @@ var mcp = defineCommand6({
870
891
  }
871
892
  });
872
893
 
894
+ // src/cli/commands/proxies.ts
895
+ import { defineCommand as defineCommand7 } from "citty";
896
+ var proxyArg = {
897
+ proxy: { type: "positional", required: true, description: "The name or the id of the proxy." }
898
+ };
899
+ var create = defineCommand7({
900
+ meta: { name: "create", description: "Create a proxy: fixed public addresses for your sandboxes." },
901
+ args: {
902
+ ...commonArgs,
903
+ name: { type: "positional", required: true, description: "The name: lower case letters, digits and hyphens." },
904
+ dedicated: { type: "boolean", description: "IPv4 addresses that no other customer uses, at a price." }
905
+ },
906
+ async run({ args }) {
907
+ const { client, out: out2 } = await context(args);
908
+ const proxy = await client.createProxy({ name: String(args.name), ipv4: args.dedicated ? "dedicated" : "shared" });
909
+ show(out2, proxy);
910
+ out2.line(out2.p.dim(` munito create --proxy ${proxy.name}`));
911
+ }
912
+ });
913
+ var ls = defineCommand7({
914
+ meta: { name: "ls", description: "List the proxies of your workspace." },
915
+ args: commonArgs,
916
+ async run({ args }) {
917
+ const { client, out: out2 } = await context(args);
918
+ const proxies2 = await client.listProxies();
919
+ for (const proxy of proxies2) out2.event({ type: "proxy", ...proxy });
920
+ if (out2.mode === "json") return;
921
+ if (!proxies2.length) {
922
+ out2.line(out2.p.dim("No proxies. Create one with `munito proxies create <name>`."));
923
+ return;
924
+ }
925
+ const rows = [
926
+ ["NAME", "IPV4", "ADDRESSES", "IPV6 BLOCK", "OPEN PORTS"],
927
+ ...proxies2.map((proxy) => [
928
+ proxy.name,
929
+ proxy.ipv4.mode,
930
+ proxy.ipv4.addresses.join(" ") || "-",
931
+ proxy.ipv6 ?? "-",
932
+ String(proxy.ports.length)
933
+ ])
934
+ ];
935
+ out2.line(table(rows, out2.p));
936
+ }
937
+ });
938
+ var get = defineCommand7({
939
+ meta: { name: "get", description: "Show a proxy, its addresses and its open ports." },
940
+ args: { ...commonArgs, ...proxyArg },
941
+ async run({ args }) {
942
+ const { client, out: out2 } = await context(args);
943
+ show(out2, await findProxy(client, String(args.proxy)));
944
+ }
945
+ });
946
+ var rm2 = defineCommand7({
947
+ meta: { name: "rm", description: "Delete proxies that no running or paused sandbox uses." },
948
+ args: { ...commonArgs, proxies: { type: "positional", required: true, description: "One or more proxies." } },
949
+ async run({ args }) {
950
+ const { client, out: out2 } = await context(args);
951
+ const refs = args._.length ? args._ : [String(args.proxies)];
952
+ for (const ref of refs) {
953
+ const proxy = await findProxy(client, ref);
954
+ await client.deleteProxy(proxy.id);
955
+ out2.event({ type: "proxy.deleted", id: proxy.id, name: proxy.name });
956
+ out2.step("deleted", proxy.name);
957
+ }
958
+ }
959
+ });
960
+ var open = defineCommand7({
961
+ meta: { name: "open", description: "Let the internet reach one port of a sandbox of the proxy." },
962
+ args: {
963
+ ...commonArgs,
964
+ ...proxyArg,
965
+ sandbox: { type: "positional", required: true, description: "The sandbox id." },
966
+ port: { type: "positional", required: true, description: "The port that a server in the sandbox listens on." },
967
+ udp: { type: "boolean", description: "A UDP port. The default is TCP." },
968
+ "public-port": { type: "string", description: "The port outside, for a dedicated proxy. The default is the port." }
969
+ },
970
+ async run({ args }) {
971
+ const { client, out: out2 } = await context(args);
972
+ const proxy = await findProxy(client, String(args.proxy));
973
+ const sandbox = String(args.sandbox);
974
+ const opened = await client.openProxyPort(proxy.id, {
975
+ sandbox_id: sandbox,
976
+ port: Number(args.port),
977
+ protocol: args.udp ? "udp" : "tcp",
978
+ public_port: args["public-port"] ? Number(args["public-port"]) : void 0
979
+ });
980
+ const ipv6 = (await client.getSandbox(sandbox).catch(() => void 0))?.proxy?.ipv6;
981
+ const reach = endpoints(proxy, opened, ipv6);
982
+ out2.event({ type: "proxy.port", ...opened, endpoints: reach });
983
+ out2.step("open", `${opened.protocol} ${opened.port} of ${sandbox}`);
984
+ for (const endpoint of reach) out2.line(` ${endpoint}`);
985
+ out2.result("", { port: opened.id, endpoints: reach });
986
+ }
987
+ });
988
+ var close = defineCommand7({
989
+ meta: { name: "close", description: "Close an open port of a proxy." },
990
+ args: {
991
+ ...commonArgs,
992
+ ...proxyArg,
993
+ port: { type: "positional", required: true, description: "The id of the open port, from `munito proxies get`." }
994
+ },
995
+ async run({ args }) {
996
+ const { client, out: out2 } = await context(args);
997
+ const proxy = await findProxy(client, String(args.proxy));
998
+ await client.closeProxyPort(proxy.id, String(args.port));
999
+ out2.event({ type: "proxy.port.closed", id: String(args.port) });
1000
+ out2.step("closed", String(args.port));
1001
+ }
1002
+ });
1003
+ function show(out2, proxy) {
1004
+ out2.event({ type: "proxy", ...proxy });
1005
+ out2.result("", { proxy: proxy.name, id: proxy.id, ipv4: proxy.ipv4.addresses, ipv6: proxy.ipv6 ?? null });
1006
+ if (out2.mode === "json") return;
1007
+ out2.step(proxy.name, proxy.ipv4.mode);
1008
+ const facts = [
1009
+ ["id", proxy.id],
1010
+ ["ipv4", proxy.ipv4.addresses.join(" ") || "-"],
1011
+ ["ipv6", proxy.ipv6 ?? "-"]
1012
+ ];
1013
+ const lines = table(facts, out2.p, false).split("\n");
1014
+ for (const line of lines) out2.line(` ${line}`);
1015
+ if (!proxy.ports.length) return;
1016
+ const rows = [
1017
+ ["PORT ID", "SANDBOX", "PROTOCOL", "PORT", "PUBLIC PORT"],
1018
+ ...proxy.ports.map((port2) => [
1019
+ port2.id,
1020
+ port2.sandbox_id,
1021
+ port2.protocol,
1022
+ String(port2.port),
1023
+ String(port2.public_port)
1024
+ ])
1025
+ ];
1026
+ for (const line of table(rows, out2.p).split("\n")) out2.line(` ${line}`);
1027
+ }
1028
+ var proxies = defineCommand7({
1029
+ meta: { name: "proxies", description: "Give sandboxes fixed public addresses. A preview." },
1030
+ subCommands: { create, ls, get, rm: rm2, open, close }
1031
+ });
1032
+
873
1033
  // src/cli/commands/sandboxes.ts
874
1034
  import { spawn as spawn3 } from "child_process";
875
- import { defineCommand as defineCommand7 } from "citty";
1035
+ import { defineCommand as defineCommand8 } from "citty";
876
1036
 
877
1037
  // src/core/ssh.ts
878
1038
  var LOOPBACK = "127.0.0.1";
@@ -908,7 +1068,7 @@ function sshArgv(user, host, forwards = []) {
908
1068
  }
909
1069
 
910
1070
  // src/cli/commands/sandboxes.ts
911
- var ls = defineCommand7({
1071
+ var ls2 = defineCommand8({
912
1072
  meta: { name: "ls", description: "List your sandboxes." },
913
1073
  args: { ...commonArgs, all: { type: "boolean", alias: "a", description: "Stopped ones too." } },
914
1074
  async run({ args }) {
@@ -925,11 +1085,12 @@ var ls = defineCommand7({
925
1085
  out2.line(table(rows, out2.p));
926
1086
  }
927
1087
  });
1088
+ var PROXY_FLAG = "The name or the id of a proxy: the sandbox gets its fixed public addresses. A preview.";
928
1089
  function row(box) {
929
1090
  const age = box.created_at ? duration(Date.now() - box.created_at * 1e3) : "";
930
1091
  return [box.id, box.status, box.template, `${box.vcpus}c ${Math.round(box.memory_mib / 1024)}g`, age];
931
1092
  }
932
- var run2 = defineCommand7({
1093
+ var run2 = defineCommand8({
933
1094
  meta: { name: "run", description: "Run one command in a throwaway sandbox." },
934
1095
  args: {
935
1096
  ...commonArgs,
@@ -941,16 +1102,19 @@ var run2 = defineCommand7({
941
1102
  },
942
1103
  size: { type: "string", description: "tiny, small, default or large.", default: "small" },
943
1104
  internet: { type: "boolean", description: "Allow outbound connections." },
1105
+ proxy: { type: "string", description: PROXY_FLAG },
944
1106
  timeout: { type: "string", description: "Seconds the command may take." }
945
1107
  },
946
1108
  async run({ args }) {
947
1109
  const { client, out: out2 } = await context(args);
1110
+ const proxy = args.proxy ? (await findProxy(client, args.proxy)).id : void 0;
948
1111
  const box = await client.createSandbox({
949
1112
  template: args.template,
950
1113
  size: args.size,
951
1114
  internet: Boolean(args.internet),
952
1115
  timeout: 600,
953
- metadata: { "munito.cli": "run" }
1116
+ metadata: { "munito.cli": "run" },
1117
+ proxy
954
1118
  });
955
1119
  try {
956
1120
  const exit = await stream(client, box.id, args.command, out2, args.timeout);
@@ -961,7 +1125,7 @@ var run2 = defineCommand7({
961
1125
  }
962
1126
  }
963
1127
  });
964
- var exec = defineCommand7({
1128
+ var exec = defineCommand8({
965
1129
  meta: { name: "exec", description: "Run a command in a sandbox you already have." },
966
1130
  args: {
967
1131
  ...commonArgs,
@@ -991,7 +1155,7 @@ async function stream(client, id, command, out2, timeout, cwd) {
991
1155
  }
992
1156
  return exit;
993
1157
  }
994
- var rm2 = defineCommand7({
1158
+ var rm3 = defineCommand8({
995
1159
  meta: { name: "rm", description: "Delete sandboxes." },
996
1160
  args: { ...commonArgs, ids: { type: "positional", required: true, description: "One or more sandbox ids." } },
997
1161
  async run({ args, rawArgs: rawArgs2 }) {
@@ -1003,7 +1167,7 @@ var rm2 = defineCommand7({
1003
1167
  }
1004
1168
  }
1005
1169
  });
1006
- var pause = defineCommand7({
1170
+ var pause = defineCommand8({
1007
1171
  meta: { name: "pause", description: "Pause a persistent sandbox." },
1008
1172
  args: { ...commonArgs, id: { type: "positional", required: true, description: "The sandbox id." } },
1009
1173
  async run({ args }) {
@@ -1012,7 +1176,7 @@ var pause = defineCommand7({
1012
1176
  out2.step("paused", box.id);
1013
1177
  }
1014
1178
  });
1015
- var resume = defineCommand7({
1179
+ var resume = defineCommand8({
1016
1180
  meta: { name: "resume", description: "Resume a paused sandbox." },
1017
1181
  args: { ...commonArgs, id: { type: "positional", required: true, description: "The sandbox id." } },
1018
1182
  async run({ args }) {
@@ -1021,7 +1185,7 @@ var resume = defineCommand7({
1021
1185
  out2.step("resumed", box.id);
1022
1186
  }
1023
1187
  });
1024
- var fork = defineCommand7({
1188
+ var fork = defineCommand8({
1025
1189
  meta: { name: "fork", description: "Start new sandboxes from a persistent one, as it is now." },
1026
1190
  args: {
1027
1191
  ...commonArgs,
@@ -1039,7 +1203,7 @@ var fork = defineCommand7({
1039
1203
  out2.result("", { forks: forks.map((box) => box.id) });
1040
1204
  }
1041
1205
  });
1042
- var ssh = defineCommand7({
1206
+ var ssh = defineCommand8({
1043
1207
  meta: { name: "ssh", description: "Open a shell in a sandbox." },
1044
1208
  args: {
1045
1209
  ...commonArgs,
@@ -1073,7 +1237,7 @@ var ssh = defineCommand7({
1073
1237
  );
1074
1238
  }
1075
1239
  });
1076
- var open = defineCommand7({
1240
+ var open2 = defineCommand8({
1077
1241
  meta: { name: "open", description: "Open a sandbox port, or its desktop, in your browser." },
1078
1242
  args: {
1079
1243
  ...commonArgs,
@@ -1096,7 +1260,7 @@ var open = defineCommand7({
1096
1260
  openInBrowser(signed.url);
1097
1261
  }
1098
1262
  });
1099
- var create = defineCommand7({
1263
+ var create2 = defineCommand8({
1100
1264
  meta: { name: "create", description: "Create a sandbox and leave it running." },
1101
1265
  args: {
1102
1266
  ...commonArgs,
@@ -1112,10 +1276,13 @@ var create = defineCommand7({
1112
1276
  size: { type: "string", description: "tiny, small, default or large.", default: "default" },
1113
1277
  internet: { type: "boolean", description: "Allow outbound connections.", default: true },
1114
1278
  persistent: { type: "boolean", description: "Keep files and processes across a pause." },
1279
+ proxy: { type: "string", description: PROXY_FLAG },
1115
1280
  timeout: { type: "string", description: "Seconds the sandbox may live." }
1116
1281
  },
1117
1282
  async run({ args }) {
1118
1283
  const { client, out: out2 } = await context(args);
1284
+ if (args.proxy && args.agent) throw new Error("A sandbox with --agent takes no --proxy yet.");
1285
+ const proxy = args.proxy ? (await findProxy(client, args.proxy)).id : void 0;
1119
1286
  const common = {
1120
1287
  template: args.template,
1121
1288
  size: args.size,
@@ -1130,15 +1297,16 @@ var create = defineCommand7({
1130
1297
  auth: args.auth,
1131
1298
  model: args.model,
1132
1299
  metadata: { "munito.cli": "create", "munito.agent": args.agent }
1133
- }) : await client.createSandbox({ ...common, metadata: { "munito.cli": "create" } });
1300
+ }) : await client.createSandbox({ ...common, metadata: { "munito.cli": "create" }, proxy });
1134
1301
  out2.step("created", box.id);
1302
+ if (box.proxy?.ipv6) out2.line(out2.p.dim(` ipv6 ${box.proxy.ipv6}`));
1135
1303
  out2.line(out2.p.dim(` munito ssh ${box.id}`));
1136
- out2.result("", { sandbox_id: box.id });
1304
+ out2.result("", { sandbox_id: box.id, ...box.proxy ? { proxy: box.proxy } : {} });
1137
1305
  }
1138
1306
  });
1139
1307
 
1140
1308
  // src/cli/commands/templates.ts
1141
- import { defineCommand as defineCommand8 } from "citty";
1309
+ import { defineCommand as defineCommand9 } from "citty";
1142
1310
  var str2 = (value) => typeof value === "string" && value ? value : void 0;
1143
1311
  var nameArg2 = {
1144
1312
  name: { type: "positional", required: true, description: "The name or the id of the template." }
@@ -1149,7 +1317,7 @@ async function readStdin() {
1149
1317
  for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
1150
1318
  return Buffer.concat(chunks).toString("utf8");
1151
1319
  }
1152
- var deploy = defineCommand8({
1320
+ var deploy = defineCommand9({
1153
1321
  meta: {
1154
1322
  name: "deploy",
1155
1323
  description: "Build a container image into a template. A name that exists gets a new version."
@@ -1192,7 +1360,7 @@ var deploy = defineCommand8({
1192
1360
  out2.result("", { template: template.name, id: template.id, version: template.build.version });
1193
1361
  }
1194
1362
  });
1195
- var ls2 = defineCommand8({
1363
+ var ls3 = defineCommand9({
1196
1364
  meta: { name: "ls", description: "List the templates of your workspace." },
1197
1365
  args: commonArgs,
1198
1366
  async run({ args }) {
@@ -1220,7 +1388,7 @@ function row2(template) {
1220
1388
  `v${build.version} ${build.status}`
1221
1389
  ];
1222
1390
  }
1223
- var get = defineCommand8({
1391
+ var get2 = defineCommand9({
1224
1392
  meta: { name: "get", description: "Show a template and its newest build." },
1225
1393
  args: {
1226
1394
  ...commonArgs,
@@ -1233,10 +1401,10 @@ var get = defineCommand8({
1233
1401
  await follow(client, out2, String(args.name));
1234
1402
  return;
1235
1403
  }
1236
- show(out2, await client.getTemplate(String(args.name)));
1404
+ show2(out2, await client.getTemplate(String(args.name)));
1237
1405
  }
1238
1406
  });
1239
- var rm3 = defineCommand8({
1407
+ var rm4 = defineCommand9({
1240
1408
  meta: { name: "rm", description: "Delete templates. Their running sandboxes keep running." },
1241
1409
  args: { ...commonArgs, names: { type: "positional", required: true, description: "One or more template names." } },
1242
1410
  async run({ args }) {
@@ -1256,10 +1424,10 @@ async function follow(client, out2, ref) {
1256
1424
  out2.step(event.status, `${event.name} v${event.version}`);
1257
1425
  }
1258
1426
  });
1259
- show(out2, template);
1427
+ show2(out2, template);
1260
1428
  if (template.build.status === "failed") process.exitCode = 1;
1261
1429
  }
1262
- function show(out2, template) {
1430
+ function show2(out2, template) {
1263
1431
  out2.event({ type: "template", ...template });
1264
1432
  const { build } = template;
1265
1433
  out2.result("", {
@@ -1287,14 +1455,14 @@ function show(out2, template) {
1287
1455
  for (const line of build.log.replace(/\n$/, "").split("\n")) out2.line(out2.p.dim(` ${line}`));
1288
1456
  }
1289
1457
  }
1290
- var templates = defineCommand8({
1458
+ var templates = defineCommand9({
1291
1459
  meta: { name: "templates", description: "Start sandboxes from your own container image." },
1292
- subCommands: { deploy, ls: ls2, get, rm: rm3 }
1460
+ subCommands: { deploy, ls: ls3, get: get2, rm: rm4 }
1293
1461
  });
1294
1462
 
1295
1463
  // src/cli/main.ts
1296
- var VERSION = true ? "0.3.0" : "0.0.0-dev";
1297
- var main = defineCommand9({
1464
+ var VERSION = true ? "0.4.0" : "0.0.0-dev";
1465
+ var main = defineCommand10({
1298
1466
  meta: {
1299
1467
  name: "munito",
1300
1468
  // Without this, `munito --version` exits with "No version specified".
@@ -1310,17 +1478,18 @@ var main = defineCommand9({
1310
1478
  login,
1311
1479
  logout,
1312
1480
  whoami,
1313
- ls,
1314
- create,
1481
+ ls: ls2,
1482
+ create: create2,
1315
1483
  run: run2,
1316
1484
  exec,
1317
1485
  ssh,
1318
- open,
1319
- rm: rm2,
1486
+ open: open2,
1487
+ rm: rm3,
1320
1488
  pause,
1321
1489
  resume,
1322
1490
  fork,
1323
- templates
1491
+ templates,
1492
+ proxies
1324
1493
  }
1325
1494
  });
1326
1495