Skip to content

Commit a3e3c39

Browse files
committed
fix(cli): use auto-generated version.ts for --version flag in compiled binaries
1 parent 2c10be2 commit a3e3c39

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ package-lock.json
2121
.codemachine/prompts
2222
.codemachine/agents
2323
.codemachine/template.json
24-
bun-migration/
24+
bun-migration//src/runtime/version.ts

scripts/build-binaries.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ const linkGlobal = args.has('--link-global');
2020
console.log('[build] Starting binary build...');
2121
console.log(`[build] Main package version: ${mainVersion}`);
2222

23+
// Generate version.ts file for compiled binaries
24+
const versionFilePath = join(repoRoot, 'src/runtime/version.ts');
25+
const versionFileContent = `// This file is auto-generated during the build process
26+
export const VERSION = '${mainVersion}';
27+
`;
28+
writeFileSync(versionFilePath, versionFileContent);
29+
console.log(`[build] Generated version.ts with version ${mainVersion}`);
30+
2331
// Auto-sync platform package versions before building
2432
if (mainPackage.optionalDependencies) {
2533
let needsSync = false;

src/runtime/cli-setup.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,12 @@ async function initializeInBackground(cwd: string): Promise<void> {
118118
}
119119

120120
export async function runCodemachineCli(argv: string[] = process.argv): Promise<void> {
121-
// Get version from package.json
122-
const { resolvePackageJson } = await import('../shared/utils/package-json.js');
123-
const packageJsonPath = resolvePackageJson(import.meta.url, 'cli setup');
124-
const { version } = JSON.parse((await import('node:fs')).readFileSync(packageJsonPath, 'utf8'));
121+
// Import version from auto-generated version file (works in compiled binaries)
122+
const { VERSION } = await import('./version.js');
125123

126124
const program = new Command()
127125
.name('codemachine')
128-
.version(version)
126+
.version(VERSION)
129127
.description('Codemachine multi-agent CLI orchestrator')
130128
.option('-d, --dir <path>', 'Target workspace directory', process.cwd())
131129
.option('--spec <path>', 'Path to the planning specification file', DEFAULT_SPEC_PATH)

0 commit comments

Comments
 (0)