@raytrace-cli/cli 0.6.0 → 0.7.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 +27 -1
- package/bin/raytrace.mjs +12 -0
- package/package.json +1 -1
- package/src/api.mjs +57 -0
- package/src/auth.mjs +35 -1
- package/src/beta.mjs +96 -0
- package/src/sandbox.mjs +60 -37
package/README.md
CHANGED
|
@@ -185,6 +185,7 @@ raytrace key # which keys are set
|
|
|
185
185
|
| `raytrace sandbox start\|stop [id]` | start or stop a sandbox; stopping keeps its files |
|
|
186
186
|
| `raytrace sandbox destroy [id]` | delete a sandbox; its recorded sessions are kept |
|
|
187
187
|
| `raytrace auth login` | sign in to RayTrace; `status`, `logout` |
|
|
188
|
+
| `raytrace --code <code>` | beta invite: redeem a code RayTrace gave you (signed in first) for one $10-credit sandbox; codes are single-use, are deleted on redemption, and expire after 3 days, as does the credit |
|
|
188
189
|
| `raytrace sandbox create --local [--name <name>]` | the same sandbox in a Linux VM on this machine; offers to download Lima if needed (`--yes` skips the question) |
|
|
189
190
|
| `raytrace sandbox list --local` | your local sandboxes; their names work with `connect`, `start`, `stop` and `destroy` |
|
|
190
191
|
| `raytrace sandbox destroy <name> [--delete-logs \| --keep-logs]` | delete a local sandbox; asks whether its captured logs go too, or move to `~/.raytrace/archive` |
|
|
@@ -192,6 +193,29 @@ raytrace key # which keys are set
|
|
|
192
193
|
| `raytrace doctor` | what this machine has and lacks, local sandboxes included |
|
|
193
194
|
| `raytrace key [openrouter\|typesafe] [--remove]` | your keys for the dashboard's AI features; asked for, never taken as an argument |
|
|
194
195
|
|
|
196
|
+
## Beta invites
|
|
197
|
+
|
|
198
|
+
If RayTrace gave you a beta code, sign in first, redeem it, then create your
|
|
199
|
+
sandbox — in that order:
|
|
200
|
+
|
|
201
|
+
```sh
|
|
202
|
+
raytrace auth login
|
|
203
|
+
raytrace --code <code> # also: raytrace code <code>
|
|
204
|
+
raytrace sandbox create
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Redeeming deletes the code on RayTrace's servers; it can never be used
|
|
208
|
+
again, by anyone. Codes expire 3 days after they are issued, and the $10 of
|
|
209
|
+
OpenRouter credit expires 3 days after you redeem it, so do not sit on
|
|
210
|
+
either. Your account shows as **Beta** in the cloud dashboard until the
|
|
211
|
+
credit ends, and the credited sandbox is tagged Beta there too. Connecting
|
|
212
|
+
to a credited sandbox after its 3 days are up warns you that model calls
|
|
213
|
+
will be refused; the sandbox itself still opens.
|
|
214
|
+
|
|
215
|
+
Codes are minted only from the backend repo (`raytrace`:
|
|
216
|
+
`python3 worker/gvisor/mint_beta_codes.py`, 10 at a time); this CLI never
|
|
217
|
+
generates them.
|
|
218
|
+
|
|
195
219
|
## Exporting traces
|
|
196
220
|
|
|
197
221
|
Export a recorded session directly from local evidence, even when RayTrace and the VM are stopped:
|
|
@@ -222,7 +246,9 @@ RayTrace's servers.
|
|
|
222
246
|
organizations cannot.
|
|
223
247
|
- `raytrace auth login` keeps your sign-in in the macOS Keychain or the Linux
|
|
224
248
|
secret service (a file readable only by you where neither is available), and
|
|
225
|
-
`raytrace auth logout` removes it.
|
|
249
|
+
`raytrace auth logout` removes it. Cloud commands ask you to sign in again
|
|
250
|
+
after 2 days with no cloud use (any cloud command resets that clock); the
|
|
251
|
+
command then continues where it left off. Local recording never asks.
|
|
226
252
|
- What RayTrace records locally stays in `~/.raytrace`, readable only by you.
|
|
227
253
|
Its local API takes the token in `~/.raytrace/api-token`, so another account
|
|
228
254
|
on the machine cannot read your traces or spend your OpenRouter key through
|
package/bin/raytrace.mjs
CHANGED
|
@@ -18,6 +18,8 @@ Cloud sandboxes:
|
|
|
18
18
|
(up to 200 MiB, 25 MiB a file, 20,000 files)
|
|
19
19
|
raytrace connect [id] a terminal in it; with one sandbox the id is
|
|
20
20
|
optional (same as: raytrace sandbox shell [id])
|
|
21
|
+
raytrace --code <code> beta invite: redeem a code RayTrace gave you for one
|
|
22
|
+
$10-credit sandbox (signed in first; also: raytrace code <code>)
|
|
21
23
|
raytrace sandbox list
|
|
22
24
|
raytrace sandbox start|stop [id]
|
|
23
25
|
raytrace sandbox destroy [id] [--yes] [--keep-traces]
|
|
@@ -79,6 +81,16 @@ if (command === '--version' || command === '-v') {
|
|
|
79
81
|
}
|
|
80
82
|
if (!command || command === 'help' || command === '--help' || command === '-h') { console.log(HELP); process.exit(0); }
|
|
81
83
|
|
|
84
|
+
// `raytrace --code <code>` (also `raytrace code <code>`): redeem a beta code.
|
|
85
|
+
if (command === '--code' || command.startsWith('--code=') || command === 'code') {
|
|
86
|
+
const beta = await import('../src/beta.mjs');
|
|
87
|
+
const code = command.startsWith('--code=') ? command.slice('--code='.length) : rest[0];
|
|
88
|
+
const extra = command.startsWith('--code=') ? rest.length : rest.length - 1;
|
|
89
|
+
if (!code || extra !== 0) { console.error('Usage: raytrace --code <code>'); process.exit(2); }
|
|
90
|
+
try { await beta.redeemBetaCode(code); process.exit(0); }
|
|
91
|
+
catch (error) { console.error(`raytrace --code: ${error.message}`); process.exit(1); }
|
|
92
|
+
}
|
|
93
|
+
|
|
82
94
|
const commands = await import('../src/commands.mjs');
|
|
83
95
|
|
|
84
96
|
// `codex` passes everything after it straight to Codex.
|
package/package.json
CHANGED
package/src/api.mjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Shared client for RayTrace's cloud API (https://api.raytracer.si;
|
|
2
|
+
// RAYTRACE_API_URL points elsewhere). Requests carry your `raytrace auth
|
|
3
|
+
// login` token; RAYTRACE_API_KEY overrides it for a server running without
|
|
4
|
+
// accounts (development).
|
|
5
|
+
import { accessToken, consumeIdleNotice, login } from './auth.mjs';
|
|
6
|
+
import { readConfig } from './config.mjs';
|
|
7
|
+
import { interactive } from './prompt.mjs';
|
|
8
|
+
|
|
9
|
+
const say = (line = '') => console.log(line);
|
|
10
|
+
const API = 'https://api.raytracer.si';
|
|
11
|
+
|
|
12
|
+
export const unreachable = (url) => new Error(`Cannot reach RayTrace at ${url.origin}. Check your connection; `
|
|
13
|
+
+ 'networks that inspect HTTPS (some company Wi-Fi) may block it.');
|
|
14
|
+
|
|
15
|
+
export class ApiError extends Error {
|
|
16
|
+
constructor(message, { status = null, data = {} } = {}) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = 'ApiError';
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.data = data;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** True when a development API key overrides the signed-in account. */
|
|
25
|
+
export function hasApiKeyOverride() {
|
|
26
|
+
return Boolean(process.env.RAYTRACE_API_KEY || readConfig().RAYTRACE_API_KEY);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function api({ autoLogin = true } = {}) {
|
|
30
|
+
const config = readConfig();
|
|
31
|
+
const url = process.env.RAYTRACE_API_URL || config.RAYTRACE_API_URL || API;
|
|
32
|
+
let key = process.env.RAYTRACE_API_KEY || config.RAYTRACE_API_KEY || await accessToken();
|
|
33
|
+
if (!key) {
|
|
34
|
+
if (!autoLogin || !interactive()) throw new Error('Not signed in. Run: raytrace auth login');
|
|
35
|
+
say(consumeIdleNotice()
|
|
36
|
+
? 'You have not used RayTrace cloud for 2 days, so you need to sign in again.'
|
|
37
|
+
: 'You are not signed in to RayTrace yet.');
|
|
38
|
+
await login();
|
|
39
|
+
key = await accessToken();
|
|
40
|
+
if (!key) throw new Error('Not signed in. Run: raytrace auth login');
|
|
41
|
+
say();
|
|
42
|
+
}
|
|
43
|
+
return { url: new URL(url), key };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function call(method, path, { body, headers = {}, autoLogin = true } = {}) {
|
|
47
|
+
const { url, key } = await api({ autoLogin });
|
|
48
|
+
let response;
|
|
49
|
+
try {
|
|
50
|
+
response = await fetch(new URL(path, url), { method, body, headers: { authorization: `Bearer ${key}`, ...headers } });
|
|
51
|
+
} catch {
|
|
52
|
+
throw unreachable(url);
|
|
53
|
+
}
|
|
54
|
+
const data = await response.json().catch(() => ({}));
|
|
55
|
+
if (!response.ok) throw new ApiError(data.error || `HTTP ${response.status}`, { status: response.status, data });
|
|
56
|
+
return data;
|
|
57
|
+
}
|
package/src/auth.mjs
CHANGED
|
@@ -75,15 +75,42 @@ function keep(data) {
|
|
|
75
75
|
access_token: data.access_token, refresh_token: data.refresh_token,
|
|
76
76
|
user: { id: data.user?.id, email: data.user?.email, name: [data.user?.first_name, data.user?.last_name].filter(Boolean).join(' ') },
|
|
77
77
|
organization_id: data.organization_id ?? null,
|
|
78
|
+
last_used_at: Date.now(),
|
|
78
79
|
};
|
|
79
80
|
}
|
|
80
81
|
|
|
82
|
+
// Cloud use asks for a fresh sign-in after 2 idle days (sliding: any cloud
|
|
83
|
+
// command resets the clock). Local recording never consults this.
|
|
84
|
+
export const CLOUD_IDLE_LIMIT_MS = 2 * 86_400_000;
|
|
85
|
+
const TOUCH_EVERY_MS = 3_600_000; // last_used_at is rewritten at most hourly
|
|
86
|
+
let idleNotice = false;
|
|
87
|
+
|
|
88
|
+
export const isIdleExpired = (session, now = Date.now()) =>
|
|
89
|
+
Boolean(session?.last_used_at && now - session.last_used_at > CLOUD_IDLE_LIMIT_MS);
|
|
90
|
+
|
|
91
|
+
/** True once after accessToken() dropped a session for idleness. */
|
|
92
|
+
export function consumeIdleNotice() { const was = idleNotice; idleNotice = false; return was; }
|
|
93
|
+
|
|
81
94
|
/** A current access token, refreshed when it is about to expire; null when signed out. */
|
|
82
95
|
export async function accessToken() {
|
|
83
96
|
const session = load();
|
|
84
97
|
if (!session?.access_token) return null;
|
|
98
|
+
if (isIdleExpired(session)) {
|
|
99
|
+
// Idle too long: drop the session so the cloud path starts a fresh
|
|
100
|
+
// sign-in and continues (it says why via consumeIdleNotice()).
|
|
101
|
+
forget();
|
|
102
|
+
idleNotice = true;
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
85
105
|
const { exp = 0 } = claims(session.access_token);
|
|
86
|
-
if (exp * 1000 - Date.now() > 60_000)
|
|
106
|
+
if (exp * 1000 - Date.now() > 60_000) {
|
|
107
|
+
// Sliding window: cloud use resets the idle clock (throttled writes;
|
|
108
|
+
// sessions saved before this field existed start their clock now).
|
|
109
|
+
if (!session.last_used_at || Date.now() - session.last_used_at > TOUCH_EVERY_MS) {
|
|
110
|
+
try { save({ ...session, last_used_at: Date.now() }); } catch { /* the token still works */ }
|
|
111
|
+
}
|
|
112
|
+
return session.access_token;
|
|
113
|
+
}
|
|
87
114
|
if (!session.refresh_token) return null;
|
|
88
115
|
const { status, data } = await workos('/authenticate', {
|
|
89
116
|
grant_type: 'refresh_token', refresh_token: session.refresh_token, client_id: CLIENT_ID,
|
|
@@ -154,6 +181,13 @@ export async function status() {
|
|
|
154
181
|
say(`Organization: ${org || session.organization_id || 'personal'}`);
|
|
155
182
|
const left = Math.round((exp * 1000 - Date.now()) / 60000);
|
|
156
183
|
say(left > 0 ? `Access token valid for ${left} more min; renewed automatically.` : 'Access token expired; it is renewed on the next command.');
|
|
184
|
+
// Beta is a cloud entitlement, separate from any local licence tier.
|
|
185
|
+
try {
|
|
186
|
+
const { betaStatus, formatCreditDeadline } = await import('./beta.mjs');
|
|
187
|
+
const beta = await betaStatus();
|
|
188
|
+
if (beta?.sandbox_consumed) say(`Beta: $10 credit used${beta.credited_sandbox_id ? ` on ${beta.credited_sandbox_id}` : ''}.`);
|
|
189
|
+
else if (beta?.entitled) say(`Beta: $${beta.credit_usd ?? 10} credit available${beta.credit_expires_at ? ` until ${formatCreditDeadline(beta.credit_expires_at)}` : ''} (raytrace sandbox create).`);
|
|
190
|
+
} catch { /* no beta entitlement, old backend, or offline: nothing to add */ }
|
|
157
191
|
}
|
|
158
192
|
|
|
159
193
|
export async function logout() {
|
package/src/beta.mjs
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// `raytrace --code <code>`: redeem a single-use beta code handed out by
|
|
2
|
+
// RayTrace. Sign-in (`raytrace auth login`) is a prerequisite — this command
|
|
3
|
+
// never starts a sign-in flow and never sends the code anywhere until a
|
|
4
|
+
// signed-in account is known. The backend is the source of truth: on a
|
|
5
|
+
// successful redeem it deletes the code irreversibly and binds a $10
|
|
6
|
+
// OpenRouter credit (hard 3-day limit) to the signed-in account. Nothing
|
|
7
|
+
// about the code or entitlement is stored on this machine.
|
|
8
|
+
import { accessToken, consumeIdleNotice } from './auth.mjs';
|
|
9
|
+
import { call, hasApiKeyOverride } from './api.mjs';
|
|
10
|
+
|
|
11
|
+
const say = (line = '') => console.log(line);
|
|
12
|
+
|
|
13
|
+
export const normalizeBetaCode = (code) => String(code ?? '').trim().toUpperCase().replace(/\s+/g, '');
|
|
14
|
+
|
|
15
|
+
// Codes are minted only in the backend repo (raytrace:
|
|
16
|
+
// worker/gvisor/mint_beta_codes.py), which stores SHA-256 hashes of the
|
|
17
|
+
// normalized code in `beta_codes` and deletes the row on redemption. The
|
|
18
|
+
// shared contract: RTB-XXXX-XXXX-XXXX (Crockford Base32), normalized as
|
|
19
|
+
// above, 3-day expiry. This CLI only presents a code; it never mints one.
|
|
20
|
+
|
|
21
|
+
export function formatCreditDeadline(iso, now = Date.now()) {
|
|
22
|
+
if (!iso) return '';
|
|
23
|
+
const when = new Date(iso);
|
|
24
|
+
if (Number.isNaN(when.getTime())) return '';
|
|
25
|
+
const label = when.toLocaleString(undefined, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
|
|
26
|
+
const ms = when.getTime() - now;
|
|
27
|
+
if (ms <= 0) return `${label} (expired)`;
|
|
28
|
+
const hours = Math.round(ms / 3_600_000);
|
|
29
|
+
return `${label} (about ${hours <= 1 ? '1 hour' : `${hours} hours`} left)`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Signed-in check that never starts a login flow and never touches a code. */
|
|
33
|
+
export async function ensureSignedIn(getToken = accessToken) {
|
|
34
|
+
if (hasApiKeyOverride()) return;
|
|
35
|
+
const token = await getToken();
|
|
36
|
+
if (!token) {
|
|
37
|
+
throw new Error(consumeIdleNotice()
|
|
38
|
+
? 'You have not used RayTrace cloud for 2 days, so you need to sign in again. Run: raytrace auth login, then re-run: raytrace --code <your-code>'
|
|
39
|
+
: 'Not signed in. Run: raytrace auth login, then re-run: raytrace --code <your-code>');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function betaStatus(apiCall = call) {
|
|
44
|
+
return apiCall('GET', '/v1/beta/status', { autoLogin: false });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function redeemError(error) {
|
|
48
|
+
switch (error?.status) {
|
|
49
|
+
case 401: return new Error('Not signed in. Run: raytrace auth login, then re-run: raytrace --code <your-code>');
|
|
50
|
+
case 422: return new Error("That code isn't valid. Check it and try again, or ask RayTrace for a new one.");
|
|
51
|
+
case 410: return new Error('That code has expired (codes must be redeemed within 3 days). Ask RayTrace for a new one.');
|
|
52
|
+
case 409: return new Error('This account already has beta credit, so this code was not used. '
|
|
53
|
+
+ 'It can still be given to someone else until it expires.');
|
|
54
|
+
case 429: return new Error('Too many code attempts. Wait a while and try again.');
|
|
55
|
+
default: return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export async function redeemBetaCode(rawCode, { ensure = ensureSignedIn, apiCall = call, log = say } = {}) {
|
|
60
|
+
const code = normalizeBetaCode(rawCode);
|
|
61
|
+
if (!code) throw new Error('Usage: raytrace --code <code>');
|
|
62
|
+
// Prerequisite first: an unauthenticated attempt must not consume,
|
|
63
|
+
// validate, or delete the code on the backend.
|
|
64
|
+
await ensure();
|
|
65
|
+
let data;
|
|
66
|
+
try {
|
|
67
|
+
data = await apiCall('POST', '/v1/beta/redeem', {
|
|
68
|
+
body: JSON.stringify({ code }),
|
|
69
|
+
headers: { 'content-type': 'application/json' },
|
|
70
|
+
autoLogin: false,
|
|
71
|
+
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
const mapped = redeemError(error);
|
|
74
|
+
if (mapped) throw mapped;
|
|
75
|
+
// The code is deleted on success, so a lost response looks like a
|
|
76
|
+
// failure here while the entitlement already exists. Check before
|
|
77
|
+
// reporting failure; the entitlement is what the user needs.
|
|
78
|
+
try {
|
|
79
|
+
const status = await betaStatus(apiCall);
|
|
80
|
+
if (status?.entitled) {
|
|
81
|
+
log("You're already good for beta testing: this account has its beta credit.");
|
|
82
|
+
if (status.credit_expires_at) log(`Use it by ${formatCreditDeadline(status.credit_expires_at)}: raytrace sandbox create`);
|
|
83
|
+
return status;
|
|
84
|
+
}
|
|
85
|
+
} catch { /* fall through to the original error */ }
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
const credit = data?.credit_usd ?? 10;
|
|
89
|
+
log(`You're good for beta testing: $${credit} of Claude Code credit (via OpenRouter) is on this account.`);
|
|
90
|
+
log('Your account now shows as Beta in the RayTrace dashboard.');
|
|
91
|
+
if (data?.credit_expires_at) {
|
|
92
|
+
log(`Hard limit: create your sandbox and use the credit by ${formatCreditDeadline(data.credit_expires_at)}. Unused credit expires.`);
|
|
93
|
+
}
|
|
94
|
+
log('Next, from a Git repository: raytrace sandbox create');
|
|
95
|
+
return data;
|
|
96
|
+
}
|
package/src/sandbox.mjs
CHANGED
|
@@ -13,8 +13,9 @@ import { lstatSync } from 'node:fs';
|
|
|
13
13
|
import { request as httpRequest } from 'node:http';
|
|
14
14
|
import { request as httpsRequest } from 'node:https';
|
|
15
15
|
import { basename, join } from 'node:path';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { account } from './auth.mjs';
|
|
17
|
+
import { api, call, ApiError, unreachable } from './api.mjs';
|
|
18
|
+
import { betaStatus, formatCreditDeadline } from './beta.mjs';
|
|
18
19
|
import { ask, confirm, interactive } from './prompt.mjs';
|
|
19
20
|
import * as local from './local-sandbox.mjs';
|
|
20
21
|
|
|
@@ -27,9 +28,6 @@ const MAX_BYTES = 200 * MIB; // all files, before compression
|
|
|
27
28
|
const MAX_FILES = 20_000;
|
|
28
29
|
const MAX_ARCHIVE = 100 * MIB; // the packed upload
|
|
29
30
|
const ID = /^rtp-[a-f0-9]{32}$/;
|
|
30
|
-
const API = 'https://api.raytracer.si';
|
|
31
|
-
const unreachable = (url) => new Error(`Cannot reach RayTrace at ${url.origin}. Check your connection; `
|
|
32
|
-
+ 'networks that inspect HTTPS (some company Wi-Fi) may block it.');
|
|
33
31
|
|
|
34
32
|
// Never packed: version control, dependencies and build output (rebuilt in the
|
|
35
33
|
// sandbox), and files that usually hold credentials.
|
|
@@ -45,34 +43,6 @@ export function packable(path) {
|
|
|
45
43
|
&& !name.startsWith('.env') && !SECRET_EXTENSIONS.test(name) && !SECRET_NAMES.has(name);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
async function api() {
|
|
49
|
-
const config = readConfig();
|
|
50
|
-
const url = process.env.RAYTRACE_API_URL || config.RAYTRACE_API_URL || API;
|
|
51
|
-
let key = process.env.RAYTRACE_API_KEY || config.RAYTRACE_API_KEY || await accessToken();
|
|
52
|
-
if (!key) {
|
|
53
|
-
if (!interactive()) throw new Error('Not signed in. Run: raytrace auth login');
|
|
54
|
-
say('You are not signed in to RayTrace yet.');
|
|
55
|
-
await login();
|
|
56
|
-
key = await accessToken();
|
|
57
|
-
if (!key) throw new Error('Not signed in. Run: raytrace auth login');
|
|
58
|
-
say();
|
|
59
|
-
}
|
|
60
|
-
return { url: new URL(url), key };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function call(method, path, { body, headers = {} } = {}) {
|
|
64
|
-
const { url, key } = await api();
|
|
65
|
-
let response;
|
|
66
|
-
try {
|
|
67
|
-
response = await fetch(new URL(path, url), { method, body, headers: { authorization: `Bearer ${key}`, ...headers } });
|
|
68
|
-
} catch {
|
|
69
|
-
throw unreachable(url);
|
|
70
|
-
}
|
|
71
|
-
const data = await response.json().catch(() => ({}));
|
|
72
|
-
if (!response.ok) throw new Error(data.error || `HTTP ${response.status}`);
|
|
73
|
-
return data;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
46
|
/** The project's files git would track, minus what must not leave this machine. */
|
|
77
47
|
function projectFiles(root) {
|
|
78
48
|
const listed = spawnSync('git', ['-C', root, 'ls-files', '-z', '--cached', '--others', '--exclude-standard'], { maxBuffer: 256 * 1024 * 1024 });
|
|
@@ -135,15 +105,52 @@ export async function create(flags) {
|
|
|
135
105
|
if (!files.length) throw new Error('Nothing to upload.');
|
|
136
106
|
// The same files, packed the same way, as a cloud sandbox gets: only the copy stays here.
|
|
137
107
|
if (flags.local) return local.create(localName, { root, files, skipped, total, archive: await pack(root, files) });
|
|
108
|
+
|
|
109
|
+
// Beta credit: consumed by the first cloud sandbox created after
|
|
110
|
+
// redemption, only before its hard 3-day deadline. A local sandbox never
|
|
111
|
+
// uses it; an older backend (or no entitlement) never blocks a plain one.
|
|
112
|
+
let useCredit = false;
|
|
113
|
+
try {
|
|
114
|
+
const beta = await betaStatus();
|
|
115
|
+
const deadlinePassed = beta?.credit_expires_at && Date.parse(beta.credit_expires_at) <= Date.now();
|
|
116
|
+
if (beta && !beta.sandbox_consumed && deadlinePassed && (beta.entitled || beta.credit_usd)) {
|
|
117
|
+
say('Your $10 beta credit has expired: the 3 days ran out, and unused credit does not carry over.');
|
|
118
|
+
if (!interactive()) throw new Error('Beta credit expired; no sandbox was created. Ask RayTrace for a new code to try again.');
|
|
119
|
+
if (!(await confirm('Create a plain sandbox without beta credit?', false))) { say('Not created.'); return; }
|
|
120
|
+
} else if (beta?.entitled && !beta.sandbox_consumed) {
|
|
121
|
+
useCredit = true;
|
|
122
|
+
say(`Using your $${beta.credit_usd ?? 10} beta credit (OpenRouter) on this sandbox`
|
|
123
|
+
+ `${beta.credit_expires_at ? ` — credit ends ${formatCreditDeadline(beta.credit_expires_at)}` : ''}.`);
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
if (/Beta credit expired/.test(error.message)) throw error;
|
|
127
|
+
// No beta answer (old backend, signed out, unreachable): proceed plain;
|
|
128
|
+
// the create call below surfaces any real auth/network failure.
|
|
129
|
+
}
|
|
138
130
|
say(`Packing ${files.length} files (${(total / 1048576).toFixed(1)} MiB) from ${root}`);
|
|
139
131
|
if (skipped.length) say(`Not uploaded (${skipped.length}): ${skipped.slice(0, 8).join(', ')}${skipped.length > 8 ? ', ...' : ''}`);
|
|
140
132
|
const archive = await pack(root, files);
|
|
141
133
|
if (archive.length > MAX_ARCHIVE) throw new Error(`The packed project is ${Math.round(archive.length / MIB)} MiB; the most is ${MAX_ARCHIVE / MIB} MiB.`);
|
|
142
134
|
say('Creating the sandbox (the first one on a host takes a little longer)...');
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
135
|
+
const headers = { 'content-type': 'application/gzip', 'x-raytrace-name': name.replace(/[^A-Za-z0-9._ -]/g, '-').slice(0, 100) };
|
|
136
|
+
let box;
|
|
137
|
+
try {
|
|
138
|
+
box = await call('POST', '/v1/sandboxes', {
|
|
139
|
+
body: archive, headers: useCredit ? { ...headers, 'x-raytrace-beta-credit': '1' } : headers,
|
|
140
|
+
});
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (!useCredit || !(error instanceof ApiError) || ![409, 410].includes(error.status)) throw error;
|
|
143
|
+
say(error.status === 410 ? 'Your beta credit expired before the sandbox was created.'
|
|
144
|
+
: 'Your beta credit was already used on another sandbox.');
|
|
145
|
+
if (!interactive() || !(await confirm('Create a plain sandbox without beta credit?', false))) {
|
|
146
|
+
throw new Error('Beta credit not applied; no sandbox was created.');
|
|
147
|
+
}
|
|
148
|
+
box = await call('POST', '/v1/sandboxes', { body: archive, headers });
|
|
149
|
+
}
|
|
146
150
|
say(`\nSandbox ${box.id} is running.`);
|
|
151
|
+
if (box.credit_applied) {
|
|
152
|
+
say(`Beta credit applied: $${box.credit_usd ?? 10} (OpenRouter)${box.credit_expires_at ? `, ends ${formatCreditDeadline(box.credit_expires_at)}` : ''}. This sandbox shows as Beta in the dashboard.`);
|
|
153
|
+
}
|
|
147
154
|
say(box.transcripts ? 'Claude Code sessions in it are recorded.'
|
|
148
155
|
: `Claude Code transcripts are off: ${box.transcripts_off}. Commands are still recorded.`);
|
|
149
156
|
say(`Open it: raytrace connect ${box.id}`);
|
|
@@ -157,7 +164,8 @@ export async function list(flags = {}) {
|
|
|
157
164
|
// The sandbox's creation time (seconds), or its container's once that is known.
|
|
158
165
|
const created = typeof box.created === 'number' ? box.created * 1000 : Date.parse(box.created);
|
|
159
166
|
const age = Math.round((Date.now() - created) / 60000);
|
|
160
|
-
|
|
167
|
+
const beta = box.beta ? ` Beta${typeof box.credit_usd === 'number' ? ` ($${Math.max(0, box.credit_usd - (box.credit_spent_usd ?? 0)).toFixed(2)} of $${box.credit_usd} left${box.credit_expires_at ? `, ends ${formatCreditDeadline(box.credit_expires_at)}` : ''})` : ''}` : '';
|
|
168
|
+
say(`${box.id} ${String(box.status).padEnd(8)} ${box.name}${beta} (${age < 120 ? `${age} min` : `${Math.round(age / 60)} h`} old)`);
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
|
|
@@ -192,6 +200,17 @@ export async function destroy(id, flags) {
|
|
|
192
200
|
else if (result.traces_deleted === false) say('Note: its traces could not be deleted; they may still show on the dashboard.');
|
|
193
201
|
}
|
|
194
202
|
|
|
203
|
+
/** Exported for tests: the warning shown when connecting to a beta sandbox
|
|
204
|
+
* whose 3 days are up, or null. Model calls inside are refused by the
|
|
205
|
+
* backend; the sandbox itself still opens. */
|
|
206
|
+
export function betaExpiryWarning(beta, id, now = Date.now()) {
|
|
207
|
+
if (!beta || beta.credited_sandbox_id !== id) return null;
|
|
208
|
+
const deadline = beta.credit_expires_at ? Date.parse(beta.credit_expires_at) : NaN;
|
|
209
|
+
if (!beta.expired && !(deadline <= now)) return null;
|
|
210
|
+
return `Warning: your beta credit for this sandbox expired${beta.credit_expires_at ? ` (${formatCreditDeadline(beta.credit_expires_at, now)})` : ''}; `
|
|
211
|
+
+ 'model calls in this sandbox will be refused. The sandbox itself still opens.';
|
|
212
|
+
}
|
|
213
|
+
|
|
195
214
|
/** An interactive terminal in the sandbox, carried over one upgraded HTTP request.
|
|
196
215
|
* `raytrace connect <id>` and `raytrace sandbox shell [id]` are the same thing. */
|
|
197
216
|
export async function shell(id, flags = {}) {
|
|
@@ -199,6 +218,10 @@ export async function shell(id, flags = {}) {
|
|
|
199
218
|
// With no id and no cloud sign-in, the one local sandbox is the likely one.
|
|
200
219
|
if (flags.local || local.isLocal(id) || (!id && Object.keys(local.registry()).length && !account())) return local.shell(id);
|
|
201
220
|
id = await pickId(id);
|
|
221
|
+
try {
|
|
222
|
+
const warning = betaExpiryWarning(await betaStatus(), id);
|
|
223
|
+
if (warning) say(warning);
|
|
224
|
+
} catch { /* no beta answer: connecting must not depend on it */ }
|
|
202
225
|
const { url, key } = await api();
|
|
203
226
|
const { stdin, stdout } = process;
|
|
204
227
|
const path = `/v1/sandboxes/${id}/shell?rows=${stdout.rows || 24}&cols=${stdout.columns || 80}`;
|