@theokit/sdk 2.14.0 → 2.15.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.
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } from './errors-9yw4UQwX.cjs';
2
- export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-9yw4UQwX.cjs';
3
- import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-CpxLdAXc.cjs';
4
- export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-CpxLdAXc.cjs';
5
- import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-TMdc7gmo.cjs';
6
- export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage, D as SDKThinkingMessage, E as SDKToolUseMessage, F as SDKUserMessage, G as SDKUserMessageEvent, H as SendOptions, J as ShellCommand, K as ShellConversationTurn, L as ShellOutput, N as ShellOutputDeltaUpdate, O as StepCompletedUpdate, Q as StepStartedUpdate, T as StreamToCompletionResult, U as SummaryCompletedUpdate, V as SummaryStartedUpdate, W as SummaryUpdate, X as TextBlock, Y as TextDeltaUpdate, Z as ThinkingCompletedUpdate, _ as ThinkingDeltaUpdate, $ as ThinkingMessage, a0 as TokenDeltaUpdate, a1 as TokenUsage, a2 as ToolCall, a3 as ToolCallCompletedUpdate, a4 as ToolCallStartedUpdate, a5 as ToolResult, a6 as ToolUseBlock, a7 as TurnEndedUpdate, a8 as UserMessage, a9 as UserMessageAppendedUpdate } from './run-TMdc7gmo.cjs';
1
+ import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } from './errors-Bart0ptP.cjs';
2
+ export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-Bart0ptP.cjs';
3
+ import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-BxLSz1UH.cjs';
4
+ export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-BxLSz1UH.cjs';
5
+ import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-DXy_MVwz.cjs';
6
+ export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, D as DoomLoopThresholds, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage, E as SDKThinkingMessage, F as SDKToolUseMessage, G as SDKUserMessage, H as SDKUserMessageEvent, J as SendOptions, K as ShellCommand, L as ShellConversationTurn, N as ShellOutput, O as ShellOutputDeltaUpdate, Q as StepCompletedUpdate, T as StepStartedUpdate, U as StreamToCompletionResult, V as SummaryCompletedUpdate, W as SummaryStartedUpdate, X as SummaryUpdate, Y as TextBlock, Z as TextDeltaUpdate, _ as ThinkingCompletedUpdate, $ as ThinkingDeltaUpdate, a0 as ThinkingMessage, a1 as TokenDeltaUpdate, a2 as TokenUsage, a3 as ToolCall, a4 as ToolCallCompletedUpdate, a5 as ToolCallStartedUpdate, a6 as ToolResult, a7 as ToolUseBlock, a8 as TurnEndedUpdate, a9 as UserMessage, aa as UserMessageAppendedUpdate } from './run-DXy_MVwz.cjs';
7
7
  import * as zod from 'zod';
8
8
  import { ZodType, z } from 'zod';
