(
pendingCheck: { command: string; cwd: string; descriptions: string[] },
signal: AbortSignal,
isNonInteractiveSession: boolean,
callbacks: AsyncClassifierCheckCallbacks,
)
| 1604 | * @param callbacks - Callbacks to check if we should continue and handle approval |
| 1605 | */ |
| 1606 | export async function executeAsyncClassifierCheck( |
| 1607 | pendingCheck: { command: string; cwd: string; descriptions: string[] }, |
| 1608 | signal: AbortSignal, |
| 1609 | isNonInteractiveSession: boolean, |
| 1610 | callbacks: AsyncClassifierCheckCallbacks, |
| 1611 | ): Promise<void> { |
| 1612 | const { command, cwd, descriptions } = pendingCheck |
| 1613 | const speculativeResult = consumeSpeculativeClassifierCheck(command) |
| 1614 | |
| 1615 | let classifierResult: ClassifierResult |
| 1616 | try { |
| 1617 | classifierResult = speculativeResult |
| 1618 | ? await speculativeResult |
| 1619 | : await classifyBashCommand( |
| 1620 | command, |
| 1621 | cwd, |
| 1622 | descriptions, |
| 1623 | 'allow', |
| 1624 | signal, |
| 1625 | isNonInteractiveSession, |
| 1626 | ) |
| 1627 | } catch (error: unknown) { |
| 1628 | // When the coordinator session is cancelled, the abort signal fires and the |
| 1629 | // classifier API call rejects with APIUserAbortError. This is expected and |
| 1630 | // should not surface as an unhandled promise rejection. |
| 1631 | if (error instanceof APIUserAbortError || error instanceof AbortError) { |
| 1632 | callbacks.onComplete?.() |
| 1633 | return |
| 1634 | } |
| 1635 | callbacks.onComplete?.() |
| 1636 | throw error |
| 1637 | } |
| 1638 | |
| 1639 | logClassifierResultForAnts(command, 'allow', descriptions, classifierResult) |
| 1640 | |
| 1641 | // Don't auto-approve if user already made a decision or has interacted |
| 1642 | // with the permission dialog (e.g., arrow keys, tab, typing) |
| 1643 | if (!callbacks.shouldContinue()) return |
| 1644 | |
| 1645 | if ( |
| 1646 | feature('BASH_CLASSIFIER') && |
| 1647 | classifierResult.matches && |
| 1648 | classifierResult.confidence === 'high' |
| 1649 | ) { |
| 1650 | callbacks.onAllow({ |
| 1651 | type: 'classifier', |
| 1652 | classifier: 'bash_allow', |
| 1653 | reason: `Allowed by prompt rule: "${classifierResult.matchedDescription}"`, |
| 1654 | }) |
| 1655 | } else { |
| 1656 | // No match — notify so the checking indicator is cleared |
| 1657 | callbacks.onComplete?.() |
| 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | /** |
| 1662 | * The main implementation to check if we need to ask for user permission to call BashTool with a given input |
no test coverage detected