pi-ate-memory 1.3.1 → 1.3.3

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.
@@ -26,7 +26,10 @@ export function collectMemoryAssets(cwd: string): KnowledgeAsset[] {
26
26
  try {
27
27
  for (const f of fs.readdirSync(dir)) {
28
28
  if (!f.endsWith(".md") || f === "MEMORY.md") continue;
29
- assets.push({ entry: `${prefix}/${f}`, desc: "" });
29
+ // desc = 文件名 kw 段(--kw1,kw2,kw3 → "kw1 / kw2 / kw3")——零 IO、总有值
30
+ const kwSeg = f.replace(/\.md$/, "").split("--")[1] ?? "";
31
+ const desc = kwSeg.split(",").map(s => s.trim()).filter(Boolean).slice(0, 5).join(" / ");
32
+ assets.push({ entry: `${prefix}/${f}`, desc });
30
33
  }
31
34
  } catch {
32
35
  // 目录不存在(L2 常见):跳过
@@ -10,6 +10,7 @@ export function registerRouting(pi: ExtensionAPI): void {
10
10
  const pendingTools = new Map<string, { toolName: string; args: unknown }>();
11
11
 
12
12
  pi.on("message_end", async (event: unknown, ctx: unknown) => {
13
+ if (ctx) router.setJudgeContext(ctx);
13
14
  router.accumulate(event as { message?: { content?: unknown } });
14
15
  void router.maybeTrigger(pi);
15
16
  });
package/lib/routing.ts CHANGED
@@ -64,6 +64,13 @@ export class MemoryRouter {
64
64
  private charCount = 0;
65
65
  private judgedBatches = new Set<string>();
66
66
  private judgeInstance: JudgeInstance<string[]> | null = null;
67
+ private pendingCtx: unknown = null;
68
+
69
+ /** message_end 事件的 ExtensionContext —— judge 调 LLM 的必要通道,首个事件到达时注入 */
70
+ setJudgeContext(ctx: unknown): void {
71
+ this.pendingCtx = ctx;
72
+ if (this.judgeInstance) (this.judgeInstance as unknown as { setContext(c: unknown): void }).setContext(ctx);
73
+ }
67
74
  readonly readTracker = createReadTracker();
68
75
 
69
76
  constructor(private cwd: string, config: RoutingConfig) {
@@ -124,6 +131,7 @@ export class MemoryRouter {
124
131
  judgeLogPath: `${process.env.USERPROFILE ?? process.env.HOME ?? ""}/.pi/agent/logs/memory-routing-llmjudge.log`,
125
132
  legacySectionKeys: ["memoryRouting", "shepherd"],
126
133
  });
134
+ if (this.pendingCtx != null) (this.judgeInstance as unknown as { setContext(c: unknown): void }).setContext(this.pendingCtx);
127
135
  }
128
136
  return this.judgeInstance;
129
137
  }
@@ -157,7 +165,14 @@ export class MemoryRouter {
157
165
  const candidates = hits.filter((a) => !this.readTracker.hasRead(a.entry)).slice(0, 3);
158
166
  if (candidates.length === 0) return;
159
167
 
160
- const lines = candidates.map((a) => `- ${a.entry}(${a.desc.slice(0, 60)})`).join("\n");
168
+ const lines = candidates.map((a) => {
169
+ const full = a.entry.startsWith("memory/")
170
+ ? `~/.pi/agent/${a.entry}`
171
+ : a.entry.startsWith(".pi/memory/")
172
+ ? `${this.cwd}/${a.entry}`
173
+ : `${this.cwd}/${a.entry}`;
174
+ return `- ${full}(${a.desc.slice(0, 60) || "关键词见文件名"})`;
175
+ }).join("\n");
161
176
  const stems = candidates.map((a) => (a.entry.split("/").pop() ?? "").split("--")[0]).join("、");
162
177
  pi.events.emit("ephemeral:hint", {
163
178
  text: `💡 记忆路由:本段工作与以下知识资产相关(你尚未读过):\n${lines}\n如相关请 read;无关可忽略。`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ate-memory",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "File-based persistent memory for AI coding agents",
5
5
  "keywords": [
6
6
  "pi-package"