Files
socraticode/skills/codebase-exploration/references/tool-reference.md
Giancarlo Erra 50d8853ea6 feat(visualize): add interactive HTML graph explorer; British-English doc sweep
Interactive Viewer (primary)
────────────────────────────
codebase_graph_visualize now accepts mode="mermaid" (default, existing
behaviour — text Mermaid diagram) or mode="interactive". Interactive
mode generates a self-contained HTML page and opens it in the user's
default browser via the `open` npm package (cross-platform: macOS,
Linux, Windows). Cytoscape.js 3.30.2 + Dagre 0.8.5 + cytoscape-dagre
2.5.0 are vendored under src/assets/ — no CDN, works offline.

Features:
- File view — every source file as a node, imports as edges, language
  colour-coded, circular deps highlighted in red.
- Symbol view toggle — functions/classes/methods as nodes with call
  edges (confidence-styled). Embedded when the symbol graph fits under
  20k symbols / 60k call edges; above that threshold the file view
  remains usable and a banner directs users to codebase_impact /
  codebase_symbols for symbol-level queries.
- Sidebar on node click — imports, dependents, per-file symbol list
  (first 30 + link to codebase_symbols), action buttons for blast
  radius and call flow.
- Right-click any node → blast radius overlay (reverse-transitive
  closure). Call-flow button on the sidebar for forward traversal.
- Live search across files and symbols, six Cytoscape layouts
  (Dagre / force / concentric / breadth-first / grid / circle),
  PNG export (filename sanitised for cross-platform safety).
- `open: false` parameter skips auto-launch and just returns the file
  path — useful in headless environments.

Viewer is XSS-safe by construction: all DOM built with createElement
+ textContent (no innerHTML anywhere); embedded JSON escapes every
"<" as \u003c so a stray </script> in a file path or symbol name
cannot break out of the script-type="application/json" container.

New files:
- src/assets/{cytoscape.min.js,dagre.min.js,cytoscape-dagre.js,
  viewer-template.html,viewer-styles.css,viewer-app.js}
- scripts/copy-assets.mjs — postbuild copier (tsc does not handle
  non-TS files); wired into npm run build and prepublishOnly
- src/services/graph-visualize-html.ts — HTML builder with scale-cap
  logic (MAX_SYMBOLS / MAX_EDGES / MAX_SYMS_PER_FILE) and parallel
  per-file Qdrant payload loading
- src/services/graph-visualize-browser.ts — temp-file write +
  cross-platform open wrapper
- tests/unit/graph-visualize-html.test.ts — 5 tests (self-contained,
  escape-safety, symbolMode omitted/capped, cycle marking)
- tests/unit/graph-visualize-browser.test.ts — 4 tests (deterministic
  path, overwrite, success + failure paths)

New runtime dependency: open@^10.2.0 (Sindre Sorhus, zero transitive
deps, cross-platform).

British-English doc sweep (secondary)
─────────────────────────────────────
Switched all project docs to British English spelling:
  behavior → behaviour                organized → organised
  color-coded → colour-coded          initialization → initialisation
  visualization → visualisation       customization → customisation
  recognized → recognised             optimized → optimised
  acknowledgment → acknowledgement    finalize → finalise
  analyzing → analysing               apologizing → apologising
  sexualized → sexualised

Affected files: README, DEVELOPER, AGENTS, CLAUDE, GEMINI, SECURITY,
CONTRIBUTING, CODE_OF_CONDUCT, agents/codebase-explorer.md,
skills/codebase-exploration/{SKILL.md,references/tool-reference.md},
skills/codebase-management/references/tool-reference.md.

Also surfaced Impact Analysis in the top-level README paragraph.

Docs
────
- README: "Interactive graph explorer" subsection under Impact Analysis,
  tool-table row updated.
- DEVELOPER.md: architecture section under codebase_graph_visualize
  covering asset layout, data flow, cap logic, XSS-safety invariants.
- AGENTS.md / CLAUDE.md / GEMINI.md: new "User asks for a visual /
  interactive / shareable graph" row in the tool-routing table.
- skills/codebase-exploration/: SKILL.md bullet + tool-reference.md
  full mode description.
- CHANGELOG.md: "Interactive Graph Explorer" section under Unreleased.

Quality gates (all green)
─────────────────────────
- Biome lint: clean
- TypeScript (tsc): clean
- Unit tests: 685/685
- Integration tests: 154/154 (real Qdrant + Ollama)
- CodeRabbit: No findings (1 fix applied — filename sanitisation)
- Snyk code test: 0 issues

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 16:04:41 +01:00

8.8 KiB

SocratiCode Exploration Tools — Full Reference

Semantic search across an indexed codebase. Only use after codebase_index is complete.

Parameter Type Required Default Description
query string yes Natural language search query (e.g. "authentication middleware", "database connection setup")
projectPath string no cwd Absolute path to the project directory
limit number (1-50) no 10 Maximum results. Override globally via SEARCH_DEFAULT_LIMIT env var
fileFilter string no Filter results to a specific file path (relative)
languageFilter string no Filter results to a specific language (e.g. "typescript", "python")
minScore number (0-1) no 0.10 Minimum RRF score threshold. Override via SEARCH_MIN_SCORE. Set to 0 to disable

Returns: Ranked code chunks with file paths, line numbers, language, and RRF scores.

