Skip to content

Commit eed9a67

Browse files
committed
fix: simplify version loading with resilient fallback
- Remove redundant pre-scripts (pretest, precli, etc.) - Keep only prebuild and prepare for the happy path - Use createRequire with try/catch for resilient fallback - Try .js first (compiled), then .ts (dev/test) for compatibility - Falls back to 'unknown' instead of crashing on missing version file
1 parent cf51f3b commit eed9a67

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
"lint": "biome check .",
2626
"lint:fix": "biome check --write .",
2727
"prebuild": "node scripts/generate-version.js",
28-
"pretest": "node scripts/generate-version.js",
29-
"prepare": "node scripts/generate-version.js",
30-
"precli": "node scripts/generate-version.js",
31-
"precli:index": "node scripts/generate-version.js",
32-
"precli:search": "node scripts/generate-version.js",
33-
"pretest:integration": "node scripts/generate-version.js"
28+
"prepare": "node scripts/generate-version.js"
3429
},
3530
"keywords": [
3631
"augment",
@@ -75,7 +70,6 @@
7570
}
7671
},
7772
"dependencies": {
78-
"@augmentcode/auggie-sdk": "^0.1.15",
7973
"cheerio": "^1.1.2",
8074
"commander": "^12.0.0",
8175
"ignore": "^5.3.0",

src/core/utils.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
/**
22
* Shared utility functions
33
*/
4+
import { createRequire } from "node:module";
5+
import { existsSync } from "node:fs";
6+
import { dirname, join } from "node:path";
7+
import { fileURLToPath } from "node:url";
48

5-
import { VERSION } from "../generated/version.js";
9+
// Load VERSION with fallback for resilience
10+
// In production/bundled environments, the generated file is always present
11+
// In development edge cases (direct tsx without prebuild), falls back to "unknown"
12+
let VERSION = "unknown";
13+
try {
14+
// Use createRequire for synchronous import that can be caught
15+
const require = createRequire(import.meta.url);
16+
const __dirname = dirname(fileURLToPath(import.meta.url));
17+
18+
// Try .js first (compiled), then .ts (source/dev)
19+
const jsPath = join(__dirname, "../generated/version.js");
20+
const tsPath = join(__dirname, "../generated/version.ts");
21+
22+
if (existsSync(jsPath)) {
23+
const versionModule = require("../generated/version.js");
24+
VERSION = versionModule.VERSION ?? "unknown";
25+
} else if (existsSync(tsPath)) {
26+
// In development/test with tsx, load the .ts file
27+
const versionModule = require("../generated/version.ts");
28+
VERSION = versionModule.VERSION ?? "unknown";
29+
}
30+
} catch {
31+
// Generated file doesn't exist or failed to load - use fallback
32+
// User-Agent will still identify the product: augment.ctxc.cli/unknown
33+
}
634

735
/**
836
* Sanitize a key for use in filenames/paths.
@@ -73,10 +101,10 @@ export interface MCPClientInfo {
73101

74102
/**
75103
* Sanitize a string for use in User-Agent per RFC 9110.
76-
* Only allows: a-z A-Z 0-9 \! # $ % & ' * + . ^ _ ` | ~ -
104+
* Only allows: a-z A-Z 0-9 \! # $ % & ' * + . ^ _ \` | ~ -
77105
*/
78106
function sanitizeUserAgentToken(s: string, maxLen: number): string {
79-
return s.replace(/[^a-zA-Z0-9\!#$%&'*+.^_`|~-]/g, "-").slice(0, maxLen);
107+
return s.replace(/[^a-zA-Z0-9\!#$%&'*+.^_\`|~-]/g, "-").slice(0, maxLen);
80108
}
81109

82110
/**

0 commit comments

Comments
 (0)