@liuxincuit/pi-codegraph 0.1.0 → 0.1.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
@@ -15,6 +15,8 @@
15
15
  npm i -g @colbymchenry/codegraph
16
16
  ```
17
17
 
18
+ 未检测到 CLI 时,插件**不会注入任何工具、命令或技能**(`codegraph_explore`、`/codegraph-*`、CodeGraph 技能均不加载),仅在会话开始时弹出一条安装提示;安装后 `/reload` 或重启 pi 即恢复全部功能。
19
+
18
20
  ## 安装
19
21
 
20
22
  ### npm(推荐)
@@ -11,13 +11,18 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
11
11
  import { Type } from "typebox";
12
12
  import * as fs from "node:fs/promises";
13
13
  import * as path from "node:path";
14
+ import { fileURLToPath } from "node:url";
14
15
 
15
16
  const INSTALL_HINT =
16
- "codegraph CLI not found on PATH. Install: npm i -g @colbymchenry/codegraph";
17
+ "未检测到 codegraph CLIPATH 中无 codegraph 命令),本插件未注入任何工具、命令或技能。" +
18
+ "安装:npm i -g @colbymchenry/codegraph,然后 /reload 或重启 pi 生效。";
19
+
20
+ // Whole-process dedup for the missing-CLI hint: extensions re-run per session and
21
+ // per subagent (separate jiti module copies), so gate on globalThis.
22
+ const MISSING_CLI_HINTED = Symbol.for("pi-codegraph.missing-cli-hinted");
17
23
 
18
24
  // Result of `codegraph version` this session — null until first check.
19
25
  let cliAvailable: boolean | null = null;
20
- let notifiedMissing = false;
21
26
 
22
27
  async function execCg(
23
28
  pi: ExtensionAPI,
@@ -88,7 +93,21 @@ A \`.codegraph/\` index exists here: SQLite knowledge graph of every symbol, edg
88
93
  - Multi-project / Monorepo: pass \`path\` to query any indexed sub-project directory.
89
94
  - If a project has no \`.codegraph/\`, use built-in tools there; indexing is the user's decision — suggest /codegraph-init if it comes up.`;
90
95
 
91
- export default function codegraphExtension(pi: ExtensionAPI) {
96
+ // When the CLI is absent, register nothing but a one-shot hint handler: no
97
+ // tools, no commands, no resources_discover (so no skill injection), no sync.
98
+ export function registerMissingCliHint(pi: ExtensionAPI) {
99
+ pi.on("session_start", async (_event, ctx) => {
100
+ if ((globalThis as Record<symbol, boolean>)[MISSING_CLI_HINTED]) return;
101
+ (globalThis as Record<symbol, boolean>)[MISSING_CLI_HINTED] = true;
102
+ if (ctx.hasUI) ctx.ui.notify(INSTALL_HINT, "warning");
103
+ });
104
+ }
105
+
106
+ export default async function codegraphExtension(pi: ExtensionAPI) {
107
+ if (!(await ensureCli(pi))) {
108
+ registerMissingCliHint(pi);
109
+ return;
110
+ }
92
111
  // ── codegraph_explore tool ─────────────────────────────────────────────
93
112
  pi.registerTool({
94
113
  name: "codegraph_explore",
@@ -238,17 +257,15 @@ export default function codegraphExtension(pi: ExtensionAPI) {
238
257
  },
239
258
  });
240
259
 
241
- // ── session_start: CLI check + incremental sync + context hint ────────
242
- pi.on("session_start", async (event, ctx) => {
243
- if (!(await ensureCli(pi))) {
244
- updateStatusBar(ctx, false);
245
- if (ctx.hasUI && !notifiedMissing) {
246
- notifiedMissing = true;
247
- ctx.ui.notify(INSTALL_HINT, "warning");
248
- }
249
- return;
250
- }
260
+ // ── resources_discover: contribute the skill only when the CLI exists ──
261
+ pi.on("resources_discover", async () => {
262
+ return {
263
+ skillPaths: [fileURLToPath(new URL("../skills/codegraph/SKILL.md", import.meta.url))],
264
+ };
265
+ });
251
266
 
267
+ // ── session_start: incremental sync + context hint ────────────────────
268
+ pi.on("session_start", async (event, ctx) => {
252
269
  const indexed = await isIndexed(ctx.cwd);
253
270
  if (indexed) {
254
271
  updateStatusBar(ctx, "sync");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liuxincuit/pi-codegraph",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CodeGraph support for pi — symbol source + call paths via the codegraph CLI",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -31,9 +31,6 @@
31
31
  "pi": {
32
32
  "extensions": [
33
33
  "./extensions"
34
- ],
35
- "skills": [
36
- "./skills"
37
34
  ]
38
35
  },
39
36
  "files": [