@cydm/pie 4.3.12 → 4.4.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 (41) hide show
  1. package/dist/builtin/extensions/ask-user/index.js +6 -6
  2. package/dist/builtin/extensions/changelog/index.js +1 -1
  3. package/dist/builtin/extensions/cron/index.js +2 -2
  4. package/dist/builtin/extensions/document-attachments/index.js +1 -1
  5. package/dist/builtin/extensions/herdr-agent-state/index.js +1 -1
  6. package/dist/builtin/extensions/im-forward/README.md +15 -2
  7. package/dist/builtin/extensions/im-forward/index.js +95 -7
  8. package/dist/builtin/extensions/init/index.js +1 -1
  9. package/dist/builtin/extensions/mcp-adapter/index.js +2 -2
  10. package/dist/builtin/extensions/memory/index.js +11 -9
  11. package/dist/builtin/extensions/pie-ipc/index.js +6 -4
  12. package/dist/builtin/extensions/pie-proc/index.js +70 -7
  13. package/dist/builtin/extensions/plan-mode/index.js +6 -6
  14. package/dist/builtin/extensions/subagent/index.js +11 -9
  15. package/dist/builtin/extensions/todo/index.js +6 -6
  16. package/dist/builtin/skills/computer-use-axi/computer-use-axi-broker.js +1 -1
  17. package/dist/builtin/skills/computer-use-axi/computer-use-axi-runtime.js +1 -1
  18. package/dist/chunks/{auth-storage-3EGM3VTK.js → auth-storage-RABPRJ6T.js} +3 -3
  19. package/dist/chunks/chunk-7KLWHWZD.js +164 -0
  20. package/dist/chunks/{chunk-I7PBXG5Q.js → chunk-7LTQLJJF.js} +9 -6
  21. package/dist/chunks/{chunk-EGNGHINP.js → chunk-AKXEZH7K.js} +6 -1
  22. package/dist/chunks/{chunk-XXGYUYXI.js → chunk-BPSCGGVF.js} +1 -1
  23. package/dist/chunks/{chunk-VHKMWOG3.js → chunk-EQOI6RZV.js} +5 -3
  24. package/dist/chunks/{chunk-B4N5LJMD.js → chunk-IPLMGAML.js} +1 -1
  25. package/dist/chunks/{chunk-GY47MKCJ.js → chunk-IZDNZW3S.js} +8 -8
  26. package/dist/chunks/{chunk-6DNYGVZP.js → chunk-OV7SLSHR.js} +4 -2
  27. package/dist/chunks/{chunk-6JEYRAQM.js → chunk-R7VO46EK.js} +2 -2
  28. package/dist/chunks/{chunk-LZQXQOPJ.js → chunk-RZGYXAJU.js} +12 -1
  29. package/dist/chunks/{chunk-ILUHTKF3.js → chunk-UCKOXAME.js} +61 -11
  30. package/dist/chunks/{chunk-XMOWWL4B.js → chunk-XO3NM7BB.js} +3 -3
  31. package/dist/chunks/{chunk-N5B5IGJ6.js → chunk-YNTIOWCD.js} +5 -5
  32. package/dist/chunks/{config-74AUVDLT.js → config-HF2PDLN5.js} +8 -4
  33. package/dist/chunks/{manager-cli-4Z6RZ7F4.js → manager-cli-BYCF4RKN.js} +5 -3
  34. package/dist/chunks/{model-registry-NKE3BRSZ.js → model-registry-7FNIUYPF.js} +5 -5
  35. package/dist/chunks/{src-V2M7FLWY.js → src-A5YI46OD.js} +6 -6
  36. package/dist/chunks/{src-4EQ7PBEI.js → src-OA3TP6DS.js} +5 -5
  37. package/dist/chunks/{src-46R5ZFOU.js → src-OVWRBWKU.js} +4 -4
  38. package/dist/chunks/{src-BHIH4VLE.js → src-TF2RAGRU.js} +3 -3
  39. package/dist/chunks/{test-stream-FC6ZRENI.js → test-stream-7YZDGBPO.js} +3 -3
  40. package/dist/cli.js +231 -49
  41. package/package.json +2 -2
@@ -1,12 +1,12 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  createAskUserCapability
4
- } from "../../../chunks/chunk-N5B5IGJ6.js";
5
- import "../../../chunks/chunk-XMOWWL4B.js";
6
- import "../../../chunks/chunk-B4N5LJMD.js";
7
- import "../../../chunks/chunk-6JEYRAQM.js";
8
- import "../../../chunks/chunk-XXGYUYXI.js";
9
- import "../../../chunks/chunk-LZQXQOPJ.js";
4
+ } from "../../../chunks/chunk-YNTIOWCD.js";
5
+ import "../../../chunks/chunk-XO3NM7BB.js";
6
+ import "../../../chunks/chunk-IPLMGAML.js";
7
+ import "../../../chunks/chunk-R7VO46EK.js";
8
+ import "../../../chunks/chunk-BPSCGGVF.js";
9
+ import "../../../chunks/chunk-RZGYXAJU.js";
10
10
 
11
11
  // builtin/extensions/ask-user/index.ts
12
12
  function askUserExtension(ctx) {
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- import "../../../chunks/chunk-LZQXQOPJ.js";
2
+ import "../../../chunks/chunk-RZGYXAJU.js";
3
3
 
4
4
  // builtin/extensions/changelog/index.ts
5
5
  import * as fs from "node:fs";
@@ -1,8 +1,8 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  Type
4
- } from "../../../chunks/chunk-XXGYUYXI.js";
5
- import "../../../chunks/chunk-LZQXQOPJ.js";
4
+ } from "../../../chunks/chunk-BPSCGGVF.js";
5
+ import "../../../chunks/chunk-RZGYXAJU.js";
6
6
 
