export const shellDetachedExecutionDependencyDeclarations = [
    {
        dependencyId: "runtime.processLifecycle.detachedHandle",
        kind: "runtime",
        required: true,
        description: "Runtime-provided detached shell execution launch 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 createHostExecutorShellDetachedExecutionProvider(executor) {
    const startDetached = executor?.shell?.startDetached;
    if (startDetached === 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.detachedExecution requires a runtime command target");
        }
        const result = await startDetached({
            command: target.command,
            shell: target.shell ?? "sh",
            cwd: typeof target.workingDirectory === "string" ? target.workingDirectory : undefined,
            launchId: typeof target.launchId === "string" && target.launchId.trim().length > 0 ? target.launchId : context.invocationId ?? "detached",
            pidFilePath: typeof target.pidFilePath === "string" ? target.pidFilePath : undefined,
            stdoutLogPath: typeof target.stdoutLogPath === "string" ? target.stdoutLogPath : undefined,
            stderrLogPath: typeof target.stderrLogPath === "string" ? target.stderrLogPath : undefined,
            restartPolicy: target.restartPolicy ?? "none",
            context,
        });
        if (!result.ok) {
            throw new Error(result.error.message);
        }
        return {
            resultEnvelope: result.output,
            metadata: { hostExecutor: "BaseToolExecutorPort.shell.startDetached", ...(result.metadata ?? {}) },
        };
    };
}
