Skip to content

feat(code-search): structural CodeMatch tool; wire CodeSearch + incremental refresh - #238

Merged
Patel230 merged 1 commit into
mainfrom
feat/cocoindex-adoptions
Aug 23, 2026
Merged

feat(code-search): structural CodeMatch tool; wire CodeSearch + incremental refresh#238
Patel230 merged 1 commit into
mainfrom
feat/cocoindex-adoptions

Conversation

@Patel230

Copy link
Copy Markdown
Contributor

Summary

Two adoptions from the cocoindex-io org mapped against hawk's code-intelligence stack (which already had repomap/codegraph but lacked a structural matcher and had unbound code-search hooks).

1. CodeMatch — structural (AST) search tool

  • Tree-sitter query search over Go/Python/TypeScript/TSX, reusing the same smacker/go-tree-sitter grammars codegraph already links. Patterns are S-expressions with @capture nodes.
  • Syntax-aware: comments/string literals cannot false-positive (unlike regex Grep).
  • Per-file auto language detection or language= restriction; gitignore-aware walk; bounded limit.
  • CGO-gated with a no-CGO stub; shared tool surface (Name/Params/Execute) lives in a cgo-free file so builds stay portable. Verified CGO_ENABLED=0 linux/windows cross-compiles.

2. Wire CodeSearch + incremental refresh (the cocoindex "only reprocess what changed" idea)

  • CodeSearchFn/RefreshCodeIndexFn were declared but never bound — CodeSearchTool reported "not available" in production and the refresh flag was a silent no-op. Now wired in tool_service.go:
    • CodeSearchFn → yaad bridge SearchCode
    • RefreshCodeIndexFnrepomap.IncrementalReindex (SHA-256 content-hash staleness: only added/changed files re-index, deleted ones pruned)
  • Small yaadCodeIndexer adapter implements repomap.CodeIndexer over the memory bridge (identical result types in two packages).

Registered CodeMatch in chat_tools.go + safety capabilities + permission aliases.

Testing

  • New CodeMatch suite (6 tests): Go function pattern, comment-false-positive, Python defs, language filter + limit/truncated, invalid-pattern-before-walk, unsupported language
  • tool, engine, repomap, memory suites pass; golangci-lint 0 issues; gofmt clean; both cgo and CGO_ENABLED=0 builds green

…mental refresh

Two adoptions from the cocoindex-io org mapped against hawk's code
intelligence stack.

CodeMatch structural search (internal/tool/code_match*.go):
- AST-level tree-sitter query search over Go/Python/TypeScript/TSX, using
  the same smacker/go-tree-sitter grammars codegraph already links. Patterns
  are S-expressions with @capture nodes; results carry per-file start/end
  lines, capture names, and line snippets.
- Syntax-aware: comments and string literals cannot false-positive (unlike
  regex Grep). Auto-detects language per file or restricts via language
  param; gitignore-aware walk with bounded match limit.
- CGO-gated with a no-CGO stub so builds stay portable; language-agnostic
  shared surface (Name/Params/Execute) lives in a cgo-free file.

Wire CodeSearch + incremental refresh (internal/engine):
- CodeSearchFn and RefreshCodeIndexFn were declared on ToolContext but never
  bound, so CodeSearchTool reported 'not available' in production and the
  refresh flag was a silent no-op. Both are now wired in tool_service.go:
  - CodeSearchFn -> yaad bridge SearchCode (with Language derived from path)
  - RefreshCodeIndexFn -> repomap.IncrementalReindex, which re-indexes only
    added/changed files via SHA-256 content-hash staleness and prunes deleted
    ones (the cocoindex incremental-engine pattern).
- Adds a small yaadCodeIndexer adapter implementing repomap.CodeIndexer over
  the memory bridge (the two packages define identical result types).

Registered CodeMatch in chat_tools.go with safety capabilities and permission
aliases; both cgo and CGO_ENABLED=0 (linux/windows) builds verified.

Verification: new CodeMatch suite (6 tests) green; tool, engine, repomap,
memory suites pass; golangci-lint 0 issues; gofmt clean.
@Patel230
Patel230 merged commit 0af8e41 into main Aug 23, 2026
26 checks passed
@Patel230
Patel230 deleted the feat/cocoindex-adoptions branch August 23, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant