nexus-agents 3.9.0 → 3.9.2

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.
@@ -52,7 +52,7 @@ import {
52
52
  } from "./chunk-OQLFRJCW.js";
53
53
 
54
54
  // src/version.ts
55
- var VERSION = true ? "3.9.0" : "dev";
55
+ var VERSION = true ? "3.9.2" : "dev";
56
56
 
57
57
  // src/config/schemas-core.ts
58
58
  import { z } from "zod";
@@ -2324,7 +2324,7 @@ async function runDoctorFix(result) {
2324
2324
  writeLine2("\u2500".repeat(40));
2325
2325
  let fixCount = 0;
2326
2326
  if (!result.dataDirectory.rootExists || result.dataDirectory.subdirectories.some((d) => !d.exists || !d.writable)) {
2327
- const { runSetup } = await import("./setup-command-LYPCG3O4.js");
2327
+ const { runSetup } = await import("./setup-command-LWTWYEM6.js");
2328
2328
  const setupResult = runSetup({
2329
2329
  skipMcp: true,
2330
2330
  skipRules: true,
@@ -2437,4 +2437,4 @@ export {
2437
2437
  startStdioServer,
2438
2438
  closeServer
2439
2439
  };
2440
- //# sourceMappingURL=chunk-M5H2WS5Z.js.map
2440
+ //# sourceMappingURL=chunk-CQAO35WX.js.map
@@ -8,7 +8,7 @@ import {
8
8
  checkSqlite,
9
9
  defaultConfig,
10
10
  initDataDirectories
11
- } from "./chunk-M5H2WS5Z.js";
11
+ } from "./chunk-CQAO35WX.js";
12
12
  import {
13
13
  BUILT_IN_EXPERTS
14
14
  } from "./chunk-YPNQPT2F.js";
@@ -2001,4 +2001,4 @@ export {
2001
2001
  setupCommand,
2002
2002
  setupCommandAsync
2003
2003
  };
2004
- //# sourceMappingURL=chunk-PGMF6I7D.js.map
2004
+ //# sourceMappingURL=chunk-DXL625N6.js.map
@@ -141,7 +141,14 @@ var SCORE_SUBSTRING = 2;
141
141
  var SCORE_EXPORTED_BONUS = 3;
142
142
  function isSourceFile(name) {
143
143
  const ext = extname2(name).toLowerCase();
144
- return [".ts", ".tsx", ".js", ".jsx"].includes(ext) && !name.endsWith(".test.ts") && !name.endsWith(".test.tsx") && !name.endsWith(".d.ts");
144
+ return (
145
+ // #4640: take the list from the extractor rather than keeping a copy. The
146
+ // two sat on opposite sides of the same decision — `extract_symbols` reaches
147
+ // the extension gate at symbol-extractor.ts:162, while this sweep filters
148
+ // *before* it — so a language added to SUPPORTED_EXTENSIONS was parsed by
149
+ // one tool and silently never indexed by the other.
150
+ SUPPORTED_EXTENSIONS.includes(ext) && !name.endsWith(".test.ts") && !name.endsWith(".test.tsx") && !name.endsWith(".d.ts")
151
+ );
145
152
  }
146
153
  async function findSourceFiles(dir, maxDepth) {
147
154
  if (maxDepth <= 0) return { files: [], skippedDirs: 1 };
@@ -272,4 +279,4 @@ export {
272
279
  findSourceFiles,
273
280
  CodebaseIndex
274
281
  };
275
- //# sourceMappingURL=chunk-BQTMMLQQ.js.map
282
+ //# sourceMappingURL=chunk-RSMG2DPB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/indexer/codebase-search.ts","../src/indexer/symbol-extractor.ts"],"sourcesContent":["/**\n * Codebase search — keyword search across symbol indices.\n *\n * Builds an in-memory symbol index for a directory of TS/JS files,\n * then supports keyword search, file summaries, and symbol lookup.\n *\n * Inspired by Augment Code's Context Engine. Uses the existing\n * extractSymbols() function for AST parsing.\n *\n * @module indexer/codebase-search\n */\n\nimport { readdir } from 'node:fs/promises';\nimport { resolve, extname, relative } from 'node:path';\nimport {\n extractSymbols,\n SUPPORTED_EXTENSIONS,\n type CodeSymbol,\n type SymbolExtractionResult,\n} from './symbol-extractor.js';\n\n/** A symbol with its source file path. */\nexport interface IndexedSymbol extends CodeSymbol {\n /** Relative file path from the indexed root. */\n filePath: string;\n}\n\n/** Search result with relevance scoring. */\nexport interface SearchResult {\n symbol: IndexedSymbol;\n /** Relevance score (higher = better match). */\n score: number;\n /** How the query matched (exact, prefix, substring, word). */\n matchType: 'exact' | 'prefix' | 'substring' | 'word';\n}\n\n/** File summary — compact overview of a source file. */\nexport interface FileSummary {\n filePath: string;\n totalLines: number;\n exportedSymbols: number;\n privateSymbols: number;\n kinds: Record<string, number>;\n}\n\n/** Index statistics. */\nexport interface IndexStats {\n totalFiles: number;\n totalSymbols: number;\n indexedAt: string;\n /** Directories not descended into because `maxDepth` was exhausted (#4243). */\n skippedDirs: number;\n}\n\n/** Default recursion depth for `CodebaseIndex.index()` (#4243 — was hardcoded 4). */\nexport const DEFAULT_INDEX_MAX_DEPTH = 24;\n/** Upper clamp for caller-supplied `maxDepth` to bound worst-case tree-walk cost. */\nexport const MAX_INDEX_MAX_DEPTH = 64;\n\n// Score weights for different match types\nconst SCORE_EXACT = 20;\nconst SCORE_PREFIX = 10;\nconst SCORE_WORD = 5;\nconst SCORE_SUBSTRING = 2;\nconst SCORE_EXPORTED_BONUS = 3;\n\nfunction isSourceFile(name: string): boolean {\n const ext = extname(name).toLowerCase();\n return (\n // #4640: take the list from the extractor rather than keeping a copy. The\n // two sat on opposite sides of the same decision — `extract_symbols` reaches\n // the extension gate at symbol-extractor.ts:162, while this sweep filters\n // *before* it — so a language added to SUPPORTED_EXTENSIONS was parsed by\n // one tool and silently never indexed by the other.\n SUPPORTED_EXTENSIONS.includes(ext) &&\n !name.endsWith('.test.ts') &&\n !name.endsWith('.test.tsx') &&\n !name.endsWith('.d.ts')\n );\n}\n\n/** Result of a recursive source-file walk: the files found plus a truncation signal. */\nexport interface FindSourceFilesResult {\n files: string[];\n /** Count of directories that were NOT descended into because maxDepth hit 0. */\n skippedDirs: number;\n}\n\n/**\n * Recursively collect TS/JS source files under `dir`, bounded by `maxDepth`,\n * skipping `node_modules`/`dist` and test/declaration files. Exported so the\n * `search_usages` tool (#4265) reuses the exact same source-file set the symbol\n * index walks — keeping the two tools' scopes apples-to-apples (DRY).\n */\nexport async function findSourceFiles(\n dir: string,\n maxDepth: number\n): Promise<FindSourceFilesResult> {\n if (maxDepth <= 0) return { files: [], skippedDirs: 1 };\n const files: string[] = [];\n let skippedDirs = 0;\n const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);\n for (const entry of entries) {\n const fullPath = resolve(dir, entry.name);\n if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== 'dist') {\n const sub = await findSourceFiles(fullPath, maxDepth - 1);\n files.push(...sub.files);\n skippedDirs += sub.skippedDirs;\n }\n if (entry.isFile() && isSourceFile(entry.name)) {\n files.push(fullPath);\n }\n }\n return { files, skippedDirs };\n}\n\nfunction scoreMatch(symbolName: string, query: string): SearchResult['score'] | null {\n const nameLower = symbolName.toLowerCase();\n const queryLower = query.toLowerCase();\n\n if (nameLower === queryLower) return SCORE_EXACT;\n if (nameLower.startsWith(queryLower)) return SCORE_PREFIX;\n\n // Word boundary match (camelCase splitting)\n const words = symbolName\n .replace(/([a-z])([A-Z])/g, '$1 $2')\n .toLowerCase()\n .split(/[\\s_-]+/);\n if (words.some((w) => w === queryLower)) return SCORE_WORD;\n\n if (nameLower.includes(queryLower)) return SCORE_SUBSTRING;\n\n return null;\n}\n\nfunction getMatchType(score: number): SearchResult['matchType'] {\n if (score >= SCORE_EXACT) return 'exact';\n if (score >= SCORE_PREFIX) return 'prefix';\n if (score >= SCORE_WORD) return 'word';\n return 'substring';\n}\n\n/** In-memory codebase symbol index. */\nexport class CodebaseIndex {\n private readonly symbols: IndexedSymbol[] = [];\n private readonly fileResults = new Map<string, SymbolExtractionResult>();\n private readonly rootDir: string;\n private skippedDirs = 0;\n\n constructor(rootDir: string) {\n this.rootDir = rootDir;\n }\n\n /**\n * Index all TS/JS source files in the directory.\n *\n * `maxDepth` is clamped to `[1, MAX_INDEX_MAX_DEPTH]` so a caller-supplied\n * value can't force an unbounded tree-walk (#4243).\n */\n async index(maxDepth: number = DEFAULT_INDEX_MAX_DEPTH): Promise<IndexStats> {\n const clampedDepth = Math.min(Math.max(maxDepth, 1), MAX_INDEX_MAX_DEPTH);\n const { files, skippedDirs } = await findSourceFiles(this.rootDir, clampedDepth);\n this.skippedDirs = skippedDirs;\n\n for (const file of files) {\n const result = await extractSymbols(file);\n const relPath = relative(this.rootDir, file);\n this.fileResults.set(relPath, result);\n\n for (const symbol of result.symbols) {\n this.symbols.push({ ...symbol, filePath: relPath });\n }\n }\n\n return {\n totalFiles: files.length,\n totalSymbols: this.symbols.length,\n indexedAt: new Date().toISOString(),\n skippedDirs,\n };\n }\n\n /** Search symbols by keyword. Returns top N results sorted by relevance. */\n search(query: string, limit = 20): SearchResult[] {\n const results: SearchResult[] = [];\n\n for (const symbol of this.symbols) {\n const baseScore = scoreMatch(symbol.name, query);\n if (baseScore === null) continue;\n\n const bonus = symbol.exported ? SCORE_EXPORTED_BONUS : 0;\n results.push({\n symbol,\n score: baseScore + bonus,\n matchType: getMatchType(baseScore),\n });\n }\n\n return results.sort((a, b) => b.score - a.score).slice(0, limit);\n }\n\n /** Get a compact summary of a file's symbols. */\n getFileSummary(filePath: string): FileSummary | undefined {\n const result = this.fileResults.get(filePath);\n if (result === undefined) return undefined;\n\n const kinds: Record<string, number> = {};\n let exported = 0;\n let priv = 0;\n\n for (const s of result.symbols) {\n kinds[s.kind] = (kinds[s.kind] ?? 0) + 1;\n if (s.exported) exported++;\n else priv++;\n }\n\n return {\n filePath,\n totalLines: result.totalLines,\n exportedSymbols: exported,\n privateSymbols: priv,\n kinds,\n };\n }\n\n /** List all indexed files with symbol counts. */\n listFiles(): Array<{ path: string; symbols: number; lines: number }> {\n return [...this.fileResults.entries()].map(([path, result]) => ({\n path,\n symbols: result.symbols.length,\n lines: result.totalLines,\n }));\n }\n\n /** Get index statistics. */\n get stats(): { files: number; symbols: number; skippedDirs: number } {\n return {\n files: this.fileResults.size,\n symbols: this.symbols.length,\n skippedDirs: this.skippedDirs,\n };\n }\n}\n","/**\n * AST symbol extraction for token-efficient code retrieval.\n *\n * Uses TypeScript's compiler API to extract function, class, method,\n * interface, and type definitions from source files.\n *\n * Token savings: ~80-99% vs reading full files.\n * No additional dependencies — uses TypeScript (already a project dep).\n *\n * @module indexer/symbol-extractor\n */\n\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport ts from 'typescript';\n\n/** A symbol extracted from source code. */\nexport interface CodeSymbol {\n /** Symbol name */\n name: string;\n /** Symbol kind */\n kind: 'function' | 'class' | 'method' | 'interface' | 'type' | 'variable' | 'enum';\n /** Start line (1-based) */\n startLine: number;\n /** End line (1-based) */\n endLine: number;\n /** Full source text of the symbol */\n text: string;\n /** Whether the symbol is exported */\n exported: boolean;\n}\n\n/**\n * Extensions the TypeScript compiler API path can parse (#4517).\n *\n * Exported so the tool layer can name them in its error message instead of\n * asserting a file \"may not be TypeScript/JavaScript\" without saying what\n * would count.\n */\nexport const SUPPORTED_EXTENSIONS: readonly string[] = ['.ts', '.tsx', '.js', '.jsx'];\n\n/** Result of extracting symbols from a file. */\nexport interface SymbolExtractionResult {\n filePath: string;\n symbols: CodeSymbol[];\n totalLines: number;\n totalChars: number;\n symbolChars: number;\n savingsPercent: number;\n /**\n * Whether the file was actually parsed (#4517).\n *\n * `false` means the extension is not supported, so `symbols: []` reports\n * that nothing was READ — not that nothing is there. An unsupported file and\n * a genuinely symbol-free file previously returned identical results, and\n * the tool guessed between them wrongly: a valid TypeScript barrel of 20\n * re-exports was reported as possibly-not-TypeScript.\n */\n parsed: boolean;\n}\n\nfunction getKind(node: ts.Node): CodeSymbol['kind'] | null {\n if (ts.isFunctionDeclaration(node)) return 'function';\n if (ts.isClassDeclaration(node)) return 'class';\n if (ts.isInterfaceDeclaration(node)) return 'interface';\n if (ts.isTypeAliasDeclaration(node)) return 'type';\n if (ts.isEnumDeclaration(node)) return 'enum';\n if (ts.isMethodDeclaration(node)) return 'method';\n if (ts.isVariableStatement(node)) return 'variable';\n return null;\n}\n\nfunction getName(node: ts.Node): string {\n if (\n ts.isFunctionDeclaration(node) ||\n ts.isClassDeclaration(node) ||\n ts.isInterfaceDeclaration(node) ||\n ts.isTypeAliasDeclaration(node) ||\n ts.isEnumDeclaration(node) ||\n ts.isMethodDeclaration(node)\n ) {\n const nameNode = (node as ts.NamedDeclaration).name;\n return nameNode ? nameNode.getText() : '<anonymous>';\n }\n if (ts.isVariableStatement(node)) {\n const decls = node.declarationList.declarations;\n const firstDecl = decls[0];\n if (firstDecl !== undefined) {\n return firstDecl.name.getText();\n }\n }\n return '<anonymous>';\n}\n\nfunction isExported(node: ts.Node): boolean {\n const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;\n if (modifiers) {\n return modifiers.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n return false;\n}\n\nfunction visitNode(node: ts.Node, sourceFile: ts.SourceFile, symbols: CodeSymbol[]): void {\n const kind = getKind(node);\n if (kind !== null) {\n const name = getName(node);\n if (name !== '<anonymous>') {\n const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());\n symbols.push({\n name,\n kind,\n startLine: start.line + 1,\n endLine: end.line + 1,\n text: node.getText(sourceFile),\n exported: isExported(node),\n });\n }\n }\n if (ts.isClassDeclaration(node)) {\n visitClassMembers(node, sourceFile, symbols);\n return;\n }\n ts.forEachChild(node, (child) => {\n visitNode(child, sourceFile, symbols);\n });\n}\n\nfunction visitClassMembers(\n node: ts.ClassDeclaration,\n sourceFile: ts.SourceFile,\n symbols: CodeSymbol[]\n): void {\n for (const member of node.members) {\n if (ts.isMethodDeclaration(member) || ts.isPropertyDeclaration(member)) {\n const memberName = member.name.getText();\n if (memberName !== '<anonymous>') {\n const start = sourceFile.getLineAndCharacterOfPosition(member.getStart());\n const end = sourceFile.getLineAndCharacterOfPosition(member.getEnd());\n symbols.push({\n name: memberName,\n kind: 'method',\n startLine: start.line + 1,\n endLine: end.line + 1,\n text: member.getText(sourceFile),\n exported: false,\n });\n }\n }\n }\n}\n\nfunction computeSavings(totalChars: number, symbolChars: number): number {\n return totalChars > 0 ? Math.round(100 * (1 - symbolChars / totalChars) * 10) / 10 : 0;\n}\n\n/**\n * Extract symbols from a TypeScript/JavaScript file.\n */\nexport async function extractSymbols(filePath: string): Promise<SymbolExtractionResult> {\n const ext = extname(filePath).toLowerCase();\n if (!SUPPORTED_EXTENSIONS.includes(ext)) {\n return {\n filePath,\n symbols: [],\n totalLines: 0,\n totalChars: 0,\n symbolChars: 0,\n savingsPercent: 0,\n parsed: false,\n };\n }\n\n const source = await readFile(filePath, 'utf-8');\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);\n const symbols: CodeSymbol[] = [];\n\n ts.forEachChild(sourceFile, (node) => {\n visitNode(node, sourceFile, symbols);\n });\n\n const totalChars = source.length;\n const symbolChars = symbols.reduce((sum, s) => sum + s.text.length, 0);\n\n return {\n filePath,\n symbols,\n totalLines: source.split('\\n').length,\n totalChars,\n symbolChars,\n savingsPercent: computeSavings(totalChars, symbolChars),\n parsed: true,\n };\n}\n\n/**\n * Why {@link extractSymbolIndex} produced no index (#4517).\n *\n * `unsupported` and `no-declarations` are different facts about the world:\n * the first says the file was never read, the second says it was read and\n * genuinely declares nothing locally — a re-export barrel, typically. Callers\n * that collapse them tell the user to check a file type that was never the\n * problem.\n */\nexport type EmptyIndexReason = 'unsupported' | 'no-declarations';\n\n/** A symbol index, or the reason there is none. */\nexport type SymbolIndexResult =\n | { readonly kind: 'index'; readonly index: string }\n | { readonly kind: 'empty'; readonly reason: EmptyIndexReason };\n\n/**\n * Extract a compact symbol index, reporting why when there is nothing to show.\n *\n * Names + locations only, no source text — the minimal representation for LLM\n * context (~95%+ token savings). Replaced the earlier `extractSymbolIndex`,\n * which returned a bare `''` for both \"could not read\" and \"read, found\n * nothing\" and so could not tell a caller which had happened.\n */\nexport async function extractSymbolIndexResult(filePath: string): Promise<SymbolIndexResult> {\n const result = await extractSymbols(filePath);\n if (!result.parsed) return { kind: 'empty', reason: 'unsupported' };\n if (result.symbols.length === 0) return { kind: 'empty', reason: 'no-declarations' };\n return { kind: 'index', index: renderIndex(filePath, result) };\n}\n\nfunction renderIndex(filePath: string, result: SymbolExtractionResult): string {\n const lines = result.symbols.map((s) => {\n const exp = s.exported ? 'export ' : '';\n return `${exp}${s.kind} ${s.name} (L${String(s.startLine)}-${String(s.endLine)})`;\n });\n return `// ${filePath} — ${String(result.symbols.length)} symbols\\n${lines.join('\\n')}`;\n}\n"],"mappings":";AAYA,SAAS,eAAe;AACxB,SAAS,SAAS,WAAAA,UAAS,gBAAgB;;;ACD3C,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,OAAO,QAAQ;AAyBR,IAAM,uBAA0C,CAAC,OAAO,QAAQ,OAAO,MAAM;AAsBpF,SAAS,QAAQ,MAA0C;AACzD,MAAI,GAAG,sBAAsB,IAAI,EAAG,QAAO;AAC3C,MAAI,GAAG,mBAAmB,IAAI,EAAG,QAAO;AACxC,MAAI,GAAG,uBAAuB,IAAI,EAAG,QAAO;AAC5C,MAAI,GAAG,uBAAuB,IAAI,EAAG,QAAO;AAC5C,MAAI,GAAG,kBAAkB,IAAI,EAAG,QAAO;AACvC,MAAI,GAAG,oBAAoB,IAAI,EAAG,QAAO;AACzC,MAAI,GAAG,oBAAoB,IAAI,EAAG,QAAO;AACzC,SAAO;AACT;AAEA,SAAS,QAAQ,MAAuB;AACtC,MACE,GAAG,sBAAsB,IAAI,KAC7B,GAAG,mBAAmB,IAAI,KAC1B,GAAG,uBAAuB,IAAI,KAC9B,GAAG,uBAAuB,IAAI,KAC9B,GAAG,kBAAkB,IAAI,KACzB,GAAG,oBAAoB,IAAI,GAC3B;AACA,UAAM,WAAY,KAA6B;AAC/C,WAAO,WAAW,SAAS,QAAQ,IAAI;AAAA,EACzC;AACA,MAAI,GAAG,oBAAoB,IAAI,GAAG;AAChC,UAAM,QAAQ,KAAK,gBAAgB;AACnC,UAAM,YAAY,MAAM,CAAC;AACzB,QAAI,cAAc,QAAW;AAC3B,aAAO,UAAU,KAAK,QAAQ;AAAA,IAChC;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,WAAW,MAAwB;AAC1C,QAAM,YAAY,GAAG,iBAAiB,IAAI,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Q;AAAA,MACxB,OAAO,OAAO;AAAA,IAChB,EAAE;AAAA,EACJ;AAAA;AAAA,EAGA,IAAI,QAAiE;AACnE,WAAO;AAAA,MACL,OAAO,KAAK,YAAY;AAAA,MACxB,SAAS,KAAK,QAAQ;AAAA,MACtB,aAAa,KAAK;AAAA,IACpB;AAAA,EACF;AACF;","names":["extname","extname"]}
@@ -12,7 +12,7 @@ import {
12
12
  extractSymbolIndexResult,
13
13
  extractSymbols,
14
14
  findSourceFiles
15
- } from "./chunk-BQTMMLQQ.js";
15
+ } from "./chunk-RSMG2DPB.js";
16
16
  import {
17
17
  FINDING_SEVERITY_LEVELS,
18
18
  SARIF_LEVEL_MAP,
@@ -22,7 +22,7 @@ import {
22
22
  DEFAULT_TASK_TTL_MS,
23
23
  DEFAULT_TOOL_RATE_LIMITS,
24
24
  clampTaskTtl
25
- } from "./chunk-M5H2WS5Z.js";
25
+ } from "./chunk-CQAO35WX.js";
26
26
  import {
27
27
  executeExpert
28
28
  } from "./chunk-EGUKCGGM.js";
@@ -46383,7 +46383,7 @@ function createScaffoldStageWrapper() {
46383
46383
  }
46384
46384
  async function searchCodebaseForTask(task) {
46385
46385
  try {
46386
- const { CodebaseIndex: CodebaseIndex2 } = await import("./codebase-search-AATGEN2H.js");
46386
+ const { CodebaseIndex: CodebaseIndex2 } = await import("./codebase-search-RHBGEWXK.js");
46387
46387
  const index = new CodebaseIndex2(process.cwd());
46388
46388
  const terms = task.toLowerCase().split(/\s+/).filter((w) => w.length > 4).slice(0, 3);
46389
46389
  if (terms.length === 0) return null;
@@ -54406,4 +54406,4 @@ export {
54406
54406
  shutdownFeedbackSubscriber,
54407
54407
  createEventBusBridge
54408
54408
  };
54409
- //# sourceMappingURL=chunk-SDZUHQYI.js.map
54409
+ //# sourceMappingURL=chunk-ZGAML4CX.js.map
package/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ import "./chunk-YP25ZDI2.js";
18
18
  import {
19
19
  setupCommandAsync,
20
20
  verifyCommand
21
- } from "./chunk-PGMF6I7D.js";
21
+ } from "./chunk-DXL625N6.js";
22
22
  import "./chunk-OM5VAEYP.js";
23
23
  import {
24
24
  AuthHandler,
@@ -139,10 +139,10 @@ import {
139
139
  validateCommand,
140
140
  validateWorkflow,
141
141
  wrapInMarkdownFence
142
- } from "./chunk-SDZUHQYI.js";
142
+ } from "./chunk-ZGAML4CX.js";
143
143
  import "./chunk-WVN62JSE.js";
144
144
  import "./chunk-HFOQKCD2.js";
145
- import "./chunk-BQTMMLQQ.js";
145
+ import "./chunk-RSMG2DPB.js";
146
146
  import {
147
147
  CATEGORY_DISPLAY_NAMES,
148
148
  DEFAULT_PR_REVIEW_CONFIG
@@ -166,7 +166,7 @@ import {
166
166
  loadConfig,
167
167
  runDoctor,
168
168
  validateNexusEnv
169
- } from "./chunk-M5H2WS5Z.js";
169
+ } from "./chunk-CQAO35WX.js";
170
170
  import {
171
171
  buildOpenAICompatAdapters,
172
172
  readOpenAICompatEnv
@@ -3,7 +3,7 @@ import {
3
3
  DEFAULT_INDEX_MAX_DEPTH,
4
4
  MAX_INDEX_MAX_DEPTH,
5
5
  findSourceFiles
6
- } from "./chunk-BQTMMLQQ.js";
6
+ } from "./chunk-RSMG2DPB.js";
7
7
  import "./chunk-ZPWHCABL.js";
8
8
  export {
9
9
  CodebaseIndex,
@@ -11,4 +11,4 @@ export {
11
11
  MAX_INDEX_MAX_DEPTH,
12
12
  findSourceFiles
13
13
  };
14
- //# sourceMappingURL=codebase-search-AATGEN2H.js.map
14
+ //# sourceMappingURL=codebase-search-RHBGEWXK.js.map
package/dist/index.js CHANGED
@@ -541,7 +541,7 @@ import {
541
541
  withLogging,
542
542
  withRetry,
543
543
  withRetryWrapper
544
- } from "./chunk-SDZUHQYI.js";
544
+ } from "./chunk-ZGAML4CX.js";
545
545
  import {
546
546
  FALLBACK_SCANNER_DATA,
547
547
  buildPlanFromAnalysis,
@@ -555,7 +555,7 @@ import {
555
555
  analyzeRepo,
556
556
  normalizeRepoId
557
557
  } from "./chunk-HFOQKCD2.js";
558
- import "./chunk-BQTMMLQQ.js";
558
+ import "./chunk-RSMG2DPB.js";
559
559
  import "./chunk-CQ77TF4Y.js";
560
560
  import {
561
561
  AppConfigSchema,
@@ -575,7 +575,7 @@ import {
575
575
  getKnownNexusVarNames,
576
576
  startStdioServer,
577
577
  validateNexusEnv
578
- } from "./chunk-M5H2WS5Z.js";
578
+ } from "./chunk-CQAO35WX.js";
579
579
  import {
580
580
  OPENAI_MODELS,
581
581
  OPENAI_MODEL_ALIASES,
@@ -8,9 +8,9 @@ import {
8
8
  runWizard,
9
9
  setupCommand,
10
10
  setupCommandAsync
11
- } from "./chunk-PGMF6I7D.js";
11
+ } from "./chunk-DXL625N6.js";
12
12
  import "./chunk-OM5VAEYP.js";
13
- import "./chunk-M5H2WS5Z.js";
13
+ import "./chunk-CQAO35WX.js";
14
14
  import "./chunk-AENOTEID.js";
15
15
  import "./chunk-AQBM5CAX.js";
16
16
  import "./chunk-OQB3XC5O.js";
@@ -41,4 +41,4 @@ export {
41
41
  setupCommand,
42
42
  setupCommandAsync
43
43
  };
44
- //# sourceMappingURL=setup-command-LYPCG3O4.js.map
44
+ //# sourceMappingURL=setup-command-LWTWYEM6.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexus-agents",
3
- "version": "3.9.0",
3
+ "version": "3.9.2",
4
4
  "description": "Governance substrate for AI coding agents — adversarial PR review, drift-detected rules, tamper-evident audit, and closed-loop outcome routing for Claude, Codex, Gemini, and OpenCode",
5
5
  "mcpName": "io.github.nexus-substrate/nexus-agents",
6
6
  "license": "MIT",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/indexer/codebase-search.ts","../src/indexer/symbol-extractor.ts"],"sourcesContent":["/**\n * Codebase search — keyword search across symbol indices.\n *\n * Builds an in-memory symbol index for a directory of TS/JS files,\n * then supports keyword search, file summaries, and symbol lookup.\n *\n * Inspired by Augment Code's Context Engine. Uses the existing\n * extractSymbols() function for AST parsing.\n *\n * @module indexer/codebase-search\n */\n\nimport { readdir } from 'node:fs/promises';\nimport { resolve, extname, relative } from 'node:path';\nimport {\n extractSymbols,\n type CodeSymbol,\n type SymbolExtractionResult,\n} from './symbol-extractor.js';\n\n/** A symbol with its source file path. */\nexport interface IndexedSymbol extends CodeSymbol {\n /** Relative file path from the indexed root. */\n filePath: string;\n}\n\n/** Search result with relevance scoring. */\nexport interface SearchResult {\n symbol: IndexedSymbol;\n /** Relevance score (higher = better match). */\n score: number;\n /** How the query matched (exact, prefix, substring, word). */\n matchType: 'exact' | 'prefix' | 'substring' | 'word';\n}\n\n/** File summary — compact overview of a source file. */\nexport interface FileSummary {\n filePath: string;\n totalLines: number;\n exportedSymbols: number;\n privateSymbols: number;\n kinds: Record<string, number>;\n}\n\n/** Index statistics. */\nexport interface IndexStats {\n totalFiles: number;\n totalSymbols: number;\n indexedAt: string;\n /** Directories not descended into because `maxDepth` was exhausted (#4243). */\n skippedDirs: number;\n}\n\n/** Default recursion depth for `CodebaseIndex.index()` (#4243 — was hardcoded 4). */\nexport const DEFAULT_INDEX_MAX_DEPTH = 24;\n/** Upper clamp for caller-supplied `maxDepth` to bound worst-case tree-walk cost. */\nexport const MAX_INDEX_MAX_DEPTH = 64;\n\n// Score weights for different match types\nconst SCORE_EXACT = 20;\nconst SCORE_PREFIX = 10;\nconst SCORE_WORD = 5;\nconst SCORE_SUBSTRING = 2;\nconst SCORE_EXPORTED_BONUS = 3;\n\nfunction isSourceFile(name: string): boolean {\n const ext = extname(name).toLowerCase();\n return (\n ['.ts', '.tsx', '.js', '.jsx'].includes(ext) &&\n !name.endsWith('.test.ts') &&\n !name.endsWith('.test.tsx') &&\n !name.endsWith('.d.ts')\n );\n}\n\n/** Result of a recursive source-file walk: the files found plus a truncation signal. */\nexport interface FindSourceFilesResult {\n files: string[];\n /** Count of directories that were NOT descended into because maxDepth hit 0. */\n skippedDirs: number;\n}\n\n/**\n * Recursively collect TS/JS source files under `dir`, bounded by `maxDepth`,\n * skipping `node_modules`/`dist` and test/declaration files. Exported so the\n * `search_usages` tool (#4265) reuses the exact same source-file set the symbol\n * index walks — keeping the two tools' scopes apples-to-apples (DRY).\n */\nexport async function findSourceFiles(\n dir: string,\n maxDepth: number\n): Promise<FindSourceFilesResult> {\n if (maxDepth <= 0) return { files: [], skippedDirs: 1 };\n const files: string[] = [];\n let skippedDirs = 0;\n const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);\n for (const entry of entries) {\n const fullPath = resolve(dir, entry.name);\n if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== 'dist') {\n const sub = await findSourceFiles(fullPath, maxDepth - 1);\n files.push(...sub.files);\n skippedDirs += sub.skippedDirs;\n }\n if (entry.isFile() && isSourceFile(entry.name)) {\n files.push(fullPath);\n }\n }\n return { files, skippedDirs };\n}\n\nfunction scoreMatch(symbolName: string, query: string): SearchResult['score'] | null {\n const nameLower = symbolName.toLowerCase();\n const queryLower = query.toLowerCase();\n\n if (nameLower === queryLower) return SCORE_EXACT;\n if (nameLower.startsWith(queryLower)) return SCORE_PREFIX;\n\n // Word boundary match (camelCase splitting)\n const words = symbolName\n .replace(/([a-z])([A-Z])/g, '$1 $2')\n .toLowerCase()\n .split(/[\\s_-]+/);\n if (words.some((w) => w === queryLower)) return SCORE_WORD;\n\n if (nameLower.includes(queryLower)) return SCORE_SUBSTRING;\n\n return null;\n}\n\nfunction getMatchType(score: number): SearchResult['matchType'] {\n if (score >= SCORE_EXACT) return 'exact';\n if (score >= SCORE_PREFIX) return 'prefix';\n if (score >= SCORE_WORD) return 'word';\n return 'substring';\n}\n\n/** In-memory codebase symbol index. */\nexport class CodebaseIndex {\n private readonly symbols: IndexedSymbol[] = [];\n private readonly fileResults = new Map<string, SymbolExtractionResult>();\n private readonly rootDir: string;\n private skippedDirs = 0;\n\n constructor(rootDir: string) {\n this.rootDir = rootDir;\n }\n\n /**\n * Index all TS/JS source files in the directory.\n *\n * `maxDepth` is clamped to `[1, MAX_INDEX_MAX_DEPTH]` so a caller-supplied\n * value can't force an unbounded tree-walk (#4243).\n */\n async index(maxDepth: number = DEFAULT_INDEX_MAX_DEPTH): Promise<IndexStats> {\n const clampedDepth = Math.min(Math.max(maxDepth, 1), MAX_INDEX_MAX_DEPTH);\n const { files, skippedDirs } = await findSourceFiles(this.rootDir, clampedDepth);\n this.skippedDirs = skippedDirs;\n\n for (const file of files) {\n const result = await extractSymbols(file);\n const relPath = relative(this.rootDir, file);\n this.fileResults.set(relPath, result);\n\n for (const symbol of result.symbols) {\n this.symbols.push({ ...symbol, filePath: relPath });\n }\n }\n\n return {\n totalFiles: files.length,\n totalSymbols: this.symbols.length,\n indexedAt: new Date().toISOString(),\n skippedDirs,\n };\n }\n\n /** Search symbols by keyword. Returns top N results sorted by relevance. */\n search(query: string, limit = 20): SearchResult[] {\n const results: SearchResult[] = [];\n\n for (const symbol of this.symbols) {\n const baseScore = scoreMatch(symbol.name, query);\n if (baseScore === null) continue;\n\n const bonus = symbol.exported ? SCORE_EXPORTED_BONUS : 0;\n results.push({\n symbol,\n score: baseScore + bonus,\n matchType: getMatchType(baseScore),\n });\n }\n\n return results.sort((a, b) => b.score - a.score).slice(0, limit);\n }\n\n /** Get a compact summary of a file's symbols. */\n getFileSummary(filePath: string): FileSummary | undefined {\n const result = this.fileResults.get(filePath);\n if (result === undefined) return undefined;\n\n const kinds: Record<string, number> = {};\n let exported = 0;\n let priv = 0;\n\n for (const s of result.symbols) {\n kinds[s.kind] = (kinds[s.kind] ?? 0) + 1;\n if (s.exported) exported++;\n else priv++;\n }\n\n return {\n filePath,\n totalLines: result.totalLines,\n exportedSymbols: exported,\n privateSymbols: priv,\n kinds,\n };\n }\n\n /** List all indexed files with symbol counts. */\n listFiles(): Array<{ path: string; symbols: number; lines: number }> {\n return [...this.fileResults.entries()].map(([path, result]) => ({\n path,\n symbols: result.symbols.length,\n lines: result.totalLines,\n }));\n }\n\n /** Get index statistics. */\n get stats(): { files: number; symbols: number; skippedDirs: number } {\n return {\n files: this.fileResults.size,\n symbols: this.symbols.length,\n skippedDirs: this.skippedDirs,\n };\n }\n}\n","/**\n * AST symbol extraction for token-efficient code retrieval.\n *\n * Uses TypeScript's compiler API to extract function, class, method,\n * interface, and type definitions from source files.\n *\n * Token savings: ~80-99% vs reading full files.\n * No additional dependencies — uses TypeScript (already a project dep).\n *\n * @module indexer/symbol-extractor\n */\n\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport ts from 'typescript';\n\n/** A symbol extracted from source code. */\nexport interface CodeSymbol {\n /** Symbol name */\n name: string;\n /** Symbol kind */\n kind: 'function' | 'class' | 'method' | 'interface' | 'type' | 'variable' | 'enum';\n /** Start line (1-based) */\n startLine: number;\n /** End line (1-based) */\n endLine: number;\n /** Full source text of the symbol */\n text: string;\n /** Whether the symbol is exported */\n exported: boolean;\n}\n\n/**\n * Extensions the TypeScript compiler API path can parse (#4517).\n *\n * Exported so the tool layer can name them in its error message instead of\n * asserting a file \"may not be TypeScript/JavaScript\" without saying what\n * would count.\n */\nexport const SUPPORTED_EXTENSIONS: readonly string[] = ['.ts', '.tsx', '.js', '.jsx'];\n\n/** Result of extracting symbols from a file. */\nexport interface SymbolExtractionResult {\n filePath: string;\n symbols: CodeSymbol[];\n totalLines: number;\n totalChars: number;\n symbolChars: number;\n savingsPercent: number;\n /**\n * Whether the file was actually parsed (#4517).\n *\n * `false` means the extension is not supported, so `symbols: []` reports\n * that nothing was READ — not that nothing is there. An unsupported file and\n * a genuinely symbol-free file previously returned identical results, and\n * the tool guessed between them wrongly: a valid TypeScript barrel of 20\n * re-exports was reported as possibly-not-TypeScript.\n */\n parsed: boolean;\n}\n\nfunction getKind(node: ts.Node): CodeSymbol['kind'] | null {\n if (ts.isFunctionDeclaration(node)) return 'function';\n if (ts.isClassDeclaration(node)) return 'class';\n if (ts.isInterfaceDeclaration(node)) return 'interface';\n if (ts.isTypeAliasDeclaration(node)) return 'type';\n if (ts.isEnumDeclaration(node)) return 'enum';\n if (ts.isMethodDeclaration(node)) return 'method';\n if (ts.isVariableStatement(node)) return 'variable';\n return null;\n}\n\nfunction getName(node: ts.Node): string {\n if (\n ts.isFunctionDeclaration(node) ||\n ts.isClassDeclaration(node) ||\n ts.isInterfaceDeclaration(node) ||\n ts.isTypeAliasDeclaration(node) ||\n ts.isEnumDeclaration(node) ||\n ts.isMethodDeclaration(node)\n ) {\n const nameNode = (node as ts.NamedDeclaration).name;\n return nameNode ? nameNode.getText() : '<anonymous>';\n }\n if (ts.isVariableStatement(node)) {\n const decls = node.declarationList.declarations;\n const firstDecl = decls[0];\n if (firstDecl !== undefined) {\n return firstDecl.name.getText();\n }\n }\n return '<anonymous>';\n}\n\nfunction isExported(node: ts.Node): boolean {\n const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;\n if (modifiers) {\n return modifiers.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);\n }\n return false;\n}\n\nfunction visitNode(node: ts.Node, sourceFile: ts.SourceFile, symbols: CodeSymbol[]): void {\n const kind = getKind(node);\n if (kind !== null) {\n const name = getName(node);\n if (name !== '<anonymous>') {\n const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());\n symbols.push({\n name,\n kind,\n startLine: start.line + 1,\n endLine: end.line + 1,\n text: node.getText(sourceFile),\n exported: isExported(node),\n });\n }\n }\n if (ts.isClassDeclaration(node)) {\n visitClassMembers(node, sourceFile, symbols);\n return;\n }\n ts.forEachChild(node, (child) => {\n visitNode(child, sourceFile, symbols);\n });\n}\n\nfunction visitClassMembers(\n node: ts.ClassDeclaration,\n sourceFile: ts.SourceFile,\n symbols: CodeSymbol[]\n): void {\n for (const member of node.members) {\n if (ts.isMethodDeclaration(member) || ts.isPropertyDeclaration(member)) {\n const memberName = member.name.getText();\n if (memberName !== '<anonymous>') {\n const start = sourceFile.getLineAndCharacterOfPosition(member.getStart());\n const end = sourceFile.getLineAndCharacterOfPosition(member.getEnd());\n symbols.push({\n name: memberName,\n kind: 'method',\n startLine: start.line + 1,\n endLine: end.line + 1,\n text: member.getText(sourceFile),\n exported: false,\n });\n }\n }\n }\n}\n\nfunction computeSavings(totalChars: number, symbolChars: number): number {\n return totalChars > 0 ? Math.round(100 * (1 - symbolChars / totalChars) * 10) / 10 : 0;\n}\n\n/**\n * Extract symbols from a TypeScript/JavaScript file.\n */\nexport async function extractSymbols(filePath: string): Promise<SymbolExtractionResult> {\n const ext = extname(filePath).toLowerCase();\n if (!SUPPORTED_EXTENSIONS.includes(ext)) {\n return {\n filePath,\n symbols: [],\n totalLines: 0,\n totalChars: 0,\n symbolChars: 0,\n savingsPercent: 0,\n parsed: false,\n };\n }\n\n const source = await readFile(filePath, 'utf-8');\n const sourceFile = ts.createSourceFile(filePath, source, ts.ScriptTarget.Latest, true);\n const symbols: CodeSymbol[] = [];\n\n ts.forEachChild(sourceFile, (node) => {\n visitNode(node, sourceFile, symbols);\n });\n\n const totalChars = source.length;\n const symbolChars = symbols.reduce((sum, s) => sum + s.text.length, 0);\n\n return {\n filePath,\n symbols,\n totalLines: source.split('\\n').length,\n totalChars,\n symbolChars,\n savingsPercent: computeSavings(totalChars, symbolChars),\n parsed: true,\n };\n}\n\n/**\n * Why {@link extractSymbolIndex} produced no index (#4517).\n *\n * `unsupported` and `no-declarations` are different facts about the world:\n * the first says the file was never read, the second says it was read and\n * genuinely declares nothing locally — a re-export barrel, typically. Callers\n * that collapse them tell the user to check a file type that was never the\n * problem.\n */\nexport type EmptyIndexReason = 'unsupported' | 'no-declarations';\n\n/** A symbol index, or the reason there is none. */\nexport type SymbolIndexResult =\n | { readonly kind: 'index'; readonly index: string }\n | { readonly kind: 'empty'; readonly reason: EmptyIndexReason };\n\n/**\n * Extract a compact symbol index, reporting why when there is nothing to show.\n *\n * Names + locations only, no source text — the minimal representation for LLM\n * context (~95%+ token savings). Replaced the earlier `extractSymbolIndex`,\n * which returned a bare `''` for both \"could not read\" and \"read, found\n * nothing\" and so could not tell a caller which had happened.\n */\nexport async function extractSymbolIndexResult(filePath: string): Promise<SymbolIndexResult> {\n const result = await extractSymbols(filePath);\n if (!result.parsed) return { kind: 'empty', reason: 'unsupported' };\n if (result.symbols.length === 0) return { kind: 'empty', reason: 'no-declarations' };\n return { kind: 'index', index: renderIndex(filePath, result) };\n}\n\nfunction renderIndex(filePath: string, result: SymbolExtractionResult): string {\n const lines = result.symbols.map((s) => {\n const exp = s.exported ? 'export ' : '';\n return `${exp}${s.kind} ${s.name} (L${String(s.startLine)}-${String(s.endLine)})`;\n });\n return `// ${filePath} — ${String(result.symbols.length)} symbols\\n${lines.join('\\n')}`;\n}\n"],"mappings":";AAYA,SAAS,eAAe;AACxB,SAAS,SAAS,WAAAA,UAAS,gBAAgB;;;ACD3C,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,OAAO,QAAQ;AAyBR,IAAM,uBAA0C,CAAC,OAAO,QAAQ,OAAO,MAAM;AAsBpF,SAAS,QAAQ,MAA0C;AACzD,MAAI,GAAG,sBAAsB,IAAI,EAAG,QAAO;AAC3C,MAAI,GAAG,mBAAmB,IAAI,EAAG,QAAO;AACxC,MAAI,GAAG,uBAAuB,IAAI,EAAG,QAAO;AAC5C,MAAI,GAAG,uBAAuB,IAAI,EAAG,QAAO;AAC5C,MAAI,GAAG,kBAAkB,IAAI,EAAG,QAAO;AACvC,MAAI,GAAG,oBAAoB,IAAI,EAAG,QAAO;AACzC,MAAI,GAAG,oBAAoB,IAAI,EAAG,QAAO;AACzC,SAAO;AACT;AAEA,SAAS,QAAQ,MAAuB;AACtC,MACE,GAAG,sBAAsB,IAAI,KAC7B,GAAG,mBAAmB,IAAI,KAC1B,GAAG,uBAAuB,IAAI,KAC9B,GAAG,uBAAuB,IAAI,KAC9B,GAAG,kBAAkB,IAAI,KACzB,GAAG,oBAAoB,IAAI,GAC3B;AACA,UAAM,WAAY,KAA6B;AAC/C,WAAO,WAAW,SAAS,QAAQ,IAAI;AAAA,EACzC;A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