Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

import { program } from "commander";
import { registerCommands } from "./commands/index.js";
import { VERSION } from "./version.js";

program
.name("trail")
.description("Leave a trail of your work for others to follow")
.version("0.1.0")
.version(VERSION)
.option(
"--data-dir <path>",
"Override trajectory storage directory (or set TRAJECTORIES_DATA_DIR)",
Expand Down
3 changes: 2 additions & 1 deletion src/cli/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { Command } from "commander";
import { registerCommands } from "./commands/index.js";
import { VERSION } from "./version.js";

export interface CommandResult {
success: boolean;
Expand Down Expand Up @@ -37,7 +38,7 @@ export async function runCommand(args: string[]): Promise<CommandResult> {
program
.name("traj")
.description("Capture the complete train of thought of agent work")
.version("0.1.0")
.version(VERSION)
.exitOverride() // Don't exit process on error
.configureOutput({
writeOut: (str) => {
Expand Down
30 changes: 30 additions & 0 deletions src/cli/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";

function findPackageJson(startDir: string): string {
let dir = startDir;
while (dir !== path.dirname(dir)) {
const candidate = path.join(dir, "package.json");
if (fs.existsSync(candidate)) {
return candidate;
}
dir = path.dirname(dir);
}
throw new Error("Could not find package.json");
}

function resolveCliVersion(): string {
try {
const here = path.dirname(fileURLToPath(import.meta.url));
const packageJsonPath = findPackageJson(here);
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, "utf-8"),
) as { version?: string };
return packageJson.version ?? "unknown";
} catch {
return "unknown";
}
}

export const VERSION = resolveCliVersion();
Loading