export const shellProcessTerminationDependencyDeclarations = [
    {
        dependencyId: "runtime.processLifecycle.termination",
        kind: "runtime",
        required: true,
        description: "Runtime-provided shell process termination 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 createHostExecutorShellProcessTerminationProvider(executor) {
    const terminateProcess = executor?.shell?.terminateProcess;
    if (terminateProcess === undefined) {
        return undefined;
    }
    return async (request, context) => {
        const target = request.target ?? {};
        const processId = target.processId;
        if (typeof processId !== "number" || !Number.isSafeInteger(processId) || processId <= 0) {
            throw new Error("shell.processTermination requires a runtime process id target");
        }
        const signal = target.signal ?? (target.force === true ? "SIGKILL" : "SIGTERM");
        const result = await terminateProcess({
            processId,
            signal,
            reason: typeof target.reason === "string" ? target.reason : undefined,
            force: target.force === true || signal === "SIGKILL",
            context,
        });
        if (!result.ok) {
            throw new Error(result.error.message);
        }
        return {
            resultEnvelope: result.output,
            metadata: { hostExecutor: "BaseToolExecutorPort.shell.terminateProcess", ...(result.metadata ?? {}) },
        };
    };
}
