export const shellExitCodeCheckingDependencyDeclarations = [
    {
        dependencyId: "runtime.execEngine.shellExecution.monitorExecution",
        kind: "runtime",
        required: true,
        description: "Runtime-owned shell execution observation port exposed through BaseToolExecutorPort.shell.monitorExecution",
    },
    {
        dependencyId: "runtime.governancePlane.toolInvocationGrant",
        kind: "permission",
        required: true,
        description: "Runtime governance decision carried in context.guard for real observation dispatch",
    },
    {
        dependencyId: "runtime.shellProcessOwnership",
        kind: "runtime",
        required: true,
        description: "Runtime owns shell process lifecycle and supplies exit observations; baseTool only classifies them",
    },
];
function isRecord(value) {
    return typeof value === "object" && value !== null && !Array.isArray(value);
}
function observationEnvelope(output) {
    return isRecord(output.observation) ? output.observation : output;
}
export function createHostExecutorShellExitCodeCheckingProvider(executor) {
    const monitorExecution = executor?.shell?.monitorExecution;
    if (monitorExecution === undefined)
        return undefined;
    return async (request, context) => {
        const result = await monitorExecution({
            target: { toolId: "shell.exitCodeChecking", executionId: request.executionId, command: request.command },
            observation: {
                exitCode: request.exitCode,
                signal: request.signal,
                timedOut: request.timedOut,
                policy: request.policy,
            },
            context: context,
        });
        if (!result.ok)
            throw new Error(result.error.message);
        const output = isRecord(result.output) ? observationEnvelope(result.output) : {};
        return {
            command: typeof output.command === "string" ? output.command : undefined,
            exitCode: typeof output.exitCode === "number" || output.exitCode === null
                ? output.exitCode
                : output.exitCode === undefined
                    ? undefined
                    : Number.NaN,
            signal: typeof output.signal === "string" || output.signal === null
                ? output.signal
                : output.signal === undefined
                    ? undefined
                    : 0,
            timedOut: typeof output.timedOut === "boolean"
                ? output.timedOut
                : output.timedOut === undefined
                    ? undefined
                    : 0,
        };
    };
}
