import { buildCodeBasePracticeAuditMetadata, createCodeBaseCoreHandler, createCodeBaseToolDefinition, injectRuntimeInvocationMetadata, jsonSchema } from "../../_shared/baseToolAdapter.js";
import { anthropicCodeDebugCaptureStatePractice } from "./anthropic.js";
import { deepmindCodeDebugCaptureStatePractice } from "./deepmind.js";
import { openaiCodeDebugCaptureStatePractice } from "./openai.js";
import { codeDebugCaptureStateDescriptor, executeCodeDebugCaptureState as executeCore, planCodeDebugCaptureState } from "./core.js";
import { codeDebugCaptureStateDependencyDeclarations } from "./dependencies.js";
export * from "./core.js";
export const codeDebugCaptureStateProviderPractices = [anthropicCodeDebugCaptureStatePractice, openaiCodeDebugCaptureStatePractice, deepmindCodeDebugCaptureStatePractice];
export const codeDebugCaptureStateBestPracticeDescriptor = { toolId: "code.debugCaptureState", bestPractice: "storage-owned-debug-state-capture-with-runtime-debug-support", sourcePriority: ["cli", "agent-sdk", "api-sdk", "praxis-native"], providerOrder: ["anthropic", "openai", "deepmind"], dependencies: codeDebugCaptureStateDependencyDeclarations };
function ordered(preferredProvider) { return preferredProvider === undefined ? codeDebugCaptureStateProviderPractices : [...codeDebugCaptureStateProviderPractices.filter((practice) => practice.providerName === preferredProvider), ...codeDebugCaptureStateProviderPractices.filter((practice) => practice.providerName !== preferredProvider)]; }
export function selectCodeDebugCaptureStatePractice(dependencies = {}) { for (const practice of ordered(dependencies.preferredProvider)) {
    const provider = practice.createProvider(dependencies);
    if (provider !== undefined)
        return { providerName: practice.providerName, practice, provider };
} return { providerName: "praxis-native", practice: { providerName: "praxis-native", source: { kind: "praxis-native", label: "Praxis dry-run fallback" }, directCliSupport: false, sideEffectPolicy: "runtime-governed", notes: ["No injected or host debug state provider is available; dry-run remains available."], createProvider: () => undefined } }; }
function audit(selection) { return buildCodeBasePracticeAuditMetadata({ providerName: selection.providerName, sourceLabel: selection.practice.source.label, sourceKind: selection.practice.source.kind, sourcePath: selection.practice.source.path, directCliSupport: selection.practice.directCliSupport, sideEffectPolicy: selection.practice.sideEffectPolicy, notes: selection.practice.notes }); }
export async function executeCodeDebugCaptureState(request = {}) { const selection = selectCodeDebugCaptureStatePractice({ executor: request.executor, provider: request.provider, preferredProvider: request.preferredProvider }); return executeCore({ ...request, provider: selection.provider, context: { ...request.context, auditMetadata: { ...(request.context?.auditMetadata ?? {}), ...audit(selection) } } }); }
const contextSchema = { type: "object", additionalProperties: true, properties: { runtimeId: { type: "string" }, sessionId: { type: "string" }, invocationId: { type: "string" }, dryRun: { type: "boolean" }, guard: { type: "object", additionalProperties: true } } };
export const codeDebugCaptureStateBaseToolDefinition = createCodeBaseToolDefinition({ toolId: "code.debugCaptureState", title: "Code Debug Capture State", description: "Capture debug state through runtime-owned debug support.", summary: "Use code.debugCaptureState to inspect stack, variables, and breakpoints without shell.", storageGroup: "debugCode", riskLevel: "normal", permissionHints: ["debug:read"], dependencies: codeDebugCaptureStateDependencyDeclarations, inputSchema: jsonSchema("code.debugCaptureState.input", { type: "object", additionalProperties: true, required: ["target"], properties: { target: { type: "object", additionalProperties: true }, capture: { type: "object", additionalProperties: true }, dryRun: { type: "boolean" }, context: contextSchema } }), outputSchema: jsonSchema("code.debugCaptureState.output", { type: "object", additionalProperties: true }) });
export const codeDebugCaptureStateHandler = createCodeBaseCoreHandler(codeDebugCaptureStateBaseToolDefinition, async (request) => { const selection = selectCodeDebugCaptureStatePractice({ ...request.input, executor: request.executor, provider: request.input.provider }); const inputContext = request.input.context ?? {}; return executeCore({ ...request.input, provider: selection.provider, context: { ...inputContext, runtimeId: inputContext.runtimeId ?? request.runtimeId, sessionId: inputContext.sessionId ?? request.sessionId, invocationId: inputContext.invocationId ?? request.toolCallId, auditMetadata: injectRuntimeInvocationMetadata({ ...audit(selection), ...(request.metadata ?? {}) }, inputContext.auditMetadata, request) } }); });
export { codeDebugCaptureStateDescriptor, planCodeDebugCaptureState };
