import { buildCodeBasePracticeAuditMetadata, createCodeBaseCoreHandler, createCodeBaseToolDefinition, injectRuntimeInvocationMetadata, jsonSchema } from "../../_shared/baseToolAdapter.js";
import { anthropicCodeDebugRunPractice } from "./anthropic.js";
import { deepmindCodeDebugRunPractice } from "./deepmind.js";
import { openaiCodeDebugRunPractice } from "./openai.js";
import { codeDebugRunDescriptor, executeCodeDebugRun as executeCore, planCodeDebugRun } from "./core.js";
import { codeDebugRunDependencyDeclarations } from "./dependencies.js";
export * from "./core.js";
export const codeDebugRunProviderPractices = [anthropicCodeDebugRunPractice, openaiCodeDebugRunPractice, deepmindCodeDebugRunPractice];
export const codeDebugRunBestPracticeDescriptor = { toolId: "code.debugRun", bestPractice: "storage-owned-debug-run-with-runtime-debug-launch-support", sourcePriority: ["cli", "agent-sdk", "api-sdk", "praxis-native"], providerOrder: ["anthropic", "openai", "deepmind"], dependencies: codeDebugRunDependencyDeclarations };
function ordered(preferredProvider) { return preferredProvider === undefined ? codeDebugRunProviderPractices : [...codeDebugRunProviderPractices.filter((practice) => practice.providerName === preferredProvider), ...codeDebugRunProviderPractices.filter((practice) => practice.providerName !== preferredProvider)]; }
export function selectCodeDebugRunPractice(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 launcher 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 executeCodeDebugRun(request = {}) { const selection = selectCodeDebugRunPractice({ 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 codeDebugRunBaseToolDefinition = createCodeBaseToolDefinition({ toolId: "code.debugRun", title: "Code Debug Run", description: "Launch or attach a debug run through runtime-owned debug support.", summary: "Use code.debugRun to start governed debug runs without shell or ad-hoc debugger commands.", storageGroup: "debugCode", riskLevel: "risky", permissionHints: ["debug:read", "debug:run"], dependencies: codeDebugRunDependencyDeclarations, inputSchema: jsonSchema("code.debugRun.input", { type: "object", additionalProperties: true, required: ["target"], properties: { target: { type: "object", additionalProperties: true }, breakpoints: { type: "array" }, environment: { type: "object", additionalProperties: { type: "string" } }, timeoutMs: { type: "integer", minimum: 1 }, dryRun: { type: "boolean" }, context: contextSchema } }), outputSchema: jsonSchema("code.debugRun.output", { type: "object", additionalProperties: true }) });
export const codeDebugRunHandler = createCodeBaseCoreHandler(codeDebugRunBaseToolDefinition, async (request) => { const selection = selectCodeDebugRunPractice({ ...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 { codeDebugRunDescriptor, planCodeDebugRun };
