probe-explore.mjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env node
  2. // One-shot probe: run handleExplore against an existing index using the built
  3. // dist, print the output + a few stats. Lets us verify explore's coverage fix
  4. // without a full agent run. Usage: node probe-explore.mjs <repo-with-.codegraph> "<query>"
  5. import { pathToFileURL } from 'node:url';
  6. import { resolve } from 'node:path';
  7. const [, , repo, query] = process.argv;
  8. if (!repo || !query) {
  9. console.error('usage: probe-explore.mjs <repo> "<query>"');
  10. process.exit(1);
  11. }
  12. const load = async (rel) => import(pathToFileURL(resolve(rel)).href);
  13. const idx = await load('dist/index.js');
  14. const tools = await load('dist/mcp/tools.js');
  15. // esModuleInterop: dynamic import of CJS yields { default: module.exports, ...named }
  16. const CodeGraph = idx.default?.default ?? idx.default ?? idx.CodeGraph;
  17. const ToolHandler = tools.ToolHandler ?? tools.default?.ToolHandler;
  18. if (typeof CodeGraph?.openSync !== 'function') {
  19. console.error('could not resolve CodeGraph.openSync; index keys:', Object.keys(idx), 'default keys:', idx.default && Object.keys(idx.default));
  20. process.exit(2);
  21. }
  22. if (typeof ToolHandler !== 'function') {
  23. console.error('could not resolve ToolHandler; tools keys:', Object.keys(tools));
  24. process.exit(2);
  25. }
  26. const cg = CodeGraph.openSync(repo);
  27. const h = new ToolHandler(cg);
  28. const res = await h.execute('codegraph_explore', { query });
  29. const text = res.content?.[0]?.text ?? '(no text)';
  30. console.log(text);
  31. console.error('\n--- PROBE STATS ---');
  32. console.error('output chars:', text.length);
  33. console.error('triggerRender body present (-> setState({})):', /triggerRender[\s\S]{0,400}setState\(\{\}\)/.test(text));
  34. console.error('App.tsx in source section:', /#### .*App\.tsx —/.test(text));
  35. try { cg.close?.(); } catch {}