MCPcopy Create free account
hub / github.com/IAmUnbounded/devctx / saveContext

Function saveContext

devctx/src/core/context.ts:16–41  ·  view source on GitHub ↗
(entry: ContextEntry)

Source from the content-addressed store, hash-verified

14}
15
16export 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
43export async function loadBranchContext(branch: string): Promise<ContextEntry[]> {
44 const dir = await getDevCtxDir();

Callers 5

mcp-server.tsFile · 0.90
watchCommandFunction · 0.90
saveCommandFunction · 0.90
summarizeCommandFunction · 0.90
handoffCommandFunction · 0.90

Calls 1

getDevCtxDirFunction · 0.85

Tested by

no test coverage detected