@@ -1429,7 +1429,7 @@ const CODER_SCHEMA = { type: "object", properties: { thought: { type: "string" }
14291429// it has no tools. normalizeToolCall recovers the real name + args so tools still fire.
14301430const TOOL_ARGKEY = { run_command: "command", run_background: "command", read_file: "path", write_file: "path", edit_file: "path", multi_edit: "path", multiedit: "path", apply_patch: "patch", patch: "patch", list_dir: "path", make_dir: "path", mkdir: "path", delete: "path", delete_file: "path", rm: "path", move: "from", copy: "from", search: "pattern", grep: "pattern", find: "glob", glob: "glob", http_fetch: "url", web_fetch: "url", fetch_url: "url", http: "url", web_search: "query", discover: "query", remember: "text", check_background: "id", stop_background: "id", list_processes: "filter", batch: "ops", batch_read: "ops", browser_read: "target", browser_page: "target", browser_eval: "expression", browser_exec: "expression", browser_screenshot: "path", browser_shot: "path", ask_user: "question", ask_question: "question", ask: "question" };
14311431const KNOWN_ARGKEYS = new Set(["path", "command", "content", "query", "q", "url", "pattern", "glob", "find", "text", "note", "id", "filter", "to", "from", "dest", "name", "tasks", "todos", "items", "method", "replace", "recursive"]);
1432- const KNOWN_TOOLS = new Set(["read_file", "write_file", "edit_file", "list_dir", "run_command", "run_background", "check_background", "stop_background", "search", "grep", "find", "find_files", "glob", "http_fetch", "web_fetch", "fetch_url", "http", "web_search", "search_web", "google", "todo_write", "todos", "todo_list", "write_todos", "sysinfo", "system_info", "list_processes", "ps", "make_dir", "mkdir", "move", "rename", "move_file", "copy", "copy_file", "delete", "delete_file", "rm", "remember", "discover", "spawn_agents", "repo_map", "repomap", "multi_edit", "multiedit", "apply_patch", "patch", "verify", "run_tests", "test_project", "find_symbol", "symbol", "goto", "find_references", "references", "find_refs", "usages", "callers", "module_graph", "import_graph", "deps_graph", "dependents", "importers", "outline", "file_outline", "symbols", "read_symbol", "read_function", "show_symbol", "json_query", "jq", "read_json", "undo_edit", "replace_in_files", "wait_for", "write_stdin", "batch", "batch_read", "invariants", "check_invariants", "difflint", "attest", "attestation", "capability_attest", "bisect", "regression_bisect", "explain_break", "explainbreak", "blame_turn", "shrink", "minimize_change", "ddmin", "browser_status", "browser_tabs", "browser_list", "browser_read", "browser_page", "browser_eval", "browser_exec", "browser_screenshot", "browser_shot", "ask_user", "ask_question", "ask"]);
1432+ const KNOWN_TOOLS = new Set(["code_search", "read_file", "write_file", "edit_file", "list_dir", "run_command", "run_background", "check_background", "stop_background", "search", "grep", "find", "find_files", "glob", "http_fetch", "web_fetch", "fetch_url", "http", "web_search", "search_web", "google", "todo_write", "todos", "todo_list", "write_todos", "sysinfo", "system_info", "list_processes", "ps", "make_dir", "mkdir", "move", "rename", "move_file", "copy", "copy_file", "delete", "delete_file", "rm", "remember", "discover", "spawn_agents", "repo_map", "repomap", "multi_edit", "multiedit", "apply_patch", "patch", "verify", "run_tests", "test_project", "find_symbol", "symbol", "goto", "find_references", "references", "find_refs", "usages", "callers", "module_graph", "import_graph", "deps_graph", "dependents", "importers", "outline", "file_outline", "symbols", "read_symbol", "read_function", "show_symbol", "json_query", "jq", "read_json", "undo_edit", "replace_in_files", "wait_for", "write_stdin", "batch", "batch_read", "invariants", "check_invariants", "difflint", "attest", "attestation", "capability_attest", "bisect", "regression_bisect", "explain_break", "explainbreak", "blame_turn", "shrink", "minimize_change", "ddmin", "browser_status", "browser_tabs", "browser_list", "browser_read", "browser_page", "browser_eval", "browser_exec", "browser_screenshot", "browser_shot", "ask_user", "ask_question", "ask"]);
14331433// A tool "name" that is really a shell command line — weak models often emit
14341434// {tool:"cat /etc/passwd"} or {tool:"ls /bin/*"} instead of run_command.
14351435const SHELL_CMD = /^(sudo\s+)?(ls|cat|grep|egrep|fgrep|echo|cd|pwd|whoami|id|uname|hostname|ps|top|df|du|free|date|env|printenv|which|type|find|locate|head|tail|awk|sed|cut|tr|sort|uniq|wc|xargs|tee|curl|wget|ping|traceroute|nmap|nc|ncat|dig|host|nslookup|ip|ifconfig|iwconfig|netstat|ss|arp|route|cp|mv|rm|mkdir|rmdir|touch|ln|stat|file|chmod|chown|tar|gzip|gunzip|zip|unzip|git|make|gcc|python3?|node|npm|npx|pip3?|bash|sh|zsh|kill|pkill|killall|systemctl|service|apt|apt-get|dpkg|ssh|scp|rsync|darknode|sentinel|nexus|nikto|sqlmap|hydra|john|hashcat|gobuster|ffuf|masscan|whatweb|searchsploit|msfconsole)(\s|$)/i;
@@ -2407,6 +2407,7 @@ async function deviceTool(name, a, cwd) {
24072407 // outline: the structural symbol outline of ONE file (functions/classes/types in source order with
24082408 // line numbers) — jump around a big unfamiliar file fast. Reuses the repo-map symbol extractor.
24092409 if (name === "read_symbol" || name === "read_function" || name === "show_symbol") return require("./lib/nexus/read-symbol").readSymbolTool(a, cwd, rp);
2410+ if (name === "code_search" || name === "semantic_search" || name === "search_code") return require("./lib/nexus/code-search").codeSearchTool(a, cwd);
24102411 if (name === "json_query" || name === "jq" || name === "read_json") return require("./lib/nexus/json-query").jsonQueryTool(a, cwd, rp);
24112412 if (name === "outline" || name === "file_outline" || name === "symbols") {
24122413 if (!(a.path || a.file)) return { error: "outline needs path (one file) — for the whole project use repo_map" };
@@ -3034,14 +3035,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
30343035 // .nexus/index.json: a BM25 index over ~60-line chunks (lib/nexus/bm25.js). An index from an
30353036 // older Nexus (a per-file keyword list) is ignored until /index is run again.
30363037 let index = null; try { const raw = JSON.parse(stripBom(fs.readFileSync(path.join(cwd, ".nexus", "index.json"), "utf8"))); if (raw && raw.version === bm25.VERSION && raw.docs) index = raw; } catch (_) {}
3037- const buildIndex = () => {
3038- const files = {}; const SKIP = /(^|\/)(\.git|node_modules|\.nexus|dist|build|\.cache|\.next|target|__pycache__)(\/|$)/;
3039- const CODE = /\.(js|jsx|ts|tsx|py|rb|go|rs|java|c|h|cpp|cc|cs|php|swift|kt|sh|css|scss|html|json|md|yml|yaml|toml)$/i;
3040- const GEN = /(^|\/)(package-lock\.json|yarn\.lock|pnpm-lock\.yaml|composer\.lock|Cargo\.lock)$|\.(min\.js|min\.css|map)$/;
3041- const list = []; let bytes = 0;
3042- const walk = (d) => { let ents; try { ents = fs.readdirSync(d, { withFileTypes: true }); } catch (_) { return; } for (const e of ents) { const fp = path.join(d, e.name); if (SKIP.test(e.name)) continue; if (e.isDirectory()) walk(fp); else if (CODE.test(e.name) && !GEN.test(e.name)) { try { if (fs.statSync(fp).size > 2000000 || bytes > 64 * 1024 * 1024) continue; const txt = fs.readFileSync(fp, "utf8"); bytes += txt.length; list.push({ path: path.relative(cwd, fp), content: txt }); } catch (_) {} } if (list.length > 4000) return; } };
3043- walk(cwd); index = Object.assign(bm25.buildIndex(list), { files: list.length, ts: Date.now() }); try { fs.mkdirSync(path.join(cwd, ".nexus"), { recursive: true }); fs.writeFileSync(path.join(cwd, ".nexus", "index.json"), JSON.stringify(index)); } catch (_) {} return list.length;
3044- };
3038+ const buildIndex = () => { index = require("./lib/nexus/code-search").buildAndSave(cwd); return index.files; };
30453039 // the chunks most relevant to the prompt by BM25, skipping files already pinned or @-mentioned
30463040 // (they are in the prompt anyway): [{ path, start, end, score }]
30473041 const retrieve = (text, k) => { if (!index) return []; return bm25.search(index, text, { k: (k || 3) + 4 }).filter((h) => !pinned.has(h.path) && !text.includes("@" + h.path)).slice(0, k || 3); };
@@ -4383,7 +4377,7 @@ function nexusTui(engine, cwd, nexusMd, autoResume, launch) {
43834377 else if (imgAttach.length) oMsgs.push({ role: "user", content: promptText, images: imgAttach.map((im) => im.b64) }); // Ollama vision (llava / llama3.2-vision / …)
43844378 else oMsgs.push({ role: "user", content: promptText });
43854379 sess.inTok += Math.ceil(promptText.length / 4);
4386- const olbl = (n, a) => n === "read_symbol" ? "ReadSymbol(" + relP(a.path) + " " + oneline(a.name || "", 30) + ")" : n === "json_query" ? "JsonQuery(" + relP(a.path) + (a.query ? " " + oneline(a.query, 30) : "") + ")" : n === "undo_edit" ? "UndoEdit(" + relP(a.path) + ")"
4380+ const olbl = (n, a) => n === "code_search" ? "CodeSearch(" + oneline(a.query || "", 40) + ")" : n === " read_symbol" ? "ReadSymbol(" + relP(a.path) + " " + oneline(a.name || "", 30) + ")" : n === "json_query" ? "JsonQuery(" + relP(a.path) + (a.query ? " " + oneline(a.query, 30) : "") + ")" : n === "undo_edit" ? "UndoEdit(" + relP(a.path) + ")"
43874381 : n === "replace_in_files" ? (a.dry_run || a.preview ? "ReplacePreview(" : "Replace(") + oneline(String(a.find != null ? a.find : a.pattern || ""), 24) + " → " + oneline(String(a.replace != null ? a.replace : a.replacement || ""), 24) + ")" : n === "wait_for" ? "WaitFor(" + oneline(String(a.port ? "port " + a.port : a.url || a.file || ((a.job || a.id || "") + (a.pattern ? " /" + a.pattern + "/" : ""))), 40) + ")"
43884382 : n === "write_stdin" ? "Stdin(" + (a.id || a.job || "?") + ": " + oneline(String(a.input != null ? a.input : a.text || ""), 30) + ")" : n === "read_file" ? "Read(" + relP(a.path) + ")" : n === "write_file" ? "Write(" + relP(a.path) + ")" : n === "edit_file" ? "Update(" + relP(a.path) + ")" : (n === "multi_edit" || n === "multiedit") ? "Update(" + relP(a.path) + ")" : (n === "apply_patch" || n === "patch") ? "Patch(" + ((_pf) => _pf.length === 1 && _pf[0].file ? relP(_pf[0].file) : (_pf.length || "?") + " files")(parsePatch(a.patch || a.diff || a.content || a.input || "") || []) + ")" : n === "run_command" ? "Bash(" + oneline(a.command, Math.max(40, cols() - 30)) + ")" : n === "run_background" ? "Background(" + oneline(a.command, 32) + ")" : n === "check_background" ? "CheckJob(" + (a.id || "all") + ")" : n === "stop_background" ? "StopJob(" + (a.id || "?") + ")" : n === "list_dir" ? "List(" + (a.path || ".") + ")" : (n === "search" || n === "grep") ? "Search(" + oneline(a.pattern || a.query, 30) + ")" : (n === "find" || n === "find_files" || n === "glob") ? "Find(" + oneline(a.glob || a.pattern || a.name, 30) + ")" : (n === "http_fetch" || n === "web_fetch" || n === "fetch_url" || n === "http") ? "Fetch(" + oneline(a.url, 36) + ")" : (n === "web_search" || n === "search_web" || n === "google") ? "WebSearch(" + oneline(a.query || a.q, 30) + ")" : (n === "view_image" || n === "view_img" || n === "show_image") ? "ViewImage(" + base(a.path || a.file || a.image || "") + ")" : (n === "todo_write" || n === "todos" || n === "todo_list" || n === "write_todos") ? "Update Todos" : (n === "sysinfo" || n === "system_info") ? "Sysinfo()" : (n === "list_processes" || n === "ps") ? "Processes()" : (n === "make_dir" || n === "mkdir") ? "Mkdir(" + base(a.path) + ")" : (n === "move" || n === "rename" || n === "move_file") ? "Move(" + base(a.to || a.dest) + ")" : (n === "copy" || n === "copy_file") ? "Copy(" + base(a.to || a.dest) + ")" : (n === "delete" || n === "delete_file" || n === "rm") ? "Delete(" + base(a.path) + ")" : n === "spawn_agents" ? "Task(" + ((a.tasks || []).length) + " agents)" : (n === "repo_map" || n === "repomap" || n === "map") ? "RepoMap()" : (n === "find_symbol" || n === "symbol" || n === "goto") ? "Symbol(" + oneline(a.name || a.symbol || a.query || "", 26) + ")" : (n === "find_references" || n === "references" || n === "find_refs" || n === "usages" || n === "callers") ? "References(" + oneline(a.name || a.symbol || a.query || "", 24) + ")" : (n === "module_graph" || n === "import_graph" || n === "deps_graph" || n === "dependents" || n === "importers") ? "ModuleGraph(" + (a.path || a.file || a.target ? base(a.path || a.file || a.target) : "project") + ")" : (n === "outline" || n === "file_outline" || n === "symbols") ? "Outline(" + base(a.path || a.file || "") + ")" : (n === "verify" || n === "run_tests" || n === "test_project") ? "Verify(" + oneline(a.kind || a.command || "auto", 24) + ")" : (n === "ask_user" || n === "ask_question" || n === "ask") ? "AskUser(" + oneline(a.question || a.prompt || a.q || "", 28) + ")" : n === "remember" ? "Remember(" + oneline(a.text || a.note || "", 34) + ")" : n === "discover" ? "Discover(" + oneline(a.query || a.q || "", 30) + ")" : (n === "batch" || n === "batch_read") ? "Batch(" + ((a.ops || a.operations || a.calls || []).length) + " ops)" : (n === "invariants" || n === "check_invariants" || n === "difflint") ? "Invariants()" : (n === "attest" || n === "attestation" || n === "capability_attest") ? "Attest()" : (n === "bisect" || n === "regression_bisect") ? "Bisect(" + oneline(a.test || a.command || "auto", 24) + ")" : (n === "explain_break" || n === "explainbreak" || n === "blame_turn") ? "ExplainBreak()" : (n === "shrink" || n === "minimize_change" || n === "ddmin") ? "Shrink(" + oneline(a.test || a.command || "auto", 24) + ")" : String(n).startsWith("mcp__") ? String(n).replace(/^mcp__/, "").replace("__", ":") + "()" : n + "()";
43894383 (async () => {
0 commit comments