package net.intrepid.aiengineering.localserver; import picocli.CommandLine; import java.util.*; /** Routing comes from the actual Picocli parse, never from scanning option values for keywords. */ public final class InvocationPolicy { private InvocationPolicy() {} private static final Set LOCAL = Set.of("init", "guide", "agent list", "agent doctor"); private static final Set READS = Set.of( "status", "next-actions", "project show", "project validate", "project compatibility", "repo list", "work show", "work list", "work context", "work check", "work validate", "discussion list", "discussion show", "decision list", "decision show", "decision history", "plan list", "plan show", "plan history", "plan experiment list", "plan experiment show", "artifact list", "topic list", "topic show", "survey list", "survey show", "survey history", "agent show", "agent history", "epic show", "epic check", "epic history", "gate status", "gate history"); public static String path(CommandLine.ParseResult parse) { var parts = new ArrayList(); for (var child = parse.subcommand(); child != null; child = child.subcommand()) parts.add(child.commandSpec().name()); return String.join(" ", parts); } public static boolean local(CommandLine.ParseResult parse) { if (path(parse).isEmpty() || LOCAL.contains(path(parse))) return true; for (var current = parse; current != null; current = current.subcommand()) if (current.isUsageHelpRequested() || current.isVersionHelpRequested()) return true; return false; } public static boolean readOnly(CommandLine.ParseResult parse) { return READS.contains(path(parse)); // Unknown/new commands conservatively count as mutations. } }