9
9
 
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } from './errors-DFiY-NHK.js';
2
- export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-DFiY-NHK.js';
3
- import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-CL_9nfhQ.js';
4
- export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-CL_9nfhQ.js';
5
- import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-TMdc7gmo.js';
6
- export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage, D as SDKThinkingMessage, E as SDKToolUseMessage, F as SDKUserMessage, G as SDKUserMessageEvent, H as SendOptions, J as ShellCommand, K as ShellConversationTurn, L as ShellOutput, N as ShellOutputDeltaUpdate, O as StepCompletedUpdate, Q as StepStartedUpdate, T as StreamToCompletionResult, U as SummaryCompletedUpdate, V as SummaryStartedUpdate, W as SummaryUpdate, X as TextBlock, Y as TextDeltaUpdate, Z as ThinkingCompletedUpdate, _ as ThinkingDeltaUpdate, $ as ThinkingMessage, a0 as TokenDeltaUpdate, a1 as TokenUsage, a2 as ToolCall, a3 as ToolCallCompletedUpdate, a4 as ToolCallStartedUpdate, a5 as ToolResult, a6 as ToolUseBlock, a7 as TurnEndedUpdate, a8 as UserMessage, a9 as UserMessageAppendedUpdate } from './run-TMdc7gmo.js';
1
+ import { T as TheokitAgentError, B as BudgetOptions, a as BudgetHandle, b as BudgetSnapshot } from './errors-DJuuubJK.js';
2
+ export { A as AgentDisposedError, c as AgentRunError, d as AgentRunErrorCode, e as AuthenticationError, f as BudgetExceedEvent, g as BudgetExceededError, h as BudgetLimit, i as BudgetMode, j as BudgetScope, k as BudgetThresholdEvent, l as BudgetWindow, C as ConfigurationError, E as ErrorCode, m as ErrorMetadata, I as IntegrationNotConnectedError, n as InvalidTaskIdError, M as MemoryAdapterError, o as MemoryAdapterErrorCode, N as NetworkError, R as RateLimitError, p as TaskNotFoundError, U as UnknownAgentError, q as UnsupportedBudgetOperationError, r as UnsupportedRunOperationError, s as UnsupportedTaskOperationError, t as isTransientError } from './errors-DJuuubJK.js';
3
+ import { A as AgentOptions, L as LocalOptions, P as ProviderRoutingSettings, S as SystemPromptResolver, C as CloudOptions, M as MemorySettings, a as AgentDefinition, b as ContextSettings, c as PluginsSettings, d as SkillsSettings, e as SDKAgent, f as ListAgentsOptions, g as ListResult, h as SDKAgentInfo, G as GetAgentOptions, i as ListRunsOptions, j as GetRunOptions, k as AgentOperationOptions, l as ProviderProfile, m as Plugin, n as ConversationStorageAdapter, o as StoredMessage, B as BudgetTracker, p as MemoryProvider, q as MemoryId, r as PreToolCallDecision, s as SDKProvider } from './cron-DcaoP7aW.js';
4
+ export { t as ActiveMemoryPassArgs, u as ActiveMemoryPassResult, v as AgentMemory, w as BudgetCheck, x as BudgetTotal, y as BudgetUsageEvent, z as CloudEnv, D as CloudRepo, E as ContextBudget, F as ContextManagerKind, H as ContextSnapshot, I as ContextSource, J as ContextSourceStatus, K as Cron, N as CronCreateOptions, O as CronGetOptions, Q as CronJob, R as CronJobStatus, T as CronListOptions, U as CronOperationOptions, V as CronRunOptions, W as CronRuntime, X as CronSchedulerStatus, Y as CronStartOptions, Z as GoalEvent, _ as GoalOptions, $ as GoalResult, a0 as HookName, a1 as InvalidateCacheOptions, a2 as MemoryAdapter, a3 as MemoryAdapterCapabilities, a4 as MemoryContext, a5 as MemoryFact, a6 as MemoryProviderHandle, a7 as MemoryProviderInitOptions, a8 as MemoryRevision, a9 as MemoryToolSchema, aa as MemoryTurnMessage, ab as PersonalityPreset, ac as PluginContext, ad as PostAssistantReplyContext, ae as PreToolCallContext, af as PreUserSendContext, ag as PreUserSendResult, ah as ProviderCapability, ai as ProviderRoute, aj as RecordSessionSummaryArgs, ak as ResolvedProviderRoute, al as RunUntilIterator, am as SDKAgentPlugins, an as SDKAgentSkills, ao as SDKArtifact, ap as SDKContextManager, aq as SDKPluginMetadata, ar as SDKProvidersManager, as as SettingSource, at as SystemPromptContext, au as SystemPromptMemoryFact, av as SystemPromptSkillRef, aw as TelemetrySettings, ax as definePlugin } from './cron-DcaoP7aW.js';
5
+ import { R as RunResult, M as ModelSelection, C as CustomTool, a as McpServerConfig, b as Run, S as SDKMessage } from './run-DXy_MVwz.js';
6
+ export { A as AgentConversationTurn, c as AssistantMessage, d as ConversationStep, e as ConversationTurn, f as CostBreakdown, g as CostSource, h as CostStatus, D as DoomLoopThresholds, I as InteractionUpdate, i as McpAuthConfig, j as McpHttpServerConfig, k as McpOAuthConfig, l as McpStdioServerConfig, m as ModelParameterValue, P as PartialToolCallUpdate, n as RunErrorDetail, o as RunGitInfo, p as RunOperation, q as RunStatus, r as RunToCompletionOptions, s as RunToCompletionResult, t as SDKAssistantMessage, u as SDKImage, v as SDKImageDimension, w as SDKObjectDelta, x as SDKRequestMessage, y as SDKStatusMessage, z as SDKSystemMessage, B as SDKTaskMessage, E as SDKThinkingMessage, F as SDKToolUseMessage, G as SDKUserMessage, H as SDKUserMessageEvent, J as SendOptions, K as ShellCommand, L as ShellConversationTurn, N as ShellOutput, O as ShellOutputDeltaUpdate, Q as StepCompletedUpdate, T as StepStartedUpdate, U as StreamToCompletionResult, V as SummaryCompletedUpdate, W as SummaryStartedUpdate, X as SummaryUpdate, Y as TextBlock, Z as TextDeltaUpdate, _ as ThinkingCompletedUpdate, $ as ThinkingDeltaUpdate, a0 as ThinkingMessage, a1 as TokenDeltaUpdate, a2 as TokenUsage, a3 as ToolCall, a4 as ToolCallCompletedUpdate, a5 as ToolCallStartedUpdate, a6 as ToolResult, a7 as ToolUseBlock, a8 as TurnEndedUpdate, a9 as UserMessage, aa as UserMessageAppendedUpdate } from './run-DXy_MVwz.js';
7
7
  import * as zod from 'zod';
