@cydm/pie 4.13.0 → 4.14.0

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 (33) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +4 -4
  2. package/dist/builtin/extensions/im-forward/index.js +8099 -8101
  3. package/dist/builtin/extensions/mcp-adapter/index.js +86 -81
  4. package/dist/builtin/extensions/memory/index.js +30 -7
  5. package/dist/builtin/extensions/pie-ipc/index.js +13 -18
  6. package/dist/builtin/extensions/pie-proc/index.js +69 -60
  7. package/dist/builtin/extensions/plan-mode/index.js +4 -4
  8. package/dist/builtin/extensions/subagent/index.js +6 -5
  9. package/dist/builtin/extensions/todo/index.js +4 -4
  10. package/dist/chunks/{chunk-BQWHLYYZ.js → chunk-26KRUYZH.js} +1 -1
  11. package/dist/chunks/{chunk-5MCIBDAM.js → chunk-BOQIGMGQ.js} +38 -93
  12. package/dist/chunks/{chunk-AKC7NMP4.js → chunk-EZZTMDWZ.js} +887 -391
  13. package/dist/chunks/{chunk-5PCLBIOO.js → chunk-FD3KBPDR.js} +110 -75
  14. package/dist/chunks/{chunk-NOSNHMA2.js → chunk-IK2FR2YF.js} +2 -1
  15. package/dist/chunks/{chunk-SXBX2P5R.js → chunk-JJH77AUU.js} +1709 -1577
  16. package/dist/chunks/{chunk-OGGL6LUN.js → chunk-JKO42HZW.js} +1 -1
  17. package/dist/chunks/{chunk-3CJLYX5J.js → chunk-KGWKRO7Z.js} +2 -2
  18. package/dist/chunks/{chunk-G2K4GY6N.js → chunk-MCR4JYI6.js} +103 -12
  19. package/dist/chunks/{chunk-IZ4DYCJ7.js → chunk-UYDS75SI.js} +810 -726
  20. package/dist/chunks/{host-image-fallback-MZK633DK.js → host-image-fallback-LPHB5CTL.js} +1 -1
  21. package/dist/chunks/{manager-cli-OTIMAWO6.js → manager-cli-ZV36YNPJ.js} +187 -173
  22. package/dist/chunks/{memory-git-Q3UBYOJ4.js → memory-git-ZJN6SPIU.js} +5 -5
  23. package/dist/chunks/{model-registry-QNEPISBJ.js → model-registry-GLBIUOJR.js} +2 -2
  24. package/dist/chunks/{read-file-understanding-KCJMSOS7.js → read-file-understanding-DFJPTTSB.js} +5 -5
  25. package/dist/chunks/{src-TIDKYA5F.js → src-76Q33OY5.js} +1 -1
  26. package/dist/chunks/{src-D5GN4Q5O.js → src-ALHMJZ5R.js} +2 -2
  27. package/dist/chunks/{src-7MZZJVOG.js → src-KZ7YID3I.js} +11 -3
  28. package/dist/chunks/{src-QI47K3W3.js → src-LEXKDSFV.js} +24 -6
  29. package/dist/chunks/{test-stream-JAJHK44G.js → test-stream-OVGDTXOY.js} +1 -1
  30. package/dist/cli.js +12910 -12631
  31. package/models.schema.json +12 -3
  32. package/package.json +1 -1
  33. package/dist/chunks/{chunk-3GG342QY.js → chunk-TYCKSYUF.js} +19 -19
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-CBDQJMUI.js";
5
5
  import {
6
6
  createMemoryLockBackend
7
- } from "./chunk-AKC7NMP4.js";
7
+ } from "./chunk-EZZTMDWZ.js";
8
8
 
9
9
  // src/commands/memory-distill.ts
10
10
  import * as fs from "node:fs";
@@ -143,8 +143,9 @@ function resolveDefaultModelSpecFromSettings() {
143
143
  return void 0;
144
144
  }
