hammer-ai 0.2.9 → 0.2.11
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 +60 -10
- package/dist/index.js +129 -61
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -2249,6 +2240,65 @@ declare abstract class Tool implements ToolLike {
|
|
|
2249
2240
|
toDefinition(): ToolDefinition;
|
|
2250
2241
|
}
|
|
2251
2242
|
|
|
2243
|
+
/**
|
|
2244
|
+
* SubAgentTool — a Tool that runs its own contained agentic loop.
|
|
2245
|
+
*
|
|
2246
|
+
* Subclasses define domain-specific logic in isolation so those rules
|
|
2247
|
+
* stay OUT of the main agent's context window:
|
|
2248
|
+
*
|
|
2249
|
+
* - `getSubAgentSystemPrompt()` — the sub-agent's dedicated system prompt
|
|
2250
|
+
* - `getSubAgentTools()` — tools available within the sub-agent loop
|
|
2251
|
+
* - `getSubAgentLLMProvider()` — LLM provider config for sub-agent inference
|
|
2252
|
+
*
|
|
2253
|
+
* The main agent calls a SubAgentTool like any other tool, passing a `task`
|
|
2254
|
+
* string. The sub-agent autonomously handles the task and returns the result.
|
|
2255
|
+
*/
|
|
2256
|
+
|
|
2257
|
+
interface SubAgentToolOptions {
|
|
2258
|
+
/** Maximum tool-call rounds before giving up. Default: 10. */
|
|
2259
|
+
maxSteps?: number;
|
|
2260
|
+
/** Temperature for LLM calls. Defaults to LLMClient's built-in default (0.2). */
|
|
2261
|
+
temperature?: number;
|
|
2262
|
+
}
|
|
2263
|
+
/**
|
|
2264
|
+
* A Tool that runs its own contained agentic loop.
|
|
2265
|
+
*
|
|
2266
|
+
* Domain-specific rules live in `getSubAgentSystemPrompt()` and are never
|
|
2267
|
+
* injected into the main agent's context — only the short tool description
|
|
2268
|
+
* is visible to the parent.
|
|
2269
|
+
*
|
|
2270
|
+
* @example
|
|
2271
|
+
* ```ts
|
|
2272
|
+
* class ImagePromptAgent extends SubAgentTool {
|
|
2273
|
+
* getName() { return "GenerateImage" }
|
|
2274
|
+
* getDescription() { return "Generate a slide background photo." }
|
|
2275
|
+
* getSchema() { return { task: { type: "string", required: true, ... } } }
|
|
2276
|
+
*
|
|
2277
|
+
* protected getSubAgentSystemPrompt() { return IMAGE_RULES_PROMPT }
|
|
2278
|
+
* protected getSubAgentTools() { return [new RawGenerateImage()] }
|
|
2279
|
+
* protected getSubAgentLLMProvider() { return getProviderConfig("qwen3.6-plus") }
|
|
2280
|
+
* }
|
|
2281
|
+
* ```
|
|
2282
|
+
*/
|
|
2283
|
+
declare abstract class SubAgentTool extends Tool {
|
|
2284
|
+
protected readonly subAgentOptions: SubAgentToolOptions;
|
|
2285
|
+
constructor(workspaceRoot?: string, options?: SubAgentToolOptions);
|
|
2286
|
+
/** Domain-specific system prompt for this sub-agent's dedicated loop. */
|
|
2287
|
+
protected abstract getSubAgentSystemPrompt(): string;
|
|
2288
|
+
/** Tools available within this sub-agent's loop. */
|
|
2289
|
+
protected abstract getSubAgentTools(): ToolLike[];
|
|
2290
|
+
/** LLM provider config used for this sub-agent's inference calls. */
|
|
2291
|
+
protected abstract getSubAgentLLMProvider(): LLMProviderConfig;
|
|
2292
|
+
getSchema(): ToolSchema;
|
|
2293
|
+
/**
|
|
2294
|
+
* Build the task string from raw execute params.
|
|
2295
|
+
* Override when `getSchema()` adds parameters beyond `task`.
|
|
2296
|
+
*/
|
|
2297
|
+
protected buildSubAgentTask(params: Record<string, any>): string;
|
|
2298
|
+
execute(params: Record<string, any>): Promise<ToolResult>;
|
|
2299
|
+
protected runSubAgentLoop(task: string): Promise<ToolResult>;
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2252
2302
|
/**
|
|
2253
2303
|
* Shared ToolRegistry infrastructure.
|
|
2254
2304
|
*
|
|
@@ -2404,4 +2454,4 @@ declare function runStructuredLLMCompaction<TMessage extends MemoryMessage, TSta
|
|
|
2404
2454
|
parseState: (obj: Record<string, unknown>) => TState | null;
|
|
2405
2455
|
}): Promise<TState | null>;
|
|
2406
2456
|
|
|
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,
|
|
2457
|
+
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, SubAgentTool, type SubAgentToolOptions, 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
|
@@ -3559,12 +3559,6 @@ function shouldPreferBashToolLogRecovery(current, recovered) {
|
|
|
3559
3559
|
}
|
|
3560
3560
|
return currentCommand !== recoveredCommand && (currentToolCall.truncated === true || /\n\[(?:TOOL_LOG|stderr|meta|exit):?/i.test(currentCommand) || /\n\[(?:stderr|meta|exit)\]/i.test(currentCommand));
|
|
3561
3561
|
}
|
|
3562
|
-
function buildParseFeedback(_content, zodError) {
|
|
3563
|
-
if (zodError) {
|
|
3564
|
-
return buildValidationErrorMessage(zodError);
|
|
3565
|
-
}
|
|
3566
|
-
return buildNoStructuredResponseFoundError();
|
|
3567
|
-
}
|
|
3568
3562
|
function looksLikeStandaloneControlSegment(content, allowedRunTargets) {
|
|
3569
3563
|
return containsStandaloneStructuredInvocationStart(content, allowedRunTargets);
|
|
3570
3564
|
}
|
|
@@ -4545,20 +4539,6 @@ function buildCompactionEntry(options) {
|
|
|
4545
4539
|
createMemoryMetadata(options.provenance)
|
|
4546
4540
|
);
|
|
4547
4541
|
}
|
|
4548
|
-
function sanitizeMemoryProvenance(value, fallback) {
|
|
4549
|
-
if (!value || typeof value !== "object") {
|
|
4550
|
-
return fallback;
|
|
4551
|
-
}
|
|
4552
|
-
const candidate = value;
|
|
4553
|
-
const source = typeof candidate.source === "string" ? candidate.source : void 0;
|
|
4554
|
-
if (!source || !MEMORY_PROVENANCE_SOURCES.has(source)) {
|
|
4555
|
-
return fallback;
|
|
4556
|
-
}
|
|
4557
|
-
return {
|
|
4558
|
-
source,
|
|
4559
|
-
detail: typeof candidate.detail === "string" ? candidate.detail : fallback.detail
|
|
4560
|
-
};
|
|
4561
|
-
}
|
|
4562
4542
|
function cleanCompactionText(text) {
|
|
4563
4543
|
return text.trim().replace(/\s+/g, " ").replace(/[.?!:;]+$/, "");
|
|
4564
4544
|
}
|
|
@@ -4607,45 +4587,35 @@ function formatMemoryMetadataTag(metadata) {
|
|
|
4607
4587
|
const detail = metadata.provenance.detail ? `/${metadata.provenance.detail}` : "";
|
|
4608
4588
|
return ` [${metadata.provenance.source}${detail}]`;
|
|
4609
4589
|
}
|
|
4610
|
-
function sanitizeCompactionEntries(input, options) {
|
|
4611
|
-
if (!Array.isArray(input)) {
|
|
4612
|
-
return [];
|
|
4613
|
-
}
|
|
4614
|
-
return input.flatMap((value) => {
|
|
4615
|
-
if (typeof value === "string") {
|
|
4616
|
-
const entry2 = options.fromString?.(value);
|
|
4617
|
-
return entry2 ? [entry2] : [];
|
|
4618
|
-
}
|
|
4619
|
-
if (!value || typeof value !== "object") {
|
|
4620
|
-
return [];
|
|
4621
|
-
}
|
|
4622
|
-
const entry = options.fromObject?.(value);
|
|
4623
|
-
return entry ? [entry] : [];
|
|
4624
|
-
});
|
|
4625
|
-
}
|
|
4626
4590
|
function createEntrySanitizer(options) {
|
|
4627
|
-
return (input, fallbackTurn, fallbackProvenance = options.defaultProvenance) =>
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
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
|
+
};
|
|
4649
4619
|
}
|
|
4650
4620
|
async function runStructuredLLMCompaction(options) {
|
|
4651
4621
|
if (!options.client) {
|
|
@@ -4665,7 +4635,14 @@ async function runStructuredLLMCompaction(options) {
|
|
|
4665
4635
|
maxTokens: options.maxTokens ?? 4096,
|
|
4666
4636
|
stream: false
|
|
4667
4637
|
});
|
|
4668
|
-
|
|
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
|
+
}
|
|
4669
4646
|
return parsed ? options.parseState(parsed) : null;
|
|
4670
4647
|
}
|
|
4671
4648
|
|
|
@@ -6688,7 +6665,7 @@ ${JSON.stringify(request.messages, null, 2)}`
|
|
|
6688
6665
|
}
|
|
6689
6666
|
if (!stepParsed) {
|
|
6690
6667
|
const parseError = new Error(
|
|
6691
|
-
|
|
6668
|
+
buildNoStructuredResponseFoundError()
|
|
6692
6669
|
);
|
|
6693
6670
|
parseError.isWebParseFailure = true;
|
|
6694
6671
|
parseError.rawContent = response.content;
|
|
@@ -7193,6 +7170,97 @@ var Tool = class {
|
|
|
7193
7170
|
}
|
|
7194
7171
|
};
|
|
7195
7172
|
|
|
7173
|
+
// src/sub-agent.ts
|
|
7174
|
+
var SubAgentTool = class extends Tool {
|
|
7175
|
+
subAgentOptions;
|
|
7176
|
+
constructor(workspaceRoot = "", options) {
|
|
7177
|
+
super(workspaceRoot);
|
|
7178
|
+
this.subAgentOptions = options ?? {};
|
|
7179
|
+
}
|
|
7180
|
+
// ---- default task schema (override to add extra params) ---------------
|
|
7181
|
+
getSchema() {
|
|
7182
|
+
return {
|
|
7183
|
+
task: {
|
|
7184
|
+
type: "string",
|
|
7185
|
+
required: true,
|
|
7186
|
+
positional: false,
|
|
7187
|
+
description: "The task for the sub-agent to complete."
|
|
7188
|
+
}
|
|
7189
|
+
};
|
|
7190
|
+
}
|
|
7191
|
+
/**
|
|
7192
|
+
* Build the task string from raw execute params.
|
|
7193
|
+
* Override when `getSchema()` adds parameters beyond `task`.
|
|
7194
|
+
*/
|
|
7195
|
+
buildSubAgentTask(params) {
|
|
7196
|
+
return typeof params.task === "string" ? params.task.trim() : "";
|
|
7197
|
+
}
|
|
7198
|
+
// ---- execute ---------------------------------------------------------
|
|
7199
|
+
async execute(params) {
|
|
7200
|
+
const task = this.buildSubAgentTask(params);
|
|
7201
|
+
if (!task) return { success: false, error: "task is required" };
|
|
7202
|
+
return this.runSubAgentLoop(task);
|
|
7203
|
+
}
|
|
7204
|
+
// ---- core loop -------------------------------------------------------
|
|
7205
|
+
async runSubAgentLoop(task) {
|
|
7206
|
+
const { maxSteps = 10, temperature } = this.subAgentOptions;
|
|
7207
|
+
const llmClient = new LLMClient(this.getSubAgentLLMProvider());
|
|
7208
|
+
const subTools = this.getSubAgentTools();
|
|
7209
|
+
const toolMap = new Map(subTools.map((t) => [t.getName(), t]));
|
|
7210
|
+
const toolDefs = subTools.map((t) => t.toDefinition());
|
|
7211
|
+
const systemPrompt = buildAgentSystemPrompt({
|
|
7212
|
+
identityLine: this.getSubAgentSystemPrompt(),
|
|
7213
|
+
tools: toolDefs,
|
|
7214
|
+
allowedRunTargets: ["tool"],
|
|
7215
|
+
supplementalRules: buildCoreStaticRules()
|
|
7216
|
+
});
|
|
7217
|
+
const messages = [
|
|
7218
|
+
{ role: "system", content: systemPrompt },
|
|
7219
|
+
{ role: "user", content: task }
|
|
7220
|
+
];
|
|
7221
|
+
for (let step = 0; step < maxSteps; step++) {
|
|
7222
|
+
const response = await llmClient.chat({ messages, temperature });
|
|
7223
|
+
messages.push({ role: "assistant", content: response.content });
|
|
7224
|
+
const parsed = parseAgentResponse(response.content, {
|
|
7225
|
+
// Allow "bash" so that exit 0 / exit 1 are intercepted as
|
|
7226
|
+
// success / failure signals without being executed.
|
|
7227
|
+
allowedRunTargets: ["tool", "bash"]
|
|
7228
|
+
});
|
|
7229
|
+
if (!parsed) {
|
|
7230
|
+
return { success: false, error: "Sub-agent produced no structured response" };
|
|
7231
|
+
}
|
|
7232
|
+
if (parsed.outcome === "success") {
|
|
7233
|
+
return { success: true, result: parsed.reasoning || "Done." };
|
|
7234
|
+
}
|
|
7235
|
+
if (parsed.outcome === "failure") {
|
|
7236
|
+
return { success: false, error: parsed.reasoning || "Sub-agent reported failure" };
|
|
7237
|
+
}
|
|
7238
|
+
if (parsed.selectedToolCall) {
|
|
7239
|
+
const raw = parsed.selectedToolCall;
|
|
7240
|
+
const toolCall = coerceToolCallToDefinition(raw, toolDefs) ?? raw;
|
|
7241
|
+
const tool = toolMap.get(toolCall.name);
|
|
7242
|
+
if (!tool) {
|
|
7243
|
+
const errResult = {
|
|
7244
|
+
success: false,
|
|
7245
|
+
error: `Unknown tool: ${toolCall.name}. Available: ${[...toolMap.keys()].join(", ")}`
|
|
7246
|
+
};
|
|
7247
|
+
messages.push({
|
|
7248
|
+
role: "tool",
|
|
7249
|
+
content: formatToolResultMessage(toolCall, errResult)
|
|
7250
|
+
});
|
|
7251
|
+
continue;
|
|
7252
|
+
}
|
|
7253
|
+
const result = await tool.execute(toolCall.parameters);
|
|
7254
|
+
messages.push({
|
|
7255
|
+
role: "tool",
|
|
7256
|
+
content: formatToolResultMessage(toolCall, result)
|
|
7257
|
+
});
|
|
7258
|
+
}
|
|
7259
|
+
}
|
|
7260
|
+
return { success: false, error: `Sub-agent did not complete within ${maxSteps} steps` };
|
|
7261
|
+
}
|
|
7262
|
+
};
|
|
7263
|
+
|
|
7196
7264
|
// src/registry.ts
|
|
7197
7265
|
function isToolRegistryOptions(value) {
|
|
7198
7266
|
if (!value || typeof value !== "object") {
|
|
@@ -7410,6 +7478,6 @@ async function executeToolLoopStep(options) {
|
|
|
7410
7478
|
};
|
|
7411
7479
|
}
|
|
7412
7480
|
|
|
7413
|
-
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,
|
|
7481
|
+
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, SubAgentTool, 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 };
|
|
7414
7482
|
//# sourceMappingURL=index.js.map
|
|
7415
7483
|
//# sourceMappingURL=index.js.map
|