@josephyoung/pi-file-reference 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.
@@ -1,10 +1,9 @@
1
- import type { ExtensionAPI, CustomEntry } from "@earendil-works/pi-coding-agent";
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
2
  import * as fs from "node:fs";
3
3
  import * as path from "node:path";
4
4
  import * as os from "node:os";
5
5
 
6
6
  const AGENTS_FILE = "AGENTS.md";
7
- const STORE_KEY = "agents-at-context";
8
7
 
9
8
  /**
10
9
  * Parse @filepath references from a line.
@@ -130,45 +129,31 @@ function loadRefs(cwd: string): RefContent[] {
130
129
  if (fs.existsSync(resolvedPath)) {
131
130
  results.push({ ref, content: fs.readFileSync(resolvedPath, "utf-8") });
132
131
  } else {
133
- console.warn(`[agents-at-reader] @${ref} -> ${resolvedPath} not found, skipping`);
132
+ console.warn(`[pi-file-reference] @${ref} -> ${resolvedPath} not found, skipping`);
134
133
  }
135
134
  }
136
135
 
137
136
  return results;
138
137
  }
139
138
 
139
+ let cachedRefs: RefContent[] = [];
140
+
140
141
  export default function (pi: ExtensionAPI) {
141
142
  pi.on("session_start", (_event, ctx) => {
142
- // Check if custom entry already exists (e.g., after reload)
143
- const entries = ctx.sessionManager.getEntries();
144
- const existing = entries.find(
145
- (e): e is CustomEntry<{ refs: RefContent[] }> =>
146
- e.type === "custom" && e.customType === STORE_KEY,
147
- );
148
- if (existing) return;
149
-
150
- const refs = loadRefs(ctx.cwd);
151
- if (refs.length === 0) return;
152
-
153
- pi.appendEntry(STORE_KEY, { refs });
143
+ cachedRefs = loadRefs(ctx.cwd);
154
144
  });
155
145
 
156
- pi.on("before_agent_start", (event, ctx) => {
157
- const entries = ctx.sessionManager.getEntries();
158
- const entry = entries.find(
159
- (e): e is CustomEntry<{ refs: RefContent[] }> =>
160
- e.type === "custom" && e.customType === STORE_KEY,
161
- );
162
- if (!entry?.data?.refs?.length) return;
146
+ pi.on("before_agent_start", (event, _ctx) => {
147
+ if (!cachedRefs.length) return;
163
148
 
164
- const injected = entry.data.refs
165
- .map((r) => `// @${r.ref}\n${r.content}`)
149
+ const injected = cachedRefs
150
+ .map((r) => `## @${r.ref}\n\n${r.content}`)
166
151
  .join("\n\n");
167
152
 
168
153
  return {
169
154
  systemPrompt:
170
155
  event.systemPrompt +
171
- `\n\n---\n// @AGENTS.md 引用文件 — 注入以下文件内容供参考\n${injected}\n---`,
156
+ `\n\n# Context References\n\n${injected}`,
172
157
  };
173
158
  });
174
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@josephyoung/pi-file-reference",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "private": false,
5
5
  "description": "Pi extension that resolves @filepath references in AGENTS.md and injects file content into system prompt",
6
6
  "type": "module",
package/tsconfig.json CHANGED
@@ -7,5 +7,5 @@
7
7
  "noEmit": true,
8
8
  "skipLibCheck": true
9
9
  },
10
- "include": ["agents-at-reader.ts"]
10
+ "include": ["extensions/**/*.ts"]
11
11
  }