@cydm/pie 2.7.16 → 2.7.17

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.
@@ -1,9 +1,9 @@
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-JTD4JJTG.js";
5
- import "../../../chunks/chunk-TDHVB2FH.js";
6
- import "../../../chunks/chunk-NM2JLPJ6.js";
4
+ } from "../../../chunks/chunk-UDCGB3LZ.js";
5
+ import "../../../chunks/chunk-2H2DD22Z.js";
6
+ import "../../../chunks/chunk-X7UO6BA6.js";
7
7
  import "../../../chunks/chunk-XXGYUYXI.js";
8
8
  import "../../../chunks/chunk-LZQXQOPJ.js";
9
9
 
@@ -608,6 +608,7 @@ function cron(ctx) {
608
608
  ctx.on("session:changed", async (e) => {
609
609
  try {
610
610
  await runtime.bind(e.sessionId);
611
+ startupError = void 0;
611
612
  } catch (e2) {
612
613
  startupError = String(e2);
613
614
  }
@@ -623,7 +624,7 @@ function cron(ctx) {
623
624
  } catch {
624
625
  }
625
626
  ctx.ui.notify("cron: session ownership is uncertain or duplicated; input blocked. Close the duplicate/worker and inspect /cron.", "warning");
626
- return { action: "consume" };
627
+ return { action: "reject" };
627
628
  });
628
629
  ctx.on("session:before_switch", (e) => {
629
630
  if (!e.targetSessionId) return;
@@ -639,7 +640,7 @@ function cron(ctx) {
639
640
  }
640
641
  });
641
642
  const run = (action, id, prompt, schedule) => {
642
- if (startupError) throw new Error(`cron unavailable: ${startupError}; see docs/cron.md recovery`);
643
+ if (startupError && action !== "list") throw new Error(`cron unavailable: ${startupError}; see docs/cron.md recovery`);
643
644
  if (action === "list") return JSON.stringify({ ...store.read(), recoveryRequired: fs3.existsSync(path4.join(store.dir, "unsafe.lock")), coordinatorPresent: fs3.existsSync(path4.join(store.dir, "scheduler.lock")) }, null, 2);
644
645
  if (action === "add") {
645
646
  if (!runtime.ready || !runtime.sessionId) throw new Error("wait for an existing session to load and register");
@@ -581,6 +581,9 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
581
581
  if (cfg.allowUsers && (!event.sender_id || !cfg.allowUsers.includes(event.sender_id))) return;
582
582
  const messageId = event.message_id;
583
583
  if (!messageId) return;
584
+ const releaseInvalidatedEvent = () => {
585
+ if (event.event_id) seenEventIds.delete(key(event.event_id));
586
+ };
584
587
  const sessionId = currentSessionId;
585
588
  const epoch = inputEpoch;
586
589
  const scope = ctx.beginUserInput?.(() => !terminated && inputEpoch === epoch && currentSessionId === sessionId && isForwardingEnabled());
@@ -595,7 +598,10 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
595
598
  retry();
596
599
  return;
597
600
  }
598
- if (!scope.isCurrent()) return;
601
+ if (!scope.isCurrent()) {
602
+ releaseInvalidatedEvent();
603
+ return;
604
+ }
599
605
  const resolution = await resolveRouteForInbound(messageId, meta);
600
606
  if (!("found" in resolution)) {
601
607
  if (isTransient(resolution)) retry();
@@ -603,15 +609,20 @@ ${pending.caption || IM_INPUT_FALLBACK_CAPTION}` : pending.caption).trim();
603
609
  return;
604
610
  }
605
611
  const route = resolution.found;
606
- if (route.sessionId !== sessionId || !scope.isCurrent()) return;
612
+ if (route.sessionId !== sessionId || !scope.isCurrent()) {
613
+ releaseInvalidatedEvent();
614
+ return;
615
+ }
607
616
  const imageKeys = event.images;
608
617
  const caption = event.text;
609
618
  if (!caption && !imageKeys.length) return;
610
619
  const submitText = `${IM_INPUT_PREFIX}
611
620
  ${caption || IM_INPUT_FALLBACK_CAPTION}`;
612
621
  const accepted = imageKeys.length ? await injectImageMessage(messageId, imageKeys, submitText, scope) : await scope.submit(submitText);
613
- if (!accepted || !scope.isCurrent()) {
614
- if (scope.isCurrent()) {
622
+ const currentAfterSubmit = scope.isCurrent();
623
+ if (!accepted || !currentAfterSubmit) {
624
+ if (!accepted && !currentAfterSubmit) releaseInvalidatedEvent();
625
+ if (currentAfterSubmit) {
615
626
  ctx.ui.notify("im-forward: message was not accepted; no input submitted.", "warning");
616
627
  await forwardMessage(`\u26A0\uFE0F \u6D88\u606F\u63A5\u6536\u5931\u8D25\uFF0C\u672A\u63D0\u4EA4\u4EFB\u52A1\u3002${imageKeys.length ? "\u8BF7\u68C0\u67E5\u9644\u4EF6\u540E\u91CD\u8BD5\u3002" : "\u8BF7\u91CD\u8BD5\u3002"}`, route.sessionId, ++forwardCounter, caption, messageId);
617
628
  }
@@ -824,6 +824,7 @@ function buildStatusFile(input) {
824
824
  import * as net from "node:net";
825
825
  import { createHmac, randomBytes as randomBytes4, randomUUID, timingSafeEqual } from "node:crypto";
826
826
  import { StringDecoder } from "node:string_decoder";
827
+ var CLOSE_FLUSH_TIMEOUT_MS = 1e3;
827
828
  function signEnvelope(e, secret) {
828
829
  const payload = [e.v, e.id, e.from, e.to, e.kind, e.createdAt, e.sessionId ?? null, e.text ?? null, e.replyTo ?? null, e.waitMs ?? null];
829
830
  return { ...e, auth: createHmac("sha256", secret).update(JSON.stringify(payload)).digest("hex") };
@@ -972,6 +973,7 @@ var IpcTransport = class {
972
973
  if (e.waitMs) socket.setTimeout(Math.max(6e4, e.waitMs + 1e3));
973
974
  if (!this.seen.add(`${e.from}:${e.id}`)) return;
974
975
  try {
976
+ if (this.closed) return;
975
977
  this.host.onEnvelope(e, (reply) => {
976
978
  if (reply.from === this.instanceId && reply.to === e.from && reply.replyTo === e.id) this.write(socket, reply, this.secret);
977
979
  }, lifecycle.signal);
@@ -1046,7 +1048,12 @@ var IpcTransport = class {
1046
1048
  if (this.closed) return;
1047
1049
  this.closed = true;
1048
1050
  for (const cancel of [...this.cancels]) cancel();
1049
- for (const socket of this.sockets) socket.destroy();
1051
+ for (const socket of this.sockets) {
1052
+ if (socket.destroyed) continue;
1053
+ socket.end();
1054
+ const timer = setTimeout(() => socket.destroy(), CLOSE_FLUSH_TIMEOUT_MS);
1055
+ timer.unref();
1056
+ }
1050
1057
  this.sockets.clear();
1051
1058
  this.server.close();
1052
1059
  this.port = null;
@@ -6,9 +6,9 @@ import {
6
6
  extractPlanTodoItems,
7
7
  markCompletedPlanSteps,
8
8
  restoreExecutionState
9
- } from "../../../chunks/chunk-JTD4JJTG.js";
10
- import "../../../chunks/chunk-TDHVB2FH.js";
11
- import "../../../chunks/chunk-NM2JLPJ6.js";
9
+ } from "../../../chunks/chunk-UDCGB3LZ.js";
10
+ import "../../../chunks/chunk-2H2DD22Z.js";
11
+ import "../../../chunks/chunk-X7UO6BA6.js";
12
12
  import {
13
13
  Type
14
14
  } from "../../../chunks/chunk-XXGYUYXI.js";
@@ -6,15 +6,15 @@ import {
6
6
  formatTransportLifecycle,
7
7
  getConfigDir,
8
8
  logTransportLifecycle
9
- } from "../../../chunks/chunk-ZDGSTGF2.js";
9
+ } from "../../../chunks/chunk-TGCI5M6R.js";
10
10
  import {
11
11
  SUBAGENT_SESSION_RECORD_VERSION,
12
12
  createPolicyEnforcedTools,
13
13
  createSharedFileSystemTools,
14
14
  createSubagentCapability
15
- } from "../../../chunks/chunk-JTD4JJTG.js";
16
- import "../../../chunks/chunk-TDHVB2FH.js";
17
- import "../../../chunks/chunk-NM2JLPJ6.js";
15
+ } from "../../../chunks/chunk-UDCGB3LZ.js";
16
+ import "../../../chunks/chunk-2H2DD22Z.js";
17
+ import "../../../chunks/chunk-X7UO6BA6.js";
18
18
  import "../../../chunks/chunk-XXGYUYXI.js";
19
19
  import "../../../chunks/chunk-LZQXQOPJ.js";
20
20
 
@@ -8,9 +8,9 @@ import {
8
8
  executeManageTodoList,
9
9
  executionStateToTodos,
10
10
  restoreExecutionState
11
- } from "../../../chunks/chunk-JTD4JJTG.js";
12
- import "../../../chunks/chunk-TDHVB2FH.js";
13
- import "../../../chunks/chunk-NM2JLPJ6.js";
11
+ } from "../../../chunks/chunk-UDCGB3LZ.js";
12
+ import "../../../chunks/chunk-2H2DD22Z.js";
13
+ import "../../../chunks/chunk-X7UO6BA6.js";
14
14
  import "../../../chunks/chunk-XXGYUYXI.js";
15
15
  import "../../../chunks/chunk-LZQXQOPJ.js";
16
16
 
@@ -4,7 +4,7 @@ import {
4
4
  disposeModelTransports,
5
5
  streamSimple,
6
6
  validateToolArguments
7
- } from "./chunk-NM2JLPJ6.js";
7
+ } from "./chunk-X7UO6BA6.js";
8
8
 
9
9
  // ../../packages/agent-core/src/failure.ts
10
10
  function getAgentFailureMetadata(error) {
@@ -850,6 +850,7 @@ var Agent = class {
850
850
  convertToLlm: this.convertToLlm,
851
851
  transformContext: this.transformContext,
852
852
  beforeToolContinuation: beforeToolContinuation ? async () => {
853
+ if (!ownsRun() || runController.signal.aborted) throw new Error("Request was aborted");
853
854
  await new Promise((resolve) => {
854
855
  acknowledgeToolTurn = resolve;
855
856
  });
@@ -7,12 +7,12 @@ import {
7
7
  defaultShellKindForPlatform,
8
8
  interpretShellExit,
9
9
  requestInteraction
10
- } from "./chunk-JTD4JJTG.js";
10
+ } from "./chunk-UDCGB3LZ.js";
11
11
  import {
12
12
  EMPTY_ASSISTANT_CONTENT_ERROR,
13
13
  OPENAI_COMPAT_PROTOCOL_ERROR_CODE,
14
14
  getLogger
15
- } from "./chunk-NM2JLPJ6.js";
15
+ } from "./chunk-X7UO6BA6.js";
16
16
  import {
17
17
  Type
18
18
  } from "./chunk-XXGYUYXI.js";
@@ -4,7 +4,7 @@ import {
4
4
  createAgentOperationError,
5
5
  getAgentFailureMetadata,
6
6
  getToolCallerIdentity
7
- } from "./chunk-TDHVB2FH.js";
7
+ } from "./chunk-2H2DD22Z.js";
8
8
  import {
9
9
  AssistantMessageEventStream,
10
10
  FileSystemGateway,
@@ -14,7 +14,7 @@ import {
14
14
  getPlatformConfig,
15
15
  hashText,
16
16
  streamSimple
17
- } from "./chunk-NM2JLPJ6.js";
17
+ } from "./chunk-X7UO6BA6.js";
18
18
  import {
19
19
  Type
20
20
  } from "./chunk-XXGYUYXI.js";
@@ -1528,7 +1528,7 @@ function getSystemIO() {
1528
1528
  return CS.System.IO;
1529
1529
  }
1530
1530
  function looksLikeBase64(value) {
1531
- return value.length > 0 && value.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(value);
1531
+ return value.length === 0 || value.length % 4 === 0 && /^[A-Za-z0-9+/]+={0,2}$/.test(value);
1532
1532
  }
1533
1533
  function getPieFileBridge() {
1534
1534
  if (typeof CS === "undefined" || !CS?.Pie?.PieFileBridge) {
@@ -8,8 +8,8 @@ import {
8
8
  createToolCallerIdentity,
9
9
  getAgentFailureMetadata,
10
10
  getToolCallerIdentity
11
- } from "./chunk-TDHVB2FH.js";
12
- import "./chunk-NM2JLPJ6.js";
11
+ } from "./chunk-2H2DD22Z.js";
12
+ import "./chunk-X7UO6BA6.js";
13
13
  import "./chunk-XXGYUYXI.js";
14
14
  import "./chunk-LZQXQOPJ.js";
15
15
  export {
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  EventStream
4
- } from "./chunk-NM2JLPJ6.js";
4
+ } from "./chunk-X7UO6BA6.js";
5
5
  import "./chunk-XXGYUYXI.js";
6
6
  import "./chunk-LZQXQOPJ.js";
7
7
 
package/dist/cli.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  migrateConfigFromAgentDir,
30
30
  setYoloGrantListener,
31
31
  truncateHeadTail
32
- } from "./chunks/chunk-ZDGSTGF2.js";
32
+ } from "./chunks/chunk-TGCI5M6R.js";
33
33
  import {
34
34
  AGENTS_CONTEXT_FILE_NAME,
35
35
  AgentSessionController,
@@ -91,8 +91,8 @@ import {
91
91
  shouldPreserveExecutionStateForUserText,
92
92
  supersedeExecutionState,
93
93
  verifyPreparedCompactionCommit
94
- } from "./chunks/chunk-JTD4JJTG.js";
95
- import "./chunks/chunk-TDHVB2FH.js";
94
+ } from "./chunks/chunk-UDCGB3LZ.js";
95
+ import "./chunks/chunk-2H2DD22Z.js";
96
96
  import {
97
97
  Deref,
98
98
  Errors,
@@ -115,7 +115,7 @@ import {
115
115
  sortToolModelCandidatesByCapability,
116
116
  streamSimple,
117
117
  type_exports
118
- } from "./chunks/chunk-NM2JLPJ6.js";
118
+ } from "./chunks/chunk-X7UO6BA6.js";
119
119
  import {
120
120
  IsArray,
121
121
  IsBigInt,
@@ -64960,7 +64960,7 @@ var ExtensionRunner = class {
64960
64960
  /**
64961
64961
  * Emit terminal:input to all extensions. Transforms chain through handlers
64962
64962
  * in registration order (each handler sees the previous transform); a
64963
- * consume result stops the chain and wins. Default: continue unchanged.
64963
+ * consume/reject result stops the chain and wins. Default: continue unchanged.
64964
64964
  */
64965
64965
  async emitTerminalInput(event) {
64966
64966
  const ctx = this.createContext();
@@ -64974,6 +64974,7 @@ var ExtensionRunner = class {
64974
64974
  const result = await handler({ ...event, text }, ctx);
64975
64975
  if (!result || typeof result !== "object" || !("action" in result)) continue;
64976
64976
  if (result.action === "consume") return { action: "consume" };
64977
+ if (result.action === "reject") return { action: "reject" };
64977
64978
  if (result.action === "transform" && typeof result.text === "string") {
64978
64979
  text = result.text;
64979
64980
  current = { action: "transform", text };
@@ -77980,6 +77981,9 @@ function setupInteractiveEditorSubmitHandler(host) {
77980
77981
  if (!text) return;
77981
77982
  if (host.extensionRunner) {
77982
77983
  const decision = await host.extensionRunner.emitTerminalInput({ type: "terminal:input", text });
77984
+ if (decision.action === "reject") {
77985
+ return;
77986
+ }
77983
77987
  if (decision.action === "consume") {
77984
77988
  host.editor.setText("");
77985
77989
  return;
@@ -80064,8 +80068,9 @@ function setupInteractiveKeybindings(host) {
80064
80068
  host.handleFollowUp();
80065
80069
  return { consume: true };
80066
80070
  }
80071
+ if (!mainEditorOwnsInput(host)) return { consume: false };
80067
80072
  const shortcuts = host.getExtensionShortcuts?.();
80068
- if (shortcuts && shortcuts.size > 0 && mainEditorOwnsInput(host)) {
80073
+ if (shortcuts && shortcuts.size > 0) {
80069
80074
  for (const shortcut of shortcuts.values()) {
80070
80075
  if (matchesKey(data, shortcut.key)) {
80071
80076
  void shortcut.handler();
@@ -83116,7 +83121,7 @@ function beginUserInput(host, extensionIsCurrent = () => true) {
83116
83121
  }
83117
83122
  let content = [text.trim(), ...mentions].filter(Boolean).join("\n");
83118
83123
  const decision = await runner.emitTerminalInput({ type: "terminal:input", text: content });
83119
- if (!isCurrent() || decision.action === "consume") return false;
83124
+ if (!isCurrent() || decision.action === "consume" || decision.action === "reject") return false;
83120
83125
  if (decision.action === "transform") content = decision.text.trim();
83121
83126
  if (!content || mentions.some((mention) => !content.includes(mention))) return false;
83122
83127
  host.queueMessage(content, "followUp", { clearEditor: false, deliverWhileStreaming: false });
@@ -83423,6 +83428,7 @@ var InteractiveMode = class {
83423
83428
  knowledgeSection = "";
83424
83429
  extensions = [];
83425
83430
  extensionRunner;
83431
+ extensionShortcutsCache;
83426
83432
  extensionUIContext;
83427
83433
  allTools = [];
83428
83434
  streamingComponent;
@@ -83766,7 +83772,7 @@ var InteractiveMode = class {
83766
83772
  async init() {
83767
83773
  const activeSession = this.sessionManager.getActiveSession();
83768
83774
  this.thinkingLevel = resolveInitialThinkingLevel({ session: activeSession, settingsManager: this.options.settingsManager });
83769
- const { Agent } = await import("./chunks/src-IY6TEIL7.js");
83775
+ const { Agent } = await import("./chunks/src-GX4UBAYF.js");
83770
83776
  this.agent = new Agent({
83771
83777
  initialState: {
83772
83778
  systemPrompt: this.buildSystemPrompt(),
@@ -84114,17 +84120,22 @@ var InteractiveMode = class {
84114
84120
  * dispatcher (duck-typed onto InteractiveKeybindingsHost). Handlers are
84115
84121
  * bound to the extension runner context here. */
84116
84122
  getExtensionShortcuts() {
84123
+ const cached = this.extensionShortcutsCache;
84124
+ if (cached && cached.extensions === this.extensions && cached.runner === this.extensionRunner) {
84125
+ return cached.shortcuts;
84126
+ }
84117
84127
  const merged = /* @__PURE__ */ new Map();
84128
+ const context = this.extensionRunner?.createContext();
84118
84129
  for (const extension of this.extensions) {
84119
84130
  for (const [key, shortcut] of extension.shortcuts) {
84120
84131
  if (merged.has(key)) continue;
84121
- const context = this.extensionRunner?.createContext();
84122
84132
  merged.set(key, {
84123
84133
  key,
84124
84134
  handler: () => shortcut.handler(context)
84125
84135
  });
84126
84136
  }
84127
84137
  }
84138
+ this.extensionShortcutsCache = { extensions: this.extensions, runner: this.extensionRunner, shortcuts: merged };
84128
84139
  return merged;
84129
84140
  }
84130
84141
  /** Live mention handler for extension-driven attachments (duck-typed onto
@@ -84654,7 +84665,7 @@ async function runPrintMode(params) {
84654
84665
  `);
84655
84666
  console.log("Assistant: ");
84656
84667
  }
84657
- const { Agent: AgentClass } = await import("./chunks/src-IY6TEIL7.js");
84668
+ const { Agent: AgentClass } = await import("./chunks/src-GX4UBAYF.js");
84658
84669
  let agent;
84659
84670
  const printModeExtensions = await loadPrintModeExtensions({
84660
84671
  cwd: runtime.cwd,
@@ -85549,7 +85560,7 @@ async function runJsonEventsMode(params) {
85549
85560
  const sideTrace = trace;
85550
85561
  const sideApiKey = runtime.apiKey;
85551
85562
  const snapshot = structuredClone(parent.state.messages);
85552
- const { Agent: AgentClass } = await import("./chunks/src-IY6TEIL7.js");
85563
+ const { Agent: AgentClass } = await import("./chunks/src-GX4UBAYF.js");
85553
85564
  const sideAgent = new AgentClass({
85554
85565
  initialState: {
85555
85566
  systemPrompt: parent.state.systemPrompt,
@@ -85913,7 +85924,7 @@ async function runJsonEventsMode(params) {
85913
85924
  if (runtime.initialModel.unconfigured || controller) {
85914
85925
  return;
85915
85926
  }
85916
- const { Agent: AgentClass } = await import("./chunks/src-IY6TEIL7.js");
85927
+ const { Agent: AgentClass } = await import("./chunks/src-GX4UBAYF.js");
85917
85928
  if (runtimeClosing) return;
85918
85929
  const compositionRegistry = createCliHostEnvelopeRegistry();
85919
85930
  const jsonModeExtensions = await loadJsonModeExtensions({ runtime, envelopeRegistry: compositionRegistry, getAgent: () => agent });
@@ -86601,7 +86612,7 @@ async function runWithJsonEventsConsoleIsolation(fn) {
86601
86612
  }
86602
86613
  async function createCliTestStreamFnFromEnv() {
86603
86614
  if (!process.env.PIE_TEST_MOCK_STREAM_SEQUENCE) return void 0;
86604
- return (await import("./chunks/test-stream-EXSL5TIO.js")).createTestStreamFnFromSequenceEnv();
86615
+ return (await import("./chunks/test-stream-AKIZNFCM.js")).createTestStreamFnFromSequenceEnv();
86605
86616
  }
86606
86617
  function resolveJsonEventsDetailFlag() {
86607
86618
  for (let index = 0; index < process.argv.length; index += 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cydm/pie",
3
- "version": "2.7.16",
3
+ "version": "2.7.17",
4
4
  "description": "Pie AI Agent CLI",
5
5
  "type": "module",
6
6
  "bin": {