@cydm/pie 3.0.0 → 4.0.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 (31) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +8 -4
  2. package/dist/builtin/extensions/cron/index.js +130 -21
  3. package/dist/builtin/extensions/im-forward/README.md +20 -5
  4. package/dist/builtin/extensions/im-forward/index.js +415 -142
  5. package/dist/builtin/extensions/memory/index.js +71 -20
  6. package/dist/builtin/extensions/pie-ipc/README.md +2 -2
  7. package/dist/builtin/extensions/pie-ipc/index.js +269 -30
  8. package/dist/builtin/extensions/pie-proc/README.md +93 -0
  9. package/dist/builtin/extensions/pie-proc/index.js +630 -0
  10. package/dist/builtin/extensions/pie-proc/package.json +11 -0
  11. package/dist/builtin/extensions/plan-mode/index.js +4 -4
  12. package/dist/builtin/extensions/subagent/index.js +5 -5
  13. package/dist/builtin/extensions/todo/index.js +4 -4
  14. package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +49 -0
  15. package/dist/chunks/{chunk-7FEPQHYX.js → chunk-FDLLNPIE.js} +143 -53
  16. package/dist/chunks/{chunk-3BC5KGDQ.js → chunk-JQRZLVPY.js} +12 -1
  17. package/dist/chunks/{chunk-GH4VW2OT.js → chunk-NCP264ZE.js} +8 -2
  18. package/dist/chunks/{chunk-YRR6C43W.js → chunk-QX6WS73C.js} +1 -1
  19. package/dist/chunks/{chunk-OEQYEYB3.js → chunk-TDKNKNPL.js} +5 -5
  20. package/dist/chunks/{chunk-BUDXV3TR.js → chunk-UOZHQ73X.js} +3 -3
  21. package/dist/chunks/{chunk-3FRKOFSP.js → chunk-WK4N5HT5.js} +32 -22
  22. package/dist/chunks/chunk-X6LBWHK3.js +37 -0
  23. package/dist/chunks/concierge-cli-PIOGXKDR.js +939 -0
  24. package/dist/chunks/{model-registry-LI5THXV4.js → model-registry-YA6U366L.js} +2 -2
  25. package/dist/chunks/{src-AE3OCAE6.js → src-AB7PLORG.js} +6 -4
  26. package/dist/chunks/{src-YG5M2H44.js → src-ODLT57PQ.js} +2 -2
  27. package/dist/chunks/{src-66XSMIAM.js → src-XSLD2IQ2.js} +1 -1
  28. package/dist/chunks/{src-RVTDUSPJ.js → src-ZZZO4HSR.js} +3 -3
  29. package/dist/chunks/{test-stream-JBWXKOQA.js → test-stream-GIUD5JWS.js} +1 -1
  30. package/dist/cli.js +962 -174
  31. package/package.json +105 -105
@@ -3,7 +3,7 @@ import {
3
3
  distillWorkerLogPath,
4
4
  readDistillWorkerLog,
5
5
  spawnDistillWorker
6
- } from "../../../chunks/chunk-OEQYEYB3.js";
6
+ } from "../../../chunks/chunk-TDKNKNPL.js";
7
7
  import {
8
8
  getConfigDir,
9
9
  getSettingsPath
@@ -12,16 +12,17 @@ import {
12
12
  DEFAULT_MEMORY_INJECTION_BUDGET,
13
13
  MemoryStore,
14
14
  consumptionSummary,
15
+ materialConsumedIn,
15
16
  projectKeyForDir,
16
17
  recordConsumption,
17
18
  recordInjection,
18
19
  saveAttestedEntry,
19
20
  searchMemory,
20
21
  todayKey
21
- } from "../../../chunks/chunk-7FEPQHYX.js";
22
- import "../../../chunks/chunk-3FRKOFSP.js";
23
- import "../../../chunks/chunk-GH4VW2OT.js";
24
- import "../../../chunks/chunk-3BC5KGDQ.js";
22
+ } from "../../../chunks/chunk-FDLLNPIE.js";
23
+ import "../../../chunks/chunk-WK4N5HT5.js";
24
+ import "../../../chunks/chunk-NCP264ZE.js";
25
+ import "../../../chunks/chunk-JQRZLVPY.js";
25
26
  import {
26
27
  Type
27
28
  } from "../../../chunks/chunk-XXGYUYXI.js";
