@colbymchenry/codegraph 0.7.6 → 0.7.9
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 +35 -10
- package/dist/bin/codegraph.js +72 -4
- package/dist/bin/codegraph.js.map +1 -1
- package/dist/bin/uninstall.d.ts +7 -7
- package/dist/bin/uninstall.d.ts.map +1 -1
- package/dist/bin/uninstall.js +23 -135
- package/dist/bin/uninstall.js.map +1 -1
- package/dist/installer/claude-md-template.d.ts +10 -6
- package/dist/installer/claude-md-template.d.ts.map +1 -1
- package/dist/installer/claude-md-template.js +15 -40
- package/dist/installer/claude-md-template.js.map +1 -1
- package/dist/installer/config-writer.d.ts +17 -24
- package/dist/installer/config-writer.d.ts.map +1 -1
- package/dist/installer/config-writer.js +44 -239
- package/dist/installer/config-writer.js.map +1 -1
- package/dist/installer/index.d.ts +45 -4
- package/dist/installer/index.d.ts.map +1 -1
- package/dist/installer/index.js +214 -78
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/instructions-template.d.ts +28 -0
- package/dist/installer/instructions-template.d.ts.map +1 -0
- package/dist/installer/instructions-template.js +63 -0
- package/dist/installer/instructions-template.js.map +1 -0
- package/dist/installer/targets/claude.d.ts +27 -0
- package/dist/installer/targets/claude.d.ts.map +1 -0
- package/dist/installer/targets/claude.js +246 -0
- package/dist/installer/targets/claude.js.map +1 -0
- package/dist/installer/targets/codex.d.ts +18 -0
- package/dist/installer/targets/codex.d.ts.map +1 -0
- package/dist/installer/targets/codex.js +185 -0
- package/dist/installer/targets/codex.js.map +1 -0
- package/dist/installer/targets/cursor.d.ts +35 -0
- package/dist/installer/targets/cursor.d.ts.map +1 -0
- package/dist/installer/targets/cursor.js +229 -0
- package/dist/installer/targets/cursor.js.map +1 -0
- package/dist/installer/targets/opencode.d.ts +30 -0
- package/dist/installer/targets/opencode.d.ts.map +1 -0
- package/dist/installer/targets/opencode.js +235 -0
- package/dist/installer/targets/opencode.js.map +1 -0
- package/dist/installer/targets/registry.d.ts +35 -0
- package/dist/installer/targets/registry.d.ts.map +1 -0
- package/dist/installer/targets/registry.js +83 -0
- package/dist/installer/targets/registry.js.map +1 -0
- package/dist/installer/targets/shared.d.ts +77 -0
- package/dist/installer/targets/shared.d.ts.map +1 -0
- package/dist/installer/targets/shared.js +246 -0
- package/dist/installer/targets/shared.js.map +1 -0
- package/dist/installer/targets/toml.d.ts +52 -0
- package/dist/installer/targets/toml.d.ts.map +1 -0
- package/dist/installer/targets/toml.js +147 -0
- package/dist/installer/targets/toml.js.map +1 -0
- package/dist/installer/targets/types.d.ts +116 -0
- package/dist/installer/targets/types.d.ts.map +1 -0
- package/dist/installer/targets/types.js +16 -0
- package/dist/installer/targets/types.js.map +1 -0
- package/package.json +2 -1
- package/scripts/local-install.sh +41 -0
- package/scripts/release.sh +70 -0
|
@@ -1,46 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Backwards-compat re-export shim.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* The instructions template moved to `instructions-template.ts` so it
|
|
6
|
+
* can be shared across all agent targets (Claude Code, Cursor, Codex
|
|
7
|
+
* CLI, opencode). This file is preserved purely so existing imports
|
|
8
|
+
* (`@colbymchenry/codegraph` consumers, downstream tooling) keep
|
|
9
|
+
* working unchanged. New code should import from
|
|
10
|
+
* `./instructions-template` directly.
|
|
11
|
+
*
|
|
12
|
+
* @deprecated Import from `./instructions-template` instead.
|
|
7
13
|
*/
|
|
8
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.CLAUDE_MD_TEMPLATE = exports.CODEGRAPH_SECTION_END = exports.CODEGRAPH_SECTION_START = void 0;
|
|
10
|
-
|
|
11
|
-
exports
|
|
12
|
-
exports
|
|
13
|
-
exports
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
CodeGraph builds a semantic knowledge graph of codebases for faster, smarter code exploration.
|
|
17
|
-
|
|
18
|
-
### If \`.codegraph/\` exists in the project
|
|
19
|
-
|
|
20
|
-
**NEVER call \`codegraph_explore\` or \`codegraph_context\` directly in the main session.** These tools return large amounts of source code that fills up main session context. Instead, ALWAYS spawn an Explore agent for any exploration question (e.g., "how does X work?", "explain the Y system", "where is Z implemented?").
|
|
21
|
-
|
|
22
|
-
**When spawning Explore agents**, include this instruction in the prompt:
|
|
23
|
-
|
|
24
|
-
> This project has CodeGraph initialized (.codegraph/ exists). Use \`codegraph_explore\` as your PRIMARY tool — it returns full source code sections from all relevant files in one call.
|
|
25
|
-
>
|
|
26
|
-
> **Rules:**
|
|
27
|
-
> 1. Follow the explore call budget in the \`codegraph_explore\` tool description — it scales automatically based on project size.
|
|
28
|
-
> 2. Do NOT re-read files that codegraph_explore already returned source code for. The source sections are complete and authoritative.
|
|
29
|
-
> 3. Only fall back to grep/glob/read for files listed under "Additional relevant files" if you need more detail, or if codegraph returned no results.
|
|
30
|
-
|
|
31
|
-
**The main session may only use these lightweight tools directly** (for targeted lookups before making edits, not for exploration):
|
|
32
|
-
|
|
33
|
-
| Tool | Use For |
|
|
34
|
-
|------|---------|
|
|
35
|
-
| \`codegraph_search\` | Find symbols by name |
|
|
36
|
-
| \`codegraph_callers\` / \`codegraph_callees\` | Trace call flow |
|
|
37
|
-
| \`codegraph_impact\` | Check what's affected before editing |
|
|
38
|
-
| \`codegraph_node\` | Get a single symbol's details |
|
|
39
|
-
|
|
40
|
-
### If \`.codegraph/\` does NOT exist
|
|
41
|
-
|
|
42
|
-
At the start of a session, ask the user if they'd like to initialize CodeGraph:
|
|
43
|
-
|
|
44
|
-
"I notice this project doesn't have CodeGraph initialized. Would you like me to run \`codegraph init -i\` to build a code knowledge graph?"
|
|
45
|
-
${exports.CODEGRAPH_SECTION_END}`;
|
|
15
|
+
exports.INSTRUCTIONS_TEMPLATE = exports.CLAUDE_MD_TEMPLATE = exports.CODEGRAPH_SECTION_END = exports.CODEGRAPH_SECTION_START = void 0;
|
|
16
|
+
var instructions_template_1 = require("./instructions-template");
|
|
17
|
+
Object.defineProperty(exports, "CODEGRAPH_SECTION_START", { enumerable: true, get: function () { return instructions_template_1.CODEGRAPH_SECTION_START; } });
|
|
18
|
+
Object.defineProperty(exports, "CODEGRAPH_SECTION_END", { enumerable: true, get: function () { return instructions_template_1.CODEGRAPH_SECTION_END; } });
|
|
19
|
+
Object.defineProperty(exports, "CLAUDE_MD_TEMPLATE", { enumerable: true, get: function () { return instructions_template_1.CLAUDE_MD_TEMPLATE; } });
|
|
20
|
+
Object.defineProperty(exports, "INSTRUCTIONS_TEMPLATE", { enumerable: true, get: function () { return instructions_template_1.INSTRUCTIONS_TEMPLATE; } });
|
|
46
21
|
//# sourceMappingURL=claude-md-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-md-template.js","sourceRoot":"","sources":["../../src/installer/claude-md-template.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"claude-md-template.js","sourceRoot":"","sources":["../../src/installer/claude-md-template.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAEH,iEAKiC;AAJ/B,gIAAA,uBAAuB,OAAA;AACvB,8HAAA,qBAAqB,OAAA;AACrB,2HAAA,kBAAkB,OAAA;AAClB,8HAAA,qBAAqB,OAAA"}
|
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Backwards-compat shim — original Claude-only writer functions.
|
|
3
|
+
*
|
|
4
|
+
* The installer now uses the multi-target architecture in
|
|
5
|
+
* `./targets/`. This file is preserved so existing imports (the test
|
|
6
|
+
* suite, downstream tooling) keep working unchanged. Each function
|
|
7
|
+
* delegates to the Claude target. New code should import the target
|
|
8
|
+
* registry from `./targets/registry` directly.
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use `targets/registry.ts` and the `AgentTarget`
|
|
11
|
+
* abstraction instead.
|
|
4
12
|
*/
|
|
5
13
|
export type InstallLocation = 'global' | 'local';
|
|
6
14
|
/**
|
|
7
|
-
*
|
|
15
|
+
* Each shim calls ONLY the named per-file helper — writeMcpConfig
|
|
16
|
+
* writes only the MCP JSON, writePermissions only settings.json,
|
|
17
|
+
* writeClaudeMd only CLAUDE.md. The full multi-file install lives
|
|
18
|
+
* in `claudeTarget.install()` which the new orchestrator uses.
|
|
8
19
|
*/
|
|
9
20
|
export declare function writeMcpConfig(location: InstallLocation): void;
|
|
10
|
-
/**
|
|
11
|
-
* Write permissions to settings.json
|
|
12
|
-
*/
|
|
13
21
|
export declare function writePermissions(location: InstallLocation): void;
|
|
14
|
-
/**
|
|
15
|
-
* Check if MCP config already exists for CodeGraph
|
|
16
|
-
*/
|
|
17
|
-
export declare function hasMcpConfig(location: InstallLocation): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* Check if permissions already exist for CodeGraph
|
|
20
|
-
*/
|
|
21
|
-
export declare function hasPermissions(location: InstallLocation): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Check if CLAUDE.md has CodeGraph section
|
|
24
|
-
*/
|
|
25
|
-
export declare function hasClaudeMdSection(location: InstallLocation): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Write or update CLAUDE.md with CodeGraph instructions
|
|
28
|
-
*
|
|
29
|
-
* If the file exists and has a CodeGraph section (marked or unmarked),
|
|
30
|
-
* it will be replaced. Otherwise, the template is appended.
|
|
31
|
-
*/
|
|
32
22
|
export declare function writeClaudeMd(location: InstallLocation): {
|
|
33
23
|
created: boolean;
|
|
34
24
|
updated: boolean;
|
|
35
25
|
};
|
|
26
|
+
export declare function hasMcpConfig(location: InstallLocation): boolean;
|
|
27
|
+
export declare function hasPermissions(location: InstallLocation): boolean;
|
|
28
|
+
export declare function hasClaudeMdSection(location: InstallLocation): boolean;
|
|
36
29
|
//# sourceMappingURL=config-writer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-writer.d.ts","sourceRoot":"","sources":["../../src/installer/config-writer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"config-writer.d.ts","sourceRoot":"","sources":["../../src/installer/config-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAYH,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAE9D;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAEhE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,eAAe,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAM/F;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAM/D;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAQjE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAWrE"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Backwards-compat shim — original Claude-only writer functions.
|
|
4
|
+
*
|
|
5
|
+
* The installer now uses the multi-target architecture in
|
|
6
|
+
* `./targets/`. This file is preserved so existing imports (the test
|
|
7
|
+
* suite, downstream tooling) keep working unchanged. Each function
|
|
8
|
+
* delegates to the Claude target. New code should import the target
|
|
9
|
+
* registry from `./targets/registry` directly.
|
|
10
|
+
*
|
|
11
|
+
* @deprecated Use `targets/registry.ts` and the `AgentTarget`
|
|
12
|
+
* abstraction instead.
|
|
5
13
|
*/
|
|
6
14
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
15
|
if (k2 === undefined) k2 = k;
|
|
@@ -39,266 +47,63 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
39
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
48
|
exports.writeMcpConfig = writeMcpConfig;
|
|
41
49
|
exports.writePermissions = writePermissions;
|
|
50
|
+
exports.writeClaudeMd = writeClaudeMd;
|
|
42
51
|
exports.hasMcpConfig = hasMcpConfig;
|
|
43
52
|
exports.hasPermissions = hasPermissions;
|
|
44
53
|
exports.hasClaudeMdSection = hasClaudeMdSection;
|
|
45
|
-
exports.writeClaudeMd = writeClaudeMd;
|
|
46
54
|
const fs = __importStar(require("fs"));
|
|
47
55
|
const path = __importStar(require("path"));
|
|
48
56
|
const os = __importStar(require("os"));
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
* Get the path to the Claude config directory
|
|
52
|
-
*/
|
|
53
|
-
function getClaudeConfigDir(location) {
|
|
54
|
-
if (location === 'global') {
|
|
55
|
-
return path.join(os.homedir(), '.claude');
|
|
56
|
-
}
|
|
57
|
-
return path.join(process.cwd(), '.claude');
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Get the path to the claude.json file
|
|
61
|
-
* - Global: ~/.claude.json (root level)
|
|
62
|
-
* - Local: ./.claude.json (project root)
|
|
63
|
-
*/
|
|
64
|
-
function getClaudeJsonPath(location) {
|
|
65
|
-
if (location === 'global') {
|
|
66
|
-
return path.join(os.homedir(), '.claude.json');
|
|
67
|
-
}
|
|
68
|
-
return path.join(process.cwd(), '.claude.json');
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Get the path to the settings.json file
|
|
72
|
-
* - Global: ~/.claude/settings.json
|
|
73
|
-
* - Local: ./.claude/settings.json
|
|
74
|
-
*/
|
|
75
|
-
function getSettingsJsonPath(location) {
|
|
76
|
-
const configDir = getClaudeConfigDir(location);
|
|
77
|
-
return path.join(configDir, 'settings.json');
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Read a JSON file, returning an empty object if it doesn't exist.
|
|
81
|
-
* Distinguishes between missing files (returns {}) and corrupted
|
|
82
|
-
* files (logs warning, returns {}).
|
|
83
|
-
*/
|
|
84
|
-
function readJsonFile(filePath) {
|
|
85
|
-
if (!fs.existsSync(filePath)) {
|
|
86
|
-
return {};
|
|
87
|
-
}
|
|
88
|
-
try {
|
|
89
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
90
|
-
return JSON.parse(content);
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
94
|
-
console.warn(` Warning: Could not parse ${path.basename(filePath)}: ${msg}`);
|
|
95
|
-
console.warn(` A backup will be created before overwriting.`);
|
|
96
|
-
// Create a backup of the corrupted file
|
|
97
|
-
try {
|
|
98
|
-
const backupPath = filePath + '.backup';
|
|
99
|
-
fs.copyFileSync(filePath, backupPath);
|
|
100
|
-
}
|
|
101
|
-
catch { /* ignore backup failure */ }
|
|
102
|
-
return {};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
57
|
+
const claude_1 = require("./targets/claude");
|
|
58
|
+
const shared_1 = require("./targets/shared");
|
|
105
59
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
60
|
+
* Each shim calls ONLY the named per-file helper — writeMcpConfig
|
|
61
|
+
* writes only the MCP JSON, writePermissions only settings.json,
|
|
62
|
+
* writeClaudeMd only CLAUDE.md. The full multi-file install lives
|
|
63
|
+
* in `claudeTarget.install()` which the new orchestrator uses.
|
|
108
64
|
*/
|
|
109
|
-
function
|
|
110
|
-
|
|
111
|
-
if (!fs.existsSync(dir)) {
|
|
112
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
113
|
-
}
|
|
114
|
-
const tmpPath = filePath + '.tmp.' + process.pid;
|
|
115
|
-
try {
|
|
116
|
-
fs.writeFileSync(tmpPath, content);
|
|
117
|
-
fs.renameSync(tmpPath, filePath);
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
// Clean up temp file on failure
|
|
121
|
-
try {
|
|
122
|
-
fs.unlinkSync(tmpPath);
|
|
123
|
-
}
|
|
124
|
-
catch { /* ignore */ }
|
|
125
|
-
throw err;
|
|
126
|
-
}
|
|
65
|
+
function writeMcpConfig(location) {
|
|
66
|
+
(0, claude_1.writeMcpEntry)(location);
|
|
127
67
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*/
|
|
131
|
-
function writeJsonFile(filePath, data) {
|
|
132
|
-
atomicWriteFileSync(filePath, JSON.stringify(data, null, 2) + '\n');
|
|
68
|
+
function writePermissions(location) {
|
|
69
|
+
(0, claude_1.writePermissionsEntry)(location);
|
|
133
70
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
*/
|
|
137
|
-
function getMcpServerConfig() {
|
|
71
|
+
function writeClaudeMd(location) {
|
|
72
|
+
const file = (0, claude_1.writeInstructionsEntry)(location);
|
|
138
73
|
return {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
args: ['serve', '--mcp'],
|
|
74
|
+
created: file.action === 'created',
|
|
75
|
+
updated: file.action === 'updated',
|
|
142
76
|
};
|
|
143
77
|
}
|
|
144
|
-
/**
|
|
145
|
-
* Write the MCP server configuration to claude.json
|
|
146
|
-
*/
|
|
147
|
-
function writeMcpConfig(location) {
|
|
148
|
-
const claudeJsonPath = getClaudeJsonPath(location);
|
|
149
|
-
const config = readJsonFile(claudeJsonPath);
|
|
150
|
-
// Ensure mcpServers object exists
|
|
151
|
-
if (!config.mcpServers) {
|
|
152
|
-
config.mcpServers = {};
|
|
153
|
-
}
|
|
154
|
-
// Add or update codegraph server
|
|
155
|
-
config.mcpServers.codegraph = getMcpServerConfig();
|
|
156
|
-
writeJsonFile(claudeJsonPath, config);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Get the list of permissions for CodeGraph tools
|
|
160
|
-
*/
|
|
161
|
-
function getCodeGraphPermissions() {
|
|
162
|
-
return [
|
|
163
|
-
'mcp__codegraph__codegraph_search',
|
|
164
|
-
'mcp__codegraph__codegraph_context',
|
|
165
|
-
'mcp__codegraph__codegraph_callers',
|
|
166
|
-
'mcp__codegraph__codegraph_callees',
|
|
167
|
-
'mcp__codegraph__codegraph_impact',
|
|
168
|
-
'mcp__codegraph__codegraph_node',
|
|
169
|
-
'mcp__codegraph__codegraph_status',
|
|
170
|
-
];
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Write permissions to settings.json
|
|
174
|
-
*/
|
|
175
|
-
function writePermissions(location) {
|
|
176
|
-
const settingsPath = getSettingsJsonPath(location);
|
|
177
|
-
const settings = readJsonFile(settingsPath);
|
|
178
|
-
// Ensure permissions object exists
|
|
179
|
-
if (!settings.permissions) {
|
|
180
|
-
settings.permissions = {};
|
|
181
|
-
}
|
|
182
|
-
// Ensure allow array exists
|
|
183
|
-
if (!Array.isArray(settings.permissions.allow)) {
|
|
184
|
-
settings.permissions.allow = [];
|
|
185
|
-
}
|
|
186
|
-
// Add CodeGraph permissions (avoiding duplicates)
|
|
187
|
-
const codegraphPermissions = getCodeGraphPermissions();
|
|
188
|
-
for (const permission of codegraphPermissions) {
|
|
189
|
-
if (!settings.permissions.allow.includes(permission)) {
|
|
190
|
-
settings.permissions.allow.push(permission);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
writeJsonFile(settingsPath, settings);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Check if MCP config already exists for CodeGraph
|
|
197
|
-
*/
|
|
198
78
|
function hasMcpConfig(location) {
|
|
199
|
-
const
|
|
200
|
-
|
|
79
|
+
const file = location === 'global'
|
|
80
|
+
? path.join(os.homedir(), '.claude.json')
|
|
81
|
+
: path.join(process.cwd(), '.claude.json');
|
|
82
|
+
const config = (0, shared_1.readJsonFile)(file);
|
|
201
83
|
return !!config.mcpServers?.codegraph;
|
|
202
84
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Check if permissions already exist for CodeGraph
|
|
205
|
-
*/
|
|
206
85
|
function hasPermissions(location) {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
86
|
+
const file = location === 'global'
|
|
87
|
+
? path.join(os.homedir(), '.claude', 'settings.json')
|
|
88
|
+
: path.join(process.cwd(), '.claude', 'settings.json');
|
|
89
|
+
const settings = (0, shared_1.readJsonFile)(file);
|
|
90
|
+
const allow = settings.permissions?.allow;
|
|
91
|
+
if (!Array.isArray(allow))
|
|
211
92
|
return false;
|
|
212
|
-
|
|
213
|
-
// Check if at least one CodeGraph permission exists
|
|
214
|
-
return permissions.some((p) => p.startsWith('mcp__codegraph__'));
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Get the path to CLAUDE.md
|
|
218
|
-
* - Global: ~/.claude/CLAUDE.md
|
|
219
|
-
* - Local: ./.claude/CLAUDE.md
|
|
220
|
-
*/
|
|
221
|
-
function getClaudeMdPath(location) {
|
|
222
|
-
const configDir = getClaudeConfigDir(location);
|
|
223
|
-
return path.join(configDir, 'CLAUDE.md');
|
|
93
|
+
return allow.some((p) => p.startsWith('mcp__codegraph__'));
|
|
224
94
|
}
|
|
225
|
-
/**
|
|
226
|
-
* Check if CLAUDE.md has CodeGraph section
|
|
227
|
-
*/
|
|
228
95
|
function hasClaudeMdSection(location) {
|
|
229
|
-
const
|
|
96
|
+
const file = location === 'global'
|
|
97
|
+
? path.join(os.homedir(), '.claude', 'CLAUDE.md')
|
|
98
|
+
: path.join(process.cwd(), '.claude', 'CLAUDE.md');
|
|
230
99
|
try {
|
|
231
|
-
if (fs.existsSync(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
100
|
+
if (!fs.existsSync(file))
|
|
101
|
+
return false;
|
|
102
|
+
const content = fs.readFileSync(file, 'utf-8');
|
|
103
|
+
return content.includes('<!-- CODEGRAPH_START -->') || content.includes('## CodeGraph');
|
|
235
104
|
}
|
|
236
105
|
catch {
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Write or update CLAUDE.md with CodeGraph instructions
|
|
243
|
-
*
|
|
244
|
-
* If the file exists and has a CodeGraph section (marked or unmarked),
|
|
245
|
-
* it will be replaced. Otherwise, the template is appended.
|
|
246
|
-
*/
|
|
247
|
-
function writeClaudeMd(location) {
|
|
248
|
-
const claudeMdPath = getClaudeMdPath(location);
|
|
249
|
-
const configDir = getClaudeConfigDir(location);
|
|
250
|
-
// Ensure directory exists
|
|
251
|
-
if (!fs.existsSync(configDir)) {
|
|
252
|
-
fs.mkdirSync(configDir, { recursive: true });
|
|
253
|
-
}
|
|
254
|
-
// Check if file exists
|
|
255
|
-
if (!fs.existsSync(claudeMdPath)) {
|
|
256
|
-
// Create new file with just the CodeGraph section
|
|
257
|
-
atomicWriteFileSync(claudeMdPath, claude_md_template_1.CLAUDE_MD_TEMPLATE + '\n');
|
|
258
|
-
return { created: true, updated: false };
|
|
259
|
-
}
|
|
260
|
-
// Read existing content
|
|
261
|
-
let content = fs.readFileSync(claudeMdPath, 'utf-8');
|
|
262
|
-
// Check for marked section (from previous installer)
|
|
263
|
-
if (content.includes(claude_md_template_1.CODEGRAPH_SECTION_START)) {
|
|
264
|
-
// Replace the marked section
|
|
265
|
-
const startIdx = content.indexOf(claude_md_template_1.CODEGRAPH_SECTION_START);
|
|
266
|
-
const endIdx = content.indexOf(claude_md_template_1.CODEGRAPH_SECTION_END);
|
|
267
|
-
if (endIdx > startIdx) {
|
|
268
|
-
// Replace existing marked section
|
|
269
|
-
const before = content.substring(0, startIdx);
|
|
270
|
-
const after = content.substring(endIdx + claude_md_template_1.CODEGRAPH_SECTION_END.length);
|
|
271
|
-
content = before + claude_md_template_1.CLAUDE_MD_TEMPLATE + after;
|
|
272
|
-
atomicWriteFileSync(claudeMdPath, content);
|
|
273
|
-
return { created: false, updated: true };
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
// Check for unmarked "## CodeGraph" section (from manual setup)
|
|
277
|
-
const codegraphHeaderRegex = /\n## CodeGraph\n/;
|
|
278
|
-
const match = content.match(codegraphHeaderRegex);
|
|
279
|
-
if (match && match.index !== undefined) {
|
|
280
|
-
// Find the end of the CodeGraph section (next h2 header or end of file)
|
|
281
|
-
// Use negative lookahead (?!#) to match "## X" but not "### X"
|
|
282
|
-
const sectionStart = match.index;
|
|
283
|
-
const afterSection = content.substring(sectionStart + 1);
|
|
284
|
-
const nextHeaderMatch = afterSection.match(/\n## (?!#)/);
|
|
285
|
-
let sectionEnd;
|
|
286
|
-
if (nextHeaderMatch && nextHeaderMatch.index !== undefined) {
|
|
287
|
-
sectionEnd = sectionStart + 1 + nextHeaderMatch.index;
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
sectionEnd = content.length;
|
|
291
|
-
}
|
|
292
|
-
// Replace the section
|
|
293
|
-
const before = content.substring(0, sectionStart);
|
|
294
|
-
const after = content.substring(sectionEnd);
|
|
295
|
-
content = before + '\n' + claude_md_template_1.CLAUDE_MD_TEMPLATE + after;
|
|
296
|
-
atomicWriteFileSync(claudeMdPath, content);
|
|
297
|
-
return { created: false, updated: true };
|
|
106
|
+
return false;
|
|
298
107
|
}
|
|
299
|
-
// No existing section, append to end
|
|
300
|
-
content = content.trimEnd() + '\n\n' + claude_md_template_1.CLAUDE_MD_TEMPLATE + '\n';
|
|
301
|
-
atomicWriteFileSync(claudeMdPath, content);
|
|
302
|
-
return { created: false, updated: false };
|
|
303
108
|
}
|
|
304
109
|
//# sourceMappingURL=config-writer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-writer.js","sourceRoot":"","sources":["../../src/installer/config-writer.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"config-writer.js","sourceRoot":"","sources":["../../src/installer/config-writer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBH,wCAEC;AAED,4CAEC;AAED,sCAMC;AAED,oCAMC;AAED,wCAQC;AAED,gDAWC;AA/DD,uCAAyB;AACzB,2CAA6B;AAC7B,uCAAyB;AACzB,6CAI0B;AAC1B,6CAAgD;AAIhD;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,QAAyB;IACtD,IAAA,sBAAa,EAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,gBAAgB,CAAC,QAAyB;IACxD,IAAA,8BAAqB,EAAC,QAAQ,CAAC,CAAC;AAClC,CAAC;AAED,SAAgB,aAAa,CAAC,QAAyB;IACrD,MAAM,IAAI,GAAG,IAAA,+BAAsB,EAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO;QACL,OAAO,EAAE,IAAI,CAAC,MAAM,KAAK,SAAS;QAClC,OAAO,EAAE,IAAI,CAAC,MAAM,KAAK,SAAS;KACnC,CAAC;AACJ,CAAC;AAED,SAAgB,YAAY,CAAC,QAAyB;IACpD,MAAM,IAAI,GAAG,QAAQ,KAAK,QAAQ;QAChC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC;QACzC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC;IAC7C,MAAM,MAAM,GAAG,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;IAClC,OAAO,CAAC,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC;AACxC,CAAC;AAED,SAAgB,cAAc,CAAC,QAAyB;IACtD,MAAM,IAAI,GAAG,QAAQ,KAAK,QAAQ;QAChC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,eAAe,CAAC;QACrD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,IAAA,qBAAY,EAAC,IAAI,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;IAC1C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,SAAgB,kBAAkB,CAAC,QAAyB;IAC1D,MAAM,IAAI,GAAG,QAAQ,KAAK,QAAQ;QAChC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,WAAW,CAAC;QACjD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IACrD,IAAI,CAAC;QACH,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACvC,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/C,OAAO,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC1F,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -1,12 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CodeGraph Interactive Installer
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Multi-target: writes MCP server config + instructions for the
|
|
5
|
+
* agents the user picks (Claude Code, Cursor, Codex CLI, opencode).
|
|
6
|
+
* Defaults to the Claude-only behavior for backwards compatibility
|
|
7
|
+
* when no targets are explicitly chosen and nothing else is detected.
|
|
8
|
+
*
|
|
9
|
+
* Uses @clack/prompts for the interactive UI; `runInstallerWithOptions`
|
|
10
|
+
* is the non-interactive entry point used by the `--target` /
|
|
11
|
+
* `--print-config` CLI flags.
|
|
5
12
|
*/
|
|
6
|
-
import type {
|
|
13
|
+
import type { AgentTarget, Location, WriteResult } from './targets/types';
|
|
14
|
+
export { writeMcpConfig, writePermissions, writeClaudeMd, hasMcpConfig, hasPermissions, hasClaudeMdSection, } from './config-writer';
|
|
15
|
+
export type { InstallLocation } from './config-writer';
|
|
16
|
+
export interface RunInstallerOptions {
|
|
17
|
+
/** Comma-separated target list, or `auto` / `all` / `none`. */
|
|
18
|
+
target?: string;
|
|
19
|
+
/** Skip the location prompt; use this value directly. */
|
|
20
|
+
location?: Location;
|
|
21
|
+
/** Skip the auto-allow prompt; use this value directly. */
|
|
22
|
+
autoAllow?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Skip every confirm and use defaults: location=global,
|
|
25
|
+
* autoAllow=true, target=auto. For scripting / CI.
|
|
26
|
+
*/
|
|
27
|
+
yes?: boolean;
|
|
28
|
+
}
|
|
7
29
|
/**
|
|
8
|
-
*
|
|
30
|
+
* Interactive entry point — preserves the historical UX (`codegraph
|
|
31
|
+
* install` with no args goes through the prompts), but now starts
|
|
32
|
+
* the targets multi-select pre-populated with detected agents.
|
|
9
33
|
*/
|
|
10
34
|
export declare function runInstaller(): Promise<void>;
|
|
11
|
-
export
|
|
35
|
+
export declare function runInstallerWithOptions(opts: RunInstallerOptions): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* For every target that has a global config and exposes
|
|
38
|
+
* `wireProjectSurfaces`, write its project-local surfaces (e.g.
|
|
39
|
+
* Cursor's `.cursor/rules/codegraph.mdc`). Idempotent — runs
|
|
40
|
+
* silently when there's nothing to write.
|
|
41
|
+
*
|
|
42
|
+
* Called by `codegraph init` so that a user who ran
|
|
43
|
+
* `codegraph install` once globally doesn't have to re-run it per
|
|
44
|
+
* project to get full agent support.
|
|
45
|
+
*
|
|
46
|
+
* Returns the list of `(target, file)` pairs that were created or
|
|
47
|
+
* updated — caller decides how to surface them.
|
|
48
|
+
*/
|
|
49
|
+
export declare function wireProjectSurfacesForGlobalAgents(): Array<{
|
|
50
|
+
target: AgentTarget;
|
|
51
|
+
file: WriteResult['files'][number];
|
|
52
|
+
}>;
|
|
12
53
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/installer/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/installer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAWH,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAK1E,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAsBvD,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAElD;AAED,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkItF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kCAAkC,IAAI,KAAK,CAAC;IAC1D,MAAM,EAAE,WAAW,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC,CAcD"}
|