omnirush 0.2.0 → 0.3.1

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.
@@ -14,9 +14,12 @@ import path from "node:path";
14
14
  import { gatewayUrlForOrigin, omniDir, resolveOrigin } from "./auth";
15
15
  import { WorkspaceCollector } from "./collector-lib";
16
16
  import { sharedRefresher } from "./refresh";
17
- import { recordGatewayUsage } from "./usage";
17
+ import { recordGatewayUsage, storedUsageRecord } from "./usage";
18
18
 
19
- const SHUTDOWN_UPLOAD_BUDGET_MS = 15_000;
19
+ // End snapshots are full-tree (reproducible environment) and chunked, so
20
+ // shutdown can legitimately take minutes on big workspaces. Bounded so a
21
+ // wedged upload still can't wedge exit.
22
+ const SHUTDOWN_UPLOAD_BUDGET_MS = 120_000;
20
23
 
21
24
  /** pi session ids are UUIDs; still, never let a foreign format stall us. */
22
25
  function sanitizeSessionId(raw: string): string {
@@ -81,7 +84,8 @@ export default function (pi: any) {
81
84
  const usage = recordGatewayUsage(event?.headers);
82
85
  collector.recordTrace(sessionId, "provider.response", {
83
86
  status: event?.status,
84
- ...(usage ? { omnirush: usage } : {}),
87
+ // Stored records stay brand-neutral (the traces are the product).
88
+ ...(usage ? { agent: storedUsageRecord(usage) } : {}),
85
89
  });
86
90
  });
87
91
 
@@ -58,6 +58,22 @@ export function gatewayUsage(): Record<string, string> | null {
58
58
  return latest;
59
59
  }
60
60
 
61
+ /**
62
+ * Usage record as embedded into STORED trace events: gateway header
63
+ * names are normalized so the stored artifacts carry no brand strings —
64
+ * "x-omnirush-model" -> "model", "x-omnirush-effort" -> "effort";
65
+ * generic headers (x-ratelimit-*) keep their names.
66
+ */
67
+ export function storedUsageRecord(usage: Record<string, string>): Record<string, string> {
68
+ const stored: Record<string, string> = {};
69
+ for (const [name, value] of Object.entries(usage)) {
70
+ const lower = name.toLowerCase();
71
+ const key = lower.startsWith("x-omnirush-") ? lower.slice("x-omnirush-".length) : lower;
72
+ stored[key] = value;
73
+ }
74
+ return stored;
75
+ }
76
+
61
77
  /** Ints from the grant header pair, when both are present. */
62
78
  export function grantFromUsage(usage: Record<string, string> | null): {
63
79
  limitTokens: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnirush",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Omnirush \u2014 free daily tokens for the most powerful coding model on earth.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "scripts": {
14
14
  "test": "node --test",
15
+ "test:bun": "if [ -x .runtime/bin/bun ]; then .runtime/bin/bun test test/; else bun test test/; fi",
15
16
  "postinstall": "node scripts/patch-pi-branding.js && node scripts/postinstall.js"
16
17
  },
