24 Commits

Author SHA1 Message Date
Giancarlo Erra 00f7be169c fix: address CodeRabbit PR review feedback
- Use Object.hasOwn() instead of `in` for log level validation
- Normalize relativePath in shouldIgnore() for Windows compatibility
- Reject zero/negative/decimal values in embedding config (Number() instead of parseInt())
- Update aggregate test count to 765
- Harden code-graph test assertion with explicit toBeDefined()
2026-04-12 21:31:45 +01:00
Giancarlo Erra bb5e6c3e19 fix: address CodeRabbit review findings 2026-04-12 20:21:36 +01:00
Giancarlo Erra f745d59ddd fix: address remaining CodeRabbit production code issues
- Scope dedupe key to label::relativePath in mergeMultiCollectionResults
  so same file in different projects is not collapsed
- Compute embedding once in searchMultipleCollections via internal
  searchChunksWithVector helper (avoids N redundant API calls)
- Compare base project hashes (not branch-suffixed names) when skipping
  duplicate linked projects in resolveLinkedCollections
- Use path.resolve() for platform-neutral assertion in query-tools tests
- Update multi-collection-search tests for new cross-project dedup semantics
2026-04-11 17:53:59 +01:00
Giancarlo Erra f09f417c6e fix: address CodeRabbit review feedback on tests
- Refactor git temp repos into initTempRepo() helper using git config
  instead of env vars (resolves Critical finding)
- Restore SOCRATICODE_LINKED_PROJECTS and SOCRATICODE_PROJECT_ID to
  original values in resolveLinkedCollections afterEach
- Fix TypeScript 'never' type errors in query-tools mocks by adding
  explicit SearchResult[] return types
2026-04-11 17:53:59 +01:00
Giancarlo Erra ad2e3b9ea1 fix: provide git identity for temp repo commits in CI
CI runners have no git user.name/email configured, causing
'git commit --allow-empty' to fail with 'Author identity unknown'.
Pass GIT_AUTHOR_NAME/EMAIL and GIT_COMMITTER_NAME/EMAIL env vars.
2026-04-11 17:53:59 +01:00
Giancarlo Erra ffa8e95bdf fix: use self-contained temp git repos in branch-aware tests
CI checks out in detached HEAD state, causing detectGitBranch(process.cwd())
to return null. Replace process.cwd() with temporary git repos that have a
known branch and initial commit, making tests deterministic everywhere.
2026-04-11 17:53:59 +01:00
Giancarlo Erra bf93e4a992 test: add includeLinked and searchMultipleCollections tests
- query-tools.test.ts: 6 new tests for includeLinked parameter:
  - omitted/false → calls searchChunks (not searchMultipleCollections)
  - true → calls searchMultipleCollections via resolveLinkedCollections
  - passes collections and args correctly
  - project label appears in output
  - no project tag when field absent

- multi-collection-search.test.ts: 1 new test for searchMultipleCollections
  empty-input short-circuit (internal searchChunks calls cannot be mocked
  from the same module — integration covered by query-tools tests)
2026-04-11 17:53:59 +01:00
Giancarlo Erra fc3c2988fa fix: linked projects use base hash without branch suffix
resolveLinkedCollections() was calling projectIdFromPath() for linked
projects, which with SOCRATICODE_BRANCH_AWARE=true appended the linked
project's git branch to its ID. Linked projects indexed without
branch-aware mode don't have __branch collections, so lookups failed.

Extract coreProjectId() helper (hash-only, no branch suffix) and use
it for linked projects. Also fix dedup to compare collection names
instead of raw IDs to handle the branch suffix mismatch.

