trajectories-sh 1.0.0 → 1.0.2

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/cli.js CHANGED
@@ -81,7 +81,7 @@ program.command("upload <directory>").description("Upload a trajectory job direc
81
81
  Pushing ${directory} \u2192 ${chalk.cyan(slug)}
82
82
  `));
83
83
  try {
84
- const { uploadJob } = await import("./upload-DOEOEXFE.js");
84
+ const { uploadJob } = await import("./upload-CANGE4U5.js");
85
85
  const result = await uploadJob(directory, {
86
86
  slug,
87
87
  name: opts.name,
@@ -104,9 +104,48 @@ async function uploadArchive(jobId, dir, files, totalSize) {
104
104
  const archiveSize = statSync(archivePath).size;
105
105
  const ratio = ((1 - archiveSize / totalSize) * 100).toFixed(0);
106
106
  console.log(` Archive: ${(archiveSize / 1024 / 1024).toFixed(1)} MB (${ratio}% compressed)`);
107
- await doSignedUploadAndExtract(jobId, archivePath, archiveSize);
107
+ if (archiveSize <= CHUNK_MAX_BYTES) {
108
+ await doSignedUploadAndExtract(jobId, archivePath, archiveSize);
109
+ } else {
110
+ await uploadChunked(jobId, dir, files, totalSize);
111
+ }
112
+ try {
113
+ (await import("fs")).unlinkSync(archivePath);
114
+ } catch {
115
+ }
116
+ }
117
+ async function uploadChunked(jobId, dir, files, totalSize) {
118
+ const targetRawPerChunk = CHUNK_MAX_BYTES * 4;
119
+ const chunks = [[]];
120
+ let currentSize = 0;
121
+ for (const file of files) {
122
+ if (currentSize + file.size > targetRawPerChunk && chunks[chunks.length - 1].length > 0) {
123
+ chunks.push([]);
124
+ currentSize = 0;
125
+ }
126
+ chunks[chunks.length - 1].push(file);
127
+ currentSize += file.size;
128
+ }
129
+ console.log(` Splitting into ${chunks.length} chunks (max ${CHUNK_MAX_BYTES / 1024 / 1024}MB each)`);
130
+ for (let i = 0; i < chunks.length; i++) {
131
+ const chunk = chunks[i];
132
+ const label = ` chunk ${i + 1}/${chunks.length}`;
133
+ const chunkPath = join(tmpdir(), `trajectories-chunk-${i}-${randomBytes(4).toString("hex")}.tar.gz`);
134
+ console.log(` Compressing${label} (${chunk.length} files)...`);
135
+ await tar.create(
136
+ { gzip: true, file: chunkPath, cwd: dir },
137
+ chunk.map((f) => f.relPath)
138
+ );
139
+ const chunkSize = statSync(chunkPath).size;
140
+ console.log(` ${label}: ${(chunkSize / 1024 / 1024).toFixed(1)} MB`);
141
+ await doSignedUploadAndExtract(jobId, chunkPath, chunkSize, label);
142
+ try {
143
+ (await import("fs")).unlinkSync(chunkPath);
144
+ } catch {
145
+ }
146
+ }
108
147
  }
109
- async function doSignedUploadAndExtract(jobId, archivePath, archiveSize) {
148
+ async function doSignedUploadAndExtract(jobId, archivePath, archiveSize, label = "") {
110
149
  const urlResp = await apiPost(`/api/cli/push/${jobId}/upload-url`, {});
111
150
  if (!urlResp.ok) throw new Error(`Failed to get upload URL: ${await urlResp.text()}`);
112
151
  const { signed_url: signedUrl } = await urlResp.json();
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "trajectories-sh",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "CLI for uploading trajectory jobs to trajectories.sh",
5
5
  "type": "module",
6
6
  "bin": {
7
- "trajectories": "./dist/cli.js"
7
+ "trajectories": "./dist/cli.js",
8
+ "trajectories-sh": "./dist/cli.js"
8
9
  },
9
10
  "scripts": {
10
11
  "build": "tsup src/cli.ts --format esm --target node18 --clean",
@@ -14,7 +15,12 @@
14
15
  "files": [
15
16
  "dist"
16
17
  ],
17
- "keywords": ["trajectories", "harbor", "terminal-bench", "cli"],
18
+ "keywords": [
19
+ "trajectories",
20
+ "harbor",
21
+ "terminal-bench",
22
+ "cli"
23
+ ],
18
24
  "license": "MIT",
19
25
  "engines": {
20
26
  "node": ">=18"