Files
cfw-autumn/scripts/dw/commands/identify.ts
amianthus a065c37649 feat(dw): 🎸 add identify subcommand for current worktree stack info
Prints the current worktree's server URL, vite URL, tmux session, and
ports in both a human-readable block and a KEY=value block for shell
eval. Canonical worktree gracefully shows direct localhost ports with no
tmux. Useful for agents landing in a Conductor/Superset-spawned worktree
to discover their stack.
2026-05-16 15:09:38 +01:00

52 lines
1.7 KiB
TypeScript

import { loadRegistry } from "../helpers/registry.ts";
import { getCurrentWorktree } from "../helpers/git.ts";
import { aliasesFor } from "../helpers/ports.ts";
import { tmuxSessionName } from "../helpers/tmux.ts";
export function cmdIdentify(): void {
const cwd = getCurrentWorktree();
const registry = loadRegistry();
const entry = registry[cwd];
if (!entry) {
console.error(`[dw] no registered worktree at ${cwd}`);
console.error(` run 'bun dw' here first to provision one`);
process.exit(1);
}
const { worktreeNum, branchName } = entry;
const offset = (worktreeNum - 1) * 100;
const serverPort = 8080 + offset;
const vitePort = 3000 + offset;
let serverUrl: string;
let viteUrl: string;
let tmux: string;
if (worktreeNum === 1) {
serverUrl = `http://localhost:${serverPort}`;
viteUrl = `http://localhost:${vitePort}`;
tmux = "";
} else {
const aliases = aliasesFor(worktreeNum);
serverUrl = aliases.apiUrl;
viteUrl = aliases.viteUrl;
tmux = tmuxSessionName(worktreeNum);
}
const tmuxHuman = tmux || "(canonical worktree — not in tmux)";
console.log(`Worktree #${worktreeNum} (${entry.path})`);
console.log(` Branch: ${branchName ?? "(canonical)"}`);
console.log(` Server URL: ${serverUrl}`);
console.log(` Vite URL: ${viteUrl}`);
console.log(` Tmux session: ${tmuxHuman}`);
console.log(` Server port: ${serverPort}`);
console.log(` Vite port: ${vitePort}`);
console.log();
console.log(`DW_WORKTREE_NUM=${worktreeNum}`);
console.log(`DW_SERVER_URL=${serverUrl}`);
console.log(`DW_VITE_URL=${viteUrl}`);
console.log(`DW_TMUX_SESSION=${tmux}`);
console.log(`DW_SERVER_PORT=${serverPort}`);
console.log(`DW_VITE_PORT=${vitePort}`);
}