@henryqw/pi-codegraph 0.1.4 → 0.2.0
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 +2 -1
- package/extensions/codegraph.ts +13 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ Then launch `pi` in a linked worktree. The adapter server is `henryqw_pi-codegra
|
|
|
28
28
|
- Initialization happens when Pi launches, not when Git creates the worktree.
|
|
29
29
|
- Each linked worktree keeps its own `.codegraph`; databases are never copied or shared between branches.
|
|
30
30
|
- Non-Git directories and repositories without a primary index are not initialized.
|
|
31
|
+
- 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
32
|
|
|
32
33
|
## State and storage
|
|
33
34
|
|
|
@@ -35,7 +36,7 @@ The extension relies on CodeGraph's own state — each worktree maintains its ow
|
|
|
35
36
|
|
|
36
37
|
## Limits and recovery
|
|
37
38
|
|
|
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.
|
|
39
|
+
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
40
|
|
|
40
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: remove the lock directory with `rmdir` only after `codegraph index` succeeds, then run `/reload`.
|
|
41
42
|
|
package/extensions/codegraph.ts
CHANGED
|
@@ -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", "
|
|
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",
|
|
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", "
|
|
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", "
|
|
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))
|
|
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", "
|
|
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",
|
|
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", "
|
|
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
|
}
|