22 lines
635 B
TypeScript
22 lines
635 B
TypeScript
import { createHash } from "node:crypto";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
|
|
// Session Path - Persist child sessions as <agent>_<uuid>.jsonl under a cwd hash.
|
|
export function getSubagentSessionPath(
|
|
cwd: string,
|
|
agentName: string,
|
|
sessionId: string,
|
|
): string {
|
|
const cwdHash = createHash("sha256").update(cwd).digest("hex").slice(0, 16);
|
|
const safeAgent = agentName.replace(/[^\w.-]+/g, "_");
|
|
const safeSessionId = sessionId.replace(/[^\w.-]+/g, "_");
|
|
return path.join(
|
|
os.homedir(),
|
|
".pi",
|
|
"subagent-sessions",
|
|
cwdHash,
|
|
`${safeAgent}_${safeSessionId}.jsonl`,
|
|
);
|
|
}
|