7
7
  // builtin/extensions/cron/index.ts
8
8
  import * as path4 from "node:path";
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- import "../../../chunks/chunk-LZQXQOPJ.js";
2
+ import "../../../chunks/chunk-RZGYXAJU.js";
3
3
 
4
4
  // builtin/extensions/document-attachments/index.ts
5
5
  import * as fs from "node:fs";
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- import "../../../chunks/chunk-LZQXQOPJ.js";
2
+ import "../../../chunks/chunk-RZGYXAJU.js";
3
3
 
4
4
  // builtin/extensions/herdr-agent-state/index.ts
5
5
  import { spawn } from "node:child_process";
@@ -69,8 +69,9 @@ are read as implicit Feishu settings. Unknown explicit providers never fall back
69
69
  Provider settings merge only within the same provider, with project precedence.
70
70
 
71
71
  The footer shows `[IM…]` while starting, `[IM]` only after the consumer's ready
72
- marker, `[IM!]` on configuration/connection failure, `[IM-DEGRADED:bus]`
73
- when the last recognized bus SDK state is disconnected beyond a ten-minute
72
+ marker, `[IM!]` on configuration/connection failure, `[IM↓]` (logged
73
+ and reported by `/tools/im-forward status` with the specific cause, `bus`
74
+ or `dispatch`) when the last recognized bus SDK state is disconnected beyond a ten-minute
74
75
  reconnect grace, and nothing when off. A five-minute probe reads a bounded
75
76
  log tail using host-local timestamps; unknown/unavailable evidence preserves
76
77
  an existing warning. Only a recognized reconnect clears it. This is passive
@@ -80,6 +81,18 @@ lark-cli daemon automatically; the warning gives the operator the explicit
80
81
  `event stop --force` recovery command. Optional card/menu consumers respawn
81
82
  on bounded backoff, reset only at their ready marker; dead children are removed.
82
83
 
84
+ On a machine where a resident holds the consumer slot, non-holder runtimes
85
+ operate in dispatch mode: they never spawn a consumer and receive events over
86
+ pie-ipc. For such runtimes the tag answers a delivery question, not a
87
+ lifecycle one: `[IM]` while dispatch mode is the working configuration (the
88
+ holder is alive and sorting), `[IM↓]` (cause `dispatch`) when the holder
89
+ heartbeat stays fresh yet nothing has been dispatched here past a ten-minute
90
+ grace window, and `[IM…]` only while the runtime is genuinely starting or
91
+ waiting to claim. A dispatched event restores `[IM]` immediately. Losing the
92
+ holder (restart churn) never shows degraded — no delivery evidence plus no
93
+ holder is not a failure signal. `/tools/im-forward status` prints the holder
94
+ identity and the last dispatched event time in dispatch mode.
95
+
83
96
  Registered panel cards can bypass metadata/claim/scope IO only AFTER all
84
97
  conversation/sender policies pass. Card ownership is session-and-epoch bound;
85
98
  pending send/patch completions never reassign the card after a session switch.
@@ -11,6 +11,7 @@ import {
11
11
  composeForwardBody,
12
12
  configSnapshot,
13
13
  configurationIdentity,
14
+ currentConsumer,
14
15
  estimatePostRequestBytes,
15
16
  failureReason,
16
17
  hasConfigLayers,
@@ -30,12 +31,12 @@ import {
30
31
  truncateMarkdown,
31
32
  tryClaimConsumer,
32
33
  writeConfig
33
- } from "../../../chunks/chunk-EGNGHINP.js";
34
+ } from "../../../chunks/chunk-AKXEZH7K.js";
34
35
  import {
35
36
  detectImageMime,
36
37
  readImageFormat
37
38
  } from "../../../chunks/chunk-F7EBZTZO.js";
38
- import "../../../chunks/chunk-LZQXQOPJ.js";
39
+ import "../../../chunks/chunk-RZGYXAJU.js";
39
40
 
40
41
  // builtin/extensions/im-forward/runtime.ts
41
42
  import * as crypto from "node:crypto";
@@ -825,12 +826,43 @@ function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
825
826
  return forwardingEnabled;
826
827
  }
827
828
  const STATUS_KEY = "im-forward";
829
+ let dispatchMode = false;
830
+ let lastDispatchReceivedAt;
831
+ const holderAlive = () => {
832
+ if (consumerLock) return true;
833
+ try {
834
+ return currentConsumer(bindingKey()).alive;
835
+ } catch {
836
+ return false;
837
+ }
838
+ };
839
+ const degradedTag = (cause) => {
840
+ ctx.log(`im-forward: footer degraded (${cause})`);
841
+ return "[IM\u2193]";
842
+ };
828
843
  function updateFooterTag() {
829
844
  ctx.ui.setStatus?.(
830
845
  STATUS_KEY,
831
- configurationFailed ? "[IM!]" : forwardingEnabled ? consumerLastExit ? "[IM!]" : busStale ? "[IM-DEGRADED:bus]" : consumerReady ? "[IM]" : "[IM\u2026]" : void 0
846
+ configurationFailed ? "[IM!]" : forwardingEnabled ? consumerLastExit ? "[IM!]" : busStale ? degradedTag("bus") : consumerReady ? "[IM]" : dispatchMode ? dispatchStale() ? degradedTag("dispatch") : "[IM]" : "[IM\u2026]" : void 0
832
847
  );
833
848
  }
