export const shellBackgroundExecutionDependencyDeclarations = [
    {
        dependencyId: "runtime.processLifecycle.backgroundHandle",
        kind: "runtime",
        required: true,
        description: "Runtime-provided background shell execution job 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 createHostExecutorShellBackgroundExecutionProvider(executor) {
    const startBackground = executor?.shell?.startBackground;
    if (startBackground === 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.backgroundExecution requires a runtime command target");
        }
        const result = await startBackground({
            command: target.command,
            shell: target.shell ?? "sh",
            cwd: typeof target.workingDirectory === "string" ? target.workingDirectory : undefined,
            jobId: typeof target.jobId === "string" && target.jobId.trim().length > 0 ? target.jobId : context.invocationId ?? "background",
            monitorIntervalMs: typeof target.monitorIntervalMs === "number" ? target.monitorIntervalMs : 1_000,
            outputBufferLimitBytes: typeof target.outputBufferLimitBytes === "number" ? target.outputBufferLimitBytes : 64 * 1024,
            captureOutput: target.captureOutput !== false,
            context,
        });
        if (!result.ok) {
            throw new Error(result.error.message);
        }
        return {
            resultEnvelope: result.output,
            metadata: { hostExecutor: "BaseToolExecutorPort.shell.startBackground", ...(result.metadata ?? {}) },
        };
    };
}