8
8
  import { ZodType, z } from 'zod';
9
9
 
package/dist/index.js CHANGED
@@ -2814,6 +2814,7 @@ function isEmptyRound(result) {
2814
2814
  return (result.result ?? "").trim() === "";
2815
2815
  }
2816
2816
  function classifyRound(result, round, maxRounds, emptyStreak) {
2817
+ if (result.stoppedByDoomLoop === true) return "no_progress";
2817
2818
  if (result.stoppedAtIterationLimit !== true) return "done";
2818
2819
  if (isEmptyRound(result) && emptyStreak >= 1) return "no_progress";
2819
2820
  if (round >= maxRounds) return "step_limit";
@@ -6979,6 +6980,7 @@ function applyScriptMetrics(base, script) {
6979
6980
  if (script.usage !== void 0) base.usage = script.usage;
6980
6981
  if (script.cost !== void 0) base.cost = script.cost;
6981
6982
  if (script.stoppedAtIterationLimit === true) base.stoppedAtIterationLimit = true;
6983
+ if (script.stoppedByDoomLoop === true) base.stoppedByDoomLoop = true;
6982
6984
  }
6983
6985
 
6984
6986
  // src/internal/runtime/cloud/cloud-run.ts
@@ -10730,6 +10732,93 @@ function evaluateBudgetGate(tracker) {
10730
10732
  }
10731
10733
  }
10732
10734
 
