import { buildCodeBasePracticeAuditMetadata, createCodeBaseCoreHandler, createCodeBaseToolDefinition, injectRuntimeInvocationMetadata, jsonSchema } from "../../_shared/baseToolAdapter.js";
import { anthropicCodeDebugCollectLogsPractice } from "./anthropic.js";
import { deepmindCodeDebugCollectLogsPractice } from "./deepmind.js";
import { openaiCodeDebugCollectLogsPractice } from "./openai.js";
import { codeDebugCollectLogsDescriptor, executeCodeDebugCollectLogs as executeCore, planCodeDebugCollectLogs } from "./core.js";
import { codeDebugCollectLogsDependencyDeclarations } from "./dependencies.js";
export * from "./core.js";
export const codeDebugCollectLogsProviderPractices = [anthropicCodeDebugCollectLogsPractice, openaiCodeDebugCollectLogsPractice, deepmindCodeDebugCollectLogsPractice];
export const codeDebugCollectLogsBestPracticeDescriptor = { toolId: "code.debugCollectLogs", bestPractice: "storage-owned-debug-log-collection-with-runtime-debug-support", sourcePriority: ["cli", "agent-sdk", "api-sdk", "praxis-native"], providerOrder: ["anthropic", "openai", "deepmind"], dependencies: codeDebugCollectLogsDependencyDeclarations };
function ordered(preferredProvider) { return preferredProvider === undefined ? codeDebugCollectLogsProviderPractices : [...codeDebugCollectLogsProviderPractices.filter((practice) => practice.providerName === preferredProvider), ...codeDebugCollectLogsProviderPractices.filter((practice) => practice.providerName !== preferredProvider)]; }
export function selectCodeDebugCollectLogsPractice(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 log 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 executeCodeDebugCollectLogs(request = {}) { const selection = selectCodeDebugCollectLogsPractice({ 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 codeDebugCollectLogsBaseToolDefinition = createCodeBaseToolDefinition({ toolId: "code.debugCollectLogs", title: "Code Debug Collect Logs", description: "Collect debug logs through runtime-owned debug support.", summary: "Use code.debugCollectLogs for debug console, process, test-run, or file logs without shell.", storageGroup: "debugCode", riskLevel: "normal", permissionHints: ["debug:read", "logs:read"], dependencies: codeDebugCollectLogsDependencyDeclarations, inputSchema: jsonSchema("code.debugCollectLogs.input", { type: "object", additionalProperties: true, required: ["sources"], properties: { sources: { type: "array" }, maxEntries: { type: "integer", minimum: 1 }, since: { type: "string" }, redaction: { type: "object", additionalProperties: true }, dryRun: { type: "boolean" }, context: contextSchema } }), outputSchema: jsonSchema("code.debugCollectLogs.output", { type: "object", additionalProperties: true }) });
export const codeDebugCollectLogsHandler = createCodeBaseCoreHandler(codeDebugCollectLogsBaseToolDefinition, async (request) => { const selection = selectCodeDebugCollectLogsPractice({ ...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 { codeDebugCollectLogsDescriptor, planCodeDebugCollectLogs };
