( isNonInteractiveSession: boolean, )
| 537 | } |
| 538 | |
| 539 | async function _executeApiKeyHelper( |
| 540 | isNonInteractiveSession: boolean, |
| 541 | ): Promise<string | null> { |
| 542 | const apiKeyHelper = getConfiguredApiKeyHelper() |
| 543 | if (!apiKeyHelper) { |
| 544 | return null |
| 545 | } |
| 546 | |
| 547 | if (isApiKeyHelperFromProjectOrLocalSettings()) { |
| 548 | const hasTrust = checkHasTrustDialogAccepted() |
| 549 | if (!hasTrust && !isNonInteractiveSession) { |
| 550 | const error = new Error( |
| 551 | `Security: apiKeyHelper executed before workspace trust is confirmed. If you see this message, post in ${MACRO.FEEDBACK_CHANNEL}.`, |
| 552 | ) |
| 553 | logAntError('apiKeyHelper invoked before trust check', error) |
| 554 | logEvent('tengu_apiKeyHelper_missing_trust11', {}) |
| 555 | return null |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | const result = await execa(apiKeyHelper, { |
| 560 | shell: true, |
| 561 | timeout: 10 * 60 * 1000, |
| 562 | reject: false, |
| 563 | }) |
| 564 | if (result.failed) { |
| 565 | // reject:false — execa resolves on exit≠0/timeout, stderr is on result |
| 566 | const why = result.timedOut ? 'timed out' : `exited ${result.exitCode}` |
| 567 | const stderr = result.stderr?.trim() |
| 568 | throw new Error(stderr ? `${why}: ${stderr}` : why) |
| 569 | } |
| 570 | const stdout = result.stdout?.trim() |
| 571 | if (!stdout) { |
| 572 | throw new Error('did not return a value') |
| 573 | } |
| 574 | return stdout |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * Sync cache reader — returns the last fetched apiKeyHelper value without executing. |
no test coverage detected