context-mcp-server 1.1.0 → 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 +56 -0
- package/codegraph/graph/symbol_resolution.py +112 -0
- package/codegraph/report.py +53 -0
- package/codegraph/server.py +99 -10
- package/codegraph/tree_html.py +241 -0
- package/package.json +2 -2
- package/pyproject.toml +4 -1
- package/src/cli.js +277 -86
- 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.md → claude/CLAUDE.md} +3 -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/{skills → claude/skills}/SKILL.md +3 -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.md → gemini/GEMINI.md} +3 -1
- 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-rules.md → windsurf/windsurf-rules.md} +6 -4
- 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 +37 -0
- package/uv.lock +1100 -3
- package/src/templates/AGENTS.md +0 -90
- package/src/templates/commands/graph-build.md +0 -5
- package/src/templates/commands/save-context.md +0 -12
- /package/src/templates/{commands → claude/commands}/context-resume.md +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# context-resume
|
|
2
|
+
|
|
3
|
+
Resume context for the current project from persistent memory.
|
|
4
|
+
|
|
5
|
+
## Steps
|
|
6
|
+
|
|
7
|
+
1. Call the `context` MCP tool with `action: "resume"` and `project: "<current project name>"`.
|
|
8
|
+
2. Read `recentEntries` — the last saved notes, decisions, and bug records.
|
|
9
|
+
3. Read `activePlans` — any in-progress multi-step plans.
|
|
10
|
+
4. Check `codegraph.built`:
|
|
11
|
+
- `true` → graph tools are available; use `codegraph_arch` before reading files
|
|
12
|
+
- `false` → run `codegraph_build` when structural questions arise
|
|
13
|
+
5. If `stats.totalEntries ≥ 20`, save a compaction summary before starting work:
|
|
14
|
+
```
|
|
15
|
+
context(action:"save", type:"compaction",
|
|
16
|
+
title:"Session summary — YYYY-MM-DD",
|
|
17
|
+
content:"<full summary of session>",
|
|
18
|
+
project:"<project>")
|
|
19
|
+
```
|
|
20
|
+
6. Summarize what was found: recent work, open plans, graph status.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# graph-build
|
|
2
|
+
|
|
3
|
+
Build or refresh the codebase knowledge graph for the current project.
|
|
4
|
+
|
|
5
|
+
## Steps
|
|
6
|
+
|
|
7
|
+
1. Identify the project root — use the workspace path or ask if ambiguous.
|
|
8
|
+
2. Call `codegraph_build` with `path: "<absolute project root>"`.
|
|
9
|
+
- This scans all source files using AST extraction (16+ languages).
|
|
10
|
+
- Incremental: only changed files are re-processed.
|
|
11
|
+
3. When complete, call `context` with `action:"save"`:
|
|
12
|
+
```
|
|
13
|
+
type: "note"
|
|
14
|
+
title: "CodeGraph built — <project>"
|
|
15
|
+
content: "nodes: N | edges: E | communities: C | time: Xms"
|
|
16
|
+
project: "<project>"
|
|
17
|
+
tags: ["codegraph"]
|
|
18
|
+
```
|
|
19
|
+
4. Report: node count, edge count, communities, any warnings.
|
|
20
|
+
5. Suggest next steps:
|
|
21
|
+
- `codegraph_arch` — module map
|
|
22
|
+
- `codegraph_report` — god nodes, surprising connections
|
|
23
|
+
- `codegraph_query` — ask structural questions
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# save-context
|
|
2
|
+
|
|
3
|
+
Save the current work state to persistent memory.
|
|
4
|
+
|
|
5
|
+
## Steps
|
|
6
|
+
|
|
7
|
+
1. Ask (or infer from context):
|
|
8
|
+
- **Title** — one-line summary of what was done
|
|
9
|
+
- **Why** — motivation or trigger
|
|
10
|
+
- **Outcome** — result, decision, or current state
|
|
11
|
+
- **Files** — list of files touched (if applicable)
|
|
12
|
+
2. Call `context` MCP tool with `action: "save"`:
|
|
13
|
+
```
|
|
14
|
+
type: "note"
|
|
15
|
+
title: "<title>"
|
|
16
|
+
why: "<why>"
|
|
17
|
+
outcome: "<outcome>"
|
|
18
|
+
files: ["<file1>", "<file2>"]
|
|
19
|
+
project: "<project>"
|
|
20
|
+
```
|
|
21
|
+
3. Confirm: report the saved entry ID and title.
|
|
22
|
+
|
|
23
|
+
## When to use
|
|
24
|
+
|
|
25
|
+
- After completing a task, fix, or feature
|
|
26
|
+
- After making a significant decision
|
|
27
|
+
- When discovering a constraint or gotcha
|
|
28
|
+
- When the user says "save this" or "remember this"
|
|
29
|
+
- After a graph build (use `graph-build` workflow instead)
|
|
@@ -112,6 +112,8 @@ codegraph_arch(path, limit?) → module map: every file, its exports
|
|
|
112
112
|
codegraph_query(path, question?, node?) → find function/class/file or answer structural question
|
|
113
113
|
codegraph_nodes(path, type) → list all nodes of a type
|
|
114
114
|
codegraph_report(path) → god nodes, clusters, structural analysis
|
|
115
|
+
codegraph_affected(path, node, depth?) → blast radius BFS — what breaks if X changes?
|
|
116
|
+
codegraph_html(path, formats?) → regenerate visualizations (auto-runs on every build)
|
|
115
117
|
```
|
|
116
118
|
|
|
117
119
|
| Question | Tool |
|
|
@@ -121,6 +123,7 @@ codegraph_report(path) → god nodes, clusters, structural ana
|
|
|
121
123
|
| What does module Y depend on? | `codegraph_query question:"what does Y import?"` |
|
|
122
124
|
| What are all the classes? | `codegraph_nodes type:"class"` |
|
|
123
125
|
| Most connected files? | `codegraph_report` |
|
|
126
|
+
| What breaks if I change X? | `codegraph_affected node:"X"` |
|
|
124
127
|
|
|
125
128
|
**Never read files for structure questions — use graph tools first.**
|
|
126
129
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Call `codegraph_build` with the path `$ARGUMENTS`.
|
|
2
|
+
|
|
3
|
+
If no argument is given, use the current working directory.
|
|
4
|
+
|
|
5
|
+
This builds the ContextGraph for the project by parsing source files into an AST
|
|
6
|
+
knowledge graph. Once built, use `codegraph_query` to answer structural questions
|
|
7
|
+
about the codebase before reading files directly.
|
|
8
|
+
|
|
9
|
+
After the build completes, report total nodes, edges, and communities.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Call the `context` MCP tool with `action: "save"` to store a note for the
|
|
2
|
+
current project.
|
|
3
|
+
|
|
4
|
+
Parse `$ARGUMENTS` to determine:
|
|
5
|
+
|
|
6
|
+
- `project`: infer from current working directory name if not specified.
|
|
7
|
+
- `title`: first sentence or phrase, up to 120 chars.
|
|
8
|
+
- `why`: why it mattered, what problem it solved, or what constraint it revealed.
|
|
9
|
+
- `outcome`: what changed, what was verified, what shipped, and which files were affected.
|
|
10
|
+
- `files`: list of files changed, required for task/bug types.
|
|
11
|
+
- `content`: full argument text.
|
|
12
|
+
- `type`: auto-detect:
|
|
13
|
+
- bug/fix/error -> `"bug"`
|
|
14
|
+
- task/done/complete/shipped/implemented -> `"task"`
|
|
15
|
+
- decision/chose/decided/approach -> `"decision"`
|
|
16
|
+
- config/env/secret/deploy -> `"config"`
|
|
17
|
+
- otherwise -> `"note"`
|
|
18
|
+
|
|
19
|
+
Confirm to the user: title, type, why, outcome, and project.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Claude Code PostToolUse hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* Input (stdin JSON): { session_id, cwd, hook_event_name: "PostToolUse",
|
|
7
|
+
* tool_name, tool_input: { command }, tool_response | tool_output }
|
|
8
|
+
*
|
|
9
|
+
* Saves failed Bash commands to context-mcp so the next session can see
|
|
10
|
+
* what broke. Exits silently when the command succeeded or the exit code
|
|
11
|
+
* 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 || 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
|
+
], {
|
|
55
|
+
encoding: 'utf8',
|
|
56
|
+
shell: true,
|
|
57
|
+
stdio: 'ignore',
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Claude Code PreToolUse hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* Input (stdin JSON): { session_id, cwd, hook_event_name: "PreToolUse",
|
|
7
|
+
* tool_name, tool_input, permission_mode }
|
|
8
|
+
*
|
|
9
|
+
* This hook is intentionally conservative. It validates the hook pipeline
|
|
10
|
+
* runs before Bash commands but never blocks or rewrites them (exit 0 =
|
|
11
|
+
* allow). Keep policy decisions in CLAUDE.md or a dedicated security hook
|
|
12
|
+
* if your team needs command blocking (exit 2 + stderr blocks the call).
|
|
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
|
+
});
|
|
@@ -118,6 +118,8 @@ codegraph_arch(path) → module map: every file, exports, im
|
|
|
118
118
|
codegraph_query(path, question?, node?) → find symbol or answer structural question
|
|
119
119
|
codegraph_nodes(path, type) → list all nodes of a type
|
|
120
120
|
codegraph_report(path) → god nodes, clusters, structural analysis
|
|
121
|
+
codegraph_affected(path, node, depth?) → blast radius BFS — what breaks if X changes?
|
|
122
|
+
codegraph_html(path, formats?) → regenerate visualizations (auto-runs on every build)
|
|
121
123
|
```
|
|
122
124
|
|
|
123
125
|
| Question | Tool |
|
|
@@ -127,6 +129,7 @@ codegraph_report(path) → god nodes, clusters, structural ana
|
|
|
127
129
|
| What does module Y import? | `codegraph_query question:"..."` |
|
|
128
130
|
| List all classes/functions | `codegraph_nodes type:"class"` |
|
|
129
131
|
| Most connected / central files | `codegraph_report` |
|
|
132
|
+
| What breaks if I change X? | `codegraph_affected node:"X"` |
|
|
130
133
|
|
|
131
134
|
---
|
|
132
135
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Context-MCP - Codex CLI Usage Guide
|
|
2
|
+
|
|
3
|
+
Persistent memory + codebase knowledge graph.
|
|
4
|
+
`context.resume` starts every session. `codegraph_query` finds specific symbols.
|
|
5
|
+
Read files only for bugs or implementation logic.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Start of Every Conversation (MANDATORY)
|
|
10
|
+
|
|
11
|
+
Call the `context` MCP tool before any other action:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"action": "resume",
|
|
16
|
+
"project": "<project>",
|
|
17
|
+
"rootPath": "<absolute path to the project root>"
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Returns: `recentEntries`, `activePlans`, `codegraph`, `stats.totalEntries`.
|
|
22
|
+
|
|
23
|
+
- `codegraph.built: true` -> use graph tools before reading files.
|
|
24
|
+
- `codegraph.built: false` -> call `codegraph_build(path)` first.
|
|
25
|
+
- `stats.totalEntries >= 20` -> write a compaction summary first.
|
|
26
|
+
- `activePlans` non-empty -> read them before starting new work.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 2. Save Triggers (MANDATORY)
|
|
31
|
+
|
|
32
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
33
|
+
|
|
34
|
+
| Trigger | Required fields |
|
|
35
|
+
|---|---|
|
|
36
|
+
| Task / fix / feature complete | title, why, outcome, files[] |
|
|
37
|
+
| Decision made | title, why, outcome |
|
|
38
|
+
| Discovery / constraint / gotcha | title, content |
|
|
39
|
+
| Config / env / deploy info | title, content |
|
|
40
|
+
| Graph build complete | title, content with nodes/edges count |
|
|
41
|
+
| User says "save this" | title, content |
|
|
42
|
+
| "compact now" / "compress memory" | `type: "compaction"`, full session summary |
|
|
43
|
+
|
|
44
|
+
Do not save routine reads, search results, or explanations of existing code.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 3. Plans (MANDATORY for multi-file work)
|
|
49
|
+
|
|
50
|
+
Create a plan when editing 2+ files, doing a multi-step implementation, refactor,
|
|
51
|
+
or multi-file bug fix.
|
|
52
|
+
|
|
53
|
+
1. Call `plan.save` with name, content, and project before starting.
|
|
54
|
+
2. Call `plan.update status: "done"` when complete.
|
|
55
|
+
|
|
56
|
+
Check `activePlans` on resume. Do not create duplicates.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 4. Auto-Summary at >= 20 Entries (MANDATORY)
|
|
61
|
+
|
|
62
|
+
When `totalEntries >= 20`, call `context.save` before the user's task:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"type": "compaction",
|
|
67
|
+
"title": "Session summary - <YYYY-MM-DD>",
|
|
68
|
+
"content": "<what was built, decided, broke, current state>",
|
|
69
|
+
"project": "<project>"
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 5. Search Before Asking
|
|
76
|
+
|
|
77
|
+
Call `search` before asking the user to re-explain past work.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 6. ContextGraph Tools
|
|
82
|
+
|
|
83
|
+
```text
|
|
84
|
+
codegraph_build(path) -> build AST graph + auto-generate all visualizations
|
|
85
|
+
codegraph_arch(path, limit?) -> module map: files, exports, imports
|
|
86
|
+
codegraph_query(path, question?, node?) -> find symbol or answer structural question
|
|
87
|
+
codegraph_nodes(path, type) -> list all nodes of a type
|
|
88
|
+
codegraph_report(path) -> structural analysis
|
|
89
|
+
codegraph_affected(path, node, depth?) -> blast radius BFS — what breaks if X changes?
|
|
90
|
+
codegraph_html(path, formats?) -> regenerate visualizations on demand
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Use `codegraph_arch` first. Read files only when you need exact bug or
|
|
94
|
+
implementation details.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 7. Rules
|
|
99
|
+
|
|
100
|
+
1. `context.resume` first, before any tool or response.
|
|
101
|
+
2. Always pass `project`.
|
|
102
|
+
3. Pass `rootPath` whenever the current project root is known.
|
|
103
|
+
4. Save on task complete with why, outcome, and files.
|
|
104
|
+
5. Compact at >= 20 entries before starting the task.
|
|
105
|
+
6. Plan before multi-file work.
|
|
106
|
+
7. Search before asking about past work.
|
|
107
|
+
8. Use graph tools before files.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
|
|
5
|
+
process.stdin.resume();
|
|
6
|
+
process.stdin.setEncoding('utf8');
|
|
7
|
+
|
|
8
|
+
let input = '';
|
|
9
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
10
|
+
process.stdin.on('end', () => {
|
|
11
|
+
let event = {};
|
|
12
|
+
try {
|
|
13
|
+
event = input.trim() ? JSON.parse(input) : {};
|
|
14
|
+
} catch {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const toolInput = event.tool_input || event.toolInput || {};
|
|
19
|
+
const toolResult = event.tool_response || event.toolResponse || event.result || {};
|
|
20
|
+
const command = toolInput.command || toolInput.cmd || event.command || '';
|
|
21
|
+
const exitCode = toolResult.exit_code ?? toolResult.exitCode ?? event.exit_code ?? event.exitCode;
|
|
22
|
+
|
|
23
|
+
if (!command || exitCode === undefined || Number(exitCode) === 0) return;
|
|
24
|
+
|
|
25
|
+
const output = String(
|
|
26
|
+
toolResult.stderr || toolResult.stdout || toolResult.output || event.output || '',
|
|
27
|
+
).trim();
|
|
28
|
+
|
|
29
|
+
const content = [
|
|
30
|
+
`Command: ${command}`,
|
|
31
|
+
`Exit code: ${exitCode}`,
|
|
32
|
+
output ? `Output:\n${output.slice(0, 4000)}` : null,
|
|
33
|
+
].filter(Boolean).join('\n\n');
|
|
34
|
+
|
|
35
|
+
spawnSync('ctx', [
|
|
36
|
+
'save',
|
|
37
|
+
'--project', process.cwd().split(/[\\/]/).pop() || 'default',
|
|
38
|
+
'--type', 'bug',
|
|
39
|
+
'--title', `Failed shell command: ${command.slice(0, 80)}`,
|
|
40
|
+
'--content', content,
|
|
41
|
+
], {
|
|
42
|
+
encoding: 'utf8',
|
|
43
|
+
shell: true,
|
|
44
|
+
stdio: 'ignore',
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Codex PreToolUse hook for context-mcp.
|
|
5
|
+
*
|
|
6
|
+
* This hook is intentionally conservative. It validates that Codex can run the
|
|
7
|
+
* project-local hook pipeline before Bash commands, but it does not block or
|
|
8
|
+
* rewrite commands. Keep policy decisions in AGENTS.md or a dedicated security
|
|
9
|
+
* hook if your team needs command blocking.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
process.stdin.resume();
|
|
13
|
+
process.stdin.setEncoding('utf8');
|
|
14
|
+
|
|
15
|
+
let input = '';
|
|
16
|
+
process.stdin.on('data', chunk => { input += chunk; });
|
|
17
|
+
process.stdin.on('end', () => {
|
|
18
|
+
try {
|
|
19
|
+
if (input.trim()) JSON.parse(input);
|
|
20
|
+
} catch {
|
|
21
|
+
// Do not interrupt the user's command because hook input changed.
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Resume project memory + ContextGraph from context-mcp"
|
|
3
|
+
argument-hint: [project]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Call the `context` MCP tool with `action: "resume"`, `project: "$ARGUMENTS"` (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>"`.
|
|
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,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Build the ContextGraph (AST knowledge graph) for a project"
|
|
3
|
+
argument-hint: [path]
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
Call `codegraph_build` with the path `$ARGUMENTS`.
|
|
7
|
+
|
|
8
|
+
If no argument is given, use the current working directory.
|
|
9
|
+
|
|
10
|
+
This builds the ContextGraph for the project by parsing source files into an AST
|
|
11
|
+
knowledge graph. Once built, use `codegraph_query` to answer structural questions
|
|
12
|
+
about the codebase before reading files directly.
|
|
13
|
+
|
|
14
|
+
After the build completes, report total nodes, edges, and communities.
|
|
@@ -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
|
+
});
|
|
@@ -68,11 +68,13 @@ Call `search` before asking user to re-explain past work.
|
|
|
68
68
|
## 6. ContextGraph Tools
|
|
69
69
|
|
|
70
70
|
```
|
|
71
|
-
codegraph_build(path) → build AST graph
|
|
71
|
+
codegraph_build(path) → build AST graph + auto-generate all visualizations
|
|
72
72
|
codegraph_arch(path, limit?) → module map: files, exports, imports
|
|
73
73
|
codegraph_query(path, question?, node?) → find symbol or answer structural question
|
|
74
74
|
codegraph_nodes(path, type) → list all nodes of a type
|
|
75
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
|
|
76
78
|
```
|
|
77
79
|
|
|
78
80
|
Use `codegraph_arch` first. Never read files for structure questions.
|
|
@@ -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
|
+
"""
|