@cydm/pie 2.6.2 → 2.6.4

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-HT3OYGS7.js";
5
- import "../../../chunks/chunk-Y4CYXJR7.js";
6
- import "../../../chunks/chunk-O2DKMLNX.js";
4
+ } from "../../../chunks/chunk-3AOMWS2Z.js";
5
+ import "../../../chunks/chunk-YEUBQBOB.js";
6
+ import "../../../chunks/chunk-OCEYHWVX.js";
7
7
  import "../../../chunks/chunk-XXGYUYXI.js";
8
8
  import "../../../chunks/chunk-LZQXQOPJ.js";
9
9
 
@@ -7,9 +7,9 @@ import {
7
7
  isPlanModeSafeCommand,
8
8
  markCompletedPlanSteps,
9
9
  restoreExecutionState
10
- } from "../../../chunks/chunk-HT3OYGS7.js";
11
- import "../../../chunks/chunk-Y4CYXJR7.js";
12
- import "../../../chunks/chunk-O2DKMLNX.js";
10
+ } from "../../../chunks/chunk-3AOMWS2Z.js";
11
+ import "../../../chunks/chunk-YEUBQBOB.js";
12
+ import "../../../chunks/chunk-OCEYHWVX.js";
13
13
  import {
14
14
  Type
15
15
  } from "../../../chunks/chunk-XXGYUYXI.js";
@@ -1,13 +1,13 @@
1
1
  import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
2
  import {
3
3
  createCliHostCapabilities
4
- } from "../../../chunks/chunk-INQMGIKU.js";
4
+ } from "../../../chunks/chunk-6QEDYZUR.js";
5
5
  import {
6
6
  createSharedFileSystemTools,
7
7
  createSubagentCapability
8
- } from "../../../chunks/chunk-HT3OYGS7.js";
9
- import "../../../chunks/chunk-Y4CYXJR7.js";
10
- import "../../../chunks/chunk-O2DKMLNX.js";
8
+ } from "../../../chunks/chunk-3AOMWS2Z.js";
9
+ import "../../../chunks/chunk-YEUBQBOB.js";
10
+ import "../../../chunks/chunk-OCEYHWVX.js";
11
11
  import "../../../chunks/chunk-5353DEEC.js";
12
12
  import "../../../chunks/chunk-XXGYUYXI.js";
13
13
  import "../../../chunks/chunk-LZQXQOPJ.js";
@@ -8,9 +8,9 @@ import {
8
8
  executeManageTodoList,
9
9
  executionStateToTodos,
10
10
  restoreExecutionState
11
- } from "../../../chunks/chunk-HT3OYGS7.js";
12
- import "../../../chunks/chunk-Y4CYXJR7.js";
13
- import "../../../chunks/chunk-O2DKMLNX.js";
11
+ } from "../../../chunks/chunk-3AOMWS2Z.js";
12
+ import "../../../chunks/chunk-YEUBQBOB.js";
13
+ import "../../../chunks/chunk-OCEYHWVX.js";
14
14
  import "../../../chunks/chunk-XXGYUYXI.js";
15
15
  import "../../../chunks/chunk-LZQXQOPJ.js";
16
16
 
@@ -2,7 +2,7 @@ import { createRequire as __createRequire } from "node:module"; const require =
2
2
  import {
3
3
  Agent,
4
4
  getToolCallerIdentity
5
- } from "./chunk-Y4CYXJR7.js";
5
+ } from "./chunk-YEUBQBOB.js";
6
6
  import {
7
7
  FileSystemGateway,
8
8
  completeSimple,
@@ -11,7 +11,7 @@ import {
11
11
  getPlatformConfig,
12
12
  hashText,
13
13
  streamSimple
14
- } from "./chunk-O2DKMLNX.js";
14
+ } from "./chunk-OCEYHWVX.js";
15
15
  import {
16
16
  Type
17
17
  } from "./chunk-XXGYUYXI.js";
