@iderouter/index-mcp 0.2.0-beta.2 → 0.2.0-beta.3
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 +1 -0
- package/package.json +1 -1
- package/src/index.js +188 -5
package/README.md
CHANGED
|
@@ -75,6 +75,7 @@ client skill catalog automatically.
|
|
|
75
75
|
## Tools
|
|
76
76
|
|
|
77
77
|
- `index_codebase`: index a local directory.
|
|
78
|
+
- `summarize_codebase`: produce a fast project overview from the local index while background fine indexing continues.
|
|
78
79
|
- `search_code`: semantic search against the local index.
|
|
79
80
|
- `ask_codebase`: answer a repository question from indexed code and cite matching snippets.
|
|
80
81
|
- `clear_index`: delete an index.
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -314,6 +314,7 @@ const searchResultCache = new Map();
|
|
|
314
314
|
const SEARCH_RESULT_CACHE_TTL_MS = Number(process.env.IDEROUTER_SEARCH_RESULT_CACHE_TTL_MS || 120000);
|
|
315
315
|
const queryAnalysisCache = new Map();
|
|
316
316
|
const QUERY_ANALYSIS_CACHE_TTL_MS = Number(process.env.IDEROUTER_QUERY_ANALYSIS_CACHE_TTL_MS || 300000);
|
|
317
|
+
const contextProbeCache = new Map();
|
|
317
318
|
|
|
318
319
|
function log(message) {
|
|
319
320
|
process.stderr.write(`[${SERVER_NAME}] ${message}\n`);
|
|
@@ -341,8 +342,9 @@ Use this skill when a repository has the \`iderouter-index\` MCP configured.
|
|
|
341
342
|
|
|
342
343
|
1. Run \`index_codebase(path=...)\` when the repository is new or stale.
|
|
343
344
|
2. Use \`get_indexing_status(path=...)\` to wait for coarse or priority-semantic readiness.
|
|
344
|
-
3. Use \`
|
|
345
|
-
4. Use \`
|
|
345
|
+
3. Use \`summarize_codebase(path=...)\` for a fast project overview while background fine indexing continues.
|
|
346
|
+
4. Use \`ask_codebase(path=..., question=...)\` for repository questions.
|
|
347
|
+
5. Use \`search_code(path=..., query=...)\` when you need ranked snippets or exact evidence.
|
|
346
348
|
|
|
347
349
|
## Notes
|
|
348
350
|
|
|
@@ -352,6 +354,88 @@ Use this skill when a repository has the \`iderouter-index\` MCP configured.
|
|
|
352
354
|
`;
|
|
353
355
|
}
|
|
354
356
|
|
|
357
|
+
function userCodexConfigPath() {
|
|
358
|
+
const codexHome = String(process.env.CODEX_HOME || "").trim();
|
|
359
|
+
if (codexHome) {
|
|
360
|
+
return path.join(codexHome, "config.toml");
|
|
361
|
+
}
|
|
362
|
+
return path.join(os.homedir(), ".codex", "config.toml");
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function contextProbeCacheKey(codebasePath) {
|
|
366
|
+
return `context:${codebasePath}`;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function summarizeContextText(text, maxLines = 8) {
|
|
370
|
+
return String(text || "")
|
|
371
|
+
.split("\n")
|
|
372
|
+
.map((line) => line.trim())
|
|
373
|
+
.filter(Boolean)
|
|
374
|
+
.filter((line) => !/^#/.test(line))
|
|
375
|
+
.slice(0, maxLines)
|
|
376
|
+
.join(" ");
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function readOptionalFileProbe(filePath, kind) {
|
|
380
|
+
try {
|
|
381
|
+
const stat = await fs.stat(filePath);
|
|
382
|
+
if (!stat.isFile()) return null;
|
|
383
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
384
|
+
return {
|
|
385
|
+
kind,
|
|
386
|
+
filePath,
|
|
387
|
+
mtimeMs: Math.trunc(stat.mtimeMs),
|
|
388
|
+
size: stat.size,
|
|
389
|
+
excerpt: summarizeContextText(content),
|
|
390
|
+
};
|
|
391
|
+
} catch {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function probeAgentContext(codebasePath) {
|
|
397
|
+
const cacheKey = contextProbeCacheKey(codebasePath);
|
|
398
|
+
const repoAgentsPath = path.join(codebasePath, "AGENTS.md");
|
|
399
|
+
const repoClaudePath = path.join(codebasePath, "CLAUDE.md");
|
|
400
|
+
const codexConfigPath = userCodexConfigPath();
|
|
401
|
+
const [agentsProbe, claudeProbe, codexProbe] = await Promise.all([
|
|
402
|
+
readOptionalFileProbe(repoAgentsPath, "repo_agents"),
|
|
403
|
+
readOptionalFileProbe(repoClaudePath, "repo_claude"),
|
|
404
|
+
readOptionalFileProbe(codexConfigPath, "codex_config"),
|
|
405
|
+
]);
|
|
406
|
+
const fingerprint = [
|
|
407
|
+
agentsProbe ? `${agentsProbe.filePath}:${agentsProbe.mtimeMs}:${agentsProbe.size}` : "",
|
|
408
|
+
claudeProbe ? `${claudeProbe.filePath}:${claudeProbe.mtimeMs}:${claudeProbe.size}` : "",
|
|
409
|
+
codexProbe ? `${codexProbe.filePath}:${codexProbe.mtimeMs}:${codexProbe.size}` : "",
|
|
410
|
+
].join("|");
|
|
411
|
+
const cached = contextProbeCache.get(cacheKey);
|
|
412
|
+
if (cached && cached.fingerprint === fingerprint) {
|
|
413
|
+
return cached.value;
|
|
414
|
+
}
|
|
415
|
+
const value = {
|
|
416
|
+
found: [agentsProbe, claudeProbe, codexProbe].filter(Boolean),
|
|
417
|
+
hasRepoAgents: Boolean(agentsProbe),
|
|
418
|
+
hasRepoClaude: Boolean(claudeProbe),
|
|
419
|
+
hasCodexConfig: Boolean(codexProbe),
|
|
420
|
+
summary: [agentsProbe, claudeProbe, codexProbe]
|
|
421
|
+
.filter(Boolean)
|
|
422
|
+
.map((item) => `${item.kind}:${item.excerpt}`)
|
|
423
|
+
.join(" | "),
|
|
424
|
+
};
|
|
425
|
+
contextProbeCache.set(cacheKey, { fingerprint, value });
|
|
426
|
+
return value;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function contextProbeNotice(contextProbe) {
|
|
430
|
+
if (!contextProbe) return "";
|
|
431
|
+
const found = [];
|
|
432
|
+
if (contextProbe.hasRepoAgents) found.push("AGENTS.md");
|
|
433
|
+
if (contextProbe.hasRepoClaude) found.push("CLAUDE.md");
|
|
434
|
+
if (contextProbe.hasCodexConfig) found.push("Codex config");
|
|
435
|
+
if (found.length === 0) return "";
|
|
436
|
+
return ` Agent context detected: ${found.join(", ")}.`;
|
|
437
|
+
}
|
|
438
|
+
|
|
355
439
|
async function initCodexSkill() {
|
|
356
440
|
const skillDir = codexSkillDir();
|
|
357
441
|
await fs.mkdir(skillDir, { recursive: true });
|
|
@@ -6713,14 +6797,15 @@ async function searchCode(args) {
|
|
|
6713
6797
|
async function collectSearchState(codebasePath, args, query, limit) {
|
|
6714
6798
|
const loadedIndex = await loadExistingIndex(codebasePath);
|
|
6715
6799
|
let job = await loadLatestJobForPath(codebasePath);
|
|
6800
|
+
const contextProbe = await probeAgentContext(codebasePath);
|
|
6716
6801
|
if (!loadedIndex) {
|
|
6717
6802
|
if (isActiveJobStatus(job?.status)) {
|
|
6718
|
-
return `No local index file is ready yet for ${codebasePath}. Index job ${job.id} is ${job.status}: ${job.progress}% (${job.embeddedCount}/${job.totalChunks} changed chunks), step=${job.currentStep}
|
|
6803
|
+
return `No local index file is ready yet for ${codebasePath}. Index job ${job.id} is ${job.status}: ${job.progress}% (${job.embeddedCount}/${job.totalChunks} changed chunks), step=${job.currentStep}.${contextProbeNotice(contextProbe)} ${AGENT_INDEX_NOTICE}`;
|
|
6719
6804
|
}
|
|
6720
6805
|
if (job?.status === "failed") {
|
|
6721
|
-
return `No local index file is available for ${codebasePath}. Last index job ${job.id} failed at ${job.progress}%: ${cleanDiagnosticMessage(job.error)}
|
|
6806
|
+
return `No local index file is available for ${codebasePath}. Last index job ${job.id} failed at ${job.progress}%: ${cleanDiagnosticMessage(job.error)}.${contextProbeNotice(contextProbe)} ${AGENT_INDEX_NOTICE}`;
|
|
6722
6807
|
}
|
|
6723
|
-
return `No local index found for ${codebasePath}. Run index_codebase first
|
|
6808
|
+
return `No local index found for ${codebasePath}. Run index_codebase first, then use summarize_codebase(path=...) for a fast project overview.${contextProbeNotice(contextProbe)} ${COMPANION_PROMPT_NOTICE} ${AGENT_INDEX_NOTICE}`;
|
|
6724
6809
|
}
|
|
6725
6810
|
const usingPartialIndex = loadedIndex.complete === false;
|
|
6726
6811
|
let resumed = null;
|
|
@@ -6863,6 +6948,71 @@ function summarizeAnswerFromResults(question, results, limit) {
|
|
|
6863
6948
|
].join("\n");
|
|
6864
6949
|
}
|
|
6865
6950
|
|
|
6951
|
+
function summarizeRepoDomains(results) {
|
|
6952
|
+
const domains = new Set();
|
|
6953
|
+
for (const result of results || []) {
|
|
6954
|
+
const relativePath = String(result.relativePath || "").toLowerCase();
|
|
6955
|
+
if (relativePath.startsWith("controller/")) domains.add("controller");
|
|
6956
|
+
else if (relativePath.startsWith("service/")) domains.add("service");
|
|
6957
|
+
else if (relativePath.startsWith("model/")) domains.add("model");
|
|
6958
|
+
else if (relativePath.startsWith("router/")) domains.add("router");
|
|
6959
|
+
else if (relativePath.startsWith("relay/")) domains.add("relay");
|
|
6960
|
+
else if (relativePath.startsWith("pkg/")) domains.add("pkg");
|
|
6961
|
+
else if (relativePath.startsWith("setting/")) domains.add("setting");
|
|
6962
|
+
else if (relativePath.startsWith("dto/")) domains.add("dto");
|
|
6963
|
+
else if (relativePath.startsWith("web/") || relativePath.startsWith("iderouter_frontend/")) domains.add("frontend");
|
|
6964
|
+
else if (relativePath.startsWith("common/")) domains.add("common");
|
|
6965
|
+
}
|
|
6966
|
+
return [...domains];
|
|
6967
|
+
}
|
|
6968
|
+
|
|
6969
|
+
function summarizeRepoTechStack(results) {
|
|
6970
|
+
const files = (results || []).map((result) => String(result.relativePath || "").toLowerCase());
|
|
6971
|
+
const stack = [];
|
|
6972
|
+
if (files.some((file) => file.endsWith(".go"))) stack.push("Go backend");
|
|
6973
|
+
if (files.some((file) => file.includes("web/") || file.includes("iderouter_frontend/") || file.endsWith(".tsx") || file.endsWith(".ts"))) {
|
|
6974
|
+
stack.push("TypeScript/React frontend");
|
|
6975
|
+
}
|
|
6976
|
+
if (files.some((file) => file.endsWith(".sql"))) stack.push("SQL schema or migrations");
|
|
6977
|
+
if (files.some((file) => file.endsWith(".yml") || file.endsWith(".yaml"))) stack.push("YAML workflow/config");
|
|
6978
|
+
return stack;
|
|
6979
|
+
}
|
|
6980
|
+
|
|
6981
|
+
function repoSummaryLines(codebasePath, state, contextProbe) {
|
|
6982
|
+
const results = Array.isArray(state?.results) ? state.results : [];
|
|
6983
|
+
const topResults = results.slice(0, 8);
|
|
6984
|
+
const domains = summarizeRepoDomains(topResults);
|
|
6985
|
+
const stack = summarizeRepoTechStack(topResults);
|
|
6986
|
+
const lines = [
|
|
6987
|
+
`Fast repository summary for ${codebasePath}:`,
|
|
6988
|
+
"",
|
|
6989
|
+
`Status: ${state?.usingPartialIndex ? "searchable partial index" : "ready index"}${state?.refresh?.skippedDueToActiveJob ? " while background indexing continues" : ""}.`,
|
|
6990
|
+
];
|
|
6991
|
+
if (stack.length > 0) {
|
|
6992
|
+
lines.push(`Likely stack: ${stack.join(", ")}.`);
|
|
6993
|
+
}
|
|
6994
|
+
if (domains.length > 0) {
|
|
6995
|
+
lines.push(`Indexed layers present: ${domains.join(", ")}.`);
|
|
6996
|
+
}
|
|
6997
|
+
if (contextProbe?.found?.length) {
|
|
6998
|
+
lines.push("");
|
|
6999
|
+
lines.push("Agent Context:");
|
|
7000
|
+
for (const item of contextProbe.found.slice(0, 3)) {
|
|
7001
|
+
lines.push(`- ${path.basename(item.filePath)}: ${item.excerpt || "context file detected"}`);
|
|
7002
|
+
}
|
|
7003
|
+
}
|
|
7004
|
+
if (topResults.length > 0) {
|
|
7005
|
+
lines.push("");
|
|
7006
|
+
lines.push("Key entrypoints:");
|
|
7007
|
+
for (const result of topResults.slice(0, 5)) {
|
|
7008
|
+
lines.push(`- ${result.relativePath}:${result.startLine}-${result.endLine}`);
|
|
7009
|
+
}
|
|
7010
|
+
}
|
|
7011
|
+
lines.push("");
|
|
7012
|
+
lines.push("Use get_indexing_status(path=...) to check background fine indexing progress.");
|
|
7013
|
+
return lines.join("\n");
|
|
7014
|
+
}
|
|
7015
|
+
|
|
6866
7016
|
async function askCodebase(args) {
|
|
6867
7017
|
const codebasePath = normalizePath(args.path);
|
|
6868
7018
|
const question = String(args.question || "").trim();
|
|
@@ -6904,6 +7054,25 @@ async function askCodebase(args) {
|
|
|
6904
7054
|
return summarizeAnswerFromResults(question, state.results, limit);
|
|
6905
7055
|
}
|
|
6906
7056
|
|
|
7057
|
+
async function summarizeCodebase(args) {
|
|
7058
|
+
const codebasePath = normalizePath(args.path);
|
|
7059
|
+
const summaryQuery = "repository overview architecture core modules backend frontend key entrypoints";
|
|
7060
|
+
const contextProbe = await probeAgentContext(codebasePath);
|
|
7061
|
+
const state = await collectSearchState(
|
|
7062
|
+
codebasePath,
|
|
7063
|
+
{ ...args, query: summaryQuery, __skipSearchCache: true },
|
|
7064
|
+
summaryQuery,
|
|
7065
|
+
Math.min(Number(args.limit || 8), 12),
|
|
7066
|
+
);
|
|
7067
|
+
if (typeof state === "string") {
|
|
7068
|
+
return `${state}${contextProbeNotice(contextProbe)}`;
|
|
7069
|
+
}
|
|
7070
|
+
if (!Array.isArray(state.results) || state.results.length === 0) {
|
|
7071
|
+
return `I could not build a repository summary for ${codebasePath} from the current index.${contextProbeNotice(contextProbe)}`;
|
|
7072
|
+
}
|
|
7073
|
+
return `${repoSummaryLines(codebasePath, state, contextProbe)}${contextProbeNotice(contextProbe)}`;
|
|
7074
|
+
}
|
|
7075
|
+
|
|
6907
7076
|
function latestJobForPath(codebasePath) {
|
|
6908
7077
|
let latest = null;
|
|
6909
7078
|
for (const job of indexJobs.values()) {
|
|
@@ -7766,6 +7935,18 @@ const tools = [
|
|
|
7766
7935
|
required: ["path", "query"],
|
|
7767
7936
|
},
|
|
7768
7937
|
},
|
|
7938
|
+
{
|
|
7939
|
+
name: "summarize_codebase",
|
|
7940
|
+
description: "Produce a fast repository overview from the local index while background fine indexing may still be running.",
|
|
7941
|
+
inputSchema: {
|
|
7942
|
+
type: "object",
|
|
7943
|
+
properties: {
|
|
7944
|
+
path: { type: "string" },
|
|
7945
|
+
limit: { type: "number" },
|
|
7946
|
+
},
|
|
7947
|
+
required: ["path"],
|
|
7948
|
+
},
|
|
7949
|
+
},
|
|
7769
7950
|
{
|
|
7770
7951
|
name: "ask_codebase",
|
|
7771
7952
|
description: "Answer a repository question using the indexed local code context and cite the strongest matching snippets.",
|
|
@@ -7806,6 +7987,8 @@ async function callTool(name, args) {
|
|
|
7806
7987
|
return args?.wait ? indexCodebase(args || {}) : startIndexJob(args || {});
|
|
7807
7988
|
case "search_code":
|
|
7808
7989
|
return searchCode(args || {});
|
|
7990
|
+
case "summarize_codebase":
|
|
7991
|
+
return summarizeCodebase(args || {});
|
|
7809
7992
|
case "ask_codebase":
|
|
7810
7993
|
return askCodebase(args || {});
|
|
7811
7994
|
case "clear_index":
|