( getAppState: () => AppState, )
| 295 | * @param getAppState Function to get the current AppState (from command context) |
| 296 | */ |
| 297 | export async function getEnhancedPRAttribution( |
| 298 | getAppState: () => AppState, |
| 299 | ): Promise<string> { |
| 300 | if (process.env.USER_TYPE === 'ant' && isUndercover()) { |
| 301 | return '' |
| 302 | } |
| 303 | |
| 304 | if (getClientType() === 'remote') { |
| 305 | const remoteSessionId = process.env.CLAUDE_CODE_REMOTE_SESSION_ID |
| 306 | if (remoteSessionId) { |
| 307 | const ingressUrl = process.env.SESSION_INGRESS_URL |
| 308 | // Skip for local dev - URLs won't persist |
| 309 | if (!isRemoteSessionLocal(remoteSessionId, ingressUrl)) { |
| 310 | return getRemoteSessionUrl(remoteSessionId, ingressUrl) |
| 311 | } |
| 312 | } |
| 313 | return '' |
| 314 | } |
| 315 | |
| 316 | const settings = getInitialSettings() |
| 317 | |
| 318 | // If user has custom PR attribution, use that |
| 319 | if (settings.attribution?.pr) { |
| 320 | return settings.attribution.pr |
| 321 | } |
| 322 | |
| 323 | // Backward compatibility: deprecated includeCoAuthoredBy setting |
| 324 | if (settings.includeCoAuthoredBy === false) { |
| 325 | return '' |
| 326 | } |
| 327 | |
| 328 | const defaultAttribution = `🤖 Generated with [Claude Code](${PRODUCT_URL})` |
| 329 | |
| 330 | // Get AppState first |
| 331 | const appState = getAppState() |
| 332 | |
| 333 | logForDebugging( |
| 334 | `PR Attribution: appState.attribution exists: ${!!appState.attribution}`, |
| 335 | ) |
| 336 | if (appState.attribution) { |
| 337 | const fileStates = appState.attribution.fileStates |
| 338 | const isMap = fileStates instanceof Map |
| 339 | const fileCount = isMap ? fileStates.size : Object.keys(fileStates).length |
| 340 | logForDebugging(`PR Attribution: fileStates count: ${fileCount}`) |
| 341 | } |
| 342 | |
| 343 | // Get attribution stats (transcript is read once for both prompt count and memory access) |
| 344 | const [attributionData, { promptCount, memoryAccessCount }, isInternal] = |
| 345 | await Promise.all([ |
| 346 | getPRAttributionData(appState), |
| 347 | getTranscriptStats(), |
| 348 | isInternalModelRepo(), |
| 349 | ]) |
| 350 | |
| 351 | const claudePercent = attributionData?.summary.claudePercent ?? 0 |
| 352 | |
| 353 | logForDebugging( |
| 354 | `PR Attribution: claudePercent: ${claudePercent}, promptCount: ${promptCount}, memoryAccessCount: ${memoryAccessCount}`, |
no test coverage detected