Adds unit test verifying linked collection names are branch-agnostic.
2026-04-11 17:53:59 +01:00
Giancarlo Erra 096f59da13 fix: update path handling and type imports in indexer and query tools 2026-04-11 17:53:59 +01:00
Giancarlo Erra 3a4139d714 feat: branch-aware collection naming via SOCRATICODE_BRANCH_AWARE
- detectGitBranch() detects current git branch via git rev-parse
- sanitizeBranchName() converts branch names to Qdrant-safe suffixes
- When SOCRATICODE_BRANCH_AWARE=true, projectIdFromPath appends __branch
  to create separate indexes per branch
- Explicit SOCRATICODE_PROJECT_ID takes precedence (no branch suffix)
- 14 unit tests for sanitization, detection, and integration

Relates to #19
2026-04-11 17:53:59 +01:00
Giancarlo Erra 61e868cf9e feat: linked projects support via .socraticode.json and SOCRATICODE_LINKED_PROJECTS
- loadLinkedProjects() reads .socraticode.json config and env var
- resolveLinkedCollections() maps linked projects to collection names
- codebase_search gains includeLinked parameter for cross-project queries
- Results tagged with [project-label] when searching across projects
- 10 unit tests for config loading and collection resolution

Relates to #20
2026-04-11 17:53:59 +01:00
Giancarlo Erra ad8db7f0db feat: multi-collection search with client-side RRF fusion and deduplication
Add searchMultipleCollections() and mergeMultiCollectionResults() to qdrant.ts.
Queries multiple Qdrant collections in parallel, merges results using Reciprocal
Rank Fusion (k=60), and deduplicates by relativePath (first collection wins).

Add optional 'project' field to SearchResult type for source attribution.

