@compr/contextengine-mcp 1.9.44

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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +200 -0
  3. package/dist/agents.d.ts +127 -0
  4. package/dist/agents.d.ts.map +1 -0
  5. package/dist/agents.js +1162 -0
  6. package/dist/agents.js.map +1 -0
  7. package/dist/cache.d.ts +15 -0
  8. package/dist/cache.d.ts.map +1 -0
  9. package/dist/cache.js +117 -0
  10. package/dist/cache.js.map +1 -0
  11. package/dist/cli.d.ts +10 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +227 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/code-chunker.d.ts +12 -0
  16. package/dist/code-chunker.d.ts.map +1 -0
  17. package/dist/code-chunker.js +263 -0
  18. package/dist/code-chunker.js.map +1 -0
  19. package/dist/collectors.d.ts +63 -0
  20. package/dist/collectors.d.ts.map +1 -0
  21. package/dist/collectors.js +617 -0
  22. package/dist/collectors.js.map +1 -0
  23. package/dist/config.d.ts +59 -0
  24. package/dist/config.d.ts.map +1 -0
  25. package/dist/config.js +213 -0
  26. package/dist/config.js.map +1 -0
  27. package/dist/embeddings.d.ts +31 -0
  28. package/dist/embeddings.d.ts.map +1 -0
  29. package/dist/embeddings.js +91 -0
  30. package/dist/embeddings.js.map +1 -0
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +557 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/ingest.d.ts +23 -0
  36. package/dist/ingest.d.ts.map +1 -0
  37. package/dist/ingest.js +79 -0
  38. package/dist/ingest.js.map +1 -0
  39. package/dist/search.d.ts +11 -0
  40. package/dist/search.d.ts.map +1 -0
  41. package/dist/search.js +58 -0
  42. package/dist/search.js.map +1 -0
  43. package/dist/sessions.d.ts +46 -0
  44. package/dist/sessions.d.ts.map +1 -0
  45. package/dist/sessions.js +143 -0
  46. package/dist/sessions.js.map +1 -0
  47. package/dist/test-sessions.d.ts +2 -0
  48. package/dist/test-sessions.d.ts.map +1 -0
  49. package/dist/test-sessions.js.map +1 -0
  50. package/dist/test.d.ts +2 -0
  51. package/dist/test.d.ts.map +1 -0
  52. package/dist/test.js +52 -0
  53. package/dist/test.js.map +1 -0
  54. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FASTPROD
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # ContextEngine
2
+
3
+ **An MCP server that turns your project documentation into a queryable knowledge base for AI agents.**
4
+
5
+ ContextEngine indexes your `copilot-instructions.md`, `SKILLS.md`, `CLAUDE.md`, runbooks, and source code — then exposes it via the [Model Context Protocol](https://modelcontextprotocol.io) so AI coding assistants (GitHub Copilot, Claude, Cursor, Windsurf) can search your accumulated knowledge in real time.
6
+
7
+ ## Why
8
+
9
+ AI coding agents are powerful — but they forget everything between sessions. Your team's hard-won knowledge lives in scattered markdown files that agents can't search.
10
+
11
+ ContextEngine fixes this: **zero-config, fully local, privacy-first.**
12
+
13
+ - 🔍 **Hybrid Search** — keyword + semantic (vector embeddings) across all your docs
14
+ - 🧠 **Semantic Search** — `all-MiniLM-L6-v2` runs locally on CPU (no API keys)
15
+ - 📁 **Auto-discover** — finds `copilot-instructions.md`, `CLAUDE.md`, `.cursorrules`, `AGENTS.md` across all projects
16
+ - 💻 **Code Parsing** — extracts functions, classes, interfaces from TS/JS/Python source files
17
+ - ⚙️ **Operational Intelligence** — collects git, Docker, PM2, nginx, cron, package.json data
18
+ - 🔒 **Local-only** — nothing leaves your machine
19
+ - ⚡ **Instant startup** — keyword search ready immediately, embeddings load in background
20
+ - 💾 **Session Persistence** — AI agents can save/restore context across conversations
21
+ - 🔌 **MCP native** — works with any MCP-compatible client
22
+
23
+ ## Quick Start
24
+
25
+ ### 1. Scaffold config (optional)
26
+
27
+ ```bash
28
+ npx contextengine-mcp init
29
+ ```
30
+
31
+ Detects your project type, creates `contextengine.json` + `.github/copilot-instructions.md` template.
32
+
33
+ ### 2. Add to your MCP client
34
+
35
+ **VS Code** — add to `~/.vscode/mcp.json` (global) or `.vscode/mcp.json` (per-project):
36
+
37
+ ```json
38
+ {
39
+ "servers": {
40
+ "ContextEngine": {
41
+ "command": "npx",
42
+ "args": ["contextengine-mcp"]
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ **Claude Desktop** — add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
49
+
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "ContextEngine": {
54
+ "command": "npx",
55
+ "args": ["contextengine-mcp"]
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ **Cursor** — add to MCP settings:
62
+
63
+ ```json
64
+ {
65
+ "mcpServers": {
66
+ "ContextEngine": {
67
+ "command": "npx",
68
+ "args": ["contextengine-mcp"]
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ That's it. ContextEngine auto-discovers your docs in `~/Projects`.
75
+
76
+ ## Tools (11)
77
+
78
+ | Tool | Description |
79
+ |------|-------------|
80
+ | `search_context` | Hybrid keyword+semantic search with mode selector |
81
+ | `list_sources` | Show all indexed sources with chunk counts |
82
+ | `read_source` | Read full content of a knowledge source by name |
83
+ | `reindex` | Force full re-index of all sources |
84
+ | `list_projects` | Discover and analyze all projects (tech stack, git, docker, pm2) |
85
+ | `check_ports` | Scan all projects for port conflicts |
86
+ | `run_audit` | Compliance agent — git, hooks, .env, Docker, PM2, versions |
87
+ | `score_project` | AI-readiness scoring 0-100% with letter grades (A+ to F) |
88
+ | `save_session` | Save key-value entry to a named session |
89
+ | `load_session` | Load all entries from a named session |
90
+ | `list_sessions` | List all saved sessions |
91
+
92
+ ## Configuration
93
+
94
+ ContextEngine works **zero-config** — it auto-discovers documentation files in `~/Projects`.
95
+
96
+ For full control, create a `contextengine.json`:
97
+
98
+ ```json
99
+ {
100
+ "sources": [
101
+ { "name": "Team Runbook", "path": "./docs/RUNBOOK.md" },
102
+ { "name": "Architecture", "path": "./docs/ARCHITECTURE.md" }
103
+ ],
104
+ "workspaces": ["~/Projects"],
105
+ "patterns": [
106
+ ".github/copilot-instructions.md",
107
+ "CLAUDE.md",
108
+ ".cursorrules",
109
+ "AGENTS.md"
110
+ ],
111
+ "codeDirs": ["src"]
112
+ }
113
+ ```
114
+
115
+ ### Auto-discovered patterns
116
+
117
+ | Pattern | Description |
118
+ |---------|-------------|
119
+ | `.github/copilot-instructions.md` | GitHub Copilot project instructions |
120
+ | `.github/SKILLS.md` | Team skills inventory |
121
+ | `CLAUDE.md` | Claude Code project instructions |
122
+ | `.cursorrules` | Cursor AI rules |
123
+ | `.cursor/rules` | Cursor AI rules (folder format) |
124
+ | `AGENTS.md` | Multi-agent instructions |
125
+
126
+ ### Config resolution order
127
+
128
+ | Priority | Source |
129
+ |----------|--------|
130
+ | 1 | `CONTEXTENGINE_CONFIG` env var |
131
+ | 2 | `./contextengine.json` |
132
+ | 3 | `~/.contextengine.json` |
133
+ | 4 | `CONTEXTENGINE_WORKSPACES` env var |
134
+ | 5 | `~/Projects` auto-discover |
135
+
136
+ ## How It Works
137
+
138
+ ```
139
+ Your Project Files ContextEngine AI Agent
140
+ +-----------------+ +-------------------+ +---------------+
141
+ | copilot- | | 1. Parse & chunk | | GitHub |
142
+ | instructions |--->| 2. Embed vectors |<-->| Copilot |
143
+ | CLAUDE.md | | 3. Hybrid search | | Claude |
144
+ | source code | | 4. Return top-k | | Cursor |
145
+ | git/docker/pm2 | | 5. Persist state | | Windsurf |
146
+ +-----------------+ +-------------------+ +---------------+
147
+ stdio (MCP)
148
+ ```
149
+
150
+ 1. **Parse** — markdown heading-based chunker + code parser (TS/JS/Python)
151
+ 2. **Embed** — `all-MiniLM-L6-v2` sentence embeddings (384-dim, local CPU)
152
+ 3. **Search** — hybrid scoring: 40% keyword overlap + 60% cosine similarity
153
+ 4. **Collect** — operational data from git, package.json, Docker, PM2, nginx, cron
154
+ 5. **Audit** — compliance checks, port conflicts, AI-readiness scoring
155
+
156
+ ### Performance
157
+
158
+ | Metric | Value |
159
+ |--------|-------|
160
+ | Startup (keyword ready) | Instant |
161
+ | Startup (semantic ready) | ~200ms from cache, ~15s first run |
162
+ | Embedding speed | ~50 chunks/sec (Apple Silicon) |
163
+ | Embedding cache | `~/.contextengine/embedding-cache.json` |
164
+ | Session storage | `~/.contextengine/sessions/` |
165
+
166
+ ## Architecture
167
+
168
+ ```
169
+ src/
170
+ ├── cli.ts # CLI - init scaffolding, help, routes to MCP
171
+ ├── index.ts # MCP server - 11 tools, resources, file watcher
172
+ ├── config.ts # Config loading, auto-discovery, 7 patterns
173
+ ├── ingest.ts # Markdown heading-based chunker
174
+ ├── search.ts # Keyword search - term overlap scoring
175
+ ├── embeddings.ts # MiniLM-L6-v2 - vector search, cosine similarity
176
+ ├── cache.ts # Embedding cache - SHA-256 hash invalidation
177
+ ├── code-chunker.ts # Code parser - TS/JS/Python function extraction
178
+ ├── collectors.ts # 11 operational data collectors
179
+ ├── agents.ts # Compliance auditor, port checker, AI scorer
180
+ └── sessions.ts # Session persistence - key-value store
181
+ ```
182
+
183
+ ## Development
184
+
185
+ ```bash
186
+ git clone https://github.com/FASTPROD/ContextEngine.git
187
+ cd ContextEngine
188
+ npm install
189
+ npm run build
190
+ npm start
191
+ ```
192
+
193
+ ## Requirements
194
+
195
+ - Node.js 18+
196
+ - No API keys needed — embeddings run locally
197
+
198
+ ## License
199
+
200
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,127 @@
1
+ import type { ProjectDirectory } from "./config.js";
2
+ /**
3
+ * Multi-Agent Architecture — Phase 1: Foundation + Compliance Agent
4
+ *
5
+ * Implements the plan-and-approve workflow described in
6
+ * FASTPROD/docs/MULTI_AGENT_ARCHITECTURE_PLAN.md
7
+ *
8
+ * Risk levels:
9
+ * 🟢 Read-only (auto-approve) — ls, cat, SELECT, status checks
10
+ * 🟡 Non-destructive write — git commit, config edit (needs review)
11
+ * 🔴 Destructive — DELETE, DROP, rm, deploy, reload (needs confirm)
12
+ */
13
+ export interface ProjectInfo {
14
+ name: string;
15
+ path: string;
16
+ type: string;
17
+ framework: string;
18
+ runtime: string;
19
+ hasGit: boolean;
20
+ gitRemotes: string[];
21
+ hasDocker: boolean;
22
+ hasPm2: boolean;
23
+ deps: Record<string, string>;
24
+ }
25
+ export interface PlanStep {
26
+ action: string;
27
+ description: string;
28
+ command?: string;
29
+ risk: "green" | "yellow" | "red";
30
+ reversible: boolean;
31
+ estimatedTime: string;
32
+ }
33
+ export interface AuditFinding {
34
+ check: string;
35
+ status: "pass" | "warn" | "fail";
36
+ message: string;
37
+ project?: string;
38
+ severity: "info" | "low" | "medium" | "high" | "critical";
39
+ remediation?: string;
40
+ command?: string;
41
+ }
42
+ export interface AuditPlan {
43
+ agent: string;
44
+ timestamp: string;
45
+ trigger: string;
46
+ scope: string;
47
+ findings: AuditFinding[];
48
+ steps: PlanStep[];
49
+ summary: {
50
+ pass: number;
51
+ warn: number;
52
+ fail: number;
53
+ critical: number;
54
+ };
55
+ }
56
+ /**
57
+ * Analyze a project directory and determine its type, framework, runtime.
58
+ */
59
+ export declare function analyzeProject(dir: ProjectDirectory): ProjectInfo;
60
+ /**
61
+ * List all projects with tech analysis.
62
+ */
63
+ export declare function listProjects(projectDirs: ProjectDirectory[]): ProjectInfo[];
64
+ interface PortUsage {
65
+ port: number;
66
+ project: string;
67
+ source: string;
68
+ details: string;
69
+ }
70
+ /**
71
+ * Scan all projects for port declarations and detect conflicts.
72
+ */
73
+ export declare function checkPorts(projectDirs: ProjectDirectory[]): {
74
+ ports: PortUsage[];
75
+ conflicts: Array<{
76
+ port: number;
77
+ usages: PortUsage[];
78
+ }>;
79
+ };
80
+ /**
81
+ * Run the full compliance audit across all projects.
82
+ * Returns a structured plan document.
83
+ */
84
+ export declare function runComplianceAudit(projectDirs: ProjectDirectory[]): AuditPlan;
85
+ /**
86
+ * Format an audit plan as a readable Markdown document.
87
+ */
88
+ export declare function formatPlan(plan: AuditPlan): string;
89
+ /**
90
+ * Format project list as a readable summary.
91
+ */
92
+ export declare function formatProjectList(projects: ProjectInfo[]): string;
93
+ /**
94
+ * Format port map as a readable table.
95
+ */
96
+ export declare function formatPortMap(ports: PortUsage[], conflicts: Array<{
97
+ port: number;
98
+ usages: PortUsage[];
99
+ }>): string;
100
+ export interface ScoreCheck {
101
+ name: string;
102
+ category: string;
103
+ points: number;
104
+ maxPoints: number;
105
+ status: "pass" | "partial" | "fail";
106
+ detail: string;
107
+ }
108
+ export interface ProjectScore {
109
+ project: string;
110
+ path: string;
111
+ score: number;
112
+ maxScore: number;
113
+ percentage: number;
114
+ grade: string;
115
+ checks: ScoreCheck[];
116
+ }
117
+ /**
118
+ * Score a project's AI-readiness (0-100%).
119
+ * Checks how well-prepared a project is for AI coding agents.
120
+ */
121
+ export declare function scoreProject(dir: ProjectDirectory): ProjectScore;
122
+ /**
123
+ * Format a project score report as Markdown.
124
+ */
125
+ export declare function formatScoreReport(scores: ProjectScore[]): string;
126
+ export {};
127
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;;;;GAUG;AAMH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IACjC,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,UAAU,CAAC;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;A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