import{n as e}from"./chunk-DR8-3Aex.js";import{n as t,s as n}from"./envUtils-BWeoiL4Y.js";import{U as r,cn as i}from"./state-sIHsFpDu.js";import{join as a}from"node:path";import{appendFileSync as o,existsSync as s,mkdirSync as c,readFileSync as l,unlinkSync as u,writeFileSync as d}from"node:fs";function f(){return a(t(),`.next-request-no-cache`)}function p(){return a(t(),`.break-cache-always`)}function m(){return a(t(),`break-cache-events.jsonl`)}function h(){try{let e=l(m(),`utf8`).trim().split(`
`).filter(Boolean).map(e=>{try{return JSON.parse(e)}catch{return null}}).filter(e=>e!==null),t=e.filter(e=>e.kind===`once`),n=e[e.length-1],r=e.filter(e=>e.kind===`always_on`||e.kind===`always_off`),i=r[r.length-1];return{totalBreaks:t.length,lastBreakAt:n?.at??null,alwaysModeEnabled:i?.kind===`always_on`}}catch{return{totalBreaks:0,lastBreakAt:null,alwaysModeEnabled:!1}}}function g(e){let n=m();c(t(),{recursive:!0});let r={at:new Date().toISOString(),kind:e};o(n,JSON.stringify(r)+`
`,`utf8`)}function _(){g(`once`)}async function v(e){let t=e.trim().toLowerCase(),n=f(),r=p();if(t===`status`){let e=h(),t=s(n),i=s(r);return{type:`text`,value:[`## Break-Cache Status`,``,`  Once marker:    ${t?`ACTIVE (next call will bust cache)`:`not set`}`,`  Always mode:    ${i?`ON (every call busts cache)`:`off`}`,``,`## Stats`,`  total_breaks:   ${e.totalBreaks}`,`  last_break_at:  ${e.lastBreakAt??`never`}`].join(`
`)}}if(t===`off`){let e=!1;return s(n)&&(u(n),e=!0),s(r)&&(u(r),e=!0),g(`always_off`),{type:`text`,value:e?`Break-cache disabled. Removed once marker and/or always flag.`:`Break-cache was not active.`}}if(t===`--clear`)return s(n)?(u(n),{type:`text`,value:`Cache-break marker cleared.\n  \`${n}\``}):{type:`text`,value:`No cache-break marker was set.`};if(t===`always`)return d(r,new Date().toISOString(),`utf8`),g(`always_on`),{type:`text`,value:[`## Always-on cache break enabled`,``,`Flag written: \`${r}\``,``,`Every API call will now append a random nonce to the system prompt,`,`permanently preventing prompt-cache hits for this session.`,``,"To disable: `/break-cache off`"].join(`
`)};if(t===``||t===`once`){let e=new Date().toISOString();d(n,e,`utf8`),_();let t=h();return{type:`text`,value:[`## Cache break scheduled`,``,`Marker written: \`${n}\``,`Timestamp: ${e}`,``,`The next API call will append a random nonce to the system prompt,`,`causing a cache miss. The marker is removed automatically after use.`,``,"To cancel before the next call: `/break-cache --clear`","For every call:               `/break-cache always`",``,`Total breaks this session: ${t.totalBreaks}`,``,`_How it works: Anthropic prompt cache keys on the system-prompt prefix hash._`,`_A unique nonce invalidates the hash, forcing a fresh compute._`].join(`
`)}}return{type:`text`,value:[`Unknown scope: "${t}"`,``,y].join(`
`)}}var y,b,x,S=e((()=>{i(),n(),y=[`Usage: /break-cache [scope]`,``,`  (no args)        Schedule a one-time cache break for the next API call`,`  once             Same as no args`,`  always           Enable persistent cache-break mode (every request)`,`  off              Disable always mode and clear any pending marker`,`  --clear          Clear the pending once marker (cancel before next call)`,`  status           Show current break-cache status and stats`,``,`How it works:`,`  The Anthropic prompt cache keys on the system-prompt prefix hash.`,`  A unique nonce invalidates the hash, forcing a fresh compute.`,`  This is useful when you want to ensure a clean context window.`].join(`
`),b={type:`local-jsx`,name:`break-cache`,description:`Manage prompt-cache breaking. Open actions or run: once, status, always, off`,isHidden:!1,isEnabled:()=>!r(),argumentHint:`[once|status|always|off|--clear]`,bridgeSafe:!0,getBridgeInvocationError:e=>e.trim()?void 0:`Use /break-cache once/status/always/off over Remote Control.`,load:()=>import(`./panel-D3wvAEFE.js`)},x={type:`local`,name:`break-cache`,description:`Force the next (or all) API call(s) to miss prompt cache. Scopes: once, status, always, off`,isHidden:!1,isEnabled:()=>r(),supportsNonInteractive:!0,bridgeSafe:!0,load:async()=>({call:v})}}));export{f as a,p as i,x as n,S as o,v as r,b as t};