|
| 1 | +# Contributing to agent-knowledge |
| 2 | + |
| 3 | +## Getting Started |
| 4 | + |
| 5 | +1. Clone the repository: |
| 6 | + ```bash |
| 7 | + git clone https://github.com/keshrath/agent-knowledge.git |
| 8 | + cd agent-knowledge |
| 9 | + ``` |
| 10 | +2. Install dependencies: |
| 11 | + ```bash |
| 12 | + npm install |
| 13 | + ``` |
| 14 | +3. Build: |
| 15 | + ```bash |
| 16 | + npm run build |
| 17 | + ``` |
| 18 | + |
| 19 | +## Development Setup |
| 20 | + |
| 21 | +### Prerequisites |
| 22 | + |
| 23 | +- **Node.js >= 20** (LTS recommended) |
| 24 | +- **Git** (for knowledge base sync) |
| 25 | +- A knowledge base repo (or create one): |
| 26 | + ```bash |
| 27 | + mkdir -p ~/claude-memory && cd ~/claude-memory && git init |
| 28 | + mkdir projects people decisions workflows notes |
| 29 | + ``` |
| 30 | + |
| 31 | +### Development Mode |
| 32 | + |
| 33 | +```bash |
| 34 | +# Watch mode — recompiles on changes |
| 35 | +npm run dev |
| 36 | + |
| 37 | +# Start dashboard standalone (port 3423) |
| 38 | +KNOWLEDGE_PORT=3423 node dist/dashboard.js |
| 39 | + |
| 40 | +# Run tests |
| 41 | +npm test |
| 42 | +npm run test:watch |
| 43 | +``` |
| 44 | + |
| 45 | +### Environment |
| 46 | + |
| 47 | +```bash |
| 48 | +export KNOWLEDGE_MEMORY_DIR=~/claude-memory |
| 49 | +export CLAUDE_DIR=~/.claude |
| 50 | +export KNOWLEDGE_PORT=3423 |
| 51 | +``` |
| 52 | + |
| 53 | +## Project Structure |
| 54 | + |
| 55 | +``` |
| 56 | +agent-knowledge/ |
| 57 | + src/ |
| 58 | + index.ts Entry point (MCP stdio + dashboard auto-start) |
| 59 | + server.ts MCP server, 10 tool definitions, request routing |
| 60 | + dashboard.ts HTTP + WebSocket server, REST API, file watcher |
| 61 | + types.ts KnowledgeConfig, getConfig() |
| 62 | + knowledge/ |
| 63 | + store.ts Markdown CRUD, frontmatter parsing, path traversal protection |
| 64 | + search.ts TF-IDF search over knowledge entries with regex fallback |
| 65 | + git.ts git pull/push/sync with timeouts |
| 66 | + sessions/ |
| 67 | + parser.ts JSONL parsing with mtime-based cache |
| 68 | + search.ts TF-IDF ranked search with 60s global index cache |
| 69 | + scopes.ts 6 search scopes (errors, plans, configs, tools, files, decisions) |
| 70 | + summary.ts Session summaries, topic extraction, file path detection |
| 71 | + search/ |
| 72 | + tfidf.ts TF-IDF scoring engine (tokenizer, stopwords, index) |
| 73 | + fuzzy.ts Levenshtein distance, sliding window fuzzy matching |
| 74 | + types.ts SearchResult, SearchOptions interfaces |
| 75 | + ui/ |
| 76 | + index.html Dashboard SPA |
| 77 | + styles.css MD3 design tokens (light + dark) |
| 78 | + app.js Client-side vanilla JS (WebSocket, tabs, rendering) |
| 79 | + tests/ |
| 80 | + tfidf.test.ts TF-IDF engine tests (8) |
| 81 | + fuzzy.test.ts Fuzzy matching tests (7) |
| 82 | + docs/ |
| 83 | + SETUP.md Installation and configuration guide |
| 84 | + ARCHITECTURE.md Technical architecture documentation |
| 85 | + DASHBOARD.md Dashboard features and usage |
| 86 | + assets/ Screenshots |
| 87 | +``` |
| 88 | + |
| 89 | +## Code Style |
| 90 | + |
| 91 | +- **TypeScript** with strict mode, ES modules |
| 92 | +- **Imports**: use `.js` extensions (TypeScript NodeNext convention) |
| 93 | +- **Naming**: `camelCase` for functions/variables, `PascalCase` for types/classes, `UPPER_SNAKE` for constants |
| 94 | +- **Async**: use `async`/`await` over raw promises |
| 95 | +- **Error handling**: throw descriptive errors, catch and return MCP-formatted errors in tool handlers |
| 96 | +- **No external formatters** -- match existing code style |
| 97 | + |
| 98 | +## Testing |
| 99 | + |
| 100 | +```bash |
| 101 | +npm test # Run all tests |
| 102 | +npm run test:watch # Watch mode |
| 103 | +npx vitest run tests/tfidf.test.ts # Single file |
| 104 | +npm run lint # Type-check (tsc --noEmit) |
| 105 | +``` |
| 106 | + |
| 107 | +Tests use **vitest** with `fs.mkdtempSync` for temp directories in filesystem tests. |
| 108 | + |
| 109 | +### What to Test |
| 110 | + |
| 111 | +- Knowledge store: CRUD, frontmatter parsing, category validation, path traversal |
| 112 | +- TF-IDF: tokenization, stopwords, ranking correctness, edge cases |
| 113 | +- Fuzzy: Levenshtein distance, threshold filtering, sliding window |
| 114 | +- Sessions: JSONL parsing, malformed line handling, message extraction |
| 115 | + |
| 116 | +## Pull Requests |
| 117 | + |
| 118 | +1. All tests must pass |
| 119 | +2. Type-check must be clean (`npm run typecheck`) |
| 120 | +3. Lint and format checks must pass (`npm run check`) |
| 121 | +4. Update docs if changing tool behavior or adding features |
| 122 | +5. Keep commits focused -- one logical change per commit |
| 123 | + |
| 124 | +## License |
| 125 | + |
| 126 | +MIT |
0 commit comments