memwiki 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ <h1 align="center">🧠 memwiki</h1>
2
+ <p align="center">
3
+ <strong>A zero-friction, persistent project memory protocol for AI agents.</strong>
4
+ </p>
5
+ <p align="center">
6
+ <img alt="NPM Version" src="https://img.shields.io/npm/v/memwiki?color=blue&style=flat-square">
7
+ <img alt="License" src="https://img.shields.io/npm/l/memwiki?style=flat-square">
8
+ <img alt="Zero Dependencies" src="https://img.shields.io/badge/dependencies-0-brightgreen?style=flat-square">
9
+ </p>
10
+
11
+ ---
12
+
13
+ AI coding agents (like Cursor, Claude Code, GitHub Copilot) suffer from "Agent Amnesia". When you start a new session, the agent forgets why certain architectural decisions were made, the project's tech stack quirks, known bugs, and the immediate context.
14
+
15
+ `memwiki` gives your project a persistent brain. It leverages the fact that modern AI agents naturally read markdown files in your workspace, providing a standardized, vendor-agnostic memory system without requiring complex plugins or subscriptions.
16
+
17
+ ## Getting Started
18
+
19
+ Initialize `memwiki` in the root of any project:
20
+
21
+ ```bash
22
+ npx memwiki init
23
+ ```
24
+
25
+ That's it. Your project now has a persistent memory.
26
+
27
+ ### Updating the Protocol
28
+ As `memwiki` evolves and we release better agent prompts and slash commands, you can update your existing project's protocol files without overwriting your actual memory wiki:
29
+
30
+ ```bash
31
+ npx memwiki update
32
+ ```
33
+ This safely updates `AGENTS.md` and your root hooks (`.cursorrules`, `CLAUDE.md`, etc.) while leaving the contents of `.memory/wiki/` completely untouched.
34
+
35
+ ## How It Works
36
+
37
+ When you run `npx memwiki init`, it creates a `.memory` directory and places specific hook files (`.cursorrules`, `CLAUDE.md`, `.github/copilot-instructions.md`) directly in your project root.
38
+
39
+ These root files act as the automatic "front door" for any AI agent that connects to your repository, explicitly instructing them: *"Hey! I have a brain. Please read `AGENTS.md` and `.memory/wiki/hot.md` before doing anything else."*
40
+
41
+ ### The Folder Structure
42
+
43
+ ```text
44
+ [Project Root]
45
+ ā”œā”€ā”€ .cursorrules (Hook for Cursor)
46
+ ā”œā”€ā”€ .github/copilot-instructions.md (Hook for Copilot)
47
+ ā”œā”€ā”€ CLAUDE.md (Hook for Claude Code)
48
+ ā”œā”€ā”€ AGENTS.md (The master protocol file)
49
+ └── .memory/
50
+ ā”œā”€ā”€ .raw/ (Immutable source documents dropped by humans)
51
+ └── wiki/
52
+ ā”œā”€ā”€ hot.md (Hot cache: recent context & next steps - READ FIRST)
53
+ ā”œā”€ā”€ index.md (Table of contents)
54
+ ā”œā”€ā”€ log.md (Append-only changelog)
55
+ ā”œā”€ā”€ stack.md (Tech stack details)
56
+ ā”œā”€ā”€ patterns.md (Coding patterns and conventions)
57
+ ā”œā”€ā”€ bugs.md (Known issues and quirks)
58
+ └── decisions.md (Architecture Decision Records)
59
+ ```
60
+
61
+ ### Reading & Synthesizing
62
+
63
+ 1. **The Hot Cache (`hot.md`)**: Agents read this file *first*. It contains immediate, short-term context (~500 words). It tells the agent exactly what was being worked on and the immediate next steps.
64
+ 2. **Immutable Sources (`.raw/`)**: Drop your PDF API docs, GitHub gists, or meeting notes here. Agents are instructed to *read* these files but *never* modify them.
65
+ - **How it works:** When you drop a file like `stripe-api.pdf` into `.raw/`, you simply tell your agent: *"Please process the new Stripe docs in the raw folder."* The agent will read the PDF and synthesize the important architectural details into a clean markdown file inside the `wiki/` folder, leaving the original PDF untouched as a source of truth.
66
+
67
+ ### Autonomous Updating
68
+
69
+ Because modern AI tools have file editing capabilities, the `AGENTS.md` protocol contains explicit instructions for the agent to maintain the wiki proactively:
70
+
71
+ - "Whenever you learn a new coding pattern, fix a complex bug, or make a significant architectural decision, edit the corresponding file in \`.memory/wiki/\`."
72
+ - "Before ending a session, you MUST update \`.memory/wiki/hot.md\` with the current state and next steps, and append a summary to \`log.md\`."
73
+
74
+ ## Using `memwiki` on Existing Projects
75
+
76
+ If you initialize `memwiki` on a project that has been in development for months, the `.memory/wiki/` files will start out mostly blank. How does the memory fill up?
77
+
78
+ There are two ways the memory gets populated:
79
+
80
+ **1. Organic Growth (The Lazy Way)**
81
+ You don't *have* to do anything. As you continue working on the project and asking your AI agent to fix bugs or build features, the agent will naturally explore your codebase. Because of the rules in `AGENTS.md`, whenever the agent learns an established pattern or makes a new architectural decision during a session, it will automatically document it in the wiki.
82
+
83
+ **2. Active Ingestion (The Fast Way)**
84
+ If you want the memory populated immediately, you can use one of the built-in agent slash commands.
85
+
86
+ ### Scaling to Enterprise Projects
87
+ Are you worried that a single `patterns.md` file will grow to thousands of lines in a massive monorepo? Don't be!
88
+
89
+ `memwiki` is not limited to the default starter files. The `AGENTS.md` protocol explicitly instructs your AI agent to **create new markdown files and subdirectories** as the project grows.
90
+ For example, if you build a complex authentication system, the agent will dynamically create `.memory/wiki/auth-system.md` and link it to the master `index.md`. The `index.md` file acts as a Map of Content (MOC), routing the agent to the right domain-specific files without overflowing the context window.
91
+
92
+ ### Agent Slash Commands
93
+
94
+ Because `AGENTS.md` explicitly teaches your AI tool how to behave, it also gives your agent "commands" you can run in your chat interface:
95
+
96
+ - `/memwiki-ingest`: The agent will scan your entire repository and populate `stack.md`, `patterns.md`, and `decisions.md` based on what it finds.
97
+ - `/memwiki-lint`: The agent will perform a health check on the wiki, fixing outdated information or filling in missing context.
98
+ - `/memwiki-fold`: The agent will condense older entries in `log.md` into a clean summary to prevent the log from becoming too large.
99
+
100
+ ## Why `memwiki`?
101
+
102
+ - **Zero Friction:** One command setup.
103
+ - **Zero Lock-in:** It's just Markdown.
104
+ - **Universal Compatibility:** Works seamlessly with Cursor, Claude, Copilot, or any tool that reads local files.
105
+ - **Team Scalability:** Ensures that whether a team member uses Cursor or Gemini, they both operate on the exact same project context.
106
+
107
+ ## Inspired By
108
+ This pattern is heavily inspired by Andrej Karpathy's [LLM Wiki pattern](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f).
package/dist/index.js ADDED
@@ -0,0 +1,143 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const command = process.argv[2];
10
+ if (command !== 'init' && command !== 'update') {
11
+ console.log('Usage: npx memwiki init | npx memwiki update');
12
+ process.exit(1);
13
+ }
14
+ console.log(`Running memwiki ${command}...`);
15
+ const targetDir = process.cwd();
16
+ const files = {
17
+ // --- Root Hook Files ---
18
+ '.cursorrules': `# MemWiki Integration
19
+ ALWAYS start your session by reading \`AGENTS.md\` and \`.memory/wiki/hot.md\` to get project context before suggesting code or answering questions.
20
+ `,
21
+ '.github/copilot-instructions.md': `# MemWiki Integration
22
+ ALWAYS read \`AGENTS.md\` and \`.memory/wiki/hot.md\` to understand the project context, tech stack, and immediate next steps before coding.
23
+ `,
24
+ 'CLAUDE.md': `# MemWiki Integration
25
+ Please read \`AGENTS.md\` and \`.memory/wiki/hot.md\` as your primary source of truth for this project before answering any queries or making changes.
26
+ `,
27
+ // --- The Protocol ---
28
+ 'AGENTS.md': `# MemWiki Protocol: Agent Instructions
29
+
30
+ This project uses **MemWiki** (inspired by the [LLM Wiki pattern](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f)), a persistent compounding knowledge base for AI coding agents.
31
+
32
+ ## 1. Session Start (Reading)
33
+ Whenever you start a new session or task, you MUST:
34
+ 1. READ \`.memory/wiki/hot.md\` immediately. This contains the immediate context, current state, and next steps.
35
+ 2. If \`hot.md\` does not have enough context, consult \`.memory/wiki/index.md\` to find relevant domain pages.
36
+ 3. If the user drops new API docs, PDF specs, or gists into \`.memory/.raw/\`, read them to understand the new information, but **never modify the files in \`.raw/\`**.
37
+
38
+ ## 2. During Work (Synthesizing)
39
+ Whenever you learn a new coding pattern, fix a complex bug, or make a significant architectural decision:
40
+ - You MUST edit the corresponding file in \`.memory/wiki/\` (e.g., \`patterns.md\`, \`bugs.md\`, \`decisions.md\`).
41
+ - **Scale the Wiki:** If the project is large, DO NOT cram everything into the default files. Create new markdown files or subdirectories in \`.memory/wiki/\` for specific features, domains, or microservices (e.g., \`.memory/wiki/auth-system.md\`).
42
+ - If you create a new file, you MUST add a link to it in \`.memory/wiki/index.md\`.
43
+ - Synthesize any raw knowledge from \`.memory/.raw/\` into the wiki pages.
44
+ - Never delete knowledge from the wiki. Only append or refine.
45
+
46
+ ## 3. Session End (Updating)
47
+ Before ending a session, completing a major task, or when you are about to lose context:
48
+ 1. **Update Hot Cache:** You MUST update \`.memory/wiki/hot.md\` with the current state of the project and the immediate next steps for the next agent.
49
+ 2. **Log Work:** You MUST append a timestamped summary of your work to \`.memory/wiki/log.md\`.
50
+
51
+ ## 4. Agent Slash Commands
52
+ The user may invoke specific commands. When you see these commands in the chat, execute the corresponding workflow:
53
+
54
+ - \`/memwiki-ingest\`: Trigger an active ingestion pass. Scan the entire repository and populate \`stack.md\`, \`patterns.md\`, and \`decisions.md\` based on your findings.
55
+ - \`/memwiki-lint\`: Perform a health check on the wiki. Look for outdated information, missing context in \`hot.md\`, or empty domain pages, and propose fixes.
56
+ - \`/memwiki-fold\`: Condense older entries in \`log.md\` into a summarized paragraph to keep the file from becoming too long, while preserving crucial history.
57
+ `,
58
+ // --- The Wiki Files ---
59
+ '.memory/wiki/hot.md': `# Hot Cache
60
+
61
+ *This file is read first by agents to get immediate context. Agents must update this at the end of every session.*
62
+
63
+ ## Current State
64
+ - Project initialized with MemWiki.
65
+
66
+ ## Immediate Next Steps
67
+ - [ ] Define the project scope.
68
+ - [ ] Set up the initial tech stack.
69
+ `,
70
+ '.memory/wiki/index.md': `# Project Wiki
71
+
72
+ *The central directory for all project knowledge.*
73
+
74
+ - [[hot.md]]: Immediate context and next steps.
75
+ - [[log.md]]: Append-only changelog of agent sessions.
76
+ - [[stack.md]]: Tech stack details and versions.
77
+ - [[patterns.md]]: Established coding patterns and conventions.
78
+ - [[bugs.md]]: Known issues, quirks, and workarounds.
79
+ - [[decisions.md]]: Architecture Decision Records (ADRs).
80
+
81
+ *(Agents: Create new files for specific features or domains as the project scales, and link them here).*
82
+ `,
83
+ '.memory/wiki/log.md': `# Work Log
84
+
85
+ *Append-only changelog. Agents must append a timestamped summary of their work here at the end of each session.*
86
+
87
+ ## Initial Setup
88
+ - Project memory initialized via MemWiki.
89
+ `,
90
+ '.memory/wiki/stack.md': `# Tech Stack
91
+
92
+ *Document the core technologies, versions, and deployment details here.*
93
+
94
+ `,
95
+ '.memory/wiki/patterns.md': `# Coding Patterns
96
+
97
+ *Document established coding conventions, file structures, and UI/UX patterns here.*
98
+
99
+ `,
100
+ '.memory/wiki/bugs.md': `# Known Bugs & Quirks
101
+
102
+ *Document unresolved issues, edge cases, and weird system quirks here to prevent future agents from falling into the same traps.*
103
+
104
+ `,
105
+ '.memory/wiki/decisions.md': `# Architectural Decisions
106
+
107
+ *Document major technical decisions, the rationale behind them, and alternatives considered.*
108
+
109
+ `
110
+ };
111
+ const createDirIfNotExists = (dir) => {
112
+ if (!fs_1.default.existsSync(dir)) {
113
+ fs_1.default.mkdirSync(dir, { recursive: true });
114
+ }
115
+ };
116
+ // Ensure .memory directories exist
117
+ createDirIfNotExists(path_1.default.join(targetDir, '.github'));
118
+ createDirIfNotExists(path_1.default.join(targetDir, '.memory', '.raw'));
119
+ createDirIfNotExists(path_1.default.join(targetDir, '.memory', 'wiki'));
120
+ let updatedCount = 0;
121
+ for (const [relativePath, content] of Object.entries(files)) {
122
+ const filePath = path_1.default.join(targetDir, relativePath);
123
+ const isProtocolFile = relativePath === 'AGENTS.md' || relativePath === '.cursorrules' || relativePath === '.github/copilot-instructions.md' || relativePath === 'CLAUDE.md';
124
+ if (command === 'update' && isProtocolFile) {
125
+ fs_1.default.writeFileSync(filePath, content, 'utf8');
126
+ console.log(`šŸ”„ Updated: ${relativePath}`);
127
+ updatedCount++;
128
+ }
129
+ else if (!fs_1.default.existsSync(filePath)) {
130
+ fs_1.default.writeFileSync(filePath, content, 'utf8');
131
+ console.log(`āœ… Created: ${relativePath}`);
132
+ updatedCount++;
133
+ }
134
+ else {
135
+ console.log(`āš ļø Skipped (already exists): ${relativePath}`);
136
+ }
137
+ }
138
+ if (updatedCount > 0) {
139
+ console.log(`\nšŸš€ MemWiki ${command} completed successfully!`);
140
+ }
141
+ else {
142
+ console.log('\nāœ… Everything is already up to date.');
143
+ }
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const command = process.argv[2];
10
+ if (command !== 'init') {
11
+ console.log('Usage: npx memwiki init');
12
+ process.exit(1);
13
+ }
14
+ console.log('Initializing memwiki project memory protocol...');
15
+ const targetDir = process.cwd();
16
+ const files = {
17
+ // --- Root Hook Files ---
18
+ '.cursorrules': `# MemWiki Integration
19
+ ALWAYS start your session by reading \`AGENTS.md\` and \`.memory/wiki/hot.md\` to get project context before suggesting code or answering questions.
20
+ `,
21
+ '.github/copilot-instructions.md': `# MemWiki Integration
22
+ ALWAYS read \`AGENTS.md\` and \`.memory/wiki/hot.md\` to understand the project context, tech stack, and immediate next steps before coding.
23
+ `,
24
+ 'CLAUDE.md': `# MemWiki Integration
25
+ Please read \`AGENTS.md\` and \`.memory/wiki/hot.md\` as your primary source of truth for this project before answering any queries or making changes.
26
+ `,
27
+ // --- The Protocol ---
28
+ 'AGENTS.md': `# MemWiki Protocol: Agent Instructions
29
+
30
+ This project uses **MemWiki**, a persistent compounding knowledge base for AI coding agents.
31
+
32
+ ## 1. Session Start (Reading)
33
+ Whenever you start a new session or task, you MUST:
34
+ 1. READ \`.memory/wiki/hot.md\` immediately. This contains the immediate context, current state, and next steps.
35
+ 2. If \`hot.md\` does not have enough context, consult \`.memory/wiki/index.md\` to find relevant domain pages.
36
+ 3. If the user drops new API docs, PDF specs, or gists into \`.memory/.raw/\`, read them to understand the new information, but **never modify the files in \`.raw/\`**.
37
+
38
+ ## 2. During Work (Synthesizing)
39
+ Whenever you learn a new coding pattern, fix a complex bug, or make a significant architectural decision:
40
+ - You MUST edit the corresponding file in \`.memory/wiki/\` (e.g., \`patterns.md\`, \`bugs.md\`, \`decisions.md\`).
41
+ - Synthesize any raw knowledge from \`.memory/.raw/\` into the wiki pages.
42
+ - Never delete knowledge from the wiki. Only append or refine.
43
+
44
+ ## 3. Session End (Updating)
45
+ Before ending a session, completing a major task, or when you are about to lose context:
46
+ 1. **Update Hot Cache:** You MUST update \`.memory/wiki/hot.md\` with the current state of the project and the immediate next steps for the next agent.
47
+ 2. **Log Work:** You MUST append a timestamped summary of your work to \`.memory/wiki/log.md\`.
48
+ `,
49
+ // --- The Wiki Files ---
50
+ '.memory/wiki/hot.md': `# Hot Cache
51
+
52
+ *This file is read first by agents to get immediate context. Agents must update this at the end of every session.*
53
+
54
+ ## Current State
55
+ - Project initialized with MemWiki.
56
+
57
+ ## Immediate Next Steps
58
+ - [ ] Define the project scope.
59
+ - [ ] Set up the initial tech stack.
60
+ `,
61
+ '.memory/wiki/index.md': `# Project Wiki
62
+
63
+ *The central directory for all project knowledge.*
64
+
65
+ - [[hot.md]]: Immediate context and next steps.
66
+ - [[log.md]]: Append-only changelog of agent sessions.
67
+ - [[stack.md]]: Tech stack details and versions.
68
+ - [[patterns.md]]: Established coding patterns and conventions.
69
+ - [[bugs.md]]: Known issues, quirks, and workarounds.
70
+ - [[decisions.md]]: Architecture Decision Records (ADRs).
71
+ `,
72
+ '.memory/wiki/log.md': `# Work Log
73
+
74
+ *Append-only changelog. Agents must append a timestamped summary of their work here at the end of each session.*
75
+
76
+ ## Initial Setup
77
+ - Project memory initialized via MemWiki.
78
+ `,
79
+ '.memory/wiki/stack.md': `# Tech Stack
80
+
81
+ *Document the core technologies, versions, and deployment details here.*
82
+
83
+ `,
84
+ '.memory/wiki/patterns.md': `# Coding Patterns
85
+
86
+ *Document established coding conventions, file structures, and UI/UX patterns here.*
87
+
88
+ `,
89
+ '.memory/wiki/bugs.md': `# Known Bugs & Quirks
90
+
91
+ *Document unresolved issues, edge cases, and weird system quirks here to prevent future agents from falling into the same traps.*
92
+
93
+ `,
94
+ '.memory/wiki/decisions.md': `# Architectural Decisions
95
+
96
+ *Document major technical decisions, the rationale behind them, and alternatives considered.*
97
+
98
+ `
99
+ };
100
+ const createDirIfNotExists = (dir) => {
101
+ if (!fs_1.default.existsSync(dir)) {
102
+ fs_1.default.mkdirSync(dir, { recursive: true });
103
+ }
104
+ };
105
+ // Ensure .memory directories exist
106
+ createDirIfNotExists(path_1.default.join(targetDir, '.github'));
107
+ createDirIfNotExists(path_1.default.join(targetDir, '.memory', '.raw'));
108
+ createDirIfNotExists(path_1.default.join(targetDir, '.memory', 'wiki'));
109
+ let createdCount = 0;
110
+ for (const [relativePath, content] of Object.entries(files)) {
111
+ const filePath = path_1.default.join(targetDir, relativePath);
112
+ if (!fs_1.default.existsSync(filePath)) {
113
+ fs_1.default.writeFileSync(filePath, content, 'utf8');
114
+ console.log(`āœ… Created: ${relativePath}`);
115
+ createdCount++;
116
+ }
117
+ else {
118
+ console.log(`āš ļø Skipped (already exists): ${relativePath}`);
119
+ }
120
+ }
121
+ if (createdCount > 0) {
122
+ console.log('\nšŸš€ MemWiki initialized successfully! Your AI agent now has a persistent brain.');
123
+ }
124
+ else {
125
+ console.log('\nāœ… MemWiki was already initialized.');
126
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "memwiki",
3
+ "version": "1.0.0",
4
+ "description": "A zero-friction persistent memory protocol for AI agents.",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "memwiki": "./dist/index.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "prepublishOnly": "npm run build"
15
+ },
16
+ "keywords": [
17
+ "ai",
18
+ "agents",
19
+ "memory",
20
+ "wiki",
21
+ "cursor",
22
+ "claude",
23
+ "copilot",
24
+ "llm"
25
+ ],
26
+ "author": "Swapnil",
27
+ "license": "ISC",
28
+ "devDependencies": {
29
+ "@types/node": "^22.13.9",
30
+ "typescript": "^5.8.2"
31
+ }
32
+ }