context-mcp-server 1.0.8 → 1.1.1
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 +29 -7
- package/codegraph/__pycache__/affected.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/cache.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/callflow_html.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/export.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/report.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/server.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/tree_html.cpython-313.pyc +0 -0
- package/codegraph/affected.py +233 -0
- package/codegraph/cache.py +51 -2
- package/codegraph/callflow_html.py +273 -0
- package/codegraph/export.py +544 -0
- package/codegraph/extractors/__pycache__/ast_extractor.cpython-313.pyc +0 -0
- package/codegraph/extractors/ast_extractor.py +143 -16
- package/codegraph/graph/__pycache__/builder.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/clustering.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/query.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/symbol_resolution.cpython-313.pyc +0 -0
- package/codegraph/graph/builder.py +10 -0
- package/codegraph/graph/clustering.py +247 -10
- package/codegraph/graph/query.py +99 -0
- package/codegraph/graph/symbol_resolution.py +112 -0
- package/codegraph/report.py +53 -0
- package/codegraph/server.py +112 -20
- package/codegraph/tree_html.py +241 -0
- package/package.json +2 -2
- package/pyproject.toml +4 -1
- package/src/cli.js +329 -227
- package/src/db.js +79 -102
- package/src/search.js +73 -9
- package/src/server.js +7 -1
- package/src/templates/antigravity/GEMINI.md +96 -0
- package/src/templates/antigravity/hooks/context-mcp-post-tool-use.js +62 -0
- package/src/templates/antigravity/workflows/context-resume.md +20 -0
- package/src/templates/antigravity/workflows/graph-build.md +23 -0
- package/src/templates/antigravity/workflows/save-context.md +29 -0
- package/src/templates/claude/CLAUDE.md +140 -0
- package/src/templates/claude/commands/graph-build.md +9 -0
- package/src/templates/claude/commands/save-context.md +19 -0
- package/src/templates/claude/hooks/context-mcp-post-tool-use.js +59 -0
- package/src/templates/claude/hooks/context-mcp-pre-tool-use.js +26 -0
- package/src/templates/claude/skills/SKILL.md +144 -0
- package/src/templates/codex/AGENTS.md +107 -0
- package/src/templates/codex/hooks/context-mcp-post-tool-use.js +46 -0
- package/src/templates/codex/hooks/context-mcp-pre-tool-use.js +23 -0
- package/src/templates/codex/prompts/context-resume.md +15 -0
- package/src/templates/codex/prompts/graph-build.md +14 -0
- package/src/templates/codex/prompts/save-context.md +24 -0
- package/src/templates/cursor/commands/context-resume.md +7 -0
- package/src/templates/cursor/commands/graph-build.md +7 -0
- package/src/templates/cursor/commands/save-context.md +12 -0
- package/src/templates/{cursor-rules.mdc → cursor/cursor-rules.mdc} +13 -3
- package/src/templates/cursor/hooks/context-mcp-post-tool-use.js +55 -0
- package/src/templates/gemini/GEMINI.md +92 -0
- package/src/templates/gemini/commands/context-resume.toml +15 -0
- package/src/templates/gemini/commands/graph-build.toml +14 -0
- package/src/templates/gemini/commands/save-context.toml +24 -0
- package/src/templates/gemini/hooks/context-mcp-after-tool.js +59 -0
- package/src/templates/gemini/hooks/context-mcp-before-tool.js +26 -0
- package/src/templates/vscode/commands/context-resume.prompt.md +15 -0
- package/src/templates/vscode/commands/graph-build.prompt.md +10 -0
- package/src/templates/vscode/commands/save-context.prompt.md +16 -0
- package/src/templates/vscode/hooks/context-mcp-post-tool-use.js +58 -0
- package/src/templates/windsurf/hooks/context-mcp-post-run-command.js +57 -0
- package/src/templates/windsurf/windsurf-rules.md +86 -0
- package/src/templates/windsurf/workflows/context-resume.md +11 -0
- package/src/templates/windsurf/workflows/graph-build.md +11 -0
- package/src/templates/windsurf/workflows/save-context.md +18 -0
- package/src/tools/codegraph.js +83 -43
- package/src/tools/context.js +42 -24
- package/src/tools/plan.js +14 -11
- package/uv.lock +1101 -4
- package/src/migrator.js +0 -124
- package/src/templates/AGENTS.md +0 -80
- package/src/templates/CLAUDE.md +0 -103
- package/src/templates/GEMINI.md +0 -80
- package/src/templates/commands/graph-build.md +0 -5
- package/src/templates/commands/save-context.md +0 -9
- package/src/templates/skills/SKILL.md +0 -108
- package/src/templates/windsurf-rules.md +0 -35
- /package/src/templates/{commands → claude/commands}/context-resume.md +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Save a note/decision/bug to context-mcp project memory"
|
|
3
|
+
argument-hint: [what to remember]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Call the `context` MCP tool with `action: "save"` to store a note for the
|
|
7
|
+
current project.
|
|
8
|
+
|
|
9
|
+
Parse the following to determine the fields: $ARGUMENTS
|
|
10
|
+
|
|
11
|
+
- `project`: infer from current working directory name if not specified.
|
|
12
|
+
- `title`: first sentence or phrase, up to 120 chars.
|
|
13
|
+
- `why`: why it mattered, what problem it solved, or what constraint it revealed.
|
|
14
|
+
- `outcome`: what changed, what was verified, what shipped, and which files were affected.
|
|
15
|
+
- `files`: list of files changed, required for task/bug types.
|
|
16
|
+
- `content`: full argument text.
|
|
17
|
+
- `type`: auto-detect:
|
|
18
|
+
- bug/fix/error -> `"bug"`
|
|
19
|
+
- task/done/complete/shipped/implemented -> `"task"`
|
|
20
|
+
- decision/chose/decided/approach -> `"decision"`
|
|
21
|
+
- config/env/secret/deploy -> `"config"`
|
|
22
|
+
- otherwise -> `"note"`
|
|
23
|
+
|
|
24
|
+
Confirm to the user: title, type, why, outcome, and project.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# context-resume
|
|
2
|
+
|
|
3
|
+
Resume project memory and ContextGraph from context-mcp before starting any work.
|
|
4
|
+
|
|
5
|
+
Call the `context` MCP tool with `action: "resume"`, infer `project` from the current working directory name, and pass `rootPath` as the absolute path to the git repo root.
|
|
6
|
+
|
|
7
|
+
This loads recent decisions, bugs, notes, active plans, and ContextGraph status. If `codegraph.built` is false, immediately call `codegraph_build` on the project path.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# graph-build
|
|
2
|
+
|
|
3
|
+
Build the ContextGraph (AST knowledge graph) for the current project.
|
|
4
|
+
|
|
5
|
+
Call `codegraph_build` with the current working directory as the path (or a path provided by the user).
|
|
6
|
+
|
|
7
|
+
After the build completes, report total nodes, edges, and communities. Once built, use `codegraph_query` to answer structural questions about the codebase instead of reading files directly.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# save-context
|
|
2
|
+
|
|
3
|
+
Save a note, decision, bug, or task to context-mcp project memory.
|
|
4
|
+
|
|
5
|
+
Call the `context` MCP tool with `action: "save"`. Infer `project` from the current working directory name. Auto-detect `type` from the user's description:
|
|
6
|
+
- bug/fix/error → `"bug"`
|
|
7
|
+
- task/done/complete/shipped → `"task"`
|
|
8
|
+
- decision/chose/decided → `"decision"`
|
|
9
|
+
- config/env/deploy → `"config"`
|
|
10
|
+
- otherwise → `"note"`
|
|
11
|
+
|
|
12
|
+
Fill in `title` (up to 120 chars), `why`, `outcome`, and `files`. Confirm back to the user what was saved.
|
|
@@ -29,13 +29,23 @@ Returns: `recentEntries`, `activePlans`, `codegraph { built, nodes, edges }`.
|
|
|
29
29
|
|
|
30
30
|
## 3. CodeGraph
|
|
31
31
|
|
|
32
|
-
Build once: `codegraph_build(path)` — then query forever.
|
|
33
|
-
|
|
32
|
+
Build once: `codegraph_build(path)` — auto-generates visualizations, then query forever.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
codegraph_arch(path) → module map (files, exports, imports)
|
|
36
|
+
codegraph_query(path, question?, node?) → find symbol or answer structural question
|
|
37
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
38
|
+
codegraph_report(path) → god nodes, clusters, structural analysis
|
|
39
|
+
codegraph_affected(path, node, depth?) → blast radius — what breaks if X changes?
|
|
40
|
+
codegraph_html(path, formats?) → regenerate visualizations on demand
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Use `codegraph_arch` for structural questions. Read files for bugs/logic.
|
|
34
44
|
|
|
35
45
|
## Rules
|
|
36
46
|
|
|
37
47
|
1. `context.resume` first — every conversation
|
|
38
48
|
2. Always pass `project`
|
|
39
49
|
3. `search` before asking the user about past work
|
|
40
|
-
4. `
|
|
50
|
+
4. `codegraph_arch` before reading files
|
|
41
51
|
5. Files only for bugs and logic
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Cursor postToolUse hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* Input (stdin JSON): { hook_event_name: "postToolUse", tool_name,
|
|
7
|
+
* tool_input: { command }, tool_response: { exit_code, stdout, stderr }, cwd }
|
|
8
|
+
*
|
|
9
|
+
* Saves failed shell commands to context-mcp so the next session can see
|
|
10
|
+
* what broke. Exits silently when the command succeeded or exit code is unknown.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { spawnSync } from 'node:child_process';
|
|
14
|
+
|
|
15
|
+
process.stdin.resume();
|
|
16
|
+
process.stdin.setEncoding('utf8');
|
|
17
|
+
|
|
18
|
+
let input = '';
|
|
19
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
20
|
+
process.stdin.on('end', () => {
|
|
21
|
+
let event = {};
|
|
22
|
+
try {
|
|
23
|
+
event = input.trim() ? JSON.parse(input) : {};
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const toolInput = event.tool_input || {};
|
|
29
|
+
const toolResult = typeof event.tool_response === 'object' && event.tool_response !== null
|
|
30
|
+
? event.tool_response
|
|
31
|
+
: {};
|
|
32
|
+
const command = toolInput.command || toolInput.cmd || '';
|
|
33
|
+
const exitCode = toolResult.exit_code ?? toolResult.exitCode ?? toolResult.code
|
|
34
|
+
?? event.exit_code ?? event.exitCode;
|
|
35
|
+
|
|
36
|
+
if (!command || exitCode === undefined || Number(exitCode) === 0) return;
|
|
37
|
+
|
|
38
|
+
const output = String(
|
|
39
|
+
toolResult.stderr || toolResult.stdout || toolResult.output || event.tool_output || '',
|
|
40
|
+
).trim();
|
|
41
|
+
|
|
42
|
+
const content = [
|
|
43
|
+
`Command: ${command}`,
|
|
44
|
+
`Exit code: ${exitCode}`,
|
|
45
|
+
output ? `Output:\n${output.slice(0, 4000)}` : null,
|
|
46
|
+
].filter(Boolean).join('\n\n');
|
|
47
|
+
|
|
48
|
+
spawnSync('ctx', [
|
|
49
|
+
'save',
|
|
50
|
+
'--project', (event.cwd || process.cwd()).split(/[\\/]/).pop() || 'default',
|
|
51
|
+
'--type', 'bug',
|
|
52
|
+
'--title', `Failed shell command: ${command.slice(0, 80)}`,
|
|
53
|
+
'--content', content,
|
|
54
|
+
], { encoding: 'utf8', shell: true, stdio: 'ignore' });
|
|
55
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Context-MCP — Gemini CLI Usage Guide
|
|
2
|
+
|
|
3
|
+
Persistent memory + codebase knowledge graph.
|
|
4
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Start of Every Conversation (MANDATORY)
|
|
9
|
+
|
|
10
|
+
Call `context` MCP tool: `action:"resume"`, `project:"<project>"` before anything else.
|
|
11
|
+
|
|
12
|
+
Returns: `recentEntries`, `activePlans`, `codegraph`, `stats.totalEntries`.
|
|
13
|
+
|
|
14
|
+
- `codegraph.built: true` → use graph tools before reading files
|
|
15
|
+
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
16
|
+
- `stats.totalEntries ≥ 20` → write compaction summary FIRST (see Rule 4)
|
|
17
|
+
- `activePlans` non-empty → read them before starting new work
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 2. Save Triggers (MANDATORY)
|
|
22
|
+
|
|
23
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
24
|
+
|
|
25
|
+
| Trigger | Required fields |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Task / fix / feature complete | title, why, outcome, files[] |
|
|
28
|
+
| Decision made | title, why, outcome |
|
|
29
|
+
| Discovery / constraint / gotcha | title, content |
|
|
30
|
+
| Config / env / deploy info | title, content |
|
|
31
|
+
| Graph build complete | title, content (nodes/edges count) |
|
|
32
|
+
| User says "save this" | title, content |
|
|
33
|
+
| "compact now" / "compress memory" | `type:"compaction"`, full session summary |
|
|
34
|
+
|
|
35
|
+
**Do NOT save:** routine reads, search results, explanations of existing code.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 3. Plans (MANDATORY for multi-file work)
|
|
40
|
+
|
|
41
|
+
**Create a plan when:** editing 2+ files, multi-step implementation, refactor, multi-file bug fix.
|
|
42
|
+
|
|
43
|
+
1. Call `plan.save` with name, content, project before starting
|
|
44
|
+
2. Call `plan.update status:"done"` when complete — deletes the plan
|
|
45
|
+
|
|
46
|
+
Check `activePlans` on resume — don't create duplicates.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 4. Auto-Summary at ≥ 20 Entries (MANDATORY)
|
|
51
|
+
|
|
52
|
+
When `totalEntries ≥ 20`, call `context.save` BEFORE the user's task:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
type: "compaction" title: "Session summary — <YYYY-MM-DD>"
|
|
56
|
+
content: "<what was built, decided, broke, current state>"
|
|
57
|
+
project: "<project>"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 5. Search Before Asking
|
|
63
|
+
|
|
64
|
+
Call `search` before asking user to re-explain past work.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## 6. ContextGraph Tools
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
codegraph_build(path) → build AST graph + auto-generate all visualizations
|
|
72
|
+
codegraph_arch(path, limit?) → module map: files, exports, imports
|
|
73
|
+
codegraph_query(path, question?, node?) → find symbol or answer structural question
|
|
74
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
75
|
+
codegraph_report(path) → structural analysis
|
|
76
|
+
codegraph_affected(path, node, depth?) → blast radius BFS — what breaks if X changes?
|
|
77
|
+
codegraph_html(path, formats?) → regenerate visualizations on demand
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Use `codegraph_arch` first. Never read files for structure questions.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 7. Rules
|
|
85
|
+
|
|
86
|
+
1. `context.resume` first — before any tool or response
|
|
87
|
+
2. Always pass `project`
|
|
88
|
+
3. Save on task complete — `why` + `outcome` + `files`
|
|
89
|
+
4. Compaction at ≥ 20 entries — before starting task
|
|
90
|
+
5. Plan before multi-file work — `status:"done"` deletes it
|
|
91
|
+
6. Search before asking about past work
|
|
92
|
+
7. Graph tools before files
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Invoked via: /context-resume [project]
|
|
2
|
+
description = "Resume project memory + ContextGraph from context-mcp"
|
|
3
|
+
|
|
4
|
+
prompt = """
|
|
5
|
+
Call the `context` MCP tool with `action: "resume"`, `project: "{{args}}"` (if no argument given, infer the project name from the current working directory name), and `rootPath: "<absolute path to the project root / git repo root>"`.
|
|
6
|
+
|
|
7
|
+
Both `project` and `rootPath` are required: `project` names the memory bucket, `rootPath` enables exact graph lookup and file sandboxing.
|
|
8
|
+
|
|
9
|
+
This loads:
|
|
10
|
+
- Recent decisions, bugs, and notes from past sessions
|
|
11
|
+
- Active plans
|
|
12
|
+
- ContextGraph status (built or not)
|
|
13
|
+
|
|
14
|
+
If `codegraph.built` is false in the response, immediately call `codegraph_build` on the project path before proceeding.
|
|
15
|
+
"""
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Invoked via: /graph-build [path]
|
|
2
|
+
description = "Build the ContextGraph (AST knowledge graph) for a project"
|
|
3
|
+
|
|
4
|
+
prompt = """
|
|
5
|
+
Call `codegraph_build` with the path `{{args}}`.
|
|
6
|
+
|
|
7
|
+
If no argument is given, use the current working directory.
|
|
8
|
+
|
|
9
|
+
This builds the ContextGraph for the project by parsing source files into an AST
|
|
10
|
+
knowledge graph. Once built, use `codegraph_query` to answer structural questions
|
|
11
|
+
about the codebase before reading files directly.
|
|
12
|
+
|
|
13
|
+
After the build completes, report total nodes, edges, and communities.
|
|
14
|
+
"""
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Invoked via: /save-context <what to remember>
|
|
2
|
+
description = "Save a note/decision/bug to context-mcp project memory"
|
|
3
|
+
|
|
4
|
+
prompt = """
|
|
5
|
+
Call the `context` MCP tool with `action: "save"` to store a note for the
|
|
6
|
+
current project.
|
|
7
|
+
|
|
8
|
+
Parse the following arguments to determine the fields: {{args}}
|
|
9
|
+
|
|
10
|
+
- `project`: infer from current working directory name if not specified.
|
|
11
|
+
- `title`: first sentence or phrase, up to 120 chars.
|
|
12
|
+
- `why`: why it mattered, what problem it solved, or what constraint it revealed.
|
|
13
|
+
- `outcome`: what changed, what was verified, what shipped, and which files were affected.
|
|
14
|
+
- `files`: list of files changed, required for task/bug types.
|
|
15
|
+
- `content`: full argument text.
|
|
16
|
+
- `type`: auto-detect:
|
|
17
|
+
- bug/fix/error -> `"bug"`
|
|
18
|
+
- task/done/complete/shipped/implemented -> `"task"`
|
|
19
|
+
- decision/chose/decided/approach -> `"decision"`
|
|
20
|
+
- config/env/secret/deploy -> `"config"`
|
|
21
|
+
- otherwise -> `"note"`
|
|
22
|
+
|
|
23
|
+
Confirm to the user: title, type, why, outcome, and project.
|
|
24
|
+
"""
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gemini CLI AfterTool hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* Input (stdin JSON): { session_id, cwd, hook_event_name: "AfterTool",
|
|
7
|
+
* tool_name, tool_input: { command }, tool_response }
|
|
8
|
+
*
|
|
9
|
+
* Saves failed run_shell_command invocations to context-mcp so the next
|
|
10
|
+
* session can see what broke. Exits silently when the command succeeded
|
|
11
|
+
* or the exit code cannot be determined.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { spawnSync } from 'node:child_process';
|
|
15
|
+
|
|
16
|
+
process.stdin.resume();
|
|
17
|
+
process.stdin.setEncoding('utf8');
|
|
18
|
+
|
|
19
|
+
let input = '';
|
|
20
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
21
|
+
process.stdin.on('end', () => {
|
|
22
|
+
let event = {};
|
|
23
|
+
try {
|
|
24
|
+
event = input.trim() ? JSON.parse(input) : {};
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const toolInput = event.tool_input || {};
|
|
30
|
+
const toolResult = typeof event.tool_response === 'object' && event.tool_response !== null
|
|
31
|
+
? event.tool_response
|
|
32
|
+
: {};
|
|
33
|
+
const command = toolInput.command || '';
|
|
34
|
+
const exitCode = toolResult.exit_code ?? toolResult.exitCode ?? toolResult.code;
|
|
35
|
+
|
|
36
|
+
if (!command || exitCode === undefined || Number(exitCode) === 0) return;
|
|
37
|
+
|
|
38
|
+
const output = String(
|
|
39
|
+
toolResult.stderr || toolResult.stdout || toolResult.output || '',
|
|
40
|
+
).trim();
|
|
41
|
+
|
|
42
|
+
const content = [
|
|
43
|
+
`Command: ${command}`,
|
|
44
|
+
`Exit code: ${exitCode}`,
|
|
45
|
+
output ? `Output:\n${output.slice(0, 4000)}` : null,
|
|
46
|
+
].filter(Boolean).join('\n\n');
|
|
47
|
+
|
|
48
|
+
spawnSync('ctx', [
|
|
49
|
+
'save',
|
|
50
|
+
'--project', (event.cwd || process.cwd()).split(/[\\/]/).pop() || 'default',
|
|
51
|
+
'--type', 'bug',
|
|
52
|
+
'--title', `Failed shell command: ${command.slice(0, 80)}`,
|
|
53
|
+
'--content', content,
|
|
54
|
+
], {
|
|
55
|
+
encoding: 'utf8',
|
|
56
|
+
shell: true,
|
|
57
|
+
stdio: 'ignore',
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Gemini CLI BeforeTool hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* Input (stdin JSON): { session_id, cwd, hook_event_name: "BeforeTool",
|
|
7
|
+
* tool_name, tool_input }
|
|
8
|
+
*
|
|
9
|
+
* This hook is intentionally conservative. It validates the hook pipeline
|
|
10
|
+
* runs before run_shell_command but never blocks (exit 0 with no decision =
|
|
11
|
+
* allow). Keep policy decisions in GEMINI.md or a dedicated security hook
|
|
12
|
+
* if your team needs blocking (print {"decision":"deny","reason":"..."}).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
process.stdin.resume();
|
|
16
|
+
process.stdin.setEncoding('utf8');
|
|
17
|
+
|
|
18
|
+
let input = '';
|
|
19
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
20
|
+
process.stdin.on('end', () => {
|
|
21
|
+
try {
|
|
22
|
+
if (input.trim()) JSON.parse(input);
|
|
23
|
+
} catch {
|
|
24
|
+
// Do not interrupt the user's command because hook input changed.
|
|
25
|
+
}
|
|
26
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
mode: agent
|
|
3
|
+
description: "Resume project memory + ContextGraph from context-mcp"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Call the `context` MCP tool with `action: "resume"`, infer `project` from the current working directory name, and pass `rootPath` as the absolute path to the git repo root.
|
|
7
|
+
|
|
8
|
+
Both `project` and `rootPath` are required: `project` names the memory bucket, `rootPath` enables exact graph lookup and file sandboxing.
|
|
9
|
+
|
|
10
|
+
This loads:
|
|
11
|
+
- Recent decisions, bugs, and notes from past sessions
|
|
12
|
+
- Active plans
|
|
13
|
+
- ContextGraph status (built or not)
|
|
14
|
+
|
|
15
|
+
If `codegraph.built` is false in the response, immediately call `codegraph_build` on the project path before proceeding.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
mode: agent
|
|
3
|
+
description: "Build the ContextGraph (AST knowledge graph) for the current project"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Call `codegraph_build` with the current working directory as the path (or a path provided by the user).
|
|
7
|
+
|
|
8
|
+
This builds the ContextGraph for the project by parsing source files into an AST knowledge graph. Once built, use `codegraph_query` to answer structural questions about the codebase before reading files directly.
|
|
9
|
+
|
|
10
|
+
After the build completes, report total nodes, edges, and communities.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
---
|
|
2
|
+
mode: agent
|
|
3
|
+
description: "Save a note/decision/bug to context-mcp project memory"
|
|
4
|
+
argument-hint: "What to remember (e.g. 'fixed auth bug in src/auth.js')"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Call the `context` MCP tool with `action: "save"` to store a note for the current project.
|
|
8
|
+
|
|
9
|
+
Infer `project` from the current working directory name. Auto-detect `type`:
|
|
10
|
+
- bug/fix/error → `"bug"`
|
|
11
|
+
- task/done/complete/shipped/implemented → `"task"`
|
|
12
|
+
- decision/chose/decided/approach → `"decision"`
|
|
13
|
+
- config/env/secret/deploy → `"config"`
|
|
14
|
+
- otherwise → `"note"`
|
|
15
|
+
|
|
16
|
+
Fill in `title` (up to 120 chars), `why`, `outcome`, and `files`. Confirm back to the user: title, type, why, outcome, and project.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* VS Code Copilot PostToolUse hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* Input (stdin JSON): { hook_event_name: "PostToolUse", tool_name,
|
|
7
|
+
* tool_input: { command }, tool_output: { exit_code, stdout, stderr }, cwd }
|
|
8
|
+
*
|
|
9
|
+
* Saves failed shell commands to context-mcp so the next session can see
|
|
10
|
+
* what broke. Exits silently when the command succeeded or exit code is unknown.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { spawnSync } from 'node:child_process';
|
|
14
|
+
|
|
15
|
+
process.stdin.resume();
|
|
16
|
+
process.stdin.setEncoding('utf8');
|
|
17
|
+
|
|
18
|
+
let input = '';
|
|
19
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
20
|
+
process.stdin.on('end', () => {
|
|
21
|
+
let event = {};
|
|
22
|
+
try {
|
|
23
|
+
event = input.trim() ? JSON.parse(input) : {};
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const toolInput = event.tool_input || {};
|
|
29
|
+
// VS Code uses tool_output (not tool_response) for the result object
|
|
30
|
+
const toolResult = typeof event.tool_output === 'object' && event.tool_output !== null
|
|
31
|
+
? event.tool_output
|
|
32
|
+
: typeof event.tool_response === 'object' && event.tool_response !== null
|
|
33
|
+
? event.tool_response
|
|
34
|
+
: {};
|
|
35
|
+
const command = toolInput.command || toolInput.cmd || '';
|
|
36
|
+
const exitCode = toolResult.exit_code ?? toolResult.exitCode ?? toolResult.code
|
|
37
|
+
?? event.exit_code ?? event.exitCode;
|
|
38
|
+
|
|
39
|
+
if (!command || exitCode === undefined || Number(exitCode) === 0) return;
|
|
40
|
+
|
|
41
|
+
const output = String(
|
|
42
|
+
toolResult.stderr || toolResult.stdout || toolResult.output || '',
|
|
43
|
+
).trim();
|
|
44
|
+
|
|
45
|
+
const content = [
|
|
46
|
+
`Command: ${command}`,
|
|
47
|
+
`Exit code: ${exitCode}`,
|
|
48
|
+
output ? `Output:\n${output.slice(0, 4000)}` : null,
|
|
49
|
+
].filter(Boolean).join('\n\n');
|
|
50
|
+
|
|
51
|
+
spawnSync('ctx', [
|
|
52
|
+
'save',
|
|
53
|
+
'--project', (event.cwd || process.cwd()).split(/[\\/]/).pop() || 'default',
|
|
54
|
+
'--type', 'bug',
|
|
55
|
+
'--title', `Failed shell command: ${command.slice(0, 80)}`,
|
|
56
|
+
'--content', content,
|
|
57
|
+
], { encoding: 'utf8', shell: true, stdio: 'ignore' });
|
|
58
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Windsurf post_run_command hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* Input (stdin JSON): { hook_event_name: "post_run_command", tool_name,
|
|
7
|
+
* tool_input: { command }, tool_response: { exit_code, stdout, stderr }, cwd }
|
|
8
|
+
*
|
|
9
|
+
* Saves failed shell commands to context-mcp so the next session can see
|
|
10
|
+
* what broke. Exits silently when the command succeeded or exit code is unknown.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { spawnSync } from 'node:child_process';
|
|
14
|
+
|
|
15
|
+
process.stdin.resume();
|
|
16
|
+
process.stdin.setEncoding('utf8');
|
|
17
|
+
|
|
18
|
+
let input = '';
|
|
19
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
20
|
+
process.stdin.on('end', () => {
|
|
21
|
+
let event = {};
|
|
22
|
+
try {
|
|
23
|
+
event = input.trim() ? JSON.parse(input) : {};
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const toolInput = event.tool_input || {};
|
|
29
|
+
const toolResult = typeof event.tool_response === 'object' && event.tool_response !== null
|
|
30
|
+
? event.tool_response
|
|
31
|
+
: typeof event.tool_output === 'object' && event.tool_output !== null
|
|
32
|
+
? event.tool_output
|
|
33
|
+
: {};
|
|
34
|
+
const command = toolInput.command || toolInput.cmd || event.command || '';
|
|
35
|
+
const exitCode = toolResult.exit_code ?? toolResult.exitCode ?? toolResult.code
|
|
36
|
+
?? event.exit_code ?? event.exitCode;
|
|
37
|
+
|
|
38
|
+
if (!command || exitCode === undefined || Number(exitCode) === 0) return;
|
|
39
|
+
|
|
40
|
+
const output = String(
|
|
41
|
+
toolResult.stderr || toolResult.stdout || toolResult.output || '',
|
|
42
|
+
).trim();
|
|
43
|
+
|
|
44
|
+
const content = [
|
|
45
|
+
`Command: ${command}`,
|
|
46
|
+
`Exit code: ${exitCode}`,
|
|
47
|
+
output ? `Output:\n${output.slice(0, 4000)}` : null,
|
|
48
|
+
].filter(Boolean).join('\n\n');
|
|
49
|
+
|
|
50
|
+
spawnSync('ctx', [
|
|
51
|
+
'save',
|
|
52
|
+
'--project', (event.cwd || process.cwd()).split(/[\\/]/).pop() || 'default',
|
|
53
|
+
'--type', 'bug',
|
|
54
|
+
'--title', `Failed shell command: ${command.slice(0, 80)}`,
|
|
55
|
+
'--content', content,
|
|
56
|
+
], { encoding: 'utf8', shell: true, stdio: 'ignore' });
|
|
57
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Context-MCP — Windsurf Usage Guide
|
|
2
|
+
|
|
3
|
+
Persistent memory + codebase knowledge graph.
|
|
4
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 1. Start of Every Conversation (MANDATORY)
|
|
9
|
+
|
|
10
|
+
Call `context` tool: `action:"resume"`, `project:"<name>"` before anything else.
|
|
11
|
+
|
|
12
|
+
Returns: `recentEntries`, `activePlans`, `codegraph`, `stats.totalEntries`.
|
|
13
|
+
|
|
14
|
+
- `codegraph.built: false` → run `codegraph_build(path)` first
|
|
15
|
+
- `stats.totalEntries ≥ 20` → write compaction summary first (see Rule 4)
|
|
16
|
+
- `activePlans` non-empty → read before starting new work
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 2. Save Triggers (MANDATORY)
|
|
21
|
+
|
|
22
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
23
|
+
|
|
24
|
+
| Trigger | Required fields |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Task / fix / feature complete | title, why, outcome, files[] |
|
|
27
|
+
| Decision made | title, why, outcome |
|
|
28
|
+
| Discovery / constraint / gotcha | title, content |
|
|
29
|
+
| Config / env / deploy info | title, content |
|
|
30
|
+
| Graph build complete | title, content (nodes/edges count) |
|
|
31
|
+
| User says "save this" | title, content |
|
|
32
|
+
| "compact now" / "compress memory" | `type:"compaction"`, full session summary |
|
|
33
|
+
|
|
34
|
+
**Do NOT save:** routine reads, search results, explanations of existing code.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 3. Plans
|
|
39
|
+
|
|
40
|
+
Call `plan.save` before any work touching 2+ files or multiple steps.
|
|
41
|
+
Call `plan.update status:"done"` when complete — deletes the plan.
|
|
42
|
+
Check `activePlans` on resume — don't duplicate.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 4. Auto-Summary at ≥ 20 Entries (MANDATORY)
|
|
47
|
+
|
|
48
|
+
When `totalEntries ≥ 20`, call `context.save` BEFORE the user's task:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
type: "compaction" title: "Session summary — <date>"
|
|
52
|
+
content: "<what was built, decided, broke, current state>"
|
|
53
|
+
project: "<project>"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 5. Search Before Asking
|
|
59
|
+
|
|
60
|
+
Call `search` before asking user to re-explain past work.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 6. ContextGraph Tools
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
codegraph_arch(path) → module map (files, exports, imports)
|
|
68
|
+
codegraph_query(path, ...) → find specific function/class/file
|
|
69
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
70
|
+
codegraph_report(path) → structural analysis
|
|
71
|
+
codegraph_affected(path, node, depth?) → blast radius — what breaks if X changes?
|
|
72
|
+
codegraph_html(path, formats?) → regenerate visualizations (auto on every build)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Use `codegraph_arch` first. Never read files for structure questions.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 7. Rules
|
|
80
|
+
|
|
81
|
+
1. `context.resume` first — every conversation
|
|
82
|
+
2. Save on task complete — `why` + `outcome` + `files`
|
|
83
|
+
3. Compaction at ≥ 20 entries — before starting task
|
|
84
|
+
4. Plan for 2+ file changes — `status:"done"` deletes it
|
|
85
|
+
5. Search before asking about past work
|
|
86
|
+
6. Graph tools before files
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# context-resume
|
|
2
|
+
|
|
3
|
+
Resume project memory and ContextGraph from context-mcp before starting any work.
|
|
4
|
+
|
|
5
|
+
1. Call the `context` MCP tool with `action: "resume"`, infer `project` from the current working directory name, and pass `rootPath` as the absolute path to the git repo root.
|
|
6
|
+
|
|
7
|
+
2. Read the returned `recentEntries` (last 15 entries), `activePlans`, and `codegraph` status.
|
|
8
|
+
|
|
9
|
+
3. If `codegraph.built` is false, call `codegraph_build` on the project path immediately before proceeding.
|
|
10
|
+
|
|
11
|
+
4. If `stats.totalEntries` is 20 or more, save a compaction summary before starting any new work.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# graph-build
|
|
2
|
+
|
|
3
|
+
Build the ContextGraph (AST knowledge graph) for the current project.
|
|
4
|
+
|
|
5
|
+
1. Call `codegraph_build` with the current working directory as the path (or a path provided by the user).
|
|
6
|
+
|
|
7
|
+
2. Wait for the build to complete.
|
|
8
|
+
|
|
9
|
+
3. Report total nodes, edges, and communities found.
|
|
10
|
+
|
|
11
|
+
4. Once built, use `codegraph_query` to answer structural questions about the codebase instead of reading files directly.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# save-context
|
|
2
|
+
|
|
3
|
+
Save a note, decision, bug, or task to context-mcp project memory.
|
|
4
|
+
|
|
5
|
+
1. Call the `context` MCP tool with `action: "save"`.
|
|
6
|
+
|
|
7
|
+
2. Infer `project` from the current working directory name.
|
|
8
|
+
|
|
9
|
+
3. Auto-detect `type` from the user's description:
|
|
10
|
+
- bug/fix/error → `"bug"`
|
|
11
|
+
- task/done/complete/shipped/implemented → `"task"`
|
|
12
|
+
- decision/chose/decided/approach → `"decision"`
|
|
13
|
+
- config/env/secret/deploy → `"config"`
|
|
14
|
+
- otherwise → `"note"`
|
|
15
|
+
|
|
16
|
+
4. Fill in `title` (up to 120 chars), `why`, `outcome`, and `files`.
|
|
17
|
+
|
|
18
|
+
5. Confirm back to the user: title, type, why, outcome, and project name.
|