// Copyright (c) 2026 Hellmai Ltd
// SPDX-License-Identifier: AGPL-3.0-only
/**
 * @file wu-claim-cloud.ts
 * @description Cloud mode helpers for wu:claim command
 *
 * WU-1590 AC2: Provides metadata builder and branch-exists check helpers
 * for --cloud claim path that persists claimed_branch and bypasses
 * remote/local branch-exists checks when claiming on the current branch.
 *
 * Cloud agents execute from existing feature branches and cannot create
 * worktrees. This module extracts the decision logic for persisting
 * claimed_branch and bypassing branch existence guards.
 */
import { CLAIMED_MODES } from '@lumenflow/core/wu-constants';
/**
 * Build claim metadata for cloud mode.
 *
 * Persists the current branch as claimed_branch so that wu:prep, wu:done,
 * and wu:cleanup can resolve it via defaultBranchFrom() without relying
 * on lane-derived branch naming.
 *
 * @param input - Cloud claim metadata input
 * @returns Metadata fields to merge into WU YAML
 */
export function buildCloudClaimMetadata(input) {
    return {
        claimed_branch: input.currentBranch,
        claimed_mode: CLAIMED_MODES.BRANCH_PR,
    };
}
/**
 * Determine whether to skip remote/local branch-exists checks.
 *
 * Cloud agents claim on an existing branch (e.g., claude/feature-xyz).
 * The standard branch-exists check would reject the claim because the branch
 * already exists. In cloud mode, the branch existence IS expected.
 *
 * @param input - Branch-exists check input
 * @returns true if branch-exists checks should be skipped
 */
export function shouldSkipBranchExistsCheck(input) {
    return input.isCloud;
}
/**
 * Determine whether to skip ensureOnMain for wu:claim.
 *
 * Cloud agents (claude/*, codex/*) operate from existing feature branches.
 * ensureOnMain would incorrectly reject their claim attempts because they
 * are not on main and cannot switch to it (hooks block non-worktree edits).
 *
 * WU-1766: Mirrors the pattern from wu-done-cloud.ts shouldSkipEnsureOnMainForDone
 * and wu-create-cloud.ts skipEnsureOnMain.
 *
 * @param input - Cloud mode state
 * @returns true if ensureOnMain should be skipped
 */
export function shouldSkipEnsureOnMainForClaim(input) {
    return input.isCloud === true;
}
/**
 * Resolve execution branch behavior for branch-only style claims.
 *
 * In cloud branch-pr mode, agents must stay on the current branch and avoid
 * creating/switching to lane-derived branches.
 */
export function resolveBranchClaimExecution(input) {
    if (input.claimedMode === CLAIMED_MODES.BRANCH_PR && input.isCloud) {
        return {
            executionBranch: input.currentBranch,
            shouldCreateBranch: false,
        };
    }
    return {
        executionBranch: input.requestedBranch,
        shouldCreateBranch: true,
    };
}
//# sourceMappingURL=wu-claim-cloud.js.map