hammer-ai 0.2.8 → 0.2.10

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.ts CHANGED
@@ -2044,15 +2044,6 @@ declare function buildValidationErrorMessage(zodError: unknown): string;
2044
2044
  */
2045
2045
  declare function buildNoStructuredResponseFoundError(): string;
2046
2046
 
2047
- /**
2048
- * Build a user-feedback message to send to the LLM when its response failed
2049
- * to parse. Gives more actionable guidance than a generic "parse failed" message.
2050
- *
2051
- * @param content The raw LLM content that failed to parse
2052
- * @param zodError Optional Zod validation error for field-specific feedback
2053
- * @returns A feedback string to send as a user message
2054
- */
2055
- declare function buildParseFeedback(_content: string, zodError?: unknown): string;
2056
2047
  interface ParseResponseWithRecoveryOptions extends ParseAgentResponseOptions {
2057
2048
  /**
2058
2049
  * The LLM's `finishReason` string. When `"length"`, Tier 2 truncation
@@ -2404,4 +2395,4 @@ declare function runStructuredLLMCompaction<TMessage extends MemoryMessage, TSta
2404
2395
  parseState: (obj: Record<string, unknown>) => TState | null;
2405
2396
  }): Promise<TState | null>;
2406
2397
 
2407
- export { AGENT_MACHINE_STATES, AgentLoop, type AgentLoopCallbacks, type AgentLoopDeps, type AgentMachineContext, type AgentMachineEvent, type AgentMachineState, type AgentMemoryCitation, type AgentMemoryConstraint, type AgentMemoryEvidence, type AgentMemoryFactoryOverrides, AgentMemoryLayer, type AgentMemoryLayerConfig, type AgentMemoryLogger, type AgentMemoryNote, type AgentMemoryTask, type AgentMessage, type AgentPhase, type AgentState, ApiError, type BackgroundBashAction, BackgroundBashRunCommand, BaseMemoryLayer, BaseValidationEnforcer, BashRunCommand, type BuildMemoryCompactionPromptOptions, CODE_QUALITY_RULE_LINE, CharTokenEstimator, type ChatMessage, type CommandRuntime, type CommandTargetInfo, type CompactionCursor, type CompactionLLMClient, type ConversationAdapter, type ConversationSink, type CreateWebRuntimeSetupOptions, DEFAULT_AGENT_FALLBACK_SYSTEM_PROMPT, DEFAULT_ALLOWED_RUN_TARGETS, DEFAULT_RUN_COMMAND_REGISTRY, DEFAULT_THREAD_AUTO_SCROLL_BOTTOM_THRESHOLD, DEFAULT_TOOL_MEMORY_EXTRACTOR, ERROR_RECOVERY_RULE_LINE, ERROR_TRUNCATED_RESPONSE, type EnforcerResult, type ExecuteWebLoopRunOptions, type FetchLike, type FetchResponseLike, type HammerAgentConfig, type HammerAgentProviderPreset, INCREMENTAL_TESTING_RULE_LINE, JUST_BASH_SCRIPT_EXECUTION_RESTRICTION_LINES, JUST_BASH_SHELL_NATIVE_WORKFLOW_COMMAND_EXAMPLES, LLMClient, type LLMClientResponse, type LLMProviderConfig, type LLMRequest, type LLMRequestOptions, type LLMResponse, LLMResponseSchema, type LoopOutcome, MAX_TOOL_RESULT_CHARS, type MemoryMessage, type MemoryProvenance, type MemoryStorage, PORT_CONFLICT_RULE_LINE, type ParseAgentResponseOptions, type ParsedAgentResponse, type ParsedBackgroundBashCommand, type ParsedStepInput, PendingAgentMessageBuffer, type PersistedMemoryData, type ProviderName, ProxyTool, type ProxyToolExecutor, ROOT_CAUSES_RULE_LINE, type RawMessage, RunCommand, type RunCommandParseResult, type RunCommandPromptAvailability, RunCommandRegistry, type RunInvocationTarget, type RuntimeController, type RuntimeSnapshotUpdater, type RuntimeStore, type RuntimeSubscriber, SHARED_TOOL_CALL_EXAMPLE_LINES, SHARED_TOOL_USAGE_RULE, SINGLE_TOOL_CALL_RUN_LINE_EXAMPLE, SKILL_INVOKE_READ_RULE_LINE, STANDARD_TOOL_CALL_FORMAT_RULES, SUPPORTED_RUN_TARGETS, type SkillSummaryLike, type StepResult, type StreamCallbacks, StreamingToolParser, type StreamingToolParserCallbacks, type SystemPromptBuildContext, type SystemPromptCustomizer, type SystemPromptSections, TODO_LIST_FIRST_RESPONSE_RULE_LINE, TOOL_CALL_SEPARATOR_RULE, type TodoItem, type TodoStatus, type TokenEstimator, Tool, type ToolCall, ToolCallSchema, type ToolDataPrimitive, type ToolDataSchema, type ToolDataValue, type ToolDefinition, type ToolDefinitionMetadata, type ToolExecutionResult, type ToolLike, ToolLoopAgentRuntime, type ToolLoopAgentRuntimeDeps, type ToolLoopRuntimeExecuteStepResult, type ToolLoopRuntimeHooks, type ToolLoopRuntimeInfrastructure, type ToolLoopRuntimeLLMRequest, type ToolLoopRuntimeLLMResponse, type ToolLoopRuntimeRunStepOptions, type ToolLoopRuntimeRunStepResult, type ToolLoopRuntimeSetup, type ToolLoopRuntimeStepContext, type ToolLoopStepExecutionResult, type ToolLoopStepExecutorCallbacks, type ToolLoopStepExecutorOptions, type ToolLoopStepExecutorResponse, type ToolMemoryCitationKind, type ToolMemoryEvidenceKind, type ToolMemoryEvidencePolicy, type ToolMemoryExtractor, type ToolMemoryMetadata, type ToolMemoryNoteKind, type ToolMemoryNotePolicy, type ToolMemoryNoteScope, type ToolMetadata, type ToolParameterDefinition, ToolRegistry, type ToolRegistryBeforeExecuteContext, type ToolRegistryMissingToolContext, type ToolRegistryOptions, type ToolResult, ToolRunCommand, type ToolSchema, type TruncatedToolInfo, VALIDATE_AFTER_CHANGES_RULE_LINE, type WebSearchToolActionInput, WebToolLoopAgentRuntime, type WebToolLoopAgentRuntimeConstructorOptions, type WebToolLoopRuntimeStateLike, WebValidationEnforcer, type WorkspaceCodingStaticRulesOptions, agentMachine, applyIdleWebAgentState, applyInitialWebAgentRunState, buildAgentIdentityLine, buildAgentSystemPrompt, buildCompactionEntry, buildCoreStaticRules, buildNoStructuredResponseFoundError, buildParseFeedback, buildSkillAwareStaticContext, buildSkillsSection, buildStepUserMessage, buildToolLogRevealFrames, buildToolUsageExample, buildValidationErrorMessage, buildWebRuntimeRules, buildWorkspaceCodingStaticRules, canonicalizeCompactionText, coerceToolCallToDefinition, configure, containsStandaloneStructuredInvocationStart, createAgentMemoryLayer, createAppendToolsSectionCustomizer, createBackgroundBashDefinition, createConversationSink, createCustomRunCommandRegistry, createInitialWebAgentState, createRunCommandRuntimeBindings, createRuntimeStore, createToolAgentMessage, createToolRegistry, createToolsSectionOverrideCustomizer, createWebAgentMessageIdGenerator, createWebSearchToolActions, createWebToolLoopCallbacks, decodeEscapedShellText, defineRuntimeController, enrichToolResultWithUnixMetadata, executeBackgroundUnixCommandString, executeToolCallWithRunCommands, executeToolLoopStep, executeToolSafe, executeUnixCommandString, extractPrimaryCommandMetadata, extractTruncatedToolInfo, formatToolCallAsUnixCommand, formatToolDefinitions, formatToolResultMessage, formatToolsSection, formatUnixToolSurface, formatZodValidationError, getDiagnosticSummaryLine, getProviderConfig, getRunCommandPromptAvailability, getToolLogSummaryLine, isBackgroundBashToolCall, isBashToolCall, limitEntriesByRecency, machineStateToWebAgentPhase, mapConversationRoleToAgentRole, parseAgentResponse, parseResponseWithRecovery, parseStructuredAgentText, parseToolResultMessage, parseUnixToolCommand, readDiagnosticLevel, readDiagnosticSource, resolveToolDefinitionForInvocation, runStructuredLLMCompaction, selectLatestByKey, shouldAutoScrollThread, shouldSkipStepUserMessage, stripDiagnosticMessagePrefix, suppressWebValidationLog, tokenizeUnixCommand, truncateToolResult };
2398
+ export { AGENT_MACHINE_STATES, AgentLoop, type AgentLoopCallbacks, type AgentLoopDeps, type AgentMachineContext, type AgentMachineEvent, type AgentMachineState, type AgentMemoryCitation, type AgentMemoryConstraint, type AgentMemoryEvidence, type AgentMemoryFactoryOverrides, AgentMemoryLayer, type AgentMemoryLayerConfig, type AgentMemoryLogger, type AgentMemoryNote, type AgentMemoryTask, type AgentMessage, type AgentPhase, type AgentState, ApiError, type BackgroundBashAction, BackgroundBashRunCommand, BaseMemoryLayer, BaseValidationEnforcer, BashRunCommand, type BuildMemoryCompactionPromptOptions, CODE_QUALITY_RULE_LINE, CharTokenEstimator, type ChatMessage, type CommandRuntime, type CommandTargetInfo, type CompactionCursor, type CompactionLLMClient, type ConversationAdapter, type ConversationSink, type CreateWebRuntimeSetupOptions, DEFAULT_AGENT_FALLBACK_SYSTEM_PROMPT, DEFAULT_ALLOWED_RUN_TARGETS, DEFAULT_RUN_COMMAND_REGISTRY, DEFAULT_THREAD_AUTO_SCROLL_BOTTOM_THRESHOLD, DEFAULT_TOOL_MEMORY_EXTRACTOR, ERROR_RECOVERY_RULE_LINE, ERROR_TRUNCATED_RESPONSE, type EnforcerResult, type ExecuteWebLoopRunOptions, type FetchLike, type FetchResponseLike, type HammerAgentConfig, type HammerAgentProviderPreset, INCREMENTAL_TESTING_RULE_LINE, JUST_BASH_SCRIPT_EXECUTION_RESTRICTION_LINES, JUST_BASH_SHELL_NATIVE_WORKFLOW_COMMAND_EXAMPLES, LLMClient, type LLMClientResponse, type LLMProviderConfig, type LLMRequest, type LLMRequestOptions, type LLMResponse, LLMResponseSchema, type LoopOutcome, MAX_TOOL_RESULT_CHARS, type MemoryMessage, type MemoryProvenance, type MemoryStorage, PORT_CONFLICT_RULE_LINE, type ParseAgentResponseOptions, type ParsedAgentResponse, type ParsedBackgroundBashCommand, type ParsedStepInput, PendingAgentMessageBuffer, type PersistedMemoryData, type ProviderName, ProxyTool, type ProxyToolExecutor, ROOT_CAUSES_RULE_LINE, type RawMessage, RunCommand, type RunCommandParseResult, type RunCommandPromptAvailability, RunCommandRegistry, type RunInvocationTarget, type RuntimeController, type RuntimeSnapshotUpdater, type RuntimeStore, type RuntimeSubscriber, SHARED_TOOL_CALL_EXAMPLE_LINES, SHARED_TOOL_USAGE_RULE, SINGLE_TOOL_CALL_RUN_LINE_EXAMPLE, SKILL_INVOKE_READ_RULE_LINE, STANDARD_TOOL_CALL_FORMAT_RULES, SUPPORTED_RUN_TARGETS, type SkillSummaryLike, type StepResult, type StreamCallbacks, StreamingToolParser, type StreamingToolParserCallbacks, type SystemPromptBuildContext, type SystemPromptCustomizer, type SystemPromptSections, TODO_LIST_FIRST_RESPONSE_RULE_LINE, TOOL_CALL_SEPARATOR_RULE, type TodoItem, type TodoStatus, type TokenEstimator, Tool, type ToolCall, ToolCallSchema, type ToolDataPrimitive, type ToolDataSchema, type ToolDataValue, type ToolDefinition, type ToolDefinitionMetadata, type ToolExecutionResult, type ToolLike, ToolLoopAgentRuntime, type ToolLoopAgentRuntimeDeps, type ToolLoopRuntimeExecuteStepResult, type ToolLoopRuntimeHooks, type ToolLoopRuntimeInfrastructure, type ToolLoopRuntimeLLMRequest, type ToolLoopRuntimeLLMResponse, type ToolLoopRuntimeRunStepOptions, type ToolLoopRuntimeRunStepResult, type ToolLoopRuntimeSetup, type ToolLoopRuntimeStepContext, type ToolLoopStepExecutionResult, type ToolLoopStepExecutorCallbacks, type ToolLoopStepExecutorOptions, type ToolLoopStepExecutorResponse, type ToolMemoryCitationKind, type ToolMemoryEvidenceKind, type ToolMemoryEvidencePolicy, type ToolMemoryExtractor, type ToolMemoryMetadata, type ToolMemoryNoteKind, type ToolMemoryNotePolicy, type ToolMemoryNoteScope, type ToolMetadata, type ToolParameterDefinition, ToolRegistry, type ToolRegistryBeforeExecuteContext, type ToolRegistryMissingToolContext, type ToolRegistryOptions, type ToolResult, ToolRunCommand, type ToolSchema, type TruncatedToolInfo, VALIDATE_AFTER_CHANGES_RULE_LINE, type WebSearchToolActionInput, WebToolLoopAgentRuntime, type WebToolLoopAgentRuntimeConstructorOptions, type WebToolLoopRuntimeStateLike, WebValidationEnforcer, type WorkspaceCodingStaticRulesOptions, agentMachine, applyIdleWebAgentState, applyInitialWebAgentRunState, buildAgentIdentityLine, buildAgentSystemPrompt, buildCompactionEntry, buildCoreStaticRules, buildNoStructuredResponseFoundError, buildSkillAwareStaticContext, buildSkillsSection, buildStepUserMessage, buildToolLogRevealFrames, buildToolUsageExample, buildValidationErrorMessage, buildWebRuntimeRules, buildWorkspaceCodingStaticRules, canonicalizeCompactionText, coerceToolCallToDefinition, configure, containsStandaloneStructuredInvocationStart, createAgentMemoryLayer, createAppendToolsSectionCustomizer, createBackgroundBashDefinition, createConversationSink, createCustomRunCommandRegistry, createInitialWebAgentState, createRunCommandRuntimeBindings, createRuntimeStore, createToolAgentMessage, createToolRegistry, createToolsSectionOverrideCustomizer, createWebAgentMessageIdGenerator, createWebSearchToolActions, createWebToolLoopCallbacks, decodeEscapedShellText, defineRuntimeController, enrichToolResultWithUnixMetadata, executeBackgroundUnixCommandString, executeToolCallWithRunCommands, executeToolLoopStep, executeToolSafe, executeUnixCommandString, extractPrimaryCommandMetadata, extractTruncatedToolInfo, formatToolCallAsUnixCommand, formatToolDefinitions, formatToolResultMessage, formatToolsSection, formatUnixToolSurface, formatZodValidationError, getDiagnosticSummaryLine, getProviderConfig, getRunCommandPromptAvailability, getToolLogSummaryLine, isBackgroundBashToolCall, isBashToolCall, limitEntriesByRecency, machineStateToWebAgentPhase, mapConversationRoleToAgentRole, parseAgentResponse, parseResponseWithRecovery, parseStructuredAgentText, parseToolResultMessage, parseUnixToolCommand, readDiagnosticLevel, readDiagnosticSource, resolveToolDefinitionForInvocation, runStructuredLLMCompaction, selectLatestByKey, shouldAutoScrollThread, shouldSkipStepUserMessage, stripDiagnosticMessagePrefix, suppressWebValidationLog, tokenizeUnixCommand, truncateToolResult };
package/dist/index.js CHANGED
@@ -168,19 +168,6 @@ var LLMResponseSchema = z.object({
168
168
  }).strict();
169
169
 
170
170
  // src/llm-client.ts
171
- function shouldOmitTemperature(config) {
172
- return config.model === "kimi-k2.5";
173
- }
174
- function buildChatPayload(config, basePayload) {
175
- const payload = { ...basePayload };
176
- if (shouldOmitTemperature(config)) {
177
- delete payload.temperature;
178
- }
179
- if (config.enableThinking !== void 0) {
180
- payload.enable_thinking = config.enableThinking;
181
- }
182
- return payload;
183
- }
184
171
  var LLMClient = class {
185
172
  config;
186
173
  constructor(config) {
@@ -213,7 +200,7 @@ var LLMClient = class {
213
200
  presencePenalty = 0,
214
201
  signal
215
202
  } = options;
216
- const payload = buildChatPayload(this.config, {
203
+ const payload = {
217
204
  model: this.config.model,
218
205
  messages,
219
206
  temperature,
@@ -221,7 +208,13 @@ var LLMClient = class {
221
208
  frequency_penalty: frequencyPenalty,
222
209
  presence_penalty: presencePenalty,
223
210
  stream
224
- });
211
+ };
212
+ if (this.config.model === "kimi-k2.5") {
213
+ delete payload.temperature;
214
+ }
215
+ if (this.config.enableThinking !== void 0) {
216
+ payload.enable_thinking = this.config.enableThinking;
217
+ }
225
218
  const headers = {
226
219
  "Content-Type": "application/json",
227
220
  Authorization: `Bearer ${this.config.apiKey}`,
@@ -239,7 +232,7 @@ var LLMClient = class {
239
232
  }
240
233
  if (attempt > 1) {
241
234
  log(`Retry attempt ${attempt}/${maxRetries}\u2026`, "warn");
242
- await sleep(1e3 * attempt);
235
+ await new Promise((r) => setTimeout(r, 1e3 * attempt));
243
236
  }
244
237
  const controller = new AbortController();
245
238
  const abortFetch = () => {
@@ -257,7 +250,7 @@ var LLMClient = class {
257
250
  if (!response.ok) {
258
251
  const errorText = await response.text();
259
252
  const err = new ApiError(response.status, errorText);
260
- if (isRetryableStatus(response.status) && attempt < maxRetries) {
253
+ if ((response.status === 429 || response.status === 500 || response.status === 502 || response.status === 503 || response.status === 408) && attempt < maxRetries) {
261
254
  log(`Transient HTTP ${response.status}. Retrying\u2026`, "warn");
262
255
  lastError = err;
263
256
  continue;
@@ -455,9 +448,6 @@ var LLMClient = class {
455
448
  });
456
449
  try {
457
450
  await streamPromise;
458
- } catch (err) {
459
- if (err.message?.includes("getFirstChunkTimeout()")) throw err;
460
- throw err;
461
451
  } finally {
462
452
  cleanup();
463
453
  signal?.removeEventListener("abort", abortStream);
@@ -483,9 +473,6 @@ var ApiError = class extends Error {
483
473
  }
484
474
  status;
485
475
  };
486
- function isRetryableStatus(status) {
487
- return status === 429 || status === 500 || status === 502 || status === 503 || status === 408;
488
- }
489
476
  function isNetworkError(err) {
490
477
  const code = err.code ?? err.cause?.code ?? "";
491
478
  return code === "ENOTFOUND" || code === "ETIMEDOUT" || code === "ECONNREFUSED" || code === "UND_ERR_CONNECT_TIMEOUT" || typeof err.message === "string" && err.message.includes("fetch failed");
@@ -506,9 +493,6 @@ function createAbortError(reason) {
506
493
  error.name = "AbortError";
507
494
  return error;
508
495
  }
509
- function sleep(ms) {
510
- return new Promise((r) => setTimeout(r, ms));
511
- }
512
496
  var AGENT_MACHINE_STATES = [
513
497
  "idle",
514
498
  "prompting",
@@ -3575,12 +3559,6 @@ function shouldPreferBashToolLogRecovery(current, recovered) {
3575
3559
  }
3576
3560
  return currentCommand !== recoveredCommand && (currentToolCall.truncated === true || /\n\[(?:TOOL_LOG|stderr|meta|exit):?/i.test(currentCommand) || /\n\[(?:stderr|meta|exit)\]/i.test(currentCommand));
3577
3561
  }
3578
- function buildParseFeedback(_content, zodError) {
3579
- if (zodError) {
3580
- return buildValidationErrorMessage(zodError);
3581
- }
3582
- return buildNoStructuredResponseFoundError();
3583
- }
3584
3562
  function looksLikeStandaloneControlSegment(content, allowedRunTargets) {
3585
3563
  return containsStandaloneStructuredInvocationStart(content, allowedRunTargets);
3586
3564
  }
@@ -4561,20 +4539,6 @@ function buildCompactionEntry(options) {
4561
4539
  createMemoryMetadata(options.provenance)
4562
4540
  );
4563
4541
  }
4564
- function sanitizeMemoryProvenance(value, fallback) {
4565
- if (!value || typeof value !== "object") {
4566
- return fallback;
4567
- }
4568
- const candidate = value;
4569
- const source = typeof candidate.source === "string" ? candidate.source : void 0;
4570
- if (!source || !MEMORY_PROVENANCE_SOURCES.has(source)) {
4571
- return fallback;
4572
- }
4573
- return {
4574
- source,
4575
- detail: typeof candidate.detail === "string" ? candidate.detail : fallback.detail
4576
- };
4577
- }
4578
4542
  function cleanCompactionText(text) {
4579
4543
  return text.trim().replace(/\s+/g, " ").replace(/[.?!:;]+$/, "");
4580
4544
  }
@@ -4623,45 +4587,35 @@ function formatMemoryMetadataTag(metadata) {
4623
4587
  const detail = metadata.provenance.detail ? `/${metadata.provenance.detail}` : "";
4624
4588
  return ` [${metadata.provenance.source}${detail}]`;
4625
4589
  }
4626
- function sanitizeCompactionEntries(input, options) {
4627
- if (!Array.isArray(input)) {
4628
- return [];
4629
- }
4630
- return input.flatMap((value) => {
4631
- if (typeof value === "string") {
4632
- const entry2 = options.fromString?.(value);
4633
- return entry2 ? [entry2] : [];
4634
- }
4635
- if (!value || typeof value !== "object") {
4636
- return [];
4637
- }
4638
- const entry = options.fromObject?.(value);
4639
- return entry ? [entry] : [];
4640
- });
4641
- }
4642
4590
  function createEntrySanitizer(options) {
4643
- return (input, fallbackTurn, fallbackProvenance = options.defaultProvenance) => sanitizeCompactionEntries(input, {
4644
- fromString: options.fromString ? (value) => options.fromString(value, {
4645
- turn: fallbackTurn,
4646
- provenance: fallbackProvenance
4647
- }) : void 0,
4648
- fromObject: (value) => options.fromObject(value, {
4649
- turn: options.getTurn?.(value, fallbackTurn) ?? (typeof value.turn === "number" && Number.isFinite(value.turn) ? value.turn : fallbackTurn),
4650
- provenance: sanitizeMemoryProvenance(
4651
- options.getProvenance?.(value) ?? value.provenance,
4652
- fallbackProvenance
4653
- )
4654
- })
4655
- });
4656
- }
4657
- function parseCompactionJsonObject(raw) {
4658
- try {
4659
- const cleaned = raw.replace(/```json\n?|```\n?/gi, "").trim();
4660
- const parsed = JSON.parse(cleaned);
4661
- return parsed && typeof parsed === "object" ? parsed : null;
4662
- } catch {
4663
- return null;
4664
- }
4591
+ return (input, fallbackTurn, fallbackProvenance = options.defaultProvenance) => {
4592
+ if (!Array.isArray(input)) return [];
4593
+ return input.flatMap((value) => {
4594
+ if (typeof value === "string") {
4595
+ const entry2 = options.fromString?.(value, { turn: fallbackTurn, provenance: fallbackProvenance });
4596
+ return entry2 ? [entry2] : [];
4597
+ }
4598
+ if (!value || typeof value !== "object") return [];
4599
+ const obj = value;
4600
+ const rawProv = options.getProvenance?.(obj) ?? obj.provenance;
4601
+ let provenance = fallbackProvenance;
4602
+ if (rawProv && typeof rawProv === "object") {
4603
+ const c = rawProv;
4604
+ const source = typeof c.source === "string" ? c.source : void 0;
4605
+ if (source && MEMORY_PROVENANCE_SOURCES.has(source)) {
4606
+ provenance = {
4607
+ source,
4608
+ detail: typeof c.detail === "string" ? c.detail : fallbackProvenance.detail
4609
+ };
4610
+ }
4611
+ }
4612
+ const entry = options.fromObject(obj, {
4613
+ turn: options.getTurn?.(obj, fallbackTurn) ?? (typeof obj.turn === "number" && Number.isFinite(obj.turn) ? obj.turn : fallbackTurn),
4614
+ provenance
4615
+ });
4616
+ return entry ? [entry] : [];
4617
+ });
4618
+ };
4665
4619
  }
4666
4620
  async function runStructuredLLMCompaction(options) {
4667
4621
  if (!options.client) {
@@ -4681,7 +4635,14 @@ async function runStructuredLLMCompaction(options) {
4681
4635
  maxTokens: options.maxTokens ?? 4096,
4682
4636
  stream: false
4683
4637
  });
4684
- const parsed = parseCompactionJsonObject(result.content);
4638
+ let parsed = null;
4639
+ try {
4640
+ const cleaned = result.content.replace(/```json\n?|```\n?/gi, "").trim();
4641
+ const obj = JSON.parse(cleaned);
4642
+ parsed = obj && typeof obj === "object" ? obj : null;
4643
+ } catch {
4644
+ parsed = null;
4645
+ }
4685
4646
  return parsed ? options.parseState(parsed) : null;
4686
4647
  }
4687
4648
 
@@ -6704,7 +6665,7 @@ ${JSON.stringify(request.messages, null, 2)}`
6704
6665
  }
6705
6666
  if (!stepParsed) {
6706
6667
  const parseError = new Error(
6707
- buildParseFeedback(response.content)
6668
+ buildNoStructuredResponseFoundError()
6708
6669
  );
6709
6670
  parseError.isWebParseFailure = true;
6710
6671
  parseError.rawContent = response.content;
@@ -7426,6 +7387,6 @@ async function executeToolLoopStep(options) {
7426
7387
  };
7427
7388
  }
7428
7389
 
7429
- export { AGENT_MACHINE_STATES, AgentLoop, AgentMemoryLayer, ApiError, BackgroundBashRunCommand, BaseMemoryLayer, BaseValidationEnforcer, BashRunCommand, CODE_QUALITY_RULE_LINE, CharTokenEstimator, DEFAULT_AGENT_FALLBACK_SYSTEM_PROMPT, DEFAULT_ALLOWED_RUN_TARGETS, DEFAULT_RUN_COMMAND_REGISTRY, DEFAULT_THREAD_AUTO_SCROLL_BOTTOM_THRESHOLD, DEFAULT_TOOL_MEMORY_EXTRACTOR, ERROR_RECOVERY_RULE_LINE, ERROR_TRUNCATED_RESPONSE, INCREMENTAL_TESTING_RULE_LINE, JUST_BASH_SCRIPT_EXECUTION_RESTRICTION_LINES, JUST_BASH_SHELL_NATIVE_WORKFLOW_COMMAND_EXAMPLES, LLMClient, LLMResponseSchema, MAX_TOOL_RESULT_CHARS, PORT_CONFLICT_RULE_LINE, PendingAgentMessageBuffer, ProxyTool, ROOT_CAUSES_RULE_LINE, RunCommand, RunCommandRegistry, SHARED_TOOL_CALL_EXAMPLE_LINES, SHARED_TOOL_USAGE_RULE, SINGLE_TOOL_CALL_RUN_LINE_EXAMPLE, SKILL_INVOKE_READ_RULE_LINE, STANDARD_TOOL_CALL_FORMAT_RULES, SUPPORTED_RUN_TARGETS, StreamingToolParser, TODO_LIST_FIRST_RESPONSE_RULE_LINE, TOOL_CALL_SEPARATOR_RULE, Tool, ToolCallSchema, ToolLoopAgentRuntime, ToolRegistry, ToolRunCommand, VALIDATE_AFTER_CHANGES_RULE_LINE, WebToolLoopAgentRuntime, WebValidationEnforcer, agentMachine, applyIdleWebAgentState, applyInitialWebAgentRunState, buildAgentIdentityLine, buildAgentSystemPrompt, buildCompactionEntry, buildCoreStaticRules, buildNoStructuredResponseFoundError, buildParseFeedback, buildSkillAwareStaticContext, buildSkillsSection, buildStepUserMessage, buildToolLogRevealFrames, buildToolUsageExample, buildValidationErrorMessage, buildWebRuntimeRules, buildWorkspaceCodingStaticRules, canonicalizeCompactionText, coerceToolCallToDefinition, configure, containsStandaloneStructuredInvocationStart, createAgentMemoryLayer, createAppendToolsSectionCustomizer, createBackgroundBashDefinition, createConversationSink, createCustomRunCommandRegistry, createInitialWebAgentState, createRunCommandRuntimeBindings, createRuntimeStore, createToolAgentMessage, createToolRegistry, createToolsSectionOverrideCustomizer, createWebAgentMessageIdGenerator, createWebSearchToolActions, createWebToolLoopCallbacks, decodeEscapedShellText, defineRuntimeController, enrichToolResultWithUnixMetadata, executeBackgroundUnixCommandString, executeToolCallWithRunCommands, executeToolLoopStep, executeToolSafe, executeUnixCommandString, extractPrimaryCommandMetadata, extractTruncatedToolInfo, formatToolCallAsUnixCommand, formatToolDefinitions, formatToolResultMessage, formatToolsSection, formatUnixToolSurface, formatZodValidationError, getDiagnosticSummaryLine, getProviderConfig, getRunCommandPromptAvailability, getToolLogSummaryLine, isBackgroundBashToolCall, isBashToolCall, limitEntriesByRecency, machineStateToWebAgentPhase, mapConversationRoleToAgentRole, parseAgentResponse, parseResponseWithRecovery, parseStructuredAgentText, parseToolResultMessage, parseUnixToolCommand, readDiagnosticLevel, readDiagnosticSource, resolveToolDefinitionForInvocation, runStructuredLLMCompaction, selectLatestByKey, shouldAutoScrollThread, shouldSkipStepUserMessage, stripDiagnosticMessagePrefix, suppressWebValidationLog, tokenizeUnixCommand, truncateToolResult };
7390
+ export { AGENT_MACHINE_STATES, AgentLoop, AgentMemoryLayer, ApiError, BackgroundBashRunCommand, BaseMemoryLayer, BaseValidationEnforcer, BashRunCommand, CODE_QUALITY_RULE_LINE, CharTokenEstimator, DEFAULT_AGENT_FALLBACK_SYSTEM_PROMPT, DEFAULT_ALLOWED_RUN_TARGETS, DEFAULT_RUN_COMMAND_REGISTRY, DEFAULT_THREAD_AUTO_SCROLL_BOTTOM_THRESHOLD, DEFAULT_TOOL_MEMORY_EXTRACTOR, ERROR_RECOVERY_RULE_LINE, ERROR_TRUNCATED_RESPONSE, INCREMENTAL_TESTING_RULE_LINE, JUST_BASH_SCRIPT_EXECUTION_RESTRICTION_LINES, JUST_BASH_SHELL_NATIVE_WORKFLOW_COMMAND_EXAMPLES, LLMClient, LLMResponseSchema, MAX_TOOL_RESULT_CHARS, PORT_CONFLICT_RULE_LINE, PendingAgentMessageBuffer, ProxyTool, ROOT_CAUSES_RULE_LINE, RunCommand, RunCommandRegistry, SHARED_TOOL_CALL_EXAMPLE_LINES, SHARED_TOOL_USAGE_RULE, SINGLE_TOOL_CALL_RUN_LINE_EXAMPLE, SKILL_INVOKE_READ_RULE_LINE, STANDARD_TOOL_CALL_FORMAT_RULES, SUPPORTED_RUN_TARGETS, StreamingToolParser, TODO_LIST_FIRST_RESPONSE_RULE_LINE, TOOL_CALL_SEPARATOR_RULE, Tool, ToolCallSchema, ToolLoopAgentRuntime, ToolRegistry, ToolRunCommand, VALIDATE_AFTER_CHANGES_RULE_LINE, WebToolLoopAgentRuntime, WebValidationEnforcer, agentMachine, applyIdleWebAgentState, applyInitialWebAgentRunState, buildAgentIdentityLine, buildAgentSystemPrompt, buildCompactionEntry, buildCoreStaticRules, buildNoStructuredResponseFoundError, buildSkillAwareStaticContext, buildSkillsSection, buildStepUserMessage, buildToolLogRevealFrames, buildToolUsageExample, buildValidationErrorMessage, buildWebRuntimeRules, buildWorkspaceCodingStaticRules, canonicalizeCompactionText, coerceToolCallToDefinition, configure, containsStandaloneStructuredInvocationStart, createAgentMemoryLayer, createAppendToolsSectionCustomizer, createBackgroundBashDefinition, createConversationSink, createCustomRunCommandRegistry, createInitialWebAgentState, createRunCommandRuntimeBindings, createRuntimeStore, createToolAgentMessage, createToolRegistry, createToolsSectionOverrideCustomizer, createWebAgentMessageIdGenerator, createWebSearchToolActions, createWebToolLoopCallbacks, decodeEscapedShellText, defineRuntimeController, enrichToolResultWithUnixMetadata, executeBackgroundUnixCommandString, executeToolCallWithRunCommands, executeToolLoopStep, executeToolSafe, executeUnixCommandString, extractPrimaryCommandMetadata, extractTruncatedToolInfo, formatToolCallAsUnixCommand, formatToolDefinitions, formatToolResultMessage, formatToolsSection, formatUnixToolSurface, formatZodValidationError, getDiagnosticSummaryLine, getProviderConfig, getRunCommandPromptAvailability, getToolLogSummaryLine, isBackgroundBashToolCall, isBashToolCall, limitEntriesByRecency, machineStateToWebAgentPhase, mapConversationRoleToAgentRole, parseAgentResponse, parseResponseWithRecovery, parseStructuredAgentText, parseToolResultMessage, parseUnixToolCommand, readDiagnosticLevel, readDiagnosticSource, resolveToolDefinitionForInvocation, runStructuredLLMCompaction, selectLatestByKey, shouldAutoScrollThread, shouldSkipStepUserMessage, stripDiagnosticMessagePrefix, suppressWebValidationLog, tokenizeUnixCommand, truncateToolResult };
7430
7391
  //# sourceMappingURL=index.js.map
7431
7392
  //# sourceMappingURL=index.js.map