Repository navigation
feat: add durable memory checkpoints #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||
| import path from "node:path"; | ||||||||||
| import { promises as fs } from "node:fs"; | ||||||||||
| import { simpleGit, type SimpleGit } from "simple-git"; | ||||||||||
| import { Bundle } from "./bundle.js"; | ||||||||||
| import { pruneEmptyDirs, regenerateIndexChain } from "./indexer.js"; | ||||||||||
|
|
@@ -59,6 +60,19 @@ export class KnowledgeBase { | |||||||||
| return readLog(this.bundle); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| async writeCheckpoint(sessionId: string, messages: unknown[]): Promise<string> { | ||||||||||
| const safe = sessionId.replace(/[^a-zA-Z0-9._-]/g, "_"); | ||||||||||
| if (!safe) throw new Error("Checkpoint session ID is required"); | ||||||||||
| const dir = path.join(this.bundle.root, ".checkpoints"); | ||||||||||
| const target = path.join(dir, `${safe}.json`); | ||||||||||
| const temp = `${target}.tmp-${process.pid}-${Date.now()}`; | ||||||||||
|
Comment on lines
+63
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win Preserve the original session ID identity in the checkpoint filename.
🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Generate a unique temporary filename. Two Proposed fix+import { randomUUID } from "node:crypto";
+
- const temp = `${target}.tmp-${process.pid}-${Date.now()}`;
+ const temp = `${target}.tmp-${process.pid}-${randomUUID()}`;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| const payload = JSON.stringify({ version: 1, session_id: sessionId, created_at: new Date().toISOString(), messages }); | ||||||||||
| await fs.mkdir(dir, { recursive: true }); | ||||||||||
| await fs.writeFile(temp, payload, { encoding: "utf-8", mode: 0o600 }); | ||||||||||
| await fs.rename(temp, target); | ||||||||||
|
Comment on lines
+71
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win Synchronize the checkpoint before reporting success.
🤖 Prompt for AI Agents |
||||||||||
| return `/.checkpoints/${safe}.json`; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| validate(): Promise<ConformanceReport> { | ||||||||||
| return validateBundle(this.bundle); | ||||||||||
| } | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🛡️ Analyzed with Security Review | 🟡 Minor | ⚡ Quick win
Security Misconfiguration
Reachability: External
Exploitability: Moderate
CWE: CWE-732 — Incorrect Permission Assignment for Critical Resource
Create
.checkpointswith mode0o700. A permissive umask can expose session-derived filenames to local users. The0o600checkpoint files prevent transcript reads, but do not prevent filename enumeration.🤖 Prompt for AI Agents