In the previous chapter, Structured Memory Taxonomy, we learned what the AI is allowed to remember (User, Feedback, Project, Reference).
Now we face a social problem. Imagine you are an expert developer who hates long explanations, but your teammate is a junior developer who needs them. If the AI learns "The user likes concise answers" from you, should it apply that rule to your teammate? No.
However, if you tell the AI "We always use Tabs, never Spaces," should that apply to your teammate? Yes.
This brings us to Scoped Persistence.
To solve the conflict between personal preferences and project facts, memdir splits memory into two physical locations. Think of them like this:
fmt library for logging," "The deployment script is deploy.sh."Let's see how the AI handles two different pieces of information during a conversation.
team/ folder. When your teammate opens the project, the AI reads this file and enforces the 4-space rule for them too.How does the AI know where to put things? We don't rely on magic. We give the AI a "map" of where the folders are and strict rules on which drawer to open.
When the system boots up, it constructs a prompt that defines these two scopes.
First, the code needs to figure out where these directories live on the hard drive. We distinguish between the Auto (Private) path and the Team path.
The Team path is actually just a sub-folder of the main memory directory.
// src/teamMemPaths.ts
export function getTeamMemPath(): string {
// It's just a 'team' folder inside the main memory directory
return (join(getAutoMemPath(), 'team') + sep).normalize('NFC')
}
getAutoMemPath(): Finds your local "Personal Notebook" folder.join(..., 'team'): Creates the "Shared Whiteboard" room inside it.
The most important part is telling the AI how to use these folders. We do this in teamMemPrompts.ts. We build a specific set of instructions that explicitly defines the difference.
// src/teamMemPrompts.ts (Simplified)
export function buildCombinedMemoryPrompt(): string {
const autoDir = getAutoMemPath()
const teamDir = getTeamMemPath()
return `
You have a persistent memory system with two directories:
1. Private: ${autoDir} (Only for the current user)
2. Team: ${teamDir} (Shared with all users)
If the user gives personal preferences -> Save to Private.
If the user gives project guidelines -> Save to Team.
`
}
By injecting the actual file paths (${teamDir}) into the prompt, the AI knows exactly where to write the files on the disk.
Since we are allowing the AI (and potentially shared team configuration) to write files to your disk, we must ensure it doesn't write outside the allowed box.
Imagine a malicious team memory that tries to write to ../../../../etc/passwd. We prevent this with strict path validation.
// src/teamMemPaths.ts (Simplified)
export function validateTeamMemWritePath(filePath: string) {
const teamDir = getTeamMemPath()
// 1. Check if the path starts with the allowed directory
if (!filePath.startsWith(teamDir)) {
throw new Error("Security Alert: Path escapes team directory!")
}
// 2. (Not shown) We also check for symlinks that point outside!
return filePath
}
This ensures that "Team Memory" stays strictly inside the memory/team folder and cannot touch your system files or your private memory.
When the system runs, the AI receives a prompt that combines the Taxonomy (Chapter 1) with the Scopes (Chapter 2). It looks roughly like this:
Input (System Prompt):
"You have a Private directory at
/Users/me/mem/and a Team directory at/Users/me/mem/team/.
Taxonomy Rules:
-
Usertype -> usually Private.
-
Projecttype -> usually Team.
-
Feedbacktype -> depends (Is it 'I hate this' or 'This logic is wrong'?)"
Output (AI Action): The AI decides on the action based on the content.
---
name: strict_linting_rules
type: feedback
scope: team
---
User stated that the linter must run before every commit.
The system then routes this file creation to the path: /Users/me/mem/team/strict_linting_rules.md.
In this chapter, we learned:
Private and Team).We now have structured files (Chapter 1) stored in the right places (Chapter 2). But as the project grows, we might have hundreds of these files. Asking the AI to read 500 files every time you say "Hello" is too slow and expensive.
How do we solve the scaling problem?
Next Chapter: Two-Tier Storage Architecture (Index vs. Detail)
Generated by Code IQ