Key behaviours:

  • Uses hybrid semantic + keyword (BM25) search with Reciprocal Rank Fusion
  • Warns if indexing is in progress (results will be incomplete during full index)
  • Warns if file watcher is not active (results may be stale)
  • Results below minScore are filtered out with a count of omitted results

codebase_status

Check index status: chunk count, indexing progress, last completed operation, file watcher state.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory

Returns: Detailed status including:

  • Collection name and indexed chunk count
  • In-progress indexing: phase, file/chunk progress percentage, batch info, elapsed time
  • Last completed operation: type, files processed, chunks created, duration
  • Incomplete index detection (previous run interrupted)
  • Cross-process indexing detection (another process actively indexing)
  • File watcher status (active / watched by another process / inactive)
  • Code graph status (files, edges, last built, cached in memory)
  • Context artifacts status

Key behaviours:

  • Call every ~60 seconds during indexing to poll progress AND keep the MCP connection alive
  • Detects both same-process and cross-process indexing

codebase_graph_query

Query the dependency graph for a specific file.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory
filePath string yes Relative path of the file to query (e.g. "src/index.ts")

Returns: Two lists: what this file imports (→) and what depends on it (←).

Key behaviours:

  • Requires graph to exist (auto-built after indexing, or use codebase_graph_build)
  • Auto-starts file watcher on query
  • Use relative paths (not absolute)

codebase_graph_stats

Get statistics about the code dependency graph.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory

Returns: Total files, edges, average dependencies per file, circular dependency count, language breakdown, top 10 most connected files, first 20 orphan files.


codebase_graph_circular

Find circular dependencies in the codebase.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory

Returns: List of circular dependency chains (up to 20, with total count).

Key behaviours:

  • Detects transitive circular dependencies
  • Useful for debugging subtle runtime issues caused by import cycles

codebase_graph_visualize

Visualise the dependency graph. Two modes:

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory
mode "mermaid" | "interactive" no "mermaid" Output format
open boolean no true In interactive mode, auto-open the browser

mode="mermaid" (default) — returns a Mermaid flowchart code block. Nodes colour-coded by language, circular dependency edges highlighted in red. Renders inline in markdown viewers, VS Code, GitHub.

mode="interactive" — generates a self-contained HTML page (vendored Cytoscape.js + Dagre, works offline) written to the OS temp dir and opened in the user's default browser.

  • File view and (when available) Symbol view toggle
  • Click a node → sidebar with imports / dependents / symbols / line numbers
  • Right-click → blast radius overlay (reverse-transitive closure)
  • Live search, six layouts, PNG export
  • Shareable file — commit to a PR or attach to chat

Key behaviours:

  • Interactive mode always includes the file view; the symbol view toggle is available when the symbol graph fits under embed caps (≤ 20k symbols / ≤ 60k call edges). Above that cap, the HTML still works — use codebase_impact / codebase_symbols for symbol-level queries.
  • Browser auto-open is best-effort. If it fails (headless environments, blocked browsers) the tool output still includes the file path.
  • Choose this mode when the user asks for a visual, interactive, or shareable graph.

codebase_graph_status

Check graph build status and progress.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory

Returns: If building: phase, file progress, elapsed time. If ready: node/edge counts, last built timestamp, cache status, last build duration.

Key behaviours:

  • Use to poll progress after codebase_graph_build
  • Shows build errors if last build failed

codebase_context

List all context artifacts defined in .socraticodecontextartifacts.json.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory

Returns: Each artifact's name, description, path, and index status (chunk count, last indexed timestamp, or "not yet indexed"). If no config exists, provides a template.


Semantic search across context artifacts.

Parameter Type Required Default Description
query string yes Natural language query (e.g. "tables related to billing", "authentication endpoints")
projectPath string no cwd Absolute path to the project directory
artifactName string no Filter to a specific artifact by name. Omit to search all
limit number (1-50) no 10 Maximum results
minScore number (0-1) no 0.10 Minimum RRF score threshold

Returns: Artifact content chunks with artifact name, file path, line ranges, and scores.

Key behaviours:

  • Auto-indexes artifacts on first use (no manual step needed)
  • Auto-detects stale artifacts and re-indexes changed ones
  • Works with any text-based artifact: SQL, OpenAPI, Terraform, K8s, YAML, markdown, etc.

codebase_about

Display information about SocratiCode and all its tools.

Parameter Type Required Default Description
(none) No parameters

Returns: Tool summary by category, typical workflow, infrastructure status, version info.


Tips

Search tips

  • A single codebase_search returns ranked snippets from the entire codebase in milliseconds — far cheaper than opening files speculatively
  • The RRF score combines semantic similarity and keyword match; higher scores = better relevance
  • Use fileFilter when you know the area, languageFilter when cross-language results are noisy
  • Lower minScore to 0 when exploring broadly; raise it for precision

Graph tips

  • The graph is auto-built after codebase_index — usually no need to call codebase_graph_build manually
  • codebase_graph_visualize generates Mermaid that renders in GitHub, VS Code, and most markdown viewers
  • Check codebase_graph_circular when debugging mysterious behaviour — circular deps cause subtle issues

Context artifact tips

  • codebase_context_search auto-indexes on first use — just search, no setup needed
  • Stale artifacts are auto-detected and re-indexed when content changes
  • Use artifactName filter to target specific schemas or specs
  • Supported types: SQL schemas, OpenAPI/Protobuf specs, Terraform configs, K8s manifests, architecture docs, env configs — any text-based file