import{c as e,u as t}from"./errors-pXKbCKbL.js";import{n,t as r}from"./editor-BmJI32_P.js";import{t as i}from"./format-a_tYXjv9.js";import{c as a,i as o,n as s,s as c}from"./fsStore-BzLA1cBc.js";import{t as l}from"./base-xqced3zT.js";import{t as u}from"./claudeDefault-B8XYzR_k.js";import*as d from"node:path";import*as f from"node:fs";var p=class extends l{toolId=`claude`;async list(t){if(!this.validateScope(t))throw new e(t);let n=c(this.resolvePath(t)),r=d.dirname(n),i=d.basename(n),a=[this.#e(n,t,!0)];if(f.existsSync(r)){let e=f.readdirSync(r,{withFileTypes:!0});for(let n of e){if(!n.isFile()||n.name===i||!this.#r(n.name))continue;let e=d.join(r,n.name);a.push(this.#e(e,t,!1))}}return{type:`files`,files:this.#i(a)}}resolvePath(e){switch(e){case`user`:return`~/.claude/settings.json`;case`project`:return`.claude/settings.json`;case`local`:return`.claude/settings.local.json`;default:throw Error(`Unsupported scope for Claude: ${e}`)}}validateScope(e){return[`user`,`project`,`local`].includes(e)}async switchProfile(n,r,a){if(!this.validateScope(n))throw new e(n);let o=r.trim();if(!o)throw Error(`Variant name cannot be empty`);let s=c(this.resolvePath(n)),l=d.dirname(s),u=this.#a(l,o,s);if(!u)throw new t(o);let f=this.readConfig(u),p={};try{p=this.readConfig(s)}catch{p={}}let m=i(p,f);if(a?.preview)return{success:!0,preview:!0,filePath:s,diff:m??void 0,data:{from:u,to:s,hasChanges:!!m},message:m?`Preview generated. Review diff before applying.`:`Current settings already match the selected variant.`};if(!m)return{success:!0,message:`Current settings already match the selected variant.`,filePath:s};let h=a?.backup??!1;return this.writeConfig(s,f,h),{success:!0,message:`Switched to ${d.basename(u)}`,filePath:s,data:{from:u,to:s}}}async edit(t,i){if(!this.validateScope(t))throw new e(t);let o=c(this.resolvePath(t)),l=d.dirname(o),u=i.name?.trim(),p=n(i.ide);s(l);let m=o,h=`default`;if(u&&u!==``&&u!==`default`){let e=this.#a(l,u,o);if(e)m=e;else if(m=d.join(l,`settings.${u}.json`),!f.existsSync(m)){let e=this.#n(o);a(m,e,!1)}h=u}else if(!f.existsSync(m)){let e=this.#n(o);a(m,e,!1)}return await r(p,m),{success:!0,message:`Opened ${h} settings in ${p}`,filePath:m,data:{variant:h,ide:p}}}#e(e,t,n){let r=o(e);return{filename:d.basename(e),variant:this.#t(e),path:e,scope:t,active:n,exists:!!r,size:r?.size,lastModified:r?.lastModified}}#t(e){let t=d.basename(e),n=t.match(/^settings(?:[._-](.+))?\.json$/);return n?n[1]??`default`:t.replace(/\.json$/,``)}#n(e){try{if(f.existsSync(e)){let t=f.readFileSync(e,`utf-8`);return JSON.parse(t)}}catch{}return{...u}}#r(e){return/^settings[._-].+\.json$/.test(e)}#i(e){return e.sort((e,t)=>e.active&&!t.active?-1:!e.active&&t.active?1:e.variant.localeCompare(t.variant))}#a(e,t,n){let r=[],i=e=>{r.includes(e)||r.push(e)};t===`default`&&i(n),t.endsWith(`.json`)?i(d.isAbsolute(t)?t:d.join(e,t)):(i(d.join(e,`settings.${t}.json`)),i(d.join(e,`settings-${t}.json`)),i(d.join(e,`settings_${t}.json`)));for(let e of r)if(f.existsSync(e))return e;return null}};export{p as t};