@munitoai/cli 0.4.0 → 0.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/README.md +5 -0
- package/dist/api/client.d.ts +4 -2
- package/dist/api/types.d.ts +8 -0
- package/dist/{chunk-7XUGUENM.js → chunk-JHSIZLVR.js} +19 -11
- package/dist/chunk-JHSIZLVR.js.map +1 -0
- package/dist/cli.js +218 -76
- package/dist/cli.js.map +1 -1
- package/dist/core/files.d.ts +6 -0
- package/dist/core/sandboxes.d.ts +12 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-7XUGUENM.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
PLUGINS,
|
|
17
17
|
PROVIDERS,
|
|
18
18
|
TemplateError,
|
|
19
|
+
WORKDIR,
|
|
19
20
|
WiringError,
|
|
20
21
|
authPath,
|
|
21
22
|
clear,
|
|
@@ -36,7 +37,7 @@ import {
|
|
|
36
37
|
waitForBuild,
|
|
37
38
|
warm,
|
|
38
39
|
wire
|
|
39
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-JHSIZLVR.js";
|
|
40
41
|
|
|
41
42
|
// src/cli.ts
|
|
42
43
|
import { runCommand, runMain } from "citty";
|
|
@@ -57,10 +58,10 @@ async function collect(dir) {
|
|
|
57
58
|
const root = resolve(dir ?? process.cwd());
|
|
58
59
|
const listed = await listTracked(root);
|
|
59
60
|
if (!listed) return [];
|
|
60
|
-
const
|
|
61
|
+
const files2 = [];
|
|
61
62
|
let total = 0;
|
|
62
63
|
for (const relative of listed) {
|
|
63
|
-
if (
|
|
64
|
+
if (files2.length >= MAX_FILES) break;
|
|
64
65
|
const absolute = join(root, relative);
|
|
65
66
|
let info;
|
|
66
67
|
try {
|
|
@@ -73,9 +74,9 @@ async function collect(dir) {
|
|
|
73
74
|
const buffer = await readFile(absolute);
|
|
74
75
|
if (isBinary(buffer)) continue;
|
|
75
76
|
total += info.size;
|
|
76
|
-
|
|
77
|
+
files2.push({ path: relative, content: buffer.toString("utf8") });
|
|
77
78
|
}
|
|
78
|
-
return
|
|
79
|
+
return files2;
|
|
79
80
|
}
|
|
80
81
|
async function listTracked(root) {
|
|
81
82
|
try {
|
|
@@ -90,10 +91,10 @@ async function listTracked(root) {
|
|
|
90
91
|
function isBinary(buffer) {
|
|
91
92
|
return buffer.subarray(0, 8e3).includes(0);
|
|
92
93
|
}
|
|
93
|
-
function describeUpload(
|
|
94
|
-
const bytes2 =
|
|
94
|
+
function describeUpload(files2) {
|
|
95
|
+
const bytes2 = files2.reduce((sum, file) => sum + Buffer.byteLength(file.content), 0);
|
|
95
96
|
const size = bytes2 > 1 << 20 ? `${(bytes2 / (1 << 20)).toFixed(1)} MiB` : `${Math.ceil(bytes2 / 1024)} KiB`;
|
|
96
|
-
return `${
|
|
97
|
+
return `${files2.length} files, ${size}`;
|
|
97
98
|
}
|
|
98
99
|
async function applyPatch(patch, dir) {
|
|
99
100
|
const root = resolve(dir ?? process.cwd());
|
|
@@ -113,7 +114,7 @@ async function applyPatch(patch, dir) {
|
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
// src/cli/main.ts
|
|
116
|
-
import { defineCommand as
|
|
117
|
+
import { defineCommand as defineCommand11 } from "citty";
|
|
117
118
|
|
|
118
119
|
// src/cli/commands/agent.ts
|
|
119
120
|
import { defineCommand } from "citty";
|
|
@@ -189,24 +190,24 @@ function cube(p) {
|
|
|
189
190
|
function out(json, stream2 = process.stdout) {
|
|
190
191
|
const p = palette(stream2);
|
|
191
192
|
const mode = json ? "json" : p.depth === 0 ? "plain" : "rich";
|
|
192
|
-
const
|
|
193
|
+
const write2 = (text2) => stream2.write(`${text2}
|
|
193
194
|
`);
|
|
194
195
|
return {
|
|
195
196
|
mode,
|
|
196
197
|
p,
|
|
197
198
|
line(text2 = "") {
|
|
198
|
-
if (mode !== "json")
|
|
199
|
+
if (mode !== "json") write2(text2);
|
|
199
200
|
},
|
|
200
201
|
step(label, detail) {
|
|
201
202
|
if (mode === "json") return;
|
|
202
203
|
const mark = mode === "rich" ? p.primary("\u203A") : ">";
|
|
203
|
-
|
|
204
|
+
write2(detail ? `${mark} ${label} ${p.dim(detail)}` : `${mark} ${label}`);
|
|
204
205
|
},
|
|
205
206
|
event(body) {
|
|
206
|
-
if (mode === "json")
|
|
207
|
+
if (mode === "json") write2(JSON.stringify(body));
|
|
207
208
|
},
|
|
208
209
|
result(text2, body) {
|
|
209
|
-
if (mode === "json")
|
|
210
|
+
if (mode === "json") write2(JSON.stringify({ type: "result", ...body, result: text2 }));
|
|
210
211
|
},
|
|
211
212
|
warn(text2) {
|
|
212
213
|
if (mode === "json") {
|
|
@@ -594,7 +595,7 @@ ${CONSOLE_KEYS}`, "API key");
|
|
|
594
595
|
key = String(answer).trim();
|
|
595
596
|
}
|
|
596
597
|
const probe = new Client({ apiKey: key, baseUrl: host, attempts: 1 });
|
|
597
|
-
await probe.listSandboxes();
|
|
598
|
+
await probe.listSandboxes({ limit: 1 });
|
|
598
599
|
const path = await save(key, host);
|
|
599
600
|
out2.step("saved", `${mask(key)} for ${host}`);
|
|
600
601
|
out2.line(out2.p.dim(` ${path}, readable by you only`));
|
|
@@ -614,25 +615,110 @@ var whoami = defineCommand3({
|
|
|
614
615
|
args: commonArgs,
|
|
615
616
|
async run({ args }) {
|
|
616
617
|
const ctx = await context(args);
|
|
617
|
-
const
|
|
618
|
-
const running = sandboxes.filter((box) => box.status === "running").length;
|
|
618
|
+
const running = (await ctx.client.listSandboxes({ status: "running" })).length;
|
|
619
619
|
ctx.out.step("host", ctx.host);
|
|
620
620
|
ctx.out.step("key", `${ctx.source}`);
|
|
621
|
-
ctx.out.step("sandboxes", `${running} running
|
|
622
|
-
ctx.out.result("", { host: ctx.host, source: ctx.source, running
|
|
621
|
+
ctx.out.step("sandboxes", `${running} running`);
|
|
622
|
+
ctx.out.result("", { host: ctx.host, source: ctx.source, running });
|
|
623
623
|
}
|
|
624
624
|
});
|
|
625
625
|
|
|
626
|
+
// src/cli/commands/files.ts
|
|
627
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
628
|
+
import { defineCommand as defineCommand4 } from "citty";
|
|
629
|
+
|
|
630
|
+
// src/core/files.ts
|
|
631
|
+
function fileSize(bytes2) {
|
|
632
|
+
const units = ["B", "KiB", "MiB", "GiB", "TiB"];
|
|
633
|
+
let value = bytes2;
|
|
634
|
+
let unit = 0;
|
|
635
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
636
|
+
value /= 1024;
|
|
637
|
+
unit++;
|
|
638
|
+
}
|
|
639
|
+
return unit === 0 ? `${value} B` : `${value.toFixed(1)} ${units[unit]}`;
|
|
640
|
+
}
|
|
641
|
+
function fileRow(entry) {
|
|
642
|
+
const modified = new Date(entry.modified_at * 1e3).toISOString().slice(0, 16).replace("T", " ");
|
|
643
|
+
return [entry.name, entry.type, entry.type === "file" ? fileSize(entry.size) : "-", modified];
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// src/cli/commands/files.ts
|
|
647
|
+
var str2 = (value) => typeof value === "string" && value ? value : void 0;
|
|
648
|
+
var idArg = { id: { type: "positional", required: true, description: "The sandbox id." } };
|
|
649
|
+
async function readStdin() {
|
|
650
|
+
if (process.stdin.isTTY) throw new Error("Pipe the content to the command, or name a local file with --from.");
|
|
651
|
+
const chunks = [];
|
|
652
|
+
for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
|
|
653
|
+
return Buffer.concat(chunks);
|
|
654
|
+
}
|
|
655
|
+
var ls = defineCommand4({
|
|
656
|
+
meta: { name: "ls", description: "List a directory of a sandbox." },
|
|
657
|
+
args: {
|
|
658
|
+
...commonArgs,
|
|
659
|
+
...idArg,
|
|
660
|
+
path: { type: "positional", required: false, description: `The directory. The default is ${WORKDIR}.` }
|
|
661
|
+
},
|
|
662
|
+
async run({ args }) {
|
|
663
|
+
const { client, out: out2 } = await context(args);
|
|
664
|
+
const entries = await client.listFiles(String(args.id), str2(args.path) ?? WORKDIR);
|
|
665
|
+
for (const entry of entries) out2.event({ type: "file", entry });
|
|
666
|
+
if (out2.mode === "json") return;
|
|
667
|
+
if (entries.length) out2.line(table([["NAME", "TYPE", "SIZE", "MODIFIED"], ...entries.map(fileRow)], out2.p));
|
|
668
|
+
else out2.line(out2.p.dim("No files."));
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
var read = defineCommand4({
|
|
672
|
+
meta: { name: "read", description: "Print a file of a sandbox." },
|
|
673
|
+
args: {
|
|
674
|
+
...commonArgs,
|
|
675
|
+
...idArg,
|
|
676
|
+
path: { type: "positional", required: true, description: "The file in the sandbox." }
|
|
677
|
+
},
|
|
678
|
+
async run({ args }) {
|
|
679
|
+
const { client, out: out2 } = await context(args);
|
|
680
|
+
const path = String(args.path);
|
|
681
|
+
const content = await client.readFileBytes(String(args.id), path);
|
|
682
|
+
if (out2.mode === "json") {
|
|
683
|
+
out2.event({ type: "content", path, size: content.length, content: new TextDecoder().decode(content) });
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
await new Promise((done, fail) => process.stdout.write(content, (error) => error ? fail(error) : done()));
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
var write = defineCommand4({
|
|
690
|
+
meta: { name: "write", description: "Write a file of a sandbox, from standard input or from a local file." },
|
|
691
|
+
args: {
|
|
692
|
+
...commonArgs,
|
|
693
|
+
...idArg,
|
|
694
|
+
path: { type: "positional", required: true, description: "The file in the sandbox. Its folders are created." },
|
|
695
|
+
from: { type: "string", description: "A local file to send. The default is standard input." }
|
|
696
|
+
},
|
|
697
|
+
async run({ args }) {
|
|
698
|
+
const from = str2(args.from);
|
|
699
|
+
const content = from ? await readFile2(from) : await readStdin();
|
|
700
|
+
const { client, out: out2 } = await context(args);
|
|
701
|
+
const path = String(args.path);
|
|
702
|
+
await client.writeFile(String(args.id), path, content);
|
|
703
|
+
out2.step("wrote", `${path} ${fileSize(content.length)}`);
|
|
704
|
+
out2.result("", { path, size: content.length });
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
var files = defineCommand4({
|
|
708
|
+
meta: { name: "files", description: "List, read and write the files of a sandbox." },
|
|
709
|
+
subCommands: { ls, read, write }
|
|
710
|
+
});
|
|
711
|
+
|
|
626
712
|
// src/cli/commands/herdr.ts
|
|
627
713
|
import { spawn as spawn2, spawnSync } from "child_process";
|
|
628
|
-
import { defineCommand as
|
|
629
|
-
var herdr =
|
|
714
|
+
import { defineCommand as defineCommand5 } from "citty";
|
|
715
|
+
var herdr = defineCommand5({
|
|
630
716
|
meta: {
|
|
631
717
|
name: "herdr",
|
|
632
718
|
description: "Run coding agents on Munito sandboxes from herdr."
|
|
633
719
|
},
|
|
634
720
|
subCommands: {
|
|
635
|
-
add:
|
|
721
|
+
add: defineCommand5({
|
|
636
722
|
meta: { name: "add", description: "Create a sandbox and add it to herdr as a machine." },
|
|
637
723
|
args: {
|
|
638
724
|
...commonArgs,
|
|
@@ -689,7 +775,7 @@ import { mkdir, writeFile as writeFile2 } from "fs/promises";
|
|
|
689
775
|
import { homedir } from "os";
|
|
690
776
|
import { dirname } from "path";
|
|
691
777
|
import { promisify as promisify2 } from "util";
|
|
692
|
-
import { defineCommand as
|
|
778
|
+
import { defineCommand as defineCommand6 } from "citty";
|
|
693
779
|
async function installedOpencode() {
|
|
694
780
|
try {
|
|
695
781
|
const { stdout } = await promisify2(execFile2)("opencode", ["--version"], { timeout: 1e4 });
|
|
@@ -698,7 +784,7 @@ async function installedOpencode() {
|
|
|
698
784
|
return null;
|
|
699
785
|
}
|
|
700
786
|
}
|
|
701
|
-
var init =
|
|
787
|
+
var init = defineCommand6({
|
|
702
788
|
meta: {
|
|
703
789
|
name: "init",
|
|
704
790
|
description: "Point a coding agent on this machine at Munito AI."
|
|
@@ -785,14 +871,14 @@ var init = defineCommand5({
|
|
|
785
871
|
});
|
|
786
872
|
|
|
787
873
|
// src/cli/commands/mcp.ts
|
|
788
|
-
import { defineCommand as
|
|
874
|
+
import { defineCommand as defineCommand7 } from "citty";
|
|
789
875
|
function text(body) {
|
|
790
876
|
return { content: [{ type: "text", text: typeof body === "string" ? body : JSON.stringify(body, null, 2) }] };
|
|
791
877
|
}
|
|
792
878
|
function failed(message) {
|
|
793
879
|
return { ...text(message), isError: true };
|
|
794
880
|
}
|
|
795
|
-
var mcp =
|
|
881
|
+
var mcp = defineCommand7({
|
|
796
882
|
meta: {
|
|
797
883
|
name: "mcp",
|
|
798
884
|
description: "Serve the Munito AI tools over MCP on stdio, for a coding agent to call."
|
|
@@ -820,7 +906,7 @@ var mcp = defineCommand6({
|
|
|
820
906
|
max_turns: z.number().int().positive().optional()
|
|
821
907
|
}
|
|
822
908
|
},
|
|
823
|
-
(async ({ prompt, agent: agent2, provider, model, files, max_turns }) => {
|
|
909
|
+
(async ({ prompt, agent: agent2, provider, model, files: files2, max_turns }) => {
|
|
824
910
|
try {
|
|
825
911
|
const run3 = await runAgent(client, {
|
|
826
912
|
agent: agent2,
|
|
@@ -828,7 +914,7 @@ var mcp = defineCommand6({
|
|
|
828
914
|
provider,
|
|
829
915
|
auth: "token",
|
|
830
916
|
model,
|
|
831
|
-
files,
|
|
917
|
+
files: files2,
|
|
832
918
|
maxTurns: max_turns
|
|
833
919
|
});
|
|
834
920
|
return text({
|
|
@@ -855,18 +941,18 @@ var mcp = defineCommand6({
|
|
|
855
941
|
timeout: z.number().int().positive().default(120).describe("Seconds the command may take.")
|
|
856
942
|
}
|
|
857
943
|
},
|
|
858
|
-
(async ({ command, template, internet, timeout }) => {
|
|
944
|
+
(async ({ command, template, internet, timeout: timeout2 }) => {
|
|
859
945
|
let id = "";
|
|
860
946
|
try {
|
|
861
947
|
const box = await client.createSandbox({
|
|
862
948
|
template,
|
|
863
949
|
size: "small",
|
|
864
950
|
internet,
|
|
865
|
-
timeout: Math.max(
|
|
951
|
+
timeout: Math.max(timeout2 + 60, 120),
|
|
866
952
|
metadata: { "munito.cli": "mcp" }
|
|
867
953
|
});
|
|
868
954
|
id = box.id;
|
|
869
|
-
const out2 = await client.exec(id, { command, timeout });
|
|
955
|
+
const out2 = await client.exec(id, { command, timeout: timeout2 });
|
|
870
956
|
return text({ exit_code: out2.exit_code, stdout: out2.stdout, stderr: out2.stderr });
|
|
871
957
|
} catch (error) {
|
|
872
958
|
return failed(`The command did not run: ${error.message}`);
|
|
@@ -892,11 +978,11 @@ var mcp = defineCommand6({
|
|
|
892
978
|
});
|
|
893
979
|
|
|
894
980
|
// src/cli/commands/proxies.ts
|
|
895
|
-
import { defineCommand as
|
|
981
|
+
import { defineCommand as defineCommand8 } from "citty";
|
|
896
982
|
var proxyArg = {
|
|
897
983
|
proxy: { type: "positional", required: true, description: "The name or the id of the proxy." }
|
|
898
984
|
};
|
|
899
|
-
var create =
|
|
985
|
+
var create = defineCommand8({
|
|
900
986
|
meta: { name: "create", description: "Create a proxy: fixed public addresses for your sandboxes." },
|
|
901
987
|
args: {
|
|
902
988
|
...commonArgs,
|
|
@@ -910,7 +996,7 @@ var create = defineCommand7({
|
|
|
910
996
|
out2.line(out2.p.dim(` munito create --proxy ${proxy.name}`));
|
|
911
997
|
}
|
|
912
998
|
});
|
|
913
|
-
var
|
|
999
|
+
var ls2 = defineCommand8({
|
|
914
1000
|
meta: { name: "ls", description: "List the proxies of your workspace." },
|
|
915
1001
|
args: commonArgs,
|
|
916
1002
|
async run({ args }) {
|
|
@@ -935,7 +1021,7 @@ var ls = defineCommand7({
|
|
|
935
1021
|
out2.line(table(rows, out2.p));
|
|
936
1022
|
}
|
|
937
1023
|
});
|
|
938
|
-
var get =
|
|
1024
|
+
var get = defineCommand8({
|
|
939
1025
|
meta: { name: "get", description: "Show a proxy, its addresses and its open ports." },
|
|
940
1026
|
args: { ...commonArgs, ...proxyArg },
|
|
941
1027
|
async run({ args }) {
|
|
@@ -943,7 +1029,7 @@ var get = defineCommand7({
|
|
|
943
1029
|
show(out2, await findProxy(client, String(args.proxy)));
|
|
944
1030
|
}
|
|
945
1031
|
});
|
|
946
|
-
var rm2 =
|
|
1032
|
+
var rm2 = defineCommand8({
|
|
947
1033
|
meta: { name: "rm", description: "Delete proxies that no running or paused sandbox uses." },
|
|
948
1034
|
args: { ...commonArgs, proxies: { type: "positional", required: true, description: "One or more proxies." } },
|
|
949
1035
|
async run({ args }) {
|
|
@@ -957,7 +1043,7 @@ var rm2 = defineCommand7({
|
|
|
957
1043
|
}
|
|
958
1044
|
}
|
|
959
1045
|
});
|
|
960
|
-
var open =
|
|
1046
|
+
var open = defineCommand8({
|
|
961
1047
|
meta: { name: "open", description: "Let the internet reach one port of a sandbox of the proxy." },
|
|
962
1048
|
args: {
|
|
963
1049
|
...commonArgs,
|
|
@@ -985,7 +1071,7 @@ var open = defineCommand7({
|
|
|
985
1071
|
out2.result("", { port: opened.id, endpoints: reach });
|
|
986
1072
|
}
|
|
987
1073
|
});
|
|
988
|
-
var close =
|
|
1074
|
+
var close = defineCommand8({
|
|
989
1075
|
meta: { name: "close", description: "Close an open port of a proxy." },
|
|
990
1076
|
args: {
|
|
991
1077
|
...commonArgs,
|
|
@@ -1025,14 +1111,34 @@ function show(out2, proxy) {
|
|
|
1025
1111
|
];
|
|
1026
1112
|
for (const line of table(rows, out2.p).split("\n")) out2.line(` ${line}`);
|
|
1027
1113
|
}
|
|
1028
|
-
var proxies =
|
|
1114
|
+
var proxies = defineCommand8({
|
|
1029
1115
|
meta: { name: "proxies", description: "Give sandboxes fixed public addresses. A preview." },
|
|
1030
|
-
subCommands: { create, ls, get, rm: rm2, open, close }
|
|
1116
|
+
subCommands: { create, ls: ls2, get, rm: rm2, open, close }
|
|
1031
1117
|
});
|
|
1032
1118
|
|
|
1033
1119
|
// src/cli/commands/sandboxes.ts
|
|
1034
1120
|
import { spawn as spawn3 } from "child_process";
|
|
1035
|
-
import { defineCommand as
|
|
1121
|
+
import { defineCommand as defineCommand9 } from "citty";
|
|
1122
|
+
|
|
1123
|
+
// src/core/sandboxes.ts
|
|
1124
|
+
var LIVE_READ = ["running", "paused", "pending", "running"];
|
|
1125
|
+
async function liveSandboxes(client) {
|
|
1126
|
+
const byId = /* @__PURE__ */ new Map();
|
|
1127
|
+
for (const status of LIVE_READ) {
|
|
1128
|
+
for (const box of await client.listSandboxes({ status })) byId.set(box.id, box);
|
|
1129
|
+
}
|
|
1130
|
+
return [...byId.values()].sort((a, b) => a.id < b.id ? 1 : -1);
|
|
1131
|
+
}
|
|
1132
|
+
function timeoutSeconds(value) {
|
|
1133
|
+
if (!/^\d+$/.test(value.trim())) {
|
|
1134
|
+
throw new Error(`The timeout is a whole number of seconds, such as 3600. It was ${JSON.stringify(value)}.`);
|
|
1135
|
+
}
|
|
1136
|
+
return Number(value);
|
|
1137
|
+
}
|
|
1138
|
+
async function newestSandboxes(client, limit) {
|
|
1139
|
+
const boxes = await client.listSandboxes({ limit: limit + 1 });
|
|
1140
|
+
return { sandboxes: boxes.slice(0, limit), older: boxes.length > limit };
|
|
1141
|
+
}
|
|
1036
1142
|
|
|
1037
1143
|
// src/core/ssh.ts
|
|
1038
1144
|
var LOOPBACK = "127.0.0.1";
|
|
@@ -1068,21 +1174,35 @@ function sshArgv(user, host, forwards = []) {
|
|
|
1068
1174
|
}
|
|
1069
1175
|
|
|
1070
1176
|
// src/cli/commands/sandboxes.ts
|
|
1071
|
-
var
|
|
1177
|
+
var ALL_LIMIT = 100;
|
|
1178
|
+
var ls3 = defineCommand9({
|
|
1072
1179
|
meta: { name: "ls", description: "List your sandboxes." },
|
|
1073
|
-
args: {
|
|
1180
|
+
args: {
|
|
1181
|
+
...commonArgs,
|
|
1182
|
+
all: { type: "boolean", alias: "a", description: "Stopped and failed ones too, the newest first." },
|
|
1183
|
+
limit: { type: "string", description: `The most sandboxes to list. With --all, the default is ${ALL_LIMIT}.` }
|
|
1184
|
+
},
|
|
1074
1185
|
async run({ args }) {
|
|
1075
1186
|
const { client, out: out2 } = await context(args);
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1187
|
+
const limit = args.limit === void 0 ? void 0 : Number(args.limit);
|
|
1188
|
+
if (limit !== void 0 && (!Number.isInteger(limit) || limit < 1)) {
|
|
1189
|
+
throw new Error("--limit takes a whole number above 0.");
|
|
1190
|
+
}
|
|
1191
|
+
let shown;
|
|
1192
|
+
let older;
|
|
1193
|
+
if (args.all) {
|
|
1194
|
+
({ sandboxes: shown, older } = await newestSandboxes(client, limit ?? ALL_LIMIT));
|
|
1195
|
+
} else {
|
|
1196
|
+
const live = await liveSandboxes(client);
|
|
1197
|
+
shown = live.slice(0, limit);
|
|
1198
|
+
older = live.length > shown.length;
|
|
1199
|
+
}
|
|
1078
1200
|
for (const box of shown) out2.event({ type: "sandbox", ...box });
|
|
1079
|
-
if (out2.mode
|
|
1080
|
-
|
|
1081
|
-
out2.line(out2.p.dim('No sandboxes. Start one with `munito agent "..."`.'));
|
|
1082
|
-
return;
|
|
1201
|
+
if (out2.mode !== "json") {
|
|
1202
|
+
if (shown.length) out2.line(table([["ID", "STATUS", "TEMPLATE", "SIZE", "AGE"], ...shown.map(row)], out2.p));
|
|
1203
|
+
else out2.line(out2.p.dim('No sandboxes. Start one with `munito agent "..."`.'));
|
|
1083
1204
|
}
|
|
1084
|
-
|
|
1085
|
-
out2.line(table(rows, out2.p));
|
|
1205
|
+
if (older) out2.warn(`The list stops at ${shown.length}. Older sandboxes exist. Use --limit to get more.`);
|
|
1086
1206
|
}
|
|
1087
1207
|
});
|
|
1088
1208
|
var PROXY_FLAG = "The name or the id of a proxy: the sandbox gets its fixed public addresses. A preview.";
|
|
@@ -1090,7 +1210,7 @@ function row(box) {
|
|
|
1090
1210
|
const age = box.created_at ? duration(Date.now() - box.created_at * 1e3) : "";
|
|
1091
1211
|
return [box.id, box.status, box.template, `${box.vcpus}c ${Math.round(box.memory_mib / 1024)}g`, age];
|
|
1092
1212
|
}
|
|
1093
|
-
var run2 =
|
|
1213
|
+
var run2 = defineCommand9({
|
|
1094
1214
|
meta: { name: "run", description: "Run one command in a throwaway sandbox." },
|
|
1095
1215
|
args: {
|
|
1096
1216
|
...commonArgs,
|
|
@@ -1125,7 +1245,7 @@ var run2 = defineCommand8({
|
|
|
1125
1245
|
}
|
|
1126
1246
|
}
|
|
1127
1247
|
});
|
|
1128
|
-
var exec =
|
|
1248
|
+
var exec = defineCommand9({
|
|
1129
1249
|
meta: { name: "exec", description: "Run a command in a sandbox you already have." },
|
|
1130
1250
|
args: {
|
|
1131
1251
|
...commonArgs,
|
|
@@ -1140,12 +1260,12 @@ var exec = defineCommand8({
|
|
|
1140
1260
|
if (exit !== 0) process.exitCode = exit;
|
|
1141
1261
|
}
|
|
1142
1262
|
});
|
|
1143
|
-
async function stream(client, id, command, out2,
|
|
1263
|
+
async function stream(client, id, command, out2, timeout2, cwd) {
|
|
1144
1264
|
let exit = 0;
|
|
1145
1265
|
const events = client.execStream(id, {
|
|
1146
1266
|
command,
|
|
1147
1267
|
cwd,
|
|
1148
|
-
timeout:
|
|
1268
|
+
timeout: timeout2 ? Number(timeout2) : void 0
|
|
1149
1269
|
});
|
|
1150
1270
|
for await (const event of events) {
|
|
1151
1271
|
if (event.type === "stdout") out2.raw(event.data);
|
|
@@ -1155,7 +1275,7 @@ async function stream(client, id, command, out2, timeout, cwd) {
|
|
|
1155
1275
|
}
|
|
1156
1276
|
return exit;
|
|
1157
1277
|
}
|
|
1158
|
-
var rm3 =
|
|
1278
|
+
var rm3 = defineCommand9({
|
|
1159
1279
|
meta: { name: "rm", description: "Delete sandboxes." },
|
|
1160
1280
|
args: { ...commonArgs, ids: { type: "positional", required: true, description: "One or more sandbox ids." } },
|
|
1161
1281
|
async run({ args, rawArgs: rawArgs2 }) {
|
|
@@ -1167,7 +1287,7 @@ var rm3 = defineCommand8({
|
|
|
1167
1287
|
}
|
|
1168
1288
|
}
|
|
1169
1289
|
});
|
|
1170
|
-
var pause =
|
|
1290
|
+
var pause = defineCommand9({
|
|
1171
1291
|
meta: { name: "pause", description: "Pause a persistent sandbox." },
|
|
1172
1292
|
args: { ...commonArgs, id: { type: "positional", required: true, description: "The sandbox id." } },
|
|
1173
1293
|
async run({ args }) {
|
|
@@ -1176,7 +1296,7 @@ var pause = defineCommand8({
|
|
|
1176
1296
|
out2.step("paused", box.id);
|
|
1177
1297
|
}
|
|
1178
1298
|
});
|
|
1179
|
-
var resume =
|
|
1299
|
+
var resume = defineCommand9({
|
|
1180
1300
|
meta: { name: "resume", description: "Resume a paused sandbox." },
|
|
1181
1301
|
args: { ...commonArgs, id: { type: "positional", required: true, description: "The sandbox id." } },
|
|
1182
1302
|
async run({ args }) {
|
|
@@ -1185,7 +1305,27 @@ var resume = defineCommand8({
|
|
|
1185
1305
|
out2.step("resumed", box.id);
|
|
1186
1306
|
}
|
|
1187
1307
|
});
|
|
1188
|
-
var
|
|
1308
|
+
var timeout = defineCommand9({
|
|
1309
|
+
meta: { name: "timeout", description: "Give a running sandbox a new end, in seconds from now." },
|
|
1310
|
+
args: {
|
|
1311
|
+
...commonArgs,
|
|
1312
|
+
id: { type: "positional", required: true, description: "The sandbox id." },
|
|
1313
|
+
seconds: {
|
|
1314
|
+
type: "positional",
|
|
1315
|
+
required: true,
|
|
1316
|
+
description: "Seconds from now until the sandbox stops, or pauses when it is persistent."
|
|
1317
|
+
}
|
|
1318
|
+
},
|
|
1319
|
+
async run({ args }) {
|
|
1320
|
+
const seconds = timeoutSeconds(args.seconds);
|
|
1321
|
+
const { client, out: out2 } = await context(args);
|
|
1322
|
+
const box = await client.setSandboxTimeout(args.id, seconds);
|
|
1323
|
+
const end = box.expires_at ? new Date(box.expires_at * 1e3).toISOString().replace(".000Z", "Z") : void 0;
|
|
1324
|
+
out2.step("timeout", end ? `${box.id} ends at ${end}` : box.id);
|
|
1325
|
+
out2.result("", { sandbox_id: box.id, expires_at: box.expires_at });
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
var fork = defineCommand9({
|
|
1189
1329
|
meta: { name: "fork", description: "Start new sandboxes from a persistent one, as it is now." },
|
|
1190
1330
|
args: {
|
|
1191
1331
|
...commonArgs,
|
|
@@ -1203,7 +1343,7 @@ var fork = defineCommand8({
|
|
|
1203
1343
|
out2.result("", { forks: forks.map((box) => box.id) });
|
|
1204
1344
|
}
|
|
1205
1345
|
});
|
|
1206
|
-
var ssh =
|
|
1346
|
+
var ssh = defineCommand9({
|
|
1207
1347
|
meta: { name: "ssh", description: "Open a shell in a sandbox." },
|
|
1208
1348
|
args: {
|
|
1209
1349
|
...commonArgs,
|
|
@@ -1237,7 +1377,7 @@ var ssh = defineCommand8({
|
|
|
1237
1377
|
);
|
|
1238
1378
|
}
|
|
1239
1379
|
});
|
|
1240
|
-
var open2 =
|
|
1380
|
+
var open2 = defineCommand9({
|
|
1241
1381
|
meta: { name: "open", description: "Open a sandbox port, or its desktop, in your browser." },
|
|
1242
1382
|
args: {
|
|
1243
1383
|
...commonArgs,
|
|
@@ -1260,7 +1400,7 @@ var open2 = defineCommand8({
|
|
|
1260
1400
|
openInBrowser(signed.url);
|
|
1261
1401
|
}
|
|
1262
1402
|
});
|
|
1263
|
-
var create2 =
|
|
1403
|
+
var create2 = defineCommand9({
|
|
1264
1404
|
meta: { name: "create", description: "Create a sandbox and leave it running." },
|
|
1265
1405
|
args: {
|
|
1266
1406
|
...commonArgs,
|
|
@@ -1306,18 +1446,18 @@ var create2 = defineCommand8({
|
|
|
1306
1446
|
});
|
|
1307
1447
|
|
|
1308
1448
|
// src/cli/commands/templates.ts
|
|
1309
|
-
import { defineCommand as
|
|
1310
|
-
var
|
|
1449
|
+
import { defineCommand as defineCommand10 } from "citty";
|
|
1450
|
+
var str3 = (value) => typeof value === "string" && value ? value : void 0;
|
|
1311
1451
|
var nameArg2 = {
|
|
1312
1452
|
name: { type: "positional", required: true, description: "The name or the id of the template." }
|
|
1313
1453
|
};
|
|
1314
|
-
async function
|
|
1454
|
+
async function readStdin2() {
|
|
1315
1455
|
if (process.stdin.isTTY) throw new TemplateError(`Pipe the token to --password-stdin, or set ${ENV_REGISTRY_TOKEN}.`);
|
|
1316
1456
|
const chunks = [];
|
|
1317
1457
|
for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
|
|
1318
1458
|
return Buffer.concat(chunks).toString("utf8");
|
|
1319
1459
|
}
|
|
1320
|
-
var deploy =
|
|
1460
|
+
var deploy = defineCommand10({
|
|
1321
1461
|
meta: {
|
|
1322
1462
|
name: "deploy",
|
|
1323
1463
|
description: "Build a container image into a template. A name that exists gets a new version."
|
|
@@ -1342,8 +1482,8 @@ var deploy = defineCommand9({
|
|
|
1342
1482
|
throw new TemplateError(`There is no --password. Use --password-stdin, or set ${ENV_REGISTRY_TOKEN}.`);
|
|
1343
1483
|
}
|
|
1344
1484
|
const { auth, ignored } = registryAuth({
|
|
1345
|
-
username:
|
|
1346
|
-
stdin: args["password-stdin"] ? await
|
|
1485
|
+
username: str3(args.username),
|
|
1486
|
+
stdin: args["password-stdin"] ? await readStdin2() : void 0,
|
|
1347
1487
|
env: process.env[ENV_REGISTRY_TOKEN]
|
|
1348
1488
|
});
|
|
1349
1489
|
const body = deployBody(String(args.name), String(args.image), auth);
|
|
@@ -1360,7 +1500,7 @@ var deploy = defineCommand9({
|
|
|
1360
1500
|
out2.result("", { template: template.name, id: template.id, version: template.build.version });
|
|
1361
1501
|
}
|
|
1362
1502
|
});
|
|
1363
|
-
var
|
|
1503
|
+
var ls4 = defineCommand10({
|
|
1364
1504
|
meta: { name: "ls", description: "List the templates of your workspace." },
|
|
1365
1505
|
args: commonArgs,
|
|
1366
1506
|
async run({ args }) {
|
|
@@ -1388,7 +1528,7 @@ function row2(template) {
|
|
|
1388
1528
|
`v${build.version} ${build.status}`
|
|
1389
1529
|
];
|
|
1390
1530
|
}
|
|
1391
|
-
var get2 =
|
|
1531
|
+
var get2 = defineCommand10({
|
|
1392
1532
|
meta: { name: "get", description: "Show a template and its newest build." },
|
|
1393
1533
|
args: {
|
|
1394
1534
|
...commonArgs,
|
|
@@ -1404,7 +1544,7 @@ var get2 = defineCommand9({
|
|
|
1404
1544
|
show2(out2, await client.getTemplate(String(args.name)));
|
|
1405
1545
|
}
|
|
1406
1546
|
});
|
|
1407
|
-
var rm4 =
|
|
1547
|
+
var rm4 = defineCommand10({
|
|
1408
1548
|
meta: { name: "rm", description: "Delete templates. Their running sandboxes keep running." },
|
|
1409
1549
|
args: { ...commonArgs, names: { type: "positional", required: true, description: "One or more template names." } },
|
|
1410
1550
|
async run({ args }) {
|
|
@@ -1455,14 +1595,14 @@ function show2(out2, template) {
|
|
|
1455
1595
|
for (const line of build.log.replace(/\n$/, "").split("\n")) out2.line(out2.p.dim(` ${line}`));
|
|
1456
1596
|
}
|
|
1457
1597
|
}
|
|
1458
|
-
var templates =
|
|
1598
|
+
var templates = defineCommand10({
|
|
1459
1599
|
meta: { name: "templates", description: "Start sandboxes from your own container image." },
|
|
1460
|
-
subCommands: { deploy, ls:
|
|
1600
|
+
subCommands: { deploy, ls: ls4, get: get2, rm: rm4 }
|
|
1461
1601
|
});
|
|
1462
1602
|
|
|
1463
1603
|
// src/cli/main.ts
|
|
1464
|
-
var VERSION = true ? "0.
|
|
1465
|
-
var main =
|
|
1604
|
+
var VERSION = true ? "0.5.0" : "0.0.0-dev";
|
|
1605
|
+
var main = defineCommand11({
|
|
1466
1606
|
meta: {
|
|
1467
1607
|
name: "munito",
|
|
1468
1608
|
// Without this, `munito --version` exits with "No version specified".
|
|
@@ -1478,7 +1618,7 @@ var main = defineCommand10({
|
|
|
1478
1618
|
login,
|
|
1479
1619
|
logout,
|
|
1480
1620
|
whoami,
|
|
1481
|
-
ls:
|
|
1621
|
+
ls: ls3,
|
|
1482
1622
|
create: create2,
|
|
1483
1623
|
run: run2,
|
|
1484
1624
|
exec,
|
|
@@ -1487,7 +1627,9 @@ var main = defineCommand10({
|
|
|
1487
1627
|
rm: rm3,
|
|
1488
1628
|
pause,
|
|
1489
1629
|
resume,
|
|
1630
|
+
timeout,
|
|
1490
1631
|
fork,
|
|
1632
|
+
files,
|
|
1491
1633
|
templates,
|
|
1492
1634
|
proxies
|
|
1493
1635
|
}
|