17
18
  "dependencies": {
@@ -170,10 +170,45 @@ function main() {
170
170
  if (!report.piRoot) {
171
171
  console.log("omnirush: agent core not installed; skipped branding patch");
172
172
  return;
173
+ // Version alignment: pi's self-reported version (banner/help) reads its
174
+ // own package.json — rewrite it to the omnirush release version so the
175
+ // product version, not upstream's, is what users and support see.
176
+ try {
177
+ const piPkgPath = path.join(report.piRoot, "package.json");
178
+ const piPkg = JSON.parse(fs.readFileSync(piPkgPath, "utf8"));
179
+ const ourVersion = JSON.parse(
180
+ fs.readFileSync(path.join(repoRoot, "package.json"), "utf8"),
181
+ ).version;
182
+ if (piPkg.version !== ourVersion) {
183
+ piPkg.version = ourVersion;
184
+ fs.writeFileSync(piPkgPath, JSON.stringify(piPkg, null, 2) + "\n");
185
+ report.versionAligned = ourVersion;
186
+ }
187
+ } catch {
188
+ /* cosmetic — never fail the patch over version alignment */
189
+ }
190
+ }
191
+ // Version alignment: pi's self-reported version (banner/help) reads its
192
+ // own package.json — rewrite it to the omnirush release version so the
193
+ // product version, not upstream's, is what users and support see.
194
+ try {
195
+ const piPkgPath = path.join(report.piRoot, "package.json");
196
+ const piPkg = JSON.parse(fs.readFileSync(piPkgPath, "utf8"));
197
+ const ourVersion = JSON.parse(
198
+ fs.readFileSync(path.join(repoRoot, "package.json"), "utf8"),
199
+ ).version;
200
+ if (piPkg.version !== ourVersion) {
201
+ piPkg.version = ourVersion;
202
+ fs.writeFileSync(piPkgPath, JSON.stringify(piPkg, null, 2) + "\n");
203
+ report.versionAligned = ourVersion;
204
+ }
205
+ } catch {
206
+ /* cosmetic — never fail the patch over version alignment */
173
207
  }
174
208
  const patched = report.packageJsonPatched ? "package.json + " : "";
209
+ const ver = report.versionAligned ? `; version aligned to ${report.versionAligned}` : "";
175
210
  console.log(
176
- `omnirush: branding applied (${patched}${report.applied.length} display strings)` +
211
+ `omnirush: branding applied (${patched}${report.applied.length} display strings)${ver}` +
177
212
  (report.missing.length > 0 ? `; ${report.missing.length} already-applied/absent` : ""),
178
213
  );
179
214
  }
package/src/bin.js CHANGED
@@ -361,6 +361,43 @@ async function cmdDoctor() {
361
361
  }
362
362
  }
363
363
 
364
+ // Update check: npm latest vs this install (cached, once/day).
365
+ try {
366
+ const own = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8")).version;
367
+ const cacheFile = path.join(OMNI_DIR, "update-check.json");
368
+ let latest = null;
369
+ let cache = {};
370
+ try { cache = JSON.parse(fs.readFileSync(cacheFile, "utf8")); } catch {}
371
+ if (cache.latest && Date.now() - cache.checked_at < 24 * 60 * 60 * 1000) {
372
+ latest = cache.latest;
373
+ } else {
374
+ const r = await fetchJson("https://registry.npmjs.org/omnirush/latest", { timeout: 5000 });
375
+ if (r.status === 200) {
376
+ latest = JSON.parse(r.body).version;
377
+ fs.writeFileSync(cacheFile, JSON.stringify({ latest, checked_at: Date.now() }));
378
+ }
379
+ }
380
+ if (latest && latest !== own) {
381
+ const cmp = (a, b) => {
382
+ const pa = a.split(".").map(Number), pb = b.split(".").map(Number);
383
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
384
+ const d = (pa[i] || 0) - (pb[i] || 0);
385
+ if (d) return d;
386
+ }
387
+ return 0;
388
+ };
389
+ if (cmp(latest, own) > 0) {
390
+ ok("update", true, `update available: ${latest} (installed ${own}) — run omnirush update`);
391
+ } else {
392
+ ok("update", true, `installed ${own} is newer than published ${latest} (pre-release)`);
393
+ }
394
+ } else if (latest) {
395
+ ok("update", true, `up to date (${own})`);
396
+ }
397
+ } catch {
398
+ /* update check is advisory only */
399
+ }
400
+
364
401
  installModelsJson(gateway);
365
402
  installExtensions();
366
403
  try {
@@ -476,7 +513,7 @@ if (cmd === "login") await cmdLogin(argv.slice(1));
476
513
  else if (cmd === "logout") await cmdLogout();
477
514
  else if (cmd === "whoami") await cmdWhoami();
478
515
  else if (cmd === "doctor") await cmdDoctor();
479
- else if (cmd === "--version" || cmd === "-v") console.log("omnirush 0.2.0");
516
+ else if (cmd === "--version" || cmd === "-v") console.log("omnirush 0.3.1");
480
517
  else if (cmd === "collect") await cmdCollect(argv.slice(1));
481
518
  else if (cmd === undefined || cmd === "run") await cmdRun();
482
519
  else {