diff --git a/.gitignore b/.gitignore index 966cee583..88c3a793c 100644 --- a/.gitignore +++ b/.gitignore @@ -66,3 +66,7 @@ graph-ui/.npm-cache-local/ # Python bytecode from tests/windows/ harness __pycache__/ *.pyc + +# Nix build symlinks (nix build → ./result, ./result-1, …) +/result +/result-* diff --git a/README.md b/README.md index 8ff708dd7..200bd8f3f 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,38 @@ scripts/build.sh --with-ui # with graph visualization # Binary at: build/c/codebase-memory-mcp ``` +### Nix (flake) + +The flake exposes two server packages plus the standalone frontend: + +| Package | Contents | +|---------|----------| +| `default` (`codebase-memory-mcp`) | Standard server, no UI | +| `codebase-memory-mcp-ui` | Server with the graph UI embedded (`--ui=true` works) | +| `graph-ui` | Just the built frontend assets (`dist/`) | + +Run directly without installing: + +```bash +# Standard server +nix run github:DeusData/codebase-memory-mcp + +# Server with the embedded graph UI +nix run github:DeusData/codebase-memory-mcp#codebase-memory-mcp-ui -- --ui=true --port=9749 +# then open http://127.0.0.1:9749 +``` + +Or build a binary into `./result/bin/codebase-memory-mcp`: + +```bash +nix build github:DeusData/codebase-memory-mcp # standard +nix build github:DeusData/codebase-memory-mcp#codebase-memory-mcp-ui # with UI +``` + +Working in a clone? Use `.` in place of the flake URL, e.g. `nix run .#codebase-memory-mcp-ui -- --ui=true`, or drop into a shell that puts the binary on `PATH` with `nix shell .#codebase-memory-mcp-ui`. + +> **Note:** launched by hand (not from an MCP client) the server exits as soon as `stdin` closes — that's normal MCP behaviour. Keep `stdin` open while testing the UI, e.g. `sleep infinity | codebase-memory-mcp --ui=true --port=9749`. The `codebase-memory-mcp-ui` package embeds the UI at build time; `nix run`'ing the standard `default` package with `--ui=true` will refuse to start the HTTP server. + ### Manual MCP Configuration
diff --git a/flake.lock b/flake.lock index d973ae562..6bea73559 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1776255774, - "narHash": "sha256-psVTpH6PK3q1htMJpmdz1hLF5pQgEshu7gQWgKO6t6Y=", + "lastModified": 1783915482, + "narHash": "sha256-FmieJB8/OUvNxbkboi7+IGfIuSXY3nF/hZQm8kD0r50=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "566acc07c54dc807f91625bb286cb9b321b5f42a", + "rev": "6cdc7fc76e8bf7fde9fa43a849fcaaa70e230dee", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 4a6a04576..25339336f 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,10 @@ forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system}); in { - packages = forAllSystems (pkgs: { + packages = forAllSystems (pkgs: rec { default = pkgs.stdenv.mkDerivation { pname = "codebase-memory-mcp"; - version = "0.6.0"; + version = "0.9.0"; src = ./.; @@ -39,6 +39,56 @@ platforms = systems; }; }; + + # The graph-ui React frontend, built to static assets (graph-ui/dist). + # buildNpmPackage fetches npm deps offline via the pinned package-lock.json; + # bump npmDepsHash whenever that lockfile changes: + # nix run nixpkgs#prefetch-npm-deps -- graph-ui/package-lock.json + graph-ui = pkgs.buildNpmPackage { + pname = "codebase-memory-graph-ui"; + version = "0.1.0"; + + src = ./graph-ui; + + npmDepsHash = "sha256-P1JVo+GFr+Gsq88dnn9OsedZqrTaj3DDGbej+nHbp4U="; + + # `npm run build` runs `tsc -b && vite build`, emitting to dist/. + installPhase = '' + runHook preInstall + cp -r dist $out + runHook postInstall + ''; + }; + + # Same server binary as `default`, but with the graph-ui assets embedded + # so `--ui=true` starts the HTTP server. The frontend is built separately + # by the graph-ui package above; here we drop its dist/ into place and run + # the embed + link path (cbm-with-ui) — no network access needed. + codebase-memory-mcp-ui = default.overrideAttrs (old: { + pname = "codebase-memory-mcp-ui"; + + buildPhase = '' + # cbm-with-ui depends on `embed`, which depends on `frontend`, which + # runs `npm ci && npm run build` — needs network access, unavailable + # in the sandbox. Supply the pre-built assets, run the embed script + # directly, then link with `cbm-with-ui` while telling make its + # `frontend`/`embed` prerequisites are already up to date (-o) so it + # won't re-run the npm build. + mkdir -p graph-ui/dist + cp -r ${graph-ui}/. graph-ui/dist/ + chmod -R u+w graph-ui/dist + + bash scripts/embed-frontend.sh graph-ui/dist build/c/embedded + + make -j$NIX_BUILD_CORES -f Makefile.cbm \ + -o frontend -o embed \ + cbm-with-ui + ''; + + meta = old.meta // { + description = "codebase-memory-mcp with the embedded graph UI (--ui)"; + }; + }); }); devShells = forAllSystems (pkgs: {