849
+ const DISPATCH_GRACE_MS = 10 * 6e4;
850
+ let dispatchStaleWarned = false;
851
+ let dispatchModeEnteredAt;
852
+ const dispatchStale = () => {
853
+ if (!dispatchMode) return false;
854
+ const anchor = Math.max(lastDispatchReceivedAt ?? 0, dispatchModeEnteredAt ?? 0);
855
+ if (anchor && Date.now() - anchor < DISPATCH_GRACE_MS) return false;
856
+ return holderAlive();
857
+ };
858
+ const noteDispatchReceived = () => {
859
+ lastDispatchReceivedAt = Date.now();
860
+ if (dispatchStaleWarned) {
861
+ dispatchStaleWarned = false;
862
+ ctx.log("im-forward: dispatched events flowing again");
863
+ }
864
+ updateFooterTag();
865
+ };
834
866
  let busStale = false;
835
867
  const probeBusHealth = async () => {
836
868
  if (terminated || !connection.consumeBusHealth) return;
@@ -848,6 +880,14 @@ function createRuntime(ctx, cfg, connection, liveEnabled, persistEnabled) {
848
880
  }
849
881
  } catch {
850
882
  }
883
+ if (dispatchMode) {
884
+ const stale = dispatchStale();
885
+ if (stale && !dispatchStaleWarned) {
886
+ dispatchStaleWarned = true;
887
+ ctx.log("im-forward: consumer holder alive but no dispatched events received past grace window");
888
+ }
889
+ updateFooterTag();
890
+ }
851
891
  };
852
892
  function writeEnabledToConfig(next) {
853
893
  persistEnabled(next);
@@ -1183,7 +1223,11 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
1183
1223
  attribution?.replyTo,
1184
1224
  attribution,
1185
1225
  deliver
1186
- ).catch(() => void 0);
1226
+ ).then((delivered) => {
1227
+ if (delivered === true && attribution?.replyTo && connection.react) {
1228
+ providerCall("react", () => connection.react(attribution.replyTo, "CheckMark")).catch(() => void 0);
1229
+ }
1230
+ }).catch(() => void 0);
1187
1231
  });
1188
1232
  ctx.on("turn:failed", (event) => {
1189
1233
  if (!isForwardingEnabled()) return;
@@ -1194,8 +1238,10 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
1194
1238
  const attribution = resolveOutboundAttribution(sessionId);
1195
1239
  const deliverTf = /* @__PURE__ */ new Map();
1196
1240
  if (!outboundRoleAllows(attribution, deliverTf)) return;
1241
+ const recoveryHint = `\u8F93\u5165\u4ECD\u5728\u4F1A\u8BDD\u4E2D\uFF0C\u56DE\u590D\u201C\u91CD\u7B54\u4E0A\u4E00\u6761\u201D\u5373\u53EF\u57FA\u4E8E\u5B83\u91CD\u65B0\u4F5C\u7B54\uFF0C\u65E0\u9700\u91CD\u53D1\u539F\u59CB\u8BF7\u6C42\u3002`;
1197
1242
  void forwardMessage(
1198
- `\u26A0\uFE0F \u4EFB\u52A1\u5931\u8D25\uFF1A${reason}`,
1243
+ `\u26A0\uFE0F \u4EFB\u52A1\u5931\u8D25\uFF1A${reason}\uFF08\u91CD\u8BD5\u5DF2\u7528\u5C3D\uFF09
1244
+ ${recoveryHint}`,
1199
1245
  sessionId,
1200
1246
  sequence,
1201
1247
  attribution?.caption,
@@ -1488,8 +1534,10 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
1488
1534
  anchor
1489
1535
  )
1490
1536
  );
1537
+ return false;
1491
1538
  }
1492
1539
  }
1540
+ return true;
1493
1541
  }
1494
1542
  const sentAnchors = /* @__PURE__ */ new Set();
1495
1543
  function registerRoute(sent, sessionId) {
@@ -1533,6 +1581,7 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
1533
1581
  try {
1534
1582
  const parsed = JSON.parse(trimmed.slice(DISPATCH_PREFIX.length).trim());
1535
1583
  if (!parsed.event) return false;
1584
+ if (dispatchMode) noteDispatchReceived();
1536
1585
  void handleInboundEvent(parsed.event);
1537
1586
  return true;
1538
1587
  } catch {
@@ -2106,7 +2155,12 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
2106
2155
  function acquireClaimedSlot(binding) {
2107
2156
  if (consumerLock) return true;
2108
2157
  if (!isManager && residentAliveSomewhere()) {
2109
- ctx.log("im-forward: a live resident owns the feed class; standing down (dispatch mode)");
2158
+ if (!dispatchMode) {
2159
+ dispatchMode = true;
2160
+ dispatchModeEnteredAt = Date.now();
2161
+ ctx.log("im-forward: a live resident owns the feed class; standing down (dispatch mode)");
2162
+ updateFooterTag();
2163
+ }
2110
2164
  return false;
2111
2165
  }
2112
2166
  const claim = tryClaimConsumer(
@@ -2132,9 +2186,20 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
2132
2186
  isManager ? void 0 : () => residentAliveSomewhere()
2133
2187
  );
2134
2188
  if (!claim) {
2135
- ctx.log("im-forward: another consumer owns the event-hub slot; dispatch mode");
2189
+ if (!dispatchMode) {
2190
+ dispatchMode = true;
2191
+ dispatchModeEnteredAt = Date.now();
2192
+ ctx.log("im-forward: another consumer owns the event-hub slot; dispatch mode");
2193
+ updateFooterTag();
2194
+ }
2136
2195
  return false;
2137
2196
  }
2197
+ if (dispatchMode) {
2198
+ dispatchMode = false;
2199
+ dispatchModeEnteredAt = void 0;
2200
+ ctx.log("im-forward: consumer slot acquired; leaving dispatch mode");
2201
+ updateFooterTag();
2202
+ }
2138
2203
  consumerLock = claim;
2139
2204
  return true;
2140
2205
  }
@@ -2294,10 +2359,15 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
2294
2359
  }, 5 * 60 * 1e3);
