@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.
- package/extensions/index.ts +10 -25
- package/package.json +1 -1
- package/tsconfig.json +1 -1
package/extensions/index.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { ExtensionAPI
|
|
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(`[
|
|
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
|
-
|
|
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,
|
|
157
|
-
|
|
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 =
|
|
165
|
-
.map((r) =>
|
|
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
|
|
156
|
+
`\n\n# Context References\n\n${injected}`,
|
|
172
157
|
};
|
|
173
158
|
});
|
|
174
159
|
}
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED