feat: Code snippet extraction and indexing (#17) #229

Merged
jack merged 2 commits from feat/17-code-snippets into main 2026-01-24 18:26:02 +00:00
Owner

Summary

  • Add database migration and entity for code_snippets table with FTS5 full-text search
  • Implement automatic code block extraction from observations (text, narrative, tool output)
  • Add language detection and normalization for 20+ programming languages
  • Add API endpoints for code snippet CRUD and search operations
  • Add CodeSnippets UI component with syntax highlighting and copy functionality
  • Integrate code snippets display into ObservationDetails view

Features

  • Automatic Extraction: Code blocks in markdown format are automatically extracted when observations are created
  • Language Detection: Detects language from fenced code blocks or uses heuristics for untagged code
  • Deduplication: Snippets are deduplicated by content hash within an observation
  • File Context: Extracts file paths and line numbers from surrounding context when available
  • Full-text Search: FTS5 index enables fast code search across all snippets

API Endpoints

  • GET /api/data/code-snippets - List with filters (project, language, sessionId)
  • GET /api/data/code-snippets/search?q=... - Full-text search
  • GET /api/data/code-snippets/languages - Get distinct languages
  • GET /api/data/code-snippets/:id - Get single snippet
  • GET /api/data/observations/:id/code-snippets - Get snippets for observation
  • DELETE /api/data/code-snippets/:id - Delete snippet

Test plan

  • Verify code blocks are extracted from new observations
  • Verify language detection works for common languages
  • Verify code snippets appear in ObservationDetails view
  • Verify copy button works
  • Verify search endpoint returns relevant results

Closes #17

🤖 Generated with Claude Code

## Summary - Add database migration and entity for `code_snippets` table with FTS5 full-text search - Implement automatic code block extraction from observations (text, narrative, tool output) - Add language detection and normalization for 20+ programming languages - Add API endpoints for code snippet CRUD and search operations - Add CodeSnippets UI component with syntax highlighting and copy functionality - Integrate code snippets display into ObservationDetails view ## Features - **Automatic Extraction**: Code blocks in markdown format are automatically extracted when observations are created - **Language Detection**: Detects language from fenced code blocks or uses heuristics for untagged code - **Deduplication**: Snippets are deduplicated by content hash within an observation - **File Context**: Extracts file paths and line numbers from surrounding context when available - **Full-text Search**: FTS5 index enables fast code search across all snippets ## API Endpoints - `GET /api/data/code-snippets` - List with filters (project, language, sessionId) - `GET /api/data/code-snippets/search?q=...` - Full-text search - `GET /api/data/code-snippets/languages` - Get distinct languages - `GET /api/data/code-snippets/:id` - Get single snippet - `GET /api/data/observations/:id/code-snippets` - Get snippets for observation - `DELETE /api/data/code-snippets/:id` - Delete snippet ## Test plan - [ ] Verify code blocks are extracted from new observations - [ ] Verify language detection works for common languages - [ ] Verify code snippets appear in ObservationDetails view - [ ] Verify copy button works - [ ] Verify search endpoint returns relevant results Closes #17 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Adds infrastructure for code snippet extraction and indexing:

- Migration: code_snippets table with FTS5 full-text search
- Entity: CodeSnippet with language, file_path, line info
- Repository: CRUD operations, search, and language listing
- Types: ICodeSnippetRepository interface and related types

Next steps: Add code extraction in observation handler and UI display.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
feat(backend,ui): add code snippet extraction and display (#17)
All checks were successful
CI / build (pull_request) Successful in 41s
25046317c1
- Extract code blocks from observations in task-dispatcher
- Add language detection and normalization
- Add API endpoints for code snippets (list, search, get, delete)
- Add CodeSnippets UI component with syntax highlighting
- Integrate code snippets into ObservationDetails view

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
jack merged commit 997a3c5b2f into main 2026-01-24 18:26:02 +00:00
Sign in to join this conversation.
No description provided.