workingBranch
uses node:sqlite
The branch a tcm in root works on: a session's (TCM_BRANCH), else the codebase's own (tcm switch).
import path from "node:path"; import { DatabaseSync } from "node:sqlite"; export function workingBranch(root: string): string | undefined { if (process.env.TCM_BRANCH) return process.env.TCM_BRANCH; try { const db = new DatabaseSync(path.join(root, ".tcm", "codebase.sqlite"), { readOnly: true }); try { return ( db.prepare("SELECT value FROM settings WHERE key = 'branch'").get() as | { value: string } | undefined )?.value; } finally { db.close(); } } catch { return undefined; } }