10735
+ // src/internal/agent-loop/doom-loop-tracker.ts
10736
+ init_errors();
10737
+ function createDoomLoopTracker(option) {
10738
+ if (option === false) return void 0;
10739
+ return new DoomLoopTracker(option);
10740
+ }
10741
+ var DEFAULT_CONFIG = { softThreshold: 3, hardThreshold: 5 };
10742
+ function assertValidThresholds(soft, hard) {
10743
+ for (const [label, value] of [
10744
+ ["softThreshold", soft],
10745
+ ["hardThreshold", hard]
10746
+ ]) {
10747
+ if (!Number.isInteger(value) || value < 1) {
10748
+ throw new ConfigurationError(
10749
+ `doomLoop.${label} must be a positive integer (received ${value}).`,
10750
+ { code: "invalid_doom_loop_threshold" }
10751
+ );
10752
+ }
10753
+ }
10754
+ }
10755
+ function sortKeys(value) {
10756
+ if (value === null || typeof value !== "object") return value;
10757
+ if (Array.isArray(value)) return value.map(sortKeys);
10758
+ const out = {};
10759
+ for (const key2 of Object.keys(value).sort()) {
10760
+ out[key2] = sortKeys(value[key2]);
10761
+ }
10762
+ return out;
10763
+ }
10764
+ function signatureOf(call) {
10765
+ const { input } = call;
10766
+ let inputSig;
10767
+ if (input === null || input === void 0) inputSig = "null";
10768
+ else if (typeof input !== "object") inputSig = String(input);
10769
+ else {
10770
+ try {
10771
+ inputSig = JSON.stringify(sortKeys(input)) ?? "null";
10772
+ } catch {
10773
+ inputSig = String(input);
10774
+ }
10775
+ }
10776
+ return `${call.name}\0${inputSig}`;
10777
+ }
10778
+ var DoomLoopTracker = class {
10779
+ #config;
10780
+ #lastSignature = "";
10781
+ #count = 0;
10782
+ constructor(config) {
10783
+ const softThreshold = config?.softThreshold ?? DEFAULT_CONFIG.softThreshold;
10784
+ const hardThreshold = config?.hardThreshold ?? DEFAULT_CONFIG.hardThreshold;
10785
+ assertValidThresholds(softThreshold, hardThreshold);
10786
+ this.#config = { softThreshold, hardThreshold };
10787
+ }
10788
+ inspect(call) {
10789
+ const signature = signatureOf(call);
10790
+ this.#count = signature === this.#lastSignature ? this.#count + 1 : 1;
10791
+ this.#lastSignature = signature;
10792
+ const count = this.#count;
10793
+ if (count >= this.#config.hardThreshold) {
10794
+ return {
10795
+ kind: "hard",
10796
+ message: `Detected ${count} consecutive identical calls to \`${call.name}\`; stopping to avoid a loop.`
10797
+ };
10798
+ }
10799
+ if (count === this.#config.softThreshold) {
10800
+ return {
10801
+ kind: "soft",
10802
+ message: `Detected ${count} consecutive identical calls to \`${call.name}\`; try a different approach.`
10803
+ };
10804
+ }
10805
+ return { kind: "ok" };
10806
+ }
10807
+ reset() {
10808
+ this.#lastSignature = "";
10809
+ this.#count = 0;
10810
+ }
10811
+ };
10812
+ function firstDoomLoopVerdict(tracker, calls) {
10813
+ let escalation = { kind: "ok" };
10814
+ for (const call of calls) {
10815
+ const v = tracker.inspect(call);
10816
+ if (v.kind === "hard") return v;
10817
+ if (v.kind === "soft" && escalation.kind === "ok") escalation = v;
10818
+ }
10819
+ return escalation;
10820
+ }
10821
+
10733
10822
  // src/internal/budget/usage-accumulator.ts
