cassian-cli 0.2.0 → 0.3.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/commands/init.js +30 -14
- package/dist/commands/sync.js +37 -47
- package/dist/commands/up.js +5 -0
- package/dist/lib/errors.js +3 -2
- package/dist/lib/push.js +26 -3
- package/dist/lib/watcher.js +36 -8
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -32,8 +32,13 @@ function promptChoice(rl, question, choices, fallback) {
|
|
|
32
32
|
}
|
|
33
33
|
function buildYaml(opts) {
|
|
34
34
|
const volName = opts.name.replace(/[^a-z0-9-]/g, "-") + "-data";
|
|
35
|
-
const syncignoreLines = opts.syncignore.map(p => ` - "${p}"`).join("\n");
|
|
36
35
|
const setupLine = opts.setup ? ` setup: ${opts.setup}\n` : "";
|
|
36
|
+
const noSyncLines = opts.noSync.length
|
|
37
|
+
? ` no_sync:\n${opts.noSync.map(p => ` - "${p}"`).join("\n")}\n` : "";
|
|
38
|
+
const storageLines = opts.storage.length
|
|
39
|
+
? ` storage:\n${opts.storage.map(p => ` - "${p}"`).join("\n")}\n` : "";
|
|
40
|
+
const excludeLines = opts.exclude.length
|
|
41
|
+
? ` exclude:\n${opts.exclude.map(p => ` - "${p}"`).join("\n")}\n` : "";
|
|
37
42
|
return `name: ${opts.name}
|
|
38
43
|
|
|
39
44
|
gpu:
|
|
@@ -52,9 +57,7 @@ resources:
|
|
|
52
57
|
shm_size: ${opts.shmSize}
|
|
53
58
|
|
|
54
59
|
workspace:
|
|
55
|
-
${setupLine}
|
|
56
|
-
${syncignoreLines}
|
|
57
|
-
`;
|
|
60
|
+
${setupLine}${noSyncLines}${storageLines}${excludeLines}`;
|
|
58
61
|
}
|
|
59
62
|
export async function init(options = {}) {
|
|
60
63
|
if (existsSync("cassian.yaml")) {
|
|
@@ -65,9 +68,6 @@ export async function init(options = {}) {
|
|
|
65
68
|
// If all required flags are provided, skip the wizard entirely
|
|
66
69
|
const allFlagsProvided = !!(options.name && options.gpu && options.gpuCount && options.memory && options.disk);
|
|
67
70
|
if (allFlagsProvided || skipPrompts) {
|
|
68
|
-
const syncignore = options.syncignore
|
|
69
|
-
? options.syncignore.split(",").map(s => s.trim()).filter(Boolean)
|
|
70
|
-
: ["outputs/**", "*.ckpt", "*.safetensors", "**/.cache/**"];
|
|
71
71
|
const yaml = buildYaml({
|
|
72
72
|
name: options.name || dirName,
|
|
73
73
|
gpuType: options.gpu || "rtx3090",
|
|
@@ -76,7 +76,9 @@ export async function init(options = {}) {
|
|
|
76
76
|
shmSize: options.shm || "16G",
|
|
77
77
|
diskSize: options.disk || "50G",
|
|
78
78
|
setup: options.setup || (existsSync("requirements.txt") ? "pip install -r /workspace/requirements.txt" : ""),
|
|
79
|
-
|
|
79
|
+
noSync: ["checkpoints/", "outputs/"],
|
|
80
|
+
storage: [],
|
|
81
|
+
exclude: ["node_modules/", ".venv/", "__pycache__/", "*.pyc", "wandb/"],
|
|
80
82
|
});
|
|
81
83
|
writeFileSync("cassian.yaml", yaml);
|
|
82
84
|
console.log();
|
|
@@ -122,13 +124,27 @@ export async function init(options = {}) {
|
|
|
122
124
|
const setupRaw = options.setup ?? await prompt(rl, ` Setup command ${dim(`[${defaultSetup || "skip"}]`)}: `, defaultSetup);
|
|
123
125
|
const setup = setupRaw === "skip" ? "" : setupRaw;
|
|
124
126
|
console.log();
|
|
125
|
-
console.log(dim("
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
console.log(dim(" Folders that stay on the GPU instance but don't sync to your machine"));
|
|
128
|
+
console.log(dim(" (large files like checkpoints, training outputs — still persists across sessions)"));
|
|
129
|
+
const noSyncRaw = options.syncignore ?? await prompt(rl, ` No-sync folders ${dim("[checkpoints/, outputs/]")}: `, "");
|
|
130
|
+
const noSync = noSyncRaw
|
|
131
|
+
? noSyncRaw.split(",").map(s => s.trim()).filter(Boolean)
|
|
132
|
+
: ["checkpoints/", "outputs/"];
|
|
133
|
+
console.log();
|
|
134
|
+
console.log(dim(" Folders streamed from cloud storage (huge datasets, pretrained models)"));
|
|
135
|
+
console.log(dim(" (doesn't use instance disk — reads directly from cloud)"));
|
|
136
|
+
const storageRaw = await prompt(rl, ` Cloud storage folders ${dim("[none]")}: `, "");
|
|
137
|
+
const storage = storageRaw
|
|
138
|
+
? storageRaw.split(",").map(s => s.trim()).filter(Boolean)
|
|
139
|
+
: [];
|
|
140
|
+
console.log();
|
|
141
|
+
console.log(dim(" Folders to exclude entirely (build artifacts, can be recreated)"));
|
|
142
|
+
const excludeRaw = await prompt(rl, ` Exclude ${dim("[node_modules/, .venv/, __pycache__/, *.pyc, wandb/]")}: `, "");
|
|
143
|
+
const exclude = excludeRaw
|
|
144
|
+
? excludeRaw.split(",").map(s => s.trim()).filter(Boolean)
|
|
145
|
+
: ["node_modules/", ".venv/", "__pycache__/", "*.pyc", "wandb/"];
|
|
130
146
|
rl.close();
|
|
131
|
-
const yaml = buildYaml({ name, gpuType, gpuCount, memory, shmSize, diskSize, setup,
|
|
147
|
+
const yaml = buildYaml({ name, gpuType, gpuCount, memory, shmSize, diskSize, setup, noSync, storage, exclude });
|
|
132
148
|
writeFileSync("cassian.yaml", yaml);
|
|
133
149
|
console.log();
|
|
134
150
|
console.log(` ${green("✓")} Created cassian.yaml`);
|
package/dist/commands/sync.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as tar from "tar";
|
|
2
|
-
import { mkdirSync
|
|
3
|
-
import { join, normalize } from "path";
|
|
2
|
+
import { mkdirSync } from "fs";
|
|
4
3
|
import { Readable } from "stream";
|
|
5
4
|
import ora from "ora";
|
|
6
5
|
import { ApiClient } from "../lib/api.js";
|
|
@@ -26,55 +25,46 @@ export async function sync() {
|
|
|
26
25
|
const tarBuf = await client.pull(instance.id, mountPath);
|
|
27
26
|
const cwd = process.cwd();
|
|
28
27
|
mkdirSync(cwd, { recursive: true });
|
|
29
|
-
// Build
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
// Build skip patterns from all workspace config fields
|
|
29
|
+
const patterns = ["**/.git/**", "**/.DS_Store"];
|
|
30
|
+
if (config.workspace?.syncignore)
|
|
31
|
+
patterns.push(...config.workspace.syncignore);
|
|
32
|
+
if (config.workspace?.no_sync) {
|
|
33
|
+
for (const p of config.workspace.no_sync) {
|
|
34
|
+
patterns.push(p.endsWith("/") ? `${p}**` : `**/${p}/**`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (config.workspace?.storage) {
|
|
38
|
+
for (const p of config.workspace.storage) {
|
|
39
|
+
patterns.push(p.endsWith("/") ? `${p}**` : `**/${p}/**`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (config.workspace?.exclude) {
|
|
43
|
+
for (const p of config.workspace.exclude) {
|
|
44
|
+
if (p.endsWith("/"))
|
|
45
|
+
patterns.push(`${p}**`);
|
|
46
|
+
else if (p.includes("*"))
|
|
47
|
+
patterns.push(`**/${p}`);
|
|
48
|
+
else
|
|
49
|
+
patterns.push(`**/${p}/**`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const ignoreRegexes = patterns.map((p) => {
|
|
33
53
|
const esc = p.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\x00").replace(/\*/g, "[^/]*").replace(/\x00/g, ".*");
|
|
34
54
|
return new RegExp(`(^|/)${esc}($|/)`);
|
|
35
55
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
await new Promise((res) => {
|
|
39
|
-
const parser = new tar.Parser({
|
|
40
|
-
onentry: (entry) => {
|
|
41
|
-
const stripped = entry.path.replace(/^[^/]+\//, "");
|
|
42
|
-
const norm = normalize(stripped);
|
|
43
|
-
if (stripped && !norm.startsWith("..") && !norm.startsWith("/"))
|
|
44
|
-
remoteFiles.add(norm);
|
|
45
|
-
entry.resume();
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
Readable.from(tarBuf).pipe(parser)
|
|
49
|
-
.on("finish", res).on("error", res);
|
|
50
|
-
});
|
|
51
|
-
// Delete local synced files not in remote
|
|
52
|
-
function walk(dir) {
|
|
53
|
-
if (!existsSync(dir))
|
|
54
|
-
return [];
|
|
55
|
-
return readdirSync(dir).flatMap((e) => {
|
|
56
|
-
const full = join(dir, e);
|
|
57
|
-
const rel = full.slice(cwd.length + 1);
|
|
58
|
-
if (ignoreRegexes.some((re) => re.test(rel)))
|
|
59
|
-
return [];
|
|
60
|
-
try {
|
|
61
|
-
return statSync(full).isDirectory() ? walk(full) : [rel];
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
for (const f of walk(cwd)) {
|
|
69
|
-
if (!remoteFiles.has(normalize(f))) {
|
|
70
|
-
try {
|
|
71
|
-
unlinkSync(join(cwd, f));
|
|
72
|
-
}
|
|
73
|
-
catch { /* skip */ }
|
|
74
|
-
}
|
|
56
|
+
function shouldSkip(rel) {
|
|
57
|
+
return ignoreRegexes.some((re) => re.test(rel));
|
|
75
58
|
}
|
|
76
|
-
// Extract
|
|
77
|
-
await new Promise((res, rej) => Readable.from(tarBuf).pipe(tar.extract({
|
|
59
|
+
// Extract with filtering
|
|
60
|
+
await new Promise((res, rej) => Readable.from(tarBuf).pipe(tar.extract({
|
|
61
|
+
cwd,
|
|
62
|
+
strip: 1,
|
|
63
|
+
filter: (path) => {
|
|
64
|
+
const stripped = path.replace(/^\.\//, "");
|
|
65
|
+
return !shouldSkip(stripped);
|
|
66
|
+
},
|
|
67
|
+
})).on("finish", res).on("error", rej));
|
|
78
68
|
spinner.succeed("Files synced");
|
|
79
69
|
}
|
|
80
70
|
catch (err) {
|
package/dist/commands/up.js
CHANGED
|
@@ -128,6 +128,11 @@ export async function up() {
|
|
|
128
128
|
shm_size: config.resources?.shm_size || null,
|
|
129
129
|
cpus: config.resources?.cpus || null,
|
|
130
130
|
},
|
|
131
|
+
workspace: {
|
|
132
|
+
no_sync: config.workspace?.no_sync || [],
|
|
133
|
+
storage: config.workspace?.storage || [],
|
|
134
|
+
exclude: config.workspace?.exclude || config.workspace?.syncignore || [],
|
|
135
|
+
},
|
|
131
136
|
});
|
|
132
137
|
spinner.succeed("Instance ready");
|
|
133
138
|
// Sync happens during ssh/exec, not during up
|
package/dist/lib/errors.js
CHANGED
|
@@ -42,14 +42,15 @@ function translateApiError(err) {
|
|
|
42
42
|
case 404:
|
|
43
43
|
fatal("Instance not found.", "Run: cassian up");
|
|
44
44
|
case 409:
|
|
45
|
-
fatal("An instance with this name already exists.", "Run: cassian down, then try again.");
|
|
45
|
+
fatal(err.detail || "An instance with this name already exists.", "Run: cassian down, then try again.");
|
|
46
46
|
case 422:
|
|
47
47
|
fatal(`Invalid configuration: ${err.detail}`);
|
|
48
48
|
case 429:
|
|
49
49
|
fatal("Too many requests.", "Wait a moment and try again.");
|
|
50
|
+
case 503:
|
|
51
|
+
fatal(err.detail || "No GPUs available right now.", "Try again in a moment or reduce gpu.count in cassian.yaml.");
|
|
50
52
|
case 500:
|
|
51
53
|
case 502:
|
|
52
|
-
case 503:
|
|
53
54
|
case 504:
|
|
54
55
|
fatal("Something went wrong on our end.", "Try again in a moment. Still broken? Reach out at trycassian.com.");
|
|
55
56
|
default:
|
package/dist/lib/push.js
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
export async function pushWorkspace(client, instanceId, config) {
|
|
2
2
|
const tar = await import("tar");
|
|
3
3
|
const mountPath = config.volumes?.[0]?.mount || "/workspace";
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
4
|
+
// Build ignore list from all workspace fields
|
|
5
|
+
const patterns = ["**/.git/**", "**/.DS_Store"];
|
|
6
|
+
if (config.workspace?.syncignore)
|
|
7
|
+
patterns.push(...config.workspace.syncignore);
|
|
8
|
+
if (config.workspace?.no_sync) {
|
|
9
|
+
for (const p of config.workspace.no_sync) {
|
|
10
|
+
patterns.push(p.endsWith("/") ? `${p}**` : `**/${p}/**`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (config.workspace?.storage) {
|
|
14
|
+
for (const p of config.workspace.storage) {
|
|
15
|
+
const name = p.replace(/\/$/, "");
|
|
16
|
+
patterns.push(`${name}`, `${name}/**`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (config.workspace?.exclude) {
|
|
20
|
+
for (const p of config.workspace.exclude) {
|
|
21
|
+
if (p.endsWith("/"))
|
|
22
|
+
patterns.push(`${p}**`);
|
|
23
|
+
else if (p.includes("*"))
|
|
24
|
+
patterns.push(`**/${p}`);
|
|
25
|
+
else
|
|
26
|
+
patterns.push(`**/${p}/**`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const ignoreRegexes = patterns.map((p) => {
|
|
7
30
|
const esc = p.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "\x00").replace(/\*/g, "[^/]*").replace(/\x00/g, ".*");
|
|
8
31
|
return new RegExp(`(^|/)${esc}($|/)`);
|
|
9
32
|
});
|
package/dist/lib/watcher.js
CHANGED
|
@@ -15,13 +15,42 @@ import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync, statSyn
|
|
|
15
15
|
import { resolve, dirname, normalize } from "path";
|
|
16
16
|
import { getCredentials, isTokenExpired, refreshToken } from "./auth.js";
|
|
17
17
|
const POLL_INTERVAL_MS = 2000;
|
|
18
|
-
const MAX_FILE_SIZE =
|
|
19
|
-
function buildIgnorePatterns(
|
|
20
|
-
|
|
21
|
-
"**/.git/**", "
|
|
22
|
-
"**/*.pyc", "**/.DS_Store",
|
|
23
|
-
...syncignore,
|
|
18
|
+
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
|
|
19
|
+
function buildIgnorePatterns(config) {
|
|
20
|
+
const patterns = [
|
|
21
|
+
"**/.git/**", "**/.DS_Store",
|
|
24
22
|
];
|
|
23
|
+
// Legacy syncignore
|
|
24
|
+
if (config.workspace?.syncignore)
|
|
25
|
+
patterns.push(...config.workspace.syncignore);
|
|
26
|
+
// no_sync: persists to cloud but doesn't sync to laptop
|
|
27
|
+
if (config.workspace?.no_sync) {
|
|
28
|
+
for (const p of config.workspace.no_sync) {
|
|
29
|
+
patterns.push(p.endsWith("/") ? `${p}**` : `**/${p}/**`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// storage: cold paths, don't sync to laptop (exclude the name itself + contents)
|
|
33
|
+
if (config.workspace?.storage) {
|
|
34
|
+
for (const p of config.workspace.storage) {
|
|
35
|
+
const name = p.replace(/\/$/, "");
|
|
36
|
+
patterns.push(name, `${name}/**`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// exclude: throwaway, don't sync to laptop
|
|
40
|
+
if (config.workspace?.exclude) {
|
|
41
|
+
for (const p of config.workspace.exclude) {
|
|
42
|
+
if (p.endsWith("/")) {
|
|
43
|
+
patterns.push(`${p}**`);
|
|
44
|
+
}
|
|
45
|
+
else if (p.includes("*")) {
|
|
46
|
+
patterns.push(`**/${p}`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
patterns.push(`**/${p}/**`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return patterns;
|
|
25
54
|
}
|
|
26
55
|
function globToRegex(pattern) {
|
|
27
56
|
const esc = pattern
|
|
@@ -41,8 +70,7 @@ async function getToken() {
|
|
|
41
70
|
}
|
|
42
71
|
export function startBidirectionalSync(instanceId, config, agentUrl) {
|
|
43
72
|
const mountPath = config.volumes?.[0]?.mount ?? "/workspace";
|
|
44
|
-
const
|
|
45
|
-
const ignoreRegexes = buildIgnorePatterns(syncignore).map(globToRegex);
|
|
73
|
+
const ignoreRegexes = buildIgnorePatterns(config).map(globToRegex);
|
|
46
74
|
const cwd = process.cwd();
|
|
47
75
|
let stopped = false;
|
|
48
76
|
// Track files recently pushed by us so we don't pull-echo them back
|
package/dist/types.d.ts
CHANGED