classifierApprovals.ts
utils/classifierApprovals.ts
No strong subsystem tag
89
Lines
2448
Bytes
10
Exports
2
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 89 lines, 2 detected imports, and 10 detected exports.
Important relationships
Detected exports
setClassifierApprovalgetClassifierApprovalsetYoloClassifierApprovalgetYoloClassifierApprovalsetClassifierCheckingclearClassifierCheckingsubscribeClassifierCheckingisClassifierCheckingdeleteClassifierApprovalclearClassifierApprovals
Keywords
tooluseidfeatureapprovalclassifier_approvalsvoidclassifierclassifier_checkingclassifiercheckingmatchedrulereason
Detected imports
bun:bundle./signal.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* Tracks which tool uses were auto-approved by classifiers.
* Populated from useCanUseTool.ts and permissions.ts, read from UserToolSuccessMessage.tsx.
*/
import { feature } from 'bun:bundle'
import { createSignal } from './signal.js'
type ClassifierApproval = {
classifier: 'bash' | 'auto-mode'
matchedRule?: string
reason?: string
}
const CLASSIFIER_APPROVALS = new Map<string, ClassifierApproval>()
const CLASSIFIER_CHECKING = new Set<string>()
const classifierChecking = createSignal()
export function setClassifierApproval(
toolUseID: string,
matchedRule: string,
): void {
if (!feature('BASH_CLASSIFIER')) {
return
}
CLASSIFIER_APPROVALS.set(toolUseID, {
classifier: 'bash',
matchedRule,
})
}
export function getClassifierApproval(toolUseID: string): string | undefined {
if (!feature('BASH_CLASSIFIER')) {
return undefined
}
const approval = CLASSIFIER_APPROVALS.get(toolUseID)
if (!approval || approval.classifier !== 'bash') return undefined
return approval.matchedRule
}
export function setYoloClassifierApproval(
toolUseID: string,
reason: string,
): void {
if (!feature('TRANSCRIPT_CLASSIFIER')) {
return
}
CLASSIFIER_APPROVALS.set(toolUseID, { classifier: 'auto-mode', reason })
}
export function getYoloClassifierApproval(
toolUseID: string,
): string | undefined {
if (!feature('TRANSCRIPT_CLASSIFIER')) {
return undefined
}
const approval = CLASSIFIER_APPROVALS.get(toolUseID)
if (!approval || approval.classifier !== 'auto-mode') return undefined
return approval.reason
}
export function setClassifierChecking(toolUseID: string): void {
if (!feature('BASH_CLASSIFIER') && !feature('TRANSCRIPT_CLASSIFIER')) return
CLASSIFIER_CHECKING.add(toolUseID)
classifierChecking.emit()
}
export function clearClassifierChecking(toolUseID: string): void {
if (!feature('BASH_CLASSIFIER') && !feature('TRANSCRIPT_CLASSIFIER')) return
CLASSIFIER_CHECKING.delete(toolUseID)
classifierChecking.emit()
}
export const subscribeClassifierChecking = classifierChecking.subscribe
export function isClassifierChecking(toolUseID: string): boolean {
return CLASSIFIER_CHECKING.has(toolUseID)
}
export function deleteClassifierApproval(toolUseID: string): void {
CLASSIFIER_APPROVALS.delete(toolUseID)
}
export function clearClassifierApprovals(): void {
CLASSIFIER_APPROVALS.clear()
CLASSIFIER_CHECKING.clear()
classifierChecking.emit()
}