/**
 * SDD Parallel Guard Plugin
 *
 * Hook opt-in para OpenCode: educa sobre paralelização real de tasks independentes.
 */

let recentTaskCalls: number[] = []

export const SddParallelGuardPlugin = async () => {
  return {
    "tool.execute.before": async (input: any) => {
      if (input.tool !== "task" && input.tool !== "Task") return

      const now = Date.now()
      recentTaskCalls = recentTaskCalls.filter((timestamp) => now - timestamp < 5000)
      recentTaskCalls.push(now)

      if (recentTaskCalls.length === 2) {
        console.log(
          "[sdd-parallel-guard] Tasks independentes devem ser disparadas juntas e depois sintetizadas pelo lead SDD."
        )
      }
    },
  }
}

export default SddParallelGuardPlugin
