browserSession
uses node:path
The agent-browser session (its own browser and daemon) for a codebase's branch: an agent working on its session's branch has its own, apart from another's and the user's. Outside a codebase, the directory's.
import { createHash } from "node:crypto"; import path from "node:path"; export function browserSession(root: string | undefined, branch: string | undefined, cwd: string) { const where = root ? `${root}\0${branch ?? ""}` : cwd; const slug = path .basename(root ?? cwd) .replace(/[^A-Za-z0-9]+/g, "-") .replace(/^-+|-+$/g, "") .slice(0, 24) || "dir"; return `tcm-${slug}-${createHash("sha256").update(where).digest("hex").slice(0, 8)}`; }