const CORE_ACTION_BUDGET_MS = 2000;
async function actuallyWriteSessionJson(ctx, opts) {
    const { projectPath, projectId } = ctx;
    if (!projectPath) {
        return;
    }
    // Honour abort before doing any work
    if (opts.signal.aborted) {
        throw new Error('write-session-json aborted before start');
    }
    const { generateSessionContext } = await import('../../session-context-generator.js');
    await new Promise((resolve, reject) => {
        opts.signal.addEventListener('abort', () => {
            reject(new Error('CoreActionTimeoutError: write-session-json timed out'));
        });
        generateSessionContext(projectPath, projectId)
            .then(() => {
            resolve();
        })
            .catch(() => {
            resolve();
        }); // best-effort — never blocks status transition
    });
}
export async function writeSessionJson(ctx) {
    const controller = new AbortController();
    const timer = setTimeout(() => {
        controller.abort();
    }, CORE_ACTION_BUDGET_MS);
    try {
        await actuallyWriteSessionJson(ctx, { signal: controller.signal });
        return { ok: true };
    }
    catch (err) {
        return { ok: false, error: err instanceof Error ? err.message : String(err) };
    }
    finally {
        clearTimeout(timer);
    }
}
//# sourceMappingURL=write-session-json.js.map