/**
 * Kernel Runtime — Phantom backend.
 *
 * PhantomRuntimeBackend wraps SubAgentRuntime so the kernel execution service
 * never imports SubAgentRuntime directly. This is the PR 3 shim; PR 4 can
 * refactor SubAgentRuntime internals without touching kernel contracts.
 */
export class PhantomRuntimeBackend {
    runtime;
    constructor(runtime) {
        this.runtime = runtime;
    }
    async prepareStep(input) {
        return {
            runId: input.runId,
            stepId: input.stepId,
            candidateFiles: input.candidateFiles ?? [],
            debugMeta: { backend: 'PhantomRuntimeBackend', phase: 'prepare' },
        };
    }
    async executeStep(input) {
        const run = await this.runtime.runNXL(input.task, undefined, 'kernel-execute');
        const warnings = [];
        if (run.state === 'failed') {
            warnings.push(`phantom execution reached state: ${run.state}`);
        }
        return {
            runId: input.runId,
            stepId: input.stepId,
            changedFiles: [],
            summary: typeof run.result === 'string' ? run.result : '',
            warnings,
            debugMeta: {
                backend: 'PhantomRuntimeBackend',
                phantomRunId: run.runId,
                state: run.state,
            },
        };
    }
    async inspectStep(input) {
        return {
            runId: input.runId,
            stepId: input.stepId,
            warnings: [],
            debugMeta: { backend: 'PhantomRuntimeBackend', phase: 'inspect' },
        };
    }
    async cleanupStep(_input) {
        // Phantom manages its own worktree lifecycle internally.
    }
}
/** Convenience factory so callers don't import SubAgentRuntime. */
export function createPhantomBackend(runtime) {
    return new PhantomRuntimeBackend(runtime);
}
