import { ShellInvocationExecutionProviderUnavailableError } from "./core.js";
export const shellInvocationExecutionDependencyDeclarations = [
    {
        dependencyId: "runtime.execEngine.shellExecutor",
        kind: "runtime",
        required: true,
        description: "Runtime-provided shell executor exposed through BaseToolExecutorPort.shell.run",
    },
    {
        dependencyId: "runtime.governancePlane.toolInvocationGrant",
        kind: "permission",
        required: true,
        description: "Runtime governance decision carried in ShellToolContext.guard",
    },
    {
        dependencyId: "runtime.capabilityExposure.shellOutputEnvelope",
        kind: "runtime",
        required: true,
        description: "Runtime output envelope for stdout, stderr, exit code, and audit material",
    },
];
export function createHostExecutorShellInvocationExecutionProvider(executor) {
    const run = executor?.shell?.run;
    if (run === undefined) {
        return undefined;
    }
    return async (request, _context) => {
        if (Object.keys(request.env).length > 0) {
            throw new ShellInvocationExecutionProviderUnavailableError("runtime shell executor does not support invocation env overrides");
        }
        const result = await run({
            command: request.executable,
            args: request.args,
            cwd: request.cwd,
            timeoutMs: request.timeoutMs,
            stdin: request.stdin,
        });
        if (!result.ok) {
            throw new Error(result.error.message);
        }
        return result.output;
    };
}
