context-mcp-server 1.0.7 → 1.1.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 +10 -11
- package/codegraph/__pycache__/server.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/query.cpython-313.pyc +0 -0
- package/codegraph/graph/query.py +43 -0
- package/codegraph/server.py +20 -17
- package/package.json +2 -2
- package/pyproject.toml +1 -1
- package/src/cli.js +152 -229
- package/src/db.js +923 -805
- package/src/guard.js +9 -3
- package/src/search.js +73 -9
- package/src/server.js +7 -6
- package/src/templates/AGENTS.md +56 -53
- package/src/templates/CLAUDE.md +89 -61
- package/src/templates/GEMINI.md +56 -53
- package/src/templates/commands/context-resume.md +1 -1
- package/src/templates/commands/save-context.md +6 -3
- package/src/templates/cursor-rules.mdc +3 -3
- package/src/templates/skills/SKILL.md +87 -60
- package/src/templates/windsurf-rules.md +69 -20
- package/src/tools/codegraph.js +46 -43
- package/src/tools/context.js +44 -28
- package/src/tools/gitTools.js +1 -3
- package/src/tools/plan.js +133 -0
- package/uv.lock +1 -1
- package/src/tools/discussion.js +0 -123
package/src/templates/GEMINI.md
CHANGED
|
@@ -1,87 +1,90 @@
|
|
|
1
1
|
# Context-MCP — Gemini CLI Usage Guide
|
|
2
2
|
|
|
3
3
|
Persistent memory + codebase knowledge graph.
|
|
4
|
-
|
|
4
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
## 1. Start of Every Conversation (MANDATORY)
|
|
9
9
|
|
|
10
|
-
Call
|
|
10
|
+
Call `context` MCP tool: `action:"resume"`, `project:"<project>"` before anything else.
|
|
11
11
|
|
|
12
|
-
Returns:
|
|
13
|
-
- `recentEntries` — decisions, bugs, notes from previous conversations
|
|
14
|
-
- `activeDiscussions` — ongoing topics (auto-linked if exactly one active)
|
|
15
|
-
- `codegraph` — `{ built: true/false, nodes, edges, communities }`
|
|
12
|
+
Returns: `recentEntries`, `activePlans`, `codegraph`, `stats.totalEntries`.
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
- `codegraph.built:
|
|
19
|
-
- `
|
|
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
|
|
20
18
|
|
|
21
19
|
---
|
|
22
20
|
|
|
23
|
-
## 2.
|
|
21
|
+
## 2. Save Triggers (MANDATORY)
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
context.save type: "architecture" title: "ContextGraph built — <project>"
|
|
28
|
-
content: "nodes: X | edges: Y | communities: Z"
|
|
29
|
-
```
|
|
23
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
30
24
|
|
|
31
|
-
|
|
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 |
|
|
32
34
|
|
|
33
|
-
**
|
|
35
|
+
**Do NOT save:** routine reads, search results, explanations of existing code.
|
|
36
|
+
|
|
37
|
+
---
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|--------------|------|
|
|
37
|
-
| Approach / library / pattern decided | `decision` |
|
|
38
|
-
| Bug found (root cause known) or fixed | `bug` |
|
|
39
|
-
| System structure understood | `architecture` |
|
|
40
|
-
| Gotcha, constraint, non-obvious behavior | `note` |
|
|
41
|
-
| Config / env var / secret key discovered | `config` |
|
|
42
|
-
| External API or service integration learned | `note` |
|
|
43
|
-
| Performance insight (why something is slow/fast) | `note` |
|
|
44
|
-
| How to run tests / test pattern discovered | `note` |
|
|
45
|
-
| Deploy / release step discovered | `note` |
|
|
46
|
-
| Milestone / feature / task completed | `note` |
|
|
39
|
+
## 3. Plans (MANDATORY for multi-file work)
|
|
47
40
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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.
|
|
51
47
|
|
|
52
48
|
---
|
|
53
49
|
|
|
54
|
-
##
|
|
50
|
+
## 4. Auto-Summary at ≥ 20 Entries (MANDATORY)
|
|
55
51
|
|
|
56
|
-
|
|
52
|
+
When `totalEntries ≥ 20`, call `context.save` BEFORE the user's task:
|
|
57
53
|
|
|
58
|
-
### Step 1 — Build (once, fast, local)
|
|
59
54
|
```
|
|
60
|
-
|
|
55
|
+
type: "compaction" title: "Session summary — <YYYY-MM-DD>"
|
|
56
|
+
content: "<what was built, decided, broke, current state>"
|
|
57
|
+
project: "<project>"
|
|
61
58
|
```
|
|
62
59
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
codegraph_nodes(path, type) → list nodes by type
|
|
69
|
-
codegraph_report(path) → full graph analysis
|
|
70
|
-
```
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 5. Search Before Asking
|
|
63
|
+
|
|
64
|
+
Call `search` before asking user to re-explain past work.
|
|
71
65
|
|
|
72
66
|
---
|
|
73
67
|
|
|
74
|
-
##
|
|
68
|
+
## 6. ContextGraph Tools
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
codegraph_build(path) → build AST graph (run once)
|
|
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
|
+
```
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
**File** — bugs, logic, tracing unexpected behavior.
|
|
78
|
+
Use `codegraph_arch` first. Never read files for structure questions.
|
|
78
79
|
|
|
79
80
|
---
|
|
80
81
|
|
|
81
|
-
##
|
|
82
|
+
## 7. Rules
|
|
82
83
|
|
|
83
|
-
1.
|
|
84
|
-
2.
|
|
85
|
-
3.
|
|
86
|
-
4.
|
|
87
|
-
5.
|
|
84
|
+
1. `context.resume` first — before any tool or response
|
|
85
|
+
2. Always pass `project`
|
|
86
|
+
3. Save on task complete — `why` + `outcome` + `files`
|
|
87
|
+
4. Compaction at ≥ 20 entries — before starting task
|
|
88
|
+
5. Plan before multi-file work — `status:"done"` deletes it
|
|
89
|
+
6. Search before asking about past work
|
|
90
|
+
7. Graph tools before files
|
|
@@ -4,7 +4,7 @@ Both `project` and `rootPath` are required: `project` names the memory bucket, `
|
|
|
4
4
|
|
|
5
5
|
This loads:
|
|
6
6
|
- Recent decisions, bugs, and notes from past sessions
|
|
7
|
-
- Active
|
|
7
|
+
- Active plans
|
|
8
8
|
- ContextGraph status (built or not)
|
|
9
9
|
|
|
10
10
|
If `codegraph.built` is false in the response, immediately call `codegraph_build` on the project path before proceeding.
|
|
@@ -2,8 +2,11 @@ Call the `context` MCP tool with `action: "save"` to store a note for the curren
|
|
|
2
2
|
|
|
3
3
|
Parse `$ARGUMENTS` to determine:
|
|
4
4
|
- `project`: infer from current working directory name if not specified
|
|
5
|
-
- `title`: first sentence or phrase
|
|
5
|
+
- `title`: first sentence or phrase (up to 120 chars — be specific)
|
|
6
|
+
- `why`: reason it mattered — what problem it solved or constraint it revealed
|
|
7
|
+
- `outcome`: result — what changed, what was verified, what shipped, which files were affected
|
|
8
|
+
- `files`: list of files changed (required for task/bug types)
|
|
6
9
|
- `content`: full argument text
|
|
7
|
-
- `type`: auto-detect —
|
|
10
|
+
- `type`: auto-detect — bug/fix/error → `"bug"`, task/done/complete/shipped/implemented → `"task"`, decision/chose/decided/approach → `"decision"`, config/env/secret/deploy → `"config"`, otherwise `"note"`
|
|
8
11
|
|
|
9
|
-
Confirm to the user
|
|
12
|
+
Confirm to the user: title, type, why, outcome, project.
|
|
@@ -13,7 +13,7 @@ Every conversation starts with `context.resume`. Every structural question uses
|
|
|
13
13
|
|
|
14
14
|
Call `context` tool, `action: "resume"`, `project: "<project-name>"` before anything else.
|
|
15
15
|
|
|
16
|
-
Returns: `recentEntries`, `
|
|
16
|
+
Returns: `recentEntries`, `activePlans`, `codegraph { built, nodes, edges }`.
|
|
17
17
|
|
|
18
18
|
- `codegraph.built: true` → use `codegraph_query` before reading files
|
|
19
19
|
- `codegraph.built: false` → run `codegraph_build(path)` first
|
|
@@ -24,8 +24,8 @@ Returns: `recentEntries`, `activeDiscussions`, `codegraph { built, nodes, edges
|
|
|
24
24
|
|-----------|--------|
|
|
25
25
|
| Decision made | `context.save` type: `"decision"` |
|
|
26
26
|
| Bug found/fixed | `context.save` type: `"bug"` |
|
|
27
|
-
|
|
|
28
|
-
|
|
|
27
|
+
| Discovery / structure understood | `context.save` type: `"note"` |
|
|
28
|
+
| Making any plan | `plan.save` + `planDir` |
|
|
29
29
|
|
|
30
30
|
## 3. CodeGraph
|
|
31
31
|
|
|
@@ -12,7 +12,17 @@ description: >
|
|
|
12
12
|
# Context-MCP
|
|
13
13
|
|
|
14
14
|
Persistent memory + codebase knowledge graph across every conversation.
|
|
15
|
-
`context.resume` starts every session. `
|
|
15
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Subcommands
|
|
20
|
+
|
|
21
|
+
When invoked with an argument, act immediately:
|
|
22
|
+
|
|
23
|
+
**`/context-mcp resume`** — call `context` tool with `action:"resume"`, infer `project` from cwd, pass `rootPath`. Report what was returned.
|
|
24
|
+
|
|
25
|
+
**`/context-mcp save`** — call `context` tool with `action:"save"` to save the most recent thing worth keeping from this conversation. Use `type:"note"`, fill in `title`, `why`, `outcome`, `files` from context. Confirm what was saved.
|
|
16
26
|
|
|
17
27
|
---
|
|
18
28
|
|
|
@@ -23,92 +33,109 @@ Call `context` tool **before any tool or response** with:
|
|
|
23
33
|
- `project: "<basename of git repo root dir>"` — infer from `cwd` if not stated
|
|
24
34
|
- `rootPath: "<absolute path to git repo root>"` — required for sandbox + graph lookup
|
|
25
35
|
|
|
26
|
-
Both fields are required: `project` names the memory bucket, `rootPath` enables exact graph matching and file sandboxing.
|
|
27
|
-
|
|
28
36
|
Returns:
|
|
29
|
-
- `recentEntries` —
|
|
30
|
-
- `
|
|
37
|
+
- `recentEntries` — last 15 entries; newest 5 have full content, rest have 200-char preview
|
|
38
|
+
- `activePlans` — in-progress plans; read them before starting any new work
|
|
31
39
|
- `codegraph` — `{ built: true/false, nodes, edges, communities }`
|
|
40
|
+
- `stats.totalEntries` — if ≥ 20, write a compaction summary before proceeding (see Rule 4)
|
|
32
41
|
|
|
33
42
|
Then:
|
|
34
|
-
- `codegraph.built: true` → use `codegraph_query`
|
|
35
|
-
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
43
|
+
- `codegraph.built: true` → use `codegraph_arch` for structure overview, `codegraph_query` for specific lookups
|
|
44
|
+
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
36
45
|
|
|
37
46
|
---
|
|
38
47
|
|
|
39
|
-
## When to
|
|
48
|
+
## When to Save Context (MANDATORY TRIGGERS)
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
42
51
|
|
|
43
|
-
**1. After graph build or rebuild**
|
|
44
|
-
Every time `codegraph_build` completes successfully, immediately call:
|
|
45
52
|
```
|
|
46
|
-
context.save
|
|
47
|
-
|
|
53
|
+
context.save
|
|
54
|
+
project: "<project>"
|
|
55
|
+
title: "<what was done — up to 120 chars>"
|
|
56
|
+
why: "<why it mattered>"
|
|
57
|
+
outcome: "<what the result was>"
|
|
58
|
+
files: ["src/file.js", ...]
|
|
48
59
|
```
|
|
49
60
|
|
|
50
|
-
**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Do NOT save
|
|
62
|
-
|
|
63
|
-
| What happened | Type |
|
|
64
|
-
|--------------|------|
|
|
65
|
-
| Approach / library / pattern decided | `decision` |
|
|
66
|
-
| Bug found (root cause known) or fixed | `bug` |
|
|
67
|
-
| System structure understood | `architecture` |
|
|
68
|
-
| Gotcha, constraint, non-obvious behavior | `note` |
|
|
69
|
-
| Config / env var / secret key discovered | `config` |
|
|
70
|
-
| External API or service integration learned | `note` |
|
|
71
|
-
| Performance insight (why something is slow/fast) | `note` |
|
|
72
|
-
| How to run tests / test pattern discovered | `note` |
|
|
73
|
-
| Deploy / release step discovered | `note` |
|
|
74
|
-
| Milestone / feature / task completed | `note` |
|
|
75
|
-
|
|
76
|
-
Always pass `project`. Feature spans multiple sessions → `discussion.create` or `discussion.update`. Need past info → `search` before asking user. Auto-compact fires at >20 entries.
|
|
61
|
+
**Save immediately after:**
|
|
62
|
+
- Task / fix / feature complete
|
|
63
|
+
- Decision made (architecture, library, approach)
|
|
64
|
+
- Discovery — non-obvious behavior, constraint, gotcha
|
|
65
|
+
- Config / env / deploy info
|
|
66
|
+
- Graph build complete — include nodes/edges count in content
|
|
67
|
+
- User says "save this" / "remember this"
|
|
68
|
+
|
|
69
|
+
**Manual compaction** — "compact now", "compress memory", "clean up context":
|
|
70
|
+
Save a full session summary as `type: "compaction"`. Server removes old entries using it.
|
|
71
|
+
|
|
72
|
+
**Do NOT save:** routine reads, search results, explanations of existing code, dead-end debugging.
|
|
77
73
|
|
|
78
74
|
---
|
|
79
75
|
|
|
80
|
-
##
|
|
76
|
+
## Plans (MANDATORY for multi-file work)
|
|
81
77
|
|
|
82
|
-
|
|
78
|
+
**Create a plan when:** editing 2+ files, multi-step implementation, refactor, multi-file bug fix.
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
**Skip plan for:** single-file edits, questions, simple config tweaks.
|
|
81
|
+
|
|
82
|
+
1. `plan.save` with name, content, project, planDir — before starting work
|
|
83
|
+
2. Work through plan
|
|
84
|
+
3. `plan.update status:"done"` when complete — deletes the plan
|
|
85
|
+
|
|
86
|
+
On `resume`, check `activePlans` — do not duplicate in-progress work.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Auto-Summary Rule (MANDATORY)
|
|
91
|
+
|
|
92
|
+
When `resume` returns `stats.totalEntries ≥ 20`, call `context.save` **before the user's task**:
|
|
89
93
|
|
|
90
|
-
### Query (free, instant, forever)
|
|
91
94
|
```
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
codegraph_report(path) → god nodes, clusters, surprises
|
|
95
|
+
type: "compaction" title: "Session summary — <date>"
|
|
96
|
+
content: "<what was built, decided, broke, current state>"
|
|
97
|
+
project: "<project>"
|
|
96
98
|
```
|
|
97
99
|
|
|
98
100
|
---
|
|
99
101
|
|
|
100
|
-
##
|
|
102
|
+
## Search Before Asking
|
|
103
|
+
|
|
104
|
+
If user references past work → `search` first. Never ask user to re-explain saved information.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## ContextGraph Pipeline
|
|
101
109
|
|
|
102
|
-
|
|
110
|
+
### Build (once per project)
|
|
111
|
+
```
|
|
112
|
+
codegraph_build(path) → AST graph: functions, classes, imports, edges
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Query tools
|
|
116
|
+
```
|
|
117
|
+
codegraph_arch(path) → module map: every file, exports, imports
|
|
118
|
+
codegraph_query(path, question?, node?) → find symbol or answer structural question
|
|
119
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
120
|
+
codegraph_report(path) → god nodes, clusters, structural analysis
|
|
121
|
+
```
|
|
103
122
|
|
|
104
|
-
|
|
123
|
+
| Question | Tool |
|
|
124
|
+
|---|---|
|
|
125
|
+
| Architecture overview / what files exist | `codegraph_arch` |
|
|
126
|
+
| Where is function/class X defined? | `codegraph_query node:"X"` |
|
|
127
|
+
| What does module Y import? | `codegraph_query question:"..."` |
|
|
128
|
+
| List all classes/functions | `codegraph_nodes type:"class"` |
|
|
129
|
+
| Most connected / central files | `codegraph_report` |
|
|
105
130
|
|
|
106
131
|
---
|
|
107
132
|
|
|
108
133
|
## Rules
|
|
109
134
|
|
|
110
|
-
1.
|
|
111
|
-
2.
|
|
112
|
-
3.
|
|
113
|
-
4.
|
|
114
|
-
5.
|
|
135
|
+
1. `context.resume` first — before any tool or response
|
|
136
|
+
2. Always pass `project`
|
|
137
|
+
3. Save on task complete — `why` + `outcome` + `files`
|
|
138
|
+
4. Compaction at ≥ 20 entries — before starting task
|
|
139
|
+
5. Plan for multi-file work — `status:"done"` deletes it
|
|
140
|
+
6. Search before asking about past work
|
|
141
|
+
7. Graph tools before files
|
|
@@ -1,35 +1,84 @@
|
|
|
1
1
|
# Context-MCP — Windsurf Usage Guide
|
|
2
2
|
|
|
3
|
-
Persistent memory + codebase knowledge graph
|
|
4
|
-
|
|
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
|
+
---
|
|
5
7
|
|
|
6
8
|
## 1. Start of Every Conversation (MANDATORY)
|
|
7
9
|
|
|
8
|
-
Call `context` tool
|
|
10
|
+
Call `context` tool: `action:"resume"`, `project:"<name>"` before anything else.
|
|
9
11
|
|
|
10
|
-
Returns: `recentEntries`, `
|
|
12
|
+
Returns: `recentEntries`, `activePlans`, `codegraph`, `stats.totalEntries`.
|
|
11
13
|
|
|
12
|
-
- `codegraph.built: true` → use `codegraph_query` before reading files
|
|
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
|
+
---
|
|
14
63
|
|
|
15
|
-
##
|
|
64
|
+
## 6. ContextGraph Tools
|
|
16
65
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
```
|
|
23
72
|
|
|
24
|
-
|
|
73
|
+
Use `codegraph_arch` first. Never read files for structure questions.
|
|
25
74
|
|
|
26
|
-
|
|
27
|
-
Use `codegraph_query` for structural questions. Read files for bugs/logic.
|
|
75
|
+
---
|
|
28
76
|
|
|
29
|
-
## Rules
|
|
77
|
+
## 7. Rules
|
|
30
78
|
|
|
31
79
|
1. `context.resume` first — every conversation
|
|
32
|
-
2.
|
|
33
|
-
3.
|
|
34
|
-
4. `
|
|
35
|
-
5.
|
|
80
|
+
2. Save on task complete — `why` + `outcome` + `files`
|
|
81
|
+
3. Compaction at ≥ 20 entries — before starting task
|
|
82
|
+
4. Plan for 2+ file changes — `status:"done"` deletes it
|
|
83
|
+
5. Search before asking about past work
|
|
84
|
+
6. Graph tools before files
|
package/src/tools/codegraph.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { spawnSync } from 'node:child_process';
|
|
7
7
|
import { dirname, join } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { saveGraph, saveContext, updateContext, getContext, flushToDisk } from '../db.js';
|
|
9
10
|
|
|
10
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
12
|
const REPO_ROOT = join(__dirname, '..', '..');
|
|
@@ -82,16 +83,18 @@ export const definitions = [
|
|
|
82
83
|
},
|
|
83
84
|
},
|
|
84
85
|
{
|
|
85
|
-
name: '
|
|
86
|
-
description:
|
|
86
|
+
name: 'codegraph_arch',
|
|
87
|
+
description:
|
|
88
|
+
'Return a module map of the project — every file with its exported functions/classes and its imports. ' +
|
|
89
|
+
'Use this to understand project structure without reading any files. ' +
|
|
90
|
+
'Call after codegraph_build. Much faster than reading each file individually.',
|
|
87
91
|
inputSchema: {
|
|
88
92
|
type: 'object',
|
|
89
93
|
properties: {
|
|
90
|
-
path:
|
|
91
|
-
|
|
92
|
-
to: { type: 'string' },
|
|
94
|
+
path: { type: 'string', description: 'Project root' },
|
|
95
|
+
limit: { type: 'integer', description: 'Max files in output (default 100)' },
|
|
93
96
|
},
|
|
94
|
-
required: ['path'
|
|
97
|
+
required: ['path'],
|
|
95
98
|
},
|
|
96
99
|
},
|
|
97
100
|
];
|
|
@@ -103,46 +106,46 @@ export function handle(name, args, state) {
|
|
|
103
106
|
|
|
104
107
|
// Persist graph metadata + save/update a context entry as a visible build record
|
|
105
108
|
if (name === 'codegraph_build' && result.success) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
saveGraph({
|
|
110
|
+
path: args.path,
|
|
111
|
+
nodes: result.nodes,
|
|
112
|
+
edges: result.edges,
|
|
113
|
+
communities: result.communities,
|
|
114
|
+
cached: result.cached,
|
|
115
|
+
changed: result.changed,
|
|
116
|
+
time_ms: result.time_ms,
|
|
117
|
+
summary: result.summary || '',
|
|
118
|
+
});
|
|
119
|
+
flushToDisk(); // write graph.json to disk immediately so ctx list sees it
|
|
117
120
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
const inferredProject = args.path
|
|
122
|
+
? args.path.replace(/\\/g, '/').replace(/\/$/, '').split('/').pop()
|
|
123
|
+
: null;
|
|
124
|
+
const project = state?.sessionProject || inferredProject || null;
|
|
125
|
+
const title = `ContextGraph built — ${args.path}`;
|
|
126
|
+
const content = [
|
|
127
|
+
`nodes: ${result.nodes} | edges: ${result.edges} | communities: ${result.communities}`,
|
|
128
|
+
`cached: ${result.cached} | changed: ${result.changed} | time: ${result.time_ms}ms`,
|
|
129
|
+
result.summary || '',
|
|
130
|
+
].filter(Boolean).join('\n');
|
|
128
131
|
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
// Search all projects — same path always produces same title regardless of session
|
|
133
|
+
const existing = getContext({ tags: ['codegraph'], limit: 100 })
|
|
134
|
+
.find(e => e.title === title);
|
|
131
135
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}).catch(() => {});
|
|
136
|
+
if (existing) {
|
|
137
|
+
updateContext({ id: existing.id, content, status: 'active' });
|
|
138
|
+
} else {
|
|
139
|
+
saveContext({
|
|
140
|
+
project,
|
|
141
|
+
sessionId: state?.sessionId || null,
|
|
142
|
+
title,
|
|
143
|
+
content,
|
|
144
|
+
type: 'note',
|
|
145
|
+
source: 'auto',
|
|
146
|
+
tags: ['codegraph', 'graph-build'],
|
|
147
|
+
});
|
|
148
|
+
}
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
return result;
|