@henryqw/pi-codegraph 0.2.0 → 0.2.2
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 +27 -6
- package/extensions/codegraph.ts +1 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@henryqw/pi-codegraph`
|
|
2
2
|
|
|
3
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
|
|
|
@@ -10,7 +10,15 @@ pi install npm:pi-mcp-adapter
|
|
|
10
10
|
pi install npm:@henryqw/pi-codegraph
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Requires `codegraph` CLI on `PATH
|
|
13
|
+
Requires the `codegraph` CLI on `PATH` and [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter).
|
|
14
|
+
|
|
15
|
+
## Works with
|
|
16
|
+
|
|
17
|
+
| Package | Relationship | Purpose |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| [`@colbymchenry/codegraph`](https://github.com/colbymchenry/codegraph) | Required | Builds the indexes and serves CodeGraph tools over MCP. |
|
|
20
|
+
| [`@henryqw/pi-footer`](https://pi.henry.wang/extensions/pi-footer) | Improves | Shows a compact CodeGraph index badge and direct tool activity when loaded. |
|
|
21
|
+
| [`pi-mcp-adapter`](https://github.com/nicobailon/pi-mcp-adapter) | Required | Connects the MCP server to Pi. |
|
|
14
22
|
|
|
15
23
|
## Use
|
|
16
24
|
|
|
@@ -20,7 +28,15 @@ From the primary checkout, initialize CodeGraph once:
|
|
|
20
28
|
codegraph init --yes
|
|
21
29
|
```
|
|
22
30
|
|
|
23
|
-
Then launch `pi` in a linked worktree.
|
|
31
|
+
Then launch `pi` in a linked worktree. When the primary checkout has an index, pi-codegraph initializes a separate worktree index and exposes CodeGraph tools through pi-mcp-adapter.
|
|
32
|
+
|
|
33
|
+
| Surface | Type | Purpose |
|
|
34
|
+
| --- | --- | --- |
|
|
35
|
+
| `codegraph_explore` | tool | Lets agents explore the indexed code through CodeGraph. |
|
|
36
|
+
| `mcp` | tool | Lets agents call other CodeGraph tools through the `henryqw_pi-codegraph__codegraph` adapter server. |
|
|
37
|
+
| CodeGraph setup status | ui | Shows users setup progress and errors, and confirms a new worktree index is ready. |
|
|
38
|
+
|
|
39
|
+
The adapter discovers tools lazily.
|
|
24
40
|
|
|
25
41
|
## Flow
|
|
26
42
|
|
|
@@ -28,17 +44,22 @@ Then launch `pi` in a linked worktree. The adapter server is `henryqw_pi-codegra
|
|
|
28
44
|
- Initialization happens when Pi launches, not when Git creates the worktree.
|
|
29
45
|
- Each linked worktree keeps its own `.codegraph`; databases are never copied or shared between branches.
|
|
30
46
|
- Non-Git directories and repositories without a primary index are not initialized.
|
|
31
|
-
-
|
|
47
|
+
- The extension reports `checking index…` and `indexing…` during setup, `indexed` when a database file exists, `missing` when no index was built, `prerequisites missing` when setup was skipped, and `setup failed` on an error. `indexed` does not guarantee database health.
|
|
48
|
+
- If `pi-footer` is also loaded, it places a compact `CG` badge first on its third line: `✓ CG` indexed, `○ CG` missing, `◐ CG` checking or indexing, `! CG` setup problem, or `? CG` unknown state. It temporarily shows `● CG` only during direct `codegraph_explore` calls or `codegraph_*` calls through this package's MCP server, not for every MCP call.
|
|
32
49
|
|
|
33
50
|
## State and storage
|
|
34
51
|
|
|
35
|
-
The extension relies on CodeGraph's own state — each worktree maintains its own `.codegraph/codegraph.db`. The extension never copies
|
|
52
|
+
The extension relies on CodeGraph's own state — each worktree maintains its own `.codegraph/codegraph.db`. The extension never copies or shares the database and does not write it directly: it delegates creation to `codegraph init --yes <worktree-root>`. Existing indexes are left alone; CodeGraph owns synchronization when its MCP server runs.
|
|
36
53
|
|
|
37
54
|
## Limits and recovery
|
|
38
55
|
|
|
39
56
|
At startup, the extension checks for a loaded adapter and runs `codegraph --version`. If either prerequisite is unavailable, Pi warns, reports `prerequisites missing`, and skips setup. Restart Pi or run `/reload` after fixing prerequisites.
|
|
40
57
|
|
|
41
|
-
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
|
|
58
|
+
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, first confirm no initializer is running, then run `codegraph index` **from the affected worktree root** (not the primary checkout or a nested directory). Only after it succeeds, remove the lock directory with `rmdir` using the path in the error message, then run `/reload`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
cd /path/to/affected-worktree-root && codegraph index && rmdir /path/to/pi-codegraph-init.lock
|
|
62
|
+
```
|
|
42
63
|
|
|
43
64
|
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.
|
|
44
65
|
|
package/extensions/codegraph.ts
CHANGED
|
@@ -74,7 +74,6 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
let attempted = false;
|
|
77
|
-
let succeeded = false;
|
|
78
77
|
try {
|
|
79
78
|
if (await hasIndex(root)) {
|
|
80
79
|
indexed = true;
|
|
@@ -91,7 +90,6 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
|
|
|
91
90
|
if (result.code !== 0 || result.killed || !(await hasIndex(root))) {
|
|
92
91
|
throw new Error(`CodeGraph init failed (${result.killed ? "timed out or killed" : `exit ${result.code}`}): ${(result.stderr || result.stdout).trim().slice(-2000)}`);
|
|
93
92
|
}
|
|
94
|
-
succeeded = true;
|
|
95
93
|
indexed = true;
|
|
96
94
|
if (ctx.hasUI) {
|
|
97
95
|
ctx.ui.setWidget(WIDGET_KEY, ["pi-codegraph: index ready"]);
|
|
@@ -104,7 +102,7 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
|
|
|
104
102
|
throw error;
|
|
105
103
|
} finally {
|
|
106
104
|
// A failed or interrupted init stays locked; never accept its partial DB on reload.
|
|
107
|
-
if (!attempted ||
|
|
105
|
+
if (!attempted || indexed) await rmdir(lock);
|
|
108
106
|
}
|
|
109
107
|
} finally {
|
|
110
108
|
ctx.ui.setStatus("pi-codegraph", indexed ? "pi-codegraph: indexed" : "pi-codegraph: missing");
|