@@ -1390,6 +1390,17 @@ function formatSkillSummariesForPrompt(skills) {
1390
1390
  var DEFAULT_SUBAGENT_TIMEOUT_SECONDS = 1200;
1391
1391
  var DEFAULT_SUBAGENT_THINKING_LEVEL = "medium";
1392
1392
  var SUBAGENT_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
1393
+ var DEFAULT_HEARTBEAT_INTERVAL_MS = 3e4;
1394
+ function formatHeartbeatElapsed(ms) {
1395
+ const totalSeconds = Math.floor(ms / 1e3);
1396
+ if (totalSeconds < 60) return `${totalSeconds}s`;
1397
+ const minutes = Math.floor(totalSeconds / 60);
1398
+ if (minutes < 60) return `${minutes}m${String(totalSeconds % 60).padStart(2, "0")}s`;
1399
+ return `${Math.floor(minutes / 60)}h${String(minutes % 60).padStart(2, "0")}m`;
1400
+ }
1401
+ function clipHeartbeatLabel(text, maxLength = 60) {
1402
+ return text.length > maxLength ? `${text.slice(0, maxLength - 1)}\u2026` : text;
1403
+ }
1393
1404
  function formatSkillsForPrompt(skills) {
1394
1405
  return formatSkillSummariesForPrompt(skills);
1395
1406
  }
@@ -1596,9 +1607,30 @@ async function runSubagentWithProgress(deps, task, reportProgress, signal) {
1596
1607
  const startTime = Date.now();
1597
1608
  task.status = "running";
1598
1609
  let timedOut = false;
1610
+ let lastProgressAt = Date.now();
1611
+ let lastActivity = "starting";
1612
+ const report = (update) => {
1613
+ lastProgressAt = Date.now();
1614
+ if (update.message) lastActivity = update.message;
1615
+ reportProgress(update);
1616
+ };
1617
+ const heartbeatIntervalMs = deps.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
1599
1618
  deps.debugLog?.("run", "runSubagentWithProgress START", { taskName: task.name, yoloMode: deps.yoloMode });
1619
+ let heartbeat;
1620
+ if (heartbeatIntervalMs > 0) {
1621
+ heartbeat = setInterval(() => {
1622
+ try {
1623
+ if (Date.now() - lastProgressAt < heartbeatIntervalMs) return;
1624
+ lastProgressAt = Date.now();
1625
+ reportProgress({
1626
+ message: `[${task.name}] Still working (${formatHeartbeatElapsed(Date.now() - startTime)} elapsed; last: ${clipHeartbeatLabel(lastActivity)})`
1627
+ });
1628
+ } catch {
1629
+ }
1630
+ }, Math.max(50, Math.min(1e3, heartbeatIntervalMs / 2)));
1631
+ }
1600
1632
  try {
1601
- reportProgress({ message: `[${task.name}] Starting...`, increment: 5 });
1633
+ report({ message: `[${task.name}] Starting...`, increment: 5 });
1602
1634
  const { plan, tools, apiKey, model } = buildSubagentPlan(deps, task.task, task.name, task.priority, task.timeoutSeconds, task.modelOverride, task.thinkingLevel, task.mode);
1603
1635
  task.plan = plan;
1604
1636
  task.needsParentWrite = task.mode === "read" && needsParentWrite(task.task);
@@ -1678,7 +1710,7 @@ ${formatSkillsForPrompt(deps.skills ?? [])}`;
1678
1710
  type: event.toolName === "bash" ? "command_run" : event.toolName === "read_file" ? "file_read" : "tool_success",
1679
1711
  message: `${event.toolName} started`
1680
1712
  });
1681
- reportProgress({ message: `[${task.name}] Using ${event.toolName}...` });
1713
+ report({ message: `[${task.name}] Using ${event.toolName}...` });
1682
1714
  }
1683
1715
  if (event.type === "tool_execution_end" && event.isError) {
1684
1716
  task.confidenceSignals.push({ type: "tool_error", message: `${event.toolName} failed` });
@@ -1692,7 +1724,7 @@ ${formatSkillsForPrompt(deps.skills ?? [])}`;
1692
1724
  prompt += "\n\nThis delegation is read mode. Do not write files. If changes are needed, describe them for the parent.";
1693
1725
  }
1694
1726
  prompt += "\n\nReturn evidence for your conclusion and state uncertainty as low, medium, or high.";
1695
- reportProgress({ message: `[${task.name}] Running plan ${plan.complexity}/${plan.modelClass}...`, increment: 20 });
1727
+ report({ message: `[${task.name}] Running plan ${plan.complexity}/${plan.modelClass}...`, increment: 20 });
1696
1728
  try {
1697
1729
  await Promise.race([
1698
1730
  (async () => {
@@ -1743,7 +1775,7 @@ ${formatSkillsForPrompt(deps.skills ?? [])}`;
1743
1775
  };
1744
1776
  task.parentHandoffRequired = isParentHandoffRequired(task) || outputTruncated;
1745
1777
  task.completedAt = Date.now();
1746
- reportProgress({ message: `[${task.name}] Completed (${durationMs}ms, ${toolCalls} tools)`, increment: 100 });
1778
+ report({ message: `[${task.name}] Completed (${durationMs}ms, ${toolCalls} tools)`, increment: 100 });
1747
1779
  } catch (error) {
1748
1780
  const errorMessage = error instanceof Error ? error.message : String(error);
1749
1781
  const stackTrace = error instanceof Error ? error.stack : void 0;
@@ -1758,7 +1790,11 @@ ${formatSkillsForPrompt(deps.skills ?? [])}`;
1758
1790
  task.uncertainty = "high";
1759
1791
  task.parentHandoffRequired = isParentHandoffRequired(task);
1760
1792
  task.completedAt = Date.now();
1761
- reportProgress({ message: `[${task.name}] Failed: ${errorMessage.slice(0, 100)}`, increment: 100 });
1793
+ report({ message: `[${task.name}] Failed: ${errorMessage.slice(0, 100)}`, increment: 100 });
1794
+ } finally {
1795
+ if (heartbeat) {
1796
+ clearInterval(heartbeat);
1797
+ }
1762
1798
  }
1763
1799
  }
1764
1800
  function buildParallelResult(tasks, totalDuration) {
@@ -3308,7 +3344,10 @@ var FileSessionStore = class {
3308
3344
  const previous = head.metadata;
3309
3345
  const merged = mergeMetadata(previous, {
3310
3346
  ...metadataPatch ?? {},
3311
- entryCount: previous.entryCount + newHeaders.length,
3347
+ // Self-heal drifted counters: seqs are dense, so the committed
3348
+ // frontier is also a lower bound on the entry count. A stale
3349
+ // entryCount (concurrent-writer lost update) must not persist.
3350
+ entryCount: Math.max(previous.entryCount + newHeaders.length, seq),
3312
3351
  messageCount: previous.messageCount + newHeaders.filter((header) => header.type === "message").length,
3313
3352
  rootEntryId: metadataPatch?.rootEntryId ?? previous.rootEntryId ?? newHeaders.find((header) => header.parentSeq === null)?.id ?? null,
3314
3353
  activeEntryId: activeEntryId ?? metadataPatch?.activeEntryId ?? newHeaders[newHeaders.length - 1]?.id ?? previous.activeEntryId
@@ -3383,7 +3422,12 @@ var FileSessionStore = class {
3383
3422
  return {
3384
3423
  summaries: collected.slice(0, limit).map(toSummary),
3385
3424
  hasMore: collected.length > limit,
3386
- total: head.metadata.entryCount
3425
+ // Sequence numbers are dense (one per committed entry), so
3426
+ // committedSeq is the authoritative entry count. metadata.entryCount
3427
+ // can drift behind it when concurrent writers race head manifests
3428
+ // (lost update), which would otherwise surface as ranges like
3429
+ // "seqs 1582-1621 of 1574" in paged UIs.
3430
+ total: Math.max(head.metadata.entryCount, head.committedSeq)
3387
3431
  };
3388
3432
  }
3389
3433
  getEntrySummary(sessionId, entryId) {
@@ -8,7 +8,7 @@ import {
8
8
  createSharedWebSearchTool,
9
9
  interpretShellExit,
10
10
  requestInteraction
11
- } from "./chunk-HT3OYGS7.js";
11
+ } from "./chunk-3AOMWS2Z.js";
12
12
  import {
13
13
  getBuiltinDir,
14
14
  getConfigDir
@@ -3223,6 +3223,7 @@ var DEFAULT_OPENAI_COMPAT_STREAM_IDLE_TIMEOUT_MS = 2 * 60 * 1e3;
3223
3223
  var DEFAULT_OPENAI_COMPAT_FIRST_BYTE_TIMEOUT_MS = 3 * 60 * 1e3;
3224
3224
  var OPENAI_COMPAT_FIRST_BYTE_MAX_ESCALATION_STEPS = 3;
3225
3225
  var openAICompatFirstByteTimeoutsByEndpoint = /* @__PURE__ */ new Map();
3226
+ var OPENAI_COMPAT_MAX_DUPLICATE_TOOL_CALLS = 3;
3226
3227
  var OPENAI_COMPAT_PROTOCOL_ERROR_CODE = "provider_response_protocol_error";
3227
3228
  var OpenAICompatProtocolError = class extends Error {
3228
3229
  code = OPENAI_COMPAT_PROTOCOL_ERROR_CODE;
@@ -3679,6 +3680,53 @@ var streamOpenAICompletions = (model, context, options) => {
3679
3680
  });
3680
3681
  }
3681
3682
  }
3683
+ const knownToolNames = new Set((context.tools ?? []).map((tool) => tool.name));
3684
+ const droppedToolCallBlocks = /* @__PURE__ */ new Set();
3685
+ const unknownNameSamples = [];
3686
+ if (knownToolNames.size > 0) {
3687
+ for (let i = toolCallEntries.length - 1; i >= 0; i--) {
3688
+ const entry = toolCallEntries[i];
3689
+ if (entry.block.name.trim() && !knownToolNames.has(entry.block.name)) {
3690
+ if (unknownNameSamples.length < 3) unknownNameSamples.push(JSON.stringify(entry.block.name));
3691
+ droppedToolCallBlocks.add(entry.block);
3692
+ toolCallEntries.splice(i, 1);
3693
+ }
3694
+ }
3695
+ }
3696
+ const emittedCallCounts = /* @__PURE__ */ new Map();
3697
+ const excessDuplicateEntries = /* @__PURE__ */ new Set();
3698
+ for (const entry of toolCallEntries) {
3699
+ const key = `${entry.block.name}
3700
+ ${entry.partialArgs}`;
3701
+ const seen = (emittedCallCounts.get(key) ?? 0) + 1;
3702
+ emittedCallCounts.set(key, seen);
3703
+ if (seen > OPENAI_COMPAT_MAX_DUPLICATE_TOOL_CALLS) excessDuplicateEntries.add(entry);
3704
+ }
3705
+ if (excessDuplicateEntries.size > 0) {
3706
+ for (let i = toolCallEntries.length - 1; i >= 0; i--) {
3707
+ if (excessDuplicateEntries.has(toolCallEntries[i])) {
3708
+ droppedToolCallBlocks.add(toolCallEntries[i].block);
3709
+ toolCallEntries.splice(i, 1);
3710
+ }
3711
+ }
3712
+ }
3713
+ if (droppedToolCallBlocks.size > 0) {
3714
+ const unknownCount = droppedToolCallBlocks.size - excessDuplicateEntries.size;
3715
+ output.content = output.content.filter(
3716
+ (block) => block.type !== "toolCall" || !droppedToolCallBlocks.has(block)
3717
+ );
3718
+ const reasons = [];
3719
+ if (unknownCount > 0) {
3720
+ reasons.push(`${unknownCount} named tools that are not part of this request (samples: ${unknownNameSamples.join(", ")})`);
3721
+ }
3722
+ if (excessDuplicateEntries.size > 0) {
3723
+ reasons.push(`${excessDuplicateEntries.size} were exact duplicates of an earlier call in the same message`);
3724
+ }
3725
+ output.content.push({
3726
+ type: "text",
3727
+ text: `[dropped ${droppedToolCallBlocks.size} tool call${droppedToolCallBlocks.size === 1 ? "" : "s"}: ${reasons.join("; ")}. Re-issue only the intended calls.]`
3728
+ });
3729
+ }
3682
3730
  for (const { block, partialArgs, contentIndex } of toolCallEntries) {
3683
3731
  if (!block.name.trim()) {
3684
3732
  throw createProtocolError("OpenAI-compatible stream returned a tool call without a function name.");
@@ -3,7 +3,7 @@ import {
3
3
  EventStream,
4
4
  streamSimple,
5
5
  validateToolArguments
6
- } from "./chunk-O2DKMLNX.js";
6
+ } from "./chunk-OCEYHWVX.js";
7
7
 
8
8
  // ../../packages/agent-core/src/agent-loop.ts
9
9
  function createLoopErrorMessage(error, config, signal) {
@@ -6,8 +6,8 @@ import {
6
6
  bindToolCallerIdentity,
7
7
  createToolCallerIdentity,
8
8
  getToolCallerIdentity
9
- } from "./chunk-Y4CYXJR7.js";
10
- import "./chunk-O2DKMLNX.js";
9
+ } from "./chunk-YEUBQBOB.js";
10
+ import "./chunk-OCEYHWVX.js";
11
11
  import "./chunk-XXGYUYXI.js";
12
12
  import "./chunk-LZQXQOPJ.js";
13
13
  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-O2DKMLNX.js";
4
+ } from "./chunk-OCEYHWVX.js";
5
5
  import "./chunk-XXGYUYXI.js";
6
6
  import "./chunk-LZQXQOPJ.js";
7
7