{"version":3,"file":"policymode-command.mjs","names":[],"sources":["../../../src/commands/policymode-command.ts"],"sourcesContent":["/**\n * /policymode — Switch between delegation and simple policy enforcement modes.\n *\n * Usage:\n *   /policymode                — show current mode\n *   /policymode delegation     — switch to delegation mode (on-chain, default)\n *   /policymode simple         — switch to simple mode (app-layer only)\n *\n * Delegation mode: policies compile to EIP-7710 on-chain delegations.\n * The agent redeems delegations through the DelegationManager contract.\n * Requires a smart account or EIP-7702 wallet for full enforcement.\n *\n * Simple mode: policies are natural-language rules enforced at the app layer.\n * No on-chain delegation, no signing, no smart account required.\n * Works with any wallet. Good for getting started or when you don't need\n * on-chain enforcement.\n */\n\nimport {\n  getPolicyMode,\n  setPolicyMode,\n  type PolicyMode,\n} from '../services/policy-types.js';\n\nexport const policymodeCommand = {\n  name: 'policymode',\n  description: 'Policy enforcement mode: /policymode [delegation|simple]',\n  acceptsArgs: true,\n  requireAuth: true,\n\n  handler: async (ctx?: any) => {\n    const args = (ctx?.args ?? '').trim().toLowerCase();\n\n    // No args: show current mode\n    if (!args) {\n      return showCurrentMode();\n    }\n\n    if (args === 'delegation' || args === 'simple') {\n      return switchMode(args);\n    }\n\n    return {\n      text: [\n        'Unknown mode. Available modes:',\n        '',\n        '  `/policymode delegation` — on-chain enforcement via EIP-7710 (default)',\n        '  `/policymode simple` — app-layer enforcement only',\n        '',\n        'Use `/policymode` with no args to see the current mode.',\n      ].join('\\n'),\n    };\n  },\n};\n\nfunction showCurrentMode() {\n  const mode = getPolicyMode();\n  const lines: string[] = [];\n\n  lines.push('**Policy Enforcement Mode**');\n  lines.push('');\n\n  if (mode === 'delegation') {\n    lines.push('Current mode: **delegation** (on-chain)');\n    lines.push('');\n    lines.push('Policies compile to EIP-7710 delegations with on-chain caveat enforcers.');\n    lines.push('The agent executes actions by redeeming delegations through the DelegationManager.');\n    lines.push('Spending limits, allowed targets, and time bounds are enforced on-chain.');\n    lines.push('');\n    lines.push('Use `/delegate create <name>` to compile and sign a policy as a delegation.');\n    lines.push('');\n    lines.push('Switch to simple mode: `/policymode simple`');\n  } else {\n    lines.push('Current mode: **simple** (app-layer)');\n    lines.push('');\n    lines.push('Policies are natural-language rules enforced at the application layer.');\n    lines.push('No on-chain delegation or signing required. Works with any wallet.');\n    lines.push('The agent checks policies before each action and asks for confirmation');\n    lines.push('when needed. Good for getting started.');\n    lines.push('');\n    lines.push('Switch to delegation mode: `/policymode delegation`');\n  }\n\n  return { text: lines.join('\\n') };\n}\n\nfunction switchMode(newMode: PolicyMode) {\n  const oldMode = getPolicyMode();\n  const lines: string[] = [];\n\n  if (oldMode === newMode) {\n    lines.push(`Already in **${newMode}** mode. No change.`);\n    return { text: lines.join('\\n') };\n  }\n\n  setPolicyMode(newMode);\n\n  lines.push(`**Policy mode switched: ${oldMode} → ${newMode}**`);\n  lines.push('');\n\n  if (newMode === 'delegation') {\n    lines.push('On-chain delegation mode is now active.');\n    lines.push('');\n    lines.push('Your existing policies still work at the app layer. To add on-chain');\n    lines.push('enforcement, use `/delegate create <policy-name>` to compile and sign');\n    lines.push('each policy as an EIP-7710 delegation.');\n  } else {\n    lines.push('Simple mode is now active.');\n    lines.push('');\n    lines.push('Policies are enforced at the application layer only. Any existing on-chain');\n    lines.push('delegations remain valid on-chain but the agent will not attempt to redeem');\n    lines.push('them. Use `/policymode delegation` to re-enable on-chain execution.');\n  }\n\n  return { text: lines.join('\\n') };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,MAAa,oBAAoB;CAC/B,MAAM;CACN,aAAa;CACb,aAAa;CACb,aAAa;CAEb,SAAS,OAAO,QAAc;EAC5B,MAAM,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa;AAGnD,MAAI,CAAC,KACH,QAAO,iBAAiB;AAG1B,MAAI,SAAS,gBAAgB,SAAS,SACpC,QAAO,WAAW,KAAK;AAGzB,SAAO,EACL,MAAM;GACJ;GACA;GACA;GACA;GACA;GACA;GACD,CAAC,KAAK,KAAK,EACb;;CAEJ;A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