sandcovery 0.7.0 → 0.9.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 +7 -6
- package/dist/cli/index.mjs +13015 -19892
- package/dist/cli/sandcovery-docker.mjs +8550 -3
- package/dist/cli/sandcovery-kubectl.mjs +7 -4
- package/dist/cli/sandcovery-t3.mjs +76 -51
- package/dist/index.d.mts +8716 -134
- package/dist/index.mjs +1 -1
- package/dist/{kubectl-ClFWX65x.mjs → kubectl-Ck04daor.mjs} +131 -97
- package/dist/saved-sandboxes-BMjkAVGx.mjs +389 -0
- package/dist/{x-account-BSasf-z-.mjs → src-DjOLw-ft.mjs} +19057 -8175
- package/dist/sync-rEFjHNC4.mjs +4171 -0
- package/dist/third-party-licenses.md +630 -0
- package/dist/types-DotsDqXt.d.mts +1264 -0
- package/dist/types.d.mts +2 -2
- package/package.json +4 -4
- package/dist/src-gAv6vIvE.mjs +0 -566
- package/dist/tool-B8KvfvY5.mjs +0 -12890
- package/dist/types-B52jOW9v.d.mts +0 -853
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { _o as some } from "../src-DjOLw-ft.mjs";
|
|
3
|
+
import { a as watchIdle, i as IDLE_WATCHER_ENV, n as kubectlRun } from "../kubectl-Ck04daor.mjs";
|
|
4
|
+
import { l as startTool } from "../saved-sandboxes-BMjkAVGx.mjs";
|
|
4
5
|
// src/cli/sandcovery-kubectl.ts
|
|
5
6
|
await startTool({
|
|
6
7
|
run: kubectlRun,
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
server: some({
|
|
9
|
+
serve: watchIdle,
|
|
10
|
+
variable: IDLE_WATCHER_ENV
|
|
11
|
+
})
|
|
9
12
|
});
|
|
10
13
|
export {};
|
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { r as onPath, t as answers } from "../kubectl-
|
|
2
|
+
import { Kt as fromJsonString, Mt as Struct, Ut as decodeUnknownOption, Xa as exists, Xt as makeFilter, ho as none, io as fromUndefinedOr, lo as isNone, mo as match, oo as getOrNull, po as map, vo as toArray, xt as NonEmptyString } from "../src-DjOLw-ft.mjs";
|
|
3
|
+
import { l as startTool, o as DESTROY_TIMEOUT_MS, s as createdSandbox, w as noop } from "../saved-sandboxes-BMjkAVGx.mjs";
|
|
4
|
+
import { r as onPath, t as answers } from "../kubectl-Ck04daor.mjs";
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
|
+
import { once } from "node:events";
|
|
6
7
|
import { parseArgs } from "node:util";
|
|
7
8
|
// src/cli/commands/t3.ts
|
|
8
9
|
const T3_PORT = 3773;
|
|
9
10
|
const T3 = process.platform === "win32" ? "t3.exe" : "t3";
|
|
10
11
|
const VERB = "link a sandbox to T3 Code";
|
|
12
|
+
const USAGE = `Usage: sandcovery-t3 [--access <access>] [--env NAME=value]... [--provider <provider>]... [--ttl <seconds>]
|
|
13
|
+
|
|
14
|
+
Creates a sandbox, installs the same version of T3 Code there as your local t3, links it to your T3 Code as an environment, and prints the sandbox's ID. Any failed step destroys the sandbox.
|
|
15
|
+
|
|
16
|
+
--access <access> What agents on your computer may do there, as t3 environment link --access takes it.
|
|
17
|
+
--env NAME=value A variable only T3 Code and the agents it runs get. Repeat it for each variable.
|
|
18
|
+
--provider <provider> A provider to use. Repeat it for each provider.
|
|
19
|
+
--ttl <seconds> The sandbox's TTL in seconds.
|
|
20
|
+
-h, --help Print this help.
|
|
21
|
+
|
|
22
|
+
It reads your key from SANDCOVERY_API_KEY, or from sandcovery login, and the API origin from SANDCOVERY_BASE_URL.
|
|
23
|
+
`;
|
|
11
24
|
const EXEC_TIMEOUT_SECONDS = 600;
|
|
12
25
|
const ANSWER_WAIT_MS = 12e4;
|
|
13
26
|
const T3_HOME = "\"$HOME/.t3\"";
|
|
@@ -30,27 +43,26 @@ const PAIR_COMMAND = [
|
|
|
30
43
|
`for _ in $(seq 60); do curl -fsS -m 5 -o /dev/null http://127.0.0.1:${String(T3_PORT)}/.well-known/t3/environment && break; sleep 1; done`,
|
|
31
44
|
`t3 auth pairing create --base-dir ${T3_HOME} --json --ttl 10m --label sandcovery`
|
|
32
45
|
].join("\n");
|
|
33
|
-
const decodePairing = decodeUnknownOption(fromJsonString(Struct({ credential: NonEmptyString })));
|
|
46
|
+
const decodePairing = decodeUnknownOption(fromJsonString(Struct({ credential: NonEmptyString.check(makeFilter((credential) => !credential.includes("\n"))) })));
|
|
34
47
|
const providerOf = (sandbox) => sandbox.provider ?? "its provider";
|
|
35
|
-
const ranT3 = async ({ args, signal, t3 }) => {
|
|
36
|
-
const closed = Promise.withResolvers();
|
|
48
|
+
const ranT3 = async ({ args, input, signal, t3 }) => {
|
|
37
49
|
const child = spawn(t3, args, {
|
|
38
50
|
signal,
|
|
39
51
|
stdio: [
|
|
40
|
-
"
|
|
52
|
+
"pipe",
|
|
41
53
|
"pipe",
|
|
42
54
|
"pipe"
|
|
43
55
|
]
|
|
44
56
|
});
|
|
45
|
-
child.
|
|
46
|
-
child.
|
|
47
|
-
const [stdout, stderr
|
|
57
|
+
child.stdin.on("error", noop);
|
|
58
|
+
child.stdin.end(input);
|
|
59
|
+
const [stdout, stderr] = await Promise.all([
|
|
48
60
|
child.stdout.toArray(),
|
|
49
61
|
child.stderr.toArray(),
|
|
50
|
-
|
|
62
|
+
once(child, "close")
|
|
51
63
|
]);
|
|
52
64
|
return {
|
|
53
|
-
code:
|
|
65
|
+
code: child.exitCode ?? 1,
|
|
54
66
|
stderr: Buffer.concat(stderr).toString(),
|
|
55
67
|
stdout: Buffer.concat(stdout).toString()
|
|
56
68
|
};
|
|
@@ -58,8 +70,8 @@ const ranT3 = async ({ args, signal, t3 }) => {
|
|
|
58
70
|
const ranInSandbox = async ({ command, env, sandbox, step, tool }) => {
|
|
59
71
|
const result = await tool.client.sandboxes.exec(sandbox.id, {
|
|
60
72
|
command,
|
|
61
|
-
cwd: null,
|
|
62
73
|
env,
|
|
74
|
+
cwd: null,
|
|
63
75
|
timeout_seconds: EXEC_TIMEOUT_SECONDS
|
|
64
76
|
}, { signal: tool.signal });
|
|
65
77
|
if (result.exit_code !== 0) throw new Error(`Can't ${VERB}. Couldn't ${step} in sandbox ${sandbox.id} on ${providerOf(sandbox)}, so Sandcovery destroyed it.`, { cause: result.stderr.slice(-2e3) });
|
|
@@ -74,40 +86,40 @@ const linked = async ({ access, env, sandbox, t3, tool, version }) => {
|
|
|
74
86
|
await ranInSandbox({
|
|
75
87
|
command: INSTALL_COMMAND,
|
|
76
88
|
env: { T3CODE_VERSION: version },
|
|
77
|
-
sandbox,
|
|
78
89
|
step: `install T3 Code ${version}`,
|
|
90
|
+
sandbox,
|
|
79
91
|
tool
|
|
80
92
|
});
|
|
81
93
|
await ranInSandbox({
|
|
82
94
|
command: SERVE_COMMAND,
|
|
95
|
+
step: "start T3 Code",
|
|
83
96
|
env,
|
|
84
97
|
sandbox,
|
|
85
|
-
step: "start T3 Code",
|
|
86
98
|
tool
|
|
87
99
|
});
|
|
88
100
|
const paired = await ranInSandbox({
|
|
89
101
|
command: PAIR_COMMAND,
|
|
90
102
|
env: null,
|
|
91
|
-
sandbox,
|
|
92
103
|
step: "make a T3 Code pairing code",
|
|
104
|
+
sandbox,
|
|
93
105
|
tool
|
|
94
106
|
});
|
|
95
107
|
const pairing = decodePairing(paired.trim());
|
|
96
108
|
if (isNone(pairing)) throw new Error(`Can't ${VERB}. T3 Code in sandbox ${sandbox.id} on ${providerOf(sandbox)} gave no pairing code, so Sandcovery destroyed it.`);
|
|
97
109
|
if (!await answers({
|
|
98
110
|
deadline: Date.now() + ANSWER_WAIT_MS,
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
url: `${url}/.well-known/t3/environment`,
|
|
112
|
+
tool
|
|
101
113
|
})) throw new Error(`Can't ${VERB}. T3 Code in sandbox ${sandbox.id} on ${providerOf(sandbox)} didn't answer at ${url} within 2 minutes, so Sandcovery destroyed it.`);
|
|
102
114
|
const link = await ranT3({
|
|
103
115
|
args: [
|
|
104
116
|
"environment",
|
|
105
117
|
"link",
|
|
106
|
-
|
|
107
|
-
"
|
|
108
|
-
pairing.value.credential,
|
|
118
|
+
"--from",
|
|
119
|
+
"-",
|
|
109
120
|
...toArray(access).flatMap((value) => ["--access", value])
|
|
110
121
|
],
|
|
122
|
+
input: `${url} ${pairing.value.credential}\n`,
|
|
111
123
|
signal: tool.signal,
|
|
112
124
|
t3
|
|
113
125
|
});
|
|
@@ -123,6 +135,10 @@ const t3Run = async (tool) => {
|
|
|
123
135
|
type: "string",
|
|
124
136
|
multiple: true
|
|
125
137
|
},
|
|
138
|
+
help: {
|
|
139
|
+
short: "h",
|
|
140
|
+
type: "boolean"
|
|
141
|
+
},
|
|
126
142
|
provider: {
|
|
127
143
|
type: "string",
|
|
128
144
|
multiple: true
|
|
@@ -131,6 +147,10 @@ const t3Run = async (tool) => {
|
|
|
131
147
|
},
|
|
132
148
|
strict: true
|
|
133
149
|
});
|
|
150
|
+
if (values.help === true) {
|
|
151
|
+
tool.io.stdout.write(USAGE);
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
134
154
|
const env = Object.fromEntries((values.env ?? []).map((pair) => {
|
|
135
155
|
const at = pair.indexOf("=");
|
|
136
156
|
if (at < 1) throw new Error("--env takes NAME=value.");
|
|
@@ -142,57 +162,62 @@ const t3Run = async (tool) => {
|
|
|
142
162
|
if (isNone(t3)) throw new Error(`Can't ${VERB}. t3 isn't on PATH.`);
|
|
143
163
|
const own = await ranT3({
|
|
144
164
|
args: ["--version"],
|
|
165
|
+
input: "",
|
|
145
166
|
signal: tool.signal,
|
|
146
167
|
t3: t3.value
|
|
147
168
|
});
|
|
148
169
|
const word = own.stdout.trim().split(" ").at(-1) ?? "";
|
|
149
170
|
const version = word.startsWith("v") ? word.slice(1) : word;
|
|
150
171
|
if (own.code !== 0 || version === "") throw new Error(`Can't ${VERB}. ${t3.value} --version printed no version.`, { cause: own.stderr.slice(-2e3) });
|
|
151
|
-
const sandbox = await
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
172
|
+
const sandbox = await createdSandbox({
|
|
173
|
+
request: {
|
|
174
|
+
api_key_id: null,
|
|
175
|
+
disk_mib: null,
|
|
176
|
+
egress: null,
|
|
177
|
+
env: null,
|
|
178
|
+
gpu: null,
|
|
179
|
+
idle_timeout_seconds: null,
|
|
180
|
+
image: null,
|
|
181
|
+
os: null,
|
|
182
|
+
ports: [T3_PORT],
|
|
183
|
+
provider: match(fromUndefinedOr(values.provider), {
|
|
184
|
+
onNone: () => null,
|
|
185
|
+
onSome: (only) => ({
|
|
186
|
+
allow_fallbacks: null,
|
|
187
|
+
ignore: null,
|
|
188
|
+
order: null,
|
|
189
|
+
sort: null,
|
|
190
|
+
only
|
|
191
|
+
})
|
|
192
|
+
}),
|
|
193
|
+
region: null,
|
|
194
|
+
slug: null,
|
|
195
|
+
slugs: null,
|
|
196
|
+
snapshot_id: null,
|
|
197
|
+
ttl_seconds: getOrNull(ttl)
|
|
198
|
+
},
|
|
199
|
+
tool
|
|
178
200
|
});
|
|
179
201
|
try {
|
|
180
202
|
const said = await linked({
|
|
181
203
|
access: fromUndefinedOr(values.access),
|
|
204
|
+
t3: t3.value,
|
|
182
205
|
env,
|
|
183
206
|
sandbox,
|
|
184
|
-
t3: t3.value,
|
|
185
207
|
tool,
|
|
186
208
|
version
|
|
187
209
|
});
|
|
188
210
|
tool.io.stderr.write(`${said}\nT3 Code ${version} in sandbox ${sandbox.id} runs until ${sandbox.expires_at}. sandcovery sandboxes destroySandbox --sandbox_id ${sandbox.id} ends it sooner, and t3 environment unlink then removes the link here.\n`);
|
|
189
211
|
tool.io.stdout.write(`${sandbox.id}\n`);
|
|
190
212
|
} catch (error) {
|
|
191
|
-
|
|
213
|
+
await tool.client.sandboxes.destroy(sandbox.id, { signal: AbortSignal.timeout(DESTROY_TIMEOUT_MS) });
|
|
192
214
|
throw error;
|
|
193
215
|
}
|
|
194
216
|
return 0;
|
|
195
217
|
};
|
|
196
218
|
// src/cli/sandcovery-t3.ts
|
|
197
|
-
await startTool({
|
|
219
|
+
await startTool({
|
|
220
|
+
run: t3Run,
|
|
221
|
+
server: none()
|
|
222
|
+
});
|
|
198
223
|
export {};
|