2295
2360
  busHealthTimer.unref?.();
2296
2361
  void probeBusHealth();
2362
+ const dispatchTagTimer = setInterval(() => {
2363
+ if (dispatchMode) updateFooterTag();
2364
+ }, 3e4);
2365
+ dispatchTagTimer.unref?.();
2297
2366
  ctx.registerCleanup?.(async () => {
2298
2367
  inputEpoch++;
2299
2368
  terminated = true;
2300
2369
  clearInterval(busHealthTimer);
2370
+ clearInterval(dispatchTagTimer);
2301
2371
  registerDispatchReceiver(void 0);
2302
2372
  registerTurnImDriver(void 0);
2303
2373
  consumerLock?.release();
@@ -2333,6 +2403,17 @@ ${caption || IM_INPUT_FALLBACK_CAPTION}`;
2333
2403
  ...cfg.appId ? [`- app: ${cfg.appId}`] : [],
2334
2404
  `- allowed senders: ${cfg.allowUsers?.join(", ") ?? "(anyone in target)"}`,
2335
2405
  `- consumer: ${terminated ? "stopped" : consumer ? consumerReady ? "ready" : "starting" : "idle (waits for first session)"}${consumerLastExit ? ` (last exit: ${consumerLastExit})` : ""}, restarts=${consumerRestarts}`,
2406
+ ...dispatchMode ? [
2407
+ `- dispatch mode: resident holds the feed (holder ${(() => {
2408
+ try {
2409
+ const c = currentConsumer(bindingKey());
2410
+ return c.info ? `${c.info.holder} pid=${c.info.pid} ${c.alive ? "alive" : "STALE"}` : "(no lock file)";
2411
+ } catch {
2412
+ return "(unreadable)";
2413
+ }
2414
+ })()}); this runtime receives events over pie-ipc`,
2415
+ `- last dispatched event: ${lastDispatchReceivedAt ? new Date(lastDispatchReceivedAt).toISOString() : "(none since start)"}${dispatchStale() ? " \u2014 STALE past grace window" : ""}`
2416
+ ] : [],
2336
2417
  `- routes: ${routes.size} forwarded message(s) routable (${threadRoutes.size} thread(s), ${replyAnchor.size} anchor(s))`,
2337
2418
  `- current session: ${currentSessionId ?? "(none)"}`
2338
2419
  ];
@@ -3581,6 +3662,13 @@ function connect(binary, profile, targetKind = "chat", settings = { targetId: ""
3581
3662
  async acknowledge(id) {
3582
3663
  await call(["im", "reactions", "create", "--as", "bot", "--params", JSON.stringify({ message_id: id }), "--data", JSON.stringify({ reaction_type: { emoji_type: "THUMBSUP" } })]);
3583
3664
  },
3665
+ // 4.4.1 turn-settled reaction (dogfood ask: "结束☑️就好"). Feishu's
3666
+ // official emoji_type table lists "CheckMark" for ✔ (verified against
3667
+ // the larksuite/cli reactions reference — OnCheck/WHITE_CHECK_MARK do
3668
+ // NOT exist and the API rejects them).
3669
+ async react(id, emoji) {
3670
+ await call(["im", "reactions", "create", "--as", "bot", "--params", JSON.stringify({ message_id: id }), "--data", JSON.stringify({ reaction_type: { emoji_type: emoji } })]);
3671
+ },
3584
3672
  async metadata(id) {
3585
3673
  const data = await call(["im", "+messages-mget", "--as", "bot", "--message-ids", id]);
3586
3674
  const message = Array.isArray(data?.messages) ? data.messages[0] : void 0;
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from "node:module"; const require =
2
2
  import {
3
3
  resolveCliProjectRoot
4
4
  } from "../../../chunks/chunk-WLFOBECN.js";
5
- import "../../../chunks/chunk-LZQXQOPJ.js";
5
+ import "../../../chunks/chunk-RZGYXAJU.js";
6
6
 
7
7
  // builtin/extensions/init/index.ts
8
8
  import fs from "node:fs";
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  Type
4
- } from "../../../chunks/chunk-XXGYUYXI.js";
4
+ } from "../../../chunks/chunk-BPSCGGVF.js";
5
5
  import {
6
6
  __commonJS,
7
7
  __export,
8
8
  __require,
9
9
  __toESM
10
- } from "../../../chunks/chunk-LZQXQOPJ.js";
10
+ } from "../../../chunks/chunk-RZGYXAJU.js";
11
11
 
12
12
  // ../../node_modules/isexe/windows.js
13
13
  var require_windows = __commonJS({
@@ -3,11 +3,12 @@ import {
3
3
  distillWorkerLogPath,
4
4
  readDistillWorkerLog,
5
5
  spawnDistillWorker
6
- } from "../../../chunks/chunk-GY47MKCJ.js";
6
+ } from "../../../chunks/chunk-IZDNZW3S.js";
7
7
  import {
8
8
  getConfigDir,
9
- getSettingsPath
10
- } from "../../../chunks/chunk-ILUHTKF3.js";
9
+ getSettingsPath,
10
+ init_config
11
+ } from "../../../chunks/chunk-UCKOXAME.js";
11
12
  import {
12
13
  DEFAULT_MEMORY_INJECTION_BUDGET,
13
14
  MemoryStore,
@@ -19,18 +20,19 @@ import {
19
20
  saveAttestedEntry,
20
21
  searchMemory,
21
22
  todayKey
22
- } from "../../../chunks/chunk-N5B5IGJ6.js";
23
- import "../../../chunks/chunk-XMOWWL4B.js";
24
- import "../../../chunks/chunk-B4N5LJMD.js";
25
- import "../../../chunks/chunk-6JEYRAQM.js";
23
+ } from "../../../chunks/chunk-YNTIOWCD.js";
24
+ import "../../../chunks/chunk-XO3NM7BB.js";
25
+ import "../../../chunks/chunk-IPLMGAML.js";
26
+ import "../../../chunks/chunk-R7VO46EK.js";
26
27
  import {
27
28
  Type
28
- } from "../../../chunks/chunk-XXGYUYXI.js";
29
- import "../../../chunks/chunk-LZQXQOPJ.js";
29
+ } from "../../../chunks/chunk-BPSCGGVF.js";
30
+ import "../../../chunks/chunk-RZGYXAJU.js";
30
31
 
31
32
  // builtin/extensions/memory/index.ts
32
33
  import * as fs from "node:fs";
33
34
  import * as path from "node:path";
35
+ init_config();
34
36
  function yesterdayKey() {
35
37
  const probe = /* @__PURE__ */ new Date();
36
38
  probe.setDate(probe.getDate() - 1);
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  Type
4
- } from "../../../chunks/chunk-XXGYUYXI.js";
4
+ } from "../../../chunks/chunk-BPSCGGVF.js";
5
5
  import {
6
6
  DEFAULT_SEND_WAIT_MS,
7
7
  DISPATCH_PREFIX,
@@ -26,8 +26,8 @@ import {
26
26
  takeDispatchFrame,
27
27
  wrapInboundText,
28
28
  wrappedMessageMarker
29
- } from "../../../chunks/chunk-EGNGHINP.js";
30
- import "../../../chunks/chunk-LZQXQOPJ.js";
29
+ } from "../../../chunks/chunk-AKXEZH7K.js";
30
+ import "../../../chunks/chunk-RZGYXAJU.js";
31
31
 
32
32
  // builtin/extensions/pie-ipc/index.ts
33
33
  import * as fs3 from "node:fs";
@@ -1894,7 +1894,9 @@ function pieIpcExtension(ctx) {
1894
1894
  ctx.registerTool({
1895
1895
  name: "ipc_send_notify",
1896
1896
  label: "Send a message to a Pie peer and get notified when it finishes",
1897
- description: `Send text to another Pie process (interactive peer) and SUBSCRIBE to its completion \u2014 the name is the contract: fire-and-forget sending requires an explicit notify:false. Default behavior: returns right after the receipt ack with a requestId; when the peer's turn settles (success, failure, or cancellation) it pushes one [ipc-done] notification as inbound input, and a local fallback timer (fallbackMs, default 600000ms) wakes a result check if that push is lost \u2014 you will be called back, do not poll in a loop and never resend while a result is pending. wait=true: hold the tool call open instead (bounded by waitMs) \u2014 one-shot hosts only. notify:false: explicit fire-and-forget (return after socket submission; receipt/consumption not confirmed; no wake). Inbound messages from peers arrive as user input or in ipc_poll.`,
1897
+ description: `Send text to another Pie process (interactive peer) and SUBSCRIBE to its completion \u2014 the name is the contract: fire-and-forget sending requires an explicit notify:false. Default behavior: returns right after the receipt ack with a requestId; when the peer's turn settles (success, failure, or cancellation) it pushes one [ipc-done] notification as inbound input, and a local fallback timer (fallbackMs, default 600000ms) wakes a result check if that push is lost \u2014 you will be called back, do not poll in a loop and never resend while a result is pending. wait=true: hold the tool call open instead (bounded by waitMs) \u2014 one-shot hosts only. notify:false: explicit fire-and-forget (return after socket submission; receipt/consumption not confirmed; no wake). Inbound messages from peers arrive as user input or in ipc_poll.
1898
+
1899
+ SIDE EFFECT: this is NOT a read-only query. The text is injected into the peer's conversation as a user input and triggers one full model turn on the peer (cost + side effects there). If the user only asked you to observe (\u770B\u770B/\u67E5\u67E5/\u4E86\u89E3\u4E00\u4E0B a peer), do NOT use this tool: read ipc_list_peers/ipc_status or the peer's session files instead. Use this tool to dispatch work or ask a peer only when the user explicitly authorized contacting that peer.`,
1898
1900
  parameters: Type.Object({
1899
1901
  to: Type.String({ description: "Peer display name or instance id (see ipc_list_peers)" }),
1900
1902
  text: Type.String({ description: "Message body for the peer" }),
@@ -2,10 +2,14 @@ import { createRequire as __createRequire } from "node:module"; const require =
2
2
  import {
3
3
  readProcessCommandLine
4
4
  } from "../../../chunks/chunk-X6LBWHK3.js";
5
+ import {
6
+ liveSessionHolder
7
+ } from "../../../chunks/chunk-7KLWHWZD.js";
8
+ import "../../../chunks/chunk-UCKOXAME.js";
5
9
  import {
6
10
  Type
7
- } from "../../../chunks/chunk-XXGYUYXI.js";
8
- import "../../../chunks/chunk-LZQXQOPJ.js";
11
+ } from "../../../chunks/chunk-BPSCGGVF.js";
12
+ import "../../../chunks/chunk-RZGYXAJU.js";
9
13
 
10
14
  // builtin/extensions/pie-proc/index.ts
11
15
  import { spawn } from "node:child_process";
@@ -15,6 +19,20 @@ import * as fs from "node:fs";
15
19
  import * as os from "node:os";
16
20
  import * as path from "node:path";
17
21
  var require_ = createRequire(import.meta.url);
22
+ function resolveOperatorSessionsDir() {
23
+ try {
24
+ const { getSessionsDir } = require_("../../../src/config.js");
25
+ return getSessionsDir();
26
+ } catch {
27
+ const override = process.env.PIE_SESSIONS_DIR;
28
+ if (override !== void 0 && override !== "") {
29
+ if (override === "~") return path.join(os.homedir(), ".pie", "sessions");
30
+ if (override.startsWith("~/")) return path.join(os.homedir(), override.slice(2));
31
+ if (path.isAbsolute(override)) return override;
32
+ }
33
+ return path.join(os.homedir(), ".pie", "sessions");
34
+ }
35
+ }
18
36
  var DEFAULT_CONFIG = { allowCwd: [], maxWorkers: 5, killGraceMs: 15e3, defaultTtlMs: 0 };
19
37
  var IM_FORWARD_ALLOWED_KEYS = /* @__PURE__ */ new Set(["enabled", "provider", "chatId", "openId", "allowUsers", "retryBackoffMs", "larkCliProfile"]);
20
38
  var ONESHOT_TASK_ENV = "PIE_PROC_ONESHOT_TASK";
@@ -160,9 +178,10 @@ function workerLiveness(record) {
160
178
  } catch {
161
179
  return "dead";
162
180
  }
181
+ const marker = record.launchToken ?? record.sessionId;
163
182
  const cmd = readProcessCommandLine(record.pid);
164
183
  if (cmd === void 0) return "unknown";
165
- return cmd.includes(record.sessionId) ? "alive" : "dead";
184
+ return cmd.includes(marker) ? "alive" : "dead";
166
185
  }
167
186
  function canonicalDir(dir) {
168
187
  const resolved = path.resolve(expandTilde(dir));
@@ -397,11 +416,36 @@ function pieProc(ctx) {
397
416
  if (params.kind === "oneshot" && params.task.startsWith("-")) throw new Error(`oneshot task must not start with "-" (got "${params.task.slice(0, 20)}\u2026")`);
398
417
  if (params.kind === "oneshot" && params.imForward) throw new Error("imForward applies to resident workers only");
399
418
  if (params.kind !== "resident" && params.ttlMs !== void 0) throw new Error("ttlMs applies to resident workers only");
419
+ if (params.kind !== "resident" && params.resumeSessionId) throw new Error("resumeSessionId applies to resident workers only");
400
420
  const canonicalCwd = cwdAllowedOrThrow(params.cwd, currentConfig().allowCwd);
401
421
  const entry = cliEntry();
402
422
  if (!entry) throw new Error("cannot resolve a trusted pie entry point (refusing to spawn)");
423
+ let resumeSessionId;
424
+ if (params.resumeSessionId) {
425
+ if (!/^[A-Za-z0-9][A-Za-z0-9-_]{5,63}$/.test(params.resumeSessionId)) throw new Error(`invalid resumeSessionId "${params.resumeSessionId}"`);
426
+ const globalSessionsDir = resolveOperatorSessionsDir();
427
+ const headPath = path.join(globalSessionsDir, params.resumeSessionId, "head.json");
428
+ let recordedCwd;
429
+ try {
430
+ const head = JSON.parse(fs.readFileSync(headPath, "utf8"));
431
+ recordedCwd = head.metadata?.cwd;
432
+ } catch {
433
+ throw new Error(`resumeSessionId "${params.resumeSessionId}" not found in the global session store (${globalSessionsDir})`);
434
+ }
435
+ if (typeof recordedCwd !== "string" || !recordedCwd) throw new Error(`session "${params.resumeSessionId}" has no recorded cwd; resume requires one`);
436
+ let canonicalRecorded = recordedCwd;
437
+ try {
438
+ canonicalRecorded = fs.realpathSync(recordedCwd);
439
+ } catch {
440
+ }
441
+ if (canonicalRecorded !== canonicalCwd) throw new Error(`resume cwd mismatch: session recorded "${recordedCwd}" but spawn cwd is "${params.cwd}" \u2014 resume in the session's own directory`);
442
+ const holder = liveSessionHolder(params.resumeSessionId);
443
+ if (holder) throw new Error(`session "${params.resumeSessionId}" is owned by a live host (pid ${holder.pid} ${holder.holder}); close it or resume another session`);
444
+ resumeSessionId = params.resumeSessionId;
445
+ }
403
446
  const generation = `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
404
- const sessionId = `pie-proc-${params.name}-${generation}`;
447
+ const launchToken = `pie-proc-${params.name}-${generation}`;
448
+ const sessionId = resumeSessionId ?? launchToken;
405
449
  const imForward = sanitizeImForward(params.imForward);
406
450
  casRegistry((snap) => {
407
451
  const current = snap.workers;
@@ -437,6 +481,8 @@ function pieProc(ctx) {
437
481
  const reservation = {
438
482
  name: params.name,
439
483
  sessionId,
484
+ launchToken,
485
+ ...resumeSessionId ? { resumedFrom: resumeSessionId } : {},
440
486
  generation,
441
487
  pid: 0,
442
488
  cwd: "",
@@ -483,7 +529,19 @@ function pieProc(ctx) {
483
529
  }
484
530
  fs.mkdirSync(logDir(), { recursive: true });
485
531
  const logFile = fs.openSync(path.join(logDir(), `${params.name}.jsonl`), "a");
486
- const args = params.kind === "resident" ? [...loaderArgs(), entry, "--json-events", "--idle", "--session-id", sessionId] : [...loaderArgs(), entry, "--session-id", sessionId];
532
+ const args = params.kind === "resident" ? [
533
+ ...loaderArgs(),
534
+ entry,
535
+ "--json-events",
536
+ "--idle",
537
+ "--session-id",
538
+ sessionId,
539
+ // 4.4.1 resume: --resume-required makes a failed load a HARD exit
540
+ // (never silently mint a same-id empty session); --worker-token
541
+ // keeps argv liveness matching on the per-launch token even when
542
+ // --session-id carries a reusable business session id.
543
+ ...resumeSessionId ? ["--resume-required", "--worker-token", launchToken] : []
544
+ ] : [...loaderArgs(), entry, "--session-id", sessionId];
487
545
  const inheritedIpcRoot = path.resolve(expandTilde(process.env.PIE_IPC_CONFIG_DIR ?? configDirRoot()));
488
546
  const { PIE_DEFAULT_PROVIDER: _p, PIE_DEFAULT_MODEL: _m, PIE_MANAGER_BOOTSTRAP: _b, PIE_PROC_CURATED_NAME: _c, ...inheritedEnv } = process.env;
489
547
  const childEnv = {
@@ -493,6 +551,7 @@ function pieProc(ctx) {
493
551
  PIE_IPC_DISPLAY_NAME: params.kind === "resident" ? params.name : process.env.PIE_IPC_DISPLAY_NAME
494
552
  };
495
553
  if (params.kind === "oneshot") childEnv[ONESHOT_TASK_ENV] = params.task ?? "";
554
+ if (resumeSessionId) childEnv.PIE_SESSIONS_DIR = resolveOperatorSessionsDir();
496
555
  try {
497
556
  child = spawn(process.execPath, args, {
498
557
  cwd: canonicalCwd,
@@ -517,6 +576,8 @@ function pieProc(ctx) {
517
576
  const record = {
518
577
  name: params.name,
519
578
  sessionId,
579
+ launchToken,
580
+ ...resumeSessionId ? { resumedFrom: resumeSessionId } : {},
520
581
  generation,
521
582
  pid: child.pid,
522
583
  cwd: canonicalCwd,
@@ -618,7 +679,8 @@ function pieProc(ctx) {
618
679
  task: Type.Optional(Type.String({ description: "oneshot: the task prompt (non-empty, must not start with '-')" })),
619
680
  ttlMs: Type.Optional(Type.Number({ description: "spawn (resident only): idle TTL in ms (0 = never reap)", minimum: 0, maximum: 864e5 })),
620
681
  force: Type.Optional(Type.Boolean({ description: "kill: skip graceful SIGTERM" })),
621
- imForward: Type.Optional(Type.Union([Type.Literal("inherit"), Type.Record(Type.String(), Type.Unknown())], { description: "spawn (resident only): IM identity binding \u2014 'inherit' copies the operator's user-layer IM identity verbatim (recommended: open_ids are per-app, hand copies break silently), or an object of identity fields only (enabled/provider/chatId/openId/allowUsers/larkCliProfile/inherit)" }))
682
+ imForward: Type.Optional(Type.Union([Type.Literal("inherit"), Type.Record(Type.String(), Type.Unknown())], { description: "spawn (resident only): IM identity binding \u2014 'inherit' copies the operator's user-layer IM identity verbatim (recommended: open_ids are per-app, hand copies break silently), or an object of identity fields only (enabled/provider/chatId/openId/allowUsers/larkCliProfile/inherit)" })),
683
+ resumeSessionId: Type.Optional(Type.String({ description: "spawn (resident only): RESUME an existing business session instead of creating a new one. The session must exist in the global store (~/.pie/sessions), its recorded cwd must equal cwd, and no live host may own it. The worker keeps the session's context, IM topic anchors and model; its own config stays isolated. Use when the user wants an old session to CONTINUE its work (e.g. '\u8BA9 TBD \u7684\u90A3\u4E2A\u4F1A\u8BDD\u63A5\u7740\u67E5'), never for fresh tasks." }))
622
684
  }),
623
685
  risk: { riskClass: "process_lifecycle", requiresPermission: true, externalSideEffect: true, readsNetwork: false, writesNetwork: false, concurrencySafe: false },
624
686
  renderHint: { summary: (args) => `${String(args.action)}${args.name ? ` ${String(args.name)}` : ""}` },
@@ -652,7 +714,8 @@ function pieProc(ctx) {
652
714
  kind: args.kind ?? "resident",
653
715
  ttlMs: typeof args.ttlMs === "number" ? args.ttlMs : void 0,
654
716
  task: args.task,
655
- imForward: args.imForward
717
+ imForward: args.imForward,
718
+ resumeSessionId: args.resumeSessionId
656
719
  });
657
720
  }
658
721
  if (action === "kill") {
@@ -6,14 +6,14 @@ import {
6
6
  createPlanCapability,
7
7
  markCompletedPlanSteps,
8
8
  restoreExecutionState
9
- } from "../../../chunks/chunk-N5B5IGJ6.js";
10
- import "../../../chunks/chunk-XMOWWL4B.js";
11
- import "../../../chunks/chunk-B4N5LJMD.js";
12
- import "../../../chunks/chunk-6JEYRAQM.js";
9
+ } from "../../../chunks/chunk-YNTIOWCD.js";
10
+ import "../../../chunks/chunk-XO3NM7BB.js";
11
+ import "../../../chunks/chunk-IPLMGAML.js";
12
+ import "../../../chunks/chunk-R7VO46EK.js";
13
13
  import {
14
14
  Type
15
- } from "../../../chunks/chunk-XXGYUYXI.js";
16
- import "../../../chunks/chunk-LZQXQOPJ.js";
15
+ } from "../../../chunks/chunk-BPSCGGVF.js";
16
+ import "../../../chunks/chunk-RZGYXAJU.js";
17
17
 
18
18
  // builtin/extensions/plan-mode/index.ts
19
19
  import { randomUUID } from "node:crypto";
@@ -5,21 +5,22 @@ import {
5
5
  createCliRetryPolicy,
6
6
  formatTransportLifecycle,
7
7
  logTransportLifecycle
8
- } from "../../../chunks/chunk-I7PBXG5Q.js";
8
+ } from "../../../chunks/chunk-7LTQLJJF.js";
9
9
  import {
10
- getConfigDir
11
- } from "../../../chunks/chunk-ILUHTKF3.js";
10
+ getConfigDir,
11
+ init_config
12
+ } from "../../../chunks/chunk-UCKOXAME.js";
12
13
  import {
13
14
  SUBAGENT_SESSION_RECORD_VERSION,
14
15
  createPolicyEnforcedTools,
15
16
  createSharedFileSystemTools,
16
17
  createSubagentCapability
17
- } from "../../../chunks/chunk-N5B5IGJ6.js";
18
- import "../../../chunks/chunk-XMOWWL4B.js";
19
- import "../../../chunks/chunk-B4N5LJMD.js";
20
- import "../../../chunks/chunk-6JEYRAQM.js";
21
- import "../../../chunks/chunk-XXGYUYXI.js";
22
- import "../../../chunks/chunk-LZQXQOPJ.js";
18
+ } from "../../../chunks/chunk-YNTIOWCD.js";
19
+ import "../../../chunks/chunk-XO3NM7BB.js";
20
+ import "../../../chunks/chunk-IPLMGAML.js";
21
+ import "../../../chunks/chunk-R7VO46EK.js";
22
+ import "../../../chunks/chunk-BPSCGGVF.js";
23
+ import "../../../chunks/chunk-RZGYXAJU.js";
23
24
 
24
25
  // src/files/subagent-session-store.ts
25
26
  import { execFileSync } from "node:child_process";
@@ -380,6 +381,7 @@ function createSubagentSessionStore(sessionsDir, log, deps) {
380
381
  }
381
382
 
382
383
  // builtin/extensions/subagent/index.ts
384
+ init_config();
383
385
  import * as path2 from "path";
384
386
  function preserveModelResolution(r) {
385
387
  return r === void 0 ? void 0 : { ...r, model: r.model };
@@ -8,12 +8,12 @@ import {
8
8
  executeManageTodoList,
9
9
  executionStateToTodos,
10
10
  restoreExecutionState
11
- } from "../../../chunks/chunk-N5B5IGJ6.js";
12
- import "../../../chunks/chunk-XMOWWL4B.js";
13
- import "../../../chunks/chunk-B4N5LJMD.js";
14
- import "../../../chunks/chunk-6JEYRAQM.js";
15
- import "../../../chunks/chunk-XXGYUYXI.js";
16
- import "../../../chunks/chunk-LZQXQOPJ.js";
11
+ } from "../../../chunks/chunk-YNTIOWCD.js";
12
+ import "../../../chunks/chunk-XO3NM7BB.js";
13
+ import "../../../chunks/chunk-IPLMGAML.js";
14
+ import "../../../chunks/chunk-R7VO46EK.js";
15
+ import "../../../chunks/chunk-BPSCGGVF.js";
16
+ import "../../../chunks/chunk-RZGYXAJU.js";
17
17
 
18
18
  // builtin/extensions/todo/index.ts
19
19
  var EXECUTION_METADATA_KEY = "executionState";
@@ -4366,7 +4366,7 @@ import path from "node:path";
4366
4366
  // src/config.ts
4367
4367
  import { existsSync, mkdirSync, readFileSync, renameSync } from "fs";
4368
4368
  import { homedir } from "os";
4369
- import { dirname, join } from "path";
4369
+ import { dirname, isAbsolute, join } from "path";
4370
4370
  import { fileURLToPath } from "url";
4371
4371
  var __filename = fileURLToPath(import.meta.url);
4372
4372
  var __dirname = dirname(__filename);