@dahawa/hawa-code 1.7.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +706 -660
- package/hawa.js +1 -1
- package/package.json +1 -1
package/hawa.js
CHANGED
|
@@ -52,7 +52,7 @@ ${c.join(`
|
|
|
52
52
|
`:`
|
|
53
53
|
`)+r,i=n+1,n=t.indexOf(`
|
|
54
54
|
`,i)}while(n!==-1);return o+=t.slice(i),o}var{stdout:w6,stderr:O6}=D6,rx=Symbol("GENERATOR"),Di=Symbol("STYLER"),To=Symbol("IS_EMPTY"),C6=["ansi","ansi","ansi256","ansi16m"],Si=Object.create(null),GG=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let r=w6?w6.level:0;t.level=e.level===void 0?r:e.level};var $G=t=>{let e=(...r)=>r.join(" ");return GG(e,t),Object.setPrototypeOf(e,Io.prototype),e};function Io(t){return $G(t)}Object.setPrototypeOf(Io.prototype,Function.prototype);for(let[t,e]of Object.entries(He))Si[t]={get(){let r=b0(this,ix(e.open,e.close,this[Di]),this[To]);return Object.defineProperty(this,t,{value:r}),r}};Si.visible={get(){let t=b0(this,this[Di],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var nx=(t,e,r,...n)=>t==="rgb"?e==="ansi16m"?He[r].ansi16m(...n):e==="ansi256"?He[r].ansi256(He.rgbToAnsi256(...n)):He[r].ansi(He.rgbToAnsi(...n)):t==="hex"?nx("rgb",e,r,...He.hexToRgb(...n)):He[r][t](...n),VG=["rgb","hex","ansi256"];for(let t of VG){Si[t]={get(){let{level:r}=this;return function(...n){let i=ix(nx(t,C6[r],"color",...n),He.color.close,this[Di]);return b0(this,i,this[To])}}};let e="bg"+t[0].toUpperCase()+t.slice(1);Si[e]={get(){let{level:r}=this;return function(...n){let i=ix(nx(t,C6[r],"bgColor",...n),He.bgColor.close,this[Di]);return b0(this,i,this[To])}}}}var KG=Object.defineProperties(()=>{},{...Si,level:{enumerable:!0,get(){return this[rx].level},set(t){this[rx].level=t}}}),ix=(t,e,r)=>{let n,i;return r===void 0?(n=t,i=e):(n=r.openAll+t,i=e+r.closeAll),{open:t,close:e,openAll:n,closeAll:i,parent:r}},b0=(t,e,r)=>{let n=(...i)=>WG(n,i.length===1?""+i[0]:i.join(" "));return Object.setPrototypeOf(n,KG),n[rx]=t,n[Di]=e,n[To]=r,n},WG=(t,e)=>{if(t.level<=0||!e)return t[To]?"":e;let r=t[Di];if(r===void 0)return e;let{openAll:n,closeAll:i}=r;if(e.includes("\x1B"))for(;r!==void 0;)e=S6(e,r.close,r.open),r=r.parent;let o=e.indexOf(`
|
|
55
|
-
`);return o!==-1&&(e=E6(e,i,n,o)),n+e+i};Object.defineProperties(Io.prototype,Si);var zG=Io(),wue=Io({level:O6?O6.level:0});var A6=zG;var nl=xe(uS(),1);var YK={visibilityState:"visible",documentElement:{lang:"en"},addEventListener:(t,e)=>{}},JK={document:YK,location:{href:"node://localhost",pathname:"/"},addEventListener:(t,e)=>{t==="beforeunload"&&process.on("exit",()=>{typeof e=="function"?e({}):e.handleEvent({})})},focus:()=>{},innerHeight:768,innerWidth:1024},XK={sendBeacon:(t,e)=>!0,userAgent:"Mozilla/5.0 (Node.js) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0",language:"en-US"};typeof window>"u"&&(global.window=JK);typeof navigator>"u"&&(global.navigator=XK);import*as rt from"fs";import*as zo from"path";import{homedir as QK}from"os";import{existsSync as ZK,unlinkSync as eW}from"fs";var nn=zo.join(QK(),it,"statsig");try{rt.mkdirSync(nn,{recursive:!0})}catch(t){oe(`Failed to create statsig storage directory: ${t}`)}var tl=class{cache=new Map;ready=!1;constructor(){try{rt.existsSync(nn)||rt.mkdirSync(nn,{recursive:!0});let e=rt.readdirSync(nn);for(let r of e){let n=decodeURIComponent(r),i=rt.readFileSync(zo.join(nn,r),"utf8");this.cache.set(n,i)}this.ready=!0}catch(e){oe(`Failed to initialize statsig storage: ${e}`),this.ready=!0}}isReady(){return this.ready}isReadyResolver(){return this.ready?Promise.resolve():null}getProviderName(){return"FileSystemStorageProvider"}getItem(e){return this.cache.get(e)??null}setItem(e,r){this.cache.set(e,r);try{let n=encodeURIComponent(e);rt.writeFileSync(zo.join(nn,n),r,"utf8")}catch(n){oe(`Failed to write statsig storage item: ${n}`)}}removeItem(e){this.cache.delete(e);let r=encodeURIComponent(e),n=zo.join(nn,r);if(ZK(n))try{eW(n)}catch(i){oe(`Failed to remove statsig storage item: ${i}`)}}getAllKeys(){return Array.from(this.cache.keys())}};var cS="client-RRNS7R65EAtReO5XA4xDC3eU6ZdJQi6lLEP6b5j32Me";var lS="tengu-token-efficient-tools",fS="token-efficient-tools-2024-12-11";var dS="claude-code-20250219";var pS=K(async()=>{let t=[dS];return(process.env.USER_TYPE==="ant"||process.env.SWE_BENCH)&&await rh(lS)&&t.push(fS),t});var rl=K(async()=>{let{code:t}=await gi("git",["rev-parse","--is-inside-work-tree"]);return t===0});var hS=!!process.env.CLAUDE_CODE_USE_BEDROCK,mS=!!process.env.CLAUDE_CODE_USE_VERTEX,xS={bedrock:"us.anthropic.claude-3-7-sonnet-20250219-v1:0",vertex:"claude-3-7-sonnet@20250219",firstParty:"claude-3-7-sonnet-20250219"},Kce=process.env.ANTHROPIC_SMALL_FAST_MODEL?process.env.ANTHROPIC_SMALL_FAST_MODEL:hS?"us.anthropic.claude-3-5-haiku-20241022-v1:0":mS?"claude-3-5-haiku@20241022":"claude-3-5-haiku-20241022";async function tW(){try{return await gS("tengu-capable-model-config",xS)}catch(t){return oe(t),xS}}var vS=K(async()=>{if(process.env.ANTHROPIC_MODEL||process.env.USER_TYPE==="SWE_BENCH"&&process.env.ANTHROPIC_MODEL)return process.env.ANTHROPIC_MODEL;let t=await tW();return hS?t.bedrock:mS?t.vertex:t.firstParty});var bS={},Ho=null,il=K(async()=>{if(le.isCI)return null;let t=await ol(),e={networkConfig:{api:"https://statsig.anthropic.com/v1/"},environment:{tier:le.isCI||["test","development"].includes("production")?"dev":"production"},logLevel:nl.LogLevel.None,storageProvider:new tl};return Ho=new nl.StatsigClient(cS,t,e),Ho.on("error",r=>{oe(`Statsig error: ${r}`)}),await Ho.initializeAsync(),process.on("exit",()=>{Ho?.flush()}),Ho});function _S(t,e){le.isCI||Promise.all([il(),rl(),pS(),e.model?Promise.resolve(e.model):vS()]).then(([r,n,i,o])=>{if(!r)return;let a={...e,model:o,sessionId:on,userType:process.env.USER_TYPE||"",...process.env.SWE_BENCH_RUN_ID?{sweBenchId:process.env.SWE_BENCH_RUN_ID}:{},...i.length>0?{betas:i.join(",")}:{},env:JSON.stringify({isGit:n,platform:le.platform,nodeVersion:le.nodeVersion,terminal:le.terminal,version:MACRO.VERSION})};process.env.USER_TYPE==="ant"&&(process.argv.includes("--debug")||process.argv.includes("-d"))&&console.log(A6.dim(`[DEBUG-ONLY] Statsig event: ${t} ${JSON.stringify(e,null,0)}`));let s={eventName:t,metadata:a};r.logEvent(s)})}var rh=K(async t=>{if(le.isCI)return!1;let e=await il();if(!e)return!1;let r=e.checkGate(t);return bS[t]=r,r});function yS(){return{...bS}}var s0e=K(async(t,e)=>{if(le.isCI)return e;let r=await il();if(!r)return e;let n=r.getExperiment(t);return Object.keys(n.value).length===0?(oe(`getExperimentValue got empty value for ${t}`),e):n.value}),gS=async(t,e)=>{if(le.isCI)return e;let r=await il();if(!r)return e;let n=r.getDynamicConfig(t);return Object.keys(n.value).length===0?(oe(`getDynamicConfig got empty value for ${t}`),e):n.value};var Yo=class extends Error{filePath;defaultConfig;constructor(e,r,n){super(e),this.name="ConfigParseError",this.filePath=r,this.defaultConfig=n}};var oW={allowedTools:[],context:{},history:[],dontCrawlDirectory:!1,enableArchitectTool:!1,mcpContextUris:[],mcpServers:{},approvedMcprcServers:[],rejectedMcprcServers:[],hasTrustDialogAccepted:!1};var al={numStartups:0,autoUpdaterStatus:"disabled",theme:"dark",preferredNotifChannel:"iterm2",verbose:!1,customApiKeyResponses:{approved:[],rejected:[]}};var S0e={...al,autoUpdaterStatus:"disabled"},E0e={...oW};function aW(t){sW(m0,{...t,projects:SS(m0,al).projects},al)}function oh(){return SS(m0,al)}function sW(t,e,r){let n=Object.fromEntries(Object.entries(e).filter(([i,o])=>JSON.stringify(o)!==JSON.stringify(r[i])));nW(t,JSON.stringify(n,null,2),"utf-8")}var uW=!1;function SS(t,e,r){if(!uW)throw new Error("Config accessed before allowed.");if(!nh(t))return wo(e);try{let n=ih(t,"utf-8");try{let i=JSON.parse(n);return{...wo(e),...i}}catch(i){let o=i instanceof Error?i.message:String(i);throw new Yo(o,t,e)}}catch(n){if(n instanceof Yo&&r)throw n;return wo(e)}}var w0e=K(()=>{let t=DS(Jr(),".mcp.json");if(!nh(t))return{};try{let e=ih(t,"utf-8"),r=n6(e);if(r&&typeof r=="object")return r=r.mcpServers,
|
|
55
|
+
`);return o!==-1&&(e=E6(e,i,n,o)),n+e+i};Object.defineProperties(Io.prototype,Si);var zG=Io(),wue=Io({level:O6?O6.level:0});var A6=zG;var nl=xe(uS(),1);var YK={visibilityState:"visible",documentElement:{lang:"en"},addEventListener:(t,e)=>{}},JK={document:YK,location:{href:"node://localhost",pathname:"/"},addEventListener:(t,e)=>{t==="beforeunload"&&process.on("exit",()=>{typeof e=="function"?e({}):e.handleEvent({})})},focus:()=>{},innerHeight:768,innerWidth:1024},XK={sendBeacon:(t,e)=>!0,userAgent:"Mozilla/5.0 (Node.js) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0",language:"en-US"};typeof window>"u"&&(global.window=JK);typeof navigator>"u"&&(global.navigator=XK);import*as rt from"fs";import*as zo from"path";import{homedir as QK}from"os";import{existsSync as ZK,unlinkSync as eW}from"fs";var nn=zo.join(QK(),it,"statsig");try{rt.mkdirSync(nn,{recursive:!0})}catch(t){oe(`Failed to create statsig storage directory: ${t}`)}var tl=class{cache=new Map;ready=!1;constructor(){try{rt.existsSync(nn)||rt.mkdirSync(nn,{recursive:!0});let e=rt.readdirSync(nn);for(let r of e){let n=decodeURIComponent(r),i=rt.readFileSync(zo.join(nn,r),"utf8");this.cache.set(n,i)}this.ready=!0}catch(e){oe(`Failed to initialize statsig storage: ${e}`),this.ready=!0}}isReady(){return this.ready}isReadyResolver(){return this.ready?Promise.resolve():null}getProviderName(){return"FileSystemStorageProvider"}getItem(e){return this.cache.get(e)??null}setItem(e,r){this.cache.set(e,r);try{let n=encodeURIComponent(e);rt.writeFileSync(zo.join(nn,n),r,"utf8")}catch(n){oe(`Failed to write statsig storage item: ${n}`)}}removeItem(e){this.cache.delete(e);let r=encodeURIComponent(e),n=zo.join(nn,r);if(ZK(n))try{eW(n)}catch(i){oe(`Failed to remove statsig storage item: ${i}`)}}getAllKeys(){return Array.from(this.cache.keys())}};var cS="client-RRNS7R65EAtReO5XA4xDC3eU6ZdJQi6lLEP6b5j32Me";var lS="tengu-token-efficient-tools",fS="token-efficient-tools-2024-12-11";var dS="claude-code-20250219";var pS=K(async()=>{let t=[dS];return(process.env.USER_TYPE==="ant"||process.env.SWE_BENCH)&&await rh(lS)&&t.push(fS),t});var rl=K(async()=>{let{code:t}=await gi("git",["rev-parse","--is-inside-work-tree"]);return t===0});var hS=!!process.env.CLAUDE_CODE_USE_BEDROCK,mS=!!process.env.CLAUDE_CODE_USE_VERTEX,xS={bedrock:"us.anthropic.claude-3-7-sonnet-20250219-v1:0",vertex:"claude-3-7-sonnet@20250219",firstParty:"claude-3-7-sonnet-20250219"},Kce=process.env.ANTHROPIC_SMALL_FAST_MODEL?process.env.ANTHROPIC_SMALL_FAST_MODEL:hS?"us.anthropic.claude-3-5-haiku-20241022-v1:0":mS?"claude-3-5-haiku@20241022":"claude-3-5-haiku-20241022";async function tW(){try{return await gS("tengu-capable-model-config",xS)}catch(t){return oe(t),xS}}var vS=K(async()=>{if(process.env.ANTHROPIC_MODEL||process.env.USER_TYPE==="SWE_BENCH"&&process.env.ANTHROPIC_MODEL)return process.env.ANTHROPIC_MODEL;let t=await tW();return hS?t.bedrock:mS?t.vertex:t.firstParty});var bS={},Ho=null,il=K(async()=>{if(le.isCI)return null;let t=await ol(),e={networkConfig:{api:"https://statsig.anthropic.com/v1/"},environment:{tier:le.isCI||["test","development"].includes("production")?"dev":"production"},logLevel:nl.LogLevel.None,storageProvider:new tl};return Ho=new nl.StatsigClient(cS,t,e),Ho.on("error",r=>{oe(`Statsig error: ${r}`)}),await Ho.initializeAsync(),process.on("exit",()=>{Ho?.flush()}),Ho});function _S(t,e){le.isCI||Promise.all([il(),rl(),pS(),e.model?Promise.resolve(e.model):vS()]).then(([r,n,i,o])=>{if(!r)return;let a={...e,model:o,sessionId:on,userType:process.env.USER_TYPE||"",...process.env.SWE_BENCH_RUN_ID?{sweBenchId:process.env.SWE_BENCH_RUN_ID}:{},...i.length>0?{betas:i.join(",")}:{},env:JSON.stringify({isGit:n,platform:le.platform,nodeVersion:le.nodeVersion,terminal:le.terminal,version:MACRO.VERSION})};process.env.USER_TYPE==="ant"&&(process.argv.includes("--debug")||process.argv.includes("-d"))&&console.log(A6.dim(`[DEBUG-ONLY] Statsig event: ${t} ${JSON.stringify(e,null,0)}`));let s={eventName:t,metadata:a};r.logEvent(s)})}var rh=K(async t=>{if(le.isCI)return!1;let e=await il();if(!e)return!1;let r=e.checkGate(t);return bS[t]=r,r});function yS(){return{...bS}}var s0e=K(async(t,e)=>{if(le.isCI)return e;let r=await il();if(!r)return e;let n=r.getExperiment(t);return Object.keys(n.value).length===0?(oe(`getExperimentValue got empty value for ${t}`),e):n.value}),gS=async(t,e)=>{if(le.isCI)return e;let r=await il();if(!r)return e;let n=r.getDynamicConfig(t);return Object.keys(n.value).length===0?(oe(`getDynamicConfig got empty value for ${t}`),e):n.value};var Yo=class extends Error{filePath;defaultConfig;constructor(e,r,n){super(e),this.name="ConfigParseError",this.filePath=r,this.defaultConfig=n}};var oW={allowedTools:[],context:{},history:[],dontCrawlDirectory:!1,enableArchitectTool:!1,mcpContextUris:[],mcpServers:{},approvedMcprcServers:[],rejectedMcprcServers:[],hasTrustDialogAccepted:!1};var al={mcpServers:{},numStartups:0,autoUpdaterStatus:"disabled",theme:"dark",preferredNotifChannel:"iterm2",verbose:!1,customApiKeyResponses:{approved:[],rejected:[]}};var S0e={...al,autoUpdaterStatus:"disabled"},E0e={...oW};function aW(t){sW(m0,{...t,projects:SS(m0,al).projects},al)}function oh(){return SS(m0,al)}function sW(t,e,r){let n=Object.fromEntries(Object.entries(e).filter(([i,o])=>JSON.stringify(o)!==JSON.stringify(r[i])||i=="mcpServers"));nW(t,JSON.stringify(n,null,2),"utf-8")}var uW=!1;function SS(t,e,r){if(!uW)throw new Error("Config accessed before allowed.");if(!nh(t))return wo(e);try{let n=ih(t,"utf-8");try{let i=JSON.parse(n);return{...wo(e),...i}}catch(i){let o=i instanceof Error?i.message:String(i);throw new Yo(o,t,e)}}catch(n){if(n instanceof Yo&&r)throw n;return wo(e)}}var w0e=K(()=>{let t=DS(Jr(),".mcp.json");if(!nh(t))return{};try{let e=ih(t,"utf-8"),r=n6(e);if(r&&typeof r=="object")return r=r.mcpServers,_S("tengu_mcprc_found",{numServers:Object.keys(r).length.toString()}),r}catch{}return{}},()=>{let t=Jr(),e=DS(t,".mcp.json");if(nh(e))try{let r=ih(e,"utf-8");return`${t}:${r}`}catch{return t}return t});function ES(){let t=oh();if(t.userID)return t.userID;let e=iW(32).toString("hex");return aW({...t,userID:e}),e}var cW=K(async()=>{let t=await gi("git",["config","user.email"]);if(t.code!==0){oe(`Failed to get git email: ${t.stdout} ${t.stderr}`);return}return t.stdout.trim()||void 0}),ol=K(async()=>{let t=ES(),e=oh(),r=process.env.USER_TYPE==="ant"?e.oauthAccount?.emailAddress??await cW()??(process.env.COO_CREATOR?`${process.env.COO_CREATOR}@anthropic.com`:void 0):void 0;return{customIDs:{sessionId:on},userID:t,appVersion:MACRO.VERSION,userAgent:le.platform,email:r,custom:{nodeVersion:le.nodeVersion,userType:process.env.USER_TYPE,organizationUuid:e.oauthAccount?.organizationUuid,accountUuid:e.oauthAccount?.accountUuid}}});async function wS(t){try{let[e,r]=await Promise.all([rl(),ol()]);Kc({nodeVersion:le.nodeVersion,platform:le.platform,cwd:Jr(),isCI:le.isCI,isGit:e,isTest:!1,packageVersion:MACRO.VERSION,sessionId:on,statsigGates:yS(),terminal:le.terminal,userType:process.env.USER_TYPE}),Wc({id:r.userID,email:r.email}),Vc(t)}catch{}}import{randomUUID as dW}from"crypto";import{homedir as pW}from"os";var ah=[],xW=100,on=dW(),Gi=_t(pW(),it);function $i(t){return t.replace(/[^a-zA-Z0-9]/g,"-")}var uh={apis:()=>_t(Gi,"project",$i(process.cwd()),"apis"),errors:()=>_t(Gi,"project",$i(process.cwd()),"errors"),messages:()=>_t(Gi,"project",$i(process.cwd()),"messages"),mcpLogs:t=>_t(Gi,"project",$i(process.cwd()),`mcp-logs-${t}`),log:()=>_t(Gi,"project",$i(process.cwd()),"log"),vcrFixtures:()=>_t(Gi,"project",$i(process.cwd()),"vcr-fixtures")};function hW(t){return t.toISOString().replace(/[:.]/g,"-")}var ch=hW(new Date);function mW(){return _t(uh.errors(),ch+".txt")}function vW(){return _t(uh.log(),ch+".log")}function gW(){return _t(uh.log(),"error-"+ch+".log")}function AS(t,e,...r){let n=r.map(i=>i instanceof Error?`${i.name}: ${i.message}
|
|
56
56
|
${i.stack.replace(/^/gm," ")}`:i);_W(e,{level:t,message:n.length==1?n[0]:n})}function Xo(...t){AS("info",vW(),...t)}function lh(...t){AS("error",gW(),...t)}function oe(t){try{let e=t instanceof Error?t.stack||t.message:String(t),r={error:e,timestamp:new Date().toISOString()};ah.length>=xW&&ah.shift(),ah.push(r),yW(mW(),{error:e})}catch{}wS(t)}function bW(t){if(!Jo(t))return[];try{return JSON.parse(lW(t,"utf8"))}catch{return[]}}function _W(t,e){let r=CS(t);Jo(r)||OS(r,{recursive:!0});let i=(typeof e=="string"?e:JSON.stringify(e))+`
|
|
57
57
|
`;Jo(t)?fW(t,i,"utf8"):sh(t,i,"utf8")}function yW(t,e){process.env.USER_TYPE;let r=CS(t);Jo(r)||OS(r,{recursive:!0}),Jo(t)||sh(t,"[]","utf8");let n=bW(t),i={...e,cwd:process.cwd(),userType:process.env.USER_TYPE,sessionId:on,timestamp:new Date().toISOString(),version:MACRO.VERSION};n.push(i),sh(t,JSON.stringify(n,null,2),"utf8")}var cl={env:{},permissions:{allow:[],deny:[]},enableAllProjectMcpServers:!1,enabledMcpjsonServers:[],autoCompactEnabled:!1,language:"auto"},fh=class t{static instance;constructor(){this.initializeConfigDirectories()}initializeConfigDirectories(){let e=this.getUserSettingsPath(),r=this.getProjectSettingsPath();this.ensureDirExists(e),sl(e)||ul(e,JSON.stringify(this.getDefaultSettingsStructure(),null,2),"utf-8"),this.ensureDirExists(r),sl(r)||ul(r,JSON.stringify(this.getDefaultSettingsStructure(),null,2),"utf-8")}getDefaultSettingsStructure(){return{env:{},permissions:{allow:[],deny:[]}}}static getInstance(){return t.instance||(t.instance=new t),t.instance}addProjectAllowedTools(e){let r=this.loadSettingsFromFile(this.getProjectSettingsPath()),n=r.permissions||{allow:[],deny:[]};if(n.allow||(n.allow=[]),n.allow.includes(e))Xo(`\u5DE5\u5177 '${e}' \u5DF2\u5B58\u5728\u4E8E\u9879\u76EE\u5141\u8BB8\u5217\u8868\u4E2D\uFF0C\u65E0\u9700\u91CD\u590D\u6DFB\u52A0`);else{n.allow.push(e),n.allow.sort();let i={...r,permissions:{...n}};this.saveSettingsToFile(this.getProjectSettingsPath(),i,cl),Xo(`\u5DF2\u5C06\u5DE5\u5177 '${e}' \u6DFB\u52A0\u5230\u9879\u76EE\u5141\u8BB8\u5217\u8868`)}}getUserSettingsPath(){return TS(wW(),".hcode","settings.json")}getProjectSettingsPath(){let e=process.cwd();return TS(e,".hcode","settings.json")}ensureDirExists(e){let r=EW(e);sl(r)||SW(r,{recursive:!0})}loadSettingsFromFile(e){if(!sl(e))return{};let r="";try{return r=DW(e,"utf-8"),JSON.parse(r)}catch(n){return console.error(`Error reading settings file ${e} => ${r} `,n),{}}}saveSettingsToFile(e,r,n){let i={...r};for(let[o,a]of Object.entries(r))if(o in n)if(typeof a=="object"&&typeof n[o]=="object"){if(JSON.stringify(a)===JSON.stringify(n[o]))delete i[o];else if(o==="permissions"&&a&&typeof a=="object"){let s=n.permissions||{},u=a;Array.isArray(u.allow)&&Array.isArray(s.allow)&&JSON.stringify(u.allow)===JSON.stringify(s.allow)&&delete u.allow,Array.isArray(u.deny)&&Array.isArray(s.deny)&&JSON.stringify(u.deny)===JSON.stringify(s.deny)&&delete u.deny,Object.keys(u).length===0&&delete i[o]}}else a===n[o]&&delete i[o];this.ensureDirExists(e),Object.keys(i).length===0?ul(e,"{}","utf-8"):ul(e,JSON.stringify(i,null,2),"utf-8")}loadSettings(){let e=this.loadSettingsFromFile(this.getUserSettingsPath()),r=this.loadSettingsFromFile(this.getProjectSettingsPath()),n={...e.env,...r.env},i={...e.permissions};if(e.permissions?.allow&&r.permissions?.allow){let a=[...e.permissions.allow];r.permissions.allow.forEach(s=>{a.includes(s)||a.push(s)}),i.allow=a}else r.permissions?.allow&&(i.allow=[...r.permissions.allow]);if(e.permissions?.deny&&r.permissions?.deny){let a=[...e.permissions.deny];r.permissions.deny.forEach(s=>{a.includes(s)||a.push(s)}),i.deny=a}else r.permissions?.deny&&(i.deny=[...r.permissions.deny]);let o={...cl,...e,...r};return n&&Object.keys(n).length>0&&(o.env=n),i&&(i.allow||i.deny)&&(o.permissions=i),o}saveUserSettings(e){let r=this.getUserSettingsPath();this.saveSettingsToFile(r,e,cl)}saveProjectSettings(e){let r=this.getProjectSettingsPath();this.saveSettingsToFile(r,e,cl)}getSetting(e){return this.loadSettings()[e]}updateSetting(e,r){let i={...this.loadSettings(),[e]:r};this.saveProjectSettings(i)}resetSetting(e){let n={...this.loadSettings()};delete n[e],this.saveProjectSettings(n)}getAllSettings(){return this.loadSettings()}},Qo=fh.getInstance(),IS=Qo.getAllSettings();function dh(){let t=Qo.getUserSettingsPath(),e=Qo.getProjectSettingsPath();FS(t,(r,n)=>{r==="change"&&(IS=null,Xo("\u7528\u6237\u7EA7\u914D\u7F6E\u5DF2\u70ED\u52A0\u8F7D"))}).on("error",r=>{lh("\u7528\u6237\u7EA7\u914D\u7F6E\u76D1\u63A7\u51FA\u9519:",r),setTimeout(()=>dh(),100)}),FS(e,(r,n)=>{r==="change"&&(IS=null,Xo("\u9879\u76EE\u7EA7\u914D\u7F6E\u5DF2\u70ED\u52A0\u8F7D",n))}).on("error",r=>{lh("\u9879\u76EE\u7EA7\u914D\u7F6E\u76D1\u63A7\u51FA\u9519:",r),setTimeout(()=>dh(),100)})}dh();function AW(){mh();let t=vh(),e=[];Object.entries(t).forEach(([r,n],i)=>{n.enable===!0&&e.push({name:`${i}. ${r}`,value:r})}),e.length===0&&(console.error(`\u8BF7\u68C0\u67E5\u914D\u7F6E\u6587\u4EF6 ~/${it}/config.json\uFF0C\u786E\u4FDD\u81F3\u5C11\u6709\u4E00\u4E2A\u6A21\u578B\u7684 enable \u8BBE\u7F6E\u4E3A true\u3002`),process.exit(1)),(async()=>{let r=await Q_.prompt([{type:"list",name:"choice",message:"\u8BF7\u9009\u62E9\u4E00\u4E2A\u6A21\u578B\uFF1A",choices:e}]);var n=t[r.choice];let i=n.env,o={};Object.keys(i).forEach(p=>{["BASE_URL","AUTH_TOKEN","MODEL","SMALL_FAST_MODEL"].includes(p)?o[`ANTHROPIC_${p}`]=i[p]:o[p]=i[p]});let a=Qo.getSetting("env")||{};process.platform==="win32"&&!process.env.HCODE_GIT_BASH_PATH&&!o.HCODE_GIT_BASH_PATH&&!a.HCODE_GIT_BASH_PATH&&(console.error("\u5728 Windows \u7CFB\u7EDF\u4E0A\u8FD0\u884C\uFF0C\u8BF7\u786E\u4FDD\u914D\u7F6E\u73AF\u5883\u53D8\u91CF HCODE_GIT_BASH_PATH\uFF0C\u53C2\u8003\u6587\u6863\uFF1Ahttps://www.hawacode.com/docs"),process.exit(1));let s=CW(import.meta.url),u=PS.dirname(s),c=PS.join(u,"cli.js"),l=OW(process.execPath,["--no-deprecation",c,...process.argv.slice(2)],{env:{...process.env,...o,...a},stdio:"inherit",cwd:process.cwd()});l.on("error",p=>{console.error("Failed to start command:",p.message),process.exit(1)}),l.on("close",p=>{process.exit(p||0)})})()}async function FW(){AW()}await FW();
|
|
58
58
|
/*! Bundled license information:
|