@henryqw/pi-codegraph 0.1.0 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,57 +1,48 @@
1
- # pi-codegraph
1
+ # @henryqw/pi-codegraph
2
2
 
3
- Get a separate CodeGraph index when you start Pi in a new Git worktree. The package also supplies a lazy CodeGraph MCP server through **pi-mcp-adapter**, including the explore tool. It does not implement an MCP client or edit your MCP configuration.
3
+ Get a separate [CodeGraph](https://github.com/colbymchenry/codegraph) index when you start Pi in a new Git worktree. Use CodeGraph's explore tool through pi-mcp-adapter from Pi.
4
4
 
5
5
  ## Install
6
6
 
7
- Requirements: Pi 0.87.x, Node.js 22.19 or newer, Git, the `codegraph` CLI on `PATH`, and **pi-mcp-adapter 2.36.x or newer within 2.x installed and enabled in Pi**.
8
-
9
- ```sh
7
+ ```bash
10
8
  npm install -g @colbymchenry/codegraph
11
9
  pi install npm:pi-mcp-adapter
12
10
  pi install npm:@henryqw/pi-codegraph
13
11
  ```
14
12
 
15
- Installing an npm peer dependency alone does not enable the adapter's Pi extension. Install both packages with Pi, then restart Pi or run `/reload`.
13
+ Requires `codegraph` CLI on `PATH`, and [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter).
14
+
15
+ ## Use
16
16
 
17
- Opt a repository in by building its first index in the **primary checkout**:
17
+ From the primary checkout, initialize CodeGraph once:
18
18
 
19
- ```sh
20
- cd /path/to/primary-checkout
19
+ ```bash
21
20
  codegraph init --yes
22
21
  ```
23
22
 
24
- After that, launch `pi` in any linked worktree. The extension initializes when Pi starts, not when Git creates the worktree.
23
+ Then launch `pi` in a linked worktree. The adapter server is `henryqw_pi-codegraph__codegraph`. It discovers tools lazily; other CodeGraph tools remain available through `mcp`.
25
24
 
26
- ## What happens
25
+ ## Flow
27
26
 
28
27
  - A missing worktree index is built only when the primary checkout already has `.codegraph/codegraph.db`.
29
- - Launching from a subdirectory still initializes the worktree root. Each worktree keeps its own `.codegraph`; databases are never copied or shared between branches.
30
- - Existing indexes are left alone. CodeGraph owns synchronization when its MCP server runs.
31
- - Non-Git directories and repositories without a primary index are not initialized. A first index always requires your explicit `codegraph init`.
32
- - Pi shows initialization or waiting status. Initialization has a ten-minute timeout; concurrent sessions wait up to five minutes for the same worktree's initializer.
33
- - The adapter server is `henryqw_pi-codegraph__codegraph`. It discovers tools lazily and exposes `codegraph_explore` directly without an extra package prefix. Other CodeGraph tools remain available through `mcp`. On a cold connection, CodeGraph may require an explicit `projectPath`; pass the worktree root when its tool schema requests it.
34
-
35
- The MCP definition uses the adapter's native `pi.mcp` package discovery. Install this **package**, not just its extension `.ts` file. Loading a single file with `pi -e` does not discover its MCP manifest. When using the whole local harness as a Pi package, its server is instead `henryqw_pi-harness__codegraph`; do not install both forms together.
36
-
37
- ## Failures and limits
28
+ - Initialization happens when Pi launches, not when Git creates the worktree.
29
+ - Each linked worktree keeps its own `.codegraph`; databases are never copied or shared between branches.
30
+ - Non-Git directories and repositories without a primary index are not initialized.
38
31
 
39
- At startup, the extension checks for a loaded adapter and runs `codegraph --version`, even when an index already exists. If either prerequisite is unavailable, Pi warns with the installation command for each missing prerequisite and skips setup without creating a lock. Headless sessions print the same warning to stderr. A broken or timed-out CLI check includes its failure details; if CodeGraph is already installed, check Pi's `PATH`. Restart Pi or run `/reload` after fixing the prerequisites.
32
+ ## State and storage
40
33
 
41
- The `codegraph` executable must be available to both Pi and its MCP child process. The package never installs either prerequisite automatically.
34
+ The extension relies on CodeGraph's own state — each worktree maintains its own `.codegraph/codegraph.db`. The extension never copies, shares, or modifies this database. Existing indexes are left alone; CodeGraph owns synchronization when its MCP server runs.
42
35
 
43
- Initialization uses an exclusive `pi-codegraph-init.lock` directory inside the worktree's Git metadata. Failed or interrupted initialization keeps this lock so a partial database is not accepted on the next launch. Errors include the exact worktree and lock paths. To recover:
36
+ ## Limits and recovery
44
37
 
45
- 1. Confirm no initializer is still running.
46
- 2. Inspect the failed index and run `codegraph index` in that worktree.
47
- 3. Only after indexing succeeds, remove the reported empty lock directory with `rmdir`, then run `/reload`.
38
+ At startup, the extension checks for a loaded adapter and runs `codegraph --version`. If either prerequisite is unavailable, Pi warns and skips setup. Restart Pi or run `/reload` after fixing prerequisites.
48
39
 
49
- Do not remove an active lock. Existing indexes without an extension-owned lock are not health-checked. The lock coordinates this extension's sessions, not manual `codegraph init` commands or unrelated clients; avoid running those during initialization. A setup error does not remove files or change adapter configuration.
40
+ Initialization uses an exclusive `pi-codegraph-init.lock` in the worktree's Git metadata. Failed or interrupted initialization keeps the lock so a partial database is not accepted. To recover: remove the lock directory with `rmdir` only after `codegraph index` succeeds, then run `/reload`.
50
41
 
51
- Only Git worktree-root indexes and the default `.codegraph` directory are supported. An alternate `CODEGRAPH_DIR` is rejected. Nested monorepo indexes are not initialized automatically. The primary checkout must remain present and indexed for automatic opt-in detection.
42
+ The package never installs prerequisites automatically. The `codegraph` executable must be available to both Pi and its MCP child process. Only Git worktree-root indexes using the default `.codegraph` directory are supported; nested monorepo indexes are not initialized automatically. The primary checkout must remain indexed for automatic opt-in detection.
52
43
 
53
- The extension does not add ignore rules, delete indexes, or prune worktrees. Add `.codegraph/` to your own ignore rules if needed. Pi Subagent and Pi Orchestrator conservatively treat ignored files as retained work: an indexed worker worktree may require manual cleanup. This package does not weaken those data-loss safeguards.
44
+ Do not remove an active lock. Existing indexes without an extension-owned lock are not health-checked. The lock coordinates this extension's sessions, not manual `codegraph init` commands; avoid running those during initialization.
54
45
 
55
- ## Existing MCP configuration
46
+ The extension does not add ignore rules, delete indexes, or prune worktrees — add `.codegraph/` to your own ignore rules if needed. Pi Subagent conservatively treats ignored files as retained work: an indexed worker worktree may require manual cleanup.
56
47
 
57
48
  If you already configured a `codegraph` server manually, remove that entry after confirming the package server works. Keeping both can expose duplicate servers/tools. The extension does not change your MCP configuration.
@@ -5,6 +5,8 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
5
5
 
6
6
  const LOCK_WAIT_MS = 5 * 60_000;
7
7
  const INIT_TIMEOUT_MS = 10 * 60_000;
8
+ const WIDGET_KEY = "pi-codegraph";
9
+ const SUCCESS_TTL_MS = 5000;
8
10
 
9
11
  async function hasIndex(root: string): Promise<boolean> {
10
12
  try {
@@ -86,7 +88,12 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
86
88
  throw new Error(`CodeGraph init failed (${result.killed ? "timed out or killed" : `exit ${result.code}`}): ${(result.stderr || result.stdout).trim().slice(-2000)}`);
87
89
  }
88
90
  succeeded = true;
89
- ctx.ui.notify("CodeGraph worktree index ready.", "info");
91
+ if (ctx.hasUI) {
92
+ ctx.ui.setWidget(WIDGET_KEY, ["pi-codegraph: index ready"]);
93
+ setTimeout(() => ctx.ui.setWidget(WIDGET_KEY, undefined), SUCCESS_TTL_MS);
94
+ } else {
95
+ ctx.ui.notify("CodeGraph worktree index ready.", "info");
96
+ }
90
97
  } catch (error) {
91
98
  if (attempted) throw new Error(`${error instanceof Error ? error.message : String(error)}\n${recovery}`, { cause: error });
92
99
  throw error;
package/package.json CHANGED
@@ -1,12 +1,25 @@
1
1
  {
2
2
  "name": "@henryqw/pi-codegraph",
3
- "version": "0.1.0",
3
+ "version": "0.1.4",
4
4
  "description": "Initialize CodeGraph indexes in opted-in Git worktrees and expose CodeGraph through pi-mcp-adapter.",
5
- "keywords": ["pi-package", "pi", "codegraph", "mcp", "worktree"],
5
+ "keywords": [
6
+ "pi-package",
7
+ "pi",
8
+ "codegraph",
9
+ "mcp",
10
+ "worktree"
11
+ ],
6
12
  "type": "module",
7
- "engines": { "node": ">=22.19.0" },
13
+ "engines": {
14
+ "node": ">=22.19.0"
15
+ },
8
16
  "license": "MIT",
9
- "files": ["LICENSE", "extensions", "mcp.json", "README.md"],
17
+ "files": [
18
+ "LICENSE",
19
+ "extensions",
20
+ "mcp.json",
21
+ "README.md"
22
+ ],
10
23
  "scripts": {
11
24
  "test": "node --test test/*.test.ts",
12
25
  "typecheck": "tsc --noEmit --allowImportingTsExtensions --target ES2024 --module NodeNext --moduleResolution NodeNext --skipLibCheck extensions/codegraph.ts test/*.test.ts",
@@ -16,16 +29,24 @@
16
29
  "@earendil-works/pi-coding-agent": ">=0.87.0 <0.88.0",
17
30
  "pi-mcp-adapter": ">=2.36.0 <3.0.0"
18
31
  },
19
- "devDependencies": { "@earendil-works/pi-coding-agent": "0.87.0" },
32
+ "devDependencies": {
33
+ "@earendil-works/pi-coding-agent": "0.87.0"
34
+ },
20
35
  "repository": {
21
36
  "type": "git",
22
37
  "url": "git+https://github.com/HenryQW/pi-harness.git",
23
38
  "directory": "extensions/pi-codegraph"
24
39
  },
25
- "bugs": { "url": "https://github.com/HenryQW/pi-harness/issues" },
26
- "publishConfig": { "access": "public" },
40
+ "bugs": {
41
+ "url": "https://github.com/HenryQW/pi-harness/issues"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
27
46
  "pi": {
28
- "extensions": ["./extensions/codegraph.ts"],
47
+ "extensions": [
48
+ "./extensions/codegraph.ts"
49
+ ],
29
50
  "mcp": "./mcp.json"
30
51
  }
31
52
  }