(entry: ContextEntry)
| 14 | } |
| 15 | |
| 16 | export async function saveContext(entry: ContextEntry): Promise<string> { |
| 17 | const dir = await getDevCtxDir(); |
| 18 | const sessionsDir = path.join(dir, "sessions"); |
| 19 | const branchesDir = path.join(dir, "branches"); |
| 20 | |
| 21 | fs.mkdirSync(sessionsDir, { recursive: true }); |
| 22 | fs.mkdirSync(branchesDir, { recursive: true }); |
| 23 | |
| 24 | // Save session |
| 25 | const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 16); |
| 26 | const sessionFile = path.join(sessionsDir, `${timestamp}.json`); |
| 27 | fs.writeFileSync(sessionFile, JSON.stringify(entry, null, 2)); |
| 28 | |
| 29 | // Update branch context (latest for this branch) |
| 30 | const branchFile = path.join(branchesDir, `${entry.branch.replace(/\//g, "__")}.json`); |
| 31 | |
| 32 | // Load existing entries or start fresh |
| 33 | let branchEntries: ContextEntry[] = []; |
| 34 | if (fs.existsSync(branchFile)) { |
| 35 | branchEntries = JSON.parse(fs.readFileSync(branchFile, "utf-8")); |
| 36 | } |
| 37 | branchEntries.push(entry); |
| 38 | fs.writeFileSync(branchFile, JSON.stringify(branchEntries, null, 2)); |
| 39 | |
| 40 | return sessionFile; |
| 41 | } |
| 42 | |
| 43 | export async function loadBranchContext(branch: string): Promise<ContextEntry[]> { |
| 44 | const dir = await getDevCtxDir(); |
no test coverage detected