@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 +21 -30
- package/extensions/codegraph.ts +8 -1
- package/package.json +29 -8
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.
|
|
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
|
-
|
|
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
|
-
|
|
13
|
+
Requires `codegraph` CLI on `PATH`, and [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter).
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
From the primary checkout, initialize CodeGraph once:
|
|
18
18
|
|
|
19
|
-
```
|
|
20
|
-
cd /path/to/primary-checkout
|
|
19
|
+
```bash
|
|
21
20
|
codegraph init --yes
|
|
22
21
|
```
|
|
23
22
|
|
|
24
|
-
|
|
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
|
-
##
|
|
25
|
+
## Flow
|
|
27
26
|
|
|
28
27
|
- A missing worktree index is built only when the primary checkout already has `.codegraph/codegraph.db`.
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
- Non-Git directories and repositories without a primary index are not initialized.
|
|
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
|
-
|
|
32
|
+
## State and storage
|
|
40
33
|
|
|
41
|
-
The
|
|
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
|
-
|
|
36
|
+
## Limits and recovery
|
|
44
37
|
|
|
45
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
package/extensions/codegraph.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
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": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi",
|
|
8
|
+
"codegraph",
|
|
9
|
+
"mcp",
|
|
10
|
+
"worktree"
|
|
11
|
+
],
|
|
6
12
|
"type": "module",
|
|
7
|
-
"engines": {
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.19.0"
|
|
15
|
+
},
|
|
8
16
|
"license": "MIT",
|
|
9
|
-
"files": [
|
|
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": {
|
|
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": {
|
|
26
|
-
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/HenryQW/pi-harness/issues"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
27
46
|
"pi": {
|
|
28
|
-
"extensions": [
|
|
47
|
+
"extensions": [
|
|
48
|
+
"./extensions/codegraph.ts"
|
|
49
|
+
],
|
|
29
50
|
"mcp": "./mcp.json"
|
|
30
51
|
}
|
|
31
52
|
}
|