omnirush 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.
@@ -15,11 +15,11 @@ import readline from "node:readline";
15
15
 
16
16
  import { omniDir, resolveOrigin, gatewayUrlForOrigin } from "./extensions/omnirush/auth";
17
17
  import {
18
- buildEnvelopePayload,
18
+ buildEnvelopeParts,
19
19
  collectFiles,
20
- compressZstd,
21
- MAX_COMPRESSED_BYTES,
22
- MAX_COLLECTOR_SESSION_BYTES,
20
+ MAX_PART_COMPRESSED_BYTES,
21
+ MAX_PART_COMPRESSED_HARD,
22
+ MAX_SESSION_BYTES,
23
23
  } from "./extensions/omnirush/collector-lib";
24
24
 
25
25
  function parseArgs(argv: string[]): { dir: string; yes: boolean; dryRun: boolean } {
@@ -55,7 +55,7 @@ async function main() {
55
55
  const sessionId = `manual-${randomBytes(6).toString("hex")}`;
56
56
  const workspaceId = path.basename(dir) || "workspace";
57
57
 
58
- const files = await collectFiles(dir, MAX_COLLECTOR_SESSION_BYTES, workspaceId, {
58
+ const files = await collectFiles(dir, MAX_SESSION_BYTES, workspaceId, {
59
59
  id: sessionId,
60
60
  segment: 1,
61
61
  resumed: false,
@@ -65,15 +65,23 @@ async function main() {
65
65
  console.error("omnirush collect: nothing to upload (empty or fully filtered workspace)");
66
66
  process.exit(1);
67
67
  }
68
- console.log(
69
- `collect: ${files.length - 1} files (${bytes} bytes, denylist/caps applied) as session ${sessionId}`,
70
- );
71
68
 
72
69
  const state = { id: sessionId, segment: 1, resumed: false };
73
- const payload = buildEnvelopePayload(state, "start", files);
74
- const compressed = await compressZstd(payload);
70
+ const parts = await buildEnvelopeParts(
71
+ state,
72
+ "start",
73
+ files,
74
+ MAX_PART_COMPRESSED_BYTES,
75
+ (message, attributes) => console.error(`omnirush collect: ${message} (${JSON.stringify(attributes ?? {})})`),
76
+ );
77
+ const plainBytes = parts.reduce((total, part) => total + part.payload.length, 0);
78
+ const compressedBytes = parts.reduce((total, part) => total + part.compressed.length, 0);
79
+ console.log(
80
+ `collect: ${files.length - 1} files (${bytes} bytes, denylist applied) as session ${sessionId}`,
81
+ );
75
82
  console.log(
76
- `envelope: ${payload.length} bytes plain, ${compressed.length} bytes zstd (cap ${MAX_COMPRESSED_BYTES})`,
83
+ `envelope: ${parts.length} part(s), ${plainBytes} bytes plain, ${compressedBytes} bytes zstd ` +
84
+ `(target <= ${MAX_PART_COMPRESSED_BYTES}, rail ${MAX_PART_COMPRESSED_HARD})`,
77
85
  );
78
86
 
79
87
  if (dryRun) {
@@ -96,28 +104,34 @@ async function main() {
96
104
  console.error("omnirush collect: no access token (run `omnirush login`)");
97
105
  process.exit(1);
98
106
  }
99
- const response = await fetch(collectUrl, {
100
- method: "POST",
101
- headers: {
102
- Authorization: `Bearer ${accessToken}`,
103
- "Content-Type": "application/zstd",
104
- "X-Omnirush-Session-ID": sessionId,
105
- },
106
- body: compressed.buffer.slice(
107
- compressed.byteOffset,
108
- compressed.byteOffset + compressed.byteLength,
109
- ) as ArrayBuffer,
110
- signal: AbortSignal.timeout(60_000),
111
- });
112
- if (!response.ok) {
113
- await response.body?.cancel().catch(() => undefined);
114
- console.error(`upload failed: HTTP ${response.status}`);
115
- process.exit(1);
107
+ for (const part of parts) {
108
+ const response = await fetch(collectUrl, {
109
+ method: "POST",
110
+ headers: {
111
+ Authorization: `Bearer ${accessToken}`,
112
+ "Content-Type": "application/zstd",
113
+ "X-Omnirush-Session-ID": sessionId,
114
+ },
115
+ body: part.compressed.buffer.slice(
116
+ part.compressed.byteOffset,
117
+ part.compressed.byteOffset + part.compressed.byteLength,
118
+ ) as ArrayBuffer,
119
+ signal: AbortSignal.timeout(120_000),
120
+ });
121
+ if (!response.ok) {
122
+ await response.body?.cancel().catch(() => undefined);
123
+ console.error(`upload failed: HTTP ${response.status}`);
124
+ process.exit(1);
125
+ }
126
+ const extra = [...response.headers]
127
+ .filter(([name]) => name.toLowerCase().startsWith("x-omnirush-"))
128
+ .map(([name, value]) => `${name}: ${value}`);
129
+ const sequence = JSON.parse(part.payload.toString("utf8")).sequence;
130
+ console.log(
131
+ `uploaded part sequence=${sequence} (${part.compressed.length} bytes, HTTP ${response.status})` +
132
+ `${extra.length ? "\n " + extra.join("\n ") : ""}`,
133
+ );
116
134
  }
117
- const extra = [...response.headers]
118
- .filter(([name]) => name.toLowerCase().startsWith("x-omnirush-"))
119
- .map(([name, value]) => `${name}: ${value}`);
120
- console.log(`uploaded (HTTP ${response.status})${extra.length ? "\n " + extra.join("\n ") : ""}`);
121
135
  }
122
136
 
123
137
  main().catch((error) => {