import { logger } from '../../core/logger.ts'
import type { AgentPacket, RiskTag } from '../../core/packet.ts'
import { costSpikeTagger } from './cost-spike.ts'
import { secretLeakTagger } from './secret-leak.ts'
import { shellPatternTagger } from './shell-pattern.ts'
import type { RiskTagger } from './types.ts'

const TAGGERS: readonly RiskTagger[] = [
  shellPatternTagger,
  secretLeakTagger,
  costSpikeTagger,
]

export function runRiskTaggers(packet: AgentPacket): RiskTag[] {
  const tags: RiskTag[] = []
  for (const t of TAGGERS) {
    try {
      const out = t(packet)
      if (out.length > 0) tags.push(...out)
    } catch (err) {
      logger.warn(`risk tagger threw: ${(err as Error).message}`)
    }
  }
  return tags
}
