{"version":3,"file":"policy-command.mjs","names":[],"sources":["../../../src/commands/policy-command.ts"],"sourcesContent":["/**\n * /policy command — set spending policies in natural language\n * Bypasses the LLM agent for fast, zero-cost responses.\n */\n\nimport { parsePolicies, formatPolicy } from '@clawnch/sdk';\nimport { addPolicy, clearPolicies, getWalletState } from '../services/walletconnect-service.js';\n\nexport const policyCommand = {\n  name: 'policy',\n  description: 'Set spending policies in natural language. Example: /policy approve under 0.05 ETH, max 10/hour',\n  acceptsArgs: true,\n  requireAuth: true,\n  handler: async (ctx: { args?: string }) => {\n    const input = ctx.args?.trim();\n\n    if (!input) {\n      const state = getWalletState();\n      if (state.policies.length === 0) {\n        return {\n          text: 'No spending policies set. All transactions require manual approval.\\n\\n' +\n            '**Examples:**\\n' +\n            '`/policy approve under 0.05 ETH`\\n' +\n            '`/policy auto-approve below 0.01 ETH, max 10/hour`\\n' +\n            '`/policy no auto-approve`',\n        };\n      }\n\n      return {\n        text: '**Active Policies:**\\n' +\n          state.policies.map(p => `- ${formatPolicy(p)}`).join('\\n'),\n      };\n    }\n\n    let result: ReturnType<typeof parsePolicies>;\n    try {\n      result = parsePolicies(input);\n    } catch (err) {\n      return {\n        text: `Failed to parse policy: ${err instanceof Error ? err.message : String(err)}\\n\\n` +\n          '**Examples:**\\n' +\n          '`/policy approve under 0.05 ETH`\\n' +\n          '`/policy auto-approve below 0.01 ETH, max 10/hour`\\n' +\n          '`/policy no auto-approve`',\n      };\n    }\n\n    if (result.clearAll) {\n      clearPolicies();\n      return {\n        text: 'All spending policies cleared. Every transaction will require manual approval.',\n      };\n    }\n\n    if (result.policies.length === 0) {\n      return {\n        text: `Could not parse: \"${input}\"\\n\\n` +\n          '**Examples:**\\n' +\n          '`/policy approve under 0.05 ETH`\\n' +\n          '`/policy auto-approve below 0.01 ETH, max 10/hour`\\n' +\n          '`/policy only allow 0xABC...DEF`\\n' +\n          '`/policy no auto-approve`',\n      };\n    }\n\n    for (const policy of result.policies) {\n      addPolicy(policy);\n    }\n\n    const formatted = result.policies.map(p => formatPolicy(p));\n    const warnings = result.unrecognized.length > 0\n      ? `\\n\\nCould not parse: ${result.unrecognized.map(u => `\"${u}\"`).join(', ')}`\n      : '';\n\n    return {\n      text: `**Policies added:**\\n${formatted.map(f => `- ${f}`).join('\\n')}${warnings}`,\n    };\n  },\n};\n"],"mappings":";;;;;;;AAQA,MAAa,gBAAgB;CAC3B,MAAM;CACN,aAAa;CACb,aAAa;CACb,aAAa;CACb,SAAS,OAAO,QAA2B;EACzC,MAAM,QAAQ,IAAI,MAAM,MAAM;AAE9B,MAAI,CAAC,OAAO;GACV,MAAM,QAAQ,gBAAgB;AAC9B,OAAI,MAAM,SAAS,WAAW,EAC5B,QAAO,EACL,MAAM,yMAKP;AAGH,UAAO,EACL,MAAM,2BACJ,MAAM,SAAS,KAAI,MAAK,KAAK,aAAa,EAAE,GAAG,CAAC,KAAK,KAAK,EAC7D;;EAGH,IAAI;AACJ,MAAI;AACF,YAAS,cAAc,MAAM;WACtB,KAAK;AACZ,UAAO,EACL,MAAM,2BAA2B,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,CAAC;;;8BAKnF;;AAGH,MAAI,OAAO,UAAU;AACnB,kBAAe;AACf,UAAO,EACL,MAAM,kFACP;;AAGH,MAAI,OAAO,SAAS,WAAW,EAC7B,QAAO,EACL,MAAM,qBAAqB,MAAM;;;;8BAMlC;AAGH,OAAK,MAAM,UAAU,OAAO,SAC1B,WAAU,OAAO;EAGnB,MAAM,YAAY,OAAO,SAAS,KAAI,MAAK,aAAa,EAAE,CAAC;EAC3D,MAAM,WAAW,OAAO,aAAa,SAAS,IAC1C,wBAAwB,OAAO,aAAa,KAAI,MAAK,IAAI,EAAE,GAAG,CAAC,KAAK,KAAK,KACzE;AAEJ,SAAO,EACL,MAAM,wBAAwB,UAAU,KAAI,MAAK,KAAK,IAAI,CAAC,KAAK,KAAK,GAAG,YACzE;;CAEJ"}