sandcovery 0.6.2 → 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 +45 -29
- package/dist/cli/index.mjs +14826 -2
- package/dist/cli/sandcovery-docker.mjs +8552 -4
- package/dist/cli/sandcovery-kubectl.mjs +9 -4
- package/dist/cli/sandcovery-t3.d.mts +1 -0
- package/dist/cli/sandcovery-t3.mjs +223 -0
- package/dist/index.d.mts +8737 -142
- package/dist/index.mjs +1 -1
- package/dist/kubectl-Ck04daor.mjs +472 -0
- package/dist/saved-sandboxes-BMjkAVGx.mjs +389 -0
- package/dist/src-DjOLw-ft.mjs +36591 -0
- 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/dist/types.mjs +6 -1
- package/package.json +13 -10
- package/dist/Schema-CoX0a2_o.mjs +0 -18812
- package/dist/handlers-CpLa3dvg.mjs +0 -19715
- package/dist/port-forwarder-DvSPr-Tg.mjs +0 -5360
- package/dist/posthog-project-BpOd2VxW.mjs +0 -1
- package/dist/posthog-project-CdWw_ofg.mjs +0 -22
- package/dist/src-BqfeIyqj.mjs +0 -2047
- package/dist/start-D1LPu-aN.mjs +0 -1604
- package/dist/telemetry-DBPKT8Ap.mjs +0 -43
- package/dist/telemetry-delivery-BSGibWPJ.mjs +0 -8712
- package/dist/types-C4amb2QE.d.mts +0 -793
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
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";
|
|
3
5
|
// src/cli/sandcovery-kubectl.ts
|
|
4
|
-
await
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
await startTool({
|
|
7
|
+
run: kubectlRun,
|
|
8
|
+
server: some({
|
|
9
|
+
serve: watchIdle,
|
|
10
|
+
variable: IDLE_WATCHER_ENV
|
|
11
|
+
})
|
|
7
12
|
});
|
|
8
13
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
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
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import { once } from "node:events";
|
|
7
|
+
import { parseArgs } from "node:util";
|
|
8
|
+
// src/cli/commands/t3.ts
|
|
9
|
+
const T3_PORT = 3773;
|
|
10
|
+
const T3 = process.platform === "win32" ? "t3.exe" : "t3";
|
|
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
|
+
`;
|
|
24
|
+
const EXEC_TIMEOUT_SECONDS = 600;
|
|
25
|
+
const ANSWER_WAIT_MS = 12e4;
|
|
26
|
+
const T3_HOME = "\"$HOME/.t3\"";
|
|
27
|
+
const ON_PATH = "export PATH=\"$HOME/.local/bin:$PATH\"";
|
|
28
|
+
const INSTALL_COMMAND = [
|
|
29
|
+
"set -e",
|
|
30
|
+
ON_PATH,
|
|
31
|
+
"curl -fsSL https://t3.codes/install.sh -o /tmp/t3-install.sh",
|
|
32
|
+
"sh /tmp/t3-install.sh",
|
|
33
|
+
"if ! command -v claude >/dev/null; then",
|
|
34
|
+
" curl -fsSL https://claude.ai/install.sh -o /tmp/claude-install.sh",
|
|
35
|
+
" bash /tmp/claude-install.sh",
|
|
36
|
+
"fi",
|
|
37
|
+
`mkdir -p ${T3_HOME}/userdata`,
|
|
38
|
+
`printf '%s\\n' '{"linkedEnvironmentsEnabled":true}' >${T3_HOME}/userdata/settings.json`
|
|
39
|
+
].join("\n");
|
|
40
|
+
const SERVE_COMMAND = [ON_PATH, `setsid t3 serve --host 0.0.0.0 --port ${String(T3_PORT)} --base-dir ${T3_HOME} --no-browser </dev/null >>${T3_HOME}/serve.log 2>&1 &`].join("\n");
|
|
41
|
+
const PAIR_COMMAND = [
|
|
42
|
+
ON_PATH,
|
|
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`,
|
|
44
|
+
`t3 auth pairing create --base-dir ${T3_HOME} --json --ttl 10m --label sandcovery`
|
|
45
|
+
].join("\n");
|
|
46
|
+
const decodePairing = decodeUnknownOption(fromJsonString(Struct({ credential: NonEmptyString.check(makeFilter((credential) => !credential.includes("\n"))) })));
|
|
47
|
+
const providerOf = (sandbox) => sandbox.provider ?? "its provider";
|
|
48
|
+
const ranT3 = async ({ args, input, signal, t3 }) => {
|
|
49
|
+
const child = spawn(t3, args, {
|
|
50
|
+
signal,
|
|
51
|
+
stdio: [
|
|
52
|
+
"pipe",
|
|
53
|
+
"pipe",
|
|
54
|
+
"pipe"
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
child.stdin.on("error", noop);
|
|
58
|
+
child.stdin.end(input);
|
|
59
|
+
const [stdout, stderr] = await Promise.all([
|
|
60
|
+
child.stdout.toArray(),
|
|
61
|
+
child.stderr.toArray(),
|
|
62
|
+
once(child, "close")
|
|
63
|
+
]);
|
|
64
|
+
return {
|
|
65
|
+
code: child.exitCode ?? 1,
|
|
66
|
+
stderr: Buffer.concat(stderr).toString(),
|
|
67
|
+
stdout: Buffer.concat(stdout).toString()
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const ranInSandbox = async ({ command, env, sandbox, step, tool }) => {
|
|
71
|
+
const result = await tool.client.sandboxes.exec(sandbox.id, {
|
|
72
|
+
command,
|
|
73
|
+
env,
|
|
74
|
+
cwd: null,
|
|
75
|
+
timeout_seconds: EXEC_TIMEOUT_SECONDS
|
|
76
|
+
}, { signal: tool.signal });
|
|
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) });
|
|
78
|
+
return result.stdout;
|
|
79
|
+
};
|
|
80
|
+
const linked = async ({ access, env, sandbox, t3, tool, version }) => {
|
|
81
|
+
const preview = await tool.client.sandboxes.portPreview(sandbox.id, T3_PORT, { signal: tool.signal });
|
|
82
|
+
const address = new URL(preview.url);
|
|
83
|
+
if (Object.keys(preview.headers).length > 0 || address.href !== `${address.origin}/`) throw new Error(`Can't ${VERB} on ${providerOf(sandbox)}. Its URL for port ${String(T3_PORT)} needs headers or a path or query, and t3 environment link sends none of them, so Sandcovery destroyed sandbox ${sandbox.id}. Pick another provider with --provider.`);
|
|
84
|
+
if (preview.expires_at !== null && Date.parse(preview.expires_at) < Date.parse(sandbox.expires_at)) throw new Error(`Can't ${VERB} on ${providerOf(sandbox)}. Its URL for port ${String(T3_PORT)} stops working at ${preview.expires_at}, before the sandbox ends at ${sandbox.expires_at}, so Sandcovery destroyed sandbox ${sandbox.id}. Pick another provider with --provider, or a shorter --ttl.`);
|
|
85
|
+
const url = address.origin;
|
|
86
|
+
await ranInSandbox({
|
|
87
|
+
command: INSTALL_COMMAND,
|
|
88
|
+
env: { T3CODE_VERSION: version },
|
|
89
|
+
step: `install T3 Code ${version}`,
|
|
90
|
+
sandbox,
|
|
91
|
+
tool
|
|
92
|
+
});
|
|
93
|
+
await ranInSandbox({
|
|
94
|
+
command: SERVE_COMMAND,
|
|
95
|
+
step: "start T3 Code",
|
|
96
|
+
env,
|
|
97
|
+
sandbox,
|
|
98
|
+
tool
|
|
99
|
+
});
|
|
100
|
+
const paired = await ranInSandbox({
|
|
101
|
+
command: PAIR_COMMAND,
|
|
102
|
+
env: null,
|
|
103
|
+
step: "make a T3 Code pairing code",
|
|
104
|
+
sandbox,
|
|
105
|
+
tool
|
|
106
|
+
});
|
|
107
|
+
const pairing = decodePairing(paired.trim());
|
|
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.`);
|
|
109
|
+
if (!await answers({
|
|
110
|
+
deadline: Date.now() + ANSWER_WAIT_MS,
|
|
111
|
+
url: `${url}/.well-known/t3/environment`,
|
|
112
|
+
tool
|
|
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.`);
|
|
114
|
+
const link = await ranT3({
|
|
115
|
+
args: [
|
|
116
|
+
"environment",
|
|
117
|
+
"link",
|
|
118
|
+
"--from",
|
|
119
|
+
"-",
|
|
120
|
+
...toArray(access).flatMap((value) => ["--access", value])
|
|
121
|
+
],
|
|
122
|
+
input: `${url} ${pairing.value.credential}\n`,
|
|
123
|
+
signal: tool.signal,
|
|
124
|
+
t3
|
|
125
|
+
});
|
|
126
|
+
if (link.code !== 0) throw new Error(`Can't ${VERB}. t3 environment link exited with ${String(link.code)}, so Sandcovery destroyed sandbox ${sandbox.id}.`, { cause: `${link.stdout}${link.stderr}`.slice(-2e3) });
|
|
127
|
+
return link.stdout.trim();
|
|
128
|
+
};
|
|
129
|
+
const t3Run = async (tool) => {
|
|
130
|
+
const { values } = parseArgs({
|
|
131
|
+
args: [...tool.args],
|
|
132
|
+
options: {
|
|
133
|
+
access: { type: "string" },
|
|
134
|
+
env: {
|
|
135
|
+
type: "string",
|
|
136
|
+
multiple: true
|
|
137
|
+
},
|
|
138
|
+
help: {
|
|
139
|
+
short: "h",
|
|
140
|
+
type: "boolean"
|
|
141
|
+
},
|
|
142
|
+
provider: {
|
|
143
|
+
type: "string",
|
|
144
|
+
multiple: true
|
|
145
|
+
},
|
|
146
|
+
ttl: { type: "string" }
|
|
147
|
+
},
|
|
148
|
+
strict: true
|
|
149
|
+
});
|
|
150
|
+
if (values.help === true) {
|
|
151
|
+
tool.io.stdout.write(USAGE);
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
const env = Object.fromEntries((values.env ?? []).map((pair) => {
|
|
155
|
+
const at = pair.indexOf("=");
|
|
156
|
+
if (at < 1) throw new Error("--env takes NAME=value.");
|
|
157
|
+
return [pair.slice(0, at), pair.slice(at + 1)];
|
|
158
|
+
}));
|
|
159
|
+
const ttl = fromUndefinedOr(values.ttl).pipe(map(Number));
|
|
160
|
+
if (exists(ttl, (seconds) => !Number.isSafeInteger(seconds) || seconds < 1)) throw new Error("--ttl takes a number of seconds.");
|
|
161
|
+
const t3 = onPath(T3);
|
|
162
|
+
if (isNone(t3)) throw new Error(`Can't ${VERB}. t3 isn't on PATH.`);
|
|
163
|
+
const own = await ranT3({
|
|
164
|
+
args: ["--version"],
|
|
165
|
+
input: "",
|
|
166
|
+
signal: tool.signal,
|
|
167
|
+
t3: t3.value
|
|
168
|
+
});
|
|
169
|
+
const word = own.stdout.trim().split(" ").at(-1) ?? "";
|
|
170
|
+
const version = word.startsWith("v") ? word.slice(1) : word;
|
|
171
|
+
if (own.code !== 0 || version === "") throw new Error(`Can't ${VERB}. ${t3.value} --version printed no version.`, { cause: own.stderr.slice(-2e3) });
|
|
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
|
|
200
|
+
});
|
|
201
|
+
try {
|
|
202
|
+
const said = await linked({
|
|
203
|
+
access: fromUndefinedOr(values.access),
|
|
204
|
+
t3: t3.value,
|
|
205
|
+
env,
|
|
206
|
+
sandbox,
|
|
207
|
+
tool,
|
|
208
|
+
version
|
|
209
|
+
});
|
|
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`);
|
|
211
|
+
tool.io.stdout.write(`${sandbox.id}\n`);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
await tool.client.sandboxes.destroy(sandbox.id, { signal: AbortSignal.timeout(DESTROY_TIMEOUT_MS) });
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
return 0;
|
|
217
|
+
};
|
|
218
|
+
// src/cli/sandcovery-t3.ts
|
|
219
|
+
await startTool({
|
|
220
|
+
run: t3Run,
|
|
221
|
+
server: none()
|
|
222
|
+
});
|
|
223
|
+
export {};
|