Files
socraticode/skills/codebase-management/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

9.3 KiB

SocratiCode Management Tools — Full Reference

codebase_index

Start indexing a codebase in the background. Returns immediately.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory
extraExtensions string no Comma-separated additional extensions (e.g. ".tpl,.blade,.hbs"). Also via EXTRA_EXTENSIONS env var

Returns: Confirmation that indexing started, with instructions to poll codebase_status.

Key behaviours:

  • Runs asynchronously — does NOT block. Returns immediately.
  • Auto-starts file watcher upon completion (if not cancelled)
  • Ensures Docker/Qdrant/Ollama infrastructure is running first
  • Concurrency guard: if already indexing, returns current progress instead of starting again
  • Auto-indexes context artifacts defined in .socraticodecontextartifacts.json
  • Auto-builds code graph after indexing completes
  • Batched and resumable: checkpoints after each batch of 50 files. Interruptions don't lose work.

codebase_update

Incrementally update an existing index. Only re-indexes changed files.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory
extraExtensions string no Comma-separated additional extensions

Returns: Statistics: files added/updated/removed, chunks created.

Key behaviours:

  • Runs synchronously (blocking), unlike codebase_index
  • Only processes files changed since last index (via content hash comparison)
  • Auto-starts file watcher if not already active
  • Usually not needed if the file watcher is running

codebase_remove

Remove a project's entire index from the vector database.

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

Returns: Confirmation of removal.

Key behaviours:

  • Destructive — cannot be undone
  • Safely stops file watcher (same-process and cross-process)
  • Cancels in-progress indexing and drains current batch
  • Waits for in-flight graph builds to finish before deletion
  • May refuse if indexing batch can't drain within 5 minutes (retry after)

codebase_stop

Gracefully stop an in-progress indexing operation.

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

Returns: Confirmation with current phase and batch info.

Key behaviours:

  • Current batch finishes and checkpoints — all progress preserved
  • Re-run codebase_index to resume from where it left off
  • Handles both same-process and cross-process (orphan) indexing
  • Sends SIGTERM to orphan processes holding the lock
  • Non-destructive — progress is never lost

codebase_watch

Start/stop/status of live file watching.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory
action enum yes "start", "stop", or "status"

Returns: Action result or list of watched projects.

Key behaviours:

  • start: Runs catch-up incremental update first, then starts debounced file watcher
  • stop: Stops same-process watcher (cross-process watchers unaffected)
  • status: Lists all watched projects including cross-process watchers
  • Detects if another process already watches the same project
  • Auto-started after successful codebase_index or codebase_update
  • Debounced with ~500ms delay to batch rapid file changes

codebase_graph_build

Build the dependency graph using AST-based static analysis.

Parameter Type Required Default Description
projectPath string no cwd Absolute path to the project directory
extraExtensions string no Additional extensions included as leaf nodes (dependency targets)

Returns: Confirmation that build started. Poll with codebase_graph_status.

Key behaviours:

  • Runs asynchronously in background
  • Auto-built during codebase_index (usually no need to call manually)
  • Concurrency guard: if already building, shows progress
  • Uses ast-grep for static import/require/export analysis across 18+ languages
  • Skips files larger than 1 MB

codebase_graph_remove

Remove a project's persisted code graph.

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

Returns: Confirmation of removal.

Key behaviours:

  • Destructive — cannot be undone
  • Waits for in-flight builds before deletion
  • Graph auto-rebuilds during next codebase_index

codebase_graph_status

Check graph build status and readiness.

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, build duration.


codebase_context_index

Index or re-index all context artifacts.

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

Returns: Summary: artifacts indexed with chunk counts, any errors.

Key behaviours:

  • Runs synchronously (blocking)
  • Usually auto-triggered by codebase_context_search on first use
  • Reports individual artifact errors without stopping the whole operation

codebase_context_remove

Remove all indexed context artifacts.

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

Returns: Confirmation of removal.

Key behaviours:

  • Destructive — cannot be undone
  • Blocked while indexing is in progress (wait for finish or use codebase_stop)
  • Removes ALL artifacts (not selective)

codebase_health

Check infrastructure health: Docker, Qdrant, Ollama, embedding model.

Parameter Type Required Default Description
(none) No parameters

Returns: Status for each component with [OK]/[MISSING] indicators.

Key behaviours:

  • Checks Docker availability
  • Checks Qdrant (managed container or external endpoint)
  • Checks embedding provider health (Ollama, OpenAI, or Google)
  • Suggests fixes for missing components
  • Works with both managed (Docker) and external (remote Qdrant) modes

codebase_list_projects

List all projects that have been indexed.

Parameter Type Required Default Description
(none) No parameters

Returns: List with project paths, collection names, last indexed timestamp, file counts, graph info, context artifact status. Flags incomplete indexes.


Architectural Behaviors

Concurrency guards

  • Only one indexing operation per project at a time
  • Only one graph build per project at a time
  • Duplicate operations return current progress instead of starting again

Checkpoint & resume

  • Indexing checkpoints after each batch of 50 files
  • Interrupted indexing resumes from the last checkpoint automatically
  • codebase_stop preserves all progress — resume with codebase_index

Cross-process coordination

  • File-based locking (proper-lockfile) prevents conflicts between multiple MCP instances
  • Detects watchers/indexing running in other processes
  • Can terminate orphan processes via SIGTERM
  • Stale locks from crashed processes are auto-reclaimed

Auto-features

  • File watcher auto-starts after indexing/updates
  • Context artifacts auto-indexed on first codebase_context_search
  • Stale artifacts auto-detected and re-indexed
  • Code graph auto-built after indexing
  • Session resume: watcher restarts on first tool use for previously indexed projects

Supported file extensions

Built-in: .js, .jsx, .ts, .tsx, .mjs, .cjs, .py, .pyw, .pyi, .java, .kt, .kts, .scala, .c, .h, .cpp, .hpp, .cc, .hh, .cxx, .cs, .go, .rs, .rb, .php, .swift, .sh, .bash, .zsh, .html, .htm, .css, .scss, .sass, .less, .vue, .svelte, .json, .yaml, .yml, .toml, .xml, .ini, .cfg, .md, .mdx, .rst, .txt, .sql, .dart, .lua, .r, .R, .dockerfile

Special files: Dockerfile, Makefile, Rakefile, Gemfile, Procfile, .env.example, .gitignore, .dockerignore

Custom: Add via extraExtensions parameter or EXTRA_EXTENSIONS env var.

Chunking defaults

  • Chunk size: 100 lines, 10 lines overlap
  • Batch size: 50 files per batch (for resumable checkpointing)
  • Max chunk chars: 2000 (safety limit)
  • Max file size: 5 MB (configurable via MAX_FILE_SIZE_MB)