@henryqw/pi-codegraph 0.1.4 → 0.2.1

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,4 +1,4 @@
1
- # @henryqw/pi-codegraph
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,14 @@ pi install npm:pi-mcp-adapter
10
10
  pi install npm:@henryqw/pi-codegraph
11
11
  ```
12
12
 
13
- Requires `codegraph` CLI on `PATH`, and [pi-mcp-adapter](https://github.com/nicobailon/pi-mcp-adapter).
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
+ | [`pi-mcp-adapter`](https://github.com/nicobailon/pi-mcp-adapter) | Required | Connects the MCP server to Pi. |
14
21
 
15
22
  ## Use
16
23
 
@@ -20,7 +27,15 @@ From the primary checkout, initialize CodeGraph once:
20
27
  codegraph init --yes
21
28
  ```
22
29
 
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`.
30
+ 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.
31
+
32
+ | Surface | Type | Purpose |
33
+ | --- | --- | --- |
34
+ | `codegraph_explore` | tool | Lets agents explore the indexed code through CodeGraph. |
35
+ | `mcp` | tool | Lets agents call other CodeGraph tools through the `henryqw_pi-codegraph__codegraph` adapter server. |
36
+ | CodeGraph setup status | ui | Shows users setup progress and errors, and confirms a new worktree index is ready. |
37
+
38
+ The adapter discovers tools lazily.
24
39
 
25
40
  ## Flow
26
41
 
@@ -28,6 +43,7 @@ Then launch `pi` in a linked worktree. The adapter server is `henryqw_pi-codegra
28
43
  - Initialization happens when Pi launches, not when Git creates the worktree.
29
44
  - Each linked worktree keeps its own `.codegraph`; databases are never copied or shared between branches.
30
45
  - Non-Git directories and repositories without a primary index are not initialized.
46
+ - When loaded, the extension reports whether the local index is `indexed`, `missing`, or `indexing…` through Pi's status channel. The `pi-footer` extension places a compact `CG` badge first on its third line and temporarily shows `● CG` during direct CodeGraph tool calls.
31
47
 
32
48
  ## State and storage
33
49
 
@@ -35,7 +51,7 @@ The extension relies on CodeGraph's own state — each worktree maintains its ow
35
51
 
36
52
  ## Limits and recovery
37
53
 
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.
54
+ 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.
39
55
 
40
56
  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`.
41
57
 
@@ -37,12 +37,12 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
37
37
  }
38
38
  if (prerequisites.length) {
39
39
  const message = `pi-codegraph: setup skipped.\n${prerequisites.join("\n")}\nThen restart Pi or /reload.`;
40
- ctx.ui.setStatus("pi-codegraph", "CodeGraph: prerequisites missing");
40
+ ctx.ui.setStatus("pi-codegraph", "pi-codegraph: prerequisites missing");
41
41
  if (ctx.hasUI) ctx.ui.notify(message, "warning");
42
42
  else console.warn(message);
43
43
  return;
44
44
  }
45
- ctx.ui.setStatus("pi-codegraph", undefined);
45
+ ctx.ui.setStatus("pi-codegraph", "pi-codegraph: missing");
46
46
  const rootResult = await pi.exec("git", ["rev-parse", "--show-toplevel"], { cwd: ctx.cwd, timeout: 10_000 });
47
47
  if (rootResult.code !== 0 || rootResult.killed) {
48
48
  if (!rootResult.killed && rootResult.stderr.includes("not a git repository")) return;
@@ -59,7 +59,8 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
59
59
  // Check the lock before the database: an in-progress/failed init can leave a partial DB.
60
60
  const recovery = `Inspect CodeGraph in ${root}. If no initializer is running, run codegraph index in that directory, then remove ${lock} with rmdir and /reload.`;
61
61
  const deadline = Date.now() + LOCK_WAIT_MS;
62
- ctx.ui.setStatus("pi-codegraph", "CodeGraph: checking index…");
62
+ ctx.ui.setStatus("pi-codegraph", "pi-codegraph: checking index…");
63
+ let indexed = false;
63
64
  try {
64
65
  while (true) {
65
66
  try {
@@ -68,26 +69,30 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
68
69
  } catch (error) {
69
70
  if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
70
71
  if (Date.now() >= deadline) throw new Error(`Timed out waiting for CodeGraph initialization. ${recovery}`);
71
- ctx.ui.setStatus("pi-codegraph", "CodeGraph: waiting for initialization…");
72
+ ctx.ui.setStatus("pi-codegraph", "pi-codegraph: indexing…");
72
73
  await delay(250);
73
74
  }
74
75
  }
75
76
  let attempted = false;
76
77
  let succeeded = false;
77
78
  try {
78
- if (await hasIndex(root)) return;
79
+ if (await hasIndex(root)) {
80
+ indexed = true;
81
+ return;
82
+ }
79
83
  const worktrees = await git(pi, root, ["worktree", "list", "--porcelain", "-z"]);
80
84
  const first = worktrees.split("\0", 1)[0];
81
85
  if (!first?.startsWith("worktree ")) throw new Error("Git returned an invalid primary worktree.");
82
86
  const primary = first.slice("worktree ".length);
83
87
  if (!primary || primary === root || !(await hasIndex(primary))) return;
84
- ctx.ui.setStatus("pi-codegraph", "CodeGraph: building worktree index…");
88
+ ctx.ui.setStatus("pi-codegraph", "pi-codegraph: indexing…");
85
89
  attempted = true;
86
90
  const result = await pi.exec("codegraph", ["init", "--yes", root], { cwd: root, timeout: INIT_TIMEOUT_MS });
87
91
  if (result.code !== 0 || result.killed || !(await hasIndex(root))) {
88
92
  throw new Error(`CodeGraph init failed (${result.killed ? "timed out or killed" : `exit ${result.code}`}): ${(result.stderr || result.stdout).trim().slice(-2000)}`);
89
93
  }
90
94
  succeeded = true;
95
+ indexed = true;
91
96
  if (ctx.hasUI) {
92
97
  ctx.ui.setWidget(WIDGET_KEY, ["pi-codegraph: index ready"]);
93
98
  setTimeout(() => ctx.ui.setWidget(WIDGET_KEY, undefined), SUCCESS_TTL_MS);
@@ -102,7 +107,7 @@ async function initialize(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void
102
107
  if (!attempted || succeeded) await rmdir(lock);
103
108
  }
104
109
  } finally {
105
- ctx.ui.setStatus("pi-codegraph", undefined);
110
+ ctx.ui.setStatus("pi-codegraph", indexed ? "pi-codegraph: indexed" : "pi-codegraph: missing");
106
111
  }
107
112
  }
108
113
 
@@ -112,7 +117,7 @@ export default function codegraphExtension(pi: ExtensionAPI): void {
112
117
  await initialize(pi, ctx);
113
118
  } catch (error) {
114
119
  const message = `pi-codegraph: ${error instanceof Error ? error.message : String(error)}`;
115
- ctx.ui.setStatus("pi-codegraph", "CodeGraph: setup failed");
120
+ ctx.ui.setStatus("pi-codegraph", "pi-codegraph: setup failed");
116
121
  if (ctx.hasUI) ctx.ui.notify(message, "error");
117
122
  else throw new Error(message, { cause: error });
118
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-codegraph",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "Initialize CodeGraph indexes in opted-in Git worktrees and expose CodeGraph through pi-mcp-adapter.",
5
5
  "keywords": [
6
6
  "pi-package",