113
114
private async _buildBranchName(request: IAgentBranchNameGeneratorRequest, branchNameHint: string | undefined): Promise<string> {
116
>
// the built-in `agents/` prefix. An empty/omitted value keeps the
117
>
// historical `agents/<hint>` shape.
118
>
const prefix = `${request.branchPrefix ?? ''}${AGENT_BRANCH_PREFIX}`;
119
>
120
>
const branchName = `${prefix}${branchNameHint ?? request.sessionId}`;
121
>
const collisionBase = branchNameHint
122
? `${branchName}-${request.sessionId.substring(0, AGENT_BRANCH_SESSION_ID_SUFFIX_LENGTH)}`
123
: branchName;
125
>
const candidate = candidateIndex === 0
126
>
? branchName
127
: branchNameHint && candidateIndex === 1
128
? collisionBase
129
: `${collisionBase}-${branchNameHint ? candidateIndex : candidateIndex + 1}`;
131
>
return candidate;
132
>
}
133
>
}
134
135
throw new Error(`Unable to find an available branch name after checking ${MAX_BRANCH_NAME_CANDIDATES} candidates`);
137
}
138