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