145
145
  function createWikiModelCall(registry, modelClass, explicitModelSpec, timeoutMs = 18e4, hooks) {
146
- const resolveTarget = () => {
146
+ const resolveTargets = () => {
147
147
  const trySpec = (spec) => {
148
+ if (typeof registry.find !== "function" || typeof registry.getApiKey !== "function") return void 0;
148
149
  const slash = spec.indexOf("/");
149
150
  if (slash <= 0 || slash === spec.length - 1) return void 0;
150
151
  const provider = spec.slice(0, slash);
@@ -160,79 +161,108 @@ function createWikiModelCall(registry, modelClass, explicitModelSpec, timeoutMs
160
161
  if (!exact) {
161
162
  throw new Error(`model "${explicitModelSpec}" is not configured or has no API key`);
162
163
  }
163
- return exact;
164
+ return [exact];
165
+ }
166
+ const targets = [];
167
+ const seen = /* @__PURE__ */ new Set();
168
+ const pushTarget = (entry) => {
169
+ if (!entry?.model || !entry.apiKey) return;
170
+ const key = `${entry.model.provider}/${entry.model.id}`;
171
+ if (seen.has(key)) return;
172
+ seen.add(key);
173
+ targets.push({ model: entry.model, apiKey: entry.apiKey });
174
+ };
175
+ for (const candidate of registry.resolveModelClassCandidates?.(modelClass) ?? []) {
176
+ pushTarget(candidate);
164
177
  }
165
178
  const byClass = registry.resolveModelClass(modelClass);
166
- if (byClass.model && byClass.apiKey) {
167
- return { model: byClass.model, apiKey: byClass.apiKey };
179
+ pushTarget(byClass);
180
+ if (modelClass === "light") {
181
+ for (const candidate of registry.resolveModelClassCandidates?.("balanced") ?? []) {
182
+ pushTarget(candidate);
183
+ }
184
+ pushTarget(registry.resolveModelClass("balanced"));
168
185
  }
169
186
  const fallbackSpec = resolveDefaultModelSpecFromSettings();
170
187
  if (fallbackSpec) {
171
- const fallback = trySpec(fallbackSpec);
172
- if (fallback) return fallback;
188
+ pushTarget(trySpec(fallbackSpec));
173
189
  }
174
- throw new Error(`no complete model/key pair for class ${modelClass}${byClass.fallbackReason ? `: ${byClass.fallbackReason}` : ""}`);
190
+ if (targets.length === 0) {
191
+ throw new Error(`no complete model/key pair for class ${modelClass}${byClass.fallbackReason ? `: ${byClass.fallbackReason}` : ""}`);
192
+ }
193
+ return targets;
175
194
  };
176
195
  return async (prompt, options) => {
177
- const { model, apiKey } = resolveTarget();
178
- const complete = hooks?.completeFn ?? (await import("./src-TIDKYA5F.js")).completeSimple;
179
- const invokeOnce = async () => {
180
- const controller = new AbortController();
181
- let timedOut = false;
182
- const timer = setTimeout(() => {
183
- timedOut = true;
184
- controller.abort();
185
- }, timeoutMs);
186
- try {
187
- const message = await complete(
188
- model,
189
- {
190
- systemPrompt: options?.system ?? "You are a disciplined memory curator. Output JSON only.",
191
- messages: [{ role: "user", content: [{ type: "text", text: prompt }], timestamp: Date.now() }]
192
- },
193
- {
194
- apiKey,
195
- ...model.reasoning ? { reasoning: "low" } : {},
196
- maxTokens: Math.min(model.maxTokens ?? 32768, 32768),
197
- signal: controller.signal
196
+ const targets = resolveTargets();
197
+ const complete = hooks?.completeFn ?? (await import("./src-76Q33OY5.js")).completeSimple;
198
+ const runCandidate = async (model, apiKey) => {
199
+ const invokeOnce = async () => {
200
+ const controller = new AbortController();
201
+ let timedOut = false;
202
+ const timer = setTimeout(() => {
203
+ timedOut = true;
204
+ controller.abort();
205
+ }, timeoutMs);
206
+ try {
207
+ const message = await complete(
208
+ model,
209
+ {
210
+ systemPrompt: options?.system ?? "You are a disciplined memory curator. Output JSON only.",
211
+ messages: [{ role: "user", content: [{ type: "text", text: prompt }], timestamp: Date.now() }]
212
+ },
213
+ {
214
+ apiKey,
215
+ ...model.reasoning ? { reasoning: "low" } : {},
216
+ maxTokens: Math.min(model.maxTokens ?? 32768, 32768),
217
+ signal: controller.signal
218
+ }
219
+ );
220
+ if (timedOut) {
221
+ const err = new Error(`wiki model call (${model.provider}/${model.id}) timed out after ${timeoutMs}ms`);
222
+ err.noImmediateReplay = true;
223
+ throw err;
198
224
  }
199
- );
200
- if (timedOut) {
201
- const err = new Error(`wiki model call (${model.provider}/${model.id}) timed out after ${timeoutMs}ms`);
202
- err.noImmediateReplay = true;
203
- throw err;
204
- }
205
- if (message.stopReason && message.stopReason !== "stop") {
206
- const detail = typeof message.errorMessage === "string" && message.errorMessage.trim() ? `: ${message.errorMessage.trim()}` : "";
207
- const err = new Error(`wiki model call (${model.provider}/${model.id}) ended with stopReason=${message.stopReason}${detail}`);
208
- if (message.retryable === false || message.stopReason === "length") {
225
+ if (message.stopReason && message.stopReason !== "stop") {
226
+ const detail = typeof message.errorMessage === "string" && message.errorMessage.trim() ? `: ${message.errorMessage.trim()}` : "";
227
+ const err = new Error(`wiki model call (${model.provider}/${model.id}) ended with stopReason=${message.stopReason}${detail}`);
228
+ if (message.retryable === false || message.stopReason === "length") {
229
+ err.noImmediateReplay = true;
230
+ }
231
+ throw err;
232
+ }
233
+ return message.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
234
+ } catch (rawError) {
235
+ if (timedOut && !(rawError instanceof Error && rawError.message.includes("timed out after"))) {
236
+ const err = new Error(`wiki model call (${model.provider}/${model.id}) timed out after ${timeoutMs}ms`);
209
237
  err.noImmediateReplay = true;
238
+ throw err;
210
239
  }
211
- throw err;
240
+ throw rawError;
241
+ } finally {
242
+ clearTimeout(timer);
212
243
  }
213
- return message.content.filter((block) => block.type === "text").map((block) => block.text).join("\n");
214
- } catch (rawError) {
215
- if (timedOut && !(rawError instanceof Error && rawError.message.includes("timed out after"))) {
216
- const err = new Error(`wiki model call (${model.provider}/${model.id}) timed out after ${timeoutMs}ms`);
217
- err.noImmediateReplay = true;
218
- throw err;
244
+ };
245
+ try {
246
+ return await invokeOnce();
247
+ } catch (firstError) {
248
+ const msg = firstError instanceof Error ? firstError.message : String(firstError);
249
+ const noReplay = Boolean(firstError?.noImmediateReplay);
250
+ if (noReplay || !isTransientDistillError(msg) || msg.toLowerCase().includes("stopreason=length")) {
251
+ throw firstError;
219
252
  }
220
- throw rawError;
221
- } finally {
222
- clearTimeout(timer);
253
+ await new Promise((resolve2) => setTimeout(resolve2, hooks?.retryDelayMs ?? 1500));
254
+ return await invokeOnce();
223
255
  }
224
256
  };
225
- try {
226
- return await invokeOnce();
227
- } catch (firstError) {
228
- const msg = firstError instanceof Error ? firstError.message : String(firstError);
229
- const noReplay = Boolean(firstError?.noImmediateReplay);
230
- if (noReplay || !isTransientDistillError(msg) || msg.toLowerCase().includes("stopreason=length")) {
231
- throw firstError;
257
+ let lastError;
258
+ for (const target of targets) {
259
+ try {
260
+ return await runCandidate(target.model, target.apiKey);
261
+ } catch (err) {
262
+ lastError = err;
232
263
  }
233
- await new Promise((resolve2) => setTimeout(resolve2, hooks?.retryDelayMs ?? 1500));
234
- return await invokeOnce();
235
264
  }
265
+ throw lastError;
236
266
  };
237
267
  }
238
268
  function isWikiDreamResultRetryable(dreamRes) {
@@ -326,22 +356,23 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false, sessionsDi
326
356
  let result;
327
357
  let wikiForError;
328
358
  try {
329
- const { ModelRegistry } = await import("./model-registry-QNEPISBJ.js");
359
+ const { ModelRegistry } = await import("./model-registry-GLBIUOJR.js");
330
360
  const { AuthStorage } = await import("./auth-storage-IJEJ2TGE.js");
331
361
  const { getSessionsDir } = await import("./config-4EOI5NOU.js");
332
- const { FileSessionStore } = await import("./src-7MZZJVOG.js");
333
- const { WikiStore, runWikiBootstrap, runWikiDream, runWikiGc } = await import("./src-QI47K3W3.js");
334
- const { commitCuratedMemoryBestEffort } = await import("./memory-git-Q3UBYOJ4.js");
362
+ const { FileSessionStore } = await import("./src-KZ7YID3I.js");
363
+ const { WikiStore, runWikiBootstrap, runWikiDreamBatches, runWikiGc } = await import("./src-LEXKDSFV.js");
364
+ const { commitCuratedMemoryBestEffort } = await import("./memory-git-ZJN6SPIU.js");
335
365
  const wiki = new WikiStore(memoryRoot);
336
366
  wikiForError = wiki;
337
- if (wiki.hasDreamedDate(date)) {
367
+ const inboxOnly = date === "__inbox__";
368
+ if (!inboxOnly && wiki.hasDreamedDate(date)) {
338
369
  result = { ok: true, status: "skipped-ran" };
339
370
  } else {
340
371
  const registry = new ModelRegistry(AuthStorage.create());
341
372
  const cwdFilter = await createExcludeCwdFilter();
342
373
  const lightCall = createWikiModelCall(registry, "light", void 0, 12e4);
343
374
  const balancedCall = createWikiModelCall(registry, "balanced", void 0, 18e4);
344
- if (!wiki.exists() && hasLegacyMemorySeed(memoryRoot)) {
375
+ if (!inboxOnly && !wiki.exists() && hasLegacyMemorySeed(memoryRoot)) {
345
376
  const boot = await runWikiBootstrap({ memoryRoot, balancedCall });
346
377
  log(`[wiki] auto-bootstrap ok=${boot.ok} written=${boot.written.length}${boot.error ? ` error=${boot.error}` : ""}`);
347
378
  if (!boot.ok) {
@@ -358,18 +389,20 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false, sessionsDi
358
389
  }
359
390
  if (!result) {
360
391
  const resolvedSessionsDir = sessionsDir ? path.resolve(sessionsDir) : getSessionsDir();
361
- const dreamRes = await runWikiDream({
392
+ const dreamRes = await runWikiDreamBatches({
362
393
  sessionStore: new FileSessionStore(resolvedSessionsDir),
363
394
  memoryRoot,
364
- dates: [date],
395
+ dates: inboxOnly ? [] : [date],
365
396
  lightCall,
366
397
  balancedCall,
367
398
  cwdFilter,
368
399
  log
369
400
  });
370
- log(`[wiki] dream ${date}: ok=${dreamRes.ok} sessions=${dreamRes.sessionsHarvested} signals=${dreamRes.signalsAuthenticated} written=${dreamRes.written.length}${dreamRes.error ? ` error=${dreamRes.error}` : ""}`);
401
+ const batchNote = dreamRes.batchesRun > 1 ? ` batches=${dreamRes.batchesRun}` : "";
402
+ const inboxNote = dreamRes.inboxMerged ? ` inbox=${dreamRes.inboxMerged}` : "";
403
+ log(`[wiki] dream ${inboxOnly ? "inbox" : date}: ok=${dreamRes.ok} sessions=${dreamRes.sessionsHarvested} signals=${dreamRes.signalsAuthenticated} written=${dreamRes.written.length}${batchNote}${inboxNote}${dreamRes.error ? ` error=${dreamRes.error}` : ""}`);
371
404
  let gcWrote = false;
372
- if (wiki.exists()) {
405
+ if (!inboxOnly && wiki.exists()) {
373
406
  const meta = wiki.readMeta();
374
407
  const sevenDaysMs = 7 * 24 * 60 * 60 * 1e3;
375
408
  const atCapacityPressure = wiki.listActivePages().length >= 18;
@@ -381,16 +414,16 @@ async function runDistillWorkerMain(memoryRoot, date, noExit = false, sessionsDi
381
414
  }
382
415
  }
383
416
  if (dreamRes.written.length > 0 || dreamRes.archived.length > 0 || gcWrote) {
384
- commitCuratedMemoryBestEffort(memoryRoot, `wiki(dream): ${date}`);
417
+ commitCuratedMemoryBestEffort(memoryRoot, inboxOnly ? "wiki(inbox): merge attested saves" : `wiki(dream): ${date}`);
385
418
  }
386
419
  if (dreamRes.ok) {
387
- const status = dreamRes.sessionsHarvested === 0 ? "skipped-empty" : "applied";
420
+ const status = dreamRes.sessionsHarvested === 0 && !dreamRes.inboxMerged ? "skipped-empty" : "applied";
388
421
  result = { ok: true, status };
389
422
  } else {
390
423
  const err = dreamRes.error ?? "wiki dream failed";
391
424
  const retryable = isWikiDreamResultRetryable(dreamRes);
392
425
  try {
393
- wiki.recordDreamFailure(err, date);
426
+ wiki.recordDreamFailure(err, inboxOnly ? "inbox" : date);
394
427
  } catch {
395
428
  }
396
429
  result = { ok: false, status: "failed", error: err, retryable };
@@ -423,7 +456,7 @@ async function runDistillAuto(memoryRoot, days = 7, runner, sessionsDir) {
423
456
  } catch {
424
457
  }
425
458
  };
426
- const { WikiStore, todayKey } = await import("./src-QI47K3W3.js");
459
+ const { WikiStore, countWikiInbox, todayKey } = await import("./src-LEXKDSFV.js");
427
460
  const wiki = new WikiStore(memoryRoot);
428
461
  const today = todayKey(Date.now());
429
462
  const dates = [];
@@ -436,15 +469,17 @@ async function runDistillAuto(memoryRoot, days = 7, runner, sessionsDir) {
436
469
  dates.push(date);
437
470
  }
438
471
  }
439
- if (dates.length === 0) {
472
+ const pendingInbox = countWikiInbox(memoryRoot);
473
+ if (dates.length === 0 && pendingInbox === 0) {
440
474
  log("auto: no missing checkpoints in the window");
441
475
  return { ok: true, lines: ["memory --auto: no missing checkpoints in the last " + days + " days."] };
442
476
  }
443
- log(`auto: ${dates.length} missing date(s): ${dates.join(", ")}`);
477
+ const runTargets = dates.length > 0 ? dates : ["__inbox__"];
478
+ log(dates.length > 0 ? `auto: ${dates.length} missing date(s): ${dates.join(", ")}` : `auto: draining ${pendingInbox} pending inbox item(s)`);
444
479
  const lines = [];
445
480
  let failures = 0;
446
481
  let hasPermanentFailure = false;
447
- for (const date of dates) {
482
+ for (const date of runTargets) {
448
483
  const result = await (runner ?? runDistillWorkerMain)(memoryRoot, date, true, sessionsDir);
449
484
  if (!result.ok && result.busy) {
450
485
  lines.push(`${date}: busy \u2014 another distillation worker is running; next schedule retries`);
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  redactText
4
- } from "./chunk-AKC7NMP4.js";
4
+ } from "./chunk-EZZTMDWZ.js";
5
5
 
6
6
  // src/commands/memory-git.ts
7
7
  import { execFileSync } from "node:child_process";
@@ -14,6 +14,7 @@ var REQUIRED_IGNORE_RULES = [
14
14
  "evidence-ledger.json",
15
15
  ".gated-patches.json",
16
16
  ".snapshots/",
17
+ "inbox/",
17
18
  "wiki/.meta.json",
18
19
  "projects/*/meta.json",
19
20
  "*.lock",