cartotree 0.2.0 → 0.2.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/.claude-plugin/marketplace.json +11 -11
- package/.claude-plugin/plugin.json +12 -12
- package/LICENSE +20 -20
- package/README.md +270 -246
- package/bin/cartotree.js +162 -162
- package/hooks/hooks.json +14 -14
- package/package.json +45 -45
- package/skills/cartotree/SKILL.md +32 -32
- package/src/ai.js +112 -112
- package/src/atlas/cache.js +46 -46
- package/src/atlas/files.js +56 -56
- package/src/atlas/git.js +65 -65
- package/src/atlas/init.js +114 -114
- package/src/atlas/links.js +87 -87
- package/src/atlas/locate.js +218 -218
- package/src/atlas/mcp.js +106 -106
- package/src/atlas/peek.js +24 -24
- package/src/atlas/symbols.js +41 -41
- package/src/clipboard.js +10 -10
- package/src/config.js +25 -25
- package/src/exports.js +73 -73
- package/src/ignore.js +30 -30
- package/src/sync.js +29 -29
- package/src/tree.js +96 -96
package/bin/cartotree.js
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { program } = require('commander');
|
|
4
|
-
const { generateTree } = require('../src/tree');
|
|
5
|
-
const { generateAI, generateJSON } = require('../src/ai');
|
|
6
|
-
const { syncToFile } = require('../src/sync');
|
|
7
|
-
const { copyToClipboard } = require('../src/clipboard');
|
|
8
|
-
const { loadIgnorePatterns } = require('../src/ignore');
|
|
9
|
-
const { loadConfig } = require('../src/config');
|
|
10
|
-
const { version } = require('../package.json');
|
|
11
|
-
|
|
12
|
-
program
|
|
13
|
-
.name('cartotree')
|
|
14
|
-
.description('AI-friendly annotated directory tree + code navigation for agents')
|
|
15
|
-
.version(version)
|
|
16
|
-
.option('-d, --depth <number>', 'max depth')
|
|
17
|
-
.option('-e, --exclude <patterns>', 'exclude patterns (comma-separated)')
|
|
18
|
-
.option('--ai', 'AI-optimized compact format')
|
|
19
|
-
.option('--json', 'JSON format')
|
|
20
|
-
.option('--no-exports', 'disable export parsing')
|
|
21
|
-
.option('--copy', 'copy to clipboard')
|
|
22
|
-
.option('--sync [file]', 'sync to CLAUDE.md or specified file')
|
|
23
|
-
.option('--full', 'no depth limit')
|
|
24
|
-
.action(opts => {
|
|
25
|
-
const config = loadConfig(process.cwd());
|
|
26
|
-
const depth = opts.full ? Infinity : parseInt(opts.depth ?? config.depth);
|
|
27
|
-
const useAI = opts.ai || config.ai;
|
|
28
|
-
const useJSON = opts.json || config.json;
|
|
29
|
-
const useCopy = opts.copy || config.copy;
|
|
30
|
-
const useSync = opts.sync || config.sync;
|
|
31
|
-
const showExports = opts.exports ?? config.exports;
|
|
32
|
-
|
|
33
|
-
const ignorePatterns = loadIgnorePatterns(process.cwd());
|
|
34
|
-
const manualExclude = opts.exclude ? opts.exclude.split(',').map(s => s.trim()) : [];
|
|
35
|
-
const exclude = [...new Set([...ignorePatterns, ...manualExclude])];
|
|
36
|
-
const target = typeof useSync === 'string' ? useSync : 'CLAUDE.md';
|
|
37
|
-
|
|
38
|
-
let output;
|
|
39
|
-
if (useAI) output = generateAI(process.cwd(), { depth, exclude, showExports });
|
|
40
|
-
else if (useJSON) output = generateJSON(process.cwd(), { depth, exclude, showExports });
|
|
41
|
-
else output = generateTree(process.cwd(), { depth, exclude, showExports });
|
|
42
|
-
|
|
43
|
-
if (useCopy) copyToClipboard(output);
|
|
44
|
-
else if (useSync) syncToFile(output, target);
|
|
45
|
-
else console.log(output);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// ---------- atlas: navigation commands for agents ----------
|
|
49
|
-
|
|
50
|
-
program
|
|
51
|
-
.command('locate <task...>')
|
|
52
|
-
.description('suggest which files to open first for a task (no LLM): BM25F over path/exports/code/past commit messages + import-graph boost')
|
|
53
|
-
.option('-k, --top <n>', 'number of results', '6')
|
|
54
|
-
.option('--no-history', 'ignore git commit history')
|
|
55
|
-
.option('--tests', 'include test files')
|
|
56
|
-
.option('--json', 'JSON output')
|
|
57
|
-
.action((task, o) => {
|
|
58
|
-
const { buildIndex, search } = require('../src/atlas/locate');
|
|
59
|
-
const { readHistory } = require('../src/atlas/git');
|
|
60
|
-
const root = process.cwd();
|
|
61
|
-
const { cached } = require('../src/atlas/cache');
|
|
62
|
-
const index = cached(root, 'locate', { tests: !!o.tests, history: o.history, v: 2 }, () =>
|
|
63
|
-
buildIndex(root, { includeTests: !!o.tests, graph: true, chunks: true, history: o.history ? readHistory(root) : null }));
|
|
64
|
-
const res = search(index, task.join(' '), { k: parseInt(o.top), chunkWeight: 0.5 });
|
|
65
|
-
if (o.history && res.length) {
|
|
66
|
-
// attach "usually changes with" for the top 2 results: helps find the second file of a change
|
|
67
|
-
const { coChanges } = require('../src/atlas/git');
|
|
68
|
-
const hist = readHistory(root);
|
|
69
|
-
const known = new Set(index.files);
|
|
70
|
-
for (const r of res.slice(0, 2)) {
|
|
71
|
-
const cc = coChanges(hist, r.file, 8);
|
|
72
|
-
if (cc.total >= 2) r.changesWith = cc.files.filter(c => known.has(c.file) && c.ratio >= 0.3).slice(0, 2);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (o.json) return console.log(JSON.stringify({ ambiguous: !!res.ambiguous, results: res }, null, 2));
|
|
76
|
-
if (!res.length) return console.log('no match — try other words (function names, folder names)');
|
|
77
|
-
const lines = res.map((r, i) => {
|
|
78
|
-
const ev = (r.evidence || []).map(e => `\n L${e.line}: ${e.code}`).join('')
|
|
79
|
-
+ (r.changesWith && r.changesWith.length ? `\n usually changes with: ${r.changesWith.map(c => `${c.file} (${Math.round(c.ratio * 100)}%)`).join(', ')}` : '');
|
|
80
|
-
return `${i + 1}. ${r.file} (score ${r.score}; ${r.matched.join(', ')})${ev}`;
|
|
81
|
-
});
|
|
82
|
-
if (res.ambiguous) lines.unshift('! top results are close — verify before choosing');
|
|
83
|
-
console.log(lines.join('\n'));
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
program
|
|
87
|
-
.command('links <target>')
|
|
88
|
-
.description('connection map for a file (imports, importers, co-changes, recent commits) or a symbol (definition + call sites)')
|
|
89
|
-
.option('--json', 'JSON output')
|
|
90
|
-
.action((target, o) => {
|
|
91
|
-
const fs = require('fs');
|
|
92
|
-
const { buildGraph, symbolLinks, fileLinks } = require('../src/atlas/links');
|
|
93
|
-
const root = process.cwd();
|
|
94
|
-
const { cached } = require('../src/atlas/cache');
|
|
95
|
-
const graph = cached(root, 'graph', {}, () => buildGraph(root));
|
|
96
|
-
const isFile = graph.set.has(target) || fs.existsSync(target);
|
|
97
|
-
const res = isFile ? fileLinks(graph, root, target) : symbolLinks(graph, target, { root });
|
|
98
|
-
if (o.json) return console.log(JSON.stringify(res, null, 2));
|
|
99
|
-
const out = [];
|
|
100
|
-
if (isFile) {
|
|
101
|
-
out.push(`# ${res.file}`);
|
|
102
|
-
if (res.exports.length) out.push(`exports: ${res.exports.slice(0, 12).join(', ')}`);
|
|
103
|
-
out.push(`imports (${res.imports.length}): ${res.imports.join(', ') || '-'}`);
|
|
104
|
-
out.push(`imported by (${res.importedByCount}): ${res.importedBy.join(', ') || '-'}`);
|
|
105
|
-
if (res.changedWith.total) {
|
|
106
|
-
out.push(`usually changes with (of ${res.changedWith.total} commits):`);
|
|
107
|
-
res.changedWith.files.forEach(c => out.push(` ${c.file} ${Math.round(c.ratio * 100)}%`));
|
|
108
|
-
}
|
|
109
|
-
if (res.recent.length) {
|
|
110
|
-
out.push('recent commits:');
|
|
111
|
-
res.recent.forEach(c => out.push(` ${c.date} ${c.hash} ${c.subject}`));
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
out.push(`# symbol ${res.symbol}`);
|
|
115
|
-
out.push('defined in: ' + (res.definedIn.map(d => `${d.file}:${d.line}${d.exported ? ' (exported)' : ''}`).join(', ') || '-'));
|
|
116
|
-
out.push('used in:');
|
|
117
|
-
res.usedIn.forEach(u => out.push(` ${u.file} (${u.count}x) ${u.first}`));
|
|
118
|
-
if (res.moreFiles) out.push(` ... +${res.moreFiles} more files`);
|
|
119
|
-
}
|
|
120
|
-
console.log(out.join('\n'));
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
program
|
|
124
|
-
.command('peek <file> <words...>')
|
|
125
|
-
.description('show only the lines of a file that contain the given words (compact grep for verifying a candidate)')
|
|
126
|
-
.option('-n, --max <n>', 'max lines', '10')
|
|
127
|
-
.option('--json', 'JSON output')
|
|
128
|
-
.action((file, words, o) => {
|
|
129
|
-
const { peek } = require('../src/atlas/peek');
|
|
130
|
-
const r = peek(process.cwd(), file, words, { max: parseInt(o.max) });
|
|
131
|
-
if (o.json) return console.log(JSON.stringify(r, null, 2));
|
|
132
|
-
if (r.error) return console.log(`${file}: ${r.error}`);
|
|
133
|
-
const out = [`# ${r.file} (${r.totalLines} lines, ${r.matchedLines} matching)`];
|
|
134
|
-
r.lines.forEach(l => out.push(`${l.line}: ${l.code}`));
|
|
135
|
-
if (r.matchedLines > r.lines.length) out.push(`... ${r.matchedLines - r.lines.length} more matching lines`);
|
|
136
|
-
console.log(out.join('\n'));
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
program
|
|
140
|
-
.command('mcp')
|
|
141
|
-
.description('run the cartotree MCP server over stdio (tools: cartotree_locate, cartotree_peek, cartotree_links)')
|
|
142
|
-
.action(async () => {
|
|
143
|
-
const { startMcpServer } = require('../src/atlas/mcp');
|
|
144
|
-
await startMcpServer(process.cwd());
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
program
|
|
148
|
-
.command('init')
|
|
149
|
-
.description('set up this project so AI agents use cartotree automatically (skill + MCP server + reminder hook)')
|
|
150
|
-
.option('--agent <names>', 'comma-separated: claude-code, cursor, codex, windsurf (default: detect)')
|
|
151
|
-
.option('--no-hook', 'do not add the SessionStart reminder hook')
|
|
152
|
-
.option('--dry-run', 'show what would change, write nothing')
|
|
153
|
-
.action(o => {
|
|
154
|
-
const { runInit } = require('../src/atlas/init');
|
|
155
|
-
const agents = o.agent ? o.agent.split(',').map(s => s.trim()) : null;
|
|
156
|
-
const { agents: list, report } = runInit(process.cwd(), { agents, hook: o.hook, dryRun: !!o.dryRun });
|
|
157
|
-
console.log(`cartotree init${o.dryRun ? ' (dry run)' : ''} — agents: ${list.join(', ')}`);
|
|
158
|
-
report.forEach(l => console.log(' ' + l));
|
|
159
|
-
if (!o.dryRun) console.log('\nRestart your agent session to load the MCP server and skill.');
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
program.parse(process.argv);
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const { generateTree } = require('../src/tree');
|
|
5
|
+
const { generateAI, generateJSON } = require('../src/ai');
|
|
6
|
+
const { syncToFile } = require('../src/sync');
|
|
7
|
+
const { copyToClipboard } = require('../src/clipboard');
|
|
8
|
+
const { loadIgnorePatterns } = require('../src/ignore');
|
|
9
|
+
const { loadConfig } = require('../src/config');
|
|
10
|
+
const { version } = require('../package.json');
|
|
11
|
+
|
|
12
|
+
program
|
|
13
|
+
.name('cartotree')
|
|
14
|
+
.description('AI-friendly annotated directory tree + code navigation for agents')
|
|
15
|
+
.version(version)
|
|
16
|
+
.option('-d, --depth <number>', 'max depth')
|
|
17
|
+
.option('-e, --exclude <patterns>', 'exclude patterns (comma-separated)')
|
|
18
|
+
.option('--ai', 'AI-optimized compact format')
|
|
19
|
+
.option('--json', 'JSON format')
|
|
20
|
+
.option('--no-exports', 'disable export parsing')
|
|
21
|
+
.option('--copy', 'copy to clipboard')
|
|
22
|
+
.option('--sync [file]', 'sync to CLAUDE.md or specified file')
|
|
23
|
+
.option('--full', 'no depth limit')
|
|
24
|
+
.action(opts => {
|
|
25
|
+
const config = loadConfig(process.cwd());
|
|
26
|
+
const depth = opts.full ? Infinity : parseInt(opts.depth ?? config.depth);
|
|
27
|
+
const useAI = opts.ai || config.ai;
|
|
28
|
+
const useJSON = opts.json || config.json;
|
|
29
|
+
const useCopy = opts.copy || config.copy;
|
|
30
|
+
const useSync = opts.sync || config.sync;
|
|
31
|
+
const showExports = opts.exports ?? config.exports;
|
|
32
|
+
|
|
33
|
+
const ignorePatterns = loadIgnorePatterns(process.cwd());
|
|
34
|
+
const manualExclude = opts.exclude ? opts.exclude.split(',').map(s => s.trim()) : [];
|
|
35
|
+
const exclude = [...new Set([...ignorePatterns, ...manualExclude])];
|
|
36
|
+
const target = typeof useSync === 'string' ? useSync : 'CLAUDE.md';
|
|
37
|
+
|
|
38
|
+
let output;
|
|
39
|
+
if (useAI) output = generateAI(process.cwd(), { depth, exclude, showExports });
|
|
40
|
+
else if (useJSON) output = generateJSON(process.cwd(), { depth, exclude, showExports });
|
|
41
|
+
else output = generateTree(process.cwd(), { depth, exclude, showExports });
|
|
42
|
+
|
|
43
|
+
if (useCopy) copyToClipboard(output);
|
|
44
|
+
else if (useSync) syncToFile(output, target);
|
|
45
|
+
else console.log(output);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// ---------- atlas: navigation commands for agents ----------
|
|
49
|
+
|
|
50
|
+
program
|
|
51
|
+
.command('locate <task...>')
|
|
52
|
+
.description('suggest which files to open first for a task (no LLM): BM25F over path/exports/code/past commit messages + import-graph boost')
|
|
53
|
+
.option('-k, --top <n>', 'number of results', '6')
|
|
54
|
+
.option('--no-history', 'ignore git commit history')
|
|
55
|
+
.option('--tests', 'include test files')
|
|
56
|
+
.option('--json', 'JSON output')
|
|
57
|
+
.action((task, o) => {
|
|
58
|
+
const { buildIndex, search } = require('../src/atlas/locate');
|
|
59
|
+
const { readHistory } = require('../src/atlas/git');
|
|
60
|
+
const root = process.cwd();
|
|
61
|
+
const { cached } = require('../src/atlas/cache');
|
|
62
|
+
const index = cached(root, 'locate', { tests: !!o.tests, history: o.history, v: 2 }, () =>
|
|
63
|
+
buildIndex(root, { includeTests: !!o.tests, graph: true, chunks: true, history: o.history ? readHistory(root) : null }));
|
|
64
|
+
const res = search(index, task.join(' '), { k: parseInt(o.top), chunkWeight: 0.5 });
|
|
65
|
+
if (o.history && res.length) {
|
|
66
|
+
// attach "usually changes with" for the top 2 results: helps find the second file of a change
|
|
67
|
+
const { coChanges } = require('../src/atlas/git');
|
|
68
|
+
const hist = readHistory(root);
|
|
69
|
+
const known = new Set(index.files);
|
|
70
|
+
for (const r of res.slice(0, 2)) {
|
|
71
|
+
const cc = coChanges(hist, r.file, 8);
|
|
72
|
+
if (cc.total >= 2) r.changesWith = cc.files.filter(c => known.has(c.file) && c.ratio >= 0.3).slice(0, 2);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (o.json) return console.log(JSON.stringify({ ambiguous: !!res.ambiguous, results: res }, null, 2));
|
|
76
|
+
if (!res.length) return console.log('no match — try other words (function names, folder names)');
|
|
77
|
+
const lines = res.map((r, i) => {
|
|
78
|
+
const ev = (r.evidence || []).map(e => `\n L${e.line}: ${e.code}`).join('')
|
|
79
|
+
+ (r.changesWith && r.changesWith.length ? `\n usually changes with: ${r.changesWith.map(c => `${c.file} (${Math.round(c.ratio * 100)}%)`).join(', ')}` : '');
|
|
80
|
+
return `${i + 1}. ${r.file} (score ${r.score}; ${r.matched.join(', ')})${ev}`;
|
|
81
|
+
});
|
|
82
|
+
if (res.ambiguous) lines.unshift('! top results are close — verify before choosing');
|
|
83
|
+
console.log(lines.join('\n'));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
program
|
|
87
|
+
.command('links <target>')
|
|
88
|
+
.description('connection map for a file (imports, importers, co-changes, recent commits) or a symbol (definition + call sites)')
|
|
89
|
+
.option('--json', 'JSON output')
|
|
90
|
+
.action((target, o) => {
|
|
91
|
+
const fs = require('fs');
|
|
92
|
+
const { buildGraph, symbolLinks, fileLinks } = require('../src/atlas/links');
|
|
93
|
+
const root = process.cwd();
|
|
94
|
+
const { cached } = require('../src/atlas/cache');
|
|
95
|
+
const graph = cached(root, 'graph', {}, () => buildGraph(root));
|
|
96
|
+
const isFile = graph.set.has(target) || fs.existsSync(target);
|
|
97
|
+
const res = isFile ? fileLinks(graph, root, target) : symbolLinks(graph, target, { root });
|
|
98
|
+
if (o.json) return console.log(JSON.stringify(res, null, 2));
|
|
99
|
+
const out = [];
|
|
100
|
+
if (isFile) {
|
|
101
|
+
out.push(`# ${res.file}`);
|
|
102
|
+
if (res.exports.length) out.push(`exports: ${res.exports.slice(0, 12).join(', ')}`);
|
|
103
|
+
out.push(`imports (${res.imports.length}): ${res.imports.join(', ') || '-'}`);
|
|
104
|
+
out.push(`imported by (${res.importedByCount}): ${res.importedBy.join(', ') || '-'}`);
|
|
105
|
+
if (res.changedWith.total) {
|
|
106
|
+
out.push(`usually changes with (of ${res.changedWith.total} commits):`);
|
|
107
|
+
res.changedWith.files.forEach(c => out.push(` ${c.file} ${Math.round(c.ratio * 100)}%`));
|
|
108
|
+
}
|
|
109
|
+
if (res.recent.length) {
|
|
110
|
+
out.push('recent commits:');
|
|
111
|
+
res.recent.forEach(c => out.push(` ${c.date} ${c.hash} ${c.subject}`));
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
out.push(`# symbol ${res.symbol}`);
|
|
115
|
+
out.push('defined in: ' + (res.definedIn.map(d => `${d.file}:${d.line}${d.exported ? ' (exported)' : ''}`).join(', ') || '-'));
|
|
116
|
+
out.push('used in:');
|
|
117
|
+
res.usedIn.forEach(u => out.push(` ${u.file} (${u.count}x) ${u.first}`));
|
|
118
|
+
if (res.moreFiles) out.push(` ... +${res.moreFiles} more files`);
|
|
119
|
+
}
|
|
120
|
+
console.log(out.join('\n'));
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
program
|
|
124
|
+
.command('peek <file> <words...>')
|
|
125
|
+
.description('show only the lines of a file that contain the given words (compact grep for verifying a candidate)')
|
|
126
|
+
.option('-n, --max <n>', 'max lines', '10')
|
|
127
|
+
.option('--json', 'JSON output')
|
|
128
|
+
.action((file, words, o) => {
|
|
129
|
+
const { peek } = require('../src/atlas/peek');
|
|
130
|
+
const r = peek(process.cwd(), file, words, { max: parseInt(o.max) });
|
|
131
|
+
if (o.json) return console.log(JSON.stringify(r, null, 2));
|
|
132
|
+
if (r.error) return console.log(`${file}: ${r.error}`);
|
|
133
|
+
const out = [`# ${r.file} (${r.totalLines} lines, ${r.matchedLines} matching)`];
|
|
134
|
+
r.lines.forEach(l => out.push(`${l.line}: ${l.code}`));
|
|
135
|
+
if (r.matchedLines > r.lines.length) out.push(`... ${r.matchedLines - r.lines.length} more matching lines`);
|
|
136
|
+
console.log(out.join('\n'));
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
program
|
|
140
|
+
.command('mcp')
|
|
141
|
+
.description('run the cartotree MCP server over stdio (tools: cartotree_locate, cartotree_peek, cartotree_links)')
|
|
142
|
+
.action(async () => {
|
|
143
|
+
const { startMcpServer } = require('../src/atlas/mcp');
|
|
144
|
+
await startMcpServer(process.cwd());
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
program
|
|
148
|
+
.command('init')
|
|
149
|
+
.description('set up this project so AI agents use cartotree automatically (skill + MCP server + reminder hook)')
|
|
150
|
+
.option('--agent <names>', 'comma-separated: claude-code, cursor, codex, windsurf (default: detect)')
|
|
151
|
+
.option('--no-hook', 'do not add the SessionStart reminder hook')
|
|
152
|
+
.option('--dry-run', 'show what would change, write nothing')
|
|
153
|
+
.action(o => {
|
|
154
|
+
const { runInit } = require('../src/atlas/init');
|
|
155
|
+
const agents = o.agent ? o.agent.split(',').map(s => s.trim()) : null;
|
|
156
|
+
const { agents: list, report } = runInit(process.cwd(), { agents, hook: o.hook, dryRun: !!o.dryRun });
|
|
157
|
+
console.log(`cartotree init${o.dryRun ? ' (dry run)' : ''} — agents: ${list.join(', ')}`);
|
|
158
|
+
report.forEach(l => console.log(' ' + l));
|
|
159
|
+
if (!o.dryRun) console.log('\nRestart your agent session to load the MCP server and skill.');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
program.parse(process.argv);
|
package/hooks/hooks.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
{
|
|
2
|
-
"hooks": {
|
|
3
|
-
"SessionStart": [
|
|
4
|
-
{
|
|
5
|
-
"hooks": [
|
|
6
|
-
{
|
|
7
|
-
"type": "command",
|
|
8
|
-
"command": "echo 'cartotree is available: to find where code lives, call cartotree_locate first (then cartotree_peek to confirm) before grep or reading whole files.'"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [
|
|
4
|
+
{
|
|
5
|
+
"hooks": [
|
|
6
|
+
{
|
|
7
|
+
"type": "command",
|
|
8
|
+
"command": "echo 'cartotree is available: to find where code lives, call cartotree_locate first (then cartotree_peek to confirm) before grep or reading whole files.'"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cartotree",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Find the right files with few tokens — annotated trees plus locate/peek/links for AI agents (CLI + MCP server + skill)",
|
|
5
|
-
"main": "src/tree.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "node --test"
|
|
8
|
-
},
|
|
9
|
-
"bin": {
|
|
10
|
-
"cartotree": "bin/cartotree.js"
|
|
11
|
-
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"cli",
|
|
14
|
-
"ai",
|
|
15
|
-
"developer-tools",
|
|
16
|
-
"tree",
|
|
17
|
-
"claude",
|
|
18
|
-
"cursor",
|
|
19
|
-
"tokens",
|
|
20
|
-
"mcp",
|
|
21
|
-
"claude-code",
|
|
22
|
-
"agents"
|
|
23
|
-
],
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"files": [
|
|
26
|
-
"bin",
|
|
27
|
-
"src",
|
|
28
|
-
"skills",
|
|
29
|
-
"hooks",
|
|
30
|
-
".claude-plugin",
|
|
31
|
-
"README.md",
|
|
32
|
-
"LICENSE"
|
|
33
|
-
],
|
|
34
|
-
"repository": {
|
|
35
|
-
"type": "git",
|
|
36
|
-
"url": "git+https://github.com/kingluminance/cartotree.git"
|
|
37
|
-
},
|
|
38
|
-
"dependencies": {
|
|
39
|
-
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
40
|
-
"chalk": "^4.0.0",
|
|
41
|
-
"clipboardy": "^2.0.0",
|
|
42
|
-
"commander": "^11.0.0",
|
|
43
|
-
"zod": "^4.6.7"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "cartotree",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Find the right files with few tokens — annotated trees plus locate/peek/links for AI agents (CLI + MCP server + skill)",
|
|
5
|
+
"main": "src/tree.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node --test"
|
|
8
|
+
},
|
|
9
|
+
"bin": {
|
|
10
|
+
"cartotree": "bin/cartotree.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"cli",
|
|
14
|
+
"ai",
|
|
15
|
+
"developer-tools",
|
|
16
|
+
"tree",
|
|
17
|
+
"claude",
|
|
18
|
+
"cursor",
|
|
19
|
+
"tokens",
|
|
20
|
+
"mcp",
|
|
21
|
+
"claude-code",
|
|
22
|
+
"agents"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"files": [
|
|
26
|
+
"bin",
|
|
27
|
+
"src",
|
|
28
|
+
"skills",
|
|
29
|
+
"hooks",
|
|
30
|
+
".claude-plugin",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/kingluminance/cartotree.git"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
40
|
+
"chalk": "^4.0.0",
|
|
41
|
+
"clipboardy": "^2.0.0",
|
|
42
|
+
"commander": "^11.0.0",
|
|
43
|
+
"zod": "^4.6.7"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: cartotree
|
|
3
|
-
description: Navigate a codebase cheaply with cartotree. Use when you need to find which files to change for a task, confirm a candidate file, or follow how files and symbols connect — especially in large or unfamiliar repositories — before falling back to grep or reading whole files.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# cartotree — find the right files with few tokens
|
|
7
|
-
|
|
8
|
-
The `cartotree_*` MCP tools (or the `npx cartotree` CLI) answer "where is this?" from a local index — no file dumps.
|
|
9
|
-
|
|
10
|
-
## Workflow (fast mode — the default)
|
|
11
|
-
|
|
12
|
-
1. **Locate first.** `cartotree_locate` with the task in plain words (CLI: `npx cartotree locate <words>`).
|
|
13
|
-
You get ranked files, each with 1–2 evidence lines, and sometimes *usually changes with* (files often edited together, from git history).
|
|
14
|
-
2. **Decide from the evidence.** If rank 1's evidence clearly implements the described behavior, go with it.
|
|
15
|
-
3. **Verify only when unsure.** If you see `! top results are close`, or the evidence is weak, call
|
|
16
|
-
`cartotree_peek` on the top 1–2 candidates with the task's key words (CLI: `npx cartotree peek <file> <words...>`).
|
|
17
|
-
Prefer peek over grep or reading whole files.
|
|
18
|
-
4. **Second file?** If the change likely spans two files (component + locales, implementation + its caller),
|
|
19
|
-
check *usually changes with* or `cartotree_links <file>`.
|
|
20
|
-
5. **Follow a call chain** with `cartotree_links <SymbolName>`: where it is defined and called, one line each.
|
|
21
|
-
|
|
22
|
-
## Tips
|
|
23
|
-
|
|
24
|
-
- If locate misses, run it again with words that would appear in the code (guessed function/file names, camelCase).
|
|
25
|
-
- Words that never appear in code (e.g. a feature's marketing name) won't match; search for the identifiers instead.
|
|
26
|
-
- Keep listing 2–3 candidate files when unsure rather than committing to one too early.
|
|
27
|
-
- Fall back to grep/read only after locate + peek did not find it.
|
|
28
|
-
|
|
29
|
-
## Measured effect
|
|
30
|
-
|
|
31
|
-
On a 21k-file TypeScript monorepo with 30 real commits (Haiku agent): same accuracy as a grep-only agent,
|
|
32
|
-
63–80% fewer tool-output tokens, 17–66% less time.
|
|
1
|
+
---
|
|
2
|
+
name: cartotree
|
|
3
|
+
description: Navigate a codebase cheaply with cartotree. Use when you need to find which files to change for a task, confirm a candidate file, or follow how files and symbols connect — especially in large or unfamiliar repositories — before falling back to grep or reading whole files.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# cartotree — find the right files with few tokens
|
|
7
|
+
|
|
8
|
+
The `cartotree_*` MCP tools (or the `npx cartotree` CLI) answer "where is this?" from a local index — no file dumps.
|
|
9
|
+
|
|
10
|
+
## Workflow (fast mode — the default)
|
|
11
|
+
|
|
12
|
+
1. **Locate first.** `cartotree_locate` with the task in plain words (CLI: `npx cartotree locate <words>`).
|
|
13
|
+
You get ranked files, each with 1–2 evidence lines, and sometimes *usually changes with* (files often edited together, from git history).
|
|
14
|
+
2. **Decide from the evidence.** If rank 1's evidence clearly implements the described behavior, go with it.
|
|
15
|
+
3. **Verify only when unsure.** If you see `! top results are close`, or the evidence is weak, call
|
|
16
|
+
`cartotree_peek` on the top 1–2 candidates with the task's key words (CLI: `npx cartotree peek <file> <words...>`).
|
|
17
|
+
Prefer peek over grep or reading whole files.
|
|
18
|
+
4. **Second file?** If the change likely spans two files (component + locales, implementation + its caller),
|
|
19
|
+
check *usually changes with* or `cartotree_links <file>`.
|
|
20
|
+
5. **Follow a call chain** with `cartotree_links <SymbolName>`: where it is defined and called, one line each.
|
|
21
|
+
|
|
22
|
+
## Tips
|
|
23
|
+
|
|
24
|
+
- If locate misses, run it again with words that would appear in the code (guessed function/file names, camelCase).
|
|
25
|
+
- Words that never appear in code (e.g. a feature's marketing name) won't match; search for the identifiers instead.
|
|
26
|
+
- Keep listing 2–3 candidate files when unsure rather than committing to one too early.
|
|
27
|
+
- Fall back to grep/read only after locate + peek did not find it.
|
|
28
|
+
|
|
29
|
+
## Measured effect
|
|
30
|
+
|
|
31
|
+
On a 21k-file TypeScript monorepo with 30 real commits (Haiku agent): same accuracy as a grep-only agent,
|
|
32
|
+
63–80% fewer tool-output tokens, 17–66% less time.
|