10734
10823
  var UsageAccumulator = class {
10735
10824
  input = 0;
@@ -10910,6 +10999,7 @@ async function initLoopContext(inputs) {
10910
10999
  tools,
10911
11000
  finalText: "",
10912
11001
  finalStatus: "finished",
11002
+ doomLoop: createDoomLoopTracker(inputs.doomLoop),
10913
11003
  usage: new UsageAccumulator(),
10914
11004
  nudgeAttempts: 0,
10915
11005
  stopFeedbackAttempts: 0,
@@ -11934,6 +12024,7 @@ async function runAgentLoop(inputs) {
11934
12024
  ctx.finalStatus = "error";
11935
12025
  }
11936
12026
  sendSpan?.setAttribute("status", ctx.finalStatus);
12027
+ if (ctx.stoppedByDoomLoop === true) sendSpan?.setAttribute("stoppedByDoomLoop", true);
11937
12028
  if (inputs.telemetry?.includeContent === true && ctx.finalText.length > 0) {
11938
12029
  sendSpan?.addEvent("response", { content: ctx.finalText });
11939
12030
  }
@@ -11960,7 +12051,8 @@ async function runAgentLoop(inputs) {
11960
12051
  ...usage !== void 0 ? { usage } : {},
11961
12052
  ...cost !== void 0 ? { cost } : {},
11962
12053
  ...ctx.error !== void 0 ? { error: ctx.error } : {},
11963
- ...ctx.stoppedAtIterationLimit === true ? { stoppedAtIterationLimit: true } : {}
12054
+ ...ctx.stoppedAtIterationLimit === true ? { stoppedAtIterationLimit: true } : {},
12055
+ ...ctx.stoppedByDoomLoop === true ? { stoppedByDoomLoop: true } : {}
11964
12056
  };
11965
12057
  } finally {
11966
12058
  if (ctxRef !== void 0 && ctxRef.memoryProviderHandle !== void 0 && inputs.memoryProvider !== void 0) {
@@ -12119,8 +12211,26 @@ async function continueOrTerminate(inputs, ctx, llmOutput) {
12119
12211
  }
12120
12212
  }
12121
12213
  pushToolConversationSteps(ctx, llmOutput.toolCalls, toolResults);
12214
+ if (await inspectDoomLoop(inputs, ctx, llmOutput.toolCalls) === "stop") return "done";
12122
12215
  return handleToolErrorContinuation(inputs, ctx, toolResults);
12123
12216
  }
12217
+ async function inspectDoomLoop(inputs, ctx, toolCalls) {
12218
+ if (ctx.doomLoop === void 0) return "continue";
12219
+ const verdict = firstDoomLoopVerdict(ctx.doomLoop, toolCalls);
12220
+ if (verdict.kind === "hard") {
12221
+ ctx.stoppedByDoomLoop = true;
12222
+ await emitAssistantTextStep(
12223
+ inputs,
12224
+ ctx,
12225
+ verdict.message ?? "Stopped: repeated identical tool calls made no progress."
12226
+ );
12227
+ return "stop";
12228
+ }
12229
+ if (verdict.kind === "soft") {
12230
+ ctx.messages.push({ role: "user", content: [{ type: "text", text: verdict.message ?? "" }] });
12231
+ }
12232
+ return "continue";
12233
+ }
12124
12234
 
12125
12235
  // src/internal/llm/fallback-client.ts
12126
12236
  init_errors();
@@ -14681,6 +14791,8 @@ function buildLoopInputs(options, runId, userText) {
14681
14791
  // M1-2: per-send iteration ceiling (validated above). The loop reads
14682
14792
  // inputs.maxIterations (default 8 when unset).
14683
14793
  ...maxIterations !== void 0 ? { maxIterations } : {},
14794
+ // Doom-loop guard config (default on; `false` disables, object tunes thresholds).
14795
+ ...options.sendOptions.doomLoop !== void 0 ? { doomLoop: options.sendOptions.doomLoop } : {},
14684
14796
  // D315-D317 — tool lifecycle hooks (cost tracking + audit + retry/alert)
14685
14797
  ...options.agentOptions.onToolStart !== void 0 ? { onToolStart: options.agentOptions.onToolStart } : {},
14686
14798
  ...options.agentOptions.onToolEnd !== void 0 ? { onToolEnd: options.agentOptions.onToolEnd } : {},
@@ -14813,6 +14925,7 @@ var RealLocalRun = class extends FixtureRunBase {
14813
14925
  if (output.usage !== void 0) this.script.usage = output.usage;
14814
14926
  if (output.cost !== void 0) this.script.cost = output.cost;
14815
14927
  if (output.stoppedAtIterationLimit === true) this.script.stoppedAtIterationLimit = true;
14928
+ if (output.stoppedByDoomLoop === true) this.script.stoppedByDoomLoop = true;
14816
14929
  if (output.error !== void 0 && this.script.errorDetail === void 0) {
14817
14930
  this.script.errorDetail = {
14818
14931
  message: output.error.message,