@yandy0725/pi-memory 2.1.0 → 2.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.
Files changed (2) hide show
  1. package/index.ts +27 -5
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -144,6 +144,9 @@ export default function (pi: ExtensionAPI) {
144
144
  */
145
145
  const inFlight = new Set<Promise<unknown>>();
146
146
 
147
+ /** `enabled: false` 时给用户的唯一动作。工具文案与 `/memory` 状态共用同一份,避免两处漂移。 */
148
+ const ENABLE_HINT = 'set "enabled": true in memory.json and restart';
149
+
147
150
  /**
148
151
  * 清空本 session 的运行时状态。三条早退路径(disabled / 配置错误 / 初始化失败)共用:
149
152
  * 残留上一 session 的 store 会让后续写入落到别的项目目录(Plan C ledger R51)。
@@ -183,7 +186,7 @@ export default function (pi: ExtensionAPI) {
183
186
  configError
184
187
  ? `Memory not initialized — ${configError.split("\n")[0]}; run /memory for details`
185
188
  : config?.enabled === false
186
- ? 'Memory is disabled — set "enabled": true in memory.json and restart'
189
+ ? `Memory is disabled — ${ENABLE_HINT}`
187
190
  : null,
188
191
  searchSessions,
189
192
  cwd: () => currentCwd,
@@ -239,14 +242,24 @@ export default function (pi: ExtensionAPI) {
239
242
  extractErrorNotified = false;
240
243
  configError = null;
241
244
  resetSessionState();
242
- config = await loadConfig(ctx);
245
+ // `loadConfig` 抛错(`getAgentDir` / `isProjectTrusted` 属宿主契约)与初始化失败同一处理:
246
+ // 转成配置错误态,不把裸 reject 冒给宿主(spec §2.4)。用局部变量承接是为了让后面的收窄
247
+ // 不受 `config` 这个工厂作用域 let 影响。(nudge 块仍可能抛错,属既有暴露面,不在本次范围。)
248
+ let loaded: MemoryConfig;
249
+ try {
250
+ loaded = await loadConfig(ctx);
251
+ } catch (e) {
252
+ failConfig([`Failed to load memory config: ${e instanceof Error ? e.message : String(e)}`], ctx);
253
+ return;
254
+ }
255
+ config = loaded;
243
256
  // 状态已经干净,disabled 直接早退即可。
244
- if (!config.enabled) return;
257
+ if (!loaded.enabled) return;
245
258
  try {
246
259
  // 启动校验(spec §2.3):模型键缺失 / 不可解析 → 本会话**完全不初始化**
247
260
  //(不解析目录、不建 store、不注册工具),错误态由 `/memory` 重复显示。
248
261
  // 校验本身抛错(registry 不合契约)也走同一个 catch:failConfig 自己会复位运行时。
249
- const errors = modelConfigErrors(config, (value) => resolveModel(value, ctx.modelRegistry) !== undefined);
262
+ const errors = modelConfigErrors(loaded, (value) => resolveModel(value, ctx.modelRegistry) !== undefined);
250
263
  if (errors.length > 0) {
251
264
  failConfig(errors, ctx);
252
265
  return;
@@ -492,7 +505,16 @@ export default function (pi: ExtensionAPI) {
492
505
  pi.registerCommand("memory", {
493
506
  description: "Show memory status or remove a stale lock",
494
507
  handler: async (args, ctx) => {
508
+ // 配置都读不出来(`loadConfig` 抛错)时也要报真实原因,而不是笼统的「未初始化」——
509
+ // `/memory` 是重读错误态的唯一入口。首次会话就失败时 `config` 仍是 null,所以这里先看错误态。
495
510
  if (!config) {
511
+ if (configError) {
512
+ ctx.ui.notify(
513
+ ["Memory: misconfigured", "Dir: not initialized", ...configError.split("\n").map((e) => `- ${e}`)].join("\n"),
514
+ "info",
515
+ );
516
+ return;
517
+ }
496
518
  ctx.ui.notify("Memory not initialized.", "info");
497
519
  return;
498
520
  }
@@ -524,7 +546,7 @@ export default function (pi: ExtensionAPI) {
524
546
  // 否则只可能是配置里 enabled 为假。
525
547
  const lines = configError
526
548
  ? ["Memory: misconfigured", "Dir: not initialized", ...configError.split("\n").map((e) => `- ${e}`)]
527
- : ["Memory: disabled", 'Dir: not initialized — set "enabled": true in memory.json and restart'];
549
+ : ["Memory: disabled", `Dir: not initialized — ${ENABLE_HINT}`];
528
550
  ctx.ui.notify(lines.join("\n"), "info");
529
551
  return;
530
552
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.1.0",
6
+ "version": "2.1.1",
7
7
  "description": "File-system driven persistent memory layer for pi coding agent",
8
8
  "license": "MIT",
9
9
  "repository": {