diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 0cffe04..61de365 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "socraticode", - "version": "1.8.3", + "version": "1.8.8", "description": "Codebase intelligence — semantic search workflows, dependency graph analysis, and context artifact exploration for SocratiCode", "author": { "name": "Giancarlo Erra", diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json index 536407a..07383da 100644 --- a/.codex-plugin/plugin.json +++ b/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "socraticode", - "version": "1.8.3", + "version": "1.8.8", "description": "Codebase intelligence: semantic search workflows, dependency graph analysis, and context artifact exploration for SocratiCode", "author": { "name": "Giancarlo Erra", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index 83bbfb1..23b724c 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "socraticode", - "version": "1.8.3", + "version": "1.8.8", "description": "Codebase intelligence: semantic search workflows, dependency graph analysis, and context artifact exploration for SocratiCode", "author": { "name": "Giancarlo Erra", diff --git a/CHANGELOG.md b/CHANGELOG.md index 653bffc..6252440 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,42 @@ All notable changes to SocratiCode are documented here. This project uses [Conventional Commits](https://www.conventionalcommits.org/) and [Semantic Versioning](https://semver.org/). +## [1.8.8](https://github.com/giancarloerra/socraticode/compare/v1.8.7...v1.8.8) (2026-05-06) + +### Features + +* **config:** support projectId in .socraticode.json for team-shared indexes ([#53](https://github.com/giancarloerra/socraticode/issues/53)) ([2c4d55c](https://github.com/giancarloerra/socraticode/commit/2c4d55ca50ae4eb60bb365dbcbff7923db4966e3)) + +## [1.8.7](https://github.com/giancarloerra/socraticode/compare/v1.8.6...v1.8.7) (2026-05-06) + +### Bug Fixes + +* **context:** checkpoint artifact metadata after each successful index ([#52](https://github.com/giancarloerra/socraticode/issues/52)) ([2007a18](https://github.com/giancarloerra/socraticode/commit/2007a18865d31cad3be6f5e2e88f834156c5df37)) + +## [1.8.6](https://github.com/giancarloerra/socraticode/compare/v1.8.5...v1.8.6) (2026-05-05) + +### Features + +* **qdrant:** add QDRANT_COLLECTION_PREFIX env var for shared instances ([70db002](https://github.com/giancarloerra/socraticode/commit/70db002796a76596badfed86c25d5af6c0331e69)) + +## [1.8.5](https://github.com/giancarloerra/socraticode/compare/v1.8.4...v1.8.5) (2026-05-05) + +### Bug Fixes + +* **graph:** allow Go resolution for projects with golang.org/* module paths ([8c26ed8](https://github.com/giancarloerra/socraticode/commit/8c26ed8b49f8aae030d519aca3a0ab84ad07d90d)) +* **graph:** resolve Go imports via go.mod module path ([c156da1](https://github.com/giancarloerra/socraticode/commit/c156da1688e4e2b8b9c1dfb042094b018131d8f7)) +* **graph:** resolve Python sibling-flat imports in service-style monorepos ([8921690](https://github.com/giancarloerra/socraticode/commit/8921690d7286ba858337d2df478ef01772d6d055)) + +### Documentation + +* add note about MCP governance and JanuScope ([bf36c0c](https://github.com/giancarloerra/socraticode/commit/bf36c0c1b7d3ceb73161afe20628cc994dca404c)) + +## [1.8.4](https://github.com/giancarloerra/socraticode/compare/v1.8.3...v1.8.4) (2026-05-04) + +### Bug Fixes + +* **graph:** pre-validate ast-grep grammar libraryPath to survive missing prebuilds ([#44](https://github.com/giancarloerra/socraticode/issues/44)) ([e6ce327](https://github.com/giancarloerra/socraticode/commit/e6ce32710acccd6cb4a241c39a3561803e0e7dbd)) + ## [1.8.3](https://github.com/giancarloerra/socraticode/compare/v1.8.2...v1.8.3) (2026-05-04) ### Features diff --git a/DEVELOPER.md b/DEVELOPER.md index 721f253..0641423 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -269,17 +269,24 @@ Defined in `src/services/docker.ts`: after starting the container, the server po ### Project ID & Collection Naming -Defined in `src/config.ts`: -- **Project ID**: First 12 characters of SHA-256 hash of the absolute project path. +Defined in `src/config.ts`. `projectIdFromPath()` resolves the project ID with the following precedence (highest first): + +1. **`SOCRATICODE_PROJECT_ID` env var** — per-machine override; bypasses both file lookup and path hashing. +2. **`projectId` field in `.socraticode.json`** — committed, team-wide stable identifier; survives different filesystem layouts and OS users. +3. **First 12 characters of SHA-256 of the absolute project path** — default fallback. + +In both override paths the value must match `[a-zA-Z0-9_-]+`; whitespace is trimmed; empty/whitespace-only values fall through to the next level. Invalid characters in an explicit override fail loud (throw) — silent fallback would hide misconfigurations that map a project to the wrong (or new) collection. + +Collection names derived from the project ID: - **Code collection**: `codebase_{projectId}` - **Graph collection**: `codegraph_{projectId}` - **Context artifacts collection**: `context_{projectId}` -This means the same folder path always maps to the same collection, even across restarts. +With the default (path-hash) ID, the same folder path always maps to the same collection across restarts. With either override, the mapping is stable across machines and checkouts. #### Branch-aware mode -When `SOCRATICODE_BRANCH_AWARE=true`, the current git branch is detected via `git rev-parse --abbrev-ref HEAD` and appended to the project ID (e.g. `abc123def456__feat_my-feature`). Branch names are sanitized: non-alphanumeric characters (except `-`) become `_`, consecutive underscores collapse, leading/trailing underscores are stripped. Detached HEAD states fall back to the branchless ID. Ignored when `SOCRATICODE_PROJECT_ID` is set explicitly. +When `SOCRATICODE_BRANCH_AWARE=true`, the current git branch is detected via `git rev-parse --abbrev-ref HEAD` and appended to the project ID (e.g. `abc123def456__feat_my-feature`). Branch names are sanitized: non-alphanumeric characters (except `-`) become `_`, consecutive underscores collapse, leading/trailing underscores are stripped. Detached HEAD states fall back to the branchless ID. Ignored when `SOCRATICODE_PROJECT_ID` is set explicitly or when `projectId` is set in `.socraticode.json` — explicit identifiers are treated as stable and not augmented per branch. #### Linked projects diff --git a/README.md b/README.md index 0580cee..201015d 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Kindly sponsored by Altaire Limited
+> 🛡️ **Need MCP governance together with codebase context?** See our sibling project [**JanuScope**](https://github.com/giancarloerra/januscope) — the local-first MCP policy proxy: tool blocking, SQL-mutation gate, PII redaction, audit, rate-limit. + > If SocratiCode has been useful to you, please ⭐ **star this repo** — it helps others discover it — and share it with your dev team and fellow developers! > > 💬 Questions or just want to chat? Join us on [Discord](https://discord.gg/5DrMXfNG). @@ -766,6 +768,20 @@ With this config, agents running in `/repo/main`, `/repo/worktree-feat-a`, and ` - Your AI agent reads actual file contents from its own worktree; the shared index is only used for discovery and navigation - When changes merge back to main, the file watcher re-indexes the changed files and the index converges +### Team-Shared Index (committed `projectId`) + +The env-var approach above works per-machine. For a stable identifier that every teammate (and CI runner) picks up automatically, commit a `projectId` in `.socraticode.json` at the project root: + +```json +{ + "projectId": "my-project" +} +``` + +Now any checkout of the repo — regardless of where it lives on disk or which user account owns it — addresses the same `codebase_my-project`, `codegraph_my-project`, and `context_my-project` Qdrant collections. This is the recommended setup for teams sharing a Qdrant instance: the index is built once and benefits everyone, even across different OS users and laptops with completely different filesystem layouts. + +The value must match `[a-zA-Z0-9_-]+`; whitespace is trimmed, and a missing or empty value falls back to the path-hash default. The `SOCRATICODE_PROJECT_ID` env var, when set, takes precedence over this file — handy for ad-hoc per-machine overrides without touching the repo. + ### Cross-Project Search (linked projects) If you work across multiple related repositories or packages, you can search them all in a single query. @@ -1141,6 +1157,7 @@ The rest of this section documents the variables themselves. Pass them using whi | `QDRANT_GRPC_PORT` | `16334` | Qdrant gRPC port (managed mode only) | | `QDRANT_HOST` | `localhost` | Qdrant hostname (alternative to `QDRANT_URL` for non-HTTPS external instances) | | `QDRANT_API_KEY` | *(none)* | Qdrant API key (required for Qdrant Cloud and other authenticated deployments). When set, the URL must be `https://...` so the key is not transmitted over plain HTTP. Loopback URLs (`localhost`, `127.0.0.1`, `[::1]`) are accepted on `http://` for local development. | +| `QDRANT_COLLECTION_PREFIX` | *(empty)* | Optional prefix prepended to every Qdrant collection name SocratiCode creates. Useful when sharing one Qdrant instance with other applications (Open-WebUI, custom RAG, etc.) or running multiple SocratiCode instances against one Qdrant for separation between projects, environments, or per-user indexes. Default empty string keeps collection names unchanged from previous releases (fully backwards compatible). Must match `[a-zA-Z0-9_-]+` if set; an invalid prefix throws at startup. Changing the prefix between runs orphans the previous collections; use `codebase_remove` first if you need to migrate. | ### Indexing Behaviour @@ -1152,8 +1169,8 @@ The rest of this section documents the variables themselves. Pass them using whi | `MAX_FILE_SIZE_MB` | `5` | Maximum file size in MB. Files larger than this are skipped during indexing. Increase for repos with large generated or data files you want indexed. | | `SEARCH_DEFAULT_LIMIT` | `10` | Default number of results returned by `codebase_search` (1-50). Each result is a ranked code chunk with file path, line range, and content. Higher values give broader coverage but produce more output. Can still be overridden per-query via the `limit` tool parameter. | | `SEARCH_MIN_SCORE` | `0.10` | Minimum RRF (Reciprocal Rank Fusion) score threshold (0-1). Results below this score are filtered out. Helps remove low-relevance noise from search results. Set to `0` to disable filtering (returns all results up to `limit`). Can be overridden per-query via the `minScore` tool parameter. Works together with `limit`: results are first filtered by score, then capped at `limit`. | -| `SOCRATICODE_PROJECT_ID` | *(none)* | Override the auto-generated project ID. When set, all paths resolve to the same Qdrant collections, allowing multiple directories (e.g. git worktrees of the same repo) to share a single index. Must match `[a-zA-Z0-9_-]+`. | -| `SOCRATICODE_BRANCH_AWARE` | `false` | When `true`, append the current git branch name to the project ID, creating separate Qdrant collections per branch. Ignored when `SOCRATICODE_PROJECT_ID` is set. | +| `SOCRATICODE_PROJECT_ID` | *(none)* | Override the auto-generated project ID. When set, all paths resolve to the same Qdrant collections, allowing multiple directories (e.g. git worktrees of the same repo) to share a single index. Must match `[a-zA-Z0-9_-]+`. Takes precedence over the `projectId` field in `.socraticode.json`. | +| `SOCRATICODE_BRANCH_AWARE` | `false` | When `true`, append the current git branch name to the project ID, creating separate Qdrant collections per branch. Ignored when `SOCRATICODE_PROJECT_ID` is set or when `projectId` is set in `.socraticode.json`. | | `SOCRATICODE_LINKED_PROJECTS` | *(none)* | Comma-separated list of additional project paths to include in cross-project search. Merged with paths from `.socraticode.json`. Non-existent paths are silently skipped. | | `SOCRATICODE_LOG_LEVEL` | `info` | Log verbosity: `debug`, `info`, `warn`, `error` | | `SOCRATICODE_LOG_FILE` | *(none)* | Absolute path to a log file. When set, all log entries are appended to this file (a session separator is written on each server start). Useful for debugging when the MCP host doesn't surface log notifications. | diff --git a/extension/package.json b/extension/package.json index 9965967..c3f7e0c 100644 --- a/extension/package.json +++ b/extension/package.json @@ -2,7 +2,7 @@ "name": "socraticode", "displayName": "SocratiCode", "description": "Codebase context engine for AI assistants. Hybrid search, dependency and call graphs, symbol-level impact analysis (blast radius), interactive graph explorer, and searchable architecture artefacts. Works with Copilot agent mode, Cline, Continue, Roo Code, and any MCP-compatible host.", - "version": "1.8.3", + "version": "1.8.8", "publisher": "giancarloerra", "license": "AGPL-3.0-only", "icon": "images/icon.png", diff --git a/package-lock.json b/package-lock.json index 347c08e..1281367 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "socraticode", - "version": "1.8.3", + "version": "1.8.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "socraticode", - "version": "1.8.3", + "version": "1.8.8", "license": "AGPL-3.0-only", "dependencies": { "@ast-grep/lang-bash": "^0.0.7", diff --git a/package.json b/package.json index efb5b20..1e8cec3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "socraticode", "mcpName": "io.github.giancarloerra/socraticode", - "version": "1.8.3", + "version": "1.8.8", "description": "SocratiCode — MCP server for local codebase indexing, semantic search, and code dependency graphs. All private, all local via Docker.", "type": "module", "main": "dist/index.js", diff --git a/src/config.ts b/src/config.ts index e443484..c53dfcb 100644 --- a/src/config.ts +++ b/src/config.ts @@ -4,6 +4,7 @@ import { execFileSync } from "node:child_process"; import { createHash } from "node:crypto"; import fs from "node:fs"; import path from "node:path"; +import { QDRANT_COLLECTION_PREFIX } from "./constants.js"; // ── Branch detection ───────────────────────────────────────────────────── @@ -38,29 +39,65 @@ export function sanitizeBranchName(branch: string): string { .replace(/^_|_$/g, ""); } +/** Pattern of characters valid in a Qdrant collection name suffix. */ +const PROJECT_ID_PATTERN = /^[a-zA-Z0-9_-]+$/; + +/** Validate an explicitly-supplied projectId. Throws on bad characters. */ +function assertValidProjectId(value: string, source: string): void { + if (!PROJECT_ID_PATTERN.test(value)) { + throw new Error(`${source} must match [a-zA-Z0-9_-]+ but got: "${value}"`); + } +} + +/** + * Read and validate `projectId` from `.socraticode.json`, if present. + * + * Returns the trimmed id when the file declares a usable string, `null` + * otherwise (file missing, malformed JSON, field absent, wrong type, or + * empty after trim). Throws when the field is a string with characters + * outside the Qdrant-friendly set — explicit user intent fails loud. + */ +function readProjectIdFromConfigFile(folderPath: string): string | null { + const config = loadSocratiCodeConfig(folderPath); + if (!config || typeof config.projectId !== "string") return null; + const trimmed = config.projectId.trim(); + if (!trimmed) return null; + assertValidProjectId(trimmed, ".socraticode.json: projectId"); + return trimmed; +} + /** * Generate a stable project ID from an absolute folder path. * Uses a short SHA-256 prefix so collection names stay Qdrant-friendly. * - * When `SOCRATICODE_PROJECT_ID` is set, that value is used directly instead - * of hashing the path. This lets multiple directory trees (e.g. git - * worktrees) share a single Qdrant index. The value must contain only - * characters valid in a Qdrant collection name (`[a-zA-Z0-9_-]`). + * Resolution order (highest precedence first): + * 1. `SOCRATICODE_PROJECT_ID` env var — per-machine override. + * 2. `projectId` in `.socraticode.json` — committed, shared across the + * team so every checkout addresses the same Qdrant collection + * regardless of where the working tree lives on disk. + * 3. SHA-256 prefix of the resolved absolute path — default fallback. + * + * In both override paths the value must match `[a-zA-Z0-9_-]+`; invalid + * characters throw. Whitespace is trimmed; empty/whitespace-only values + * fall through to the next level. * * When `SOCRATICODE_BRANCH_AWARE` is `"true"` (and no explicit project ID - * is set), the current git branch name is appended to the hash, producing - * a separate set of collections per branch. + * is set via env var or config file), the current git branch name is + * appended to the hash, producing a separate set of collections per + * branch. */ export function projectIdFromPath(folderPath: string): string { - const explicit = process.env.SOCRATICODE_PROJECT_ID?.trim(); - if (explicit) { - if (!/^[a-zA-Z0-9_-]+$/.test(explicit)) { - throw new Error( - `SOCRATICODE_PROJECT_ID must match [a-zA-Z0-9_-]+ but got: "${explicit}"`, - ); - } - return explicit; + const envExplicit = process.env.SOCRATICODE_PROJECT_ID?.trim(); + if (envExplicit) { + assertValidProjectId(envExplicit, "SOCRATICODE_PROJECT_ID"); + return envExplicit; } + + const fileExplicit = readProjectIdFromConfigFile(folderPath); + if (fileExplicit) { + return fileExplicit; + } + let id = coreProjectId(folderPath); // Branch-aware mode: append sanitized branch name to isolate per-branch indexes @@ -79,62 +116,115 @@ export function projectIdFromPath(folderPath: string): string { /** * Core project ID: SHA-256 hash of the resolved path, without branch suffix. - * Used internally by resolveLinkedCollections so linked projects always - * resolve to their base collection regardless of SOCRATICODE_BRANCH_AWARE. + * Used as the default fallback when no explicit project ID is configured. */ function coreProjectId(folderPath: string): string { const normalized = path.resolve(folderPath); return createHash("sha256").update(normalized).digest("hex").slice(0, 12); } +/** + * Branch-suffix-free, env-var-free project ID for a given path. + * + * Resolution: `projectId` from `.socraticode.json` if present, else the + * SHA-256 path hash. Used for linked projects (where `SOCRATICODE_PROJECT_ID` + * is process-scoped and ambiguous when applied to a different project) and + * for dedup keys in `resolveLinkedCollections` (where we need a stable + * identity that doesn't drift across branches). + */ +function effectiveBaseProjectId(folderPath: string): string { + const fileId = readProjectIdFromConfigFile(folderPath); + return fileId ?? coreProjectId(folderPath); +} + /** * Derive a Qdrant collection name for a project's code chunks. + * + * The optional `QDRANT_COLLECTION_PREFIX` env var is prepended verbatim to + * isolate this SocratiCode instance's collections when sharing a Qdrant + * server with other applications or other SocratiCode instances. Empty + * prefix (the default) preserves the legacy `codebase_