@@ -108,15 +109,25 @@ function memoryExtension(ctx) {
108
109
  const project = projectKeyForDir(ctx.cwd);
109
110
  let activeSessionId = null;
110
111
  ctx.on("session:changed", (event) => {
111
- if (activeSessionId !== null && activeSessionId !== event.sessionId) {
112
+ const next = event.sessionId;
113
+ if (activeSessionId !== null && next === null) {
112
114
  sessionConsumedIds = /* @__PURE__ */ new Set();
115
+ turnInjectedIds = [];
113
116
  injectionMemo = null;
114
117
  pendingDistillHint = false;
115
- ctx.log(`[memory] session switch (${activeSessionId.slice(0, 8)} \u2192 ${event.sessionId.slice(0, 8)}): injection memo + consumption scope reset`);
118
+ ctx.log(`[memory] session unbound (${activeSessionId.slice(0, 8)} \u2192 none): injection memo + consumption scope reset`);
119
+ } else if (activeSessionId !== null && next !== null && activeSessionId !== next) {
120
+ sessionConsumedIds = /* @__PURE__ */ new Set();
121
+ turnInjectedIds = [];
122
+ injectionMemo = null;
123
+ pendingDistillHint = false;
124
+ ctx.log(`[memory] session switch (${activeSessionId.slice(0, 8)} \u2192 ${next.slice(0, 8)}): injection memo + consumption scope reset`);
116
125
  }
117
- activeSessionId = event.sessionId;
126
+ activeSessionId = next;
118
127
  });
119
128
  let injectionMemo = null;
129
+ let turnInjectedIds = [];
130
+ let turnSnapshots = [];
120
131
  let sessionConsumedIds = /* @__PURE__ */ new Set();
121
132
  let pendingDistillHint = false;
122
133
  const distillWatermark = () => Math.max(0, ...Object.values(store.loadState().runs).map((run) => run.ops > 0 ? run.ranAt : 0));
@@ -131,7 +142,11 @@ function memoryExtension(ctx) {
131
142
  ctx.log(`[memory] injection memo dropped (${reason})`);
132
143
  };
133
144
  ctx.on("agent:end", (event) => {
134
- if (injectionMemo === null || injectionMemo.injectedIds.length === 0) return;
145
+ const injectedIds = turnInjectedIds;
146
+ turnInjectedIds = [];
147
+ const snapshots = turnSnapshots;
148
+ turnSnapshots = [];
149
+ if (injectedIds.length === 0) return;
135
150
  try {
136
151
  const textOf = (message) => {
137
152
  if (typeof message.content === "string") return message.content;
@@ -141,9 +156,16 @@ function memoryExtension(ctx) {
141
156
  return "";
142
157
  };
143
158
  const output = event.messages.filter((message) => message.role === "assistant" || message.role === "toolResult").map(textOf).join("\n");
144
- const eligible = injectionMemo.injectedIds.filter((id) => !sessionConsumedIds.has(id));
159
+ const eligible = injectedIds.filter((id) => !sessionConsumedIds.has(id));
145
160
  if (eligible.length === 0) return;
146
- const { consumed } = recordConsumption(store, eligible, output);
161
+ const eligibleSnapshots = snapshots.filter((s) => eligible.includes(s.id));
162
+ const consumed = eligibleSnapshots.filter((s) => snapshotConsumedIn(s, output)).map((s) => s.id);
163
+ if (consumed.length > 0) {
164
+ try {
165
+ recordConsumption(store, consumed, output);
166
+ } catch {
167
+ }
168
+ }
147
169
  for (const id of consumed) sessionConsumedIds.add(id);
148
170
  if (consumed.length > 0) {
149
171
  ctx.log(`[memory] consumption credited: ${consumed.length} entr${consumed.length === 1 ? "y" : "ies"} this session`);
@@ -153,6 +175,7 @@ function memoryExtension(ctx) {
153
175
  }
154
176
  });
155
177
  ctx.on("before_agent_start", (event) => {
178
+ turnInjectedIds = [];
156
179
  try {
157
180
  const injectOn = readInjectSetting();
158
181
  ctx.ui.setStatus?.("memory", injectOn ? pendingDistillHint && injectionMemo !== null ? "[MEM*]" : "[MEM]" : void 0);
@@ -163,7 +186,8 @@ function memoryExtension(ctx) {
163
186
  injectionMemo = {
164
187
  text: built.text,
165
188
  watermark,
166
- injectedIds: built.injectedIds
189
+ injectedIds: built.injectedIds,
190
+ snapshots: built.snapshots
167
191
  };
168
192
  pendingDistillHint = false;
169
193
  try {
@@ -176,6 +200,8 @@ function memoryExtension(ctx) {
176
200
  ctx.ui.setStatus?.("memory", "[MEM*]");
177
201
  }
178
202
  if (!injectionMemo.text) return;
203
+ turnInjectedIds = [...injectionMemo.injectedIds];
204
+ turnSnapshots = injectionMemo.snapshots;
179
205
  return { systemPrompt: `${event.baseSystemPrompt}
180
206
 
181
207
  ${injectionMemo.text}` };
@@ -184,6 +210,7 @@ ${injectionMemo.text}` };
184
210
  return {};
185
211
  }
186
212
  });
213
+ const snapshotConsumedIn = (snapshot, output) => materialConsumedIn(snapshot.text, snapshot.quotes, output);
187
214
  ctx.registerTool({
188
215
  name: "memory_save",
189
216
  description: 'Explicitly save a durable memory. HIGHEST-PRIORITY RULE: when the user explicitly asks to remember something (e.g. "\u8BB0\u4F4F\u2026", "from now on\u2026", "always\u2026"), you MUST call this tool \u2014 never claim you will remember without a successful call. Supersedes conflicting entries of the same kind automatically. After success, confirm briefly (e.g. "\u5DF2\u8BB0\u4F4F\uFF1A\u2026"). If this tool is unavailable, say the request only holds for the current session.',
@@ -194,8 +221,8 @@ ${injectionMemo.text}` };
194
221
  Type.Literal("project"),
195
222
  Type.Literal("thread")
196
223
  ]),
197
- text: Type.String({ description: "The durable memory, <= 240 chars single line, in the user's dominant language", maxLength: 240 }),
198
- quote: Type.String({ description: "The user's verbatim phrasing that attests this memory, <= 240 chars", maxLength: 240, minLength: 1 })
224
+ text: Type.String({ description: "The durable memory, MAX 240 characters \u2014 write one compact line and count the length before sending; over-length calls are rejected. In the user's dominant language", maxLength: 240 }),
225
+ quote: Type.String({ description: "The user's verbatim phrasing that attests this memory, <= 240 chars \u2014 trim with an ellipsis if the source is longer", maxLength: 240, minLength: 1 })
199
226
  }),
200
227
  async execute(args) {
201
228
  const { ops, entryId } = saveAttestedEntry(store, {
@@ -274,8 +301,26 @@ function buildInjectionSectionWithIds(store, budget, projectKey) {
274
301
  const memory = take("memory", budget.memory);
275
302
  const threads = take("threads", budget.threads);
276
303
  const projectLines = projectKey ? take("project", budget.project, (entry) => entry.projectKey === projectKey) : [];
304
+ const soulRaw = store.readSoul();
305
+ let soulBudgetTokens = 0;
306
+ let soulText;
307
+ if (soulRaw) {
308
+ const candidate = soulRaw.slice(0, 2e3);
309
+ if (estimateTokens(candidate) <= budget.soul) {
310
+ soulText = candidate;
311
+ soulBudgetTokens = estimateTokens(candidate);
312
+ } else {
313
+ let fit = candidate;
314
+ while (fit.length > 0 && estimateTokens(fit) > budget.soul) {
315
+ const cut = fit.lastIndexOf("\n");
316
+ fit = cut > 0 ? fit.slice(0, cut) : fit.slice(0, Math.floor(fit.length / 2));
317
+ }
318
+ soulText = fit.length > 0 ? `${fit}
319
+ \u2026\uFF08\u4EBA\u683C\u622A\u65AD\uFF1ASOUL.md \u8D85\u51FA\u9884\u7B97\uFF0C\u5B8C\u6574\u7248\u8BF7\u7F16\u8F91 ~/.pie/memory/SOUL.md \u7F29\u77ED\uFF09` : void 0;
320
+ soulBudgetTokens = fit.length > 0 ? estimateTokens(fit) : 0;
321
+ }
322
+ }
277
323
  const recentDates = store.listJournalDates().slice(-3);
278
- let digestUsed = 0;
279
324
  const digest = [];
280
325
  for (const date of recentDates.reverse()) {
281
326
  const journal = store.readJournal(date);
@@ -287,10 +332,11 @@ function buildInjectionSectionWithIds(store, budget, projectKey) {
287
332
  digest.push(`- ${date}: ${snippet}`);
288
333
  digestUsed += cost;
289
334
  }
290
- if (user.length === 0 && memory.length === 0 && threads.length === 0 && projectLines.length === 0 && digest.length === 0) {
291
- return { text: "", injectedIds: [] };
335
+ if (user.length === 0 && memory.length === 0 && threads.length === 0 && projectLines.length === 0 && digest.length === 0 && !soulText) {
336
+ return { text: "", injectedIds: [], snapshots: [] };
292
337
  }
293
338
  const sections = [];
339
+ if (soulText) sections.push({ heading: "Soul (persona)", items: [{ line: soulText }] });
294
340
  if (user.length > 0) sections.push({ heading: "User (stable preferences)", items: user });
295
341
  if (projectLines.length > 0) sections.push({ heading: "This project", items: projectLines });
296
342
  if (memory.length > 0) sections.push({ heading: "Durable facts", items: memory });
@@ -303,9 +349,14 @@ function buildInjectionSectionWithIds(store, budget, projectKey) {
303
349
  const render = (list) => ["## Memory", "", ...list.flatMap((section) => [`### ${section.heading}`, ...section.items.map((item) => item.line), ""]), footer].join("\n").trim();
304
350
  while (sections.length > 0) {
305
351
  const rendered = render(sections);
306
- if (estimateTokens(rendered) <= ceiling) {
352
+ if (estimateTokens(rendered) <= ceiling + soulBudgetTokens) {
307
353
  const injectedIds = sections.flatMap((section) => section.items.map((item) => item.id).filter((id) => id !== void 0));
308
- return { text: rendered, injectedIds };
354
+ const byId = new Map(entries.map((entry) => [entry.id, entry]));
355
+ const snapshots = injectedIds.map((id) => {
356
+ const entry = byId.get(id);
357
+ return { id, text: entry?.text ?? "", quotes: entry?.evidence.map((ev) => ev.quote) ?? [] };
358
+ });
359
+ return { text: rendered, injectedIds, snapshots };
309
360
  }
310
361
  const last = sections[sections.length - 1];
311
362
  if (last.items.length > 0) {
@@ -315,7 +366,7 @@ function buildInjectionSectionWithIds(store, budget, projectKey) {
315
366
  sections.pop();
316
367
  }
317
368
  }
318
- return { text: "", injectedIds: [] };
369
+ return { text: "", injectedIds: [], snapshots: [] };
319
370
  }
320
371
  function memoryOverview(store) {
321
372
  const entries = store.loadEntries();
@@ -12,10 +12,10 @@ No configuration is required. By default IPC trusts authenticated local clients
12
12
  }
13
13
  ```
14
14
 
15
- Absent `allowPeers` defaults to `["*"]`, trusting authenticated local clients; an explicit empty array **denies** messages and bodies. `/tools/ipc allow <instance-id>` approves one peer for this runtime. `autoInject` defaults to `true`; set it to `false` for inbox + poll delivery. Unreadable config files disable IPC rather than selecting these defaults. Same-user processes are trusted, not isolated. Auto-injection is interactive-only; headless clients can send and wait without advertising.
15
+ Absent `allowPeers` defaults to `["*"]`, trusting authenticated local clients; an explicit empty array **denies** messages and bodies. `/tools/ipc allow <instance-id>` approves one peer for this runtime. `autoInject` defaults to `true`; set it to `false` for inbox + poll delivery. Unreadable config files disable IPC rather than selecting these defaults. Same-user processes are trusted, not isolated. Auto-injection works on interactive TUI hosts AND long-lived embedded hosts (json-events residents): since S1 the resident's sendUserMessage is real controller-queue intake, so injected messages queue as genuine follow-up turns. One-shot headless (`pie -p`) clients can send and wait without advertising but are never injected.
16
16
 
17
17
  Use `/tools/ipc peers`, `/tools/ipc status <peer>`, `/tools/ipc send <peer> <text>`, `/tools/ipc result <peer> [requestId]`, `/tools/ipc poll`, `/tools/ipc name`, `/tools/ipc mute [off]`, and `/tools/ipc allow <id|*>`. Only explicit `/tools/ipc poll` submits command output to the model; other commands notify the user. Changes from commands are ephemeral.
18
18
 
19
- Tools: `ipc_list_peers`, `ipc_status`, `ipc_send`, `ipc_result`, `ipc_poll`. Every send exposes a requestId. Non-waiting requests can be polled with `ipc_result` through accepted/running/done or failed; omitting requestId lists recent results. Reads do not consume results. Results are session-scoped, bounded, retained in memory only, and unknown after eviction/restart. A receipt is not a result: waited results use the original authenticated socket after input consumption and execution settlement. Queued/muted input never receives unrelated turn output. Delivery is bounded, best-effort, not durable; uncertain busy followups are never automatically duplicated. Restart every peer after protocol changes; there is no compatibility layer. Windows uses native HANDLE-based ACL verification and atomic protected directory and temporary-file creation. Ancestors with public add-file/write-data, write-attributes, write-EA, delete or control grants are rejected (including standard ProgramData when it has these rights). No-delete handles prevent rename/delete; ACL checks, not a reparse lock, exclude untrusted in-place mutation. Unsafe profile/TEMP/drive ancestry fails closed without repair or insecure fallback; use an explicitly provisioned safe `PIE_IPC_CONFIG_DIR` if needed. Same-user isolation and the stale-advertisement/first-send unencrypted endpoint-identity limitation remain outside this guarantee; see the release checklist below.
19
+ Tools: `ipc_list_peers`, `ipc_status`, `ipc_send_notify`, `ipc_result`, `ipc_poll`. Every send exposes a requestId. `ipc_send_notify` — the name is the contract: sending subscribes to completion by DEFAULT (returns after the receipt ack; the peer pushes one `[ipc-done]` message with outcome + bounded answer when its turn settles). On interactive AND embedded resident hosts it is injected (single wake — both are editorInjection hosts); on one-shot headless clients it lands in the pollable inbox with an informational `[ipc-done-check]` hint. A local fallback timer (`fallbackMs`) wakes a result check if no push arrives. Explicit `notify:false` opts out to fire-and-forget (no wake, receipt unconfirmed). Non-waiting requests can be polled with `ipc_result` through accepted/running/done or failed; omitting requestId lists recent results. Reads do not consume results. Results are session-scoped, bounded, retained in memory only, and unknown after eviction/restart. A receipt is not a result: waited results use the original authenticated socket after input consumption and execution settlement. Queued/muted input never receives unrelated turn output. Delivery is bounded, best-effort, not durable; uncertain busy followups are never automatically duplicated. Restart every peer after protocol changes; there is no compatibility layer. Windows uses native HANDLE-based ACL verification and atomic protected directory and temporary-file creation. Ancestors with public add-file/write-data, write-attributes, write-EA, delete or control grants are rejected (including standard ProgramData when it has these rights). No-delete handles prevent rename/delete; ACL checks, not a reparse lock, exclude untrusted in-place mutation. Unsafe profile/TEMP/drive ancestry fails closed without repair or insecure fallback; use an explicitly provisioned safe `PIE_IPC_CONFIG_DIR` if needed. Same-user isolation and the stale-advertisement/first-send unencrypted endpoint-identity limitation remain outside this guarantee; see the release checklist below.
20
20
 
21
21
  See [the complete contract](../../../../../docs/pie-ipc.md) for configuration, HMAC/permissions, snapshot freshness, limits, recovery limitations, and reproducible tests including a checked-in two-process factory dogfood driver.