This is the shared foundation for linked projects (#20) and branch-aware
indexing (#19).

Refs: #19, #20
2026-04-11 17:53:59 +01:00
jason.ma 5a734eb301 fix: resolve JVM imports in multi-module Maven/Gradle projects
Single-module resolution (src/main/java/…) already worked.
Multi-module layouts like:

  module-a/sub/src/main/java/com/example/Foo.java

were silently unresolved because the three fixed src-dir prefixes
never matched. The dependency graph therefore always produced 0
edges for any Java/Kotlin/Scala project that follows the standard
Maven/Gradle multi-module layout.

Fix: introduce `buildJvmSuffixMap()` which scans `fileSet` once
(O(n)) and registers every JVM source file by its class-path key
(i.e. everything after src/main/<lang>/). `resolveImport` accepts
the map as an optional last argument and falls back to it when the
existing prefix-based approach yields no result.

- `buildJvmSuffixMap` exported for reuse / testing.
- Map is built once per `buildCodeGraph` call, only when the
  project contains at least one JVM file — zero cost for other
  language projects.
- Lookup is O(1) per import, replacing a worst-case O(n) linear
  scan on every miss.
- Works on both Windows (backslash) and POSIX (forward-slash)
  because the map key is built with `path.sep`.
- 7 new unit tests covering: map construction, test-source
  exclusion, multi-module Java resolution, Kotlin resolution,
  unresolvable class, stdlib guard.

Fixes: enterprise Java/Spring Boot codebases (30+ Maven modules)
reporting 0 edges in codebase_graph_stats.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 20:23:03 +08:00
Csaba Tuncsik c7e160cb5c feat: add CSS @import tracking and path alias resolution to dependency graph
Add CSS @import extraction from Svelte/Vue <style> blocks and standalone
CSS/SCSS/SASS/LESS files. Add path alias resolution from tsconfig.json /
jsconfig.json compilerOptions.paths with extends chain support.
2026-03-18 20:18:44 +01:00
Giancarlo Erra be5184338e Merge pull request #9 from pineapplestrikesback/feat/svelte-import-parsing
feat: add Svelte and Vue import parsing to dependency graph

Thanks pineapplestrikesback, nice idea and nicely implemented with zero-dependencies.
2026-03-18 13:45:28 +00:00
Giancarlo Erra 0c45ed9906 Merge pull request #10 from midweste/midweste-dotfiles
feat: add env support for controlling indexing of dotfiles
2026-03-18 12:32:13 +00:00
Giancarlo Erra 2e0cdbbd08 Merge pull request #11 from midweste/midweste-qdrantport
feat: auto-infer port from QDRANT_URL for reverse proxy support
2026-03-18 12:23:50 +00:00
Giancarlo Erra 4d255f50ee fix: only call ensureOllamaReady when using Ollama provider (#8)
ensureOllamaReady() was called unconditionally on every search and context
operation, causing failures for OpenAI and Google embedding users. Now only
called when embeddingProvider is ollama; otherwise the configured provider
is initialized via getEmbeddingProvider().

Fixes #7

Co-authored-by: pineapplestrikesback <pineapplestrikesback@users.noreply.github.com>
2026-03-17 17:46:51 +00:00
midwestE 507d823336 feat: auto-infer port from QDRANT_URL for reverse proxy support 2026-03-17 07:20:56 -05:00
midwestE 7265247d83 feat: add env support for controlling indexing of dotfiles 2026-03-17 07:11:25 -05:00
pineapplestrikesback 4c2bd0cc53 feat: add Svelte and Vue import parsing to dependency graph
Svelte and Vue files were included in the graph as leaf nodes (targets
of import edges) but their own imports were never extracted because
no ast-grep grammar exists for these languages.

This adds support by parsing .svelte/.vue files as HTML (built-in
grammar), extracting <script> block content, and re-parsing it as
TypeScript to extract imports using the existing JS/TS logic.

Changes:
- code-graph.ts: register .svelte and .vue in getAstGrepLang()
- graph-imports.ts: add Svelte/Vue script extraction handler; refactor
  JS/TS import extraction into shared extractJsTsImportsFromNode()
  helper to avoid duplication
- graph-resolution.ts: add "svelte" and "vue" cases to resolveImport(),
  with .svelte/.vue as first-priority extension resolution
- graph-imports.test.ts: add tests for Svelte (static, dynamic, module,
  no-script, JS-only) and Vue import extraction

Zero new dependencies — uses the built-in Lang.Html and Lang.TypeScript
grammars from @ast-grep/napi.

Known limitation: path aliases ($lib/, @/) are not resolved and will be
treated as external packages (same as current JS/TS behavior).
2026-03-16 16:23:18 +01:00
Csaba Tuncsik 505fbd722b fix: use relative paths for index keys to support shared worktree indexes
When SOCRATICODE_PROJECT_ID is set to share a Qdrant collection across
git worktrees, the indexer still used absolute paths as keys in the file
hash map, chunk IDs, and for deleting file chunks. This caused every
worktree to see all files as "new" and trigger a full re-index, defeating
the purpose of the shared project ID feature.

Switch all internal keying from absolute paths to relative paths:
- chunkId() now hashes on relativePath for stable IDs across worktrees
- File hash map (change detection) keyed by relativePath
- deleteFileChunks() filters on relativePath Qdrant field
- Deleted file detection uses relative path sets

Absolute paths are now only used for actual file I/O (stat, readFile).
2026-03-16 08:39:22 +01:00
Csaba Tuncsik fadfd8a80e feat: add SOCRATICODE_PROJECT_ID env var for shared indexes across directories
When working with git worktrees (or any setup where the same codebase lives
in multiple directories), each path currently gets its own Qdrant collection.
This means the same codebase is indexed multiple times.

This change adds a SOCRATICODE_PROJECT_ID environment variable that, when set,
overrides the path-based project ID generation. All directories sharing the
same SOCRATICODE_PROJECT_ID will use the same Qdrant collections (codebase,
codegraph, context), eliminating redundant indexing.

The value must match [a-zA-Z0-9_-]+ to remain Qdrant-friendly. An error is
thrown at startup if the value contains invalid characters.
2026-03-15 10:58:58 +01:00
Giancarlo Erra 3f0ed5a286 feat: SocratiCode v1.0.0 — initial release 2026-02-28 17:06:21 +00:00