export const shellForegroundExecutionDependencyDeclarations = [
    {
        dependencyId: "runtime.execEngine.shellExecutor",
        kind: "runtime",
        required: true,
        description: "Runtime-provided foreground shell execution provider; baseTools do not own shell/process side effects",
    },
    {
        dependencyId: "runtime.governancePlane.toolInvocationGrant",
        kind: "permission",
        required: true,
        description: "Runtime governance decision carried in context.guard for real execution",
    },
    {
        dependencyId: "runtime.capabilityExposure.shellAuditEnvelope",
        kind: "runtime",
        required: true,
        description: "Runtime audit envelope for process lifecycle and shell output material",
    },
];
export function createHostExecutorShellForegroundExecutionProvider(executor) {
    const run = executor?.shell?.run;
    if (run === undefined) {
        return undefined;
    }
    return async (request, _context) => {
        const target = request.target ?? {};
        if (typeof target.command !== "string" || target.command.trim().length === 0) {
            throw new Error("shell.foregroundExecution requires a runtime command target");
        }
        const result = await run({
            command: target.shell ?? "sh",
            args: ["-lc", target.command],
            cwd: typeof target.workingDirectory === "string" ? target.workingDirectory : undefined,
            timeoutMs: typeof target.timeoutMs === "number" ? target.timeoutMs : undefined,
            stdin: typeof target.stdin === "string" ? target.stdin : undefined,
        });
        if (!result.ok) {
            const error = new Error(result.error.message);
            error.name = result.error.code;
            throw error;
        }
        return {
            resultEnvelope: result.output,
            metadata: { hostExecutor: "BaseToolExecutorPort.shell.run" },
        };
    };
}
