Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

3.7 KB
Raw Blame
/// How far a new agent may go without asking — the choice in New Harness ▸ Advanced.
///
/// Mirrors the CLI's `PERMISSION_MODES` (cli/src/lib/engineLaunch.ts) mode for mode: this is the
/// menu, the CLI is what turns a mode into flags and refuses one an engine lacks. An engine absent
/// here offers no choice. Keep both tables in step.
library;

class PermissionMode {
  const PermissionMode(this.id, this.label, this.detail, {this.risky = false});

  /// What the machine is sent (`agent_create`'s `permissionMode`).
  final String id;
  final String label;
  final String detail;

  /// Turns off the engine's own safety net; worded as such in the menu.
  final bool risky;
}

/// The default for every engine that has modes.
const kDefaultPermissionMode = 'auto';

const _auto = 'auto';
const _ask = 'ask';

const Map<String, List<PermissionMode>> kEnginePermissionModes = {
  'claude': [
    PermissionMode(
      _auto,
      'Auto-approve',
      'Approves routine actions, checks risky ones',
    ),
    PermissionMode(
      'acceptEdits',
      'Accept edits',
      'Edits files freely, asks before commands',
    ),
    PermissionMode(
      'plan',
      'Plan first',
      'Reads and plans, changes nothing until you agree',
    ),
    PermissionMode(
      _ask,
      'Ask first',
      'Asks before acting, as Claude Code does',
    ),
    PermissionMode(
      'full',
      'Skip all checks',
      'No approvals and no safety checks. Risky',
      risky: true,
    ),
  ],
  'codex': [
    PermissionMode(
      'readOnly',
      'Read only',
      'Reads and suggests, asks before any change',
    ),
    PermissionMode(_ask, 'Ask first', 'Asks before acting, as Codex does'),
    PermissionMode(
      _auto,
      'Auto-approve',
      'Approves routine actions in the sandbox',
    ),
    PermissionMode(
      'full',
      'Full access',
      'No approvals and no sandbox. Risky',
      risky: true,
    ),
  ],
  'cursor': [
    PermissionMode(_auto, 'Auto-approve', 'Runs commands without asking'),
    PermissionMode(_ask, 'Ask first', 'Asks before running commands'),
  ],
  'opencode': [
    PermissionMode(_auto, 'Auto-approve', 'Approves actions on its own'),
    PermissionMode(_ask, 'Ask first', 'Asks before acting'),
  ],
};

/// Modes Harness launches on its own and New Harness never offers: an older
/// Buddy's saved mode, now full (CLI engines/*/launch.ts, task #2832), and
/// Team-written work's, named here so their details read by name. The older
/// Buddy modes go with the CLI's aliases after 2026-12-04.
const Map<String, List<PermissionMode>> kLaunchOnlyPermissionModes = {
  'claude': [
    PermissionMode(
      'buddy',
      'Full, older Buddy',
      'Runs with full access, as its owner\'s own session',
    ),
    PermissionMode(
      'teamWritten',
      'Full, project settings off',
      'Reads none of the branch\'s own settings',
    ),
  ],
  'codex': [
    PermissionMode(
      'readOnlyAsk',
      'Full, older Buddy',
      'Runs with full access, as its owner\'s own session',
    ),
    PermissionMode(
      'teamWritten',
      'Full, project settings off',
      'Reads none of the branch\'s own settings',
    ),
  ],
};

/// The modes [engine] offers, or empty when it has none to choose between.
List<PermissionMode> permissionModesOf(String engine) =>
    kEnginePermissionModes[engine] ?? const [];

/// Whether [mode] lets the agent act without stopping to ask — the yes/no a daemon that predates
/// modes understands (`bypassPermission`). Plan and Read only read as no, so an older machine asks
/// rather than approving on their behalf; Skip all checks reads as yes and gets Auto-approve there.
bool permissionModeApproves(String mode) => mode == _auto || mode == 'full';