code-graph-llm 2.1.3 → 3.0.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
CHANGED
|
@@ -1,54 +1,108 @@
|
|
|
1
|
-
# CODE-GRAPH (
|
|
1
|
+
# CODE-GRAPH (v3.0.0)
|
|
2
2
|
|
|
3
3
|
A language-agnostic, ultra-compact codebase mapper and **agent memory system** designed specifically for LLM agents. It optimizes context and token usage while enabling agents to learn from their own mistakes across sessions.
|
|
4
4
|
|
|
5
|
-
## 🚀 New in
|
|
5
|
+
## 🚀 New in v3.0: Major Version Upgrade
|
|
6
6
|
- **Project Initializer:** Automated bootstrapping with `code-graph init`.
|
|
7
|
-
- **Intelligent Reflection:** Deduplication and categorization in `
|
|
7
|
+
- **Intelligent Reflection:** Deduplication and categorization in `llm-agent-project-learnings.md`.
|
|
8
8
|
- **Commit Advisories:** Soft-nudge git hooks to remind agents of missing reflections.
|
|
9
9
|
- **Production-Ready Core:** Refactored Service-based architecture with full async support.
|
|
10
10
|
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
code-graph
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
11
|
+
## 🛠️ The Code-Graph Skillset
|
|
12
|
+
|
|
13
|
+
Code-Graph transforms your codebase into an agent-friendly environment using five core skills:
|
|
14
|
+
|
|
15
|
+
### 1. **Structural Mapping (`generate`)**
|
|
16
|
+
* **What it does:** Scans your project for symbols (classes, functions, interfaces) and builds a dense dependency graph (`imports`, `requires`, `inheritance`).
|
|
17
|
+
* **How to use:** Run `code-graph generate`. This creates `llm-code-graph.md`, which agents use as their "Source of Truth" for navigation.
|
|
18
|
+
* **Agent Benefit:** Prevents "hallucinating" file paths and reduces token usage by giving the agent a compact map instead of raw file content.
|
|
19
|
+
|
|
20
|
+
### 2. **Memory Persistence (`reflect`)**
|
|
21
|
+
* **What it does:** Logs non-obvious fixes, environment quirks, and architectural lessons into `llm-agent-project-learnings.md`.
|
|
22
|
+
* **How to use:** `code-graph reflect <CATEGORY> "The lesson learned"`.
|
|
23
|
+
* **Agent Benefit:** Enables "Cross-Session Memory." If an agent fixes a Windows-specific bug in one session, the next agent reads the reflection and avoids the same pitfall.
|
|
24
|
+
|
|
25
|
+
### 3. **Automated Integration (`install-skills`)**
|
|
26
|
+
* **What it does:** Bridges the gap between the graph and your LLM platform (Claude, Cursor, Gemini, etc.).
|
|
27
|
+
* **How to use:** `code-graph <platform> install`.
|
|
28
|
+
* **Agent Benefit:** Installs **Tool Hooks** and **Always-On Rules** that force the agent to consult the graph before using search tools. It effectively "bakes" the graph into the agent's internal loop.
|
|
29
|
+
|
|
30
|
+
### 4. **Self-Healing Sync (`install-hook`)**
|
|
31
|
+
* **What it does:** Installs a Git pre-commit hook to keep the map and memory in sync with code changes.
|
|
32
|
+
* **How to use:** `code-graph install-hook`.
|
|
33
|
+
* **Agent Benefit:** Ensures the agent is never working with an outdated map. It also nudges the agent to record a reflection if significant code changed but no lesson was logged.
|
|
34
|
+
|
|
35
|
+
### 5. **Real-Time Context (`watch`)**
|
|
36
|
+
* **What it does:** Monitors your filesystem and rebuilds the graph instantly as you or the agent edits code.
|
|
37
|
+
* **How to use:** `code-graph watch`.
|
|
38
|
+
* **Agent Benefit:** Vital for long-running agent sessions where the project structure is rapidly evolving.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🧠 Workflow: The Reflection Cycle
|
|
43
|
+
|
|
44
|
+
To get the most out of Code-Graph, force your agent to follow this **Strict Protocol** (defined in `llm-agent-rules.md`):
|
|
45
|
+
|
|
46
|
+
1. **PRE-TASK (Read):** The agent MUST read `llm-agent-project-learnings.md` to check for existing pitfalls and `llm-code-graph.md` to locate the relevant "God Nodes" (core logic).
|
|
47
|
+
2. **EXECUTION (Monitor):** During the task, the agent monitors for "Learned Moments"—failures, unexpected OS behaviors, or complex regex fixes.
|
|
48
|
+
3. **POST-TASK (Reflect):** If a lesson was learned, the agent MUST run `code-graph reflect`.
|
|
49
|
+
4. **COMMIT (Sync):** Upon commit, the Git hook automatically runs `code-graph generate` to update the map for the next agent.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 🚀 Automated Agent Integration
|
|
54
|
+
|
|
55
|
+
After generating a graph, you can automatically configure your favorite LLM agent to use it by running the matching install command.
|
|
56
|
+
|
|
57
|
+
| Platform | Command |
|
|
58
|
+
| :--- | :--- |
|
|
59
|
+
| **Claude Code** | `code-graph claude install` |
|
|
60
|
+
| **Cursor** | `code-graph cursor install` |
|
|
61
|
+
| **Gemini CLI** | `code-graph gemini install` |
|
|
62
|
+
| **Codex** | `code-graph codex install` |
|
|
63
|
+
| **OpenCode** | `code-graph opencode install` |
|
|
64
|
+
| **GitHub Copilot CLI** | `code-graph copilot install` |
|
|
65
|
+
| **VS Code Copilot Chat** | `code-graph vscode install` |
|
|
66
|
+
| **Aider** | `code-graph aider install` |
|
|
67
|
+
| **OpenClaw** | `code-graph openclaw install` |
|
|
68
|
+
| **Factory Droid** | `code-graph droid install` |
|
|
69
|
+
| **Trae** | `code-graph trae install` |
|
|
70
|
+
| **Hermes** | `code-graph hermes install` |
|
|
71
|
+
| **Kiro IDE/CLI** | `code-graph kiro install` |
|
|
72
|
+
| **Google Antigravity** | `code-graph antigravity install` |
|
|
73
|
+
|
|
74
|
+
### What this does:
|
|
75
|
+
- **Always-on Rules:** Writes project-level rule files (e.g., `CLAUDE.md`, `.cursor/rules/`, `AGENTS.md`) telling the agent to read `llm-code-graph.md` before answering architecture questions.
|
|
76
|
+
- **Pre-Tool Hooks:** For platforms that support it (Claude, Codex, Gemini, OpenCode), it installs hooks that fire before every file-search or bash call, injecting a reminder to check the graph first. This prevents the agent from grepping every file when a high-level map already exists.
|
|
77
|
+
- **Global Skills:** Copies the Code-Graph skill to the platform's global skill directory for persistence across projects.
|
|
78
|
+
|
|
79
|
+
**Uninstall** by replacing `install` with `uninstall` (e.g., `code-graph claude uninstall`).
|
|
80
|
+
|
|
81
|
+
### Skill Installation Details
|
|
82
|
+
|
|
83
|
+
| Platform | Action Taken | Directory / Files |
|
|
84
|
+
| :--- | :--- | :--- |
|
|
85
|
+
| **Claude Code** | Adds instructions to `CLAUDE.md` and installs a `preToolUse` hook for `glob` and `grep`. | `.claude/settings.json` |
|
|
86
|
+
| **Cursor** | Writes a global rule with `alwaysApply: true`. | `.cursor/rules/code-graph.mdc` |
|
|
87
|
+
| **Gemini CLI** | Copies skill globally and adds a `beforeTool` hook for `read_file`. | `~/.gemini/skills/code-graph/SKILL.md`, `.gemini/settings.json`, `GEMINI.md` |
|
|
88
|
+
| **Codex** | Updates `AGENTS.md` and installs a `preToolUse` hook for `bash`. | `.codex/hooks.json` |
|
|
89
|
+
| **OpenCode** | Registers a plugin that fires before `bash` tool calls. | `.opencode/plugins/code-graph.js`, `opencode.json`, `AGENTS.md` |
|
|
90
|
+
| **GitHub Copilot CLI** | Copies the Code-Graph skill to the global skill directory. | `~/.copilot/skills/code-graph/SKILL.md` |
|
|
91
|
+
| **VS Code Copilot** | Writes session-persistent instructions. | `.github/copilot-instructions.md` |
|
|
92
|
+
| **Aider / Trae / etc.** | Updates `AGENTS.md` and copies skill to global platform directory. | `~/.<platform>/skills/code-graph/SKILL.md`, `AGENTS.md` |
|
|
93
|
+
| **Kiro IDE/CLI** | Writes global skill and steering file for automatic inclusion. | `.kiro/skills/code-graph/SKILL.md`, `.kiro/steering/code-graph.md` |
|
|
94
|
+
| **Antigravity** | Writes always-on rules and registers a slash command workflow. | `.agent/rules/code-graph.md`, `.agent/workflows/code-graph.md` |
|
|
95
|
+
|
|
96
|
+
### How agents use it:
|
|
97
|
+
1. **Direct Instructions:** Most platforms are configured to read project-level files (`CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, etc.) automatically. These files tell the agent: "Before searching files, read `llm-code-graph.md`."
|
|
98
|
+
2. **Tool Hooks (The "Always-On" Mechanism):** For Claude, Gemini, and Codex, the tool installs a **blocking hook**. When the agent tries to use a search tool (like `grep`), the hook intercepts the call and injects a reminder: "Knowledge graph exists. Read `llm-code-graph.md` first." This forces the agent to use the graph for navigation instead of brute-force searching.
|
|
99
|
+
3. **Slash Commands:** Some platforms (Kiro, Antigravity) register `/code-graph` as a command to manually invoke or refresh the graph context.
|
|
46
100
|
|
|
47
101
|
## 🧠 LLM Agent Strategy
|
|
48
102
|
|
|
49
103
|
### 1. The Mandatory Protocol
|
|
50
|
-
Instruct your agent to follow the **STRICT AGENT PROTOCOL** in `
|
|
51
|
-
1. Reads `
|
|
104
|
+
Instruct your agent to follow the **STRICT AGENT PROTOCOL** in `llm-agent-rules.md`. This ensures the agent:
|
|
105
|
+
1. Reads `llm-agent-project-learnings.md` before starting any task.
|
|
52
106
|
2. Updates reflections after any failure or "learned moment."
|
|
53
107
|
3. Regenerates the project map (`llm-code-graph.md`) after structural changes.
|
|
54
108
|
|
|
@@ -66,36 +120,36 @@ The `llm-code-graph.md` file provides a high-level map and structural graph for
|
|
|
66
120
|
```
|
|
67
121
|
|
|
68
122
|
### 3. Example System Prompt
|
|
69
|
-
> "Before acting, read `llm-code-graph.md`. Follow the protocol in `
|
|
123
|
+
> "Before acting, read `llm-code-graph.md`. Follow the protocol in `llm-agent-rules.md`. If you encounter a bug or an environment quirk, use the `code-graph reflect` tool to record the lesson in `llm-agent-project-learnings.md`."
|
|
70
124
|
|
|
71
125
|
## 🤖 Agent-Specific Integration
|
|
72
126
|
|
|
73
|
-
Maximize efficiency by pointing your agent directly to the `llm-code-graph.md` and `
|
|
127
|
+
Maximize efficiency by pointing your agent directly to the `llm-code-graph.md` and `llm-agent-rules.md` files.
|
|
74
128
|
|
|
75
129
|
### Roo Code (Cline)
|
|
76
130
|
Add this to your `.clinerules` file:
|
|
77
131
|
```markdown
|
|
78
132
|
Before starting any task:
|
|
79
133
|
1. Read `llm-code-graph.md` for project structure.
|
|
80
|
-
2. Read `
|
|
81
|
-
3. Read `
|
|
82
|
-
4. **MANDATORY:** After any fix or learning event, you MUST update `
|
|
134
|
+
2. Read `llm-agent-rules.md` for operational protocol.
|
|
135
|
+
3. Read `llm-agent-project-learnings.md` for past lessons.
|
|
136
|
+
4. **MANDATORY:** After any fix or learning event, you MUST update `llm-agent-project-learnings.md` using `code-graph reflect`.
|
|
83
137
|
```
|
|
84
138
|
|
|
85
139
|
### Cursor / Windsurf
|
|
86
140
|
Add to `.cursorrules` or `.windsurfrules`:
|
|
87
141
|
```text
|
|
88
|
-
Always reference `llm-code-graph.md` before editing. You are REQUIRED to follow the "Reflection Cycle" in `
|
|
142
|
+
Always reference `llm-code-graph.md` before editing. You are REQUIRED to follow the "Reflection Cycle" in `llm-agent-rules.md`. If a task involves a non-obvious fix or an environment quirk, you MUST record it in `llm-agent-project-learnings.md` immediately.
|
|
89
143
|
```
|
|
90
144
|
|
|
91
145
|
### GitHub Copilot
|
|
92
146
|
Add to `.github/copilot-instructions.md`:
|
|
93
147
|
```markdown
|
|
94
|
-
When answering questions about this codebase, prioritize the mapping data in `llm-code-graph.md`. You MUST suggest or perform a reflection entry for `
|
|
148
|
+
When answering questions about this codebase, prioritize the mapping data in `llm-code-graph.md`. You MUST suggest or perform a reflection entry for `llm-agent-project-learnings.md` after every bug fix or identified pitfall.
|
|
95
149
|
```
|
|
96
150
|
|
|
97
151
|
### Gemini CLI
|
|
98
|
-
Create a `GEMINI.md` file (if not already using `
|
|
152
|
+
Create a `GEMINI.md` file (if not already using `llm-agent-rules.md`):
|
|
99
153
|
```markdown
|
|
100
154
|
- Always read `llm-code-graph.md` as the primary source of truth.
|
|
101
155
|
- **CRITICAL:** Use `run_shell_command` to execute `code-graph reflect` after any bug fix or discovered quirk. Memory persistence is a mandatory part of every task completion.
|
|
@@ -107,7 +161,7 @@ In your project instructions or session startup:
|
|
|
107
161
|
|
|
108
162
|
### Codex / GPT-Engineer / AutoGPT
|
|
109
163
|
Add to your project prompt or `prompts.md`:
|
|
110
|
-
> "Use `llm-code-graph.md` to navigate. Strictly adhere to the reflection cycle in `
|
|
164
|
+
> "Use `llm-code-graph.md` to navigate. Strictly adhere to the reflection cycle in `llm-agent-rules.md`. You MUST persist project memory by updating `llm-agent-project-learnings.md` on every failure or learned moment."
|
|
111
165
|
|
|
112
166
|
### Generic Agent (System Prompt)
|
|
113
167
|
For any other agent, add this to your system instructions:
|
package/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import fs from 'fs';
|
|
|
10
10
|
import { promises as fsp } from 'fs';
|
|
11
11
|
import path from 'path';
|
|
12
12
|
import { fileURLToPath } from 'url';
|
|
13
|
+
import os from 'os';
|
|
13
14
|
import chokidar from 'chokidar';
|
|
14
15
|
import ignore from 'ignore';
|
|
15
16
|
|
|
@@ -19,8 +20,8 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
19
20
|
export const CONFIG = {
|
|
20
21
|
IGNORE_FILE: '.gitignore',
|
|
21
22
|
MAP_FILE: 'llm-code-graph.md',
|
|
22
|
-
REFLECTIONS_FILE: '
|
|
23
|
-
RULES_FILE: '
|
|
23
|
+
REFLECTIONS_FILE: 'llm-agent-project-learnings.md',
|
|
24
|
+
RULES_FILE: 'llm-agent-rules.md',
|
|
24
25
|
SUPPORTED_EXTENSIONS: [
|
|
25
26
|
'.js', '.ts', '.jsx', '.tsx', '.py', '.go', '.rs', '.java',
|
|
26
27
|
'.cpp', '.c', '.h', '.hpp', '.cc', '.rb', '.php', '.swift',
|
|
@@ -235,7 +236,7 @@ class ProjectMapper {
|
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
formatOutput() {
|
|
238
|
-
const header = `# CODE_GRAPH_MAP\n> MISSION: COMPACT PROJECT MAP FOR LLM AGENTS.\n> PROTOCOL: Follow
|
|
239
|
+
const header = `# CODE_GRAPH_MAP\n> MISSION: COMPACT PROJECT MAP FOR LLM AGENTS.\n> PROTOCOL: Follow llm-agent-rules.md | MEMORY: See llm-agent-project-learnings.md\n> Legend: [CORE] Entry Point, (↑N) Outgoing Deps, (↓M) Incoming Dependents\n> Notation: syms: [Name [Signature/Context]], desc: File Summary, [TAG: Context]\n\n`;
|
|
239
240
|
const nodes = this.files.map(f => {
|
|
240
241
|
const inCount = this.incomingEdges[f.path] || 0;
|
|
241
242
|
const tags = f.tags.length ? ` [${f.tags.join(', ')}]` : '';
|
|
@@ -254,7 +255,7 @@ class ReflectionManager {
|
|
|
254
255
|
if (!lesson) return console.error('[Code-Graph] Usage: reflect <cat> <lesson>');
|
|
255
256
|
|
|
256
257
|
const filePath = path.join(process.cwd(), CONFIG.REFLECTIONS_FILE);
|
|
257
|
-
const header = `#
|
|
258
|
+
const header = `# LLM_AGENT_PROJECT_LEARNINGS\n> LLM AGENT MEMORY: READ BEFORE STARTING TASKS. UPDATE ON FAILURES.\n`;
|
|
258
259
|
const entry = `- [${category.toUpperCase()}: ${new Date().toISOString().split('T')[0]}] ${lesson}`;
|
|
259
260
|
|
|
260
261
|
try {
|
|
@@ -281,7 +282,7 @@ class ProjectInitializer {
|
|
|
281
282
|
const rulesPath = path.join(cwd, CONFIG.RULES_FILE);
|
|
282
283
|
const reflectPath = path.join(cwd, CONFIG.REFLECTIONS_FILE);
|
|
283
284
|
|
|
284
|
-
const rulesContent = `#
|
|
285
|
+
const rulesContent = `# LLM_AGENT_RULES (STRICT PROTOCOL)
|
|
285
286
|
> This protocol is MANDATORY for all LLM agents. Failure to update memory is a failure of the task.
|
|
286
287
|
|
|
287
288
|
## 🧠 THE REFLECTION CYCLE
|
|
@@ -296,7 +297,7 @@ class ProjectInitializer {
|
|
|
296
297
|
- \`STYLE\`: Project-specific architectural rules.
|
|
297
298
|
`;
|
|
298
299
|
|
|
299
|
-
const reflectContent = `#
|
|
300
|
+
const reflectContent = `# LLM_AGENT_PROJECT_LEARNINGS\n> LLM AGENT MEMORY: READ BEFORE STARTING TASKS. UPDATE ON FAILURES.\n`;
|
|
300
301
|
|
|
301
302
|
try {
|
|
302
303
|
if (!fs.existsSync(rulesPath)) {
|
|
@@ -313,6 +314,174 @@ class ProjectInitializer {
|
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
|
|
317
|
+
/**
|
|
318
|
+
* Manages platform-specific skills and agent integrations.
|
|
319
|
+
*/
|
|
320
|
+
class SkillManager {
|
|
321
|
+
constructor(cwd) {
|
|
322
|
+
this.cwd = cwd;
|
|
323
|
+
this.home = os.homedir();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async execute(platform, action) {
|
|
327
|
+
if (!platform) return console.error('[Code-Graph] Platform required. Usage: code-graph <platform> [install|uninstall]');
|
|
328
|
+
const p = platform.toLowerCase();
|
|
329
|
+
const act = (action || 'install').toLowerCase();
|
|
330
|
+
|
|
331
|
+
if (act === 'install') await this.install(p);
|
|
332
|
+
else if (act === 'uninstall') await this.uninstall(p);
|
|
333
|
+
else console.error(`[Code-Graph] Unknown action: ${act}`);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
async install(p) {
|
|
337
|
+
console.log(`[Code-Graph] Installing skill for ${p}...`);
|
|
338
|
+
try {
|
|
339
|
+
switch (p) {
|
|
340
|
+
case 'claude': await this.installClaude(); break;
|
|
341
|
+
case 'codex': await this.installCodex(); break;
|
|
342
|
+
case 'opencode': await this.installOpenCode(); break;
|
|
343
|
+
case 'cursor': await this.installCursor(); break;
|
|
344
|
+
case 'gemini': await this.installGemini(); break;
|
|
345
|
+
case 'aider':
|
|
346
|
+
case 'openclaw':
|
|
347
|
+
case 'droid':
|
|
348
|
+
case 'trae':
|
|
349
|
+
case 'trae-cn':
|
|
350
|
+
case 'hermes':
|
|
351
|
+
await this.installGenericAgent(p);
|
|
352
|
+
break;
|
|
353
|
+
case 'kiro': await this.installKiro(); break;
|
|
354
|
+
case 'antigravity': await this.installAntigravity(); break;
|
|
355
|
+
case 'copilot': await this.installCopilot(); break;
|
|
356
|
+
case 'vscode': await this.installVSCode(); break;
|
|
357
|
+
default: return console.error(`[Code-Graph] Unsupported platform: ${p}`);
|
|
358
|
+
}
|
|
359
|
+
console.log(`[Code-Graph] Successfully installed ${p} skill.`);
|
|
360
|
+
} catch (err) {
|
|
361
|
+
console.error(`[Code-Graph] Installation failed for ${p}: ${err.message}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async uninstall(p) {
|
|
366
|
+
console.log(`[Code-Graph] Uninstalling skill for ${p}...`);
|
|
367
|
+
// Simplification: just remove the primary files
|
|
368
|
+
try {
|
|
369
|
+
switch (p) {
|
|
370
|
+
case 'claude': await this.removeFile('CLAUDE.md'); break;
|
|
371
|
+
case 'codex': await this.removeFile('AGENTS.md'); break;
|
|
372
|
+
case 'opencode': await this.removeFile('AGENTS.md'); break;
|
|
373
|
+
case 'cursor': await this.removeFile('.cursor/rules/code-graph.mdc'); break;
|
|
374
|
+
case 'gemini': await this.removeFile('GEMINI.md'); break;
|
|
375
|
+
case 'aider':
|
|
376
|
+
case 'openclaw':
|
|
377
|
+
case 'droid':
|
|
378
|
+
case 'trae':
|
|
379
|
+
case 'trae-cn':
|
|
380
|
+
case 'hermes':
|
|
381
|
+
await this.removeFile('AGENTS.md');
|
|
382
|
+
break;
|
|
383
|
+
case 'kiro': await this.removeFile('.kiro/steering/code-graph.md'); break;
|
|
384
|
+
case 'antigravity': await this.removeFile('.agent/rules/code-graph.md'); break;
|
|
385
|
+
case 'copilot': await fsp.rm(path.join(this.home, '.copilot', 'skills', 'code-graph'), { recursive: true, force: true }); break;
|
|
386
|
+
case 'vscode': await this.removeFile('.github/copilot-instructions.md'); break;
|
|
387
|
+
}
|
|
388
|
+
console.log(`[Code-Graph] Successfully uninstalled ${p} skill.`);
|
|
389
|
+
} catch (err) {
|
|
390
|
+
console.error(`[Code-Graph] Uninstallation failed: ${err.message}`);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
async installClaude() {
|
|
395
|
+
const section = `\n## 🗺️ Code-Graph Integration\nBefore answering architecture questions, read \`${CONFIG.MAP_FILE}\` for god nodes and community structure. This ensures high-level context before searching raw files.\n`;
|
|
396
|
+
await this.appendToFile('CLAUDE.md', section);
|
|
397
|
+
await this.writeJson('.claude/settings.json', { hooks: { preToolUse: [{ tools: ['glob', 'grep'], message: `code-graph: Knowledge graph exists. Read ${CONFIG.MAP_FILE} before searching raw files.` }] } });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async installCodex() {
|
|
401
|
+
const section = `\n## 🗺️ Code-Graph Navigation\nAlways check for \`${CONFIG.MAP_FILE}\` to understand project structure before using bash tools.\n`;
|
|
402
|
+
await this.appendToFile('AGENTS.md', section);
|
|
403
|
+
await this.writeJson('.codex/hooks.json', { hooks: { preToolUse: [{ tools: ['bash'], message: `code-graph: Knowledge graph exists. Read ${CONFIG.MAP_FILE} for architectural context.` }] } });
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async installOpenCode() {
|
|
407
|
+
await this.appendToFile('AGENTS.md', `\n## 🗺️ Code-Graph\nRead \`${CONFIG.MAP_FILE}\` for high-level mapping.\n`);
|
|
408
|
+
const plugin = `export default { name: 'code-graph', beforeExecute: (tool) => { if (tool.name === 'bash') return "code-graph: Read ${CONFIG.MAP_FILE} for god nodes."; } };`;
|
|
409
|
+
await this.writeFile('.opencode/plugins/code-graph.js', plugin);
|
|
410
|
+
await this.writeJson('opencode.json', { plugins: ['./.opencode/plugins/code-graph.js'] });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
async installCursor() {
|
|
414
|
+
const content = `---\ndescription: Always use knowledge graph for navigation.\nalwaysApply: true\n---\n# Code-Graph\n- Read \`${CONFIG.MAP_FILE}\` before searching.\n- Prioritize god nodes for architecture.\n- Adhere to \`${CONFIG.RULES_FILE}\`.\n`;
|
|
415
|
+
await this.writeFile('.cursor/rules/code-graph.mdc', content);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async installGemini() {
|
|
419
|
+
const skillPath = path.join(this.home, '.gemini', 'skills', 'code-graph', 'SKILL.md');
|
|
420
|
+
await fsp.mkdir(path.dirname(skillPath), { recursive: true });
|
|
421
|
+
await fsp.writeFile(skillPath, `# Code-Graph Skill\nUse \`${CONFIG.MAP_FILE}\` for navigation.\n`);
|
|
422
|
+
await this.appendToFile('GEMINI.md', `\n## 🗺️ Code-Graph\nRead \`${CONFIG.MAP_FILE}\` before file-read tools.\n`);
|
|
423
|
+
await this.writeJson('.gemini/settings.json', { hooks: { beforeTool: [{ tools: ['read_file'], message: `code-graph: Knowledge graph exists. Read ${CONFIG.MAP_FILE}.` }] } });
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async installGenericAgent(p) {
|
|
427
|
+
await this.appendToFile('AGENTS.md', `\n## 🗺️ Code-Graph\nRead \`${CONFIG.MAP_FILE}\` for structural context.\n`);
|
|
428
|
+
const globalPath = path.join(this.home, `.${p}`, 'skills', 'code-graph', 'SKILL.md');
|
|
429
|
+
await fsp.mkdir(path.dirname(globalPath), { recursive: true });
|
|
430
|
+
await fsp.writeFile(globalPath, `# Code-Graph Skill for ${p}\n`);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async installKiro() {
|
|
434
|
+
await this.writeFile('.kiro/skills/code-graph/SKILL.md', `# Code-Graph Skill\n`);
|
|
435
|
+
await this.writeFile('.kiro/steering/code-graph.md', `inclusion: always\n# Code-Graph\nRead \`${CONFIG.MAP_FILE}\`.\n`);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
async installAntigravity() {
|
|
439
|
+
await this.writeFile('.agent/rules/code-graph.md', `# Code-Graph Rules\nAlways read \`${CONFIG.MAP_FILE}\`.\n`);
|
|
440
|
+
await this.writeFile('.agent/workflows/code-graph.md', `# Code-Graph Workflow\nRegisters /code-graph\n`);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async installCopilot() {
|
|
444
|
+
const skillPath = path.join(this.home, '.copilot', 'skills', 'code-graph', 'SKILL.md');
|
|
445
|
+
await fsp.mkdir(path.dirname(skillPath), { recursive: true });
|
|
446
|
+
await fsp.writeFile(skillPath, `# Code-Graph Skill\nUse \`${CONFIG.MAP_FILE}\`.\n`);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
async installVSCode() {
|
|
450
|
+
await this.appendToFile('.github/copilot-instructions.md', `\n## 🗺️ Code-Graph\nAlways read \`${CONFIG.MAP_FILE}\` for architectural context.\n`);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
async appendToFile(filename, content) {
|
|
454
|
+
const fullPath = path.join(this.cwd, filename);
|
|
455
|
+
if (fs.existsSync(fullPath)) {
|
|
456
|
+
const existing = await fsp.readFile(fullPath, 'utf8');
|
|
457
|
+
if (!existing.includes(content.trim())) await fsp.appendFile(fullPath, content);
|
|
458
|
+
} else {
|
|
459
|
+
await fsp.writeFile(fullPath, content);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
async writeFile(filename, content) {
|
|
464
|
+
const fullPath = path.join(this.cwd, filename);
|
|
465
|
+
await fsp.mkdir(path.dirname(fullPath), { recursive: true });
|
|
466
|
+
await fsp.writeFile(fullPath, content);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
async writeJson(filename, data) {
|
|
470
|
+
const fullPath = path.join(this.cwd, filename);
|
|
471
|
+
let existing = {};
|
|
472
|
+
if (fs.existsSync(fullPath)) {
|
|
473
|
+
try { existing = JSON.parse(await fsp.readFile(fullPath, 'utf8')); } catch (e) {}
|
|
474
|
+
}
|
|
475
|
+
const merged = { ...existing, ...data };
|
|
476
|
+
await this.writeFile(filename, JSON.stringify(merged, null, 2));
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
async removeFile(filename) {
|
|
480
|
+
const fullPath = path.join(this.cwd, filename);
|
|
481
|
+
if (fs.existsSync(fullPath)) await fsp.unlink(fullPath);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
316
485
|
// --- CLI Entry Point ---
|
|
317
486
|
|
|
318
487
|
async function main() {
|
|
@@ -320,6 +489,8 @@ async function main() {
|
|
|
320
489
|
const cwd = process.cwd();
|
|
321
490
|
|
|
322
491
|
try {
|
|
492
|
+
const platforms = ['claude', 'codex', 'opencode', 'cursor', 'gemini', 'aider', 'openclaw', 'droid', 'trae', 'trae-cn', 'hermes', 'kiro', 'antigravity', 'copilot', 'vscode'];
|
|
493
|
+
|
|
323
494
|
switch (command || 'generate') {
|
|
324
495
|
case 'generate':
|
|
325
496
|
await new ProjectMapper(cwd).generate();
|
|
@@ -334,11 +505,18 @@ async function main() {
|
|
|
334
505
|
await ProjectInitializer.init(cwd);
|
|
335
506
|
await installGitHook(cwd);
|
|
336
507
|
break;
|
|
508
|
+
case 'install-skills':
|
|
509
|
+
await new SkillManager(cwd).execute(args[0], args[1]);
|
|
510
|
+
break;
|
|
337
511
|
case 'watch':
|
|
338
512
|
startWatcher(cwd);
|
|
339
513
|
break;
|
|
340
514
|
default:
|
|
341
|
-
|
|
515
|
+
if (platforms.includes(command?.toLowerCase())) {
|
|
516
|
+
await new SkillManager(cwd).execute(command, args[0]);
|
|
517
|
+
} else {
|
|
518
|
+
console.log('Usage: code-graph [generate|init|reflect|install-hook|watch|install-skills <platform>]');
|
|
519
|
+
}
|
|
342
520
|
}
|
|
343
521
|
} catch (err) {
|
|
344
522
|
console.error(`[Code-Graph] Critical Error: ${err.message}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# LLM_AGENT_PROJECT_LEARNINGS
|
|
2
2
|
> LLM AGENT MEMORY: READ BEFORE STARTING TASKS. UPDATE ON FAILURES.
|
|
3
3
|
|
|
4
4
|
## ⚠️ CRITICAL PITFALLS
|
|
@@ -10,5 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
## ✅ BEST PRACTICES
|
|
12
12
|
- [STYLE] Always include dependency counts (↑N ↓M) in `llm-code-graph.md` to help prioritize architectural understanding.
|
|
13
|
-
|
|
14
|
-
- [TOOLING: 2026-04-15] Added reflect command to simplify LLM memory updates.
|
|
13
|
+
|
|
14
|
+
- [TOOLING: 2026-04-15] Added reflect command to simplify LLM memory updates.
|
|
15
|
+
- [TOOLING: 2026-04-16] Upgraded to v3.0.0: Unified agent renaming (llm-agent-*) and added `install-skills` for automated platform integration (Claude, Cursor, Gemini, etc.).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# LLM_AGENT_RULES (STRICT PROTOCOL)
|
|
2
2
|
> This protocol is MANDATORY for all LLM agents. Failure to update memory is a failure of the task.
|
|
3
3
|
## 🧠 THE REFLECTION CYCLE
|
|
4
4
|
Every execution MUST follow this cycle:
|
|
5
|
-
1. **PRE-TASK:** Read
|
|
5
|
+
1. **PRE-TASK:** Read `llm-agent-project-learnings.md` to identify existing pitfalls.
|
|
6
6
|
2. **EXECUTION:** Monitor for "Learned Moments" (failures, unexpected behaviors, or non-obvious fixes).
|
|
7
7
|
3. **POST-TASK:** If a significant lesson was learned, run \`code-graph reflect <CAT> <LESSON>\`.
|
|
8
8
|
- **NOTE:** Routine, expected changes do not require reflections. Focus on high-signal context.
|
package/llm-code-graph.md
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# CODE_GRAPH_MAP
|
|
2
2
|
> MISSION: COMPACT PROJECT MAP FOR LLM AGENTS.
|
|
3
|
-
> PROTOCOL: Follow
|
|
3
|
+
> PROTOCOL: Follow llm-agent-rules.md | MEMORY: See llm-agent-project-learnings.md
|
|
4
4
|
> Legend: [CORE] Entry Point, (↑N) Outgoing Deps, (↓M) Incoming Dependents
|
|
5
5
|
> Notation: syms: [Name [Signature/Context]], desc: File Summary, [TAG: Context]
|
|
6
6
|
|
|
7
|
-
- [CORE] index.js (↑
|
|
8
|
-
- syms: [CONFIG [=], CodeParser [--- Core Services --- Handles extraction of symbols, edges, and metadata from source code.], ProjectInitializer [Scaffolds the initial agent-agnostic rule and reflection files.], ProjectMapper [Manages the project mapping and file generation.], ReflectionManager [Manages project reflections and lessons learned.], SUPPORTED_EXTENSIONS [: [], add [(context ? `${display} [${context}]` : display)], extract [(content)], init [(cwd)], installGitHook [(cwd)], main [|app|server|cli)\./i.test(path.basename(relPath))], processFile [(fullPath, relPath)], walk [(dir, ig)]]
|
|
7
|
+
- [CORE] index.js (↑8 ↓1) [TODO: |FIXME|BUG|DEPRECATED):?\s*(.*)/i,, bug: s or complex regex pitfalls., bug: s or version deprecations., bug: ,"] | desc: !usrbinenv node
|
|
8
|
+
- syms: [CONFIG [=], CodeParser [--- Core Services --- Handles extraction of symbols, edges, and metadata from source code.], ProjectInitializer [Scaffolds the initial agent-agnostic rule and reflection files.], ProjectMapper [Manages the project mapping and file generation.], ReflectionManager [Manages project reflections and lessons learned.], SUPPORTED_EXTENSIONS [: [], SkillManager [Manages platform-specific skills and agent integrations.], add [(context ? `${display} [${context}]` : display)], appendToFile [('CLAUDE.md', section)], execute [(platform, action)], extract [(content)], init [(cwd)], install [|uninstall]')], installAntigravity [()], installClaude [()], installCodex [()], installCopilot [()], installCursor [()], installGemini [()], installGenericAgent [(p)], installGitHook [(cwd)], installKiro [()], installOpenCode [()], installVSCode [()], main [|app|server|cli)\./i.test(path.basename(relPath))], processFile [(fullPath, relPath)], removeFile [('CLAUDE.md')], uninstall []')], walk [(dir, ig)], writeFile [(path.join(this.cwd, CONFIG.MAP_FILE)], writeJson [('.claude/settings.json', { hooks: { preToolUse: [{ tools: ['glob', 'grep'], message: `code-graph: Knowledge graph exists. Read ${CONFIG.MAP_FILE} before searching raw files.` }] } })]]
|
|
9
9
|
- [CORE] test/index.test.js (↑10 ↓0) | desc:
|
|
10
10
|
- syms: []
|
|
11
11
|
|
|
12
12
|
## GRAPH EDGES
|
|
13
|
+
[index.js] -> [imports] -> [bash]
|
|
13
14
|
[index.js] -> [imports] -> [chokidar]
|
|
14
15
|
[index.js] -> [imports] -> [fs]
|
|
15
16
|
[index.js] -> [imports] -> [ignore]
|
|
17
|
+
[index.js] -> [imports] -> [os]
|
|
16
18
|
[index.js] -> [imports] -> [path]
|
|
17
19
|
[index.js] -> [imports] -> [symbols]
|
|
18
20
|
[index.js] -> [imports] -> [url]
|
package/package.json
CHANGED
package/test/index.test.js
CHANGED
|
@@ -121,8 +121,8 @@ test('ProjectMapper - Format Output Header', () => {
|
|
|
121
121
|
const output = mapper.formatOutput();
|
|
122
122
|
|
|
123
123
|
assert.ok(output.includes('MISSION: COMPACT PROJECT MAP FOR LLM AGENTS.'));
|
|
124
|
-
assert.ok(output.includes('PROTOCOL: Follow
|
|
125
|
-
assert.ok(output.includes('MEMORY: See
|
|
124
|
+
assert.ok(output.includes('PROTOCOL: Follow llm-agent-rules.md'));
|
|
125
|
+
assert.ok(output.includes('MEMORY: See llm-agent-project-learnings.md'));
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
test('Recursive Ignore Simulation (Logic Check)', async () => {
|