feat(memories): store memories in markdown#232
Merged
Conversation
Add a local, inspectable memory system for `code-ollama` using Markdown files under `~/.code-ollama/memories/`. Start with manual memory only; no automatic saving, no database, and no semantic retrieval in v1.
---
Changes
- Add memory storage under:
```text
~/.code-ollama/memories/
global/
MEMORY.md
projects/
<project-slug>-<hash>/
MEMORY.md
metadata.json
```
- Derive project memory ID from the normalized git remote URL when available; fall back to the git root absolute path. Use a readable slug plus a 12-character hash.
- Load bounded memory into the system prompt:
- global `MEMORY.md`
- current project `MEMORY.md`
- cap each at first 200 lines or 25KB, whichever comes first.
- Treat `MEMORY.md` as a concise startup summary plus table of contents to relative topic files.
- Do not automatically load topic files like `debugging.md` or `conventions.md`; the agent may read them with normal file tools when relevant.
---
CLI/TUI Behavior
- Add a `/memory` command group:
- `/memory show` displays loaded global and project memory.
- `/memory add <text>` appends a bullet to the project `MEMORY.md`.
- `/memory add --global <text>` appends a bullet to global `MEMORY.md`.
- `/memory edit` opens or prints the project memory path, depending on existing editor behavior in the app.
- `/memory path` shows the active memory directory and files.
- If memory files do not exist, create them lazily on first write.
- Do not save secrets, transient branch facts, command transcripts, or speculative conclusions unless the user explicitly adds them.
---
Implementation Notes
- Add a `src/utils/memory.ts` module for:
- project ID derivation
- memory path resolution
- bounded Markdown reads
- append operations
- metadata creation
- Update system prompt construction in `src/utils/agents.ts` to include loaded memory after `AGENTS.md` and before skills.
- Add memory command handling alongside existing slash-command/menu handling, following current TUI command patterns.
- Keep the config shape minimal; no config required for v1 unless memory needs a disable flag already matching existing config style.
Now command suggestions behave like this: - `Tab` completes the highlighted suggestion into the input. - `/mo` + Tab -> `/models` - `/mem` + Tab -> `/memory` - `/memory a` + Tab -> `/memory add` - `Enter` submits/runs the highlighted command when it is executable. - File/model suggestions keep their old behavior because the new Tab completion path is opt-in for command suggestions.
- If command suggestions are visible, raw text submission backs off. - The selected suggestion submits instead. - `handleSubmitCommand` now accepts memory subcommands like `/memory path`, not just top-level commands.
Now command-specific validity lives next to command suggestions in `CommandMenu.tsx`: - `getMatchingCommands(input)` - `isSubmittableCommand(value)` - `MEMORY_COMMANDS` `ChatInput` only asks those helpers whether suggestions exist or whether the command is submittable. It no longer knows memory subcommand grammar directly.
`/memory show` should show contents only; `/memory path` is for locations.
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the motivation for this pull request?
Feature addition: a local, inspectable memory system that persists context across sessions using Markdown files under
~/.code-ollama/memories/.plan.md
What is the current behavior?
No persistent memory — context is lost between sessions.
What is the new behavior?
MEMORY.mdare loaded into the system prompt (capped at 200 lines / 25 KB each)./memorycommand group is added to the TUI:/memory show— display loaded global and project memory contents/memory add <text>— append a bullet to the projectMEMORY.md/memory add --global <text>— append a bullet to globalMEMORY.md/memory path— show the active memory directory and filesChecklist: